akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
#include <set>
using namespace std;



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

    int ue[n];
    int shita[n];
    int ans = 0;

    for(int i = 0; i < n; i++) cin >> ue[i];
    for(int i = 0; i < n; i++) cin >> shita[i];

    for(int i = 0; i < n; i++)
    {
        int sum = 0;
        for(int j = 0; j < i + 1; j++)
        {
            sum += ue[j];
        }

        for(int k = i; k < n; k++)
        {
            sum += shita[k];
        }

        ans = max(ans, sum);
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cctype>
#include<cstring>
#include<utility>
const int inf=0x7fffffff;
typedef long long int ll;
using namespace std;
string s,p;
char ans[][10] ={
	"No",
	"Yes"
};
bool check(int b){
	int len=s.length();
	for(int i=0;i<p.length();i++){ 
		if(s[(b+i)%len]!=p[i])return 0;
	}
	return 1;
}
bool slove(){
	for(int i=0;i<s.length();i++){
		if(check(i))return 1;
	}
	return 0;
}
int main()
{
//#ifdef DEBUG
//	freopen("in", "r", stdin);
////	freopen("out", "w", stdout);
//#endif
	
	cin>>s>>p;
	printf("%s\n", ans[slove()]);
	//insert code above
	return 0;
}
//aoj1_8_d.cc

Measured memory_bytes: 1160
#include<stdio.h>
int main(void){
  char s[3];
  scanf("%s",&s);
  if(s[0]=='S'&&s[1]=='U'){printf("%d",7);}
  else if(s[0]=='M'){printf("%d",6);}
  else if(s[0]=='T'&&s[1]=='U'){printf("%d",5);}
  else if(s[0]=='W'){printf("%d",4);}
  else if(s[0]=='T'&&s[1]=='H'){printf("%d",3);}
  else if(s[0]=='F'){printf("%d",2);}
  else {printf("%d",1);}
  return 0;
}
  


Measured memory_bytes: 1688
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<map>

using namespace std;
#define REP(i, n) for(int i=0;i<(int)n;i++)
const int INF = (1<<29) + 1;

int n, m;

template<typename T>
struct Serializer{
	map<T, int> enc;
	vector<T> dec;
	int operator()(const T &t){
		auto it = enc.find(t);
		if(it != enc.end()) return it->second;
		dec.push_back(t);
		return enc[t] = dec.size() - 1;
	}
	size_t size(){
		return dec.size();
	}
};

int g[201][201], g2[201][201];

int main(){
	while(cin >> n, n){
		Serializer<string> se;
		REP(i, 200)REP(j, 200)
			g[i][j] = g2[i][j] = i == j ? 0 : INF;
		REP(i, n){
			string s;
			cin >> s;
			int p = s.find('-');
			int u = se(s.substr(0, p));
			int v = se(s.substr(p+1));
			g[u][v] = g2[u][v] = g2[v][u] = 1;
		}
		n = se.size();
		REP(i, n)REP(j, i){
			int f = 0;
			REP(k, n){
				if(g[i][k] == 1 && g[k][j] == 1 || g[j][k] == 1 && g[k][i] == 1){
					f = 0; break;
				}
				if(g[i][k] == 1 && g[j][k] == 1 || g[k][i] == 1 && g[k][j] == 1)
					f = 1;
			}
			if(f){
				if(g[i][j] == INF) g[i][j] = 501;
				if(g[j][i] == INF) g[j][i] = 501;
			}
		}
		REP(k, n)REP(i, n)REP(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		REP(k, n)REP(i, n)REP(j, n) g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]);
		cout << n << endl;
		cin >> m;
		REP(i, m){
			string s;
			cin >> s;
			int p = s.find('-');
			int u = se(s.substr(0, p));
			int v = se(s.substr(p+1));
			if((g2[u][v] & 1) && g[u][v] < INF) puts("YES");
			else puts("NO");
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define grt() greater<int>()
#define grtl() greater<long long>()

int main()
{
    ll x;
    cin >> x;

    double it = 0.01;
    ll nw = 100;
    int y = 0;

    while(nw < x) {
        nw += nw * it;
        y++;
    }

    cout << y << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define endl '\n'
#define pi 3.1415926536
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
signed main()
{
    SPEED;
  	int n,i;
  	cin>>n;
  	string s,t;
  	cin>>s>>t;
  	for(i=0;i<n;i++)
      cout<<s[i]<<t[i];
}

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

a = a-1

X=[]
Y=[]
for i in range(1,42):
    if a%(2**(i+1))<(2**i):
        X.append('0')
    else:
        if a%2==1:
            X.append('0')
        else:
            X.append('1')
            
for i in range(1,42):
    if b%(2**(i+1))<(2**i):
        Y.append('0')
    else:
        if b%2==1:
            Y.append('0')
        else:
            Y.append('1')

if a%4==1 or a%4 ==2:
    X.insert(0,'1')
else:
    X.insert(0, '0')

if b%4==1 or b%4 ==2:
    Y.insert(0,'1')
else:
    Y.insert(0, '0')

X.reverse()
Y.reverse()

A = ' '
for x in X:
    A += x
B = ' '
for x in Y:
    B += x

print(int(A,2)^int(B,2))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define N 200010
ll a[N],n,m;
bool judge(ll k){
    for(int i=0;i<n-k;i++){
	if(a[2*k+i]+a[2*n-1-i]<m)return 0;
    }
    return 1;
}
ll t;
bool solve(ll z){
    for(int i=0;i<t;i++){
	if(a[i]+a[2*t-1-i]>z)return 0;
    }
    for(int i=0;i<n-t;i++){
	if(a[2*t+i]+a[2*n-1-i]>m+z)return 0;
    }
    return 1;
}
int main(){
    cin>>n>>m;
    for(int i=0;i<2*n;i++)cin>>a[i];
    sort(a,a+n*2);
    ll l=-1,r=n,mid;
    while(l<r-1){
	mid=(l+r)/2;
	if(judge(mid))r=mid;
	else l=mid;
    }
    t=r;
    l=-1,r=m-1;
    while(l<r-1){
	mid=(l+r)/2;
	if(solve(mid))r=mid;
	else l=mid;
    }
    cout<<r<<endl;
    return 0;
}



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

typedef long long ll;
using namespace std;
//    freopen("hps.in", "r", stdin);
//    freopen("hps.out", "w", stdout);



int main() {
    std::ios_base::sync_with_stdio(false), std::cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; i++)cin >> arr[i];
    vector<int> dp(n );
    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);
    for(int i = 2; i < n; i++)dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]), dp[i - 2] + abs(arr[i] - arr[i - 2]));
    cout << dp.back() << endl;
}

Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int q;
    cin>>q;
    while(q--) {
        int c,a,n;
        cin>>c>>a>>n;
        int x=min(a,min(c,n));
        c-=x, a-=x, n-=x;
        int y=min(a,c/2);
        a-=y,c-=y*2;
        int z=c/3;
        cout<<x+y+z<<endl;
    }
    return 0;
}

Measured memory_bytes: 3164
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 100000;
int N;
ll A, B, H[Nmax];

bool condition(ll x){
	ll center = 0;
	for(int i=0; i<N; i++){
		ll remain = max(0LL, H[i]-B*x);
		center += remain/(A-B) + (remain%(A-B)==0 ? 0 : 1);
	}
	return center <= x;
}

int main(){
	cin >> N >> A >> B;
	for(int i=0; i<N; i++){
		cin >> H[i];
	}

	ll lb = 0, ub = 1e9;
	while(ub-lb>1){
		ll mid = (ub+lb)/2;
		if(condition(mid)){
			ub = mid;
		}
		else{
			lb = mid;
		}
	}

	cout << ub << endl;

	return 0;
}


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

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

#define rep(i,n) for (ll i = 0; i < (n); i++)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;

ll choose(ll n, ll a) {
	ll x = 1;
	ll y = 1;
	for (ll i = 0; i < a; i++)
	{
		x *= n - i;
		y *= i + 1;
	}
	return x / y;
}

int main()
{
	ll n;
	cin >> n;
	vector<int> a(n);
	map<ll,ll> p;

	rep(i, n) {
		int aa;
		cin >> aa;
		a[i] = aa;

		if (p.find(aa) == p.end()) {
			p.insert(make_pair(aa, 1));
		}else{
			p[aa]++;
		}
	}

	map<ll, ll> p2; // 要素, 組み合わせ数
	ll all = 0;
	for (auto itr = p.begin(); itr != p.end(); ++itr) {
		ll ch = choose(itr->second, 2);
		p2.insert(make_pair(itr->first, ch));
		all += ch;
	}

	rep(k, n) {
		ll ans = all - p2[a[k]] + choose(p[a[k]] - 1, 2);
		cout << ans << endl;
	}




	return 0;
}

Measured memory_bytes: 19968
//Apple and Peach
#include<bits/stdc++.h>
using namespace std;

int main(){
  vector<string> v;
  string s, tmp;
  getline(cin, s);
  stringstream ss(s);
  while(getline(ss, tmp, ' ')){
    int i;
    if((i=tmp.find("apple", 0))!=string::npos){
      tmp.replace(i, 5, "peach");
    }
    else if((i=tmp.find("peach", 0))!=string::npos){
      tmp.replace(i, 5, "apple");
    }
    v.push_back(tmp);
  }
  for(int i=0; i<v.size(); i++){
    cout<<v[i];
    if(i!=v.size()-1)cout<<' ';
    else cout<<endl;
  }
  return 0;
}

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

int main(void){
    int h = 0,w  = 0; 
    int s[101][101];

    scanf("%d%d", &h, &w);

    for(int i = 0; i < h; i++){
        scanf("%s", s[i]);
//        printf("%s\n", s[i]);
    }

    for(int i = 0; i <= w + 1; i++){
        printf("#");
    }
    printf("\n");

    for(int i = 0; i < h; i++){
        printf("#%s#\n", s[i]);
    }

    for(int i = 0; i <= w + 1; i++){
        printf("#");
    }
    printf("\n");


    return 0;

} 


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

#define debug(x) cerr << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (i * fat[i-1]) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

vector<int>graph[maxn];
int cnt[maxn];

int ans[maxn];

void dfs(int u, int p, int qt)
{
  ans[u] += qt;
  for(const auto &v: graph[u])
  {
    if(v == p)
      continue;
    dfs(v, u, qt + cnt[v]);
  }
}

int main()
{
  ios::sync_with_stdio(0);
  int n,q;
  cin >> n >> q;
  for(int i = 1; i < n; i++)
  {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  while(q--)
  {
    int p,x;
    cin >> p >> x;
    cnt[p] += x;
  }
  dfs(1,1,cnt[1]);
  for(int i = 1; i <= n; i++)
    cout << ans[i] << ' ';
  cout << endl;
  return 0;
}

Measured memory_bytes: 28656
#include <bits/stdc++.h>
 
using namespace std;
 
int H,W;
bool visited[25][25];
char field[25][25];
map<string,int> mp;
const int dx[] = {-1,-1,-1,0,0,1,1,1};
const int dy[] = {-1,0,1,-1,1,-1,0,1};
 
void rec(int x,int y,int d,string s){
    if(visited[y][x]) return;
    visited[y][x] = true;
    int nx = (x + dx[d] + W) % W;
    int ny = (y + dy[d] + H) % H;
    mp[s+field[y][x]]++;
    rec(nx,ny,d,s+field[y][x]);
}
 
int main(){
    while(cin >> H >> W, H){
	mp.clear();
	for(int i = 0 ; i < H ; i++){
	    for(int j = 0 ; j < W ; j++){
		cin >> field[i][j];
	    }
	}
	for(int i = 0 ; i < H ; i++){
	    for(int j = 0 ; j < W ; j++){
		for(int k = 0 ; k < 8 ; k++){
		    memset(visited,false,sizeof(visited));
		    rec(j,i,k,"");
		}
	    }
	}
	int ans_size = -1;
	string ans;
	map<string,int>::iterator it;
	for(it = mp.begin() ; it != mp.end() ; ++it){
	    int size = it->first.size();
	    if(it->second < 2 || size < 2) continue;
	    if(ans_size < size){
		ans_size = size;
		ans = it->first;
	    }
	}
	if(ans_size == -1){
	    cout << 0 << endl;
	}else{
	    cout << ans << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 38936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
int d=365, n=26;
int c[27];
int s[366][27];
int a[366];
int sat[366]={};
int last[27]={};
int ans[100010]={};
void Main(){
    cin >> d;
    For(i,1,n+1) cin >> c[i];
    For(i,1,d+1) For(j,1,n+1) cin >> s[i][j];
    For(i,1,d+1) cin >> a[i];
    For(i,1,d+1){
        sat[i] = sat[i-1] + s[i][a[i]];
        last[a[i]] = i;
        For(j,1,n+1){
            sat[i] -= (i-last[j]) * c[j];
        }
    }
    ans[0]=sat[d];
    int m;
    cin >> m;
    For(x,0,m){
        int t,p,q;
        cin >> t >> q;
        p=a[t];
        int lp=0,rp=d+1,lq=0,rq=d+1;
        For(i,1,d+1){
            if(a[i]==p){
                if(i<t) lp=max(lp,i);
                else if(i>t) rp=min(rp,i);
            }
            else if(a[i]==q){
                if(i<t) lq=max(lq,i);
                else if(i>t) rq=min(rq,i);
            }
            if(i==t) a[i]=q;
        }
        int diff=s[t][q]-s[t][p];
        //cout << lp << " " << rp << " " << lq << " " << rq << endl;
        diff -= (t-lp) * (rp-t) * c[p];
        diff += (t-lq) * (rq-t) * c[q];
        ans[x+1] = ans[x] + diff;
    }
    For(i,1,m+1) cout << ans[i] << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3956
#include<cstdio>
#define N 262144
#define p 998244353
#define ll long long
inline int mod(int x){return x>=p?x-p:x;}
inline int calc(int x,int y)
{
	int z=1;
	for(;y;x=(ll)x*x%p,y>>=1)if(y&1)z=(ll)x*z%p;
	return z;
}
int a[N],i,j,k,n,x,y;
inline void FWT(){for(i=1;i<n;i<<=1)for(j=0,k=i;k<n;j+=i,k+=i)while(k&i)x=a[j],y=a[k],a[j++]=mod(x+y),a[k++]=mod(p+x-y);}
int main()
{
	scanf("%d",&n),n=1<<n;
	for(i=0;i<n;i++)scanf("%d",a+i),x+=a[i];
	for(i=0,x=mod(p-calc(x,p-2));i<n;i++)a[i]=(ll)a[i]*x%p;
	for(FWT(),i=0;i<n;i++)a[i]=calc(p-1-a[i],p-2);
	for(FWT(),i=0;i<n;i++)printf("%d\n",mod(p+a[i]-*a));
	return 0;
}

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

namespace abc137_c
{
    static class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().ToInteger();
            var s = new Dictionary<string, int>();
            for (int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().ToArray();
                Array.Sort(input);
                var input2 = new string(input);
                if (s.ContainsKey(input2))
                {
                    s[input2] += 1;
                }
                else
                {
                    s.Add(input2, 1);
                }
            }

            // アナグラムのグループの個数
            var count = s.Sum(m => Calc(m.Value));

            Console.WriteLine($"{count}");
        }

        static long Calc(int texts)
        {
            var patterns = 0L;
            if (texts >= 2)
            {
                patterns = Combination(texts, 2);
            }
            return patterns;
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        /// <summary>
        /// 順列を計算します
        /// </summary>
        /// <param name="n">全部でいくつ</param>
        /// <param name="k">いくつ選ぶ</param>
        /// <returns>順列</returns>
        static long Permutation(int n, int k)
        {
            var ret = 1L;
            for (int i = 0; i < k; i++)
            {
                ret *= n - i;
            }
            return ret < 1 ? 1 : ret;
        }

        /// <summary>
        /// 組み合わせを計算します
        /// </summary>
        /// <param name="n">全部でいくつ</param>
        /// <param name="k">いくつ選ぶ</param>
        /// <returns>組み合わせ</returns>
        static long Combination(int n, int k)
        {
            var p = Permutation(n, k);
            var d = Permutation(k, k);
            var ret = p / d;
            return ret < 1 ? 1 : ret;
        }

    }
}


Measured memory_bytes: 31296
#include <cmath>
#include <iostream>

int main()
{
    int N;
    std::cin >> N;

    long int sum = 0, sum_sq = 0;
    for (int i = 0, x = 0; i < N; ++i) {
        std::cin >> x;
        sum += x;
        sum_sq += x * x;
    }

    long double avr = (long double)sum / N;
    int P;

    if (std::fabs((long int)avr - avr) < 0.5) {
        P = (long int)avr;
    } else {
        P = (long int)avr + 1;
    }

    std::cout << (sum_sq - 2 * P * sum + N * P * P);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;

int main()
{
	int n;
	cin >> n;
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		if ((i % 3 != 0) && (i % 5 != 0)) {
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
#define mp make_pair
#define x first
#define y second

vector<int> veki;
int n,m,q;
int niz[4][54];

int rek(int x,int y){
	if(x==n){
		int s=0;
		for(int i=0;i<q;i++){
			if(veki[niz[1][i]-1]-veki[niz[0][i]-1]==niz[2][i]) s+=niz[3][i];
		}
		return s;
	}
	int mx=0;
	for(int i=y;i<=m;i++){
		veki.push_back(i);
		mx=max(mx,rek(x+1,i));
		veki.pop_back();
	}
	return mx;
}

int main () {
	cin>>n>>m>>q;
	for(int i=0;i<q;i++){
		cin>>niz[0][i]>>niz[1][i]>>niz[2][i]>>niz[3][i];
	}
	cout<<rek(0,1);


return 0;
}



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

int main() {
  ll N,sum=0;
  cin >> N;
  vector<ll> a(N),b(N),ab(N);
  for(ll i=0;i<N;i++) {
    cin >> a[i] >> b[i];
    sum -= b[i];
    ab[i] = a[i]+b[i];
  }
  sort(ab.begin(),ab.end());
  for(int i=0;i<N;i+=2) {
    sum+=ab[N-1-i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mondai0051
{
	class Program
	{
		static void Main(string[] args)
		{
			var	n	= int.Parse( Console.ReadLine() );
			for( int i = 0; i < n; i++ ) {
				var	s	= Console.ReadLine();
				var	c	= s.ToCharArray();
				Array.Sort( c );
				int	min	= int.Parse( new string( c ) );
				Array.Sort( c, (char c1, char c2) => c2 - c1 );
				int	max	= int.Parse( new string( c ) );
				Console.WriteLine( max - min );
			}
		}
	}
}

Measured memory_bytes: 5712
use std::io;
use std::cmp;

fn main() {
    let n = read_values::<usize>()[0];
    let mut hp = (0..n).map(|_| {
        let v = read_values::<usize>();
        (v[0], v[1])
    }).collect::<Vec<_>>();
    hp.sort_by(|a, b| {
        let (h1, p1) = *a;
        let (h2, p2) = *b;
        (h1 + p1).cmp(&(h2 + p2))
    });

    let inf = 1e15 as usize;
    let mut dp = vec![inf; n + 1];
    dp[0] = 0;
    for i in 0..n {
        let (h, p) = hp[i];
        for j in (0..n).rev() {
            if dp[j] <= h {
                dp[j + 1] = cmp::min(dp[j + 1], dp[j] + p);
            }
        }
    }

    let mut ans = 0;
    for i in 0..n {
        if dp[i + 1] < inf {
            ans = cmp::max(ans, i + 1);
        }
    }
    println!("{}", ans);
}

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}

fn read_values<T>() -> Vec<T>
    where T: std::str::FromStr,
          T::Err: std::fmt::Debug
{
    read_line()
        .split(' ')
        .map(|a| a.trim().parse().unwrap())
        .collect()
}

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

int main(){
  int n, f, t = 0, h = 0;
  char c1[101], c2[101];
  scanf("%d", &n);
  while(n--){
    scanf("%s%s", c1, c2);
    f = strcmp(c1, c2);
    if(!f) t++,h++;
    else if(f > 0) t += 3;
    else if(f < 0) h += 3;
  }
  printf("%d %d\n", t, h);
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
using namespace std;
int so[1001];

int main(void){
    for(int i=2;i*i<=1000;i++){
        if(so[i]!=1){
            for(int j=i*2;j<=1000;j+=i)so[j]=1;
        }
    }
    long long n,ans=1;
    cin>>n;
    for(int i=2;i<=n;i++){
        if(so[i])continue;
        int j=i,ct=0;
        while(n>=j){
            ct+=(n/j);
            j*=i;
        }
        ans=(ans*(ct+1))%1000000007;
        
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int t,min = 999;
  	string n;
  	cin >> n;
  	for(int i = 0; i < n.size()-2; i++) {
    	t= (int)(n[i]-'0')*100 + (int)(n[i+1]-'0')*10 + (int)(n[i+2] -'0');
      	if(abs(t-753) < min)
          	min = abs(t-753);
    }
	cout << min << endl;  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,f,e) for(int (i)=(f); (i)<(e); (i)++)
#define repr(i,e,f) for(int (i)=(e-1); (i)>=(f); (i)--)

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int A[2000010];

int main(){
    int K,N;
    cin >> K >> N;
    rep(i,0,N){
        cin >> A[i];
    }

    int ans = INF;
    int bindex;
    int nindex;
    rep(i,0,N){
        if(i==0) bindex = N-1;
        else bindex = i-1;
        if(i==N-1) nindex = 0;
        else nindex = i+1;
        if(A[i]-A[bindex]<0) ans = min(ans, K-(A[i]+(K-A[bindex])));
        else ans = min(ans, K-(A[i]-A[bindex]));
        if(A[nindex]-A[i]<0) ans = min(ans, K-(A[nindex]+(K-A[i])));
        else ans = min(ans, K-(A[nindex]-A[i]));
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
from bisect import bisect
from collections import defaultdict
N, M = map(int, input().split())
Y = defaultdict(list)
P = set()
PY = []
for i in range(M):
    Pi, Yi = map(int, input().split())
    Y[Pi].append(Yi)
    P.add(Pi)
    PY.append([Pi,Yi])

for p in P:
    Y[p].sort()


for pi, yi in PY:
    i = bisect(Y[pi],yi)
    id = '%06d%06d'%(pi,i)
    print(id)

Measured memory_bytes: 42540
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

ll N, A, B;

int main() {
	cin >> N >> A >> B;
	if (A < B)swap(A, B);
	if ((A - B) % 2 == 0) {
		cout << (A - B) / 2 << endl;
	}
	else {
		cout << min((A - 1 + B - 1) / 2, (N - A + N - B) / 2) + 1 << endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
  
int main(){

  int n,a,b,c,d,numa,numb,suma,sumb;
  cin>>n>>a>>b>>c>>d;
  numa=n/a; numb=n/c; suma=numa*b; sumb=numb*d;
  if(n%a!=0) suma+=b;
  if(n%c!=0) sumb+=d;
  if(suma<sumb) cout<<suma<<endl;
  else cout<<sumb<<endl;
  return 0;
}
   
 
      
 
  
   
  
	
	  
	  
	  
	  
	  
	  
     
  
  
  
  
  

  

 
  


 

    
  



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define mii map<int,int>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define N 200005
//#define M 1000005
#define pi 3.14159265359
#define cpdd const pdd
#define MAXN 100005
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
bitset<600000000> b,ans;
int main(){
	int n;
	scanf("%d",&n);
	int a[1005];
	LL odd=0,even=0;
	LL Max=-1e9-1,Maxi;
	LL all=1;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]>0){
			if(i%2==0)
			odd+=a[i];
			else
			even+=a[i];
			all=0;
		}
		else{
			if(Max<a[i]){
				Max=a[i];
				Maxi=i;
			}			
		}
	}
	if(all){
		Maxi++;
		printf("%lld\n",Max);
		printf("%d\n",n-1);
		for(int i=n;i>Maxi;i--)
		printf("%d\n",i);

		for(int i=1;i<Maxi;i++)
		printf("1\n");
	}
	else if(odd>even){
		vector<int> v;
		int cnt=0;
		int hi;
		for(hi=0;a[hi]<0;hi+=2){
			cnt+=2;
		}
		for(int i=n-1;i>=hi;i--){
			if(i%2==0){
				if(a[i]<=0){
					v.pb(i+1);
					cnt+=2;
					if(i==n-1)
					cnt--;
				}
			}
		}
		for(int i=0;i<hi;i++){
			v.pb(1);
		}
		n-=cnt;
		while(n>1){
			v.pb(2);
			n-=2;
		}
		printf("%lld\n",odd);
		printf("%d\n",v.size());
		for(auto it:v)
		printf("%d\n",it);
	}
	else{
		vector<int> v;
		int cnt=1;
		int hi;
		for(hi=1;a[hi]<0;hi+=2){
			cnt+=2;
		}
		for(int i=n-1;i>=hi;i--){
			if(i%2==1){
				if(a[i]<=0){
				//	printf("%d\n",i+1);
					v.pb(i+1);
					cnt+=2;
					if(i==n-1)
					cnt--;
				}
			}
		}
		for(int i=0;i<hi;i++){
			v.pb(1);
		}
		n-=cnt;
		//printf("%d\n",n);
		while(n>1){
			v.pb(2);
			n-=2;
		}
		printf("%lld\n",even);
		printf("%d\n",v.size());
		for(auto it:v)
		printf("%d\n",it);
	}
}
/*
BC
ACC
AABC
CC
ABC
AACC*/

Measured memory_bytes: 256
#include <iostream>
#define inf 1e9

using namespace std;

int n;
int a[100005];
int lmin[100005], rmin[100005];

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

  lmin[0] = 0;
  for(int i = 1; i <= n; i++){
    if(a[i] == 0) lmin[i] = inf;
    if(a[i] > 0) lmin[i] = lmin[i-1] - 1;
    if(a[i] < 0) lmin[i] = min(lmin[i-1]-1, -a[i]-1);
  }
  rmin[n+1] = 0;
  for(int i = n; i >= 1; i--){
    if(a[i] == 0) rmin[i] = inf;
    if(a[i] > 0) rmin[i] = rmin[i+1] - 1;
    if(a[i] < 0) rmin[i] = min(rmin[i+1]-1, -a[i]-1);
  }

  //for(int i = 1; i <= n; i++) cout << lmin[i] << " "; cout << endl;
  //for(int i = 1; i <= n; i++) cout << rmin[i] << " "; cout << endl;

  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(a[i] > 0) ans += max(0, min(a[i], max(lmin[i], rmin[i])+1));
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 4268
////基本の者ども
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF =2000000000;
//////forども//////////////////////////////////////////
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REPR(i,n) for(int i = int(n); i >= 0; i--)
#define FOR(i,m,n) for(int i = int(m); i < int(n); i++)
#define FOREACH(x,a) for(auto& (x) : (a) )
////////////////////////////////////////////////////////////////
//cinおよびcout拡張
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
/////////////////////////////////////////////////////////////////
//////あまった
#define MP make_pair
#define ALL(v) v.begin(), v.end()
#define pb(a) push_back(a)



//メモ
	//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
	//vector<intなど> 変数名(要素数,初期値)
	//dfsではvector<vector<int>> g(n);で◎
void Main(){//本処理はココ
	//入力パート
 	//string ;
 	ll  r;
 	cin>>r;
 //答え出力パート
     cout<<r*2*M_PI;
     cout<<endl;
 }
int main(){//ここは前処理のゾーン
    //COMinit();//nCrするならON
    //Prime();//素数ならコレをon//PRIME_MAXとかisPrimeもいじろう
    //string a,b;
    //ll n,a;
    std::cout << std::fixed << std::setprecision(15);//浮動小数点絶対殺すマン
  	Main();
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vec vector
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << a << endl
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define Yes "Yes"
#define YES "YES"
#define No "No"
#define NO "NO"


int main() {
  int N;
  cin >> N;
  vec<ll> plus(N),minus(N);
  rep(i,N) {
    ll x,y;
    cin >> x >> y;
    plus[i] = x+y;
    minus[i] = x-y;
  }
  sort(all(plus));
  sort(all(minus));
  ll ans = 0;
  ans = max(ans,abs(plus[N-1]-plus[0]));
  ans = max(ans,abs(minus[N-1]-minus[0]));
  print(ans);
  return 0;
}

Measured memory_bytes: 6352
#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;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


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

  int x;
  cin>>x;
  bool dp[x+10]={};
  dp[0]=true;
  int a[6]={100,101,102,103,104,105};
  rep(i,6){
    rep(j,x){
      if(j+a[i]>x) continue;
      dp[j+a[i]]|=dp[j];
    }
  }

  cout<<dp[x]<<endl;


}

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

int main (){
  int A,B;
  cin >> A >> B;
  if(A%3==0 || B%3==0 || (A+B)%3 ==0){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#define ll long long
using namespace std;
int main()
{
	int a,b,c,i,n;
	cin>>a>>b;
	cout<<100<<' '<<100<<endl;
	int j;
	for(i = 0;i < 50;i++){
        for(j = 0;j < 100;j++){
            if(i%2&&j%2&&a>1){
                cout<<'.';
                a--;
            }
            else{
                cout<<'#';
            }
        }
        cout<<endl;
	}
	for(i = 0;i < 50;i++){
        for(j = 0;j < 100;j++){
            if(i%2&&j%2&&b>1){
                cout<<'#';
                b--;
            }
            else{
                cout<<'.';
            }
        }
        cout<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline long long read () {
	long long num = 0;
	char c = ' ';
	bool flag = true;
	for (;c > '9' || c < '0';c = getchar())
		if (c == '-')
			flag = false;
	for (;c >= '0' && c <= '9';num = (num << 1) + (num << 3) + c - 48, c = getchar());
	return flag ? num : -num;
}
namespace graph {
	const int maxn = 100020;
	struct node {
		int y, next;
	} a[maxn << 1];
	int head[maxn], top = 0;
	void insert (int x, int y) {
		a[top].y = y;
		a[top].next = head[x];
		head[x] = top ++;
	}
} using namespace graph;

namespace INIT {
	map <long long, int> m;
	int n; long long d[maxn];
	void init () {
		n = read ();
		for (int i = 1;i <= n;i ++) {
			d[i] = read ();
			m[d[i]] = i;
		}
		sort (d + 1,d + 1 + n);
	}
} using namespace INIT;

namespace WORK {
	int size[maxn];
	void work () {
		memset (head, -1, sizeof head);
		for (int i = 1;i <= n;i ++)
			size[i] = 1;
		for (int i = n;i > 1;i --) {
			int x = m[d[i]];
			long long t = n - 2 * size[x];
			if (t < 0) {
				printf ("-1\n");
				exit (0);
			}
			t = d[i] - t;
			if (m.count(t) == 0) {
				printf ("-1\n");
				exit (0);
			}
			int y = m[t];
			insert (y, x);
			insert (x, y);
			size[y] += size[x];
		}
	}
} using namespace WORK;

namespace CHECK {
	int dis[maxn];
	void dfs (int x, int fa) {
		for (int i = head[x];i + 1;i = a[i].next) {
			int y = a[i].y;
			if (y == fa) continue;
			dis[y] = dis[x] + 1;
			dfs (y, x);
		}
	}
	void check () {
		dfs (m[d[1]], -1);
		long long s = 0;
		for (int i = 1;i <= n;i ++)
			s += dis[i];
		if (s != d[1]) {
			printf ("-1\n");
		}
		else {
			for (int i = 0;i < top;i += 2) {
				printf ("%d %d\n",a[i].y, a[i ^ 1].y);
			}
		}
	}
} using namespace CHECK;
int main () {
	init ();
	work ();
	check ();
	return 0;
}

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

int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 //   freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); 
    
  ll a,b; 
ll n; 
cin>>a>>b;
ll ans=(a*b)/(__gcd(a,b)); 
cout<<ans;
 return 0;
}

Measured memory_bytes: 256
import itertools
n, k = map(int,input().split())
list1 = []
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    list1.append(a)
b = list(itertools.chain.from_iterable(list1))
b = set(b)

print(n - len(b))

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

#define endl '\n'

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}
const int MAXN = 1e5 + 5 ;
stack<int> g[MAXN] ;
vector<int> g2[MAXN];
int vis[MAXN] ; 
deque<int> ans ;
int deg[MAXN] ;
void dfs(int u){
    vis[u] = 1 ;
    ans.push_back(u) ;
    while(!g[u].empty()){
        int v = g[u].top() ;
        g[u].pop() ;
        if(!vis[v]){
            dfs(v) ;
            break ;
        }
    }
}
bool has_cycle = 0 ;
int en_vert = 0 ;
bool done = 0 ;
int v2 ;
bool bck ;
void dfs0(int u,int p){
    vis[u] = 1 ;
    int cntr = 0 ;
    if(bck){
        ans.push_back(u) ;
    }
    else{
        ans.push_front(u) ;
    }
    for(auto v:g2[u]){
        if(!vis[v]){
            cntr++ ;    
            dfs0(v, u) ;
            if(u == v2){
                if(cntr == 1){
                    bck = 1 ;
                }
                if(cntr == 2){
                    return ;
                }
            }
            else{
                if(cntr == 1){
                    return ;
                }
            }
        }
        else if(vis[v] == 2){
            assert(0) ;
        }
    }
}
int main(int argc,char* argv[]) { 
    io() ;
    #ifndef ONLINE_JUDGE
     //   freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int n, m, u, v ;
    cin >> n >> m ;
    for(int i = 1 ; i <= m ; i++){
        cin >> u >> v ;
        deg[u]++ ;
        deg[v]++ ;
        g[u].push(v) ;
        g[v].push(u) ;
        g2[u].push_back(v) ;
        g2[v].push_back(u) ;
    }
    v2 = 1 ;
    for(int i = 1 ; i <= n ; i++){
        if(deg[i] < deg[v2]){
            v2 = i ;
        }
    }
    dfs0(v2,0) ;
    // if(done){
        cout << (int)ans.size() << endl ;
        while(!ans.empty()){
            int u = ans.front() ;
            ans.pop_front() ;
            cout << u << " " ;
        }
        cout << endl ;
        return 0 ;
    // }
    // else{
        // assert(0) ;
    // }
    return 0 ;
    memset(vis,0,sizeof(vis)) ;
    int v1 = 0 ;
    for(int i = 1 ; i <= n ; i++){
        if(deg[i] == 1){
            v1 = 1 ;
        }
    }
    dfs(v1) ;
    cout << (int)ans.size() << endl ;
    for(auto u:ans){
        cout << u << " " ;
    }
    cout << endl ;
    return 0 ; 
}

Measured memory_bytes: 79308
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>
#include <numeric>
#include <bitset>
#include <queue>
#include <map>

using namespace std;


int main() {
	/*
	①同じ文字が異なる文字に変換された。(a->b,a->c)  例:aab&cdd
	②異なる文字が同じ文字に変換された。(b->a,c->a) こっちはOK 例：chokudai&redcoder
	の一つでも該当したらNo
	*/

	//input
	string S, T;
	cin >> S >> T;

	map<char, char> st,ts;
	int ans_st = 0;

	//①ここを高速化したい
	int time_cnt = 0;
	for (int i = 0; i < S.size(); ++i) {
		char tmp = T[i];
		for (int j = i + 1; j < S.size(); ++j) {
			time_cnt++;
			if (time_cnt > 200000) {
				break;
			}
			if (S[i] == S[j]) {
				char tmp2 = T[j];
				if (tmp != tmp2) {
					ans_st = 1;
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}

	//S,Tの同じ番目のmapをつくる
	for (int i = 0; i < S.size(); ++i) {
		char s = S[i];
		char t = T[i];

		st.insert(make_pair(s, t));
		ts.insert(make_pair(t, s));
	}

	//Sの重複の削除
	sort(S.begin(), S.end());
	S.erase(unique(S.begin(), S.end()), S.end());

	//stのキーをvectorに格納する
	

	//st[S[i]]をvecに格納する(Tに重複があるとき)
	vector<char> vec;
	for (int i = 0; i < st.size(); ++i) {
		vec.push_back(st[S[i]]);
	}
	//②vecに同じ文字があったら一つの文字が二つの変換先を持つということになるのでフラグを立てる
	for (int i = 0; i < vec.size(); ++i) {
		for (int j = i+1; j < vec.size(); ++j) {
			if (vec[i] == vec[j]) {
				ans_st = 1;
				cout << "No" << endl;
				return 0;
			}
		}
	}

	//Tの重複の削除
	sort(T.begin(), T.end());
	T.erase(unique(T.begin(), T.end()), T.end());

	//st[T[i]]をvecに格納する(Sに重複があるとき)
	vector<char> vec2;
	for (int i = 0; i < ts.size(); ++i) {
		vec2.push_back(ts[T[i]]);
	}
	//②vecに同じ文字があったら一つの文字が二つの変換先を持つということになるのでフラグを立てる
	for (int i = 0; i < vec2.size(); ++i) {
		for (int j = i + 1; j < vec2.size(); ++j) {
			if (vec2[i] == vec2[j]) {
				ans_st = 1;
				cout << "No" << endl;
				return 0;
			}
		}
	}

	if (ans_st == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 776
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			if (n == 0)
				return;
			strs = new String[n];
			for (int i = 0; i < n; i++) {
				strs[i] = scanner.next();
			}
			System.out.println(solve() ? "OK" : "NG");
		}
	}

	private boolean solve() {
		int[] in = new int[26], out = new int[26];
		UnionFind unionFind = new UnionFind(26);
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			int from = (int) (strs[i].charAt(0) - 'a');
			int to = (int) (strs[i].charAt(strs[i].length() - 1) - 'a');
			in[from]++;
			out[to]++;
			if (!list.contains(from))
				list.add(from);
			unionFind.merge(to, from);
		}
		for (int i = 0; i < 26; i++) {
			if (in[i] != out[i]) {
				return false;
			}
		}
		for (int i = 1; i < list.size(); i++) {
			if (!unionFind.isSame(list.get(0), list.get(i))) {
				return false;
			}
		}

		return true;
	}

	int n;
	String[] strs;

	class UnionFind {
		int[] pars;
		int[] rank;

		@Override
		public String toString() {
			return "UnionFind [pars=" + Arrays.toString(pars) + ", rank="
					+ Arrays.toString(rank) + "]";
		}

		UnionFind(int size) {
			pars = new int[size];
			rank = new int[size];
			for (int i = 0; i < size; i++)
				pars[i] = i;
		}

		int root(int x) {
			if (x == pars[x])
				return x;
			return pars[x] = root(pars[x]);
		}

		boolean isSame(int x, int y) {
			return root(x) == root(y);
		}

		void merge(int x, int y) {
			x = root(x);
			y = root(y);
			if (x == y)
				return;
			if (rank[x] > rank[y])
				pars[y] = x;
			else {
				pars[x] = y;
				if (rank[x] == rank[y])
					rank[y]++;
			}
		}
	}
}

Measured memory_bytes: 47304
#include <stdio.h>

int g_n , g_s , count;

int func(int n , int i , int s){
	int j;
	if(n == g_n){
		if(s == g_s) count++;
	}
	for(j=i;j<10;j++){
		func(n+1 , j+1 , s+j);
	}
}

int main(void){
	while(1){
		scanf("%d %d" , &g_n , &g_s);
		if(g_n==0&&g_s==0) break;
		count = 0;
		func(0 , 0 , 0);
		printf("%d\n" , count);
	}
return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int n, a[200020], b[200020], bc;
int mn[800020];
int ad[800020];
void build(int x, int l, int r) {
	if (l + 1 == r) {
		mn[x] = b[l];
		return;
	}
	int m = (l + r) / 2;
	build(x * 2 + 1, l, m);
	build(x * 2 + 2, m, r);
	mn[x] = min(mn[x * 2 + 1], mn[x * 2 + 2]);
	return;
}
void push(int x) {
	mn[x * 2 + 1] += ad[x];
	mn[x * 2 + 2] += ad[x];
	ad[x * 2 + 1] += ad[x];
	ad[x * 2 + 2] += ad[x];
	ad[x] = 0;
}
void change(int x, int l, int r, int L, int R) {
	if (L <= l && r <= R) {
		mn[x]++;
		ad[x]++;
		return;
	}
	if (r <= L || R <= l) {
		return;
	}
	push(x);
	int m = (l + r) / 2;
	change(x * 2 + 1, l, m, L, R);
	change(x * 2 + 2, m, r, L, R);
	mn[x] = min(mn[x * 2 + 1], mn[x * 2 + 2]);
}
int query(int x, int l, int r, int L, int R) {
	if (L <= l && r <= R) {
		return mn[x];
	}
	if (r <= L || R <= l) {
		return 2e9;
	}
	push(x);
	int m = (l + r) / 2;
	return min(query(x * 2 + 1, l, m, L, R), query(x * 2 + 2, m, r, L, R));
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
	}
	sort(b, b + n);
	bc = unique(b, b + n) - b;
	build(0, 0, bc);
	long long z = 0;
	for (int i = 0; i < n; i++) {
		int p = lower_bound(b, b + bc, a[i]) - b;
		z += query(0, 0, bc, p, bc) - a[i];
		change(0, 0, bc, 0, p);
	}
	printf("%lld\n", z);
	return 0;
}

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

using namespace std;

const int N = 2e6 + 5 , MOD = 1e9 + 7;
long long fact[N] , fact_inv[N];

int add (int a , int b) {
    a += b;
    while (a >= MOD) a -= MOD;
    while (a < 0) a += MOD;
    return a;
}

long long mul(long long a , long long b) {
    return a * b % MOD;
}

long long power(long long a , long long b) {
    if (!b) return 1;
    long long r = power(a , b / 2);
    r = mul(r , r);
    if (b&1) return mul(r , a);
    return r;
}

long long mod_inv(long long x) {
    return power(x , MOD - 2);
}

long long nCr(long long n , long long r){
    if (!r) return 1;
    if (r > n) return 0;
    return mul(fact[n] , mul(fact_inv[n - r] , fact_inv[r]));
}

void pre() {
    fact[0] = fact_inv[0] = 1;
    for(int i = 1 ; i < N ;i++) {
        fact[i] = mul(fact[i - 1] , i);
        fact_inv[i] = mod_inv(fact[i]);
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    pre();

    int r1 , c1 , r2 , c2;
    cin >> r1 >> c1 >> r2 >> c2;

    auto get = [] (int n , int r) {
        if (n < r)
            return 0ll;
        return nCr(n + 1 , r + 1);
    };

    int ans = 0;
    for (int i = r1 ; i <= r2 ;i++)
        ans = add(ans , add(get(i + c2 , i) , -get(i + c1 - 1 , i)));

    cout << ans;
}


Measured memory_bytes: 34904
import sys

N, M = map(int, input().split())
ship = [[] for i in range(N+1)]

for i in range(M):
    a, b = map(int, input().split())
    ship[a].append(b)
    ship[b].append(a)

flag = 0
for i in ship[1]:
    if N in ship[i]:
        flag = 1
if flag == 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 38320
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> arr(3*n);
  for(int i=0;i<3*n;i++){
      cin >>arr.at(i);
  }
  sort(arr.begin(),arr.end());
  reverse(arr.begin(),arr.end());
  int64_t sum=0;
  for(int i=1;i<2*n;i+=2){
    sum+=arr.at(i);
  }
  cout<<sum;
  return 0;
}

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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;

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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (2*a*b + 2*b*c + 2*c*a < a*a + b*b + c*c and a + b < c) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
    return (b == 0) ? a : gcd(b, a % b);
}
int main()
{
    int N, D;
    cin >> N >> D;
    int x = 2 * D + 1;
    if (2 * D + 1 >= N)
    {
        cout << 1 << endl;
        return 0;
    }
    if (N % x == 0)
    {
        cout << N / x << endl;
    }
    else
    {
        cout << N / x + 1 << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 3e3 + 10;

int n, m;

void prework(){

}

void read(){

}

int a[MAXN];
vector<int > E[MAXN];

int dfs(int x, int fa){
	int y;
	for(int i = 0; i < E[x].size(); i++){
		if ((y = E[x][i]) != fa){
			if (a[x] > a[y]){
				if (dfs(y, x) == 0) return 1;
			}
		}
	}
	return 0;
}

void solve(int casi){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for(int i = 1; i < n; i++){
		int x, y;
		scanf("%d%d", &x, &y);
		E[x].push_back(y);
		E[y].push_back(x);
	}
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		if (dfs(i, 0)){
			if (cnt) putchar(' ');
			cnt++;
			printf("%d", i);
		}
	}
	puts("");
}

void printans(){

}


int main(){
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  string s;
  cin >> s;
  reverse(s.begin(),s.end());
  if(s[0]=='s') s = "se" + s;
  else s = "s" + s;
  reverse(s.begin(),s.end());
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
using namespace std;
typedef long long ll;

int X[50];
ll dp[51][51][3010];

int main()
{
	int N,A;
	cin >> N>>A;
	
	for(int i = 0; i < N; i++) 
		cin >> X[i];
	
	dp[0][0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N*A; k++) {
				if (dp[i][j][k]) {
					dp[i + 1][j][k] += dp[i][j][k];
					dp[i + 1][j + 1][k + X[i]] += dp[i][j][k];
				}
			}
		}
	}
	ll ans = 0;
	for (int i = 1; i <= N; i++)
		ans += dp[N][i][i*A];
	cout << ans << endl;
	return	0;
}

Measured memory_bytes: 58240