akhauriyash/Code-Regression huggingface dataset:
s = input()
l = 0
r = len(s)-1
res = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x' and s[r] != 'x':
        res += 1
        l += 1
    elif s[l] != 'x' and s[r] == 'x':
        res += 1
        r -= 1
    elif s[l] != s[r] and s[l] != 'x' and s[r] != 'x':
        print(-1)
        exit()
print(res)

Measured memory_bytes: 3316
from collections import deque
N,*L = map(int, open(0).read().split())
A = L[:N]
B = L[N:]
q = deque()
for i in range(N):
  x,y,z = (i-1)%N,i%N,(i+1)%N
  if A[y]>=A[x]+A[z]>0:
    q.append(y)
a = 0
while q:
  y = q.pop()
  x,z = (y-1)%N,(y+1)%N
  if A[x]+A[z]==0:
    continue
  a += A[y]//(A[x]+A[z])
  A[y] = A[y]%(A[x]+A[z])
  s = (x-1)%N
  if A[x]>=A[s]+A[y]:
    q.append(x)
  t = (z+1)%N
  if A[z]>=A[y]+A[t]:
    q.append(z)
q = deque()
for i in range(N):
  x,y,z = (i-1)%N,i%N,(i+1)%N
  if B[y]>=B[x]+B[z]>0:
    q.append(y)
b = 0
while q:
  y = q.pop()
  x,z = (y-1)%N,(y+1)%N
  if B[x]+B[z]==0:
    continue
  b += B[y]//(B[x]+B[z])
  B[y] = B[y]%(B[x]+B[z])
  s = (x-1)%N
  if B[x]>=B[s]+B[y]:
    q.append(x)
  t = (z+1)%N
  if B[z]>=B[y]+B[t]:
    q.append(z)
if A==B and b>=a:
  print(b-a)
else:
  print(-1)


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

int main() {
  int N,M,n,m;cin>>N>>M;
   for (int i=1;i<N;i++){
   n += i;}
   for (int j=1;j<M;j++){
   m += j;}
   cout<<n+m<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <algorithm>
#include <math.h>
#include <iostream>
using namespace std;
#define maxint 0x7fffffff
int dis[1000010],neg[1000010],pos[1000010];
int main()
{
	int n,k;
	cin>>n>>k;
	int i,j;
	int num=0,sum=0;
	for(i=1;i<=n;i++)
	{
		cin>>dis[i];
		if(dis[i]<0)
			neg[++num]=abs(dis[i]);
		else
			pos[++sum]=dis[i]; 
	}
	int ans=maxint;
	for(i=0;i<=k;i++)
	{
		/*if(i==3)
			cout<<"u";*/
		int temp=k-i;
		if(num>=i && temp<=sum)
			if(neg[num-i+1]<pos[temp])
				ans=min(neg[num-i+1]*2+pos[temp],ans);
			else
				ans=min(neg[num-i+1]+pos[temp]*2,ans); 
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8576
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	long long a,b;
	cin>>a>>b;
	int x;
	if (a==0 || b==0 || a<0 && b>0){
		cout<<"Zero"<<endl;
	}else if (a<0 && b<0){
		if ( (b - a + 1)%2==0){
			cout<<"Positive"<<endl;
		}else{
			cout<<"Negative"<<endl;
		}
	}else if(a>0 &&b>0){
		cout<<"Positive"<<endl;
	}
	return 0;
}

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

int main(void)
{
    int H, W;
    cin >> H >> W;
    string s;
    char c;
    vector<vector<int>> dpr(H, vector<int>(W));
    vector<vector<int>> dpl(H, vector<int>(W));
    vector<vector<int>> dpu(H, vector<int>(W));
    vector<vector<int>> dpd(H, vector<int>(W));
    vector<vector<bool>> dp(H, vector<bool>(W));
    for(int i=0;i<H;i++){
        cin >> s;
        for(int j=0;j<W;j++){
            c = s.at(j);
            if(c == '#'){
                dp.at(i).at(j) = false;
            }else{
                dp.at(i).at(j) = true;
            }
        }
    }
    // right
    for(int i=0;i<H;i++){
        if(dp.at(i).at(W-1)){
            dpr.at(i).at(W-1) = 1;
        }else{
            dpr.at(i).at(W-1) = 0;
        }
        for(int j=W-2;j>=0;j--){
            if(dp.at(i).at(j)){
                dpr.at(i).at(j) = dpr.at(i).at(j+1) + 1;
            }else{
                dpr.at(i).at(j) = 0;
            }
        }
    }
    // rleft
    for(int i=0;i<H;i++){
        if(dp.at(i).at(0)){
            dpl.at(i).at(0) = 1;
        }else{
            dpl.at(i).at(0) = 0;
        }
        for(int j=1;j<W;j++){
            if(dp.at(i).at(j)){
                dpl.at(i).at(j) = dpl.at(i).at(j-1) + 1;
            }else{
                dpl.at(i).at(j) = 0;
            }
        }
    }
    // up 
    for(int i=0;i<W;i++){
        if(dp.at(0).at(i)){
            dpu.at(0).at(i) = 1;
        }else{
            dpu.at(0).at(i) = 0;
        }
        for(int j=1;j<H;j++){
            if(dp.at(j).at(i)){
                dpu.at(j).at(i) = dpu.at(j-1).at(i) + 1;
            }else{
                dpu.at(j).at(i) = 0;
            }
        }
    }
    // down
    for(int i=0;i<W;i++){
        if(dp.at(H-1).at(i)){
            dpd.at(H-1).at(i) = 1;
        }else{
            dpd.at(H-1).at(i) = 0;
        }
        for(int j=H-2;j>=0;j--){
            if(dp.at(j).at(i)){
                dpd.at(j).at(i) = dpd.at(j+1).at(i) + 1;
            }else{
                dpd.at(j).at(i) = 0;
            }
        }
    }
    int max_number = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            max_number = max(max_number, dpr.at(i).at(j)+dpl.at(i).at(j)+dpu.at(i).at(j)+dpd.at(i).at(j)-3);
            // cout << dpd.at(i).at(j) << ", ";
        }
        // cout << endl;
    }
    cout << max_number;
    return 0;
}

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

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

int sum(int x) {
	int ret=0;
	while(x)
		ret+=x%10, x/=10;
	return ret;
}

int eval(int a, int b) {
	return sum(a)+sum(b);
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	int ret=1e9;
	for (int a=1; a<n; a++)
		ret=min(ret,eval(a,n-a));
	cout << ret << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    repi2(h, 1, 3500) {
        repi2(n, 1, 3500) {
            if((4 * h * n - N * n - N * h) > 0) {
                ll w = N * h * n / (4 * h * n - N * n - N * h);
                if(w < 0) continue;
                ll shi = n * h * w;
                ll bo = w * n + h * w + h * n;
                if(shi * 4 == bo * N) {
                    cout << h << ' ' << w <<  ' ' << n << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3624
#!/usr/bin/env python
a, b, c, x, y = map(int, input().split())
if a + b <= 2*c:
    ans = a*x+b*y
else:
    ans = 2 * c * min(x, y)
    if x >= y:
        add = min(a*(x-y), 2 * c * (x-y))
        ans += add
    else:
        add = min(b*(y-x), 2 * c * (y-x))
        ans += add

print(ans)

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,k;
  cin >> n >> k;
  ll ans = n - k;
  if(k==1) ans = 0;
  cout << ans<< endl;
  return 0;
}


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

typedef long long lli;

const int M = 5000001;
const int P = M/10;

lli C[128];
lli X[M];

lli convert(const char s[]) {
  lli j = 0;
  for(lli i = 0; s[i] != '\0'; ++i) {
    j |= C[s[i]]<<(i*3LL);
  }
  return j;
}

void insert(const char s[]) {
  int x = convert(s);
  int p = x%M;
  while(X[p] != -1LL) p = (p+P)%M;
  X[p] = x;
}

bool find(const char s[]) {
  int x = convert(s);
  int p = x%M;
  while(X[p] != -1LL) {
    if(X[p] == x) return true;
    p = (p+P)%M;
  }
  return false;
}

int main() {
  int n;
  char s[100];
  C['A'] = 1LL;
  C['C'] = 2LL;
  C['G'] = 3LL;
  C['T'] = 4LL;
  fill(X,X+M, -1LL);
  scanf("%d", &n);
  while(n--) {
    scanf("%s", s);
    if(s[0] == 'f') {
      scanf("%s", s);
      if(find(s))
        printf("yes\n");
      else
        printf("no\n");
    } else {
      scanf("%s", s);
      insert(s);
    }
  }
  return 0;
}

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

#define N 1000

int main(){
  int top=0;
  char stack[N];
  int S[N];
  int g;

  while(scanf("%s",stack)!=EOF){
    if(top >=  N - 1) top--;
    
    if(stack[0] == '+'){
      S[top-2] = S[top-2] + S[top-1];
      //printf("%d\n",S[top-2]);
      top = top - 1; 
    }

    else if(stack[0] == '-'){
      S[top-2] = S[top-2] - S[top-1];
      top = top - 1;
    }

    else if(stack[0] == '*'){
      S[top-2] = S[top-2] * S[top-1];
      top = top - 1;
    }

    else{
      S[top] = atoi(stack);
      top++;
    }

  }

  
  printf("%d",S[0]);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2736
def main():
    N, M, K=map(int, input().split())
    friend_or_block = [0] * N
    parent = [-1] * N

    def root(x):
        p, s = parent[x], list()
        while p >= 0:
            s.append(x)
            x, p = p, parent[p]
        for c in s: parent[c] = x
        return x

    def same(x, y): return root(x) == root(y)

    def count(x): return -parent[root(x)]

    def unite(x, y):
        xr, yr = root(x), root(y)
        if xr == yr: return
        if parent[xr] > parent[yr]: xr, yr = yr, xr
        parent[xr] += parent[yr]
        parent[yr] = xr

    for _ in range(M):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        unite(a, b)
        friend_or_block[a] += 1
        friend_or_block[b] += 1

    for _ in range(K):
        c, d = map(int, input().split())
        c, d = c-1, d-1
        if same(c, d):
            friend_or_block[c] += 1
            friend_or_block[d] += 1

    print(*[count(i) - friend_or_block[i] - 1 for i in range(N)])

if __name__ == '__main__':
    main()



Measured memory_bytes: 74248
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




int main(){
    int a,b,c;cin >> a >> b >> c;
    int k;cin >> k;
    int cnt = 0;
    while(a >= b){
        cnt++;
        b *= 2;
    }
    while(b >= c){
        cnt++;
        c *= 2;
    }
    if(cnt > k) puts("No");
    else puts("Yes");
    return 0;
}


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

int main(void)
{
    int N;
    cin >> N;

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

    sort(d, d+N, greater<int>());

    int count = 1;
    for (int i = 0; i < N-1; i++) {
        if (d[i] > d[i+1])
            count++;
    }
    cout << count << endl;
}


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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

int main() {
  string s;
  ll k;
  cin >> s >> k;
  --k;
  char res = '1';
  ll n = s.size();
  rep(i,min(n,k+1)){
    if(s[i]!='1'){
      res = s[i];
      break;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 3636
import math

input_num = int(input())
input_numline = list(map(int,input().split(' ')))
q = int(input())

op_list = []
for i in range(q):
    op_list.append(list(map(int,input().split(' '))))

maxnum = 100000

num_list = [0 for m in range(maxnum+1)]

for n in input_numline:
    num_list[n] += 1

ans = 0

for j in range(maxnum+1):
    ans += j*num_list[j]

for o in op_list:
    ans -= o[0]*num_list[o[0]]
    ans += o[1]*num_list[o[0]]
    num_list[o[1]] += num_list[o[0]]
    num_list[o[0]] = 0

    print(ans)


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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long d = sc.nextInt();
    int ans = 0;

    for (int cnt = 0; cnt < n; cnt++) {
      long x = sc.nextInt();
      long y = sc.nextInt();
      if (d * d >= x * x + y * y) {
        ans++;
      }
    }
    System.out.println(ans);
    sc.close();
  }
}


Measured memory_bytes: 59660
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=1e18,MOD=1e9+7,MAXN=1e6+2;

int spf[MAXN];

void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)

        spf[i] = i;

    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (int j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}

set<int> getFactorization(int x)
{
    set<int> ret;
    while (x != 1)
    {
        ret.insert(spf[x]);
        x = x / spf[x];
    }
    return ret;
}


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n;
    cin>>n;
    int a[n];
    lp(i,0,n)
        cin>>a[i];
    sieve();
    int freq[MAXN]={};
    bool flag=0;
    lp(i,0,n){
        set<int>s=getFactorization(a[i]);
        for(auto j:s){
            freq[j]++;
            if(freq[j]>1)
                flag=1;
        }
    }
    if(!flag)
        return cout<<"pairwise coprime",0;
    int g=0;
    lp(i,0,n)
        g=__gcd(g,a[i]);
    if(g==1)
        cout<<"setwise coprime";
    else
        cout<<"not coprime";
}

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

int main()
{
  int n, k;
  int d[200];
  int a[200][200];
  cin >> n >> k;
  for (int i = 0; i < k; i++)
  {
    cin >> d[i];
    for (int j = 0; j < d[i]; j++)
    {
      cin >> a[i][j];
    }
  }

  int ans[200] = {};
  for (int i = 0; i < k; i++)
  {
    for (int j = 0; j < d[i]; j++)
    {
      ans[a[i][j]-1] = 1;
    }
  }
  int ansn = 0;
  for (int i = 0; i < n; i++)
  {
    if (ans[i] == 0)
    {
      ansn++;
    }
  }
  cout << ansn << endl;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var UF = new UnionFind(H * W);
		int[] dx = new int[]{0,1,0,-1};
		int[] dy = new int[]{1,0,-1,0};
		
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(S[i][j] == '#') UF.b[i * W + j]++;
				if(S[i][j] == '.') UF.w[i * W + j]++;
			}
		}
		
		
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				for(int t=0;t<4;t++){
					int ny = i + dy[t];
					int nx = j + dx[t];
					if(!InRange(ny, 0, H) || !InRange(nx, 0, W)) continue;
					if(S[i][j] != S[ny][nx]) UF.Unite(i * W + j, ny * W + nx);
				}
			}
		}
		
		long tot = 0;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(!UF.IsRoot(i * W + j)) continue;
				tot += (long) UF.b[i * W + j] * (long) UF.w[i * W + j];
			}
		}
		Console.WriteLine(tot);
		
		
		
	}
	
	bool InRange(int t, int l, int r){
		return l <= t && t < r;
	}
	
	int H,W;
	String[] S;
	public Sol(){
		var d = ria();
		H = d[0]; W = d[1];
		S = new String[H];
		for(int i=0;i<H;i++) S[i] = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}



class UnionFind{
	
	int[] parent;
	int[] mem;
	int compo;
	int N;
	public int[] b;
	public int[] w;
	public UnionFind(int n_){
		Initialize(n_);
	}
	
	public void Initialize(int n_){
		N=n_;
		parent=new int[N];
		mem=new int[N];
		for(int i=0;i<N;i++){
			parent[i]=i;
			mem[i]=1;
		}
		compo=N;
		b = new int[N];
		w = new int[N];
	}
	
	public int Parent(int a){
		if(parent[a]==a) return a;
		return parent[a] = Parent(parent[a]);
	}
	
	public bool IsUnited(int a,int b){
		return Parent(a) == Parent(b);
	}
	
	public void Unite(int a,int b){
		a = Parent(a); b = Parent(b);
		if(a == b) return;
		if(mem[a] <= mem[b]){
			parent[a] = b;
			mem[b] += mem[a];
			this.b[b] += this.b[a];
			this.w[b] += this.w[a];
			compo -= 1;
		} else {
			parent[b] = a;
			mem[a] += mem[b];
			compo -= 1;
			this.b[a] += this.b[b];
			this.w[a] += this.w[b];
		}
	}
	
	public bool IsRoot(int x){
		return x == parent[x];
	}
	public int MemCnt(int x){
		return mem[Parent(x)];
	}
	
	public void Dump(){
		for(int i=0;i<parent.Length;i++){
			Console.Write(i==0?"{0}":" {0}",parent[i]);
		}
		Console.WriteLine("");
	}
	
	public int Compo{
		get{
			return compo;
		}
	}
	
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

long long X, Y;
int main() {
    std::cin >> X >> Y;

    long long i = 1;
    while(X <= Y) {
        X = (X << 1);
        ++i;
    }
    std::cout << i-1 << std::endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

const (
	initialBufSize = 10000
	maxBufSize     = 10000000
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	return sc
}()

func scanIntNums() (nums []int) {
	sc.Scan()
	numString := strings.Split(sc.Text(), " ")

	nums = make([]int, len(numString))
	var err error

	for i := 0; i < len(nums); i++ {
		nums[i], err = strconv.Atoi(numString[i])
		if err != nil {
			panic(err)
		}
	}
	return nums
}

func main() {
	inputs := scanIntNums()
	K := inputs[0]
	N := inputs[1]

	distances := scanIntNums()

	var dist int
	max := K - distances[N-1] + distances[0]
	for i := 0; i < N-1; i++ {
		dist = distances[i+1] - distances[i]
		if max < dist {
			max = dist
		}
	}

	fmt.Println(K - max)
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	string s, t;
	cin >> s >> t;
	string ss = s + s;

	int sLen = s.size();
	int tLen = t.size();

	// 探索
	int curLoops = 0;
	int curPos = -1; // 0文字目に対応できるよう最初だけ-1
	int chPos;
	REP(idx, tLen) {
		if (curPos == -1) {
			chPos = (int)ss.find(t[idx]);
		} else {
			chPos = (int)ss.find(t[idx], curPos + 1);
		}
		if (chPos < 0) {
			// 解なし
			cout << "-1" << endl;
			return 0;
		}

		curPos = chPos;
		if (curPos >= sLen) {
			curPos -= sLen;
			++curLoops;
		}
	}

	long answer = (long)curLoops * sLen + curPos + 1L;

	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,w;
	scanf("%d %d %d %d %d",&a,&s,&d,&f,&g);
	if(a<40){
	a=40;
	}
	if(s<40){
	s=40;
	}
	if(d<40){
	d=40;
	}
	if(f<40){
	f=40;
	}
	if(g<40){
	g=40;
	}	
	w=(a+s+d+f+g)/5;
	printf("%d\n",w);
	return 0;
}	

Measured memory_bytes: 1024
//#i#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}
using namespace std;

const ll ST =  LLONG_MAX / 4;
ll n, k;

ll comp(ll mi, ll now) {
	if (now > 0 && mi >= 0) return mi / now;
	if (now > 0 && mi < 0) return (mi - now + 1) / now;
	if (now < 0 && mi <= 0) return (mi+now+1) / now;
	if (now < 0 && mi > 0) return mi/ now;
	return 0;
}

int main() {
	cin >> n >> k;
	vector<ll> da(n);
	rip(i, n, 0) cin >> da[i];
	sort(all(da));
	vector<ll> ad = da;
	reverse(all(ad));
	ll ok = ST, ng = -ST;
	while (ok - ng > 1) {
		ll mi = (ok + ng) / 2;
		ll co = 0;
		rip(i, n, 0) {
			if (da[i] > 0) {
				ll gg = upper_bound(da.begin(), da.end(), comp(mi, da[i])) - da.begin();
				if (gg > i) gg--;
				co += gg;
			}
			else if (da[i] < 0) {
				ll gg = da.end() - lower_bound(da.begin(), da.end(), comp(mi, da[i]));
				if (gg + i >= n) gg--;
				co += gg;
			}
			else {
				if (mi >= 0) co += n - 1;
			}
		}
		co /= 2;
		if (co >= k)ok = mi;
		else ng = mi;
	}
	cout << ok << endl;
}

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

using namespace std;

typedef long long ll;

const int MAXN = 100005;

int n, a[MAXN], b[MAXN];

int vis[MAXN], path[MAXN];

ll ans = LLONG_MAX;
vector<int> way;

void dfs(int depth) {
  if(depth > n) {
    path[depth] = path[1];
    ll cost = 0;
    for(int i = 1; i <= n; i++) {
      cost += min(a[path[i]], b[path[i + 1]]);
    }
    if(cost < ans) {
      ans = cost;
      way.clear();
      for(int i = 1; i <= n + 1; i++) {
        way.push_back(path[i]);
      }
    }
  } else {
    for(int i = 1; i <= n; i++) {
      if(!vis[i]) {
        vis[i] = 1;
        path[depth] = i;
        dfs(depth + 1);
        vis[i] = 0;
      }
    }
  }
}


void brute() {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i], &b[i]);
  }
  dfs(1);
  printf("%lld\n", ans);
  for(auto t: way) {
    printf("%d ", t);
  }
  puts("");
}

int main() {
  scanf("%d", &n);
  ll costA = 0, costB = 0;
  vector<pair<int, int> > v;
  for(int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i], &b[i]);
    v.push_back({a[i], i});
    v.push_back({b[i], i});
    costA += a[i];
    costB += b[i];
  }
  ans = min(costA, costB);
  sort(v.begin(), v.end());
  map<int, int> M;
  ll tot = 0;
  for(int i = 0; i < n - 2; i++) {
    ++M[v[i].first];
    tot += v[i].first;
  }
  for(int i = 1; i <= n; i++) {
    ll cost = a[i] + b[i];
    int A = 0, B = 0;
    if(M[a[i]]) --M[a[i]], A = 1;
    if(M[b[i]]) --M[b[i]], B = 1;
    ll newTot = tot;
    if(A) newTot -= a[i], ++M[a[i]];
    if(B) newTot -= b[i], ++M[b[i]];
    int cur = n - 2;
    while(A + B) {
      if(v[cur].second == i) {
        ++cur;
        continue;
      }
      newTot += v[cur].first;
      --A, ++cur;
    }
    cost += newTot;
    ans = min(ans, cost);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 12016
#include<stdio.h>
int main(){
    int n,m,i,j;
    int a[100][100],b[100],c[100]={0};
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
            }}
    for(i=0;i<m;i++){
        scanf("%d",&b[i]);}
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){ 
            c[i]+=a[i][j]*b[j];    }
            printf("%d\n",c[i]);  }
    return 0;}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf=10000000005;
int n,f[5005][5005];
struct O{int h,p;}a[6000];
bool cmp(O a,O b){
	return a.h+a.p<b.h+b.p;
}
signed main(){
	scanf("%lld",&n);
	for (int i=1;i<=n;++i) scanf("%lld%lld",&a[i].h,&a[i].p);
	sort(a+1,a+n+1,cmp);
	for (int i=0;i<=n;++i)
	for (int j=0;j<=n;++j) f[i][j]=inf;
	f[0][0]=0;
	for (int i=0;i<n;++i)
	for (int j=0;j<=n;++j)
	if (f[i][j]<inf){
		f[i+1][j]=min(f[i+1][j],f[i][j]);
		if (f[i][j]<=a[i+1].h)
		f[i+1][j+1]=min(f[i+1][j+1],min(inf,f[i][j]+a[i+1].p));
	}
	for (int j=n;~j;--j)
		if (f[n][j]<inf) {printf("%lld\n",j); return 0;}
	return 0;
}

Measured memory_bytes: 195840
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin>>x;
    if(x>=400&& x<=999)
    {
        if(x>=400&&x<=599)
        {
            cout<<"8";
        }
        else if(x>=600&&x<=799)
        {
            cout<<"7";
        }
        else
            cout<<"6";
    }

    else if (x>=1000 && x<=1799)
    {
        if(x>=1000&&x<=1199)
        {
            cout<<"5";
        }
        else if(x>=1200&&x<=1599)
        {
            if(x>=1200&&x<=1399)
            {
                cout<<"4";
            }
            else if(x>=1400&&x<=1599)
            {
                cout<<"3";
            }
        }
        else
            cout<<"2";
    }
    else
        cout<<"1";



}


Measured memory_bytes: 3592
import math
A,B,H,M = map(int,input().split())
l=(360*H/12+360/12*M/60+90)%360
s=(360*M/60+90)%360
xA=math.cos(math.radians(l))*A
yA=math.sin(math.radians(l))*A
xB=math.cos(math.radians(s))*B
yB=math.sin(math.radians(s))*B
d=math.sqrt((xB-xA)**2+(yB-yA)**2)
print(d)


Measured memory_bytes: 62540
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i=0;i<n-2;++i) {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ++ans;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    
        var sc = new Scanner(System.in);
        
        String s = sc.next();
        
        if(s.charAt(s.length()-1) == 's'){
            System.out.println(s + "es");
        }else{
            System.out.println(s + "s");
        }
    }
}

Measured memory_bytes: 38472
#include <stdio.h>

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(a<b &&b<c)
	{
		printf("Yes\n");
	}

		
	
	else
	{
		printf("No\n");
	}
	
	return 0;		
	
}


Measured memory_bytes: 2140
import sys

a = [int(i) for i in input().split()]
n = a[0]
m = a[1]

nums = [None for i in range(n)]
for i in range(m):
  a = [int(j) for j in input().split()]
  s = a[0]
  s_mod = s - 1
  c = a[1]
  if n != 1 and s_mod == 0 and c == 0:
    print(-1)
    sys.exit()
  
  if nums[s_mod] is not None and nums[s_mod] != c:
    print(-1)
    sys.exit()
    
  nums[s_mod] = c

ans = ''
for idx, i in enumerate(nums):
  if i is None:
    if idx == 0 and n != 1:
      ans += '1'
    else:
      ans += '0'
  else:
    ans += str(i)
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    string S; cin>>S;

    vector<int> nW(S.size()+1,0),nB(S.size()+1,0);
    rep(i,1,S.size()+1){
        nW.at(i)=nW.at(i-1);
        nB.at(i)=nB.at(i-1);

        if(S.at(i-1)=='.') nW.at(i)++;
        else nB.at(i)++;
    }

    int ans=INT_MAX;
    rep(i,0,S.size()+1){
        int _ans=nB.at(i)+(nW.back()-nW.at(i));
        ans=min(ans,_ans);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 2180
#include <stdio.h>

#define DATA 100

int main(void)
{
	int mid[DATA], final[DATA], add[DATA];
	int i, j, score, count = 0;

	for(i = 0;i < DATA;i++)
	{
		mid[i] = 0;
		final[i] = 0;
		add[i] = 0;
	}
	for(i = 0;i < DATA;i++)
	{
		count++;
		scanf("%d %d %d", &mid[i], &final[i], &add[i]);
		if(mid[i] + final[i] + add[i] == -3)
			break;
	}
	for(i = 0;i < count - 1;i++)
	{
		score = mid[i] + final[i];
		if((mid[i] == -1) || (final[i] == -1))
			printf("F\n");
		else if(score >= 80)
			printf("A\n");
		else if((65 <= score) && (score < 80))
			printf("B\n");
		else if((50 <= score) && (score < 65))
			printf("C\n");
		else if((30 <= score) && (score < 50))
		{
			if(add[i] >= 50)
				printf("C\n");
			else
				printf("D\n");
		}
		else if(mid[i] + final[i] + add[i] == -3)
			break;
		else if(score < 30)
			printf("F\n");
	}

	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#define intt long long 
using namespace std;
char s[1000000];
intt num,ans,id;
int main(){	
	scanf("%s",s+1);
	int n=strlen(s+1);
	id=n;
	for(int i=n;i;i--)
		if(s[i]=='B')ans+=id-i,id--;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int N, X;
    std::cin >> N >> X;

    int L;
    int D = 0, cnt = 1;
    for (int i = 0; i < N; ++i) {
        std::cin >> L;
        D += L;
        if (D <= X) {
            ++cnt;
        } else {
            break;
        }
    }
        
    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>


using namespace std;



int main()
{
    int a;
    cin>>a;
    long long x[100];
    x[0]=2;
    x[1]=1;
    for(int i=2;i<=100;i++)
    x[i]=x[i-1]+x[i-2];
    cout<<x[a];

    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int n, count=2147483647;
    bool isOdd=false;
    cin >> n;
    int N[n];
    for(int i=0; i<n ; i++){
      cin >> N[i];
      for(int j=0;not isOdd;j++){
        if (N[i]%2 == 1){
          isOdd = true;
          if(count > j) count = j;
        }
        N[i] = N[i]/2;
      }
      isOdd = false;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.

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

	void run(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		boolean[] AC=new boolean[N];
		int[] WA=new int[N];
		for(int i=0;i<M;++i){
			int p=sc.nextInt();
			--p;
			String s=sc.next();
			if(s.equals("AC")){
				AC[p]=true;
			}else{
				if(!AC[p])++WA[p];
			}
		}
		int ok=0;int ng=0;
		for(int i=0;i<AC.length;++i){
			if(AC[i]){
				++ok;
				ng+=WA[i];
			}
		}
		System.out.println(ok+" "+ng);
	}
	
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}
// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase
	

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

using namespace std;

typedef long long ll;
typedef long double ld;


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

    int k;
    cin >> k;
    string s = "ACL";
    for (int i = 1; i <= k; i++)
    {
        cout << s;
    }
    cout << "\n";
}


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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  string Sd, T;
  cin >> Sd;
  cin >> T;
  vector<string> Ss;
  bool f;
  REP(i, Sd.size() - T.size() + 1) {
    f = true;
    REP(j, T.size()) {
      if(Sd[i + j] != '?' && Sd[i + j] != T[j]) {
        f = false;
      }
    }
    if(f) {
      string S = Sd;
      REP(j, T.size()) {
        S[i + j] = T[j];
      }
      Ss.push_back(S);
    }
  }
  if(Ss.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  REP(i, Ss.size()) {
    REP(j, Ss[i].size()) {
      if(Ss[i][j] == '?') {
        Ss[i][j] = 'a';
      }
    }
  }
  sort(Ss.begin(), Ss.end());
  cout << Ss[0] << endl;
  return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N; cin >> N;
  auto f=[&](int x){int ret=0;while(x)ret+=x%10,x/=10;return ret;};
  Yes(N%f(N)==0);

    return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N, K;
int A[510];

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

	cin >> N >> K;
	int sum = 0;
	rep(i, 0, N)
	{
		cin >> A[i];
		sum += A[i];
	}

	priority_queue<int> pq;
	rep(i, 1, (int)sqrt(sum) + 1)
	{
		if (sum%i == 0)
		{
			pq.push(i);
			pq.push(sum / i);
		}
	}

	while (!pq.empty())
	{
		int v = pq.top();
		pq.pop();
		vector<int> ma;
		int l = 0, r = 0;
		rep(i, 0, N)
		{
			if (A[i] % v != 0)
			{
				ma.push_back(A[i] % v);
				r += v - ma.back();
			}
		}
		sort(all(ma));
		rep(i, 0, SZ(ma))
		{
			l += ma[i];
			r -= v - ma[i];
			if (l == r)
			{
				break;
			}
		}
		if (l != r)continue;
		if (l <= K)
		{
			cout << v << endl;
			break;
		}
	}

	return 0;
}

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

int main(){
  int N; cin >> N;
  int xy[10][2];
  for(int i=0; i<N; i++) cin >> xy[i][0] >> xy[i][1];
  double lsum=0;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      lsum+=sqrt((xy[i][0]-xy[j][0])*(xy[i][0]-xy[j][0])
                 +(xy[i][1]-xy[j][1])*(xy[i][1]-xy[j][1]));
    }
  }
  cout << setprecision(10) << lsum*2./N << endl;
}

Measured memory_bytes: 256
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N, K = map(int, input().split())
S = list(map(int, input()))

X = []
for c in S:
    if len(X) >= 1 and X[-1][0] == c:
        X[-1][1] += 1
    else:
        X.append([c, 1])

sm = [0] * (len(X) + 1)
for i in range(len(X)):
    sm[i + 1] = sm[i] + X[i][1]

ans = 0
for i in range(len(X)):
    if X[i][0] == 0:
        # X[i] ... X[i + (K - 1) * 2 + 1]
        ans = max(ans, sm[min(i + (K - 1) * 2 + 2, len(X))] - sm[i])
        pass
    else:
        # X[i] ... X[i + K * 2]
        ans = max(ans, sm[min(i + K * 2 + 1, len(X))] - sm[i])
print(ans)


Measured memory_bytes: 83160
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	int ans = 1;
	for (int i = 0; i < a; i++)ans = min(ans + b, ans * 2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define MP make_pair
const int oo = 1e9;
int n,t[100000];
int main(){_
for(int i=0;i<3;i++){ cin >> t[i] ;}
sort(t,t+3);
int ans=0;
for(int i=1;i<3;i++){
    ans+=t[i]-t[i-1];
}
cout << ans << endl ;
}


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

using namespace std;
const int maxn = 1e5 + 6;
using ll = long long;
ll n, a, b;
array<ll, maxn> health;
ll l, r;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    auto check = ([&](auto mid) -> bool {
        ll tot = 0;
        for (int i = 1; i <= n; ++i) {
            ll subDamage = mid * b;
            if (health[i] - subDamage > 0) {
                tot += ceil((double) (health[i] - subDamage) / (a - b)) + 0.1;
            }
        }
        return tot <= mid;
    });
    cin >> n >> a >> b;
    for (int i = 1; i <= n; ++i) cin >> health[i];
    l = 1, r = static_cast<ll>(1e9);
    while (l <= r) {
        ll mid = (l + r) >> 1;
        if (check(mid)) {
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    cout << l << "\n";
#ifndef ONLINE_JUDGE
    cout.flush();
#endif
}

Measured memory_bytes: 1024
#入力
N = input()
a = list(map(int, input().split()))

set_a=set(a)
cnt=[0]*(max(a)+1)
ans=0

for i in a:
    cnt[i]+=1

if len(cnt) ==1:
    print(cnt[0])

elif len(cnt)==2:
    ans= cnt[0]+cnt[1]
    print(ans)

else:
    for i in range(1,max(a)):
        ans=max(ans,cnt[i-1]+cnt[i]+cnt[i+1])
    
    print(ans)

Measured memory_bytes: 14004
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int x = Integer.parseInt(str[0]);
    int t = Integer.parseInt(str[1]);
    System.out.println(x-t>=0?x-t:0);
  }
}

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

int main(void) {
  int N;
  cin >> N;

  string s;
  cin >> s;

  for (auto &c : s) {
    c = (c - 'A' + N) % 26 + 'A';
  }

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
// ALDS_1_2_D.cpp
// Shell Sort

#include <iostream>
#include <vector>
using namespace std;

int cnt = 0;

void trace(vector<int> &A, int n)
{
	for (int i = 0; i < n; i++) {
		cout << A[i] << endl;
	}
}

void insertionSort(vector<int> &A, int n, int g)
{
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;

		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(vector<int> &A, int n)
{
	cnt = 0;
	int m = 0;
	vector<int> G;
	for (int h = 1; h <= n; h = 3 * h + 1) {
		G.push_back(h);
		m++;
	}
	cout << m << endl;
	for (int i = m - 1; i >= 0; i--) {
		insertionSort(A, n, G[i]);
		if (i < m - 1) cout << " ";
		cout << G[i];
	}
	cout << endl;
}

int main()
{
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	shellSort(A, n);
	cout << cnt << endl;
	trace(A, n);

	return 0;
}

Measured memory_bytes: 6712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
    cin >> vec.at(i);
    
  int A=0, B=0;
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i = 0; ; i+=2) {
    if (i < N)
      A += vec.at(i);
    else
      break;
    if (i+1 < N)
      B += vec.at(i+1);
    else
      break;
  }
  cout << A-B << endl;
}

Measured memory_bytes: 256
n = int(input())
x = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    x.append([i*3, 1])
l = []
y = 0
for i in range(n):
    l.append([x[i][0]+x[i][1], x[i][0]-x[i][1]])
l.sort()
z = l[0][1]
for i in range(n):
    if l[i][1] >= z:
        y += 1
        z = l[i][0]
print(y)

Measured memory_bytes: 51656
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N, K;
    cin >> N >> K;
    int res = K;
    N--;
    while (N > 0) {
        res *= K - 1;
        N--;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	int n, m;
  	cin >> n >> m;
  	cout << (n-1)*(m-1) << endl;
    return 0;
}



Measured memory_bytes: 256