akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
b = [0]*n
for i in range(n):
    b[i]= a[i]-i-1
b.sort()
x = 0
ab = 0
if n%2==0:
    x = int(n//2)
    ab = b[x]+b[x-1]
    ab = ab//2
else:
    x = int((n+1)//2 -1)
    ab = b[x]
ans = 0
for i in range(n):
    ans += abs(b[i]-ab)
print(ans)

Measured memory_bytes: 26180
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  int a,b,c,d;
  cin >> a >> b >> c>> d;
  cout << min(a,b)+min(c,d) << 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> 
#include<cmath>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define INF (int)1e9+5
#define nax (int)1e5+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define MAX_N 3005
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
// look for  all edge cases
//search for a pattern
int n,m,x;
vector<vector<int>> v(13,vector<int> ());
vector<int> cost(13);
int ans = INF;




//void calc(int index,int opt){
	//if(index == n){
		//for(int i =0;i<)
	//}
//}

int main(){
	fast;
	cin >> n >> m >> x;
	for(int i =0 ;i<n;i++){
		cin >> cost[i];
		for(int j = 0;j<m;j++){
			int temp;
			cin >> temp;
			v[i].pb(temp);
		}
	}
	//calc(0,1);
	//calc(0,2);
	for(int mask =0;mask<(1<<n);mask++){
		vector<int> algo(m,0);
		int temp =0;
		for(int i =0 ;i<n;i++){
			if((1<<i)&mask){
				temp += cost[i]; 
				for(int j = 0 ;j<m;j++){
					algo[j] += v[i][j];
					
				}
			}
		}
		bool ok = true;
		for(int j = 0 ;j<m;j++){
			if(algo[j] < x){
				ok = false;
				break;
			}
					
		}
		if(ok){
			ans = min(ans,temp);
		}
	}
	if(ans == INF){
		ans = -1;
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 3664
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll n,x,a[100000];
int main()
{
	cin>>n>>x;
	for(ll i=0;i<n;i++) cin>>a[i];
	ll ans=0;
	for(ll i=0;i<n-1;i++){
		if(a[i]+a[i+1]>x){
			ll s=min(a[i+1],a[i]+a[i+1]-x);
			ans+=s;
			a[i+1]-=s;
			if(a[i]+a[i+1]>x){
				ans+=a[i]+a[i+1]-x;
				a[i]-=a[i]+a[i+1]-x;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    priority_queue<int> pq;
    map<int,int> mp;
    pair<ll,int>p[100010];

    int N,K;cin>>N>>K;
    int t;ll d;
    for(int i=0;i<N;i++){
        cin>>t>>d;
        p[i]={-d,t};
    }
    sort(p,p+N);
    ll sum=0,kind=0;
    for(int i=0;i<K;i++){
        sum-=p[i].first;
        mp[p[i].second]++;
        if(mp[p[i].second]==1)kind++;
        if(mp[p[i].second]>=2)pq.push(i);
    }
    
    sum+=(ll)pow(kind,2);
    
    ll ans=sum;
    int i=K;
    while(!pq.empty() && i<N){
        if(mp[p[i].second]==0){
            int m=pq.top();
            ll k=kind;
            kind++;
            sum+=(ll)pow(kind,2)-(ll)pow(k,2)+p[m].first-p[i].first;
            ans=max(ans,sum);
            mp[p[i].second]++;
            pq.pop();
        }
        i++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int H, W;
  string S;
  cin >> H >> W;
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;
  for (int i = 0; i < H; i++) {
    cin >> S;
    cout << "#" << S << "#" << endl;
  }
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;
}




Measured memory_bytes: 256
n=int(input())
s_t = []
for i in range(n):
    s_t.append(list(map(str, input().split())))
x = input()

for i,v in enumerate(s_t):
    if v[0] == x:
        sleep_i = i
cnt = 0
for i in s_t[sleep_i+1:]:
    cnt += int(i[1])

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b&&b!=c)||(b==c&&c!=a)||a==c&&c!=b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
a,b,c = [input() for i in range(3)]

t = "a"

while True:
  if t=="a":
    if a:
      t = a[0]
      a = a[1:]
    else:
      print("A")
      exit()
  elif t=="b":
    if b:
      t = b[0]
      b = b[1:]
    else:
      print("B")
      exit()  
  else:
    if c:
      t = c[0]
      c = c[1:]
    else:
      print("C")
      exit()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main(){
	string x;
	cin>>x;
	if(x=="a" || x=="i" || x=="u" || x=="e" || x=="o"){
		cout<<"vowel"<<endl;
	}else{
		cout<<"consonant"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll INF = 1LL << 60; //MAX 9223372036854775807


int main()
{
ll n ;
cin >> n ;
vector<pair<ll,bool>> v;
map<pair<ll,bool>,ll> m;
rep(i,2*n){
  ll a ;
  char b ;
  cin >> b >> a ;
  if(b=='W'){v.emplace_back(a-1,0);m[{a-1,0}]=i;}
  else {v.emplace_back(a-1,1);m[{a-1,1}]=i;}
}
ll bl[2*n][n+1]={};
ll wh[2*n][n+1]={};
rep(i,n){
  ll b=0,w=0;
  rep(j,2*n){
    bl[j][i]=b;
    wh[j][i]=w;
    if(v[j].second&&v[j].first>=i)b++;
    if(!v[j].second&&v[j].first>=i)w++;
  }
}
ll dp[n+1][n+1];//w,b
rep(i,n+1)rep(j,n+1)dp[i][j]=INF;
dp[0][0]=0;
rep(i,n+1)rep(j,n+1){
  if(i!=n)dp[i+1][j]=min(dp[i+1][j],dp[i][j]+wh[m[{i,0}]][i]+bl[m[{i,0}]][j]);
  if(j!=n)dp[i][j+1]=min(dp[i][j+1],dp[i][j]+wh[m[{j,1}]][i]+bl[m[{j,1}]][j]);
}
cout << dp[n][n] << endl;
return 0;
}


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

int main(){
	string s,t;
	int i,j;
	bool flag;

	cin>>s>>t;

	int k=s.size()-t.size();
	for(i=k;i>=0;i--){
		for(j=0;j<t.size();j++){
			flag=false;
			if(s[i+j]==t[j]||s[i+j]=='?')flag=true;
			if(!flag)break;
		}
		if(flag)break;
	}
	if(!flag){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	for(j=0;j<t.size();j++)
		s[i+j]=t[j];
	for(int l=0;l<s.size();l++)
		if(s[l]=='?')s[l]='a';
	cout<<s<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;
typedef long long ll;

int main()
{
    int n,k;
	cin >> n >> k;
	ll ans = k;
	for(int i = 0; i < n - 1; i++){
		ans *= k - 1;
	}
	cout << ans << endl;
    return 0;
}


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

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

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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


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


int main(){
  ll n;

  scanf("%lld",&n);

  if(n % 2 == 0){
    puts("1");
  }else{

    ll pow2 = 1;
    
    for(;;){
      pow2 *= 2;

      if(pow2 >= n){
        printf("%lld\n",n+1);
        return 0;
      }

      ll a = (n+1) - (n / pow2 * pow2);
      ll b = pow2;
      
      if(a > b){
        printf("%lld\n",min(a,b));
        return 0;
      }else if(a < b){
        printf("%lld\n",min(a,b));
        return 0;
      }
      
    }
    
  }
  
  
  return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <cstring>

using namespace std;

bool square[21][21];

int main() {
  int N;
  while (true) {
    cin >> N;
    if (N == 0) break;
    memset(square, false, sizeof(square));
    for (int i = 0; i < N; i++) {
      int x, y;
      cin >> x >> y;
      square[x][y] = true;
    }
    int x = 10,  y = 10;
    int count = 0;
    if (square[x][y]) {
      square[x][y] = false;
      count++;
    }
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
      string d;
      int amt;
      cin >> d >> amt;
      for (int j = 0; j < amt; j++) {
        if (d == "N") {
          y++;
        } else if (d == "E") {
          x++;
        } else if (d == "S") {
          y--;
        } else {
          x--;
        }
        if (square[x][y]) {
          square[x][y] = false;
          count++;
        }
      }
    }
    if (count == N) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }  
  return 0;
}

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

main(){
  int a,b,c;
  cin >> a >> b >> c;
 if(a == b && b == c){cout << 1 << endl;}
 else if(a == b || a == c || b == c)cout << 2 << endl;
  
  else{cout << 3;}
}

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

#define rep(i, n) for(int i = 0; (int)(i) < n; i++)
 
using namespace std;
 
int main() {
  
  int n , m;
  int sum = 0;
  string ans = "Yes";
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  rep(i, n) sum += a.at(i);
  sort(a.begin(), a.end(), greater<int>());
  
  rep(i, m){
    if(a.at(i) * m * 4 < sum){
      ans = "No";
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int membersCount = Integer.parseInt(line[0]);
		int trainFee = Integer.parseInt(line[1]);
		int taxiFee = Integer.parseInt(line[2]);
		int result = 0;
		if(membersCount*trainFee>=taxiFee) {
			result = taxiFee;
		}else {
			result = membersCount*trainFee;
		}
		System.out.println(result);
		
		
		
		
	}
}

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

int main() {
    string a,b;
    cin>>a>>b;
    if (a.size()==b.size()) {
        if (a==b)
            puts("EQUAL");
        else if (a<b)
            puts("LESS");
        else
            puts("GREATER");
    } else {
        if (a.size()<b.size())
            puts("LESS");
        else
            puts("GREATER");
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void);

int main(void)
{
    int n, i, x;
    scanf("%d", &n);
    
    for(i = 1; i <= n; i++){
        x = i;
        if(x % 3 ==0){
            printf(" %d", i);
        }
        else{
            do{//do-whileで処理を1度実行してから条件判定
                if(x % 10 == 3){
                    printf(" %d", i);
                    x = 0;   
                }
                x /= 10;//xを10で割った値x
            }while( x );
        }
    }
    printf("\n");
    return(0); 
}


Measured memory_bytes: 2148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int c[] = new int[101];
			while (true) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				if ((a | b) == 0) {
					break;

				}
				c[a]++;
				c[b]++;
			}
			int odd = 0;
			boolean flag = true;
			for (int i = 0; i < 101; i++) {

				if (c[i] == 0)
					continue;
				if (c[i] % 2 != 0) {
					odd++;
					if (odd > 2) {
						flag = false;
						break;
					}
				}
			}
			if (odd!=2)flag = false;
			System.out.println(flag ? "OK" : "NG");
		}
	}
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  if (s.size() % 2 != 0) {
    cout << "No\n";
    return 0;
  }
  
  bool ok = true;
  for (int i = 0; i < s.size() - 1; i += 2) {
    if (!(s[i] == 'h' && s[i + 1] == 'i')) ok = false;
  }
  
  if (ok) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define mod 998244353
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000;
#define PI 3.14159265
int main()
{
    fastio;
    string s;
    cin>>s;
    if(s=="AAA" || s=="BBB")
        cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
import math

A=0
N=int(input())
for i in range(5,10):
  X = N / i
  if X == int(X):
    A += math.floor(N / i)
    break
  else:
    continue
  
B = N - A
anum=[]
bnum=[]
a=0
b=0

while A > 0:
    anum.append(A%10)
    A //= 10 
anum.reverse()

while B > 0:
    bnum.append(B%10)
    B //= 10 
bnum.reverse()

for q in anum:
  a += q
for w in bnum:
  b += w

print(a+b)
 



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		float sum=0;
		for(int i=0;i<n;i++){
			float a;
			string arr;
			cin>>a>>arr;
			if(arr=="JPY"){
				sum+=a;
			}
			else{
				sum+=380000*a;
			}
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int b,r,g,c,s,t,m;

int main()
{
	for(;;)
	{
		scanf("%d%d%d%d%d%d",&b,&r,&g,&c,&s,&t);
		if(b+r+g+c+s+t==0)
			break;
		printf("%d\n",100+95*b+63*r+g*7+c*2-(t-s)*3);
	}
	return 0;
}

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

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

    vector<int> v(n);
    rep(i,n)    cin >> v[i];

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

    int ans(v[k-1]-v[0]);
    for(int i=0;i<n-k+1;i++){
        ans = min(ans,v[i+k-1]-v[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3724
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int n,m,l,ans=0;
 	cin >> n>>m>>l;
 	for (int i = 0; i < n; i++){
 		int x,y,a,b;
 		cin >> x>>y;
 		a=x/m;
 		b=y/l;
 		if(a<b){
 			ans=ans+a;
 		}else{
 			ans=ans+b;
 		}
 		
 	}
 	cout << ans << endl;
 }

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

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...)
#endif

/**
 * @title Union-find
 * @docs unionfind.md
 */
class UnionFind {
  int n;
  mutable std::vector<int> parent;
  std::vector<int> depth, size;
  int count;

public:
  UnionFind(){}
  UnionFind(int n): n(n), parent(n), depth(n, 1), size(n, 1), count(n){
    std::iota(parent.begin(), parent.end(), 0);
  }

  int root_of(int i) const {
    if(parent[i] == i) return i;
    else return parent[i] = root_of(parent[i]);
  }

  bool is_same(int i, int j) const {return root_of(i) == root_of(j);}

  int merge(int i, int j){
    const int ri = root_of(i), rj = root_of(j);
    if(ri == rj) return ri;
    else{
      --count;
      if(depth[ri] < depth[rj]){
        parent[ri] = rj;
        size[rj] += size[ri];
        return rj;
      }else{
        parent[rj] = ri;
        size[ri] += size[rj];
        if(depth[ri] == depth[rj]) ++depth[ri];
        return ri;
      }
    }
  }

  int size_of(int i) const {return size[root_of(i)];}

  int count_groups() const {return count;}

  auto get_groups() const {
    std::vector<std::vector<int>> ret(n);

    for(int i = 0; i < n; ++i){
      ret[root_of(i)].push_back(i);
    }

    ret.erase(std::remove_if(ret.begin(), ret.end(), [](const auto &a){return a.empty();}), ret.end());

    return ret;
  }
};




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

  int N, Q; std::cin >> N >> Q;
  UnionFind uf(N);

  for(int i = 0; i < Q; ++i){
    int type, u, v; std::cin >> type >> u >> v;
    if(type == 0) uf.merge(u, v);
    else std::cout << uf.is_same(u, v) << "\n";
  }

  return 0;
}


Measured memory_bytes: 5544
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define lowbit(x) (x&(-x))
#define X first
#define Y second
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=100000+50;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int mx=(1<<4);
const double PI=acos(-1.0);
const double eps=1e-9;
//void add(int &a,int b){
//    a+=b;
//    if(a>=mod)a-=mod;
//}
//int pdt(int x,int y) {
//    int ret;
//    __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n":"=d"(ret):"a"(x),"b"(y),"c"(mod));
//    return ret;
//}
int hehe[3];
char s[maxn];
int a[maxn];
int main(){
#ifdef local
    freopen("in.txt","r",stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>(s+1);
    int n,tot=0; n=strlen(s+1);
    a[0]=1;
    for (int i=1;i<=n;i++) a[i]=1ll*a[i-1]*3%mod;
    for (int i=1;i<=n;i++){
        int tmp[3]={0};
        for (int j=0;j<3;j++){
            if (s[i]!='?' && s[i]-'A'!=j) continue;
            for (int k=0;k<3;k++) tmp[k]=(tmp[k]+hehe[k])%mod;
            if (!j) tmp[j]+=a[tot]; else tmp[j]+=hehe[j-1];
            tmp[j]%=mod;
        }
        for (int j=0;j<3;j++) hehe[j]=tmp[j]%mod;
        if (s[i]=='?') tot++;
    }
    cout<<hehe[2]<<"\n";
    return 0;
}


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

int main()
{
    char s[10][10];
    for(int i=0;i<3;i++)
    scanf("%s",s[i]);
    printf("%c%c%c",s[0][0],s[1][1],s[2][2]);
    return 0;
}




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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 100 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

int dx[4]={0,0,1,-1};
int dy[4]={-1,1,0,0};
int a[1005][1005];
vector<pair<int,int>>v;

int main()
{
    ll r,d,x;
    cin>>r>>d>>x;
    for(int i=0;i<10 ;++i){
        x=r*1LL*x-d;
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        String s = bf.readLine();
        ArrayList<Integer> counts = new ArrayList<Integer>();
        int count = 0;
        char lastchar = '!';
        for(int i=0; i<s.length(); i++) {
          if(s.charAt(i) == lastchar) {
            i++;
            lastchar = '!';
            if(i!= s.length())count++;
          }
          else {
            lastchar = s.charAt(i);
            count++;
          }
        }
        out.println(count);
        // int n = Integer.parseInt(bf.readLine());
        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        // int n = Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }
}


Measured memory_bytes: 27208
#include<stdio.h>

int n,m,s,i;
int taro[1000];
int hana[1000];
int T,H,X;
int anst,ansh;

int main(){
  while(1){
    scanf("%d %d",&n,&m);
    if(n==0&&m==0)break;

    T=0;
    H=0;
    for(i=0;i<1000;i++){
      taro[i]=0;
      hana[i]=0;
    }
    for(i=0;i<n;i++){
      scanf("%d",&s);
      taro[s]=1;
      T+=s;
    }
    for(i=0;i<m;i++){
      scanf("%d",&s);
      hana[s]=1;
      H+=s;
    }

    
    X=(H-T)/2;
    anst=-1;
    ansh=-1;

    for(i=0;i<=100;i++){
      if(0<=i+X&&taro[i]==1&&hana[i+X]==1){
	anst=i;
	ansh=i+X;
	break;
      }
    }
    
    if((H-T)%2!=0||anst==-1){
      printf("-1\n");
    }else{
      printf("%d %d\n",anst,ansh);
    }

  }
  return 0;
}

Measured memory_bytes: 1048
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

#include <vector>

class UnionFind {
    std::vector<int> parent;
    std::vector<int> rank;

    int root(int x) {
        return parent[x] >= 0 ? parent[x] = root(parent[x]) : x;
    }

public:
    void unite(int x, int y) {
        int root_x = root(x);
        int root_y = root(y);
        if (root_x == root_y)
            return;

        if (rank[root_x] > rank[root_y]) {
            parent[root_x] += parent[root_y];
            parent[root_y] = root_x;
        } else {
            if (rank[root_x] == rank[root_y])
                ++rank[root_y];

            parent[root_y] += parent[root_x];
            parent[root_x] = root_y;
        }
    }

    bool is_same(int x, int y) {
        return root(x) == root(y);
    }

    int group_size(int x) {
        return -parent[root(x)];
    }

    int num_groups() {
        int num = 0;
        for (int k : parent) {
            num += k < 0;
        }
        return num;
    }

    UnionFind(int n) : parent(n, -1), rank(n, 1) {}
};

int main() {
    int n, m; cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; ++i) {
        int x, y, z; cin >> x >> y >> z;
        --x; --y;
        uf.unite(x, y);
    }
    cout << uf.num_groups() << endl;
    return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val MAX = 1000
    var N = Integer.parseInt(readLine());
    var L = Array(MAX+1) { _ -> IntArray(MAX+1) };
    
    for (x in 1..N) {
        val a = readLine();
        val b = readLine();
        
        val n = a!!.length;
        val m = b!!.length;
        
        for (i in 0..(n-1)) {
            for (j in 0..(m-1)) {
                if (a[i] == b[j]) {
                    L[i+1][j+1] = L[i][j] + 1
                } else {
                    L[i+1][j+1] = if (L[i+1][j] > L[i][j+1]) {
                        L[i+1][j]
                    } else {
                        L[i][j+1]
                    }
                }
            }
        }
        println(L[n][m]);
    }
}



Measured memory_bytes: 33712
#include <stdio.h>

int main(){
char S[5], tmp;

scanf("%s", S);

tmp = S[0];
for(int i = 1; i < 4; i++){
    if(S[i] == tmp){
        printf("Bad\n");
        return 0;
    }
    else
        tmp = S[i];
}
printf("Good\n");

return 0;
}

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

const int MOD = 1000000007;

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

  int n;
  cin >> n;

  vector<int> d(1001, 0);

  for (int i = 2; i <= n; i++) {
    int num = i;
    for (int j = 2; j <= n; j++) {
      while (num % j == 0) {
        num /= j;
        d.at(j)++;
      }

      if (num == 1) break;
    }
  }

  ll ans = 1;
  for (int i = 0; i < 1001; i++) {
    if (d.at(i) > 0) {
      ans = ans * (d.at(i) + 1) % MOD;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,a,b,c,d;
  char s[200020];
  scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
  scanf("%s",s);

  int i,k;
  k = (c>d) ? c : d;
  for(i=a;i<k-1;i++){
    if(s[i]==s[i+1] && s[i]=='#'){
      printf("No\n");
      return 0;
    }
  }

  if(c > d){
    for(i=b-1;i<d;i++){
      if(s[i-1]==s[i] && s[i]==s[i+1] && s[i]=='.'){
        printf("Yes\n");
        return 0;
      }
    }
    printf("No\n");
    return 0;
  }else
    printf("Yes\n");
  return 0;
}

Measured memory_bytes: 384
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
int A[500000],cnt=0;
void merge(int T[],int l,int r,int mid){
	int a=mid-l,b=r-mid;
	int L[a+1],R[b+1];
	for(int i=0;i<a;i++) L[i]=T[i+l];
	for(int i=0;i<b;i++) R[i]=T[i+mid];
	L[a]=R[b]=1000000002;
	int i=0,j=0;
	for(int k=l;k<r;k++){
		if (L[i]<=R[j]) T[k]=L[i++];
		else T[k]=R[j++];
		cnt++;
	}
}
void msort(int T[],int l,int r){
	if (r-l>1){
		int mid=(l+r)/2;
		msort(T,l,mid);
		msort(T,mid,r);
		merge(T,l,r,mid);
	}
}
//void merge2(int A[],int x,int y,int T[]){
//	if(y-x>1){
//		int m=(x+y)/2;
//		int p=x,q=m,i=x;
//		merge2(A,x,m,T);
//		merge2(A,m,y,T);
//		while(p<m||q<y){
//			if (q>=y||(p<m&&A[p]<=A[q])) T[i++]=A[p++];
//			else T[i++]=A[q++];
//			cnt++;
//		}
//		for (int i=x;i<y;i++) A[i]=T[i];
//	}
//}
//void msort2(int A[],int n){
//	int T[n];
//	merge2(A,0,n,T);
//} 
main(){
	int n;scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	msort(A,0,n);
	for(int i=0;i<n;i++){
		printf("%d",A[i]);
		if(i!=n-1) printf(" ");
		else printf("\n");
	}
	printf("%d\n",cnt);
}



Measured memory_bytes: 7104
fun main(args: Array<String>) {
    val (n, k, q) = readIntList()
    val a = List(q) { readInt() }
    val p = MutableList(n) { k }
    a.forEach {
        p[it-1]++
    }
    p.forEach {
        if (it-q > 0) println("Yes")
        else println("No")
    }
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

using ll = long long;

int N, K;
int D[11];

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

   ll num = N;
   while (1) {
      string s = to_string(num); // 数字を文字列にする

      bool ok = true; // 嫌いな数字が存在しないならtrue
      // 嫌いな数字の有無を判定
      for (int i = 0; i < K; i++) {
         if (count(s.begin(), s.end(), D[i]+'0')) {
            ok = false;
            num++;
            break;
         }
      }

      // 嫌いな数字が泣けらばnumを出力して終了
      if (ok) {
         cout << num << endl;
         return 0;
      }
   }

   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	while(1){
		int a, b, c = 0, d = 0, i, j;
		scanf("%d %d", &a, &b);
		if(a == 0 && b == 0){
			break;
		}
		for(i = 0;i < a;i++){
			for(j = 0;j < b;j++){
				if(d == 0){
					printf("#");
					d = 1;
				}else{
					printf(".");
					d = 0;
				}
			}
			printf("\n");
			if(c == 0){
				c = 1;
				d = 1;
			}else{
				c = 0;
				d = 0;
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
/*
Problem:Xor Sum 2 (AtCoder 4142)
Algorithm:Two Pointers + Prefix Sum
Status:
*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <utility>
#include <list>
#include <ctime>
#include <memory.h>
#include <stack>
#include <stdio.h>
#include <string.h>

using namespace std;

const int INF=1e9+7;

int xo[200005],sum[200005];
int a[200005];
int n;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
	}
	xo[0]=0;
	sum[0]=0;
	for(int i=1;i<=n;i++){
		xo[i]=a[i]^xo[i-1];
		sum[i]=a[i]+sum[i-1];
	}
	
	long long cnt=0;
	
	//Two Pointers
	int l=1,r=1;
	for(;l<=n;l++){
		if(r<l)r=l;
		for(;r<=n;r++){
			//cout<<"l="<<l<<",r="<<r<<endl;
			if(sum[r]-sum[l-1]==(xo[r]^xo[l-1])){
				cnt+=r-l+1;
				
				//cout<<"sum="<<sum[r]-sum[l-1]<<",xor="<<(xo[r]^xo[l-1])<<endl;
			}
			else{
				break;
			}
		}
	}
	
	cout<<cnt<<endl;
	
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
static const int NIL = -1;
static const int MAX = 100000;
int n, color[MAX];
vector<int> G[MAX];

void dfsByStack(int s, int clr)
{
    stack<int> S;
    S.push(s);
    color[s] = clr;
    while (!S.empty())
    {
        int u = S.top();
        S.pop();
        for (int i = 0; i != G[u].size(); ++i)
        {
            int v = G[u][i];
            if (color[v] == NIL)
            {
                color[v] = clr;
                S.push(v);
            }
        }
    }
}

int main()
{
    int m, q, s, t;
    cin >> n >> m;
    for (int i = 0; i != m; ++i)
    {
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    for (int i = 0; i != MAX; ++i)
    {
        color[i] = NIL;
    }
    int clr = 0;
    for (int i = 0; i != n; ++i)
    {
        if (color[i] == NIL)
        {
            dfsByStack(i, ++clr);
        }
    }
    cin >> m;
    for (int i = 0; i != m; ++i)
    {
        cin >> s >> t;
        if (color[s] == color[t])
        {
            cout << "yes" << endl;
        }
        else
        {
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 8956
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

pair<long long ,long long> a[100010] = {};
long long res[100010] = {};

int main(void){
    // Here your code !
    long long n;
    cin >> n;
    
    long long Max = 0;
    vector<long long> order;
    
    for(int i = 0; i < n; i++){
        cin >> a[i].first;
        a[i].second = i;
        
        if(Max < a[i].first){
            Max = a[i].first;
            order.push_back(i);
            //cout << ":" << i << endl;
        } 
        
    }
    
    sort(a,a+n);
    
    /*
    for(int i = 0; i < n; i++){
        cout << a[i].first << " " << a[i].second << endl;
    }*/
    
    long long t = order[order.size()-1];
    long long sum = 0;
    long long before = 0;
    
    for(int i = n-2; i >= 0; i--){
        
        res[t] += (a[i+1].first - a[i].first)*(n-i-1);
        
        t = min(t,a[i].second);
        
    }
    
    res[t] += (a[0].first)*(n);
    
    for(int i = 0; i < n; i++){
        cout << res[i] << endl;
    }
    
}


Measured memory_bytes: 4340
# coding: utf-8

'''
S 1
H 3
H 7
C 12
D 8
'''

cards = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11', 'S12', 'S13',
'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'H10', 'H11', 'H12', 'H13',
'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11', 'C12', 'C13',
'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'D11', 'D12', 'D13']

for _ in range(int(input())):
    # suit, number = input().split()
    suit, number = map(str, input().split())
    cards.remove(suit + number)

for trump in cards:
    print(trump[0], trump[1:])




Measured memory_bytes: 5624
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(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 INF = 1e18;
#define foreach(ix,a) for(auto& (ix) : (a) 

vector<int> tree(100005);
int search(int i){
  if(tree[i]<0)return i;
  else{
    return tree[i]=search(tree[i]);
  }
}
bool unite(int x,int y ){
    int ix=search(x);
    int iy=search(y);
    if(ix==iy)return false;
    if(tree[ix] > tree[iy])swap(ix,iy);
    tree[ix]+=tree[iy];
    tree[iy]=ix;
    return true;
}
int size(int i){
  return -tree[search(i)];
}
bool same(int a,int b){
  if(search(a)==search(b))return true;
  else return false;
}
int main(){
  ll n,m,k;
  cin>>n>>m>>k;
  rep(i,n+100)tree[i]=-1;
  int fre[1000000];
  vector<int> blo[1000000];
  rep(i,n)fre[i]=0;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    fre[a]++;fre[b]++;
    unite(a,b);
  }
  
  rep(i,k){
    int a ,b;
    cin>>a>>b;
    a--;b--;
    blo[a].push_back(b);
    blo[b].push_back(a);
    }
  rep(i,n){
    int ans = size(i)-1-fre[i];
    for(int v : blo[i]){
      if(same(v,i))ans--;
    }
    if(i==n-1)cout<<ans<<endl;
    else cout<<ans<<' ';}
  
}

Measured memory_bytes: 31232
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n,i,h,b=0,t=0,res=0;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> h;
    if(h<=b){
      t++;
      res=max(res,t);
    }else{
      t=0;
    }
    b=h;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf 1000000000000000000

using namespace std;

void run();

void init() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    cout<<fixed;
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(3*n);
    rep(i,3*n){
        cin>>a[i];
    }
    vi s1;
    priority_queue<int> q1;
    int s=0;
    rep(i,n){
        s+=a[i];
        q1.push(-a[i]);
    }
    s1.pb(s);
    Rep(i,n,2*n){
        q1.push(-a[i]);
        int t=q1.top();
        if(t!=-a[i]){
            s=s+t+a[i];
        }
        q1.pop();
        s1.pb(s);
    }
    vi s2;
    priority_queue<int> q2;
    s=0;
    for(int i=3*n-1;i>=2*n;i--){
        s+=a[i];
        q2.push(a[i]);
    }
    s2.pb(s);
    for(int i=2*n-1;i>=n;i--){
        q2.push(a[i]);
        int t=q2.top();
        if(t!=a[i]){
            s=s-t+a[i];
        }
        q2.pop();
        s2.pb(s);
    }
    reverse(all(s2));
    int ans=-inf;
    rep(i,s1.size()){
        ans=max(ans,s1[i]-s2[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6516
import numpy as np
import sys
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,D = IL()
print(math.ceil(N/(D*2+1)))

Measured memory_bytes: 21752
MAX_N = 100000
MOD = 1000000007

def modinv(a)
  b = MOD
  u = 1
  v = 0
  while b > 0 do
    t = a / b
    a -= t * b
    tmp = a; a = b; b = tmp
    u -= t * v
    tmp = u; u = v; v = tmp
  end
  u %= MOD
  u += MOD if (u < 0)
  u
end

FS = Array.new(MAX_N*2)
IFS = Array.new(MAX_N*2)
FS[0] = 1
IFS[0] = 1
for i in 1 .. (MAX_N * 2) do
  FS[i] = (i * FS[i-1]) % MOD
  IFS[i] = modinv(FS[i])
end

def comb(n, r)
  (FS[n] * IFS[r] * IFS[n-r]) % MOD
end

while line = STDIN.gets
  H, W, A, B = line.split(/\s/).map(&:to_i)
end

ans = 0
for i in B .. (W-1) do
  a = H - A - 1
  b = i
  cb = (comb(a+b, a) * comb((H-1)-(a+1)+W-b-1, (W-1)-b)) % MOD
  ans += cb
  ans %= MOD
end
p ans

Measured memory_bytes: 5116
#include<iostream>
#include<string>
#include<vector>
#include<algorithm> 
#include<functional> 
#include<cassert>
#include<numeric> // std::accumulate(vec.begin(),vec.end(),0) sum of element
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>


using namespace std;


typedef long long ll;
typedef std::pair<int, int> P;
typedef vector<int> vi;


#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(c) c.begin(),c.end()
#define show(x) cout << #x << " = " << x << endl

#define fi first
#define se second
#define pb push_back



#define DEBUG


// void print_vector(const std::vector<int> &t);
// void unique_vector(std:: vector<int> &t);

template <class X>
void print_vector(const std::vector<X> &t);
template <class X>
void unique_vector(std:: vector<X> &t);


int w, h;

vector<int> xl={-1, 0, 1, 0};
vector<int> yl={0, 1, 0, -1};

int main(){

  vi ans;
  while(true){
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    vector<vector<char>> f(h, vector<char>(w));
    queue<P> ser;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++) {
	cin >> f[i][j];
	if(f[i][j] == '@')
	  ser.push(make_pair(i, j));
      }
    }
    int c = 0;
    while(!ser.empty()){
      P t = ser.front();
      ser.pop();
      int y = t.fi, x = t.se;
      // show(x); show(y);
      if(f[y][x] == '@') f[y][x] = '#';
      for(int i = 0; i < 4; i++) {
	int dx = x+xl[i], dy=y+yl[i];
	// cout << dx << ' ' << dy << endl;
	// show(dx); show(dy);
	if(dy < 0 || dy >= h || dx < 0 || dx >= w || f[dy][dx] == '#')
	  continue;
	
	if(f[dy][dx] == '.'){
	  c++;
	  ser.push(make_pair(dy, dx));
	  f[dy][dx] = '#';
	}
      }	
      // for(int i = 0; i < h; i++) {
      // 	for(int j = 0; j < w; j++) {
      // 	  cout << f[i][j] << ' ';
      // 	}
      // 	cout << endl;
      // }
      // cout << endl;
    }
    ans.pb(c+1);
  }
  for(auto &i : ans) cout << i << endl;
}

template <class X>
void unique_vector(std::vector<X> &t)
{
  std::sort(t.begin(), t.end());
  t.erase( std::unique(t.begin(), t.end()), t.end() );
}

template <class X>
void print_vector(const std::vector<X> &t){
  for(auto itr=t.begin(); itr != t.end(); itr++){
    std::cout << *itr;
    if(itr != t.end()-1) std::cout << ' ';
  }
  std::cout << std::endl;
}

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

using namespace std;

int main(){
    int N,K;
    cin>>N>>K;
    vector <int>A(N);

    int one = 0;
    for(int i=0 ; i<N ; i++){
        cin>>A[i];
        if (A[i] == 1)one = i+1;
    }
    
    int forword = N - one;
    int back = N - forword-1;
    int ans =0;
    int remnant =0;

    int small, big;
    if(forword>back){
        small=back;
        big=forword;
    }else{
        small=forword;
        big=back;      
    }

    if (small/(K-1) <1){
        ans +=1;
        remnant =K-small-1;
    }
    else {
        if(small%(K-1) == 0)ans += small/(K-1);
        else {
            ans += 1+small/(K-1);
            remnant = K - small%(K-1);
        }
    }

    if ((big-remnant)/(K-1)<1)ans +=1;
    else {
        if((big-remnant)%(K-1) == 0)ans += (big-remnant)/(K-1);
        else ans += 1+(big-remnant)/(K-1);
    }

    if(K==N)ans=1;
    cout<<ans<<endl;

    
    
    
    return 0;
}


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

int main(void){

    string s;
    int N;
    cin >> N >> s;

    int count = 1;
    char now_s = s[0];
    
    for(int i=1;i<N;i++){
        if(s[i] != now_s){
            now_s = s[i];
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,y,flag=0;
    cin>>n;
    while(n>0)
    {
        y=n%10;
        if(y==7)
        {
            flag=1;
            break;
        }
        n=n/10;
    }
    if(flag==1)
    {
        cout<<"Yes"<<endl;
    }
    else if(flag==0)
    {
        cout<<"No"<<endl;
    }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<ll> sll;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))

constexpr ll MOD = 1e9+7;

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T checkmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T checkmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

// constexpr int INF = 1<<25;
// constexpr ll  INF = 1LL<<50;
// int dp[N_MAX][M_MAX] = {}

// Forward declaration
template <typename T>
void dumpContents(const T& v, const string& msg="");

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

typedef pair<ll, int> bar;  // cost, 0: yoko, 1: tate

int main(int argc, char** argv) {
  int W, H;
  cin >> W >> H;

  vector<bar> bars;
  bars.reserve(W+H);

  for (int i=0; i<W; i++) {
    ll x;
    cin >> x;
    bars.push_back({x, 0});
  }
  for (int i=0; i<H; i++) {
    ll x;
    cin >> x;
    bars.push_back({x, 1});
  }

  Sort(bars);

  int ch = H+1;
  int cw = W+1;
  ll ret = 0;
  for (auto bar : bars) {
    assert(ch>0);
    assert(cw>0);
    switch (bar.second) {
    case 0: // yoko
      ret += bar.first * ch;
      cw--;
      break;
    case 1: // tate
      ret += bar.first * cw;
      ch--;
      break;
    }

    // cerr << "d: " << bar.second << ": " << ret << endl;
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 3328
from fractions import gcd
import math

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n =int(input())
    v = list(map(float, input().split()))
    v.sort()

    ans = v[0]
    for i in range(1, n):
        ans = (ans + v[i]) / 2
    print(ans)
main()


Measured memory_bytes: 5588
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n, k;
    cin >> n >> k;
    if(k > (n-1)*(n-2)/2){
        cout << -1 << endl;
        return 0;
    }
    vector<pii>a;
    rep(i,n-1){
        a.emplace_back(1,i+2);
    }
    k = (n-1)*(n-2)/2 - k;
    rep(i,n-1){
        rep(j,n-1){
            if(i < j and k > 0){
                a.emplace_back(i+2,j+2);
                k--;
            }
        }
    }
    cout << a.size() << endl;
    for(auto x: a){
        cout << x.first << " " << x.second << endl;
    }
}

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

int main() {
  string s, t; cin >> s >> t;
  deque<char> sq, tq;
  string ans = "No";
  int sn = s.size();
  rep(i,sn) {
    sq.push_back(s[i]);
    tq.push_back(t[i]);
  }
  rep(i,sn) {
    tq.push_front(tq.back());
    tq.pop_back();
    if (sq == tq) ans = "Yes";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
//#define DEBUG

using namespace std;
struct node {
    int id, point;
} node[1<<18];
int n, a[131072];

void add(int id, int x)
{
    id=n-1+id;
    node[id].point+=x;

    while (id>0) {
        id=(id-1)/2;
        int c1=2*id+1, c2=2*id+2;
        if (node[c1].point>=node[c2].point)
            node[id]=node[c1];
        else
            node[id]=node[c2];
    }
}

void print()
{
#ifdef DEBUG
    int k=1;
    int x=0;
    while (true) {
        for(int i=0;i<k;++i) printf("(%d %d)", node[x+i].id, node[x+i].point);
        puts("");
        x+=k;
        k<<=1;
        if (x>=n) break;
    }
    puts("");
#endif
}

int main()
{
    int m, r, l;
    scanf("%d%d%d", &m, &r, &l);
    n=1;
    while (n<m) n<<=1;
    for(int i=0;i<m;++i) node[n-1+i].id=i;

    int pt=0;
    for(int i=0;i<r;++i) {
        int d, t, x;
        scanf("%d%d%d", &d, &t, &x);

        if (pt<t) {
            int id=node[0].id;
            a[id]+=t-pt;
        }
        add(d-1, x);
        print();
        pt=t;
    }
    print();
    a[node[0].id]+=l-pt;
#ifdef DEBUG
    for(int i=0;i<n;++i) printf("%d ", a[i]); puts("");
#endif
    printf("%d\n", 1+(max_element(a, a+n)-a));
}

Measured memory_bytes: 3168
#include<iostream>
using namespace std;
int main()
{
        long long int n,m,temp;
        cin>>n;
        cin>>m;
        long long int i,sum;
        for(i=0,sum=0;i<m;i++)
        {
                cin>>temp;
                sum=sum+temp;
        }
        if(sum>n)
                cout<<"-1"<<endl;
        else
        {
                cout<<n-sum<<endl;
        }
        return 0;
}


Measured memory_bytes: 3624
n = int(input())
c = [list(map(int, input().split())) for _ in range(n)]

for i in c:
    if i[2] > 0:
        o = i
        break

for cx in range(101):
    for cy in range(101):
        H = o[2] + abs(o[0] - cx) + abs(o[1] - cy)
        f = True
        for i in c:
            x, y, h = i[0], i[1], i[2]
            if h != max(0, H - abs(x - cx) - abs(y - cy)):
                f = False
                break
        if f:
            print(cx, cy, H)
            exit()

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

int main() {
  int board = 1;
  int N, K;
  cin >> N >> K;
  
  int i;
  for(i = 0; i < N; i++){ 
    if(board > K)
      break;
    board *= 2;
  }
  for(;i < N; i++)
    board += K;
    
  cout << board << endl;
}

Measured memory_bytes: 3604