akhauriyash/Code-Regression huggingface dataset:
import std;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long A, B, C, D;
    scan(A, B, C, D);
    long t = (C + B - 1) / B;
    long a = (A + D - 1) / D;
    writeln((t <= a) ? "Yes" : "No");
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int popcount(string s)
{
  int ans=0;
  for(int i=0;i<s.length();i++)if(s[i]=='1')ans++;
  
  //else for(int i=0;i<32;i++)if((1<<i)&n)ans++;
  return ans;
}
long long op(int n)
{
  long long ans=0;
  int t=n;
  while(t!=0)
  {
	t=t%__builtin_popcount(t);
    ans++;
  }
  return ans;
}
string tc()
{
  string s="";
  for(int i=0;i<200000;i++)
  {
    char c=(rand()%2)+'0';
    s.push_back(c);
  }
  return s;
}
long long fast_exp(int a,int b,int mod)
{
  long long x=a;
  long long y=(b%2)? x:1;
  b>>=1;
  while(b>0)
  {
    x=((x%mod)*(x%mod))%mod;
    if(b%2)
    {
      y=(y==1)? x:((x%mod)*(y%mod))%mod;
    }
    b>>=1;
  }
  return y;
}
int main()
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  int pc1=popcount(s);
  int pos_x=0;
  int neg_x=0;
  int pos_t=1;
  int neg_t=1;
  vector<int>pp(n);
  vector<int>np(n);
  for(int i=0;i<n;i++)
  {
    if(s[i]=='0')continue;
    if(pc1>0)
    {
    	pp[n-1-i]=pos_t%(pc1+1);
    	pos_x=(pos_x+(fast_exp(2,n-i-1,pc1+1)))%(pc1+1);
    	
    }
    if(pc1>1)
    {
      np[n-1-i]=neg_t%(pc1-1);
      neg_x=(neg_x+(fast_exp(2,n-i-1,pc1-1)))%(pc1-1);
    }
  }
  for(int i=0;i<n;i++)
  {
    if(s[i]=='0')
    {
      int o=(pos_x+fast_exp(2,n-1-i,pc1+1))%(pc1+1);
      cout<<op(o)+1<<endl;
    }
    else if(s[i]=='1' && pc1>1)
    {
      int y=(neg_x+pc1-1-fast_exp(2,n-1-i,pc1-1))%(pc1-1);
      cout<<op(y)+1<<endl;
    }
    else cout<<0<<endl;
  }
  return 0;
}

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

#define N 112345
char x[N];
int a[N]={};

int main(){
  int n, q; scanf("%d%d%s", &n, &q, x);
  REP(i, n) if(x[i]=='A' && x[i+1]=='C') a[i+1]=1;
  REP(i, n+1) a[i+1]+=a[i];
  REP(i, q){
  	int s, t; scanf("%d%d", &s, &t); s--; t;
    int ans = a[t]-a[s];
    if(x[t-1]=='A' && x[t]=='C') ans--;
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 1280
import numpy as np
from itertools import product
H, W, K = map(int, input().split())
G = np.array([list(map(int, input())) for _ in range(H)])
 
ans = float('inf')

for pattern in product([0, 1], repeat=H - 1):
    # スライスで横方向への割り方を表現する
    div=[0]
    for i, p in enumerate(pattern):
      if p==1:
        div= div+[i+1]
    div += [10]       
    
     # 横方向へ割った後、各ブロックについて縦方向にホワイトチョコの数を修正
    rows = []
    for i in range(len(div) - 1):
        rows.append(np.sum(G[div[i]: div[i + 1]], axis=0))
    
     # 縦方向にすでにK個より多いホワイトチョコが含まれている場合はどうにもならない
    count=0
    for r in rows:
      if np.any(r>K):
        count=1
    if count==1:
      continue
    
    # 縦方向に貪欲に割っていく
    rows = [r.tolist() for r in rows]
    tmp_ans = 0
    counts = [0] * len(rows)
    w = 0
    
    while w<W:
      for r in range(len(rows)):
        counts[r] += rows[r][w]
        
      if any([c>K for c in counts]):
        counts=[0] * len(rows)
        w -=1
        tmp_ans += 1
      
      w+=1
    a=tmp_ans +len(div)-2
    ans=min(a,ans)
  
print(ans)

Measured memory_bytes: 14176
n,a,b,c = map(int,input().split())
s = []
for _ in range(n):
    s.append(input())
if a + b + c == 0:
    print('No')
elif a + b + c == 1:
    ans = ''
    for i in range(n):
        if s[i] == 'AB':
            if a == 1 and b == 0:
                a = 0
                b = 1
                ans += 'B'
            elif a == 0 and b == 1:
                a = 1
                b = 0
                ans += 'A'
            else:
                print('No')
                exit()
        elif s[i] == 'BC':
            if b == 1 and c == 0:
                b = 0
                c = 1
                ans += 'C'
            elif b == 0 and c == 1:
                b = 1
                c = 0
                ans += 'B'
            else:
                print('No')
                exit()
        else:
            if a == 1 and c == 0:
                a = 0
                c = 1
                ans += 'C'
            elif a == 0 and c == 1:
                a = 1
                c = 0
                ans += 'A'
            else:
                print('No')
                exit()
    print('Yes')
    for i in range(n):
        print(ans[i])
else:
    ans = ''
    s2 = 'AC'
    for i in range(n):
        s1 = s[i]
        if i != n-1:
            s2 = s[i+1]
        if s1 == 'AB':
            if a >= 1 and b == 0:
                a -= 1
                b = 1
                ans += 'B'
            elif a == 0 and b >= 1:
                a = 1
                b -= 1
                ans += 'A'
            elif a >= 1 and b >= 1:
                if s2 == 'BC':
                    b += 1
                    a -= 1
                    ans += 'B'
                else:
                    a += 1
                    b -= 1
                    ans += 'A'
            else:
                print('No')
                exit()
        elif s1 == 'BC':
            if b >= 1 and c == 0:
                b -= 1
                c = 1
                ans += 'C'
            elif b == 0 and c >= 1:
                b = 1
                c -= 1
                ans += 'B'
            elif b >= 1 and c >= 1:
                if s2 == 'AC':
                    c += 1
                    b -= 1
                    ans += 'C'
                else:
                    b += 1
                    c -= 1
                    ans += 'B'
            else:
                print('No')
                exit()
        else:
            if a >= 1 and c == 0:
                a -= 1
                c = 1
                ans += 'C'
            elif a == 0 and c >= 1:
                a = 1
                c -= 1
                ans += 'A'
            elif a >= 1 and c >= 1:
                if s2 == 'AB':
                    a += 1
                    c -= 1
                    ans += 'A'
                else:
                    a -= 1
                    c += 1
                    ans += 'C'
            else:
                print('No')
                exit()
        # s1 = s2
    print('Yes')
    for i in range(n):
        print(ans[i])


Measured memory_bytes: 16292
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string a,b,c;
    string hantei,stock;
    cin >> a >> b >> c;
    stock = a;
    hantei = a.erase(1);
    a = stock.substr(1);
    for(int i=0;;i++){
        if(hantei == "a"){
            if(a.empty()){
                cout << "A" << endl;
                break;
            }
            stock = a;
            hantei = a.erase(1);
            a = stock.substr(1);
        }
        else if(hantei == "b"){
            if(b.empty()){
                cout << "B" << endl;
                break;
            }
            stock = b;
            hantei = b.erase(1);
            b = stock.substr(1);
        }
        else if(hantei == "c"){
            if(c.empty()){
                cout << "C" << endl;
                break;
            }
            stock = c;
            hantei = c.erase(1);
            c = stock.substr(1);
        }
    }
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
 
long [100] L;
 
long foo(int n) {
if(L[n]==0) {
L[n]= foo(n-1) + foo(n-2);
}
return L[n];
}
 
void main() {
int N = readln().chomp().to!(int);
L[0]=2;L[1]=1;
writeln(foo(N));
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for (int i=a; i<(b);++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;

int N,A,sum;
int x[55];
ll dp[55][2505][55]; // iばんめまで見たとき、jの和、kこ選んだ。

int main(){
    cin >> N >> A;
    REP(i,N){
        cin >> x[i];
        sum += x[i];
    }

    dp[0][0][0] = 1; // 0ばんめまで見た時、和が0、選んだ枚数が0
    REP(i,N){
        REP(j,sum+1){
            REP(k,N){
               dp[i+1][j][k] += dp[i][j][k]; // i番目の数字を使わない
               dp[i+1][j+x[i]][k+1] += dp[i][j][k]; // 使う
            }
        }
    }

    ll ans = 0;
    rep(i,1,N+1) ans += dp[N][i*A][i]; // 平均値　＝　j / k
    cout << ans << endl;
}

Measured memory_bytes: 54528
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    while(1)
    {
        int nb_ballons;
        cin>>nb_ballons;
        if(nb_ballons==0) break;
        vector<vector<int> > dp(nb_ballons+2,vector<int>(4,100000000));
        vector<int> position(nb_ballons+2);
        vector<int> temps(nb_ballons+2);
        for(int c=1;c<=nb_ballons;c++) cin>>position[c]>>temps[c];
        position[0]=temps[0]=0;
        position[nb_ballons+1]=0;
        temps[nb_ballons+1]=100000000;
        dp[0][0]=0;

        for(int c=1;c<=nb_ballons+1;c++)
        {
            bool okidoki = false;
            for(int c2=0;c2<4;c2++)
            {
                int duree = position[c-1]*(c2+1)+position[c];
                if(duree+temps[c-1]<=temps[c]&&dp[c-1][c2]<100000000)
                {
                    okidoki=true;
                    dp[c][1]=min(dp[c][1],dp[c-1][c2]+position[c]+position[c-1]);
                }
                if(c2+1<=3)
                {
                    duree = abs(position[c-1]-position[c])*(c2+1);
                    if(duree+temps[c-1]<=temps[c]&&dp[c-1][c2]<100000000)
                    {
                        dp[c][c2+1]=min(dp[c][c2+1],dp[c-1][c2]+abs(position[c]-position[c-1]));
                        okidoki=true;
                    }
                }
            }
            if(!okidoki)
            {
                cout<<"NG "<<c<<endl;
                goto end;
            }
        }
        cout<<"OK "<<dp[nb_ballons+1][1]<<endl;
        end:;
    }
}

Measured memory_bytes: 1216
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
string s;
ll ans=0;
int main()
{
	cin>>s;
	int n=s.size();
	for(int i=0;i<(1<<(n-1));i++)
	{
		ll num=0;
		for(int j=0;j<n;j++)
		{
			num=num*10+(s[j]-'0');
			if(1&(i>>j))
			{
				ans+=num;
				num=0;
			}
		}
		ans+=num; 
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
a, b, c = [int(i) for i in input().split()]

if a%2==1 or b%2==1 or c%2==1:
    print(0)
    sys.exit()
if a==b and b==c:
    print(-1)
    sys.exit()

i=0
while True:
    if a%2==1 or b%2==1 or c%2==1:
        print(i)
        sys.exit()
    else:
        d=(b+c)/2
        e=(a+c)/2
        f=(b+c)/2
        a=d
        b=e
        c=f
        i+=1


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

int main(){
  int N,i=0,a,cnt=0;
  int f[1000];
  int dp[1000000],odp[1000000];
  while(1){
    f[i]=(i+1)*(i+2)*(i+3)/6;
    if(f[i]>1000000) break;
    cnt++;
    i++;
  }
  dp[0]=0;dp[1]=1;
  odp[0]=0;odp[1]=1;
  for(int i=2;i<1000000;i++){
    dp[i]=odp[i]=10000000;
  }
  for(int i=2;i<1000000;i++){
    for(int j=0;j<cnt;j++){
      if((i-f[j])<0) break;
      else dp[i]=min(dp[i-f[j]]+1,dp[i]);
    }
  }
  for(int i=2;i<1000000;i++){
    for(int j=0;j<cnt;j++){
      if((i-f[j])<0) break;
      else if(j%4!=0) continue;
      else odp[i]=min(odp[i-f[j]]+1,odp[i]);
    }
  }
  while(1){
    cin>>N;
    if(N==0) break;
    cout<<dp[N]<<" "<<odp[N]<<endl;
  }
  return 0;
}



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

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> A(N);
	
	priority_queue<ll> q;
	
	rep(i,N){
		cin >> A[i];
		q.push(A[i]);
	}
	
	ll ans = 0;
	rep(i,M){
		ll temp = q.top();
		q.pop();
		q.push(temp/2);
	}
	
	rep(i,N){
		ans += q.top();
		q.pop();
	}
	
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2168
n, m = gets.chomp.split(' ').map(&:to_i)
graph = []
n.times { graph << [] }
m.times do
  a, b = gets.chomp.split(' ').map { |i| i.to_i - 1 }
  graph[a] << b
  graph[b] << a
end
queue = [0]
visited = Hash.new(false)
visited[0] = true
arr = Array.new(n)
until queue.empty? do
  q = queue.shift
  graph[q].each do |i|
    next if visited[i]
    visited[i] = true
    arr[i] = q + 1
    queue << i
  end
end
arr.shift
puts 'Yes'
puts arr

Measured memory_bytes: 37488
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    double d,t,s;
    cin >> d >> t >> s;
    if(d/s <= t) cout << "Yes" << endl;
    else cout << "No" << endl;
return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define _GLIBCXX_DEBUG
int main() {
  
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  
  int price = a * x + b * y,Tprice;
  
  for ( int i = 1; i <= 100000; i++){
    Tprice = i * 2 * c + max(0,x-i) * a + max(0,y-i) * b;
    price = min(price,Tprice);
  }
  
  cout << price << endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a[101]={0},b[101]={-1};
	int i,j=0,inp,max=0;

	while(scanf("%d",&inp) != EOF)
	{
		if(inp<0 || inp>100)
			continue;
		a[inp]++;
	}

	for(i=0;i<101;i++)
	{
		if(max<a[i])
		{
			max=a[i];
		}
	}
	for(i=0;i<101;i++)
	{
		if(max==a[i])
		{
			printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
using namespace std;
bool prime[300005];

void init(void){
  for(int i = 0 ; i < 300005 ; i++){prime[i] = true;}
  prime[0] = false, prime[1] = false;
  for(int i = 2 ; i < 300005 ; i++){
    if(prime[i] == true){
      for(int k = 2 ; i * k < 300005 ; k++){
	prime[i * k] = false;
      }
    }
  }
}

int main(void){
    init();
    for(;;){
        int N, P;
        cin >> N >> P;
	if(N == -1 && P == -1){return 0;}
        int p[100];
        int ptr=0;
        for(int i = N + 1 ; ptr<100 ; i++){
            if(prime[i]){p[ptr] = i; ptr++;}
        }
        int sum[50*101]; ptr=0;
        for(int i = 0 ; i < 100 ; i++){
            for(int j = i ; j < 100 ; j++){
                sum[ptr] = p[i] + p[j]; ptr++;
            }
        }
	sort(sum, sum+5050);
        cout << sum[P-1] << endl;
    }
}



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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

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

	if (N%2==0) {
		int n = N / 2;
		ce(N * (n  - 1));
		for (int i = 1; i <= N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (i + j == N + 1) { continue; }
				doublece(i, j);
			}
		}
	}
	else {
		int n = N / 2;
		ce(2*n * (n  - 1) + N - 1);
		for (int i = 1; i < N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (i + j == N) { continue; }
				doublece(i, j);
			}
			//doublece(i, N);
		}
	}
    return 0;
}



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

int main(int , char **)
{
	ll S=0;
	int N , T;
	cin >> N >> T;
	int t1,t2;
	t1 = -T*2;
	for(int i=0;i<N;i++){
		cin >> t2;
		S += min(T , (t2-t1));
		t1 = t2;
	}
	printf("%ld\n",S);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,d=0,e=0;
  cin>>a>>b;
  int c[a+1];
for(int i=0;i<a+1;i++){
  cin>>c[i];
}
  for(int i=0;i<a+1;i++){
    if(d>b){
      break;
    }
    d+=c[i];
    e++;
  }
  cout<<e;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

	vector<int> c(n), s(n), f(n);
	rep(i,n){
		cin >> c[i] >> s[i] >> f[i];
	}

	rep(j,n){
		int cnt = s[j] + c[j];
		range(i,j + 1,n){
			if(cnt <= s[i]){
				cnt = s[i] + c[i];
			}else{
				int diff = cnt - s[i];
				int wait = diff / f[i];
				if(diff % f[i] != 0) wait++;

				cnt = s[i] + wait * f[i] + c[i];
			}
		}
		cout << cnt << endl;
	}

	cout << 0 << endl;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    long n = scan!long;
    long ans;
    foreach(d; 1 .. n + 1){
        long x = n / d;
        ans += d * x * (1 + x) / 2;
        log("d:", d, "x:", x, "ans:", ans);
    }
    ans.writeln;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define PREC(n) fixed << setprecision(n)
using namespace std;

int main() {
    double r;
    cin >> r;
    double p = acos(-1);
    cout << PREC(20) << r * r * p << " " << 2 * p * r << endl;
}



Measured memory_bytes: 3288
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))

(defparameter modnum 1000000007)

(defun mod* (a b)
  (mod (* a b) modnum))

(defun mod+ (a b)
  (mod (+ a b) modnum))
(defun modpow2 (a)
  (mod* a a))

(defun modpow (a b)
  (if (zerop b)
	1
	(mod* (if (oddp b)
			a
			1)
		  (modpow (mod* a a) (floor b 2)))))


(defun modinv (x)
  (modpow x (- modnum 2)))


(defun melt (x)
  (let ((res (list)))
	(loop for i from 2 while (<= (* i i) x)
		  when (zerop (mod x i))
		  do
		  (let ((n 0))
			(loop while (zerop (mod x i))
				  do
				  (progn
					(incf n)
					(setf x (/ x i))))
			(push (cons i n) res)))
	(cons (cons x 1) res)))


(let* ((n (read))
	   (line (loop repeat n collect (read)))
	   (line2 (concatenate 'vector line))
	   (sum (make-array (1+ (expt 10 6)) :initial-element 0))
	   (allsum 1)
	   (ans 0))
  (loop for i below n
		do
		(let ((as (melt (aref line2 i))))
		  (loop for j in as do
				(setf (aref sum (car j)) (max (aref sum (car j)) (cdr j))))))
  (loop for i from 0 to (expt 10 6)
		do
		(setf allsum (mod* allsum (modpow i (aref sum i)))))
  (loop for i in line
		do
		(setf ans (mod+ ans (mod* allsum (modinv i)))))
  (princ ans))



Measured memory_bytes: 60600
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int diff = Math.abs(a-b)%2;

        if(diff == 0) {
            System.out.println("Alice");
        } else if (diff >= 1) {
            System.out.println("Borys");
        } else {
            System.out.println("Draw");
        }
    }
}


Measured memory_bytes: 35680
def init(n):
    for i in range(N):
        par[i] = i
        rnk[i] = 0

def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if (rnk[x] < rnk[y]):
        par[x] = y
    else:
        par[y] = x
        if(rnk[x] == rnk[y]):
            rnk[x] += 1
            
N, M = map(int, input().split())

X = [0 for i in range(M)]
Y = [0 for i in range(M)]
Z = [0 for i in range(M)]

for i in range(M):
    X[i], Y[i], Z[i] = map(int, input().split())
    X[i] -= 1
    Y[i] -= 1

par = [0 for i in range(N)]
rnk = [0 for i in range(N)]
init(N)

for i in range(M):
    unite(X[i], Y[i])
    
for i in range(N):
  find(i)

print(len(set(par)))

Measured memory_bytes: 77472
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const ll INF = 1e14;
const int MOD = 1000000007;
vector<int> dx = {0,0,1,-1};
vector<int> dy = {1,-1,0,0};
int h = 405,w =405;
vector<string> maze(h);
vector<vector<int>> visited(h,vector<int>(w,-1));
vector<ll> group;

int id(int i,int j){
    return i * w + j;
}

void dfs(int now,int g){
    int y = now / w;
    int x = now % w;
    visited[y][x] = g;
    if(maze[y][x] == '.') group[g] ++;
    rep(i,4){
        int new_y = y + dy[i];
        int new_x = x + dx[i];
        if(0 <= new_y && new_y < h && 0 <= new_x && new_x < w){
            if(visited[new_y][new_x] >= 0) continue;
            if(maze[y][x] == maze[new_y][new_x]) continue;
            dfs(id(new_y,new_x),g);
        }
    }
}

int main(){
    cin >> h >> w;
    rep(i,h) cin >> maze[i];

    rep(i,h)rep(j,w){
        if(visited[i][j] < 0 && maze[i][j] =='#'){
            group.push_back(0);
            dfs(id(i,j),group.size()-1);
        }
    }

    ll ans = 0;
    rep(i,h)rep(j,w){
        if(maze[i][j] == '.') continue;
        ans += group[visited[i][j]];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18560
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()

    if s == s[::-1]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61480
/*==============================================*\
ID:          shahidul_brur
 
Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh
 
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = (int)2e5+5;
const int logn = 20;
int c[maxn], n, last[maxn];
string s;

int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin>>s;
    n = s.size();
    f0(i,n)
    {
        if(s[i]=='R'){
            int j = i+1;
            while(s[j]!='L') ++j;
            f2(k,i,j-1) last[k] = j;
            i = j;
        }
    }
    fr(i,n-1,0)
    {
        if(s[i]=='L'){
            int j = i-1;
            while(s[j]!='R') --j;
            f2(k,j+1,i) last[k] = j;
            i = j;
        }
    }
    f0(i,n)
    {
        if(abs(i-last[i])%2==0) c[last[i]]++;
        else{
            if(s[i]=='L') c[last[i]+1]++;
            else c[last[i]-1]++;
        }
    }
    f0(i,n) cout << c[i] << " ";
    return 0;
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	n, a := readInt(), readInt()

	if a >= n%500 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int cnt = 0;
    rep(i, n) FOR(j, i+1, n) FOR(k, j+1, n) {
        if (a[i]==a[j] || a[j]==a[k] || a[i]==a[k]) continue;
        if (a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[i]+a[k]>a[j]) {
            debug(a[i], a[j], a[k]);
            cnt++;
        }
    }
    cout << cnt << endl;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

int64_t getVal(int64_t d){
  int64_t ans = 1;
  for(int i=1;i<d;i++){
    ans *= 10;
  }
  return ans;
}



signed main() {
  int a,b;
  cin >> a >> b;
  int ans = a-b*2;
  if(ans<0)ans=0;
    
  cout << ans << endl;
  return 0;
  
}




Measured memory_bytes: 3652
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int n = sc.nextInt();
		int[] p= new int[W];
		for(int i=0;i<W;i++){
			p[i]=i+1;
		}
		for(int i=0;i<n;i++){
			String str=sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0])-1;
			int b = Integer.parseInt(ab[1])-1;
			int c;
			c=p[a];
			p[a]=p[b];
			p[b]=c;
		}
		for(int i=0;i<W;i++){
			System.out.println(p[i]);
		}
	}
}

Measured memory_bytes: 26144
#include<iostream>
#include<string>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int main(){
	int n;
	string s;
	cin>>n>>s;
	int a[n+1],range[n+1];
	fill(a,a+n+1,0);
	fill(range,range+n+1,0);
	rep(i,s.size()){
		if(s[i]=='W'){
			a[i+1]++;
			a[s.size()+1]--;
		}else{
			a[0]++;
			a[i]--;
		}
	}
	rep(i,s.size()){
		if(i==0)range[i]=a[i];
		else range[i]=range[i-1]+a[i];
	}
	int ans=INF;
	rep(i,s.size()){
		ans=min(ans,range[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2948
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int r,c,a[][]=new int[101][101],i,j;
		r=stdIn.nextInt();
		c=stdIn.nextInt();
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=stdIn.nextInt();
				a[i][c]+=a[i][j];
			}
		}
		for(i=0;i<c;i++){
			for(j=0;j<r;j++)a[r][i]+=a[j][i];
			a[r][c]+=a[r][i];
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				if(j!=0)System.out.print(" ");
				System.out.print(a[i][j]);
			}
			System.out.println();
		}
	}
}


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


int main(){
  int W,H;
  cin>>W>>H;
  
  int x,y,r;
  cin>>x>>y>>r;
  
  if(x-r >= 0 && x+r <=W && y-r >= 0 && y+r <=H)
 cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    string p="CODEFESTIVAL2016";
    int count=0;
    for(int i=0;i<s.size();i++){
        
        if(s.at(i)!=p.at(i)){
            count++;
        }
    }

    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u)
        cout << a - 1 << " " << b << endl;
    else
        cout << a << " " << b - 1 << endl;
}

Measured memory_bytes: 256
import static java.util.Comparator.comparing;

import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==========================================================
    int[] getHB(int n) {
    	int[] hb = new int[2];
    	hb[1] = n % 10;
    	hb[0] = n;
    	while (n >= 10) {
			hb[0] = n / 10;
			n /= 10;
		}
//    	out.println("n = " + n + "  head = " + hb[0] + "  bottom = " + hb[1]);
    	return hb;
    }
    boolean check(int n, int m) {
    	int[] nhb = getHB(n);
    	int[] mhb = getHB(m);
    	if(nhb[0] == mhb[1] && nhb[1] == mhb[0])
    		return true;
    	else
    		return false;
    }
    long[][] count = new long[10][10];
    public void solve() {
    	int N = ni();
    	int[] hb;
    	for (int i = 1; i <= N; i++) {
    		hb = getHB(i);
        	count[hb[0]][hb[1]]++;
		}
    	long ans = 0;
    	for (int i = 1; i <= N; i++) {
    		hb = getHB(i);
    		ans += count[hb[1]][hb[0]];
		}
    	out.println(ans);
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  
  ll ans = max(a, max(b, c));
  REP(i, k)
    ans *= 2;
  
  cout << ans + (a+b+c-max(a, max(b, c))) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int h[maxn],ma[maxn]={0};
int main(){
	int n,m,a,b;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	for(int i=0;i<m;i++){
		cin>>a>>b;
		ma[a]=max(h[b],ma[a]);
		ma[b]=max(h[a],ma[b]);
	}
	int count=0;
	for(int i=1;i<=n;i++){
		count+=(h[i]>ma[i]);
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 4424
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
)

const Mod = int(1e9) + 7

func main() {
	N := ReadInt()
	a := make([][]int, N)
	for i := 0; i < N; i++ {
		a[i] = make([]int, N)
		for j := 0; j < N; j++ {
			a[i][j] = ReadInt()
		}
	}
	dp := make([]int, 1<<N)
	dp[0] = 1
	for s := 0; s < (1 << N); s++ {
		i := bits.OnesCount(uint(s))
		for j := 0; j < N; j++ {
			if s>>j&1 == 0 && a[i][j] == 1 {
				nextS := s | 1<<j
				dp[nextS] += dp[s]
				dp[nextS] %= Mod
			}
		}
	}
	fmt.Println(dp[1<<N-1])
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


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

using namespace std ;

#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define ll long long int 

#define fr first
#define se second

#define all(v) v.begin(),v.end() 
#define rall(v) v.rbegin(),v.rend()
#define sz(v) v.size() 

#define pb push_back
#define mp make_pair 

#define PI 3.141592653589793238



ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b / gcd(a,b) ;}


//bool valid(int x, int y){return x > 0 && x < 9 && y > 0 && y < 9;}

double sum;
int n;

int main(){
  cin >> n;
  while(n--){
    string s;
    long double l;
    cin >> l >> s;
    if(s == "BTC")
      sum += (l*380000.0);
    else
      sum += l;
  }  
  printf("%lf\n",sum);
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>

using namespace std;

int Sum10(int n);

int main()
{
    // 入力
    int n;
    cin >> n;
    string s[n];

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

    for(int i=0;i<n-1;i++){
        //cout << s[i] << "::" <<endl;
        //cout << s[i][0] <<endl;
        int size = s[i].size();
        //cout << s[i][size-1] <<endl;
        //cout << s[i+1][0] <<endl;
        if (s[i][size-1] != s[i+1][0]){
            flag = 0;
            //cout << "not" <<endl;
        }
        for (int j=i+1;j<n;j++){
            if(s[i]==s[j]){
                flag = 0;
                //cout << i << "::" << j <<endl;
            }
        }
        if (flag == 0){
            //cout << flag << endl;
            //break;
        }
    }
    if (flag==0){
        cout << "No" <<endl;
    }else{
        cout << "Yes" <<endl;
    }

    return 0;
}

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

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

int main(){
	int N,M;
	cin >> N >> M;
	vector<P> A;
	rep(i,N){int t; cin>>t; A.push_back(P(t,1)); }
	rep(i,M){
		int b; cin >> b;
		int c; cin >> c;
		A.push_back(P(c,b));
	}

	sort(A.begin(),A.end());
	reverse(A.begin(),A.end());
	ll ans = 0;
	int idx = 0;
	while(N>0 && idx<(int)A.size()){
		ans += A[idx].first * min(N,A[idx].second);
		N -= min(N,A[idx].second);
		idx++;
	}
	cout << ans << endl;

}


Measured memory_bytes: 6256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
ll MOD = 10e8 + 7;

int getMasu(int row, int col, vector<string>s) {
    int masu = 1;
    for(int i=row-1; i>=0; i--) {
        if(s[i][col] == '.') masu++;
        else break;
    }
    int row_max = s.size();
    int col_max = s.front().size();
    for(int i=row+1; i<row_max; i++) {
        if(s[i][col] == '.') masu++;
        else break;
    }
    for(int j=col-1; j>=0; j--) {
        if(s[row][j] == '.') masu++;
        else break;
    }
    for(int j=col+1; j<col_max; j++) {
        if(s[row][j] == '.') masu++;
        else break;
    }
    return masu;
}

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<int> > tmp = vector<vector<int> >(h, vector<int>(w, 0));
    vector<string> s = vector<string>(h, "");
    REP(i, h) {
        cin >> s[i];
    }
    int masu = 0;
    int s_index, g_index[h];
    
    REP(i, h) {
        REP(j, w) {
            if(s[i][j] == '#') {
                tmp[i][j] = 0;
                if (s_index != -1) {
                    for(int p=s_index; p<j; p++) {
                        tmp[i][p] += j-s_index;
                    }
                    s_index = -1;
                }
            } else {
                if (s_index == -1) s_index = j;
            }
            if (j == w-1 && s_index != -1) {
                for(int p=s_index; p<=j; p++){
                    tmp[i][p] += j+1-s_index;
                }
                s_index = -1;
            }
        }
    }
    
    REP(i, w) {
        REP(j, h) {
            if(s[j][i] == '#') {
                tmp[j][i] = 0;
                if (s_index != -1) {
                    for(int p=s_index; p<j; p++) {
                        tmp[p][i] += j-s_index;
                    }
                    s_index = -1;
                }
            } else {
                if (s_index == -1) s_index = j;
            }
            if (j == h-1 && s_index != -1) {
                for(int p=s_index; p<=j; p++){
                    tmp[p][i] += j+1-s_index;
                }
                s_index = -1;
            }
        }
    }
    int maxxx = 0;
    REP(i, h) {
        REP(j, w) {
            tmp[i][j]--;
            maxxx = max(maxxx, tmp[i][j]);
        }
    }
    OUT(maxxx);
    return 0;
}


Measured memory_bytes: 20096
import java.util.*;

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

        Scanner sc = new Scanner(System.in);

        // 整数N
        int num = sc.nextInt();
        // K進数
        int base = sc.nextInt();

        // 出力
        System.out.println(Integer.toString(num, base).length());
    }
}

Measured memory_bytes: 21716
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        long tmp = n % k;
        if (tmp == 0) {
            System.out.println(0);
        } else {
            System.out.println(Math.min(Math.abs(tmp - k), Math.abs(Math.abs(tmp - k) - k)));
        }
    }
}


Measured memory_bytes: 20820
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int left = 1, right = n;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		left = max(left, a);
		right = min(right, b);
	}
	cout << max(right - left + 1, 0) << endl;
}

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

long long n,x,t,ans;

int main()
{
	scanf("%lld%lld%lld",&n,&x,&t);
	if(n%x)
	{
		ans=(n/x+1)*t;
	}
	else
	{
		ans=n/x*t;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3820
#include<iostream>
#include<cstring> 
using namespace std;
int main()
{
	int n,w;
	cin>>n>>w;
	int wt[n+1],v[n+1];
	for(int i=1;i<=n;i++)
	cin>>wt[i]>>v[i];
	long long dp[n+1][w+1];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
	for(int j=1;j<=w;j++)
	{
		if(j<wt[i])
		dp[i][j]=dp[i-1][j];
		else
		dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i]]+v[i]);
	}
	long long ans=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=w;j++)
		if(dp[i][j]>ans)
		ans=dp[i][j];
		cout<<ans;
	
 } 

Measured memory_bytes: 82364
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int x,y; cin >> x >> y;
    vi a(x);
    rep(i,x){
        cin >> a[i];
    }
    sort(all(a));
    int ans = 0;
    rep(i,y){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  string s;

  while (cin >> s) {
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '@') {
        int x = s[i + 1] - '0';
        cout << string(x, s[i + 2]);
        i += 2;
      } else {
        cout << s[i];
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 3020
n=int(input())
l=[]
for i in range(n):
    s=input()
    l.append(s)
a=l.count("AC")
b=l.count("WA")
c=l.count("TLE")
d=l.count("RE")
print("AC x",a)
print("WA x",b)
print("TLE x",c)
print("RE x",d)

Measured memory_bytes: 16124
#include <iostream>

int main(){
   int a, b;
   std::cin >> a >> b;

   if(a>b) for(int i=0; i<a; ++i) std::cout << b;
   else for(int i=0; i<b; ++i) std::cout << a;
   std::cout << std::endl;

   return 0;
}


Measured memory_bytes: 256
import itertools

N, M, Q = map(int, input().split())
ABCD = [[int(x) for x in input().split()] for i in range(Q)]

ans=0
for A in itertools.combinations_with_replacement([m for m in range(1,M+1)], N):
  ans2=0
  for (a,b,c,d) in ABCD:
    if A[b-1]-A[a-1]==c:
      ans2+=d
  ans=max(ans, ans2)
print(ans)


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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    for (int i = 0; i < 200; i++) {
        for (int j = -200; j < 200; j++) {
            if (pow(i, 5) - pow(j, 5) == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 4092