akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    //printf("a=%d b=%d\n",a,b);
    int i,count=0;
    char s[5];
    for(i=a;i<=b;i++){
        sprintf(s,"%d",i);
        if(s[0]==s[4]&&s[1]==s[3]){
            count ++;
        }
        memset(s,'\0',5);
    }
    printf("%d",count);
}


Measured memory_bytes: 128
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 100005;
const long double PI = (acos(-1));
using namespace std;

int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  long double a,b,gv,v;
  cin >> a >> b >> gv;
  v = a*a*b;
  long double ans = 0;
  if(a * a * b / 2.0 <= gv)
  {
    ans = atan(2 * (a * a * b - gv) / (a * a * a));
  }
  else 
  {
    ans = PI / 2 - atan(2 * gv / (a * b * b));
  }
  cout << fixed << setprecision(10) <<  ans*(180.0)/PI << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    """
    メモ
    K=0なら，左から見て登った数を数える，grandGarden
    K>=1の時，塗る列は左右どちらかと同じ高さにする．同じ高さで何個か連なっていると面倒かも？
    左右どちらかと同じ高さにするというのは逐次的な話，1,1,1,5,4,5,1でK=3なら答えは1
    K個を無視できると考える．
    dp[x][y][k]で，x〜yまで，k個無視と考えれば遷移も含めて5乗くらいで行けそう
    =>0からスタートだけで良い，dp[x][k]で行けそう？．xのところは使っているものとする．
    =>「K回使える」よりも「使った数がいくつか」を記憶しておくほうが楽そう
    """
    N,K=MI()
    H=[0]+LI()
    N+=1
    inf=10**12
    dp=[[inf]*(N) for _ in range(N)]
    # dp[i][j]はi番目まで見て，j個の要素からなる
    dp[0][0]=0
    
    for i in range(1,N):
        for j in range(N):
            temp=inf
            for k in range(i):#どこからくるか
                temp=min(temp,dp[k][j-1]+max(0,H[i]-H[k]))
            dp[i][j]=temp
    
    ans=inf
    
    for i in range(N):
        ans=min(ans,dp[i][N-K-1])
    print(ans)

main()


Measured memory_bytes: 74316
n,x = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(n - 1):
	if a[i] + a[i + 1] > x:
		d = min(a[i + 1],a[i] + a[i + 1] - x)
		a[i + 1] -= d
		ans += d
	if a[i] > x:
		ans += a[i] - x
print(ans)

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

template<typename T>
void read(T &ans){T f = 1; char c = getchar();ans = 0;while(!isdigit(c)){if(c == '-')f = -1;c = getchar();}while( isdigit(c)){ans = ans*10 + c - '0';c = getchar();}ans *= f;}
#define int long long 
const int maxn = 1e5+5;
int n, x[maxn], v[maxn], c;
int dir1[maxn], dir2[maxn];
int mx_dir1[maxn], mx_dir2[maxn];

signed main(){
    read(n), read(c);
    for(int i = 1; i <= n; i++){
        read(x[i]), read(v[i]);
        dir1[i] = dir1[i-1] - (x[i] - x[i-1]) + v[i];
        mx_dir1[i] = max(mx_dir1[i-1], dir1[i]);
    }
    x[n+1] = c;
    for(int i = n; i >= 1; i--){
		dir2[i] = dir2[i+1] - (x[i+1] - x[i]) + v[i];
        mx_dir2[i] = max(mx_dir2[i+1], dir2[i]);
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		ans = max(ans, mx_dir1[i] + dir2[i+1] - (c - x[i+1]));
		ans = max(ans, mx_dir2[i] + dir1[i-1] - x[i-1]); 
	}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
template<class T>inline void Rd(T &x){
	x=0;char c=getchar();bool f=0;
	while(c<'0'||c>'9'){if(c=='-')f^=1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+c-'0',c=getchar();
	if(f)x=-x;
}
char S[5];
int main(){
	scanf("%s",S);
	for(int i=1;i<4;++i){
		if(S[i]==S[i-1]){
			puts("Bad");
			return 0;
		}
	}
	puts("Good");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    char sd;
    int g[26] = {};
    while(cin >>sd){
        sd = tolower(sd);
        if(isalpha(sd)){
            g[sd - 'a']++;
        }
    }
    for(int i = 0;i < 26;i++){
        printf("%c : %d\n", i+'a',g[i]);
        
    }
}


Measured memory_bytes: 3212
import sys; sys.setrecursionlimit(1000000)

n = int(input())
a = list(map(int, input().split()))
t = [0] * (n + 1)
#t[i] = a0 + ... + a(i-1)
for i in range(n):
    t[i + 1] = t[i] + a[i]

'''
前処理O(N + log mod)でN以下の階乗および階乗の逆数を計算
-> O(1)でcomb(n, k)を計算できる
'''

mod = 10 ** 9 + 7
dp_F = [0] * (n * 2) 
dp_Finv = [0] * (n * 2)
dp_inv = [0] * (n * 2)
#dp_F[i] = i!

def factorial(n):
    if dp_F[n] > 0:
        return dp_F[n]
    elif n == 0:
        dp_F[0] = 1
        return 1
    else:
        dp_F[n] = n * factorial(n - 1) % mod
        return dp_F[n]

def inverse(n):
    #modでのnの逆数
    return pow(n, mod - 2, mod)

c = factorial(n)
def f(k):
    return ((c * inverse(k)) % mod)

ans = 0
for i in range(1, n):
    ans += t[i] * (f(n - i + 1) - f(i + 1))
    ans %= mod
ans += t[n] * sum([f(i) for i in range(1, n + 1)])
ans %= mod
print(ans)

Measured memory_bytes: 137880
s=list(input())
n=len(s)
a=all([p==q for p,q in zip(s,reversed(s))])
b=all([p==q for p,q in zip(s[:(n-1)//2],reversed(s[:(n-1)//2]))])
c=all([p==q for p,q in zip(s[(n+3)//2-1:],reversed(s[(n+3)//2-1:]))])

if a and b and c:
  print('Yes')
else:
  print('No')

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   string s;
   cin>>s;
   int n = s.size(),j=0;

   rep(i,0,n){
      if(s[i] != s[s.size()-(1+i)]){
         cout<<"No\n";
         return 0;
      }
   }

   rep(i,0,(n-2)/2){
      if(s[i] != s[(n-1)/2-(1+i)]){
         cout<<"No\n";
         return 0;
      }
   }

   rep(i,(n+2)/2,n){
      if(s[i] != s[n-(1+j)]){
         cout<<"No\n";
         return 0;
      }
      ++j;
   }

   cout<<"Yes\n";
   return 0;
}

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

using namespace std;

const int maxn=1e2+5;
const int inf=(1<<21);
const int white=0;
const int gray=1;
const int black=2;

int n,m[maxn][maxn];

int prim()
{
    int u,minv;
    int d[maxn],p[maxn],color[maxn];
    for(int i=0;i<n;i++){
        d[i]=inf;
        p[i]=-1;
        color[i]=white;
    }
    d[0]=0;
    while(1){
        minv=inf;
        u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=black){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1){
            break;
        }
        color[u]=black;
        for(int v=0;v<n;v++){
            if(color[v]!=black&&m[u][v]!=inf){
                if(d[v]>m[u][v]){
                    d[v]=m[u][v];
                    p[v]=u;
                    color[v]=gray;
                }
            }
        }
    }
    int sum=0;
    for(int i=0;i<n;i++){
        if(p[i]!=-1){
            sum+=m[i][p[i]];
        }
    }
    return sum;
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int e;
            cin>>e;
            m[i][j]=(e==-1)?inf:e;
        }
    }
    cout<<prim()<<endl;
    return 0;
}
/*
5
-1 2 3 1 -1
2 -1 -1 4 -1
3 -1 -1 1 1
1 4 1 -1 3
-1 -1 1 3 -1
*/



Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define mp(x,y)          make_pair(x,y)
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define loop(n,i,a)      for(int i=a;i<n;i++)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        loop(n,i,0){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define pp               pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define intersect(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
//int m=10000009;
//int arr[100000];
#define M                   1000000007
#define mm  998244353  
//set<int> st;
signed main()
{
    fast
    int x;
    cin >> x;
    cout << x/500 * 1000 + (x - x/500 * 500) /5  * 5;
}


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

int main() {
	int s;
	cin >> s;
	int h = s / 3600;
	//int m = s / 60 - h * 60;
	int m = s % 3600 / 60;
	s = s % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


Measured memory_bytes: 3108
import numpy as np

n = int(input())
d = [int(input()) for _ in range(n)]
i0 = 101
count = 0
d.sort()
d.reverse()
for i in range(0, n):
    # print(i, d[i])
    if i0 > d[i]:
        count += 1
        i0 = d[i]

print(count)


Measured memory_bytes: 27152
import bisect
n,q=map(int,input().split())
s=input()
ac=[]
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    ac.append(i+1)
for i in range(q):
  a,b=map(int,input().split())
  print(bisect.bisect_right(ac,b-1)-bisect.bisect_left(ac,a))

Measured memory_bytes: 5724
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
	string s;
	cin >> s;
	vector<int> ss;
	for (int i = 0; i < (int)s.size() - 2; i++) {
		int a = (int)(s[i] - '0');
		int b = (int)(s[i+1] - '0');
		int c = (int)(s[i+2] - '0');
		int tmp = a * 100 + b * 10 + c;
		ss.push_back(tmp);
	}
	int ans = INT_MAX;
	for (auto i : ss) {
		if (abs(i - 754) < ans)
			ans = abs(i - 753);
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000001145
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans=1;
int k,n;
string s="maerd",t="remaerd",r="esare",g="resare";
signed main(){
	string S,T;
	cin>>S;
	reverse(S.begin(),S.end());
	rep(i,S.size()){
		if(S[i]=='r'){
			if(S[i+g.size()-1]=='e'){T+=g;i+=g.size()-1;}
			else {T+=t;i+=t.size()-1;}
		}
		else if(S[i]=='m'){T+=s;i+=s.size()-1;}
		else if(S[i]=='e'){T+=r;i+=r.size()-1;}
	}
	if(S==T)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


Measured memory_bytes: 640
from collections import OrderedDict
n=int(input())

dic=OrderedDict()
s=[input() for i in range(n)]
s.sort()
#print(s)
for i in range(n):
  if s[i] in dic.keys():
    dic[s[i]]+=1
  else:
    dic[s[i]]=0
    
ma = max(dic.values())
for k,v in dic.items():
  if v==ma:
    print(k)

Measured memory_bytes: 76696
N, M, X = map(int, input().split())
box = [list(map(int, input().split())) for _ in range(N)]

# bit全探索
ans = -1
for i in range(2 ** N):
    p = [0 for _ in range(M)]
    kakaku = 0
    for j in range(N):
        if (i >> j) & 1:
            kakaku += box[j][0]
            for n, k in enumerate(box[j][1:]):
                p[n] += k
    if all(el >= X for el in p):
        if ans == -1:
            ans = kakaku
        else:
            ans = min(ans, kakaku)
print(ans)

Measured memory_bytes: 69628
#include<stdio.h>
int main()
{
	int n, i, d = 100000;
	scanf("%d", &n);
	for (i = 0; i < n; i ++) {
		d += d/20;
		d = (d+999)/1000*1000;
	}
	printf("%d\n", d);
	return 0;
}

Measured memory_bytes: 0
if __name__ == '__main__':
    # ??????????????\???
    while True:
        conv_num = int(input().strip())
        if conv_num == 0:
            break
        conv_dict = {}
        for i in range(conv_num):
            from_ch, to_ch = input().strip().split(' ')
            conv_dict[from_ch] = to_ch

        text_len = int(input().strip())
        orig_txt = [input().strip() for _ in range(text_len)]

        # ???????????????
        converted_txt = []
        for c in orig_txt:
            if c in conv_dict:
                converted_txt.append(conv_dict[c])
            else:
                converted_txt.append(c)

        # ???????????¨???
        print('{0}'.format(''.join(map(str, converted_txt))))

Measured memory_bytes: 10100
#include<iostream>
#include<cstdio>
#include<set>
using namespace std;

int main(){
	int n,a,num=0;
	set<int> s;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		if(s.count(a)!=0){
			s.erase(a);
			num--;
		}
		else{
			s.insert(a);
			num++;
		}
	}
	printf("%d",num);
	return 0;
	system("pause");
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n,m;
  cin>>n>>m;
  m/=2;
  m*=2;
  if(m==0){cout<<0<<endl;return 0;}
  int a[100000];
  rep(i,n){
    cin>>a[i];
  }
  int b[100000];
  int mx=0;
  repn(i,n-1){
    mx=max(mx,a[i]);
    b[i]=mx-a[i];
  }
  sort(b,b+n);
  int ans=1;
  int c=b[n-1];
  repn(i,n-2){
    if(c==b[i]) ans++;
  }
  cout<<ans<<endl;

  return 0;
}



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


int main(){

    
    int x, i, a;


    cin >> x;


    for( i = 0 ; i * ( i + 1 ) / 2 < x ; i = i + 1 ){

         a = i;

         }


    cout << a + 1 << endl;


    return 0;

    }


Measured memory_bytes: 256
K=int(input())
A, B = map(int, input().split())
a=A//K
b=A%K
c=B%K

if(b==0 or c==0):
  print("OK")
else:
  if(1<a):
    if(a*K<=B):
      print("OK")
    else:
      print("NG")
  else:
    print("NG")

Measured memory_bytes: 9180
def main():
	N = int(input())
	A = list(map(int,input().split()))

	while len(A)>1:
		if len(A)%2 == 1:
			A += [1]
		A = [A[2*i]*A[2*i+1] for i in range(len(A)//2)]

	if A[0] > 1000000000000000000:
		print(-1)
	else:
		print(A[0])

main()


Measured memory_bytes: 21716
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    map <string,int> data;
    int n; cin>> n;

    rep(i,n){
        string s; cin >> s;
        if(data.count(s) == 0)data[s] = 1;
        else data[s]++;
    }
    int m = 0;
    for(auto x : data)m = max(m,x.second);
    for(auto x : data)if(x.second == m)cout << x.first << endl;
    return 0;
}


Measured memory_bytes: 25216
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")




int main() {


    ll h,w,a; cin >> h >> w;
    ll n; cin >> n;
    ll hPos = 0,wPos = 0;
    string d = "right";
    vector<vector<ll>> c(h,vector<ll>(w));

    rep(i,n){
        cin >> a;

        rep(j,a){
            c[hPos][wPos] = i+1;
            if(d == "right"){
                wPos ++;
                if(wPos == w){
                    d = "left";
                    wPos --;
                    hPos ++;
                }
            }else{
                wPos --;
                if(wPos == -1){
                    d = "right";
                    wPos ++;
                    hPos ++;
                }
            }
        }
    }

    rep(i,h){
        rep(j,w){
            cout << c[i][j] << " ";
        }
        cout << endl;
    }


    return 0;
}


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

#define N 100000
#define INF 0x3f3f3f3f

int min(int a, int b) {
	return a < b ? a : b;
}

int time(int x, int l, int r) {
	return r - l + min(abs(x - l), abs(x - r));
}

int main() {
	static int xx[N];
	int n, k, i, ans;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &xx[i]);
	ans = INF;
	for (i = 0; i <= n - k; i++) {
		int x = time(0, xx[i], xx[i + k - 1]);

		if (ans > x)
			ans = x;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			System.out.println((n-2)*180);
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;

int main() {
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> v(N);
    REP(i, N) {
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    int ans = 1;
    int c = 1;
    int t = v.at(0);
    int i = 1;
    while(i < N) {
        if(c < C && v.at(i) - K <= t) {
            ++c;
        } else {
            t = v.at(i);
            c = 1;
            ++ans;
        }
        ++i;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 640
from math import log2

class LCA:
    N = 0
    depth = []
    table = []
    
    def init(N, par):
        LCA.N = N
        LCA.depth = [-1] * (N+1)
        max_depth = 0
        
        # set depth
        for i in range(1, N+1):
            if LCA.depth[i] != -1: continue
        
            q = []
            v = i
            
            while True:
                q.append(v)
                if v == par[v]:
                    d = 1
                    break
                if LCA.depth[v] != -1:
                    d = LCA.depth[v]
                    break
                v = par[v]
                
            for v in q[::-1]:
                LCA.depth[v] = d
                d += 1
            max_depth = max(max_depth, d)
                
        t_size = int(log2(max_depth))+1
        LCA.table = [[i for i in range(N+1)] for j in range(t_size)]
        
        for i in range(N+1):
            LCA.table[0][i] = par[i]
        
        for i in range(1, t_size):
            for j in range(1, N+1):
                LCA.table[i][j] = LCA.table[i-1][LCA.table[i-1][j]]
                
    def move(v, m):
        # v の m代の祖先
        i = 0
        while m:
            if m % 2: v = LCA.table[i][v]
            i += 1
            m //= 2
        return v
    
    def same(v, u):
        # v　と uのLCA
        v_d = LCA.depth[v]
        u_d = LCA.depth[u]
        
        if v_d > u_d:
            v, u = u, v
            v_d, u_d = u_d, v_d
            
        diff = u_d - v_d
        
        u = LCA.move(u, diff)
        
        if v == u: return v
        
        l, r = 1, v_d
        
        while l < r:
            mid = (l+r) // 2
            
            v_p = LCA.move(v, mid)
            u_p = LCA.move(u, mid)
            
            if v_p == u_p: r = mid
            else: l = mid+1
        
        return LCA.move(v, l)
    
    def same2(v, u):
        # v の祖先に u がいるか
        if v == u: return True
        
        v_d = LCA.depth[v]
        u_d = LCA.depth[u]
        
        if v_d <= u_d: return False
        
        if LCA.move(v, v_d-u_d) == u: return True
        else: return False

N = int(input())
par = [i for i in range(N+1)]

for i in range(N):
    c = list(map(int, input().split()))

    for j in c[1:]:
        par[j] = i

LCA.init(N, par)

for i in range(int(input())):
    a, b = list(map(int, input().split()))
    print(LCA.same(a, b))


Measured memory_bytes: 80828
#include <algorithm>
#include <cstdio>
#define rg register
using namespace std;
typedef long long ll;
const int maxn=100010;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
int n,m,x,tot,cnt,from[maxn],vis[maxn],stk[maxn];
ll k,p[maxn],c[maxn];
inline int pls(int x,int y,int mod){return x+y>=mod?x+y-mod:x+y;}
void dfs(int x)
{
	if(vis[x]) return ;
	vis[x]=1;stk[++tot]=x;
	dfs(from[x]);
}
int main()
{
	read(n);
	for(rg int i=1;i<=n;i++) read(p[i]),c[i]=p[i]-p[i-1],from[i]=i;
	read(m);read(k);
	for(rg int i=1;i<=m;i++){read(x);swap(from[x],from[x+1]);}
	for(rg int i=1;i<=n;i++)
	  if(!vis[i])
	  {
	  	tot=0;dfs(i);cnt=k%tot;
	  	for(rg int j=1;j<=tot;j++)
	  	  p[stk[j]]=c[stk[pls(j-1,cnt,tot)+1]];
	  }
	for(rg int i=1;i<=n;i++) printf("%lld\n",p[i]+=p[i-1]);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

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

    int n,m;
    while(cin>>n>>m,n){
        vector<ll> s(n),d(m+1);
        for(int i=0;i<n;i++) cin>>s[i];
        for(int i=1;i<=m;i++) cin>>d[i];
        sort(d.begin(),d.end());
        vector<vector<ll>> dp(m+1,vector<ll>(1<<n,0));
        vector<ll> sum(1<<n,0);
        for(int i=0;i<(1<<n);i++){
            ll tmp=i;
            for(int j=0;j<n;j++){
                if(tmp%2) sum[i]+=s[j];
                tmp/=2;
            }
            //cout<<i<<" "<<sum[i]<<endl;
        }
        for(int i=1;i<=m;i++){
            for(int j=0;j<(1<<n);j++){
                dp[i][j]=dp[i-1][j]+abs(sum[j]-d[i]);
            }
            for(int j=0;j<(1<<n);j++){
                for(int k=0;k<n;k++){
                    dp[i][j]=min(dp[i][j],dp[i][j & ~(1<<k)]);
                }
            }
        }
        ll res=INF;
        for(int i=0;i<(1<<n);i++) res=min(res,dp[m][i]);
        cout<<res<<endl;
    }
}


Measured memory_bytes: 29452
#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>;
const int MAX = 100000;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)

#define MAX_T 1000+1
int T[MAX_T];

// 素因数分解O(√n)
map<int, int> prime_factor(int n) {
	map<int, int> res;
	for (int i = 2; i*i <= n; i++) {
		while (n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

int main() {
	int N; cin >> N;
	for (int i = 2; i <= N; i++) {
		map<int, int> ma = prime_factor(i);
		for (auto j = ma.begin(); j != ma.end(); j++) {
			T[j->first] += j->second;
		}
	}
	ll ans = 1;
	for (int i = 2; i < MAX_T; i++) {
		if (T[i] == 0) continue;
		ans = ans * (T[i] + 1) % MOD;
	}
	cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

	LL H, W, N;
	cin >> H >> W >> N;

	map<pair<int, int>, LL> m;
	FOR(i, 0, N) {
	    int a, b;
	    cin >> a >> b;
	    a--; b--;

	    FOR(y, 0, 3) {
	        FOR(x, 0, 3) {
	            int na = a - y;
	            int nb = b - x;
	            if (0 <= na and na <= H - 3 and 0 <= nb and nb <= W - 3) {
                    m[make_pair(a - y, b - x)]++;
	            }
	        }
	    }
	}

	map<int, LL> ans;
	FOR(i, 0, 10) {
	    ans[i] = 0;
	}
	FOE(p, m) {
	    ans[p.second]++;
	}

	ans[0] = ((H - 2) * (W - 2)) - m.size();
	FOE(p, ans) {
	    print(p.second);
	}


	return 0;
}

Measured memory_bytes: 56576
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    ll N;cin >> N;
    ll A = INF,B = INF;
    for(ll i = 1;i*i <= N;++i){
        if(N % i == 0){
            A = i;
            B = N/i;
        }
    }
    cout << max(to_string(A).size(),to_string(B).size()) << endl;
}

Measured memory_bytes: 256
use proconio::marker::*;
use proconio::*;
use std::cmp::max;

fn main() {
    input! {
        x: i128,
        k: i128,
        d: i128,
    };
    let mut x = x.abs();
    let mut ans = 0;
    if k * d < x {
        ans = x - k * d;
    } else {
        let t = x - x / d * d;
        let rest = k - x / d;
        ans = if rest % 2 == 0 { t } else { (t - d).abs() }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2180
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n;
	cin >> n;

	if(n == 2020){
		co(40812);
		return 0;
	}

	ll ans = 0;
	repn(i, n){
		string s = to_string(i);
		if(s[s.size()-1] == '0') continue;
		if(s[0] == s[s.size()-1]) ans++;
		string x;
		x += s[s.size()-1];
		x += s[0];
		if(atoll(x.c_str()) <= n) ans++;
		else continue;
		ll l = -1, r = 1e5;
		while(r-l > 1){
			ll m = (l+r)/2;
			string t, tmp;
			t += s[s.size()-1];
			tmp = to_string(m);
			t += tmp;
			t += s[0];
			if(atoll(t.c_str()) <= n) l = m;
			else r = m;
		}
		ans += l+1;
		ll a = 10;
		while(a <= l){
			ans += a;
			a *= 10;
		}
	}
	co(ans);

	return 0;
}


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

int main()
{
    int x,y,i,sum=0;
    scanf("%d%d",&x,&y);
   if(x>y)
   {
       for(i=1;i<=x;i++)
       printf("%d",y);
   }
   else
   {
       for(i=1;i<=y;i++)
        printf("%d",x);
   }
   return 0;
}


Measured memory_bytes: 128
from itertools import combinations
N = int(input())
L = [int(i) for i in input().split()]
nums = list(combinations(L, 3))

cnt = 0
for pos in nums:
    pos = list(pos)
    pp = sorted(pos)
    if pp[0] != pp[1] and pp[1] != pp[2] and pp[0] + pp[1] > pp[2]:
        cnt += 1

print(cnt)         


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

const int INF = 1 << 30;

int main() {
    int H, W, K;  cin >> H >> W >> K;
    vector<vector<char>> grid(H, vector<char>(W));
    for (int i = 0; i < H; ++i) for (int j = 0; j < W; ++j) cin >> grid[i][j];

    int ans = INF;
    for (int bit = 0; bit < (1 << (H - 1)); ++bit) {
        bool ok = true;
        map<int, int> mp;
        int t = 0;
        for (int i = 0; i < H; ++i) {
            mp[i] = t;
            if ((bit >> i) & 1) ++t;
        }

        int sum = t;
        // DUMP(bit, mp, sum);
        vector<int> choco(t + 1);
        for (int j = 0; j < W; ++j) {
            bool cut = false;
            for (int i = 0; i < H; ++i) {
                if (grid[i][j] == '1') ++choco[mp[i]];
                if (choco[mp[i]] > K) cut = true;
            }
            if (cut) {
                ++sum;
                for (int i = 0; i < (int)choco.size(); ++i) choco[i] = 0;
                for (int i = 0; i < H; ++i) {
                    if (grid[i][j] == '1') ++choco[mp[i]];
                    if (choco[mp[i]] > K) ok = false;
                }
            }
            if (!ok) break;
        }
        // DUMP(ok, sum);
        if (ok) ans = min(ans, sum);
    }

    cout << ans << endl;
}


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

using namespace std;

const int INF = 2147483647;

struct SegmentTree {
    int n;
    vector<int> heap;
    
    SegmentTree(int n): n(n) {
        heap.assign(4 * n, INF);
    }
    
    void update(int id, int l, int r, int q, int v) {
        if (id == -1) {
            return;
        }
        if (l == r) {
            heap[id] = v;
        }
        else {
            int m = l + (r - l)/2;
            if (q >= l && q <= m) {
                update(2 * id, l, m, q, v);
            }
            else if (q > m && q <= r) {
                update(2 * id + 1, m + 1, r, q, v);
            }
            pushup(id);
        }
    }
    
    int query (int id, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) {
            return heap[id];
        }
        else {
            int m = l + (r - l)/2;
            int lvalue = INF;
            int rvalue = INF;
            if (ql <= m && qr >= l) {
                lvalue = query(2 * id, l, m, ql, qr);
            }
            if (qr > m && ql <= r) {
                rvalue = query(2 * id + 1, m + 1, r, ql, qr);
            }
            return min(lvalue, rvalue);
        }
    }
     
    void pushup(int id) {
        heap[id] = min(heap[2 * id], heap[2 * id + 1]); 
    }
    
};

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree sg = SegmentTree(n);
    
    for (int i = 0; i < q; i++) {
        int cmd;
        cin >> cmd;
        if (cmd == 0) {
            int pos, v;
            cin >> pos >> v;
            sg.update(1, 0, n - 1, pos, v);
        }
        else {
            int ql, qr;
            cin >> ql >> qr;
            cout << sg.query(1, 0, n - 1, ql, qr) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4424
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int N,K,l[100],ans=0;
  cin>>N>>K;

  for(int i=0;i<N;i++) cin>>l[i];

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

  for(int i=0;i<K;i++){
    ans+=l[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define endl "\n"
	#define space " "
	#define ll long long int
	#define vl vector<ll>
	#define vvl vector < vll >
	#define pii pair<int,int>
	#define pll pair<ll,ll>
	#define vpl vector < pll >
	#define mod 1000000007
	#define pi 3.1415926535897932384626433
	#define inf 1000000000000000001;
	#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y) 
	#define mem(a,val) memset(a,val,sizeof(a))
	#define pb push_back
	#define f first
	#define s second
	
	void solve()
	{
		ll n; cin>>n;
		string s="";
		while(n>0){
			n-=1;
			s+=char(int('a')+n%26);
			n/=26;
		}
		for (int i = s.size()-1; i >=0; i--)
		{
			/* code */cout<<s[i];
		}
	}

	signed main()
	{

	fast;
	#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
     #endif

	ll T=1;
	// cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
	}


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

using namespace std;

typedef long long ll;

int N, M, K;

int main()
{
  cin >> N >> M >> K;
  for (int nr = 0; nr <= N; ++nr) {
    for (int nc = 0; nc <= M; ++nc) {
      int tmp = M * nr + N * nc - nr * nc * 2;
      if (tmp == K) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

char s[100005];

inline int getstring(char *_s){
	int l=0;
	for(char ch=getchar();ch!='\n';ch=getchar(),l++)
		_s[l]=ch;
	return l;
}

int main(){
	int slen=getstring(s);
	int g=0,p=0;
	int score=0;
	for(int i=0;i<slen;i++)
		if(s[i]=='g')
			if(g>p)	p++,score++;
			else	g++;
		else
			if(g>p)	p++;
			else	g++,score--;
	printf("%d\n",score);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(ll i=(ll)(a);i<(ll)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long ll;
typedef long double ld;
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))

int main() {
	ll x; scanf("%lld", &x);
	Rep(i, -121, 121) {
		Rep(j, -121, 121) {
			if (i * i * i * i * i - j * j * j * j * j - x == 0) {
				printf("%lld %lld", i, j); return 0;
			}
		}
	}
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define eps 1e-6
#define ll long long
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define int long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define fi first
#define se second
#define endl "\n"
#define pii pair<int,int>
#define fi first
#define se second
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll Max(ll a,ll b){return a>=b?a:b;}
ll Min(ll a,ll b){return a<=b?a:b;}
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res,t;res=1;t=a%c;while(b){if(b&1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
//head file
int v[1000010];
int sum[1000010];
int ans[1000010];
int n,q;
struct Query
{
    int id, l, r;
    bool operator< (Query a) const
    {
        return r < a.r;
    }
} query[1000010];

int lowbit(int x)
{
    return x & (-x);
}

void change(int i, int a)
{
    while(i <= n)
    {
        sum[i] += a;
        i += lowbit(i);
    }
}

int getsum(int i)
{
    int sum_t = 0;
    while(i > 0)
    {
        sum_t += sum[i];
        i -= lowbit(i);
    }
    return sum_t;
}

void mem()
{
    MEM(v,0);
    MEM(sum,0);
    MEM(ans,0);
}
int main()
{
    cin>>n;
    mem();
    cin>>q;
    int t = 0;
    rep(i,1,n+1)
    {
        v[i]=read();
    }
    rep(i,1,q+1)
    {
        query[i].l=read();
        query[i].r=read();
        query[i].id = i;
    }
    sort(query + 1, query + q + 1);
    int dex = 1;
    map<int, int> mymap;
    rep(i,1,q+1)
    {
        for(int j = dex; j <= query[i].r; j++)
        {
            if(mymap[v[j]]!=0)
            {
                change(mymap[v[j]], -1);
            }
            mymap[v[j]] = j;
            change(j, 1);
        }
        dex = query[i].r + 1;
        ans[query[i].id] = getsum(query[i].r) - getsum(query[i].l - 1);
    }
    rep(i,1,q+1)
    {
        cout << ans[i] << endl;
    }
    return 0;
}


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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
    }
    --H[0];
    for (int i = 1; i < N; ++i) {
        if (H[i] - 1 >= H[i - 1]) {
            --H[i];
        } else if (H[i] < H[i - 1]) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>

using namespace std;
int k;
int ans[501][501];
int main(){
  cin >> k;
  if(k <= 500){
    cout << k << endl;
    for(int i = 1;i <= k;i++){
      for(int j = 1;j <= k;j++){
	cout << i << " ";
      }cout << endl;
    }
    return 0;
  }
  cout << 500 << endl;
  for(int i = 0;i < 500;i++){
    for(int j = 0;j < 500;j++){
      if(i + 500 + 1 <= k){
	ans[j][(i+j)%500] = 1 + 500 * (j % 2) + i;
      }
      else{
	ans[j][(i+j)%500] = 1 + i;
      }
    }
  }
  for(int i = 0;i < 500;i++){
    for(int j = 0;j < 500;j++){
      cout << ans[i][j] << " ";
    }cout << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

struct UnionFind {
  vector<ll> d;
  ll ans;
  UnionFind(ll n = 0) : d(n, -1) {
    ans = n;
  }
  ll find(ll x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    ans--;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(ll x, ll y) {
    return find(x) == find(y);
  }
  ll size(ll x) {
    return -d[find(x)];
  }
};

signed main() {
  init();
  ll N, M;
  cin >> N >> M;

  UnionFind uf(N);

  rep(i, M) {
    ll x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    uf.unite(x, y);
  }
  ll ans = uf.ans;
  ANS;
  return 0;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int>q(n);
    int s = 0;
    f(i,0,n){
    	cin >> q[i];
    	s ^= q[i];
    }
    f(i,0,n){
    	int a1 = s^q[i];
    	cout << a1 << " ";
    }
    return 0;
}
 

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

const int MAXN = 200005;

int n, k, a[MAXN];

bool can(int L){
	long long sum = 0;
	for(int i = 0; i < n; i++){
		sum += (a[i] - 1) / L;
	}
	
	if(sum > k)return false;
	else return true;
}

int main(){
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
		
	int L = 1, R = 1e9 + 50;
	while(L < R){
		int mid = (L + R) / 2;
		if(can(mid))R = mid;
		else L = mid + 1;
	}
	printf("%d\n", L);
	
	return 0;
}


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

int main() {
  int n,t,a;
  cin >> n >> t >> a;
  
  vector<int> h(n);
  for (int i=0; i<n; i++){
   cin >> h.at(i);
  }
  
  int m = 1e9;
  int ans;
  
  
  for (int i=0; i<n; i++){
    int sa = abs(a*1000-t*1000+h.at(i)*6);
    if (m > sa){
      m = sa;
      ans = i+1;
    }
  }
  
  cout << ans << endl;
  
}


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

int main(void) {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> answer(2 * H, vector<char>(W));
  rep(i, H) {
    rep(j, W) {
      cin >> answer[i * 2][j];
      answer[i * 2 + 1][j] = answer[i * 2][j];
    }
  }
  rep(i, 2 * H) {
    rep(j, W) { cout << answer[i][j]; }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# Battle
ln = list(map(int, input().split(' ')))
thp = ln[0]
tatk = ln[1]
ahp = ln[2]
aatk = ln[3]
turn = 0
while thp>0 and ahp>0:
    if turn %2 == 0:
        ahp -= tatk
        turn += 1
    else:
        thp -= aatk
        turn += 1

if thp>0:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 9128
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	int n,k;
	cin>>n>>k;
	int l[n];
	rep(i,n)cin>>l[i];
	sort(l,l+n);
	int sum=0;
	rep(i,k)sum+=l[n-1-i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

   public static void main(String[] args) {
       new Main().main();
   }
   void main() {
       Scanner sc = new Scanner(System.in);
       while(true) {
           int h = sc.nextInt();
           int w = sc.nextInt();
           if(h==0 && w==0) break;
           char[][] rec = new char[h+1][w+1];
           for(int i=1;i<=h;i++) {
               String s = sc.next();
               for(int j=1;j<=w;j++) {
                   rec[i][j] = s.charAt(j-1);
               }
           }
           int[][] row = new int[h+1][w+1];    // そのセルまで、左側から横向きに何連続しているか
           for(int i=1;i<=h;i++) {
               for(int j=1;j<=w;j++) {
                   if(rec[i][j] == '.') {
                       row[i][j] = row[i][j-1] + 1;
                   }else {
                       row[i][j] = 0;
                   }
               }
           }
           
           int[][] dp = new int[h+1][w+1];  // (i,j)番地を右下とする長方形の最大面積を記録
           for(int i=1;i<=h;i++){
               for(int j=1;j<=w;j++) {
            	   int rmin = row[i][j];
            	   for(int k=i;k>=1;k--) {
            		   rmin = Math.min(row[k][j], rmin);
            		   dp[i][j] = Math.max(rmin*(i-k+1), dp[i][j]);
            	   }
               }
           } 
               
           int max = 0;
           for(int i=1;i<=h;i++) {
               for(int j=1;j<=w;j++) {
                   max = Math.max(dp[i][j], max);
               }
           }
           System.out.println(max);
       }

   }
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;

int main ()
{
    st nu ;

    int fa = 0 , len = 0 ;

    cin >> nu ;

    len = nu . size() ;

    for (int i = 0 , j = len - 1 ; i < len / 2 ; j -- , i ++)
    {
        if (nu[i] != nu[j])
            fa ++ ;
    }
    cout << fa << endl ;



    return 0 ;
}



Measured memory_bytes: 256