akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
string S;

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  cin >> S;
  N = S.size();

  int l = -1;
  int cnt = 0;
  int md = 0;
  vector<pii> segs;
  rep(i, N) {
    if (S[i] == 'A') {
      if (l != -1) {
        segs.eb(pii(l, cnt));
      }

      l = i;
      cnt = 0;
      md = 0;
    } else if (S[i] == 'B') {
      if (l == -1) continue;

      if (md == 1) {
        segs.eb(pii(l, cnt));
        l = -1;
      } else {
        md ^= 1;
        assert(md == 1);
      }
    } else if (S[i] == 'C') {
      if (l == -1) continue;

      if (md == 0) {
        segs.eb(pii(l, cnt));
        l = -1;
      } else {
        md ^= 1;
        cnt++;
        assert(md == 0);
      }
    } else assert(0);
  }
  if (l != -1) {
    segs.eb(pii(l, cnt));
  }
  //for (auto p : segs) {
  //  cout << p.X << ", "<<p.Y << endl;
  //endl}

  LL ans = 0;
  while (!segs.empty()) {
    auto p = segs.back(); segs.pop_back();
    ans += p.Y;
    if (!segs.empty()) {
      if (segs.back().X+segs.back().Y*2+1 == p.X) {
        segs.back().Y += p.Y;
      }
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 2700
#include <iostream>

using namespace std;

int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	bool c = false;
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++)
		{
			if (k == i*m + j*n - 2*i*j)
			{
				c = true;
			}
		}
	if (c)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int i,count=0,a,b,c;

	scanf("%d%d%d",&a,&b,&c);

	for(i=a;i<=b;i++){
		if(c%i==0){
			count++;
		}
	}
	printf("%d\n",count);

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>

#define NIL -1

using namespace std;

struct Node
{
	int key;
	Node * parent, * lchild, * rchild;
};


void insert(Node * &T, int key);
void insert_rec(Node * &T, int key);
void print(Node * T);
void inorder(Node * T);
void preorder(Node * T);


int main()
{
	int n;
	Node * T = NULL;
	
	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		string cmd;
		
		cin >> cmd;
		if (cmd == "insert")
		{
			int key;
			cin >> key;
			insert_rec(T, key);
			
		}
		else if (cmd == "print")
		{
			print(T);
		}
	}
}


void insert(Node * &T, int key)
{
	Node * p = new Node;
	p->key = key;
	p->lchild = p->rchild = NULL;
	
	if (T == NULL) T = p;
	else
	{
		Node * q = NULL, * r = T;
		while (r != NULL)
		{
			q = r;
			if (p->key < r->key)
				r = r->lchild;
			else 
				r = r->rchild;
		}
	
		if (p->key < q->key)
			q->lchild = p;
		else
			q->rchild = p;
	}
}


void insert_rec(Node * &T, int key)
{
	if (T == NULL)
	{
		Node * p = new Node;
		p->key = key;
		p->lchild = p->rchild = NULL;
		T = p;
	}
	else if (key < T->key)
		insert_rec(T->lchild, key);
	else
		insert_rec(T->rchild, key);
}







void print(Node * T)
{
	inorder(T);
	cout<< endl;
	preorder(T);
	cout << endl;
}


void inorder(Node * T)
{
	if (T == NULL) return;
	inorder(T->lchild);
	cout << ' ' << T->key;
	inorder(T->rchild);
}

void preorder(Node * T)
{
	if (T == NULL) return;
	cout << ' ' << T->key;	
	preorder(T->lchild);
	preorder(T->rchild);
}



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

long long x, i, j;
int main() {
	cin >> x;
	for(i=-120; i<=120; i++) for(j=-120; j<=120; j++) {
		if(pow(i,5) - pow(j,5) == x) {
			cout << i << ' ' << j;
			return 0;
		}
	}
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64
#define n_max int(1e5+2)
#define INF 2*(1e9 +1)


int n;

struct dot{
    int id;
    llong x;
    llong y;
};

struct edge{
    int v1;
    int v2;
    llong d;
};

bool x_comp(dot a, dot b){
    return a.x < b.x;
}

bool y_comp(dot a, dot b){
    return a.y < b.y;
}

bool e_comp(edge a, edge b){
    return a.d < b.d;
}


struct UnionFind{
    int data[n_max];
    UnionFind(int n){
        REP(i,n) data[i]=i;
    }

    int root(int x){
        int tmp;
        if(data[x]==x) return x;
        else{
            tmp=root(data[x]);
            data[x]=tmp;
            return tmp;
        }
    }

    bool is_same(int x,int y){
        return root(x) == root(y);
    }

    void merge(int x,int y){
        data[root(x)] = root(y);
    }
};


int main(){
    cin >> n;
    dot A[n_max+5],B[n_max+5];
    int x,y;
    FOR(i,1,n+1){
        scanf("%d%d",&x,&y);
        A[i].x=x;
        A[i].y=y;
        A[i].id=i;
        B[i].x=x;
        B[i].y=y;
        B[i].id=i;
    }
    A[0].x=-INF;
    A[0].y=-INF;
    A[0].id=0;
    B[0].x=-INF;
    B[0].y=-INF;
    B[0].id=0;
    A[n+1].x=INF;
    A[n+1].y=INF;
    A[n+1].id=n+1;
    B[n+1].x=INF;
    B[n+1].y=INF;
    B[n+1].id=n+1;

    sort(A+1,A+n+1,x_comp);
    sort(B+1,B+n+1,y_comp);

    
    edge E[4 * n_max +5];
    int j=0;
    FOR(i,1,n+1){
        E[j].v1=A[i].id;
        E[j].v2=A[i-1].id;
        E[j].d=A[i].x - A[i-1].x;
        j+=1;
        E[j].v1=A[i].id;
        E[j].v2=A[i+1].id;
        E[j].d=A[i+1].x - A[i].x;
        j+=1;
        E[j].v1=B[i].id;
        E[j].v2=B[i-1].id;
        E[j].d=B[i].y - B[i-1].y;
        j+=1;
        E[j].v1=B[i].id;
        E[j].v2=B[i+1].id;
        E[j].d=B[i+1].y - B[i].y;
        j+=1;
    }

    sort(E,E+4*n,e_comp);

    int edge_num=0;
    llong ans=0;
    UnionFind U(n+2);
    j=0;
    while(edge_num < n-1){
        if(not U.is_same(E[j].v1,E[j].v2)){
            edge_num+=1;
            U.merge(E[j].v1,E[j].v2);
            ans+=E[j].d;
        }
        j+=1;
    }


    cout << ans << endl;
}



Measured memory_bytes: 11520
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,X = map(int,input().split())
L = list(map(int,input().split()))

total = 0
ans = 1
for l in L:
    total += l
    if total <= X:
        ans += 1
    else:
        break

print(ans)

Measured memory_bytes: 3060
#include "stdio.h"
#include "math.h"


int main()
{
	int N,a,b;
	double c;
	scanf("%d", &N);
	a = 800 * N;
	c = N / 15;
	double floor(double c);
	b = 200 * c;
	printf("%d", a - b);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

const int N = 109;

int x[N];
int y[N];
int h[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", x + i, y + i, h + i);
  }
  for (int cx = 0; cx <= 100; ++cx) {
    for (int cy = 0; cy <= 100; ++cy) {
      int ch = 2'000'000'000;
      for (int i = 0; i < n; ++i) {
        if (x[i] == cx && y[i] == cy) {
          ch = h[i];
          break;
        }
        int v = abs(x[i] - cx) + abs(y[i] - cy);
        if (h[i] != 0 || v == 1) {
          ch = v + h[i];
          break;
        }
      }
      if (ch == 2'000'000'000) {
        continue;
      }
      bool ok = true;
      for (int i = 0; i < n; ++i) {
        if (max(ch - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]) {
          ok = false;
        }
      }
      if (ok) {
        printf("%d %d %d\n", cx, cy, ch);
        return 0;
      }
    }
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  vector<vector<int>> sum(26, vector<int>(n+1));
  rep(i, 26) rep(j, n) {
    sum[i][j+1] = sum[i][j] + (s[j] == 'a'+i);
  }
  rep(i, 26) rep(j, n+1) {
    sum[i][j] *= 2;
    sum[i][j] -= j;
  }
  rep(i, 26) {
    set<pair<int, int>> st;
    rep(j, n+1) {
      if(!st.empty() && st.begin()->first < sum[i][j]) {
        cout << st.begin()->second+1 << ' ' << j << endk;
        return 0;
      }
      if(j-1>=0) st.insert({sum[i][j-1], j-1});
    }
  }
  cout << -1 << ' ' << -1 << endk;
  return 0;
}


Measured memory_bytes: 18224
# coding:utf-8

N = int(input())

ans = 0
for i in range(1, N+1):
    if i % 2 == 0:
        continue

    divNum = 0
    for j in range(1, i+1):
        if i % j == 0:
            divNum += 1


    if divNum == 8:
        ans += 1

print(ans)

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

using namespace std;

const int NMAX = 1e5 + 10;
int a[NMAX], b[NMAX], n;

long long ans;

int main(){
    int i;
    cin >> n;
    for(i = 1 ; i <= n ; i++)
        cin >> a[i];
    cin >> a[n + 1];

    for(i = 1 ; i <= n ; i++)
        cin >> b[i];

    for(i = 1 ; i <= n ; i++){
        int x = min(a[i], b[i]);
        ans += x;
        a[i] -= x;
        b[i] -= x;

        if(b[i] > 0){
            x = min(b[i], a[i + 1]);
            ans += x;
            a[i + 1] -= x;
            b[i] -= x;
        }
    }

    cout << ans;

    return 0;
}


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

typedef long long ll;

int main() {
    ll N, T, limit;
    ll t[200000];
    ll ans = 0;
    cin >> N >> T;

    for (int i = 0; i < N; i++) {
        cin >> t[i];
    }

    limit = t[0] + T;
    for (int i = 1; i < N; i++) {
        if (t[i] < limit) {
            ans += t[i] - t[i-1];
        } else {
            ans += T;
        }
        limit = t[i] + T;
    }

    ans += T;
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,a,b) for(int i=(a);i>=(b);i--)
#define debug(x) do { cerr << #x << ": " << x << endl; } while(0)

using namespace std;
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;


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


  ll H, W;
  cin >> H >> W;

  int N;
  cin >> N;

  vi a(N), b(N);
  set<pair<int,int>> points;
  set<pair<int,int>> recs;
  vector<ll> ans(10, 0); // 0-9
  rep(i, 0,N-1) {
    int u, v;
    cin >> u >> v;
    points.insert( {u, v} );
    rep(dx,-2, 0) rep(dy,-2,0) {
      int nu = u+dx;
      int nv = v + dy;
      int nu1 = nu  + 2;
      int nv1 = nv + 2;
      if (nu >=1 && nv >= 1 && nu1 <= H && nv1 <= W) 
        recs.insert({nu,nv});
    }
  }
  for(auto p: recs) {
    int u = p.first;
    int v = p.second;
    int c =0;
    rep(dx,0, 2) rep(dy,0,2) {
      if (points.count({u+dx, v+dy}) > 0) c++;
    }
    ans[c]++;
  }

  ll rest = 0;
  rep(i,1,9) rest += ans[i];
  ans[0] = (H-2)*(W-2) - rest;

  rep(i,0,9) cout << ans[i] << endl;

  
}


Measured memory_bytes: 47872
// Garg's Code
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define set set <ll>
#define ll long long
#define vec vector < ll >
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;
int main()
{
  fast();

  
  ll n;
  cin >> n;
  vector<pair<ll,ll> > v;
  f(i,0,n)
  {
  	ll a;
  	cin >> a;
  	v.pb(mp(a, i + 1));
  }
  sort(all(v));
  f(i,0,v.size())
  {
  	cout << v[i].S << " ";
  }
  
  return 0;
}


Measured memory_bytes: 2544
#include <bits/stdc++.h>
using namespace std;
int p;
string s;
int number();
int factor();
int term();

int expression(){
    int num=term();
    while(s.size()>p){
        if(s[p]=='+'){
            p++;
            num+=term();
        }else if(s[p]=='-'){
            p++;
            num-=term();
        }else{
            break;
        }
    }
    return num;
}

int term(){
    int num=factor();
    while(s.size()>p){
        if(s[p]=='*'){
            p++;
            num*=factor();
        }else if(s[p]=='/'){
            p++;
            num/=factor();
        }else{
            break;
        }
    }
    return num;
}

int factor(){
    int num;
    if(s.size()>p and s[p]=='('){
        p++;
        num=expression();
        p++;
    }else{
        return number();
    }
    return num;
}

int number(){
    int num=0;
    while(s.size()>p and isdigit(s[p])){
        num*=10;
        num+=s[p]-'0';
        p++;
    }
    return num;
}

int main(void){
    int n,i;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>s;
        p=0;
        cout<<expression()<<endl;
    }
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
int main(){
  string str;
  cin>>str;
  ll count=0;
  for(ll i=0;i<(ll)str.size()/2;i++){
    if(str.at(i)!=str.at((ll)str.size()-i-1)){count++;}
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxn = 1e6 + 5;

int n;
int a[maxn], cnt[maxn];
int p[maxn / 10], tot;
bool np[maxn];
void init() {
	np[1] = 1;
	for(int i = 2; i <= 1e6; ++i) {	
		if(!np[i]) p[++tot] = i;
		for(int j = 1; j <= tot && i * p[j] <= 1e6; ++j) {
			np[i * p[j]] = 1;
			if(i % p[j] == 0) break;
		}
	}
}
bool _Div(int x) {
	bool flag = 0;
	for(int i = 1; i <= tot && x != 1; ++i) {
		if(!np[x]) {			
			if(cnt[x]) flag = 1;
			cnt[x]++;
			break;
		}
		if(x % p[i] == 0) {
			if(cnt[p[i]]) flag = 1;
			cnt[p[i]] ++;
			while(x % p[i] == 0)
				x /= p[i];
		}
	}
	return flag;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	cin >> n;
	init();
	for(int i = 1; i <= n; ++i) cin >> a[i];
	bool flag1 = 0, flag2 = 0;
	for(int i = 1; i <= n; ++i)
		if(_Div(a[i])) flag1 = 1;
	for(int i = 1; i <= 1000000; ++i)
		if(cnt[i] == n) {
			flag2 = 1;
			break;
		}
	if(!flag1) cout << "pairwise coprime\n";
	else if(!flag2) cout << "setwise coprime\n";
	else cout << "not coprime\n";
	return 0;
}

Measured memory_bytes: 12724
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        int N = S.length();

        int i = 0;
        while (i <= N - 1) {
            if (i + 6 <= N && S.substring(i, i + 6).equals("eraser")) {
                i += 6;
                continue;
            }

            if (i + 5 <= N && S.substring(i, i + 5).equals("erase")) {
                i += 5;
                continue;
            }

            if (i + 5 <= N && !S.substring(i, i + 5).equals("dream")) {
                System.out.println("NO");
                return;
            }

            if (i + 7 <= N && S.substring(i, i + 7).equals("dreamer")) {
                if (i + 8 <= N && S.substring(i, i + 8).equals("dreamera")) {
                    // dream
                    i += 5;
                    continue;
                }

                // dreamer
                i += 7;
                continue;
            }

            if (i + 5 <= N && S.substring(i, i + 5).equals("dream")) {
                i += 5;
                continue;
            }

            System.out.println("NO");
            return;
        }

        System.out.println("YES");
    }
}

Measured memory_bytes: 29116
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int initialize(void);
int isEmpty(void);
int isFull(void);
void push(int);
int pop(void);

int top=0;
int S[100];

int main(){
  int x;
 char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      push(pop()+pop());
    }
    else if ( s[0] == '-' ){
      x = pop();
      push(pop()-x);
    }
    else if ( s[0] == '*' ){
      push(pop()*pop());
    }
    else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",S[top]);
  
  return 0;
}

int initialize(void)
{
  top = 0;
}

int isEmpty(void)
{
  return top == 0;
}

int isFull(void)
{
  return top >= 100;
}


void push(int x)
{
  if(isFull()) printf("error:overflow\n");

  top++;
  S[top] = x;
}

int pop(void)
{
  if(isEmpty()) printf("error:underflow\n");
  top--;
  return S[top+1];
}

Measured memory_bytes: 548
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
ll a,b,n;
ll calc(ll x){
    return (a*x)/b-a*(x/b);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cin>>a>>b>>n;
    if(n<b-1){
        cout<<calc(n)<<endl;
        return 0;
    }
    ll k=(n-(b-1))/b;
    k=k*b+b-1;
    cout<<calc(k)<<endl;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
int a[200005];
int b[200005];

int searchLeft(int u,int n){
    int L = 1, R = n;
    int res = -1;
    while(L<=R){
        int M = (L+R)/2;
        if(b[M]>=u){
            res = M;
            R = M-1;
        }
        else L = M+1;
    }
    return res;
}

int searchRight(int u,int n){
    int L = 1, R = n;
    int res = -1;
    while(L<=R){
        int M = (L+R)/2;
        if(b[M]<=u){
            res = M;
            L = M+1;
        }
        else R = M-1;
    }
    return res;
}

//bit = highest bit
int getCnt(int n,int bit){
    int res = 0;
    for(int i = 1; i <= n; i++){
        if(a[i]&bit){
            int lower = 0, upper = bit*2-1-a[i];
            int L = searchLeft(lower,n), R = searchRight(upper,n);
            //printf("L = %d, R = %d\n",L,R);
            if(L!=-1 && R!=-1 && L<=R) res = (res+R-L+1)%2;
            lower = bit*2+bit-a[i];
            L = searchLeft(lower,n), R = n;
            //printf("L = %d, R = %d\n",L,R);
            if(L!=-1 && R!=-1 && L<=R) res = (res+R-L+1)%2;
        }
        else{
            int lower = bit-a[i];
            int upper = bit*2-1-a[i];
            int L = searchLeft(lower,n), R = searchRight(upper,n);
            if(L!=-1 && R!=-1 && L<=R) res = (res+R-L+1)%2;
        }
        //printf("i = %d, res = %d\n",i,res);
    }
    return res;
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    for(int i = 1; i <= n; i++) scanf("%d",&b[i]);
    int ans = 0;
    for(int i = 28; i >= 0; i--){
        int mod = 1<<(i+1);
        for(int j = 1; j <= n; j++) b[j] %= mod, a[j] %= mod;
        std::sort(b+1,b+1+n);
        int res = getCnt(n,mod/2);
        if(res!=0){
            //printf("i = %d\n",i);
            //for(int j = 1; j <= n; j++) printf("%d ",a[j]);
            //printf("\n");
            //for(int j = 1; j <= n; j++) printf("%d ",b[j]);
            //printf("\n");
            ans += mod/2;
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;
int main(){
    int D, G;
    cin >> D >> G;
    vector<int> p(D);
    vector<int> c(D);
    int ans = 1e9;
    for(int i = 0; i < D; i++) cin >> p.at(i) >> c.at(i);
    for(int i = 0; i < (1 << D); i++){
        int score = 0, take = 0, reset_max = -1;
        for(int j = 0; j < D; j++){
            if(i & (1 << j)){
                score += 100 * (j+1) * p.at(j) + c.at(j);
                take += p.at(j);
            }else{
                reset_max = j + 1;
            }
        }
        if(score < G){
            int n = 100 * reset_max;
            int n_1 = (G - score) % n;
            int n_2 = (G - score) / n;
            if((n_1 == 0 ? n_2 : n_2 + 1) >= p.at(reset_max - 1)) continue;
            take += n_1 == 0 ? n_2 : n_2 + 1;
        }
        if(take < ans) ans = take;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007

int main(){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> idx;
    rep(i, N-1){
        if(S.substr(i, 2)=="AC"){

            idx.emplace_back(i);
        }
    }
    rep(q, Q){
        int l, r;
        cin >> l >> r;
        cout << lower_bound(idx.begin(), idx.end(), r-1) - lower_bound(idx.begin(), idx.end(), l-1) << endl;
    }
// // 
//     printf("%d\n", N);
    return 0;
}

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

int lcs(string X,string Y){
  int c[1001][1001];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for(int i=0;i<=m;i++) c[i][0]=0;
  for(int j=1;j<=n;j++) c[0][j]=0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(X[i]==Y[j]) c[i][j]=c[i-1][j-1]+1;
      else c[i][j]=max(c[i-1][j],c[i][j-1]);
      maxl=max(maxl,c[i][j]);
    }
  }
  return maxl;
}

int main(){
  int q;cin>>q;
  while(q--){
    string a,b;cin>>a>>b;
    cout<<lcs(a,b)<<endl;
  }
  return 0;
}



Measured memory_bytes: 7072
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> state;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }
int ceil(int a,int b){
  // a/bの切り上げを考える
  return (a+b-1)/b;
}

int main() {
  int n;
  cin >> n;
  n = n % 1000;
  cout << ((n == 0)?0:1000-n) << endl;
}


Measured memory_bytes: 3632
#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>;

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout << n1 << "\n"
#define INF 100000000000000
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
class graph
{
public:
    ll a, b, c;
};
int main()
{
    FAST
        // freopen("input1.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
        ll n,
        m, l;
    cin >> n >> m >> l;
    // ve <graph> adj[n+1];
    ll adj[n + 1][n + 1], distance[n + 1][n + 1];
    rep(i, 0, n + 1)
    {
        rep(j, 0, n + 1)
        {
            adj[i][j] = 0;
        }
    }
    rep(i, 0, m)
    {
        graph x;
        ll x1, x2, x3;
        cin >> x1 >> x2 >> x3;
        adj[x1][x2] = x3;
        adj[x2][x1] = x3;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (i == j)
                distance[i][j] = 0;
            else if (adj[i][j])
                distance[i][j] = adj[i][j];
            else
                distance[i][j] = INF;
        }
    }
    for (int k = 1; k <= n; k++)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                distance[i][j] = min(distance[i][j],
                                     distance[i][k] + distance[k][j]);
            }
        }
    }
    rep (i,0,n+1)
    {
        rep (j,0,n+1)
        {
            if (distance[i][j]<=l)
            {
                distance[i][j]=1;
            }
            else
            {
                distance[i][j]=INF;
            }
            
        }
    }
    for (int k = 1; k <= n; k++)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                distance[i][j] = min(distance[i][j],
                                     distance[i][k] + distance[k][j]);
            }
        }
    }
    ll q;
    cin >> q;
    while (q--)
    {
        ll s,t;
        cin>>s>>t;
        // cout<<"dis.. "<<distance[s][t]<<"\n";
        ll ans=distance[s][t];
        if (ans>=1000000000000)
        cout<<"-1\n";
        else
        cout<<ans-1<<"\n";
    }
}


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

#define vl vector<ll>
#define vi vector<int>

#define ff first
#define ss second

#define pb push_back
#define MOD 1e9+7 
const int nax = 1e6+5;
#define display(v) for(int i =0;i<v.size();++i)cout << v[i] << " "

inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }

int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int h,a;  cin>>h>>a;
    int val = h/a;
    if(h%a)++val;
    cout << val;
    
    return 0;
 }

Measured memory_bytes: 256
n = int(input())
queue = [[n,0]]
count = 0
maxi = 10000
ax = [1000 for i in range(1000)]

while queue:
    ato,count = queue.pop(0)
    if ato <= 1000:
        if ax[ato-1] > count:
            ax[ato-1] = count
        else:continue

    if ato == 0:
        maxi = min(maxi,count)
        continue
    a = ato
    b = ato
    counta = 0
    countb = 0
    countc = 0
    if ato >= 6:
        while a >= 9:
            a = a//9
            counta +=1
        while b >=6:
            b = b//6
            countb +=1
    else:
        countc = ato
    if counta > 0:
        queue.insert(0,[ato-9**counta,count+1])
    if countb >0:
        queue.insert(0,[ato-6**countb,count+1])
    if countc > 0:
        queue.insert(0,[0, count + ato])

print(maxi)

Measured memory_bytes: 3064
N, K = map(int, input().split())
TD = []
for _ in range(N):
    TD.append(list(map(int, input().split())))
TD.sort(key=lambda x: -x[1])

removable_list = []
S = set()
base_pt = 0
for t, d in TD[:K]:
    if t in S:
        removable_list.append([t, d])
    else:
        S.add(t)
    base_pt += d
kind = len(S)
removable_list.sort(key=lambda x: x[1])

addable_list = []
for t, d in TD[K:]:
    if t in S:
        continue
    addable_list.append([t, d])
    S.add(t)

pt = [base_pt + kind*kind]
l = min(len(removable_list), len(addable_list))

for rl, al in zip(removable_list[:l], addable_list[:l]):
    kind += 1
    base_pt += al[1] - rl[1]
    pt.append(base_pt + kind*kind)
print(max(pt))


Measured memory_bytes: 36960
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if ((n | m) == 0) {
				break;
			}

			int[] a = new int[n];
			int[] b = new int[m];
			int sumA, sumB;
			sumA = sumB = 0;
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				sumA += a[i];
			}
			for (int i = 0; i < m; i++) {
				b[i] = sc.nextInt();
				sumB += b[i];
			}

			int q = sumA - sumB;
			int optA, optB;
			optA = optB = -1;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if ((a[i] - b[j]) * 2 == q) {
						if (optA == -1 || a[i] + b[j] < optA + optB) {
							optA = a[i];
							optB = b[j];
						}
					}
				}
			}

			if (optA == -1) {
				System.out.println(-1);
			} else {
				System.out.println(optA + " " + optB);
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 21044
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

bool is_prime(int x) {
  for(int i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int x;
	cin >> x;
	while(true){
		if(is_prime(x)){
			cout << x << '\n';
			break;
		}
		x++;
	}
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
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;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,ans=1;
	cin>>n;
	rep(i,n){
		ll t; cin>>t;
		ans=lcm(ans,t);
	}
	puta(ans);
	return 0;
}

Measured memory_bytes: 256
x , n = map(int, input().split())
if n == 0:
    print(x)

else:
    p = list(map(int,input().split()))

    mi = 200
    for i in range(102):
        if not i in p:
            d1 = abs(x-i)
            if d1<mi:
                ans = i
                mi = min(d1,mi)
    print(ans)


Measured memory_bytes: 9176
a,b,c,x,y = map(int,input().split())
ans = 0
if a+b>2*c:
    if x>y:
        ans = min(c*2*x,c*y*2+(x-y)*a)
    else:
        ans = min(c*2*y,c*x*2+(y-x)*b)
else:
    ans = a*x + b*y
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
using namespace std;
long long n,x;
int abs(int x)
{
	if(x>=0) return x;
	else return -x;
}
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if((a<0&&b>0)||(a>0&&b<0)||(a==0)||(b==0)) printf("Zero\n"); 
	else if(a>0&&b>0){printf("Positive\n");}
		else if((abs(a-b)+1)%2==1) printf("Negative\n");
			else printf("Positive\n");
 } 

Measured memory_bytes: 128
pub fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let nm = readn::<usize>(" ");
    let _n = nm[0];
    let m = nm[1];

    let mut a = (0..m).map(|_| readn::<usize>(" ")).collect::<Vec<Vec<usize>>>();
    a.sort_by(|a1, a2| a1[1].cmp(&a2[1]));

    let mut east = 0;
    let mut ans = 0;
    for ab in a.iter() {
        if ab[0] >= east {
            east = ab[1];
            ans += 1;
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 10492
#include <cstdio>
using namespace std;

typedef long long Int;

int main(){
	int n;
	Int res;
	
	scanf("%d", &n);
	
	res = 1;
	while(n > 1){
		res *= n;
		n--;
	}
	
	printf("%lld\n", res);
	
	return 0;
}

Measured memory_bytes: 1020
#include<map>
#include<vector>
#include<iostream>
using namespace std;
typedef pair<string,string> P;
/*?????????pair<string,string>??? ??? ?????????P???????????¨????????????
  ??£?¨??????????????????\??§?????????
  
 */

int main(){
  int N,F; 
  cin>>N>>F;
  map<P,int> m; // keyword???????????????pair, value ??? int
                // map<P<string,string>,int> m; ??¨??£?¨????????????????

/*    ????????°
    map<string,int> A;
    A["abc"]=2;
    cout<<"A["abc"]<<endl;
    ?????????2?????????????????????

    map<pair<string,string> ,string> B;
    pair<string,string> a = make_pair("abc","xyz");
    B[a] = 100;
    cout<< B[a]<<endl;
    ?????????100??????????????????
*/
  int anssize = 0;
  for(int i=0;i<N;i++){
    int M;
    cin>>M;
    vector<string> info(M);
    for(int j=0;j<M;j++) cin>>info[j];


    for(int j=0;j<M;j++){
      for(int k=j+1;k<M;k++){
	string a = info[j];
	string b = info[k];
	if(a > b) swap(a,b); 
	m[make_pair(a,b)]++;
	if(m[make_pair(a,b)] == F) anssize++;
      }
    }
  }
  
  /*????????????*/ 
  cout<<anssize<<endl;
  map<P,int>:: iterator it;
  for(it=m.begin();it!=m.end();it++){ //it???map????????????key????°???????????????????
    int cnt = it->second; //(*it).second ??§???????????????
    if(cnt<F) continue;
    string a = it->first.first; //(*it).first.first ??§???????????????
    string b = it->first.second;//(*it).first.second??§???????????????
    cout<<a<<" "<<b<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3500
#include <stdio.h>

int main(void){
	int i,j;
	for(i=0;i<9;++i){
		for(j=0;j<9;++j){	
			printf("%dx%d=%d\n",i+1,j+1,(i+1)*(j+1));
		}
	}
	return 0;
}

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  if(n % 2 == 0){
    ll cnt = 10;
    ll ans = 0;
    while(n/cnt > 0){
      ans += n/cnt;
      cnt *= 5;
    }
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
card = [int(i) for i in input().split(" ")]
 
all = 0
for i in card:
    all += i
 
a = card[0]
mab = abs(a - (all - a))
for i in range(1,len(card) - 1):
    a += card[i]
    if mab > abs(a - (all - a)):
    	mab = abs(a - (all - a))
print(mab)

Measured memory_bytes: 24812
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int m,k,n;
  cin>>m>>k;
  n=pow(2,m);
  if(n<=k||(n==2&&k==1)) cout<<-1;
  else if(n==2&&k==0) cout<<"0 0 1 1";
  else{
    rep(i,n) if(n-1-i!=k) cout<<n-1-i<<" ";
    cout<<k<<" ";
    rep(i,n) if(i!=k) cout<<i<<" ";
    cout<<k;
  }
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <chrono>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <sstream>
#include <queue>
#include <bitset>

using namespace std;
using ll = unsigned long long;
using triplet = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vi>;

int main()
{
#ifdef LOCAL_TEST
    freopen("data.txt", "r", stdin);
#endif
    
    char buff[64];
    
    int n;
    scanf("%d\n", &n);
    vector<string> strings;
    strings.reserve(n);
    
    for (int i = 0; i < n; ++i)
    {
        scanf("%s\n", buff);
        strings.push_back(buff);
        sort(strings.back().begin(), strings.back().end());
    }
    
    vi ci(n, 0);
    string result;
    for (int i = 0; i < strings[0].length(); ++i)
    {
        char ch = strings[0][i];
        int mc = 1;
        for (int j = 1; j < (int)strings.size(); ++j)
        {
            int k = ci[j];
            while (k < strings[j].size() && strings[j][k] < ch) k++;
            ci[j] = k;
            if ((k >= strings[j].length()) || strings[j][k] != ch) break;
            mc++;
            ci[j]++;
        }
        if (mc == n) result.append(1, ch);
    }
    
    printf("%s\n", result.c_str());
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/indexed.hpp>
using namespace std;

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

template <typename T>
std::ostream &operator<<(std::ostream &ostr, const std::vector<T> &v) {
  for (const auto &i : v | boost::adaptors::indexed())
    ostr << (i.index() > 0 ? " " : "") << i.value();
  return ostr;
}

using P = pair<int, int>;
const int INF = 1e9;
const int NX[4] = {-1, 1, 0, 0};
const int NY[4] = {0, 0, -1, 1};

int h, w;
int black = 0;
vector<vector<bool>> chizu(50, vector<bool>(50, false));

inline void input() {
  cin >> h >> w;
  char c;
  rep(i, h) {
    rep(j, w) {
      cin >> c;
      if(c == '#') {
        black++;
      }
      chizu.at(i).at(j) = (c == '.');
    }
  }
}

inline int bfs(P s, P g) {
  vector<vector<int>> vvi(h, vector<int>(w, INF));
  queue<P> qp;
  P p;
  int dx, dy, re;

  qp.push(s);
  vvi.at(s.first).at(s.second) = 0;

  while(!qp.empty()) {
    p = qp.front();qp.pop();

    if(p.first==g.first && p.second==g.second) {
      return vvi.at(p.first).at(p.second);
    }

    rep(i, 4) {
      dx = p.first  + NX[i];
      dy = p.second + NY[i];
      re = vvi.at(p.first).at(p.second) + 1;

      if(!(0<=dx && dx<h && 0<=dy && dy<w)) continue;
      if(!chizu.at(dx).at(dy)) continue;
      if(vvi.at(dx).at(dy) <= re) continue;

      qp.push(P(dx, dy));
      vvi.at(dx).at(dy) = re;
    }
  }

  return -1;
}

inline int solve() {
  P s = P(0, 0);
  P g = P(h-1, w-1);
  int kyori = bfs(s, g);

  if(kyori != -1) {
    kyori++;
    return h*w - kyori - black;
  } else {
    return -1;
  }
}

inline void Main() {
  // code
  input();
  cout << solve() << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
/**
 * X = {(u,v)|0<=u,v<=N && ∃a,b>=0, s.t. a^b==u,a+b==v} に対して #X mod p を求める。(1<=N<=1e18)
 * 
 * 1. 条件を満たす(u,v)に対してu<=vが成り立つので、0<=u<=v<=Nと仮定してよい。
 * 
 * 2. Y = {(a,b)|0<=a,b && a+b<=N} に対して全射 f: Y → X; (a,b) ↦ (a^b,a+b) を考える。
 *    このとき、「f(a,b)==f(a',b') ⇔ (a,b)の同じ位置にあるビットをいくつか置き換えると(a',b')になる」を示す。
 * proof) (⇐) a^b, a+bは同じ位置のビットの置き換えで変化しないのでOK。
 *        (⇒) 背理法。a^b==a'^b'なる(a,b),(a',b')で、同じ位置にあるビットの置き換えでは作れないものをとる。
 *            iビット目が置き換えできないとすると、{(aのiビット目,bのiビット目), (a'のiビット目,b'のiビット目)} は
 *            {(0,0),(1,1)} となるしかない（そのほかのパターンならどれも入れ替えができるから）。
 *            すると、a+bとa'+b'の差が1<<(i+1)増加するが、このようなiがいくつあっても（互いに桁が異なるので）
 *            足して0になることはない。これはa+b==a'+b'に反する。//
 *  
 * 3. 2.より、各桁については(0,0),(0,1),(1,1)の3通りだけ考えればよい。
 *  
 * 4. #(Y/{この同値類}) を桁DPで求める。
 *    dp[d][s] := 「a+bとN-s*(1<<d)が上から見てdビット目まで等しいような場合の数」とおくと、
 *    求めるものは sum_s(dp[0][s])である。
 *    dp[infty][0] = 1 を初期値とする。
 *    dp[d+1][s] = 「a+bとN-s*(1<<(d+1)) == N-2*s*(1<<d)がd+1ビット目まで等しい場合の数」なので、
 *    Nのdビット目をN_dと書くと、
 *    - a,bのdビット目の和が0のとき dp[d][2*s+N_d] += dp[d+1][s]
 *    - a,bのdビット目の和が1のとき dp[d][2*s+N_d-1] += dp[d+1][s]
 *    - a,bのdビット目の和が2のとき dp[d][2*s+N_d-2] += dp[d+1][s]
 *    s>=2のとき2*s+N_d-2>=4+0-2>=2なので、s∈{0,1,2}として、dの大きい順に計算していけばよい。
 */
using ll = long long;
constexpr ll p=1e9+7;
int main(){
    ll n, dp[64][3]={0};
    scanf("%lld",&n);
    dp[63][0]=1;
    for(int d=62;d>=0;d--){
        int n_d=(n>>d)&1;
        for(int s=0;s<=2;s++){
            for(int k=0;k<=2;k++){
                int s2=2*s+n_d-k;
                if(s2>2)s2=2;
                if(s2>=0)dp[d][s2]+=dp[d+1][s];
                dp[d][s2]%=p;
            }
        }
    }
    printf("%lld\n",(dp[0][0]+dp[0][1]+dp[0][2])%p);
    return 0;
}

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

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

    int count[m+10] = {0};
    int count2 = 0;
    for (int i=0; i<n; i++) {
        int k;
        cin >> k;
        int a[k+10];
        for (int j=0; j<k; j++) {
            cin >> a[j];
            count[a[j]] += 1;
        }
        //if (count[i] == n) ++count2;
    }

    for (int i=0; i<=m; i++) {
        if (count[i] == n) ++count2;
    }
    /*
    int count2 = 0;
    for (int i=0; i<k; i++) {
        cout << count[i];
        if(count[i] == n) ++count2;
    }
    */
    cout << count2 << endl;
    
    return 0;
}


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>;
const double PI=acos(-1);

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

    ll d[200000], s[200001];

    rep(i,n){
        cin >> d[i];
        s[i+1] = s[i] + d[i];
    }

    double ans = 0;
    ll sum = 0;
    ll t = 0;
    
    for (int i = k; i <= n; ++i) {
        t = s[i] - s[i-k] + k;
        sum = max(sum,t);
    }

    ans = (double)sum/2.0;


    printf("%lf\n", ans);


    return 0;
    
}

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

using namespace std;

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;

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

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

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, k;
	cin>>n>>k;
	if(n*(n-1)/2-k<n-1){
		cout<<-1<<'\n';
		return 0;
	}
	vector<pii> ans;
	REP(i, n-1){
		ans.push_back(pii(0, i+1));
	}
	int num=(n-1)*(n-2)/2;
	int idx1=n-2, idx2=n-1;
	while(num!=k){
		ans.push_back(pii(idx1, idx2));
		--num;
		if(idx1==1){
			--idx2;
			idx1=idx2-1;
		}
		else{
			--idx1;
		}
	}
	cout<<(int)ans.size()<<'\n';
	for(auto x : ans){
		cout<<x.first+1<<' '<<x.second+1<<'\n';
	}
	return 0;
}


Measured memory_bytes: 384