akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
vector<vector<int>>edge;
auto TopologicalSort(int n){
    vector<int>v(n,false);
    vector<int>out(n);
    int idx = n-1;
    function<void (int)>dfs = [&](int u) -> void{
        v[u] = true;
        for(int i = 0; i < edge[u].size();i++){
            int nv = edge[u][i];
            if(!v[nv])dfs(nv);
        }
        out[idx--] = u;
    };
    for(int i = 0; i < v.size();i++){
        if(!v[i])dfs(i);
    }
    return out;
}
signed main(){
    int n,m;
    cin >> n >> m;
    edge = vector<vector<int>>(n);
    rep(i,m){
        int x,y; cin >> x >> y;
        --x,--y;
        edge[x].push_back(y);
    }
    auto v = TopologicalSort(n);
    vector<int>dp(n,0LL);
    for(auto e : v){
        rep(j,edge[e].size()){
            int nv = edge[e][j];
            cmax(dp[nv],dp[e]+1);
        }
    }
    cout << *max_element(all(dp)) << endl;;
}



Measured memory_bytes: 9984
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <stack>
#include <tuple>

using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;

ll ans = 0;
string s = "";

void solve(ll cash, int index,int sum)
{
    if (index == s.size() - 1)
    {
        ans += cash + sum;
        return;
    }
    //+を挿入しない場合
    solve(cash * 10 + s[index + 1] - '0', index + 1,sum);
    //+を挿入した場合
    solve(s[index + 1] - '0', index + 1,sum + cash);
}

int main()
{
    cin >> s;
    solve(s[0] - '0', 0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())

dp = [[0 for _ in range(W)] for _ in range(H + 1)]

dp[0][0] = 1

for i in range(1, H + 1):
    for j in range(W):
        for k in range(2 ** (W - 1)):
            if bin(k).count("11") >= 1:
                continue
            if j + 1 <= W - 1 and (k >> j) & 1:
                dp[i][j] += dp[i - 1][j + 1]
            elif j - 1 >= 0 and (k >> (j - 1)) & 1:
                dp[i][j] += dp[i - 1][j - 1]
            else:
                dp[i][j] += dp[i - 1][j]
        dp[i][j] %= (10 ** 9 + 7)
print(dp[H][K - 1] % (10 ** 9 + 7))


Measured memory_bytes: 3064
using System;

namespace AizuOnLine
{
    class Program
    {

        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] data = Console.ReadLine().Split(' ');

            for (int i = data.Length - 1; 0 < i; i--)
            {
                Console.Write(data[i] + " "); 
            }

            Console.WriteLine(data[0]);
        }
    }
}

Measured memory_bytes: 8940
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}          // Least Commont Multiple オーバーフローしないように先に割る

const ll INF = LONG_MAX;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("c.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    int n, k, q;
    cin >> n >> k >> q;

    //vector<int> a(n);
    int a[100000];
    rep(i, q) cin >> a[i];

    //vector<int> correct(n);
    int correct[100000];

    rep(i, n) {
        correct[i] = 0;
    }


    rep(i, q) {
        correct[a[i]-1]++;
    }

    rep(i, n) {
        if ( (k - q + correct[i]) > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }

    return 0;
}

/*
  - 1e9 : 10^9
  - vector
    vector<int> A(N);
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  ll N;
  cin >> N;
  vector<ll> B(N-1);
  for(int i = 0;i < N-1;i++)cin >> B[i];

  ll ans = B[0] + B[N-2];
  for(int i = 0;i < N-2;i++){
    ans += min(B[i],B[i+1]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

# N = int(input())
S = input()
T = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

ma = 0
s = len(S)
t = len(T)
for i in range(s - t + 1):
    cnt = 0
    for j in range(t):
        if S[i + j] == T[j]:
            cnt += 1
    if cnt > ma:
        ma = cnt
print(t - ma)

Measured memory_bytes: 9048
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef long long ll;

int main(){
  vector<vector<int>> c(3,vector<int>(3));
  rep(i,3)rep(j,3)
    cin>>c[i][j];
  
  rep(i,2){
    rep(j,2){
       if(c[i][j + 1] - c[i][j] != c[i + 1][j + 1] - c[i + 1][j]){
          cout<<"No"<<endl;
          return 0;
       }
    }
    rep(j,2){
       if(c[j + 1][i] - c[j][i] != c[j + 1][i + 1] - c[j][i + 1]){
          cout<<"No"<<endl;
          return 0;
       }
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
const int MaxN = 5e5 + 5;
int n,m,a,b[MaxN + 5];

map<int,int>num;
map<int,int>cnt;

int main()
{
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a);
		num[a]++;
	}
	scanf("%d",&m);
	for(int i = 1; i <= m; i++){
		scanf("%d",&b[i]);
		int k = b[i];
		cnt[k]++;
	}
	for(int i = 1; i <= m; i++){
		int k = b[i];
		if(num[k] < cnt[k]){
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

 

Measured memory_bytes: 19840
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// hoge hoge hoge

fn main() {
    input! {
        mut a: [i64; 5],
        k: i64,
    }

    // jfkafsdlfjkergogjadfas

    a.sort();

    let ans = if a[4] - a[0] > k { ":(" } else { "Yay!" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P = sorted(P, reverse=True)[:X]
Q = sorted(Q, reverse=True)[:Y]
R = sorted(R, reverse=True)

L = sorted(P + Q + R, reverse=True)
print(sum(L[:X+Y]))


Measured memory_bytes: 115948
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	int a,b,t;
	scanf("%d %d",&a,&b);
	t = a+b;
	if(a-b>t)
	 t = a-b;
	 if(a*b>t)
	 t = a*b;
	 printf("%d\n",t);
	 return 0;
} 

Measured memory_bytes: 256
from fractions import gcd
a,b,c,d=map(int,input().split())
l=(c*d)//gcd(c,d)
e=(a-1)//c
f=b//c
g,h=(a-1)//d,b//d
i,j=(a-1)//l,b//l
print(b-a+1-f+e-h+g+j-i)

Measured memory_bytes: 5048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();

		String[] n = line.split(" ");
		int a = Integer.parseInt(n[0]);
		int b = Integer.parseInt(n[1]);
		int c = Integer.parseInt(n[2]);

		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}



Measured memory_bytes: 26084
#include<cstdio>
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
using  ll = long long;
using namespace std;

int main(){
  int x, y; cin >> x >> y;
  int z[13] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  if(z[x] == z[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

const int N = 9;
int memo[N][1 << N] , n;

int solve (int i , int msk) {
    if (i == n)
        return 1;

    int &ret = memo[i][msk];
    if (~ret)
         return ret;

    ret = 0;
    for (int j = 0 ;j < n ;j++)
        if (!(msk & (1 << j)))
            ret += solve(i + 1 , msk | (1 << j));

    return ret;
}

int get(vector<int> &a) {
    auto fact = [](int n) {
        int ret = 1;
        for (int i = 2 ;i <= n ;i++)
            ret *= i;
        return ret;
    };

    int less = 0 , msk = 0;
    for (int i = 0 ;i < n ;i++) {
        for (int j = 0 ;j < a[i] ;j++)
            if (!(msk & (1 << j)))
                less += solve(i + 1 , msk | (1 << j));
        msk |= 1 << a[i];
    }

    return less + 1;
}

int main() {
    cin >> n;

    vector<int> a(n) , b(n);
    for (int i = 0 ;i < n ;i++) {
        cin >> a[i];
        a[i]--;
    }

    for (int i = 0 ;i < n ;i++) {
        cin >> b[i];
        b[i]--;
    }

    memset(memo , -1 , sizeof memo);
    cout << abs(get(a) - get(b));
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll n, p = 0;
ll f[50];

void init() {
	f[0] = 1;
	for (int i = 1; i <= 45; i++)
		f[i] = 2 * f[i - 1];
}

int main() {
	init();
	scanf("%lld", &n);
	while (n >= f[p]) p++;
	printf("%lld\n", f[p] - 1);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main(){
    ll n;
    cin >> n;
    n--;
    cout << n*(n+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int main() {
	int a, b, n;
	cin >> a >> b;
	while(a!=0)
	{
	cin >> n;
	vector<vector<int> > c(a, vector<int>(b));
	vector<vector<int> > s(a, vector<int>(b));
	vector<int> zero(b,0);
	vector<int> iti(b, 1);
	for (int i = 0; i < a; i++) {
		c[i] = zero;
		s[i] = iti;
	}
	c[0][0] = 1;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		s[x - 1][y - 1] = 0;
	}
	for (int i = 0; i < (a - 1) + (b - 1); i++) {
		vector<vector<int> > cq(a, vector<int>(b));
		cq = c;
		for (int j = 0; j < a; j++) {
			for (int k = 0; k < b; k++) {
				if (j==0) {
					if (k != 0) {
						c[0][k] = cq[0][k - 1] * s[0][k];
					}
				}
				else {
					if (k == 0) {
						c[j][0] = cq[j - 1][0] * s[j][0];
					}
					else {
						c[j][k] = s[j][k]*(cq[j-1][k]+cq[j][k-1]);
					}
				}
			}
		}
	}
	cout << c[a-1][b-1]<<endl;
	cin >> a>>b;
	}
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int a[100005];
int p[100005];
int main(void){
    int n,k,q; cin>>n>>k>>q;
    for(int i=0;i<q;i++){
        cin>>a[i];
        p[a[i]]++;
    }
    for(int i=1;i<=n;i++){
        p[i]=k-(q-p[i]);
        if(p[i]>0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    
}


Measured memory_bytes: 1408
#include<iostream>
#include <algorithm>
using namespace std;

static const int MAX = 200000;

int main() {
	int R[MAX]; //???????????????
	int n; //????????°
	
	//??\???
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> R[i];
	}

	//?¨????
	int maxv = -2000000000; //???????°??????????????????????????¨????
	int minv = R[0];

	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	//??????
	cout << maxv << endl;

	return 0;
}

int max(int oldMax, int newMax) {
	int nowMax;

	nowMax = oldMax;
	if (newMax > oldMax) {
		nowMax = newMax;
	}

	return nowMax;
}

int min(int oldMin, int newMin) {
	int nowMin;

	nowMin = oldMin;
	if (newMin > oldMin) {
		nowMin = newMin;
	}

	return nowMin;
}

Measured memory_bytes: 3872
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int a,b,c,d,e,k;
  bool conn = true;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a > k) conn = false;

  if (conn){
    cout << "Yay!";
    
  }else{
    cout << ":(";
    
  }
  
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    
    String a = s.substring(0, 1);
    String b = s.substring(1, 2);
    String c = s.substring(2, 3);
    String d = s.substring(3, 4);
    
    if (a.equals(b) && b.equals(c) && c.equals(d)) {
      System.out.println("No");
    } else if (a.equals(b) && c.equals(d)) {
      System.out.println("Yes");
    } else if (a.equals(c) && b.equals(d)) {
      System.out.println("Yes");
    } else if (a.equals(d) && b.equals(c)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23636
#include <iostream>
#include <cstring>

using namespace std;

int main() {
    int n;
    cin >> n;
    for(int i=1; i<=n; ++i) {
        if(i%3==0) {
            cout << " " << i;
            continue;
        }
        int x = i;
        while(x) {
            if(x%10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
}



Measured memory_bytes: 3084
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 1000055
//#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,fac[N],inv[N],f[N],ans;
int C(int n,int m){
	if (n<m||m<0) return 0;
	return (ll) fac[n]*inv[n-m]%mod;
}
int ksm(int x,int k){
	int sum=1;
	while (k){
		if (k&1) sum=(ll)sum*x%mod;
		x=(ll)x*x%mod;
		k>>=1;
	}
	return sum;
}
signed main(){
	n=read();
	fac[0]=1;F(i,1,n) fac[i]=(ll)fac[i-1]*i%mod;
	inv[n]=ksm(fac[n],mod-2);D(i,n-1,0) inv[i]=(ll)inv[i+1]*(i+1)%mod;
	F(i,(n+1)/2,n-1){
		f[i]=(ll)C(i-1,n-i-1)*fac[i]%mod;
		ans=(ans+(ll)(f[i]-f[i-1])*i)%mod;
	}
	wrn((ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;

const int N = (int)1e5;

pair<int,int> dat[N+5];

int main() {
    for (int i=0; i<N+3; i++) dat[i] = make_pair(1,0);
    dat[1].second = 1;

    int n,q; scanf("%d %d", &n, &q);
    for (int i=1; i<=q; i++) {
        int a,b; scanf("%d %d", &a, &b);

        dat[a].first -= 1;
        dat[b].first += 1;
        dat[b].second |= dat[a].second;

        if (dat[a].first == 0) {
            dat[a].second = 0;
        }
    }

    int res = 0;
    for (int i=1; i<=n; i++) res += dat[i].second;
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
    long long a,b,c,x,ans=0;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++)
     for(int j=0;j<=b;j++)
      for(int k=0;k<=c;k++)
      {
       int sum=i*500+j*100+k*50;
       if(sum==x)ans++;
       if(sum>x)break;
      }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a;i < b; i++)

int main() {

	int a;
	string s;

	cin >> a >> s;

	if (a >= 3200) cout << s << endl;
	else cout << "red" << endl;

	return 0;
}

Measured memory_bytes: 256
// ----------------------------------------------------------
// --https://kenkoooo.com/atcoder/#/table/soma62jp

// ----------------------------------------------------------
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef long double ld;

#define LL_MOD          (ll)1000000007
#define LL_INF          (ll)1 << 62
#define INT_INF         (int)1 << 30

#define rSort(a)        sort(a.rbegin(),a.rend())
#define Sort(a)         sort(a.begin(),a.end())
#define Reverse(a)      reverse(a.begin(),a.end())
#define Sum(a)          accumulate(a.begin(), a.end(), 0)
#define REP(i, n)       for(ui i = 0;i < n;i++)
#define REPR(i, n)      for(ui i = n;i >= 0;i--)
#define FOR(i, m, n)    for(ui i = m;i < n;i++)
#define pb(i)           push_back(i)
#define mp              make_pair
#define SWAP(x,y)       ((x!=y)&&(x^=y,y^=x,x^=y))


int main(int argc, char* argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,R;

    cin >> N >> R;

    cout << (N>=10 ? R : R + 100 * (10 - N)) << endl;
    
    return 0;
    
}



Measured memory_bytes: 256
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    a = na()
    print(a.index(0)+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10588
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
typedef long long ll;

int main(){
  int s,w;
  cin>>s>>w;
  if(w>=s){
    cout<<"unsafe";
  }else{
    cout<<"safe";
  }
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){

  int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  int set=C*2;
  int ans=0;
  int min=0;
  if(A+B>set){
  
    if(X<Y)min=X;
    else min=Y;
    ans+=set*min;
    X-=min;
    Y-=min;
  }
  else {
  
    cout<<X*A+Y*B;
    return 0;
  }
  if(A<set)ans+=A*X;
  else ans+=set*X;
  if(B<set)ans+=B*Y;
  else ans+=set*Y;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vl L(n);
    rep(i, n) {
        cin >> L[i];
    }
    sort(all(L));

    ll ans = 0;
    rep(i, n-1) {
        exrep(j, i+1, n-1) {
            ll pos = lower_bound(all(L), L[i] + L[j]) - L.begin();
            ans += pos - j - 1;
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    static int[][] map = new int[8][8];

    static void explosion(int i, int j) {
        if (i < 0 || i > 7 || j < 0 || j > 7)
            return;
        if (map[i][j] == 1) {
            map[i][j] = 0;
            for (int x = 1; x <= 3; x++) {
                explosion(i + x, j);
                explosion(i - x, j);
                explosion(i, j + x);
                explosion(i, j - x);
            }
        } else {
            return;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String line;
        br.readLine();

        for (int num = 0; num < n; num++) {
            // initialize map
            for (int i = 0; i < 8; i++) {
                line = br.readLine();
                char[] c = line.toCharArray();
                for (int j = 0; j < 8; j++) {
                    if (c[j] == '1') {
                        map[i][j] = 1;
                    } else {
                        map[i][j] = 0;
                    }
                }
            }

            int x = Integer.parseInt(br.readLine());
            int y = Integer.parseInt(br.readLine());

            explosion(y - 1, x - 1);

            System.out.println("Data " + (num + 1) + ":");
            for (int i = 0; i < 8; i++) {
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < 8; j++) {
                    sb.append(map[i][j]);
                }
                System.out.println(sb);
            }

            br.readLine();
        }

    }
}


Measured memory_bytes: 24188
<?php
    ini_set('memory_limit', -1);
    $num = array_map('intval',explode(" ",trim(fgets(STDIN))));
    $item = $num[0];
    $WEIGHT = $num[1];
    for($i=1;$i<=$item;$i++){
        list($v,$w)= array_map('intval',explode(" ",trim(fgets(STDIN))));
        $value[$i]=$v;
        $weight[$i]=$w;
        
    }
    $value[0]=0;
    $weight[0]=0;
    for($i=0;$i<=$item;$i++){
        for($w=0;$w<=$WEIGHT;$w++){
            $dp[$i][$w] = 0;
        }
    }
    for($i=0;$i<=$item;$i++){
        for($w=0;$w<=$WEIGHT;$w++){
            if($w>=$weight[$i]){
                $dp[$i+1][$w] = max($dp[$i][$w-$weight[$i]]+$value[$i],$dp[$i][$w]);
            }else{
                $dp[$i+1][$w] = $dp[$i][$w];
            }
        }
    }
    echo max($dp[$item+1])."\n";
?>


Measured memory_bytes: 159604
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

namespace zyt
{
	const int N = 1010, B = 31;
	const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
	const char ch[] = "RLUD";
	int n, cnt[2];
	pair<int, int> arr[N];
	int abs(const int x)
	{
		return x < 0 ? -x : x;
	}
	bool check(const int x, const int y, const int i)
	{
		return (long long)abs(x) + abs(y) < (1 << i);
	}
	int work()
	{
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%d%d", &arr[i].first, &arr[i].second), ++cnt[(arr[i].first + arr[i].second) & 1];
		if (cnt[0] && cnt[1])
		{
			 puts("-1");
			 return 0;
		}
		printf("%d\n", cnt[0] ? B + 1 : B);
		if (cnt[0])
		{
			printf("1 ");
			for (int i = 1; i <= n; i++)
				--arr[i].first;
		}
		for (int i = 0; i < B; i++)
			printf("%d ", (1 << i));
		puts("");
		for (int i = 1; i <= n; i++)
		{
			char buf[B + 1];
			buf[B] = '\0';
			int x = arr[i].first, y = arr[i].second;
			for (int j = B - 1; j >= 0; j--)
			{
				for (int k = 0; k < 4; k++)
				{
					if (check(x + dx[k] * (1 << j), y + dy[k] * (1 << j), j))
					{
						buf[j] = ch[k ^ 1];
						x = x + dx[k] * (1 << j), y = y + dy[k] * (1 << j);
						break;
					}
				}
			}
			if (x || y)
			{
				fprintf(stderr, "gg");
				return -1;
			}
			if (cnt[0])
				putchar('R');
			printf("%s\n", buf);
		}
		return 0;
	}
}
int main()
{
	return zyt::work();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[4000][4000];
string s,t;
int n , m ;		
void solve(){
	n = s.size();
	m = t.size();
	memset(dp,0,sizeof(dp));
	for(int i =1;i<=n;i++){
		for(int j =1;j<=m;j++){
			if(s[i-1]==t[j-1]){
				dp[i][j] = 1 + dp[i-1][j-1];
			}
			else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	string ans;
	int i =n,j=m;
	while(dp[i][j]!=0){
		if(dp[i][j] > max(dp[i-1][j],dp[i][j-1])){
			ans+=s[i-1];
			--i;
			--j;
		}
		else{
			if(dp[i-1][j]<=dp[i][j-1])
			--j;
			else
				i--;
		}
	}
	reverse(all(ans));
	cout<<ans<<'\n';
}
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		cin>>s>>t;
		solve();
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 127232
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
// const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const int MAXN = 210;
const int INF = 1000000000;

// destination, capacity
vector<pair<int, int> > g[MAXN];

int max_flow(int s, int t, int n) {
    vector<int> ff(n + 1, 0);
    vector<int> fa(n + 1, 0);
    vector<int> fi(n + 1, 0);
    vector<bool> z(n + 1, 0);
    
    int i = 0, now, ans = 0;
    
    i = s;
    now = INF;
    
    while (true) {
        z[i] = true;
        ff[i] = now;
        bool flag = false;
        auto p = g[i].begin();
        while (p != g[i].end()) {
             if (p->second > 0 && !z[p->first]) {
                flag = true;
                if (p->second < now) now = p->second;
                fa[p->first] = i;
                fi[p->first] = p - g[i].begin();
                i = p->first;
                if (i == t) {
                    ans += now;
                    while (i != s) {
                        int tmp = i;
                        i = fa[i];
                        p = g[i].begin() + fi[tmp];
                        p->second -=now;
                        g[tmp].push_back(make_pair(i, now));
                    }
                    now = INF;
                    z = vector<bool> (n + 1, false);
                }
                break;
            }
            ++p;
        }
        if (flag) continue;
        if (!flag && i == s) break;
        
        if (i != s) {
            i = fa[i];
            now = ff[i];
        }
    }
    
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    int n;
    cin >> n;
    vector<pii> red(n+1), blue(n+1);
    FOR(i, 1, n) cin >> red[i].first >> red[i].second;
    FOR(i, 1, n) cin >> blue[i].first >> blue[i].second;
    int src = 2*n+1;
    int tgt = src+1;
    FOR(i, 1, n) {
    	g[src].push_back({i, 1});
    	g[n+i].push_back({tgt, 1});
    	FOR(j, 1, n) {
    		if(red[i].first < blue[j].first && red[i].second < blue[j].second) {
    			g[i].push_back({n+j, 1});
    		}
    	}
    }
    cout << max_flow(src, tgt, tgt) << endl;

    return 0;
}

Measured memory_bytes: 384
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);		
		int N = sc.nextInt();
		long A[] = new long[N];
		boolean zero = false;
		for(int i = 0 ; i < N ; ++i){
			A[i] = sc.nextLong();
			if(A[i] == 0){
				zero = true;
			}
		}
		if(zero){
			System.out.println(0);
		}else{
			long limit = 1000000000000000000L;
			BigInteger LIM = BigInteger.valueOf(limit);
			BigInteger ret = BigInteger.ONE;
			boolean overflow = false;
			for(long a : A){
				if(a == 1){
					continue;
				}
				ret = ret.multiply(BigInteger.valueOf(a));
				if(ret.compareTo(LIM) > 0){
					overflow = true;
					break;
				}
			}
			if(overflow){
				System.out.println(-1);
			}else{
				System.out.println(ret.toString());
			}
		}
	}
}


Measured memory_bytes: 62108
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,T;
    cin >> n >> T;
    int c[n];
    int t[n];
    for(int i=0;i<n;++i) cin >> c[i] >> t[i];
    int ans=100000;
    for(int i=0;i<n;++i) {
        if(t[i]<=T) ans=min(ans,c[i]);
    }
    if(ans<100000) cout << ans << endl;
    else cout << "TLE" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int a[7],i,x;
    for(i=0;i<7;i++)
    {
        a[i]=pow(2,(double)i);
    }
    while(~scanf("%d",&x))
    {
        for(i=6;i>=0;i--)
        {
            if(a[i]<=x)
            {
                printf("%d\n",a[i]);
                break;
            }
        }
    }

}


Measured memory_bytes: 128
import sys

n = int(input())
c = [0 if x=='W' else 1 for x in input()]
counter = 0

white_index = [i for i,ele in enumerate(c) if ele == 0]
red_index = [i for i in range(len(c)-1, -1, -1) if c[i] == 1]
    
    
for i in range(min(len(white_index), len(red_index))):
    if white_index[i] < red_index[i]:
        counter += 1
print(counter)

Measured memory_bytes: 18656
#include <bits/stdc++.h>

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    char C[2][4];
    cin >> C[0] >> C[1];

    // cout << C[0] << endl;
    // cout << C[1] << endl;

    if (C[0][0] == C[1][2] && C[0][1] == C[1][1] && C[0][2] == C[1][0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
public class Main {

	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int S = sc.nextInt();
		int h = S / (60 * 60);
		int m = (S - h*60*60) / 60;
		int s = S - h*60*60 - m*60;
		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 26108
#include <stdio.h>

int main (){
	int N;
	int a;
	scanf("%d", &N);
	
	a = N / 10;
	
	if ( N % 10 == 7){
		printf("Yes");
	}
	else if ( N / 100 == 7){
		printf("Yes");
	}
	else if ( a % 10 == 7){
		printf("Yes");
	}
	else {
		printf("No");
	}
	 
	return 0;
}

Measured memory_bytes: 1724
#include <cstdio>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <tuple>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long int ll;
using namespace std;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main()
{

    ll x;
    cin>>x;
    cout<<x*x*x<<endl;
    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;

using i64 = long long;

int cost[100005]={0};

int main(){
    int n;
    cin >> n;
    vector<int> v;
    for(int i=0;i<n;++i){
        cost[i] = INT_MAX;
        int h;
        cin >> h;
        v.push_back(h);
    }
    cost[0] = 0;
    for(int i=0;i<n-1;++i){
        if(i+2 < n){
            cost[i+2] = min(cost[i+2], cost[i]+abs(v[i]-v[i+2]));
        }
        cost[i+1] = min(cost[i+1], cost[i]+abs(v[i]-v[i+1]));
    }

    cout << cost[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;

int keta(int n) {
    string S = to_string(n);
    int tmp=0;
    for (char c:S) tmp += c - '0';
    return tmp;
}

int main(){
    int N;
    cin >> N;
    int minwa=1000000;
    for (int a=1;a<N;a++) {
        int wa=0;
        wa = keta(a) + keta(N-a);
        if(wa<=minwa)  {
            minwa = wa ;
        }
    }
    cout << minwa << endl;
}

Measured memory_bytes: 256
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	int a, b;
	cin >> a >> b;
	int ans = max(0, a - b * 2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main()
{
    int x,t,i;
    while(cin>>x)
    {
        t=sqrt(x)*sqrt(2);
        for(i=t+1;;i++)
        {
            if(i*t/2>=x)
            {
                break;
            }
            else
            {
                t=i;
            }
        }
        cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)
#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(V.begin(),V.end(),c))

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,K;
    cin >>N>>K;
    int cl=0,cr=0;
    string S;
    cin >> S;
    rep(i,N){
        if(i!=0){
            if(S[i-1]=='R' && S[i]=='L')cr++,cl++;
        }else{
            if(S[0]=='L')cl++;
        }
    }
    if(S[N-1]=='R')cr++;
    int T=min({K,cl,cr});
    cl-=T;
    cr-=T;
    cout << N-max(cl+cr,1) <<endl;
    return (0);
}

Measured memory_bytes: 512
#include <stdio.h>
#define min(a,b) ( ((a) < (b)) ? (a) : (b) )		/*øt«}N(I[o[EwbhªÈ¢ÌÅ·)*/

int goal_depth = 0;
int correct_answer = 0;

int DFS(int sum,int nowdepth,int node)			/*recursive call(ÄAÄÑoµ)*/
{
	int count = 0;			/* ¡Ì[³ÌJEg */
	int next_node = 0;				/* Tõ·ém[hðè·é */
	
	if(nowdepth == goal_depth){				/* êÔ[¢Æ±ëÜÅ½ç */
		if(sum == correct_answer){
			return 1;						/*count++ÉÄé (countÍOÏÉµÄÜ¹ñBµ½ç©ÉÈé)*/
		} else {
			return 0;
		}
	}
			/*		} è	*/
	for(next_node = min(node,correct_answer - sum)  ;  next_node >= 0  ;  next_node--){
		count += DFS( sum + next_node , nowdepth + 1 , next_node - 1 );
	}
	
	return count;		/*Å[ÉBµÄ¢È¢ÌÉAnext_nodeªÌlÈçAúl0ðÔ·B*/
}


int main()
{
	int n,s;
							/*©É­¢ÌÅ«Ìæ¤ÉµÄÝ½*/
	while(scanf("%d %d",&n,&s), !(n == 0 && s == 0) ){
		int myanswer=0;
		goal_depth = n;
		correct_answer = s;
		
		myanswer = DFS(0,0,9);
		
		printf("%d\n",myanswer);
	}
	
	return 0;
}

Measured memory_bytes: 0
def main():
    N = int(input())
    
    S = sorted(sorted(input()) for _ in range(N))

    sol = 0
    current = 1

    for i, s in enumerate(S[1:], start=1):
        if s == S[i - 1]:
            current += 1
        else:
            sol += (current * (current - 1)) // 2
            current = 1

    sol += (current * (current - 1)) // 2
    print(sol)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26004
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353 
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'



int main()
{
    fastio;
    #ifdef APNA_IO
        start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);    
    #endif

    ll n;cin>>n;
    ll a=0,b=0;
    for(ll i=0;i<n;i++)
    {
        ll x,y;cin>>x>>y;

        if(x>=a && y>=b)
        {
            a=x,b=y;
            continue;
        }

        ll p=(a/x)+((a%x)?1LL:0LL);
        ll q=(b/y)+((b%y)?1LL:0LL);
        if(p>q) swap(p,q);
        if(p*x>=a && p*y>=b)
        {
            a=x*p,b=y*p;
            continue;
        }

        a=q*x,b=q*y;

    }
    cout<<a+b;

    #ifdef APNA_IO
        end_routine();
    #endif
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define FOR(i, a, b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define YYS(x, arr) for(auto& x: arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb empalce_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = (ll)1e9 + 7;

template<class T> T &chmin(T &a, const T &b){a = min(a, b);}
template<class T> T &chmax(T &a, const T &b){a = max(a, b);}
template<class T> void UNIQUE(vector<T> &a){a.erase(unique(a.begin(), a.end()), a.end());}

template<class S, class T> ostream& operator <<(ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
  
ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[10000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

int main(){

  int n = in();
  vector<vector<int>> a(2, vector<int>(n));
  vector<vector<int>> s(2, vector<int>(n+1));
  REP(i, 2){
    REP(j, n){
      a[i][j] = in();
      s[i][j+1] = s[i][j] + a[i][j];
    }
  }

  int ans = 0;
  REP(j, n){
    chmax(ans, s[0][j+1] + (s[1][n] - s[1][j]));
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int S;
  cin>>S;
  set<int> X;
  X.insert(S);
  int Y=1;
  rep(i,1000001){
    if(S%2) S=S*3+1;
    else S/=2;
    X.insert(S);
    if(X.size()==Y){
      cout<<i+2<<endl;
      break;
    }
    Y++;
  }
}



Measured memory_bytes: 256
from sys import stdin
input = stdin.readline().split()
A, B, C, D = int(input[0]), int(input[1]), int(input[2]), int(input[3])
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x % y
            x = y
            y = z
        else:
            return z
def lcm(m, n):
    return int(m * n / gcd(m, n))
# print(gcd(C, D))
val_lcm = lcm(C, D)
# print(val_lcm)
b_c = B // C
b_d = B // D
a_c = (A - 1) // C
a_d = (A - 1) // D
b_lcm = B // val_lcm
a_lcm = (A - 1) // val_lcm
dif_c = b_c - a_c
dif_d = b_d - a_d
dif_lcm = b_lcm - a_lcm
# print(dif_c, dif_d, dif_lcm)
print(B - A + 1 - (dif_c + dif_d) + dif_lcm)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;

  int nlen = s.length();
  int ans = 0;

  FOR(i,0,9){
    FOR(j,0,9){
      FOR(k,0,9){
        int ref = 0;
        bool flaga = false;
        bool flagb = false;
        bool flagc = false;
        FOR(l,0,nlen-1){
          if(ref==0){
            if((int)(s[l]-'0')==i){
              ++ref;
              flaga = true;
            }
          }
          else if(ref==1){
            if((int)(s[l]-'0')==j){
              ++ref;
              flagb = true;
            }
          }
          else if(ref==2){
            if((int)(s[l]-'0')==k){
              ++ref;
              flagc = true;
            }
          }
        }

        if(flagc) ++ans;
      }
    }
  }

  cout << ans << endl;

  


}



Measured memory_bytes: 256