akhauriyash/Code-Regression huggingface dataset:
//start of jonathanirvings' template v3.0.3 (BETA)

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <deque>
#include <string>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <time.h>
#include <bitset>
#include <list>
#include <assert.h>
#include <time.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n,q,v,w;

int main()
{
  scanf("%d %d",&n,&q);
  TC(q)
  {
    scanf("%d %d",&v,&w);
    if (n == 1)
    {
      printf("%d\n",min(v,w));
    } else
    {
      --v;
      --w;
      while (v != w)
      {
        if (v > w) v = (v-1)/ n;
        else w = (w-1)/n;
      }
      printf("%d\n",v+1);
    }
  }
  return 0;
}










Measured memory_bytes: 1280
def get_switch(i, N):
    ans = list()
    for _ in range(N):
        ans.append(i%2)
        i //= 2
    return ans

def turn_light(switch, k_s, p, N, M):
    for i in range(M):
        count = 0
        for j in range(1, k_s[i][0]+1):
            if switch[k_s[i][j]-1] == 1:
                count += 1
        
        if count % 2 != p[i]:
            return 0
    
    return 1

N, M = map(int, input().split())
k_s = list()
for i in range(M):
    k_s.append(list(map(int, input().split())))

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

ans = 0
for i in range(2**N):
    switch = get_switch(i, N)
    ans += turn_light(switch, k_s, p, N, M)

print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    if B % A == 0:
        print(A+B)
    else:
        print(B-A)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N = int(input())
A = [int(i) for i in input().split()]
count = 0
flag = 1
while flag != 0:
    flag = 0
    for i, a in enumerate(A):
        if a % 2 == 0:
            A[i] = a/2
            count += 1
            flag = 1
print(count)


Measured memory_bytes: 4152
#include <iostream>

void print_array(int a[], int n)
{
    for (int i = 0; i < n; ++i)
    {
        if (0 < i)
        {
            std::cout << " ";
        }

        std::cout << a[i];
    }

    std::cout << std::endl;
}

template <class T>
void swap(T& left, T& right)
{
    T temp = left;
    left = right;
    right = temp;
}

int bubble_sort(int a[], int n)
{
    auto swap_count = 0;

    auto flag = true;
    while (flag)
    {
        flag = false;
        for (int j = n - 1; 0 < j; --j)
        {
            if (a[j] < a[j - 1])
            {
                swap_count++;
                std::swap(a[j], a[j - 1]);
                flag = true;
            }
        }
    }
    return swap_count;
}


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

    auto swap_count = bubble_sort(a, n);
    print_array(a, n);
    std::cout << swap_count << std::endl;

    return 0;
}


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

int main() {
  int n;cin>>n;
  vector<int> v(n);
  rep(i,n)cin>>v[i];
  sort(all(v));
  double ans=v[0];
  for(int i=1;i<n;i++)ans=(ans+v[i])/2;
  cout<<ans<<endl;
}

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

int main() {
  int N, X, A = 1, P = 0;
   
  cin >> N >> X;

  for (int i = 0; i < N; i++){
    int L;
    
    cin >> L;
    
    if ((P += L) <= X){
      
      A++;
      
    }
  }
    
    cout << A << endl;
  
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
all_num = 3**n
odd_num = 0
even_num = 0
for i in range(n):
    if a[i] % 2 == 1:
        odd_num += 1
    else:
        even_num += 1
print(all_num - 2**even_num)


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

int main(){
	ll h,w,k;
	cin >> h >> w >> k;
	// 0 mitei 
	ll cnt = 0 , ans[h][w]={};
	string s[h];
	FOR(i,0,h) cin >> s[i];
	FOR(i,0,h){
		FOR(j,0,w){
			if(s[i][j]=='#')ans[i][j]=++cnt;
		}
	}

	FOR(i,0,h){
		bool allzero = true;
		FOR(j,0,w){
			if(ans[i][j])allzero = false;
		}
		if(not allzero){
			FOR(j,0,w-1)if(not ans[i][j+1]){
				ans[i][j+1] = ans[i][j];
			}
			FORR(j,1,w)if(not ans[i][j-1]){
				ans[i][j-1] = ans[i][j];
			}
		}
	}
	FOR(i,1,h){
		bool allzero = true;
		FOR(j,0,w){
			if(ans[i][j])allzero = false;
		}
		if(allzero){
			FOR(j,0,w)ans[i][j]=ans[i-1][j];
		}
	}
	FORR(i,0,h-1){
		bool allzero = true;
		FOR(j,0,w){
			if(ans[i][j])allzero = false;
		}
		if(allzero){
			FOR(j,0,w)ans[i][j]=ans[i+1][j];
		}
	}
	FOR(i,0,h){
		FOR(j,0,w){
			cout << ans[i][j] << (j+1==w?"\n":" ");
		}
	}

}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define REP(i,n)    for(int i = 0; i < (int)n; i++)

void solve(){
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    int rev_cnt = 0;
    REP(i, Q){
        int query;
        cin >> query;
        if(query == 1){
            rev_cnt++;
        }
        else{
            int F;
            string C;
            cin >> F >> C;
            if((F == 1 && rev_cnt % 2 == 0) || (F == 2 && rev_cnt % 2 == 1)){
                S.insert(0,C);
            }
            else{
                S.insert(S.size(),C);
            }
        }
    }
    if(rev_cnt % 2)
        reverse(S.begin(),S.end());
    cout << S << endl;
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 900
# -*- coding: utf-8 -*-
"""
Created on Sat Feb  9 20:33:17 2019

@author: Yamazaki Kenichi
"""

K,A,B = map(int,input().split())

if B-A <= 2:
    print(1+K)
else:
    ans = 0
    c = (K+1) - A
    if c%2 ==0:
        ans += (c//2)*(B-A)
    else:
        ans += (c//2)*(B-A)+1
    ans += A
    print(ans)
    
#    c = (K+1) // (A+2)
#    ans = 0
#    ans += (K+1)-c*(A+2)
#    ans += c*B
#    print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int count = 0;

		for(int i = 1; i <= N; i++) {
			int p = scan.nextInt();
			if(p != i) {
				count++;
			}
		}

		System.out.println(count <= 2? "YES": "NO");
	}

}

Measured memory_bytes: 22868
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
template <typename T>
T gcd(T a,T b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
template <typename T>
T lcm(T a,T b){
  return a/gcd(a,b)*b;
}

struct z{
	int y,m,d;
};
int cmp(const z &a,const z &b){
	if(a.y==b.y){
		if(a.m==b.m){
			if(a.d==b.d){
				return 0;
			}else if(a.d < b.d){
				return 1;
			}else{
				return -1;
			}
		}else if(a.m < b.m){
			return 1;
		}else{
			return -1;
		}
	}else if(a.y < b.y){
		return 1;
	}else{
		return -1;
	}
}
int cmpmd(const z &a,const z &b){
	if(a.m==b.m){
		if(a.d==b.d){
			return 0;
		}else if(a.d < b.d){
			return 1;
		}else{
			return -1;
		}
	}else if(a.m < b.m){
		return 1;
	}else{
		return -1;
	}
}
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
	z A,B;
	cin>>A.y>>A.m>>A.d;
	cin>>B.y>>B.m>>B.d;
	if(cmp(A,B)==-1){
		swap(A,B);
	}
	if(!cmpmd(A,B)){
		cout << B.y-A.y;
	}else if(cmpmd(A,B)==-1){
		cout << B.y-A.y;
	}else{
		cout << B.y-A.y+1;
	}
	cout << endl;

}



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

void solve(std::istream& ist, std::ostream& ost)
{
    /* ------- 宣言と入力 ------- */

    int A,B,C,D;
    ist >> A>>B>>C>>D;

    /* ------- 計算 ------- */

    while(1) {
        C -=B;
        if(C<=0) {
            cout<<"Yes"<<endl;
            return;
        }

        A-=D;
        if(A<=0) {
            cout<<"No"<<endl;
            return;
        }

    }
    return;

}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin>>n;
  vi a(n);
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  int c = 0;
  int cnt = 0;
  while(c!=1){
    c = a[c];
    cnt++;
    if(cnt>1000000)break;
  }
  if(cnt>1000000) cnt = -1;
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 0; i < n - 2; i++) {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		}

		System.out.println(count);




	}

}


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

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>> wh(h, vector<char>(w));
    vector<vector<int>> dp(h, vector<int>(w));
    rep(i,h){
        rep(j,w){
            cin >> wh.at(i).at(j);
        }
    }
    if (wh[0][0] == '.'){
        dp[0][0] = 0;
    }
    else{
        dp[0][0] = 1;
    }
    repp(k,w,1){
        if (wh[0][k] == '.'){
            dp[0][k] = dp[0][k-1];
        }
        else if (wh[0][k] == '#' && wh[0][k-1] == '.'){
            dp[0][k] = dp[0][k-1] + 1;
        }
        else{
            dp[0][k] = dp[0][k-1];
        }
    }
    repp(l,h,1){
        if (wh[l][0] == '.'){
            dp[l][0] = dp[l-1][0];
        }
        else if (wh[l][0] == '#' && wh[l-1][0] == '.'){
            dp[l][0] = dp[l-1][0] + 1;
        }
        else{
            dp[l][0] = dp[l-1][0];
        }
    }
    repp(a,h,1){
        repp(s,w,1){
            if (wh[a][s] == '.'){
                dp[a][s] = min(dp[a-1][s], dp[a][s-1]);
            }
            else{
                if (wh[a-1][s] == '#' && wh[a][s-1] == '#'){
                    dp[a][s] = min(dp[a-1][s], dp[a][s-1]);
                }
                else if (wh[a-1][s] == '#' && wh[a][s-1] =='.'){
                    dp[a][s] = min(dp[a-1][s], dp[a][s-1]+1);
                }
                else if (wh[a-1][s] == '.' && wh[a][s-1] =='#'){
                    dp[a][s] = min(dp[a-1][s]+1, dp[a][s-1]);
                }
                else{
                    dp[a][s] = min(dp[a-1][s]+1, dp[a][s-1]+1);
                }
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int a; cin >> a;
  string s; cin >> s;
  string result = (a>=3200) ? s : "red";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(a,b) (x+y-1)/y
#define min(x,y)(x<y?x:y)
 
using namespace std;
typedef pair<int, int> P;


int main() {
	FAST;

	int n;
	cin >> n;

	long a[n+1];
	a[0]=0;
	rep(i,1,n+1) {cin >> a[i]; a[i] = a[i-1] + a[i];}

	long ans=LONG_MAX;

	long s[4];

	int l=1, r=3;
	for(int i=2; i<n; i++) {
		while (l<i && abs(a[i]-a[l] - abs(a[l])) >= abs(a[i]-a[l+1] - abs(a[l+1]))) l++;
		while (r<n && abs(a[n]-a[r] - abs(a[r]-a[i])) >= abs(a[n]-a[r+1] - abs(a[r+1]-a[i]))) r++;
		// cout << "i="<<i <<",l="<<l<<",r="<<r<<"\n";
		s[0] = a[l]; s[1] = a[i] - a[l]; s[2] = a[r] - a[i]; s[3] = a[n] - a[r];
		// cout << "s = " << s[0] << " " << s[1] << " " << s[2] << " " << s[3] << "(before sort)\n";
		sort(s, s+4);
		// cout << "s = " << s[0] << " " << s[1] << " " << s[2] << " " << s[3] << "(after sort)\n";
		// cout << "ans = " << ans << "\n";
		// cout << "s   = " << abs(s[]3]-s[0]) << "\n";
		ans = min(ans, abs(s[3]-s[0]));
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstdlib>
#include<vector>

using namespace std;

#define REP(i,n) for(int i = 0 ; i < n ; i++)
	

int conv_i(string s)
{
	int ret = 0;
	
	REP(i,s.size())
	{
		int n = 1;
		char tmp = s[i];
		if(isdigit(tmp))
		{
			n = tmp - '0';
			i++;
			tmp = s[i];
		}
		switch(tmp)
		{
			case 'm':ret += 1000 * n;break;
			case 'c':ret += 100 * n;break;
			case 'x':ret += 10 * n;break;
			case 'i':ret += n;break;
		}
	}
	
	return ret;
	
}

string conv_s(int n)
{
	int m,c,x,i;
	i = n % 10;
	n /= 10;x = n % 10;
	n /= 10;c = n % 10;
	n /= 10;m = n % 10;
	string ret;
	if(m)
	{
		if(m == 1)ret += 'm';
		else{char tmp = m + '0';ret += tmp ;ret += 'm';}
	}
	if(c)
	{
		if(c == 1)ret += 'c';
		else{char tmp = c + '0';ret += tmp ;ret += 'c';}
	}
	if(x)
	{
		if(x == 1)ret += 'x';
		else{char tmp = x + '0';ret += tmp ;ret += 'x';}
	}
	if(i)
	{
		if(i == 1)ret += 'i';
		else{char tmp = i + '0';ret += tmp ;ret += 'i';}
	}
	return ret;
}

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

	REP(a,n)
	{
		string a1,a2,ret;
		int b1,b2,tmp;
		
		cin >> a1 >> a2;
		
		b1 = conv_i(a1);b2 = conv_i(a2);
		tmp = b1 + b2;
		ret = conv_s(tmp);
		
		cout << ret << endl;
		
	}
	return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	string s,t;
 	cin>>s>>t;
 	ll n,m;
 	cin>>n>>m;
 	map<string ,ll>mp;
 	mp[s]=n;
 	mp[t]=m;
 	string u;
 	cin>>u;
 	mp[u]--;
 	cout<<mp[s]<<" "<<mp[t]<<endl;
    return 0;
}

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

int main()
{

	string str;

	cin >> str;
	for(int i = 0; i < str.length(); i++) {
		str[i] - 3 >= 65 ? str[i] -= 3 : str[i] += 23;
	}

	cout << str << endl;

	return 0;

}

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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
  
	long long int a,b;
	cin>>a>>b;
	long long int count = 0;
	while(a <= b){
		count += 1;
		a *= 2;
	}
	cout<<count;
	return 0;
}

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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> h(n + 1, 0), ans(n + 1, INT_MAX);
    for (int i = 0; i < n; i++) cin >> h[i];
    ans[0] = 0;
    for (int i = 0; i < n - 1; i++) {
        ans[i + 1] = min(ans[i + 1], ans[i] + abs(h[i + 1] - h[i]));
        ans[i + 2] = min(ans[i + 2], ans[i] + abs(h[i + 2] - h[i]));
    }
    cout << ans[n - 1];
    return 0;
}

Measured memory_bytes: 1024
import java.io.PrintWriter

val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun println(value: Any) { pw.println(value) }

fun func() {
    val (N, K) = listOfInt()
    val V = listOfInt()
    var ans = 0
    for (l in 0..K) {
        for (r in 0..K - l) {
            if (l + r > N) break
            val S: MutableList<Int> = arrayListOf()
            for (n in 0 until l) S.add(V[n])
            for (n in 0 until r) S.add(V[N - n - 1])
            S.sort()
            var now = 0
            var d = K - l - r
            for (n in 0 until S.count()) {
                if (S[n] < 0 && d > 0)
                    d--
                else
                    now += S[n]
            }
            ans = Math.max(ans, now)
        }
    }
    println(ans);
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) } //{ it.toInt() }


Measured memory_bytes: 38604
from copy import deepcopy
import sys
input = sys.stdin.readline


def warshall_floyd(d):
    # d        : nxn adjacent matrix
    # next_node: node after i on the shortest path of (i,j)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]


def check(a, b):
    res = 0
    for i in range(n):
        for j in range(i + 1, n):
            if b[i][j] < a[i][j]:
                return -1
            flag = True
            for k in range(n):
                if k == i or k == j:
                    continue
                if b[i][j] == b[i][k] + b[k][j]:
                    flag = False
                    break
            if flag:
                res += a[i][j]
    return res


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
b = deepcopy(a)
warshall_floyd(b)
ans = check(a, b)
print(ans)


Measured memory_bytes: 76620
#!/usr/bin/env python3

def main():
    n, m = map(int, input().split())
    k, *a = map(int, input().split())
    ans = set(a)
    for i in range(n - 1):
        k, *a = map(int, input().split())
        ans = ans & set(a)
    print(len(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9060
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
int main()
{
	SPEED
	int n;
	cin >> n;
	

	int count_AC = 0;
	int count_WA = 0;
	int count_TLE = 0;
	int count_RE = 0; 

	while(n--)
	{
		string a;
		cin >> a;
		if (a=="AC")
		{
			count_AC++;
		}
		else if (a=="WA")
		{
			count_WA++;
		}
		else if (a=="TLE")
		{
			count_TLE++;
		}
		else if (a=="RE")
		{
			count_RE++;
		}
	}


	cout << "AC x " << count_AC << '\n';
	cout << "WA x " << count_WA << '\n';
	cout << "TLE x " << count_TLE << '\n';
	cout << "RE x " << count_RE;
	return 0;
}

Measured memory_bytes: 3656
import sys
from itertools import product

N,M = list(map(int, input().split()))

Lmax = 1
Rmin = N

for i in range(M):
    L,R = list(map(int, input().split()))
    Lmax = max(Lmax, L)
    Rmin = min(Rmin, R)

if Lmax <= Rmin:
    print(Rmin-Lmax+1)
else:
    print(0)


Measured memory_bytes: 44120
import sys
from string import ascii_lowercase

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    s = set(S)
    for c in ascii_lowercase:
        if c not in s:
            print(c)
            return

    print('None')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 10032
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = -1;
        for(int i = 1;i <= 1000;i++){
            if((i*8)/100==a && i/10==b){
                ans = i;
                break;
            }

        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 25684
#include <iostream>
#include <vector>
#include <functional>

#define INF 1000000000

using namespace std;

int main()
{
  int N, T;
  cin >> N >> T;
  vector<int> c(N), t(N);
  for (int i = 0; i < N; i++) {
    cin >> c[i] >> t[i];
  }

  function<int(int, int)> iter = [&](int idx, int res)->int{
    if (idx >= N) return res;
    if (t[idx] <= T) return iter(idx + 1, min(res, c[idx]));
    else return iter(idx + 1, res);
  };

  int res = iter(0, INF);
  if (res != INF) cout << res << endl;
  else cout << "TLE" << endl;


  return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  cout << string(w + 2, '#') << endl;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    cout << "#" << s << "#" << endl;
  }
  cout << string(w + 2, '#') << endl;
  return 0;
}


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


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

  // dp[i][0]:上からi桁，ピッタリ払うときの最小枚数
  // dp[i][1]:上からi桁，おつりをもらうように払うときの最小枚数
  vector<vector<int>> dp(1000010, vector<int>(2,0));

  dp[0][0] = 0; dp[0][1] = 11;

  for(int i=1; i<=S.length(); i++){
    int d = S[i-1] - '0';

    dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + d;
    dp[i][1] = min(dp[i-1][0] + 1 + 10-d, dp[i-1][1] - 1 +10-d);

    //cout << dp[i][0] << " " << dp[i][1] << endl;
  }

  cout << min(dp[S.length()][0], dp[S.length()][1]) << endl;
}

Measured memory_bytes: 55940
use proconio::{input, fastout};

#[fastout]
fn main() {
    input !{
        n: usize,
        s: [String; n]
    }
    let march = ['M', 'A', 'R', 'C', 'H'];
    let mut ans: usize = 0;
    for x in 0..5 {
        for y in x + 1 .. 5 {
            for z in y + 1..5 {
                let cx = march[x];
                let cy = march[y];
                let cz = march[z];

                let mut num_cx = 0;
                let mut num_cy = 0;
                let mut num_cz = 0;

                for ss in &s {
                    let first = ss.chars().nth(0).unwrap();
                    if first == cx {
                        num_cx += 1;
                    }
                    if first == cy {
                        num_cy += 1;
                    }
                    if first == cz {
                        num_cz += 1;
                    }
                }
                ans += num_cx * num_cy * num_cz;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 8184
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		if(s.substring(2, 3).equals(s.substring(3, 4))&&s.substring(4, 5).equals(s.substring(5, 6))) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22100
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (int argc, char const *argv[])
{
    char S[16];
    int64_t len, win = 0;

    gets(S);
    len = strlen(S);

    for (int i = 0; i < strlen(S); i++) {
        if (S[i] == 'o') win++;
    }

    if ((15 - len + win) >= 8) {
        puts("YES");
    } else {
        puts("NO");
    }

    return 0;
}


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


int main(){
    int N; cin >> N;
    int imos[100010],check[100010];
    fill(check,check+100001,0);
    int a,b;
    for(int i = 0; i < N; i++){
        cin >> a >> b;
        a--; 
        check[a]++;
        check[b]--;
    }
    imos[0] = check[0];
    for(int i = 1; i <= 100001; i++){
        imos[i] = imos[i-1]+check[i];
    }
    int ans = 0;
    for(int i = 0; i <= 100001; i++){
        if(imos[i] >= i){
            ans = max(ans,i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

int main()
{
    string s;
    cin >> s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3])
        cout << "Bad" << endl;
    else
        cout << "Good" << endl;   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    ll C;
    cin>>R>>C>>N;
    vp on_edge(0);
    vec x(2), y(2);
    rep(i,N){
        cin>>x[0]>>y[0]>>x[1]>>y[1];
        if((x[0] * y[0] > 0) && (x[0] < R) && (y[0] < C)) continue;
        if((x[1] * y[1] > 0) && (x[1] < R) && (y[1] < C)) continue;
        rep(j,2){
            if(x[j] == 0){
                on_edge.emplace_back(C - y[j], i);
            }else if(y[j] == 0){
                on_edge.emplace_back(C + x[j], i);
            }else if(x[j] == R){
                on_edge.emplace_back(C + R + y[j], i);
            }else{
                on_edge.emplace_back(C*2 + R*2 - x[j], i);
            }
        }
    }
    sort(on_edge.begin(), on_edge.end());
    stack<ll> num;
    set<ll> in_stack;
    for(P p : on_edge){
        //cout<<p.fi<<' '<<p.se<<endl;
        if(in_stack.find(p.se) == in_stack.end()){
            num.push(p.se);
            in_stack.insert(p.se);
        }else{
            ll last = num.top();
            num.pop();
            in_stack.erase(last);
            if(last != p.se){
                cout<<"NO"<<endl;
                return 0;
            }
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 6512
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  string in;
  while(getline(cin,in)){
    rep(i,in.size()-4){
      if(in.substr(i,5)=="apple")in.replace(i,5,"peach");
      else if(in.substr(i,5)=="peach")in.replace(i,5,"apple");
    }
    cout<<in<<endl;
    }


}

Measured memory_bytes: 1188
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
#define __int64 long long
//const ll M=1000000007;


struct Seg{
	public:
	int n;//ノードの個数
	vector<ll>seg;
	ll INF;
	void init(ll x){
		n=1;
		INF=-700000000000000000;
 
 
		while(n<x)n*=2;//最下段の個数
		seg.resize(n*2+1);
		
		rep(i,n*2)seg[i]=INF;
	}
 
	void update(int i,ll x){
		int now=i+n-1;
		seg[now]=max(seg[now],x);
	
		while(now>0){
			now=(now-1)/2;
			seg[now]=max(seg[now*2+1],seg[now*2+2]);
		}
	}
	
	ll find(int a,int b,int k,int l,int r){//[a,b,0,0,n)
		//cout<<"A"<<a<<" "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
		if(r<=a||b<=l)return INF;
		else if(a<=l&&r<=b)return seg[k];
		
		else{
			ll v1,v2;
			v1=find(a,b,k*2+1,l,(l+r)/2);
			v2=find(a,b,k*2+2,(l+r)/2,r);
			return max(v1,v2);
		}
	}
};




ll n,c;
ll x[111111],v[111111];
ll r1[111111],r2[111111];
ll ans=0;

int main(){
	cin>>n>>c;
	rep(i,n)cin>>x[i]>>v[i];
	
	Seg a,b;//座標0からi地点に行くのにかかるコスト
	a.init(111111);
	b.init(111111);
	ll cost=0,dist=0;
	for(int i=0;i<n;i++){
		cost+=v[i],dist=x[i];
		a.update(i,cost-dist);
		r1[i]=cost-dist;
		//cout<<i<<" "<<cost-dist<<endl;
	}

	//cerr<<endl;
	cost=0,dist=0;
	for(int i=n-1;i>=0;i--){//bは反時計回りに番号を振っている
		cost+=v[i],dist=c-x[i];
		b.update((n-1)-i,cost-dist);	
		r2[i]=cost-dist;
		//cout<<(n-1)-i<<" "<<cost-dist<<endl;	
	}
	//cerr<<endl;

	ll ret;

	for(int i=0;i<n;i++){
		ans=max(ans,r1[i]);
	}
	for(int i=n-1;i>=0;i--){
		ans=max(ans,r2[i]);
	}



	for(int i=0;i<n-1;i++){//時計回り
			ret=0;
			ret+=r1[i];
			ret-=x[i];
			int l=n-1,r=i+1;
			l=(n-1)-l,r=(n-1)-r;
			ll c=b.find(l,r+1,0,0,b.n);
			ret+=c;
			//cout<<"A"<<ret<<endl;
			ans=max(ans,ret);
			//cout<<l<<" "<<r<<" "<<r1[i]<<" "<<c<<" "<<ret<<endl;
	}

	for(int i=n-1;i>0;i--){//反時計回り
		ret=0;
		ret+=r2[i];
		ret-=(c-x[i]);
		int l=0,r=i-1;
		//cout<<r2[i]<<" ";
		ll c=a.find(l,r+1,0,0,a.n);
		ret+=c;
		//cout<<l<<" "<<r<<" "<<ret<<endl;
		ans=max(ans,ret);
	}
	

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

Measured memory_bytes: 7424
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		char[] c = s.toCharArray();
		//char配列をリストに変換する
		List<Character> list = new ArrayList<Character>();
		for (char i : c) {
			list.add(i);
		}
		List<Character> list2 = new ArrayList<Character>(new HashSet<>(list));
		if(list.size()==list2.size()) {
			System.out.println("yes");
		}else {
			System.out.println("no");
		}

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

int main(){
    long long n,k;
    cin>>n>>k;
    long long result = 0;
    if (n == k){
        cout<<0<<endl;
    }
    else if (k == 0){
        long long k = n*n;
        cout<<k<<endl;
    }
    else{
        for (int i = 1;i <= n - k; i ++){
            int b = i + k;
            result += n/b*i;
            if (n%b - k >= 0){
                result += n%b - k+1;
            }

        }
        cout<<result<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (auto &t : a) {
		cin >> t;
	}
	for (auto &t : b) {
		cin >> t;
	}
	auto check = [&]() {
		int ok = 1;
		for (int i = 0; i < n; i++) {
			ok &= (a[i] != b[i]);
		}
		if (ok) {
			cout << "Yes\n";
			for (auto t : b) {
				cout << t << ' ';
			}
			cout << '\n';
			exit(0);
		}
	};
	check();
	reverse(b.begin(), b.end());
	check();
	reverse(b.begin(), b.end());
	rotate(b.begin(), b.begin() + n / 2, b.end());
	check();
	reverse(b.begin(), b.end());

	cout << "No\n";
}

Measured memory_bytes: 4768
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var x = int.Parse(input[0]);
            var n = int.Parse(input[1]);

            var exclude = new List<int> { };

            var input1 = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                exclude.Add(int.Parse(input1[i]));
            }

            int c = 0;
            int res = 0;
            while (true)
            {
                if (!exclude.Contains(x - c))
                {
                    res = x - c;
                    break;
                }
                if (!exclude.Contains(x + c))
                {
                    res = x + c;
                    break;
                }
                c++;
            }

            Console.WriteLine(res);


        }

    }
}



Measured memory_bytes: 27832
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

int main(){

	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		string str;
		cin>>str;
		if(str.size()<=4)
			cout<<"NA"<<endl;
		else if(str.substr(0,2)==">'"&&str[str.size()-1]=='~'&&str.size()%2==0){
			string ss=str.substr(2,str.size()-3);
			if(ss.size()>=3){
				bool f=true;
				for(int j = 0; j < ss.size(); j++){
					if(j==0){
						if(ss[j]!='='){
							f=false;
							break;
						}
					}
					else if(j==(ss.size()/2)){
						if(ss[j]!='#'){
							f=false;
							break;
						}
					}
					else{
						if(ss[j]!='='){
							f=false;
							break;
						}
					}
				}
				if(f)
					cout<<"A"<<endl;
				else
					cout<<"NA"<<endl;
			}
			else{
				cout<<"NA"<<endl;
			}
		}
		else if(str.substr(0,2)==">^"&&str.substr(str.size()-2,2)=="~~"&&str.size()%2==0){
			string ss=str.substr(2,str.size()-4);
			bool f=true;
			if(ss.size()>=2){
				for(int j = 0; j < ss.size(); j+=2){
					if(ss.substr(j,2)!="Q="){
						f=false;
						break;
					}
				}
				if(f)
					cout<<"B"<<endl;
				else
					cout<<"NA"<<endl;
			}
			else
				cout<<"NA"<<endl;
		}
		else
			cout<<"NA"<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
import math

B, A, H, M = map(int,input().split())
m = (M/60) * 360
h = ((30*H + 0.5*M)/360) * 360
# print(m)
# print(h)
if abs(m-h) > 180:
    theta = 360 - abs(m-h)
else:
    theta = abs(m-h)
# print(theta)
theta = math.radians(theta)
ans = math.sqrt(A**2 + B**2 -2*A*B*math.cos(theta))
print(ans)

Measured memory_bytes: 9448
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

struct Dinic{
  
  struct edge {
    int to, cap, rev;
    edge(int a, int b, int c):to(a),cap(b),rev(c){}
  };
  
  vector<vector<edge> > G;
  vector<int> level, iter;
  int MAX_V;
  
  Dinic(int max_v):G(max_v,vector<edge>()),MAX_V(max_v){}
  
  int add_edge(int from,int to,int cap){
    int id = G[from].size();
    
    G[from].push_back(edge(to,cap,G[to].size()));
    G[to].push_back(edge(from,0,G[from].size() - 1));
    
    return id;
  }
  
  void bfs(int s){
    level.assign(MAX_V,-1);
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while(q.size()){
      int v = q.front(); q.pop();
      for(int i=0;i<G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[e.to] < 0){
          level[e.to] = level[v] + 1;
          q.push(e.to);
        }
      }
    }
  }
  
  int dfs(int v, int t, int f){
    if(v == t) return f;
    for(int &i = iter[v];i < G[v].size(); i++){
      edge &e = G[v][i];
      if(e.cap > 0 && level[v] < level[e.to]){
        int d = dfs(e.to, t, min(f,e.cap));
        if(d > 0){
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  
  int solve(int s, int t){
    int flow = 0;
    while(1){
      bfs(s);
      if(level[t] < 0) return flow;
      iter.assign(MAX_V,0);
      int f;
      while((f = dfs(s, t, INF)) > 0) flow += f;
    }
  }
  
};

int main(){
  int n;
  string s;

  int count[26][26] = {};
  
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    count[s[0]-'a'][s[s.size()-1]-'a']++;
  }

  for(int i=0;i<26;i++){
    int sum = 0; bool f = false;
    
    Dinic d(28), d2(30);

    for(int j=0;j<26;j++) sum += count[i][j] * (i != j);
    for(int j=0;j<26;j++) f |= count[j][i];

    if(!f) continue;
    
    //debug(sum);
    
    for(int j=0;j<26;j++){
      for(int k=0;k<26;k++){
        if(j == k) continue;

        if(j == i){
          d.add_edge(26, k, count[j][k]);
          d2.add_edge(26, k, count[j][k]);
        }else if(k == i){
          d.add_edge(j, 27, count[j][k]);
          d2.add_edge(j, 27, count[j][k]);
        }else{
          d.add_edge(j, k, count[j][k]);
          d2.add_edge(j, k, count[j][k]);
        }
      }
    }

    d2.add_edge(28, 26, sum);
    d2.add_edge(28, 29, 1);
    for(int j=0;j<26;j++) if(i != j) d2.add_edge(29, j, 1);
    
    auto flow = d.solve(26, 27);
    auto flow2 = d2.solve(26, 27);

    if(flow == sum || flow2 == sum+1){
      printf("%c\n", i+'a');
    }
  }
  
  return 0;
}



Measured memory_bytes: 3404
from collections import deque
n=int(input())
mod=10**9+7
G=[[] for i in range(n)]
for i in range(n-1):
  x,y=map(int,input().split())
  x=x-1
  y=y-1
  G[x].append(y)
  G[y].append(x)
A=[0]*n
A[0]=1
B=deque([0])
C=[0]
GG=[[] for i in range(n)]
while len(B)>0:
  v=B[0]
  B.popleft()
  for i in range(len(G[v])):
    if A[G[v][i]]==0:
      A[G[v][i]]=1
      B.append(G[v][i])
      C.append(G[v][i])
      GG[v].append(G[v][i])
C=C[::-1]
dp=[[0]*2 for i in range(n)]
for i in range(n):
  if len(GG[C[i]])==0:
    dp[C[i]]=[1,1]
  else:
    a=1
    b=1
    for j in range(len(GG[C[i]])):
      a=(a*(dp[GG[C[i]][j]][0]+dp[GG[C[i]][j]][1]))%mod
      b=(b*dp[GG[C[i]][j]][0])%mod
    dp[C[i]][0]=a
    dp[C[i]][1]=b
print((dp[0][0]+dp[0][1])%mod)

Measured memory_bytes: 91936
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  long long n, k;
  cin>>n>>k;
  long long cnt[k + 1];
  REP(i, k + 1) cnt[i] = 0;
  cnt[k] = 1;
  for(long long d = k - 1; d > 0; d--){
    long long num = po(k / d, n);
    for(long long i = 2; i * d <= k; i++){
      num -= cnt[i * d];
      num = mod(num);
    }
    cnt[d] = num;
  }
  long long ans = 0;
  for(long long d = 1; d <= k; d++){
    ans += mod(d * cnt[d]);
    ans = mod(ans);
  }
  cout<<ans<<endl; 
  return 0;
}



Measured memory_bytes: 4360
// B

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  int N,M;
  cin>>N>>M;
  long double ans(0);
  int T = 1900*M + 100*(N-M);
  for (int i(1);i<=10000;i++){
    long double a = 1 / (long double)pow(2,M);
    long double b = 1 - a;
    long double tmp = T*i*(long double)pow(b,i-1)/(long double)pow(2,M);
    ans += tmp;
  }
  cout << ans << endl;
}




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

long long w[102], v[102];

long long dp[102][100002];

long long sentinel = 1e9 + 1;
void solve(long long n,long long sum, long long W) {
    int i, j;
    for(i=1;i<=sum;i++)
        dp[0][i] = sentinel;
    dp[0][0] = 0;
    for(i=1;i<=n;i++) {
        for(j=1;j<=sum; j++) {
            dp[i][j] = dp[i-1][j];
            if(j>=v[i] && dp[i-1][j - v[i]]  + w[i] <=W )
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i]);
                
           // cout<<i<<" , "<<j<<" : "<<dp[i][j]<<"\n";
        }
    }
}
int main() {
	long long n, W;
	cin>>n>>W;
	int i, j;
	int sum = 0;
	for(i=1;i<=n;i++)
	    cin>>w[i] >> v[i], sum+=v[i];
	for(i=1;i<=n;i++)
	    for(j=1;j<=1e5;j++)
	        dp[i][j] = sentinel;
	solve(n,sum,W);
	int ans = 0;
	for(i=sum;i>=1;i--)
	    if(dp[n][i]<= W) {
	        ans = i;
	        break;
	    }
	 cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 79104
input()
nums = list(map(int, input().split(' ')))

n = int(input())
for _ in range(n):
    f, m, l = list(map(int, input().split(' ')))
    m = m-f
    if f > l:
        f, l = l, f
    sb_1 = list(nums[f:f+m])
    sb_2 = list(nums[l:l+m])

    nums = nums[:f] + sb_2 + nums[f+m:l] + sb_1 + nums[l+m:]

print(' '.join(map(str, nums)))




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


int main(){
  int a,b,c;
  cin>>a>>b>>c;
  
  if(a > b) swap(a,b);
  if(b > c) swap(b,c);
  if(a > b) swap(a,b);
   
  cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 3104
def min_square(min_,max_,AB):
    mid=(min_+max_)//2
    if max_-min_<=1:
        if mid**2<AB:
            return mid
        else:
            return mid-1
    if mid**2 < AB:
        return min_square(mid,max_,AB)
    elif mid**2>AB:
        return min_square(min_,mid,AB)
    else:
        return mid-1

Q=int(input())
for i in range(Q):
    AB=list(map(int,input().split()))
    if AB[0]==AB[1]:
        print((AB[0]-1)*2)
        continue
    mid = min_square(min(AB),max(AB),AB[0]*AB[1])
    if mid*(mid+1)<AB[0]*AB[1]:
        print(mid*2-1)
    else:
        print(mid*2-2)

Measured memory_bytes: 3064