akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin >> s >> t;
	ll ans = 0, k = 0;
	int n = s.size(),m = t.size();
	vector<vector<int>> dist(n,vector<int>(26,-1));
	dist.at(n - 1).at(s.at(n - 1) - 'a') = n - 1;
	for(int i = n - 2; i >= 0; i--){
		rep(j,26){
			dist.at(i).at(j) = dist.at(i + 1).at(j);
		}
		dist.at(i).at(s.at(i) - 'a') = i;
	}
	rep(i,m){
		char c = t.at(i);
		if(s.at(k) == c){
			ans++;
			k++;
			k %= n;
		}
		else{
			if(dist.at(k).at(c - 'a') == -1){
				ans += n - k;
				k = 0;
				if(dist.at(k).at(c - 'a') == -1){
					cout << -1 << endl;
					return 0;
				}
				ans += dist.at(k).at(c - 'a') - k + 1;
				k = dist.at(k).at(c - 'a') + 1;
				k %= n;
			}
			else{
				ans += dist.at(k).at(c - 'a') - k + 1;
				k = dist.at(k).at(c - 'a') + 1;
				k %= n;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 13776
#include <bits/stdc++.h>
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
const int MAX=2e3+5;
const int NAX=1e3+5;
const ll INF=1e18+5;
const double M=4e18;
using namespace std;
const int MOD=1e9+7;
typedef pair<int,int> pii;
const double eps=0.000000001;
int n,m;
ll dis[NAX];
int from[MAX],to[MAX];
bool neg[MAX];
ll cost[MAX];
ll an;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d%lld",&from[i],&to[i],&cost[i]);
        cost[i]=-cost[i];
    }
    fill(dis+1,dis+1+n,INF);
    dis[1]=0;
    for(int i=0;i<n-1;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(dis[from[j]]==INF)
                continue;
            if(dis[to[j]]>dis[from[j]]+cost[j])
            {
                dis[to[j]]=dis[from[j]]+cost[j];
            }
        }
    }
    an=dis[n];
    for(int i=0;i<n-1;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(dis[from[j]]==INF)
                continue;
            if(dis[to[j]]>dis[from[j]]+cost[j])
            {
                neg[to[j]]=true;
                dis[to[j]]=dis[from[j]]+cost[j];
            }
            if(neg[from[j]])
                neg[to[j]]=true;
        }
    }
    if(neg[n])
        printf("inf\n");
    else
        printf("%lld\n",-an);
}

Measured memory_bytes: 256
#include <stdio.h>


int main(){
    int r, g, b, num, rem;
    scanf("%d %d %d", &r, &g, &b);
    num = 100*r + 10*g + b;
    rem = num % 4;

    if(rem == 0){
	printf("YES");
    }else{
	printf("NO \n" );
    }    

    return 0;
}

Measured memory_bytes: 128
/*
AtCoDeer has red, blue and green cards.
Cards is written from 1 to 9. and red card is wriiten r, blue card is written b, green card is written g.
Line three cards in order to red, blue, green.
*/

#include <stdio.h>

int main(void)
{
  int r, g, b;
  int integer;

  scanf("%d %d %d", &r, &g, &b);

  integer = r*100 + g*10 + b;

  if (integer%4 == 0) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong();
        long b = scan.nextLong();
        long c = scan.nextLong();
        long k = scan.nextLong();
        if(k%2==0)System.out.println(a-b);
        else System.out.println(b-a);
    }
}

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

int main(void){
	int N,i,j;
	scanf("%d",&N);
	int r[N],diff[N-1];
	for(i=0;i<N;i++)
	{
		scanf("%d",&r[i]);
	}
	
	int min=r[0];
	
	for(i=1;i<N;i++)
	{
		
		if(min>=r[i-1])
		{
			min=r[i-1];
		}
		for(j=0;j<i;j++)
		{
			diff[i-1]=r[i]-min;
			//printf("%d %d %d\n",diff[i-1],r[i],min);
		}
	}
	
	int max=diff[0];
	
	for(i=0;i<N-1;i++)
	{
		if(max<=diff[i])
		{
			max=diff[i];
		}
	}
	
	printf("%d\n",max);
	
	return 0;
}


Measured memory_bytes: 3348
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

vector<pair<long long, long long>> FACT(long long n) {
    vector<pair<long long, long long>> res;
    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            long long cnt = 0;
            while (n % i == 0) cnt++, n /= i;
            res.push_back(make_pair(i, cnt));
        }
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {

    long long N, P;
    cin >> N >> P;

    auto res = FACT(P);
    long long ans = 1;

    for (auto x : res) {
        if (x.second >= N) {
            long long d = x.second / N;
            for (int i = 0; i < d; i++) ans *= x.first;
        }
    }


    cout << ans << endl;

}



























Measured memory_bytes: 256
def main():
    S = input()
    K = int(input())
    ans = []
    def dfs(s,cnt):
        res = cnt 
        if len(s) > K:
            return
        for i in range(97,123):
            tmp = s + chr(i)
            if tmp in S:
                res += 1
                ans.append(tmp)
                if res == K:
                    return
                dfs(tmp,res)

    
    dfs('',0)
    ans.sort()
    print(ans[K-1])



if __name__ == "__main__":
    main()

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

using namespace std;

int main() {
    int n = 0, m = 0;
    vector<int> t, constt;
    vector<int> p;
    vector<int> x;
    cin >> n;

    int temp = 0;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        t.push_back(temp);
        constt.push_back(temp);
    }
    cin >> m;

    int tempp = 0, tempx = 0;
    for (int i = 0; i < m; ++i) {
        cin >> tempp >> tempx;
        p.push_back(tempp);
        x.push_back(tempx);
    }

    int ans = 0;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < t.size(); ++j) {
            if (j == p[i] - 1) {
                t[j] = x[i];
            }
            ans += t[j];
        }
        cout << ans << endl;
        for (int k = 0; k < t.size(); ++k) {
            t[k] = constt[k];
        }
        ans = 0;
    }
}

Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	int iCount5 = 0, iCount7 = 0;

	cin >> a >> b >> c;

	if (a == 5)
		++iCount5;

	if (a == 7)
		++iCount7;

	if (b == 5)
		++iCount5;

	if (b == 7)
		++iCount7;

	if (c == 5)
		++iCount5;

	if (c == 7)
		++iCount7;

	if (iCount5 == 2 && iCount7 == 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
a,b,c = map(int,input().split())
flag = False
if a == b:
  if a != c:
    flag = True
elif b == c:
  if a != b:
    flag = True
elif c == a:
  if a != b:
    flag = True
if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
using P=pair<int,int>;

int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<vector<int>> a(n,vector<int> (m));
    vector<int> c(n);

    rep(i,n){
        cin>>c[i];
        rep(j, m){
            cin>>a[i][j];
        }
    }

    int ans =12345678;
    int all = 1<<n;
    rep(mask, all){
        vector<int> level(m);
        int cost = 0;
        rep(i,n){
            if((mask>>i)&1){
                cost += c[i];
                rep(j, m){
                    level[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        
        rep(j, m) {
            if(level[j] < x) ok = false;
        }

        if(ok) ans = min(ans,cost);
    }

    if (ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;

}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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

int main() {
	int a,b;
	cin >> a >> b;
	int cur=1;
	int count=0;
	while (cur < b) {
		count++;
		cur--;
		cur += a;
	}
	cout << count << endl;

  return 0;
}


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


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

struct Segtree{
    int N;
    vector<int> data;
    const int DEFAULT = 0;

    Segtree(int n){
        N=1;
        while(N <= n) N*=2;
        data.resize(2*N-1);
        for(int i=0;i<2*N-1;i++){
            data[i] = DEFAULT; 
            //maxの時は-1とか-INFとか、sumなら0
        }
    }

    void update(int k, int a){
        k+=N-1;//kは0-indexed
        data[k] = a;

        while(k > 0){
            k = (k-1)/2;
            data[k] = max(data[2*k+1],data[2*k+2]); 
            //min,max,sumなどで可変
        }
    }

    int query(int a,int b){return query(a, b, 0, 0, N);}
    
    int query(int a, int b, int k, int l, int r){
        // [l,r)より、r未満になるように値を入力する必要がある
        if(r <= a || b <= l) return DEFAULT; //初期化値
        if(a <= l && r <= b) return data[k];
        int vl = query(a, b, 2*k+1, l, (l+r)/2);
        int vr = query(a, b, 2*k+2, (l+r)/2, r);
        return max(vl,vr);//minじゃなくても
    }

    int a(int k){
        return data[N+k-1]; //kは0-indexed
    }
};

int main(){
    int N,K;
    cin>>N>>K;
    Segtree S(300010);
    //S.update(1,5);
    //cout<<S.query(0,0)<<S.query(1,1)<<S.query(1,2);
    rep(i,0,N){
        int a;
        cin>>a;
        int now = S.query(max(a-K,0),min(a+K+1,300001));
        S.update(a,now+1);
    }

    cout<<S.query(0,300002);
    
    return 0;
}

Measured memory_bytes: 7468
a,b,c=map(int,input().split())
if (a>b):
   n=a
   a=b
   b=n
if (b>c):
   n=b
   b=c
   c=n
if (a>b):
   n=a
   a=b
   b=n
print(str(a)+" "+str(b)+" "+str(c))


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i > (ll)(n); --i)
const ll MOD = 1000000007;
const ll MMOD = 998244353;
const double pi = 3.14159265358979323846;

int main(void){
    int n;
    cin >> n;
    n %= 10;
    if(n == 3) cout << "bon" << endl;
    else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    
    return 0;
}

Measured memory_bytes: 3568
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}


ll pr[1000000]={};
void makelcm(ll n){
    ll a=0;
    while(n%2==0){
        n/=2;
        a++;
    }
    pr[2]=max2(pr[2],a);
    // printf("%lld ",pr[2]);
    repp(i,3,min2(n,999)+2,2){
        if(n<i) break;
        if(n%i==0){
            a=0;
            while(n%i==0){
                n/=i;
                a++;
            }
            pr[i]=max2(pr[i],a);
        }
    }
    if(n>1000){
        pr[n]=1;
    }
}

/*aのb進数時の桁数*/
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
/*nをa進数にしたときの、i桁目の数*/
ll placenai(ll n, ll a, ll i){return i==1?n%a:placenai(n/a,a,i-1);}
/*aのn乗(mod)*/
ll modpow(ll a, ll n, ll mod){
    ll i,s[digits(n,2)],ans=1;
    for(i=0;i<digits(n,2);i++){
        s[i]= i==0 ? a : s[i-1]*s[i-1]%mod ;
        ans*=placenai(n,2,i+1)==1?s[i]:1; ans%=mod;}
    return n==0?1:ans;
}

ll inv[1000005];
void makeinv(ll n){
    inv[1]=1;
    for(ll i=2;i<=n;i++){
        inv[i]=MOD1 - inv[MOD1%i] * (MOD1 / i) % MOD1;
        // finv[i] = finv[i - 1] * inv[i] % MOD1;
        }
}

int main(void){
    // char ;
    ll n,ans=0;
    scanf("%lld",&n);
    ll a[n];
    rep(i,0,n){
        scanf("%lld",&a[i]);
        makelcm(a[i]);
    }
    makeinv(maxn(n,a));
    ll lcms=1;
    rep(i,0,1000000){
        if(pr[i]!=0){
            lcms = lcms*modpow(i,pr[i],MOD1)%MOD1;
        }
    }
    // printf("%lld\n",lcms);
    ll b[n];
    rep(i,0,n){
        b[i]=lcms*inv[a[i]];
        b[i]%=MOD1;
        // printf("%lld ",b[i]);
    }
    rep(i,0,n){
        ans+=b[i];
        ans%=MOD1;
    }
    // rep(i,0,100){
    //     printf("%lld ",pr[i]);
    // }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 15744
import sys
readline=sys.stdin.readline

N,X,M = map(int,readline().split())
route = [X]
dic = {}
first = []
loop = []
for i in range(1, N):
  X = (X ** 2) % M
  if X in dic:
    first = route[:dic[X]]
    loop = route[dic[X]:]
    break
  route.append(X)
  dic[X] = i
  
if len(first) == 0:
  print(sum(route[:N]))
  exit(0)

if N == len(first):
  print(sum(first))
elif N < len(first):
  print(sum(first[:N]))
else:
  ans = sum(first)
  one_loop = sum(loop)
  N -= len(first)
  loop_cnt = N // len(loop)
  rest = N % len(loop)
  ans += loop_cnt * (sum(loop))
  ans += sum(loop[:rest])

  print(ans)


Measured memory_bytes: 15816
#include<cstdio>
#include<deque>
#include<algorithm>

using namespace std;

typedef double Real;

long long ts[500500];
long long vs[500500];
Real vals[500500];
int N;
long long L;

void input(){
	scanf("%d%lld", &N, &L);
	for(int i = 0; i < N; ++i){
		scanf("%lld%lld", ts + i, vs + i);
	}
}

typedef pair<long long, Real> P;

deque<P> deq;

Real ans[500500];

bool check(P p1, P p2, P p3){
	Real dx1 = p2.first - p1.first;
	Real dy1 = p2.second - p1.second;
	Real dx2 = p3.first - p1.first;
	Real dy2 = p3.second - p1.second;
	return (dx1 * dy2 - dx2 * dy1 >= 0);
}

Real f(Real x, Real y, Real a, Real b){
	//printf("%f %f %f %f\n", x, y, a, b);
	return x + (y - x) * (a / (a + b));
}

void solve(){
	for(int i = 0; i < N; ++i){
		vals[i] = (Real)ts[i] * vs[i];
//		printf("%f\n", vals[i]);
	}
	ans[0] = ts[0];
	deq.push_front(P(0, 0));
	deq.push_back(P(L, vals[0]));
	for(int i = 1; i < N; ++i){
		if(vs[i] == L){
			P fi = deq[0];
			P nfi = P(fi.first - vs[i], fi.second - vals[i]);
			while(deq.size() >= 2){
				deq.pop_back();
			}
			deq.push_front(nfi);
			ans[i] = ts[i];
			continue;
		}
		long long ub = deq[0].first + L - vs[i];
		while(deq.back().first > ub){
			P tmp = deq.back();
			deq.pop_back();
			if(deq.back().first > ub){
				continue;
			}else if(deq.back().first == ub){
				break;
			}else{
				Real nxt = f(deq.back().second, tmp.second, ub - deq.back().first, tmp.first - ub);
				deq.push_back(P(ub, nxt));
//				printf("%f\n", nxt);
				break;
			}
		}
		P fi = deq[0];
		P nfi = P(fi.first - vs[i], fi.second - vals[i]);
		while(deq.size() >= 2){
			if(check(nfi, deq[0], deq[1])){
				deq.pop_front();
			}else{
				break;
			}
		}
		deq.push_front(nfi);
		Real val = deq.back().second - deq[0].second;
		ans[i] = val / L;
	}
}

int main(){
	input();
	solve();
	for(int i = 0; i < N; ++i){
		printf("%.12f\n", ans[i]);
	}
	return 0;
}


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

int a, b, c;
int a2, b2, c2;
int step;

int main() {
	scanf("%d%d%d", &a, &b, &c);
	while (step <= 100000) {
		if (a & 1 || b & 1 || c & 1) break;
		++step;
		a2 = a >> 1; b2 = b >> 1; c2 = c >> 1;
		a = b2 + c2;
		b = a2 + c2;
		c = a2 + b2;
	}
	if (step == 100001) puts("-1");
	else printf("%d\n", step);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int>vec(N-1);
  vector<int>vv(N);
  for (int X=0; X<N-1; X++){
    cin >> vec[X];
    vv[vec[X]-1]+=1;
  }
  for (int X=0; X<N; X++){
    cout << vv[X] << endl;
  }
}


Measured memory_bytes: 4828
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    ll N, M;
    cin >> N >> M;
    ll num[M];
    fill(num, num + M, 0);
    REP(i, 0, N) {
        ll K;
        cin >> K;
        REP(i, 0, K) {
            ll a;
            cin >> a;
            num[a - 1]++;
        }
    }
    ll ans = 0;
    REP(i, 0, M) {
        if (num[i] == N) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll n;
	cin >> n;
	ll ans=100000000000000ll;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			chmin(ans,i+(n/i)-2);
		}
	}
	cout << ans << endl;
}

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

int main(){
  int A;
  cin >> A;
  vector<int>B(A+1);
  vector<int>C(A+1);
  for(int i=1;i<=A;i++){
    cin >> B[i];
    C[B[i]]++;
  }
  for(int i=1;i<=A;i++){
    cout << C[i] << endl;
  }
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll d[2][2] = {{0, 1}, {1, 0}};
    const ll inf = LONG_LONG_MAX / 2 + 1;
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    vector<vector<ll>> dp(h, vector<ll>(w, inf));
    queue<pair<ll, ll>> q;
    q.emplace(0, 0);
    dp[0][0] = (s[0][0] == '#') ? 1 : 0;
    while(!q.empty()) {
        auto p = q.front(); q.pop();
        ll x = p.second, y = p.first;
        rep(i, 2) {
            ll nx = x + d[i][0];
            ll ny = y + d[i][1];
            if ((nx < 0) || (nx >= w) || (ny < 0) || (ny >= h)) continue;
            ll v = dp[y][x];
            if ((s[y][x] != '#') && (s[ny][nx] == '#')) v++;
            if (dp[ny][nx] > v) {
                dp[ny][nx] = v;
                q.emplace(ny, nx);
            }
        }
    }
    cout << dp[h - 1][w - 1] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    cout << min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 256
n = int(input())
a = input().split()
i = 0
while i < n:
  a[i] = int(a[i])
  i = i + 1 
 
i = 0
while i < n:
  j = i + 1
  while j < n:
    if a[i] < a[j]:
      temp = a[i]
      a[i] = a[j]
      a[j] = temp
    j = j + 1
  i = i + 1
 
sums = sum(a)

if(sums - a[0] > a[0]):
  print("Yes")
else:
  print("No")
sum = sum(a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,cnt[26];
char s[100005];
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k;
	scanf("%d",&n);
	scanf("%s",s);
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
    for(i=0;i<n;++i){
		++cnt[s[i]-'a'];
	}
	int res=1;
	for(i=0;i<26;++i){
		res=(LL)res*(LL)(cnt[i]+1)%MOD1;
	}
	res+=MOD1-1ll;
	res%=MOD1;
	printf("%d\n",res);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

Measured memory_bytes: 384
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector<double> vd;
typedef std::vector<std::string> vs;
typedef std::vector<pii> vpii;
typedef std::vector<vi> vvi;
typedef std::vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { rep(i,v.size()) is >> v[i]; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int &s = 0, const int &d = 0, const Weight &w = 0) : src(s), dst(d), weight(w) {}
};

typedef std::vector<Edge> Edges;
typedef std::vector<Weight> Array;
typedef std::vector<Array> Matrix;

class Graph {
  std::vector<Edges> g;

public:
  Graph(const int &size = 0) : g(size) {}
  int size() const { return g.size(); }
  const Edges &operator[](const int &i) const { return g[i]; }
  void addArc(const int &src, const int &dst, const Weight &w = 1) { g[src].emplace_back(src, dst, w); }
  void addEdge(const int &node1, const int &node2, const Weight &w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }
};

template<int inf = std::numeric_limits<Weight>::max() / 8> std::pair<std::vector<Weight>, std::vector<int>> dijkstra(const Graph &g, const int &src) {
  using state = std::pair<Weight, int>;
  std::priority_queue<state, std::vector<state>, std::greater<state>> q;
  std::vector<Weight> dist(g.size(), inf);
  std::vector<int> via(g.size());
  dist[src] = 0;
  q.emplace(0, src);
  while (q.size()) {
    Weight d;
    int v;
    std::tie(d, v) = q.top();
    q.pop();
    if (dist[v] < d) continue;
    for (auto &e : g[v]) {
      if (cmin(dist[e.dst], dist[v] + e.weight)) {
        via[e.dst] = v;
        q.emplace(dist[e.dst], e.dst);
      }
    }
  }
  return {dist, via};
}

main {
  int n, m;
  cin >> n >> m;
  Graph t(n);
  char gomi;
  rep(i, m) {
    int a, b, c, d;
    cin >> a >> gomi >> b >> gomi >> c >> gomi >> d;
    --a, --b;
    t.addArc(a, b, c);
    t.addArc(b, a, d);
  }
  int s, g, v, p;
  cin >> s >> gomi >> g >> gomi >> v >> gomi >> p;
  --s, --g;
  vector<Weight> dist1 = dijkstra(t, s).first;
  vector<Weight> dist2 = dijkstra(t, g).first;
  cout << v - p - dist1[g] - dist2[s] << endl;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define faster cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define MOD (int)(1e9+7)


const int N=1e5+5;


// fun(node,color);
// func(node,white)=func(child,white)+func(child,black) + ;
// func(node,black)=func(child,white);

vector<int> edge[N];
ll dp[N][2];
int n;
int u,v;

// 0 for white
// 1 for black

void dfs(int x, int last)
{
	dp[x][0] = dp[x][1] = 1;
	for (auto to : edge[x]) {
		if (to == last) continue;
		dfs(to, x);
		dp[x][0] = dp[x][0] * ((dp[to][0] + dp[to][1]) % MOD) % MOD;
		dp[x][1] = dp[x][1] * dp[to][0] % MOD;
	}
}
 

int main()
{
	cin>>n;
	
	for(int i=0;i<n-1;i++)
	{
		cin>>u>>v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	dfs(1,-1);
	cout<<(dp[1][0]+dp[1][1])%MOD<<endl;
}
	


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

int ara[2100],path[2004],vis[2003],ck[2001][2001];
vector<int>adj[2009];

void bfs(int src, int dst)
{
    queue<int>q;
    int fr,sc,tr=0,sz;  path[src]=0;  vis[src]=1;

    q.push(src);

    while(!q.empty())
    {
        fr=q.front();  q.pop();
        sz=adj[fr].size();
        for(int i=0;i<sz;i++)
        {
            sc=adj[fr][i];
            if(vis[sc]==0)
            {

            path[sc]=path[fr]+1;  //cout<<sc<<"   "<<src<<"   "<<dst<<"    "<<path[sc]<<endl;



            if(ck[src][sc]==0 && sc>src){ara[path[sc]]++; ck[src][sc]==77;}

            q.push(sc);  vis[sc]=1;


            }
        }

        if(tr==1)
        {
            break;
        }

    }

    while(!q.empty())
    {
        q.pop();
    }
}

int main()
{



    int n,x,y,i,j,k;

    scanf("%d %d %d",&n,&x,&y);
    for(i=1;i<n;i++)
    {
        adj[i].push_back(i+1);
        adj[i+1].push_back(i);

    }

    adj[x].push_back(y);  adj[y].push_back(x);

    for(i=1;i<n;i++)
    {




            bfs(i,n);
            memset(vis,0, sizeof vis);


    }

    for(i=1;i<=n-1;i++)
    {
        printf("%d\n",ara[i]);
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        int a,b,c,k;
        cin>>a>>b>>c>>k;
        int sum = 0;
        a = min(a,k);
        k-=a;
        b = min(b,k);
        k-=b;
        c = min(c,k);
        k-=c;
        sum =a+c*-1;
        cout<<sum;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define print(n) cout << n << endl
#define in(v) int v; cin >> v
#define vint vector<int>
#define pb push_back
typedef long long int ll;

int main(){
  int n,m,x;cin>>n>>m>>x;
  int c[n],a[n][m];
  rep(i,n){
    cin >> c[i];
    rep(j,m){
      cin >> a[i][j];
    }
  }
  int mn=1000000000;
  for(int i=0;i<(1<<n);i++){
    int sum[m],cost=0;
    rep(j,m)sum[j]=0;
    for(int j=0;j<n;j++){
      if(i&(1<<j)){
        rep(k,m){
          sum[k]+=a[j][k];
        }
        cost+=c[j];
      }
    }
    int f=1;
    rep(j,m){
      if(sum[j]<x){
        f=0;
      }
    }
    if(f==1){
      mn=min(mn,cost);
    }
  }
  if(mn==1000000000){
    print(-1);
  }else{
    print(mn);
  }
  return 0;
}

Measured memory_bytes: 3636
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
INF = 10**18

N=ri()
dig = len(str(N))
ans = 0
if N>=357:
    for d in range(3,dig):
        ans += 3**d - 3*(2**d) + 3
    import itertools
    item = [3,5,7]
    for dl in itertools.product(item,repeat=dig):
        if 3 not in dl or 5 not in dl or 7 not in dl:
            continue
        n = 0
        for i in range(dig):
            n += dl[i]*(10**i)
        if N >= n:
            ans += 1

print(ans)



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

using namespace std;

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

void Main()
{
	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	for(int i = l; i <= r; i++){
		if(i % d == 0){
			ans++;
		}
	}
	cout << ans << endl;
}

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


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long k, x;
	cin >> k >> x;
	if (k * 500 >= x) cout << "Yes\n";
	else cout << "No\n";


	return 0;
}


Measured memory_bytes: 888
def main():

    N, Ma, Mb = map(int, input().split())
    drug = []
    for _ in range(N):
        a, b, c = map(int, input().split())
        drug.append([a, b, c])

    cur = dict()
    cur[(0, 0)] = 0
    for i in range(N):
        temp = cur.copy()
        for p in cur:
            a, b = p[0]+drug[i][0], p[1]+drug[i][1]

            if (a, b) not in temp:
                temp[(a, b)] = cur[p] + drug[i][2]
            else:
                temp[(a, b)] = min(temp[(a, b)], cur[p]+drug[i][2])
        cur = temp

    # print(cur)
    min_c = float('inf')
    for p in cur:
        if p != (0, 0) and p[0]*Mb == p[1]*Ma:
            min_c = min(min_c, cur[p])
    if min_c == float('inf'):
        return -1
    else:
        return min_c

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

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

using namespace std;

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(nullptr);
    string s;
    while (getline(cin, s)) {
//        cout << s << "\n";
        s[3] = '8';
        cout << s << "\n";
    }

    return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int m1, d1; cin >> m1 >> d1;
    int m2, d2; cin >> m2 >> d2;

    if (m1 != m2 && d2 == 1) {
        puts("1");
    } else {
        puts("0");
    }
}

Measured memory_bytes: 256
H,W = map(int,input().split())
ans = float("inf")
for h in range(1,H):
    S1 = h*W
    S2,S3 = (H-h)*(W//2),(H-h)*(W//2+1)
    S = max(S1,S2,S3) - min(S1,S2,S3) if W%2==1 else max(S1,S2) - min(S1,S2)
    ans = min(ans,S)
    h1 = H-h
    S2,S3 = (h1//2)*W,(h1//2+1)*W
    S = max(S1,S2,S3) - min(S1,S2,S3) if h1%2==1 else max(S1,S2) - min(S1,S2)
    ans = min(ans,S)
for w in range(1,W):
    S1 = H*w
    S2,S3 = (H//2)*(W-w),(H//2+1)*(W-w)
    S = max(S1,S2,S3) - min(S1,S2,S3) if H%2==1 else max(S1,S2) - min(S1,S2)
    ans = min(ans,S)
    w1 = W-w
    S2,S3 = H*(w1//2),H*(w1//2+1)
    S = max(S1,S2,S3) - min(S1,S2,S3) if w1%2==1 else max(S1,S2) - min(S1,S2)
    ans = min(ans,S)

print(ans)

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

int main(){
	int N,M;
	cin >> N >> M;
	
	vector<pair<int,int>> p(M);
	
	rep(i,M){
		int x,y;
		cin >> x >> y;
		x--;
		y--;
		p[i] = make_pair(y,x);
	}
	
	sort(p.begin(),p.end());
	
	int ans = 0;
	int cut = 100005;
	rep(i,M){
		if(cut >= p[i].first || p[i].second > cut){
			ans++;
			cut = p[i].first -1;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,ans,tmp,hoge,fuga,piyo;
ll A[200100],B[200100],C[200100],D[200100];
string st,str;
char ch;
int main(){
  cin>>a>>b>>c>>d>>e;
  cout<<((c-a)*60+(d-b)-e);
  return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int n=1;
		int i=0;
		while(n<B) {
			i++;
			n=n+A-1;
		}
		System.out.println(i);
	}
}

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

int main() {
  int R;
  cin >> R;
  
  if( R < 1200 ){
    cout << "ABC" << endl;
  }else if( R < 2800 ){
    cout << "ARC" << endl;
  }else if( R >= 2800 ){
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let ans=0
  rep(4,()=>{
    if(ssin()=='+')ans++
    else ans--
  })
  out(ans)
}
main();

Measured memory_bytes: 7372
<?php
  $n = intval(fgets(STDIN));

  $arrayA = explode(" ", trim(fgets(STDIN)));
  $arrayB = explode(" ", trim(fgets(STDIN)));

  $total = 0;
  for($i=0; $i<$n; $i++){
    if($arrayA[$i]>=$arrayB[$i]){
      $total += $arrayB[$i];
    }else{
      $total += $arrayA[$i];
      $arrayB[$i] -= $arrayA[$i];
      
      if($arrayB[$i]>0){
        if($arrayA[$i+1]>=$arrayB[$i]){
          $total += $arrayB[$i];
          $arrayA[$i+1] -= $arrayB[$i];
        }else{
          $total += $arrayA[$i+1];
          $arrayA[$i+1] = 0;
        }
      }
    }
  }

  echo $total."\n";

Measured memory_bytes: 20980
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=1000000000000001;
const double PI=3.141592653589;


int main(){
  string s; cin>>s;
  int ans=0;
  rep(i,s.size()){
    if(s[i]=='+')
    ans++;
    else
    ans--;
  }
  cout<<ans<<endl;

  return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int H, W, A, B;
  cin >> H >> W >> A >> B;

  rep(i, H){
    rep(j, W){
      if(((i < B) == (j < A))){
        cout << 0;
      }else{
        cout << 1;
      }
    }
    cout << endl;
  }


  return 0;
}


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

#define pb push_back
#define mp make_pair

#define F first
#define S second

using ll = long long;
using namespace std;

void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

const int mod = 1000000007;
const int INF = 1e+9;

ll a[100010][3];
ll dp[100010][3];

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }


    // jとkが一致していなければ更新
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k) {
                    chmax(dp[i+1][k], dp[i][j]+a[i][k]);
                }
            }
        }
    }

    ll res = 0;
    for (int i = 0; i < 3; i++) chmax(res, dp[n][i]);
    cout << res << endl;
}



Measured memory_bytes: 4992
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

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

	int sum = N;
	if (N % 2 == 0) ++sum;

	int i, j;
	vector<PII> res;
	FOR(i, 1, N + 1)
		FOR(j, i + 1, N + 1)
		if (i + j != sum)
			res.push_back(PII(i, j));

	printf("%d\n", SIZE(res));
	FOR(i, 0, SIZE(res)) printf("%d %d\n", res[i].first, res[i].second);
	return 0;
};


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve() {
    string S;
    cin >> S;

    int ans;
    if (S[0] == 'R' && S[1] == 'R' && S[2] == 'R') ans = 3;
    else if (S[1] == 'R' && (S[0] == 'R' || S[2] == 'R')) ans = 2;
    else if (S[0] == 'R' || S[1] == 'R' || S[2] == 'R') ans = 1;
    else ans = 0;
    cout << ans << endl;
}

int main(void) {
#ifndef ONLINE_JUDGE
    const auto in_stream = freopen("../in.txt", "r", stdin);
    if (in_stream == nullptr) {
        cerr << "ERROR!" << endl;
        return 1;
    }
#endif

    solve();

#ifndef ONLINE_JUDGE
    fclose(in_stream);
#endif
}


Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  int a[3];
  rep(i,3) cin >> a[i];
  sort(a, a+3);
  if(a[0]+a[1]==a[2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

signed main(){
	int N, D, A, X, H;
	scanf("%lld%lld%lld", &N, &D, &A);
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	while(N--){
		scanf("%lld%lld", &X, &H);
		pq.push(make_pair(X, H));
	}
	int ans = 0, now = 0;
	while(pq.size() > 0){
		X = pq.top().first;
		H = pq.top().second;
		pq.pop();
//		printf("(X, H) = (%lld, %lld)\n", X, H);
		if(H < 0){
			now += H;
		}
		else{
			if(H > now){
				ans += (H - now + A - 1) / A;
				pq.push(make_pair(X + 2 * D + 1, -((H - now + A - 1) / A) * A));
				now += (H - now + A - 1) / A * A;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

int main(){

    int n;
    cin >> n;
    vector<int> a(n+1,0);
    for(int i = 0 ;i < n;i++){
        cin >> a[i+1];
    }
   
    int count=0;
    for(int i = 1;i < n+1;i++){

        if(a[i] != i){
            continue;
        }else{
            swap(a[i],a[i+1]);
            count++;
        }

    }
    cout << count << endl;
    
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){
long long int a,b,c,sum=0;
  scanf("%lld%lld%lld",&a,&b,&c);
  if(b<c){
  sum=sum+(b+b);
  c=c-b;
  if(c>a){
    sum=sum+(a+1);
     printf("%lld",sum);
  }
    else if(c==a){
      sum=sum+c;
       printf("%lld",sum);
    }
    else{
      sum=sum+c;
       printf("%lld",sum);
    }
  }
  else if(b==c){
    sum=sum+(b+b);
     printf("%lld",sum);
  }
  else{
    sum=sum+(c+c);
    b=b-c;
    sum=sum+b;
     printf("%lld",sum);
  }

}

Measured memory_bytes: 128
from sys import stdin


def swqp(ps, li, ri):
    result = ps[:]
    tmp = result[li]
    result[li] = result[ri]
    result[ri] = tmp
    return result


def check(ps):
    for i in range(len(ps) - 1):
        if ps[i] > ps[i + 1]:
            return False
    return True


def main():
    N = int(stdin.readline().rstrip())
    ps = [int(x) for x in stdin.readline().rstrip().split()]
    if check(ps):
        print('YES')
        return
    for i in range(N - 1):
        for j in range(i + 1, N):
            if check(swqp(ps, i, j)):
                print('YES')
                return
    print('NO')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int main()
{
  int N;
  set<int> s;

  cin >> N;
  Rep(i, N) {
    int a; cin >> a;
    s.insert( a );
  }

  int s_size = s.size();
  if( s_size % 2 == 0 ) cout << s_size - 1 << endl;
  else cout << s_size << endl;
}

Measured memory_bytes: 4864
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[200007];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    int now=1;
    for(int i=1;i<=n;++i){
        if(a[i]==now){
            ++now;
        }
    }
    if(now>1)
        cout<<n-now+1;
    else
        cout<<-1;
    return 0;
}


Measured memory_bytes: 1024