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

using namespace std;

typedef long long ll;

ll comb[100][100];

int main(){
    int N, P;
    cin >> N >> P;
    vector<int> A(N);
    int odd_cnt = 0;
    int even_cnt = 0;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 2 == 0){
            even_cnt++;
        }
        else{
            odd_cnt++;
        }
    }
    
    // 二項係数テーブルの作成
    comb[0][0] = 1;
    for(int i = 1; i <= N; ++i){
        comb[i][0] = 1;
        comb[i][i] = 1;
    }
    for(int i = 2; i <= N; ++i){
        for(int j = 1; j < i; ++j){
            comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
        }
    }
    
    ll cnt = 1;
    // 和が奇数の場合、(奇数を奇数個取ってくる場合の数 * 偶数の取り方のすべて)
    if(P == 1){         
        if(odd_cnt == 0){
            cout << 0 << endl;
            return 0;
        }
        
        // 奇数の場合の数
        ll temp = 0;
        for(int i = 1; i <= odd_cnt; i += 2){
            temp += comb[odd_cnt][i];
        }
        cnt *= temp;
        
        // 偶数の場合の数
        temp = 1;
        for(int i = 0; i < even_cnt; ++i){
            temp *= 2;
        }
        cnt *= temp;
    }
    
    // 和が偶数の場合、(奇数を偶数個取ってくる場合の数 * 偶数の取り方のすべて)
    else{
        ll temp = 0;
        for(int i = 0; i <= odd_cnt; i += 2){
            temp += comb[odd_cnt][i];
        }
        cnt *= temp;
        
        temp = 1;
        for(int i = 0; i < even_cnt; ++i){
            temp *= 2;
        }
        cnt *= temp;
    }
    
    cout << cnt << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  string S,T;
  cin>>S>>T;
  int N=S.size();
  int M=T.size();
  int res=M;
  rep(i,N-M+1){
    int cnt=0;
    rep(j,M){
      if(S[i+j]!=T[j])cnt++;
    }
    minch(res,cnt);
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;++i)
int main(){
  ll H,W;
  cin>>H>>W;
  ll s1,s2,s3;
  ll smax,smin,ans=1e10;
  //横2本線
  rep(h1,1,H-1){
    s1=h1*W;
    ll h2=(H-h1)/2;
    ll h3=H-h1-h2;
    s2=h2*W;
    s3=h3*W;
    smax=max(s1,s3);
    smin=min(s1,s2);
    ans=min(ans,smax-smin);
  }
  //横→縦
  rep(h1,1,H){
    s1=h1*W;
    ll w2=W/2;
    ll w3=W-w2;
    s2=(H-h1)*w2;
    s3=(H-h1)*w3;
    smax=max(s1,s3);
    smin=min(s1,s2);
    ans=min(ans,smax-smin);
  }
  //縦2本
  rep(w1,1,W-1){
    s1=w1*H;
    ll w2=(W-w1)/2;
    ll w3=W-w1-w2;
    s2=H*w2;
    s3=H*w3;
    smax=max(s1,s3);
    smin=min(s1,s2);
    ans=min(ans,smax-smin);
  }
  //縦→横
  rep(w1,1,W){
    s1=H*w1;
    ll h2=H/2;
    ll h3=H-h2;
    s2=h2*(W-w1);
    s3=h3*(W-w1);
    smax=max(s1,s3);
    smin=min(s1,s2);
    ans=min(ans,smax-smin);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {
  string n;
  cin >> n;
  char last_num = n.back();
  if (last_num == '3')
    cout << "bon" << endl;
  else if (last_num == '1' || last_num == '0' || last_num == '6' ||
           last_num == '8')
    cout << "pon" << endl;
  else
    cout << "hon" << endl;

  return 0;
}

Measured memory_bytes: 3128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

ll gcd(ll a,ll b){
      ll temp;
      while(b>0){
            temp=b;
            b=a%b;
            a=temp;
      }
      return a;
}

ll proinverse(ll x,ll m){
    ll res=1,M=m-2; 
    while(M>0){
        if(M&1) res=res*x%m;
        x=x*x%m;
        M>>=1;
    }
    return res;
}

int main() {
     ll a,b,n,ans=-INF; cin>>a>>b>>n;
     if(n<b){
     rep(i,min(50000000LL,n)){
           ans=max(ans,((a*((n-i)%b))-a*(n-i)%b)/b);
     }
     }
     else{
           rep(i,min(50000000LL,b)){
           ans=max(ans,((a*((b-i)%b))-a*(b-i)%b)/b);
     }
     }
     cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::string a, b, c; cin >> a >> b >> c;
	
	printf("%c%c%c\n", a[0], b[0], c[0]);
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
const int inf = 1 << 30;
const int mod = 998244353;
map<char,int>mp;
map<int,int>steam;
map<int,int>::iterator it;
const int maxn = 1e5;
/*
struct point{
	int x,cont;
	float c;
}num[maxn+5];

bool cmp(point a,point b){
	if(a.c == b.c) return a.cont > b.cont;
	return a.c > b.c;
}
*/
LL qwe (LL x,LL y){
	LL t = 1;
	while (y){
		if (y%2!=0)
			t = t * x % mod;
		y /= 2;
		x = x * x % mod;
	}
	return t;
}
LL jc(LL x){
	LL t = 1;
	for(int i = 1;i<=x;i++){
		t*=i;
		t % mod;
	}
	return t;
}
LL ans = 0;
vector<int>num[maxn+5];
int main(){
	string a;
	cin >> a;
	for(int i = 0;i<3;i++){
		mp[a[i]]++;
	}
	if(mp['a']&&mp['b']&&mp['c']) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main() {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    
    int n;
    cin>>n;
	int x=0;
	while(x<n)
	{
		x+= 1000;
	}
	cout<<x-n;
	return 0;
}

Measured memory_bytes: 3648
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int[][] c = new int[3][];

		for(int i=0;i<c.length;i++){
			c[i] = nextInts();
		}
		int[] a = new int[3];
		int[] b = new int[3];

		a[0]=0;
		b[0]=c[0][0];
		b[1]=c[0][1];
		b[2]=c[0][2];
		a[1]=c[1][0]-b[0];
		a[2]=c[2][0]-b[0];

		String ans = "Yes";
		int sum=0;
		for(int i=0;i<3;i++){
			for(int k=0;k<3;k++){
				if(c[i][k]!=a[i]+b[k]){
					ans="No";
					System.out.println(ans);
					return ;
				}
			}
		}
		System.out.println(ans);


	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

int main(){
    int n;cin>>n;
    bool flag=false;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(i*j==n) flag=true;
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main() {
  char s;
  cin >> s;
  
  // ここにプログラムを追記
  if (s == 'a' or s == 'e' or s == 'i' or s == 'o' or s == 'u') {
  	cout << "vowel" << endl;  
  } else {
  	cout << "consonant" << endl;  
  }

}


Measured memory_bytes: 3620
global cnt
cnt=0

def merge(A,left,mid,right):
    L=A[left:mid]
    R=A[mid:right]
    L.append(float("inf"))
    R.append(float("inf"))
    
    i=0
    j=0
    for k in range(left,right):
        global cnt
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i=i+1
        else:
            A[k]=R[j]
            j=j+1

def mergeSort(A,left,right):
    if left+1<right:
        mid=(int)((left+right)/2)
        mergeSort(A,left,mid)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)

n=int(input())
S=list(map(int,input().split()))

mergeSort(S,0,n)
print(*S)
print(cnt)


Measured memory_bytes: 63432
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 
int main() {
	int h,w;
	cin >> h >> w;
	vector<string> a(h+10);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
	vector<bool> x(h+10, false);
	vector<bool> y(w+10, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				x[i] = true;
				y[j] = true;
			}
		}
	}
 
	for (int i = 0; i < h; i++) {
		if (x[i]) {
			for (int j = 0; j < w; j++) {
				if (y[j]) 
					cout << a[i][j];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 256
#!/usr/bin/perl

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @aa = map { $_ - 0 } split(/\s+/,<STDIN>);

if( $n == 1 ){
  print "0\n"; exit(0);
}

my $s = 0;
my $p = $aa[0];
for(my $i=1;$i<$n;$i++){
  my $c = $aa[$i];
  if( $c < $p ){
    $s += $p - $c;
    $c = $p;
  }
  $p = $c;
}
print "$s\n";



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

bool filled[1005];
int main() {
  int a, b, N;
  cin >> a >> b >> N;
  for(int i=0; i<1005; i++) filled[i]=false;
  for(int i=0; i<N; i++){
    int s, f;
    cin >> s >> f;
    for(int j=s; j<f; j++) filled[j]=true;
  }
  int ans=0;
  for(int i=a; i<b; i++){
    if(filled[i]) ans=1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

void solve() {
    int n;
    int i, j;
    cin >> n;
    ll a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    string s;
    cin >> s;
    VI v(63, -1);
    for (i = n - 1; i >= 0; i--) {
        if (s[i] == '0') {
            for (j = 62; j >= 0; j--) {
                if ((a[i] >> j) & 1) {
                    if (v[j] == -1) {
                        v[j] = a[i];
                        break;
                    } else
                        a[i] ^= v[j];
                }
            }
        } else {
            for (j = 62; j >= 0; j--) {
                if ((a[i] >> j) & 1) {
                    if (v[j] != -1) a[i] ^= v[j];
                }
            }
            if (a[i] != 0) {
                cout << 1 << endl;
                return;
            }
        }
    }
    cout << 0 << endl;
}

int main() {
    int i, j;
    int t;
    cin >> t;
    while (t--) solve();
}

Measured memory_bytes: 3596
#include<stdio.h>
#define NIL -1
#define MAX 100000
struct Node{
  int parent;
  int left;
  int right;
};
struct Node gNode[MAX];
int gDepth[MAX];
void print(int);
void rec(int,int);
int main(){
  int i,j,n,nodeNum,nodeindex,left,root,node;
  scanf("%d",&n);
  for(i=0;i<n;++i){
    gNode[i].parent = gNode[i].left = gNode[i].right = NIL;
  }
  for(i=0;i<n;++i){
    scanf("%d %d",&nodeindex,&nodeNum);
    for(j=0;j<nodeNum;++j){
      scanf("%d",&node);
      if(j==0){
	gNode[nodeindex].left=node;
      }else{
	gNode[left].right = node;
      }
      left = node;
      gNode[node].parent = nodeindex;
    }
  }
  for(i=0;i<n;++i){
    if(gNode[i].parent == NIL){
      root = i;
    }
  }
  rec(root,0);
  for(i=0;i<n;++i){
    print(i);
  }
  return 0;
}

void print(int node){
  int i,left;
  printf("node %d:",node);
  printf(" parent = %d,",gNode[node].parent);
  printf(" depth = %d,",gDepth[node]);
  if(gNode[node].parent == NIL)printf(" root,");
  else if(gNode[node].left == NIL)printf(" leaf,");
  else printf(" internal node,");
  printf(" [");
  for(i=0,left=gNode[node].left;left!=NIL;++i,left = gNode[left].right){
    if(i)printf(", ");
    printf("%d",left);
  }
  printf("]\n");
}

void rec(int node,int parent){
  gDepth[node] = parent;
  if(gNode[node].right != NIL){
    rec(gNode[node].right , parent);
  }
  if(gNode[node].left != NIL){
    rec(gNode[node].left,parent+1);
  }
}



Measured memory_bytes: 6480
import sys
sys.setrecursionlimit(10**5)

def DFS(i,g):
    if i not in done:
        done.add(i)
        circle.add(i)
        g_list[i]=g
        for f in F[i]:
            DFS(f,g)
    else:
        return

N,M,K=map(int,input().split())
F=[[] for _ in range(N)]
B=[[] for _ in range(N)]

for f in range(M):
    f1,f2=map(int,input().split())
    F[f1-1].append(f2-1)
    F[f2-1].append(f1-1)
for b in range(K):
    b1,b2=map(int,input().split())
    B[b1-1].append(b2-1)
    B[b2-1].append(b1-1)

Group=[]
circle=set()
done=set()
g_list=[0 for _ in range(N)]
g=0
for i in range(N):
    if i not in done:
        DFS(i,g)
        Group.append(circle)
        circle=set()
        g+=1

ans=[-1 for _ in range(N)]
for i in range(N):
    G=g_list[i]
    ans[i]+=len(Group[G])
    for fr in F[i]:
        if fr in Group[G]:
            ans[i]-=1
    for bl in B[i]:
        if bl in Group[G]:
            ans[i]-=1

print(*ans)

Measured memory_bytes: 71644
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};


int main(){
  int N, D;
  cin >> N >> D;
  vector<vector<int>> a(N, vector<int>(D));
  rep(i,N){
    rep(j,D){
      cin >> a[i][j];
    }
  }
  int ans = 0;
  bool flag = false;
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      int r = 0;
      flag = false;
      rep(l,D){
	int diff = abs(a[i][l]-a[j][l]);
	r += diff * diff;
      }
      for(int k = 0; k <= r; k++){
	if(k*k == r) flag = true;
      }
      if(flag) ans++;
    }
  }
  cout << ans << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int calc(int type,int y,int init,double rate,int c){
	int i,b=0;
	if(type==0){
		for(i=0;i<y;i++){
			b+=init*rate;
			init-=c;
		}
		return init+b;
	}
	else{
		for(i=0;i<y;i++){
			b=init*rate;
			init=init+b-c;
		}
		return init;
	}
}
int main(void){
	int m,ans,init,y,n,t,c,tmp;
	double r;
	scanf("%d",&m);
	while(m--){
		ans=0;
		scanf("%d %d %d",&init,&y,&n);
		while(n--){
			scanf("%d %lf %d",&t,&r,&c);
			tmp=calc(t,y,init,r,c);
			if(ans<tmp)
				ans=tmp;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
const int mod = 1e9+7;

int A[200200], sum[200200];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin>>n;
    for (int i=1; i<=n; i++) cin>>A[i];
    for (int i=1; i<=n; i++) sum[i] = sum[i-1] + A[i];
    int res = 0;
    for (int i=1; i<n; i++) {
        res = ((sum[n] - sum[i])%mod*A[i]%mod + res)%mod;
    }
    cout << res;
    return 0;
}

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


long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

    long long n, X;
    cin >> n >> X;
    long long x[n + 1];
    x[0] = X;
    for (long long i = 1; i <= n; ++i) {
        cin >> x[i];
    }
    sort(x, x + n + 1);

    long long int g = 0;
    for (long long i = 1; i <= n; ++i) {
        if (i == 1) {
            g = x[i] - x[i - 1];
        } else {
            g = gcd(g, x[i] - x[i - 1]);
        }
    }

    cout << g << '\n';

    return 0;
}


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

int main()
{
    int N,X; cin>>N>>X;
    vector<int> L(N);
    for(int i=0; i<N; i++) cin>>L.at(i);

    int place = 0;
    int bounding = 1;
    for(int i=0; i<N; i++)
    {
        if((place += L.at(i)) <= X) bounding++;
    }

    cout << bounding;

    return 0;
}

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

#define REP(i,n) for(ll i = 0;i < n;++i)
#define PB(s) push_back(s)
#define ST(n) sort(n.begin(),n.end())

using namespace std;
typedef long long ll;

int main(){
  int N,A,B;
  
  cin >>N >> A >> B;
  
  cout << min(N*A,B)  << endl;
}



Measured memory_bytes: 256
local mmi, mma = math.min, math.max
local n = io.read("*n")
local a, b = {}, {}
local ta, tb = io.read("*n"), io.read("*n")
if tb < ta then ta, tb = tb, ta end
local a, b = {ta}, {tb}
local minv, minp, maxv, maxp = ta, 1, tb, 1
for i = 2, n do
  ta, tb= io.read("*n", "*n")
  if tb < ta then ta, tb = tb, ta end
  a[i], b[i] = ta, tb
  if ta < minv then
    minv = ta
    minp = i
  end
  if maxv < tb then
    maxv = tb
    maxp = i
  end
end
local ret = nil
if minv == maxv then
  -- (A) all same
  ret = 0
else
  -- (B) R has min, B has max value
  local redmax, bluemin = a[1], b[1]
  for i = 2, n do
    redmax = mma(redmax, a[i])
    bluemin = mmi(bluemin, b[i])
  end
  ret = (redmax - minv) * (maxv - bluemin)
end

-- (C) R has both of min and max values
do
  local t = {}
  for i = 1, n do t[i] = i end
  table.sort(t, function(x, y) return a[x] < a[y] end)
  local bmin = nil
  local bmax = nil
  local minlen = a[t[n]] - a[t[1]]
  for i = 1, n do
    if i == 1 then
      bmin, bmax = b[t[1]], b[t[1]]
    else
      bmin = mmi(bmin, b[t[i]])
      bmax = mma(bmax, b[t[i]])
    end
    local l = i == n and bmin or mmi(a[t[i + 1]], bmin)
    local r = i == n and bmax or mma(a[t[n]], bmax)
    minlen = mmi(minlen, r - l)
  end
  ret = mmi(ret, minlen * (maxv - minv))
end
print(ret)


Measured memory_bytes: 13180
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int main(){
    int n, r;
    while(cin>>n>>r&&n){
        vector<int> line(n);
        REP(i, n)line[i]=n-i;
        REP(i, r){
            int p, c;
            cin >> p >> c;
            vector<int> nl(line.begin()+p-1, line.begin()+p+c-1);
            nl.insert(nl.end(), line.begin(), line.begin()+p-1);
            nl.insert(nl.end(), line.begin()+p+c-1, line.end());
            line=nl;
        }
        cout << line.front() << endl;
    }

    return 0;
}



Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
#define maxn 1000010
#define ull unsigned long long
#define  ll long long
#define db double
int main() {
    int n;
    cin>>n;
    int a[n],m[n];
    for (int i = 0; i <n ; ++i) {
        cin>>a[i];
    }
    int ans=0;
    m[0]=a[0];
    for (int j = 1; j <n ; ++j) {
        if(a[j]<m[j-1])m[j]=a[j];
        else m[j]=m[j-1];
    }
    for (int k = 0; k <n ; ++k) {
        if (m[k]==a[k])ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int N = 310;
const ll MOD = 998244353;

string s;
int k;
ll dp[N][N];
ll dp2[N][N];

void add(ll& a, ll b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> s >> k;
	reverse(ALL(s));
	int cnt = 0;
	vector<int> vv;
	int mx = 0;
	for (char c : s) {
		if (c == '1') {
			++cnt;
			++mx;
		} else {
			vv.push_back(cnt);
			cnt = 0;
		}
	}
	vv.push_back(cnt);
	k = min(k, mx);

	dp[0][0] = 1;

	int sm = 0;
	for (int i = 0; i < vv.size(); ++i) {
		memset(dp2, 0, sizeof(dp2));
		for (int cur = 0; cur <= sm; ++cur) {
			for (int used = cur; used <= sm && used <= k; ++used) {
				for (int now = 0; now <= cur; ++now) {
					add(dp2[cur - now][used], dp[cur][used]);
				}
				for (int now = 1; now <= vv[i] && used + now <= k; ++now) {
					add(dp2[cur + now][used + now], dp[cur][used]);
				}
			}
		}

		memcpy(dp, dp2, sizeof(dp));
		sm += vv[i];
	}

	ll ans = 0;
	for (int i = 0; i <= k; ++i) {
		add(ans, dp[0][i]);
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 5148
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int sub(int a,int b){a-=b;return a<0?a+mod:a;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
/* math */
const int N = (1<<18)*18;
int ch[N][2], s[N], sum[N], prod[N], cnt;
int H;
int inv[1<<18];
inline void addtag(int x,int p){
	prod[x]=mul(prod[x], p);
	sum[x]=mul(sum[x],p);
}
inline void pd(int x){
	if(prod[x]!=1){
		for(int j=0;j<2;j++)if(ch[x][j]){
			addtag(ch[x][j], prod[x]);
		}
		prod[x]=1;
	}
}
inline void ins(int& rt,int s,int x,int dep,int curs){
	int c=(s>>(dep-1))&1;
	if(!rt){
		rt=++cnt;
		prod[rt] = 1, sum[rt] = 0;
	}
	// cout << x << "::" << curs << endl;
	pd(rt);
	if(!dep){
		sum[rt] = add(sum[rt], mul(x, s));
		prod[rt] = 1;
		return ;
	}
	ins(ch[rt][c],s,x,dep-1,curs*2+c);
	if(ch[rt][0])sum[rt] = add(sum[rt], sum[ch[rt][0]]);
	if(ch[rt][1])sum[rt] = add(sum[rt], sum[ch[rt][1]]);
	sum[rt] = mul(sum[rt], curs);
}
int ans2;
inline int merge(int x,int y,int s){
	if(!x||!y)return x+y;
	pd(x),pd(y);
	ch[x][0] = merge(ch[x][0], ch[y][0], s<<1), ch[x][1] = merge(ch[x][1], ch[y][1], s<<1|1);
	// cout << s << ":" << sum[x] << " " << sum[y] << ":" << endl;
	int qwq = mul(inv[s], mul(sum[x], sum[y]));
	// cout << qwq << endl;
	ans2 = add(ans2, qwq);
	ans2 = sub(ans2, mul(s/2,mul(sum[x],sum[y])));
	// cout << mul(s/2,mul(sum[x],sum[y])) << endl;
	sum[x] = add(sum[x], sum[y]);
	return x;
}

int p[1<<18];
int rt[1<<18];

int main()
{
	inv[1]=1;for(int i=2;i<1<<18;i++){
		inv[i] = mul(mod-mod/i,inv[mod%i]);
	}
	cin >> H;
	for(int i=0;i<1<<(H-1);i++){
		scanf("%d",&p[(1<<(H-1))+i]);
		p[(1<<(H-1))+i]--;
		p[(1<<(H-1))+i]+=1<<(H-1);
	}
	int ans=0;
	for(int i=(1<<H)-1;i;i--){
		if(i>=(1<<(H-1))){
			// cout << i << "->" << p[i] << "!" << endl;
			ins(rt[i], p[i], i, H-1, 1);
		}else{
			ans2=0;
			rt[i] = merge(rt[i<<1], rt[(i<<1)|1], 1);
			ans2 = mul(ans2, i);
			ans = add(ans, ans2);
			// cout << i << ">> ";cout << ans << ":" << ans2 << endl;
			addtag(rt[i], i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 43104
#include <cstring>
#include <cstdio>
#define rg register
using namespace std;
typedef long long ll;
const int maxn=2010,INF=0x3f3f3f3f;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
struct data{int v,nxt;}edge[maxn<<1];
int n,k,lim,p=-1,cnt,ans=INF,head[maxn];
inline void insert(int u,int v)
{
	edge[++p]=(data){v,head[u]};head[u]=p;
	edge[++p]=(data){u,head[v]};head[v]=p;
}
void dfs(int x,int dep,int pre)
{
	if(dep>k) ++cnt;
	for(int i=head[x];~i;i=edge[i].nxt)
	  if(edge[i].v^pre)
	    dfs(edge[i].v,dep+1,x);
}
void input()
{
	int u,v;
	read(n);read(k);
	memset(head,0xff,sizeof(head));
	for(rg int i=1;i<n;i++)
	{
		read(u);read(v);
		insert(u,v);
	}
}
int main()
{
	input();
	if(~k&1)
	{
		k>>=1;
		for(rg int i=1;i<=n;i++)
		{
			cnt=0;
			dfs(i,0,i);
			getmin(ans,cnt);
		}
	}
	else
	{
		k>>=1;
		for(int i=0;i<p;i+=2)
		{
			cnt=0;
			dfs(edge[i].v,0,edge[i^1].v);
			dfs(edge[i^1].v,0,edge[i].v);
			getmin(ans,cnt);
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    long long k;
    cin >> k;
    long long ans = 0;
    for(int i=1;i<=k;i++)for(int j=1;j<=k;j++)for(int l=1;l<=k;l++){
        ans+=__gcd(__gcd(i,j),l);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# import sys
# sys.setrecursionlimit(10**9)

def resolve():
    N,Q=map(int,input().split())
    S=str(input())

    L, R = [0] * Q, [0] * Q
    for i in range(Q):
        L[i], R[i] = map(int, input().split())
        L[i], R[i] = L[i]-1, R[i]-1

    A=[0]*N
    for i in range(N-1):
        if S[i:i+2]=='AC':
            A[i]=1

    B = [0] + A
    B = list(accumulate(B))  # 累積和を格納したリスト作成

    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    for j in range(Q):
        ans=B[R[j]]-B[L[j]]
        print(ans)



resolve()

Measured memory_bytes: 16628
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/

const int max_n = 100005;

/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<int> b(n);
    rep(i, n-1) cin >> b[i];

    int a[max_n];
    a[0] = b[0];
    a[n-1] = b[n-2];
    for(int i = 1; i < n-1; ++i){
        a[i] = min(b[i-1], b[i]);
    }

    int ans = 0;
    rep(i, n) ans += a[i];

    cout << ans << endl;

return 0;
}

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

//bool f[200000];
int main(){
    int N,M;
    cin>>N>>M;
    int L[200000],R[200000];
    int Lmax=0,Rmin=1e9;
    for(int i=0;i<M;i++){
        cin>>L[i]>>R[i];
        Lmax=max(L[i],Lmax);
        Rmin=min(R[i],Rmin);
    }

    cout<<max(Rmin-Lmax+1,0)<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	s = "s" + s; t = "t" + t;

	int dp[3001][3001];
	for (int i = 0; i <= n; ++i) dp[i][0] = 0;
	for (int j = 0; j <= m; ++j) dp[0][j] = 0;
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) {
		if (s[i] == t[j]) dp[i][j] = dp[i-1][j-1] + 1;
		else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
	}

	string ans_rev = "";
	for (int i = n, j = m; i != 0 && j != 0; ) {
		if (i > 0 && dp[i][j] == dp[i-1][j]) i--;
		else if (j > 0 && dp[i][j] == dp[i][j-1]) j--;
		else {
			ans_rev.push_back(s[i]);
			i--; j--;
		}
	}

	for (int i = ans_rev.size()-1; i >= 0; --i) cout << ans_rev[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 35456
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		
		int ans = 0;
		for(int i=0;i<=a;i++) {
			for(int j=0;j<=b;j++) {
				for(int k=0;k<=c;k++) {
					if(i*500+j*100+k*50 == x) {
						ans += 1;
					}
				}
			}
		}
		System.out.println(ans);
	}

}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




int main() {

	int h, w;
	cin >> h >> w;
	int a, b;
	cin >> a >> b;

	VVB c(h, VB(w, false));

	VI v(w, 0);

	if (h == 1 || w == 1) {
		if (h == 1) {
			if (b != 0) {
				cout << "No" << endl;
			}
			else {
				REP(i, a)cout << 1;
				REP(i, w - a)cout << 0;
			}
		}
		else{
			if (a != 0) {
				cout << "No" << endl;
			}
			else {
				REP(i, b)cout << 1 << endl;
				REP(i, h - b)cout << 0 << endl;
			}
		}
		return 0;
	}
	
	REP(i, h) {
		REP(j, w) {
			int d = 0;
			int e = 0;
			if (j < a)d++;
			if (i < b)e++;
			if (d == e)cout << 1;
			else cout << 0;
		}
		cout << endl;
	}

	return 0;


}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main()
{
    int n,r;
    scanf("%d%d",&n,&r);
    if(n>=10)
    {
        printf("%d",r);
    }
    else
    {
        printf("%d",r+100*(10-n));
    }
    return 0;
}


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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 15, msksz = (1 << nsz) - 1, inf = 0x3f3f3f3f;
int n, m, full, lg[msksz + 5], g[nsz + 5], w[nsz + 5][nsz + 5];
int sum[msksz + 5], sm[msksz + 5][nsz + 5], dp[msksz + 5][nsz + 5];

int inline at(int S, int id) { return S >> id & 1; }

int inline lb(int S) { return S & -S; }

string inline bin(int S, int len = n) {
	string s;
	loop (i, len) s += at(S, i) + 48;
	return s;
}

void inline upd(int &a, int b) { if (a < b) a = b; }

int main() {
	ios::sync_with_stdio(0);
	cin >> n >> m;
	full = (1 << n) - 1;
	cont (i, m) {
		int u, v, w;
		cin >> u >> v >> w;
		--u, --v;
		g[u] |= 1 << v;
		g[v] |= 1 << u;
		::w[u][v] = ::w[v][u] = w;
	}
	loop (i, n) lg[1 << i] = i;
	
	cont (S, full) {
		int u = lg[lb(S)];
		sum[S] = sum[S - lb(S)];
		for (int t = g[u] & S, d = t & -t; t; t -= d, d = t & -t) {
			int v = lg[lb(t)];
			sum[S] += w[u][v];
		}
	}
	
	cont (S, full) {
		int pS = S - lb(S), p = lg[lb(S)];
		for (int rS = S ^ full, t = rS, d = t & -t; d; t -= d, d = t & -t) {
			int u = lg[lb(t)];
			sm[S][u] = sm[pS][u] + w[p][u];
		}
	}
	
	memset(dp, -inf, sizeof(dp));
	cont (S, full) {
		if (!at(S, 0) || at(S, n - 1)) continue;
		dp[S][0] = sum[S];
	}
	cont (S, full) {
		if (!at(S, 0)) continue;
		int rS = S ^ full;
		for (int T = rS; T; T = (T - 1) & rS) {
			if (at(T, n - 1)) continue;
			int mx = 0;
			for (int t = S, d = t & -t; t; t -= d, d = t & -t) {
				int u = lg[d];
				upd(mx, sm[T][u]);
			}
			for (int t = S, d = t & -t; t; t -= d, d = t & -t) {
				int u = lg[d];
				upd(dp[S | T][u], dp[S][u] + mx + sum[T]);
			}
		}
		for (int t = S, d = t & -t; t; t -= d, d = t & -t) {
			int u = lg[d];
			if (dp[S][u] < 0) continue;
			for (int t = rS & g[u], d = t & -t; d; t -= d, d = t & -t) {
				int v = lg[d];
				upd(dp[S | (1 << v)][v], dp[S][u] + w[u][v]);
			}
		}
	}
	cout << sum[full] - dp[full][n - 1] << ln;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef map<LL, int> :: iterator Mit;

const int N = 2500;

int n, pcnt, ans, pr[N / 2]; 
LL x, y;
map<LL, int> mp, vis;

inline bool is_prim(LL x) {
	LL y = sqrt(x);
	return y * y == x;
}
void pre(int n) {
	for(int i = 2, f = 1; i <= n; ++i, f = 1) {
		for(int j = 2; j < i && f; ++j)
			if(i % j == 0) f = 0;
		if(f) pr[++pcnt] = i;
	}
}
LL calc(LL x) {
	LL y = 1;
	for(int i = 1; i <= pcnt; ++i) {
		if(x % pr[i]) continue;
		int cnt = 0;
		while(x % pr[i] == 0)
			x /= pr[i], ++cnt;
		cnt %= 3;
		if(!cnt) continue;
		for(int j = 1; j <= 3 - cnt; ++j)
			y *= pr[i];
	}
	if(x == 1) return y;
	y *= is_prim(x) ? (LL) sqrt(x) : x * x;
	return y;
}

int main() {
	scanf("%d", &n);
	pre(N);
	for(int k = 1; k <= n; ++k) {
		scanf("%lld", &x);
		y = 1;
		for(int i = 1; i <= pcnt; ++i) {
			if(x % pr[i]) continue;
			int cnt = 0;
			while(x % pr[i] == 0)
				x /= pr[i], ++cnt;
			cnt %= 3;
			for(int j = 1; j <= cnt; ++j)
				y *= pr[i];
		}
		y *= x;
		mp[y]++;
	}
	for(Mit it = mp.begin(); it != mp.end(); ++it) {
		x = (*it).first;
		if(vis[x]) continue;
		y = calc(x);
		if(x == y) ++ans;
		else {
			vis[y] = 1;
			ans += max(mp[x], mp[y]);
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 25216
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
	int r,d,x;
	scanf("%d%d%d",&r,&d,&x);
	for (int i=1;i<=10;i++)
	{
		printf("%lld\n",(long long)r*x-d);
		x=r*x-d;
	}
	return 0;
}


Measured memory_bytes: 256
/**
 * @author karayuu
 */
fun main(args: Array<String>) {
    val filterList = mutableListOf('a', 'e', 'i', 'o', 'u')

    val input = readLine()!!.toCharArray().first()
    if (filterList.contains(input)) {
        println("vowel")
    } else {
       println("consonant")
    }
}

Measured memory_bytes: 32308
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

class City {
    public:
    City(){};
    City(ll y, ll p, ll index) : y(y), p(p), index(index) {};
    ll y, p, index;
    bool operator<(City c) {
        return this->y < c.y;
    }
};

int main(){
    ll n,m; cin >> n >> m;
    vector<City> c(m);
    rep(i,m){
        ll p,y; cin >> p >> y;
        c[i] = City(y,p,i);
    }
    sort(all(c));
    vector<ll> num(n,0);
    string s[m];
    auto num2str = [&](ll num){
        string s = to_string(num);
        ll zero = 6 - s.size();
        string ret(zero,'0');
        return ret + s;
    };
    rep(i,m){
        num[c[i].p-1]++;
        ll ind = num[c[i].p-1];
        s[c[i].index] = num2str(c[i].p) + num2str(ind);
    }
    rep(i,m)cout << s[i] << "\n";
}

Measured memory_bytes: 10880
#include <stdio.h>
#include <string.h>

void inverse(char *a,char *b){
	int i;
	
	for(i=0;i<strlen(a);i++){
		b[i]=a[strlen(a)-i-1];
	}
}

int main(){
	char S[100];
	char Sinv[100];
	char keyence[7]="keyence";
	char keyenceinv[7]="ecneyek";
	int i,f;
	int patn=0;
	int n=0;
	
	gets(S);
	
	patn=strcspn(S,"k");
	
	if(patn==strlen(S)){
		printf("NO");
	}else if(1<=patn){
		if(strstr(S,keyence)!=NULL){
			printf("YES");
		}else{
			printf("NO");
		}
	}else{
		if(strstr(S,keyence)!=NULL){
			printf("YES");
		}else{
			inverse(S,Sinv);
			i=0;
			while(S[i]==keyence[i]){
				i++;
			}
			
			f=0;
			while(Sinv[f]==keyenceinv[f] && f<7-i){
				f++;
			}
			
			if(i+f==7)	printf("YES");
			else	printf("NO");
		}
	}
	
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	unordered_map<int,int>m;
	for(int i=2;i<=n;++i){
		int num=i;
		for(int j=2;j<=n;++j){
			while(num&&num%j==0){
				num/=j;
				++m[j];
			}
		}
	}
	int ans=1,mod=1e9+7;
	for(auto&i:m)ans=(int64_t)ans*(i.second+1)%mod;
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <stdio.h>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, n = 2019, m, cnt[n], ans = 0, now = 0;
  char s[200010];
  scanf("%s", s);
  for(i = 0; i < n; ++i) cnt[i] = 0;
  cnt[0] = 1;
  for(i = 0; s[i]; ++i);
  m = i;
  ll p[m];
  p[0] = 1;
  for(i = 1; i < m; ++i) p[i] = p[i - 1] * 10, p[i] %= n;
  for(i = m - 1; i >= 0; --i) {
    now += p[m - 1 - i] * (s[i] - '0'), now %= n;
    cnt[now]++;
  }
  for(i = 0; i < n; ++i) ans += cnt[i] * (cnt[i] - 1) / 2;
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 3496
import java.util.HashSet;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        final Scanner cin = new Scanner(System.in);
        final int n = cin.nextInt();

        if (n == 3) {
            System.out.println("2 5 63");
        } else if (n == 4) {
            System.out.println("2 5 20 63");
        } else if (n == 5) {
            System.out.println("2 5 20 63 30");
        } else {
            HashSet<Integer> nums = new HashSet<>();
            int[] offset = new int[] {2, 3, 4, 6};
            int k = 0;
            int summary = 0;
            for (int i = 0; i < n; i++) {
                k = i / 4;
                int ai = k * 6 + offset[i % 4];
                nums.add(ai);
                summary += ai;
            }
            int next6k = (k + 1) * 6;
            if (nums.contains(next6k)) next6k += 6;
            int fraction = summary % 6;
            int[] candidateToRemove = new int [] {0, 0, 8, 9, 0, 9};
            int[] candidateToAppend = new int [] {
                    0, 0, (k + 1) * 6, (k + 1) * 6, 0, k * 6 + 4};
            if (fraction != 0) {
                nums.remove(candidateToRemove[fraction]);
                int append = candidateToAppend[fraction];
                if (nums.contains(append)) append += 6;
                nums.add(append);
            }
            System.out.println(
                    nums.stream().map((Integer i) -> i.toString()).collect(Collectors.joining(" ")));
        }

    }
}


Measured memory_bytes: 29396
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int n;
string s[100];

int main(){
  cin >> n;
  vi Mn(26,100);
  rep(i,0,n) cin >> s[i];
  rep(i,0,n) {
    vi cnt(26,0);
    for(auto ch : s[i])
      cnt[ch-'a']++;
    rep(i,0,26) Mn[i]=min(Mn[i],cnt[i]);
  }
  string ans="";
  rep(i,0,26) ans+=string(Mn[i],char(i+'a'));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    ll a[n], b[n];
    rep(i, n) {
        cin >> a[i];
    }
    using P = pair<ll, int>;
    priority_queue<P> que;
    rep(i, n) {
        cin >> b[i];
        que.emplace(b[i], i);
    }
    ll ans = 0;
    while (!que.empty()) {
        P p = que.top();
        int t = p.second;
        que.pop();
        if (a[t] > p.first) {
            cout << -1 << endl;
            return 0;
        }
        if (a[t] < b[t]) {
            ll sum = b[(t - 1 + n) % n] + b[(t + 1) % n];
            if (b[t] - a[t] < sum) {
                cout << -1 << endl;
                return 0;
            }
            ans += (b[t] - a[t]) / sum;
            b[t] -= sum * ((b[t] - a[t]) / sum);
            que.emplace(b[t], t);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9328
n,m=map(int,input().split())
C=set(map(int,input().split()))

ANSLIST=[n]*(n+1)

ANSLIST[0]=0

for i in range(1,n+1):
    ANSLIST[i]=min([ANSLIST[i-c]+1  for c in C if i-c>=0])

print(ANSLIST[n])


Measured memory_bytes: 7256
import Foundation

let n = Int(readLine()!)!
let prices = readLine()!
    .split(separator: " ")
    .map { Int($0)! }
var money = 1000
var stocks = 0

for i in 0 ..< n - 1 {
    if prices[i] > prices[i + 1] {
        // Sell
        money += stocks * prices[i]
        stocks = 0
    } else if prices[i] < prices[i + 1] {
        // Buy
        stocks += money / prices[i]
        money = money % prices[i]
    }
}

money += stocks * prices[n - 1]

print(money)


Measured memory_bytes: 13592
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        long long in;
        cin >> in;
        while(in % 2 == 0){
            in = in / 2;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

const int modNum = 2019;

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

    reverse(s.begin(), s.end());

    int n = s.size();

    int nowNumRemainder = 0, base = 1, remZeroCount = 0;

    vector<int> remainderCountVec(2019, 0);

    for (const char &singleNumChar : s)
    {
        nowNumRemainder += (int)(singleNumChar - '0') * base;
        nowNumRemainder %= modNum;

        ++remainderCountVec.at(nowNumRemainder);

        if (nowNumRemainder == 0)
        {
            ++remZeroCount;
        }

        base *= 10;
        base %= modNum;
    }

    long long ansCount = remZeroCount;

    for (const int &singleRemainderCount : remainderCountVec)
    {
        ansCount += singleRemainderCount * (singleRemainderCount - 1) / 2;
    }

    cout << ansCount << endl;
}

Measured memory_bytes: 3748
import math
 
N, M = map(int, input().split())
 
def comb(n, r):
    if n == 0:
        return 0
    if r == 0:
        return 0
    if n < 2:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
 
if N + M < 2:
    print(0)
elif N == 1 and M == 1:
    print(0)
else:
    ans = comb(N, 2) + comb(M, 2)
    print(ans)

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

int N;

int main() {
	cin >> N;
	int ans = 1;
	for (int i = 0; i <= 7; i++) {
		if (ans * 2 <= N) ans = ans * 2;
		else break;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

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;
}

int main() {
  string s;
  cin >> s;
  if (s == "ABC")
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
  return 0;
}

Measured memory_bytes: 3596