akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>
#include <set>

using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)
#define INF 1000000010
const int mo=1e9+7;




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

  set<int> a;

  r(i,n){
    int b;
    scanf("%d",&b);
    a.insert(b);
  }



  if(a.size()%2==0)printf("%d\n", a.size()-1);
  else printf("%d\n", a.size());

  return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

double combination(int a, int b){
  double ret = 1;
  for(int i = 0; i < b; ++i){
    ret *= (double)(a-i)/(i+1);
  }
  return ret;
}

int main(){
  int N, M, L;
  cin >> N >> M >> L;
  int P[N], T[N], V[N];
  for(int i = 0; i < N; ++i){
    cin >> P[i] >> T[i] >> V[i];
  }
  double prob[N][M+1];

  for(int i = 0; i < N; ++i) prob[i][0] = 1.0;
  for(int i = 0; i < N; ++i){

    for(int j = 1; j <= M; ++j){
      prob[i][j] = prob[i][j-1]*P[i]/100.0*(M-j+1)/j;
    }
    double t = 1.0;
    for(int j = M; j >= 0; --j){
      prob[i][j] *= t;
      t *= (1.0 - (double)P[i]/100.0);
    }
  }
  double acum[N][M+2];
  for(int i = 0; i < N; ++i) acum[i][M+1] = 0;
  for(int i = 0; i < N; ++i){
    for(int j = M; j >= 0; --j){
      acum[i][j] = acum[i][j+1] + prob[i][j];
    }
  }
  vector< vector<double> > time(N,vector<double>(M+1));
  for(int i = 0; i < N; ++i) time[i][0] = (double)L/V[i];
  for(int i = 0; i < N; ++i){
    for(int j = 1; j <= M; ++j){
      time[i][j] = time[i][j-1] + T[i];
    }
  }
  for(int i = 0; i < N; ++i){
    double ans = 0.0;
    for(int j = M; j >= 0; --j){
      double t = prob[i][j];
      for(int k = 0; k < N; ++k){
        if(k == i) continue;
        int id = upper_bound(time[k].begin(),time[k].end(),time[i][j]) - time[k].begin();
        if(id > M){
          t = 0;
          break;
        }
        t *= acum[k][id];
      }
      ans += t;
    }
    printf("%.12f\n",ans);
  }
  return 0;
}

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

int main() {
	string S("2019/04/30");
	int N, T, H;
	char c1, c2;
	cin >> N >> c1 >> T >> c2 >> H;
	if (N <= 2019 && T <= 4 && H <= 30)
		cout << "Heisei" << endl;
	else
		cout << "TBD" << endl;
	return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    int N; cin >> N;
    vi H(N); REP(i, N) cin >> H[i];

    vi dp(N, 0);
    dp[0] = 1;
    vi h = H;
    h[0]--;
    FOR(i,1, N) {
        if (h[i] - 1 >= h[i - 1]) h[i]--;

        dp[i] = dp[i - 1] == 1 && h[i - 1] <= h[i];
    }

    string ans = dp[N-1]==1 ? "Yes" : "No";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
import math
K = int(input())

runn=['0','1','2','3','4','5','6','7','8','9']
List=['1','2','3','4','5','6','7','8','9']
while True:
    if len(runn)-1>K:
        print(int(runn[K]))
        break
    else:
        list1=[]
        for i in range(len(List)):
            
            if List[i][-1]=='0':
                list1.append(List[i]+'0')
                list1.append(List[i]+'1')
            
            for u in range(1,9):
                if List[i][-1]=='{}'.format(u):
                    list1.append(List[i]+'{}'.format(u-1))
                    list1.append(List[i]+'{}'.format(u))
                    list1.append(List[i]+'{}'.format(u+1))
            if List[i][-1]=='9':
                list1.append(List[i]+'8')
                list1.append(List[i]+'9')
           # print(list1)
        List=list1
        runn=runn+list1
        #print(runn)        


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

ll kaisu(string S){//何回文字を変更するか
  int i=0;
  ll ans=0;
  while(i<=S.size()-2){
    if(S[i]==S[i+1]){
      ans++;
      i++;
    }
    i++;
  }
  return ans;
}

int main() {
  string S;
  ll K;
  cin>>S>>K;
  ll N=S.size();
  ll ans;
  
  if(S[0]!=S[N-1]) {
    ans = kaisu(S)*K;
    cout<<ans<<endl;
    return 0;
  }
  //S[0]==S[N-1]
  int i=0;
  ll X1=0,X2=0,X3;
  bool flag=true;//Sが全文字同じ文字の場合
  for(int i=0;i<=N-1;i++){
    if(S[i]==S[0]) X1++;
    else {
      flag=false;
      break;
    }
  }
  if(flag){
    ans=N*K/2;
    cout<<ans<<endl;
    return 0;
  }
  for(int i=N-1;i>=0;i--){
    if(S[i]==S[N-1]) X2++;
    else break;
  }
  X3 = X1+X2;
  ans=kaisu(S)*K-(X1/2+X2/2-X3/2)*(K-1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
A, B = map(int,input().split())

if B <= 1:
    print(0)

elif A >= B:
    print(1)

elif (B-A) % (A-1) == 0:
    print((B-A) // (A-1) + 1)

else:
    print((B-A) // (A-1) + 2)

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

#ifndef __TOPCYBERFLOWER
#define debug(...) 0
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

#define TYPEMAX(type)   numeric_limits<type>::max()
#define TYPEMIN(type)   numeric_limits<type>::min()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int SZ=200005;
ll rems[SZ];
int pre[SZ];
int vst[SZ];
int mypow(int x, int y, int p){
    int res=1;
    while(y){
        if(y%2) res=(res*x)%p;
        x=(x*x)%p;
        y/=2;
    }
    return res;
}
int main(void){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n,p; cin>>n>>p;
    string s; cin>>s;
    if(p==2 || p==5){
        ll ans=0;
        for(int i=0;i<n;i++){
            if((s[i]-'0')%p==0) ans+=(ll)(i+1);
        }
        cout<<ans;
        return 0;
    }
    rems[0]++;
    for(int i=0;i<n;i++){
        pre[i+1]=(pre[i]*10+(s[i]-'0'))%p;
        int xx=(pre[i+1]*mypow(10,n-i,p))%p;
        rems[xx]++;
    }
    ll ans=0;
    for(int i=0;i<p;i++){
        if(rems[i]>1) ans+=rems[i]*(rems[i]-1)/2;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1428
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>
#include <map>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    map<char, int> mp;
    for(int i = 0; i < s.size(); i++) mp[s[i]]++;
    string target = "KUPC";
    int ans = 0;
    while(true)
    {
        int cnt = 0;
        for(int i = 0; i < target.size(); i++)
        {
            if(mp[target[i]] == 0) break;
            else
            {
                mp[target[i]]--;
                cnt++;
            }
        }
        if(cnt == 4) ans++;
        else break;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define ll long long int
#define ve vector<int>
#define vl vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vve vector<vector<int>>
#define all(a) a.begin(),a.end()
using namespace std;

int main(){
  double n,k;
  cin>>n>>k;
  int ans;
  ans=(log(n)/log(k))+1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
num = [0]*n
for i in A:
  num[i-1] += 1
def comb(n):
    if n < 2:
      return 0
    else:
      return n * (n-1) // 2
ans_sub = 0
for i in num:
  ans_sub += comb(i)
for i in A:
  if num[i-1] < 2:
    a = 0
  else:
    a = num[i-1]-1
  print(ans_sub-a)

Measured memory_bytes: 26140
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;


int main(void){
    // Your code here!
    
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    long double PI = acos(-1);
    
    long double A_Kaku = (H/12 + (M/60)/12) * (2*PI);
    long double B_kaku = M / 60.0 * (2 * PI);
    long double AB_kaku = A_Kaku - B_kaku;


        
    double ans = sqrt((A * A) + (B * B) - 2 * A * B * cos(AB_kaku)); 
    printf("%.10f\n", ans);

    
}


Measured memory_bytes: 3564
#include <cstdio>
#include <algorithm>

using namespace std;

int a, b;

int main() {

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

	int mid = (a + b) / 2;

	if (mid - a == b - mid) {
		printf("%d\n", mid);
	} else {
		puts("IMPOSSIBLE");
	}

	return 0;

}

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

int main(){
	int sx,sy,tx,ty;	cin>>sx>>sy>>tx>>ty;

	string ans="";
	for(int i=sy;i<ty;i++)ans+="U";
	for(int i=sx;i<tx;i++)ans+="R";
	for(int i=sy;i<ty;i++)ans+="D";
	for(int i=sx;i<tx;i++)ans+="L";
	ans+="L";	
	for(int i=sy;i<ty+1;i++)ans+="U";
	for(int i=sx-1;i<tx;i++)ans+="R";
	ans+="DR";
	for(int i=sy;i<ty+1;i++)ans+="D";
	for(int i=sx;i<tx+1;i++)ans+="L";
	ans+="U";


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


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


int main(void) {
  // エラトステネスの篩
  int MAX = 101010;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0, is_prime[1] = 0;
  for (int i = 2; i < MAX; ++i) {
    // すでに素数でないとされているので飛ばす
    if (!is_prime[i]) continue;
    // iの2倍3倍4倍はiで割り切れる
    for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
  }

  // 2017-like 数かどうか
  // Nも(N+1)/2も素数を満たす奇数Nかどうかの配列
  vector<int> a(MAX, 0);
  for (int i = 0; i < MAX; ++i) {
    if (i % 2 == 0) continue;
    if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
  }

  // 上の配列を利用して、累積和する
  vector<int> s(MAX+1, 0);
  for (int i = 0; i < MAX; ++i) s[i+1] = s[i] + a[i];

  // クエリ処理
  int Q;
  cin >> Q;
  for (int q = 0; q < Q; ++q) {
    int l, r;
    cin >> l >> r;
    ++r;

    cout << s[r] - s[l] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e17;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

ll n, q;
ll nxt[N][30];
char arr[N];
ll dp[255][255][255];

string a, b, c;

ll recur(ll posa, ll posb, ll posc) {

  if (posa == 0 && posb == 0 && posc == 0)
    return 0;
  ll &ans = dp[posa][posb][posc];
  if (ans != -1)
    return ans;

  ans = n + 1;
  if (posa) {
    ll len = recur(posa - 1, posb, posc);
    //  cout << posa << " " << len << endl;
    ans = min(ans, nxt[len + 1][a[posa] - 'a']);
  }
  if (posb) {
    ll len = recur(posa, posb - 1, posc);
    ans = min(ans, nxt[len + 1][b[posb] - 'a']);
  }
  if (posc) {
    ll len = recur(posa, posb, posc - 1);
    ans = min(ans, nxt[len + 1][c[posc] - 'a']);
  }

  return ans;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  ll freq[30];
  memset(freq, 0, sizeof(freq));
  string s;
  cin >> s;
  for (char c : s) {
    freq[c - 'a']++;
  }

  for (ll i = 1; i < n; i++) {
    string s;
    cin >> s;
    ll freq2[30];
    memset(freq2, 0, sizeof(freq2));
    for (char c : s) {
      freq2[c - 'a']++;
    }
    for (ll i = 0; i < 30; i++)
      freq[i] = min(freq[i], freq2[i]);
  }

  for (ll i = 0; i < 26; i++) {
    while (freq[i]--)
      cout << (char)(i + 'a');
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int n,m,i,j,temp1,temp2;
	int s[101], t[101];
	int count, ssum, tsum;
	int cht, chh, check;
	
	while(scanf("%d %d",&n,&m))
	{
		if(n==0&&m==0)
		break;
		else
		{
			ssum = 0;
			tsum = 0;
			count = 201;
			check = 0;
			for(i=0;i<n;i++){
				scanf("%d",&s[i]);
				ssum+=s[i];
			}
			for(i=0;i<m;i++){
				scanf("%d",&t[i]);
				tsum+=t[i];
			}
			for(i=0;i<n;i++)
			{
				for(j=0;j<m;j++)
				{
					temp1 = ssum-s[i];
					temp2 = tsum-t[j];
					temp1+=t[j];
					temp2+=s[i];
					if(temp1==temp2&&count>s[i]+t[j])
					{
						count=s[i]+t[j];
						cht = s[i];
						chh = t[j];
						check = 1;
					}
				}
			}
			if(check==0)
			printf("-1\n");
			else
			printf("%d %d\n",cht,chh);
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
    char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const int maxn=2e5+5;
struct E{int v,nxt,w;}e[maxn<<1];
struct Edge{int a,b;LL c;}E[maxn*55];
int sum[maxn],vis[maxn],head[maxn],mx[maxn],a[maxn],fa[maxn],sz[maxn];
int n,num,m,dx,S,rt;LL dw,ans,pre[maxn];
inline void add(int x,int y,int z) {
    e[++num].v=y;e[num].nxt=head[x];head[x]=num;e[num].w=z;
}
void getroot(int x,int fa) {
    sum[x]=1,mx[x]=0;
    for(re int i=head[x];i;i=e[i].nxt) {
        if(vis[e[i].v]||e[i].v==fa) continue;
        getroot(e[i].v,x);sum[x]+=sum[e[i].v];
        mx[x]=max(mx[x],sum[e[i].v]);
    }
    mx[x]=max(mx[x],S-sum[x]);
    if(mx[x]<mx[rt]) rt=x;
}
void getdis(int x,int fa) {
    E[++m]=(Edge){dx,x,pre[x]+a[x]+dw};
    for(re int i=head[x];i;i=e[i].nxt) {
        if(vis[e[i].v]||e[i].v==fa) continue;
        getdis(e[i].v,x);
    }
}
void chk(int x,int fa) {
    if(pre[x]+a[x]<dw) dw=pre[x]+a[x],dx=x;
    for(re int i=head[x];i;i=e[i].nxt) {
        if(vis[e[i].v]||e[i].v==fa) continue;
        pre[e[i].v]=pre[x]+e[i].w;chk(e[i].v,x);
    }
}
void dfs(int x) {
    dx=x,dw=a[x];vis[x]=1;pre[x]=0,chk(x,0),getdis(x,0);
    for(re int i=head[x];i;i=e[i].nxt) {
        if(vis[e[i].v]) continue;
        S=sum[e[i].v],rt=0,getroot(e[i].v,0),dfs(rt);
    }
}
inline int cmp(Edge A,Edge B) {return A.c<B.c;}
inline int find(int x) {return x==fa[x]?x:fa[x]=find(fa[x]);}
inline int merge(int x,int y) {
    int xx=find(x),yy=find(y);
    if(xx==yy) return 0;
    if(sz[xx]<sz[yy]) fa[xx]=yy,sz[yy]+=sz[xx];
        else fa[yy]=xx,sz[xx]+=sz[yy];
    return 1;
}
int main() {
    n=read();
    for(re int i=1;i<=n;i++) a[i]=read();
    for(re int x,y,z,i=1;i<n;i++) 
        x=read(),y=read(),z=read(),add(x,y,z),add(y,x,z); 
    mx[0]=n+1,S=n,rt=0,getroot(1,0),dfs(rt);
    std::sort(E+1,E+m+1,cmp);
    for(re int i=1;i<=n;i++) sz[i]=1,fa[i]=i;
    for(re int i=1;i<=m;i++) if(merge(E[i].a,E[i].b)) ans+=E[i].c;
    std::cout<<ans;
    return 0;
}

Measured memory_bytes: 74496
N,M=map(int,input().split(' '))
l = [0]
for i in range(1,int(pow(M,0.5)+2)):
    if M%i==0:
        l.append(i)
        l.append(M//i)
if len(l)==1:
    print(0)
    exit()
l = sorted(list(set(l)))
for n,i in enumerate(l[1:]):
    if M/i<N:
        print(l[n])
        exit()
print(l[-1])

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    int ans = 0;
    for(int j = 1; j <= i; j++) {
      for(int k = 1; k <= i; k++) {
        if(j * j + k * k + j * k + j + k > n) {
          break;
        }
        for(int l = 1; l <= i; l++) {
          int num = j * j + k * k + l * l + j * k + k * l + l * j;
          if(num > i) {
            break;
          }
          if(num == i) {
            ans++;
            break;
          }
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    string S,T;

    cin >>S;
    cin >> T;


    int Ssize= S.size();
    int Tsize= T.size();

    int minnum =Tsize;    
    for(int i=0;i<(Ssize -Tsize)+1;++i){
        int tnum =0;
        for(int j=0;j<Tsize;++j){
            if(S[i+j] == T[j]){

            }
            else{
                ++tnum;
            }
        }
        if(minnum  > tnum){
            minnum = tnum;
        }
    }

    cout<<minnum<<endl;

}



Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		int s = scan.nextInt();
		int ans = 0;
		for (int i = 0; i <= k; i++) {
			for (int j = 0; j <= k; j++) {
				int temp = s - i - j;
				if (k >= temp && temp >= 0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
import java.util.Scanner;

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

		int leader = 0;
		int ans = Integer.MAX_VALUE;

		int E[] = new int[N+1];
		int W[] = new int[N+1];
		W[0] = 0;
		// E[0] = 0;


		int count = 0;
		for (int a = 0; a < N; a++) {
			if (S.charAt(a) == 'W') {
				count++;
				W[a+1] = count;
			} else {
				W[a+1] = count;
			}
		}
		count = 0;
		int i = N-1;
		for (int a = N-1; a >= 0; a--) {
			// System.out.println("S.charAt(a) "+S.charAt(a));
			if (S.charAt(a) == 'E') {
				count++;
				E[i] = count;
			} else {
				E[i] = count;
			}
			i--;
		}
		
		// System.out.println(Arrays.toString(W));
		// System.out.println(Arrays.toString(E));
		
		for (int a = 0; a <= N; a++) {
			int left = W[a];
			// System.out.println("a "+ a+" left "+left);
			int right = E[a];
			// System.out.println("a "+ a+" riht "+right);
			ans = Math.min(ans, (left+right));
		}
		System.out.println(ans);
	}
}
// https://www.youtube.com/watch?v=w2AEXSloYk8

//0 1 1 2 2 3 3 3 3 4 5 6 6
// W E W E W E E E W W W E
//
//0 1 1 1 1 2 3 4 4 5 5 6 6
// E W W W E E E W E W E W



//0 0 0 1 2 2
// W W E E W


Measured memory_bytes: 30732
#include <stdio.h>

int main() {
	int x[101], y[101], N, M, i, max, min;

	scanf("%d %d %d %d", &N, &M, &x[0], &y[0]);
	max = x[0];
	min = y[0];

	for (i = 1; i <= N; i++) {
		scanf("%d", &x[i]);
		if (x[i] > max) max = x[i];
	}
	for (i = 1; i <= M; i++) {
		scanf("%d", &y[i]);
		if (y[i] < min) min = y[i];
	}

	if (max < min) {
		printf("No War");
	}
	else {
		printf("War");
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  
  int min_ = p[0];
  int ans = 1;
  rep(i, n-1) {
    int j = i+1;
    if (min_ > p[j]) ans++;
    min_ = min(min_, p[j]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main{

    static int bubbleSort(int[] a, int n){
        int count = 0;
        int flag = 1;
        while(flag == 1){
            flag = 0;
            for(int i = n - 1; i >= 1; i--){
                if(a[i - 1] > a[i]){
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp; 
                    flag = 1;
                    count++;
                }
            }
        }
        return count;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());;
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());;
        }

        int bs = bubbleSort(a, n);

        for(int i = 0; i < n - 1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n - 1]);

        System.out.println(bs);
    }
}


Measured memory_bytes: 26164
class Node:
    def __init__(self, parent, left, right):
        self.parent = parent
        self.left = left
        self.right = right


n = int(input())

node = {k: Node(-1, -1, -1) for k in range(n)}

for u in range(n):
    tmp = list(map(int, input().split()))
    if tmp[1] == 0:
        continue
    node[tmp[0]].left = tmp[2]
    node[tmp[2]].parent = tmp[0]
    prev_sibling = tmp[2] 
    for sib in tmp[3:]:
        node[prev_sibling].right = sib
        node[sib].parent = tmp[0]
        prev_sibling = sib

def get_depth(node, u):
    d = 0
    while node[u].parent is not -1:
        u = node[u].parent
        d += 1
    return d


def list_children(node, u):
    chilren = []
    c = node[u].left
    while c is not -1:
        chilren.append(c)
        c = node[c].right
    return chilren


for i in range(n):
    node_id = i
    node_parent = node[i].parent
    node_depth = get_depth(node, i)
    node_children = list_children(node, i)
 
    if node_parent == -1:
        node_type = "root"
    elif len(node_children) > 0 :
        node_type = "internal node"
    else:
        node_type = "leaf"

    print("node {}: parent = {}, depth = {}, {}, {}".format(node_id, node_parent, node_depth, node_type, node_children))



Measured memory_bytes: 41628
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  while(true){
  ll n;cin>>n;
  if(!n)break;
  vll p(n);
  vvll dp(n,vll(n,0));
  rep(i,0,n){
    cin>>p[i];
  }
  
  rep(haba,2,n+1){
    rep(i,0,n-haba+1){
      int j=i+haba-1;
      if(dp[i+1][j-1]==haba-2&&abs(p[i]-p[j])<=1){
        dp[i][j]=haba;
      }
      rep(k,i,j){
        dp[i][j]=max(dp[i][j],dp[i][k]+dp[k+1][j]);
      }
    }
  }
  cout<<dp[0][n-1]<<endl;
  }
}



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

int main()
{
   int h,w,cnt=0,k=0;
   char ch;
   string s="\0",str[105];
   scanf("%d %d",&h,&w);
   for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        cin>>ch;
       if(ch=='.'){
        cnt++;
       }
     s+=ch;

    }
    if(cnt!=w){
       str[k++]=s;
    }
    s="\0";
    cnt=0;
   }
   cnt=0;
   for(int i=0;i<w;i++){
    for(int j=0;j<k;j++){
     if(str[j][i]=='.'){
        cnt++;
     }
    // printf("j %d i %d\n",j,i);
    }
    if(cnt==k){
        for(int r=0;r<k;r++){
            str[r][i]='1';////////
        }
    }
    cnt=0;
   }
   for(int p=0;p<k;p++){
     for(int i=0;i<w;i++){
        if(str[p][i]!='1'){
            printf("%c",str[p][i]);
        }
     }
     printf("\n");
   }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <cstring>

using namespace std;

struct Circle {
    int x, y, r, c;
    Circle() {}
    Circle(int x, int y, int r, int c)
        : x(x), y(y), r(r), c(c) {}
};

int n;
vector<char> dp;
vector<int> up;
vector<Circle> c(24);

inline bool isOverlap(const Circle &a, const Circle &b)
{
    int r = (a.r + b.r) * (a.r + b.r);
    int d = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
    return r > d;
}

int Rec(int s)
{
    if (~dp[s])
        return dp[s];

    int res = 0;
    // 取り除く2つの円の選択
    for (int i = 0; i < n; ++i) {
        // c[i]がないか取り除けない
        if (!(s >> i & 1) || s & up[i])
            continue;

        for (int j = i + 1; j < n; ++j) {
            // c[i]とc[j]の色が異なる
            if (c[i].c != c[j].c)
                continue;
            // c[j]がないか取り除けない
            if (!(s >> j & 1) || s & up[j])
                continue;
            res = max(res, Rec(s & ~(1 << i) & ~(1 << j)) + 2);
        }
    }

    return dp[s] = res;
}

int main()
{
    while (cin >> n, n) {
        dp.assign(1 << n, -1);
        up.assign(n, 0);

        // 円の入力
        for (int i = 0; i < n; ++i)
            cin >> c[i].x >> c[i].y >> c[i].r >> c[i].c;

        // 円の重なり，上下関係
        for (int i = 0; i < n; ++i)
            for (int j = i + 1; j < n; ++j)
                if (isOverlap(c[i], c[j]))
                    up[j] |= (1 << i);

        cout << Rec((1 << n) - 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 17424
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

ll modComb(ll n, ll k) {
    ll tmp = 1;
    for (int i = 0; i < k; i++) {
        tmp *= n - i;
        tmp %= MOD;
    }
    for (int i = 1; i <= k; i++) {
        tmp *= modInv(i);
        tmp %= MOD;
    }
    return tmp;
}

vector<ll> graph[200010];

//start_sumは最初の人間の番号
//返り値はグラフの要素の総和
ll bfs(ll start_num, vector<bool>& checked) {
    ll graph_sum = 1;

    queue<ll> next_num;
    next_num.push(start_num);
    checked[start_num] = true;

    while (!next_num.empty()) {
        for (ll i = 0; i < (ll)graph[next_num.front()].size(); i++) {
            ll tmp_next_num = graph[next_num.front()][i];
            if (!checked[tmp_next_num]) {
                checked[tmp_next_num] = true;
                next_num.push(tmp_next_num);
                graph_sum++;
            }
        }
        next_num.pop();
    }
    return graph_sum;
}

int main() {

    ll N, M;
    
    vector<bool> checked(200010, false);
    
    ll ans = 0;

    cin >> N >> M;
    rep(i, M) {
        ll A, B;
        cin >> A >> B;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }

    for (ll i = 1; i <= N; i++) {
        if (!checked[i]) {
            ll graph_sum = bfs(i, checked);
            ans = max(ans, graph_sum);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 16684
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * Problem A: Dirichlet's Theorem on Arithmetic Progressions
 */
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		boolean[] ps = new boolean[1000000 + 1];
		Arrays.fill(ps, true);
		ps[0] = false;
		ps[1] = false;

		for (int i = 2; i < ps.length; i++) {
			if (ps[i]) {
				for (int j = i * 2; j < ps.length; j += i) {
					ps[j] = false;
				}
			}
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			StringTokenizer st = new StringTokenizer(line);

			int a, d, n;
			a = parseInt(st.nextToken());
			d = parseInt(st.nextToken());
			n = parseInt(st.nextToken());
			if ((a | d | n) == 0) break;

			int i = a, c = 0;
			while (true) {
				if (ps[i]) {
					c++;
					if (c == n) break;
				}
				i += d;
			}
			System.out.println(i);

		} // end while
	} // end main
}

Measured memory_bytes: 27656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String X = sc.next();

		for (int i = 0; i < X.length(); i++) {
			int let = X.charAt(i) + N;
			if (let > 90) {
				let = let - 26;
			}
			System.out.print((char)let);
		}

	}
}

Measured memory_bytes: 39860
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.CodeFes2017QB
{
    class XXFESTIVAL
    {
        public static void Main()
        {
            var str = ReadLine().Trim();
            WriteLine(str.Substring(0, str.Length - 8));
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <ctype.h>

int main() {

	char ch, str[1200];
	int i = 0;

	while (1) {

		scanf("%c",&ch);
		if (islower(ch) != 0) {
			ch = toupper(ch);
		}
		else if (isupper(ch)!=0){
			ch = tolower(ch);
		}
		str[i] = ch;
		printf("%c", str[i]);
		i++;
		if (ch == '\n') {
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,m,r,a,b,c,lis[10];
int used[10],li[210][210]={};
ll mi=LINF;
vector<int> vec;

ll solve(){
	ll s=0;
	REP(i,0,vec.size()-1) s+=li[vec[i]][vec[i+1]];
	
	return s;
}

int dfs(int i,int d){
	if(used[i]||d>r) return 0;
	used[i]=true; vec.push_back(lis[i]);
	if(d==r){mi=min(mi,solve());}
	
	REP(i,0,r) dfs(i,d+1);
	
	used[i]=false; vec.pop_back();
	return 0;
}

int main(){
	cin >> n >> m >> r;
	REP(i,0,r) cin >> lis[i],lis[i]--;
	REP(i,0,n) REP(j,0,n) if(i!=j) li[i][j]=INF;
	REP(i,0,m) cin >> a >> b >> c,li[a-1][b-1]=li[b-1][a-1]=c;
	
	REP(k,0,n) REP(i,0,n) REP(j,0,n) li[i][j]=min(li[i][j], li[i][k]+li[k][j]);
	
	REP(i,0,r) dfs(i,1);
	
	cout << mi << endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
		for(int i = 0; i < n; i++) {
			if(hm.containsKey(a[i]) && hm.get(a[i]) == 1) {
				hm.put(a[i], 0);
			} else {
				hm.put(a[i], 1);
			}
		}
		int cout = 0;
		for(int key : hm.keySet()) {
			if(hm.get(key) == 1) {
				cout++;
			}
		}
		System.out.println(cout);
	}
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;
constexpr int MAX = 2000200;

using namespace std;

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

	int cnt = 0;

	for (int i = 1; i <= m; i++){
		for (int j = 1; j <= d; j++) {
			int d10 = j / 10;
			int d1 = j % 10;

			if ((d1 * d10) == i && d1 >= 2 && d10 >= 2) {
				cnt++;
			}

		}
	}
	cout << cnt << endl;

	//cout << 24 % 10 << endl;
}




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

int main(){
    int a;
    cin >> a;
    int ans = a + a*a + a*a*a;
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n)  for (int i = 0; i < (int) (n); i++)
#define Rrep(i, n) for (int i = ((int) n - 1); i >= 0; i--)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
#define INF 2e15
#define MOD 10e9 + 7

typedef vector <int> vint;
typedef long long    ll;



int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    vector <int> seq(n);
    rep(i, n) {
        cin >> seq.at(i);
    }

    int marker = 1;

    rep(i, n) {
        if (seq.at(i) == marker) {
            marker++;
        }
    }
    if (marker == 1) {
        cout << "-1" << endl;
    }
    else {
        cout << n - marker + 1 << endl;
    }


    return 0;
}


Measured memory_bytes: 1152
#include<iostream>

using namespace std;

int main(){
 int n;
 cin>>n;
 int flag=0;
 while(n>0){
   int temp=n%10;
   if(temp==9){
     flag=1;
     break;
   }
   n=n/10;
 }
 if(flag){
    cout<<"Yes"<<endl;
 }else{
    cout<<"No"<<endl;
 }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define REP(i,n) for(int i=0; i<n;i++)
int main(){
    int i,n,k,s=1;
    int a[100001];
    cin >> n >> k;
    REP(i,n) cin >> a[i];
    for(i=0;s < n;i++) s += (k-1);
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 105;
const ll MOD = 1000000007;

int n;
int h[MAXN];

ll f[MAXN][MAXN][2];

bool vis[MAXN][MAXN][2];

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

ll dfs(int l,int r,bool fl)
{
	if (l > r)
		return fl;
	if (vis[l][r][fl])
		return f[l][r][fl];
	vis[l][r][fl] = 1;
	int H = max(h[l - 1],h[r + 1]),MN = 1e9;
	ll res = 1;
	for (int i = l;i <= r;i++)
		MN = min(MN,h[i]);
	int lst = l;
	for (int i = l;i <= r;i++)
		if (h[i] == MN)
		{
			(res *= dfs(lst,i - 1,1)) %= MOD;
			lst = i + 1;
		}
	f[l][r][1] = res * dfs(lst,r,1) * 2 % MOD;
	lst = l;
	res = 1;
	for (int i = l;i <= r;i++)
		if (h[i] == MN)
		{
			(res *= (dfs(lst,i - 1,0) + dfs(lst,i - 1,1) * ((i - 1 >= lst) + 1)) * 2) %= MOD;
			lst = i + 1;
		}
	f[l][r][0] = (res * (dfs(lst,r,0) + dfs(lst,r,1) * ((r >= lst) + 1)) - f[l][r][1]) % MOD;
	(f[l][r][1] *= power(2,MN - H - 1)) %= MOD;
	return f[l][r][fl];
}

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n;i++)
		scanf("%d",&h[i]);
	printf("%lld\n",(dfs(1,n,0) + dfs(1,n,1) + MOD + MOD) % MOD);
	return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;


public class Main {


    static void solve() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        Map<String, Integer>map = new HashMap<>();
        for (int i=0;i<n;i++) {
            String s = scan.next();
            if(map.containsKey(s)) {
                map.put(s, map.get(s) + 1);
            }else{
                map.put(s, 1);
            }
        }

        if(map.containsKey("AC")) {
            String ss = "AC x " + map.get("AC");
            System.out.println(ss);
        }else{
            System.out.println("AC x 0");
        }
        if(map.containsKey("WA")) {
            String ss = "WA x " + map.get("WA");
            System.out.println(ss);
        }else{
            System.out.println("WA x 0");
        }
        if(map.containsKey("TLE")) {
            String ss = "TLE x " + map.get("TLE");
            System.out.println(ss);
        }else{
            System.out.println("TLE x 0");
        }
        if(map.containsKey("RE")) {
            String ss = "RE x " + map.get("RE");
            System.out.println(ss);
        }else{
            System.out.println("RE x 0");
        }


//        long t = scan.nextLong();

//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
//            int res = n%1000;
//            System.out.println(res);
////            scase(n);
//        }
    }


    static void solveCase(int t, int x, String s) {

    }

    static void scase(long n) {

    }


    public static void main(String[] args) {
        solve();
        //        Main m = new Main();
        //        Scanner scan = new Scanner(System.in);

        //        long n = scan.nextLong();
        //        long r = scan.nextLong();
        //        List<Long> list = new ArrayList<>();
        ////        int[] arr = new int[n];
        //        for (long i=0;i<n;i++){
        //            list.add(scan.nextLong());
        //        }
//            System.out.println(ch);
        //        solve(n, arr);
        //        scan.close();
    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }


//    static class TreeNode {
//        int val;
//        TreeNode left;
//        TreeNode right;
//
//        TreeNode(int x) {
//            val = x;
//        }
//    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

}

Measured memory_bytes: 49312
#include <bits/stdc++.h>
#define Task        "test"
#define pb          emplace_back
#define fi          first
#define se          second
#define mp          make_pair
#define ll          long long
//#define int         int64_t

using namespace std;

typedef pair<ll, ll> pii;
const int N = (int)2e5 + 2;
const ll inf = (ll)1e18;

ll f[N][3];
int n, a[N];
char op[N];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n; op[0] = '+';
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        if(i < n) cin >> op[i];
    }
    fill_n(&f[0][0], N * 3, -inf);
    f[1][0] = a[1];
    for(int i = 2; i <= n; ++i) {
        if(op[i - 1] == '-') a[i] *= (-1);
        f[i][0] = max(max(f[i - 1][0], f[i - 1][2]) + a[i], f[i - 1][1] - a[i]);
        f[i][1] = max(f[i - 1][1] - a[i], f[i - 1][2] + a[i]);
        f[i][2] = f[i - 1][2] + a[i];
        if(op[i - 1] == '-') {
            f[i][1] = max(f[i - 1][0] + a[i], f[i][1]);
            f[i][2] = max(f[i - 1][1] - a[i], f[i][2]);
        }
    }
    cout << f[n][0];
}


Measured memory_bytes: 5504
from collections import Counter
n = int(input())
work = [Counter(list(input())) for i in range(n)]
temp = work[0]
for el in work[1:]:
    for k, v in temp.items():
        if k in el.keys():
            temp[k] = v if el[k] > v else el[k]
        else:
            temp[k] = 0
result = ""
for k, v in temp.items():
    if v > 0:
        result += k*v
print("".join(sorted(result)))

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

int main(){
    long long x,n;
    vector<long long>num;
    cin >> x;
    for(long long i = 0; i < x; i++){
        cin >> n;
        num.push_back(n);
    }
    long long min = *min_element(num.begin(), num.end());
    long long max = *max_element(num.begin(), num.end());
    long long sum = accumulate(num.begin(), num.end(),0LL);
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3280
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,int> P;

static const double eps = 10e-6;

class intersect_triangle{
private:
	double dst[3];
	double orig[3], dir[3];
	double vert0[3],vert1[3],vert2[3];

	double dot(double v1[3],double v2[3]){
		return v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2];
	}
	void cross(double dest[3],double v1[3],double v2[3]){
		dest[0] = v1[1]*v2[2]-v1[2]*v2[1];
		dest[1] = v1[2]*v2[0]-v1[0]*v2[2];
		dest[2] = v1[0]*v2[1]-v1[1]*v2[0];
	}

	void sub(double dest[3],double v1[3], double v2[3]){
		dest[0] = v1[0]-v2[0];
		dest[1] = v1[1]-v2[1];
		dest[2] = v1[2]-v2[2];
	}
public:
	intersect_triangle(double xp1,double yp1,double xp2,double yp2,double xp3,double yp3,
		double xk,double yk){
		vert0[0] = xp1;
		vert0[1] = yp1;
		vert0[2] = 0;

		vert1[0] = xp2;
		vert1[1] = yp2;
		vert1[2] = 0;

		vert2[0] = xp3;
		vert2[1] = yp3;
		vert2[2] = 0;

		orig[0] = xk;
		orig[1] = yk;
		orig[2] = -1;

		dst[0] = xk;
		dst[1] = yk;
		dst[2] = 1;

		double len = sqrt(pow(dst[0]-orig[0],2.0)+pow(dst[1]-orig[1],2.0)+pow(dst[2]-orig[2],2.0));
		dir[0] = (dst[0]-orig[0])/len;
		dir[1] = (dst[1]-orig[1])/len;
		dir[2] = (dst[2]-orig[2])/len;
	}

	bool is_intersect(){
		double edge1[3],edge2[3],tvec[3],pvec[3],qvec[3];
		double det,inv_det,t=0,v=0,u=0;

		sub(edge1,vert1,vert0);
		sub(edge2,vert2,vert0);

		cross(pvec,dir,edge2);

		det=dot(edge1,pvec);

		if(det > -eps && det < eps) return false;

		inv_det = 1.0/det;

		sub(tvec,orig,vert0);

		u=dot(tvec,pvec)*inv_det;
		if(u < 0.0 || u > 1.0) return false;

		cross(qvec,tvec,edge1);

		v=dot(dir,qvec) * inv_det;
		if(v < 0.0 || u+v > 1.0) return false;

		t = dot(edge2,qvec) * inv_det;

		return true;

	}
};

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

	for(int i=0;i<n;i++){
		double xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
			&xp1,&yp1,&xp2,&yp2,&xp3,&yp3,&xk,&yk,&xs,&ys);
		intersect_triangle inter_t1(xp1,yp1,xp2,yp2,xp3,yp3,xk,yk);
		intersect_triangle inter_t2(xp1,yp1,xp2,yp2,xp3,yp3,xs,ys);
		printf("%s\n",(inter_t1.is_intersect() && inter_t2.is_intersect()) 
			|| (!inter_t1.is_intersect() && !inter_t2.is_intersect())
			? "NG" : "OK");
	}
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#include <numeric>
#define fast()                        \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
#define PI 3.14159265358979323846
#define ff first
#define pb push_back
#define ss second
#define un unordered
#define for0(i, n) for (i = 0; i < n; i++)
#define for1(j, n) for (j = 1; j <= n; j++)
#define ll long long int
#define all(v) v.begin(), v.end()
#define t6 2000010
#define t5 200005
using namespace std;
#define mod 1000000007

ll mult(ll a,ll b){
 	return ((a%mod)*(b%mod))%mod;
}
ll power(ll x,ll y,ll p)
{
  ll res = 1; 
  x = x % p;  
  while (y > 0)
  {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve(){


	ll n,k;
	cin>>n>>k;
	ll res1=0;
	ll res[k+1]={0};
	for(int i=k;i>=1;i--){
		res[i]=power(k/i,n,mod);
		for(int j=2*i;j<=k;j+=i){
			res[i]-=res[j];
			res[i]+=mod;
			res[i]%=mod;
		}
	}
	for(ll i=1;i<=k;i++){
		
		res1+=mult(i,res[i]);
		//cout<<res<<" ";
		res1=res1%mod;
	}
	cout<<res1<<endl;


}

int main()
{
	fast()
	ll t = 1;
	for (ll i = 0; i < t; i++)
	{   //cout<<"Case #"<<i+1<<": ";
		solve();
	}   

	return 0;
}

Measured memory_bytes: 4424
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x){
    return mpow( x, MOD-2 );
}

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

    vector<ll> a(n);
    ll s = 0, s2 = 0;
    int i;
    for (i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        s = (s + a[i]) % MOD;
        s2 = (s2 + a[i] * a[i]) % MOD;
    }
    ll ans = (s*s - s2) % MOD*minv(2) % MOD;
    printf("%lld\n", ans);

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 4360
import heapq
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,R = IL()
if N >= 10:
  print(R)
else:
  print(R + 100*(10-N))

Measured memory_bytes: 38488
import java.util.Scanner;

public class Main {
		public static void main(String args[]) {
			Scanner sc = new Scanner(System.in);
			char array[] = new char[1200], cnt = 0;
			int code[] = new int['z'-'a'+1];
			String str;
			
			while(sc.hasNext()) {
				str = sc.next();
				for(int j = 0; j < str.length(); j++) {
					array[cnt] = str.charAt(j);
					cnt++;
				}
			}
			sc.close();
			
			for(int i = 0; i < cnt; i++) {
				if(array[i] <= 90 && array[i] >= 65) {
					array[i] += 'a' - 'A';
				}
				
				if(array[i] >= 97 && array[i] <= 122) {
					code[(int) array[i] - 97]++;
				}
			}
			
			for(int i = 0; i < 'z'-'a'+1; i++) {
				System.out.printf("%c : %d\n", 97+i, code[i]);
			}
		}
}


Measured memory_bytes: 26360
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define Rep(i, s, n) for (ll i = (ll)s; i < (ll)n; i++)
#define len(array) (sizeof(array) / sizeof(array[0]))
 
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;
    cin >> a >> b;
    if ((a+b)%2) cout << "IMPOSSIBLE" << endl;
    else cout << (a+b)/2 << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=1000000000;
ll INF=10000000000000000;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n){
        string u;
        cin >> u;
        sort(u.begin(),u.end());
        s.at(i)=u;
    }
    sort(s.begin(),s.end());
    ll q=1;
    ll ans=0;
    rep(i,n-1){
        if (s.at(i)==s.at(i+1)){
            q++;
        }
        else {
            ans+=q*(q-1)/2;
            q=1;
        } 
    }
    ans+=q*(q-1)/2;
            q=1;
    cout << ans << endl;
}


Measured memory_bytes: 5760
N = int(input())
if N%2 == 0:
  m = N//2
  print(N,N,m)
else:
  f = True
  for h in range(1,3501):
    for n in range(1,3501):
      w_ = (-(h+n)/(h*n) + 4/N)
      if w_ > 0:
        w = (1/w_)
        if w%1 < 10E-8:
          print(h,n,int(w))
          f = False
          break
    if not f:
      break

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
A.append(0)

money = 1000
stock = 0
for i in range(N):
    if A[i] < A[i+1]:
        if money >= A[i]:
            stock += money // A[i]
            money %= A[i]
    elif A[i] > A[i+1]:
        money += stock * A[i]
        stock = 0
        
print(money)

Measured memory_bytes: 9200