akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  }
  template<class T>inline void Max(T &x, T y) {
    if (y > x) x = y;
  }
  template<class T>inline void Min(T &x, T y) {
    if (y < x) x = y;
  }
}
using namespace Header_Template;

const int N = 1e5 + 10;
int n, m, p[N], fa[N], id[N], col[N];

int Find(int x) {
  return fa[x] == x ? x : fa[x] = Find(fa[x]);
}
int main(void) {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) read(p[i]);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1, x, y; i <= m; ++i) {
    read(x), read(y);
    int fx = Find(x), fy = Find(y);
    if (fx != fy) fa[fx] = fy;
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (Find(i) == i) id[i] = ++cnt;
  for (int i = 1; i <= n; ++i)
    col[i] = id[Find(i)];
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += (col[p[i]] == col[i]);
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 1664
n,m = [int(i) for i in input().split()]
l = [[i for i in input().split()] for _ in range(m)]

ac = 0
wa = 0
problems = [[0,0] for _ in range(n)]
for i in l:
    if i[1] == 'WA' and problems[int(i[0])-1][0] == 0:
        problems[int(i[0])-1][1] += 1
    elif i[1] == 'AC' and problems[int(i[0])-1][0] == 0:
        problems[int(i[0])-1][0] = 1
    else:
        pass


for i in problems:
    ac += i[0]
    wa += i[1] if i[0] > 0 else 0
    
print(ac,wa)
    
    

Measured memory_bytes: 36204
# -*- coding: utf-8 -*-

n = int(input())
s = input()
k = int(input())
temp = []

for i in range(n):
    if s[i]!=s[k-1] :
        temp.append("*")
    else:
        temp.append(s[k-1])

ans = "".join(temp)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(ll i=a;i<=(ll)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;
ll n;
bool check(string &s) {
    bool a=0,b=0,c=0;
    for(auto i:s) {
        if(i=='7') a=1;
        else if(i=='5') b=1;
        else if(i=='3') c=1;
    }
    return a&&b&&c;
}
int dfs(string s) {
    if(stoll(s)>n) return 0;
    int t=check(s);
    t+=dfs(s+'3');
    t+=dfs(s+'5');
    t+=dfs(s+'7');
    return t;
}

int main() {
    cs
    cin>>n;
    cout<<dfs("0");
}

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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
	int a = ri(), b = ri();
	cout << a-b+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main (void){

    int in_car[32]={0};
    int out_car[32]={0};

    int i=0;
    int j=0;
    while(scanf("%d",&in_car[i])!=EOF){
        if(in_car[i]==0){
            i--;
            out_car[j]=in_car[i];
            in_car[i]=0;
            j++;
        }else{
            i++;
        }

    }
    for(i=0;i<32;i++){
        if(out_car[i]!=0)printf("%d\n",out_car[i]);
    }


    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    string s;
    cin >> s;
    REP(i,3){
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) ((a).begin(), (a).end())
typedef long long ll;
// const long long INF = 1LL << 60;
const int INF = 1010101010;
// using Graph = vector<vector<int>>;
const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> b(200010);
  rep(i, n) b[a[i]]++;
  ll ans = 0;
  rep(i, b.size()) {
    if (b[i] >= 1) {
      ans += b[i] * (b[i] - 1) / 2;
    }
  }

  rep(i, n) {
    // b[a[i]]は0にはならない
    if (b[a[i]] >= 2) {
      cout << ans - b[a[i]] * (b[a[i]] - 1) / 2 +
                  (b[a[i]] - 1) * (b[a[i]] - 2) / 2
           << endl;

    } else {
      cout << ans - b[a[i]] * (b[a[i]] - 1) / 2 << endl;
    }
  }
}


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

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

#define pii pair<int,int>
#define pll pair<ll, ll>
#define forn(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007

ll dp[100005];
ll a[100005];

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	forn(i, 0, n - 1){
		cin >> a[i];
	}
	dp[n - 1] = 0;
	ford(i, n - 2, 0){
		dp[i] = 1e18;
		forn(j, i + 1, i + k){
			if(j >= n) break;
			dp[i] = min(dp[i], abs(a[i] - a[j]) + dp[j]);
		}
	}
	cout << dp[0] << "\n";
	return 0;
}

Measured memory_bytes: 1792
from fractions import gcd

a,b,c,d = map(int,input().split())

a_mod_c = a%c
if a_mod_c == 0:
  a_mod_c = c
a_c = a + (c - a_mod_c)
count_c = (b - a_c)//c + 1

a_mod_d = a%d
if a_mod_d == 0:
  a_mod_d = d
a_d = a + (d - a_mod_d)
count_d = (b - a_d)//d + 1

lcm = (c*d)//gcd(c,d)

a_mod_lcm = a%lcm
if a_mod_lcm == 0:
  a_mod_lcm = lcm
a_lcm = a + (lcm - a_mod_lcm)
count_lcm = (b - a_lcm)//lcm + 1

ans = (b-a+1) - (count_d + count_c - count_lcm)

print(int(ans))

Measured memory_bytes: 5716
#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 vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

    
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  string s;
  cin >> s;
  ll n=s.size();
  int a=0,b=0;
  rep(i,n){
    if(s[i]=='0')a++;
    else b++;
  }
  cout << 2*(min(a,b))<< endl;
}


Measured memory_bytes: 12496
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int high(int H, int x, int y, int cx, int cy);
int main()
{
	int N;
	int CX, CY, H;
	cin >> N;
	vector<int> x;
	vector<int> y;
    vector<int> h;

    for(int i=0; i<N; i++)
    {
    	int a,b,c;
    	cin >> a >> b >> c;
    	x.push_back(a);
    	y.push_back(b);
    	h.push_back(c);
    }

    int M = *max_element(h.begin(), h.end());
    vector<int>::iterator maxIt = max_element(h.begin(), h.end());
    size_t maxIndex = distance(h.begin(), maxIt);
    
    bool flag = true;
    if(M==0){
    for(int i=0; i<=100; i++)
    {
    	for(int j=0; j<=100; j++)
    	{
    		H = abs(x[0]-i) + abs(y[0]-j);
    		for(int k=1; k<N; k++)
    		{
    			H = min(H,abs(x[k]-i) + abs(y[k]-j)); 
    		}    
    		if(H>0)
    		{
    			CY = j;
    			break;
    		}
    	}
        if(H>0){ 
        	CX = i;
        	break;
        }
    }
    }
        
    else{
    	for(int i=0;i<=100;i++)
    	{
    		for(int j=0;j<=100;j++)
    		{
    			flag = true;
    			H = h[maxIndex] 
    			    + abs(x[maxIndex]-i)
    			    + abs(y[maxIndex]-j);
    			// cout << H << endl;
    			for(int k=0; k<N; k++)
    			{
                     if(h[k]!=high(H,x[k],y[k],i,j))
                     { 
                       flag = false;
                       break;
                     }
    			}
    			if(flag==true)
    			{
    				CY = j;
    				break;
    			}
    		}
    		if(flag==true)
    		{
    		    CX = i; 
    			break;
    		}
    	}
    } 

    cout << CX << " " << CY << " " << H << endl;

	return 0;
}

int high(int H, int x, int y, int cx, int cy)
{
	return max(H-abs(x-cx)-abs(y-cy),0);
}

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

int main()
{
    int x, y;
    bool yes = false;
    cin >> x >> y;

    for(int i = 0; i <= x; ++i)
    {
        if(2 * i + 4 * (x - i) == y)
        {
            yes = true;
        }
    }

    cout << (yes ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 3512
n = int(input())

c0 = 0
c1 = 0
c2 = 0
c3 = 0

for i in range(n):
    s = input()
    if s == 'AC':
        c0 = c0 + 1
    elif s == 'WA':
        c1 = c1 + 1
    elif s == 'TLE':
        c2 = c2 + 1
    else:
        c3 = c3 + 1

print('AC x ',c0)
print('WA x ',c1)
print('TLE x ',c2)
print('RE x ',c3)



Measured memory_bytes: 9208
#include<stdio.h>
#define max 100000

int n,k;
int w[max];
int cheak(long long int P){
    int i=0,j;
    for(j=1;j<=k;j++){
        int s=0;
        while(s+w[i]<=P){
            s+=w[i];
            i++;
            if(i==n)return n;
        }
    }
    return i;
}

int main(){
    scanf("%d %d",&n,&k);
    int i;
    for(i=0;i<=n-1;i++)scanf("%d",&w[i]);
    
    long long int left=0,right=100000*10000;
    
    while(left+1<right){
        long long int mid=(left+right)/2;
        int v=cheak(mid);
        if(v<n){
            left=mid;
        }else{
            right=mid;
        }
    }
    printf("%lld\n",right);
    
    return 0;
}

Measured memory_bytes: 984
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

const int foods[]={100,101,102,103,104,105};

int main() {
  int x;
  cin>>x;
  int n=x/100,m=x%100;
  if(m<=n*5) cout<<"1"<<endl;
  else cout<<"0"<<endl;
  return 0;
}


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

int main()
{
	string s;
	cin >> s;
	int ans = 1000;
	for(auto i = 0; i < (int)s.size() - 2; ++i){
		ans = min(ans, abs(stoi(s.substr(i, 3)) - 753));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int D,G;
    cin >>D>>G;
    vector<int> p(D);
    vector<int> c(D);
    for(int i = 0; i<D; i++) cin >> p[i] >> c[i];

    int ans = 100000000;
    for(int A = 0; A < (1 << D); A++) {
        int cnt = 0;
        int sum = 0;
        int res = 1;
        for(int B = 0; B < D; B++) {
            if(A & 1 << B) {
                cnt += 100 * (B + 1) * p[B] + c[B];
                sum += p[B];
            } else {
                res = B;
            }
        }
        if(cnt < G) {
            int tmp = 100 * (res + 1);
            int ned = (G - cnt + tmp - 1) / tmp;
            if(ned > p[res]) continue;
            sum += ned;
        }
        ans = min(ans , sum);
    }
   cout << ans;
}

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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

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

int main(){
    int n; cin>>n;
    vector<int> c(n+10, 0), s(n+10, 0), f(n+10, 0);
    for(int i=0; i<n-1; i++) cin>>c[i]>>s[i]>>f[i];

    for(int i=0; i<n; i++){
        int ans=c[i]+s[i];
        for(int j=i+1; j<n-1; j++){
            if(ans > s[j]){
                ans = ((ans + (f[j] - 1)) / f[j]) * f[j];
            }
            else{
                ans = s[j];
            }
            ans += c[j];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int n;
scanf("%d",&n);
switch(n){
case 1: printf("1"); break;
case 2: printf("3"); break;
case 3: printf("4"); break;
case 4: printf("7"); break;
case 5: printf("11"); break;
case 6: printf("18"); break;
case 7: printf("29"); break;
case 8: printf("47"); break;
case 9: printf("76"); break;
case 10: printf("123"); break;
case 11: printf("199"); break;
case 12: printf("322"); break;
case 13: printf("521"); break;
case 14: printf("843"); break;
case 15: printf("1364");  break;
case 16: printf("2207"); break;
case 17: printf("3571"); break;
case 18: printf("5778"); break;
case 19: printf("9349"); break;
case 20: printf("15127"); break;
case 21: printf("24476"); break;
case 22: printf("39603"); break;
case 23: printf("64079"); break;
case 24: printf("103682"); break;
case 25: printf("167761"); break;
case 26: printf("271443"); break;
case 27: printf("439204"); break;
case 28: printf("710647"); break;
case 29: printf("1149851"); break;
    
case 35: printf("20633239"); break;
case 36: printf("33385282"); break;
    
case 42: printf("599074578"); break;
case 51: printf("45537549124"); break;
case 62: printf("9062201101803"); break;
case 79: printf("32361122672259149"); break;
case 85: printf("580696784543856761"); break;
case 86: printf("939587134549734843"); break;
default: break;
}
return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int ans = 0;
  for (int a = 0; a <= A; a++) {
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {
        if (X == 500*a + 100*b + 50*c) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

int main(){
    ll x,y;
    cin>>x>>y;
    ll count=1;
    for(int i=0;i<1000;i++){
        if(x*2<=y){
            count++;
            x*=2;
        }
        else{
            break;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#define int long long
#define INF 1000000007
using namespace std;
signed main(){
    int n,k;
    int h[114514];
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>h[i];
    int dp[114514];
    for(int i=0;i<114514;i++)dp[i]=INF;
    dp[0]=0;
    for(int i=1;i<k;i++){
        for(int j=0;j<i;j++){
            dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
        }
    }
    if(k<=n){
        for(int i=k;i<n;i++){
            for(int j=1;j<=k;j++){
                dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
            }
        }
    }
    
    cout<<dp[n-1]<<endl;
    return 0;
}





Measured memory_bytes: 1920
def gcd(a, b):
	if a < b:
		tmp = a
		a = b
		b = tmp
	
	r = a % b
	while r != 0:
		a = b
		b = r
		r = a % b

	return b

if __name__ == '__main__':
	l = list(map(int, input().split()))
	x = l[0]
	y = l[1]

	ans = gcd(x, y)
	print(ans)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
   string s;
   cin >> s;
   int count0 = 0, count1 = 0;
   rep(i,s.size()){
       if(s[i]=='0')
           count0++;
        if(s[i]=='1')
            count1++;
   }
   cout << 2 * min(count0, count1) << endl;
   return 0;
}

Measured memory_bytes: 512
n,m = map(int,input().split())
a = []
for i in range(m):
    array = list(map(int,input().split()))+[i+1]
    a.append(array)
lst = sorted(a)
num_city = 0
num_prf_old = lst[0][0]
ans_arr = []
for i in range(m):
    num_prf = lst[i][0]
    id_prf = str(num_prf).zfill(6)
    if num_prf != num_prf_old:num_city = 0
    num_city += 1
    id_city = str(num_city).zfill(6)
    num_prf_old = num_prf
    arr = [id_prf+id_city,lst[i][2]]
    ans_arr.append(arr)
lst_ans = sorted(ans_arr, key=lambda x: x[1])
for i in range(m):
    print(lst_ans[i][0])

Measured memory_bytes: 43236
N, M = map(int, input().split())
lamp = [0] * M 
for j in range(M):
    s = ['0'] * N 
    k, *num = map(int, input().split())    #; print(k, num)
    for x in num:
        s[x-1] ='1'
    lamp[j] = int(''.join(s[::-1]), 2)     #; print(bin(lamp[j]))

p = [int(i) for i in input().split()] 
ans = 0
for i in range(2**N):
    for j in range(M):
        if bin(i&lamp[j]).count('1') % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)        


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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n); 0<=i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());                   //昇順
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());    //降順
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper); 
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
#define SetPre(x) setprecision(x)

int main(void){
    //標準入力
    ll X,N;
    cin >> X >> N;

    VI P(N);
    REP(i,N)
    {
        cin >> P.at(i);
    }
    //自身が数列に含まれないなら自身を出力する例外処理
    bool flag1 = false;
    REP(i,N)
    {
        if( X == P.at(i) )
        {
            flag1 = true;
            break;
        }
    }
    if(flag1 == false)
    {
        cout << X << endl;
        return 0;
    }

    //Xに対して前後に広げていき、イコールとならなければOK
    //最も小さいほうを出力するので、先に-1をして、次に+1をする
    //数値の範囲は1～100
    //負側全探索
    bool flag2;
    ll result1 = 0;

    V_SORT_U(P);
    REP(i,101)
    {
        flag2 = false;
        REP(j,N)
        {
            if( (X-i) == P.at(j) )
            {
                flag2 = true;
                //cout  << "P.at(j)" << P.at(j) << endl;
                break;
            }
        }
        if( flag2 == false )
        {
            result1 = X-i;
            break;
        }
    }

    bool flag3;
    ll result2 = 0;
    REP(i,101)
    {
        flag3 = false;
        REP(j,N)
        {
            if( (X+i) == P.at(j) )
            {
                flag3 = true;
                break;
            }
        }
        if( flag3 == false )
        {
            result2 = X+i;
            break;
        }
    }

    if( abs(X - result1) > abs(X - result2) ){
        cout << result2 << endl;
    }
    else{
        cout << result1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

int g[50][50];
signed main() {
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++) {
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a][b]++;
        g[b][a]++;
    }
    for(int i=0;i<n;i++) {
        int count=0;
        for(int j=0;j<n;j++) {
            count+=g[i][j];
        }
        cout<<count<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//  ©   ___MRX___

#include <bits/stdc++.h>
    using namespace std;

#define ll long long int

int main()
{
    int n;
    double d, x, y, flag = 0;

    cin >> n >> d;
    while(n--) {
        cin >> x >> y;
        x = abs(x);
        y = abs(y);
        if(sqrt(x * x + y * y) <= d)
            flag++;
    }

    cout << flag << '\n';

    return 0;
}


Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
int fa[200005];
int getfa(int x)
{
	if(fa[x]!=x)fa[x]=getfa(fa[x]);
	return fa[x];
}
void Merge(int x,int y)
{
	fa[x]=y;
}
int cnt[200005];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1;i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		int r1=getfa(x),r2=getfa(y);
		if(r1!=r2)Merge(r1,r2);
	}
	for(int i=1;i<=n;++i)getfa(i),++cnt[fa[i]];
	int ans=0;
	for(int i=1;i<=n;++i)ans=max(ans,cnt[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10844
N = int(input())
Hs = [int(i) for i in input().split()]

for i in range(N):
    decr = None
    if i+1 != N:
        if Hs[i] > Hs[i+1]:
            decr = True
            Hs[i] -= 1
        if Hs[i] > Hs[i+1]:
            print('No')
            exit()

    if i == 0:
        continue

    if Hs[i] > Hs[i-1]:
        if not decr:
            Hs[i] -= 1
    if Hs[i] < Hs[i-1]:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 14396
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
int n;
int mod=1000000007;
int dp[101][4][4][4];//0で初期化
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    dp[0][3][3][3]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                for(int l=0;l<4;l++){
                    if(dp[i][j][k][l]==0) continue;//条件に当てはまるものがない
                    for(int a=0;a<4;a++){
                        if(a==2&&l==1&&k==0)continue;
                        if(a==2&&l==0&&k==1)continue;
                        if(a==2&&l==1&&j==0)continue;
                        if(a==2&&k==1&&j==0)continue;
                        if(a==1&&l==2&&k==0)continue;
                    dp[i+1][k][l][a]+=dp[i][j][k][l];
                    dp[i+1][k][l][a]%=mod;
                    }
                }
            }
        }
    }
    int ans=0;
    for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                for(int l=0;l<4;l++){
                    ans+=dp[n][j][k][l];
                    ans%=mod;
                }
            }
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  int n,q;
  int name[100010][11],t[100010];
  int top=0,tail=1;
  int i,j;
  int t_total=0;
  int count=0;

  scanf("%d",&n);
  scanf("%d",&q);
  tail=n;
  for(i=0;i<n;i++){
    scanf("%s",name[i]);
    scanf("%d",&t[i]);
  }
  while(top!=tail){
    if(t[top]<=q){
      t_total+=t[top];
      printf("%s %d\n",name[top],t_total);
      top=(top+1)%100000;
    }
    else{
      t_total+=q;
      strcpy(name[tail],name[top]);
      t[tail]=t[top]-q;
      top=(top+1)%100000;
      tail=(tail+1)%100000;
    }
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> c(n, 0), s(n, 0), f(n, 0);
  rep(i, n-1) cin >> c[i+1] >> s[i+1] >> f[i+1];

  vector<int> ans(n, 0);
  for(int i = 0; i < n; ++i){
    for(int j = i; j < n-1; ++j){
      ans[i] = max(ans[i], s[j+1]);
      ans[i] = (ans[i] + f[j+1] - 1) / f[j+1] * f[j+1];
      ans[i] += c[j+1];
    }
  }
  for(int i = 0; i < n; ++i){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
from math import ceil

a, b = map(int, input().split())

a_min = a * 100 / 8
a_max = (a + 1) * 100 / 8

b_min = b * 100 / 10
b_max = (b + 1) * 100 / 10

out = max(a_min, b_min)
print(ceil(out) if (out < a_max) & (out < b_max) else -1)

Measured memory_bytes: 3060
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const long long MXN = 1e5 + 100;
const long long MNN = 3e2 + 10;
const long long MOD = 998244353;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n, ans;
bool yeahboy[MNN][MNN];
char ch[MNN][MNN];

bool check(int a, int b){
	char rez[MNN][MNN];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			rez[(i + a) % n][(j + b) % n] = ch[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(rez[i][j] != rez[j][i]){
				return false;
			}
		}
	}
	return true;
}

int main(){
	ios;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> ch[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		if(check(0, i)){
			yeahboy[0][i] = 1;
		}
	}
	for(int i = 0; i < n; i++){
		if(yeahboy[0][i] == 1){
			ans++;
			for(int j = 1; j < n; j++){
				if(yeahboy[j % n][(i + j) % n] == 0) ans++;
				yeahboy[j % n][(i + j) % n] = 1;
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  int *a=(int *)calloc(n,sizeof(int));
  int i,j;
  for(i=0;i<n;i++) scanf("%d",a+i);
  char *dp=(char *)calloc(k+1,sizeof(char));
  for(i=0;i<k;i++){
    if(dp[i]) continue;
    for(j=0;j<n && a[j]<=k-i;j++){
      dp[i+a[j]]=1;
    }
  }
  puts(dp[k]?"First":"Second");
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define int long long
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int N, M, x = 0;
	cin >> N >> M;
	vector <int> s(M), c(M);
	rep(i, M)
		cin >> s[i] >> c[i];

	if (N == 1 && M == 0)
		cout << 0;

	if (N > 1) {
		rep(i, M) {
			if (s[i] == 1 && c[i] == 0) {
				cout << -1;
				return 0;
			}
		}
	}

	rep(i, M) {
		rep(j, M) {
			if (s[i] == s[j] && c[i] != c[j]) {
				cout << -1;
				return 0;
			}
		}
	}

	if (N == 1) {
		rep(i, M) {
			if ((s[i] == 1)&&(x==0)) {
				cout << c[i];
				x++;
			}
			if (x == 0)
				cout << 0;
		}
	}
	if (N == 2) {
		rep(i, M) {
			if (s[i] == 1 && x==0) {
				cout << c[i];
				x++;
			}
		}
		if (x == 0)
			cout << 1;
		x = 0;
		rep(i, M) {
			if (s[i] == 2 && x==0) {
				cout << c[i];
				x++;
			}
		}
		if (x == 0)
			cout << 0;
	}
	if (N == 3) {
		rep(i, M) {
			if (s[i] == 1 && x==0) {
				cout << c[i];
				x++;
			}
		}
		if (x == 0)
			cout << 1;
		x = 0;
		rep(i, M) {
			if (s[i] == 2 && x==0) {
				cout << c[i];
				x++;
			}
		}
		if (x == 0)
			cout << 0;
		x = 0;
		rep(i, M) {
			if (s[i] == 3 && x==0) {
				cout << c[i];
				x++;
			}
		}
		if (x == 0)
			cout << 0;
	}
}

Measured memory_bytes: 256
var = [0]*3
n, var[0], var[1], var[2] = list(map(int, input().split()))
choice = [input() for i in range(n)]
selVar = []
addVar = 0
res = []
flag = True

for i in range(len(choice)):
    if choice[i] == 'AB':
        selVar = [0,1]
    elif choice[i] == 'BC':
        selVar = [1,2]
    else:
        selVar = [0,2]
    if var[0]+var[1]+var[2] == 0:
        flag = False
        break
    elif var[0]+var[1]+var[2] == 1:
        if var[selVar[0]] == 0 and var[selVar[1]] == 0:
            flag = False
            break
        elif var[selVar[0]] == 0:
            var[selVar[0]] += 1
            var[selVar[1]] -= 1
            addVar = selVar[0]
        else:
            var[selVar[0]] -= 1
            var[selVar[1]] += 1
            addVar = selVar[1]
    elif var[0]+var[1]+var[2] >= 2:
        if var[selVar[0]] == 0 and var[selVar[1]] == 0:
            flag = False
            break
        elif var[selVar[0]] == 0:
            var[selVar[0]] += 1
            var[selVar[1]] -= 1
            addVar = selVar[0]
        elif var[selVar[1]] == 0:
            var[selVar[0]] -= 1
            var[selVar[1]] += 1
            addVar = selVar[1]
        elif var[0]+var[1]+var[2] == 2:
            if i < len(choice) - 1:
                if choice[i] != choice[i+1]:
                    commonLet = set(list(choice[i])) & set(list(choice[i+1]))
                    if 'A' in commonLet:
                        var[0] += 1
                        addVar = 0
                        if selVar[0] == 0:
                            var[selVar[1]] -= 1
                        else:
                            var[selVar[0]] -= 1
                    if 'B' in commonLet:
                        var[1] += 1
                        addVar = 1
                        if selVar[0] == 1:
                            var[selVar[1]] -= 1
                        else:
                            var[selVar[0]] -= 1
                    if 'C' in commonLet:
                        var[2] += 1
                        addVar = 2
                        if selVar[0] == 2:
                            var[selVar[1]] -= 1
                        else:
                            var[selVar[0]] -= 1
                else:
                    var[selVar[0]] -= 1
                    var[selVar[1]] += 1
                    addVar = selVar[1]
            else:
                var[selVar[0]] -= 1
                var[selVar[1]] += 1
                addVar = selVar[1]
        else:
            if var[selVar[0]] < var[selVar[1]]:
                var[selVar[0]] += 1
                var[selVar[1]] -= 1
                addVar = selVar[0]
            else:
                var[selVar[0]] -= 1
                var[selVar[1]] += 1
                addVar = selVar[1]
    if addVar == 0:
        res.append('A')
    elif addVar == 1:
        res.append('B')
    else:
        res.append('C')

if not flag:
    print('No')
else:
    print('Yes')
    for re in res:
        print(re)

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

int toIdx(char s){
    if(s == 'S') return 0;
    if(s == 'H') return 1;
    if(s == 'C') return 2;
    if(s == 'D') return 3;
}

char toSuit(int i){
    if(i == 0) return 'S';
    if(i == 1) return 'H';
    if(i == 2) return 'C';
    if(i == 3) return 'D';
}

int main(){
    int n,m;
    cin >> n >> m;
    int A[n][m],b[m];
    for(int i =0;i<n;++i){
        for(int j=0;j<m;++j){
            cin >> A[i][j];
        }
    }
    for(int i=0;i<m;++i){
        cin >> b[i];
    }

    for(int i=0;i<n;++i){
        int ci = 0;
        for(int j=0;j<m;++j){
            ci += A[i][j] * b[j];
        }
        cout << ci << endl; 
    }
    return 0;
}



Measured memory_bytes: 3148
x,n = map(int,input().split())
pi = [int(i) for i in input().split()]

li = [0]*(100+2)
for i in range(n):
    li[pi[i]] = 1
    
#print(li)

dif = 10**10
ans = -1
    
for i in range(102):
    if li[i] == 0:
        if dif > abs(x-i):
            dif = abs(x-i)
            ans = i
            
print(ans)

Measured memory_bytes: 61772
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)


//橋・二重辺連結成分の列挙 verified 天下一プロコン2015qualA-D
#define MAX_V 100000
vector<int> G[MAX_V];

void visit(int cur, int prev, vector<pii> &brg, vector<vector<int>> &each_bcc, vector<int> &cmp, stack<int> &roots, stack<int> &S, vector<bool> &inS, vector<int> &order, int &k){
    order[cur] = ++k;				//頂点を訪れた順に順序付け
    S.push(cur); inS[cur] = true;	//訪れた頂点の集合を管理
    roots.push(cur);				//各二重辺連結成分をDFS木の部分木として見たときの、根を管理
    
    rep(i,G[cur].size()){
        int to = G[cur][i];
        if(order[to]==0){
            visit(to,cur,brg,each_bcc,cmp,roots,S,inS,order,k);
        }
        else if(to!=prev && inS[to]){	//後退辺をたどる
            while(order[roots.top()] > order[to]) roots.pop();	//cur〜toまで(toは含まない)の頂点をrootsから捨てる
        }
    }
    
    if(cur==roots.top()){	//オイラーツアーみたいなのを考えて、葉側から根側に橋を渡るとき、条件式がTRUEになる
        if(prev!=-1)brg.pb(pii(prev,cur));
        vector<int> bcc;
        while(1){
            int node = S.top(); S.pop(); inS[node] = false;	//集合Sからnodeを捨てる
            bcc.pb(node);									//nodeを二重辺連結成分に追加
            cmp[node] = each_bcc.size();
            if(node==cur)break;
        }
        each_bcc.pb(bcc);
        roots.pop();
    }
}


void bridge(int V, vector<pii> &brg, vector<vector<int>> &each_bcc, vector<int> &cmp){	//橋の列挙と二重辺連結成分分解を同時に行う
    vector<int> order(V);
    vector<bool> inS(V);
    stack<int> roots, S;
    int k=0;
    rep(i,V){
        if(order[i]==0){
            visit(i,-1,brg,each_bcc,cmp,roots,S,inS,order,k);
        }
    }
}


void getBccedGraph(vector<vector<int>> each_scc, vector<int> cmp, vector<int> newGraph[MAX_V]){   //bccの結果からグラフを得る O(E)くらい？
    rep(i,each_scc.size()){
        set<int> edges;
        rep(j,each_scc[i].size()){
            rep(k,G[each_scc[i][j]].size()){
                int to = G[each_scc[i][j]][k];
                if( cmp[to]!=i )edges.insert(cmp[to]);
            }
        }
        for(auto &edge:edges)newGraph[i].pb(edge);
    }
}


int main(){
    int v,e;
    cin>>v>>e;
    rep(i,e){
        int u,v;
        cin>>u>>v;
        u--,v--;
        G[u].pb(v);
        G[v].pb(u);
    }
    
    vector<pii> brg;				//橋のリスト
    vector<vector<int>> each_bcc;	//二重辺連結成分のリスト
    vector<int> cmp(v);				//cmp[i] = 頂点iが所属している二重辺連結成分の番号
    bridge(v,brg,each_bcc,cmp);
    
    cout<<brg.size()<<endl;
    
}


Measured memory_bytes: 2560
#include <iostream>
#include <map>
using namespace std;
using ll = long long;

int main() {
	int N;
	cin >> N;
	map<int, ll> A;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		auto it = A.find(a);
		if (it == A.end()) {
			A.emplace(a, 1);
		} else {
			(it->second)++;
		}
	}
	ll S = 0;
	for (auto p : A) {
		S += p.first * p.second;
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int B, C;
		cin >> B >> C;
		if (A.find(B) != A.end()) {
			S += (C - B) * A.at(B);
			if (A.find(C) == A.end()) {
				A.emplace(C, A.at(B));
			} else {
				A.at(C) += A.at(B);
			}
			A.erase(B);
		}
		cout << S << endl;
	}
	return 0;
}


Measured memory_bytes: 7412
'use strict'
function Main(input){
  input=input.trim().split(/\s+/);
  var N=input.shift()-0;
  var K=input.shift()-0;
  input=input.join('');
  var S=input.split('').map(x=>x-0);
  var c=[1];
  for(let i=0;i<N-1;i++){
    if(S[i+1]===S[i]){
      c[c.length-1]++;
    }else{
      c.push(1);
    }
  }
  if(S[0]===0)c.unshift(0);
  if(c.length%2===0)c.push(0);
  var L=2*K+1;
  if(L>=c.length){
    console.log(N);
    return;
  }
  var v=[0];
  for(let j=0;j<L;j++){
    v[0]+=c[j];
  }
  for(let j=0;j<(c.length-L)/2;j++){
    v[j+1]=v[j]+c[2*j+L]+c[2*j+L+1]-c[2*j]-c[2*j+1];
  }
  var result=Math.max.apply(null,v);
  console.log(result);
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 15436
#include <stdio.h>
int main (){
	
	int x = 0;
	int n;
	scanf("%d\n", &n);
	char s[n];
	scanf("%s", s);
	int temp = 0;
	
	for (int i=0; i<n; i++){
		if (s[i] == 73){ 
			x++;
		}
		if (s[i] != 73){
			x--;
		}
		if (x>temp){
			temp++;
		}
	}
	printf("%d", temp);
	
	return 0;
}

Measured memory_bytes: 1728
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
b = [(int(input())) for _ in range(N)]

bingo1 =[0,0,0]
bingo2 =[0,0,0]
bingo3 =[0,0,0]
for i in range(3):
    for j in range(N):
        if A1[i]==b[j]:
            bingo1[i]=1
        elif A2[i]==b[j]:
            bingo2[i]=1
        elif A3[i]==b[j]:
            bingo3[i]=1    


            
if bingo1[0] == bingo1[1] == bingo1[2] == 1:
    print("Yes")
elif bingo2[0] == bingo2[1] == bingo2[2] == 1:
    print("Yes")
elif bingo3[0] == bingo3[1] == bingo3[2] == 1:
    print("Yes")
elif bingo1[0] == bingo2[0] == bingo3[0] == 1:
    print("Yes")
elif bingo1[1] == bingo2[1] == bingo3[1] == 1:
    print("Yes")
elif bingo1[2] == bingo2[2] == bingo3[2] == 1:
    print("Yes")
elif bingo1[0] == bingo2[1] == bingo3[2] == 1:
    print("Yes")
elif bingo1[2] == bingo2[1] == bingo3[0] == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX = 100010;
ll inv[MAX],fact[MAX],fi[MAX],mod = 1000000007;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll a[3010],dp[3010][3010] = {};
int main(){
	int i,j,n,q;
	cin >> n >> q;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	inverse();
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(a[i]>a[j]) dp[i][j] = 1;
		}
	}
	for(i=0;i<q;i++){
		ll x,y; cin >> x >> y;
		x--; y--;
		for(j=0;j<n;j++){
			if(j==x || j==y) continue;
			ll u = dp[x][j],v = dp[y][j];
			dp[x][j] = (u + v)*inv[2]%mod;
			dp[y][j] = (u + v)*inv[2]%mod;
			u = dp[j][x],v = dp[j][y];
			dp[j][x] = (u + v)*inv[2]%mod;
			dp[j][y] = (u + v)*inv[2]%mod;
		}
		ll u = dp[x][y],v = dp[y][x];
		dp[x][y] = (u + v)*inv[2]%mod;
		dp[y][x] = (u + v)*inv[2]%mod;
	}
	ll ans = 0;
	for(i=0;i<n;i++){
		for(j=i + 1;j<n;j++){
			ans += dp[i][j];
		}
	}
	for(i=0;i<q;i++){
		(ans *= 2) %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 73344
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	int sum=0;
	int n=s.size();
	for(int i=0;i<n-1;i++)
	if(s[i]!=s[i+1]) sum++;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 512
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;


public class  Main{
	public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();
        int ans=1;int cov=sc.nextInt();
        for(int i=1;i<n;i++) {
        	int x=sc.nextInt();
        	if(x>=cov) {
        		ans++;cov=x;
        	}
        }
        pw.println(ans);
        pw.flush();
    }
    static class edge implements Comparable<edge>{
    	int node;int cost;
    	edge(int a,int b){
    		node=a;cost=b;
    	}
		@Override
		public int compareTo(edge o) {
			if(cost!=o.cost) {
				return cost-o.cost;
			}
				return node-o.node;
			
		}
		public String toString() {
			return "("+node+" "+cost+")";
		}
    }
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21332
#include <stdio.h>

int Divisor( int , int);
int main(){
  int x,y,div;
  scanf("%d%d",&x,&y);
  if(x>y) div=Divisor(x,y);
  else div=Divisor(y,x);
  printf("%d\n",div);
  return 0;
}

int Divisor(int num1, int num2){
  if(num1%num2==0) return num2;
  else return Divisor(num2,num1%num2);
}



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

int main(){
    long long N;
    std::cin >> N;
    if(N == 2){
        std::cout << 1 << std::endl;
        return 0;
    }
    int ans = 2;
    int max = (int)std::sqrt(N);
    for(int i=2; i<=max; i++){
        long long N_tmp = N;
        if(N_tmp % i == 0){
            while(N_tmp % i == 0){
                N_tmp = N_tmp / i;
            }
            if(N_tmp  % i == 1){
                ans++;
            }
        }else if(N_tmp % i == 1){
            if((N-1) / i == i){
                ans++;
            }else{
                ans += 2;
            }
        }
    }

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



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

using namespace std;
#define ll long long

int main()
{
    int n;
    cin >> n;
    int ans=0;
    ans+=(n/500)*1000;
    n-=n/500*500;
    ans+=n/5*5;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256