akhauriyash/Code-Regression huggingface dataset:
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}
 
 
int n;
vector<int> adj[100005];
 
 
int dp(int v, int par){

	int cnt[30] = {0};
	for(auto vv : adj[v])
		if(vv != par){
			int mask = dp(vv, v);
			for(int i=0;i<30;i++)
				if((mask >> i) & 1)
					cnt[i]++;
		}

	//read editorial
	//mask denotes all labels visible from v
	//if atleast 2 children have v contribute to label x being visible 
	//from v, then label(v) should be atleast x+1

	int atleast = 0;
	for(int i=0;i<30;i++)
		if(cnt[i] >= 2)
			atleast = i;
	while(atleast < 30 && cnt[atleast] > 0)
		atleast++;
	cnt[atleast]++;

	int ans = 0;
	while(atleast < 30){
		if(cnt[atleast] > 0)
			ans |= (1<<atleast);
		atleast++;
	}

	return ans;
}
 


 
int main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin>>n;
    int e = n-1;
    while(e--){
    	int a, b;
    	cin>>a>>b;
    	adj[a].pb(b);
    	adj[b].pb(a);
    }
 
    int ans = dp(1, -1);
    for(int i=30;i>=0;i--)
    	if((ans >> i) & 1){
    		cout<<i;
    		return 0;
    	}
 
    return 0;
}
 
 




Measured memory_bytes: 18304
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using node = pair<double,int>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9+7;

int main(void){
  int n;
  cin >> n;
  vector<double> a;
  double sum = 0;
  for(int i = 0;i < n;++i){
    double tmp;
    cin >> tmp;
    sum += tmp;
    a.push_back(tmp);
  }
  double ave = sum / n;
  vector<node> calc;
  for(int i = 0;i < n;++i){
    calc.push_back(node(abs(a[i] - ave), i));
  }
  sort(calc.begin(),calc.end());
  cout << calc[0].second << endl;
  return 0;
}


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

#define int long long
#define rep(i,a,b) for(int i = a; i < b; i++)
const int mod = 1e9 + 7;
const int inf = 1e16;

signed main() {
    while (true) {
        int N,M;
        cin >> N >> M;
        if (N == 0 and M == 0) break;
        int C[M];
        rep(i,0,M) cin >> C[i];
        int X[N];
        rep(i,0,N) cin >> X[i];
        int dp[N+1][256];
        rep(i,0,N+1)rep(j,0,256) dp[i][j] = inf;
        dp[0][128] = 0;
        rep(i,1,N+1) {
            rep(j,0,256) {
                for(int c: C) {
                    int k = j + c;
                    k = min(k,255LL);
                    k = max(k,0LL);
                    dp[i][k] = min(dp[i][k], dp[i-1][j] + (X[i-1] - k)*(X[i-1] - k));
                }
            }
        }
        int ans = inf;
        rep(j,0,256) ans = min(ans, dp[N][j]);
        cout << ans << endl;
    }
}


Measured memory_bytes: 43240
import java.util.Scanner;
 
public class Main{
	public static void main(String[] args){
      	Scanner scanner = new Scanner(System.in);
      	int k = scanner.nextInt();
        String s = scanner.next();
      
      if(s.length() <= k){
      	System.out.println(s);
     }else{
      	System.out.println(s.substring(0,k) + "...");
      }
    }
}

Measured memory_bytes: 26968
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i64 = read();
    let v: i64 = read();
    let b: i64 = read();
    let w: i64 = read();
    let t: i64 = read();

    let dist = (a - b).abs();
    if (v - w) * t >= dist {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 2136
N = int(input())
A = list(map(int, input().split()))

A_plus = []
A_minus = []
for i in range(N):
    if A[i] >= 0:
        A_plus.append(A[i])
    else:
        A_minus.append(A[i])

if len(A_plus) == 0:
    A_plus.append(A_minus.pop(A_minus.index(max(A_minus))))
elif len(A_minus) == 0:
    A_minus.append(A_plus.pop(A_plus.index(min(A_plus))))
        
ans_list = []
while len(A_plus) + len(A_minus) != 1:
    if len(A_plus) <= len(A_minus):
        x = A_plus.pop(0)
        y = A_minus.pop(0)
        ans_list.append([x, y])
        A_plus.append(x-y)
    else:
        x = A_minus.pop(0)
        y = A_plus.pop(0)
        ans_list.append([x, y])
        A_minus.append(x-y)

M = A_plus[0]
print(M)
for i in range(len(ans_list)):
    print(ans_list[i][0], ans_list[i][1])

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

	int a[1010];
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	sort(a, a+n);

	int ans = 0;
	for(int i = 0;i < k;i++){
		ans += a[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3644
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	/*
	  boolean st = true;
	  int count = 0;
	
	  for(int i=0;i<(a+b+c);i++){
	  if(st==true){
	  b--;
		
	  if(b<0){
	  a--;
	  System.out.println("a");
	  if(a<0) break;
	  }
	  count++;
	  } else {
	  c--;
	  st = true;
	  if(c<0){
	  b--;
	  st = false;
	  if(b<0) a--;
	  }
	  count++;
	  }
	  }
	  System.out.println(count);*/
	if(a+b+1>=c) System.out.println(b+c);
	else System.out.println(b+(a+b+1));
	
    }
}

Measured memory_bytes: 21332
N = int(input())
if N < 600:
    ans = 8
elif N < 800:
    ans = 7
elif N < 1000:
    ans = 6
elif N < 1200:
    ans = 5
elif N < 1400:
    ans = 4
elif N < 1600:
    ans = 3
elif N < 1800:
    ans = 2
else:
    ans = 1
print(ans)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
typedef int64_t i64;


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

int N; cin >> N;
VI a(N); 
int cnt4 = 0; // 4の倍数の数．
int cnt2 = 0; // 2の倍数であり，かつ4の倍数でない数の数
rep(i, 0, N) {
    cin >> a[i];
    if (a[i] % 4 == 0) ++cnt4;
    else if (a[i] % 2 == 0) ++cnt2;
}
if (cnt4 >= N / 2) {
    cout << "Yes\n";
    return 0;
}

if (N - cnt4 * 2 == cnt2)
    cout << "Yes\n";
else 
    cout << "No\n";


}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct state { long long a, b; };
//inline bool operator<(const state& s1, const state& s2) { return s1.a < s2.a; }
int N; long long D, A[33], B[33];
state vl[7777777], vr[7777777]; // meet-in-the middle
int que[14348922]; // searching deque
int main() {
	scanf("%d%lld", &N, &D);
	for (int i = 0; i < N; i++) scanf("%lld%lld", &A[i], &B[i]);

	// Meet-in-the-middle Algorithm
	int sep1 = (N >> 1), sep2 = N - sep1;
	vector<long long> sa1(1 << sep1), sb1(1 << sep1);
	vector<long long> sa2(1 << sep2), sb2(1 << sep2);
	for (int i = 0; i < sep1; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa1[j] = sa1[j - b1] + A[i];
			sb1[j] = sb1[j - b1] + B[i];
		}
	}
	for (int i = 0; i < sep2; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa2[j] = sa2[j - b1] + A[i + sep1];
			sb2[j] = sb2[j - b1] + B[i + sep1];
		}
	}
	int cnt1 = 0, cnt3 = 0;
	for (int i = 0; i < 1 << sep1; i++) {
		int r = (1 << sep1) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa1[k] - sa1[j];
			long long r2 = sb1[k] - sb1[j];
			if (r1 >= 0) vl[cnt1++] = state{ r1, r2 };
			if (r1 > 0) cnt3++;
			j = (j - 1) & r;
		} while (j != r);
	}
	int cnt2 = 0, cnt4 = 0;
	for (int i = 0; i < 1 << sep2; i++) {
		int r = (1 << sep2) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa2[k] - sa2[j];
			long long r2 = sb2[k] - sb2[j];
			if (r1 >= 0) vr[cnt2++] = state{ r1, r2 };
			if (r1 > 0) cnt4++;
			j = (j - 1) & r;
		} while (j != r);
	}
	sort(vl, vl + cnt1, [](state s1, state s2) { return s1.a < s2.a; }); cnt1 += cnt3;
	sort(vr, vr + cnt2, [](state s1, state s2) { return s1.a < s2.a; }); cnt2 += cnt4;
	int cnt5 = cnt1 - cnt3;
	int cnt6 = cnt2 - cnt4;

	vector<state> wl(cnt1), wr(cnt2);
	for (int i = 0; i < cnt3; i++) wl[i] = state{ -vl[cnt5 - i - 1].a, -vl[cnt5 - i - 1].b };
	for (int i = 0; i < cnt4; i++) wr[i] = state{ -vr[cnt6 - i - 1].a, -vr[cnt6 - i - 1].b };
	copy(vl, vl + cnt5, wl.begin() + cnt3);
	copy(vr, vr + cnt6, wr.begin() + cnt4);

	// Searching with deque
	int cl = 0, cr = 0, dl = 0, dr = 0;
	long long ret = 0;
	for (int i = cnt2 - 1; i >= 0; i--) {
		while (cr < cnt1 && wl[cr].a + wr[i].a <= D) {
			while ((dr - dl) && wl[que[dr - 1]].b <= wl[cr].b) dr--;
			que[dr++] = cr++;
		}
		while (cl < cnt1 && wl[cl].a + wr[i].a < -D) {
			if ((dr - dl) && que[dl] == cl) dl++;
			cl++;
		}
		if (dr - dl) ret = max(ret, wr[i].b + wl[que[dl]].b);
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 681944
N,K = map(int,input().split())
V = list(map(int,input().split()))

Q = min(N,K)+1
res = 0
for a in range(Q):
    for b in range(Q-a):
        W = V[:a] + V[N-b:]
        W.sort()
        for k in range(min(K-a-b,len(W))):
            if W[k] < 0:
                W[k] = 0
            else:
                break
        res = max(res,sum(W))

print(res)


Measured memory_bytes: 40048
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for(ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for(ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 2e9
using namespace std;
typedef long long ll;

int main() {
  ll n, m;
  map<ll, vector<ll>> e;
  ll* r;
  bool* done;
  queue<ll> q;

  cin >> n >> m;
  
  ll a, b;
  REP(i, m) {
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }

  done = new bool[n];
  REP(i, n) {
    done[i] = false;
  }
  done[0] = true;

  r = new ll[n];
  q.push(1);
  while (q.size() != 0) {
    ll x = q.front();
    q.pop();
    vector<ll> ys = e[x];

    for (auto y : ys) {
      auto idx = y - 1;
      if (!done[idx]) {
        r[idx] = x;
        done[idx] = true;
        q.push(y);
      }
    }
  }

  cout << "Yes" << endl;
  FOR(i, 1, n - 1) {
    cout << r[i] << endl;
  }


  return 0;
}

Measured memory_bytes: 19656
N = long(raw_input())
MOD = 10**9 + 7

fact = [1]*(N+1)

for i in range(1, N+1):
    fact[i] = r = i*fact[i-1] % MOD

cnts = [0]*(N+1)
rev = 1
for K in range(N-1, (N+1)/2-1, -1):
    cnts[K] = fact[K]*fact[K-1]*rev % MOD
    rev = rev * (2*K-N) * (2*K-N-1) % MOD

ans = 0
for K in range((N+1)/2, N):
    ans += (cnts[K] - cnts[K-1]) * K % MOD
    ans %= MOD
ans = (ans * pow(fact[N-2], MOD-2, MOD)) % MOD
print ans


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


int main(){
    int n; cin >> n;
    for(int i = 0; i*4 <= n; i++){
        for(int j = 0; 7*j <= n; j++){
            if(i*4 + j*7 == n){
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}


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

ll d[100009][40], s[100009][40];
vector<int> v;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	d[0][0] = 1;
	for (int i = 0; i <= 32; i++)
		s[0][i] = 1;
	for (int i = 1; i <= n; i++) {
		d[i][0] = s[i][0] = 1;
		for (int j = 1; j <= 32; j++) {
			d[i][j] = s[i - 1][j];
			s[i][j] = (s[i][j - 1] + d[i][j]) % 1000000007LL;
		}
	}
	for (int i = 2; i * i <= m; i++) {
		if (m % i == 0) {
			m /= i; v.push_back(i);
			i = 1;
		}
	}
	if (m > 1)
		v.push_back(m);
	ll c = 0, ans = 1;
	for (int i = 0; i < v.size(); i++) {
		c++;
		if (i == v.size() - 1 || v[i] != v[i + 1]) {
			ans = (ans * d[n][c]) % 1000000007LL;
			c = 0;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 62720
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int ans=0;
int main(void){
	int r;
	cin>>r;
	if(r<1200)cout<<"ABC\n";
	else if(r<2800)cout<<"ARC\n";
	else cout<<"AGC\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
          int a;
          int b;
          int c;
          cin >> a;
          cin >> b;
          cin >> c;
          if (a==b && a==c)
          {
                    cout << "1";

          }
          else if (a==b && a!= c)
          {
                    cout << "2";

          }
          else if (a==c && a!= b)
          {
                    cout << "2";

          }

          else if (a!=b && a!= c)
                    if(b==c)
                    {
                               cout << "2";

                    }
                    else
                    {
                              cout << "3";

                    }
          else if (a<1 || a>=100)
          {


          }
          else if (b<1 || b>=100)
          {

          }
          else if (c<1 || c>=100)
          {

          }





    return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
cs = []
m.times do |i|
  p,y = gets.split.map(&:to_i)
  cs << [p,y,i]
end

cs = cs.sort_by do |c|
  [c[0], c[1]]
end

num = 1
h = {}
cs.each do |c|
  pref = c[0]
  h[pref] ||= 0
  h[pref] += 1
  id = "#{pref.to_s.rjust(6,'0')}#{h[pref].to_s.rjust(6, '0')}"
  c << id
end

cs.sort_by!{|c| c[2]}
cs.each do |c|
  puts c[3]
end


Measured memory_bytes: 42556
N, M = map(int, input().split())
A = [True] * (N + 1)
for _ in range(M):
    a = int(input())
    A[a] = False

dp = [0] * (N + 1)

dp[0] = 1
for i in range(N):
    for j in range(i + 1, min(N, i + 2) + 1):
        if A[j] is True:
            dp[j] += dp[i]
            dp[j] %= 10 ** 9 + 7

print(dp[N])


Measured memory_bytes: 13424
x=input()
n=int(x)
x=input().split()
p=[]
for k in range(n):
  p.append(int(x[k])) 
count=1
minim=p[0]
for k in range(1,n):
  if p[k] < minim:
    count+=1
    minim=p[k]
print(count)    

Measured memory_bytes: 25768
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    int N,M; cin>>N>>M;
    vector<vector<ll>>a(N,vector<ll>(2));
      rep(i,N)cin>>a[i][0]>>a[i][1];
    vector<vector<ll>>c(M,vector<ll>(2));
    rep(i,M)cin>>c[i][0]>>c[i][1];
    rep(i,N){
        ll mn =1e+9;
        rep(j,M){
            ll dis=abs(c[j][0]-a[i][0])+abs(c[j][1]-a[i][1]);
            mn =min(dis,mn);
        }
        rep(j,M){
            ll dis=abs(c[j][0]-a[i][0])+abs(c[j][1]-a[i][1]);
            if(dis==mn){
                cout<<j+1<<endl;
                break;
            }
        }
        
        }
    }
 



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}






    
void test_case() {



    int s, w;
    cin>>s>>w;

    if(w >= s) {
        cout<<"unsafe";
    } else {
        cout<<"safe";
    }


    

}


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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 3528
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long int keytype;

//quicksort(<#keytype *a#>, <#int first#>, <#int last#>)

void quicksort(keytype a[], long long int first, long long int last){
    long long int i, j;
    keytype x, t;
    
    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int main() {
    long long int k,n;
    long long int p[200000];
    long long int i=0,j=0;
    long long int max=0,sum = 0,count=0,ans_sum=0;
    double ans;
    scanf("%lld %lld",&n,&k);
    for (i=0; i<n; i++) {
        scanf("%lld",&p[i]);
    }
    for (j=0; j<k; j++) {
        sum=sum+p[j];
    }
    max=sum;
    for (i=0; i<n-k; i++) {
        sum=sum-p[i]+p[i+k];
        if (sum>max) {
            max=sum;
            count=i;
        }
    }
    ans_sum=max+k;
    ans=(double)ans_sum/2;
    printf("%f",ans);
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define VECTOR_LIMIT (55)

int main() {
	char s1[VECTOR_LIMIT] = { 0 }, s2[VECTOR_LIMIT] = { 0 };
	int n, i;
	long long res=1;
	bool bVecNow, bVecLeft;

	cin >> n;

	for (i = 0; i < n; i++) { cin >> s1[i]; }
	for (i = 0; i < n; i++) { cin >> s2[i]; }


	for (i = 0; i < n; i++) {
		bVecNow = (s1[i] == s2[i]);
		if (i == 0) {
			if (bVecNow) {res *= 3;}
			else {res *= 6;i++;}
			continue;
		}

		bVecLeft = (s1[i - 1] == s2[i - 1]);
		if (bVecNow) {//当前是竖块
			if (bVecLeft) {
				res *= 2;
			} else {
				res *= 1;
			}
			//res %= 1000000007;
		} else {//当前是横块
			if (bVecLeft) {
				res *= 2;
			} else {
				res *= 3;
			}
			i++;
			//res %= 1000000007;
		}
	}
	res %= 1000000007;
	cout << res << endl;
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 998244353LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 1000005
const int N = 1000000 ;

int a[maxn] ;

int main()
{
    int i , j , k , l , m , n ;

    scanf("%d",&n) ;

    bool fl = false ;

    for(i=1 ; i<=n ; i++)
    {
        scanf("%d",&a[i]) ;
        fl |= (a[i]%2) ;
    }

    if(fl==true) printf("first\n") ;
    else printf("second\n") ;

    return 0 ;
}


Measured memory_bytes: 640
table = list(map(int, input().split()))

for i in range(2, 0, -1):
    k = 0
    while k < i:
        if table[k] > table[k + 1]:
            table[k], table[k + 1] = table[k + 1], table[k]
        k += 1

print(table[0], table[1], table[2])



Measured memory_bytes: 5600
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N,ans=0,cnt=0;
  string S;

  cin>>N;
  cin>>S;

  int first[26]={},second[26]={};

//ch-'a'+1

  for(int i=0;i<N;i++){ //S[0]~S[i]までとS[i+1]~S[N]までにわける

    cnt=0;//カウント初期化
    for(int i=0;i<26;i++){//アルファベット表を初期化
      first[i]=0;
      second[i]=0;
    }
    for(int j=0;j<=i;j++){//前半に含まれる文字を列挙
      first[S[j]-'a']=1;
    }
    for(int k=i+1;k<N;k++){//後半
      second[S[k]-'a']=1;
    }
    for(int i=0;i<26;i++){//どっちも含む文字を数える
      if(first[i]==1 && second[i]==1){
        cnt++;
      }
    }
    if(ans<=cnt)ans=cnt;//答えを更新
  }

  cout<<ans;

  return 0;
}

Measured memory_bytes: 256
a = int(input())
ba = 0
count = 0
A = 0
B = 0
for i in range(a):
    l = input()
    count += l.count("AB")
    if l[0] == "B" and l[-1] == "A":
        ba += 1
    elif l[0] == "B":
        B += 1
    elif l[-1] == "A":
        A += 1
if ba == 0:
    count += min(A,B)
else:
    if A + B == 0:
        count += ba - 1
    else:
        count += ba + min(A,B)
print(count)

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

const int MOD = 1e9 + 7;
const int N = 100 + 5;

int a[N];
int n, k;
int dp[N][256][N];
int fact[111];

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> k;
    fact[1] = 1;
    for (int i = 2; i < 110; i++) {
        fact[i] = (long long)fact[i - 1] * i % MOD;
    }
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= 255; j++) {
            for (int w = 0; w <= i; w++) {
                if (dp[i][j][w] == 0) continue;
                dp[i + 1][j][w] = (dp[i + 1][j][w] + dp[i][j][w]) % MOD;
                dp[i + 1][j ^ a[i + 1]][w + 1] = (dp[i + 1][j ^ a[i + 1]][w + 1] + dp[i][j][w]) % MOD;
            }
        }
    }
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        sum = (sum + (long long)fact[i] * dp[n][k][i] % MOD) % MOD;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
#define ll long long
#define pb(a) push_back(a)
#define pi pair<int,int>
using namespace std;
int solveC()
{
    int x,n;
    cin>>x>>n;
    vector<int>arr(n);
    for(int i=0;i<n;i++)
    cin>>arr[i];
    int ans=0;
    map<int,int>mp;
    for(int a:arr)
    mp[a]=1;
    int i=0;
    while(true)
    {
        if(mp.find(x-i)==mp.end())
        {
            ans=x-i;
            break;
        }
        if(mp.find(x+i)==mp.end())
        {
            ans = x+i;
            break;
        }
        i++;
    }
    return ans;
}
int  main()
{
    cout<<solveC();
}

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

vector<int> prime_factor;
map<int, int> factor; // <Mの素因数, その個数>

void Factorize(int M) {
  int a = 2;
  while (M >= a * a) {
    if (M % a == 0) {
      if (factor[a] == 0) {
        prime_factor.push_back(a);
      }
      factor[a]++;
      M /= a;
    } else {
      a++;
    }
  }
  if (factor[M] == 0) {
    prime_factor.push_back(M);
  }
  factor[M]++;
}

int main() {
  int N; cin >> N;
  for (int i = 2; i <= N; i++) {
    int M = i;
    Factorize(M);
  }

  /*
  for (int i = 0; i < factor.size(); i++) {
    cout << factor[i] << " ";
  }
  */
  
  vector<int> number;
  for (int i = 2; i <= 100; i++) {
    if (factor[i] != 0) {
      number.push_back(factor[i]);
    }
  }

  sort(number.begin(), number.end());
  reverse(number.begin(), number.end());

  int over74 = 0, over24 = 0, over14 = 0, over4 = 0, over2 = 0;
  for(int i = 0; i < number.size(); i++) {
    if (number[i] >= 74) {
      over74++; over24++; over14++; over4++; over2++;
    } else if (number[i] >= 24) {
      over24++; over14++; over4++; over2++;
    } else if (number[i] >= 14) {
      over14++; over4++; over2++;
    } else if (number[i] >= 4) {
      over4++; over2++;
    } else if (number[i] >= 2) {
      over2++;
    } 
  }

  // cout<<over74<<" "<<over24<<" "<<over14<<" "<<over4<<" "<<over2<<"\n";
  
  int ans = 0;

  ans += over74;

  ans += (over24 * (over2 - 1));

  ans += ((over4 * (over4 - 1) / 2) * (over2 - 2));

  ans += over14 * (over4 - 1);

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define erep(i,n) for (int i = 0; i <= (n); ++i)
#define brep(i,n) for (int i = n; i >= 0; i--)
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 100005;
const int MAX_K = 55;
const int MAX_W = 200005; 

int dp[205][205];

int main(){

    int k;
    string s;

    cin >> k >> s;
    int n = s.size();
    if(n > k){
        string a = s.substr(0,k);
        a = a+"...";
        cout << a << endl;
    }else{
        cout << s << endl;
    }

}

Measured memory_bytes: 3628
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import defaultdict, deque

def main():
  tree = defaultdict(list)
  weights = dict()
  n = int(input())
  colors = dict()
  
  for _ in range(n-1):
    u, v, w = map(int, input().strip().split())
    tree[u].append(v)
    tree[v].append(u)
    weights[(u, v)] = weights[(v, u)] = w%2
  
  def bs(iroot=1):
    visited = set()
    dq = deque()
    dq.append((iroot, 0))
    colors[iroot] = 0
    while dq:
      inode, sw = dq.popleft()
      visited |= set([inode])
      
      for ichild in tree[inode]:
        if ichild in visited:
          continue
        colors[ichild] = (sw + weights[(inode, ichild)])%2
        dq.append((ichild, (sw + weights[(inode, ichild)]%2)))
    return colors
  
  colors = bs()
  for i in range(1, len(colors)+1):
    print(colors[i])

if __name__=='__main__':
  main()



Measured memory_bytes: 124760
#include<iostream>
using namespace std;
int n,k;
int d;
int x;
bool vis[105];
int tot;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=k;i++)
    {
        cin>>d;
        for(int j=1;j<=d;j++)
        {
            cin>>x;
            vis[x]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i])
            tot++;
    }
    cout<<n-tot;
    return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n, m;
    cin >> n >> m;
    ll t = 100 * (n - m);
    ll p = pow(2, m);
    cout << p * (t + 1900 * m) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,a,b) for(int i = a;i <= b;i++)
int main(void){
  long long int n,a,b; scanf("%lld%lld%lld",&n,&a,&b);
  if(n%(a+b)<a){
    printf("%lld",(n/(a+b))*a + (n%(a+b)));
  }
  else{
    printf("%lld",((n/(a+b))+1)*a);
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
queue<P> que;
 long int x;
 double w0,r0,r,c;

 while(1){
   
   cin>>r0>>w0>>c>>r;
   if(r0==0 && w0==0 && c==0 && r==0)break;
   x=0;

   while(2){

     if(c<=(r0+x*r)/w0)
       break;
     else
       x++;

	}//endwhile2
   cout<<x<<endl;
 }

}

Measured memory_bytes: 3228
#include<cstdio>
int x1,x2,y1,y2;
int main(){
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	printf("%d %d %d %d",x2-y2+y1,y2+x2-x1,x1+y1-y2,y1+x2-x1);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  bool p = true;
  map<int, int> mp;
  for (int i : a) mp[i]++;
  if (a[n - 1] == 2 * a[0]) {
    if (mp[a[0]] != 1) p = false;
    for (int i = a[0] + 1; i < a[n - 1] + 1; i++) if (mp[i] < 2) p = false;
  } else if (a[n - 1] == 2 * a[0] - 1) {
    if (mp[a[0]] != 2) p = false;
    for (int i = a[0] + 1; i < a[n - 1] + 1; i++) if (mp[i] < 2) p = false;
  } else p = false;
  cout << (p ? "Possible" : "Impossible") << '\n';
}

Measured memory_bytes: 256
Z='RUBY_THREAD_VM_STACK_SIZE';ENV[Z]||(require'rubygems';exec({Z=>'50000000'},Gem.ruby,$0));def f(i)a=H[i].map{|e|f(e)}.sort_by(&:-@);r=0;a.size.times{|i|x=a[i]+i+1;r<x&&r=x};r end;N=gets.to_i;H=Hash.new{|h,k|h[k]=[]};(N-1).times{|i|H[gets.to_i-1]<<i+1};p f(0)

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

const int INF = 1e8;

const int dx[] = { 1, 0, -1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int var = 4;

string D = "DRUL";

struct node {
	node *fail;
	vector<node*> next;
	vector<int> ok;
	node() : fail(nullptr), next(var, nullptr) {}
};

class Aho_Corasick {
	static int trans(char c) {
		switch (c)
		{
		case 'R': return 0;
		case 'D': return 1;
		case 'L': return 2;
		case 'U': return 3;
		default: break;
		}
		exit(EXIT_FAILURE);
	}
	vector<int> unite(const vector<int>& a, const vector<int>& b) {
		vector<int> res;
		set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res));
		return res;
	}
	int K;
public:
	node *root;
	Aho_Corasick(const vector<string>& Ts) : K(Ts.size()), root(new node) {
		node *now;
		root->fail = root;
		for (int i = 0; i < K; i++) {
			auto &T = Ts[i];
			now = root;
			for (auto c : T) {
				if (now->next[trans(c)] == nullptr) {
					now->next[trans(c)] = new node;
				}
				now = now->next[trans(c)];
			}
			now->ok.push_back(i);
		}
		queue<node*> q;
		for (int i = 0; i < var; i++) {
			if (root->next[i] == nullptr) {
				root->next[i] = root;
			}
			else {
				root->next[i]->fail = root;
				q.push(root->next[i]);
			}
		}
		while (!q.empty()) {
			now = q.front(); q.pop();
			for (int i = 0; i < var; i++) {
				if (now->next[i] != nullptr) {
					node *nx = now->fail;
					while (nx->next[i] == nullptr) {
						nx = nx->fail;
					}
					now->next[i]->fail = nx->next[i];
					now->next[i]->ok = unite(now->next[i]->ok, nx->next[i]->ok);
					q.push(now->next[i]);
				}
			}
		}
	}
	node* getnext(node* p, char c) {
		while (p->next[trans(c)] == nullptr) p = p->fail;
		return p->next[trans(c)];
	}
};

using T = tuple<int, int, node*>;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m, p;
	while (cin >> n >> m, n | m) {
		vector<string> S(n);
		int sx = 0, sy = 0, gx = 0, gy = 0;
		for (int i = 0; i < n; i++) {
			cin >> S[i];
			for (int j = 0; j < (int)S[i].size(); j++) {
				if (S[i][j] == 'S') {
					sx = i;
					sy = j;
				}
				else if (S[i][j] == 'G') {
					gx = i;
					gy = j;
				}
			}
		}
		cin >> p;
		vector<string> pts(p);
		for (int i = 0; i < p; i++) {
			cin >> pts[i];
		}
		Aho_Corasick aho(pts);
		vector<vector<map<node*, int>>> f(n, vector<map<node*, int>>(m));
		queue<T> q;
		q.push(make_tuple(sx, sy, aho.root));
		f[sx][sy][aho.root] = 0;
		while (!q.empty()) {
			auto p = q.front(); q.pop();
			for (int i = 0; i < 4; i++) {
				int tx = get<0>(p) + dx[i], ty = get<1>(p) + dy[i];
				node *t = aho.getnext(get<2>(p), D[i]);
				if (0 <= tx && tx < n && 0 <= ty && ty < m && S[tx][ty] != '#' && t->ok.empty() && f[tx][ty].count(t) == 0) {
					q.push(make_tuple(tx, ty, t));
					f[tx][ty][t] = f[get<0>(p)][get<1>(p)][get<2>(p)] + 1;
				}
			}
		}
		int res = INF;
		for (auto p : f[gx][gy]) {
			res = min(res, p.second);
		}
		cout << (res != INF ? res : -1) << endl;
	}
	return 0;
}

Measured memory_bytes: 9648
#include <stdio.h>

int main(){
  int n,k;
  scanf("%d%d",&n,&k);
  double answer = 0;
  int bin,count;
  long num;
  for(int i = 1; i <= n; ++i){
    count = 0;
    bin = i;
    num = 1;
    while(1){
      if(bin >= k) break;
      bin = bin * 2;
      count++;
      num = num * 2;
    }
    answer += 1 / (double)num;
  }
  long m = (long) n;
  answer = answer / (double) m;
  printf("%.20lf\n",answer);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>

using namespace std;
using ll = long long;

ll fact[100010];

void init(ll p){
    fact[0] = 1;
    for(ll i=1;i<sizeof(fact)/sizeof(ll);i++){
        fact[i] = fact[i-1] * i % p;
    }
}

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

ll mod_inv(ll a, ll m){
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x%m) % m;
}

ll mod_fact(ll n, ll p, ll& e){
    e = 0;
    if(n == 0) return 1;

    ll res = mod_fact(n/p, p, e);
    e += n/p;

    if(n/p % 2 != 0) return res * (p-fact[n%p]) % p;
    return res * fact[n%p] % p;
}

ll mod_comb(ll n, ll k,  ll p){
    if(n < 0 || k < 0 || n < k) return 0;
    ll e1, e2, e3;
    ll a1 = mod_fact(n, p, e1);
    ll a2 = mod_fact(k, p, e2);
    ll a3 = mod_fact(n-k, p, e3);
    if(e1 > e2+e3) return 0;
    return a1*mod_inv(a2*a3 % p, p) % p;
}


int main(void){
    init(1000000007);
    int n;
    cin >> n;
    vector<int> a(n+1, 0);
    int x=0,y=0;
    for(int i=1;i<=n+1;i++){
        int p;
        cin >> p;
        if(a[p]){
            x = a[p];
            y = i;
        }
        a[p] = i;
    }
    
    for(ll k=1; k<=n+1;k++)
    {
        ll a = mod_comb(n+1, k, 1000000007);
        ll b = mod_comb(x-1 + n+1-y, k-1, 1000000007);
        cout << (a - b + 1000000007)%1000000007 << endl;
    }

    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const int PI = acos(-1);
int main(){
	ll n,a,b;cin>>n>>a>>b;
	ll mi =((n-1)*a);
	mi+=b;
	ll ma =((n-1)*b);
	ma+=a;
	if(n==1&&a!=b){
		cout<<0<<endl;
		return 0;
	}
	if(a>b){
		cout<<0<<endl;
		return 0;
	}
	cout<<ma-mi+1<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    string S;
    cin >> S;
    if(S=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}


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

int32_t main()
{
	int s[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int n;
	cin >> n;
	cout << s[n-1] << '\n';	
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
struct edge{int to,cost;};

typedef pair<string, int> siP;
typedef pair<int, string> isP;

bool cmp(const siP& left, const siP& right){
    return left.second == right.second ? left.first < right.first : left.second > right.second;
}

int main(){
    int n;
    while(cin >> n, n){
        map<string, int> counter;
        for(int i=0;i<n;i++){
            string line;
            getline(cin, line);
            if(line.size()==0){
                i--;
                continue;
            }
            string str = "";
            for(int j=0;j<line.size();j++){
                if(line[j]==' '){
                    counter[str]++;
                    str = "";
                }else{
                    str.push_back(line[j]);
                }
            }
            if(str.size())counter[str]++;
        }
        char k;
        cin >> k;
        vector<siP> v(counter.begin(),counter.end());
        sort(v.begin(), v.end(), cmp);
        int count = 0;
        for(int i=0;i<v.size();i++){
            if(v[i].first[0]==k){
                if(count==0){
                    cout << v[i].first;
                }else{
                    cout << " " << v[i].first;
                }
                count++;
                if(count==5)break;
            }
        }
        if(count==0)cout << "NA" << endl;
        else cout << endl;
    }

    return 0;
}

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

int main()
{
    int n, d;
    cin >> n >> d;
    cout << (n + d * 2) / (2 * d + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    a, b = MII()
    cards = [2,3,4,5,6,7,8,9,0,11,12,13,1]
    i_a = cards.index(a)
    i_b = cards.index(b)
    if i_a == i_b: print('Draw')
    elif i_a > i_b: print('Alice')
    else: print('Bob')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;

class Strongly_Connected_Components {
private:
	int n;
	vvi G;
	vvi rG;
	vi visited;
	stack<int> order;
public:
	vvi ret;
	Strongly_Connected_Components(vvi A) {
		G = A;
		n = G.size();
		rG.resize(n);
		Loop(i, n) {
			Loop(j, G[i].size()) {
				rG[G[i][j]].push_back(i);
			}
		}
		visited.resize(n);
		fill(visited.begin(), visited.end(), 0);
		mainf();
	}
	void dfs(int a) {
		visited[a] = 1;
		Loop(j, G[a].size()) {
			if (visited[G[a][j]]) continue;
			dfs(G[a][j]);
		}
		order.push(a);
	}
	void rdfs(int a) {
		visited[a] = 1;
		Loop(j, rG[a].size()) {
			if (visited[rG[a][j]]) continue;
			rdfs(rG[a][j]);
		}
		ret.back().push_back(a);
	}
	void mainf() {
		Loop(i, n) {
			if (visited[i]) continue;
			dfs(i);
		}
		fill(visited.begin(), visited.end(), 0);
		while (order.size()) {
			int focus = order.top(); order.pop();
			if (visited[focus]) continue;
			ret.push_back({});
			rdfs(focus);
		}
	}
};

int main() {
	int v, e; cin >> v >> e;
	vvi G(v);
	Loop(i, e) {
		int s, t; cin >> s >> t;
		G[s].push_back(t);
	}
	Strongly_Connected_Components scc(G);
	if (scc.ret.size() < v) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

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

using namespace std;

typedef long long int64;

int N, subtree[100000], NextPath[100000], idx[100000];
char S[100001];
vector< int > g[100000];
deque< int64 > dp[100000][2];
int64 ret;

void BuildSubTreeSize()
{
  memset(subtree, -1, sizeof(subtree));
  stack< pair< int, int > > s;
  s.emplace(0, -1);
  while(!s.empty()) {
    auto p = s.top();
    s.pop();
    if(~subtree[p.first]) {
      NextPath[p.first] = -1;
      for(auto& to : g[p.first]) {
        if(p.second == to) continue;
        subtree[p.first] += subtree[to];
        if(NextPath[p.first] == -1 || subtree[NextPath[p.first]] < subtree[to]) {
          NextPath[p.first] = to;
        }
      }
    } else {
      s.push(p);
      subtree[p.first] = 1;
      for(auto& to : g[p.first]) {
        if(p.second != to) s.push({to, p.first});
      }
    }
  }
}

void update(int idx)
{
  bool button = S[idx] == '(';
  if(~NextPath[idx]) swap(dp[NextPath[idx]], dp[idx]);
  if(dp[idx][button ^ 1].size() > 1) {
    ret += dp[idx][button ^ 1][1];
    dp[idx][button ^ 1].pop_front();
  } else {
    dp[idx][button ^ 1][0] = 0;
  }
  dp[idx][button].push_front(0);
  ++dp[idx][button][1];
  for(auto& to : g[idx]) {
    if(to == NextPath[idx]) continue;
    auto& dp1 = dp[idx], & dp2 = dp[to];
    for(int j = 0; j < dp2[0].size(); j++) {
      if(j < dp1[1].size()) ret += dp1[1][j] * dp2[0][j];
    }
    for(int j = 0; j < dp2[1].size(); j++) {
      if(j < dp1[0].size()) ret += dp1[0][j] * dp2[1][j];
    }
    for(int j = 0; j < dp2[0].size(); j++) {
      int nextIdx = j + (button ? -1 : 1);
      if(nextIdx < 0) continue;
      while(dp1[0].size() <= nextIdx) dp1[0].push_back(0);
      dp1[0][nextIdx] += dp2[0][j];
    }
    for(int j = 0; j < dp2[1].size(); j++) { // '('
      int nextIdx = j + (button ? 1 : -1);
      if(nextIdx < 0) continue;
      while(dp1[1].size() <= nextIdx) dp1[1].push_back(0);
      dp1[1][nextIdx] += dp2[1][j];
    }
    dp2[0].clear();
    dp2[1].clear();
  }
}

int main()
{
  scanf("%d", &N);
  scanf("%s", S);
  for(int i = 0; i < N - 1; i++) {
    int A, B;
    scanf("%d %d", &A, &B);
    --A, --B;
    g[A].push_back(B);
    g[B].push_back(A);
  }
  for(int i = 0; i < N; i++) {
    dp[i][0].push_back(0);
    dp[i][1].push_back(0);
  }
  BuildSubTreeSize();
  iota(idx, idx + N, 0);
  sort(idx, idx + N, [&](const int& a, const int& b)
  {
    return (subtree[a] < subtree[b]);
  });
  for(int i = 0; i < N; i++) update(idx[i]);
  cout << ret << endl;
}

Measured memory_bytes: 195972
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

struct Node{
    int parent, left, right;
};

void preparse(int u, Node *T){
    if(u==-1) return;
    printf(" %d", u);
    preparse(T[u].left, T);
    preparse(T[u].right, T);
}

void inparse(int u, Node *T){
    if(u==-1) return;
    inparse(T[u].left, T);
    printf(" %d", u);
    inparse(T[u].right, T);
}

void postparse(int u, Node *T){
    if(u==-1) return;
    postparse(T[u].left, T);
    postparse(T[u].right, T);
    printf(" %d", u);
}



int main(){
    Node *T;
    int n,i,j;

    scanf("%d", &n);

    T = (Node*)malloc(sizeof(Node)*n);

    for(i=0;i<n;i++) T[i].parent=-1;

    for(i=0;i<n;i++){
        int d;
        scanf("%d", &d);
        scanf("%d %d", &T[d].left, &T[d].right);
        T[T[d].left].parent = d;
        T[T[d].right].parent = d;
    }

    for(i=0;i<n;i++){
        if(T[i].parent==-1){
            j=i;
            break;
        }
    }

    printf("Preorder");
    printf("\n");
    preparse(j, T);
    printf("\n");
    printf("Inorder");
    printf("\n");
    inparse(j, T);
    printf("\n");
    printf("Postorder");
    printf("\n");
    postparse(j, T);
    printf("\n");


    free(T);
    return 0;

    
}



Measured memory_bytes: 3204
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
cnt = [0]*N

for _ in range(M):
    a, b = map(int, input().split())
    cnt[a-1] += 1
    cnt[b-1] += 1

for i in range(N):
    if cnt[i]%2==1:
        print('NO')
        exit()

print('YES')

Measured memory_bytes: 74596
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long N = I.nextLong();
		long M = I.nextLong();
		long ans = 0;
		if (M>=2*N) {
			ans+=N;
			M-=2*N; //Using all S's and pairing them up with 2 c's each
			ans+=M/4; //4 c's make a Scc puzzle
			
		}else {
			ans+=M/2;
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 25452