akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    // int N;
    // ll W;
    // cin>>N>>W;
    // ll d[101][100001];
    // rep(i,100001) d[0][i] = -1;
    // d[0][0] = 0;
    // int v;
    // ll w;
    // Rep(i,N){
    //     cin>>w>>v;
    //     for(int val=0;val<v;val++) d[i][val] = d[i-1][val];
    //     for(int val=v;val<100001;val++){
    //         if (d[i-1][val] == -1 && d[i-1][val-v] == -1)d[i][val] = -1;
    //         else if(d[i-1][val] == -1) d[i][val] = d[i-1][val-v] + w;
    //         else if(d[i-1][val-v] == -1) d[i][val] = d[i-1][val];
    //         else d[i][val] = min(d[i-1][val-v] + w, d[i-1][val]);
    //     }
    // }
    // for(int val = 100000;val>-1;val--){
    //     if(d[N][val] != -1 && d[N][val] <= W){
    //         cout<<val;
    //         return 0;
    //     }
    // }

    int N;
    ll W;
    cin>>N>>W;
    ll d[100001];
    rep(i,100001) d[i] = 10000000000;
    d[0] = 0;
    int val;
    ll w;
    rep(i,N){
        cin>>w>>val;
        for(int v=100000;v>=val;v--) d[v] = min(d[v], d[v-val] + w);
    }
    for(int v=100000;v>-1;v--){
        if(d[v] <= W){
            cout<<v;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
import           Control.Monad.State
import qualified Data.ByteString.Char8        as B
import qualified Data.Vector                  as V
import qualified Data.Set                     as S

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT $ B.readInt . B.dropWhile ((==) ' ')

readParser :: Parser a -> IO a
readParser p = maybe (error "parser error") fst . runStateT p <$> B.getLine

main :: IO ()
main = do
  n  <- readParser parseInt
  ss <- V.replicateM n B.getLine
  print $ solve ss

solve :: V.Vector B.ByteString -> Int
solve = S.size . V.foldr S.insert S.empty


Measured memory_bytes: 69284
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

struct stock{LL w,v;};

bool comp(const stock& a,const stock& b){
    return (a.w==b.w ? a.v>b.v : a.w<b.w);
}



int main(){

    LL N,W;
    cin>>N>>W;
    vector<stock> allstock;
    REP(i,N){
        LL w,v;
        cin>>w>>v;
        allstock.push_back(stock{w,v});
    }

    sort(ALL(allstock),comp);

    vector<stock> stocks[4];
    int pointer=0;
    LL w=allstock[0].w;
    REP(i,N){
       stocks[allstock[i].w-w].push_back(allstock[i]);
    }

    LL sum[4];
    LL sumW[4];
    fill_n(sum,4,0);
    fill_n(sumW,4,0);
    LL ans=0;


    REP(i,stocks[0].size()+1){
        if(i!=0&&sumW[0]+w<=W){
            sum[0]+=stocks[0][i-1].v;
            sumW[0]+=w;
        }

        sum[1]=sum[0];
        sumW[1]=sumW[0];
        REP(j,stocks[1].size()+1){

            if(j!=0&&sumW[1]+w+1<=W){
                sum[1]+=stocks[1][j-1].v;
                sumW[1]+=w+1;
            }

            sum[2]=sum[1];
            sumW[2]=sumW[1];
            REP(k,stocks[2].size()+1){
                if(k!=0&&sumW[2]+w+2<=W){
                    sum[2]+=stocks[2][k-1].v;
                    sumW[2]+=w+2;
                }

                sum[3]=sum[2];
                sumW[3]=sumW[2];
                REP(l,stocks[3].size()+1){
                    if(l!=0&&sumW[3]+w+3<=W){
                        sum[3]+=stocks[3][l-1].v;
                        sumW[3]+=w+3;
                    }
                }
                ans =max(ans,sum[3]);
            }
        }
    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

void upd(int a[], pii &x, int y) {
    if (a[y] > a[x.first]) {
        x.second = x.first;
        x.first = y;
    } else if (x.second == -1 || y != x.first && a[y] > a[x.second]) {
        x.second = y;
    }
}

void upd(int a[], pii &x, pii y) {
    upd(a, x, y.first);
    if (y.second != -1) {
        upd(a, x, y.second);
    }
}

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

    pii m[1<<n];
    for (int i = 0; i < (1 << n); i++) {
        m[i] = pii(i, -1);
        for (int j = 0; j < n; j++) {
            if ((1 << j) & i) {
                upd(a, m[i], m[i&~(1<<j)]);
            }
        }
    }

    int ans = -1;
    for (int i = 1; i < (1 << n); i++) {
        ans = max(ans, a[m[i].first] + a[m[i].second]);
        cout << ans << endl;
    }

    return 0;
}


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

int main(void)
{
	int x;
	int i=0;

	while (1)
	{
		cin >> x;
		if (x == 0)break;
		cout << "Case " << i+1 << ":" << " " << x << endl;
		i++;
	}
	return 0;
}

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


int calc(int n, int x)
{
    int count = 0;
    for(int i=1; i<=n; ++i){
        for(int j=i+1; j<=n; ++j){
            for(int k=j+1; k<=n; ++k){
                if(i + j + k == x) count++;
            }
        }
    }
    return count;
}


int main()
{
    int n, x;
    cin >> n >> x;
    
    while(1){
        cout << calc(n, x) << endl;
        cin >> n >> x;
        if(n == 0 && x == 0) break;
    }
    return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <iostream>
using namespace std;

int main () {
	int n;
	scanf ("%d", &n);

	long long a[3*n];
	for (int i=0;i<3*n;i++) {
		scanf ("%lld", &a[i]);
	}

	long long f[3*n], b[3*n];
	memset (f, 0, sizeof(f));
	memset (b, 0, sizeof(b));
	multiset <long long> s;
	for (int i=0;i<n;i++) {
		s.insert(a[i]);
		f[n-1] += a[i];
	}

	for (int i=n;i<2*n;i++) {
		if (a[i] > *s.begin()) {
			f[i] = f[i-1]-(*s.begin())+a[i];
			s.erase(s.begin());
			s.insert(a[i]);
		} else {
			f[i] = f[i-1];
		}
	}
	s.erase(s.begin(),s.end());

	reverse(a, a+3*n);
	for (int i=0;i<n;i++) {
		s.insert(a[i]);
		b[n-1] += a[i];
	}

	for (int i=n;i<2*n;i++) {
		//cout << a[i] << " " << *s.rbegin() << " ";
		if (a[i] < *s.rbegin()) {
			b[i] = b[i-1]-(*s.rbegin())+a[i];
			s.erase(--s.rbegin().base());
			s.insert(a[i]);
		} else {
			b[i] = b[i-1];
		}
		//cout << b[i] << endl;
	}

	long long ret = -(1LL<<60);

	for (int i=n-1;i<2*n;i++) {
		//cout << i << " " << (3*n-(i+1)-1) << " " << f[i]  << " " << b[3*n-(i+1)-1] << endl;
		ret = max(ret, f[i]-b[3*n-(i+1)-1]);
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pii;

const int N=5e5+100;
const ll INF=1e18;

vector<pii>G[N];
int n,m;
ll dis[N];

int getRoot(int l,int r){
    int ans=l+r;
    if(l==r || (ans&1)) return ans;
    return ans+1;
}

void addEdge(int u,int v,int w,int flag=0){
    if(flag==0) G[u].push_back(pii(v,w));
    else G[v].push_back(pii(u,w));
}

void dfs(int l,int r,int flag,int add){
    if(l==r){
        if(flag==0)
            addEdge(getRoot(l,r),getRoot(l,r)+2*n,0,0);
        return ;
    }
    int m=(l+r)>>1;
    addEdge(getRoot(l,r)+add,getRoot(l,m)+add,0,flag);
    addEdge(getRoot(l,r)+add,getRoot(m+1,r)+add,0,flag);
    dfs(l,m,flag,add);
    dfs(m+1,r,flag,add);
}

void dfs2(int l,int r,int a,int b,int c,int cur){
    if(l==a && r==b){
        addEdge(getRoot(l,r)+2*n,cur,0);
        addEdge(cur,getRoot(l,r),c);
        return ;
    }
    int m=(l+r)>>1;
    if(b<=m) dfs2(l,m,a,b,c,cur);
    else if(a>m) dfs2(m+1,r,a,b,c,cur);
    else{
        dfs2(l,m,a,m,c,cur);
        dfs2(m+1,r,m+1,b,c,cur);
    }
}

priority_queue< pii,vector<pii>,greater<pii> > que;

void dijkstra(int s){
    for(int i=0;i<N;i++) dis[i]=INF;
    dis[s]=0;
    que.push(pii(0,s));
    while(!que.empty()){
        pii t=que.top();
        que.pop();
        int u=t.second;
        if(dis[u]<t.first) continue;
        for(auto e:G[u]){
            int v=e.first;
            if(dis[v]>e.second+dis[u]){
                dis[v]=e.second+dis[u];
                que.push(pii(dis[v],v));
            }
        }
    }
}

void solve(){
    scanf("%d%d",&n,&m);
    dfs(1,n,0,0);
    dfs(1,n,1,2*n);
    int cur=4*n;
    for(int i=1;i<=m;i++){
        int l,r,c;
        scanf("%d%d%d",&l,&r,&c);
        dfs2(1,n,l,r,c,++cur);
    }
    dijkstra(getRoot(1,1));
    ll ans=dis[getRoot(n,n)];
    if(ans>=INF) ans=-1;
    printf("%lld\n",ans);
}

int main(){

    solve();
	return 0;
}


Measured memory_bytes: 94172
import heapq


class MinimumSpanningTree:
    """ Prim's algorithm: find minimum spanning tree
        Complexity: O(E log(V))
        used in GRL2A(AOJ)
    """

    def __init__(self, V, E, start=0, INF=10**9):
        """ V: the number of vertexes
            E: adjacency list (undirected graph)
            start: start vertex
            INF: Infinity cost
        """
        self.prim(V, E, start, INF)

    def prim(self, V, E, start=0, INF=10**9):
        used = [False] * V
        self.mincost = 0
        que = []
        heapq.heappush(que, (0, 0))
        while len(que) > 0:
            cost, v = heapq.heappop(que)
            if used[v]:
                continue
            used[v] = True
            self.mincost += cost
            for to, c in E[v]:
                heapq.heappush(que, (c, to))

    def minCost(self):
        return self.mincost

V = int(input())
edge = [[] for _ in range(V)]
for i in range(V):
    for j, d in enumerate(map(int, input().split())):
        if d != -1:
            edge[i].append((j, d))
mst = MinimumSpanningTree(V, edge)
print(mst.minCost())

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

#define PI 4*atan(1)
#define INF 1e8

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(){
  unsigned long long N;
  cin >> N;
  unsigned long long pow = 1;
  for(unsigned long long i = 1; i <= N; i++){
    pow = (pow * i) % (1000000000 + 7);
  }
  cout << pow << endl;
}


Measured memory_bytes: 384
def resolve():
	from collections import deque
	K = int(input())
	q = deque(str(i) for i in range(1, 10))
	cnt = 9
	if K < 10:
		print(K); return
	while True:
		tmp = q.popleft()
		las = int(tmp[-1])
		for i in range(las-1, las+2):
			if 0<=i<=9:
				q.append(tmp + str(i))
				cnt += 1
				if cnt==K:
					print(q.pop()); return
resolve()

Measured memory_bytes: 74668
/*input

3
1 2 2
2 3 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

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

vector<pll> edge[maxn];
bool vis[maxn];
ll dis[maxn];

void dfs(int u){
	vis[u]=1;
	for(pll nxt:edge[u]) if(!vis[nxt.F]){
		dis[nxt.F]=dis[u]+nxt.S;
		dfs(nxt.F);
	}
}

int main(){
	IOS;
	int n;
	cin>>n;
	REP(i,n-1){
		ll u,v,d;
		cin>>u>>v>>d;
		u--;v--;
		edge[u].pb(MP(v,d));
		edge[v].pb(MP(u,d));
	}
	dfs(0);

	REP(i,n) cout<<dis[i]%2<<'\n';
	return 0;
}


Measured memory_bytes: 15488
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        var a = vals[0];
        var b = vals[1];
        var x = vals[2];

        var X = x / a;
        double rad;
        if (X >= a * b / 2)
        {
            // a*b = a*a*tanθ/2 + X
            // a*a*tanθ/2 = a*b - X
            // tanθ = (b/a - X/(a*a))*2
            rad = Math.Atan((b / a - X / (a * a)) * 2);
        }
        else
        {
            // X = b*b*tan(2/π-θ)/2
            // tan(2/π-θ) = 2*X /(b*b)
            rad = Math.PI / 2 - Math.Atan(2 * X / (b * b));
        }

        var deg = rad * (180 / Math.PI);
        Console.WriteLine(deg);
    }
}

Measured memory_bytes: 13268
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        aa: [String; n]
    };
    if n == 1 {
        println!("{}", aa[0]);
        return;
    }
    // 1 -> 0
    // 2 -> 1 0
    // 3 -> 2 0 1
    // 4 -> 3 1 0 2
    // 5 -> 4 2 0 1 3
    // 6 -> 5 3 1 0 2 4
    let evens = (0..(n + 1) / 2)
        .map(|i: usize| aa[2 * i].as_str())
        .collect::<Vec<&str>>();
    let odds = (0..n / 2)
        .map(|i: usize| aa[2 * i + 1].as_str())
        .collect::<Vec<&str>>();
    let (mae, ato) = if n % 2 == 0 {
        (odds, evens)
    } else {
        (evens, odds)
    };
    println!(
        "{}",
        mae.into_iter()
            .rev()
            .chain(ato.into_iter())
            .collect::<Vec<_>>()
            .join(" ")
    );
}


Measured memory_bytes: 20304
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int val =sc.nextInt();
        int gold =sc.nextInt();
        int fav = sc.nextInt();
        int count = gold/val;
        System.out.println(count > fav?fav:count);
    }
}

Measured memory_bytes: 23892
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
//#define iinf (3000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
ll l[100];
int main(){
	std::ios::sync_with_stdio(false);
	int n,i;
	cin>>n;
	l[0]=2,l[1]=1;
	f(i,2,n+1){
		l[i]=l[i-1]+l[i-2];
	}		
	cout<<l[n]<<endl;
} 


Measured memory_bytes: 256
x, y, a, b, c = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True); Q.sort(reverse=True)
print(sum(sorted(P[:x]+Q[:y]+R, reverse=True)[:x+y]))

Measured memory_bytes: 29340
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
int n,K;
void MAIN() {
	cin>>n>>K;
	bool chk[110]={false};
	rep(j,K) {
		int d;cin>>d;
		rep(i,d) {
			int t;cin>>t;
			chk[t]=true;
		}
	}
	int cnt=0;
	rep(i,n)if(!chk[i+1])cnt++;
	cout<<cnt;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 100005
#define M 8000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define mk make_pair
#define pb push_back
#define fi first
#define se second

#define Mo 998244353
#define g 3

using namespace std;

int i,j,m,n,p,k,NN,rev[N],w[2][N],fac[N],inv[N],AA,BB,A[N],B[N],C[N];

int power(int x,int y)
{
		int sum=1;
		for (;y;y>>=1)
		{
				if (y&1) sum=1ll*sum*x%Mo;
				x=1ll*x*x%Mo;
		}
		return sum;
}

char c[N],s[N];

void NTT(int *A,int f)
{
		int i,j,k,l,t;
		for (i=0;i<NN;++i) if (i<rev[i]) swap(A[i],A[rev[i]]); 
		for (i=1;i<NN;i<<=1)
			for (j=0,t=NN/(i<<1);j<NN;j+=(i<<1))
				for (k=0,l=0;k<i;++k,l+=t)
				{
						int x=A[j+k],y=1ll*A[j+k+i]*w[f][l]%Mo;
						A[j+k]=(x+y)%Mo; A[j+k+i]=(x-y+Mo)%Mo;
				}
		if (f)
		{
				int invn=power(NN,Mo-2);
				for (i=0;i<NN;++i) A[i]=1ll*A[i]*invn%Mo; 
		}
}

int getC(int x,int y)
{
		return 1ll*fac[x]*inv[y]%Mo*inv[x-y]%Mo;
}

int main()
{
		fac[0]=1;
		for (i=1;i<N;++i) fac[i]=1ll*fac[i-1]*i%Mo;
		for (i=0;i<N;++i) inv[i]=power(fac[i],Mo-2);
		scanf("%s",c+1);
		scanf("%s",s+1); n=strlen(c+1);
		for (i=1;i<=n;++i) if (c[i]=='1'&&s[i]=='1') AA++;
							else if (c[i]!=s[i]) BB++;
		BB/=2;
		for (NN=1;NN<n;NN<<=1); NN<<=1; 
		w[0][0]=1; w[0][1]=power(g,(Mo-1)/NN);
		for (i=2;i<N;++i) w[0][i]=1ll*w[0][i-1]*w[0][1]%Mo;
		for (i=0;i<N;++i) w[1][i]=power(w[0][i],Mo-2);
 		for (i=0;i<NN;++i) 
 		{
 				for (j=1,k=i;j<NN;j<<=1,k>>=1) (rev[i]<<=1)|=(k&1);
 		}
 		for (i=0;i<=AA;++i) A[i]=B[i]=inv[i+1];
 		C[0]=1;
		for (j=0;(1<<j)<=BB;++j)
		{
			if (BB&(1<<j)) 
			{
					NTT(C,0); NTT(A,0);
					for (i=0;i<NN;++i) C[i]=1ll*C[i]*A[i]%Mo;
					NTT(C,1); NTT(A,1);
					for (i=AA+1;i<NN;++i) C[i]=0;
			}
			memset(B,0,sizeof(B));
			for (i=0;i<=AA;++i) B[i]=A[i];
			NTT(A,0); NTT(B,0);
			for (i=0;i<NN;++i) A[i]=1ll*A[i]*B[i]%Mo;
			NTT(A,1);
			for (i=AA+1;i<NN;++i) A[i]=0;
		}
		int ans=0;
		for (i=0;i<=AA;++i)
		{
			int sum=1ll*fac[BB]*fac[i+BB]%Mo*C[i]%Mo;
			sum=1ll*sum*getC(AA,i)%Mo*getC(AA+BB,i+BB)%Mo;
			sum=1ll*sum*fac[i]%Mo;
			sum=1ll*sum*fac[AA-i]%Mo*fac[AA-i]%Mo;
			(ans+=sum)%=Mo;
		}
		printf("%d\n",ans);
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

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

	ll X,Y,Z,K;
	cin >> X >> Y >> Z >> K;
	vector<ll> A(X),B(Y),C(Z),D,E;
	FOR(i,0,X)cin>>A[i];
	FOR(i,0,Y)cin>>B[i];
	FOR(i,0,Z)cin>>C[i];
	FOR(i,0,X){
		FOR(j,0,Y){
			D.push_back(A[i]+B[j]);
		}
	}
	SORT(D);
	REV(D);
	FOR(i,0,min(X*Y,K)){
		FOR(j,0,Z){
			E.push_back(D[i]+C[j]);
		}
	}
	SORT(E);
	REV(E);
	FOR(i,0,K){
		cout << E[i] << endl;
	}
}

Measured memory_bytes: 43240
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define rep(i,x) for(int (i)=1;(i)<=(x);(i)++)
#define repp(i,x,y) for(int (i)=(x);(i)<=(y);(i)++)
#define forn(i,x) for(int (i)=0;(i)<(x);(i)++)
#define foreach(i,x) for(auto (i):(x))
using namespace std;
typedef pair<int,int>pii;
int n;
int a[100010];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++){
		if(a[i]%2!=0){
			puts("first");
			return 0;
		}
	}
	puts("second");
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	ll a, b;
	cin >> a >> b;
	ll x = a, y = b;
	string strx, stry;
	bool swapflag = false;
	
	if( x < y ){
		swap(x, y);
		swap(a, b);
		swapflag = true;
	}
	
	ll r;
	while( r = x%y ){
		x = y;
		y = r;
	}
	ll kgV = a*b/y;
	
	if( swapflag ){
		cin >> stry >> strx;
	} else {
		cin >> strx >> stry;
	}
	
	for( int i = 0; i < y; ++i ){
		if( strx[a/y*i] != stry[b/y*i] ){
			cout << "-1" << endl;
			return 0;
		}
	}
	
	cout << kgV << endl;
	return 0;
}

Measured memory_bytes: 512
from collections import deque
S=input()
q=int(input())
Q=[]
state=True
ans=deque(S)
for _ in range(q):
    t = input().split()
    if t[0] == "1":
        Q.append(int(t[0]))
    elif t[0] == "2":
        Q.append((int(t[0]),int(t[1]),t[2]))
for que in Q:
    if que == 1:
        state = not state
    else:
        if state:
            if que[1] == 1:
                ans.appendleft(que[2])
            else:
                ans.append(que[2])
        else:
            if que[1] == 2:
                ans.appendleft(que[2])
            else:
                ans.append(que[2])
anss=""
if not state:
    while len(ans) >0:
        anss += ans.pop()
else:
    while len(ans) >0:
        anss += ans.popleft()
print(anss)


Measured memory_bytes: 22480
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return x;}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in()-1ll;
	vector<char> C,D(26);
	iota(ALL(D),'a');
	//rotate(D.begin(),D.begin()+25,D.end());
	while(N>=0){
		ll X = (N)%26ll;
		C.push_back(D[X]);
		N /= 26ll;
		N--;
	}
	if(C.empty()) C.push_back('a');
	reverse(ALL(C));
	for(auto& x:C) cout<<x;
	out();
	return 0;
}


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

using namespace std;

int a[505], b[505], ans = 0, n, k;

void solve(const int x) {
  long long sum = 0LL;
  for (int i = 1; i <= n; ++i) {
    sum += a[i] - a[i] / x * x;
    b[i] = (a[i] / x + 1) * x - a[i];
  }
  sort(b + 1, b + 1 + n);
  long long bsum = 0LL;
  for (int i = 1; i <= sum / x; ++i)
    bsum += b[i];
  if (sum - sum / x * x + bsum <= k)
    ans = max(ans, x);
  else if (sum / x < n && bsum + b[sum / x + 1] <= k)
    ans = max(ans, x);
  return;
}

int main(void) {
  long long sum = 0LL;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i)
    sum += a[i];
  for (int i = 1; i * i <= sum; ++i)
    if (sum % i == 0) {
      solve(i);
      solve(sum / i);
    }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
//
//三井住友信託銀行プログラミングコンテスト2019
//D
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    int ans=0;
    REP(i,10){
        int ip=-1;
        REP(fi,n){
            if (i==(s[fi]-48)) {
                ip = fi;
                break;
            }
        }
        if (ip==-1) continue;
        
        REP(j,10){
            int jp=-1;
            FOR(fj, ip+1, n-1){
                if (j==(s[fj]-48)) {
                    jp = fj;
                    break;
                }
            }
            if (jp==-1) continue;

            REP(k,10){
                FOR(fk, jp+1, n-1){
                    if (k==(s[fk]-48)) {
                        //cout << i << " " << j << " " << k << endl;
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  if (n == 3) {
    cout << "2 5 63" << endl;
    return 0;
  }
  vector<int> c;
  c.push_back(2);
  c.push_back(4);
  for (int i = 3; i <= 30000; ++i) {
    if (i % 6 == 3) {
      c.push_back(i);
    }
  }
  for (int i = 5; i <= 30000; ++i) {
    if (i % 6 == 2 || i % 6 == 4) {
      c.push_back(i);
    }
  }
  for (int i = 6; i <= 30000; ++i) {
    if (i % 6 == 0) {
      c.push_back(i);
    }
  }
  vector<int> ans;
  if (n % 2) {
    ans.push_back(c.back());
    c.pop_back();
    --n;
  }
  for (int i = 0; i < n; ++i) {
    ans.push_back(c[i]);
  }
  for (int i : ans) {
    cout << i << ' ';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 640
//
// Created by TakahiroYamaji on 2020/07/29.
//
#include<iostream>
#include<algorithm>
typedef long long ll;
typedef std::pair<int, int>P;
int N, M;
P p[100000];
bool comp(P& x, P& y){
    return x.second < y.second;
}

int main(){
    std::cin >> N >> M;
    for (int i=0;i<M;i++){
        std::cin >> p[i].first >> p[i].second;
    }
    std::sort(p, p+M, comp);
    int res = 1;
    int end = p[0].second;
    for (int i=1;i<M;i++){
        if (end > p[i].first) continue;
        else{
            res++;
            end = p[i].second;
        }
    }
    std::cout << res << std::endl;
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000
string s = "aeiou";

int main(){
    cin.sync_with_stdio(false);
    char c;
    cin >> c;

    bool ok = false;
    rep(i, 5) if (s[i] == c) ok = true;

    cout << ((ok) ? "vowel" : "consonant") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 310000
ll MOD=998244353;

int a[1100][1100];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int U[N],D[N],R[N],L[N];
main(){
    int h=in(),w=in(),n=in();
    int x=in(),y=in();
    string s,t;cin>>s>>t;
    int u=0,d=h+1;
    bool flag=false;
    rep3(i,n-1,0){
        if(t[i]=='U')d=min(d+1,h+1);
        else if(t[i]=='D')u=max(0,u-1);
        if(s[i]=='U')u++;
        else if(s[i]=='D')d--;
        if(u>=h||d<=1)flag=true;
        //cout<<u<<" "<<d<<endl;
    }
    int l=0,r=w+1;
    //U L
    //D R
    rep3(i,n-1,0){
        if(t[i]=='L')r=min(r+1,w+1);
        else if(t[i]=='R')l=max(0,l-1);
        if(s[i]=='L')l++;
        else if(s[i]=='R')r--;
        if(l>=w||r<=1)flag=true;
        //cout<<l<<" "<<r<<endl;
    }
    if(u>=x||d<=x||r<=y||l>=y)flag=true;
    cout<<(flag?"NO":"YES");
}



Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
    int n,x=0,ans=0;
    string s;
    cin>>n>>s;

    for(int i=0; i<n; i++){
        if(s[i]=='I') x++;
        else x--;
        ans = max(ans,x);
    }
    cout<<ans<<endl;
    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll H, W;
	cin >> H >> W;
	if (H == 1 || W == 1) cout << 1 << endl;
	else cout << ((H+1) / 2) * ((W+1) / 2) + (H/2) * (W/2) << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
bool used[9],d[9][9];
 
void dfs(int p,int c){
  if(c==n)ans++;
  used[p]=1;
  for(int i=1;i<=n;i++)
    if(!used[i]&&d[p][i])dfs(i,c+1);
  used[p]=0;
}
 
int main(){
  cin>>n>>m;
  for(int i=0,a,b;i<m;i++){
    cin>>a>>b;
    d[a][b]=d[b][a]=1;
  }
  dfs(1,1);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)

struct Point{
  double x,y;

  Point(){}
  Point(double x,double y) : x(x),y(y) {}

  Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
  Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
  Point operator * (const double &k)const{ return Point(x*k,y*k); }
  Point operator / (const double &k)const{ return Point(x/k,y/k); }
};

double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double norm(const Point &p){ return dot(p,p); }
double abs(const Point &p){ return sqrt(norm(p)); }

istream &operator >> (istream &is,Point &p){ 
  return is >> p.x >> p.y;
}

typedef Point Vector;

#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
typedef Point Vector;

int ccw(Point p0,Point p1,Point p2){
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if(cross(a,b) > EPS){ return COUNTER_CLOCKWISE; }
  if(cross(a,b) < -EPS){ return CLOCKWISE; }
  if(dot(a,b) < -EPS){ return ONLINE_BACK; }
  if(norm(a) < norm(b)){ return ONLINE_FRONT; }
  return ON_SEGMENT;
}

struct Segment{
  Point s,t;
  Segment(){}
  Segment(Point s,Point t) : s(s),t(t) {}
};

Point projection(Segment s,Point p){
  Vector b = s.t-s.s;
  double t = dot(p-s.s,b)/norm(b);
  return s.s+b*t;
}

bool isIntersectSP(const Segment &s,const Point &p){
  return equal(ccw(s.s,s.t,p),0);
}

bool isIntersectSS(const Segment &a,const Segment &b){
  Point s[2] = {a.s,a.t}, t[2] = {b.s,b.t};
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0
    && ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

double distanceSP(const Segment &s,const Point &p){
  Point r = projection(s,p);
  if(isIntersectSP(s,r)){ return abs(r-p); }
  return min(abs(s.s-p),abs(s.t-p));
}

double distanceSS(const Segment &a,const Segment &b){
  if(isIntersectSS(a,b)){ return 0; }
  return min(min(distanceSP(a,b.s),distanceSP(a,b.t)),
             min(distanceSP(b,a.s),distanceSP(b,a.t)));
}

int main(){
  int Q;
  Segment s1,s2;
  cin >> Q;
  while(Q--){
    cin >> s1.s >> s1.t >> s2.s >> s2.t;
    printf("%.10f\n",distanceSS(s1,s2));
  }
  return 0;
}

Measured memory_bytes: 1248
/*
             ██████  ██████
             ██   ██ ██   ██
 Author ->   ██████  ██   ██
             ██      ██   ██
             ██      ██████
 
    nik is love.
    nik is motivation.
    Use modulus operator very carefully.
    Watch for integer overflows.
*/
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                   0.000000001
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define endl                 '\n'
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> val(300010,1),vis(300010,0),dis(300010,-1),mini(300010,inf);
vector<pair<int,int>> adj[110];
int seg[5010][5010];
int myrandom (int i) { return std::rand()%i;}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int n;
    cin>>n;
    map<string,int> mt;
    int maxi=0;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        mt[s]++;
        maxi=max(maxi,mt[s]);
    }
    auto itr=mt.begin();
    while(itr!=mt.end())
    {
        if(itr->ss==maxi)
        {
            cout<<itr->ff<<endl;
        }
        itr++;
    }
    
}


Measured memory_bytes: 28544
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

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

	vector<ll>a(n);

	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());

	vector<ll> t(a[n - 1] + 1);

	for (ll i = 0; i < a[n - 1] + 1; i++) {
		t[i] = 0;
	}

	for (ll i = 0; i < n; i++) {
		for (ll j = 1; a[i] * j <= a[n - 1]; j++) {
			if (t[a[i] * j] == 2) {
				continue;
			}
			t[a[i] * j] += 1;

		}
	}

	int h = 0;

	for (ll i = 0; i < n; i++) {

		if (t[a[i]] == 1) {
			h++;
		}
	}

	cout << h;
	return 0;
}

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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    ll S;
    cin >> S;
    ll x1,y1,x2,y2;

    ll t = 1000000000;
    ll tmp;
    if (S%t!=0) {
        tmp = S + t;
    }
    else {
        tmp = S;
    }

    x1 = t;
    y2 = tmp/t;

    ll res = x1*y2 - S;
    x2 = res;
    y1 = 1;

    cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;


}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; cin >> N;
  vector<int> A(N); cin >> A;
  map<int, int> m;
  rep(i, N) {
    m[i] = A[i];
  }
  ll ans = 0;
  for (auto& e: m) {
//    cout << e.first << " - " << e.second << "\n";
    if (e.second > 1) {
      ans += e.second / 2;
      e.second -= e.second / 2 * 2;
    }
    if (e.second == 1 && m[e.first + 1]) {
      ans++;
      e.second--;
      m[e.first + 1]--;
    }
//    cout << ans << ", " << e.first << " - " << e.second << "\n";
  }
  cout << ans << endl;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    string x;
    cin >> x;

    ll c = 0;
    ll cs = 0;
    rep(i, 0, x.size()){
        if(x[i] == 'S'){
            cs++;
        }else if(x[i] == 'T' && cs > 0){
            cs--;
            c += 2;
        }
    }

    cout << x.size() - c << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  char a,b,c,d;
  cin>>a>>d>>d>>d>>b>>d>>d>>d>>c;
  cout<<a<<b<<c;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = list()
b = list()

for i in range(n):
    a.append(list(map(int, input().split())))

for i in range(m):
    b.append(int(input()))

for i in range(n):
    ans = 0
    for j in range(m):
        ans += a[i][j] * b[j]
    print(ans)



Measured memory_bytes: 6008
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#define PB push_back
using LL = long long;
using namespace std;

const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};
const double EPS = 1e-10;
const double PI = acos(-1.0);

signed main(){
     //cin.tie(0);
     //ios::sync_with_stdio(false);
     vector<string> blue;
     vector<string> red;

     int N;
     cin >> N;
     REP(i, N){
         string temp;
         cin >> temp;
         blue.PB(temp);
     }
     int M;
     cin >> M;
     REP(i, M){
         string temp;
         cin >> temp;
         red.PB(temp);
     }

     int count = 0;
     int countBefor = -101;
     int res = 0;
     for (string blueStr: blue){
         for (string comp: blue){
             if (blueStr == comp) count++;
             //cout << blueStr << " : " << comp<< '\n';
             dump(count)
         }
         for (string comp: red){
             if (blueStr == comp) count--;
             //cout << blueStr << " : " << comp<< '\n';
             dump(count)
         }

         if(count>countBefor){
             res = count;
             countBefor = count;
         }
         dump(res)
         count = 0;

     }
     if (res<0) res = 0;

     cout << res << endl;

}


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

#define M 1000005/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;//文字が4種類のためp*=5するとどの文字列のパターンでもkeyの値は被らない
  }
  return sum;
}

int h1(int key){ return key%M; }//ハッシュ値を返す
int h2(int key){ return 1+(key%(M-1)); }//衝突が起きた場合のハッシュ値

int find(char str[]){
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0) return 1;//ハッシュ値の場所に同じ文字列が格納されていた場合
		else if(strlen(H[h])==0) return 0;//空だった場合
	}	
	return 0;//ハッシュ値が示す位置に文字列がなかった場合

}

int insert(char str[]){
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0) return 1;//同じ文字列が前に格納されていた場合
		else if(strlen(H[h])==0){//ハッシュ値の示す箱が空だった場合
			strcpy(H[h],str);//格納
			return 0;
		}
	}
	return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}


Measured memory_bytes: 15444
x, n = gets.chomp.split(" ").map(&:to_i)
arr = gets.chomp.split(" ").map(&:to_i)

if !arr.include?(x)
  puts x
else
  size = [x, 100-x].max
  for i in 1..size do
    small = x-i 
    big = x+i
    if !arr.include?(small)
      puts small
      break
    end
    if !arr.include?(big)
      puts big
      break
    end
  end
end

Measured memory_bytes: 14368