akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int M, T, P, R;
    while(cin >> M >> T >> P >> R, M){
        vector< pair< pair<int, int>, int> > data(T);
        for(int i = 0 ; i < T ; i++){
            data[i].second = -i;
        }
        vector< vector< pair<bool, int> > > solved(T, vector< pair<bool, int> >(P));
        for(int i = 0 ; i < R ; i++){
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--;
            p--;
            if(j == 0){
                data[t].first.first--;
                data[t].first.second += solved[t][p].second + m;
                solved[t][p].first = true;
            }else if(!solved[t][p].first){
                solved[t][p].second += 20;
            }
        }

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

        string ans = to_string(-data[0].second + 1);
        for(int i = 1 ; i < T ; i++){
            if(data[i].first == data[i - 1].first){
                ans.push_back('=');
            }else{
                ans.push_back(',');
            }
            ans += to_string(-data[i].second + 1);
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3252
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);
    char[] input;
    char[] iwistr = { 'i', 'w', '(', ')' };
    int INF = 1 << 28;
    int min = INF;

    void run() {
        solve(0, sc.next().toCharArray(), 0);
        System.out.println(min);
    }

    void solve(int n, char[] str, int cost) {
        if (cost >= min) {
            return;
        }
        if (n == str.length) {
            if (isSymmetry(str)) {
                min = cost;
            }
            return;
        }
        for (int i = 0; i < 4; i++) {
            char[] nstr = Arrays.copyOf(str, str.length);
            nstr[n] = iwistr[i];
            solve(n + 1, nstr, cost + (str[n] == nstr[n] ? 0 : 1));
        }
    }

    boolean isSymmetry(char[] str) {
        for (int i = 0; i < str.length / 2; i++) {
            int init = i;
            int tail = str.length - 1 - i;
            if (str[init] == '(' && str[tail] == ')') {
                continue;
            }
            if (str[init] == ')' && str[tail] == '(') {
                continue;
            }
            if (str[init] != str[tail] || str[init] == '(' || str[init] == ')') {
                return false;
            }
        }
        if (str.length % 2 == 1
                && (str[str.length / 2] == '(' || str[str.length / 2] == ')'))
            return false;
        return true;
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
using namespace std;
static const ll max_n = 100010;

vector<ll> primes(max_n);
vector<bool> is_prime(max_n, true);

ll sieve(ll N){
    fill(is_prime.begin(), is_prime.end(), true);
    is_prime[0] = false;
    is_prime[1] = false;
    ll num_p=0;
    for(ll i=2;i<N;i++){
        if(is_prime[i]){
            primes[num_p++] = i;
            for(ll j=2*i;j<N;j+=i){
                is_prime[j] = false;
            }
        }
    }
    return num_p;
}

int main(){
    ll Q, l, r, c, gcd_num;
    scanf("%lld", &Q);
    vector<ll> cum_sum(max_n, 0);
    sieve(max_n);
    cum_sum[0] = 0;
    cum_sum[1] = 0;
    cum_sum[2] = 0;
    for(ll i=3;i<=max_n;i+=2){
        bool is_ok = (is_prime[i] && is_prime[(i+1)/2]);
        cum_sum[i] = ((ll)is_ok + cum_sum[i-2]);
        cum_sum[i+1] = cum_sum[i];
        // printf("cum sum[%lld] = %lld\n", i, cum_sum[i]);
    }
    vector<ll> answers;
    for(ll i=0;i<Q;i++){
        scanf("%lld %lld", &l, &r);
        ll ans = cum_sum[r] - cum_sum[l-1];
        answers.push_back(ans);
    }

    for(auto ans:answers){
        printf("%lld\n", ans);
    }

    // printf("%lld\n", sieve(N));
    return 0;
}

Measured memory_bytes: 3064
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    L, R, d = map(int, input().split())
    count = 0
    for k in range(L, R + 1):
        if k % d == 0:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 65216
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define sec second
#define fir first
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
 
int main(){
	ll n;
	cin>>n;
	if(n%1000==0) cout<<0;
	else{
		cout<<((n/1000) + 1)*1000 - n;
	}
	
}
		 

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    for (int& i : p) cin >> i;
    sort(p.begin(), p.end());
    int r = 0;
    for (int i = 0; i < k; ++i) r += p[i];
    cout << r;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int x[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> x[i];
    int sol = 1e9;
    for (int i = 1; i <= 100; ++i)
    {
        int sum = 0;
        for (int j = 0; j < n; ++j)
            sum += (x[j] - i) * (x[j] -i);
        sol = min(sol, sum);
    }
    cout << sol;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring> 
#include<cstdio>
#include<set>
#define MN 100000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
multiset<int> s[MN+5];multiset<int>::iterator it;
int n,f[MN+5],head[MN+5],cnt,ans,flag,mid,rt,d[MN+5];
struct edge{int to,next;}e[MN*2+5];
inline void ins(int f,int t)
{
	e[++cnt]=(edge){t,head[f]};head[f]=cnt;++d[f];
	e[++cnt]=(edge){f,head[t]};head[t]=cnt;++d[t];
}
void dfs(int x,int fa)
{
	s[x].clear();f[x]=0;
	for(int i=head[x];i;i=e[i].next)
		if(e[i].to!=fa) dfs(e[i].to,x),s[x].insert(f[e[i].to]+1);
	int has=0,has2=0,size=s[x].size();
	if(!size) ++ans;ans-=(size-1)/2;
	if(s[x].size()&&(*(--(it=s[x].end())))>mid) return(void)(flag=0);
	while(!s[x].empty())
	{
		it=s[x].end();--it;
		int v=*it;s[x].erase(it);
		it=s[x].upper_bound(mid-v);
		if(it==s[x].begin())
		{
			if(!has) has=v,f[x]=has;
			else if(~size&1)
			{
				if(!has2) has2=v,f[x]=has2;
				else return(void)(flag=0);
			}
			else return (void)(flag=0);
		}
		else s[x].erase(--it);
	}
}
int main()
{
	n=read();
	for(int i=1;i<n;++i) ins(read(),read());
	int l=1,r=n,res,Ans;
	for(rt=1;~d[rt]&1;++rt);
	while(l<=r)
	{
		mid=l+r>>1;ans=0;flag=1;
		dfs(rt,0);
		//cout<<"Solve"<<mid<<" ok "<<flag<<endl;
		if(flag) res=mid,r=mid-1,Ans=ans;
		else l=mid+1;
	}
	printf("%d %d",Ans,res);
	return 0;
}

Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3010;
const ll p=1000000007;
ll fp(ll a,ll b)
{
	ll s=1;
	for(;b;b>>=1,a=a*a%p)
		if(b&1)
			s=s*a%p;
	return s;
}
const ll inv2=fp(2,p-2);
int a[N];
int n,q;
ll f[N][N];
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(a[i]<a[j])
				f[i][j]=1;
	int x,y;
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d",&x,&y);
		f[x][y]=f[y][x]=(f[x][y]+f[y][x])*inv2%p;
		for(int j=1;j<=n;j++)
			if(j!=x&&j!=y)
			{
				f[x][j]=f[y][j]=(f[x][j]+f[y][j])*inv2%p;
				f[j][x]=f[j][y]=(f[j][x]+f[j][y])*inv2%p;
			}
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)
			ans=(ans+f[i][j])%p;
	ans=ans*fp(2,q)%p;
	ans=(ans%p+p)%p;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 70784
#include<iostream>

using namespace std;

#define MAX 500000
#define N 2000000000

int L[MAX/2+2],R[MAX/2+2];
int tmp;

void marge(int A[],int n,int l,int mid,int r){
  int n1=mid-l;
  int n2=r-mid;

  for(int i=0;i<n1;i++) L[i]=A[l+i];
  for(int i=0;i<n2;i++) R[i]=A[mid+i];

  L[n1]=R[n2]=N;
  int i=0,j=0;

  for(int k=l;k<r;k++){
    tmp++;
    if(L[i]<=R[j]){
      A[k]=L[i++];
    }else{
      A[k]=R[j++];
    }
  }
}

void sort(int A[],int n,int l,int r) {
  if(l+1<r){
    int mid=(l+r)/2;
    sort(A,n,l,mid);
    sort(A,n,mid,r);
    marge(A,n,l,mid,r);
  }
}

int  main() {
int A[MAX],n,i;
tmp=0;

cin >>n;

for( i=0;i<n;i++) cin >> A[i];

sort(A,n,0,n);

for (i=0;i<n;i++) {
 if(i) cout << " ";
 cout << A[i];
}
cout << endl;

cout << tmp << endl;
  return 0;
}



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

int main(void) {
  ll N;
  cin >> N;
  ll A[2][N + 1];
  A[0][0] = A[1][0] = 0;
  REP(i, 0, 2) REP(j, 1, N + 1) cin >> A[i][j];

  REP(i, 0, 2) REP(j, 1, N + 1) A[i][j] += A[i][j - 1];

  ll ans = 0;
  REP(i, 0, N) {
    ll x = (A[0][i + 1] - A[0][0]);
    ll y = (A[1][N] - A[1][i]);
    ans = max(ans, x + y);
  }
  cout << ans << endl;
}


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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int count = 0;
	int plus = 0;
	cin >> count >> plus;
	
	int boad = 1;
	for (int i = 0; i < count; ++i) {
		if (boad < plus) {
			boad *= 2;
		} else {
			boad += plus;
		}
	}
	cout << boad << endl;
	return 0;
}


Measured memory_bytes: 888
N = gets.to_i
A = gets.split.map(&:to_i)
count = 0
0.upto(N-1) do |i|
  minj = i
  i.upto(N-1) do |j|
    if A[j] < A[minj]
      minj = j
    end
  end
  A[i],A[minj] = A[minj],A[i]
  count += 1 if minj != i
end
puts A.join(" ")
puts count

Measured memory_bytes: 6108
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int[] p = new int[n];
      	int counter = 0;
      	for(int i = 0; i < n ; i ++){
        	p[i] = scan.nextInt();
        }
      	for(int j = 0; j < n-2; j++){
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         }
      	System.out.print(counter);
    }

}

Measured memory_bytes: 21844
n,d=map(int,input().split())
xList=[list(map(int,input().split()))for i in range(n)]
ans=0;temp=0
for i in range(0,n):
    for j in range(i+1,n):
        for k in range(d):
            temp+=(xList[i][k]-xList[j][k])**2
        temp**=0.5
        if temp==int(temp):
            ans+=1
        temp=0
print(ans)


Measured memory_bytes: 3060
MOD = 10 ** 9 + 7
n, k = map(int, input().split())
ans = 0
for x in range(k, n + 2):
    p = x * (x - 1) // 2
    q = x * (x - 1) // 2 + (n - x + 1) * x
    ans += q - p + 1
print(ans % MOD)


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int a[100];

signed main()
{
    int n,cur=1000,s=0;
    cin>>n;
    for(int i=0;i<n;++i)cin>>a[i];
    a[n]=-1;
    for(int i=0;i<n;++i)
    {
        if(a[i+1]>a[i])
        {
            s+=cur/a[i];
            cur%=a[i];
        }
        else
        {
            cur+=s*a[i];
            s=0;

        }
    }
    cout<<cur<<endl;
    return 0;
}


Measured memory_bytes: 3540
#include <cstdio>

inline int read()
{
    register int x = 0;
    register char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return x;
}

int main()
{
    register int n, i;
    scanf("%d", &n);
    for (register int i = 1, x; i <= n; i++)
        if (!((x = read()) & 1) && x % 3 && x % 5)
        {
            printf("DENIED\n");
            return 0;
        }
    printf("APPROVED\n");
}

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

#define MAX_L 3000

int dp[MAX_L + 1][MAX_L + 1];
std::pair<int, int> hist[MAX_L + 1][MAX_L + 1];

int main() {
  std::string s, t;
  int ls, lt;

  std::cin >> s >> t;
  ls = (int) s.size();
  lt = (int) t.size();

  hist[0][0] = std::make_pair(0, 0);
  for(int i = 0; i < ls; ++i) {
    for(int j = 0; j < lt; ++j) {
      if(s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
        hist[i + 1][j + 1] = std::make_pair(i, j);
      } else {
        dp[i + 1][j + 1] = std::max(dp[i + 1][j], dp[i][j + 1]);
        if(dp[i + 1][j + 1] == dp[i + 1][j]) hist[i + 1][j + 1] = std::make_pair(i + 1, j);
        else hist[i + 1][j + 1] = std::make_pair(i, j + 1);
      }
    }
  }

  std::string ans = "";
  int i = ls, j = lt;
  while(i > 0 && j > 0) {
    if(s[i - 1] == t[j - 1]) ans = s[i - 1] + ans;
    auto p = hist[i][j];
    i = p.first, j = p.second;
  }

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

Measured memory_bytes: 105728
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  bool flag = false;
  if (s == "hi" ||
      s == "hihi" ||
      s == "hihihi" ||
      s == "hihihihi" ||
      s == "hihihihihi") {
    flag = true;
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define int long long
#define mod 1000000007

int dp[100001];

int solve1(int* a, int n, int k) {
	int i, j;
	for (i = 1; i <= k; i++) {
		int flg = 0;
		for (j = 0; j < n; j++) {
			if (i >= a[j]) {
				if (dp[i - a[j]] == 0)flg = 1;
			}
			if (flg == 1)break;
		}
		dp[i] = flg;
	}

	return dp[k];
}

void solve() {
	int n;
	cin >> n;
	int k;
	cin >> k;
	int a[n];
	int i;
	for (i = 0; i < n; i++)cin >> a[i];
	memset(dp, -1, sizeof(dp));
	dp[0] = 0;

	int len = solve1(a, n, k);
	if (len == 1)cout << "First" << endl;
	else cout << "Second" << endl;

	return;
}


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

Measured memory_bytes: 4416
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long  ll;
const long long maxt=1e18;
int main()
{
	ll n,a[100005],b,ans=1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
		{
			cout<<0;
			return 0;
		}
	}
	for(int i=0;i<n;i++)
	{
		if((maxt/ans)<a[i])
		{
			cout<<-1;
			return 0;
		}
		ans*=a[i];
		
	}
	cout<<ans;
}

Measured memory_bytes: 4304
#include <bits/stdc++.h>
using namespace std;
int mincol = 0;

map <pair<int,int>, int > edge;

void color_edges(vector<vector<int> > arr)
{
    vector <int> pcolor(arr.size()+1, -1);
    pcolor[1] = 0;
    queue <int> q;
    q.push(1);
    while(!q.empty()){
        int col = 1;
        int v = q.front();
        q.pop();

        for(int i=0;i<arr[v].size();i++){
            int u = arr[v][i];
            if(pcolor[u] != -1){
                continue;
            }
            if(col == pcolor[v]){
                col++;

            }
            pcolor[u] = edge[{v, u}] = edge[{u, v}] = col++;
            q.push(u);
        }
    }
}

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

    int n;
    cin >> n;
    vector<vector<int>> arr(n+1);
    vector<pair<int,int> > input;

    for(int i=0;i<n-1;i++){
        int a, b;
        cin >> a >> b;
        input.push_back({a, b});
        arr[a].push_back(b);
        arr[b].push_back(a);

        mincol = max(mincol,(int)max(arr[a].size(), arr[b].size()));
    }

    cout << mincol << '\n';

    color_edges(arr);

    for(int i=0;i<input.size();i++){
       cout <<  edge[{input[i].first, input[i].second}] << '\n';
    }
    return 0;
}


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



ll W,H;
ll inv_6;

ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll gcd(ll x,ll y){

	x = abs(x);
	y = abs(y);

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

ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}


ll numC3(ll num){

	if(num <= 2)return 0;

	ll ret = num;

	ret *= num-1;
	ret %= MOD;
	ret *= num-2;
	ret %= MOD;
	ret *= inv_6;
	ret %= MOD;

	return ret;
}

//https://betrue12.hateblo.jp/entry/2020/05/02/163444

int main(){

	inv_6 = mod_inverse(6,MOD);

	scanf("%lld %lld",&W,&H);

	ll N = (W+1)*(H+1);
	ll mult = mod_pow(2,N-3,MOD);

	ll base = numC3(N);

	ll minus = 0;

	for(ll i = 0; i <= H; i++){
		for(ll k = 0; k <= W; k++){
			if(i ==0 && k == 0)continue;

			ll tmp = (H+1-i)*(W+1-k);
			tmp %= MOD;

			if(i > 0 && k > 0){
				tmp *= 2;
				tmp %= MOD;
			}

			tmp *= gcd(i,k)-1;
			tmp %= MOD;

			minus += tmp;
			minus %= MOD;
		}
	}

	base -= minus;
	if(base < 0){

		base += MOD;
	}

	ll ans = base*mult;
	ans %= MOD;

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 3228
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { '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' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	return !b ? a : gcd(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		//printf("%d ", 2);
//		aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			//printf("%d ", i);
			//aa.insert(i);
			n /= i;
		}
	}
	if (n > 2){
		//printf("%d ", n);
	//	aa.insert(n);
	};
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
const int N = 105;
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n, m;
	cin >> n >> m;
	char s[N][N];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> s[i][j];
	for (int i = 0; i < n; i++)
	{
		bool ok = 0;
		for (int j = 0; j < m; j++)
		{
			if (s[i][j] != '.')
			{
				ok |= 1;
				break;
			}
		}
		if (!ok)
		{
			for (int idx = 0; idx < m; idx++)
				s[i][idx] = '-';
		}
	}
	for (int i = 0; i < m; i++) {
		bool ok = 0;
		for (int j = 0; j < n; j++)
		{
			if (s[j][i] == '.' || s[j][i] == '-')
				continue;
			else {
				ok |= 1; break;
			}
		}
		if (!ok)
		{
			for (int idx = 0; idx < n; idx++)
				s[idx][i] = '-';
		}
	}
	for (int i = 0; i < n; i++)
	{
		bool ok = 0;
		for (int j = 0; j < m; j++)
		{
			if (s[i][j] != '-')
				cout << s[i][j],ok|=1;
		}
		if(ok)
			cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
main(){
  int N,M;
  cin>>N>>M;
  M/=2;
  int n_pairs0=min(N,M);
  N-=n_pairs0;
  M-=n_pairs0;
  if(N>=M){
    cout<<n_pairs0<<endl;
    return 0;
  }
  M+=N;
  int n_pairs1=M/2;
  cout<<n_pairs0+n_pairs1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  Sieve sieve(55555);
  int cnt = 0;
  for (int i = 11; i <= 55555; ++i) {
    if (sieve.isPrime(i) && i % 5 == 1) {
      cout << i << " ";
      cnt++;
    }
    if (cnt == n) break;
  }
  cout << endl;
  return 0;
}

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

int main() {
    int K, X;
    cin >> K >> X;
    if(500 * K >= X){
        cout << "Yes";
    }else
    cout << "No";
}

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

int main() {
  int a,b;

  scanf("%d %d",&a,&b);
  while( a!=0 || b!=0) {
      for(int i=0;i<a;i++)
      {
          for(int j=0;j<b;j++)
          {
              cout << "#";
          }
          cout << endl;
      }
      cout << endl;
      scanf("%d %d",&a,&b);
  }

  return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	string str("0123456789");
	int n;
	while(cin>>n){
		if(n==0) break;
		string s;
		int a[n][2];
		for(int i=0;i<n;i++){
			a[i][0]=0;
			a[i][1]=0;
			cin>>s;
			for(int j=0;j<10;j++){
				if(s[0]==str[j]){
					a[i][0]=a[i][0]+60*60*10*j;
				}
				if(s[1]==str[j]){
					a[i][0]=a[i][0]+60*60*j;
				}
				if(s[3]==str[j]){
					a[i][0]=a[i][0]+60*10*j;
				}
				if(s[4]==str[j]){
					a[i][0]=a[i][0]+60*j;
				}
				if(s[6]==str[j]){
					a[i][0]=a[i][0]+10*j;
				}
				if(s[7]==str[j]){
					a[i][0]=a[i][0]+j;
				}
			}
			cin>>s;
			for(int j=0;j<10;j++){
				if(s[0]==str[j]){
					a[i][1]=a[i][1]+60*60*10*j;
				}
				if(s[1]==str[j]){
					a[i][1]=a[i][1]+60*60*j;
				}
				if(s[3]==str[j]){
					a[i][1]=a[i][1]+60*10*j;
				}
				if(s[4]==str[j]){
					a[i][1]=a[i][1]+60*j;
				}
				if(s[6]==str[j]){
					a[i][1]=a[i][1]+10*j;
				}
				if(s[7]==str[j]){
					a[i][1]=a[i][1]+j;
				}
			}
		}
		int ct=0,iru=0;
		for(int i=0;i<86400;i++){
			for(int j=0;j<n;j++){
				if(a[j][0]==i){
					ct++;
				}
				else if(a[j][1]==i){
					ct--;
				}
			}
			iru=max(iru,ct);
		}
		cout<<iru<<endl;
	}
    return 0;
}

Measured memory_bytes: 1292
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

long long pow_mod(long long x, long long n, long long mod_num) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) { res = (res * x) % mod_num; }
        x = (x * x) % mod_num;
        n = (n >> 1);
    }
    return res;
}

int one_bit_at(const int loc) {
    return 1 << (loc - 1);
}

bool is_bit_at(const int bit, const int loc) {
    return (bit & one_bit_at(loc)) > 0;
}

const int MAX_N = 50;
const int MAX_X = 5;
const int MAX_Y = 7;
const int MAX_Z = 5;

const int MASK = 0b11111111111111111;

long long dp[MAX_N][MASK+1];

const long long MOD = 1000000007;

int N, X, Y, Z;

int push(int base, int num) {
    base = (base << num) + one_bit_at(num);
    return base & MASK;
}

bool can_make(int bit) {
    return is_bit_at(bit, Z) && is_bit_at(bit, Y + Z) && is_bit_at(bit, X + Y + Z);
}

int main(int argc, char **argv) {
    std::cin >> N >> X >> Y >> Z;

    for (int n = 0; n <= N; n++) {
        for (int bit = 0; bit <= MASK; bit++) {
            dp[n][bit] = 0;
        }
    }

    dp[0][0] = 1;

    for (int n = 1; n <= N; n++) {
        for (int bit = 0; bit <= MASK; bit++) {
            for (int i = 1; i <= 10 ; i++) {
                if (!can_make(push(bit, i))) {
                    dp[n][push(bit, i)] = (dp[n][push(bit, i)] + dp[n-1][bit]) % MOD;
                }
            }
        }
    }

    long long total = pow_mod(10, N, MOD);
    long long tmp = 0;
    for (int bit = 0; bit <= MASK; bit++) {
        tmp = (tmp + dp[N][bit]) % MOD;
    }

    std::cout << (total - tmp + MOD) % MOD << std::endl;

    return 0;

}


Measured memory_bytes: 43264
#include<stdio.h>
 
int main(){
	
	int N, K;
	scanf("%d %d", &N, &K);
	int score[N];
	for(int i=0;i<N;i++){
		scanf("%d", &score[i]);
	}
	for(int i=K;i<N;i++){
		if(score[i-K]<score[i]){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2436
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
int main(){
	string a,b,c;
	cin >> a >> b >> c;
	if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
import math
import itertools

N = int(input())

xy = [list(map(int, input().split())) for _ in range(N)]



route = itertools.permutations([i for i in range(N)], N)
cnt = 0

for r in route:
    for i in range(N-1):
        xi = xy[r[i]][0]
        xj = xy[r[i+1]][0]
        yi = xy[r[i]][1]
        yj = xy[r[i+1]][1]
        cnt += math.sqrt((xi-xj)**2 + (yi-yj)**2)

print(cnt/math.factorial(N))


Measured memory_bytes: 3188
N = input()
le = len(N)
N = int(N)
ans = 0
L = ['3', '5', '7']


def clear(n):
    global ans

    if len(n) > le:
        return
    if ('3' in n) and ('5' in n) and ('7' in n) and int(n) <= N:
        ans += 1

    for l in L:
        n = n + l
        clear(n)
        n = n[:-1]


clear('')
print(ans)

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


using namespace std;
using ll = long long;
using ull = unsigned long long;


#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

int main() {
	int n;
	cin >> n;
	int stop = 0;
	vector<int> di;
	int i = 1;
	while (true) {
	
		stop = pow(2, i);

		di.push_back(stop);
		i += 1;
		if (stop >= 100)break;
	}

	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}


	rep(i, 0, di.size()) {
		if (n < di[i]) {
			cout << di[i - 1] << endl;
			break;
		}
	}



	return 0;
}



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

typedef pair<int,int> P;
typedef pair<int,P> P2;

int main(){
	int n,m,t,s,d;
	P2 p[20010];
	bool v[20010];
	
	while(cin >> n >> m && (n||m)){
		for(int i=1;i<=n;i++)v[i] = false;
		v[1] = true;
		
		for(int i=0;i<m;i++){
			cin >> t >> s >> d;
			p[i] = P2(t,P(s,d));
		}
		
		sort(p,p+m);
		
		for(int i=0;i<m;i++){
			P infe = p[i].second;
			if(v[infe.first])v[infe.second] = true;
		}
		
		int ans = 0;
		for(int i=1;i<=n;i++)
			if(v[i])ans++;
		cout << ans << endl;
	}
}

Measured memory_bytes: 1124
def algae(r: int, D: int, x2000: int)->int:
    x = x2000

    res = []
    for _ in range(10):
        x = r*x - D
        res.append(x)

    return res


if __name__ == "__main__":
    r, D, x2000 = map(int, input().split())

    for ans in algae(r, D, x2000):
        print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

string S;
 
void solve()
{
  int res = 0;
  forn (i, S.size()) {
    if (S[i] == '+') ++res;
    else --res;
  }
  cout << res << endl;
}

int main(void)
{
  cin >> S;
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val a, b, c = sc.nextInt()
    if (a == b && b == c && a % 2 == 1) {
      println(0)
    } else if (a == b && b == c && a % 2 == 0) {
      println(-1)
    } else {
      println(f(a, b, c))
    }
  }

  def f(a: Int, b: Int, c: Int): Int = {
    if (!Array(a, b, c).forall(m => m % 2 == 0)) {
      0
    } else {
      1 + f((b + c) / 2, (a + c) / 2, (a + b) / 2)
    }
  }
}


Measured memory_bytes: 25668
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstdio>
#include<map>
#include<set>
#include<queue>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

int main(){

    ll n;
    cin >> n;
    if(n == 3 || n == 5 || n == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }



    return 0;
}

Measured memory_bytes: 256
s = input()
c = 0
first, second = s[:len(s)//2], s[(len(s)+1)//2:]
if first == reversed(second):
    print(c)
else:
    for x in range(len(first)):
        if first[x] != second[len(second)-x-1]:
            c += 1
    print(c)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//
template <typename T>
vector<T> dijkstra(vector<vector<pair<ll, T>>> &G, ll start){
    using P = pair<T, ll>;
    const T inf = numeric_limits<T>::max();
    ll N = G.size();
    vector<T> dist(N, inf);
    vector<ll> route(N, -1);
    priority_queue<P, vector<P>, greater<P>> pq;
    dist[start] = 0;

    pq.emplace(dist[start], start);
    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        T c;ll from;
        tie(c, from) = p;
        if (dist[from] < c) continue;
        for(auto& e:G[from]){
            ll to;T cost;
            tie(to,cost) = e;
            if(dist[to]>dist[from]+cost){
                dist[to] = dist[from] + cost;
                route[to] = from;
                pq.emplace(dist[to], to);
            }
        }
    }
    // 各頂点までの最小コスト
    return dist;
    // 始点から各頂点へのルート
    // return route;
}

int main() {
    init();
    ll N,M;
    cin >> N >> M;
    vvc<pair<ll,ll>> G(N*3);
    rep(i,M){
        ll u, v;
        cin >> u >> v;
        u--, v--;
        G[u * 3].eb(v * 3 + 1,1);
        // G[v * 3 + 1].eb(u * 3,1);
        G[u * 3 + 1].eb(v * 3 + 2,1);
        // G[v * 3 + 2].eb(u * 3 + 1,1);
        G[u * 3 + 2].eb(v * 3,1);
        // G[v * 3].eb(u * 3 + 2,1);
    }
    ll S,T;
    cin >> S >> T;
    S--, T--;

    vl dist = dijkstra(G, S * 3);
    cout << ((dist[T*3]>=INF)?-1:dist[T * 3] / 3) << endl;
}

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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

ll N, K;
vector<ll> A;
vector<ll> path;
set<ll> used;

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

    cin >> N >> K;
    A.resize(N);
    REP(i, N) {
        int d; cin >> d;
        d--;
        A.at(i) = d;
    }

    ll dst = 0;

    while (used.count(dst) == 0) {
        used.insert(dst);
        path.push_back(dst);
        dst = A[dst];
    }

    ll s = find(ALL(path), dst) - path.begin();
    ll r = path.size() - s;

    if (K < s) {
        cout << path.at(K) + 1 << endl;
    } else {
        cout << path.at((K - s) % r + s) + 1 << endl;
    }

    return 0;

}

Measured memory_bytes: 15360
A, B = map(int, input().split())

if (A == 1) and (B != 1):
    print("Alice")

elif (A != 1) and (B != 1) and (A > B):
    print("Alice")

elif (B == 1) and (A != 1):
    print("Bob")

elif (B != 1) and (A != 1) and (A < B):
    print("Bob")

elif (A == B):
    print("Draw")


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

int main() {
    string s,t;
    std::cin >> s>>t;
    ll cnt = 0;
    for (int i = 0; i < 3; i++) {
        if( s[i] == t[i]){
            cnt++;
        }
    }
    std::cout << cnt << std::endl;
}


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            int Fans = 0;
            int Sans = 0;
            for (int i = 0; i < 2; i++)
            {
                
                if (i==0)//010101010...
                {
                    bool kuro = true;
                    for (int j = 0; j < s.Length; j++)
                    {
                        if (kuro)
                        {
                            if (s[j] == '1')
                            {
                                Fans++;
                            }
                            kuro = false;
                        }
                        else
                        {
                            if (s[j] == '0')
                            {
                                Fans++;
                            }
                            kuro = true;
                        }
                    }
                }
                else if (i == 1)//101010101...
                {
                    bool shiro = true;
                    for (int j = 0; j < s.Length; j++)
                    {
                        if (shiro)
                        {
                            if (s[j] == '0')
                            {
                                Sans++;
                            }
                            shiro = false;
                        }
                        else
                        {
                            if (s[j] == '1')
                            {
                                Sans++;
                            }
                            shiro = true;
                        }
                    }
                }
            }
            WriteLine(Min(Fans, Sans));
        }
    }
}


Measured memory_bytes: 13116
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e7 + 5;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

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

ll cnt[N];
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        ll n,ans=0ll;
        cin>>n;
        for(int i=1; i<=n; ++i) {
            for(int j=i; j<=n; j+=i) {
                cnt[j]++;
            }
        }
        for(ll i=1ll; i<=n; ++i) {
            ans+=i*cnt[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 81736
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
Y,Z=0,0
V,W=0,0
T,U=0,0
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  Y,Z=-1,-10**20
  V,W=Y,Z
  T,U=V,W
  for j in range(26):
    if Y==-1:
      Y,Z=0,X[0]+S[i][0]
    if Z<X[j]+S[i][j]:
      T,U=V,W
      V,W=Y,Z
      Y,Z=j,X[j]+S[i][j]
    elif W<X[j]+S[i][j]:
      T,U=V,W
      V,W=j,X[j]+S[i][j]
    elif U<X[j]+S[i][j]:
      T,U=j,X[j]+S[i][j]
  XX[Y]-=X[Y]
  X[Y]=0
  P.append([Y,V,T])
  if randrange(0,50)==0:
    P[i][1]=randrange(0,26)
  if randrange(0,5)==0:
    P[i][2]=randrange(0,26)
  P[i]=tuple(P[i])
SCORE=0
X=[0]*26
for i in range(D):
  SCORE+=S[i][P[i][0]]
  for j in range(26):
    X[j]+=C[j]
  X[P[i][0]]=0
  SCORE-=sum(X)
SCORE2=0
YY=[]
for i in range(D):
  for k in range(2):
    d,q=i,P[i][k+1]
    SCORE2=SCORE
    YY=XX[:]
    SCORE2-=S[d][P[d][0]]
    SCORE2+=S[d][q]
    for j in range(26):
      X[j]=0
    YY[P[d][0]],YY[q]=0,0
    for j in range(D):
      if j==d:
        Z=q
      else:
        Z=P[j][0]
      X[P[d][0]]+=C[P[d][0]]
      X[q]+=C[q]
      X[Z]=0
      YY[P[d][0]]+=X[P[d][0]]
      YY[q]+=X[q]
    if SCORE2-sum(YY)>SCORE-sum(XX):
      z=[P[i][k+1]]
      for l in range(3):
        if l!=k:
          z.append(P[i][l])
      P[i]=tuple(z)
      XX=YY[:]
      SCORE=SCORE2
for i in range(D):
  print(P[i][0]+1)

Measured memory_bytes: 84996
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  double l;
  cin >> l;

  double a = l / 3;
  cout << a * a * a << endl;
}

Measured memory_bytes: 3804
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
    int a,b;
    cin >> a >> b;
    int ans = 0;
    for (int i = a;i <= b;i++){
        string s;
        s = to_string(i);
        if (s[0] != s[4] || s[1] != s[3] ) continue;
        ans++;
    }
    cout << ans << endl;

    
    
    return 0;
}

Measured memory_bytes: 256
/**
 *  author: nayakashutosh9
 *	[2020-09-22 19:29]
**/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define modd 998244353
#define inf 1e18
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> pbds;
const int N = 300005;
/*******************************************************/

struct cmp {
	bool operator()(pii a, pii b) {
		if (a.ff == b.ff) return a.ss < b.ss;
		return a.ff > b.ff;
	}
};
int n;
vector<pii> a;
int dp[2005][2005];
int check(int i, int p, int q) {
	if (i == n) return 0;
	if (dp[p][q] != -1) return dp[p][q];
	int cur = 0;
	cur = max(cur, a[i].ff * abs(a[i].ss - p) + check(i + 1, p + 1, q));
	cur = max(cur, a[i].ff * abs(q - a[i].ss) + check(i + 1, p, q - 1));
	return dp[p][q] = cur;
}
void solve() {
	cin >> n;
	a.clear(); a.resize(n);
	for (int i = 0; i < n; i++) cin >> a[i].ff, a[i].ss = i;
	sort(all(a), cmp());
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) dp[i][j] = -1;
	}
	cout << check(0, 0, n - 1) << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int T = 1;
	// cin >> T; cin.ignore();
	for (int i = 1; i <= T; i++) {
		// cout << "Case #" << i << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 35188
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int N;
  string S;
  cin>>N>>S;
  int count=0;
  rep(i,N-2) {
if((S.at(i)=='A') &&(S.at(i+1)=='B')&& (S.at(i+2)=='C')) {
  count++;
}
  }
    cout << count<< endl;
}


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

int main(){
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<char>> c(h, vector<char>(w, '.'));
	rep(i, h) rep(j, w) cin >> c[i][j];
	
	int ans = 0;
	for(int i = 0; i < (1 << h); ++i){
		for(int j = 0; j < (1 << w); ++j){
			int count = 0;
			for(int si = 0; si < h; ++si){
				for(int sj = 0; sj < w; ++sj){
					bool bsi = 0 == ((i >> si) & 1);
					bool bsj = 0 == ((j >> sj) & 1);
					if(bsi && bsj && ('#' == c[si][sj])){
						count++;
					}
				}
			}
			if(count == k){
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}



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

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

    int a,b;
    cin>>a>>b;

    int n=0;
    int cnt=1;

    while(cnt<b)
    {
        cnt+=a-1;
        n++;
    }

    cout<<n<<"\n";

    return 0;
}


Measured memory_bytes: 3620