akhauriyash/Code-Regression huggingface dataset:
#include "stdlib.h"
#include "stdio.h"

int N;
int num[1000010];
int G[100];
int cnt;

void printfResult(){
    int i;
    for(i=0; i<N; i++){
        printf("%d ", num[i]);
    }
    printf("\n");
}

void insertSort(int g){
    int i, j;
    int temp;
    for(i=g; i<N; i++){
        temp = num[i];
        j = i-g;
        while(j>=0 && temp<num[j]){
            num[j+g] = num[j];
            j = j - g;
            cnt++;
        }
        num[j+g] = temp;
    }
}

void shellSort(){
    int i;
    int m=0;
    G[0] = 1;
    while((3 * G[m] + 1) <= N){
        ++m;
        G[m] = 3 * G[m-1] + 1;
    }
    printf("%d\n", m+1);
    for(i=m; i>0; i--){
        printf("%d ",G[i]);
    }
    printf("%d\n", G[0]);
    for(i=m; i>=0; i--){
        insertSort(G[i]);
    }
}



int main(){
    //freopen("D:\\zhouyu\\study\\codes\\SortSample.txt", "r", stdin);
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        scanf("%d", &num[i]);
    }
    shellSort();
    printf("%d\n", cnt);
    for(int i=0; i<N; i++){
        printf("%d\n", num[i]);
    }
}


Measured memory_bytes: 5652
import sys
read = sys.stdin.read
def main():
    n = int(input())
    if n <= 9 or n % 2 == 1:
        print(0)
        sys.exit()

    n5 = 5
    r = 0
    while n >= n5 * 2:
        r += n // (n5 * 2)
        n5 *= 5
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61860
#include <bits/stdc++.h>
 
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define y1 my_y1
#define fi first
#define se second
#define lcm mylcm
 
using namespace std;
 
const ll mod = 998244353;
const ll inf = 2e9;
const int N = 1e5 + 5;

ll n, m, w[N], v[N], dp[105][N], mx;

int main () {
	//freopen("a.out", "w", stdout);
    cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j >= w[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
		}
	}
	for (int i = 1; i <= m; i++) {
		mx = max(mx, dp[n][i]);
	}
	cout << mx;
	return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

vector<long long int> inverse;
vector<long long int> f, f_inverse;

void factorial_Initialize(int max){
    vector<long long int> a(max+1,1);
    inverse = a;
    f = a;
    f_inverse = a;

    for (int i=2; i<=max; i++){
        inverse[i]   = MOD - inverse[MOD % i] * (MOD / i) % MOD;
        f[i]         = f[i-1]         * i          % MOD;
        f_inverse[i] = f_inverse[i-1] * inverse[i] % MOD;
    }
}

long long int nCr(int n, int r){
    if(n < r || r < 0) return 0;
    if (n >= f.size()){
        factorial_Initialize(n);
    }
    return f[n] * f_inverse[r] % MOD * f_inverse[n-r] % MOD;
}

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

    long long int ans = 0;
    for(int i=1; i<=n-1; i++){
        long long int cases = (f[i]   * f[n-1-i] % MOD) * nCr(i-1, n-1-i) % MOD
                            - (f[i-1] * f[n-i]   % MOD) * nCr(i-2, n-i)   % MOD;
        cases = (cases % MOD + MOD) % MOD;
        //cout << i << " " << cases << endl;
        ans += i * cases % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34388
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

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; }

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

int main() {
	ll A,B,Q;
	cin>>A>>B>>Q;
	vector<ll> s(A),t(B),x(Q);
	rep(i,A)cin>>s[i];
	rep(i,B)cin>>t[i];
	rep(i,Q)cin>>x[i];
	s.insert(s.begin(), {-INFLL});
	t.insert(t.begin(), {-INFLL});
	s.push_back(INFLL);
	t.push_back(INFLL);
	print(s);print(t);
	rep(i,Q){
		ll ans =  INFLL;
		int si = lower_bound(all(s), x[i]) - s.begin();
		int ti = lower_bound(all(t), x[i]) - t.begin();
		//cerr<<x[i]<<" "<<si<<" "<<ti<<endl;
		for(int j = si-1; j <= si; j++){
			for(int k = ti-1; k <= ti; k++){
				ll S = s[j];
				ll T = t[k];
				chmin(ans, abs(S - x[i]) + abs(S - T));
				chmin(ans, abs(T - x[i]) + abs(T - S));
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3680
#include<stdio.h>

int main(void)
{
	unsigned long long int kai=1;
	int n,i,x=0;
	scanf("%d",&n);
	for(i=1;i<n+1;i++)
	{
		 kai=kai*i;

		 while(kai % 10 ==0)
		 {
			 kai = kai / 10;
			 x+=1;
		 }
	}
	if(x==0){
	printf("%llu\n",kai);
	}
	else
	{
		printf("%llu",kai);
		for(i=0;i<x;i++)
		{
			printf("%d",0);
		}
		printf("\n");
	}
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<char> S(N);
    for(int i=0; i<N; i++) cin >> S.at(i);
    int Rcnt = 0, Gcnt = 0, Bcnt= 0; 
    for(int i=0; i<N; i++){
        if(S.at(i) == 'R') Rcnt++;
        else if(S.at(i) == 'G') Gcnt++;
        else Bcnt++;
    }
    int64_t rgb = Rcnt;
    rgb *= Gcnt;
    rgb *= Bcnt;
    for(int i=1; i<=(N - 1)/2; i++){
        for(int j=0; 2*i+j<N; j++){
            if (S.at(j) != S.at(i+j) && S.at(i+j) != S.at(2*i+j) && S.at(2*i+j) != S.at(j)){
                rgb--;
            }
        }
    }
    cout << rgb  << endl;
}

Measured memory_bytes: 3608
n=int(input())

field=[[0 for i in range(20)]for j in range(15)]

for i in range(n):
  
    b,f,r,v=map(int,input().split())
    h=(b-1)*4+f-1
    w=r*2-1
    n=v
    field[h][w]+=n
    
for y in range(15):
  
    for x in range(20):
      
        if(y%4==3):field[y][x]='#'
        elif x%2==0 :field[y][x]=' '
        print(field[y][x],end='')
    
    print()


Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k;
    cin >> n >> k;
    int ans = 1;
    rep(i,n)
    {
	    ans = min(ans * 2, ans + k);
    }
    cout << ans << endl;

}


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

void input(vector<int>& rvnProblm)
{
  int nProblmSiz;
  cin >> nProblmSiz;
  rvnProblm.resize(nProblmSiz);

  for (int& rnProblm : rvnProblm)
    cin >> rnProblm;
}
  
int calcDevPgmCnt(const vector<int>& cnrvnProblm)
{
  vector<int> vnSrtProblm(cnrvnProblm);
  sort(begin(vnSrtProblm), end(vnSrtProblm));

  int n = vnSrtProblm.size() / 2;
  return (vnSrtProblm[n] - vnSrtProblm[n - 1]);
}
  
int main()
{
  vector<int> vnProblm;

  input(vnProblm);
  cout << calcDevPgmCnt(vnProblm) << endl;

  return 0;
}

Measured memory_bytes: 4044
(N, X) = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
    
ans = 0

diff = []
for i in range(len(x)-1):
    diff.append(x[i+1] - x[i])
#print("diff: ")
#print(diff)

base = min(diff)
for i in range(1, base+1):
    flag = True
    if base%i != 0:
        continue
    div = int(base/i)
    for j in range(len(diff)):
        if diff[j]%div != 0:
            flag = False
            break
    if flag == True:
        ans = div
        break

print(ans)



Measured memory_bytes: 14228
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int a,b;
  cin>>a>>b;
  string s(b,'0'+a);  
  string t(a,'0'+b);
string ans=t;
  if(a<=b) ans=s;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 998244353
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 709
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int sa[mx],du[mx],level[mx],g[mx][mx],n,m,u,v,warna[mx];
vector<int>b[mx];
bool sudah[mx];
void dfs(int now,int lev){
//	debug(now);
//	debug(lev);
	sudah[now]=true;
	level[now]=lev;
	for(int i:b[now]){
		if(!sudah[i])dfs(i,lev+1);
		else{
			if(abs(level[now]-level[i])%2==0){
			//	debug(now);
			//	debug(i);
				cout<<-1<<endl;
				exit(0);
			}
		}
	}
}

int dep[mx][mx],idx;

int dp(int now,int pick){
	if(now==idx+1)return pick;
	int&ret=dep[now][pick];
	if(ret!=-1)return ret;
	ret=1e9;
	ret=min(ret,dp(now+1,abs(pick+sa[now]-du[now])));
	ret=min(ret,dp(now+1,abs(pick-sa[now]+du[now])));
	return ret;
}

void lagi(int now,int lev){
//	debug(now);
	sudah[now]=true;
	if(lev&1)sa[idx]++;
	else du[idx]++;
	for(int i:b[now]){
		if(!sudah[i])lagi(i,lev+1);
	}
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>u>>v;
		g[u][v]=g[v][u]=1;
	}
	for(int i=1;i<=n;i++)g[i][i]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(g[i][j]==0){
				b[i].pb(j);
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(!sudah[i])dfs(i,1);
	}
	//debug(n);
	reset(dep,-1);
	reset(sudah,false);
	for(int i=1;i<=n;i++){
		if(!sudah[i]){
			++idx;
			lagi(i,0);
		}
	}
	int jaw=dp(1,0);
	int satu=(jaw+n)/2;
	int dua=n-satu;
	cout<<satu*(satu-1)/2+dua*(dua-1)/2<<endl;
}




Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){

      int n;
       cin>>n;

      map<int,string>p;

         p[2] = "hon";
         p[4] = "hon";
         p[5] = "hon";
         p[7] = "hon";
         p[9] = "hon";
         p[0] = "pon";
         p[1] = "pon";
         p[6] = "pon";
         p[8] = "pon";
         p[3] = "bon";

          int rem = n % 10;

           cout<<p[rem];
}


Measured memory_bytes: 3580
#include <map>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MIN(_A, _B) (((_A) < (_B)) ? (_A) : (_B))

int h, w, n;
std::map<int, bool> M[233333];
int p[233333][2];
int f[233333];
int ans;

int main(){
	scanf("%d %d %d", &h, &w, &n);
	for(int i = 1; i <= n; i++){
		scanf("%d %d", &p[i][0], &p[i][1]);
		M[p[i][0]][p[i][1]] = true;
	}
	ans = h;
	f[1] = 1;
	for(int i = 2; i <= h; i++){
		if(M[i][f[i - 1] + 1]) f[i] = f[i - 1];
		else f[i] = f[i - 1] + 1;
	}
	for(int i = 1; i <= n; i++){
		if(p[i][0] == 1) continue;
		if(p[i][1] <= f[p[i][0] - 1]) ans = MIN(ans, p[i][0] - 1);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 30592
/// In The Name Of God
/// I wish, that I could leave it all behind me / Go to my own world where no one can find me
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define int long long
#define ll long long
#define pii pair <int , int>
#define ld long double
#define for2(a,b,c) for(int (a) = (b); (a) < (c); (a)++)
#define for3(a,b,c) for(    (a) = (b); (a) < (c); (a)++)
#define setp cout << fixed << setprecision(15)
//#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define all(x) (x).begin() , (x).end()


int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vector<pair<string,string> > v((1<<n));
    for2(mask,0,(1<<n)){
        string a,b;
        for2(i,0,n) if(mask & (1<<i)) a += s[i];
                                else  b += s[i];
     //   if(a.length() < b.length() || ((a.length() == b.length()) && a>b)) swap(a,b);
        reverse(all(b));
    //    if(a.length() == 4) cout << a << ' ' << b << endl;

       // if(a.length() == 2) cout << a << ' ' << b << endl;
        v[mask] = {a,b};
    }
    sort(all(v));
  //  for(auto x : v) cout << x.F << ' ' << x.S << endl;
  //  cout << endl;

    ll ans = 0;
    for2(mask,0,(1<<n)){
        string a,b;
        for2(i,0,n) if(mask & (1<<i)) a += s[i+n];
                                else  b += s[i+n];
     //   if(a.length() < b.length() || ((a.length() == b.length()) && a>b)) swap(a,b);
        reverse(all(a));
    //    cout << a << ' ' << b << endl;
      //  if(a.length() == 2) cout << a << ' ' << b << endl;
        pair<string,string> p = {a,b};
        int t = 1;
        if(a == b) t = 1;
        ans += (upper_bound(all(v),p) - lower_bound(all(v),p))/t;

    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 33408
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        int n=sc.nextInt();
        int z[] =new int[n];
        for(int i=0;i<n;i++) {
            z[i]=sc.nextInt();
        }
        for(int i=(n-1);i>=1;i--) {
            System.out.print(z[i]+" ");
            }
        for(int i=(n-1);i>=0;i--) {
            if(i==0) 
            System.out.print(z[i]);
            }System.out.println();
        }
    }


Measured memory_bytes: 26444
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

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

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

int main() {
	int N;
	lli a[1000*100];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
	}
	sort(a, a+N);

	int num = 0;
	int index = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (index != a[i]) {
			if (num < index) {
				ans += num;
			}
			num = 1;
			index = a[i];
		} else {
			num++;
		}

		if (num > index) {
			ans++;
		}
		eprintf("index %d num %d ans %d\n", index, num, ans);
	}
	if (num < index) {
		ans += num;
	}
	printf("%d\n", ans);
}


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

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	for (int i = 1; i <= 1000; i++) {
		if ((floor(i*0.08) == A) and (floor(i*0.1) == B) ) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
   int n,m,k;
   cin>>n>>m>>k;
   char s[n+9][m+9];
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<m;j++)
        cin>>s[i][j];
   }
   int ans=0;
   for(int a=0;a<(1<<n);a++)
   {
       for(int b=0;b<(1<<m);b++)
       {
           int cnt=0;
           for(int i=0;i<n;i++)
           {
               for(int j=0;j<m;j++)
               {
                   if(((1<<i)&a) or ((1<<j)&b))
                    continue;
                   if(s[i][j]=='#')cnt++;
               }
           }
           if(cnt==k)ans++;
       }
   }
   cout<<ans;

}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

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

    ll P, Q, R;
    cin >> P >> Q >> R;

    cout << min(P+Q, min(P+R, Q+R)) << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
h = gets.split.map(&:to_i)

INF = 10010010001

dp = Array.new(n, INF)
dp[0] = 0

0.upto(n - 2) do |i|
  dp[i + 1] = [dp[i + 1], dp[i] + (h[i + 1] - h[i]).abs].min
  dp[i + 2] = [dp[i + 2], dp[i] + (h[i + 2] - h[i]).abs].min if i + 2 < n
end

puts dp[n - 1]


Measured memory_bytes: 11396
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
map<int, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	string board[50];
	for (int i = 0; i < h; ++i) cin >> board[i];
	const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
	const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (board[i][j] == '#') continue;
			int num = 0;
			for (int d = 0; d < 8; ++d) {
				const int ni = i + dy[d];
				const int nj = j + dx[d];
				if (ni < 0 or h <= ni) continue;
				if (nj < 0 or w <= nj) continue;
				if (board[ni][nj] == '#') num++;
			}
			board[i][j] = char(num + '0');
		}
	}
	for (int i = 0; i < h; ++i) cout << board[i] << endl;
	return 0;
}

Measured memory_bytes: 256
x, k, d = map(int, input().split())
x = abs(x)
if x >= k * d:
    print(x - k * d)
else:
    a = x - (x // d) * d
    if (k - (x // d)) % 2 != 1:
        print(a)
    else:
        print(abs(a - d))

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  string s;
  cin >> s;
  if(s=="Sunny")
    cout << "Cloudy" << endl;
  else if(s=="Cloudy")
    cout << "Rainy" << endl;
  else
    cout << "Sunny" << endl;
}


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

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

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

vector<pair<int,int>> A(N);
int a;

rep(i,N){
    cin>>a;
    A[i]=mp(a,i+1);
}

sort(A.begin(),A.end());
rep(i,N)cout<<A[i].second<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int_max 1e18

int power(int x,int n)
{
    if(n==0)
        return 1;
    return x*power(x,n-1);
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    // ll t;cin>>t;
    // while(t--)
    // {
        string s;cin>>s;
        if(s=="ABC")cout<<"ARC";else{cout<<"ABC";}
        // ll n,q;cin>>n>>q;string s;cin>>s;map<char,int>mp;
        // for(ll i=0;i<s.length();i++)mp[s[i]]++;
        // while(q--)
        // {
        //     ll c,ans=0;cin>>c;
        //     for(auto it=mp.cbegin();it!=mp.cend();++it){if(it->second-c>0)ans+=it->second-c;}
        //     cout<<ans<<"\n";
        // }
    // }
    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).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;
}

int dp[20010];

int main(){
    int h,n;
    cin >>h >> n;
    vector<int>a(n),b(n);
    rep(i,n)cin >> a[i] >> b[i];
    rep(i,20010){
        dp[i] = inf;
    }
    dp[0] = 0;
    rep(i,n){
        for(int j=0;j<=h;j++){
            chmin(dp[j+a[i]],dp[j]+b[i]);
        }
    }
    int mi = inf;
    for(int k=h;k<=20001;k++){
        chmin(mi,dp[k]);
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct P{
  int f[N2];
  int space;
  string path;

  bool operator<(const P&p) const{
    int i;
    for(i=0;i<N2;i++){
      if(f[i]==p.f[i])continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};

static const int dx[4]={-1, 0, 1, 0};
static const int dy[4]={0, -1, 0, 1};
static const char dir[4]={'u', 'l', 'd', 'r'};

bool isT(P p){
  int i;
  for(i=0;i<N2;i++)
    if(p.f[i]!=(i+1))return false;
    return true;
}

string bfs(P s){
  queue<P> Q;
  map<P, bool> V;
  P u, v;
  s.path="";
  Q.push(s);
  V[s]=true;
  int sx, sy, tx, ty, r;

  while(!Q.empty()){
    u=Q.front();
    Q.pop();
    if(isT(u)) return u.path;
    sx=u.space/N;
    sy=u.space%N;
    for(r=0;r<4;r++){
      tx=sx+dx[r];
      ty=sy+dy[r];
      if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
      v=u;
      swap(v.f[u.space], v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
        V[v]=true;
        v.path+=dir[r];
        Q.push(v);
      }
    }
  }
  return"unsolvable";
}

int main(){
  P in;
  int i;

  for(i=0;i<N2;i++){
    cin>>in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  string ans=bfs(in);
  cout<<ans.size()<<endl;

  return 0;
}


Measured memory_bytes: 30680
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;
const int maxn = 200005;
ll b[maxn];
int n;
void update(int x ,ll d) {
	while (x <= n) {
		b[x] = max(b[x], d);
		x += x & (-x);
	}
}
ll query(int x) {
	ll ret = 0;
	while (x) {
		ret = max(ret, b[x]);
		x -= x & (-x);
	}
	return ret;
}
void go() {
	cin >> n;
	int h[n + 5], w[n + 5];
	f(n) {
		cin >> h[i];
	}
	f(n) {
		cin >> w[i];
	}
	ll ans = 0;
	f(n) {
		ll v = query(h[i]) + w[i];
		ans = max(ans, v);
		update(h[i], v);
	}
	cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}

Measured memory_bytes: 6716
#include <stdio.h>

int main ()
{
	char buf,last,mid;
	int count=0;
	buf = getchar();
	last = buf;
	while((mid=getchar())!='\n')
	{
		last = buf;
		buf = mid;
		if(buf != last) ++count;
	}
	printf("%d\n",count);
	return 0;
}

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

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )

template < typename T >
inline T read( )
{
	register T x = 0;
	register char ch = gc( );
	register bool f = 0;
	while( !std::isdigit( ch ) )
	{
		f = ( ch == '-' );
		ch = gc( );
	}
	while( std::isdigit( ch ) )
	{
		x = x * 10 + ( ch - '0' );
		ch = gc( );
	}
	return f ? -x : x;
}

template < typename T >
void print( T x )
{
	if( x < 0 )
	{
		x = -x;
		pc( '-' );
	}
	if( x < 10 )
	{
		pc( x + 48 );
		return;
	}
	print < T > ( x / 10 );
	pc( x % 10 + 48 );
	return ;
}

namespace Solution
{
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( ' ' )
#define ptl( i ) print < long long > ( i ), putchar( ' ' )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
	const int Maxn = 204001;
	int n, a[ Maxn ];
	long long ans = 0;
	std::deque < int > v;
	void fakemain( )
	{
		n = rdi( );
		For( i, 1, n )
			a[ i ] = rdi( );
		std::sort( a + 1, a + 1 + n, std::greater < int > ( ) );
		v.push_back( a[ 1 ] );
		int last = 1;
		For( i, 2, n )
		{
			if( a[ i ] == a[ i + 1 ] )
				continue;
			int d = a[ i ];
			For( j, last + 1, i )
			{
				ans += v.front( );
				v.pop_front( );
				v.push_back( d );
				v.push_back( d );
			}
			last = i;
		}
		ptl( ans ); 
		return;
	}

} // namespace Solution

int main( int argc, char* argv[] )
{
	Solution::fakemain( );
	return 0;
}

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

int solve(int p, int q, int s, int t)
{
    int ans = 0;
    for (int i = p; i <= s; i++)
    {
        for (int j = q; j <= t; j++)
        {
            if (i % 2 == 1 && j % 2 == 0)
                continue;
            else
                ans++;
        }
    }
    return ans;
}

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << solve(a, b, c, d) << endl;
    }
}


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
	
	int n; cin >> n;
	vector<int> h(n);
	vector<int> w(n, 1000000000);
	for (int i = 0; i < n; i++) { cin >> h[i]; }
	for (int i = 0; i < n; i++) {

		if (2 <= i) {
			w[i] = min(w[i - 1] + abs(h[i] - h[i - 1]), w[i - 2] + abs(h[i] - h[i - 2]));
		}
		else {
			if (i == 1) {
				w[i] = w[i - 1] + abs(h[i] - h[i - 1]);
			}
			if (i == 0) {
				w[i] = 0;
			}
		}

	}
	//for (int i = 0; i < n; i++) { cout << w[i] << " "; }
	cout << w[n - 1] << endl;
	//cout << w[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 1024
def solve():
    N = int(input())
    d = [int(input()) for _ in range(N)]
    d.sort()

    number_of_steps = 0
    previous_diameter = 0
    for i in range(N):
        if d[i] > previous_diameter:
            number_of_steps += 1
        previous_diameter = d[i]

    print(number_of_steps)

solve()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll cost=INF;
  vector<ll> a(3);
  rep(i,3){
  	cin>>a[i];
   }
   ll cnt=0,temp=0,latter;
   do {
   		cnt=0,temp=0;
   		reps(x,a){
   			if(cnt==0){
   				temp=0;
   				latter=x;
   				cnt++;
   			}else{
   				temp+=abs(x-latter);
   				latter=x;
   			}
   		}
   		cost=min(cost,temp);
    } while( next_permutation(all(a))); 
    cout<<cost<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,k;cin>>a>>b>>c>>k;ll sum=0;
  if(a>=k)  cout<<k<<endl;
  else if(a+b>=k)cout<<a<<endl;
   else if(a+b+c>=k)
   {
     cout<<a-(k-a-b)<<endl;
   }
}


Measured memory_bytes: 3592
N,M = map(int,input().split())
PY = [list(map(int,input().split())) + [i] for i in range(M)]

PY.sort()

pnow = PY[0][0]
c = 1

ans = [-1 for i in range(M)]

for i in range(M):
    if pnow != PY[i][0]:
        c = 1
        pnow = PY[i][0]
    ans[PY[i][2]] = str(PY[i][0]).zfill(6) + str(c).zfill(6)
    c += 1

print('\n'.join(ans))


Measured memory_bytes: 34500
N = int(input())
MOD = 10 ** 9 + 7
x = 1
for i in range(2, N + 1):
  x *= i

count = 1
ans = 1
for i in range(2, N + 1):
  if x % i != 0:
    continue
  count = 1
  while x % i == 0:
    x //= i
    count += 1
  ans *= count
print(ans % MOD)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long int
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N = 1e6 + 5;
const int oo = 1e9 + 5;
const LL ooll = 1e18 + 5;
const int MOD = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l, r) uniform_int_distribution<int>(l, r)(rng)

int v[205];
void solve() {
    int n, ans = 0;
    cin >> n;
    for (int i=0;i<n;++i) cin >> v[i];
    for (int i=0;i<n;++i) for (int j=i+1;j<n;++j) for (int k=j+1;k<n;++k) {
        if (v[i] + v[j] <= v[k] || v[i] + v[k] <= v[j] || v[j] + v[k] <= v[i]) continue;
        if (v[i] == v[j] || v[j] == v[k] || v[i] == v[k]) continue;
        ++ans;
    }
    cout << ans << '\n';
}

int main() {
    FASTIO;
    int T = 1;
    // cin >> T;
    while(T--) {
        solve();
    }
    // cerr << fixed << setprecision(10);
    // cerr << (clock() - start) / ((long double)CLOCKS_PER_SEC) << '\n';
    return 0;
} 

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> a(3),b(3);
  for(int i = 0; i < 3; i++)
  {
    cin >> a.at(i) >>b.at(i);
  }
  int ans =0;
  for(int i = 1; i < 3; i++){
 if(a.at(0)==a.at(i)||a.at(0)==b.at(i)||b.at(0)==a.at(i)||b.at(0)==b.at(i))
 ans++;
  }
  
 if(a.at(1)==a.at(2)||a.at(1)==b.at(2)||b.at(1)==a.at(2)||b.at(1)==b.at(2))
 ans++;
 
 if(ans==2)
 cout<<"YES"<<endl;
 else
 {
   cout<<"NO" <<endl;
 }
 
  
}

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

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

const int INF=1e9+5;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,res=0,fres=0;
    vector<int> af;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];

    for(int i=1; i<n; i++)
    {
        if(a[i]<=a[i-1]){
            res++;
            fres=max(fres,res);
        }
        else
        {
            res=0;
        }

    }

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


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
#define pi acos(-1.0)
int main()
{
   long int n,a,i,ara[10000];
   long long s=0,p;
   scanf("%ld %ld",&n,&a);
   for(i=0;i<a;i++)
   {
       scanf("%ld",&ara[i]);
       s=s+ara[i];
   }
   p=n-s;
   if(p<0) printf("-1");
   else printf("%lld\n",p);
   return 0;
}



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

int main() {
  int a,b;
  int cnt=0;
  
  cin >> a >> b;
  
  for (int i=a; i<=b; i++){
    string num;
    num=to_string(i);
    if (num[0]==num[4] && num[1]==num[3]){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll const N=1e3;
ll INF=0x3f3f3f3f;
ll a[N];
int main()
{
    ll n,k,lk,s=0,minz=1000,maxn=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    minz=s/n;
    lk=11234456789,k=0;
   // cout<<lk<<endl;
    for(int i=minz;i<=minz+1;i++)
    {
        s=0;
        for(int j=1;j<=n;j++)
        {
            s+=(i-a[j])*(i-a[j]);
        }
        if(lk>s)
        {
            lk=s;
            k=i;
        }
    }
    cout<<lk<<endl;
    return 0;
}


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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

int H, W;
int s[52][52];

signed main(){
	cin >> H >> W;
	
	string wk;
	REP(i, 0, H) {
		cin >> wk;
		REP(j, 0, W)
			if(wk[j] == '#')	s[i+1][j+1] = 1;
	}
//	REP(i, 0, H+2) {
//	    REP(j, 0, W+2) {
//	        cout << s[i][j] << " ";
//	    }
//	    cout << endl;
//	}
	REP(i, 1, H+1) {
		REP(j, 1, W+1) {
			if(s[i][j] == 1 && s[i-1][j] == 0 && s[i+1][j] == 0
				 			&& s[i][j-1] == 0 && s[i][j+1] == 0) {
				 cout << "No" << endl;
				 return 0;
			}
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000000
#define P1 31
#define P2 37
#define M  1000000007
#define M2 1000000009
#define pii pair<ll,ll>
typedef long long ll;
using namespace std;
const int N = 355001;
const int SQRTN = 320;
const int LOGN = 20;
const long double PI = acos(-1);
const long double TAU = 2*PI;

ll n,sum,a[N];

signed main(){
    cin >> n;
    for(int i = 0 ; i < 3*n ; i++){
        scanf("%lld",&a[i]);
    }
    sort(a,a+(3*n));
    for(int i = n ; i<n*3 ; i+=2)sum+=a[i];
    cout << sum << endl;


}



Measured memory_bytes: 2560
//unionfind
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int par[100010];//親
int rnk[100010];//ランク

void init(int n){//初期化
  for(int i=0;i<n;i++){
     par[i]=i;
     rnk[i]=0;
  }
}

int find(int x){//親を求める
  if(par[x]==x) return x;
  return par[x]=find(par[x]);
}

void unite(int x,int y){//union
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(rnk[x]<rnk[y]){//rankが小さい方にくっつける
    par[x]=y;
  }
  else{
   par[y]=x;
    if(rnk[x]==rnk[y])rnk[x]++;//rankが同じ時は1増やす
  }
}

bool same(int x,int y){
 return find(x)==find(y); 
}

int main(){cout<<fixed<<setprecision(10);
		   int n,m;
           cin>>n>>m;
           int ans=n;
           int x,y,z;
           init(n);
           rep(i,0,m){
             cin>>x>>y>>z;
             unite(x,y);
           }
           rep(i,1,n){
             if(same(i,0)){
              ans--; 
             }
             else{
               unite(0,i);
             }
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 4420
n, a, b = map(int, input().split())
mod = 1000000007
all_comb = pow(2, n, mod)

def inv(k):
    return pow(k, mod - 2, mod)

def comb(k):
    x = 1
    y = 1
    for i in range(k):
        y = y * (n - i) % mod
        x = x * (i + 1) % mod
    return y * inv(x) % mod

ans = all_comb - 1 - comb(a) - comb(b)
print(ans % mod)

Measured memory_bytes: 38512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int x, y, z;
	cin >> x >> y >> z;
	cout << ((x - z) / (y + z));
	return 0;
}

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

#define INF_LL (int64)1e18
//#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


constexpr int64 mod = 1e9+7;

vector<int64> divisor(int64 x) {
    vector<int64> res;
    for (int64 i = 1; i*i <= x; i++) {
        if (x % i == 0) {
            res.push_back(i);
            if (x/i != i)
                res.push_back(x/i);
        }
    }
    sort(all(res));
    return res;
}

int main(void) {
    int64 N, K;
    cin >> N >> K;
    vector<int64> A(N);
    REP(i, N) cin >> A[i];
    int64 sum = accumulate(all(A), 0);
    auto div = divisor(sum);
    reverse(all(div));
    for (auto r : div) {
        vector<int64> a;
        REP(i, N) {
            if (A[i] % r != 0) a.push_back(A[i] % r);
        }
        sort(all(a));
        int64 ls = 0, rs = 0;
        ls = accumulate(all(a), 0);
        bool ok = a.empty();
        for (int64 i = a.size()-1; i >= 0; i--) {
            ls -= a[i]; rs += r - a[i];
            if (ls == rs && ls <= K) {
                ok = 1;
            }
        }
        if (ok) {
            cout << r << endl;
            return 0;
        }
    }
}


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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	ll x; cin >> x;
	ll ans = 0;
	if (x <= 6) ans = 1;
	else if (x <= 11) ans = 2;
	else {
		ans = 2 * (x / 11);
		x %= 11;
		if (x > 0 && x <= 6) ans++;
		else if (x > 0) ans += 2;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
dic = {}
m = 0

for _ in range(N):
    s = input()
    if s not in dic:
        dic[s] = 0
    dic[s]+=1
    if dic[s]>m:
        m = dic[s]

re = {}
for key in dic:
    if dic[key] not in re:
        re[dic[key]] = []
    re[dic[key]].append(key)
    
for one in sorted(re[m]):
    print(one)


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

int main(){
    string s;cin>>s;
    ll ans=0;
    int n=s.size();

    for(int bit=0;bit<(1<<n-1);bit++){
        string ss="";
        for(int i=0;i<n;i++){
            ss+=s[i];
            if(bit>>i&1){
                ans+=stoll(ss);
                ss="";
            }
        }
        ans+=stoll(ss);
        ss="";
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3572
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInteger
getIntList = map readInt . BS.words <$> BS.getLine
getIntMatrix = map (map readInt . BS.words) . BS.lines <$> BS.getContents

main = do
  [r,d,x] <- getIntList
  mapM_ print $ take 10 $ drop 1 $ iterate (f r d) x

f r d x = r*x-d

Measured memory_bytes: 380
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ggr getchar();getchar();return 0;
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int a[114];
signed main() {
	int n, inf = 1000000000000, cnt = 0;
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	for (int j = a[0]; j <= a[n - 1]; j++) {
		for (int i = 0; i < n; i++) {
			cnt += abs(a[i] - j)*abs(a[i] - j);
		}
		if (cnt < inf)inf = cnt;
		cnt = 0;
	}
	cout << inf << endl;
	ggr
}

Measured memory_bytes: 256
using System;

namespace codefestival_2016_final_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int sqrt = (int)Math.Sqrt(n) - 1;
            while (sqrt * (sqrt + 1) / 2 < n) sqrt++;
            for (int i = 1; i <= sqrt; i++)
            {
                if (i == sqrt * (sqrt + 1) / 2 - n) continue;
                Console.WriteLine(i);
            }
        }
    }
}

Measured memory_bytes: 13140
if __name__ == "__main__":
    n, m = map(int, input().split())
    l = 1
    r = n

    for _ in range(m):
        li, ri = map(int, input().split())
        if l < li:
            l = li
        if r > ri:
            r = ri

    print(max(r-l+1,0)) 

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using namespace std;
long mod=1e9+7,a[1<<17],b[1<<17];
int n;
vector<int>G[1<<17];
long f(int,int);
long g(int,int);
long f(int u,int p)
{
	if(a[u])return a[u];
	a[u]=1;
	for(int i=0;i<G[u].size();i++)if(p!=G[u][i])a[u]=a[u]*g(G[u][i],u)%mod;
	return a[u]=(a[u]+g(u,p))%mod;
}
long g(int u,int p)
{
	if(b[u])return b[u];
	b[u]=1;
	for(int i=0;i<G[u].size();i++)if(p!=G[u][i])b[u]=b[u]*f(G[u][i],u)%mod;
	return b[u];
}
main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int x,y;cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	cout<<f(1,0)<<endl;
}

Measured memory_bytes: 15232
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		//int cnt = 0;
		//while(cnt < 101){
		long result = 0;
		//s = String.valueOf(cnt);
		int len = s.length();
		int next = 0;
		int five = 0;
		for(int i = len-1; i >= 0; i--){
		    int n = s.charAt(i) - '0';
		    n += next;
		    if(n >= 5) n += five;
		    if(n <= 4){
		        result += n;
		        next = 0;
		        five = 0;
		    }else if(n == 5){
		        result += n;
		        next = 0;
		        five = 1;
		    }else{
		        result += 10 - n;
		        next = 1;
		        five = 0;
		    }
		}
		result += next;
		
		// 出力
		System.out.println(result);
		//System.out.println(cnt + ":" + result);
		//cnt++;
		//}
	}
}


Measured memory_bytes: 34872
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  for (int i = 0; 7*i<=n; ++i) {
    if ((n-7*i)%4==0) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}


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


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(s==u) a--;
    else b--;
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 
# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)
# define UB upper_bound

const int MAXN = 100 * 1000 + 10;
int a[MAXN], b[MAXN], ind[MAXN];

bool c(int i, int j)
{
	return (a[i] + b[i] > a[j] + b[j]);
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
	{
		cin >> a[i] >> b[i];
		ind[i] = i;
	}
	sort(ind, ind + n, c);

	ll ans = 0;
	for (int i = 0; i < n; i ++)
		ans += ((i & 1 ^ 1) ? a[ind[i]] : (-1 * b[ind[i]]));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
int main(){
  int cnt=1;
  short dt[100002];
  while(true){
    scanf("%d",dt+cnt);
    if(!dt[cnt])break;
    ++cnt;
  }
  for(int i=1;i<cnt;++i)
    printf("Case %d: %d\n",i,dt[i]);
}

Measured memory_bytes: 2616
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()
    

int main(){
  ll N;
  cin >> N;
  vec A(N);
  rep(i,N){
    cin >> A.at(i);
  }
  ll x=0,y=0,k=0,ans=0;
  while(y<N){
    while(x<N&&(k^A.at(x))==(k+A.at(x))){
      k+=A.at(x);
      x++;
    }
    ans+=x-y;
    k^=A.at(y);
    y++;
  }
  cout << ans << endl;
}
      

Measured memory_bytes: 4848