akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    ll sum = 0;
    rep(i, N) sum += a[i];
    set<ll> candidates;
    for (int i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            candidates.insert(i);
            candidates.insert(sum / i);
        }
    }
    ll ans = 1;
    for (ll x : candidates) {
        ll need;
        { // calc need
            vector<ll> r(N);
            rep(i, N) r[i] = a[i] % x;
            sort(r.begin(), r.end());
            ll B = 0; // 正にする回数
            rep(i, N) B += x - r[i];
            ll A = 0; // 負にする回数
            need = 1e18;
            rep(i, N) {
                // 正負の区切り位置を全部試す
                A += r[i];
                B -= x - r[i];
                need = min(need, max(A, B));
            }
        }
        if (need <= K) ans = max(ans, x);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
count = 0
N = int(input())
A = input()
B = input()
C = input()
for i in range(N):
  if A[i] == B[i] and B[i] == C[i]:
    count = count
  elif A[i] == B[i] or B[i] == C[i] or C[i] == A[i]:
    count = count + 1
  else:
    count = count + 2
print(count)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <random>
#include <stdio.h>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef string ST;


#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) for(auto (a): v )   cerr << a << endl
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl


#if 0
vector<LL> X;
vector<LL> A;
LL cnt_min;
LL recusive(LL N, LL v, LL cnt, LL i) {

  if (A[N] != 0) {
    return A[N];
  }
  LL x = X[i];
  if (x == 1) {
    //cerr << v+cnt << endl;
    cnt_min = min(v + cnt, cnt_min);
    return cnt_min;
  }

  i++;
  recusive(v, cnt, i);
  for (LL j = 1; j < v / x; j++) {
    //fprintf(stderr, "x=%lld, v=%lld j=%lld\n", x, v, j);
    recusive(v - (x * j), cnt + j, i);
  }


}

#endif

vector<LL> X;
vector<LL> A;

LL recusive(LL n) {

  if (n == 0) {
    return 0;
  }
  if (A[n] != 0) {
    return A[n];
  }

  LL a_min = LLONG_MAX;
  for (auto x : X) {
    if (n - x >= 0) {
      a_min = min( a_min, (A[n - x] + 1) );
    }
    //cerr << a_min << endl;
  }
  return a_min;
}

void func() {

  LL N;
  cin >> N;
  A.resize(N+1);
  LL NMAX = 100000;
  X.push_back(1);
  LL x = 6;
  while (x <= NMAX) {
    X.push_back(x);
    x *= 6;
  }
  x = 9;
  while (x <= NMAX) {
    X.push_back(x);
    x *= 9;
  }
  sort(ALL(X), greater<LL>());
  
  for(LL i=1;i<=N;++i){
    A[i] = recusive(i);
  }

  //PRINTSP(X);
  //PRINTLN(A);
  cout << A[N];
}

#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "\n%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
	int m, n, k = 0, ben = 0, sum = 0;
	while (scanf("%d,%d", &m, &n) == 2) {
		k++;
		ben += m*n;
		sum += n;
	}
	cout << ben << endl;
	cout << (int)(sum / (double)k + 0.5) << endl;
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(int i=1;i<=n;i++)
#define FORl(i,l,n) for(int i=l;i<n;i++)
using namespace std;
#define pi pair<int,int>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<in>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll mod = 1e9+7;
ll power(ll num,ll g,ll mod)
{
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

  
int main() { 
	int n;
	cin>> n;
	n%=26;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++){
    	s[i] = (s[i] -'A' + n)>=26?'A'+(s[i] -'A' + n)%26:(s[i] + n);
    }
    cout << s;

} 

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

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;
	int a ;
	double b; cin >> a >> b;

	int c = (int)((b+0.005)*100);
	//if(ans!=0) ans /= 100;


	
	cout << (a*c)/100 << endl;
	
	return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if((a - b) == (b - c)){
        yes;
    }else{
        no;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
using ll = long long;

using namespace std;



int main() {
    string n;
    cin>>n;
    ll sum = 0;
    rep(i,n.length()) {
        sum += (int)(n[i]-'0');
    }
    
    if(sum%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3716
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define N 200003
#define LL long long
#define mod 998244353

int n;
int p[N];

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++)
	  p[i]=read();
	bool flag=1;
	for (int i=1;i<=n;i++)
	  	if (p[i]!=i){
			flag=0;
			break;
	  	}
	if (flag){
		puts("YES");
		return 0;
	}
	for (int i=1;i<=n;i++)
	  for (int j=1;j<=n;j++){
		  flag=1;
		  swap(p[i],p[j]);
		  for (int k=1;k<=n;k++){
			  if (p[k]!=k){
				  flag=0;
				  break;
			  }
		  }
		  if (flag){
			  puts("YES");
			  return 0;
		  }
		  swap(p[i],p[j]);
	  }
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
K,N =map(int, input().split())
A=list(map(int, input().split()))
D=list()

for i in range(N):
    if N-1>i:
        D.append(A[i+1]-A[i])
    else:
        D.append(K-A[i]+A[0])


D.remove(max(D))

print(sum(D))

Measured memory_bytes: 26444
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,i,j;
	while(1){
		scanf("%d %d %d",&a,&s,&d);
		if(a==-1&&s==-1&&d==-1)	break;
		if(a==-1||s==-1)
			printf("F\n");
		else if(a+s>=80)
			printf("A\n");
		else if(a+s>=65)
			printf("B\n");
		else if(a+s>=50||d>=50)
			printf("C\n");
		else if(a+s>=30)
			printf("D\n");
		else
			printf("F\n");
	}
	return 0;
}

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

class Cube{
public:
  int f[6];
  Cube(){}
  void roll_z(){ roll(1,2,4,3);}
  void roll_y(){ roll(0,2,5,3);}
  void roll_x(){ roll(0,1,5,4);}
  void roll(int i,int j,int k,int l){
    int t=f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=t;
  }
  void move(char ch){
    if(ch == 'E') for(int i=0;i<3;i++) roll_y();
    if(ch == 'W') roll_y();
    if(ch == 'N') roll_x();
    if(ch == 'S') for(int i=0;i<3;i++) roll_x();
  }
};

int main(){
  Cube c;
  string com;

  for(int i=0;i<6;i++)cin>>c.f[i];
  cin>>com;
  
  for(int i=0;i<(int)com.size();i++)c.move(com[i]);
  
  cout<<c.f[0]<<endl;
  
  return 0;
}



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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 105;

/* ...o(^-^)o... */

lint cost[MAX][MAX];
lint nxt[MAX][MAX];
int V;
void warshall_floyd(){
    rep(i, V) rep(j, V) rep(k, V){
        if(cost[j][i]+cost[i][k] < cost[j][k]){
            cost[j][k] = cost[j][i]+cost[i][k];
            nxt[j][k] = nxt[j][i];
        }
    }
}

bool edge[MAX][MAX], used[MAX][MAX];

void shortest_path(int s, int t){
    int i = s, j;
    while(j != t){
        j = nxt[i][t];
        used[i][j] = true; used[j][i] = true;
        i = j;
    }
}

int main(){
    cin >> V; int m; cin >> m;
    rep(i, V) rep(j, V){
        if(i == j) cost[i][j] = 0;
        else cost[i][j] = INF;
        nxt[i][j] = j;
    }

    rep(i, m){
        lint a, b, c; cin >> a >> b >> c;
        a--; b--;
        cost[a][b] = c;
        cost[b][a] = c;
        edge[a][b] = true; edge[b][a] = true;
    }

    warshall_floyd();

    rep(i, V) rep(j, V){
        if(i >= j) continue;
        shortest_path(i, j);
    }

    int res = 0;
    rep(i, V) rep(j, V){
        if(edge[i][j] && !used[i][j]) res++;
    }
    out(res / 2);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
#define pie 3.14159265358979323846
void solve()
{
	string n;
	cin>>n;
	ll int sum=0;
	for(ll int i=0;i<n.size();i++){
		sum+=n[i]-'0';
	}
	if(sum%9==0)
	cout<<"Yes\n";
	else
	cout<<"No\n";
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


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

int main()
{
    int n; cin >> n;
    int dp[n][3];
    for(int i = 0; i < n; i++)
        cin >> dp[i][0] >> dp[i][1] >> dp[i][2];
    for(int i = 1; i < n; i++)
    {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2])+dp[i][0];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2])+dp[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1])+dp[i][2];
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
    return 0;
}



Measured memory_bytes: 1408
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int t;
    scanf("%d",&t);
    for(int w=0;w<t;w++){
        int up=0,down=0,n,a[100];
        scanf("%d %d",&n,a);
        for(int i=0;i<n-1;i++){
            scanf("%d",a+i+1);
            up=max(up,a[i+1]-a[i]);
            down=max(down,a[i]-a[i+1]);
        }
        printf("%d %d\n",up,down);
    }
    return 0;
}

Measured memory_bytes: 1024
#ABC142-E Get Everything
"""
宝箱の制約が12個なので、これの状態を集合とする.
全ての状態について、(これはdpテーブルの状態ではない)
全ての鍵について考え、
この2つの状態のorで得られる状態sのdpテーブルをcost最小値で更新
そのようにして得られるdp[-1]が答えで、
この時O(2^N*M)がだいたい60**6なのでギリok
"""
import sys
readline = sys.stdin.buffer.readline

n,m = map(int,readline().split())
INF = 10**10
cost_len_key = []
for i in range(m):
    a,b = map(int,readline().split())
    lst1 = list(map(int,readline().split()))
    res = 0
    for j in lst1:
        res += 1<<(j-1)
    cost_len_key.append([a,b,res])

#dp:状態s(か、s以上)の箱を開けた場合の最小コスト
dp = [INF for _ in range(1<<n)]
dp[0] = 0 #1つも開けていない状態はコスト0

for i in range(1<<n): #すべての状態について回す
    for j in cost_len_key: #すべての鍵について回す
        s = i|j[2] #状態=iの状態の宝箱が空いているときに、鍵jで追加して開ける時の状態
        dp[s] = min(dp[s],dp[i]+j[0]) #そのような状態の時のコストの最小値

ans = dp[-1] #全部の鍵が空いた時の最小コストが答え
if ans < INF:
    print(ans)
else:
    print(-1)

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

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

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

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

int ans=INF,n,k;

void dfs(int pos,int sum) {
	if(pos==n) {
		ans=min(ans,sum);
		return;
	}
	dfs(pos+1,sum+k);
	dfs(pos+1,2*sum);
}

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

 	cin>>n>>k;
	dfs(0,1);
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let c = read1::<String>().chars().collect::<Vec<char>>()[0];
    if c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' {
        println!("vowel");
    } else {
        println!("consonant");
    }
}

Measured memory_bytes: 4352
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a<13) b=b/2;
    if(a<6) b=0;
    cout<<b<<endl;
    
    
    return 0;
}


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

int main(void) {
	char s[101], t[101];
	int i, j, k, flag = 0, cnt = 0;
	
	scanf("%s", &s[0]);
	scanf("%s", &t[0]);
	
	for (k = 0; k < strlen(s); k++) {
		cnt = 0;
		for (i = 0, j = k; i < strlen(s); i++,j=(j+1)%strlen(s)) {
			if (s[i] == t[j]) {
				cnt++;
				if (cnt == strlen(s)){
					flag = 1;
					break;
				}
			}else{
				break;
			 }
		}
	}
	
	printf(flag ? "Yes" : "No");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
typedef long long ll;
ll f(ll x){
    ll p=0;
    while(x){
        p+=x%10;
        x/=10;
    }
    return p;
}
int main(void){
    int n;
    cin>>n;
    ll a=0;
    ll b=1;
    for(int i=0;i<n;i++){
        if((a+b)*f(a+b*10)>(a+b*10)*f(a+b)){
            b*=10;
        }
        a+=b;
        cout<<a<<endl;
    }
}


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

int N;
vector<int> A;
vector<int> Aa;
int cbb = 0;


int main(){
  cin >> N;

  int a;
  vector<bool> show(N+1, false);
  for(int i = 0; i < N; i++){ cin >> a; A.push_back(a); }

  int i = 0; int j = 1;  //不可能な奴を取り除く
  while(i < N){
    if(j >= A[i]){ 
      if(!show[A[i]]){ 
      Aa.push_back(A[i]); 
      show[j] = true;
      j++;
      } 
    }
    i++;
  }

  
  cbb = N - j + 1; 
    
  if(Aa.size() == 0) cout << -1 << endl;  //空なら満たす壊し方はない
  else cout << cbb << endl;
  return 0;
   
}









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

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

 int a[] = {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};
 cout << a[K-1] << endl;
 return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Plogram
{
    static void Main()
    {
        var n = Console.ReadLine().Split();
        long N = long.Parse(n[0]);
        long M = long.Parse(n[1]);

        AB[] ab = new AB[N];

        for (int i = 0; i < N; i++)
        {
            var line = Console.ReadLine().Split();
            ab[i] = new AB(long.Parse(line[0]), long.Parse(line[1]));
        }

        var ab2 = ab.OrderBy(x=>x.A).ToArray();
        long count = 0;

        for (int i = 0; i < N; i++)
        {
            if(M >= ab2[i].B)
            {
                M -= ab2[i].B;
                count += ab2[i].A * ab2[i].B;
            }
            else
            {
                count += ab2[i].A * M;
                M = 0;
            }

            if(M<=0)
            {
                break;
            }
        }
        Console.WriteLine(count);
    }
}

class AB
{
    public long A { get; set; }
    public long B { get; set; }

    public AB(long a, long b)
    {
        A = a;
        B = b;
    }
}

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

n,m=map(int, input().split())

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

uf1=UnionFind(n)
for i in range(m):
    a,b=map(int, input().split()) #a,b:つながっている辺
    uf1.union(a-1,b-1)

for i in range(n):
    uf1.find(i)
from collections import Counter
c=Counter(uf1.par)
print(max(c.values()))


Measured memory_bytes: 102616
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


int main(){
  intl N;
  cin >>N;
  vi A(N+1),n(N+1,1);
  intl reaves=0;
  Rep(i,N+1){
    cin >>A[i];
    reaves += A[i];
  }
  if(N==0 & A[0]==1){cout <<1;return 0;}
  if(N==0 & A[0]!=1){cout <<-1;return 0;}
  intl nsum =1;
  if(A[0] == 1 && N != 0){cout <<-1;return 0;}
  Rep1(i,N){
    n[i]=min(reaves,(n[i-1] - A[i-1])*2 );
    //cout << n[i]<<endl;
    reaves -= A[i];
    if(n[i] <= 0){ cout <<-1;return 0;}
    nsum += n[i];
  }
  if(n[N] != A[N]){cout <<-1;return 0;}
  cout <<nsum;
}

Measured memory_bytes: 4804
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	
	long N , K; cin >> N >> K;
    long res = 1;

	for (int i = 1; i <= N; i++) res += min(res, K);

	cout << res << endl;

}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = []
    for i in range(N):
        S, P = input().split()
        A.append((S,int(P),i+1))

    sort_A = sorted(A, key=lambda x:(x[0], -x[1])) 
    for i in range(N):
        print(sort_A[i][2])

main()

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

#define MAX 1000000007
typedef long long int ll;


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    string a,b;
    cin>>a>>b;

    int j=0, m=0, match=0;
    int l1 = a.length(), l2=b.length();
    int ans = l2, cnt=0;

    for(int i=0; i< l1-l2+1; i++) {
        for(int j=0; j<l2; j++) 
            if(a[i+j]!=b[j]) cnt++;
        ans= min(cnt, ans);
        cnt=0;
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 3588
#include<algorithm>
#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>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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; }

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

    string s, t;
    cin >> s >> t;

    vvi dp(s.size() + 1, vi(t.size() + 1));

    rep(i, s.size())
    {
        rep(j, t.size())
        {
            chmax(dp[i + 1][j + 1], dp[i + 1][j]);
            chmax(dp[i + 1][j + 1], dp[i][j + 1]);

            if(s[i] == t[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1);
        }
    }

    string ans;
    ll length = dp[s.size()][t.size()];
    for (int i = s.size(); i >= 1; i--)
    {
        reple(j, 1, t.size())
        {
            if (dp[i][j] == length && s[i - 1] == t[j - 1])
            {
                ans += s[i - 1];
                length--;
                break;
            }
        }
    }

    reverse(all(ans));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35584
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


n = int(input())
print(n + n**2 + n**3)


Measured memory_bytes: 68040
#include<stdio.h>

int main() {
	int m, j, r;
	while (1) {
		scanf("%d %d %d", &m, &j, &r);
		if (m == -1 && j == -1 && r == -1)break;
		else if (m == -1 || j == -1)printf("F\n");
		else if (m + j >= 80)printf("A\n");
		else if (m + j >= 65)printf("B\n");
		else if (m + j >= 50)printf("C\n");
		else if (m + j >= 30) {
			if (r >= 50)printf("C\n");
			else printf("D\n");
		}
		else printf("F\n");
	}


	return 0;
}


Measured memory_bytes: 2604
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

VI e[10];
int ans;

void dfs(int now, VI a){
    int n = a.size();
    int x = 0;
    REP(i,n) x += a[i];
    if (x == n){
        ans++;
        return;
    }
    REP(i,e[now].size()){
        int next = e[now][i];
        if (a[next]) continue;
        a[next] = 1;
        dfs(next, a);
        a[next] = 0;
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    while (m--){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    VI a(n);
    a[0] = 1;
    dfs(0, a);

    cout << ans << endl;



    return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	vector<int> a, b( N+1 );
	for( int i = 1; i <= N; ++i ) { cin >> b[i]; }

	for( int i;; ) {
		for( i = b.size()-1; i > 0; --i ) {
			if( b[i] != i ) { continue; }

			a.push_back( i );
			b.erase( b.begin() + i );
			break;
		}

		if( i == 0 ) {
			break;
		}
	}

	if( b.size() > 1 ) {
		cout << -1 << endl;
	}
	else {
		for( int i = a.size()-1; i >= 0; --i ) {
			cout << a[i] << '\n';
		}
	}

	return 0;
}


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

using namespace std;

const int N=1e5;
int n;
int a[N],b[N],c[N];
int mem[N][5];

int solve(int i,int lst){
    if(i==n)
        return 0;
    if(mem[i][lst]!=-1) return mem[i][lst];
    int op1=lst!=0?solve(i+1,0)+a[i]:-1000000000;
    int op2=lst!=1?solve(i+1,1)+b[i]:-1000000000;
    int op3=lst!=2?solve(i+1,2)+c[i]:-1000000000;
    return mem[i][lst]=max(op1,max(op2,op3));
}

int main() {
    scanf("%d",&n);
    for(int i=0;i<n;++i)
        scanf("%d%d%d",a+i,b+i,c+i);
    memset(mem,-1,sizeof mem);
    printf("%d",max(solve(0,0),max(solve(0,1),solve(0,2))));
    return 0;
}


Measured memory_bytes: 8064
def main():
    N, M = (int(i) for i in input().split())
    G = [set() for _ in range(N+1)]
    for m in range(M):
        a, b = (int(i) for i in input().split())
        G[a].add(b)
        G[b].add(a)
    
    from itertools import permutations
    trial_path = (p for p in permutations(range(2,N+1),N-1))

    def exist_path(st,path):
        for p in path:
            if p in G[st]: st = p
            else: return False
        else: 
            return True

    ans = 0
    for path in trial_path:
        if exist_path(1,path):
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 40924
#include<stdio.h>
#include<string.h>
#include<string.h>
struct Node{
  int key;
  struct Node *right,*left,*parent;
};
  
struct Node *root,*NIL;
typedef struct Node * node;
struct Node * find(struct Node *u,int k){
  while(u != NIL && k != u->key){
    if(k < u->key){
      u = u -> left;
    }
    else {
      u = u -> right;
    }
  }
  return u;
}
  
void insert(int k){
  struct Node *x=root;
  struct Node *y=NIL;
  struct Node *z;
  z=malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while( x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z; 
  }else{
    if(z->key < y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}
  
void inorder(struct Node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
  
void preorder(struct Node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
  
int main(){
  int n,i,x;
  int a=0,b=0;
  char com[10];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
      struct Node *t=find(root,x);
      if(t != NIL)printf("yes\n");
      else printf("no\n");

    }
    if(strcmp(com,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    if(strcmp(com,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

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

int main()
{
    vector<int> a(3);
    int sum = 0;
    for(int i = 0;i < 3;i++){
        cin >> a[i];
        if(a[i] == 5) sum += 1;
        if(a[i] == 7) sum += 10;
    }
    if(sum == 12) cout << "YES" << endl;
    else cout << "NO" << endl;

}


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

using namespace std;

vector<vector<int>> g(100005);
int d[100005], u[100005];

void dfs(int v) {
    u[v] = 1;
    for(int i = 0; i < g[v].size(); i++) {
        int to = g[v][i];
        if(!u[to])
            dfs(to);
        d[v] = max(d[v], d[to]+1);
    }
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

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

    int n, m;
    cin >> n >> m;

    for(int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }

    for(int i = 1; i <= n; i++)
        if(!u[i])
            dfs(i);

    cout << *max_element(d, d+n+2);

    return 0;
}


Measured memory_bytes: 12836
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

pll calc(ll num, ll one_cnt)
{
  if (one_cnt == 0)
    return MP(0, num);
  pll res = calc((num + one_cnt) % 10, (num + one_cnt) / 10);
  res.first += one_cnt;
  return res;
}

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

  ll m;
  cin >> m;
  ll d[200010], c[200010];
  rep(i, m) cin >> d[i] >> c[i];
  ll ans = 0;
  ll a[200010];
  rep(i, m)
  {
    pll p = calc((d[i] * c[i]) % 10, (d[i] * c[i]) / 10);
    p.first += c[i] - 1;
    ans += p.first;
    a[i] = p.second;
  }

  rep(i, m - 1)
  {
    if (a[i] + a[i + 1] >= 10)
    {
      ans++;
      a[i + 1] = (a[i] + a[i + 1]) % 10 + 1;
    }
    else
    {
      a[i + 1] = a[i] + a[i + 1];
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<cmath>
#include<cstdio>
#include<vector>

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

using namespace std;

const long double EPS=1e-8;
const long double PI=acos(-1);

struct point{
	long double x,y;
	point():x(0),y(0){}
	point(long double x,long double y):x(x),y(y){}
	point operator-(const point &a)const{ return point(x-a.x,y-a.y); }
};

long double cross(const point &a,const point &b){ return a.x*b.y-a.y*b.x; }

long double arg(const point &a){
	long double t=atan2(a.y,a.x);
	return t<0?t+2*PI:t;
}

struct line{
	point a,b;
	line(){}
	line(const point &a,const point &b):a(a),b(b){}
};

enum{CCW=1,CW=-1,ON=0};
int ccw(const point &a,const point &b,const point &c){
	long double rdir=cross(b-a,c-a);
	if(rdir>0) return CCW;
	if(rdir<0) return CW;
	return ON;
}

long double dist(const point &a,const point &b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

const long double g=9.8;

int main(){
	int n;
	long double v; scanf("%d%Lf",&n,&v);
	point p[10000];
	rep(i,n) scanf("%Lf%Lf",&p[i].x,&p[i].y);

	long double a[9999],b[9999]; // y = a*x + b
	rep(i,n-1){
		a[i]=(p[i+1].y-p[i].y)/(p[i+1].x-p[i].x);
		b[i]=p[i].y-a[i]*p[i].x;
	}

	long double ans=dist(p[0],p[1]);
	for(int i=1;i<n-1;){
		if(ccw(p[i-1],p[i],p[i+1])!=CW){ // ジャンプしない
			ans+=dist(p[i],p[i+1]);
			i++;
		}
		else{ // ジャンプする
			long double vx=v*cos(arg(p[i]-p[i-1]));
			long double vy=v*sin(arg(p[i]-p[i-1]));
			long double x0=p[i].x,y0=p[i].y;
			for(;i+1<n;i++){
				// 斜面とぶつかる時刻 t を求める
				// A*t^2 + B*t + C = 0
				long double A=-g/2;
				long double B=vy-a[i]*vx;
				long double C=y0-a[i]*x0-b[i];
				if(B*B-4*A*C<0) continue;

				long double t0=(-B+sqrt(B*B-4*A*C))/(2*A);
				long double t1=(-B-sqrt(B*B-4*A*C))/(2*A);

				long double xx; // 斜面とぶつかる位置
				xx=x0+vx*t0;
				if(p[i].x<xx && xx<p[i+1].x){ point q(xx,-g/2*t0*t0+vy*t0+y0); ans+=dist(q,p[i+1]); break; }
				xx=x0+vx*t1;
				if(p[i].x<xx && xx<p[i+1].x){ point q(xx,-g/2*t1*t1+vy*t1+y0); ans+=dist(q,p[i+1]); break; }
			}
			i++;
		}
	}

	printf("%.15Lf\n",ans);

	return 0;
}

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

typedef long long ll;

#ifndef YUKININO
#define cerr if (false) cerr
#endif
#define debug(x) cerr << "[" << #x": " << x << "]" << endl
template <class T, class U> ostream& operator<< (ostream& out, const pair<T, U> &x) { return out << x.first << " " << x.second; }
template <class T> ostream& operator<< (ostream& out, const vector<T> &vec) { for (auto i = vec.begin(); i != vec.end(); i++) { if (i != vec.begin()) out << " "; out << *i; } return out; }

void solve();
int main() {
#ifdef YUKININO
  freopen("Testing.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int T = 1;
  // cin >> T;
  while (T--) solve();
  debug((clock() * 1.0 / CLOCKS_PER_SEC));
}
// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------

const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;

void solve() {
  int A, B;
  while (cin >> A >> B) {
    int g = __gcd(A, B);
    int k; cin >> k;
    for (int i = g; i >= 1; i--) {
      if (g % i == 0) {
        --k;
        if (k == 0) {
          cout << i << "\n";
          break;
        }
      }
    }
  }
}

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

using namespace std;

int main()
{
  string S;
  cin >> S;
  string T = "CODEFESTIVAL2016";

  int ret = 0;
  for(int i = 0; i < S.size(); i++) {
    ret += S[i] != T[i];
  }
  cout << ret << endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	ll a;
	double b;
	cin >> a >> b;
	ll b2 = round(b * 100);
	cout << a * b2 / 100 << endl;
}

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

int uf[100001];

bool cmp1(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b)
{
	return a.first.first < b.first.first;
}
bool cmp2(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b)
{
	return a.first.second < b.first.second;
}

int find(int x)
{
	if(uf[x]<0)
	{
		return x;
	}
	return uf[x] = find(uf[x]);
}

bool merge(int x,int y)
{
	x = find(x);
	y = find(y);
	if(x==y)
	{
		return false;
	}
	uf[y] = x;
	return true;
}

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

	int res = 0;
	int n,a,b;
	vector <pair<pair<int,int>,int>> v;
	vector <pair<int,pair<int,int>>> c;
	cin >> n;

	for(int i=1;i<=n;i++)
	{
		cin >> a >> b;
		v.push_back(make_pair(make_pair(a,b),i));
	}

	sort(v.begin(),v.end(),cmp1);

	for(int i=1;i<v.size();i++)
	{
		c.push_back(make_pair(abs(v[i-1].first.first - v[i].first.first),make_pair(v[i-1].second,v[i].second)));
	}

	sort(v.begin(),v.end(),cmp2);

	for(int i=1;i<v.size();i++)
	{
		c.push_back(make_pair(abs(v[i-1].first.second - v[i].first.second),make_pair(v[i-1].second,v[i].second)));
	}

	sort(c.begin(),c.end());
	memset(uf,-1,sizeof(uf));
	for(int i=0;i<c.size();i++)
	{
		if(merge(c[i].second.first,c[i].second.second))
		{
			res += c[i].first;
		}
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 6004
#include <bits/stdc++.h>
#define MAX (ll)(1e5 + 7)
#define INF (ll)(1e18)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;
using p = pair<ll,  ll>;
using pp = pair<pair<ll, ll>, pair<ll, pair<ll, ll>>>;

int main () {
	int a;
	cin >> a;
	cout << a * (1 + a * (1 + a)) << "\n";
}
	


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;

int main() {
  int N, K; cin >> N >> K;
  vector<int> p(N);
  vector<int> S(N+1, 0);
  for(int i = 0; i < N; i++) {
    cin >> p[i];
    S[i+1] = S[i] + p[i];
  }
  int max_sum = 0, pos = 0;
  for(int i = 0; i < N-K+1; i++) {
    if(max_sum < S[i+K] - S[i]){
      max_sum = S[i+K]-S[i], pos = i;
    }
  }
  double ans = 0.;
  for(int i = pos; i < pos+K; i++) {
    ans += double(1+p[i])/2.;
  }
  cout << setprecision(10);
  cout << fixed << ans << endl;

  return 0;
}


Measured memory_bytes: 1920
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();

        Map<Integer, Peak> map = new HashMap<>();

        for (int i = 1; i <= n; i++) {
            long h = scanner.nextInt();
            map.put(i, new Peak(i, h));
        }

        for (int i = 0; i < m; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            Peak peaka = map.get(a); // a -> b
            peaka.addRoute(b);

            Peak peakb = map.get(b); // b -> a
            peakb.addRoute(a);
        }


        int count = 0;
        for (Peak peak : map.values()) {
            if (peak.routes.size() == 0) {
                count++;
            } else {

                boolean higher = true;
                for (int targetId : peak.routes) {
                    Peak target = map.get(targetId);

                    if (peak.h <= target.h) {
                        higher = false;
                        break;
                    }
                }
                if (higher) {
                    count++;
                }
            }
        }
        System.out.println(count);

    }

    static class Peak {
        int id;
        long h;
        Set<Integer> routes;

        public Peak(int id, long h) {
            this.id = id;
            this.h = h;
            routes = new HashSet<>();
        }

        public void addRoute(int b) {
            routes.add(b);
        }

        @Override
        public String toString() {
            return this.id + ":" + this.h + ":" + this.routes;
        }
    }
}

Measured memory_bytes: 93744
int main() {

    int a;

    scanf("%d", &a);

    if (a % 10 == 2 || a % 10 == 4 || a % 10 == 5 || a % 10 == 7 || a % 10 == 9) {
        printf("hon");
    }
    else if (a % 10 == 0 || a % 10 == 1|| a % 10 == 6 || a % 10 == 8) {
        printf("pon");
    }
    else {
        printf("bon");
    }

    return 0;
}

Measured memory_bytes: 1724
//thanks God For Every Thing!
//contest link:
#include<bits/stdc++.h>
#define pi                      acose(-1)

typedef long long int           ll;
typedef double                  dl;
using namespace std;
const int mx = 1e2+5;


int main()
{
    int n, h1;
    cin>>n;
    if(n%2==1)
    {
        cout<<"No"<<endl;
        return 0;
    }
    char str[n+5];
    for(int i=0; i<n; i++)
    {
        cin>>str[i];
    }
    int cnt=0;

    for(int i=0; i<n/2; i++)
    {
        if(str[i]!=str[n/2+i])
        {
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 3636
import java.util.*;

import static java.util.Arrays.sort;

public class Main {
    static Scanner sc;


    public static void main(String[] args) {
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }
        sort(l);
        int ans = 0;
        for (int a = 0; a < n; a++) {
            for (int b = a+1; b < n; b++) {
                for (int c = b + 1; c < n; c++) {
                    if(l[c] >= l[a] + l[b]) break;
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}



Measured memory_bytes: 26848
(* O(n log(max a_s)) *)
Scanf.scanf "%d" @@ fun n ->
  let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0 in
  let rec count c m = if m mod 2 = 1 then c else count (c + 1) (m / 2) in
  Array.map (count 0) a_s |> Array.fold_left min max_int |> Printf.printf "%d\n"

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 200010
using namespace std;
struct node{
	char s[12];
}q[maxn];
char pre[12];
int cmp(node a,node b){
	return strcmp(a.s,b.s)<0;
}
int main(){
	int n,i,cnt=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%s",q[i].s);
	sort(q+1,q+1+n,cmp);
	strcpy(pre,q[1].s);
	for(i=2;i<=n;i++)
		if(strcmp(q[i].s,pre)!=0)strcpy(pre,q[i].s),cnt++;
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> sum(n + 1, 0);
  REP(i, n) {
    ll a;
    cin >> a;
    sum[i + 1] = sum[i] + a;
  }
  map<ll, vector<ll>> mp;
  REP(i, n + 1) { mp[(sum[i] - i) % k].push_back(i); }
  ll ans = 0;
  FOREACH(x, mp) {
    vector<ll> v = x.second;
    ll m = SZ(v);
    REP(i, m) {
      auto it = upper_bound(v.begin() + i + 1, v.end(), v[i] + k - 1);
      ans += max(0LL, (it - v.begin()) - i - 1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 23680
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void) {
	string w;
	cin >> w;
	int temp[100], ans = 0;


		for (int i = 0; i < w.length(); i++) {
			temp[i] = 0;
			for (int j = 0; j < w.length(); j++) {

				if (w[i] == w[j])temp[i]++;
			}
		}
		for (int i = 0; i < w.length(); i++) {
			ans += temp[i];
		}
		for (int i = 0; i < w.length(); i++) {
			
			if (temp[i] % 2 != 0) {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
		


	return 0;
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

struct RSQ{
    int n;
    vector<int> dat;
    RSQ() {}
    RSQ(int n_) {
        n = 1;
        while(n < n_) n *= 2;
        dat.resize(2 * n - 1, 0);
        // rep(i, 0, 2 * n - 1) dat[i] = MAX;
    }
    void add(int k, int a){
        k += n - 1;
        dat[k] += a;
        while(k > 0){
            k = (k - 1) / 2;
            dat[k] = dat[2 * k + 1] + dat[2 * k + 2];
        }
    }
    //sum[a, b)
    int query(int a, int b){
        return query(a, b, 0, 0, n);
    }
    int query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return dat[k];
        int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return vl + vr;
    }
};

signed main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
        a[i] -= k;
    }
    vector<int> sum(n, 0);
    sum[0] = a[0];
    int ans = 0;
    rep(i, 1, n){
        sum[i] = sum[i - 1] + a[i];
    }
    vector<P> d; 
    RSQ r(n);
    rep(i, 0, n){
        if(sum[i] >= 0) ans++;
        d. push_back(P(sum[i], i));
    }
    sort(all(d));
    reverse(all(d));
    rep(i, 0, n){
        int idx = d[i].second;
        ans += idx - r.query(0, idx);
        r.add(idx, 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 13552
#include <stdio.h>
int main(){
	int a, b,d,r;
	double f;
	scanf("%d %d", &a, &b);
	d = a / b;
	r = a%b;
	f = (double)a / (double)b;
	printf("%d %d %f\n", d, r, f);
	return 0;
}

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

int main()
{
	string s, t;
	cin >> s >> t;

	int ans = 0;
	for( int i = 0; i < 3; i++ ) {
		if( s[i] == t[i] ) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
import os,sys
c=0
ok=False
n=input()
for i in range(int(n)):
    m=input()
    one=m[0]
    two=m[2]
    if one==two:
        c+=1
    else:
        c=0
    if c>=3:
        ok=True
    
if(ok):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9088
n,k= map(int, input().split())
# s = input()

# n,m,q = map(int, input().split())
# abcd = [map(int, input().split())for _ in range(q)]

# a = list(map(int, input().split()))

count = [0]*n

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in a:
        count[j-1]+=1

ans = 0
for i in count :
    if i == 0:
        ans+=1
print(ans)

Measured memory_bytes: 9192
#include <iostream>

using namespace std;

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

    int a[N];
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    int x = a[N - 1];
    int i = 0;
    for (int j = 0; j < N - 1; ++j) {
        if (a[j] <= x) {
            swap(a[i], a[j]);
            ++i;
        }
    }
    swap(a[i], a[N - 1]);

    for (int j = 0; j < N; ++j) {
        cout << (j == i ? "[" : "") << a[j] << (j == i ? "]" : "") << (j < N - 1 ? " " : "");
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3468
#include <bits/stdc++.h>
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;

map<int, int> cnt;

int n, m, a, b;
int main(){
    cin >> n >> m;
    while(m--){
        int i; string s;
        cin >> i >> s;
        if(cnt[i] != -1){
            if(s == "AC"){
               a++;
               b += cnt[i];
               cnt[i] = -1;
            }
            else{
                cnt[i]++;
            }
        }
    }
    
    print(a, b);
    
    return 0;
}

Measured memory_bytes: 4992
fun main(args: Array<String>) {
    fun f(a: Int, b: Int, c: Int): Int {
        if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) return 0
        if (a == b && b == c) return -1
        return f((a + b) / 2, (b + c) / 2, (c + a) / 2) + 1
    }

    val (a, b, c) = readLine()!!.split(' ').map { it.toInt() }
    println(f(a, b, c))
}


Measured memory_bytes: 38192