akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long int 
#define pb  push_back
#define mp  make_pair
#define pii pair<int, int>
using namespace std;

const ll mod = 1e9+7;
const int N = 1e5;
ll dp[N+1][2] = {0};
vector<vector<int>> adj(N+1);

ll dp_recurse(int node, int color, int parent){
	if(adj[node].size()==1 && adj[node][0] == parent){
		return 1;
	}

	if(dp[node][color] != 0){
		return dp[node][color];
	}

	ll sum = 0;
	ll global_sum = 1;

	for(int i=0;i<adj[node].size();i++){
		if(adj[node][i] != parent){
			sum = (dp_recurse(adj[node][i], 0, node))%mod;
			if(color == 0){
				sum = (sum + dp_recurse(adj[node][i], 1, node))%mod;
			}

			global_sum = (global_sum*sum)%mod;
		}
	}

	dp[node][color] = global_sum;
	//cout << node << " " << color << " " << global_sum << endl;
	return global_sum;
}
/*
ll power(ll a, ll x){
	if(x==0){
		return 1;
	}

	ll half = power(a, x/2);
	half = (half*half)%mod;

	if(x%2==1){
		half = (half*a)%mod;
	}

	return half;
}
*/
void solve(){
    //solve here//
	int n, x, y;
	


	cin >> n;
	//cout << "1" << endl;
	for(int i=0;i<n-1;i++){
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	//cout << "2" << endl;

	/*
	vector<int> fron;
	vector<int> next_fron;
	int check[N+1] = {0};

	fron.pb(1);
	int level = 0;
	ll sum[2] = {0, 1};

	next_fron.clear();
	while(fron.size() != 0){
		for(int i=0;i<fron.size();i++){
			int node = fron[i];
			//cout << node << endl;
			for(int j=0;j<adj[node].size();j++){
				int child = adj[node][j];
				if(check[child] == 0){
					next_fron.pb(child);
					sum[level%2]++;
				}
			}

			check[node] = 1;
		}

		level++;
		fron = next_fron;
		next_fron.clear();
	}

	cout << (power(2, sum[0]) + power(2, sum[1]) -1)%mod << endl;
	*/
	if(n==1){
		cout << "2" << endl;
		return;
	}
	cout << (dp_recurse(1, 0, 0) + dp_recurse(1, 1, 0))%mod << endl;

}


int main(){
    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }
}



Measured memory_bytes: 15616
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)
#define pb push_back

using namespace std;
const int N=200005,M=20;
bool ans[N];
int n,m,a[N],c;
int g1[M][N],g2[M][N],f1[1<<M],f2[1<<M];
vector <int> vt[N],Q[N];
struct data{int x,y;} dat[N];

int getint()
{
	char ch;
	int f=1;
	while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x*f;
}

int main()
{
	n=getint(),m=getint();
	rep(i,1,n) a[i]=getint();
	for(int x=m; ; x>>=1,++c)
	{
		int i=1,j=1;
		while(j+1<=n && a[j+1]-a[j]<=x) ++j;
		rep(k,1,n+1) g2[c][k]=n+1;
		rep(k,1,n)
		{
			if(k>j) i=j=k;
			while(j+1<=n && a[j+1]-a[j]<=x) ++j;
			if(!c) dat[k]=(data){i,j};
			else
			{
				g1[c][i]=max(g1[c][i],j);
				g2[c][j]=min(g2[c][j],i);
			}
		}
		g1[c][n+1]=n,g2[c][0]=1;
		rep(k,1,n) g1[c][i]=max(g1[c][i],g1[c][i-1]);
		repd(k,n,1) g2[c][i]=min(g2[c][i],g2[c][i+1]);
		if(!x) break;
	}
	rep(i,0,(1<<c)-1) f2[i]=n+1;
	rep(i,0,(1<<c)-1)
	{
		rep(j,0,c-1) if(!(i&(1<<j)))
		{
			f1[i|(1<<j)]=max(f1[i|(1<<j)],g1[j+1][f1[i]+1]);
			f2[i|(1<<j)]=min(f2[i|(1<<j)],g2[j+1][f2[i]-1]);
		}
	}
	int S=(1<<c)-1;
	rep(i,0,S)
	{
		int x=min(f1[i]+1,n);
		int y=max(f2[S^i]-1,1);
		vt[x].pb(y);
	}
	rep(i,1,n) Q[dat[i].x].pb(i);
	int p=n+1;
	repd(i,n,1)
	{
		int sz=vt[i].size();
		rep(j,0,sz-1) p=min(p,vt[i][j]);
		sz=Q[i].size();
		rep(j,0,sz-1) ans[Q[i][j]]=p<=dat[Q[i][j]].y;
	}
	rep(i,1,n) if(ans[i]) puts("Possible"); else puts("Impossible");
	return 0;
}
	

Measured memory_bytes: 51976
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String[] nk = scanner.nextLine().split(" ");
        int n = Integer.parseInt(nk[0]);
        int k = Integer.parseInt(nk[1]);
        String s = scanner.nextLine();

        List<Integer> a = new ArrayList<>();
        a.add(0);

        char current = s.charAt(0);
        for (int i = 1; i < n; i++) {

            if (s.charAt(i) != current) {
                a.add(i);
                current = s.charAt(i);
            }
        }
        a.add(s.length());


        int max = 0;


        for (int i = 0; i < a.size() - 1; i++) {

            int j = s.charAt(a.get(i)) == '0' ? i + 2 * k : i + 2 * k + 1;
            j = Math.min(j, a.size() - 1);

            int x = a.get(j) - a.get(i);

            if (x > max) {
                max = x;
            }
        }

        System.out.println(max);
    }
}

Measured memory_bytes: 27328
X,N=map(int,input().split())
p_list=list(map(int,input().split()))
f_list=list(range(102))
for i in p_list:
    f_list.remove(i)
ans=f_list[0]
for i in f_list:
    if abs(X-ans)>abs(X-i):
        ans=i
print(ans)

Measured memory_bytes: 61972
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const ll INF = 1e10;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


int main() {
    ll n, w;
    cin >> n >> w;
    vector<ll> weight(n);
    vector<ll> value(n);
    rep(i,n){
        cin >> weight.at(i) >> value.at(i);
    }
    vector<vector<ll>> dp(n+1, vector<ll>((n * 1000) + 1, INF));
    dp[0][0] = 0;

    for(ll i = 0; i < n; i++){
        for(ll j = 0; j <= n * 1000; j++){
            if(j - value[i] >= 0){
                dp[i+1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i]);
            }else{
                dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            }
        }
    }

    ll ans = 0;
    rep(i, n * 1000 + 1){
        if(dp[n][i] <= w){
            ans = i;
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 80256
k,x=map(int,input().split())

maxa=x+(k-1)
mina=x-(k-1)

if maxa>1000000:
  maxa=1000000
if mina<-1000000:
  mina=-1000000

a=[]
for i in range(mina,maxa+1):
  a.append(i)
  
for i in range(len(a)):
  print(a[i],end=" ")


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

using namespace std;

int main(void)
{
  int i, counter;
  string s;
  cin >> s;

  if (s[0] == 'o') counter++;
  if (s[1] == 'o') counter++;
  if (s[2] == 'o') counter++;

  cout << 700 + 100 * counter << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define m_p make_pair
#define sz(x) (int)x.size()
#define out(x) cerr<<#x<<" = "<<x<<" "
#define outln(x) cerr<<#x<<" = "<<x<<endl
#define outarr(x,l,r) cerr<<#x"["<<l<<"-"<<r<<"] = "; for (int _i=l;_i<=r;++_i) cerr<<x[_i]<<" ";cerr<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define gc() getchar()
//char buf[1<<23],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <class T> void read(T &x)
{
    x=0; char c=gc(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=gc();
    while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=gc();
    if (flag) x=-x;
}
template <class T> T _max(T a,T b){return a>b ? a : b;}
template <class T> T _min(T a,T b){return a<b ? a : b;}
template <class T> bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;}
template <class T> bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;}
const int N=100005;
int n,a[N],b[N],rnk[N<<1];
pii c[N<<1];
ll ans=0,pre[N<<1];
void init()
{
    read(n);
	for (int i=1;i<=n;++i)
	{
		read(a[i]); read(b[i]);
		c[i+i-1]=m_p(a[i],i+i-1);
		c[i+i]=m_p(b[i],i+i);
	}
	sort(c+1,c+n+n+1);
	for (int i=1;i<=n+n;++i)
	{
		rnk[c[i].second]=i;
	}
	//outarr(rnk,1,n+n);
}
 
void solve()
{
	ll tmp1=0,tmp2=0;
	for (int i=1;i<=n;++i)
	{
		tmp1+=a[i];
		tmp2+=b[i];
	}
	ans=_min(tmp1,tmp2);
	for (int i=1;i<=n;++i)
	{
		pre[i]=pre[i-1]+(ll)c[i].first;
	}
	for (int i=1;i<=n;++i)
	{
		if (rnk[i+i-1]<=n&&rnk[i+i]<=n)
		{
			checkmin(ans,pre[n]);
		}
		else if (rnk[i+i-1]>n&&rnk[i+i]>n)
		{
			checkmin(ans,pre[n-2]+a[i]+b[i]);
		}
		else if (rnk[i+i-1]<=n&&rnk[i+i]>n)
		{
			if (rnk[i+i-1]==n) checkmin(ans,pre[n-2]+a[i]+b[i]);
			else checkmin(ans,pre[n-1]+b[i]);
		}
		else
		{
			if (rnk[i+i]==n) checkmin(ans,pre[n-2]+a[i]+b[i]);
			else checkmin(ans,pre[n-1]+a[i]);
		}
	}
	printf("%lld\n",ans);
} 
       
#undef int
int main()
{
    int T=1;
    //read(T);
    while (T--)
    {
        init();
        solve();
    }
    return 0;
}


Measured memory_bytes: 7516
// Amsal Shoma Ro Gaedan Ye Amal Pasandidas !

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	ll d = abs(a - b);
	if(v <= w) cout << "NO\n";
	else {
		ll d2 = t * abs(v - w);
		cout << (d2 >= d ? "YES" : "NO") << '\n';
	}
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(){
  int n;
  vector<long long> v;
  cin >> n;
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  long long max_a = v.back();
  long long a, b;
  if (max_a % 2 == 0) {
    a = max_a/2;
    b = max_a/2;
  } else {
    a = max_a/2;
    b = max_a/2 + 1;
  }
  long long mindiff = max_a;
  long long r;
  for (auto it = v.begin();it != v.end();it++) {
    long long da = llabs(*it - a);
    long long db = llabs(*it - b);
    long long d = da < db?da:db;
    if (*it == max_a) {
      break;
    }
    if (d <= mindiff) {
      mindiff = d;
      r = *it;
    }
  }
  cout << max_a << " " << r << endl;
  return(0);
}


Measured memory_bytes: 1400
//written by libra9z
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cmath>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define repit(it,a) for (__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define ITR(...) __VA_ARGS__::iterator
#define all(a) (a).begin(),(a).end()
#define reunique(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define sz(a) (int)a.size()
#define MP(...) make_pair(__VA_ARGS__)
#define X first
#define Y second
#define sqr(x) ((x)*(x))
#define fill_inf(a) memset(a,-19999873,sizeof(a))
#define fill_neginf(a) memset(a,-19999872,sizeof(a))
#define fill_0(a) memset(a,0,sizeof(a))
#define fill_neg1(a) memset(a,-1,sizeof(a))
#define pow_of_2(a) (1<<(a))
#define is_pow_of_2(a) (((a-1)&a)==0)
#define printtime cerr<<"\n\nTime elasped : "<<clock()*1.0/1000<<" seconds.\n\n"
using ll=long long;
const int inf=1e9;
const ll lnf=1e18;
const int mod=1e9+7;
int n,a[200005],nx[200005]={200004},dp[200005],x;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cout<<setprecision(15);
	cin>>n;
	for (int i=0;i<n;++i) cin>>a[i],nx[a[i]]=i;
	for (int i=0;i<n;++i) dp[i]=dp[nx[a[i]-1]]+1;
	for (int i=0;i<n;++i) x=max(x,dp[i]);
	cout<<n-x<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main()
{
	int n, m, ai[200100], bi[200100], c, a, b;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		ai[i] = 0;
		bi[i] = 0;
	}
	for (int i = 0; i < m; i++)
	{
		cin >> a >> b;
		if (a == 1 || b == 1)
		{
			if (a == 1)
				ai[b - 1] = 1;
			else
				ai[a - 1] = 1;
		}
		else if (a == n || b == n)
		{
			if (a == n)
				bi[b - 1] = 1;
			else
				bi[a - 1] = 1;
		}
		else if (a == 1 || b == 1)
		{
			if (a == 1)
				ai[b - 1] = 1;
			else
				ai[a - 1] = 1;
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (ai[i] == 1 && bi[i] == 1)
		{
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
		cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] array = in.nextIntArray(n);

            Map<Integer, Integer> countMap = new HashMap<>();
            for (int i = 0; i < n; i++) {
                for (int j = -1; j <= 1; j++) {
                    countMap.merge(array[i] + j, 1, Integer::sum);
                }
            }

            int ans = 0;
            for (int count : countMap.values()) {
                ans = Math.max(ans, count);
            }

            out.println(ans);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 45492
// Copyright 2017 wu_qing
#include <cstdio>
#include <bitset>
#include <algorithm>
const int N = 5e3 + 10;
std::bitset<N> b;
int n, k, t, l, r, cnt, a[N];
inline bool check(int x) {
    b.reset();
    b[0] = 1;
    for (int i = 1; i <= cnt; i++) {
        if (i == x) continue;
        b |= b << a[i];
    }
    for (int i = k - a[x]; i < k; i++)
        if (b[i])
            return true;
    return false;
}
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &t);
        if (t <= k)
            a[++cnt] = t;
    }
    std::sort(a + 1, a + cnt + 1);
    l = 0;
    r = cnt;
    while (l < r) {
        int m = (l + r) / 2;
        if (check(m + 1))
            r = m;
        else
            l = m + 1;
    }
    printf("%d\n", r);
    return 0;
}



Measured memory_bytes: 128
#include<stdio.h>
int n, ans, i;
int a[100001];
int main(void){
  scanf("%d", &n);
  for(i=1; i<=n; i++){
    scanf("%d", a+i);
    if(a[a[i]]==i){ans++;}
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int maxn=1005;
int ans[maxn][maxn]={};
int main(){
    int n,m,a,b;
    cin>>n>>m>>a>>b;
    for(int i=1;i<=b;++i){
        for(int j=1;j<=a;++j)
        ans[i][j]=1;
    }
    for(int i=b+1;i<=n;++i){
        for(int j=a+1;j<=m;++j)
            ans[i][j]=1;
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j)
            printf("%d",ans[i][j]);
        puts("");
    }
}


Measured memory_bytes: 5120
import itertools,sys,collections,math,random,fractions,bisect;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]
 
N, M = I()
x = itertools.combinations
print(len(list(x(range(N), 2))) + len(list(x(range(M), 2))))


Measured memory_bytes: 6056
import std.stdio;
import std.conv;
import std.numeric;

long f(long n, long c, long d) {
	return n - (n / c) - (n / d) + (n / (c * d / gcd(c, d)));
}

void main() {
	long a, b, c, d;
	scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
	write(f(b, c, d) - f(a-1, c, d));
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	ll i,n,x;
	cin>>n;
	map<string,ll>m;
	for0(i,n){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		m[s]++;
		}
	ll c=0;
	for(auto it:m){
		x = it.se;
		c += (x*(x-1))/2;
		}
	cout<<c<<nw;
	return 0;
}

Measured memory_bytes: 11136
# 貰うDP
n = int(input())
a = [1]
i = 6
while i <= n:
  a.append(i)
  i *= 6
i = 9
while i <= n:
  a.append(i)
  i *= 9
t = [0] * (n + 1)
for i in range(1, n + 1):
  k = float("inf")
  for j in a:
    if i - j >= 0 and k > t[i - j] + 1:
      k = t[i - j] + 1
  t[i] = k
print(t[n])


Measured memory_bytes: 3828
a, b, k = gets().chomp.split("\s").map{|x| x.to_i}

ar = a - k
ar = 0 if ar < 0

kr = k - a
if kr > 0
  br = b - kr
else
  br = b
end
br = 0 if br < 0

puts "#{ar} #{br}"  


Measured memory_bytes: 14332
N, K = map(int, input().split(" "))

LIM = int(N ** 0.5) * 2 + 1
dp = [[0] * LIM for i in range(K - 1)]

ts = set()
tsl = []
tsr = []
num = {}
for i in range(1, int(N ** 0.5) + 1):
    x = N // i
    y = N // (N // i)
    if not tsl or tsl[-1] > x:
        tsl.append(x)
    if x != y and (not tsr or tsr[-1] < y):
        tsr.append(y)
    if x not in num:
        num[x] = 0
    if y not in num:
        num[y] = 0
ts = tsl + tsr[::-1]

idx = {k: i for i, k in enumerate(ts)}
for j, t in enumerate(ts):
    num[t] = (N // t - N // ts[j-1]) if j > 0 else 1
    # print(t, num[t])
    dp[0][idx[t]] = num[t] * t


MOD = 1000000007
for i in range(1, K - 1):
    pref = 0
    for j in reversed(range(len(ts))):
        # R = idx[N // ts[j]]
        R = len(ts) - j - 1
        pref += dp[i-1][R]
        dp[i][j] = pref * num[ts[j]] % MOD
        # pref += dp[i-1][R] * num[ts[j]]

        # print(f"0 - {R}")
        # dp[i][j] = sum(dp[i-1][k] * num[ts[j]] for k in range(R + 1))
        # print(pref, dp[i][j])


# for x in dp:
    # print(x)
ans = sum(dp[-1])
print(ans % 1000000007)


Measured memory_bytes: 102760
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < a.length; ++i) {
            a[i] = sc.nextInt();
        }

        System.out.println(solve(a));

        sc.close();
    }

    static String solve(int[] a) {
        int minIndex = 0;
        int maxIndex = 0;
        for (int i = 1; i < a.length; ++i) {
            if (a[i] < a[minIndex]) {
                minIndex = i;
            }
            if (a[i] > a[maxIndex]) {
                maxIndex = i;
            }
        }

        List<String> operations = new ArrayList<>();
        if (a[minIndex] + a[maxIndex] >= 0) {
            for (int i = 0; i < a.length; ++i) {
                operations.add(String.format("%d %d", maxIndex + 1, i + 1));
            }

            for (int i = 0; i < a.length - 1; ++i) {
                operations.add(String.format("%d %d", i + 1, i + 2));
            }
        } else {
            for (int i = 0; i < a.length; ++i) {
                operations.add(String.format("%d %d", minIndex + 1, i + 1));
            }

            for (int i = a.length - 1; i >= 1; --i) {
                operations.add(String.format("%d %d", i + 1, i));
            }
        }

        return String.format("%d\n%s", operations.size(), String.join("\n", operations));
    }
}

Measured memory_bytes: 23764
N = int(input())
T = list(map(int, input().split()))
M = int(input())

P, X = [], []
for i in range(M):
    p1, x1 = map(int, input().split())
    P.append(p1)
    X.append(x1)

count = 0
for i in range(len(T)):
    count += T[i]

c = count

for i in range(M):
    count = c
    count += X[i]
    count -= T[P[i] - 1]
    print(count)

Measured memory_bytes: 3064
#include <cstdio>
#include <random>
using namespace std;

random_device rd;
mt19937 mt(rd());

template <class T>
struct tree
{
	struct node
	{
		T v;
		int c, p;
		node *n[2];

		node(T x)
		{
			v = x;
			c = 1;
			p = mt();
			n[0] = n[1] = nullptr;
		}
	};

	typedef node N;
	N *root;
	long counter;

	tree()
	{
		root = nullptr;
		counter = 0;
	}

	inline int count(N *n) {return n ? n->c : 0;}

	N* rotate(N* r, int b) 
	{
		N *s = r->n[1 - b];

		r->c += count(s->n[b]) - count(r->n[1 - b]);
		r->n[1 - b] = s->n[b];

		s->c += r->c - count(s->n[b]);
		s->n[b] = r;
		return s;
	}

	N* insert(int x, N *t, int cnt)
	{
		if (!t) {
			counter += cnt;
			return new N(x);
		}
		int b = !(x < t->v);
		if (b)
			cnt -= 1 + count(t->n[0]);
		t->n[b] = insert(x, t->n[b], cnt);
		t->c++;
		return t->p > t->n[b]->p ? rotate(t, 1 - b) : t;
	}

	void insert(T x)
	{
		root = insert(x, root, count(root));
	}
};

int main()
{
	int	n, x;
	scanf("%d", &n);

	tree<int> t;
	while (n--) {
		scanf("%d", &x);
		t.insert(x);
	}

	printf("%ld\n", t.counter);
}



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

int main(){
  int N;
  cin >> N;
  
  vector<double> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  
  double newValue = (vec.at(0) + vec.at(1)) / 2;
  
  for (int i = 2; i < N; i++) {
    newValue = (newValue + vec.at(i)) /2;
  }
  
  cout << fixed << setprecision(10);
  
  cout << newValue << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <tuple>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;


int main(void){
    int l,r;
    cin >> l >> r;
    int mi=2018*2018;
    for (int  i = l; i<r; i++)
    {   
        int L=i%2019;
        for (int j = i+1; j <= r; j++)
        {
            int R=j%2019;
            int ama=(L*R)%2019;
            if (ama<mi)
            {
                mi=ama;
                if (mi==0)
                {
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
    }
    cout << mi << endl;
    
}


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

int main() {
  int input;
  int a, b, c;
  
  cin >> input;
  
  a = input % 2;
  b = (input - a) / 10 % 2;
  c = (input - (a + 10 * b)) / 100 % 2;
  
  cout << a + b + c << endl;
  
}

Measured memory_bytes: 3644
#include<stdio.h>

main()
{
	int h,w;
	int i,j;
	
	do{
		scanf("%d %d",&h,&w);
		
		if(h == 0 && w == 0){
			break;
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}while(1);
	
	return 0;
}

Measured memory_bytes: 572
#include<iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a[1001];
int main(){
  while(cin>>n>>m,n){
    int ans=0;
    r(i,n)cin>>a[i];
    r(i,n)r(j,n)if(i!=j)
      if(a[i]+a[j]<=m)ans=max(ans,a[i]+a[j]);
    if(ans)cout<<ans<<endl;
    else cout<<"NONE"<<endl;
  }
}

Measured memory_bytes: 3084
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		for (int z = 0; z < q; z++) {
			int n = sc.nextInt();
			int r = 0;
			while (n / 10 > 0) {
				String s = Integer.toString(n);
				int max = 0;
				for (int i = 1; i < s.length(); i++) {
					int f = Integer.parseInt(s.substring(0, i));
					int e = Integer.parseInt(s.substring(i));
					int l = f * e;
					max = Math.max(max, l);
				}
				n = max;
				r++;
			}
			System.out.println(r);
		}
		sc.close();
	}
}

Measured memory_bytes: 23360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3 + 5, INF = 0x3f3f3f3f, M = N << 1;

int a[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  ll ans = 0;
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      for (int k = j + 1; k <= n; k++) {
        if (a[i] + a[j] <= a[k]) break;
        if (((a[i] + a[j]) > a[k]) && ((a[i] + a[k]) > a[j]) && ((a[j] + a[k]) > a[i])) ans++;
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
# 6,8,1,2,3
# 中央値である3から初めて、残りから最大→最小の繰り返しで貪欲に取る
# 3 8 1 6 2
# 最小->最大の順でやるのと両パターン試して、大きい方採用
#
# 3 1 4 1 5 9
# 1 1 3 4 5 9
# 偶数のときは、中央値も2パターン取って大きいのを採用
#
# 5 5 1
# 5 1 5

N=int(input())
A=[0] * N
for i in range(N):
  A[i] = int(input())
  
if N == 2:
  print(abs(A[0] - A[1]))
  exit(0)
  
A=sorted(A)

from collections import deque

def calc(A,first,flip):
  q = deque(A)
  ans = 0
  cur = first
  while q:
    if flip:
      a = q.popleft()
    else:
      a = q.pop()
    ans += abs(a - cur)
    cur = a
    flip^=True
  return ans

if N%2:
  # 奇数のとき
  mid = A.pop(N//2)
  ans1 = calc(A,mid,True)
  ans2 = calc(A,mid,False)
  print(max(ans1,ans2))
  
else:
  # 偶数のとき
  A2 = A.copy()
  mid1 = A.pop(N//2-1)
  ans1_1 = calc(A,mid1,True)
  ans1_2 = calc(A,mid1,False)
  
  mid2 = A2.pop(N//2)
  ans2_1 = calc(A2,mid2,True)
  ans2_2 = calc(A2,mid2,False)
  
  print(max(ans1_1,ans1_2,ans2_1,ans2_2))


Measured memory_bytes: 8856
cnt = 0
a, b, c = map(int, input().split())
while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    a, b, c = (b + c) / 2, (a + c) / 2, (b + a) / 2
    cnt += 1
    if cnt >= 10 ** 5:
        print(-1)
        exit()
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define NO {puts("No"); return 0;}
typedef long long ll;
using namespace std;
const int N = 100 + 10;
int n, m, f[26], cnt[4];
char st[N][N];

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		scanf("%s", st[i]);
		for (int j = 0; j < m; ++j)
			++f[st[i][j] - 'a'];
	}
	for (int i = 0; i < 26; ++i)
		++cnt[f[i] % 4];

	if ((n & 1) && (m & 1)) {
		if (cnt[1] + cnt[3] != 1) NO;
		if (!cnt[1]) --cnt[3], ++cnt[2];
		if (n / 2 + m / 2 < cnt[2]) NO;
	}
	else if ((n & 1) || (m & 1)) {
		if (cnt[1] || cnt[3]) NO;
		if (n & 1) {
			if (m / 2 < cnt[2]) NO;
		}
		else {
			if (n / 2 < cnt[2]) NO;
		}
	}
	else {
		if (cnt[1] || cnt[2] || cnt[3]) NO;
	}
	puts("Yes");
	return 0;
}

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

int main(void){
    string s;
    cin>>s;
    reverse(all(s));
    int n = s.size();
    int del = 0;
    rep(i,n){
        if(s[i]=='B'){
            del++;
        }else if(del>0){
            s[i] = 'B';
            del--;
        }
    }
    reverse(all(s));
    rep(i,n){
        if(s[i]!='B')cout<<s[i];
    }
    cout<<endl;
    return 0;
}


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

int main(void){
	double r;
	double L,S;
	double P=M_PI;

	cin >> r;
	L=2*r*P;
	S=r*r*P;
	cout<<fixed;
	cout.precision(6);
	cout << S << " " << L <<endl;
	return 0;
}

Measured memory_bytes: 1288
#include<stdio.h>
#include<math.h>
#define Max (int)1e5+10
#define MAX_INT (int)1e9+2

int dp[Max];
void init(){
	int i;
	for(i=0;i<Max;i++)
		dp[i] = 0;
}
void solve(int n,int a[]){
	int x,y,i;
	for(i=n-1;i>=0;i--){
		if(i+1 < n)
			x = dp[i+1]+fabs(a[i+1]-a[i]);
		else
			x = MAX_INT;
		
		if(i+2 < n)
			y = dp[i+2]+fabs(a[i+2]-a[i]);
		else
			y = MAX_INT;

		dp[i] = (x<y)?x:y;
		dp[i] = dp[i] == MAX_INT ? 0 : dp[i];
		//printf("%d %d %d %d\n",i,dp[i],x,y);
	}

}
int main(){
	int n,a[Max],i;
	
	init();
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);

	solve(n,a);
	printf("%d\n",dp[0]);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<int,int> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    vector<vector<char> > a(1010,vector<char>(1010));
    vector<int> dx={1,-1,0,0},dy={0,0,1,-1};
    vector<vector<int> > d(1010,vector<int>(1010,-1));
    queue<P> que;
    FOR(i,1,h+1){
      FOR(j,1,w+1){
        cin>>a[i][j];
        if(a[i][j]=='#'){
          que.push({i,j});
          d[i][j]=0;
        }
      }
    }
    while(!que.empty()){
      P p=que.front();
      que.pop();
      rep(i,4){
        int nx=p.first+dx[i],ny=p.second+dy[i];
        if(1<=nx && nx<=h && 1<=ny && ny<=w && d[nx][ny]==-1){
          d[nx][ny]=d[p.first][p.second]+1;
          que.push({nx,ny});
        }
      }
    }
    int ans=0;
    FOR(i,1,h+1){
      FOR(j,1,w+1){
        if(ans<d[i][j]) ans=d[i][j];
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 13456
#include<stdio.h>

int main(){
	double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
	
	while(0<=scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&xa1,&ya1,&xa2,&ya2,&xb1,&yb1,&xb2,&yb2)){
		
		if(xb2<xa1 || xa2<xb1 || yb2<ya1 || ya2<yb1){
			printf("NO\n");
			continue;
		}

		printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<list>

typedef long long ll;

using namespace std;

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

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

int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int a[10010];
	
	for(int i = 1 ; i<=n ; i++){
		cin>>a[i];
	}
	
	int ans = 1;
	for(int i = 1 ; i<=n ; i++){
		ans = lcm(ans,a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3208
N = int(input())
 
X = list(map(int, input().split()))
 
a = round((sum(X) / N), 3)
integer = int(a)
f = a - integer
 
if f < 0.5:
    P = integer
else:
    P = integer + 1
 
total = 0
for i in X:
    total += (i - P) ** 2
 
print(total)

Measured memory_bytes: 3064
N = int(input())
H = [0] + [int(i) for i in input().split()]

flg = True
for i in range(1, N + 1) :
    if H[i] != H[i-1] :
        H[i] -= 1
    if H[i] < H[i-1] :
        flg = False
        
if flg :
    print('Yes')
else :
    print('No')

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

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			Book[] books = new Book[N];
			for (int i = 0; i < N; ++i) {
				int r = sc.nextInt();
				int w = sc.nextInt();
				books[i] = new Book(r, w);
			}
			Arrays.sort(books);
			int sumR = 0;
			int sumW = 0;
			for (int i = 0; i < N; ++i) {
				sumR += books[i].r;
				sumW += books[i].w;
			}
			int maxR = books[N - 1].r;
			if (sumR - maxR < maxR) {
				int early = early(books, maxR - (sumR - maxR));
				System.out.println(Math.max(sumR + sumW, maxR * 2 + sumW - early));
			} else {
				System.out.println(sumR + sumW);
			}
		}
	}

	static int early(Book[] books, int time) {
		boolean[] ok = new boolean[time + 1];
		ok[0] = true;
		for (int i = 0; i < books.length - 1; ++i) {
			int w = books[i].w;
			for (int j = time; j - w >= 0; --j) {
				if (ok[j - w]) ok[j] = true;
			}
		}
		for (int i = time; i >= 0; --i) {
			if (ok[i]) return i;
		}
		return 0;
	}

	static class Book implements Comparable<Book> {
		int r, w;

		public Book(int r, int w) {
			this.r = r;
			this.w = w;
		}

		public int compareTo(Book o) {
			return this.r - o.r;
		}
	}

}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  int all = 0;
  rep(i,n) all ^= a[i];
  rep(i,n-1) cout << (all ^ a[i]) << " ";
  cout << (all ^ a.back()) << endl;
}

Measured memory_bytes: 3876
board = [['#']*8 for i in range(8)]
n = int(input())
v1=[0]*8
v2=[0]*8
v3=[0]*16
v4=[0]*16


def dot(y,x):
    for j in range(8):
        board[y][j]='.'
        board[j][x]='.'
    for i in range(1,min(x,y)+1):
        board[y-i][x-i]='.'
    for i in range(1,min(7-x,y)+1):
        board[y-i][x+i]='.'
    for i in range(1,min(x,7-y)+1):
        board[y+i][x-i]='.'
    for i in range(1,min(7-x,7-y)+1):
        board[y+i][x+i]='.'
    board[y][x]='Q'
st=set()
ans=[]

def dfs(now,k,stock):
    if now == 8:
        ans.append(list(stock))
        return stock
    if not li[now]:
        dfs(now+1,k,stock)
    for i in li[now]:
        x,y1,y2=i
        if v2[x]==0 and v3[y1+7]==0 and v4[y2]==0:
            stock.add((now,x))
            v2[x]=1
            v3[y1+7]=1
            v4[y2]=1
            dfs(now+1,k,stock)
            v2[x]=0
            v3[y1+7]=0
            v4[y2]=0
            stock.remove((now,x))

for i in range(n):
    y , x = map(int, input().split())
    dot(y,x)
    v1[y]=1
    v2[x]=1
    v3[y-x+7]=1
    v4[y+x]=1

li=[[]for i in range(8)]
for i in range(8):
    for j in range(8):
        if board[i][j]=='#':
            li[i].append((j,i-j,j+i))

dfs(0,2,st)

for i in ans[0]:
    y,x=i
    dot(y,x)

for i in board:
    print(''.join(i))



Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<int>> dp(n+1, vector<int>(2, 0));
    dp[0][1] = 1;
    for(int i = 1; i <= n; i++){
        dp[i][0] = min(dp[i-1][0] + (s[i-1]-'0'), dp[i-1][1] + 10 - (s[i-1]-'0'));
        dp[i][1] = min(dp[i-1][0] + (s[i-1]-'0') + 1, dp[i-1][1] + 10 - (s[i-1]-'0') - 1);
    }
    cout << dp[n][0] << endl;
}

Measured memory_bytes: 55940
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s;
    int l,i;
    cin >> s;
    l=s.length();
    for(i=0;i<l;i++) cout << 'x';
    cout << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    int a=1,ans=0,b=0;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    } 
    //sort(A.begin(), A.end());
    for (int i = 0; i < N; i++){
        if(A.at(i)==1){
            b++;
        } 
        if(A.at(i)==a) a++;
        else ans++;
    }

    if(b==0) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>

using namespace std;

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

    double numerator = (N/2 + N%2)*1.0, denominator = N*1.0;
    cout << setprecision(6) << numerator/denominator << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
ll gcd(ll p,ll q){
	while(q){
		ll t=p%q;
		p=q;
		q=t;
	}
	return p;
}
int main(){
    ll n;
	scanf("%lld",&n);
    ll a[n+10],l[n+10],r[n+10],ans;
	rep(i,0,n)scanf("%lld",&a[i]);
	l[0]=0;
	r[0]=0;
	rep(i,1,n+1){
		l[i]=gcd(l[i-1],a[i-1]);
		r[i]=gcd(r[i-1],a[n-i]);
	}
	ans=max(l[n-1],r[n-1]);
	rep(i,1,n-1)ans=max(ans,gcd(l[i],r[n-1-i]));
	printf("%lld",ans);
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <math.h>

int main(void) {

  long mod = pow(10,9)+7;
  long n,k;
  scanf("%ld %ld", &n, &k);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long left[n],right[n];
  for (long i = 0; i < n; i++) {
    left[i] = 0;
    for (long j = 0; j < i; j++) {
      if (a[j] < a[i]) {
        left[i]++;
      }
    }
    right[i] = 0;
    for (long j = i+1; j < n; j++) {
      if (a[j] < a[i]) {
        right[i]++;
      }
    }
  }
  long sum = 0;
  long plus;
  for (long i = 0; i < n; i++) {
    plus = (k-1)*k/2;
    plus %= mod;
    plus *= left[i]+right[i];
    plus %= mod;
    plus += right[i]*k;
    plus %= mod;
    sum += plus;
    sum %= mod;
  }
  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int a,b;
for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
    a=i+1;
    break;
    }
}
for(int i=(s.size())-1;i>0;i--){
    if(s[i]=='Z'){
    b=i+1;
    break;
    }
}
cout<<b-a+1;
return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int n;
V< V<int> > s;
V<int> col;

bool isBipartite(int i, int c) {
    if (col[i] != -1) return col[i] == c;
    col[i] = c;
    for (int j = 0; j < n; j++) {
        if (s[i][j] == 1) {
            if (col[j] == -1) {
                if (!isBipartite(j, c ^ 1)) return false;
            } else {
                if (col[j] == c) return false;
            }
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    s.resize(n, V<int>(n));
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
        char c; cin >> c;
        s[i][j] = c - '0';
    }
    col.resize(n, -1);
    if (!isBipartite(0, 0)) cout << -1 << '\n';
    else {
        V< V<int> > d(n, V<int>(n, INF));
        for (int i = 0; i < n; i++) d[i][i] = 0;
        for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (s[i][j]) d[i][j] = 1;
        for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (d[i][j] > d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];
        int ans = 0;
        for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) chmax(ans, d[i][j]);
        cout << ans + 1 << '\n';
    }
    return 0;
}


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

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

int main() {
  int n, ans = 0;
  map<ll, ll> mp;
  cin >> n;
  vector<ll> a(n);
  bool two = false;
  rep(i, n) cin >> a[i], mp[a[i]]++;

  int even = 0, odd = 0;
  for (auto m : mp) {
    if (m.second > 1)
      if (m.second % 2 == 1)
        odd++;
      else
        even++;
    ans++;
  }

  cout << (even % 2 == 0 ? ans : ans - 1) << endl;
  return 0;
}


Measured memory_bytes: 7296
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, ans = 0;
  scanf("%lld", &n);
  if(n & 1) {
    printf("0");
    return 0;
  }
  n /= 2;
  while(n) n /= 5, ans += n;
  printf("%lld", ans);
  return 0;
}

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

using namespace std;
#define ll long long
#define db long double
#define all(a) a.begin(),a.end()
#define pb push_back
#define f(i,l,u) for(ll i=l;i<u;i++)
#define lb lower_bound
#define ub upper_bound
#define pii pair<ll,ll> 

unsigned long long fac[200001]; 
void powe(ll p)
{

    fac[0] = 1; 
    for (int i = 1; i <= 200001; i++) 
        fac[i] = (fac[i - 1] * i) % p; 

}

unsigned long long power(unsigned long long x, 
                         ll y, ll p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, ll p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
unsigned long long nCrModPFermat(unsigned long long n, 
                                 ll r, ll p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    else
    return gcd(b,a%b);
}


int main() {
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll t=1;
//cin>>t;
while(t--)
{
    ll n;
    cin>>n;

string s;
cin>>s;
ll ct=0;
f(i,0,s.length())
{
 if(s[i]=='R')
 ct++;
}
ll ctt=0;
    f(i,0,ct)
    {
        if(s[i]=='R')
        ctt++;
    }
    
    cout<<ct-ctt<<endl;
}




return 0;
}

Measured memory_bytes: 3744
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    ll n;
	cin >> n;
    map<ll, int, greater<ll>> mp;
    
    rep(i, n) {
        ll a;
        cin >> a;
        mp[a]++;
    }
    
    auto opp = [&](ll x){
        int cnt = 0;
        ll temp = x;
        while(x){
            x /= 2;
            cnt++;
        }
        ll nibeki = 1LL<<cnt;
        return nibeki - temp;
    };
    
    int ans = 0;

    for(auto entry : mp){
        ll now = entry.fi;
        ll temp = opp(now);
        int cnt;
        if(now != temp) cnt = min(mp[now], mp[temp]);
        if(now == temp) cnt = mp[now]/2;
        // cout << now << " " << temp << " " << cnt << endl;
        ans += cnt;
        mp[now] -= cnt;
        mp[temp] -= cnt;
    }
    
    cout << ans << endl;
    return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D){
    cout << "Left" << endl;
  }
  else if (A + B == C + D){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void){
	char s1[1001];
	char s2[] = " .\n";
	char w[11];
	char end[] = "END_OF_TEXT";
	char *tok;
	char *tp;
	int i;
	int cnt = 0;

	scanf("%s", w);

	for(i = 0;i< sizeof(w)/sizeof(w[0]);i++){
		w[i] = tolower(w[i]);
	}

	while(1){
		scanf("%s", s1);
		/*divide sentences to token*/
		tok = strtok( s1, s2);

		while(tok != NULL){
			if(strcmp(end,tok) == 0){
				printf("%d\n", cnt);
				return 0;
			}
			/*set token pointer*/
			tp = tok;

			while(*tok != '\0'){
				*tok = tolower(*tok);
				++tok;
			}
			/*set again*/
			tok = tp;

			if(strcmp(w,tok) == 0){
				cnt++;
			}
			tok = strtok(NULL,s2);
		}
	}

	return 0;
}

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

using namespace std;

int main(void) {
  long N, M;
  cin >> N >> M;
  vector<long> candidate;
  for (long i = 1; i * i <= M; i++) {
    if (M % i == 0) {
      candidate.push_back(i);
      candidate.push_back(M / i);
    }
  }
  long revans = M;
  for (auto it = candidate.begin(); it != candidate.end(); ++it) {
    if (*it < revans and N <= *it) revans = *it;
  }
  cout << M / revans << endl;
  return 0;
}


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

int main(){
	int n[5],ans[5];
	while(cin>>n[0],n[0]){
		int rock,paper,scissors;
		rock=paper=scissors=0;
		for(int i=1;i<5;i++){
			cin>>n[i];
		}
		for(int i=0;i<5;i++){
			switch(n[i]){
				case 1:
				rock++;
				break;
				case 2:
				scissors++;
				break;
				case 3:
				paper++;
				break;
			}
		}
		if(rock>0 && paper>0 && scissors>0){
			for(int i=0;i<5;i++)ans[i]=3;
		}else if((!rock && !paper) || (!rock && !scissors) || (!paper && !scissors)){
			for(int i=0;i<5;i++)ans[i]=3;
		}else{
			if(rock==0){
				for(int i=0;i<5;i++){
					if(n[i]==2)ans[i]=1;
					else ans[i]=2;
				}
			}else if(paper==0){
				for(int i=0;i<5;i++){
					if(n[i]==1)ans[i]=1;
					else ans[i]=2;
				}
			}else{
				for(int i=0;i<5;i++){
					if(n[i]==3)ans[i]=1;
					else ans[i]=2;
				}
			}
		}
		for(int i=0;i<5;i++)cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#define RONE 100000

int main(void){
	
	int N,sum=RONE,i,a;
	
	scanf("%d",&N);
	
	for(i=0;i<N;i++){
		sum=sum*1.05;
		a=sum/1000;
		if(a*1000-sum){
			sum=a*1000+1000;
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 588