akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a < 0 && c > 100)
        cout << "No" << endl;
    else if (a < b && b < c)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
}


Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Text;

namespace ITP1_3_D
{
	class Program
	{
		static void Main(string[] args)
		{
			string s = Console.ReadLine();
			string[] input = s.Split();

			int min = int.Parse(input[0]);
			int max = int.Parse(input[1]);
			int div = int.Parse(input[2]);
			int c = 0;
			for (int i = min; i <= max; i++) {
				if (div % i == 0) {
					c++;
				}
			}
			Console.WriteLine(c);
		}
	}
}

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

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

const long long MOD = 1000000007;

int main(){
  string s;
  int q;
  int x=0;
  cin >> s >> q;
  int n=s.size();
  int t,f;
  vector<char> fr,ba;
  char c;
  rep(i,q){
    cin >> t;
    if(t==1){
      x = (x ? 0 : 1);
    }
    else{
      cin >> f >> c;
      if(f==1){
        if(x==0) fr.push_back(c);
        else ba.push_back(c);
      }
      else{
        if(x==0) ba.push_back(c);
        else fr.push_back(c);
      }
    }
  }
  if(x==0){
    rep(i,fr.size()) cout << fr.at(fr.size()-1-i);
    cout << s;
    rep(i,ba.size()) cout << ba.at(i);
    cout << endl;
  }
  else{
    rep(i,ba.size()) cout << ba.at(ba.size()-1-i);
    n=s.size();
    rep(i,n){ 
      cout<<s.at(n-1-i);
    }
    rep(i,fr.size()) cout << fr.at(i);
    cout << endl;
  }
      
}


Measured memory_bytes: 1024
#include <math.h>
#include <iomanip>
#include <iostream>

int main() {
  double x1, y1, x2, y2;
  std::cin >> x1 >> y1 >> x2 >> y2;
  std::cout << std::fixed << std::setprecision(12)
            << sqrt(pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0)) << std::endl;
  return 0;
}



Measured memory_bytes: 3228
n = int(input())
f = [0 for i in range(n+1)]
for i in range(1,n+1):
    cur = i
    while cur<=n:
        f[cur] += 1
        cur += i 

ans = 0
for i in range(1,n+1):
    if i%2==1 and f[i]==8:
        ans += 1

print(ans)

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,n,i;
    cin>>x>>n;
    if(n==0){
        cout<<x<<endl;
        return 0;
    }

    int p[102],pnum;
    for(i=0; i<n; i++){
        cin>>pnum;
        p[pnum]=1;
    }
    
    if(p[x]!=1){
        cout<<x<<endl;
        return 0;
    }
    
    for(i=1; i<=100; i++){
        if(x-i>=0){
            if(p[x-i]!=1){
                cout<<x-i<<endl;
                return 0;
            }
        }
        if(x+i<=101){
            if(p[x+i]!=1){
                cout<<x+i<<endl;
                return 0;
            }
        }
    }
}

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

int main() {
    int Q; cin >> Q;
    for (int _ = 0; _ < Q; ++_) {
        int res = 0;
        string S[2]; cin >> S[0] >> S[1];

        if (S[0] == S[1]) {
            cout << 0 << endl;
            continue;
        }
        
        int n = S[0].size(); 

        int ichi = 0;
        int zerogawa = 0;
        bool allzero = true;
        for (int i = 0; i < n; ++i) {
            if (S[0][i] != S[1][i]) {
                ichi = i;
                break;
            }
        }
        if (S[0][ichi] == '0') zerogawa = 0;
        else zerogawa = 1;
        for (int i = ichi; i < n; ++i) {
            if (S[zerogawa][i] == '1') allzero = false;
        }

        if (allzero) {
            int first = 0;
            for (int i = ichi; i >= 0; --i) {
                if (S[zerogawa][i] == '1') {
                    first = i;
                    break;
                }
            }
            ichi = first;
        }

        for (int iter = 0; iter < 2; ++iter) {
            int second = ichi;
            for (int i = ichi; i < n; ++i) {
                if (S[iter][i] == '1') {
                    second = i;
                }
            }
            res += second - ichi;
        }
        cout << res << endl;
    }
}






























Measured memory_bytes: 3208
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	function<T(T,T)>calcfn,updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
		function<T(T,T)>calcfn_=[](T a,T b){return a<b?a:b;},
		function<T(T,T)>updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query(int a,int b)//[a,b)
	{
		int L=(a<0?0:a>n?n:a)+n-1;
		int R=(b<0?0:b>n?n:b)+n-1;
		T lret=defvalue,rret=defvalue;
		for(;L<R;L>>=1,R>>=1)
		{
			if(!(L&1))lret=calcfn(lret,dat[L]);
			if(!(R&1))rret=calcfn(dat[--R],rret);
		}
		return calcfn(lret,rret);
	}
};
int N,K;
bool flag[2<<17];
main()
{
	cin>>N>>K;
	segtree<int>X(N,0,[](int a,int b){return a<b?b:a;});
	segtree<int>Y(N,1e9,[](int a,int b){return a>b?b:a;});
	vector<int>P(N);
	for(int i=0;i<N;i++)
	{
		cin>>P[i];
	}
	X.copy(P);
	Y.copy(P);
	int ans=0;
	int p=0;
	int ret=0;
	for(int i=0;i<N;i++)
	{
		if(i>0&&P[i-1]>P[i])p=i;
		if(i-p+1>=K)
		{
			flag[i]=true;
			ret=1;
		}
		if(i>=K-1&&!flag[i])
		{
			if(i==K-1||flag[i-1]||!flag[i-1]&&(P[i-K]!=Y.query(i-K,i)||P[i]!=X.query(i-K+1,i+1)))
			{
				ans++;
			}
		}
	}
	//cout<<ans<<endl;
	//cout<<cnt<<endl;
	cout<<ans+ret<<endl;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    int Lmax = 0,Rmin = 100000;
    for(int i = 0;i < M;i++){
        int L,R;
        cin >> L >> R;
        Lmax = max(Lmax,L);
        Rmin = min(Rmin,R);
    }
    cout << max(0,Rmin-Lmax+1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll sum=0;
  rep(i,n){
    cin >> a.at(i);
    sum+=a.at(i);
  }
  ll p=0,ans=1e10;
  rep(i,n){
    sum-=a.at(i);
    p+=a.at(i);
    ans=min(ans,abs(p-sum));
  }
  cout << ans;
}
  

Measured memory_bytes: 4816
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, mm, xx, yy, zz;
	cin >> nn >> mm;
	vector<int64> aa000(nn), aa001(nn), aa010(nn), aa011(nn), aa100(nn), aa101(nn), aa110(nn), aa111(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> xx >> yy >> zz;
		aa000[ii] =  xx + yy + zz;
		aa001[ii] =  xx + yy - zz;
		aa010[ii] =  xx - yy + zz;
		aa011[ii] =  xx - yy - zz;
		aa100[ii] = -xx + yy + zz;
		aa101[ii] = -xx + yy - zz;
		aa110[ii] = -xx - yy + zz;
		aa111[ii] = -xx - yy - zz;
	}
	sort(aa000.begin(), aa000.end());
	sort(aa001.begin(), aa001.end());
	sort(aa010.begin(), aa010.end());
	sort(aa011.begin(), aa011.end());
	sort(aa100.begin(), aa100.end());
	sort(aa101.begin(), aa101.end());
	sort(aa110.begin(), aa110.end());
	sort(aa111.begin(), aa111.end());
	int64 ans = 0, tmp = 0;
	for(int64 ii = 0;ii < mm;ii++)
	{
		tmp += aa000[nn - 1 - ii];
	}
	ans = max(ans, tmp);
	tmp = 0;
	for(int64 ii = 0;ii < mm;ii++)
	{
		tmp += aa001[nn - 1 - ii];
	}
	ans = max(ans, tmp);
	tmp = 0;
	for(int64 ii = 0;ii < mm;ii++)
	{
		tmp += aa010[nn - 1 - ii];
	}
	ans = max(ans, tmp);
	tmp = 0;
	for(int64 ii = 0;ii < mm;ii++)
	{
		tmp += aa011[nn - 1 - ii];
	}
	ans = max(ans, tmp);
	tmp = 0;
	for(int64 ii = 0;ii < mm;ii++)
	{
		tmp += aa100[nn - 1 - ii];
	}
	ans = max(ans, tmp);
	tmp = 0;
	for(int64 ii = 0;ii < mm;ii++)
	{
		tmp += aa101[nn - 1 - ii];
	}
	ans = max(ans, tmp);
	tmp = 0;
	for(int64 ii = 0;ii < mm;ii++)
	{
		tmp += aa110[nn - 1 - ii];
	}
	ans = max(ans, tmp);
	tmp = 0;
	for(int64 ii = 0;ii < mm;ii++)
	{
		tmp += aa111[nn - 1 - ii];
	}
	ans = max(ans, tmp);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3664
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define ll        	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

ll me(ll x,ll y,ll M)
{
	if(y==0)
	{
		return 1;
	}
	else
	{
		if(y%2==0)
		{
			return me((x*x)%M,y/2,M);
		}
		else
		{
			return (x*me((x*x)%M,(y-1)/2,M))%M;
		}
	}
}

int binStringtodec(string s,int x)
{
	int val=0;
	for(auto &it:s)
	{
		val = val * 2 + (it - '0');
		val = val%x;
	}
	return val;
}

int find_mod(int x,int M)
{
	if(x>=0)
		return x%M;
	return (M +  x%M)%M;
}

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int n;
		string s;
		cin >> n;
		cin >> s;
		int cou = 0;
		for(char c:s)
		{
			if(c=='1')
				cou++;
		}
		int cou1 = cou - 1;
		int cou2 = cou + 1;
		int val1 = -1 , val2 = -1;
		if(cou1>0)
		{
			val1 = binStringtodec(s,cou1);
		}
		val2 = binStringtodec(s,cou2);
		rep(i,0,n-1)
		{
			int couu = cou;
			if(s[i]=='1')
				couu--;
			else
				couu++;
			if(couu<=0)
			{
				cout << "0" << endl;
				continue;
			}
			int val;
			if(couu==cou1)
				val = val1;
			else
				val = val2;
			int idx = n - i - 1;
			int f = me(2,idx,couu);
			int x;
			if(s[i]=='0')
			 	x = val + f;
			else
				x = val - f;
			x = find_mod(x,couu);
			//deb1(x);
			int c = 1;
			while(x>0)
			{
				int f = __builtin_popcountll(x);
				x = x%f;
				c++;
			}
			cout << c << endl;
		}
	}
}

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

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

  if (a == 0) {
    cout << 1 << endl;
    return 0;
  }

  if (b == 0) {
    cout << 2 << endl;
    return 0;
  }
  if (c == 0) {
    cout << 3 << endl;
    return 0;
  }
  if (d == 0) {
    cout << 4 << endl;
    return 0;
  }
  if (e == 0) {
    cout << 5 << endl;
    return 0;
  }
}

Measured memory_bytes: 3588
mod=10**9+7
x,y=map(int,input().split())

X,Y=(2*y-x)//3,(2*x-y)//3
if X<0 or Y<0 or (x+y)%3!=0:print(0);exit()


def cmb(n,r,mod):
    if r<0 or r>n:return 0
    return g1[r]*g2[r]%mod


n=X+Y
k=max(X,Y)
g1=[1,n]
g2=[1,1]
inverse=[0,1]

for i,j in enumerate(range(n-1,((n-k+1)-1),-1)):
    i=i+2
    g1.append((g1[-1]*j)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1]%mod))

print(cmb(n,k,mod))

Measured memory_bytes: 156708
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, dp[210000], s[210000], f[210000];
int main() {
	cin >> n;
	REP(i, 210000)f[i] = -1;
	dp[0] = 1;
	REPO(i, n) cin >> s[i];
	REPO(i, n) {
		dp[i] += dp[i - 1];
		if (f[s[i]] != -1 and f[s[i]] != i - 1) dp[i] += dp[f[s[i]]];
		dp[i] %= MOD;
		f[s[i]] = i;
	}
	cout << dp[n] % MOD << endl;
}



Measured memory_bytes: 5120
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
typedef long long ll;

typedef struct
{
    int b;
    int c;
} replace;

int compare_struct_int(const void *p, const void *q)
{
    return ((replace *)q)->c - ((replace *)p)->c;
}

int compare_int(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int main(void)
{
    int n, m, a[100000];
    replace repl[100000];
    ll ans = 0;
    scanf("%d%d", &n, &m);
    rep(i, n)
        scanf("%d", &a[i]);
    rep(i, m)
        scanf("%d%d", &repl[i].b, &repl[i].c);

    qsort(a, n, sizeof(int), compare_int);
    qsort(repl, m, sizeof(replace), compare_struct_int);

    int cntRepl = 0, cntB = 0;
    rep(i, n)
    {
        if (repl[cntRepl].c > a[i])
        {
            a[i] = repl[cntRepl].c;
            ++cntB;
            if (cntB == repl[cntRepl].b)
            {
                cntRepl++;
                cntB = 0;
            }
        }
        else
            break;
    }

    rep(i, n)
        ans += a[i];
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2164
def bubbleSort(A, N):
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in range(N - 1):
            if A[i] > A[i + 1]:
                tmp = A[i]
                A[i] = A[i + 1]
                A[i + 1] = tmp
                flg = True
                cnt += 1
    return A, cnt


def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans, cnt = bubbleSort(A, N)
    print(*ans)
    print(cnt)


resolve()



Measured memory_bytes: 5616
#include "bits/stdc++.h"
using namespace std;
int main(){
 int N;
 cin >> N;
 map<int,int> val;
 for(int x =1;x<=N;x++){
 	val.insert(pair<int,int>(x,0));	
 }
 for(int x = 1; x<N; x++){
 	int z;
 	cin >> z;
 	val.at(z)++;
 }
 for(pair<int,int> y : val){
 	cout << y.second << endl;
 }

}
	


Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define ll long long
using namespace std;
ll dp[210][100009];
int ka[214514],inv[214514];
void setkaijo(int n){
	ka[0]=1;
	for(int i=1;i<=n;i++){
		ka[i] = ka[i-1] * i;
		ka[i] %= inf;
	}
}
int modpow(int x,int k){
	// x ^ k mod inf
	int p2[55],res=1;
	p2[0]=1;p2[1]=x%inf;
	for(int i=2;i<=50;i++){
		p2[i]=p2[i-1]*p2[i-1];
		p2[i] %= inf;
	}
	for(int i=1;i<=50;i++){
		if(k%2==1){
			res *= p2[i];
			res %= inf;
		}
		k /= 2;
	}
	return res;
}
void setinv(int n){
	for(int i=0;i<=n;i++){
		inv[i] = modpow(ka[i],(ll)inf-2);
	}
}
int comb(int n,int k){
	if(k>n)return 0;
	if(k==0 || k==n)return 1;
	int res = (ka[n] * inv[k]) % inf;
	res = (res*inv[n-k]) % inf;
	return res;
}
signed main(){
	ll n,x;
	cin>>n>>x;
	vector<ll> a;
	map<ll,ll> mope;
	setkaijo(100009);
	setinv(100009);
	for(int i=0;i<n;i++){
		ll tx;
		cin>>tx;
		a.pb(tx);
		mope[tx]++;
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	vector< pair<ll,ll> > v;
	for(int i=0;i<n;i++){
		if( mope[ a[i] ] != 0){
			v.pb( mp( a[i], mope[a[i]]) );
			mope[a[i]] = 0;
		}
	}
	dp[0][x] = 1;
	ll rem = n;
	for(int i=0;i<v.size();i++){
		ll md = v[i].first;
		ll num = v[i].second;
		ll cb = comb(rem-1,num-1);
		ll cb2 = comb(rem-1,num);
		for(int j=0;j<=100000;j++){
			dp[i+1][j%md] += ( dp[i][j] * cb )%inf;
			dp[i+1][j] += (dp[i][j] * cb2)%inf;
		}
		rem -= num;
	}
	ll ans = 0;
	for(int i=0;i<=x;i++){
		ans = (ans + i*dp[v.size()][i])%inf;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

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

    vector<int> c(n), s(n), f(n);

    for (int i = 0; i < n - 1; i++) {
        int data;
        cin >> data;
        c[i] = (data);
        cin >> data;
        s[i] = (data);
        cin >> data;
        f[i] = (data);
    }

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

        int time = 0;

        while (current < n - 1) {
            if (time <= s[current]) {
                //time += s[current] - time;
                time = s[current];
            } else {
                int m = time / f[current];
                //time += f[current] * (m + 1) - time;
                time = f[current] * (m + (time % f[current] != 0));
            }

            time += c[current];
            current++;
        }
        cout << time << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ull b=10009;
    ull b2=10007;
    ll n;cin>>n;
    string s;cin>>s;
    ll u=n+1;
    ll d=0;
    while(u-d>1){
        ll i=(u+d)/2;
        //if(i*2>n)continue;
        ull t=1,t2=1;
        rep(j,0,i){
            t*=b;
            t%=mod;
            t2*=b2;
            t2%=mod2;
        }
        ull ha[n];
        ull ha2[n];
        fill(ha,ha+n,-1);
        fill(ha2,ha2+n,-1);
        ull ah=0;
        ull ah2=0;
        rep(j,0,i){
            ah=ah*b+s[j];
            ah%=mod;
            ah2=ah2*b2+s[j];
            ah2%=mod2;
        }
        rep(j,0,n){
            ha[j]=ah;
            ha2[j]=ah2;
            if(j+i>=n)break;
            ah=ah*b+s[j+i];
            ah%=mod;
            ull r=s[j]*t;
            r%=mod;
            ah-=r;
            ah+=mod;
            
            ah%=mod;
            ah2=ah2*b2+s[j+i];
            ah2%=mod2;
            ull r2=s[j]*t2;
            r2%=mod2;
            ah2-=r2;
            ah2+=mod2;
            
            ah2%=mod2;
        }
        //rep(j,0,n)cout<<ha[j]<<endl;
        map<pll,ll> mp;
        ll y=0;
        rep(j,i,n){
            if(j+i>n)break;
            mp[{ha[j-i],ha2[j-i]}]=1;
            if(mp[{ha[j],ha2[j]}]==1){
                y=1;
                break;
            }
        }
        if(y)d=i;
        else u=i;
    }
    cout<<d<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);

class UnionFind {
public:
    vector <int> par; // 各元の親を表す配列
    vector <int> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(int sz_): par(sz_), siz(sz_, (int)1) {
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, (int)1);
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    int root(int x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(int x, int y) { // 連結判定
        return root(x) == root(y);
    }

    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	pair<P, int> p[N];
	UnionFind uf(N);
	priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>> que;
	rep(i,N){
		cin >> p[i].first.first >> p[i].first.second;
		p[i].second = i;
	}
	sort(p, p+N);
	rep(i,N-1){
		que.push({p[i+1].first.first-p[i].first.first, P(p[i].second, p[i+1].second)});
	}
	rep(i,N){
		swap(p[i].first.first, p[i].first.second);
	}
	sort(p, p+N);
	rep(i,N-1){
		que.push({p[i+1].first.first-p[i].first.first, P(p[i].second, p[i+1].second)});
	}
	int ans = 0;
	while(!que.empty()){
		auto e = que.top();
		que.pop();
		int v = e.first;
		int x = e.second.first;
		int y = e.second.second;
		if(uf.issame(x,y)) continue;
		uf.merge(x,y);
		ans += v;
	}
	cout << ans << endl;
}

Measured memory_bytes: 12528
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
 pair<pair<int,int>,int> p[100001];
signed main() {
 int n,m;
 cin>>n>>m;

 int c,l,r;
 for(int i=0;i<m;i++){
   cin>>l>>r>>c;
   p[i]=make_pair(make_pair(l-1,r-1),c);
 }
 int dp[n];sort(p,p+m);fill(dp,dp+n,MOD*MOD);
 dp[0]=0;int j=0;
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
   while(j<m&&p[j].first.first==0){
     que.push(make_pair(dp[0]+p[j].second,p[j].first.second));j++;
   }

 for(int i=1;i<n;i++){
   while(!que.empty()&&que.top().second<i)que.pop();
   if(!que.empty())dp[i]=que.top().first;
   while(j<m&&p[j].first.first<i)j++;
   while(j<m&&p[j].first.first==i){
     que.push(make_pair(dp[i]+p[j].second,p[j].first.second));j++;
   }
 }
 if(dp[n-1]>=MOD*MOD)cout<<-1;
 else cout<<dp[n-1];






return 0;
}


Measured memory_bytes: 5364
#include<stdio.h>

int main(){
  int A, B, C, D, P, X, Y, result;
  scanf("%d %d %d %d %d", &A, &B, &C, &D, &P);
  X = A * P;
  if(P <= C){
    Y = B;
  }else{
    Y = B + (P - C) * D;
  }
  if(X > Y){
    result = Y;
  }else{
    result = X;
  }
  printf("%d\n", result);
  return 0;
}

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

int main(){
    ll n,q,i,ans=0;
    ll a,b,c,maxnum=0;
    cin>>n;
    vector<ll> arr(1000001,0);
    for(i=0;i<n;i++){
        cin>>a;
        arr[a]++;
        if(maxnum<a) maxnum=a;
        ans+=a;
    }
    cin>>q;
    for(i=0;i<q;i++){
        cin>>b>>c;
        ans=ans+arr[b]*(c-b);
        cout<<ans<<endl;
        arr[c]=arr[c]+arr[b];
        arr[b]=0;
    }

    return 0;
}


Measured memory_bytes: 11096
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(v) v.begin(),v.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,pii> plii;

string mdf(int x){
	int keta=1;
	while(x/(int)pow(10,keta)!=0)keta++;
	string res="";
	for(int i=keta-1;i>=0;i--){
		int tmp=x/pow(10,i);
		res+=(char)(tmp+'0');
		x-=tmp*pow(10,i);
	}
	if(res.size()<6)while(res.size()<6)res='0'+res;
	return res;
}

signed main(){
	int n,m;
	cin>>n>>m;
	int cnt[n];
	string ans[m];
	fill(cnt,cnt+n,1);
	vector<plii> city;
	int p;
	ll y;
	rep(i,m){
		cin>>p>>y;
		city.pb(plii(y,pii(p-1,i)));
	}
	sort(all(city));
	rep(i,m){
		ans[city[i].second.second]=mdf(city[i].second.first+1)+mdf(cnt[city[i].second.first]);
		cnt[city[i].second.first]++;
	}
	rep(i,m)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 12272
S = input()

def judge_s(s):
    if len(s)%2==1:
        return False
    mid = len(s)//2
    if s[:mid]==s[mid:]:
        return True

for i in range(1, len(S)-1):
    if judge_s(S[:-i]):
        ans = S[:-i]
        break

print(len(ans))

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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int main(){
    int n, h; cin>>n>>h;
    vector<int> a(n), b(n);
    int MAX=0;
    for(int i=0; i<n; i++){
        cin>>a[i]>>b[i];
        MAX = max(MAX, a[i]);
    }

    sort(b.begin(), b.end(), greater<int>());

    int cnt=0;
    for(int i=0; b[i]>MAX; i++){
        h -= b[i];
        cnt++;

        if(h <= 0){
            cout << cnt << endl;
            return 0;
        }
    }

    cout << cnt + (h + (MAX - 1)) / MAX << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include<iomanip>
#include <cstdint>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int abs( int a ) { return a < 0 ? -a : a; }
uint64_t gcd( uint64_t a, uint64_t b ) {
	return b == 0 ? a : gcd( b, a % b );
}

int main() {
	uint64_t a, b, c, d;
	cin >> a >> b >> c >> d;
	if ( d < c ) swap( c, d );
	a--;
	uint64_t s = b - a;
	s -= ( b / c - a / c );
	s -= ( b / d - a / d );
	uint64_t e = c * d / gcd( c, d );
	s += ( b / e - a / e );
	cout << s << endl;
	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 int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int mi = 0, mx = n;
    rep(i,m){
        int l, r;
        cin >> l >> r;
        chmax(mi, l);
        chmin(mx, r);
    }
    int ans = 0;
    chmax(ans, mx - mi + 1);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*  ex2_3
    hangan2020 */

#include <stdio.h>

int main(void){
    int N, A; 
    //NとAの入力
    scanf("%d", &N);
    scanf("%d", &A);
    //条件付け
    if( N < 1 || 100 <= N || A < 0 || A > N*N){
        fprintf(stderr, "Valid input should satisfy the following conditions:\n 1 <= N <= 100\n 0 <= A <= N^2");
        return 1;
        }
    //Answerの計算
    printf("%d\n", N*N - A);
    return 0;
}

Measured memory_bytes: 128
n,m = map(int,input().split())

switch = []

for i in range(m):
    switch.append(list(map(lambda x:int(x)-1 ,input().split()))[1:])
p = list(map(int,input().split()))


ans = 0
for i in range(2**n):
    s = []
    for j in range(n):
        s.append((i>>j)&1)
    f = 1
    for j in range(m):
        a = 0
        for k in switch[j]:
            a += s[k]

        if a%2== p[j]:
            pass
        else:
            f = 0
            break

    if f:
        ans += 1

print(ans)

Measured memory_bytes: 9228
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  putStrLn . unwords . map show $ solve as


solve = map fst . sortOn snd . zip [1..]


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

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

    int n, m;
    cin >> n >> m;
    int ans = (1900 * m + 100 * (n - m)) * pow(2, m);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int sub(int a,int b){a-=b;return a<0?a+mod:a;}
inline int mul(int a,int b){return (ll)a*b%mod;}
inline int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
inline int inv(int x){return qpow(x,mod-2);}
/* math */
int n;
const int N=2e6+5;
int fac[N],ifac[N];
inline void init(int n){
	fac[0]=ifac[0]=1;for(int i=1;i<=n;i++)fac[i]=mul(fac[i-1],i);
	ifac[n]=inv(fac[n]);for(int i=n-1;i;i--)ifac[i]=mul(ifac[i+1],i+1);
}
int f[N][3];
int F(int x){
	return f[x][1];
}
int G(int x){
	return mul(inv(3),mul(inv(n),inv(x)));
}
int binom(int a,int b){
	if(b>a)return 0;
	return mul(fac[a],mul(ifac[b],ifac[a-b]));
}
int main()
{
	cin >> n;
	init(n*2);
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<3;j++)for(int k=0;k<3;k++)if(j!=k)f[i][j] = add(f[i][j], f[i-1][k]);
		//cout<<f[i][1]<<" "<<f[i][2]<<" "<<f[i][0]<<endl;
	}
	int ans=0,all= inv(qpow(3,n-1));
	for(int i=1;i<=n;i++){
	//	cout<<F(i)<<" "<<binom(n,i)<<" "<<all<<endl;
		int P = mul(mul(F(i), binom(n,i)), all);
		int L = G(i);
	//	cout<<P<<" "<<L<<endl;
		ans = add(ans, mul(P, L));
	}
	cout << ans << endl;
}

Measured memory_bytes: 29056
import collections
def main():

    N, M, Q = map(int, input().split())
    p = collections.defaultdict(int)
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        p[(a-1, b-1, c)] = d

    lv = [[1]]
    for i in range(N):
        temp = []
        for v in lv:
            for j in range(v[-1], M+1):
                temp.append(v + [j])
        lv = temp

    ans = 0
    for v in lv:
        q = 0
        for a, b, c in p:
            if v[b] - v[a] == c:
                q += p[(a, b, c)]
        ans = max(ans, q)
    return ans

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 109824
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

struct Edge {
    int to;
    ll d;
};

int colors[100100];
bool visited[100100];
vector<vector<Edge> > es;

void dfs(int v, int p) {
    if (visited[v]) return;
    visited[v] = true;
    for (auto e: es[v]) {
        //cout << "to: " << e.to << " cost: " << e.d << endl;
        if (p == e.to) continue;

        if (e.d % 2 == 0) colors[e.to] = colors[v]; 
        else colors[e.to] = (colors[v]+1) % 2;
        dfs(e.to,v);
    }
    return;
}

int main() {
    int n; cin >> n;
    es.resize(n);

    rep(i,n-1) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        --u; --v;
        Edge edge1 = {v,w};
        es[u].pb(edge1);
        Edge edge2 = {u,w};
        es[v].pb(edge2);
    }

    dfs(0,-1);
    rep(i,n) cout << colors[i] << endl;
    return 0;
}





























Measured memory_bytes: 9728
def main():
    s = str(input())
    n = len(s)
    ans = 0
    for i in range(n + 1):
        for j in range(i + 1, n + 1):
            x = int(s[i:j])
            p = 2 ** max(0, i - 1)
            q = 2 ** max(0, n - j - 1)
            ans += x * p * q

    print(ans)

if __name__ == '__main__':
    main()


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

int main(void){
    int N;
    cin >> N;
    int A[210000];
    int i;
    for(i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A, A + N);
    int flag = 0;
    for(i=0; i<(N-1); i++){
        if(A[i+1] == A[i]){
            flag = 1;
        }
    }
    if(flag == 1){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
while 1:
    n,x = map(int, input().split())
    if n == x == 0: break
    
    cnt = 0
    for a in range(1,n+1):
        for b in range(a+1,n+1):
            for c in range(b+1,n+1):
                if x - a - b - c == 0: cnt += 1
    
    print(cnt)


Measured memory_bytes: 5596
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;
#define MAX_N 10000000
int main() {
  long long N, K;
  cin >> N >> K;
  if (K % 2 == 1) {
	  cout << (N / K) * (N / K) * (N / K) << endl;
	  return 0;
	}
  K /= 2;
  long long ans1 = 0;
  long long ans2 = 0;
  bool flag      = true;
  for (int i = K; i <= N; i += K) {
	  if (flag) {
		  ans1++;
		} else {
		  ans2++;
		}
	  flag = !flag;
	}
  cout << ans1 * ans1 * ans1 + ans2 * ans2 * ans2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;



int main() {
    

    ll n,k;
    cin >> n >> k;
    vector <ll> p;
    for (ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    ll nowsum, maxsum;
    maxsum = 0;
    for (ll i=0;i<k;i++){
        maxsum += p[i];
        nowsum = maxsum;
    }
    ll en = k - 1;
    ll st = 0;
    while(en + 1 < n){
        nowsum = nowsum - p[st] + p[en+1];
        if(maxsum < nowsum){
            maxsum = nowsum;
        }
        st++;
        en++;
    }
    cout << setprecision(10) << (long double)(maxsum + k)/2.0 << endl;

}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const unordered_map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define dbg(x) cout<<#x<<" = "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________________
int main()
{
       ll n;
       cin>>n;
       ll ans = 0;
       for(ll i = 2 ; i * i <= n ; i++)
       {
              ll cnt = 0;
              while((n%i)==0)
              {
                     cnt++;
                     n /= i;
              }
              ll sum = 0;
              ll curr = 0;
              while(sum <= cnt)
              {
                     curr++;
                     sum += curr;
              //       cout<<sum<<endl;
                     if(sum <= cnt){
                            ans++;
                     }
                     else{
                            break;
                     }
              }
       }
       if(n!=1){ans++;}
       cout<<ans<<endl;
}


Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
ans = 1
a.sort()
if a[0] == 0:
    print(0)
    exit()

for i in range(n):
    ans *= a[i]
    if ans > pow(10, 18):
        print(-1)
        exit()
else:
    print(ans)


Measured memory_bytes: 21528
#include<iostream>
using namespace std;
const int dy[] = { 0, 1, -1, 0}, dx[] = { 1, 0, 0, -1};
int n, mas[8][8];
bool used[8][8];
bool isover( int& y, int& x){
  return x < 0 || y < 0 || x >= n || y >= n;
}
bool dfs( int hoge, int y, int x, int sum){
  if(hoge == 0 && sum == n * n) return true;
  bool ret = false;
  if(hoge < 0){
    for(int i = 0 ; i < 4 ; i++ ){
      int ny = y + dy[i], nx = x + dx[i];
      if(!isover(ny,nx) && mas[ny][nx] > 0 && !used[ny][nx]){
        used[ny][nx] = true;
        ret += dfs( hoge + mas[ny][nx], ny, nx, sum + 1);
        used[ny][nx] = false;
      }
    }
  }else if(!hoge){
    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ; j < n ; j++ ){
        if(mas[i][j] < 0 && !used[i][j]){
          used[i][j] = true;
          ret += dfs( mas[i][j], i, j, sum + 1);
          used[i][j] = false;
          return ret;
        }
      }
    }
  }
  return ret;
}
int main(){
  while(cin >> n , n){
    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ; j < n ; j++ ){
        cin >> mas[i][j];
      }
    }
    cout << (dfs(0,0,0,0) ? "YES" : "NO") << endl;
  }
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

signed main(){
	int n=read(),k=read();
	vi a;
	REP(i,n)
		a.PB(read());
	vi l(n+1,0),r(n+1,0),s(n+1,0);
	REP(i,n)
		s[i+1]=s[i]+a[i];
	REP(i,n)
		l[i+1]=l[i]+max(a[i],0LL);
	for(int i=n-1;i>=0;i--)
		r[i]=r[i+1]+max(a[i],0LL);
	int ans=LLONG_MIN;
	for(int b=0;b+k<=n;b++)
		chmax(ans,l[b]+r[b+k]+max(0LL,s[b+k]-s[b]));
	cout<<ans<<endl;
}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,a,b;
    cin >> n >> a >> b;
    long long remainAB = n % (a+b);
    long long divAB = n / (a+b);
    if(remainAB-a>0){
        cout << a*divAB+a << endl;
    }else{
        cout << a*divAB+remainAB << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k;
    scanf("%d %d", &n, &k);
    vector <pair <int, int> > ans;
    for (int i = 2; i <= n; i++) {
		ans.pb({1, i});
		k -= i - 2;
	}
	for (int i = 2; i <= n && k < 0; i++) {
		for (int j = i + 1; j <= n && k < 0; j++, k++) {
			ans.pb({i, j});
		}
	}
	if (k != 0) {
		printf("-1");
	} else {
		printf("%d\n", (int)ans.size());
		for (auto x : ans) {
			printf("%d %d\n", x.fi, x.se);
		}
	}
    return 0;
}


Measured memory_bytes: 3808
import java.lang.Math;
import java.util.ArrayList;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sn = new Scanner(System.in);
        int a = sn.nextInt();
        int b = sn.nextInt();
        int c = sn.nextInt();
        int co = 0;
        for (int i = a; i <= b; i++) {
            if (c % i != 0) {
                continue;
            }
            co++;
        }
        System.out.println(co);
    }
}

Measured memory_bytes: 17324
// Devarshi

#include<bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn=1000001;


int main(){

int a,b,c;
cin>>a>>b;
fore(i,1,3){
if((a*b*i)%2==1){
    cout<<"Yes";
    return 0;
}
}
cout<<"No";
return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;

  if(a % 2 == 0 || b % 2 == 0)  //どちらかが偶数なら積も偶数
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;

}


Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}
// 立っている ビットの数
int bitcount(unsigned int uc);
int bitcount(unsigned int uc)
{
	int bit;

	for (bit = 0; 0 != uc; uc = (unsigned int)(uc >> 1))
		if (0 != (uc & 1))++bit;

	return bit;
}//bitco

#pragma endregion

// ABC064 A-RGB Cards

int main(void) {
	int r,g,b;
	
	scanf("%d %d %d", &r, &g,&b);
	((r * 100 + g * 10 + b)%4)?printf("NO\n"):printf("YES\n");
	return 0;
}

Measured memory_bytes: 1660
package main
import "fmt"

func main() {
    var N int
    fmt.Scan(&N)
    var p int
    var p_max int = 0
    var p_sum int = 0
    for i := 0; i < N; i++ {
        fmt.Scan(&p)
        if p > p_max {
            p_max = p
        }
        p_sum += p
    }
    var sum int = p_sum - p_max / 2
    fmt.Println(sum)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n;ll a;cin>>n;
    ll p=1;ll count=0;
    for(ll i=0;i<n;++i)
    {
        cin>>a;
        if(a!=p){count++;}
        else{p++;}
    }
    if(count<n){cout<<count;return 0;}
    cout<<-1;
}


Measured memory_bytes: 256
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())

for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = -1

for i in range(3):
    if A[i][0] == -1 and A[i][1] == -1 and A[i][2] == -1:
        print("Yes")
        exit()

for i in range(3):
    if A[0][i] == -1 and A[1][i] == -1 and A[2][i] == -1:
        print("Yes")
        exit()

if A[0][0] == -1 and A[1][1] == -1 and A[2][2] == -1:
        print("Yes")
        exit()

if A[0][2] == -1 and A[1][1] == -1 and A[2][0] == -1:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 3064