akhauriyash/Code-Regression huggingface dataset:
#include <iostream> 
using namespace std;

int sushu[100001]={0};//素数表 
int qianzhui[100001]={0};//前缀和 
void sieve(){
	for(int i=2;i*i<=100000;i++){
		if(sushu[i]==0){//合数的倍数不需要再做筛选 
			for(int j=2;i*j<100000;j++){
			    //要把合数下标置1
			    sushu[i*j]=1;
		    }
		}
	}
}
int main(){
	int q,l,r;
	cin>>q;
	sieve();
	sushu[1]=1;
	sushu[2]=1;
	for(int i=1;i<=100000;i++){
		if(sushu[i]==0&&sushu[(i+1)/2]==0&&i!=2||i==3){
			qianzhui[i]=qianzhui[i-1]+1;
		}else{
			qianzhui[i]=qianzhui[i-1];
		}
	}
	for(int j=1;j<=q;j++){
		cin>>l>>r;
		cout<<qianzhui[r]-qianzhui[l-1]<<endl;
	} 
    return 0;
}

Measured memory_bytes: 3952
#include <stdio.h>

int answer(int,int);
int A[30],n;

int main(){
    int i,q,ans;

    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }

    scanf("%d",&q);
    int m[q];
    for(i=0;i<q;i++){
        scanf("%d",&m[i]);
    }

    for(i=0;i<q;i++){
        ans = answer(m[i],0);
        if(ans==1) printf("yes\n");
        else printf("no\n");
    }
 
 return 0;

}

int answer(int m,int a){
 int ans;
 if(m==0) return 1;
 if(a>n)return 0;
 /*OR演算子をつかう*/
 ans =answer(m,a+1)||answer(m-A[a],a+1);
 return ans;
}



Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    if (A >= 13)
        cout << B << endl;
    else if (A >= 6 && A <= 12)
        cout << B / 2 << endl;
    else
        cout << 0 << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#define MAX 101

int main(){
  int i,j,m,n,k,l,A[MAX][MAX];

  scanf("%d",&n);
  for(i = 0; i < MAX; i++){
    for(j = 0; j < MAX; j++){
      A[i][j] = 0;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d",&m);
    scanf("%d",&k);
    for(j = 0; j < k; j++){
      scanf("%d",&l);
      A[m][l] = 1;
    }
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      printf("%d",A[i+1][j+1]);
      if(j != n-1) printf(" ");
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2100
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    s = S()
    ans = 0

    for t in s:
        ans += int(t)

    print(yn[ans % 9 == 0])


if __name__ == '__main__':
    main()


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

int main() {
	int N;
	cin >> N;
	vector<int> fig(N);
	for (int i = 0; i < N; i++) {
		cin >> fig.at(i);
	}
	sort(fig.begin(), fig.end());
	int sum = 0;
	for (int i=0; i < N-1; i++) {
		sum += fig.at(i);
	}
	if (sum > fig.at(N - 1)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

def sumdigi(x) :
  ans=0
  temp=x
  while(temp>0) :
    #q=temp // 10
    md=temp % 10
    ans+=md
    temp =temp //10
  return ans
#print(sumdigi(834))

if n % sumdigi(n) ==0:
  print("Yes")
else :
  print("No")

Measured memory_bytes: 2940
int main()
{
    int n, i, x;
    scanf("%d", &n);

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


Measured memory_bytes: 2028
#include<iostream>
#include<cmath>
using namespace std;
int main(void)
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d))
        cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >>n;
    vector<int>l(n);
    for(int i=0;i<n;i++)cin >>l[i];
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    int ans=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
            if(l[i] < l[j] + l[k])ans++;
            }
        }
    }
    cout <<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N+2),B(N+1);
    for(int i=1;i<=N+1;i++) cin >> A[i];
    for(int i=1;i<=N;i++) cin >> B[i];
    ll ans = 0;
    for(int i=1;i<=N;i++){
        ans += min(A[i],B[i]);
        B[i] = max(B[i]-A[i],0LL);
        ans += min(A[i+1],B[i]);
        A[i+1] = max(A[i+1]-B[i],0LL);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>



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

int a,b;

int main(){
    cin >> a >> b;
    if( a <= 9 && b <= 9 && b > 0 && a >0){
        cout << a*b << endl;
    }
    else cout << -1 << endl;


return 0;
}


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

void hyouji(const vector<int> &v, int n) {
  for (int k = 0; k < n; k++) {
    if (k == n - 1) {
      cout << v.at(k) << endl;
    } else {
      cout << v.at(k) << " ";
    }
  }
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  hyouji(a, n);

  for (int i = 1; i < n; i++) {
    int v = a.at(i);
    int j = i - 1;
    while (j >= 0 && a.at(j) > v) {
      a.at(j + 1) = a.at(j);
      j--;
    }
    a.at(j + 1) = v;
    hyouji(a, n);
  }
}



Measured memory_bytes: 3080
# coding: utf-8

n = int(input().rstrip())
s = input().rstrip()

east_count = [ 0 for i in range(n)]
east_count[n-1] = (1 if s[-1] == "E" else 0)
for i in reversed(range(n-1)):
    east_count[i] = east_count[i + 1]
    if s[i] == "E":
        east_count[i] += 1

west_count = [0 for i in range(n)]
west_count[0] = 1 if s[0] == "W" else 0

for i in range(1,n):
    west_count[i] = west_count[i-1]
    if s[i] == "W":
        west_count[i] += 1

ans = n
for i in range(n):
    tmp = 0
    if i < n-1:
        tmp += east_count[i+1]
    if i > 0:
        tmp += west_count[i-1]

    ans = min(ans,tmp)

print(ans)

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

string s;

main() {
    cin >> s;
    if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) ct("Yes")
    else ct("No")
}








Measured memory_bytes: 256
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int fact(ll n) {
    int num = 0;
    while(n > 0) {
        num++;
        n /= 10;
    }
    return num;
}

int main(void) {
    ll n;
    cin >> n;
    vector<ll> decomp;
    ll a = 2;
    while ( n >= a* a) {
        if(n % a == 0) {
            decomp.push_back(a);
            n /= a;
        }else {
            a++;
        }
    }
    if(n != 1)
        decomp.push_back(n);

    int num = decomp.size();

    int ans = 100;
    for(int bit = 0; bit < (1 << num); ++bit) {
        ll fact1 = 1;
        ll fact2 = 1;
        for(int i = 0; i < num; ++i) {
            if(bit & (1 << i)) {
                fact1 *= decomp[i];
            }else {
                fact2 *= decomp[i];
            }
        }
        ans = min(ans, max(fact(fact1), fact(fact2)));
    }
    cout << ans << endl;
    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[]a=new int[n];
		int[]b=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
		}
		int maxa=0;
		int maxb=0;
		int mina=Integer.MAX_VALUE/2;
		int minb=Integer.MAX_VALUE/2;
		for(int i=0;i<n;i++) {
			if(maxa<a[i]) {
				maxa=a[i];
				maxb=b[i];
			}
			if(mina<a[i]) {
				mina=a[i];
				minb=b[i];
			}
		}
		int ans=maxa+maxb;
		System.out.println(ans);
	}
}

Measured memory_bytes: 65048
import sys
import collections
input = sys.stdin.readline

N,K = map(int,input().split())
a = list(map(int,input().split()))
c = collections.Counter(a)
d = len(c)
ans = 0
c_sorted = sorted(c.items(),key = lambda x:x[1])
for i in c_sorted:
    if K >= d:
        break
    ans += i[1]
    d -= 1
print(ans)

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

int main()
{
    int n, m, x, c[15], a[15][15], ans = -1;

    scanf("%d %d %d", &n, &m, &x);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &c[i]);
        for (int j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    }

    for (int i = 0; i < pow(2, n); i++)
    {
        int total = 0, check[15] = {0}, k = i, flag = 1;
        for (int j = 0; j < n; j++)
        {
            for (int l = 0; l < m; l++)
                check[l] += a[j][l] * (k % 2);

            total += c[j] * (k % 2);
            k /= 2;
        }

        for (int l = 0; l < m; l++)
        {
            if (check[l] < x)
                flag = 0;
        }

        if (flag && (ans > total || ans == -1))
            ans = total;
    }

    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 2600
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

void print(char *str, int a, int b)
{
	for (int i = a; i <= b; i++) {
		printf("%c", str[i]);
	}
	printf("\n");
}

void reverse(char *str, int a, int b) {
	char s[1024];
	strncpy( s, &str[a], b - a + 1);
	s[ b - a + 1 ] = '\0';
	int pos = b;
	for ( int i = a; i <= b; i++ ) {
		str[ pos ] = s[ i - a ];
		pos--;
	}
}

void replace(char *str, int a, int b, char *p) {
	for (int i = a; i <= b; i++) {
		str[i] = p[ i - a ];
	}

}

int main(void) {

	char sentense[1024];
	int n;
	char command[16];
	int st, ed;
	char p[1024];

	scanf("%s", sentense);
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", command);
		if (strcmp(command, "replace") == 0) {
			scanf("%d %d %s", &st, &ed, &p);
			replace(sentense, st, ed, p);
		} else if (strcmp(command, "reverse") == 0) {
			scanf("%d %d", &st, &ed);
			reverse(sentense, st, ed);
		} else if (strcmp(command, "print") == 0) {
			scanf("%d %d", &st, &ed);
			print(sentense, st, ed);
		}
	}


}

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

int main(){
  int N;
  string S;
  int answer=1;
  cin>>N;
  cin>>S;
  for(int i=1;i<N;i++){
    if(S[i-1]!=S[i]) answer++;
  }
  cout<<answer<<endl;
 return 0;
 }

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

int main() {
    long long N;
    cin >> N;
    N--;
    string s;
    while (N >= 0) {
        s.insert(s.begin(), 'a' + (N % 26));
        N = N / 26 - 1;
    }
    cout << s << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>

using namespace std;

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

    int N, K;
    char S[10];

    cin >> N;
    cin >> S;
    cin >> K;

    char k = S[K - 1];
    for (int i = 0; i < N; ++i)
    {
        if (S[i] != k)
        {
            cout << '*';
        }
        else
        {
            cout << S[i];
        }
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 888
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define MAXN 50010
#define MAXM 30
#define INF 1000000
int dp[MAXM][MAXN];
int n, m;
int C[MAXM];
int main(void) {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> C[i];
    }
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j <= n; j++) {
            if (j < C[i]) {
                dp[i+1][j] = dp[i][j];
            } else {
                dp[i+1][j] = min(dp[i][j], dp[i+1][j-C[i]]+1);
            }
//            printf("dp[%d][%d] = %d\n", i+1, j, dp[i+1][j]);
        }
    }
    cout << dp[m][n] << endl;
    return 0;
}

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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int X, Y;
    cin >> X >> Y;
    vector<int> x(N);
    vector<int> y(M);
    for(int n=0; n<N; n++) {
        cin >> x[n];
    }
    for(int m=0; m<M; m++) {
        cin >> y[m];
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    
    if(X<y[0] && y[0]<=Y && x[N-1]<y[0]) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int a[200];
  int i;
  for(i=0;i<150;++i)a[i]=0;
  
  for(i=0;i<n;++i){
    int d;
    scanf("%d",&d);
    a[d]++;
  }
  
  int ans = 0;
  
  for(i=0;i<150;++i){
    if(a[i]>0) ans++;
  }
  
  printf("%d\n",ans);
}


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

int main(){
    int n,a,b,ans=0;
    cin>>n>>a;
    rep(i,n-1){
        cin>>b;
        if(a<b)ans++;
        a=b;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



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

	for(int i=0;i<t;i++){
		long long A,B,C,D;
		scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
		long long g = __gcd(D,B);
		if(B>A){
			printf("No\n");
		}else if(B>D){
			printf("No\n");
		}else if(C>=B){
			printf("Yes\n");
		}else{
			if(B-g+(A%g)>C){
				printf("No\n");
			}else{
				printf("Yes\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
 
using namespace std;
typedef long long ll;
typedef vector<int> vi;
//const int MAX=;
 
int N,K;
int a[5002];
bool dp[5002][5002];
 
bool nn(int i){
	//i番目を使わず和をK-a[i]以上K-1以下にできるかどうか
	//dp[j][k]はj番目までで和をkにできるかどうか
  	dp[0][0]=true;
	rep1(j,N){
		if(j==i){
			rep(k,K)dp[j][k]=dp[j-1][k];
		}
		else{
			rep(k,K){
				dp[j][k]=dp[j-1][k];
				if(a[j]<=k)dp[j][k]=(dp[j][k] || dp[j-1][k-a[j]]);
			}
		}
	}
	bool ok=false;
	for(int k=max(0,K-a[i]);k<K;k++)if(dp[N][k])ok=true;
	
	return !ok;
	
}
 
int main(){
	cin>>N>>K;
	rep1(i,N)cin>>a[i];
	a[0]=0;
	sort(a,a+(N+1));
	
	int lb=0, ub=N+1;
	while(ub-lb>1){
		int mid=(ub+lb)/2;
		if(nn(mid))lb=mid;
		else ub=mid;
	}
	cout<<lb;
}

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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long max = -10000000000000000000000000000000000;
  if (max < a*c) max = a*c;
  if (max < a*d) max = a*d;
  if (max < b*c) max = b*c;
  if (max < b*d) max = b*d;
  
  cout << max;
  
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 87;
vector<int> g[N], s[2], c[3];
int p[N];
void dfs(int u, int p, int d)
{
    s[d % 2].push_back(u);
    for (int v : g[u])
        if (v != p)
            dfs(v, u, d + 1);
}
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1, 1, 1);
    if (s[1].size() < s[0].size())
        swap(s[0], s[1]);
    for (int i = 1; i <= n; ++i)
        c[i % 3].push_back(i);
    if (s[0].size() <= c[0].size()) {
        while (s[0].size()) {
            int x = s[0].back();
            s[0].pop_back();
            int y = c[0].back();
            c[0].pop_back();
            p[x] = y;
        }
        while (s[1].size()) {
            int x = s[1].back();
            s[1].pop_back();
            int y = -1;
            for (int i = 0; i < 3; ++i)
                if (c[i].size()) {
                    y = c[i].back();
                    c[i].pop_back();
                    break;
                }
            p[x] = y;
        }
    } else {
        while (s[0].size()) {
            int x = s[0].back();
            s[0].pop_back();
            int y = -1;
            for (int i : {2, 0})
                if (c[i].size()) {
                    y = c[i].back();
                    c[i].pop_back();
                    break;
                }
            p[x] = y;
        }
        while (s[1].size()) {
            int x = s[1].back();
            s[1].pop_back();
            int y = -1;
            for (int i : {1, 0})
                if (c[i].size()) {
                    y = c[i].back();
                    c[i].pop_back();
                    break;
                }
            p[x] = y;
        }
    }
    for (int i = 1; i <= n; ++i)
        cout << p[i] << " \n"[i == n];
}


Measured memory_bytes: 22260
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
const int MAX_H = 50000;
int main()
{
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    vector<vector<ll>> dp(N + 1, vector<ll>(MAX_H, INF));

    dp[0][0] = 0;
    rep(i, N) {
        rep(j, MAX_H) {
            if (j < A[i]) {
                chmin(dp[i + 1][j], dp[i][j]);
            }
            else {
                chmin(dp[i + 1][j], min(dp[i][j], dp[i + 1][j - A[i]] + B[i]));
            }
        }
        for (int j = MAX_H - 2; j >= 0; j--) {
            chmin(dp[i + 1][j], dp[i + 1][j + 1]);
        }
    }
/*
    rep(i, N + 1) {
        rep(j, 2 * H + 1) {
            cout << (dp[i][j] == INF ? -1 : dp[i][j]) << " ";
        }
        cout << endl;
    }
*/

    ll ans = INF;
    repd(i, H, MAX_H) chmin(ans, dp[N][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 396040
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int dp[405][405];
int main(){
    int n, ma,mb;
    cin >> n >>ma >> mb;
    rep(i,405)rep(j,405)dp[i][j] = 1<<29;
    dp[0][0] = 0;
    rep(i,n){
        int a, b, c;
        cin >> a >> b >> c;
        rep(i,405)rep(j,405){
            if(dp[404-i][404-j] == 1<<29)continue;
            dp[404-i+a][404-j+b] = min(dp[404-i+a][404-j+b],dp[404-i][404-j]+c);
        }
    }
    int ans = 1<<29;
    rep(i,405)rep(j,405){
        if(i==0 or j == 0)continue;
        int g = __gcd(i,j);
        if(i/g==ma and j/g==mb){
            ans = min(ans, dp[i][j]);
        }
    }
    if(ans == 1<<29)ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#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 rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

typedef pair<long long, long long> P;
int main(){
    long long n,m;
    cin>>n>>m;
    vector<P> v(n);
    rep(i,n){
        cin>>v[i].first>>v[i].second;
    }
    sort(v.begin(),v.end());
    long long i=0;
    long long ans=0;
    while(m>0){
        if(m>v[i].second){
            m-=v[i].second;
            ans+=v[i].second*v[i].first;
        }
        else{
            ans+=m*v[i].first;
            m=0;
        }
        i++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
signed main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  long long n,keta[5],ns,nb,kaisu=0,a=4;
  while(true){
    cin>>n;
    if(n==0000) break;
    else{
      if(n%1111==0) cout<<"NA"<<'\n';
      else{
	while(true){
	  if(n==6174){
	    cout<<kaisu<<'\n';
	    kaisu=0;
	    break;
	  }
	  else{
	    kaisu++;
	    for(int i=0;i<4;i++){
	      keta[i]=n%10;
	      n=n/10;
	    }
	    sort(keta,keta +a);
	    ns=keta[0]*1000+keta[1]*100+keta[2]*10+keta[3];
	    nb=keta[3]*1000+keta[2]*100+keta[1]*10+keta[0];
	    n=nb-ns;
	  }
	}
      }
    }
  }
  return(0);
}



Measured memory_bytes: 3180
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll=long long;
#define MOD  1000000007

int main(int argc, char const *argv[]) {
  int a[5];
  std::cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  if(a[2]==a[0]+a[1]) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
  return 0;
}

Measured memory_bytes: 256
import sys


S = [str(s) for s in input()]

s_dic = {}
for s in S:
    if s in s_dic.keys():
        s_dic[s] += 1
    else:
        s_dic[s] = 1


for i in s_dic.values():
    if int(i) != 2:
        print("No")
        sys.exit()

print("Yes")


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

using namespace std;

#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";
#define FIO ios_base::sync_with_stdio(false);cout.setf(ios::fixed);cout.precision(10);cout.tie(nullptr);cin.tie(nullptr);

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

template < class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template < class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template < class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template < class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); }return a; }

template <class T> inline T bigmod(T p, T e, T m) {
	T ret = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1) ret = (ret * p) % m; p = (p * p) % m;
	} return (T)ret;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif


void solve()
{
	vector<int> items(5);

	for(int i=0;i<5;i++){
		cin>>items[i];
	}

	for(int i=0;i<5;i++){
		if(items[i]==0){
			cout<<i+1<<nl;
			return;
		}
	}
}

int main()
{
	FIO;

	int t = 1;
	while (t--)
	{
		solve();
	}

	return 0;
}


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

using namespace std;

int main()
{
    int n,i,j,k,cnt=0;
    cin >> n;

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

    sort(L.begin(),L.end());

    for(i=0; i<n-2; i++){
        for(j=i+1; j<n-1; j++){
            for(k=j+1; k<n; k++){
                int I,J,K;
                I = L.at(i);
                J = L.at(j);
                K = L.at(k);
                
                if(I+J>K && J+K>I && K+I>J && I != J && J != K && K != I){
                    cnt++;
                }
            }
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>

#define MIN(a,b) ((a)<(b)?(a):(b))

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

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int *x=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",x+i);
  int *cnt=(int *)calloc(m,sizeof(int));
  for(i=0;i<n;i++) if(x[i]) cnt[x[i]%m]++;
  int ans=cnt[0]/2;
  cnt[0]%=2;
  for(i=1;i<m-i;i++){
    int k=MIN(cnt[i],cnt[m-i]);
    ans+=k;
    cnt[i]-=k;
    cnt[m-i]-=k;
  }
  if(m%2==0){
    ans+=cnt[m/2]/2;
    cnt[m/2]%=2;
  }
  qsort(x,n,sizeof(int),cmp);
  i=0;
  while(i+1<n){
    if(x[i]==x[i+1] && cnt[x[i]%m]>=2){
      ans++;
      cnt[x[i]%m]-=2;
      i+=2;
    } else {
      i++;
    }
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


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

int main(void) {
  int N;
  long long C;
  cin >> N >> C;
  vector<long long> x(N), v(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
  }

  vector<long long> R_cals(N), L_cals(N);
  vector<long long> R_max_cals(N), L_max_cals(N);
  vector<long long> R_b_cals(N), L_b_cals(N);
  long long cal = 0, nowx = 0;
  for (int i = 0; i < N; i++) {
    cal = cal - abs(nowx - x[i]);
    cal += v[i];
    R_cals[i] = cal;
    R_b_cals[i] = cal - x[i];
    if (i != 0) R_max_cals[i] = max(R_max_cals[i - 1], cal);
    else R_max_cals[i] = cal;
    nowx = x[i];
  }
  // for (int i = 0; i < N; i++) {
  //   cerr << R_cals[i] << " " << R_max_cals[i] << " " << R_b_cals[i] << endl;
  // }

  cal = 0, nowx = C;
  for (int i = 0; i < N; i++) {
    int id = N-1-i;
    cal = cal - abs(nowx - x[id]);
    cal += v[id];
    L_cals[i] = cal;
    L_b_cals[i] = cal - abs(C - x[id]);

    if (i != 0) L_max_cals[i] = max(L_max_cals[i - 1], cal);
    else L_max_cals[i] = cal;
    nowx = x[id];
  }

  // 左にi個行って戻ってくる
  long long ret = 0;
  for (int i = 0; i < N-1; i++) {
    ret = max(ret, L_b_cals[i] + R_max_cals[N-1-i-1]);
    ret = max(ret, R_b_cals[i] + L_max_cals[N-1-i-1]);
  }
  ret = max(R_max_cals[N-1], ret);
  ret = max(L_max_cals[N-1], ret);
  cout << ret << endl;
  return 0;
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL N, L;
  cin >> N >> L;

  LL sum = 0;

  LL aji = L;

  LL absmin = mod;
  LL a = 0;
  REP(i, N)
  {
    sum += aji;
    if(absmin>abs(aji)){
      absmin = abs(aji);
      a = aji;
    }
    aji++;
  }

  cout << sum - a << endl;
}


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

bool isDivisor(int target, int div)
{
    return target % div == 0;
}

int main()
{
    int a = 0, b = 0, c = 0;
    cin >> a >> b >> c;

    int count = 0;
    for (int i=a; i <= b; ++i)
    {
        count += isDivisor(c, i) ? 1 : 0;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1160
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        print(e - s, 'sec', file=sys.stderr)
        return ret

    return wrap


@mt
def slv(N, P):
    Q = [-1] * N
    for i, p in enumerate(P):
        Q[p - 1] = i

    p = -1
    mc = 0
    c = 0
    for q in Q:
        if q > p:
            c += 1
        else:
            c = 1
        mc = max(mc, c)
        p = q

    return N - mc


def main():
    N = read_int()
    P = [read_int() for _ in range(N)]

    print(slv(N, P))


if __name__ == '__main__':
    main()


Measured memory_bytes: 24028
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception{
    MyScanner sc = new MyScanner();
    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    String line = sc.next();
    int threshold = Integer.parseInt(line);
    char[] chars = line.toCharArray();

    char[] letters = new char[chars.length];
    for (int i = 0; i < letters.length; i++) {
      letters[i] = chars[0];
    }
    int result = Integer.parseInt(new String(letters));
    if (result>=threshold){

    }else {
      for (int i = 0; i < letters.length; i++) {
        int v = letters[i] + 1;
        letters[i] =(char)v;
      }
    }
    out.println(new String(letters));
    out.close();
  }

  /*
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}

Measured memory_bytes: 21076
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

typedef pair<double,int> P;
vector<double> dijkstra(int s, const vector<vector<pair<int,double> > >& G){
    priority_queue< P, vector<P>, greater<P> > que;
    vector<double> d(G.size(), LINF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        int curr  = que.top().second;
        double  dcurr = que.top().first;
        que.pop();
        if(d[curr] < dcurr) continue;
        int i;
        for(i=0; i<(int)G[curr].size(); i++){ 
            int next = G[curr][i].first;
            double  dist = G[curr][i].second;
            if(d[next] > d[curr] + dist){
                d[next] = d[curr] + dist;
                que.push(P(d[next], next));
            }
        }
    }
    return d;
}
 
 
int main(int argc, char* argv[])
{
    int xs,ys,xt,yt;
    scanf("%d%d%d%d", &xs, &ys, &xt, &yt);
    int n;
    scanf("%d", &n);
    vector<vector<int> > z;
    int i;
    for(i=0; i<n; i++) {
        vector<int> v(3);
        scanf("%d%d%d", &v[0], &v[1], &v[2]);
        z.push_back(v);
    }
    {
        vector<int> v(3);
        v[0]=xs; v[1]=ys;
        z.push_back(v);
    }
    {
        vector<int> v(3);
        v[0]=xt; v[1]=yt;
        z.push_back(v);
    }

    vector<vector<pair<int,double> > > G(n+2);
    int j;
    for(i=0; i<n+2; i++) {
        for(j=i+1; j<n+2; j++) {
            double tmp0=z[i][0]-z[j][0];
            double tmp1=z[i][1]-z[j][1];
            double tmp2=z[i][2]+z[j][2];
            double dist=MAX(0, sqrt(tmp0*tmp0+tmp1*tmp1)-tmp2);
            G[i].push_back(make_pair(j, dist));
            G[j].push_back(make_pair(i, dist));
        }
    }
    vector<double> vdist = dijkstra( n, G);
    printf("%.10lf\n", vdist[n+1]);

    return 0;
}



Measured memory_bytes: 22384
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2 * (1e5 + 5);

int main()
{
    fastio;
    ll i, j, k, t, n, m;

    cin>>n;
    vll a;
    for ( i = 0; i < n; i++)
    {
        cin>>j;
        a.pb(j);
    }
    
    ll money=1000, stock=0;

    for ( i = 0; i < n-1; i++)
    {
        if (a[i]>a[i+1])
        {
            money+=stock*a[i];
            stock=0;
        }
        else if (a[i]<a[i+1])
        {
            stock+=money/a[i];
            money%=a[i];
        }
    }
    money+=stock*a[n-1];
    
    cout<<money<<endl;
    

    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<string>
using namespace std;

int main(){
	string str,meirei,p,x;
	int q,a,b;

	cin >> str>>q;
	for (int i = 0; i < q; i++){
		cin >> meirei >> a >> b;
		if (meirei == "print"){
			cout << str.substr(a, b-a+1) << endl;
		}
		else if (meirei == "reverse"){
			while (a <= b){
				char temp = str[a];
				str[a] = str[b];
				str[b] = temp;
				a++;
				b--;
			}
		}
		else if (meirei == "replace"){
			cin >> p;
			for (int i = a; i <= b; i++){
				str[i] = p[i - a];
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3228
#include <stdio.h>
#include<stdlib.h>
#define ll long long

ll func( ll n ){
  if( n == 0 ) return 0;
  return func(n/10)+1;
}

int main(void){
  ll a,b;
  scanf("%lld %lld",&a,&b);
  for(int i=0;i<func(b);++i){
    a *= 10;
  }
  ll num = a + b;
  for(ll i=1;i*i<=num;++i){
    if( i*i == num ){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  // printf("%lld\n",num);
  return 0;
}



Measured memory_bytes: 1616
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();
    
    int D;
    cin >> D;
    
    cout << "Christmas ";
    
    for (int i = 1; i <= 25 - D; ++ i) {
   		cout << "Eve ";
    }
    
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n, x, m, min=1000, sum=0;;
    cin >> n >> x;
    for(int i=0; i<n; i++) {
        cin >> m;
        if(min>m) min=m;
        sum += m;
    }
    cout << n + (x-sum)/min << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    // 右端からApplePen
    string S;
    cin >> S;
    ll ans = 0;
    map<int, int> remain;
    remain[0] = 1;
    int power = 1;
    reverse(S.begin(), S.end());
    int cur = 0;
    for (char s : S) {
        int x = s - '0';
        cur += x * power;
        cur %= 2019;
        remain[cur]++;
        power *= 10; power %= 2019;
    }
    for (auto p : remain) {
        int y = p.second;
        ans += y * (y-1) / 2;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

const int MAX = 1000010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  int X, Y; cin >> X >> Y;
  ll n = (X+Y)/3;
  COMinit();
  if ((X+Y)%3==0 && n<=X && X<=2*n) {
    ll j = Y-n;
    ll ans = COM(n,j);
    cout << ans << endl;

  }
  else cout << 0 << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 27068
// In the Name of Allah
#include<bits/stdc++.h>
#define bp(i) __builtin_popcount(i)
#define double long double
typedef long long ll;
const ll MAX_N = 1e5+100;
const ll MOD = 1e9+7;
using namespace std;

int main()
{
    int n;
    cin >> n;
    set<string> st;
    for(int i = 1;i<=n;++i){
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size();
    return 0;
}


Measured memory_bytes: 19232
#include<iostream>
using namespace std;
int main(){
    int a,b,d,r;
    double f;
    
    cin >> a >> b;
    
    d = a/b;
    r = a%b;
    f = double(a)/double(b);
    
    cout << d << " " << r << " " << fixed <<f<< endl;
    
    return 0;
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<char>> A(N, vector<char>(N)), B(M, vector<char>(M));
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      cin >> A[i][j];
    }
  }
  for (int i=0; i<M; i++) {
    for (int j=0; j<M; j++) {
      cin >> B[i][j];
    }
  }
  string ans="No";
  int same=1;
  for (int i=0; i<=N-M; i++) {
    for (int j=0; j<=N-M; j++) {
      same=1;
      for (int k=0; k<M; k++) {
        for (int l=0; l<M; l++) {
          if (A[i+k][j+l]!=B[k][l]) {
            same=0;
          }
        }
      }
      if (same==1) {
        ans = "Yes";
        break;
      }
    }
    if (same==1) {break;}
  }
  cout << ans << endl;
}


Measured memory_bytes: 3560
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

int main() {
	string S, T;
	cin >> S >> T;

	string ans = T + S;

	cout << ans << endl;

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
	b = B[i]
	a1,a2 = A[i], A[i+1]
	if b <= a1:
		ans += b
	else:
		ans += a1
		rest = b - a1
		if rest <= a2:
			ans += rest
			A[i+1] -= rest
		else:
			ans += a2
			A[i+1] = 0
print(ans)

Measured memory_bytes: 18624
N, K = map(int, input().split())
A = list(map(int, input().split()))
def digits_count(n):
  cnt = 0
  while n != 0:
    cnt += 1
    n //= 2
  return cnt
M = digits_count(max(max(A), K))
L = digits_count(K)
X = [0 for _ in range(M)] # 1 times per digits
B = [1 for _ in range(M)]
for i in range(M-1):
  B[i+1] = B[i] * 2
for i in range(M):
  for j in range(N):
    X[i] += A[j] % 2
    A[j] //= 2
S = 0
for i in range(L, M):
  S += B[i] * X[i]
def XXOR(m, n):
  if n == 0:
    val = 0
    for i in range(m):
      val += B[i] * X[i]
    return val
  else:
    d = (n // B[m-1]) % 2
    if d == 1:
      left = B[m-1] * X[m-1]
      for i in range(m-1):
        left += max(X[i], N - X[i]) * B[i]
      return max(XXOR(m-1, n - B[m-1]) + (N - X[m-1]) * B[m-1], left)
    else:
      return XXOR(m-1, n) + X[m-1] * B[m-1]
print(XXOR(L, K) + S)

Measured memory_bytes: 15260
#!/usr/bin/env python3

from functools import lru_cache

def prime_factor_of_fact(n):
    di = {}
    for i in range(1, n + 1):
        pf = prime_factor(i)
        for p in pf:
            if p not in di:
                di[p] = 1
            else:
                di[p] += 1
    return di

@lru_cache()
def prime_factor(n):
    if n == 1:
        return []
    for i in range(2, n + 1):
        if n % i == 0:
            res = prime_factor(n // i) + [i]
            break
    return res

def shichigo_su(pff):
    have_seventyfour = len([k for k in pff if pff[k] >= 74])
    have_twentyfour = len([k for k in pff if pff[k] >= 24])
    have_fourteen = len([k for k in pff if pff[k] >= 14])
    have_four = len([k for k in pff if pff[k] >= 4])
    have_two = len([k for k in pff if pff[k] >= 2])
    if have_four >= 2 and have_two >= 3:
        res = ((have_four * (have_four - 1)) // 2) * (have_two - 2) \
            + have_fourteen * (have_four - 1) \
            + have_twentyfour * (have_two - 1) \
            + have_seventyfour
        return res
    else:
        return 0

def main():
    n = int(input())
    pff = prime_factor_of_fact(n)
    print(shichigo_su(pff))

main()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

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

        vector<int> h(n);
        REP(i, n) cin >> h[i];

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

        ll ans = 0;
        REP(i, n) {
                if (k <= i) {
                        ans += h[i];
                }
        }

        cout << ans << endl;

        return 0;
}


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

int main()
{
	string s;
	cin>>s;
	for(int i=0; i<s.length(); i++) {
		if(i!=3) { cout << s[i]; }
		else { cout << 8; }
	}
	cout << '\n';
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  int N,H,W;
  cin >> N >> H >> W;
  cout << max(0,(N-H+1)*(N-W+1)) << endl;
}

Measured memory_bytes: 256