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

using namespace std;
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }




int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int q;
	cin >>q;
	rep(zz, q){
		ll a,b;
		cin >>a >>b;
		if(a>b) swap(a,b);
		
		ll lw=0, hi=b*3;
		while(hi - lw > 1){
			ll md= (hi + lw) >> 1, lmx = 0;
			for(ll i=max(md/2-10, 1LL); i<=min(md/2+10, md);i++){
				ll y = i;
				if(i>=a) y++;
				ll x = md +1 - i;
				if(i<=md-b+1) x++;
				lmx = max(lmx, y*x);
			}
			if( lmx < a*b) lw = md; else hi = md;
		}
		
		cout << lw << "\n";
	}
	return 0;
	
}


Measured memory_bytes: 256
#coding: utf-8

from collections import Counter
N = int(input())

s_list = []
for i in range(N):
    input_string = list(input())
    input_string.sort()
    input_string = "".join(input_string)
    s_list.append(input_string)

s_list.sort()

list_counter = Counter(s_list)

count = 0
for key in list_counter.keys():
    tmp_count = list_counter[key]
    if tmp_count < 2:
        pass
    elif tmp_count == 2:
        count += 1
    else:
        permutations = tmp_count * (tmp_count - 1)
        combination = permutations/2
        count += int(combination)

print(int(count))


Measured memory_bytes: 19788
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int x, y;
    cin >> x >> y;
    if (y < x + x || y > x + x + x + x || y % 2 != 0) {
        cout << "No" << endl;
    } else cout << "Yes" << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
int k;
 string s;
  cin>>k>>s;
  if(s.size()<=k)
    cout<<s;
  else
  {
   for(int i=0;i<k;i++)
     cout<<s[i];
    cout<<"...";
  }
}

Measured memory_bytes: 3624
import math
a,b,x = map(int,input().split())
if x >= a*a*b/2:
    deru = a*a*b - x
    tans = deru*2/(a*a*a)
    atan1 = math.degrees(math.atan(tans))
else:
    tans = b*b*a/2/x
    atan1 = math.degrees(math.atan(tans))
print(atan1)




Measured memory_bytes: 3060
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	if N == M:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
	main()

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

const int N=200000+10;
int a[N],b[N];

int main(){
    int n,k,tmp,cnt=0,ans=0;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(b[a[i]]==0) cnt++;
        b[a[i]]++;
    }
    multiset <int> s;
    multiset <int> ::iterator it;
    for(int i=0;i<N;i++){
        if(b[i]!=0) s.insert(b[i]);
    }
    if(cnt<=k) {cout<<0<<endl;return 0;}
    for(int i=1;i<=cnt-k;i++){
        it=s.begin();s.erase(it);
        ans+=*it;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 11136
import java.util.*;
import java.io.*;
class Job{
    long reward;
    long wait;
    public Job(long w, long r){
        this.reward = r;
        this.wait = w;
    }
    static Comparator<Job> moreReward(){
        return (x,y) -> Long.compare(y.reward, x.reward);
    }
    static Comparator<Job> faster(){
        return (x,y) -> Long.compare(x.wait, y.wait);
    }

    public String toString(){
        return "["+wait+" "+reward+"]";
    }

}
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        List<Job> jobs = new ArrayList<Job>(N);
        for(int n=0; n<N; n++) jobs.add(new Job(sc.nextLong(), sc.nextLong()));
        jobs.sort(Job.faster());
        LinkedList<Job> joblist = new LinkedList<>(jobs);

        PriorityQueue<Job> validJobs = new PriorityQueue<>(Job.moreReward());
        long ans = 0;
        for(int m=1; m<=M; m++){
            while(!joblist.isEmpty() && joblist.getFirst().wait<=m) validJobs.add(joblist.pop());
            if(!validJobs.isEmpty()) ans += validJobs.poll().reward;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 97872
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(int arg_x,int arg_y,int arg_z){
		x = arg_x;
		y = arg_y;
		z = arg_z;
	}
	bool operator<(const struct Info &arg) const{
		if(x != arg.x){
			return x < arg.x;
		}else if(y != arg.y){
			return y > arg.y;
		}else{
			return z > arg.z;
		}
	}
	int x,y,z;
};

struct Data{
	Data(int arg_y,int arg_z){
		y = arg_y;
		z = arg_z;
	}
	bool operator<(const struct Data &arg) const{
		return y < arg.y;
	}
	int y,z;
};

int m,n,A,B;
vector<Info> V;

int a, b, C = ~(1<<31), M = (1<<16)-1;
int r() {
  a = 36969 * (a & M) + (a >> 16);
  b = 18000 * (b & M) + (b >> 16);
  return (C & ((a << 16) + b)) % 1000000;
}

void func(){

	V.clear();
	a = A;
	b = B;

	int tmp_x,tmp_y,tmp_z;

	for(int loop = 0; loop < m; loop++){

		scanf("%d %d %d",&tmp_x,&tmp_y,&tmp_z);
		V.push_back(Info(tmp_x,tmp_y,tmp_z));
	}

	for(int loop = 0; loop < n; loop++){

		tmp_x = r();
		tmp_y = r();
		tmp_z = r();

		V.push_back(Info(tmp_x,tmp_y,tmp_z));
	}

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

	vector<set<Data>> SET(m+n);

	SET[0].insert(Data(V[0].y,V[0].z));

	int max_group = 0;
	int left,right,mid,next_group;

	for(int i = 1; i < m+n; i++){

		left = 0,right = max_group,mid = (left+right)/2;
		next_group = 0;

		while(left <= right){

			auto at = SET[mid].lower_bound(Data(V[i].y, V[i].z));

			if(at != SET[mid].begin() && (--at)->z < V[i].z){

				next_group = mid+1;
				left = mid+1;

			}else{

				right = mid-1;
			}
			mid = (left+right)/2;
		}

		if(max_group < next_group){

			max_group = next_group;
			SET[next_group].insert(Data(V[i].y,V[i].z));

		}else{

			auto at = SET[next_group].lower_bound(Data(V[i].y, V[i].z));
			while (at != SET[next_group].end() && at->z >= V[i].z){
				at = SET[next_group].erase(at);
			}

			if(SET[next_group].size() == 0){

				SET[next_group].insert(Data(V[i].y,V[i].z));

			}else{

				at = SET[next_group].lower_bound(Data(V[i].y, V[i].z));
				if(at == SET[next_group].begin() || (--at)->z != V[i].z){
					SET[next_group].insert(Data(V[i].y,V[i].z));
				}
			}
		}
	}
	printf("%d\n",max_group+1);
}

int main(){

	while(true){
		scanf("%d %d %d %d",&m,&n,&A,&B);
		if(m == 0 && n == 0 && A == 0 && B == 0)break;

		func();
	}

	return 0;
}



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

#define f(x, y, z) for (int x = (y), __ = (z); x < __; ++x)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define mst(x, a) memset(x, a, sizeof(x))

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1 << 27;
const ll LLINF = (ll)1 << 60;
const int MOD = 1e9+7;

inline int mod(int x, int y) {
  return (x % y + y) % y;
}

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

int D, K;
vector<int> dim;
int dp[2][100][2] = {};

int main() {
  dim.push_back(-1);
  do {
    char ch;
    scanf("%c", &ch);
    if (ch == '\n') break;
    dim.push_back(ch - '0');
  } while (true);
  scanf("%d", &D);

  // dp[i][mod][eq]
  dp[0][0][1] = 1;
  K = dim.size() - 1;
  int cur = 0, prev = 1;
  for (int i = 1; i <= K; i++) {
    swap(cur, prev);
    for (int state = 0; state < D; state++) {
      dp[cur][state][1] = dp[prev][(state - dim[i] + D) % D][1];

      int sum = 0;
      for (int j = 0; j <= 9; j++) {
        sum = (sum + dp[prev][mod(state - j, D)][0]) % MOD;
      }
      for (int j = 0; j < dim[i]; j++) {
        sum = (sum + dp[prev][mod(state - j, D)][1]) % MOD;
      }
      dp[cur][state][0] = sum;
    }
  }
  printf("%d\n", mod(dp[cur][0][0] + dp[cur][0][1] - 1, MOD));
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin>>K;
    cout<<a[K-1]<<endl;
    return 0;
}


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

int main() {
  long long N,K;
  cin >> N >> K;
  vector<long long>vec(N);
  long long v[200002] = {};
  for(long long i=0; i<N; i++){
  cin >> vec[i];
    v[vec[i]-1]++;
  }
  sort(v,v+N);
  long long ans = 0;
  for(long long i=0; i<N-K; i++){
    ans += v[i];
  }
  cout << ans << endl;
}


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

int n;
long long int v[200000];
long long int s[200000];
long long int x[200000];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

	for (int i = 0; i < n; i++) {
		s[i] += v[i];
		if (i) s[i] += s[i-1];
		x[i] ^= v[i];
		if (i) x[i] ^= x[i-1];
	}

	long long int ans = 0LL;

	for (int i = 0; i < n; i++) {
		int l = i, r = n;

		while (r - l > 1) {
			int m = (l + r) / 2;
			long long int sum = s[m] - (i > 0 ? s[i-1] : 0LL);
			long long int xr = x[m] ^ (i > 0 ? x[i-1] : 0LL);

			if (sum == xr) l = m;
			else r = m;
		}

		ans += (long long int)(r - i);
	}

	cout << ans << endl;

	return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

long long gcd(long long x, long long y){
  if(y == 0) return x;
  else return gcd(y, x%y);
}

bool IsPrime(long long n){
  if(n == 1) return false;
  for(long long i = 2; i * i < n; i++){
    if(n%i == 0) return false;
  }
  return true;
}

vector<long long> EnumDivisors(long long n){
  vector<long long> res;

  for(long long i = 1; i * i <= n; i++){
    if(n % i == 0){
      res.push_back(i);
      if(n/i != i) res.push_back(n/i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

vector<pair<long long, long long>> PrimeFactorize(long long n){
  vector<pair<long long, long long>> res;

  long long a = 0;
  long long b = 0;

  for(long long i = 2; i * i <= n; i++){
    a = 0;
    if(n%i == 0){
      if(IsPrime(i)){
        while(n % i == 0){
          n /= i;
          a++;
        }
        res.push_back(make_pair(i, a));
      }
    }
  }

  if(n!= 1) res.push_back(make_pair(n, 1));

  return res;

}

int main(){
  long long a, b;
  cin >> a >> b;

  vector<pair<long long, long long>> a_fac = PrimeFactorize(a);
  vector<pair<long long, long long>> b_fac = PrimeFactorize(b);

  // for(int i = 0; i < a_fac.size(); i++) cout << a_fac[i].first << ", " << a_fac[i].second << endl;
  // for(int i = 0; i < b_fac.size(); i++) cout << b_fac[i].first << ", " << b_fac[i].second << endl;

  long long ans = 0;
  for(int i = 0; i < a_fac.size(); i++){
    for(int j = 0; j < b_fac.size(); j++){
      if(a_fac[i].first == b_fac[j].first) {
        // cout << "i = " << i << ", j = " << j << endl;
        ans ++;
      }
    }
  }
  cout << ans + 1 << endl;
  
  

  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
long long ppow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret *= x;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x *= x;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}
int main()
{
    long long int x;
    cin >> x;

    int sqrtx = std::sqrt((float)x) + 1;
    //cout << sqrtx << endl;
    for(int a=0; a<=sqrtx; a++){
        for(int b=0; b>=-sqrtx; b--){
            //cout << a << " " << b << endl;
            
            if(ppow(a,5) - ppow(b,5) == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
        for(int b=1; b<=sqrtx; b++){
            //cout << a << " " << b << endl;
            
            if(ppow(a,5) - ppow(b,5) == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
    int N;
    cin >> N;
    vector<vector<ll>> v(N,vector<ll>(N,0));
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) cin >> v[i][j];
    ll ans = 0;
    for(int i=0;i<N-1;i++) for(int j=i+1;j<N;j++) ans += min(v[i][j],v[j][i]);
    cout << ans << endl;
}


Measured memory_bytes: 3216
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
using ll=long long;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define REP1(i, n)  for(int i = 1; i < (int)n; ++i)
#define REPll1(i, n)  for(ll i = 1; i*i < (int)n; ++i)

int cnt(ll n) {
    int c = 0;
    while (true) {
        if (n < 1)break;
        n = n / 10;
        c++;
    }
    return c;
}

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll mod = 1e9 + 7;
const ll MAX1E5 = 100000;
const ll MAX1E10 = 10000000000;
const ll MAX1E15 = 1000000000000000;

int main() {
    int N;
    ll a = 0, x, y, answer = MAX1E15, sum = 0, allSum, tmp;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) {
        cin >> a;
        sum += a;
        A[i] = sum;
    }

    allSum = sum;

    REP(i, N - 1) {
        x = A[i];
        y = allSum - x;
        answer = min(answer, abs(x-y));
    }

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 1792
def main():
    c = 0
    s = input()
    f = ''
    b = ''
    for _ in range(int(input())):
        q = input().split()
        if q[0] == '1':
            c += 1
        else:
            if (q[1] == '1' and c%2 == 0) or (q[1]=='2' and c%2==1):
                f = q[2] + f
            else:
                b += q[2]
    if c % 2 == 0:
        print(f+s+b)
    else:
        print(b[::-1]+s[::-1]+f[::-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 4464
from collections import deque
N, K = map(int, input().split())
MOD = 10 ** 9 + 7

# guchoku case

# dp = [[0 for _ in range(N+1)] for _ in range(K+1)]

# for i in range(N+1):
#     dp[1][i] = 1
# for i in range(K):
#     for j in range(1,N+1):
#         for k in range(1, N // j + 1):
#             dp[i+1][j] += dp[i][k]
#             dp[i+1][j] %= MOD

JN = deque()  # N//j table
SQN = int(N**0.5)
JN.append(SQN)

if SQN**2 != N:
    JN.append(N//SQN)
for j in range(SQN-1, 0, -1):
    JN.appendleft(j)
    JN.append(N//j)
JN.appendleft(0)

# JN.sort()
# PJN = {JN[i]: JN[i-1] for i in range(1, len(JN))}  # prev jn
LJN = len(JN)

dp = [[0 for _ in range(LJN)] for _ in range(K)]
cdp = [[0 for _ in range(LJN)] for _ in range(K)]
w = [0 for _ in range(LJN)]

# init dp
prv = 0
for i in range(1,LJN):
    jn = JN[i]
    dp[0][i] = 1
    w[i] = jn - prv
    cdp[0][i] = jn
    prv = JN[i]

for i in range(K-1):
    for j in range(1,LJN):
        dp[i+1][j] = cdp[i][LJN-j]
        dp[i+1][j] %= MOD
        cdp[i+1][j] = cdp[i+1][j-1] + dp[i+1][j] * w[j]
        cdp[i+1][j] %= MOD

print(cdp[-1][-1])


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

using namespace std;
using ll = long long;


int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a += b;
    c += d;
    if(a == c){
        cout << "Balanced" << endl;
    }else if(a > c){
        cout << "Left" << endl;
    }else{
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << ' ' << b << ' ' << c;
}


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

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    int ma = 0;
    rep(i, N){
        cin >> A[i];
        ma = max(ma, A[i]);
    }
    sort(A.begin(), A.end());

    if(K > ma){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    int now = A[0];
    bool ok = true;
    while(ok){
        ok = false;
        int nex = now;
        rep(i, N){
            int a = A[i] % now;
            if(a == 0)continue;
            ok = true;
            nex = min(nex, a);
        }
        now = nex;
    }

    if(K % now == 0){
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 3708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            long tss = long.Parse(str[1]);
            long count = 1;
            
            while (true)
            {
                if(tss >= long.Parse(str[0]))
                {
                    if ( tss == long.Parse(str[0]))
                    {
                        count++;
                    }
                    break;
                }
                else
                {
                    tss *= long.Parse(str[1]);
                }
                count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
$data = []
ans = []
def culc ope, level
	case ope
	when '+'
		result = 0
		exe = "+="
	when '*'
		result = 1
		exe = "*="
	end
	loop{
		if $data.empty? || $data.first.length < level 
			return result
		else
			tmp = $data.first.split("").last.to_s
			if tmp == '*' || tmp == '+'
				ans = culc $data.shift.split("").last.to_s, level + 1
			else
				ans = $data.shift.split("").last.to_i
			end
		end
		eval("result"+exe+"ans")
	}
end

loop{
	num = gets.to_i
	break if num == 0
	num.times do
		$data << gets.chomp 
	end
	if num == 1
		ans << $data.shift
	else
		ans << culc($data.shift ,2)
	end
}
ans.each do |a|
	puts a
end

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

using namespace std;

const int N=2e3+100;
int n,m[N],h[N],y,x,k,cnt,a[N],b[N];
vector <int> v[N];
void dfs(int s)
{
	m[s]=1;
	int y;
	for(int i=0; i<v[s].size(); i++)
	{
		y=v[s][i];
		if(m[y]==0)
		{
			h[y]=h[s]+1;
			dfs(y);
		}
	}
}
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin >> n >> k;
	for(int i=1; i<n; i++)
	{
		cin >> a[i] >> b[i];
		v[a[i]].push_back(b[i]);
		v[b[i]].push_back(a[i]);
	}
	if(k%2==0)	
	{
		y=1e9;
		for(int i=1; i<=n; i++)
		{
			cnt=0;
			fill(m,m+N,0);
			h[i]=0;
			dfs(i);
			for(int j=1; j<=n; j++)
			if(h[j]>k/2)
				cnt++;
		//	cout << cnt << ' ';
			y=min(y,cnt);
		}
		//cout << endl;
		cout << y << endl;
		return 0;
	}
	else
	{
                y=1e9;
		k--;
                for(int i=1; i<n; i++)
                {
			cnt=0;
                        fill(m,m+N,0);
                        m[a[i]]=1;
			m[b[i]]=1;
			h[a[i]]=0;
			h[b[i]]=0;
                        dfs(a[i]);
			dfs(b[i]);
                        for(int j=1; j<=n; j++)
                        if(h[j]>k/2)
                                cnt++;
                        y=min(y,cnt);
                }
                cout << y << endl;
                return 0;
        }

}


Measured memory_bytes: 512
a=list(input())
b=list(input())
c=['']*1000000
j=0
z=1
e=''
for i in range(0,len(a)):
  c[j]+=a[i]
  j+=2
for i in range(0,len(b)):
  c[z]+=b[i]
  z+=2
for i in range(len(a)+len(b)):
  e+=c[i]
print(e)
  


Measured memory_bytes: 10868
from typing import Any,Sequence



def Insertion_sort(A:Sequence, N:int, g:int) -> None:
    global cnt
    for i in range(g, N):
        tmp = A[i]
        j = i - g
        while j >= 0 and A[j] > tmp:
            A[j + g] = A[j]
            j = j - g
            cnt += 1
        A[j + g] = tmp


def shell_sort(A:Sequence, N:int) -> None:
    global cnt
    cnt = 0
    g = []
    h = 1
    while h <= N:
        g.append(h)
        h = (3 * h) + 1
    g.reverse()
    m = len(g)
    print(m)
    print(' '.join(map(str, g)))

    for i in range(m):
        Insertion_sort(A, N, g[i])


n = int(input())
B = [int(input()) for i in range(n)]

shell_sort(B, n)
print(cnt)
[print(B[i]) for i in range(n)]


Measured memory_bytes: 54856
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,m,s,x;
map<int,int> q;
long long ans;
int main(){
	scanf("%d%d",&n,&m);
	q[0]=1;
	fo(i,1,n){
		scanf("%d",&x);
		s=(s+x)%m;
		if (q.count(s)) ans+=q[s];
		q[s]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<long long> A(N,0);
    long long sum_=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        sum_+=A[i];
    }

    long long ans=100000000000;
    long long tmp=0;
    for(int i=0; i<N; i++){
        tmp+=2*A[i];
        ans=min(abs(sum_-tmp),ans);
    }
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[5005][5005];
const int mod=998244353;
int32_t main(){
	int a, b, c, d; cin>>a>>b>>c>>d;
	dp[a][b]=1;
	for(int i=a; i<=c; i++) for(int j=b; j<=d; j++) if(!(i==a && j==b)){
		dp[i][j]=(dp[i-1][j]*j+dp[i][j-1]*i+mod-dp[i-1][j-1]*(i-1)*(j-1))%mod;
      	if(dp[i][j]<0) dp[i][j]+=mod;
    }
	cout<<dp[c][d]<<endl;
	return 0;
}

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

int main()
{
    string str;
    cin >> str;
    int first = str.find('A');
    int last = str.find('C');
    if ((first >= 0) && ((first + 1) == last))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if(a > b){
			int x;
			x = a;
			a = b;
			b = x;
		}

		if(b > c){
			int x;
			x = b;
			b = c;
			c = x;
		}

		if(a > b){
			int x;
			x = a;
			a = b;
			b = x;
		}

		System.out.println(a + " " + b + " " + c);
	}
}

Measured memory_bytes: 26292
def solve():
    s = ''.join(reversed(input()))
    words = [''.join(reversed(substr)) for substr in ["dream", "dreamer", "erase", "eraser"]]
    while True:
        word = [w for w in words if s.startswith(w)]
        if word:
            s = s[len(word[0]):]
            if not s:
                return "YES"
        else:
            return "NO"


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3956
# https://atcoder.jp/contests/keyence2020/tasks/keyence2020_c

n, k, s = map(int, input().split())
if s == 10 ** 9:
    ans = [1] * n
    for i in range(k):
        ans[i] = s
else:
    ans = [s + 1] * n
    for i in range(k):
        ans[i] = s
print(*ans)

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

int main()
{
	char c;
	cin >> c;

	switch( c )
	{
		case 'A':
			cout << 'T' << endl;
			break;
		case 'C':
			cout << 'G' << endl;
			break;
		case 'T':
			cout << 'A' << endl;
			break;
		case 'G':
			cout << 'C' << endl;
			break;
		default:
			break;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ; 
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
//template<class C> min(C x,C y){ if(x>y) return y ; return x ; } 
//template<class C> max(C x,C y){ if(x>y) return x ; return y ; } 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main() 
{
	int n ; cin>>n ; //, k ; cin>>n>>k ; 
	cout<<n*n*n<<endl;	
}

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

using namespace std;

bool isacgt(char c)
{
  return (   c == 'A' 
          || c == 'C'
          || c == 'G'
          || c == 'T' );
}

int main()
{
  string s; cin >> s;
  int maxlen = 0;
  int len = 0;
  for (int i = 0; i < s.size(); i++)
  {
    if (isacgt(s[i])) len++;
    else len = 0;
    maxlen = max(len, maxlen);
  }
  cout << maxlen << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
typedef struct{
  char suit;
    int value;
}Card;
void bubble(Card A[],int N){
  int i,j;
  Card t;
  for(i=0;i<N;i++){
    for(j=N-1;j>=i+1;j--){
      if(A[j].value<A[j-1].value){
	t=A[j];
	A[j]=A[j-1];
	A[j-1]=t;
      }
    }
  }
}

void selection(Card A[],int N){
  int i,j,minj;
  Card t;
  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j].value<A[minj].value)minj=j;
    }
    t=A[i];
    A[i]=A[minj];
    A[minj]=t;
  }
}

void print(Card A[],int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%c",A[i].suit);
    printf("%d",A[i].value);
  }
    printf("\n");
}
int flag(Card C1[],Card C2[],int N){
  int i,flag=0;
  for(i=0;i<N;i++){
    if(C1[i].suit != C2[i].suit){
      flag=1;
    }
  }
  return flag;
}

int main(){
  Card C1[100],C2[100];
  int N,i,a;
  char ch;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf(" %c",&C1[i].suit);
    scanf(" %d",&C1[i].value);
  }
  for(i=0;i<N;i++)C2[i]=C1[i];
  bubble(C1,N);
  selection(C2,N);
  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  a=flag(C1,C2,N);
  if(a==1){
      printf("Not stable\n");
  }
      else printf("Stable\n");

  return 0;
}




Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int n ; cin >> n ;
	vi a(n),b(n),c(n);
	re(a);re(b);re(c);
	sort(all(a));
	sort(all(c));
	sort(all(b));
	int ans = 0 ; 
	int ita=0,itc=0;
	rep(i,0,n){
		while(ita < n and a[ita]<b[i]) ita++;
		while(c[itc]<=b[i] and itc < n)itc++;
		ans+=ita*(n-itc);
	}
	cout << ans << endl;
}
signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 5580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int A,B,M;
    cin >> A >> B >> M;
    vector<int> a(A),b(B);
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    int ans = INF;
    rep(i,M){
        int x,y,c;
        cin >> x >> y >> c;
        chmin(ans,a[x-1] + b[y-1] - c);
    }
    sort(all(a));
    sort(all(b));
    chmin(ans,a[0] + b[0]);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 1E+05;

int A, B, C, D, E, F;

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

    cin >> A >> B >> C >> D >> E >> F;

    int sg = 0;
    int wt = A;
    double maxd = 0;
    for (int c0 = 0; c0 <= F / (100 * A); c0++) {
        for (int f = F % 100; f <= F; f += 100) {
            if (((F - f) / 100 - A * c0) % B == 0) {
                int c1 = ((F - f) / 100 - A * c0) / B;
                for (int d = 0; d <= f; d++) {
                    for (int c3 = 0; c3 <= d / C; c3++) {
                        if ((d - c3 * C) % D == 0) {
                            int c4 = (d - c3 * C) / D;
                            int w = A * c0 + B * c1;
                            int s = c3 * C + c4 * D;
                            if (s <= w * E && double(s) / double(100 * w + s) > maxd) {
                                //cout << "maxd = " << maxd << "\n";
                                maxd = double(s) / double(100 * w + s);
                                //cout << "newmaxd = " << maxd << "\n";
                                sg = s;
                                wt = w;
                            }
                        }
                    }
                }
            }
        }
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << 100 * wt + sg << " " << sg << "\n";

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>

#ifdef DEBUG
#include "libs/debug.cpp"
#define DEBUG 1
#else
#define DEBUG 0
#endif

#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()

using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
template<typename T>
using optional = boost::optional<T>;
const auto none = boost::none;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

int main() {
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (DEBUG) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll N;
  cin >> N;
  vector<ll> A;
  rep (i, N) {
    ll v0;
    cin >> v0;
    A.push_back(v0);
  }

  ll prev = -1;
  ll ans = 0;
  each (a, A) {
    if (a == prev) {
      ans += 1;
      prev = -1;
    } else {
      prev = a;
    }
  }
  cout << ans << "\n";

}

Measured memory_bytes: 380
#!/usr/bin/env python3
import sys

MOD = 2019  # type: int

def solve(L: int, R: int):
    if L == 0:
        L = 1
    res = float('inf')
    for i in range(L,R):
        for j in range(i+1,R+1):
            res = min(res,(i*j)%MOD)
            if res == 0:
                break
        if res == 0:
            break
    print(res)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(L, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#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;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n;
ll dp[3003][3003][2], a[3003];

ll calc (int l, int r, int t) {
   if (l > r) return 0;
   ll &res = dp[l][r][t];
   if (res != -1) return res;   
   if (t) res = min (calc (l, r - 1, (t ^ 1)) - a[r], calc (l + 1, r, (t ^ 1)) - a[l]);
   else res = max (calc (l, r - 1, (t ^ 1)) + a[r], calc (l + 1, r, (t ^ 1)) + a[l]);  
   return res;
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   memset (dp, -1, sizeof dp);
   cout << calc (1, n, 0);
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 141440
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> Type igcd(Type x,Type y){return (y==0)?x:igcd(y,x%y);}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n,k;
	cin>>n>>k;
	
	int num=1;
	int cnt=0;
	while(num<=n){
		num*=k;
		cnt++;
	}
	
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
def myAnswer(N:int, txy:list) -> str:
   prex = 0
   prey = 0
   pret = 0
   for t,x,y in txy:
      xy =abs(x - prex)+abs(y - prey)
      if(xy > (t -pret) or  xy % 2 != (t - pret) % 2):
         return "No"
      else:
         prex = x
         prey = y
         pret = t
   return "Yes"

def modelAnswer():
   return
def main():
   N = int(input())
   txy = []
   for _ in range(N):
      txy.append(list(map(int,input().split())))
   print(myAnswer(N,txy[:]))
if __name__ == '__main__':
   main()

Measured memory_bytes: 28092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
int main(){
	int n,k,s;
	cin>>n>>k;
	s=k;
	for(int i=2;i<=n;i++){
		s*=(k-1);
	}
	cout<<s;
	return 0;
}

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

int N, P[3], T[8], ans = 1145141919;

void solve(int n, int a, int b, int c, int tmp){
    if(n == N){
        if(a && b && c){
            int cost = tmp + abs(a - P[0]) + abs(b - P[1]) + abs(c - P[2]);
            ans = min(ans, cost);
        }
        return;
    }
    solve(n + 1, a, b, c, tmp);
    solve(n + 1, a + T[n], b, c, tmp + (a?10:0));
    solve(n + 1, a, b + T[n], c, tmp + (b?10:0));
    solve(n + 1, a, b, c + T[n], tmp + (c?10:0));    
}

int main(){
    cin >> N;
    for(int i = 0; i < 3; i++)cin >> P[i];
    for(int i = 0; i < N; i++)cin >> T[i];
    solve(0, 0, 0, 0, 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
int main() {
	char s[200010];
	char t[200010];
	char c1, c2;
	cin >> s;
	cin >> t;
	for (int i = 0;s[i] != '\0';i++) {
		if (s[i] != t[i]) {
			c1 = s[i];
			c2 = t[i];
			for (int j = 0;j < i;j++) {
				if (s[j] == s[i] || s[j] == t[i]) {
					cout << "No" << endl;
					return 0;
				}
			}
			for (int j = i;s[j] != '\0';j++) {
				if (s[j] == c1) {
					s[j] = c2;
				}
				else if (s[j] == c2) {
					s[j] = c1;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, M;
	cin >> N >> M;

	cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int a, b;
 
    scanf("%d%d", &a, &b);
    if (a < b) printf("a < b\n");
    else if (a > b) printf("a > b\n");
    else printf("a == b\n");
    return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    vector<ll> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    vector<ll> vec_copy(N);
    rep(i,N){
        vec_copy[i] = max(vec[i], -1 * vec[i]);
    }
    sort(all(vec_copy));
    int count = 0;
    rep(i,N){
        if (vec[i] <= 0) count++;
    }
    ll ans = 0;
    if (count % 2 == 0){
        rep(i,N){
            ans += vec_copy[i];
        }
    }
    else{
        ans += vec_copy[0] * -1;
        rep(i,N - 1){
            ans += vec_copy[i + 1];
        }
    }
    cout << ans << endl;
}



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

int main()
{
	int N, K;
	cin >> N >> K;
	map<int, int> countMap;
	rep(i, N) {
		int a;
		cin >> a;
		countMap[a] = countMap[a] + 1;
	}
	vector<int> countList(countMap.size());
	for (auto c : countMap) {
		countList.push_back(c.second);
	}
	sort(countList.begin(), countList.end());
	int len = countList.size() - K;
	int ans = 0;
	rep(i, len) {
		ans += countList[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11248
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
a = LIST()

ave = sum(a)/N

b = [abs(x-ave) for x in a]

ans = b.index(min(b))
print(ans)


Measured memory_bytes: 5204
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string str;
int main(void)
{
  while(cin >> str){
    int J = 0,I = 0;
    for(int i = 0; i < (int)str.size()-2; i++){
      string s = str.substr(i,3);
      if(s == "JOI"){
	J++;
	i++;
      }else if(s == "IOI"){
	I++;
	i++;
      }
    }
    cout << J << endl << I << endl;
  }
}

Measured memory_bytes: 1212
n, k = gets.split.map(&:to_i)
edge = Array.new(n+1){[]}
(n-1).times do
    a, b = gets.split.map(&:to_i)
    edge[a] << b
    edge[b] << a
end

m = 10 ** 9 + 7

stack = [[1, 0, 0]]
ans = 1
while x = stack.pop
    now, par, s = x
    ans = ans * (k - s) % m

    i = par == 0 ? 1 : 2
    edge[now].each do |y|
        next if y == par
        stack << [y, now, i]
        i += 1
    end
end

puts ans

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

int main(int argc, char const *argv[])
{
	int n, a, b; cin >> n >> a >> b;
	cout << min(n * a, b) << endl;
	return 0;
}


Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

i = 0

while True:
	if i % 2 == 0:
		C -= B
		if C <= 0:
			print('Yes')
			exit(0)
	else:
		A -= D
		if A <= 0:
			print('No')
			exit(0)
	i += 1


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

int main(void){
    
  int A,B,K,s;
  cin >> A >> B >> K;
  s = B - A + 1;
  
  if(s <= 2*K)  for(int i=A;i<=B;i++){ cout << i << endl; }
  else{
      for(int i=A;i<(A+K);i++) cout << i << endl;
      for(int i=(B-K+1);i<=B;i++) cout << i << endl;
  }
}

Measured memory_bytes: 3600
#include<iostream>
#include <string>
#include <stdio.h>
#include <math.h>
using namespace std;

int main()
{
    string N;

    cin >> N;

    int length = N.length();

    char num = N[length-1];

    switch(num){
        case '0' :
            cout << "pon" << endl;
            break;
        case '1' :
            cout << "pon" << endl;
            break;
        case '2' :
            cout << "hon" << endl;
            break;
        case '3' :
            cout << "bon" << endl;
            break;
        case '4' :
            cout << "hon" << endl;
            break;
        case '5' :
            cout << "hon" << endl;
            break;
        case '6' :
            cout << "pon" << endl;
            break;
        case '7' :
            cout << "hon" << endl;
            break;
        case '8' :
            cout << "pon" << endl;
            break;
        case '9' :
            cout << "hon" << endl;
            break;
    }

    return 0;
}

Measured memory_bytes: 3036
/***** author :  C0d1ngPhenomena *****/

#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define TestCases int T; cin>>T; while(T--)
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define revrep(i,a,b) for(ll i = b-1; i >= a; i--)
#define vll vector<ll>
#define vvll vector < vll >
#define pll pair<ll, ll>
#define vpll vector <pll>
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define alld(c) c.begin(),c.end(),greater<int>()
#define mem(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
#define pb push_back
using namespace std;

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

	ll N, X, T;
	cin >> N >> X >> T;
	ll k = 1;

	while (1)
	{
		ll sum = X * k;
		if (N > sum)
			k++;
		else
			break;
	}

	cout << k * T;

	return 0;
}







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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<ll> a(N);
    REP(i,N){
        cin >> a[i];
    }

    REP(i,N-1){
        a[i+1] += a[i];
    }
    ll ans = 1e15;
    REP(i,N-1){
        ans = min(ans, abs(a[N-1]-a[i]-a[i]));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s="keyence";
  string t;
  cin>>t;
  int n=t.size();
  for(int i=0;i<8;i++){
    string a,b;
    a=t.substr(0,7-i);
    b=t.substr(n-i,i);
    if(a==s.substr(0,7-i)&&b==s.substr(7-i,i)){
      cout<<"YES"<<endl;
      return 0;
    }
    //cout<<a<<b<< " "<<s.substr(0,7-i)<<" "<<s.substr(7-i,i)<<endl;
  }
  cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 3568