akhauriyash/Code-Regression huggingface dataset:
def main():
    dic = {}

    n = int(input())
    for _ in range(n):
        nome = input()
        try:
            dic[nome] += 1
        except KeyError:
            dic[nome] = 1

    resp = []
    Max = 0
    
    for nome, voto in dic.items():
        if voto > Max:
            Max = voto
            resp = [nome]
            
        elif voto == Max:
            resp.append(nome)

    resp.sort()
    print('\n'.join(resp))

main()

Measured memory_bytes: 147376
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int N;
int A[20], B[20];
int DP[(1<<20)][20];

int solve(int S, int x) {
  if(DP[S][x]>0) return DP[S][x];
  if(S==0) {
    return DP[S][x] = x;
  }
  DP[S][x] = inf;
  int pos = -1; // Sのうちビットが立っているものの最後の要素のインデックス
  for(int i=0;i<N;++i) {
    if((S&(1<<i))!=0) pos++;
  }
  int num = 0;
  for(int i=0;i<x;++i) {
    if((S&(1<<i))==0) num++;
  }
  int tmp1, tmp2;
  for(int i=0;i<N;++i) {
    if((S&(1<<i))==0) continue;
    if((i-pos)%2==0) tmp1 = A[i]; 
    else tmp1 = B[i];
    if((x-(pos+1))%2==0) tmp2 = A[x];
    else tmp2 = B[x];
    if(tmp1>tmp2) continue;
    DP[S][x] = min(DP[S][x], solve((S^(1<<i)), i)+num);
  }
  return DP[S][x];
}

int main() {
  cin>>N;
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=0;i<N;++i) cin>>B[i];
  int S = (1<<N) - 1;
  int ans = inf;
  for(int i=0;i<N;++i) {
    ans = min(ans, solve(S^(1<<i), i));
  }
  if(ans==inf) cout<<-1<<endl;
  else cout<<ans<<endl;
}



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

int main(){
	double ans;
	int n, k;
	cin >> n >> k;
	rep(i, n){
		double t_ans = 1./n;
		//cerr << t_ans << endl;
		int s = i+1;
		while(s < k){
			s *= 2;
			t_ans *= 0.5;
		}
		//cerr << t_ans << endl;
		ans += t_ans;
	}
	
	printf("%.12f\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int timer = b-c;
    if(b>d)timer = timer + d - b;
    if(a>c)timer = timer + c - a;
    if(timer<0)timer=0;
    cout << timer << endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
int a,b,c, tmp;

cin>> a >> b >>c;
if(a>b) {tmp=a; a=b; b=tmp;}
if(b>c) {tmp=b; b=c; c=tmp;}
if(a>b) {tmp=a; a=b; b=tmp;}
printf("%d %d %d\n",a,b,c);
}


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

int main() {
    int n, p;
    cin >> n >> p;
    vector<vector<int>> graph(n, vector<int>(0));
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    vector<int> score(n);
    for (int i = 0; i < p; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        score[a] += b;
    }
    vector<bool> seen(n, false);
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        seen[0] = true;
        int v = q.front();
        q.pop();
        for (int nv : graph[v]) {
            if (seen[nv]) continue;
            seen[nv] = true;
            score[nv] += score[v];
            q.push(nv);
        }
    }
    for (int i : score) cout << i << endl;
}


Measured memory_bytes: 16084
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

long long dpfibo(int n){
    long long F[44];
    F[0] = F[1] = 1;
    if(n == 0 or n == 1) return 1;
    for(int i = 2; i <= n; ++i){
        F[i] = F[i-1] + F[i-2];
    }
    return F[n];
}

int main(){
    int n;
    scanf("%d", &n);
    cout << dpfibo(n) << endl;
    return 0;
}



Measured memory_bytes: 3236
l = [0]*100005
n = int(raw_input())
for x in xrange(n):
	a = map(int,raw_input().strip().split())
	for y in xrange(a[0],a[1]+1):
		l[y] = 1
ans = 0
for x in l:
	if x == 1:
		ans += 1
print(ans)

Measured memory_bytes: 3332
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <utility>
#include <set>

using namespace std;

bool is[100005];

int main()
{
    int K;

    cin >> K;

    typedef pair<int, int> pii;

    deque<pii> dq;

    dq.push_front(make_pair(1, 1));

    while (1)
    {
        pii o = dq[0];
        dq.pop_front();
        int nk1, nk2;
        int ok = o.first;
        is[ok] = true;
        int oc = o.second;

        if (ok == 0)
        {
            cout << oc << endl;
            break;
        }

        nk1 = (ok * 10) % K;
        nk2 = (ok + 1) % K;
        if (is[nk1] == false)
        {
            dq.push_front(make_pair(nk1, oc));
        }
        if (is[nk2] == false)
        {
            dq.push_back(make_pair(nk2, oc + 1));
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<int>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=405,mod=998244353;
const ll mod2=(ll)mod*mod*8;
ll F[N][N],G[N][N],ff[N],gg[N],pw[N];
int sz[N],n,h[N],q[N],ch[N][2],f[N],g[N];
inline void add(ll &a,ll b){
	a+=b; if(a>=mod2)a-=mod2;
}
void dfs(int p,int H){
	sz[p]=1;
	F[p][0]=1; G[p][0]=1; G[p][1]=mod-1;
	For(i,0,1)if(ch[p][i]){
		int v=ch[p][i];
		dfs(v,h[p]);
		For(j,0,sz[p]){
			For(k,0,sz[v]){
				add(ff[j+k],F[p][j]*F[v][k]);
				add(gg[j+k],G[p][j]*G[v][k]);
			}
		}
		sz[p]+=sz[v];
		For(j,0,sz[p]){
			F[p][j]=ff[j]%mod; G[p][j]=gg[j]%mod; ff[j]=gg[j]=0;
		}
	}
	For(i,1,h[p]-H){
		For(j,1,sz[p]){
			F[p][j]=(F[p][j]*(pw[sz[p]-j]-1)+G[p][j])%mod;
			G[p][j]=G[p][j]*pw[sz[p]-j]%mod;
		}
		F[p][0]=F[p][0]*pw[sz[p]]%mod;
		G[p][0]=G[p][0]*pw[sz[p]]%mod;
	}
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	n=read();
	For(i,1,n)h[i]=read();
	For(i,pw[0]=1,n)pw[i]=pw[i-1]*2%mod;
	int top=0;
	For(i,1,n+1){
		while(h[q[top]]>h[i])g[q[top--]]=i;
		f[i]=q[top]; q[++top]=i;
	}
	For(i,1,n)if(h[f[i]]<=h[g[i]])ch[g[i]][0]=i; else ch[f[i]][1]=i;
	int rt=ch[n+1][0]; 
	dfs(rt,0);
	ll ans=0;
	For(i,0,n)ans+=F[rt][i];
	cout<<ans%mod<<endl;
}
/*
F[i][j] 表示 i 子树，有 j 列禁止点
G[i][j] 表示 i 子树，最下面放了 j 列禁止点 
*/


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int N;
	cin>>N;
	
	vector<long long> A(1<<N);
	
	long long B = 1000000;
	
	for(int i=0;i<(1<<N);i++){
		cin>>A[i];
		A[i]*=B;
		A[i]+=i;
	}
	
	vector<vector<pair<long long,long long>>> dp((1<<N),vector<pair<long long,long long>> (N+1));
	
	for(int i=0;i<=N;i++){
		for(int j=0;j<(1<<N);j++){
			if(i==0){
				dp[j][i] = make_pair(0,A[j]);
			}
			else{
				vector<long long> V;
				V.push_back(dp[j][i-1].first);
				V.push_back(dp[j][i-1].second);
				if((j>>(i-1))&1){
					V.push_back(dp[j&(~(1<<(i-1)))][i-1].first);
					V.push_back(dp[j&(~(1<<(i-1)))][i-1].second);
				}
				sort(V.rbegin(),V.rend());
				V.erase(unique(V.begin(),V.end()),V.end());
				dp[j][i].first = V[0];
				dp[j][i].second = V[1];
			}
		}
	}
	
	vector<long long> ans(1<<N);
	
	for(int i=0;i<(1<<N);i++){
		ans[i] = dp[i][N].first/B + dp[i][N].second/B;
		if(i!=0)ans[i] = max(ans[i],ans[i-1]);
	}
	
	for(int i=1;i<(1<<N);i++){
		cout<<ans[i]<<endl;
	}
	
	
	
    return 0;
}

Measured memory_bytes: 96896
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int N;
string S;

int solve() {
    int allE = 0, allW = 0;
    for (int i = 0; i < (int)S.size(); ++i) {
        if (S[i] == 'E') ++allE;
        else ++allW;
    }
    int res = (int)S.size();
    int curE = 0, curW = 0;
    for (int i = 0; i < (int)S.size(); ++i) {
        int migiE = allE - curE;
        if (S[i] == 'E') --migiE;
        chmin(res, curW + migiE);
        
        if (S[i] == 'E') ++curE;
        else ++curW;
    }
    
    return res;
}

int main() {
    while (cin >> N >> S) {
        cout << solve() << endl;
    }
}

















Measured memory_bytes: 900
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e16;
const double EPS=1e-8;
const ll mod = 1000000007;

int64_t powm(int64_t a,int64_t b){//a^bを求める
	if(b==0){
		return 1;
	}else{
		int64_t temp = powm(a,b/2);
		temp = temp * temp;
		if(b%2==1){
			temp = temp * a;
		}
		return temp;
	}
}

int main(){
	ll n;
	cin>>n;
	vector<string> c;
	for(ll i1=0;i1<n;i1++){
		string temp;
		cin>>temp;
		sort(temp.begin(),temp.end());
		c.push_back(temp);
	}

	ll ans=0;
	map<string,ll*> table;
	for(ll i1=0;i1<n;i1++){
		auto iter = table.find(c[i1]);
		if(iter==table.end()){
			ll *temp = new ll;
			*temp=1;
			table.insert(std::make_pair(c[i1],temp));
		}else{
			ans += *(iter->second);
			(*(iter->second))++;
		}
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 15092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> k >> n;
  vector<int>a(n);
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  int minn = 1<<30;
  for(i=0;i<n-1;i++){
    if(minn > k-(a[i+1]-a[i]))minn = k-a[i+1]+a[i];
  }
  if(minn > a[n-1]-a[0])minn = a[n-1]-a[0];
  cout<<minn << endl;


}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cerr << #x << " = " << x << endl

int main(int qtd, char* nome[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	int n;
	cin >> n;
	int a[n];
	map<int, int> mp;
	for(int i=0; i<n; i++)
		cin >> a[i], mp[a[i]]++;
	function<ll(int)> sum = [](const int &n) -> ll {
		return (n-1ll)*n/2ll;
	};
	ll mx = 0ll;
	for(auto it=mp.begin(); it!=mp.end(); it++)
		mx += sum(it->second);
	for(int i=0; i<n; i++)
		cout << mx-mp[a[i]]+1 << endl;
	
	return 0;
}

Measured memory_bytes: 10336
#include"iostream"
using namespace std;

int main()
{
	int n, ans;
	cin >> n;
	int a[100100], b[100100];
	for (int i = 0; i < 100100; i++)b[i] = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] < 100100)b[a[i]]++;
		else ans++;
	}
	for (int j = 0; j < 100100; j++)
	{
		if (b[j] < j)ans += b[j];
		else if (b[j] > j)ans += b[j] - j;
	}
	cout << ans << endl;
}

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

int main()
{
    unsigned long long int X;
    unsigned long long int sum = 0;
    cin >> X;

    for (int i = 1; i <= X; i++) {
        sum += i;
        if (sum >= X) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    queue<lint> lun;
    int n;cin>>n;
    lint x;
    for(lint i=1;i<10;i++)lun.push(i);
    for(int i=0;i<n;i++){
        x=lun.front();lun.pop();
        if(x%10!=0)lun.push(x*10+(x%10)-1);
        lun.push(x*10+(x%10));
        if(x%10!=9)lun.push(x*10+(x%10)+1);
    }
    cout<<x<<endl;
}


Measured memory_bytes: 5040
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007
#define PAI 3.14159265358979
// ver1.7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n;
  cin >> n;
  int b;
  cin >> b;
  int ans = b;
  rep(i,0,n-1){
    cin >> b;
    ans = lcm(ans,b);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int a,b,n;
bool area[18][18];
bool memo[18][18];
int dx[2] = {0,1};
int dy[2] = {1,0};
int cnt;


void dp(int x,int y){
	fill_n(*memo,18*18,0);
	if(x == a && y == b)cnt++;

	for(int i = 0;i < 2;i++){
		int nx = x + dx[i];
		int ny = y + dy[i];

		if(area[nx][ny])continue;

		dp(nx,ny);
	}
	return;
}

int main(){
	int x,y;
	while (cin >> a >> b >> n,a){
		fill_n(*area,18*18,1);
		cnt = 0;
		for(int i = 1;i <= b;i++){
			for(int j = 1;j <= a;j++){
				area[j][i] = 0;
			}
		}
		for(int i = 0;i < n;i++){
			cin >> x >> y;
			area[x][y]=1;
		}
		dp(1,1);
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
import math
n=int(input())
X=[int(x) for x in input().split()]
Y=[int(y) for y in input().split()]
d1=0
d2=0
d3=0
D=[]
for i in range(n):
    d1+=abs(X[i]-Y[i])
print(f'{d1:.6f}')
for i in range(n):
    d2+=abs(X[i]-Y[i])**2
print(f'{math.sqrt(d2):.6f}')
for i in range(n):
    d3+=abs(X[i]-Y[i])**3
print(f'{d3**(1/3):.6f}')
for i in range(n):
    D.append(abs(X[i]-Y[i]))
print(f"{max(D):.6f}")



Measured memory_bytes: 5712
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}


int main() {
	IOS;
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	cout << (s < t ? "Yes" : "No") << endl;
}



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

int main() {
	string s; cin >> s;
	
	int s_len = (int)s.size();
	int zero_cnt = count(s.begin(), s.end(), '0');
	int one_cnt = count(s.begin(), s.end(), '1');

	int ans = s_len - abs(zero_cnt - one_cnt);

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

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
#define rep(i,N) for(int i=0;i<(int)N;++i)
//cout << fixed << setprecision(20) << *** << endl;
typedef long long ll;
using namespace std;
//ユークリッド
ll gcd(ll a,ll b){
	ll t;
	if(a<b){
		t=a;
		a=b;
		b=t;
	}
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int main()
{
	ll A,B,C,D,ANS=0;
	cin>>A>>B;
	if(max(A,B)%min(A,B)==0){
		cout<<max(A,B)<<endl;
	}
	else{
		C=A;
		D=B;
		for(;;){
			if(C==D)break;
			else{
				if(C<D)C=C+A;
				else D=D+B;
			}
			//cout<<C<<":"<<D<<endl;
		}
		cout<<C<<endl;
	}
}

Measured memory_bytes: 504
n = int(input())

a = list(map(int, input().split()))


dict_odd = {}
dict_even = {}

for i in range(n):
  #リストの奇数番目、０始まりなのであまりは０
  if i %2 == 0:
    dict_odd[a[i]] = dict_odd.get(a[i], 0) + 1
  else:
    dict_even[a[i]] = dict_even.get(a[i], 0) + 1
    
#print(dict_odd, dict_even)    

v_odd_sorted = sorted(dict_odd.values())
v_even_sorted = sorted(dict_even.values())

odd_sorted = sorted(dict_odd.items(), key=lambda x : x[1])
even_sorted = sorted(dict_even.items(), key=lambda x : x[1])

#print(v_odd_sorted, v_even_sorted)    
ans = 0
#数字が一種類しかない場合は、一方を置き換える必要がある
if len(set(a)) == 1:
  ans = sum(v_odd_sorted)
  #print(sum(v_odd_sorted))
else:
  #偶数列と奇数列について、書き換えた後が同じ数字なら成立しないので、一方の書き換える先を次に多い数字にする
  if odd_sorted[-1][0] == even_sorted[-1][0]:
    comp1 = ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-2]) + v_even_sorted[-1]
    comp2 = ans = sum(v_even_sorted[:-1]) + sum(v_odd_sorted[:-2]) + v_odd_sorted[-1]
    ans = min([comp1, comp2])
    """
    if odd_sorted[-1][1] >= even_sorted[-1][1]:
      #偶数列を変更したほうが少ない場合
      ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-2]) + v_even_sorted[-1]
    else:
      #奇数列を変更したほうが少ない場合
      ans = sum(v_even_sorted[:-1]) + sum(v_odd_sorted[:-2]) + v_odd_sorted[-1]
      """
  else:
    ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-1])
print(ans)

Measured memory_bytes: 27932
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

    string s;
    int k;
    cin >> s >> k;
    set<string> result;
    for(int i = 0; i < s.size(); i++){
        for(int len = 1; len <= k && i+len <= s.size(); len++){
            result.insert(s.substr(i,len));
        }
    }
    auto itr = result.begin();
    rep(i,k) itr++;
    itr--;
    cout << *itr << endl;
}

Measured memory_bytes: 1664
import sys

input_list = input().split(" ")
input_list = list(map(int, input_list))

w = input_list[0]
h = input_list[1]
x = input_list[2]
y = input_list[3]
r = input_list[4]

if 0 <= x - r and x + r <= w:
    if 0 <= y - r and y + r <= h:
        print("Yes")
        sys.exit()

print("No")

Measured memory_bytes: 7672
a, b, c = gets.chomp.split.map(&:to_i)

remainders = [0]
while true do
  break if remainders[-1] == c

  remainders.push((remainders[-1] + a) % b)
  break if remainders[-1] == remainders[0]
end

ans = remainders[-1] == c ? "YES" : "NO"
puts ans

Measured memory_bytes: 1788
#include<stdio.h>
#include<string.h>
int main(){
  char S[20],T[20];
  scanf(" %s", S);
  scanf(" %s", T);

  int A, B;
  scanf("%d %d", &A, &B);
  
  char U[20];
  scanf(" %s", U);

  if(strcmp(S,U)==0){
    A= A-1;
    printf("%d %d", A, B);
  }
  else if(strcmp(T,U)==0){
    B=B-1;
    printf("%d %d", A, B);
  } else{} 
  return 0;
}

Measured memory_bytes: 1704
//a,b,...,z をそれぞれ根とするmap木構造の深さに帰結できるかな？
#include<bits/stdc++.h>
using namespace std;

int ans=0;

void tree(int &n, string &s, vector<int> &v, int count){
  if (v.size()==1) return;
  count++;
  map<char,vector<int>> nm;
  for (auto i: v){
    int j=i+count;
    if (j<n) nm[s[j]].push_back(i);
    else ans=max(ans,min(count,i-v[0])); //j==nの処理が悪かった？
  }
  for (auto i: nm){
    auto nv=i.second;
    if (nv.size()==1){
      for (auto j: v){ //かぶり判定の処理が悪かった？（比較対象はv[v.size()-1]だけじゃない）
        if (ans>=count) break;
        ans=max(ans,min(count,abs(j-nv[0])));
      }
    }
    tree(n,s,nv,count);
  }
}


int main(){
  int n;
  string s;
  cin>> n >> s;
  
  map<char,vector<int>> m;
  for (int i=0; i<n; i++) m[s[i]].push_back(i);
  
  int count=0;
  for (auto i: m){
    tree(n,s,i.second,count);
  }
  
  cout<< ans <<endl;
}

Measured memory_bytes: 160896
import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

/*
 *      /\\\        /\\\      /\\\\\\\\\      /\\\\\\\\\\\   /\\\\\\\\\\\\\     /\\\        /\\\      /\\\\\\\\\      /\\\        /\\\
 *      \/\\\       \/\\\    /\\\\\\\\\\\\\   \/////\\\///   \/\\\/////////\\\  \/\\\       \/\\\    /\\\\\\\\\\\\\   \/\\\       \/\\\
 *       \//\\\      /\\\    /\\\/////////\\\      \/\\\      \/\\\       \/\\\  \/\\\       \/\\\   /\\\/////////\\\  \//\\\      /\\\
 *         \//\\\    /\\\    \/\\\       \/\\\      \/\\\      \/\\\\\\\\\\\\\\   \/\\\\\\\\\\\\\\\  \/\\\       \/\\\   \//\\\    /\\\
 *           \//\\\  /\\\     \/\\\\\\\\\\\\\\\      \/\\\      \/\\\/////////\\\  \/\\\/////////\\\  \/\\\\\\\\\\\\\\\    \//\\\  /\\\
 *             \//\\\/\\\      \/\\\/////////\\\      \/\\\      \/\\\       \/\\\  \/\\\       \/\\\  \/\\\/////////\\\     \//\\\/\\\
 *               \//\\\\\       \/\\\       \/\\\      \/\\\      \/\\\       \/\\\  \/\\\       \/\\\  \/\\\       \/\\\      \//\\\\\
 *                 \//\\\        \/\\\       \/\\\   /\\\\\\\\\\\  \/\\\\\\\\\\\\\/   \/\\\       \/\\\  \/\\\       \/\\\       \//\\\
 *                   \///         \///        \///   \///////////   \/////////////     \///        \///   \///        \///         \///
 */
public class Main implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(),"Main",1<<27).start();
    }
    @Override
    public void run() {
        try{
            FastReader sc = new FastReader();
            int n = sc.nextInt();
            System.out.println(LongStream.rangeClosed(1, n).filter(a -> ((a%3!=0) && (a%5!=0))).sum());

        }
        catch (Exception e){}
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

int main()
{
  vector<int64_t> L;
  L={2,1};
  int64_t result=0;
  int N=0;
  
  scanf("%d", &N);
  if(N!=0 && N!=1)
  {
    for(int i=2; i<=N; i++)
    {
      result=L.at(i-2)+L.at(i-1);
      L.push_back(result);
    }

  }
  printf("%ld",L.at(N));
  
  
  

}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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


    int n;
    cin>>n;
    vi p(n);
    rep(i,n){
        cin>>p[i];
    }

    int m=inf;
    int ans=0;

    rep(i,n){
        if(p[i]<=m){
            m=p[i];
            ans++;
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
#include <list>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define COSTMAX A * N

ll llmin(ll a, ll b){
  return a < b ? a : b;
}

int main(){
  ll N, A, B;
  cin >> N >> A >> B;
  ll idx[N];
  rep(i, N){
    ll p;
    cin >> p;
    idx[p-1] = i;
  }

  ll dp[N][N+1];
  rep(i, N) rep(j, N+1) dp[i][j] = COSTMAX;
  if(idx[0] == 0){
    dp[0][0] = 0;
  } else{
    dp[0][0] = B;
    dp[0][idx[0]] = 0;
  }

  rep(a, N-1){
    rep(b, N+1){
      if(dp[a][b] == COSTMAX) continue;
      if(b <= idx[a+1]){
        dp[a+1][b] = llmin(dp[a+1][b], dp[a][b] + B);
        dp[a+1][idx[a+1]] = llmin(dp[a+1][idx[a+1]], dp[a][b]);
      }
      else{
        dp[a+1][b] = llmin(dp[a+1][b], dp[a][b] + A);
      }
    }
  }
  ll ans = llmin(A, B) * N;
  rep(i, N+1) ans = llmin(ans, dp[N-1][i]);
  cout << ans << endl;
  // rep(i, N){
  //   rep(j, N+1) cout << dp[i][j] << " ";
  //   cout << endl;
  // }
  return 0;
}


Measured memory_bytes: 195584
/**
 *    author:  FromDihPout
 *    created: 2020-08-25
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    long long sum = 0;
    for (char c : s) {
        sum += c - '0';
    }
    if (sum % 9 == 0) {
        cout << "Yes" << '\n';
    }
    else {
        cout << "No" << '\n';
    }
    return 0;
}

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

int main(){
  const int Vmax= 100000;
  using pii= pair<int, int>;
  int N,buf;
  cin >> N;

  int Nhalf= N/2;

  vector<pii> odd;
  vector<pii> even;
  for(int i=0; i<=Vmax; i++){// 頻度をとるとき1-indexedのままにするため,ダミーを入れる
    odd.emplace_back(make_pair(i,0));
    even.emplace_back(make_pair(i,0));
  }
  for(int i=0; i<N; i+=2){
    cin >> buf;
    odd.at(buf).second++;

    cin >> buf;
    even.at(buf).second++;
  }

  auto comp= [](pii a, pii b){
    bool ans= (a.second != b.second) ? (a.second > b.second)
                                     : (a.first  > b.first);
    return ans;
  };
  sort(odd.begin(), odd.end(), comp);
  sort(even.begin(), even.end(), comp);

  int ans= (odd.at(0).first != even.at(0).first ) ? (Nhalf- odd.at(0).second)+ (Nhalf- even.at(0).second)
          :(odd.at(1).second > even.at(1).second) ? (Nhalf- odd.at(1).second)+ (Nhalf- even.at(0).second)
                                                  : (Nhalf- odd.at(0).second)+ (Nhalf- even.at(1).second);

  cout << ans << endl;
}

Measured memory_bytes: 2036
import java.util.Scanner;

public class Main{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int g = sc.nextInt();
    int b = sc.nextInt();
    int num;

    num = r*100+g*10+b;
    if(num%4==0){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }

  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N,D,X[200000],Y[200000],i,res=0;
  cin >> N >> D;
  for(i=0;i<N;i++){
    cin >> X[i] >> Y[i];
    if(sqrt(X[i]*X[i]+Y[i]*Y[i])<=D){
      res++;
    }
  }
  cout << res;
}

Measured memory_bytes: 6732
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	ios_base::sync_with_stdio(0); cin.tie(0);
 	string s;
 	cin >> s;
 	for (int i = 0; i < (int) s.length(); i++) if (s[i] == '?') s[i] = 'D';
 	cout << s << '\n';
 	return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int result = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		result ^= a[i];
	}
	for (int i = 0; i < n; i++)
	{
		if (i != 0)
		{
			cout << ' ';
		}
		cout << (result ^ a[i]);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3992
#include<iostream>
using namespace std;
int main() {
	int a[4] = { 6000,4000,3000,2000 };
	int b, c;
	for (int i = 0; i < 4; i++) {
		cin >> b >> c;
		cout << a[b - 1] * c << endl;
	}
}

Measured memory_bytes: 3096
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] li = new long[n];
        for(int i = 0; i < n; i++){
            li[i] = sc.nextLong();
        }
        long ans = Long.MAX_VALUE;
        for(int i = 0; i < n-k+1; i++){
            long min = Math.min(Math.abs(li[i]),Math.abs(li[i+k-1])); 
            long max = Math.max(Math.abs(li[i]),Math.abs(li[i+k-1])); 
            if(li[i] < 0 && li[i+k-1] > 0){
                ans = Math.min(ans, max+min*2);
            }else{
                ans = Math.min(ans, max);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 57892
n,m = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
mod = 10**9 + 7

dp = [[0 for j in range(m+1)] for i in range(n+1)]

sum_dp = [[0 for j in range(m+1)] for i in range(n+1)]

dp[0][0] = 1
for i,x in enumerate(S):
    for j,y in enumerate(T):
        if x == y:
            dp[i+1][j+1] = sum_dp[i][j]+1
            dp[i+1][j+1] %= mod
        else:
            dp[i+1][j+1] = 0
        sum_dp[i+1][j+1] = sum_dp[i][j+1]+sum_dp[i+1][j]-sum_dp[i][j]+dp[i+1][j+1]
        sum_dp[i+1][j+1] %= mod

ans = 0
for i in range(n+1):
    #print(dp[i])
    ans += sum(dp[i])
    ans %= mod

print(ans)

Measured memory_bytes: 109148
#include <iostream>

using namespace std;

const int maxn = 1e5;
int a[maxn + 100], b[maxn + 100];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    long long sum = 0, ope1 = 0;
    for (int i = 0; i < n; i++){
        sum += a[i];
        if (i % 2 == 0 && sum <= 0){
            ope1 += 1 - sum;
            sum = 1;
        }
        if (i % 2 == 1 && sum >= 0){
            ope1 += sum + 1;
            sum = -1;
        }
    }
    sum = 0;
    long long ope2 = 0;
    for (int i = 0; i < n; i++){
        sum += a[i];
        if (i % 2 == 0 && sum >= 0){
            ope2 += sum + 1;
            sum = -1;
        }
        if (i % 2 == 1 && sum <= 0){
            ope2 += 1 - sum;
            sum = 1;
        }
    }
    cout << min(ope1, ope2) << endl;
}


Measured memory_bytes: 1024
#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 all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

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

        ll m = n % k;

        cout << min(m, abs(m - k)) << endl;

        return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
int N;

int main(int argc, char ** argv) {
	scanf("%d", &N);
	printf("%d\n", (N*(N+1))/2);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

const i64 rhmod = 1e9 + 7;
const i64 BASE_C = 2;
const i64 base[] = {9973, 10007};

struct rolling_hash {
  i64 n;
  vector<i64> hs[BASE_C], pw[BASE_C];
  
  template<class Array>
  rolling_hash(const Array& arr) {
    n = arr.size();
    for(int i = 0;i < BASE_C;i++) {
      hs[i].assign(n + 1, 0);
      pw[i].assign(n + 1, 0);
      hs[i][0] = 0;
      pw[i][0] = 1;
      for(int j = 0;j < n;j++) {
        pw[i][j + 1] = pw[i][j] * base[i] % rhmod;
        hs[i][j + 1] = (hs[i][j] * base[i] + arr[j]) % rhmod;
      }
    }
  }

  pair<i64, i64> hash(i64 l, i64 r) {
    return {
      ((hs[0][r + 1] - hs[0][l] * pw[0][r + 1 - l]) % rhmod + rhmod) % rhmod,
      ((hs[1][r + 1] - hs[1][l] * pw[1][r + 1 - l]) % rhmod + rhmod) % rhmod,
    };
  }
};

int main() {
  i64 N;
  cin >> N;
  string s;
  cin >> s;
  rolling_hash rh(s);

  i64 OK = 0;
  i64 NG = N;

  while(abs(OK - NG) > 1) {
    i64 m = (OK + NG) / 2;

    i64 bl = false;
    multiset<pair<i64, i64>> st;
    for(i64 i = 0; i + m + m - 1 < N; i++) {
      st.insert(rh.hash(i, i + m - 1));
      if(st.count(rh.hash(i + m, i + m + m - 1))) {
        bl = true;
        break;
      }
    }
    if(bl) {
      OK = m;
    }
    else {
      NG = m;
    }
  }
  cout << OK << endl;
}


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

signed main() {
  string S;
  cin >> S;
  
  int ans = 0;
  int count = 0;
  int B = 0; //Bが何個現れたか
  for( int i = S.size()-1; i >= 0; i-- ){
    if( S.at(i) == 'B' ){
      ans += count-B;
      B++;
    }
    count++;
  }
  cout << ans << endl;
    
}


Measured memory_bytes: 640
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,a;
	cin>>n;
	int num[100001];
	rep(i,100001)num[i]=0;
	rep(i,n){
		cin>>a;
		num[a-1]++;
		num[a]++;
		num[a+1]++;
	}
	int ans=0;
	rep(i,100001){
		ans=max(ans,num[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll factorial[201000];
ll invfactorial[201000];

ll extGCD(ll a, ll b, ll &x, ll &y){
	if (b == 0){
		x = 1;
		y = 0;
		return a;
	}
 
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

ll nCrM(ll n, ll r){
	ll ret = factorial[n];
	ret *= invfactorial[n - r];
	ret %= MOD;
	ret *= invfactorial[r];
	ret %= MOD; 
	return ret;
}
ll modpow(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b & 1){
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        b >>= 1;
    }
    return res;
}
int main(void){
    ll n, a, b;
    cin >> n >> a >> b;
    factorial[0] = 1;

    for (int i = 1; i < 201000; i++){
        factorial[i] = (factorial[i - 1] * i) % MOD;
    }
    for (int i = 0; i < 201000; i++){
        ll x, y;
        ll g = extGCD(factorial[i], MOD, x, y);
        while (x < 0) x += MOD;
        x %= MOD;
        invfactorial[i] = x;
    }

    ll faca = n;
    for(ll i = n - 1; i > n - a; i--){
        faca *= i;
        faca %= MOD;
    }

    ll facb = n;
    for(ll i = n - 1; i > n - b; i--){
        facb *= i;
        facb %= MOD;
    }

    ll ans = modpow(2LL, n) % MOD - 1;
    ans %= MOD;
    ll useab = ((faca * invfactorial[a]) % MOD) + ((facb * invfactorial[b]) % MOD);
    useab %= MOD;
    ans -= useab;
    ans %= MOD;
    if(ans < 0) ans += MOD;
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

LL dp[1001][1001];


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

    int H, W;
    cin >> H >> W;
    vector<string> a(H);

    rep(i, H) cin >> a[i];

    dp[0][0] = 1;
    rep(y, H) rep(x, W) {
        if (x == 0 && y == 0) continue;
        if (a[y][x] == '.') {
            int top = (y ? dp[y-1][x] : 0);
            int left = (x ? dp[y][x-1] : 0);
            dp[y][x] = (top + left) % MOD;
        } else {
            dp[y][x] = 0;
        }
    }

    cout << dp[H-1][W-1] << endl;


    return 0;
}


Measured memory_bytes: 9088
#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> pp;
const int INF = 1e9;
const int MOD = 1000000007;

 
int main() {
        int n;
        cin >> n;
        vector<int> a(n);
        rep(i,n){
                int b;
                cin >> b;
                a.at(i) = b-1;
        }
        //rep(i,n) cout << a.at(i) << endl;
        vector<ll> cnt(n,0);
        ll res = 0;
        rep(i,n){
                res += cnt[a[i]];
                cnt[a[i]] ++;
        }
        //cout << res << endl;
        rep(i,n){
                cout << res - cnt[a[i]] + 1 << endl;
        }
        
  return 0;
}




Measured memory_bytes: 4992
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
    #include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
    #define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
    #define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
    #define debug(x...)
    #define light_debug(x) 
#endif

template<typename T>
T& ckmin(T& a, T b){ return a = a > b ? b : a; }

template<typename T>
T& ckmax(T& a, T b){ return a = a < b ? b : a; }

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

string s, t;
pii nxt[3000][3000];
int dp[3000][3000];
bool ch[3000][3000];

int LCS(int i, int j){
	if(i == (int)s.size() || j == (int)t.size()) return 0;
	if(ch[i][j]) return dp[i][j];
	ch[i][j] = 1;
	if(s[i] == t[j]) {
		nxt[i][j] = {i + 1, j + 1};
		return dp[i][j] = 1 + LCS(i + 1, j + 1);
	}else{
		int x = LCS(i, j + 1), y = LCS(i + 1, j);
		nxt[i][j] = {i + (x < y), j + (x >= y)};
		return dp[i][j] = max(x, y);
	}
}

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    #ifdef DEBUG
        freopen("debug", "w", stderr);
    #endif
	
	cin >> s >> t;

	LCS(0, 0);

	string lcs;
	for(int i = 0, j = 0; i < (int)s.size() && j < (int)t.size(); tie(i, j) = nxt[i][j])
		if(s[i] == t[j]) lcs += s[i];
	
	cout << lcs << '\n';

    #ifdef DEBUG
        dbg::dout << "\nExecution time: " << clock() << "ms\n";
    #endif

    return 0;
}


Measured memory_bytes: 118276
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector< vector<int> > A(2, vector<int>(N+1));
    for(int i=0; i<2; i++) {
        for(int j=1; j<=N; j++) {
            cin >> A[i][j];
        }
        
    }

    for(int i=0; i<2; i++) {
        partial_sum(A[i].begin(), A[i].end(), A[i].begin());
    }

    int ans = 0;
    for(int j=1; j<=N; j++) {
        ans = max(ans, A[0][j] + A[1][N] - A[1][j-1]);
    }

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


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

using namespace std;

int main() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<vector<int>> train(n, vector<int>(n, 0));
	for (int i = 0; i < m; ++i) {
		int li, ri;
		cin >> li >> ri;
		li--; ri--;
		train[li][ri]++;
	}

	vector<vector<int>> score(n, vector<int>(n, 0));
	for (int st = 0; st < n; ++st) {
		score[st][st] = train[st][st];
		for (int en = st+1; en < n; ++en) {
			score[st][en] += score[st][en - 1];
			for (int k = st; k <= en; ++k) {
				score[st][en] += train[k][en];
			}
		}
	}
	for (int i = 0; i < q; ++i) {
		int pi, qi;
		cin >> pi >> qi;
		pi--; qi--;
		cout << score[pi][qi] << endl;
	}
	return 0;
}

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

namespace _3028
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int[] c = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int[] color = new int[x[0]]; int[] price = new int[x[0]];
			for (int i = 0; i < x[0]; i++)
			{
				int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
				color[i] = a[0] - 1; price[i] = a[1];
			}
			Array.Sort(price, color);
			Array.Reverse(color); Array.Reverse(price);
			int ret = 0;
			for (int i = 0; i < x[0] && x[1] > 0; i++)
			{
				if (c[color[i]] > 0)
				{
					x[1]--; ret += price[i];
					c[color[i]]--;
				}
			}
			Console.WriteLine(ret);
		}
	}
}


Measured memory_bytes: 30716
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int dp1[3004][3004];
int dp2[3004][3004];

int main(){
  int N, T;
  scanf("%d", &N);
  scanf("%d", &T);
  std::vector<int > A(N), B(N);
  int max=-1;
  int maxindex=-1;
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
    scanf("%d", &B[i]);
  }
  for (int i=0; i<3004; i++){
    for (int j=0; j<3004; j++){
      dp1[i][j]=-1;
      dp2[i][j]=-1;
    }
  }
  dp1[0][0]=0;
  dp2[N][0]=0;
  for (int i=0; i<N; i++){
    //printf("i1=%d\n", i);
    for (int j=0; j<=T; j++){
      if (j>0) dp1[i+1][j]=std::max(dp1[i+1][j-1], dp1[i+1][j]);
      if (dp1[i][j]!=-1){
	if (j+A[i]<=T) dp1[i+1][j+A[i]]=std::max(dp1[i+1][j+A[i]], dp1[i][j]+B[i]);
	dp1[i+1][j] = std::max(dp1[i+1][j], dp1[i][j]);
      }
    }
  }
  for (int i=N-1; i>=0; i--){
    //printf("i2=%d\n", i);
    for (int j=0; j<=T; j++){
      if (j>0) dp2[i+1][j]=std::max(dp2[i+1][j-1], dp2[i+1][j]);
      if (dp1[i+1][j]!=-1){
	if (j+A[i]<=T) dp2[i][j+A[i]]=std::max(dp2[i][j+A[i]], dp2[i+1][j]+B[i]);
	dp2[i][j] = std::max(dp2[i][j], dp2[i+1][j]);
      }
    }
  }
  int ans = -1;
  for (int k=0; k<N; k++){
    //printf("k=%d\n", k);
    int cand = -1;
    for (int j=1; j<T-1; j++){
      int val1 = std::max(dp1[k][j], 0);
      int val2 = std::max(dp2[k+1][T-j-1], 0);
      cand = std::max(cand, val1+val2);
      //if (val1+val2+B[k]>55) printf("k=%d, j=%d, %d + %d + B[%d](=%d)\n", k, j, dp1[k][j], dp2[k+1][T-j],k, B[k]);
    }
    ans = std::max(ans, cand+B[k]);
  }
  std::cout << ans << std::endl;
  return 0;
}
 

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

public class Program
{
    public static void Main()
    {
        var pad = "\0";
        var o = Console.ReadLine().AsEnumerable().Concat(pad);
        var e = Console.ReadLine().AsEnumerable().Concat(pad);

        var pwQuery = Enumerable.Zip(o, e, (co, ce) => new [] {co, ce})
            .SelectMany(x => x)
            .Where(x => x != '\0');
        var pw = string.Join("", pwQuery);

        Console.WriteLine(pw);
    }
}


Measured memory_bytes: 13396