akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define INF 999999999
using namespace std;
int main() {
  ll n,k;
  cin>> n >> k;
  std::vector<ll> v;
  std::vector<ll> flag(n);
  bool loop = false;

  for (int i = 0; i < n; i++) {
    ll a;
    cin>> a;
    v.push_back(a);
    v[i] --;
  }
  if (k <= 2000000) {
    ll x = 0;
    for (int i = 0; i < k; i++) {
      x = v[x];
    }
    cout<< x+1 <<endl;
  }
  else{
    ll next = 0;
    ll count = 0;
    int s = 0;
    while (!loop) {
      if (!flag[next]) {
        flag[next] = count;
      }
      else{
        loop = true;
        s = count - flag[next];
        break;
      }
      count++;
      next = v[next];
    }
     k = k-flag[next];
     k = k%s;
     while (k != 0) {
       next = v[next];
      k--;
     }
     cout<< next+1 <<endl;
  }
}


Measured memory_bytes: 6920
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define Mx(a , b) ((a) > (b) ? (a) : (b))
#define Mn(a , b) ((a) < (b) ? (a) : (b))

const double EPS = 1e-10;
const int INF = 2147483647;
const LL mod = 1e9 + 7;

int N , C;
int A[401] , B[401];
LL R[401][401];
LL dp[401][401];

int main(){
	for(int i = 1 ; i < 401 ; ++i){
		R[i][0] = 1;
		for(int j = 1 ; j < 401 ; ++j){
			R[i][j] = (R[i][j - 1] * i) % mod;
		}
	}
	for(int j = 0 ; j < 401 ; ++j){
		for(int i = 1 ; i < 401 ; ++i){
			R[i][j] += R[i - 1][j];
			R[i][j] %= mod;
		}
	}
	scanf("%d%d" , &N , &C);
	for(int i = 1 ; i <= N ; ++i){
		scanf("%d" , A + i);
	}
	
	for(int i = 1 ; i <= N ; ++i){
		scanf("%d" , B + i);
	}
	dp[0][0] = 1;
	for(int i = 1 ; i <= N ; ++i){
		for(int j = 0 ; j <= C ; ++j){
			for(int k = 0 ; k <= j ; ++k){
				dp[i][j] += dp[i - 1][j - k] * (R[B[i]][k] - R[A[i] - 1][k] + mod);
				dp[i][j] %= mod;
			}
			//printf("%d %d %lld\n" , i , j , dp[i][j]);
		}
	}
	printf("%lld\n" , dp[N][C]);
	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  string S;
  IN(S);
  string S2;
  IN(S2);
  int cnt;
  REP(i,3){
    if(S[i] ==S2[i]) ++cnt;
  }
  OUT(cnt);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

int dp1[101][101]={0};
int dp2[101][101]={0};
int dp3[101][101]={0};
int dp4[101][101]={0};

int main(){
  // dp[x][y]
  // dp1 : x???????????§?????????????????§????????????????§???°
  // dp2 : x???????????§?????????????????§???????????????
  // dp3 : y???????????§?????????????????§????????????
  // dp4 : y???????????§?????????????????§???????????????

  repl(i,1,101) dp1[i][0]=1;
  repl(i,1,101) dp3[0][i]=1;
  repl(i,1,101) repl(j,1,101){
    dp1[i][j] = (dp1[i-1][j] + dp2[i-1][j])%100000;
    dp2[i][j] = dp3[i-1][j];
    dp3[i][j] = (dp3[i][j-1] + dp4[i][j-1])%100000;
    dp4[i][j] = dp1[i][j-1];
  }

  int h,w;
  while(cin>>h>>w, h|w){
    h--;w--;
    cout << (dp1[h][w] + dp2[h][w] + dp3[h][w] + dp4[h][w])%100000 << endl;
  }

  return 0;
}

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

struct Card{
    char suit, value;
};

void BubbleSort(struct Card C[], int N){
    int i,j;
    for(i = 0; i < N; i++){
        for(j = N-1; j > i; j--){
            if(C[j].value < C[j-1].value)swap(C[j], C[j-1]);
        }
    }
}

void SelectionSort(struct Card C[], int N){
    int i, j, minj;
    for(i = 0; i < N; i++){
        minj = i;
        for( j = i; j < N; j++){
            if(C[j].value < C[minj].value){
                minj = j;
            }
        }
        swap(C[i], C[minj]);
    }
}

void print(struct Card C[], int N){
    int i;
    for(i = 0; i < N; i++){
        if(i > 0) cout << " ";
        cout << C[i].suit << C[i].value;
    }
    cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N){
    int i;
    for(i = 0; i < N; i++){
        if(C1[i].suit != C2[i].suit){
            return false;
        }
    }
    return true;
}

int main(){
    int N;
    struct Card C1[100], C2[100];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> C1[i].suit >> C1[i].value;
    }
    for(int i = 0; i < N; i++){
        C2[i] = C1[i];
    }
    BubbleSort(C1, N);
    print(C1, N);
    cout << "Stable" << endl;
    SelectionSort(C2, N);
    print(C2, N);
    if(isStable(C1, C2, N)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    return 0;
}


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


int main()
{
	int seat[2];
	int ct=0, N,num=0;
	cin >> N;
	while (ct < N) {
		cin >> seat[0];
		cin >> seat[1];
		num += (seat[1] - seat[0] + 1);
		ct++;
	}
	cout << num;

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e9+7;
const int inf=1e9+7;
const double eps=1e-6;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
const double pi=acos(-1);


int main()
{
    TB
    int x;
    cin>>x;
    if(x>1799){
        cout<<1;
    }else if(x>1599){
        cout<<2;
    }else if(x>1399){
        cout<<3;
    }else if(x>1199){
        cout<<4;
    }else if(x>999){
        cout<<5;
    }else if(x>799){
        cout<<6;
    }else if(x>599){
        cout<<7;
    }else cout<<8;

    return 0;
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() {
    int A, B;
    cin >> A >> B;
    cout << (A + B) % 24 << endl;

    return 0;
}


Measured memory_bytes: 256
ans=114514;
char s[111];
main()
{
	gets(s);
	for(int i=0;i<strlen(s);i++)
	{
		int m=0,k=0;
		for(int j=0;j<=strlen(s);j++)
		{
			if(j==strlen(s)||s[i]==s[j])
			{
				if(m<k)m=k;
				k=0;
			}
			else
			{
				k++;
			}
		}
		if(ans>m)ans=m;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
	int N, M;
	cin >> N >> M;
	int A[N], cnt=0, sum=0;
	for(int i=0;i<N;i++){
		cin >> A[i];
		sum += A[i];
	}
	for(int i=0;i<N;i++){
		if(4*M*A[i]>=sum) cnt++;
	}

	if(cnt>=M){
		cout << "Yes" <<endl;
	}else{
		cout << "No" <<endl;
	}
  
    
  	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N, M;
    long long int X;
    cin >> N >> M >> X;
    
    vector<long long int> C(N);
    vector<vector<long long int> > A(N, vector<long long int>(M));
    for(int n=0; n<N; n++) {
        cin >> C[n];
        for(int m=0; m<M; m++) {
            cin >> A[n][m];
        }
    }
    
    long long int ans=1e9;
    for(int i=0; i<(1<<N); i++) {
        vector<long long int> tmp(M, 0);
        vector<bool> cnt(M, false);
        long long int cst=0;
        for(int n=0; n<N; n++) {
            if(i & (1<<n)) {
                cst += C[n];
                for(int m=0; m<M; m++) {
                    tmp[m]+=A[n][m];
                    if(!cnt[m] && tmp[m]>=X) {
                        cnt[m]=true;
                    }
                }
            }
        }
        bool flag=true;
        for(int m=0; m<M; m++) {
            if(!cnt[m]) {
                flag=false;
                break;
            }
        }
        if(flag) {
            ans = min(ans, cst);
        }
    }
    if(ans==1e9) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }


    return 0;
    
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll a,b,x;
cin>>a>>b>>x;
ll aa,bb;
aa=a/x;
bb=b/x;
if(a==0){
cout<<b/x+1<<endl;}
else if(a%x==0){
cout<<bb-aa+1<<endl;}
else{
cout<<bb-aa;}}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m=0,s=1;
	cin>>n;
	int a[n+1];
	int f=1;
	for(int i=1;i<=n;i++)
	{
		
		cin>>a[i];
	}
	while(f==1)
	{
		s=s*2;
		for(int i=1;i<=n;i++)
		{
			if(a[i]%2==0)
			{
				a[i]=a[i]/2;
			}
			else
			{
				f=0;
			}
		}
		if(f!=0)
		{
			m++;
		}
	}
	cout<<m;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;

typedef long long ll;
const int INF = 1000000000;
const int MOD = 1000000000 + 7;
const int MAX_N = 100000 + 1;
const int MAX_M = 100000 + 1;
int dp[MAX_N];
vector<int> G[MAX_N];
bool seen[MAX_N];
vector<int> order;

void rec(int v) {
  seen[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int next = G[v][i];
    if (seen[next]) continue;
    rec(next);
  }
  order.push_back(v);
}

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

  int N, M;
  cin >> N >> M;

  int x, y;
  for (int i = 0; i < M; i++) {
    cin >> x >> y;
    x--; y--;  // 0-index
    G[x].push_back(y);
  }

  fill(seen, seen + MAX_N, false);

  for (int v = 0; v < N; v++) {
    if (seen[v]) continue;
    rec(v);
  }
  reverse(order.begin(), order.end());
  
  for (int i = 0; i < order.size(); i++) {
    int v = order[i];
    for (int j = 0; j < G[v].size(); j++) {
      int nv = G[v][j];
      dp[nv] = max(dp[nv], dp[v] + 1);
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) ans = max(ans, dp[i]);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 11932
void main() {
    int[] tmp = readln.split.to!(int[]);
    int hw = tmp[0], ww = tmp[1];
    tmp = readln.split.to!(int[]);
    int hb = tmp[0], wb = tmp[1];
    writeln((hw - hb) * (ww - wb));
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = a[0]

def gcd(x,y):
    d = 0
    if max(x,y) == x:
        x,y = y,x
    while True:
        if y%x == 0:
            return x
        else:
            d = y%x
            y,x = x,d

for i in range(1,len(a)):
  ans = gcd(ans,a[i])
print(ans)

Measured memory_bytes: 14252
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
X, Y = map(int, input().split())

sum = 0
if X == 1 :
  sum += 300000
elif X == 2 :
  sum += 200000
elif X == 3 :
  sum += 100000

if Y == 1 :
  sum += 300000
elif Y == 2 :
  sum += 200000
elif Y == 3 :
  sum += 100000

if X == 1 and Y == 1 :
  sum += 400000
  
print (sum)


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    vector<int> n(3); cin >> n;
    YES(
        accumulate(ALL(n),0)==17
     && all_of(ALL(n),[](int x){return x==5||x==7;})
    );
}


Measured memory_bytes: 256
import sys
from collections import deque,Counter
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    a = I()
    print(a+a**2+a**3)
    return

if __name__=='__main__':
    Main()

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

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


Measured memory_bytes: 4508
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,res=0,ind,min,tmp=0,max;
  bool bm[201],rm[201];
  REP(i,201){
    rm[i] = false;
    bm[i] = false;
  }
  P red[200],blue[200],t;
  cin >> N;
  REP(i,N)cin >> red[i].first >> red[i].second;
  REP(i,N)cin >> blue[i].first >> blue[i].second;
  sort(blue,blue+N);
  REP(i,N){
    t = blue[i];
    ind = -1;
    max = -1;
    REP(j,N){
      if(red[j].first < t.first && red[j].second < t.second){
        if(max <= red[j].second && rm[j] == false){
          ind = j;
          max = red[j].second;
        }
      }
    }
    if(ind != -1){
      if(rm[ind] == true)
        continue;
      rm[ind] = true;
      tmp++;
    }
  }
  
  cout << tmp << endl;
  return 0;
}



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

#define MAX_N 10000

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

  int count1 = 0;
  int parity = 0;
  for(int i=0; i<s.size(); i++) {
    if(s[i] != (char)(parity + 48)) {
      count1 ++;
    }
    parity ^= 1;
  }

  int count2 = 0;
  parity = 1;
  for(int i=0; i<s.size(); i++) {
    if(s[i] != (char)(parity + 48)) {
      count2 ++;
    }
    parity ^= 1;
  }

  if(count1 < count2) {
    cout << count1 << endl;
  } else {
    cout << count2 << endl;
  }
  return 0;
}



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

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

int main(){
  int a,b,c; cin >> a >> b >> c;
  if(a + b >= c) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 764
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)
#define MAX_N (100010)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }
class UF {
    private:
        int par[MAX_N];
        int rank[MAX_N];
    public:
        UF(int N) {
            for(int i = 1;i <= N;i++) {
                par[i] = i;
                rank[i] = 0;
            }
        }

        int root(int x) {
            return x == par[x] ? x : par[x] = root(par[x]);
        }

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

        void merge(int x,int y) {
            x = root(x);
            y = root(y);
            if(x == y) {
                return;
            }

            if(rank[x] < rank[y]) {
                par[x] = y;
            } else {
                par[y] = x;
                if(rank[x] == rank[y])
                    rank[x]++;
            }

            return;
        }

        int connect(int n) {
            vector<bool> node;
            for(int i = 1;i <= n;i++) {
                node.push_back(false);
            }

            for(int i = 1;i <= n;i++) {
                int u = root(par[i]);
                u--;
                node[u] = true;
            }
            int ans = 0;
            for(int i = 0;i < n;i++) {
                if(node[i])
                    ans++;
            }

            return ans;
        }
};


int main(void) {
    int N,M;
   
    cin>>N>>M;
    UF uf(N);
    for(int i = 1;i <= M;i++) {
        int x,y,z;
        cin>>x>>y>>z;
        uf.merge(x,y);
    }

    cout<<uf.connect(N)<<endl;

    return 0;
}





Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
using namespace std;

int main() {
	long long int n, x = -1, tmp, m = 0, fop[30] = { 1 }, fon[30] = { 2 }, sump[30] = { 1 }, sumn[30] = { 2 };
	cin >> n;
	m = n;
	if (n == 0) { cout << 0; return 0; }
	if (n == 1) { cout << 1; return 0; }
	for (int i = 1; i <= 29; i++) {
		fop[i] = fop[i - 1] * 4;
		fon[i] = fon[i - 1] * 4;
	}
	for (int i = 1; i <= 29; i++) {
		sump[i] = sump[i - 1] +fop[i];
		sumn[i] = sumn[i - 1] +fon[i];
		
	}
	if (n >= 0) {
		for (int i = 29; i >= 0; i--) {
			if (m <= sump[i]) { tmp = i;  }
			
		}
		for (int i = tmp; i >= 2; i--) {
			if (n > sump[i-1]) { n -= fop[i]; cout << 1; }
			else { cout << 0; }
			if (n < -sumn[i-2]) { n += fon[i - 1]; cout << 1; }
			else {
				cout << 0;
			}
		}
		if (n > sump[0]) { n -= fop[1]; cout << 1; }
		else { cout << 0; }
		if (n < 0) { n += fon[0]; cout << 1; }
		else {
			cout << 0;
		}
		if (n > 0) { n -= fop[0]; cout << 1; }
		else { cout << 0; }

	}
	else {
		m=-m;
		for (int i = 29; i >= 0; i--) {
			if (m <= sumn[i]) { tmp = i; }

		}

		
		for (int i = tmp; i >= 1; i--) {
				if (n < -sumn[i-1]) { n += fon[i]; cout << 1; }
			else {
				cout << 0;
			}
			if (n > sump[i-1]) { n -= fop[i]; cout << 1; }
			else { cout << 0; }
		
		}
		if (n < 0) { n += fon[0]; cout << 1; }
		else {
			cout << 0;
		}
		if (n > 0) { n -= fop[0]; cout << 1; }
		else { cout << 0; }

	}
	
} 

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

struct stutime{
	int login;
	int logout;
	int num;
};

int main(){
	vector<stutime> v[10001];
	stutime stu;
	int pc[1001];
	int N,M,r,q;
	int t,n,m,s;
	int ts,te;
	while(1){
		cin >> N >> M;
		if(N == 0)break;
		for(int i = 1;i <= N;i++){
			pc[i] = 0;
		}
		for(int i = 1;i <= M;i++){
			v[i].clear();
		}
		cin >> r;
		for(int i = 0;i < r;i++){
			cin >> t >> n >> m >> s;
			if(s == 1){
				stu.num = n;
				stu.login = t;
				stu.logout = 0;
				v[m].push_back(stu);
			}
			else{
				for(int j = 0;j < v[m].size();j++){
					if(v[m][j].num == n && v[m][j].logout == 0){
						v[m][j].logout = t;
					}
					if(j != 0){
						if(v[m][j-1].logout >= v[m][j].login && v[m][j-1].logout != 0 && v[m][j].logout != 0){
							if(v[m][j-1].logout < v[m][j].logout){
								v[m][j].login = v[m][j-1].login;
								v[m].erase(v[m].begin() + j - 1);
							//	v[m][j-1].login = v[m][j-1].logout = 1;
							}
							else if(v[m][j-1].logout >= v[m][j].logout){
								v[m][j].login = v[m][j].logout = 1;
							}
						}
					}
				}
			}
		}
		for(int i = 0;i < M;i++){
			for(int j = 1;j < v[i].size();j++){
				if(v[i][j-1].logout >= v[i][j].login){
					if(v[i][j-1].logout < v[i][j].logout){
						v[i][j].login = v[i][j-1].login;
						v[i].erase(v[i].begin() + j-1);
					//	v[i][j-1].login = v[i][j-1].logout = 1;
					}
					else if(v[i][j-1].logout >= v[i][j].logout){
					//	v[i][j].login = v[i][j].logout = 1;
					v[i].erase(v[i].begin() +  j);
					}
					j--;
				}
			}
		}
		cin >> q;
		for(int i = 0;i < q;i++){
			int res = 0;
			cin >> ts >> te >> m;
			for(int j = 0;j < v[m].size();j++){
				if(v[m][j].login >= te || v[m][j].logout <= ts)continue;
				else if(v[m][j].login >= ts && v[m][j].logout <= te){
					res += v[m][j].logout - v[m][j].login;
				}
				else if(v[m][j].login <= ts && v[m][j].logout <= te){
					res += v[m][j].logout - ts;
				}
				else if(v[m][j].login <= ts && v[m][j].logout >= te){
					res += te - ts;
				}
				else if(v[m][j].login >= ts && v[m][j].logout >= te){
					res += te - v[m][j].login;
				}
				//cout << m << " :: " << "login : " << v[m][j].login << "logout : " << v[m][j].logout <<endl;
			}
			cout << res << endl;
		}
	}

	return 0;
}

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

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

fn main() {
    let a: Vec<char> = read::<String>().chars().collect();
    let b: Vec<char> = read::<String>().chars().collect();
    let c: Vec<char> = read::<String>().chars().collect();
    println!("{}{}{}", a[0], b[1], c[2]);
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int k = sc.NextInt();

        int answer = n % k == 0 ? 0 : 1;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include<stdio.h>

int main(){
    int N;
    int S[100];

    scanf("%d", &N);

    for (int i = 0; i < N; i++){
        scanf("%d" , &S[i]);
    }

    for (int i = N-1; i >= 0; i--)
    {
        printf("%d", S[i]);
        if (i > 0){
            printf(" ");
        }
    }

    printf("\n");

    return 0;
}



Measured memory_bytes: 2088
Num_people = gets.to_i
sum_money = 0

for i in 1..Num_people
  otoshidama = readline.split(" ")
  
  if otoshidama[1] == "BTC"
    sum_money += 380000.0 * otoshidama[0].to_f 
  else
    sum_money += otoshidama[0].to_f
  end
end

puts sum_money

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

int n,m,dis[200001];
bool vis[200001];
vector<pair<int,int> > g[200001];

bool dfs(int x){
	int i,y,d;
	vis[x]=true;
	for(i=0;i<g[x].size();i++){
		y=g[x][i].first,d=g[x][i].second;
		if(!vis[y]){
			dis[y]=dis[x]+d;
			if(!dfs(y))return false;
		}	
		else
			if(dis[x]+d!=dis[y])return false;
	}
	return true;
}

int main(){
	int i,u,v,w;
	cin >> n >> m;
	for(i=1;i<=m;i++){
		cin >> u >> v >> w;
		g[u].push_back(make_pair(v,w));
		g[v].push_back(make_pair(u,-w));
	}
	for(i=1;i<=n;i++)
		if(!vis[i])
			if(!dfs(i)){
				cout << "No" << endl;
				return 0;
			}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 14464
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int modpow(int x, int n, int m) {
    if (n == 0) return 1%m;
    long long u = modpow(x,n/2,m);
    u = (u*u)%m;
    if (n%2 == 1) u = (u*x)%m;
    return u;
}

int ncr(int n, int r){
  int res = 1;
  while(r>0){
    res = res*n%mod;
    res = res*modpow(r,mod-2,mod)%mod;
    n--;r--;
  }
  return res;
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int n,a,b;
  cin >> n >> a >> b;
  int ans = modpow(2,n,mod);
  ans = (ans-1+mod)%mod; 

  ans = (ans - ncr(n,a) + mod)%mod;
  ans = (ans - ncr(n,b) + mod)%mod;
  
  cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<int> hist(26);
	for(int i = 0; i < n; ++i){
		string pi;
		cin >> pi;
		++hist[pi[0] - 'A'];
	}
	priority_queue<int> pq;
	for(const auto x : hist){
		if(x > 0){ pq.push(x); }
	}
	int answer = 0;
	while(pq.size() >= k){
		vector<int> v(k);
		for(int i = 0; i < k; ++i){
			v[i] = pq.top();
			pq.pop();
		}
		for(int i = 0; i < k; ++i){
			if(v[i] > 1){ pq.push(v[i] - 1); }
		}
		++answer;
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
	ll a,b;
	cin >> a >> b;
	if(a<=0&&0<=b)	cout << "Zero" << endl;
	else if((0<=a&&0<=b)||(b-a)%2==1)	cout << "Positive" << endl;
	else	cout << "Negative" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    rep(i,n) {
        cin >> a[i];
    }
    ll ans = 0;
    rep(i,n) {
        ans += a[i]/2;
        a[i] %= 2;
        if(a[i] == 1) if(a[i+1] >= 1) {
            ans += 1;
            a[i]--;
            a[i+1]--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
from heapq import heappop,heappush,heapify

class Graph():
    def __init__(self,n,edge,directed=False):
        self.n = n
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0]].append((e[1],e[2]))
            if not directed:
                self.graph[e[1]].append((e[0],e[2]))
    def warshall_floyd(self,INF=10**18):
        dist = [[INF for j in range(self.n)] for i in range(self.n)]
        for i in range(self.n):
            dist[i][i] = 0
        for i in range(self.n):
            for j,cost in self.graph[i]:
                dist[i][j] = cost
        for k in range(self.n):
            for i in range(self.n):
                for j in range(self.n):
                    if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
        return dist

INF = 10**18

import sys
input = sys.stdin.readline

V,E = map(int,input().split())
edge = [tuple(map(int,input().split())) for _ in range(E)]

g = Graph(V,edge,True)
D = g.warshall_floyd(INF)


for i in range(V):
    for j in range(V):
        if D[i][j] == INF: D[i][j] = 'INF'

for i in range(V):
    if D[i][i] < 0:
        print('NEGATIVE CYCLE')
        break
else:
    print('\n'.join(map(lambda d: ' '.join(map(str,d)),D)))


Measured memory_bytes: 8012
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let s = scan!();

    let mut v = vec![];
    for i in 0..s.len() {
        for j in i + 1..s.len() + 1 {
            if s[i..j]
                .chars()
                .all(|c| c == 'A' || c == 'C' || c == 'G' || c == 'T')
            {
                v.push(s[i..j].len());
            }
        }
    }
    println!("{}", v.iter().max().unwrap_or(&0))
}


Measured memory_bytes: 4352
import bisect
import collections

N, M = map(int, input().split())
PM = [[int(j) for j in input().split()] for i in range(M)]
A = collections.defaultdict(list)
for x, y in sorted(PM):
    A[x] += [y]
for x, y in PM:
    z = bisect.bisect(A[x], y)
    print('%06d%06d'%(x,z))

Measured memory_bytes: 41024
/* 実行時間1s制限の場合10^6 1,000,000 : 余裕をもって間に合う10^7
  10,000,000 : おそらく間に合う10^8 100,000,000 : 非常にシンプルな処理
  でないと厳しい
 */
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;

typedef long long ll;                                // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll, int>> factorize(ll n)
{ // a,bの公約数 = GCD(a, b)の約数
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; i++)
  { // √nまで探せばよい
    if (n % i)
      continue;
    res.emplace_back(i, 0); // 割り切れたら
    while (n % i == 0)
    {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
  return res;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) { return (a + b - 1) / b; }

const ll INF = LONG_MAX;
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return 1;
  }
  return 0;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
  // 以降 cin の入力元が 'xxx.txt' になる
  std::ifstream in("code.txt");
  std::cin.rdbuf(in.rdbuf());
#endif

  int a, b;
  cin >> a >> b;
  cout << a*b;


  return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));  // 2次元配列初期化
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<vector<int>> vec(3);
    for (int i = 0; i < 3; ++i) {
        vec[i].resize(n);
    }
    
    for (int i = 0; i < n; ++i) {
        cin >> vec[0][i] >> vec[1][i] >> vec[2][i];
    }
    
    vector<vector<int>> D(3);
    for (int i = 0; i < 3; ++i) {
        D[i].resize(n);
        D[i][0] = vec[i][0];
    }
    
    for (int i = 1; i < n; ++i) {
        D[0][i] = max(D[1][i-1], D[2][i-1]) + vec[0][i];
        D[1][i] = max(D[0][i-1], D[2][i-1]) + vec[1][i];
        D[2][i] = max(D[0][i-1], D[1][i-1]) + vec[2][i];
    }
    
    cout << max({D[0].back(), D[1].back(), D[2].back()});
    
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#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 _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;


void solve() {
    ll n, k; cin >> n >> k;
    ll ans = k;
    rep(i, 1, n) ans *= k-1;
    cout << ans << endl;

    return;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

constexpr int MOD = 1e9+7;

int main() {

  int N, W; cin >> N >> W;
  vector<int> ws(N);
  vector<int> wsum(N);
  rep(i, N) {
    cin >> ws[i];
  }

  sort(all(ws), greater<int>());

  rep(i, N) {
    wsum[i] = ws[i] + (i ? wsum[i-1] : 0);
  }

  static int dp[2][10001];
  dp[0][W] = 1;

  rep(i, N) {
    fill(dp[(i+1)&1], dp[(i+1)&1] + W + 1, 0);
    rep(j, W+1) {
      if(wsum[N-1] - (i ? wsum[i-1] : 0) <= j) {
        dp[(i+1)&1][j] = 0;
      } else {
        dp[(i+1)&1][j] = dp[i&1][j];
      }

      if(ws[i] <= j) {
        dp[(i+1)&1][j-ws[i]] += dp[i&1][j];
        dp[(i+1)&1][j-ws[i]] %= MOD;
      }
    }
  }
  
  int ans = 0;

  rep(i, W+1) {
    ans += dp[N&1][i];
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

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

vector<pair<ll,ll> > to[444][444];
bool seen[411][411];

int main(){
    ll h,w;cin>>h>>w;
    char c[411][411];
    rep(i,0,h)rep(j,0,w)cin>>c[i][j];
    ll x[2]={1,0},y[2]={0,1};
    rep(i,0,h){
        rep(j,0,w){
            rep(k,0,2){
                if(i+x[k]>h-1||j+y[k]>w-1)continue;
                if(c[i+x[k]][j+y[k]]!=c[i][j]){
                    to[i][j].push_back(make_pair(i+x[k],j+y[k]));
                    to[i+x[k]][j+y[k]].push_back(make_pair(i,j));
                }
            }
        }
    }
    ll an=0,bl,wh;

    rep(i,0,h){
        rep(j,0,w){
            if(seen[i][j])continue;
            bl=0,wh=0;
            if(c[i][j]=='#')bl++;
            else wh++;
            seen[i][j]=1;
            queue<pair<ll,ll> > q;
            q.push(make_pair(i,j));
            while(!q.empty()){
                pair<ll,ll> now=q.front();
                q.pop();
                for(auto nx:to[now.first][now.second]){
                    if(seen[nx.first][nx.second])continue;
                    seen[nx.first][nx.second]=1;
                    if(c[nx.first][nx.second]=='#')bl++;
                    else wh++;
                    q.push(make_pair(nx.first,nx.second));
                }
            }
            an+=bl*wh;
        }
    }
    cout<<an<<endl;

}







Measured memory_bytes: 17664
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

// long long gcd(long long a, long long b){
//     if (a < b){
//         a ^= b;
//         b ^= a;
//         a ^= b;
//     }
//     return b ? gcd(b, a % b) : a;
// }

// long long lcm(long long a, long long b){
//     return a * b / gcd(a, b);
// }

int main(){
    int n;
    char s[10000];
    cin >> n >> s;
    rep(i,n) rep(j,strlen(s)){
        if(s[j] == 'Z'){
            s[j] = 'A';
            continue;
        }
        s[j]++;
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

extern inline char gc() {
    static char RR[23456], *S = RR + 23333, *T = RR + 23333;
    if(S == T) fread(RR, 1, 23333, stdin), S = RR;
    return *S ++;
}
inline int read() {
    int p = 0, w = 1; char c = gc();
    while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); }
    while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
    return p * w;
}

#define ll long long
#define ri register int
#define sid 5005

int n, k, ans, a[sid];
bitset <sid> f;

inline bool ck(int v) {
    if(a[v] >= k) return 0;
    f.reset(); f[0] = 1;
    for(ri i = 1; i <= n; i ++) {
        if(i == v) continue;
        f |= (f << a[i]);
    }
    for(ri i = k - 1; i >= k - a[v]; i --)
    if(f[i]) return 0; return 1;
}

inline int Solve() {
    int l = 0, r = n, ans = 0;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(ck(mid)) l = mid + 1, ans = mid;
        else r = mid - 1;
    }
    return ans;
}

int main() {
    n = read(); k = read();
    for(ri i = 1; i <= n; i ++) a[i] = read();
    sort(a + 1, a + n + 1);
    printf("%d\n", Solve());  
    return 0;
}

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

int main() {
  string S;
  cin>>S;
  
  int min=1000000;
  for(int i=0;i<S.size()-2;++i){
    int x=stoi(S.substr(i,3));
    int y=abs(x-753);
    if(y<min)
      min=y;
  }
  
  cout<<min<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << " " << max(a + b - n, 0) << endl;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	// ------ ここまでテンプレ ------ //
	
	char[] s = readln.chomp.to!(char[]);
	
	long x, y;
	foreach(c; s) if(c == '0') x += 1; else y += 1;
	
	print!1("x:", x, " y:", y);
	
	long ans;
	if(x <= y) ans = x * 2; else ans = y * 2;
	
	ans.writeln;
	
	
}


Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384626433832795

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}
struct node {
	node *left=NULL,*right=NULL,*parent=NULL;
	int key=-1;
};

node *root = NULL;

void insert(node *z) {
	node *y =NULL;
	node *x = root;
	while (x != NULL) {
		y = x;
		if (z->key < x->key)x = x->left;
		else x = x->right;
	}
	z->parent = y;

	if (y == NULL) {
		root = z;
	}
	else if(z->key < y->key){
		y->left = z;
	}
	else y->right = z;
}

void preprint(node* n) {
	cout << " " << n->key;
	if (n->left != NULL)preprint(n->left);
	if (n->right != NULL)preprint(n->right);
}

void inoprint(node* n) {
	if (n->left != NULL)inoprint(n->left);
	cout << " " << n->key;
	if (n->right != NULL)inoprint(n->right);
}

void findkey(int key) {
	node *curr=root;
	while (curr != NULL) {
		if (curr->key == key) {
			cout << "yes" << endl;
			return;
		}
		if (key < curr->key)curr = curr->left;
		else curr = curr->right;
	}
	cout << "no" << endl;
	return;
}



int main(){
	int n,in;
	string s;
	cin >> n;
	vector<node> zz(n);
	rep(i, n) {
		cin >> s;
		if (s == "insert") {
			cin >> in;
			zz[i].key = in;
			zz[i].left = NULL;
			zz[i].right = NULL;
			zz[i].parent= NULL;
			insert(&zz[i]);
		}
		else if (s == "find") {
			cin >> in;
			findkey(in);
		}
		else {
			inoprint(root);
			cout << endl;
			preprint(root);
			cout << endl;

		}
	}
}


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

int arr[N];
signed main() {
  int n, k; cin >> n >> k;
  int res = 1;
  for(int i = k; i <= n; i++) {
    int mn = ((i-1)*i)/2;
    int son = n;
    int bas = n-i+1;
    int mx = ((son+bas)*i)/2;
    res = (res + mx - mn + 1)%1000000007;
  }
  cout << res << endl;

}


Measured memory_bytes: 3676