akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>

using namespace std;


template <typename T>
struct BIT {
    private:
        vector<T> array;
        const int n;
    
    public:
        BIT(int _n) : array(_n + 1, 0), n(_n) {}

        T sum(int i) {
            if (i < 0) return 0;
            T s = 0;
            i++;
            while (i) {
                s += array[i - 1];
                i -= i & -i;
            }
            return s;
        }

        T sum(int i, int j) {
            T ret_i = sum(i - 1);
            T ret_j = sum(j);
            return ret_j - ret_i;
        }

        void add(int i, T x) {
            i++;
            while (i < n) {
                array[i-1] += x;
                i += i & -i;
            }
        }

        T operator()(int i) {
            if (i < 0) return 0;
            T s = 0;
            i++;
            while(i) {
                s += array[i - 1];
                i -= i & -i;
            }
            return s;
        }
};

int maian() {
    int N, Q;
    string S;
    vector<BIT<int>> bt;
    for (int i = 0; i < 26; i++) {
        BIT<int> x(20);
        bt.push_back(x);
    }
    cin >> N >> S;
    for (int i = 0; i < N; i++) {
        bt[S[i] - 'a'].add(i, 1);
    }
    cin >> Q;
    while (Q--) {
        int i; cin >> i;
        if (i == 1) {
            int x;
            string s;
            cin >> x >> s;
            x--;
            bt[s[x] - 'a'].add(x, -1);
            S[x] = s[0];
            bt[S[x] - 'a'].add(x, 1);
        }
        else {
            int L, R;
            cin >> L >> R;
            L--, R--;
            int cnt = 0;
            for (int i = 0; i < 26; i++) {
                if (bt[i].sum(L, R)) cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;

}

int N;
string S;
int Q;

#define FOR(x, y) for (int x = 0; x < y; x++)

template<class V, int ME> class BIT2 {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT2<int,20> bt[26];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	FOR(i,N) bt[S[i]-'a'].add(i,1);
	cin>>Q;
	while(Q--) {
		cin>>i;
		if(i==1) {
			cin>>x>>s;
			x--;
			bt[S[x]-'a'].add(x,-1);
			S[x]=s[0];
			bt[S[x]-'a'].add(x,1);
		}
		else {
			int L,R;
			cin>>L>>R;
			L--,R--;
			int cnt=0;
			FOR(i,26) {
				if(bt[i](R)-bt[i](L-1)) cnt++;
			}
			cout<<cnt<<endl;
		}
	}
	
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 107396
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

/*
w h n
x1 y1 a1
...
xn yn an
 */

int w,h,n;

int main(){
  cin >>w>>h>>n;
  int lx=0, rx=w, by=0, ty=h;
  REP(i,n){
    int x,y,a;
    cin >>x>>y>>a;
    switch(a){
    case 1:
      lx = max(lx, x);
      break;
    case 2:
      rx = min(rx,x);
      break;
    case 3:
      by = max(by,y);
      break;
    case 4:
      ty = min(ty, y);
      break;
    }
  }

  cout << max(rx-lx,0)*max(0,ty-by) << endl;

  return 0;
}


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

using namespace std;

struct Persimmon {
	int x;
	int y;

	void plant(int _x, int _y) {
		x = _x;
		y = _y;
	}

	bool _inRange(int val, int s, int e) {
		if (val < s) {
			return false;
		}
		if (e < val) {
			return false;
		}
		return true;
	}

	bool inRange(int start_x, int end_x, int start_y, int end_y) {
		return _inRange(x, start_x, end_x) and _inRange(y, start_y, end_y);
	}
};

vector<Persimmon> plantPersimmon(int num) {
	vector<Persimmon> place(num);
	for(int i = 0; i < num; i++) {
		int x, y;
		cin >> x >> y;
		Persimmon tmp;
		tmp.plant(x, y);
		place[i] = tmp;
	}
	return place;
}

int countUp(int w, int h, int ew, int eh, vector<Persimmon>& pers) {
	int count = 0;
	for(auto p : pers) {
		if(p.inRange(w, w + ew - 1, h, h + eh - 1)) {
			count++;
		}
	}
	return count;
}

int Search(int num, int fw, int fh, int ew, int eh, vector<Persimmon>& pers) {
	int max = 0;

	for(int w = 1; w <= fw - ew + 1; w++) {
		for(int h = 1; h <= fh - eh + 1; h++) {
			int count = countUp(w, h, ew, eh, pers);
			if(count > max) {
				max = count;
			}
		}
	}

	return max;
}


int main(void) {
	int num;

	while(1) {
		cin >> num;
		if(num == 0) {
			break;
		}

		int f_width, f_heigh;
		cin >> f_width >> f_heigh;

		vector<Persimmon> persimmon = plantPersimmon(num);

		int e_width, e_heigh;
		cin >> e_width >> e_heigh;

		int max_num = Search(num, f_width, f_heigh, e_width, e_heigh, persimmon);

		cout << max_num << endl;
	}
	return 0;
}

Measured memory_bytes: 2996
N, M, K = map(int, input().split())

for n in range(N + 1):
    if (N - 2 * n) == 0:
        continue
    if (K - n * M) % (N - 2 * n) == 0:
        if 0 <= (K - n * M) // (N - 2 * n) <= M:
            print ('Yes')
            exit()

print ('No')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ls  (n<<1)
#define rs  (ls|1)
using namespace std;

typedef long long  LL;
const int N=100010;
const LL oo=1LL<<60;
int n,k,m,c[2*N],l[N],r[N],s;
LL t[4*N],sum;

void build(int n,int l,int r)
{
	if (l==r)  t[n]=-c[l];
	else
		{
			int mid=(l+r)>>1;
			build(ls,l,mid),build(rs,mid+1,r);
			t[n]=min(t[ls],t[rs]);
		}
}

LL askmin(int n,int l,int r,int L,int R)
{
	if (t[n]==oo)  return oo;
	LL ret;
	if ((L<=l)&&(r<=R))  ret=t[n],t[n]=oo;
	else
		{
			int mid=(l+r)>>1;
			if (mid>=R)  ret=askmin(ls,l,mid,L,R);
			else  if (L>mid)  ret=askmin(rs,mid+1,r,L,R);
			else  ret=min(askmin(ls,l,mid,L,R),askmin(rs,mid+1,r,L,R));
			t[n]=min(t[ls],t[rs]);
		}
	return ret;
}

void modify(int n,int l,int r,int x,LL k)
{
	if (l==r)  t[n]=min(t[n],k-c[l]);
	else
		{
			int mid=(l+r)>>1;
			if (t[n]==oo)  t[ls]=t[rs]=oo;
			x<=mid?modify(ls,l,mid,x,k):modify(rs,mid+1,r,x,k);
			t[n]=min(t[ls],t[rs]);
		}
}

LL getans(int n,int l,int r)
{
	if (t[n]==oo)  return oo;
	if (l==r)  return t[n]+c[l];
	else
		{
			int mid=(l+r)>>1;
			return min(getans(ls,l,mid),getans(rs,mid+1,r));
		}
}

void work()
{
	scanf("%d %d",&n,&k);
	for (int i=1,a,b; i<=n; i++)
		{
			scanf("%d %d",&a,&b),sum+=2*a;
			if ((b==1)&&(2*a>k))  puts("-1"),exit(0);
			if (b==1)  l[i]=(s+2LL*(k-a%k))%k,r[i]=s;  else  l[i]=k-1;
			s=(s+2LL*(k-a%k))%k;
		}
	for (int i=1; i<=n; i++)  c[i]=l[i],c[i+n]=r[i];
	sort(c+1,c+2*n+1),m=unique(c+1,c+2*n+1)-c-1;
	for (int i=1; i<=n; i++)
		{
			l[i]=lower_bound(c+1,c+m+1,l[i])-c;
			r[i]=lower_bound(c+1,c+m+1,r[i])-c;
		}
	build(1,1,m);
	for (int i=1; i<=n; i++)
		if (l[i]<r[i])
			{
				if (r[i]-l[i]>1)
					modify(1,1,m,r[i],askmin(1,1,m,l[i]+1,r[i]-1)+c[r[i]]);
			}else
			{
				if (l[i]<m)  modify(1,1,m,r[i],askmin(1,1,m,l[i]+1,m)+k+c[r[i]]);
				if (r[i]>1)  modify(1,1,m,r[i],askmin(1,1,m,1,r[i]-1)+c[r[i]]);
			}
	printf("%lld",sum+getans(1,1,m));
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>

using namespace std;

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

    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = 0; ; k++) {
                if (((i ^ j) & (1 << k)) > 0) {
                    cout << (j == i + 1 ? "" : " ") << k + 1;
                    break;
                }
            }
        }
        cout << endl;
    }
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

struct Edge {
	int to,dist,danger;
	Edge(int to,int dist,int danger):to(to),dist(dist),danger(danger) {}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while(true) {
		int hotel,road,money,d[100][110];
		vector<Edge> G[100];
		cin>>hotel>>road>>money;
		if(hotel==0) break;
		REP(i,road) {
			int u,v,dist,danger;
			cin>>u>>v>>dist>>danger;
			u--,v--;
			G[u].pb(Edge(v,dist,danger));
			G[v].pb(Edge(u,dist,danger));
		}
		REP(i,100) REP(j,110) d[i][j]=INF;
		priority_queue<PP,vector<PP>,greater<PP> > pq;
		pq.push(PP(0,P(0,money)));
		d[0][money]=0;
		while(!pq.empty()) {
			PP p=pq.top();pq.pop();
			int v=p.fi,danger_sum=p.se.fi,rest=p.se.se;
			if(d[v][rest]<danger_sum) continue;
			for(auto e:G[v]) {
				if(d[e.to][rest]>danger_sum+e.danger) {
					d[e.to][rest]=danger_sum+e.danger;
					pq.push(PP(e.to,P(d[e.to][rest],rest)));
				}
				if(rest-e.dist<0) continue;
				if(d[e.to][rest-e.dist]>danger_sum) {
					d[e.to][rest-e.dist]=danger_sum;
					pq.push(PP(e.to,P(d[e.to][rest-e.dist],rest-e.dist)));
				}
			}
		}
		int ans=INF;
		REP(i,110) ans=min(ans,d[hotel-1][i]);
		cout<<ans<<endl;
	}

	return 0;
}



Measured memory_bytes: 3844
#include<iostream>
#include<vector>
#include<string.h>

using namespace std;
int x[100010], y[100010];
vector<int> adjacent[100010];
void DFSx(int a) {
  for (int b : adjacent[a]) {
    if (x[b] == -1) {
      x[b] = x[a] + 1;
      DFSx(b);
    }
  }
}
void DFSy(int a) {
  for (int b : adjacent[a]) {
    if (y[b] == -1) {
      y[b] = y[a] + 1;
      DFSy(b);
    }
  }
}

int main() {
  memset(x, -1, sizeof(x));
  memset(y, -1, sizeof(y));
  int n;
  cin >> n;
  int i;
  for (i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    adjacent[a].push_back(b);
    adjacent[b].push_back(a);
  }
  x[0] = 0;
  y[n-1] = 0;
  DFSx(0);
  DFSy(n-1);
  int X = 0, Y = 0;
  for (i = 0; i < n; i++) {
    if (x[i] <= y[i]) {
      X++;
    } else {
      Y++;
    }
  }
  if (X <= Y) {
    cout << "Snuke" << endl;
  } else {
    cout << "Fennec" << endl;
  }
}
  
  


Measured memory_bytes: 9600
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)
#define int long long
//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;

//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int N,K,S;

  cin >> N >> K >> S;

  if(S == 1){
  	for(int i = 0 ; i < K ; i++){
  		cout << 1 << " ";
  	}
  	for(int i = K ; i < N ; i++){
  		cout << S+1 << " ";
  	}
  	cout << endl;
  	return 0;
  }

  if(N == K){
  	for(int i = 0 ; i < N ; i++){
  		cout << S << " ";
  	}
  	cout << endl;
  	return 0;
  }
  else{
  	int first = S / 2;
  	int second = S - first;
  	int pair = -1;
  	for(; pair < K ; pair++){
  		if(pair % 2 != 0){
  			cout << first << " ";
  		}
  		else{
  			cout << second << " ";
  		}
  	}

  	for(int i = (pair + 1); i < N ; i++){
  		if(S != 1000000000){
	  		cout << S + 1 << " ";
  		}
  		else{
  			cout << S - 1 << " ";
  		}
  	}
  	cout << endl;
  	return 0;
  }


  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

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

int main(){
    int N, K, i;
    cin >> N >> K;
    int num = 1;
    for(i = 0; i < N; i++){
        if(num * 2 > num + K){
            num = num + K;
        }
        else num = num * 2;
    }
    cout << num << endl;
}

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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> cnt(n,0);
    for (int i = 0;i < m;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        cnt[u]++;
        cnt[v]++;
    }
    for (int i = 0;i < n;++i) if (cnt[i]%2) {
        cout << "NO" << endl;
        exit(0);
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
    long long A, B, K;
    scanf("%lld%lld%lld", &A, &B, &K);
    if (K<=A) printf("%lld %lld", A-K, B);
    else if (K<=A+B) printf("%lld %lld", 0, A+B-K);
    else printf("%lld %lld", 0, 0);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdlib>

using namespace std;

int top, S[1000];

void push(int x){
	top++;
	S[top] = x;
}

int pop() {
	top--;
	return S[top + 1];
}

int main() {
	int a, b;
	top = 0;
	char s[100];
	while (cin>>s) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			a = pop();
			b = pop();
			push(b - a);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a*b);
		}
		else {
			push(atoi(s));
		}
		//cout << S[top] << endl;
	}
	cout << pop() << endl;

	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

long long N, A[100009], B[100009], cl = 0, cr, ans = 0;
vector<tuple<long long, long long, long long>>tup;

int main() {
	cin >> N; cr = N - 1;
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		tup.push_back(make_tuple(A[i] + B[i], A[i], B[i]));
	}
	sort(tup.begin(), tup.end());
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) { ans += get<1>(tup[cr]); cr--; }
		if (i % 2 == 1) { ans -= get<2>(tup[cr]); cr--; }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5876
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
  int x, i, j, t;
  x = A[r];
  i = p - 1;
  for(j = p ; j < r ; j++){
    if(A[j] <= x){
      i++;
      t =  A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }

  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;
  return i+1;
}

int main(){
  int i,q;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }

  q = partition(0,n-1);

  for(i = 0 ; i < n ; i++){
    if(i) printf(" ");
    if(i == q) printf("[");
    printf("%d",A[i]);
    if(i == q) printf("]");
  }

  printf("\n");

  return 0;
}




Measured memory_bytes: 2092
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int ans = 0;
        for(char c : s){
            if(c == '+'){
                ans++;
            }else{
                ans--;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int ans = 0;
    string s; cin >> s;
    for (int i = 0; i < (s.size() + 1) / 2; ++i) {
        if (s[i] != s[s.size() - 1 - i]) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            var min = int.MaxValue;
            for (int i = 0; i < str.Length - 2; i++)
            {
                var num = int.Parse(str.Substring(i, 3));

                var diff = Math.Abs(753 - num);
                if (diff < min)
                {
                    min = diff;
                }
            }
            Console.WriteLine(min);
        }
    }
}


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

int main()
{
  int N;cin>>N;
  int answer[N]; int i; int sum1=0; int sum2=0;
  for(i=0;i<N;i++){cin>>answer[i];sum1+=answer[i];}
  int diff = sum1;
  for(i=0;i<N;i++)
  {
    sum2+=answer[i];
    if(abs(sum1-2*sum2)<diff){diff=abs(sum1-2*sum2);}
    else{break;}
  }
  cout<<diff<<endl;
 return 0; 
}

Measured memory_bytes: 256
import java.io.*
import java.lang.*


fun solve() {
    val N = rd.readInt()
    val A = LongArray(N)
    for (i in 0 until N) {
        A[i] = rd.readLong()
    }

    var cnt = 0L
    var sum = 0L
    for (i in 0 until N) {
        if (A[i] == 0L) {
            cnt += sum/2L
            sum = 0L
        } else {
            sum += A[i]
        }
    }
    cnt += sum/2L

    val ans = cnt
    println(ans)
}


//val rd = debug.Reader("agc", "003", "b", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 46528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _172B
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] S = Console.ReadLine()?.ToCharArray();
            char[] T = Console.ReadLine()?.ToCharArray();

            long num = 0;

            for(var i = 0; i < S.Length; i++)
            {
                if (S[i] == T[i])
                {
                    ;
                }
                else
                {
                    S[i] = T[i];
                    num++;
                }
            }
            Console.WriteLine(num);
        }
    }
}


Measured memory_bytes: 28164
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  map<int, int> mp;
  map<int, int> correctMp;
  cin >> n >> m;
  rep (i, n) {
    mp[i] = 0;
    correctMp[i] = 0;
  }
  int progN;
  string ans;
  int correct = 0;
  int miss = 0;
  rep (i, m) {
    cin >> progN;
    cin >> ans;
    if (ans == "AC") {
      if (correctMp[progN] == 0) {
        correct++;
        miss += mp[progN];
        correctMp[progN] = 1;
      }
    } else {
      mp[progN]++;
    }
  }
  cout << correct << " " << miss << endl;
  return 0;
}

Measured memory_bytes: 9600
import Control.Monad

main = do
    n <- readLn
    ls <- replicateM n getLine
    mapM_ putStrLn (solve ls)

solve :: [String] -> [String]
solve = map(solve_ . map (\x -> read x :: Int) . words)

solve_ :: [Int] -> String
solve_ x =
    let m1 = (maximum x) ^2 *2; m2 = sum $ map (^2) x
    in if (m1 == m2) then "YES" else "NO"

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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+123;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define MP make_pair
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll n;
    cin>>n;
    if(n<11){cout<<"Yes" el; return;}
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0 and n/i<10){
            cout<<"Yes" el;
            return;
        }
    }
    cout<<"No" el;
}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;

int vis[maxn];

int main(){
	memset(vis,0,sizeof(vis));
	int n;
	scanf("%d",&n);
	for(int i = 2;i <= n;i++){
		int x;
		scanf("%d",&x);
		vis[x]++;
	}
	for(int i = 1;i <= n;i++){
		printf("%d\n",vis[i]);
	}
	return 0;
}

Measured memory_bytes: 4620
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        long h = Long.valueOf(arr01[0]);

        if (h == 1) {
            System.out.println(1);
        } else {

            long cnt = 0;

            long temp = 1;

            long mysum = 0;

            while (h / 2 >= 2) {

                h = h / 2;
                cnt += 1;

                mysum += temp;

                temp *= 2;

            }

            double ans = mysum + Math.pow(2, cnt) * 3;

            //            System.out.println(ans);
            System.out.println((long) ans);
        }

    }
}


Measured memory_bytes: 21076
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <utility>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int W, H, N; cin >> W >> H >> N;
  int b[110][110];
  for (int i = 0; i < 110; i++) {
    for (int j = 0; j < 110; j++)
      b[i][j] = 0;
  }
  for (int i = 0; i < N; i++) {
    int x, y, a; cin >> x >> y >> a;
    if (a == 1) {
      for (int j = 0; j <= H; j++) {
        for (int i = 0; i <= x; i++)
          b[j][i] = 1;
      }
    } else if (a == 2) {
      for (int j = 0; j <= H; j++) {
        for (int i = x+1; i <= W; i++)
          b[j][i] = 1;
      }
    } else if (a == 3) {
      for (int j = 0; j <= y; j++) {
        for (int i = 0; i <= W; i++)
          b[j][i] = 1;
      }
    } else {
      for (int j = y+1; j <= H; j++) {
        for (int i = 0; i <= W; i++)
          b[j][i] = 1;
      }
    }
  }
  int ans = 0;
  for (int j = 1; j <= H; j++) {
    for (int i = 1; i <= W; i++)
      ans += (b[j][i] == 0);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    
    int N;
    cin >> N;
    
    int C0 = 0;
    int C1 = 0;
    int C2 = 0;
    int C3 = 0;
    
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        if(S == "AC"){
            C0++;
        }
        if(S == "WA"){
            C1++;
        }
        if(S == "TLE"){
            C2++;
        }
        if(S == "RE"){
            C3++;
        }
    }
     cout << "AC x " << C0 << endl;
     cout << "WA x " << C1 << endl;
     cout << "TLE x " << C2 << endl;
     cout << "RE x " << C3 << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a, T b){return (a < b ? a = b, true : false);}
template<typename T>inline bool chmin(T &a, T b){return (a > b ? a = b, true : false);}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const long double EPS = 1e-9;

int main() {
	string s1, s2;
	cin >> s1 >> s2;
	if (s1.size() > s2.size()) {
		cout << "GREATER" << endl;
	} else if (s1.size() < s2.size()) {
		cout << "LESS" << endl;
	} else {
		REP(i, s1.size()) {
			if (s1[i] < s2[i]) {
				cout << "LESS" << endl;
				return 0;
			} else if (s1[i] > s2[i]) {
				cout << "GREATER" << endl;
				return 0;
			}
		}
		cout << "EQUAL" << endl;
	}
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a,b;
    cin>>a>>b;
    if(a=='H'){
        cout<<b<<"\n";
    }
    else{
        if(b=='H')b='D';
        else b='H';
        cout<<b<<"\n";
    }
}


Measured memory_bytes: 3576
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;

	vector<int> T(N);
	int sum = 0;
	REP(i,N){ 
		cin >> T[i];
		sum += T[i];
	}

	int M; cin >> M;
	vector<int> ans(M,0);
	REP(i,M){
		int P, X; cin >> P >> X;
		ans[i] = sum - T[P-1];
		ans[i] += X;
	}


	REP(i,M) cout << ans[i] << endl;


	return 0;

}


Measured memory_bytes: 256
import scala.collection.mutable.Queue


object Main {
  def process(queue: Queue[(String, Int)], quantum: Int, elapse: Int = 0): Unit = {
    if (queue.length == 0) {
      return ()
    }

    val (name, last) = queue.dequeue
    val last2 = last - quantum
    if (last2 > 0) {
      queue += (name -> last2)
      process(queue, quantum, elapse + quantum)
    } else {
      println(s"$name ${elapse + last}")
      process(queue, quantum, elapse + last)
    }
  }

  def main(args: Array[String]) = {
    val Array(n, qua) = io.StdIn.readLine.split(" ").map(_.toInt)
    // println(n, qua)
    val queue = new Queue[(String, Int)]
    1 to n foreach { _ =>
      val Array(name, time) = io.StdIn.readLine.split(" ")
      queue += (name -> time.toInt)
    }
    // queue.foreach(println _)

    process(queue, qua)
  }
}



Measured memory_bytes: 132744
#include<stdio.h>

int main(){

   int S;         // input, [s]
   int h, m, s;   // output, [hour, min, sec]

   scanf("%d", &S);
   
   h = S/3600;
   S = S%3600;
   m = S/60;
   s = S%60;

   printf("%d:%d:%d\n", h, m, s);
   return 0;

}

Measured memory_bytes: 592
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

// a>=0, b>=0, x*a+y*b=gcd>=0, a>0,b>0=>abs(y)<=a,abs(x)<=b
LL gcdex(LL a,LL b,LL& x, LL& y){
	LL ax=1,ay=0;
	LL bx=0,by=1;
	while(b){
		LL r=a/b;
		LL t=a-r*b; a=b; b=t;
		LL tx=ax-r*bx; ax=bx; bx=tx;
		LL ty=ay-r*by; ay=by; by=ty;
	}
	x=ax;
	y=ay;
	return a;
}
template<class T> T powmod(T p,T n,T mod){
	T q=p%mod;
	T pow=1;
	while(n){
		if(n&1){
			pow*=q;
			pow%=mod;
		}
		q=q*q;
		q%=mod;
		n/=2;
	}
	return pow;
}

LL F[3*100*1000+1];
#if 0
LL Comb(int i,int j,LL p){
	if(i<j){
		return 0;
	}
	LL ret=F[i];
	LL x,y;
	gcdex(F[j],p,x,y);
	ret*=x;
	ret%=p;
	if(ret<0){
		ret+=p;
	}
	gcdex(F[i-j],p,x,y);
	ret*=x;
	ret%=p;
	if(ret<0){
		ret+=p;
	}
	return ret;
}
#else
LL Comb(int i,int j,LL p){
	if(i<j){
		return 0;
	}
	LL ret=F[i];
	ret*=powmod(F[j],p-2,p);
	ret%=p;
	ret*=powmod(F[i-j],p-2,p);
	ret%=p;
	return ret;
}
#endif
const LL M=998244353;
int main() {
	LL N,A,B,K;
	cin >> N >> A >> B >> K;
	LL ret=0;
	F[0]=1;
	for(LL i=1;i<=N;i++){
		F[i]=i*F[i-1]%M;
	}
	for(LL i=0;i<=N;i++){
		LL r=K-A*i;
		if(r>=0&&r%B==0){
			LL j=r/B;
			if(i<=N&&j<=N){
				ret+=Comb(N,i,M)*Comb(N,j,M)%M;
				ret%=M;
			}
		}
	}
	cout << ret << endl;


	return 0;
}



Measured memory_bytes: 2560
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#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 FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

const LL MOD = 998244353;

char str[2005];
LL dp[4005][4005];

int main() {
	int b = 0, r = 0;
	cin >> str;
	int n = strlen(str);
	dp[0][0] = 1;
	REP(i, 2 * n) {
		if (i < n) {
			b += '2' - str[i];
			r = 2 * (i + 1) - b;
		}
		REP(j, i + 1) {
			// B
			if (b > j) {
				dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD;

			}
			// R
			if (r - (i - j)>0) {
				dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
			}
		}
	}
	cout << dp[2 * n][b] << endl;
	return 0;
}


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

int F[102][102];
int xg,yg,ok;

void Maze(int X,int Y,int C){
	//cout << X<<Y<<F[X][Y]<<endl;
	if(F[X][Y]!=C)
		return;

	

	if(X==xg&&Y==yg){
		cout << "OK"<<endl;
		ok++;
	}

	F[X][Y]='.';

	Maze(X-1,Y  ,C);
	Maze(X  ,Y+1,C);
	Maze(X+1,Y  ,C);
	Maze(X  ,Y-1,C);
	
}



int main(){	
	while(1){
		ok=0;
		for(int i=1; i<=100; i++)
			for(int j=1; j<=100; j++)
				F[j][i]=0;


		for(int i=0; i<102;i++){
			F[0][i]=6;
			F[i][0]=6;
		}


		int w,h,xs,ys,n,c,d,x,y;

		cin >>w>>h;
		if(w==0&&h==0)
			return 0;

		cin >>xs>>ys;
		cin >>xg>>yg;
		cin >>n;



		for(int i=0; i<=w;i++)
				F[w+1][i]=6;

		for(int i=0; i<=h;i++)
				F[i][h+1]=6;


		int N=0;
		while(N<n){
//cout <<N;
			cin >>c>>d>>x>>y;
//cout<<c<<d<<x<<y<<endl;
			if(d){
				for(int i=x; i<x+2; i++)
					for(int j=y; j<y+4; j++){
						F[i][j]=c;
//cout <<F[i][j];
				}
//cout <<endl;
			}else{
				for(int i=x; i<x+4; i++)
					for(int j=y; j<y+2; j++){
						F[i][j]=c;
//cout <<F[i][j];
					}
//cout <<endl;
			}
			N++;
		}

//for(int i=0; i<=101; i++){
	//for(int j=0; j<=101; j++){
		//cout <<F[j][i];
		//}
	//cout << endl;
//}
		
		Maze(xs,ys,F[xs][ys]);

		if(ok==0)
			cout <<"NG"<<endl;

	}

}

Measured memory_bytes: 1220
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 LN             PIC X(60).
01 N              PIC 9(19).
01 A              PIC 9(19).
01 B              PIC 9(19).
01 dv             PIC 9(19).
01 rm             PIC 9(19).
01 ans            PIC 9(19).
01 ZS             PIC Z(18)9.

PROCEDURE DIVISION.
  ACCEPT LN.
  UNSTRING LN DELIMITED BY SPACE INTO N A B.
  COMPUTE dv = N / (A + B).
  COMPUTE rm = N - dv * (A + B).
  IF A < rm
      COMPUTE ans = A * dv + A
  ELSE
      COMPUTE ans = A * dv + rm
  END-IF.
  MOVE ans TO ZS.
  DISPLAY ZS.
  STOP RUN.


Measured memory_bytes: 384
# 基本的に重複がない
# n+1Ck − (n+1)-(r-l+1)Ck−1

MOD = 10**9+7
U = 10**5 + 1

def power_mod(a,n):
  if n == 0:
    return 1
  x = (power_mod(a,n//2)**2)%MOD
  return x if n%2 == 0 else (a*x)%MOD

def make_fact(fact,fact_inv):
  for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
  fact_inv[U] = power_mod(fact[U],MOD-2)
  for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD

def comb(n,k):
  if k < 0 or k > n:
    return 0
  x = fact[n]
  x *= fact_inv[k]
  x %= MOD
  x *= fact_inv[n-k]
  x %= MOD
  return x

fact = [1]*(U+1)
fact_inv = [1]*(U+1)
make_fact(fact,fact_inv)

# 重複の起きる場所の間隔だけが問題
n = int(input())
A = [int(x) for x in input().split()]

memo = dict()
d = 0
for i,x in enumerate(A):
  if x in memo:
    d = i - memo[x]
    break
  memo[x] = i

rest = n-d

for k in range(1,n+2):
  ans = comb(n+1,k) - comb(rest,k-1)
  ans %= MOD
  print(ans)


Measured memory_bytes: 64816
using System;

class Program
{
    static void Main(string[] args)
    {
        var abcd = Console.ReadLine().Split(' ');
        var a = int.Parse(abcd[0]);
        var b = int.Parse(abcd[1]);
        var c = int.Parse(abcd[2]);
        var d = int.Parse(abcd[3]);

        if (Math.Abs(a - c) <= d)
        {
            Console.WriteLine("Yes");
        }
        else if (Math.Abs(a - b) <= d &&
             Math.Abs(b - c) <= d)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
#include <cstdio>
#include <cstring>
using std::size_t;

struct Node
{
   int key;
   Node *prev, *next;
   Node(): Node(0) {}
   Node(int k): key(k), prev(nullptr), next(nullptr) {}
};
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
class List
{
private:
   Node *nil;

public:
   List(): nil(new Node) {
      nil->prev = nil->next = nil;
   }

   const Node* const begin()const { return(nil -> next); }
   const Node* const end()  const { return(nil); }

   const Node* const search(int k) const;
   void push_front(int k);
   void erase(const Node* const u);
   void erase_key(int k);
};
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
void List::push_front(int k)
{
   Node *u = new Node(k);
   nil->next->prev   = u;
   u->next           = nil->next;
   nil->next         = u;
   u->prev           = nil;
}

const Node* const List::search(int k) const
{
   Node *i = nil -> next;
   while(i != nil && i->key != k)
      i = i->next;
   return(i);
}

void List::erase(const Node* const u)
{
   if( u == nil )return;
   u->next->prev = u->prev;
   u->prev->next = u->next;
   delete u;
}

void List::erase_key(int k)
{
   erase( search(k) );
}
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


static List ls;

int main()
{
   int N;
   char s[32];
   scanf("%d", &N);

   while(N--){
      scanf("%s", s);
      if(strlen(s) == 6){
         int n; scanf("%d", &n);
         if(*s == 'd')
            ls.erase_key(n);
         else
            ls.push_front(n);
      }
      else {
         if(s[6] == 'F')
            ls.erase( ls.begin() );
         else
            ls.erase( ls.end() -> prev );
      }
   }

   bool nf = false;
   for(auto i = ls.begin(); i != ls.end(); i = i->next){
      if(nf)printf(" ");
      else nf = true;
      printf("%d", i -> key);
   }
   printf("\n");
}




Measured memory_bytes: 33940
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    ll k;
    cin >> n >> k;
    vi a(n);
    cin >> a;
    rep(i,n) a[i]--;
    int cnt = 0;
    vi seen(n,-1);
    seen[0] = 0;
    int now = 0;
    int st,time,ro;
    while(true) {
        cnt++;
        now = a[now];
        if(seen[now] != -1) {
            st = now;
            time = seen[now];
            ro = cnt-seen[now];
            break;
        } else {
            seen[now] = cnt;
        }
    }
    if(k < time) {
        now = 0;
        rep(_,k) now = a[now];
        cout << now+1 << endl;
        return 0;
    }
    k -= time;
    k %= ro;
    now = st;
    rep(_,k) now = a[now];
    cout << now+1 << endl;
}


Measured memory_bytes: 4784
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
	int n,x,mns;
	cin>>n>>x;
	int m[109];
	for(int a=0;a<n;a++)
	{
		cin>>m[a];
	}
	int sum=0;
	for(int i=0;i<n;i++)
	{
		sum=sum+m[i];
	}
	if(x==sum)
		cout<<n;
	if(x!=sum)
	{
		mns=x-sum;
		int sml=1001;
		for(int j=0;j<n;j++)
		{
			sml=min(sml,m[j]);
		}
	n=n+mns/sml;
	cout<<n;
	}
	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
q = int(input())
abcd = [[int(i) for i in input().split()] for _ in range(q)]

sdp = [(0, 0)]
tdp = [(0, 0)]
for s in S :
    a, b = sdp[-1]
    if s == 'A' :
        sdp.append((a + 1, b))
    else :
        sdp.append((a, b + 1))
for t in T :
    a, b = tdp[-1]
    if t == 'A' :
        tdp.append((a + 1, b))
    else :
        tdp.append((a, b + 1))

for a, b, c, d in abcd :
    sa = sdp[b][0] - sdp[a-1][0]
    sb = sdp[b][1] - sdp[a-1][1]
    ta = tdp[d][0] - tdp[c-1][0]
    tb = tdp[d][1] - tdp[c-1][1]
    
    tb -= ta - sa
    if abs(sb - tb) % 3 == 0 :
        print('YES')
    else :
        print('NO')

Measured memory_bytes: 78808
N, M = map(int, raw_input().split())
ans = 0
list = [map(int , raw_input().split()) for n in range(N)]
list = sorted(list, key = lambda list: list[0])
cnt = 0
for n in range(N):
    A, B = list[n]
    for b in range(B):
        ans += A
        cnt += 1
        if cnt == M:
            print(ans)
            exit()


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    int n;
    cin>>n;

    //b棟f階のr番目の部屋にv人が追加で入居したことを示します。
    //vが負の値の場合、-v人退去したことを示します。
    //vector<vector<vi>> bld;
    int bld[4+1][3+1][10+1]={};
    REP(i,n){
        int b,f,r,v;
        cin>>b>>f>>r>>v;
        bld[b-1][f-1][r-1]+=v;
    }
    //１フロア１０部屋、３階建ての公舎４棟
    REP(i,4){
        REP(j,3){
            REP(k,10){
                cout<<" ";
                cout<<bld[i][j][k];
            }
            cout<<endl;
        }
        if(i<3) cout<<"####################"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3124
import heapq
from collections import deque
import sys
input = sys.stdin.readline
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.sort()
q.sort()
r.sort(reverse=True)
red_que = p[a-x:]
heapq.heapify(red_que)
green_que = q[b-y:]
heapq.heapify(green_que)
for i in range(c):
    re_mi = heapq.heappop(red_que)
    gr_mi = heapq.heappop(green_que)
    if re_mi < gr_mi:
        if re_mi < r[i]:
            heapq.heappush(red_que,r[i])
            heapq.heappush(green_que,gr_mi)
        else:
            heapq.heappush(green_que,gr_mi)
            heapq.heappush(red_que,re_mi)
            break
    else:
        if gr_mi < r[i]:
            heapq.heappush(red_que,re_mi)
            heapq.heappush(green_que,r[i])
        else:
            heapq.heappush(green_que,gr_mi)
            heapq.heappush(red_que,re_mi)
            break
print(sum(green_que) + sum(red_que))

Measured memory_bytes: 110288