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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

typedef long long ll;

char s[2521];
int n;
ll k;

ll dp[2521][2521];
int len[2521][2521];

const ll INF = 2000000000000000000ll;

int main(){
  scanf("%s",s);
  n = strlen(s);
  scanf("%lld",&k);
  // ll maxval = 0;
  FOR(l,0,n+1)REP(i,n-l+1){
    int j = i+l;
    if(j-i<=1){
      len[i][j] = j-i;
      dp[i][j] = 1;
      continue;
    }
    if(s[i]==s[j-1]){
      len[i][j] = len[i+1][j-1] + 2;
      dp[i][j] = dp[i+1][j-1];
      continue;
    }
    int minlen = min(len[i+1][j], len[i][j-1]);
    len[i][j] = minlen + 2;
    if(minlen == len[i+1][j]){
      dp[i][j] += dp[i+1][j];
    }
    if(minlen == len[i][j-1]){
      dp[i][j] += dp[i][j-1];
    }
    dp[i][j] = min(dp[i][j], INF);
    // maxval = max(maxval, dp[i][j]);
  }
  // cout << maxval << endl;
  if(dp[0][n] < k){
    puts("NONE");
    return 0;
  }
  int i = 0, j = n;
  string head = "", tail = "";
  while(j-i>1){
    if(s[i]==s[j-1]){
      head += s[i];
      tail += s[j-1];
      i++; j--; continue;
    }
    if(len[i+1][j] < len[i][j-1]){
      head += s[i];
      tail += s[i];
      i++; continue;
    }else if(len[i+1][j] > len[i][j-1]){
      head += s[j-1];
      tail += s[j-1];
      j--; continue;
    }else{
      if(s[i] < s[j-1]){
        if(k <= dp[i+1][j]){
          head += s[i];
          tail += s[i];
          i++; continue;
        }else{
          head += s[j-1];
          tail += s[j-1];
          k-=dp[i+1][j];
          j--; continue;
        }
      }else{
        if(k <= dp[i][j-1]){
          head += s[j-1];
          tail += s[j-1];
          j--; continue;
        }else{
          head += s[i];
          tail += s[i];
          k-=dp[i][j-1];
          i++; continue;
        }
      }
    }
  }
  string ans = head;
  reverse(tail.begin(), tail.end());
  FOR(x,i,j)ans += s[x];
  ans += tail;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 42252
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int N,m; cin >> N >> m;
    vector<int> c(m),d(m);

    vector<int> flag(N+1);
    for(int i = 0; i < m;i++){
        cin >> c[i] >> d[i];
        
        for(int j = c[i]; j < d[i];j++){
            flag[j] = true;
        }
    }
    int cnt = accumulate(flag.begin(),flag.end(),0);
    
    ll ans = cnt*3 + (N+1-cnt);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3236
#include<bits/stdc++.h>
#define int long long 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define ld long double
#define ub upper_bound
#define lb lower_bound
#define pii pair<int,int>
using namespace std;
signed main()
{
    fast;
    int n,m;
    cin>>n>>m;
    if(m == n)
        cout<<"Yes";
    else cout<<"No";
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b; cin>>a>>b;
  string s; cin>>s;
  string ans="No";
  if(s[a]=='-'){
    string t=s.substr(0,a);
    string u=s.substr(a+1);
    if("0"<=t && t<="99999" && "0"<=u && u<="99999"){
      ans="Yes";
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int RLEN=1<<18|1;
inline char nc() {
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
    char ch=nc(); int i=0,f=1;
    while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
    while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
    return i*f;
}

const int N=1e5+50, INF=0x3f3f3f3f;
int n, k, li[N], ri[N], odd[N], ans[N];
#define L li
#define R ri
vector <int> edge[N];
inline void getans(int x,int f) {
    if(!f) {ans[x]=((li[x]&1)==odd[x]) ? li[x] : (li[x]+1);}
    else {ans[x]=ans[f]-1; if(ans[x]<li[x]) ans[x]+=2;}
    for(int e=edge[x].size()-1;e>=0;e--) {
        int v=edge[x][e]; if(v==f) continue;
        getans(v,x);
    }
}
inline void dfs_son(int x,int f) {
    for(int e=edge[x].size()-1;e>=0;e--) {
        int v=edge[x][e]; if(v==f) continue;
        dfs_son(v,x);
        R[x]=min(R[x],R[v]+1); L[x]=max(L[x],L[v]-1);
        if(~odd[v]) {
            if(!~odd[x]) odd[x]=(!odd[v]);
            else if(odd[x]==odd[v]) {
                puts("No");
                exit(0);
            }
        }
    }
}
inline void dfs_fa(int x,int f) {
    if(f) {
        R[x]=min(R[x], R[f]+1);
        L[x]=max(L[x], L[f]-1);
        if(~odd[x]) odd[x]=(!odd[f]);
    } 
    if((L[x]>R[x]) || (L[x]==R[x] && ((L[x]&1)!=odd[x]))) {
        puts("No"); exit(0);
    }
    for(int e=edge[x].size()-1;e>=0;e--) {
        int v=edge[x][e]; if(v==f) continue;
        dfs_fa(v,x);
    }
}
int main() {
    n=rd();
    for(int i=1;i<=n;i++) li[i]=-INF, ri[i]=INF, odd[i]=-1;
    for(int i=1;i<n;i++) {
        int x=rd(), y=rd();
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    k=rd();
    for(int i=1;i<=k;i++) {
        int x=rd(), v=rd();
        li[x]=ri[x]=v;
        odd[x]=(v&1);
    }
    if(!k) {
        li[1]=ri[1]=0; odd[1]=0;
        getans(1,0); puts("Yes");
        for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
    } else {
        dfs_son(1,0); 
        dfs_fa(1,0);
        getans(1,0);
        puts("Yes");
        for(int i=1;i<=n;i++) printf("%d\n",ans[i]);    
    }
}

Measured memory_bytes: 11904
# 四種類の塩基 A, C, G, T が存在し、A と T、C と G がそれぞれ対
# 文字 b が入力され A, C, G, T のいずれか
# 塩基 b と対になる塩基を表す文字を出力

b = input()

if b == 'A':
    print('T')
elif b == 'C':
    print('G')
elif b == 'G':
    print('C')
else:
    print('A')

Measured memory_bytes: 8844
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int D, N;
    cin >> D >> N;
    if (N == 100) {
        cout << "101" + string(D * 2, '0') << endl;
    } else {
        cout << N << string(D * 2, '0') << endl;
    }
    return 0;
}



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

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String K = scan.next();
    int p=0;
    int y[]=new int[3];
if(K.substring(0,1).equals("R")){y[0]=1;}

        if(K.substring(1,2).equals("R")){y[1]=1;}

        if(K.substring(2,3).equals("R")){y[2]=1;}

        if(y[0]==1||y[1]==1||y[2]==1){p=1;};
        if((y[0]==1&&y[1]==1)||(y[1]==1&&y[2]==1)){p=2;}
        if(y[0]==1&&y[1]==1&&y[2]==1){p=3;}

        System.out.println(p);
    }

}


Measured memory_bytes: 26836
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 200001;
int n, v[N];

int main(){
	scanf("%d", &n);
	for(int i = 0; i<n; ++i){scanf("%d", v+i);}
	int an = 0, ad = 0;
	for(int i = 0; i<n-1; ++i){
		if(v[i] >= v[i+1])++ad;
		else ad = 0;
		an = max(an,ad);
	}
	printf("%d\n",an);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define f(i,j,k) for(int i=j;i<k;i++)
int main(){
    long long n;
    cin>>n;
    long long nn=n/2;
    long long a[n];
    f(i,0,n){
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<a[nn]-a[nn-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
using System;

namespace Prob0002
{
    class Program
    {
        static void Main(string[] args)
        {
            // EOFまで1行ずつ読み込む
            string line;
            while((line = Console.ReadLine()) != null)
            {
                string[] tokens = line.Split(' ');
                int sum = int.Parse(tokens[0]) + int.Parse(tokens[1]);

                // 桁数数え上げ
                int digit = 1;
                sum /= 10;
                while(sum != 0)
                {
                    digit++;
                    sum /= 10;
                }

                Console.WriteLine(digit);
            }
        }
    }
}



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

int main() {
  int N;
  cin >> N;
  vector<int> points(N,1);

  vector<string> n(N);
  for(int i =0;i < N;i++){
    cin >> n.at(i);
  }

  int M;
  cin >> M;
  vector<string> m(M);
  for(int i=0; i < M; i++){
    cin >> m.at(i);
  }

  //ポイント加算区間
  for(int i =1; i < N; i++){
    if(n.at(0) == n.at(i)){
      points.at(0)++;
    }
  }
  for(int i = 1; i < N; i++){
     bool flag = true;
    //既出かどうかの判定
    for(int j = i - 1; j >= 0; j--){
      if(n.at(i) == n.at(j)){
        flag = false;
        break;
      }
    }
    if (flag){
      for(int k = i + 1; k < N; k++){
        if(n.at(i) == n.at(k)){
          points.at(i)++;
        }
      }
    }
  }


  //ポイント減算区間
  for(int i = 0;i < N; i++){
    for(int j =0; j < M; j++){
      if(n.at(i) == m.at(j)){
        points.at(i)--;
      }
    }
  }

  /*for(int i =0; i<N; i++){
    cout << points.at(i) <<endl;
  }*/
  int ans = points.at(0);
  for(int i =0; i<N; i++){
    if(ans < points.at(i)){
      ans = points.at(i);
    }
  }

  //cout << ans <<endl;

  if(ans <= 0){
    cout << "0" << endl;
  }
  else{
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
int a[5];
using namespace std;
int main()
{
 for(int i=1;i<=3;i++)
 {
     scanf("%d",&a[i]);
 }
    sort(a+1,a+4);
    printf("%d\n",a[1]+a[2]);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>
#include <set>
#include <unordered_map>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

void judge_outer(bool judge_exp,string ok = "Yes",string ng = "No"){
    if(judge_exp){
        cout << ok << endl;
    }else{
        cout << ng << endl;
    }
}


int main(void){
    string a;
    cin >> a;
    judge_outer(a[0] != a[1] && a[0] != a[2] && a[2] != a[1]);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
long long x, cnt;
double a=100;
int main(){
	scanf("%lld", &x);
	for(;a<x;){
		a=a*(1.01);
		a=floor(a);
		//cout<< a<< endl;
		cnt++;
	}
	printf("%lld", cnt);
	//cout<< cnt;
	return 0;
}

Measured memory_bytes: 3808
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

typedef long long int tint;

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

	tint n, k; cin >> n >> k;

	tint res = 0;
	forsn(i, k + 1, n + 1) {
		for (int j = 0;j <= n;j += i) {
			res += max(0LL, min(i - k, n - j + 1 - k));
		}
		res -= k == 0;
	}
	
	cout << res << endl;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;  // or pb_ds;

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#ifndef DEBUG
#define endl "\n"
#endif
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

template <typename T, typename B = null_type>
using oset =
    tree<T, B, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order / order_of_key

const ld eps = 1e-12;

/*-----------------END TEMPLATE-----------------*/

vi vals;
vi valsR;

int(((((((((((((((main)))))))))))))))() {
  FASTIO;
  ll n;
  cin >> n;
  if (n % 2 == 1) n *= 2;
  cout << n << endl;
}

/*

0 1 2 3 4
      x

*/

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		List<Integer> list = new ArrayList<>();
		List<Integer> subList = new ArrayList<>();

		for (int i = 0; i < m; i++) {
			int x = sc.nextInt();

			list.add(x);

		}
		if (n > m) {
			System.out.println(0);
			sc.close();
			return;
		}
		Collections.sort(list);

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

			int low = list.get(i);
			int high = list.get(i + 1);

			int sub = high - low;

			subList.add(sub);

		}

		Collections.sort(subList);
		Collections.reverse(subList);

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

			subList.remove(0);

		}
		int ans = subList.stream().mapToInt(Integer::valueOf).sum();

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 64208
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main(){
    string s;
    cin >> s;
    if(s[0]==s[1]&&s[1]==s[2]) cout  << "No" << endl;
    else cout << "Yes" <<endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
import collections
n=int(input())
l=sorted(list(map(int,input().split())))
a=sorted(list(set(l)))
num=len(a)
d=collections.Counter(l)
ans=0
for i in range(num-2):
  for j in range(i+1,num-1):
    c=a[i]+a[j]
    K= bisect.bisect_left(a, c)
    for k in range(j+1,K):
      ans+=d[a[i]]*d[a[j]]*d[a[k]]
print(ans)

Measured memory_bytes: 68460
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main(){ 
  int a,b=0,c=0;cin>>a;
  vector<int>d(a);
  rep(i,a)cin>>d[i];
  while(1){
    c++;
    b=d[b]-1;
    if(b==1||c>a)break;
  }
  if(c==a+1)cout<<-1;
  else cout<<c;
  }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
	int i = 0;
	int l;
	int flg=0;
	string S;
	cin >> S;
	l = S.size();
        while((i + 4) < l) {
		flg = 0;
		if (S.at(i) == 'd') {
			if (S.at(i+1) != 'r') break;
			if (S.at(i+2) != 'e') break;
			if (S.at(i+3) != 'a') break;
			if (S.at(i+4) != 'm') break;
			flg = 1;
			if((i + 6) < l) {
				if(S.at(i+5) == 'e' && S.at(i+6) == 'r') {
					if((i + 9) < l) {
						if (S.at(i+7) == 'a' && S.at(i+8) == 's'&& S.at(i+9) == 'e') {
							i+=5;
						}
						else {
							i+=7;
						}
					}
					else {
						i+=7;
					}
				}
				else {
					i+=5;
				}
			}
			else {
				i+=5;
			}
		}
		else if (S.at(i) == 'e') {
			if (S.at(i+1) != 'r') break;
			if (S.at(i+2) != 'a') break;
			if (S.at(i+3) != 's') break;
			if (S.at(i+4) != 'e') break;
			flg = 1;
			if((i + 5) < l) {
				if(S.at(i+5) == 'r') {
					i+=6;
				}
				else {
					i+=5;
				}
			}
			else {
				i+=5;
			}
		}
		else {
			break;
		}
	}
	if(i == l && flg == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 512
import numpy as np

N,M=map(int,input().strip().split())
PY=np.array([list(map(int,input().strip().split())) for _ in range(M)])

l=[[] for n in range(N)]
for m in range(M):
    l[PY[m,0]-1].append(PY[m,1])

dp={}
for n in range(N):
    if l[n]:
        l[n].sort()
        for i in range(len(l[n])):
            city="000000"+str(n+1)
            num="000000"+str(i+1)
            dp[(n,l[n][i]-1)]=str(city[-6:]+num[-6:])
for m in range(M):
    print(dp[(PY[m,0]-1,PY[m,1]-1)])

Measured memory_bytes: 67072
import sys

input = sys.stdin.readline

P = 10 ** 9 + 7
Q = 13


def main():
    S = input().rstrip()

    N = len(S)
    dp = [[0] * Q for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        base = pow(10, N - 1 - i, Q)
        D = S[i]
        if D == "?":
            for d in range(10):
                n = d * base
                for j in range(Q):
                    next_j = (j + n) % Q
                    dp[i + 1][next_j] += dp[i][j]
                    dp[i + 1][next_j] %= P
        else:
            n = int(D) * base
            for j in range(Q):
                next_j = (j + n) % Q
                dp[i + 1][(j + n) % Q] += dp[i][j]
                dp[i + 1][(j + n) % Q] %= P

    ans = dp[N][5]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 96168
import math
N=int(input())

A=N
B=1

sqrtN=int(math.sqrt(N))+1
#print(sqrtN)
for i in range(sqrtN,0,-1):
    if(N%i==0):
        A=i
        B=N//i
        break

#print("{} {}".format(A,B))
order=max(int(math.log10(A))+1,int(math.log10(B))+1)

print(order)


Measured memory_bytes: 3060
use std::cmp;
const MOD: usize = 998244353;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let s = sc
        .chars()
        .into_iter()
        .map(|c| c as usize - '0' as usize)
        .collect::<Vec<_>>();
    let n = s.len();

    let mut dp = vec![0; 2 * n + 1];
    dp[s[0]] = 1;
    for turn in 0..(2 * n) {
        let mut next = vec![0; 2 * n + 1];
        let total = 2 * cmp::min(turn + 1, n) - turn;
        let add = if turn + 1 < n { s[turn + 1] } else { 0 };
        for red in 0..(total + 1) {
            let blue = total - red;
            if red > 0 {
                next[red + add - 1] += dp[red];
                next[red + add - 1] %= MOD;
            }
            if blue > 0 {
                next[red + add] += dp[red];
                next[red + add] %= MOD;
            }
        }
        dp = next;
    }

    println!("{}", dp[0]);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
vector<ll> g[ohara];
ll vi[ohara];
unordered_map<ll,ll> used;
ll ha[ohara];
ll ha_cou=0;
ll dp[ohara];
vector<ll> gyaku[ohara];

//-------------------------↓↓↓↓↓↓------------------------

ll dfs(ll parent,ll now){
    ll depth=0;
    rep(i,Size(g[now])){
        depth=max(dfs(now,g[now][i]),depth);
    }
    //cerr<<now+1<<" "<<depth<<"\n";
    if(depth==k-1){
        if(parent!=0)ans++;
        return 0;
    }
    else return depth+1;
}

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

    cin>>n>>k;
    rep(i,n)cin>>a[i];
    if(a[0]!=1)ans=1;
    rrep(i,1,n){
         g[a[i]-1].push_back(i);
         gyaku[i].push_back(a[i]-1);
    }
    dfs(0LL,0LL);
    Cout(ans);
    return 0;
}


Measured memory_bytes: 67584
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int N;
int s[101];
int dp[10010];
/**********************************/

void dpSol() {
    DOWN(i, N, 1) {
        s[i] = s[i-1];
    }
    dp[0] = true;
    UP(i, 1, N) {
        DOWN(j, 10000, 0) {
            if(dp[j]) {
                dp[j+s[i]] = true;
            }
        }
    }
    int ans = 0;
    UP(i, 1, 10000) {
        if(dp[i]&&i%10!=0) {
            ans = max(ans, i);
        }
    }
    cout << ans << endl;
}

void mySol() {
    int mini = 1<<30;
    int sum = 0;
    REP(i, N) {
        sum += s[i];
        if(s[i]%10!=0&&s[i]<mini) {
            mini = s[i];
        }
    }
    if(sum%10!=0) {
        cout << sum << endl;
    }
    else if(mini!= 1<<30) {
        cout << sum - mini << endl;
    }
    else {
        cout << 0 << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N;
    REP(i, N) cin >> s[i];

    //mySol();
    dpSol();
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n; double x[100000], y[100000];
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        scanf("%lf", &x[i]);
        scanf("%lf", &y[i]);
    }
    
    pair<double, double> p1[100000], p2[100000];
    
    for(int i = 0; i < n; i++)
    {
        p1[i] = make_pair(x[i], y[i]);
    }
    
    for(int i = 0; i < n; i++)
    {
        p2[i] = make_pair(y[i], x[i]);
    }
    
    sort(p1, p1 + n);
    sort(p2, p2 + n);
    
    double sqr_ans = 100000000.0;
    
    for(int i = 0; i < n - 1; i++)
    {
        int r = min(5000, n - i - 1);
        
        for(int j = 1; j <= r; j++)
        {
            double distance_ = (p1[i + j].first - p1[i].first) * (p1[i + j].first - p1[i].first) + (p1[i + j].second - p1[i].second) * (p1[i + j].second - p1[i].second);
        
            sqr_ans = min(distance_, sqr_ans);
        }
    }
    
    for(int i = 0; i < n - 1; i++)
    {
        int r = min(5000, n - i - 1);
        
        for(int j = 1; j <= r; j++)
        {
            double distance_ = (p2[i + 1].first - p2[i].first) * (p2[i + 1].first - p2[i].first) + (p2[i + 1].second - p2[i].second) * (p2[i + 1].second - p2[i].second);
        
            sqr_ans = min(distance_, sqr_ans);
        }
    }
    
    printf("%.15f\n", sqrt(sqr_ans));
    
    return 0;
}

Measured memory_bytes: 7440
#include<iostream>
#include<algorithm>
#define NUM 256
using namespace std;

int dp[20001][NUM];

int main(){
  int n,m;
  while(cin>>n>>m,n){
    for(int i=0;i<=n;i++)
      for(int j=0;j<NUM;j++)
	dp[i][j]=1<<30;
    dp[0][128]=0;
    int c[m],x[n];
    for(int i=0;i<m;i++)cin>>c[i];
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<n;i++){
      for(int j=0;j<NUM;j++){
	for(int k=0;k<m;k++){
	  if(j+c[k]<=0){
	    dp[i+1][0]=min(dp[i+1][0],dp[i][j] + x[i]*x[i]);
	  }else if(j+c[k]>=255){
	    dp[i+1][255]=min(dp[i+1][255],dp[i][j] + (x[i]-255)*(x[i]-255));
	  }else{
	    dp[i+1][j+c[k]]=min(dp[i+1][j+c[k]],dp[i][j] + (x[i]-j-c[k])*(x[i]-j-c[k]));
	  }
	}
      }
    }
    // for(int j=0;j<256;j++){
    //   for(int i=0;i<n;i++){
    // 	cout << dp[i][j] << " ";
    //   }
    //   cout << endl;
    // }

    int res=1<<30;
    for(int i=0;i<NUM;i++)res=min(res,dp[n][i]);
    cout << res << endl;
  }
  return 0;
}

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

int main() {
   std::string N;
   std::cin >> N;
   long long M = 0;
   for (long long i = 0; i < N.size(); i++) {
      // std::cout << (int)N.at(i) - 48 << '\n';
      M += (int)N.at(i) - 48;
   }
   // std::cout << M << '\n';
   if (M % 9 == 0) {
      std::cout << "Yes" << '\n';
   } else {
      std::cout << "No" << '\n';
   }
   return 0;
}


Measured memory_bytes: 3716
#include <stdio.h>
int main(){
  int i,sum,n;

  while(1){
    scanf("%d",&sum);
    if(sum == 0) break;
    for(i=0;i<9;i++){
      scanf("%d",&n);
      sum -= n;
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 600
I = int(input())

pt = px = py = 0
for i in range(I):
    t, x, y = map(int, input().split())

    costtime = abs(t - pt)
    distance = abs(x - px) + abs(y - py)

    if costtime%2 != distance%2:
        print("No")
        exit()

    if costtime < distance:
        print("No")
        exit()

    pt,px,py = t,x,y

print("Yes")


Measured memory_bytes: 9168
#include <iostream>

using namespace std;

struct Node {
    int key;
    Node *parent=nullptr;
    Node *left= nullptr;
    Node *right= nullptr;
};

#define NIL nullptr
Node *root;

void insert(int key) {
    Node *y = nullptr;
    Node *x = root;

    while (x != NIL) {
        y = x;
        if (key < x->key) {
            x = x->left;
        } else if (key > x->key) {
            x = x->right;
        }
    }
    Node *z = new Node;
    z->key=key;
    z->parent=y;


    if (y==NIL) {
        root = z;
    } else if (z->key < y->key) {
        y->left = z;
    } else if (z->key > y->key){
        y->right = z;
    }
}

void print_pre_order(Node* r) {
    if (r==NIL) return;
    cout << " " << r->key;
    print_pre_order(r->left);
    print_pre_order(r->right);
}

void print_middle_order(Node* r) {
    if (r==NIL) return;
    print_middle_order(r->left);
    cout << " " << r->key;
    print_middle_order(r->right);
}

int main() {
    int n, key;
    string cmd;

    cin >> n;

    for (int j=0; j < n; j++) {
        cin >> cmd;
        if (cmd == "insert") {
            cin >> key;
            insert(key);
        } else {
            print_middle_order(root);
            cout << endl;

            print_pre_order(root);
            cout << endl;
        }
    }
    return 0;
}


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

const int limit = 50;
int n, m;
int a[limit], b[limit];
bool graph[limit][limit];
bool visited[limit];

void dfs(int v) {
    visited[v] = true;
    for (int v2 = 0; v2 < n; ++v2) { //頂点v2は、頂点vに隣接しているかつ未訪問ならdfsするループ
        if (graph[v][v2] == false) continue; //隣接してなかったらdfsしない
        if (visited[v2] == true) continue; //未訪問だったらdfsしない
        dfs(v2);
    }
}

int main(void) {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--; //0スタートにするため
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true; //グラフを作る a-b辺はb-a辺でもある
    }

    int ans = 0;
    for (int i = 0; i < m; ++i) {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false; //一つ辺を決めてfalseにする
        for (int j = 0; j < n; ++j) visited[j] = false; //visitedを初期化
        dfs(0); //0スタートで、グラフが連結か判定
        bool bridge = false; //非連結になる辺であればtrue
        for (int j = 0; j < n; ++j)
            if (visited[j] == false) bridge = true; //グラフの全部の頂点が辿れなければ非連結
        if (bridge) ans += 1; //非連結をカウント
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true; //最初にfalseにした辺をtrueに戻す
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int a,b,c,d,e,f;
	cin >>a>>b>>c>>d>>e>>f;


	double con = 0.0;
	int water = 0,sugar = 0;
	for(int w = 0; w <=10; w++){
		for(int x = 0; x <= 10; x++){
			for(int y = 0; y <= 3000; y++){
				for(int z = 0; z <= 3000; z++){
					int water_weight = a*w+b*x, sugar_weight = c*y+d*z;
					int total = 100*water_weight + sugar_weight;
					if(total <= f && sugar_weight <= water_weight*e){
						if(con < (double)sugar_weight/total){
							con = (double)sugar_weight/total;
							water = 100*water_weight;
							sugar = sugar_weight;
						}
					}
				}
			}
		}
	}
  if(con == 0) water = 100*a;

	cout << water+sugar << " " << sugar << endl;

	return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S)

ans = 0
for i in range(2**(N-1)):
    num = int(S[0])
    for j in range(N-1):
        if i & (1<<j) > 0:
            ans += num
            num = int(S[j+1])
        else:
            num *= 10
            num += int(S[j+1])
    ans += num

print(ans)

Measured memory_bytes: 3188
def solve(A,B,C,D,S):  
  if S[C-1] == "#" or S[D-1] == "#" or "##" in S[A:C-1]or "##" in S[B:D-1]:
    print("No")
    exit()
  if (D<C):
    if "..." not in S[B-2:D+1]:
      print("No")
      exit()
  print("Yes")

N, A, B, C, D = map(int, input().split())
S = input()
solve(A,B,C,D,S)

Measured memory_bytes: 3636
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
#include<set>
#include<vector>
using namespace std;
int main(){

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





return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int N;
int A[5001];
int B[5001];
int C[5001];
int D[5001];
int team[101];
int main()
{
  cin >>N;
  for(int i = 1;i <= N*(N-1)/2;i++){
    cin>>A[i]>>B[i]>>C[i]>>D[i];
    if(C[i] >D[i]){
      team[A[i]] +=3;
    }else if(C[i] <D[i]){
      team[B[i]] +=3;
    }else{
      team[A[i]]++;
      team[B[i]]++;
    }   
  }
  int score[101] ={0};
  int k = 1;
    for(int n = 1;n <=N+1;n++){
      int tempmax = -1;
      bool flag1 = false;
      for(int i =1;i <=N;i++){
	if(tempmax <team[i]){
	  tempmax = team[i];
	  flag1 =true;
	}
      }
    if(!flag1){
       for(int l = 1;l <=N;l++){
	  cout <<score[l]<<endl;
      }
       return 0;
    }
    bool flag =false;
    int kasan = 0;

    for(int j = 1;j <=N;j++){
    if(tempmax ==team[j]){
      if(flag =true){
	kasan++;
      }
      score[j] = k;
      team[j] =team[j]-(tempmax+2);
      flag = true;
    }
    }
    k+=kasan;
    }
  return 0;
}

Measured memory_bytes: 1236
/*author: hyperion_1724
  date: 
*/

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(int i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(int a=b;a<c;a++)
#define FORD(a,b,c) for(int a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

	READV(N);
	READV(D);
	ld A[N][D];
	FORI(i,0,N)
	{
		FORI(j,0,D)
		{
			READ(A[i][j]);
		}
	}
	ll ans=0;
	FORI(i,0,N-1)
	{
		FORI(j,i+1,N)
		{
			ld dis=0;
			FORI(k,0,D)
			{
				dis+=(A[j][k]-A[i][k])*(A[j][k]-A[i][k]);
			}
			dis=sqrt(dis);
			if (dis==floor(dis))
			{
				ans++;
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}

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

using namespace std;


signed main() {

    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    long long n;
    cin >> n;
    cout << n *(n - 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    String parametreImage = scan.nextLine();
    String[] parametre = parametreImage.split(" ");

    int hauteur = Integer.parseInt(parametre[0]);
    int largeur = Integer.parseInt(parametre[1]);

    String[] image = new String[hauteur];

    for (int i = 0; i < hauteur; i++){
      image[i] = scan.nextLine();
    }


    for (int j = 0; j < hauteur; j++){
      System.out.println(image[j]);
      System.out.println(image[j]);
    }



  }

}


Measured memory_bytes: 11596
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
namespace SOLVE {
	VI w;
	VI dp;

	void main() {
		int n, k;
		cin >> n >> k;
		w.resize(n + k + 5);
		dp.resize(n + k + 5);
		fill(dp.begin(), dp.end(), 1000000000);

		REP(i, 1, n + 1) {
			cin >> w[i];
		}
		dp[1] = 0;
		REP(i, 1, n + 1) {
			REP(j, 1, k + 1) {
				dp[i + j] = min(dp[i + j], dp[i] + abs(w[i] - w[i + j]));
			}
		}
		cout << dp[n];
	}
}


signed main() {

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define S second
#define F first

using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
const int maxn = 1e5 + 10;
vector<pii> g[maxn];
int vis[maxn];
int p[maxn];
int deg[maxn];
int dfs(int u){
    vis[u]  = 1;
    for (pii e : g[u]){
        if (vis[e.F]) continue;
        p[e.F] = p[u] + e.S;
        dfs(e.F);
    }
    vis[u] = 2;
}
int32_t main(){
    int n,m;
    cin >> n >> m;
    vector<pair<pii,int> > v;
    for (int i = 0;i < m;i++){
        int l,r,x;
        cin >> l >> r >> x;
        g[l].pb({r,x});
        v.pb({{l,r},x});
        deg[r]++;
    }
    for (int i = 1;i <= n;i++){
        if (deg[i] != 0) continue;
        if (vis[i] == 0){
            dfs(i);
        }
    }
    for (int i = 0;i < v.size();i++){
        if (p[v[i].F.S] - p[v[i].F.F] != v[i].S){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 15788
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n , d;
    cin >> n >> d;
    ll foo = 2*d + 1 ;
    ll rem = n % foo ;
    ll q = n / foo ;
    if(rem  == 0){
        cout << q <<el ;
        ro ;
    }
    else {
        ++q ;
        cout << q << el ;
        ro ;
    }
}































Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	ll N, T;
	cin >> N >> T;
	ll a[N], total = 0;
	
	rep(N){
		cin >> a[i];
	}
	
	rep(N-1){
		total += min(a[i+1] - a[i], T);
	}
	total += T;
	
	cout << total;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>

int main()
{
  using namespace std;
  int a, b, max;
  vector<int> v;

  cin >> a >> b;
  v.push_back(a+b);
  v.push_back(a-b);
  v.push_back(a*b);

  max = -99999;	
  for (auto it = v.begin(); it != v.end(); it++) {
    if (max < *it) max = *it;
  }

  cout << max << endl;

  return 0;
}


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

using namespace std;

int main() {
	int charList[26];
	for (int i = 0; i < 26; i++) {
		charList[i] = 0;
	}

	string s;
	while (getline(cin, s)) {
		
		for (int i = 0; i < s.length(); i++) {
			s[i] = tolower(s[i]);
			int index = int(s[i] - 97);
			charList[index] += 1;
		}
	}
	
	

	char title = 97;
	for (int i = 0; i < 26; i++) {
		cout << char(title + i);
		cout << " : ";
		cout << charList[i]<<endl;
	}


	return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
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; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll K, N;
	cin >> K >> N;

	vector<ll> A(N);
	for (ll i = 0; i < N; ++i) cin >> A[i];

	ll sum_d = 0;
	ll max_d = -1;
	for (ll i = 0; i < N - 1; ++i)
	{
		ll d = A[i + 1] - A[i];
		sum_d += d;
		max_d = max(max_d, d);
	}

	ll d = A[0] + K - A[N - 1];
	sum_d += d;
	max_d = max(max_d, d);

	ll ans = sum_d - max_d;

	cout << ans << endl;
}


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

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main() {
  int N; cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; ++i) cin >> a[i];
  
  vector<int> left(N+1, 0), right(N+1,0);
  for(int i=0; i<N; ++i) left[i+1] = GCD(left[i], a[i]);
  for(int i= N-1; i>=0; --i) right[i] = GCD(right[i+1], a[i]);
  
  int res = 0;
  for(int i=0; i<N; ++i) {
    int l = left[i];
    int r = right[i+1];
    chmax(res, GCD(l,r));
  }
  cout << res << endl;
}


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

string concat(long long a,long long t)
{
    string ret = "";
    for(int i=0;i<t;++i)ret += ('0'+a);
    return ret;
}
void solve(long long a, long long b){
    auto s1 = concat(a,b);
    auto s2 = concat(b,a);
    if(s1<s2)cout<<s1<<endl;else cout<<s2<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

ll rec(ll n, ll x) {
  ll all = (1LL << n + 1) - 3;
  ll p = (1LL << n) - 1;
  if (x == 0)
    return 0;
  else if (x <= all + 1)
    return rec(n - 1, x - 1);
  else if (x <= all + 2)
    return p + 1;
  else if (x <= 2 * (all + 1))
    return p + 1 + rec(n - 1, x - all - 2);
  else
    return p * 2 + 1;
}

int main() {
  ll n, x;
  cin >> n >> x;

  cout << rec(n, x) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int n,q,A[20];

int solve(i,m){
  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;
  if(res = solve(i+1,m)) return res;
  if(res = solve(i+1,m-A[i])) return res;;
  return res;
}


int main(){
  int i,M[200],check,a;
  scanf("%d",&n);
  for(i=0; i<n; i++)  scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++)  scanf("%d",&M[i]);

  for(i=0; i<q; i++){
    check = solve(0,M[i]);
    if(check == 1) printf("yes\n");
    else if(check == 0) printf("no\n");
  }

  return 0;

}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n)for((i)=0;(i)<(int)(n);(i)++)
#define _abs(x) ((x)>0?(x):-(x))
bool between(ll x,ll y1,ll y2){
  if(y1>y2)swap(y1,y2);
  y1++;y2--;
  if(!(y1<=y2))return false;
  while(x> 0){
    if(x% 3 == 1){
      if(y2-y1> 3)return true;
      for(ll y=y1;y<=y2;y++)if(y% 3 == 1)return true;
    }
    x/= 3;y1/= 3;y2/= 3;
  }
  return false;
}
ll get_extra(ll x1,ll y1,ll x2,ll y2){
  ll ans= 0;int i;ll three= 1;
  REP(i,35){
    if(x1/three==x2/three&&between(x1/three,y1/three,y2/three)){
      ll tmp=min(min(x1%three,x2%three) + 1,three-max(x1%three,x2%three));
      ans=max(ans,tmp);
    }
    three*= 3;
  }
  return ans;
}
ll get_dist(ll x1,ll y1,ll x2,ll y2){
  return _abs(x1-x2) +_abs(y1-y2) + 2 *max(get_extra(x1,y1,x2,y2),get_extra(y1,x1,y2,x2));
}
int main(){
  int Q;
  cin >> Q;
  for(int i=0; i<Q; ++i){
    ll a, b, c, d;
    cin>>a>>b>>c>>d;
    --a;--b;--c;--d;
    cout<< get_dist(a,b,c,d) << endl;
  }
}

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

int main(void){
    int A,B,m;
    cin>>A>>B>>m;
    int a[A];
    int b[B];
    for (int i = 0; i<A;i++){
        cin>>a[i];
    }
    for (int i = 0; i<B;i++){
        cin>>b[i];
    }
    
    int x[m];
    int y[m];
    int c[m];
    
    for (int i = 0; i<m;i++){
        cin>>x[i]>>y[i]>>c[i];
    }
    
    int ans = 1010001000;
    for (int i = 0; i<m;i++){
        ans = min({ans,a[x[i]-1]+b[y[i]-1] -c[i]});
    }

    sort(a,a+A);sort(b,b+B);
    
    ans = min({ans,a[0]+b[0]});
    
    cout<<ans;
}


Measured memory_bytes: 2176