akhauriyash/Code-Regression huggingface dataset:
def main():
    divs = ["dream", "dreamer", "erase","eraser"]

    S = input()

    rev_S = S[::-1]
    
    rev_divs = [div[::-1] for div in divs]
    
    i = 0
    while(1):
        can = False
        for rev_div in rev_divs:
            if rev_S[i:(i+len(rev_div))] == rev_div:
                can = True
                i += len(rev_div)

                if i == len(rev_S):
                    print("YES")
                    return 
        
        if not can:
            print("NO")
            return

main()
        
        



    

Measured memory_bytes: 41072
def gcd(a,b):
    if a <= b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

N = int(input())
A = list(map(int, input().split()))

L_gcd = [0]*(N+1)
R_gcd = [0]*(N+1)

for i in range(N):
    L_gcd[i+1] = gcd(L_gcd[i],A[i])
    R_gcd[N-i-1] = gcd(R_gcd[N-i],A[N-i-1])

ans = 0
for i in range(N):
    if gcd(L_gcd[i],R_gcd[i+1])>ans:
        ans = gcd(L_gcd[i],R_gcd[i+1])
    
print(ans)

Measured memory_bytes: 14400
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>

#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;

// <<fixed<<setprecision(6)<<

int gcd(lint x, lint y){
	return y==0 ? x:gcd(y,x % y);
}


int main(){
  int n;
  vector<pair<int,int>> tasks;
  cin>>n;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    tasks.emplace_back(b,a);
  }
  sort(all(tasks));
  int sum = 0;
  bool isyes=true;
  for (auto v : tasks){
    sum+=v.second;
    if(sum > v.first){
      isyes=false;
      break;
    }
  }
  if(isyes){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


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

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

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

    for (int i = K; i < N; ++i)
    {
        if (A[i] > A[i - K])
        {
            cout << "Yes"
                 << "\n";
        }
        else
        {
            cout << "No"
                 << "\n";
        }
    }
}


Measured memory_bytes: 4632
#include<bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
 
#define limit (int) (2e5 + 5) 
#define mod (long long int) (1e9 + 7)
 
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

lli s[limit],rs[limit];

int main()
{
	// ios_base::sync_with_stdio(false);cin.tie(NULL);   
   	int n;
   	cin >> n;

   	int x,y;
   	for (int i = 0; i < n; ++i)
   	{
   		cin >> x >> y;
   		s[i] = x+y;
   		rs[i] = x-y;
   	}

   	sort(s,s+n);
   	sort(rs,rs+n);

   	cout << max(s[n-1]-s[0],rs[n-1]-rs[0]);
    return 0;
}




Measured memory_bytes: 6720
def main():
    N, T = map(int, input().split())
    TN = tuple(map(int, input().split()))

    i = 0
    t = 0
    while i < N - 1:
        t += min(TN[i+1] - TN[i], T)
        i += 1

    print(t + T)

main()


Measured memory_bytes: 26964
#include <stdio.h>
#include <utility>
#define MAX_N 100

int a,b;

int gcd(int,int);

int main(void){
    scanf("%d %d",&a,&b);
    if( a < b) std::swap(a,b);
    printf("%d\n",gcd(a,b));
    return 0;
}

int gcd(int a,int b){
    if(b == 0){ return a;}
    else{return gcd(b, a%b);}
    
}

Measured memory_bytes: 2740
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int main(){
	string s;
	cin>>s;
	int res=0;
	for(int i=1;i<s.size();i++){
		if(s[i]==s[i-1])
			continue;
		else{
			res++;
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define MOD 1000000007
#define dataSize 500005
#define INF 1e18+7
#ifndef LOCAL
#define map unordered_map
#define endl "\n"
#endif
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	LL n;
	cin>>n;
	LL ar[n],par[n];
	for(LL i=0;i<n;i++){
		cin>>ar[i];
		par[i]=ar[i];
	}
	sort(par,par+n);
	LL p=0;
	for(LL i=0;i<n;i++) ar[i]!=par[i]?p++:p+=0;
	puts(p<3?"YES":"NO");
}


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

int main()
{
	int a;
	long long  b, n;
	cin >> a >> b >> n;
	long long int max;
	if(b <= n)
		max = (a * (b-1))/b;
	else if ( b > n )
	{
		max = (a * n)/b;
	}
	cout << max << endl;
}


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

int main(){
  int N;
  cin>>N;
  vector<string> gacha(N);
  for(int i=0;i<N;i++)
    cin>>gacha.at(i);
  int count=1;
  sort(gacha.begin(),gacha.end());
  for(int i=1;i<N;i++)
    if(gacha.at(i)!=gacha.at(i-1))
      count++;
  cout<<count<<endl;
}
    

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

int main() {
  int n;
  string s[102];
  cin >> n;
  
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (s[i] == "Y") {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}
    
    

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
      	int k = sc.nextInt();
      	int[] sticks = new int[n];
      	for (int i = 0; i < sticks.length; i++) {
        	sticks[i] = sc.nextInt();
        }
      	Arrays.sort(sticks);
      	int res = 0;
      	int pos = sticks.length - 1;
      	
      	while (k > 0) {
        	res += sticks[pos];
          	k--;
          	pos--;
        }
      	System.out.println(res);
	}
	
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 21204
#include<stdio.h>
int main()
{
int a,i,d;
  d=0;
  scanf("%d",&a);
int b[a],c[a];  
  for(i=0;i<a;++i)
  {scanf("%d",&b[i]);}
  
   for(i=0;i<a;++i)
  {scanf("%d",&c[i]);}
  
   for(i=0;i<a;++i)
  {if(b[i]-c[i]>0) d=d+b[i]-c[i];
   }
  
printf("%d",d);
return 0;
}

Measured memory_bytes: 128
K=int(input())
def run(K):
	run=[1,2,3,4,5,6,7,8,9]
	run2=[1,2,3,4,5,6,7,8,9]
	while len(run)<K:
		run3=[]
		for i in run2:
			st=str(i)
			for j in range(10):
				if abs(int(st[-1])-j)<=1:
					run.append(int(10*i+j))
					run3.append(int(10*i+j))
		run2=run3
	return run
ans=run(K)
print(ans[K-1])

Measured memory_bytes: 20316
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int ans;
int N;
vector<ll>v;
void dfs(ll n, ll k){
	if (k > 1e9)return;
	int f[10] = {}, t = n;
	while (t) {
		f[t % 10]++;
		t /= 10;
	}
	if (f[3] && f[5] && f[7])v.push_back(n);
	dfs(n + 3 * k, k * 10);
	dfs(n + 5 * k, k * 10);
	dfs(n + 7 * k, k * 10);
}
int main() {
	ans = 0;
	cin >> N;
	dfs(0, 1);
	sort(v.begin(), v.end());
	ll i = 0;
	for (; i < v.size(); ++i) {
		if (v[i] > N)break;
	}
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 100;
        for (int i = 0; i < 26; i++) {
            char alp  = (char)('a' + i);
            if(s.indexOf(alp) < 0) continue;
            int len = s.length() -1;
            boolean changed = true;
            char[] pre = s.toCharArray();
            int cnt = 0;
            while(changed){
                char[] cur = new char[len];
                changed = false;
                for (int j = 0; j < len; j++) {
                    if(pre[j] == alp || pre[j+1] == alp){
                        cur[j] = alp;
                    }else{
                        cur[j] = pre[j];
                    }
                    if(pre[j] != alp) changed = true;
                }
                if(pre[len] != alp) changed = true;
                if(changed)cnt++;
                pre = cur;
                len--;
            }
            ans = Math.min(ans, cnt);
        }
        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 24020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



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

  bool db = false;
  int max_count = 0;
  FOR(i,0,N-1){
    if(a[i]==max) ++ max_count;
  }
  if(max_count>1) db = true;

  int max_sec = 0;

  if(db == false){

    FOR(i,0,N-1){
      if(a[i]!=max) chmax(max_sec,a[i]);
    }
  }

  FOR(i,0,N-1){
    if(a[i]!=max) cout << max << endl;
    else{
      if(db == true) cout << max << endl;
      else cout << max_sec << endl;
    }
  }





}



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

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    int n = A >= B ? B : A;
    int k=0;
    while(true){
        if(A%n == 0 && B%n == 0){
            k++;
        }
        if(k == K){
            cout << n;
            break;
        }
        n--;
    }
    return EXIT_SUCCESS;
}

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

N = int(input())
A = list(map(int,input().split()))

A.sort()
S = 0
d = {}
for i in A:
    S += i
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

Q = int(input())

for i in range(Q):
    B,C = map(int,input().split())
    if B in d:
        x = d[B]
        S += (C-B) * x
        d[B] = 0
        if C in d:
            d[C] += x
        else:
            d[C] = x
    print(S)


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

int main() {
    int n;
    cin>>n;
    vector<int> g[n];
    pair<int,int> e[n-1];
    for (int i=0;i<n-1;i++) {
        int a,b;cin>>a>>b;a--,b--;
        e[i]={a,b};
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int used[n]{};
    map<pair<int,int>,int> m;
    int k=0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int v=q.front();
        q.pop();
        int c=1;
        for (int u:g[v]) {
            if (m[{v,u}]) continue;
            if (c==used[v]) c++;
            m[{v,u}]=m[{u,v}]=used[u]=c;
            k=max(k,c);
            q.push(u);
            c++;
        }
    }
    cout<<k<<endl;
    for (int i=0;i<n-1;i++)
        cout<<m[e[i]]<<endl;
    return 0;
}

Measured memory_bytes: 21760
#include<bits/stdc++.h>
#define ll long long int
const int MOD = 1e9+7;
using namespace std;
int main()
{   ios_base::sync_with_stdio(false); cin.tie(0);
	  int n,k;cin>>n>>k;
    int dp[k+1];
    vector<int> v;
    for(int i=0;i<=k;i++) dp[i]=0;
    for(int i=1;i<=n;i++)
    {   int last_element;cin>>last_element;
        v.push_back(last_element);
    }
    for(int suppose_sum=0;suppose_sum<=k;suppose_sum++)
      {
        for(int first_chosen:v)           //lets us  suppose that sum is suppose_sum then if
          {                               //first turn is given to firtst palyer(taro)
  if(suppose_sum>=first_chosen&&!dp[suppose_sum-first_chosen])   //dp[i]=1 if taro wins and 0 if 2nd player wins
          dp[suppose_sum]=1;              // * first_chosen is the first value chosen by TARO
          }                                // we look at all possibilites of first_chosen
    }                                      // and if for any first value we come to know that taro
(dp[k])?(cout<<"First"):(cout<<"Second");  // wins then we update it as 0 bcoz taro is playing optimally
          return 0;
}


Measured memory_bytes: 768
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll i;
  vector<vector<ll> > x(30);
  string s,t;
  cin >> s >> t;
  for(i=0;i<s.size();i++){
    x[s[i]-'a'].push_back(i);
  }
  for(i=0;i<t.size();i++){
    if(x[t[i]-'a'].size()==0){
      printf("-1\n");
      return 0;
    }
  }
  ll b=0,c=0;
  for(i=0;i<t.size();i++){
    ll mid,min=-1,max=x[t[i]-'a'].size();
    while(abs(min-max)>1){
      mid=(min+max)/2;
      if(x[t[i]-'a'][mid]>=c){
        max=mid;
      }
      else{
        min=mid;
      }
    }
    if(max==x[t[i]-'a'].size()){
      b++,c=0;
      i--;
    }
    else{
      c=x[t[i]-'a'][max]+1;
    }
  }
  cout << b*s.size()+c << endl;
}

Measured memory_bytes: 4628
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
#define F first
#define S second
#define pb push_back
#define REP(i,a,b) for (int i = a; i <= b; i++)

int main()
{
  ll n;
  cin >> n;ll a[n];map<ll,ll> mp;map<ll,ll> calc;
  for(ll i=0;i<n;i++)
  {
      cin >> a[i];
      mp[a[i]]=0;
      
  }
  sort(a,a+n);
  for(ll i=0;i<n;i++)
  {
      calc[a[i]]++;
  }
  for(ll i=0;i<n;i++)
  {
      ll prod=a[i];ll j=2;
      while(prod<=a[n-1])
      {
          prod=a[i];
          if(calc[a[i]]>1)
          {
              mp[prod]++;
          }
          prod*=j;
          mp[prod]++;
          j++;
          
      } 
     
  }
  
   ll count=0;
  for(auto x :mp)
  {
     
      if(x.second==0)
      {
          count++;
      }
  }

  
  
  cout << count << endl;
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    int ans=0;
    rep(i, N) rep(j, N) rep(k, N){
        if (i<j && j<k){
            if (A[i]==A[j]) continue;
            if (A[k]==A[j]) continue;
            if (A[i]==A[k]) continue;
            if ((long long)A[i]+A[j]+A[k]<= max({A[i], A[j], A[k]})*2) continue;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
N = int(input())
dd = list(map(int, input().split()))
d = [0]
d.extend(dd)
d.append(0)

diff = [abs(d[i + 1] - d[i]) for i in range(N + 1)]
dd = []
for i in range(N):
    temp = abs(d[i + 1] - d[i]) + abs(d[i + 2] - d[i + 1])
    temp_2 = abs(d[i + 2] - d[i])
    if temp > temp_2:
        dd.append(temp - temp_2)
    else:
        dd.append(0)
s = sum(diff)
for i in range(N):
    print(s - dd[i])

Measured memory_bytes: 14980
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 4000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

ll digit(ll n){
	string s=to_string(n);
	ll ret=0;
	for(int i=0;i<s.size();i++){
		ret+=(s[i]-'0');
		
	}
	return ret;
}


int main(){
	init();
	ll N;
	cin>>N;
	vector<ll>A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	sort(A.begin(),A.end());
	A.push_back(-1);
	ll num=1;
	ll ans=0;
	for(int i=0;i<N;i++){
		if(A[i]==A[i+1]){
			num++;
		}else{
			//cout<<num<<endl;
			if(num>=A[i])ans-=(A[i]-num);
			else ans+=num;
			num=1;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
N,M=map(int,input().split())
L=[]
S=[]
for i in range(N):
    x = input()
    l=[y for y in x]
    L.append(l)
for i in range(M):
    x = input()
    s=[y for y in x]
    S.append(s)
flag = 0
sum = 0
for i in range(N):
    for j in range(N):
        for k in range(M):
            for l in range(M):
                if i+k < N and j+l < N:
                    if L[i+k][j+l] == S[k][l]:
                        sum += 1
                        if sum == M * M:
                            flag = 1
                    else:
                        sum = 0
                else:
                    sum = 0
if flag == 0:
    print("No")
else:
    print("Yes")


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

int main() {
  int n,p;
  char y;
  
  p = 0;
  
  cin >> n;
  
  for(int i = 0; i < n; i++){
    cin >> y;
    if(y == 'Y'){
      p = 1;
    }
  }
  if(p == 1){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
l = [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
a = 0

while True:
  b = l[0] - a
  c = l[0] + a
  if b not in n:
    print(b)
    break
  elif c not in n:
    print(c)
    break
  else:
    a += 1

Measured memory_bytes: 9184
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    int a[n];
    rep(i, n)   cin >> a[i];
    
    int sum = 0;
    rep(i, n)   sum += a[i];
    int ave1 = sum / n;
    int ave2 = ave1 + 1;
    
    int cost1 = 0, cost2 = 0;
    
    rep(i, n){
        cost1 += pow(a[i] - ave1, 2);
    }
    
    rep(i, n){
        cost2 += pow(a[i] - ave2, 2);
    }
    
    cout << min(cost1, cost2) << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    static char[][] A;
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();        
        int[] HW = r.ii();
        int H = HW[0],
            W = HW[1];
        A = new char[H][W];
        HashSet<int[]> queue = new HashSet<>();
        for(int i = 0; i < H; i++){
            String Ai = r.s();
            for(int j = 0; j < W; j++){
                A[i][j] = Ai.charAt(j);
                if(A[i][j] == '#') queue.add(new int[]{i, j});
            }
        }
        int count = 0;
        while(true){
            Iterator<int[]> iterator = queue.iterator();
            HashSet<int[]> queue2 = new HashSet<>();
            while(iterator.hasNext()){
                int[] ij = iterator.next();
                int i = ij[0],
                    j = ij[1];
                turnBlack(i-1, j, queue2);
                turnBlack(i, j-1, queue2);
                turnBlack(i+1, j, queue2);
                turnBlack(i, j+1, queue2);
            }
            if(queue2.size() > 0){
                queue.clear();
                queue.addAll(queue2);
                count++;
            } else{
                break;
            }            
        }
        print(count);
    }
    static void turnBlack(int i, int j, HashSet<int[]> queue){
        try{
            if(A[i][j] == '.'){
                A[i][j] = '#';
                queue.add(new int[]{i, j});
            }
        } catch(ArrayIndexOutOfBoundsException e){}
    }
    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return readLine().split(" ");
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 126160
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <limits.h>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

vector<ll> V;
map<ll,ll> M;

int main(){
  ll N;
  cin >> N;
  V.pb(0);
  M[0]++;
  rep(i,N){
    ll X;
    cin >> X;
    V.pb(V[i]+X);
    M[V[i]+X]++;
  }
  ll ANS=0;
  for(auto P : M){
    ANS+=P.sc*(P.sc-1)/2;
  }
  cout << ANS <<  endl;
} 


Measured memory_bytes: 17180
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
複雑すぎて法則みえないな。必ずNになるとか？

   1
 1 2 3 =2
 
 3
    3
  2 3 4
1 2 3 4 5

    3
  2 4 3
1 5 2 4 3

    2
  2 2 3
5 1 2 3 4

    2
  4 2 2
4 5 1 2 3

    2
  2 2 3
  2 2
  2 2
3 2 1 4
  さえおさえておけばいいのね
*/
int main(){
  ll N,x; cin>>N>>x;
  vector<ll> ans(2*N,0);
  vector<bool> is_use(2*N,false);
  if(x==1 || x==2*N-1){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  if(N==2){
    cout<<1<<endl<<2<<endl<<3<<endl;
    return 0;
  }
  else if(x>=3){
    ans[N-2]=x-1;
    ans[N-1]=x;
    ans[N]=x+1;
    ans[N+1]=x-2;
    for(int i=x-2; i<=x+1; i++)
      is_use[i]=true;
    for(int i=1, j=1; i<=2*N-1; i++){
      if(i==N-2) i+=4;
      if(j==x-2) j+=4;
      ans[i]=j++;
    }
  }
  else if(x==2){
    ans[N-2]=3;
    ans[N-1]=2;
    ans[N]=1;
    ans[N+1]=4;
    for(int i=1; i<=4; i++)
      is_use[i]=true;
    for(int i=1, j=1; i<=2*N-1; i++){
      if(i==N-2) i+=4;
      if(j==1) j+=4;
      ans[i]=j++;
    }
  }
  for(int i=1; i<=2*N-1; i++)
    cout<<ans[i]<<endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    rep(i, M) { cin >> X[i]; }

    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }

    // 以下, N < M
    sort(X.begin(), X.end());
    vector<int> d(M - 1);
    rep(i, M - 1) { d[i] = X[i + 1] - X[i]; }

    sort(d.begin(), d.end());
    int ans = 0;
    rep(i, M - 1 - (N - 1)) { ans += d[i]; }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
def main():
    k, s = map(int, input().split())
    answer = 0
    for i in range(k + 1):
        for j in range(k + 1):
            l = s - i - j
            if 0 <= l <= k:
                answer += 1
    print(answer)


if __name__ == '__main__':
    main()



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

int main(){
  int A, B;
  cin >> A>>B;
  int count=0;
  for(int i=A;i<=B;i++){
      if(i/10000==i%10&&(i/1000)%10==(i/10)%10){
          count++;
      }
  }
  cout << count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int N;
int H,W;
int num;
int sum[1500];
int cou;
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d%d",&H,&W);
		if(sum[60*H+W]==0)num++;
		sum[60*H+W]++;
	}
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d%d",&H,&W);
		if(sum[60*H+W]==0)num++;
		sum[60*H+W]++;
	}
	for(int i=0;i<1440;i++){
		if(sum[i]!=0){
			if(cou+1==num)printf("%d:%02d\n",i/60,i%60);
			else printf("%d:%02d ",i/60,i%60);
			cou++;
		}
	}
	return 0;
}

Measured memory_bytes: 1204
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = Integer.parseInt(sc.next());
        int t = Integer.parseInt(sc.next());
        int s = Integer.parseInt(sc.next());
        if(d <= t*s) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35520
#include<stdio.h>

int main(void)
{
	int a,b,c;
	int temp;

	scanf("%d %d %d ",&a,&b,&c);

	if(a>b){
		temp=a;
		a=b;
		b=temp;		
	}

	if(b>c){
		temp=b;
		b=c;
		c=temp;
	}
	
	if(a>b){
		temp=a;
		a=b;
		b=temp;
	}
	
	printf("%d %d %d\n",a,b,c);

	return 0;

}
	

Measured memory_bytes: 600
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0518
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	while (true) {
		int n; cin >> n;
		if (n == 0) break;
		vector<pair<int, int>> P(n);
		vector<vector<bool>> m(5010, vector<bool>(5010));
		for (int i = 0; i < n;i++) {
			int x, y; cin >> x >> y;
			m[x][y] = true;
			P[i] = make_pair(x, y);
		}
		sort(P.begin(), P.end());
		int ans = 0;
		for (int i = 0; i < n;i++) {
			for (int j = i + 1; j < n;j++) {
				pair<int, int> p1, p2;
				p1.first  = P[j].first - (P[j].second - P[i].second);
				p1.second = P[j].second + (P[j].first - P[i].first);

				p2.first  = P[i].first - (P[j].second - P[i].second);
				p2.second = P[i].second + (P[j].first - P[i].first);

				if (p1.first < 0 || p1.first > 5000) continue;
				if (p1.second < 0 || p1.second > 5000) continue;
				if (p2.first < 0 || p2.first > 5000) continue;
				if (p2.second < 0 || p2.second > 5000) continue;

				if (m[p1.first][p1.second] && m[p2.first][p2.second]) {
					ans = max(ans, (int)pow(P[i].first - P[j].first, 2) + (int)pow(P[i].second - P[j].second, 2));
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 6292
#include<bits/stdc++.h>
using namespace std;
int par[200006],a[200006];
int rep(int n){
  if(par[n]==n)return n;
  return par[n] = rep(par[n]);
}
void join(int x,int y){
  int a = rep(x);
  int b  = rep(y);
  if(a!=b){
    par[a]=b;
  }
  if(rep(x)==rep(y)) return;
  par[rep(x)]= rep(y);
}
int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
    par[i]=i;
  }
  int x,y;
  for(int i=1;i<=q;i++){
    scanf("%d%d",&x,&y);
    join(x,y);
  }
  int ans = 0;
  for(int i=1;i<=n;i++){
    if(rep(a[i])==rep(i) ){
      //cout<<a[i]<<" "<<par[i]<<endl;
      ans++;
    }

  }
  printf("%d\n",ans);
}


Measured memory_bytes: 1024
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it with "scanf" and other c input!

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int n;
    scanf("%d",&n);
    int a[200010];
    for (int i = 1;i <= n;i ++) {
        scanf("%d",a + i);
    }
    int x[200010];
    for (int i = 1;i <= n;i ++) {
        x[i] = i - a[i];
    }
    sort(x + 1, x + 1 + n);
    ll c = 0;
    for (int i = 1;i <= n;i ++) {
        if (a[i] + i == i - a[i]) c --;
        int *l = lower_bound(x + 1, x + n + 1, a[i] + i);
        int *e = upper_bound(x + 1, x + n + 1, a[i] + i);
        c += e - l;
    }
    printf("%lld\n",c);
    return 0;
}


Measured memory_bytes: 4792
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int t = 0;
    foreach (i; 0 .. 5) {
        int x; readf("%d\n", &x);
        t += max(x, 40);
    }
    writeln(t / 5);
}

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

using namespace std;

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

bool check(vector<pair<int, int>> v) {
  int now = 0;
  for (auto p : v) {
    if (now - p.first < 0) return false;
    now += p.second;
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> v1, v2;
  int total = 0;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    int cnt = 0;
    int m = 0;
    for (auto c : s) {
      if (c == '(') {
        cnt++;
      } else {
        cnt--;
      }
      chmax(m, -cnt);
    }
    if (cnt >= 0) {
      v1.push_back({m, cnt});
    } else {
      v2.push_back({cnt + m, -cnt});
    }
    total += cnt;
  }
  if (total != 0) {
    cout << "No" << endl;
    return 0;
  }

  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());

  if (check(v1) && check(v2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 18724
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>

using namespace std;

int main()
{
	int n,x,a[105];
	memset(a,0,sizeof(a));
	while(cin>>n){
		x=0;
		string str;
		for(int i=0;i<n;i++){
			cin>>str[i];
			if (str[i]=='I'){
				x++;
				a[i]=x;
			}
			else if (str[i]=='D'){
				x--;
				a[i]=x;
			}
		}
		sort(a,a+n);
		if (a[n-1]<0) cout<<"0"<<endl;
		else cout<<a[n-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
using namespace std;
int main() {
    int D,G;
    cin >> D >> G;
    //問題数，コンプボーナス
    int p[D], c[D];
    for (int i=0;i<D;i++) {
        cin >> p[i] >> c[i];
    }
    int min = 10000;
    //bit全探索
    for(int bit=0; bit < (1<<D); bit++) {
        int sum=0;
        int total = 0;
        for(int i=0;i<D;i++) {
            //全部解く場合
            if(bit&(1<<i)) {
                sum += 100*p[i]*(i+1) + c[i];
                total += p[i];
            }
        }
        //全部とかないiについて足す(上から)
        for(int i=D-1;i>=0;i--) {
            if(sum>=G) break;
            if(!(bit&(1<<i))) {
                if(G-sum <= (100*(p[i]-1)*(i+1))) {
                    while(sum<G) {
                        sum += 100*(i+1);
                        total++;
                    }
                } else {
                    sum += (100*(p[i]-1)*(i+1));
                    total += p[i]-1;
                }
            }
        }
        if(sum >=G && min > total) min = total;
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5;
set<int> s[maxn+5];
int f[maxn+5],a[maxn+5];
int n,m,ans;
int find(int x)
{
    if(f[x]==x) return x;
    return f[x]=find(f[x]);
}
int main()
{

    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i) scanf("%d",&a[i]),f[i]=i;
    while(m--)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        x=find(x),y=find(y);
        if(x!=y) f[x]=y;
    }
    for(int i=1;i<=n;++i)
    {
        f[i]=find(i);
        s[f[i]].insert(a[i]);
    }
    for(int i=1;i<=n;++i)
    {
        if(s[f[i]].count(i)) ++ans;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 10368
n = int(input())
a = [int(v) for v in input().split()]
a.append(0)

all_sum = sum([abs(a[i] - a[i+1]) for i in range(n)])
all_sum += abs(a[0])

ans = []
if a[0] < 0 <= a[1] or a[0] > 0 >= a[1]:
    ans.append(all_sum - abs(a[0]) * 2)
elif 0 <= a[0] <= a[1] or 0 >= a[0] >= a[1]:
    ans.append(all_sum)
else:
    ans.append(all_sum - abs(a[0] - a[1]) * 2)

for i in range(n-1):
    if a[i+1] < a[i] <= a[i+2] or a[i+1] > a[i] >= a[i+2]:
        ans.append(all_sum - abs(a[i] - a[i+1]) * 2)
    elif a[i] <= a[i+1] <= a[i+2] or a[i] >= a[i+1] >= a[i+2]:
        ans.append(all_sum)
    else:
        ans.append(all_sum - abs(a[i+1] - a[i+2]) * 2)

for line in ans:
    print(line)

Measured memory_bytes: 13792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y, lli p){
    lli res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
vll grundy;
vector<bool> vis;
void calc_grundy(lli a, vll& piles){
	lli n = piles.size();
	vis.clear();
	vis.resize(a+1, false);
	loop(i, 0, n){
		if(a >= piles[i])
			vis[grundy[a-piles[i]]] = true;
		else
			break;
	}
	lli mex = 0;
	loop(i, 0, a+1){
		if(vis[i] == false){
			break;
		}
		else
			mex++;
	}
	grundy[a] = mex;
	return ;
}
lli solve(){
	lli n, k;
	cin>>n>>k;
	vll piles(n);
	grundy.clear();
	loop(i, 0, n)	cin>>piles[i];
	grundy.resize(k+1, -1);
	grundy[0] = 0;
	loop(i, 1, k+1)
		calc_grundy(i, piles);
//	loop(i, 0, k+1)
//		cout<<grundy[i]<<"\n";
//	lli xr = grundy[k - piles[0];
//	loop(i, 1, n)	xr = xr ^ grundy[k - piles[i]];
	lli xr = grundy[k];
	if(xr == 0)
		cout<<"Second\n";
	else
		cout<<"First\n";
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
 
int main() {
    string s;
    ll k;
  cin >> s >> k ;
  ll n=s.size();
  if(count(all(s),s[0])==s.size()){
    cout << s.size()*k/2 << endl;
    return 0;
  }
  ll a=0,cnt=0;
  rep(i,s.size()-1){
    cnt=1;
    while(s[i]==s[i+1]) i++,cnt++;
    if(cnt>1) a+=cnt/2;
  }
  if(s[0]!=s[n-1]){
    cout << a*k << endl;
    return 0;
  }
  s+=s;
  ll b=0;
  rep(i,s.size()-1){
    cnt=1;
    while(s[i]==s[i+1]) i++,cnt++;
    if(cnt>1) b+=cnt/2;
  }
  cout << a+(b-a)*(k-1) << endl;
    
 return 0;
}

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

#define tt template<typename T> ostream& operator <<(ostream& os, const
#define tuv template<typename U, typename V> ostream& operator<<(ostream& os, const
tt vector<T>& v)            { os << "["; for(auto & x : v) os << " " << x; os << " ]"; return os; }
tt vector<vector<T> >& m)   { for(auto & x : m) { for(auto & y : x) os << y << " "; os << "\n"; } return os; }
tt set<T>& s)               { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt unordered_set<T>& s)     { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt queue<T>& q)             { queue<T> q2(q); while(!q2.empty()) { os << q2.front() << " "; q2.pop(); } return os; }
tt stack<T>& s)             { stack<T> s2(s); while(!s2.empty()) { os << s2.top() << " "; s2.pop(); } return os; }
tuv pair<U,V>& p)           { os << "(" << p.first << "," << p.second << ")"; return os; }
tuv map<U,V>& m)            { os << "{ "; for(auto & x : m) os << x.first << ":" << x.second << " "; os << "}"; return os; }
tuv unordered_map<U,V>& um) { os << "{ "; for(auto & x : um) os << x.first << ":" << x.second << " "; os << "}"; return os; }


void incr(std::vector<int>& v, int& ndigits)
{
    for(int i = v.size() - 1; i >= 0; --i)
    {
	if(i == v.size() - ndigits)
	{
	    if(v[i] == 9)
	    {
		v[i-1] = 1;
		for(int j = i; j < v.size(); ++j) v[j] = 0;
		ndigits++;
		return;
	    }
	    else
	    {
		v[i]++;
		for(int j = i+1; j < v.size(); ++j) v[j] = max(0, v[j-1]-1);
		return;
	    }
	}
	else if(v[i] == v[i-1]-1)
	{
	    v[i]++;
	    for(int j = i+1; j < v.size(); ++j) v[j] = max(0, v[j-1]-1);
	    return;
	}
	else if (v[i] == v[i-1])
	{
	    if(v[i] != 9)
	    {
		v[i]++;
		for(int j = i+1; j < v.size(); ++j) v[j] = max(0, v[j-1]-1);
		return;
	    }
	}
    }
    return;
}

int main(int argc, char * argv[])
{
    std::ios_base::sync_with_stdio(false);    
    std::cin.tie(NULL);

    int K;
    std::cin >> K;

    std::vector<int> num(10, 0);
    int ndigits = 1;
    for(int i = 1; i <= K; ++i)
    {
	incr(num, ndigits);

    }

    bool zero_part = true;
    for(int i = 0; i < num.size(); ++i)
    {
	if(num[i] != 0) zero_part = false;
	if(!zero_part) cout << num[i];
    }
    std::cout << std::endl;
    
    

    return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 200007, M = 1e9 + 7;
ll v[N], fat[N];


ll fast_pow(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b&1) ans = (ans * a)%M;
        b >>= 1;
        a = a * a % M;
    }
    return ans;
}
ll choose(ll n, ll k) {
    if(k > n or k < 0) return 0;
    ll den = fat[n-k] * fat[k] % M;
    return fat[n] * fast_pow(den, M - 2) % M;
}

int main() {
    int n, k; cin >> n >> k;

    fat[0] = 1;
    for(int i = 1; i <= 2 * n; ++i) fat[i] = fat[i-1] * i % M;
    for(int i = 0; i < n; ++i) cin >> v[i];
    sort(v, v + n);

    ll ans = 0;
    // soma
    for(int i = 0; i < n; ++i) {
        ll aux = v[i] * choose(i, k-1) % M;
        ans = (ans + aux)%M;
    }

    // subtrair
    for(int i = 0; i < n; ++i) {
        ll aux = v[i] * choose(n - i - 1, k-1) % M;
        ans = (ans - aux + M)%M;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let s:String = read();
    let s:Vec<_> = s.chars().collect();
    let n = s.len();

    let parin = |xs:&[_]| {
        let n = xs.len();
        for i in 0..(n/2) {
            if xs[i] != xs[n-i-1] {
                return false
            }
        }
        true
    };

    let flg = parin(&s[..]);
    let flg = flg && parin(&s[..(n-1)/2]);
    let flg = flg && parin(&s[(n+1)/2..]);

    println!("{}", if flg { "Yes" } else { "No" });
}

Measured memory_bytes: 4352
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        mut p:[usize; n]
    }
    p.sort();

    let mut ans = 0;
    for i in 0..k {
        ans += p[i];
    }
    println!("{}", ans)
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef long long ull;
typedef long double ld;

int main(){

    int a,b;
    cin >> a >> b;
    if(500*a>=b)
        cout << "Yes";
    else
        cout << "No";


    return 0;
}








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

int main() {
  string S;
  cin >> S;
  int sum=0;
  while(S.size()>0){
    int tmp;

    tmp = stoi(S.substr(S.size()-1));
    S.erase(S.size()-1);
    sum+=tmp;
    if(sum%9==0){
      sum=0;
    }
    //cout << S <<endl;
  }

  if(sum%9==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	
	ll s=0;
	for(int i=1 ; i<=n ; ++i){
		if(i%3 && i%5){
			s += i;
		}
	}
	
	cout << s;
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;
const int nmax=200005;
const int mod=1000*1000*1000+7;
int v[nmax],dp[nmax],sum[nmax];
int n,x,i,j,nr;
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(x!=v[nr])
            v[++nr]=x;
    }
    dp[0]=1;
    for(i=1;i<=nr;i++)
    {
        sum[v[i]]+=dp[i-1];
        if(sum[v[i]]>=mod)
            sum[v[i]]-=mod;
        dp[i]=sum[v[i]];
    }
    cout<<dp[nr];
    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
main()
{
    int N,K,i=0,s=0,j=1;
    scanf("%d%d",&N,&K);
 
    while(N/K!=0)
    {
        N=N/K;
        j++;
    }
    printf("%d",j);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

struct RMQ{
	using T = long long;
	T operator()(const T &a, const T &b) { return min(a,b); };
	static constexpr T identity() { return 1LL << 60; }
	static constexpr T init() { return 0; }
};

template<class Monoid>
class rangeAddQuery{
	private:
		using T = typename Monoid::T;
		Monoid op;
		const int n;
		vector<T> dat, lazy;
		T query(int a, int b, int k, int l, int r){
			eval(k);
			if(b <= l || r <= a) return op.identity();
			else if(a <= l && r <= b) return dat[k];
			else{
				T left = query(a, b, k * 2, l, (l + r) / 2);
				T right = query(a, b, k * 2 + 1, (l + r) / 2, r);
				propTo(k);
				return op(left, right);
			}
		}
		void add(int a, int b, int k, int l, int r, T x){
			eval(k);
			if(a <= l && r <= b){
				lazy[k] += x;
				eval(k);
			}else if(l < b && a < r){
				add(a, b, k * 2, l, (l + r) / 2, x);
				add(a, b, k * 2 + 1, (l + r) / 2, r, x);
				propTo(k);
			}
		}
		inline void eval(int k){
			if(lazy[k] == op.init()) return;
			dat[k] += lazy[k];
			if(k < n){
				lazy[k * 2] += lazy[k];
				lazy[k * 2 + 1] += lazy[k];
			}
			lazy[k] = op.init();
		}
		inline void propTo(int k){
			dat[k] = op(dat[k * 2], dat[k * 2 + 1]);
		}
		int power(int n){
			int res = 1;
			while(n >= res) res*=2;
			return res;
		}
	public:
		rangeAddQuery(int n) : n(power(n)), dat(4 * n, op.identity()), lazy(4 * n, op.init()) {}
		rangeAddQuery(const vector<T> &v) : n(power(v.size())), dat(4 * n), lazy(4 * n, op.init()){
			copy(begin(v), end(v), begin(dat) + n);
			for(int i = n - 1; i > 0; i--) propTo(i);
		}
		T query(int a, int b){ return query(a,b,1,0,n); }
		void add(int s, int t, T x){ add(s, t, 1, 0, n, x); }
		T get(int a){ return query(a, a + 1); };
		void out(){
			rep(i,n * 2){ cout << dat[i + 1] << ' '; } cout << endl;
		}
};

int main(){
	int n, q;
	cin >> n >> q;

	vector<RMQ::T> tmp(n,0);
	rangeAddQuery<RMQ> seg(tmp);
	rep(i,q){
		int com;
		cin >> com;
		if(not com){
			int s, t, x;
			cin >> s >> t >> x;
			seg.add(s, t + 1, x);
		}else{
			int s, t;
			cin >> s >> t;
			cout << seg.query(s, t + 1) << endl;
		}
		//seg.out();
	}
}



Measured memory_bytes: 11816
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

S = input()
X, Y = list(map(int, input().split()))


def turn(d):
    return 'x' if d == 'y' else 'y'


i = 0
while i < len(S) and S[i] == 'F':
    i += 1
xs = {i}
ys = {0}
direction = 'x'
while i < len(S):
    while i < len(S) and S[i] == 'T':
        direction = turn(direction)
        i += 1
    cnt = 0
    while i < len(S) and S[i] == 'F':
        i += 1
        cnt += 1
    if direction == 'x':
        xs = {x + cnt for x in xs} | {x - cnt for x in xs}
    else:
        ys = {y + cnt for y in ys} | {y - cnt for y in ys}
if X in xs and Y in ys:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 4968