akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define REP1(i,n) for(long long i=1;i<=(n);i++)
#define REP2D(i,j,h,w) for(long long i=0;i<(h);i++) for(long long j=0;j<(w);j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=(h);i++) for(long long j=1;j<=(w);j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) ((a).begin()),((a).end())
#define RANGE(a) (a),((a)+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define ENTER printf("\n")
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<(a)<<endl

#ifdef DEBUG
#define DBPRT(a) cout << "[Debug] - " << #a << " : " << (a) << endl
#define DBSTART if(1){
#define DBEND }
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#else
#define DBPRT(a) if(0){}
#define DBSTART if(0){
#define DBEND }
#define PRTLST(arr,num) if(0){}
#define PRTLST2(arr2,d1,d2) if(0){}
#define PRTLST2D(arr2,d1,d2) if(0){}
#endif

#define TOSUM(arr,sum,n) {sum[0]=arr[0];REP1(i,n-1) sum[i]=sum[i-1]+arr[i];}

#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 100000
//---------------------

string s;

int main(){
	cin >> s;
	string curs;
	bool res = false;
	REP(i,7){
		curs += "hi";
		if(curs == s) res = true;
	}
	YNPRT(res);
	return 0;
}









Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x%2==0){
            if(x%3==0 || x%5==0){
                continue;
            }
            else{
                cout<<"DENIED"<<endl;
                return 0;
            }
        }
    }
    cout<<"APPROVED"<<endl;





    return 0;
}


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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  while (A >= B && K > 0)
  {
    B *= 2;
    K--;
  }
  if (A >= B)
  {
    cout << "No" << endl;
    return 0;
  }
  while (B >= C && K > 0) {
    C *= 2;
    K--;
  }
  if (C <= B)
  {
    cout << "No" << endl;
    return 0;
  } else
  {
    cout << "Yes" << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <unordered_map>
#include<cstring>
#include<cstdlib>
using namespace std;

const long long mod=1000000007;
const long long inf=mod*mod;





int main(){
string s1,s2;
cin>>s1>>s2;
int n=s1.length(),m=s2.length();
int dp[n+1][m+1];
for(int i=0;i<=n;i++)
{
    for(int j=0;j<=m;j++){
        if(i==0||j==0) dp[i][j]=0;
        else if(s1[i-1]==s2[j-1]){
            dp[i][j]=dp[i-1][j-1]+1;
        }
        else{
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }

}


int count=dp[n][m];
char lcs[count+1];
lcs[count]='\0';
int i=n,j=m;
while(i>0 && j>0){
    if(s1[i-1]==s2[j-1]){
        lcs[count-1]=s1[i-1];
        i--;
        j--;
        count--;
    }
    else if(dp[i-1][j]>dp[i][j-1]){
        i--;
    }
    else{
        j--;
    }
}
cout<<lcs;
return 0;
}


Measured memory_bytes: 35456
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;
const ll inf = 1LL << 60;

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

ll N;
vector<string> S;

vector<ll> color;

bool dfs (ll v, ll c) {
    color[v] = c;
    Rep (i, N) {
        // cout << S[v][i] << "\n";
        if (S[v][i] == '1') {
            if (color[i] == c) return false;
            if (color[i] == 0 && !dfs(i, -c)) return false;
        }
    }
    return true;
}


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

    cin >> N;
    S.resize(N);
    color.assign(N, 0);
    Rep (i, N) {
        cin >> S[i];
    }

    vector<vector<ll>> d(N, vector<ll>(N, inf));

    Rep (i, N) {
        d[i][i] = 0;
        Rep (j, N) {
            if (S[i][j] == '1') {
                d[i][j] = 1;
            }
        }
    }

    Rep (k, N) {
        Rep (i, N) {
            Rep (j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    if (!dfs(0, 1)) {
        cout << -1 << endl;
        return 0;
    }

    // Rep (i, N) {
    //     cout << color[i] << "\n";
    // }
    ll ans = 0;
    Rep (i, N) {
        Rep (j, N) {
            chmax(ans, d[i][j]);
        }
    }
    ans++;

    cout << ans << endl;
}

Measured memory_bytes: 640
N = input()
arr = input().split(' ')

i = 0
while True:
    arr_mod = list(map(lambda x: int(x)%2, arr))
    sum_a = sum(arr_mod)
    arr = list(map(lambda x: int(x)/2, arr))
    
    if sum_a > 0.0:
      print(i)
      break
    
    i += 1

    

Measured memory_bytes: 3060
#include <iostream>
#include<vector>
using namespace std;
//#define int long long int
#include<deque>
#include<algorithm>
//Compiler version g++ 6.3.0

deque<int> d;
int32_t main()
{
  int n,t;cin>>n;
  for(int i=1;i<=n;i++){
    cin>>t;
    if(i&1){
      d.push_back(t);
    }
    else {
      d.push_front(t);
    }
  }
  vector<int> v;
  for(auto x: d){
    v.push_back(x);
  }
  if((n&1)){
    reverse(v.begin(),v.end());
  }
  for(auto x:v){
    cout<<x<<" ";
  }
}


Measured memory_bytes: 3960
import math

A, B, H, M = map(int, input().split())

if H >= 12:
    H = H - 12
# それぞれの割合
nw = H * 30 + M * 0.5
mw = M * 6
ans = abs(nw - mw)
do = min(ans, 360-ans)


c2 = A**2 + B**2 - 2*A*B*math.cos(math.radians(do))
print(math.sqrt(c2))

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

int main(){
  int N,K;
  string S;
  cin >> N >> K >> S;
  S[K-1]-='A'-'a';
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int sum(int a, int b){
  return (b - a + 1) * (b + a) / 2.0;
}

int main(void){
  int n, i, j, cnt;

  while(scanf("%d", &n)){
    cnt = 0;
    if(n == 0){
      break;
    }
    for(i = 1; i < n; i++){
      for(j = 1; j < n; j++){
        if(sum(i, j) == n){
          cnt++;
        }
      }
    }

    printf("%d\n", cnt);
  }

  return 0;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    //vector<vector<int>> data(h,vector<int>(w,0));
    int n;
    cin >> n;
    int ans;
    if(h <= w){
        if(n % w == 0) ans = n / w;
        else ans = n / w + 1;
    }
    else if(h > w){
        if(n % h == 0) ans = n / h;
        else ans = n / h + 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

import static java.util.stream.Collectors.*;
import static java.util.stream.IntStream.range;

public class Main {
    final static PrintStream so = System.out;
    final static Scanner sc = new Scanner(System.in);
    static final String PLUS = "p";

    public static void main(String[] args) {
        int[] digits = sc.next().chars().map(i -> i-'0').toArray(); // 125 -> {1, 2, 5}

        int minBits = 0;
        int supBits = 1 << (digits.length-1);
        
        long ans = range(minBits, supBits).mapToObj(bits -> toExprOfAddition(digits, bits))
                                          .mapToLong(expr -> eval(expr))
                                          .sum();
        so.println(ans);
    }
    
    static String toExprOfAddition(int[] nums, int bits) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < nums.length; i++) {
            sb.append(nums[i]);
            if ((bits >> i & 1) == 1) {
                sb.append(PLUS);
            }
        }
        return sb.toString();
//        return range(0, nums.length).mapToObj(i -> nums[i] + ((bits >> i & 1) == 1 ? PLUS : ""))
//                                    .collect(joining());
    }
    
    static long eval(String exprOfAddition) {
        return Arrays.stream(exprOfAddition.split(PLUS)).mapToLong(Long::parseLong).sum();
    }
}


Measured memory_bytes: 28624
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanString()
	c0, c1 := 0, 0
	for _, e := range s {
		if e == '0' {
			c0++
		} else {
			c1++
		}
	}

	fmt.Fprintln(wr, min(c0, c1)*2)
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

int n, i, x, y;
vector<int> list[maxN];
int gr[maxN];

int dp[maxN], up[maxN];

void dfs(int node, int root) {
    int i;

    for (i = 0; i < list[node].size(); i++) {
        int to = list[node][i];

        if (to == root) {
            list[node][i] = list[node].back();
            list[node].pop_back();
            i--;
            continue;
        }

        dfs(to, node);
    }

    if (list[node].empty()) {
        dp[node] = 1;
        up[node] = 0;
        return;
    }

    if (list[node].size() == 1) {
        int to = list[node][0];
        up[node] = up[to];
        dp[node] = dp[to];
        return;
    }

    up[node] = n + 1;
    for (auto to : list[node])
        dp[node] += dp[to];

    int base = dp[node];

    for (auto to : list[node])
        dp[node] = min(dp[node], base - dp[to] + up[to]);
}

int main()
{
   // freopen("test.in","r",stdin);

    cin >> n;
    for (i = 1; i < n; i++) {
        cin >> x >> y;
        x++; y++;

        list[x].pb(y);
        list[y].pb(x);
        gr[x]++; gr[y]++;
    }

    for (i = 1; i <= n && gr[i] <= 2; i++);
    if (i == n) {
        cout << 1;
        return 0;
    }

    dfs(i, 0);
    cout << dp[i];


    return 0;
}


Measured memory_bytes: 10240
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main(){
  int n;
  cin >> n;
  double a;
  a = ((n+1)/2)/(double)n;
  cout << a << endl;
}

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

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
int h[1000];
int main(){
    int r, g;
    cin >>r >> g;
    cout << 2*g - r << endl;
}



Measured memory_bytes: 256
N = int(input())
data = [{}]*N

for i in range(N):
  tempS, tempP = input().split()
  data[i] = {'ID': i+1, 'Name': tempS, 'Point': int(tempP)}

data_sort = sorted(
  data,
  key = lambda x: (x['Name'], -x['Point'])
)

for i in range(N):
  print(data_sort[i]['ID'])

Measured memory_bytes: 3064
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n, k; cin >> n >> k;
    cout << (ll) k * (ll) pow(k-1, n-1) << endl;
    return 0;
}

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

int shoukyo(int*,int);
int nokori;
bool check(int*,int);
void hyouji(int*);

int main(){
	int a[10000],b[10000];
	int n,i,j,k,l;
	int chP,chC;
	int mini;
	
	while(1){
		
		cin>>n;
		if(n==0){break;}
		nokori=n;
		for(i=n-1;i>=0;i--){
		cin>>b[i];
	}
	//hyouji(b);
		mini=n;
		
		
		
		
		for(j=0;j<n-1;j++){
			for(i=0;i<n;i++){
				a[i]=b[i];
			}
		
			nokori=n;
			a[j]=a[j+1];
			k=1;
			while(k==1){
				if(nokori<4){break;}
				for(int i=0;i<nokori-3;i++){
					k=check(a,i);
					if(k==1){i=0;}
				}
			}
			if(nokori<mini){
				mini=nokori;
			}
		}
		for(j=1;j<n;j++){
			for(i=0;i<n;i++){
				a[i]=b[i];
			}
			nokori=n;
			a[j]=a[j-1];
			k=1;
			while(k==1){
				if(nokori<4){break;}
				for(int i=0;i<nokori-3;i++){
					k=check(a,i);
				}
			}
			if(nokori<mini){mini=nokori;}
		}
		cout<<mini<<endl;
				
	
	}
	return 0;
}

int shoukyo(int a[],int p){
	int k=4;
	while(k+p<nokori&&a[p]==a[k+p]){
		k++;
	}
	
	
	for(int i=p;i<nokori-k;i++){
		a[i]=a[i+k];
		
	}
	nokori=nokori-k;


	
	
	return 0;
}


bool check(int a[],int i){
	if(abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2])+abs(a[i+2]-a[i+3])==0){
		//hyouji(a);
		shoukyo(a,i);
		return 1;
	}
	return 0;
}

void hyouji(int a[]){
	for(int i=0;i<nokori;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
	return;
}


Measured memory_bytes: 3088
// atcoder/abc142/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

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

  const int N = 1e6 + 5;
  bool prime[N];
  fill(prime, prime + N, true);
  prime[0] = prime[1] = false;
  for (lli i = 2; i * i < N; ++i) {
    for (lli j = 2; i * j < N; ++j) {
      prime[i * j] = false;
    }
  }
  vector<lli> p;
  for (int i = 0; i < N; ++i) {
    if (prime[i]) p.push_back(i);
  }

  lli a, b;
  while (cin >> a >> b) {
    lli x = __gcd(a, b);
    vector<lli> v;
    each (i, p) {
      if (x % i == 0) {
        v.push_back(i);
        while (x % i == 0) {
          x /= i;
        }
      }
    }
    if (x != 1) v.push_back(x);
    cout << v.size() + 1 << endl;

    // int cnt = 0;
    // each (i, p) cnt += (a % i == 0) && (b % i == 0);
    // cout << cnt + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 2424
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in();
    ll ans=0;
    for(ll a=1;a<=n;++a){
        ll b_h=a%10;if(b_h==0)continue;
        ll b_t=[](ll n){while(n>=10){n/=10;}return n;}(a);

        ll b_cnt=0;
        if(b_h==b_t&&b_h<=n)++b_cnt;

        ll b=b_h*10+b_t,posib=1;
        while(true){
            if(n>=b+(posib-1)*10){
                b_cnt+=posib;
            }else{
                // n>=b+(posib-1)*10
                // posib<=(n-b+10)/10
                b_cnt+=max((n-b+10)/10,0ll);
                break;
            }
            b=(b-b_t)*10+b_t;
            posib*=10;
        }
        ans+=b_cnt;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
str_chr = input()
n = int(input())
order = []

for _ in range(n):
    order = list(input().split())
    a,b = int(order[1]),int(order[2])+1
    if   order[0] == 'replace':
        str_chr = str_chr[:a]+order[3]+str_chr[b:]
    elif order[0] == 'reverse':
        str_chr = str_chr[:a]+str_chr[a:b][::-1]+str_chr[b:]
    elif order[0] == 'print':
        print(str_chr[a:b])



Measured memory_bytes: 5612
import java.util.*;

public class Main {


    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        List<Integer> cards = new ArrayList<>();
        Map<Integer, Integer> map = new HashMap<>();

        for(int i = 0;i < n;i++){
            cards.add(sc.nextInt());
        }

        for(int i = 0;i < m;i++){
            int b = sc.nextInt();
            int c = sc.nextInt();
            map.merge(c, b,
                    (v1, v2) -> {
                        return v1+v2;
                    });
        }

        Collections.sort(cards);
        List<Integer> changes = new ArrayList<>();
        changes.addAll(map.keySet());
        Collections.sort(changes);

        long sum = 0;
        int cIndex = changes.size()-1;
        int change = changes.get(cIndex);
        int cNum = map.get(change);
        for(int i = 0;i < n;i++){
            if(cards.get(i) <= change){
                sum += change;
                cNum--;
                if(cNum == 0){
                    cIndex--;
                    if(cIndex < 0){
                        for(int j = i+1;j < n;j++){
                            sum += cards.get(j);
                        }
                        break;
                    }
                    change = changes.get(cIndex);
                    cNum = map.get(change);
                }
            } else {
                for(int j = i;j < n;j++){
                    sum += cards.get(j);
                }
                break;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 102096
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long N;
    cin >> N;
    vector<int> d;
    for (int i = 0; i < 20; i++)
    {
        int p = N % 26;

        if (p == 0)
        {
            N -= 26;
            d.push_back(26);
        }
        else
        {
            d.push_back(p);
        }
        N /= 26;
        if (N == 0)
            break;
    }

    for (int i = 0; i < d.size(); i++)
    {
        cout << (char)('a' + d[d.size() - 1 - i] - 1);
    }
    cout << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0;i <n;i++)
int main(){
	int n, c,ans = 1<<30; cin >> n >> c;
	vector<vector<int>> D(c, vector<int>(c)),C(n,vector<int>(n)),t(3,vector<int>(c+1,0));
	rep(i, c) rep(j, c) cin >> D[i][j];
	rep(i, n) rep(j, n) cin >> C[i][j], t[(i + j) % 3][C[i][j] - 1]++;
	rep(i, c) rep(j, c) if (i != j) rep(k, c) {
		if (i != k && j != k) {
			int tt = 0;
			rep(l, c) tt += t[0][l] * D[l][i];
			rep(l, c) tt += D[l][j] * t[1][l];
			rep(l, c) tt += D[l][k] * t[2][l];
			if (tt < ans) ans = tt;
		}
	}cout << ans << endl;
}

Measured memory_bytes: 4636
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

A, B, K = mi()
C = [A, B]

turn = 0 #0はAのターン、1はBのターン
for _ in range(K):
  if C[turn] % 2 == 1:
    C[turn] -= 1
  C[turn] //= 2
  C[~turn] += C[turn]
  turn = ~turn

print(C[0], C[1])



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

main()
{
    int n;
    double r=1.08;
    cin>>n;

    int a,b,c;
    b=n/r;
    a=b-1;
    c=b+1;

    double A,B,C;
    A=floor(a*r);
    B=floor(b*r);
    C=floor(c*r);

    if(A==n)cout<<a<<endl;
    else if(B==n)cout<<b<<endl;
    else if(C==n)cout<<c<<endl;
    else cout<<":("<<endl;
}

Measured memory_bytes: 256
a, b, c, d, e, f=map(int, input().split())
def g(x, y):
  if y==0:
    return 0
  else:
    return x/y
  
maxnodo=g(e, 100+e)
a*=100
b*=100

candnodo=0
out=[a, 0]
q_max=f//b
for q in range(q_max, -1, -1):
  p_max=(f-b*q)//a
  for p in range(p_max, -1, -1):
    s_max=(f-(a*p+b*q))//d
    while s_max>0 and g(d*s_max, a*p+b*q+d*s_max)>maxnodo:
      s_max-=1
      
    for s in range(s_max, -1, -1):
      r=(f-(a*p+b*q+d*s))//c
      while r>0 and g(c*r+d*s, a*p+b*q+c*r+d*s)>maxnodo:
        r-=1
        
      if g(c*r+d*s, a*p+b*q+c*r+d*s)>candnodo:
        candnodo=g(c*r+d*s, a*p+b*q+c*r+d*s)
        out=[a*p+b*q+c*r+d*s, c*r+d*s]
        temp=[p, q, r, s]
print(*out)

Measured memory_bytes: 3064
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,m,x,y,z,len,dist[500010];
vector <pii> g[500010];
map <pii,int> mp;
priority_queue <pii,vector <pii>,greater <pii> > q;

void addedge(int pos,int pos2,int val,int val2)
{
	g[pos].pb(mpr(pos2,val));
	g[pos2].pb(mpr(pos,val2));
}

int getdownid(int pos,int val)
{
	if(mp.find(mpr(pos,val))!=mp.end()) return mp[mpr(pos,val)];
	int downid=++len;
	addedge(pos,downid,1,0);
	return mp[mpr(pos,val)]=downid;
}

int main()
{
	cin>>n>>m;
	len=n;
	rep(i,m)
	{
		scanf("%d%d%d",&x,&y,&z);
		int pos=getdownid(x,z),pos2=getdownid(y,z);
		addedge(pos,pos2,0,0);
	}
	q.push(mpr(0,1));
	rep(i,500005) dist[i]=1e9;
	dist[1]=0;
	while(!q.empty())
	{
		pii t=q.top();
		q.pop();
		rep(i,g[t.se].size())
		{
			if(dist[g[t.se][i].fi]<=t.fi+g[t.se][i].se) continue;
			dist[g[t.se][i].fi]=t.fi+g[t.se][i].se;
			q.push(mpr(dist[g[t.se][i].fi],g[t.se][i].fi));
		}
	}
	if(dist[n]==1e9) puts("-1");
	else cout<<dist[n]<<endl;
	return 0;
}

Measured memory_bytes: 59128
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>
 
// #include <unordered_set>
// #include <unordered_map>
 
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
 
#define pb push_back
#define mp make_pair
 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
 
typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;
 
const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
 
using namespace std;
 
#define N 1000000
int arr[N];
int a[N];
 
signed main(int argc, char const *argv[]){
    

    int n;
    cin>>n;

    int tmp=n/100;

    cout<<"ai1333";

    for(int i=0;i<tmp;i++){
        cout<<3;
    }

    cout<<endl;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353,N=3e5+5;
long long k,ans=1,rr[N],gg[N],bb[N];char ch[N];
int n,r[N],g[N],b[N],x,y,z;
int main()
{
	scanf("%d%s",&n,ch+1);
	int R=0,G=0,B=0;
	for(int i=1;i<=3*n;i++)
		if(ch[i]=='R')r[++R]=i;else
		if(ch[i]=='G')g[++G]=i;else
		b[++B]=i;
	for(int i=1;i<=3*n;i++)
		if(ch[i]=='R')rr[i]=rr[i-1]+1,gg[i]=gg[i-1],bb[i]=bb[i-1];else
		if(ch[i]=='G')gg[i]=gg[i-1]+1,rr[i]=rr[i-1],bb[i]=bb[i-1];else
		bb[i]=bb[i-1]+1,rr[i]=rr[i-1],gg[i]=gg[i-1];
	for(int i=1;i<=n;i++)
	{
		x=r[i],y=g[i],z=b[i];
		if(x>y)swap(x,y);
		if(x>z)swap(x,z);
		if(y>z)swap(y,z);
		if(ch[x]=='R')k=rr[y]-rr[x-1];else
			if(ch[x]=='G')k=gg[y]-gg[x-1];else
				k=bb[y]-bb[x-1];
		ans=ans*k%mod;
		if(ch[z]=='R')k=rr[z]-rr[y];else
			if(ch[z]=='G')k=gg[z]-gg[y];else
				k=bb[z]-bb[y];
		ans=ans*k%mod;
	}
	for(long long i=2;i<=n;i++)ans=ans*i%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9856
N, L=map(int, input().split())
ans=0
a=10000
for i in range(1, N+1):
    if abs(L+i-1)<=a:
        k=i
        a=abs(L+i-1)

for i in range(1, N+1):
    d=L+i-1
    if i==k:
        pass
    else:
        ans+=d
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;

vector<int> v[100009];
queue<pair<int, pair<int, int> > > q;
int d[100009][3];
bool vs[100009][3];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		v[a].push_back(b);
	}
	int s, e; cin >> s >> e;
	q.push(make_pair(0, make_pair(s, 0))); vs[s][0] = true;
	d[e][0] = -3;
	while (!q.empty()) {
		int hn = q.front().second.first, hc = q.front().second.second; d[hn][hc] = q.front().first; q.pop();
		for (int i = 0; i < v[hn].size(); i++) {
			int tn = v[hn][i], tc = (hc + 1) % 3;
			if (vs[tn][tc]) continue;
			vs[tn][tc] = true;
			q.push(make_pair(d[hn][hc] + 1, make_pair(tn, tc)));
		}
	}
	cout << d[e][0] / 3 << '\n';
	return 0;
}	

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N+1);
  for(int i=1; i<=N; i++) {
    cin >> a.at(i);
  }
  
  int cnt =0;
  for(int i=1; i !=2; i = a.at(i) ){
    cnt++;
    if(cnt>N){
      cnt = -1;
      break;
    }
  }
  cout << cnt << endl;
}

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

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ldb long double 
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

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

const int md = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

ll abst(ll a)
{
 return ((a<0)?(-1*a):(a));
}

int main()
{
  int n;
  cin>>n;
  int maxn=0;
  map<str,int> mp;
  vector<str> v;
  for(int i=0;i<n;i++)
  {
      str s;
      cin>>s;
      mp[s]++;
      if(mp[s]>maxn)
       maxn=mp[s];
       v.pb(s);
  }
  set<str> st;
   for(int i=0;i<n;i++)
   {
       if(mp[v[i]]==maxn)
       {
          st.insert(v[i]); 
       }
   }
   for(auto it=st.begin();it!=st.end();it++)
   {
       cout<<(*it)<<"\n";
   }
    return 0;
}

Measured memory_bytes: 36080
#line 1 "DPL_5_B.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_B"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

#line 1 "../modint.cpp"
template <ll Mod>
struct ModInt {
  ll n;
  ModInt(const ll x = 0) : n(x) { while (n < 0) n += Mod; n %= Mod; }
  ModInt operator+(const ModInt r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt r) const { return ModInt(*this) /= r; }
  ModInt &operator+=(const ModInt r) { n += r.n; if (n >= Mod) n -= Mod; return *this; }
  ModInt &operator-=(const ModInt r) { if (n < r.n) n += Mod; n -= r.n; return *this; }
  ModInt &operator*=(const ModInt r) { n = n * r.n % Mod; return *this; }
  ModInt &operator/=(const ModInt r) { return *this *= r.inv(); }
  ModInt pow(ll x) const { ModInt<Mod> ret(1), tmp(*this); while (x) { if (x&1) ret *= tmp; tmp *= tmp; x >>= 1; } return ret; }
  ModInt inv() const { return pow(Mod-2); }
  friend ostream& operator<<(ostream& os, const ModInt& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, ModInt& obj) { ll t; is >> t; obj = ModInt(t); return is; }
};
constexpr ll mod = 1000000007;
using mint = ModInt<mod>;
mint operator"" _mi(unsigned long long n) { return mint(n); }
#line 1 "../combination.cpp"
// T modint
template<class T>
struct Combination {
  vector<T> fact, inv_fact;
  Combination(ll n) : fact(n+1), inv_fact(n+1) {
    fact[0] = T(1);
    for (ll i = 1; i <= n; i++) fact[i] = fact[i-1] * static_cast<T>(i);
    inv_fact[n] = fact[n].inv();
    for (ll i = n; i > 0; i--) inv_fact[i-1] = inv_fact[i] * static_cast<T>(i);
  }

  T P(ll n, ll k) const {
    if (n < k or k < 0) return T(0);
    return fact[n] * inv_fact[n-k];
  }

  T C(ll n, ll k) const {
    if (n < k or k < 0) return T(0);
    return fact[n] * inv_fact[n-k] * inv_fact[k];
  }

  T H(ll n, ll k) const {
    if (n < 0 or k < 0) return T(0);
    if (n == 0 and k == 0) return T(1);
    return C(n+k-1, n-1);
  }
};
#line 16 "DPL_5_B.test.cpp"

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

  ll n, k;
  cin >> n >> k;
  Combination<mint> c(max(n, k));
  cout << c.P(k, n) << endl;
}



Measured memory_bytes: 3184
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
print(-(-N//1000)*1000-N)

Measured memory_bytes: 61736
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#define maxn 55

using namespace std;
typedef long long ll;

string s[maxn],x;
int sumt[maxn],n;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n;
  for(int i = 1;i <= n;i++) cin >> s[i] >> sumt[i];
  for(int i = 1;i <= n;i++) sumt[i] += sumt[i - 1];
  cin >> x;
  for(int i = 1;i <= n;i++){
    if(s[i] == x){
      cout << sumt[n] - sumt[i] << endl;
    }
  }
  return 0;
}


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

using namespace std;

int main(void){
  int n,m,c=0,in;
  cin>>n;
  vector<int> a(n);
  for(int i = 0 ; i < n ; i ++)cin>>a[i];

  cin>>m;
  for(int i = 0 ; i < m ; i ++){
    cin>>in;
    int r = 0, l = n;

    while(l > r){
    //  cout<<in<<" "<<l<<" "<<r<<endl;
      int mid = (l+r)/2;
      if(a[mid] == in){
        c++;
        break;
      }
     
      if(a[mid] < in){
        r = mid+1;
      }else{
        l = mid;
      }
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 3112
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

ll q,h,s,d,n,ret;

int main(){
    cin >> q >> h >> s >> d;
    cin >> n;
    h = min(q*2,h);
    s = min(h*2,s);
    d = min(s*2,d);
    cout << ( (n%2) * s + (n/2) * d ) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define rep(i, s, e) for (auto i = s; i < e; i++)
#define peek(v)      \
	for (auto i : v) \
		cout << i << ' ';

void solve()
{
	ll n, x;
	cin >> n >> x;
	vector<ll> t(n);
	rep(i, 0, n)
	{
		cin >> t[i];
	}
	ll total = 0;
	rep(i, 0, n - 1)
	{
		ll cur = t[i];
		ll next = t[i + 1];
		if (cur + x <= next)
			total += x;
		else
			total += t[i + 1] - t[i];
	}
	cout << total + x;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Scanner;




class Main{


	static	ArrayList<Integer> one ;
	static	ArrayList<Integer> two ;
	static	ArrayList<Integer> three ;
	static	ArrayList<Integer> four ;
	static long pow = 1000000007;

	static int n;
	static int m;
	static int ans  = 0;
	static int[][] g;
	static boolean[] used;



	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);			//文字の入力
		int	n =sc.nextInt();
		int	ma =sc.nextInt();
		int mb = sc.nextInt();
		int[] a = new int[40];
		int[] b = new int[40];
		int[] c = new int[40];

		for(int i = 0;i < n;i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}

		int dp[][][] = new int[41][401][401];
		int inf = 10000000;

		for(int i = 0;i <= n;i++){						//dp初期化
			for(int ca = 0;ca <= 400;ca++){
				for(int cb = 0;cb <= 400;cb++){
					dp[i][ca][cb] = inf;
				}
			}
		}

		dp[0][0][0] = 0;

		for(int i  =0;i < n;i++){
			for(int ca = 0;ca <= 400;ca++){
				for(int cb = 0;cb <= 400;cb++){
					if(dp[i][ca][cb] == inf){
						continue;
					}
					dp[i+1][ca][cb] = Math.min(dp[i+1][ca][cb], dp[i][ca][cb]);
					dp[i+1][ca+a[i]][cb+b[i]] = Math.min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
				}
			}
		}
		int ans = inf;
		for(int ca = 1;ca <= 400;ca++){
			for(int cb = 1;cb <= 400;cb++){
				if(ca*mb == cb*ma){
					ans = Math.min(ans, dp[n][ca][cb]);
				}
			}
		}
		
		if(ans == inf){
			ans = -1;
		}
		
		System.out.println(ans);





	}

}



class Pair implements Comparable{
	Character from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 54612
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int N=sc.nextInt();
      int A[]=new int[N];
      int cnt1=0;
      int cnt2=0;
      System.out.println();
      for(int i=0;i<N;i++){
         A[i]=sc.nextInt();
         if(A[i]%2==0){
            cnt1++;
            if(A[i]%3==0||A[i]%5==0){
               cnt2++;
            }
         }
      }
      if(cnt1==cnt2){
         System.out.println("APPROVED");
      }else{
         System.out.println("DENIED");
      }
   }
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

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

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

int main() {
	string s; cin >> s;
	int a = 0;
	for (char c:s) {
		if (c=='p') ++a;
	}
	cout << (s.size() / 2 - a) << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <vector>
#define rep(i, n)	for(int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;

bool comparesecond(pair<int, int>a, pair<int, int>b){
	return a.second < b.second;
}

int main(){
	/*input*/
	ll n, k;	cin >> n >> k;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	/*calculation*/
	sort(a.begin(), a.end());
	vector<pair<int, int> >dic;
	dic.push_back(pair<int, int>(a[0], 0));
	ll dicnum = 0;
	for(ll i = 0; i < n; i++){	//辞書作り
		if(a[i] == dic[dicnum].first){
			dic[dicnum].second++;
		}else{
			dic.push_back(pair<int, int>(a[i], 1));
			dicnum++;
		}
	}
	int ans = 0; 
	if(dic.size() <= k){
		ans = 0;
	}else{
		sort(dic.begin(), dic.end(), comparesecond);	//?.secondの小さい順にsort
		rep(i, dic.size() - k){
			ans += dic[i].second;
		}
	}
	/*output*/
	cout << ans << endl;
}


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

#pragma GCC optimize("O3")

long long dp[1000005];

const long long MOD = 1e9+7;

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

    long long retainWays = 0;
    long long fact = 1;
    for(int i = 1; i <= N; i ++){
        fact = fact*i%MOD;
        retainWays += fact;
    }
    retainWays %= MOD;

    //printf("retainWays=%lld\n", retainWays);

    dp[0] = fact;
    long long slidingWindowSum = dp[0];
    for(int i = 1; i <= H; i ++){
        dp[i] = slidingWindowSum;

        if(i == H){break;}

        dp[i] = dp[i]*retainWays%MOD;
        slidingWindowSum += dp[i];
        if(i >= D){slidingWindowSum -= dp[i-D];}

        if(slidingWindowSum >= MOD){slidingWindowSum -= MOD;}
        else if(slidingWindowSum < 0){slidingWindowSum += MOD;}

        //printf("dp[%d]=%lld\n", i, dp[i]);
    }

    printf("%lld", dp[H]);
    return 0;
}


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

using namespace std;
#define ll long long

ll INF = 1e9 + 7;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a,res=0;

    cin>>a;

    res = a + (a*a) + (a*a*a);

    cout<<res<<endl;

    return 0;
}


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

int main(int argc, char const *argv[])
{
	int n,m;
	while(cin>>n>>m,n+m)
	{
		int a[n],ans=0;
		for (int i = 0; i < n; ++i) cin>>a[i];
		for (int i = 0; i < n; ++i) for (int j = 0; j < i; ++j) if(a[i]+a[j]<=m) ans=max(ans,a[i]+a[j]);
		if(ans) cout<<ans<<endl;
		else cout<<"NONE\n";
	}
	return 0;
}



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

int main(){
    ll a,b,n,ans;
    cin >> a >> b >> n;

    if(b>n){
        ans=(a*n)/b;
    }else{
        ans=(a*(b-1))/b;
    }
    cout << ans;
}


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

using namespace std;



int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(20);
    //freopen("intput.txt", "r", stdin);

    int a, b, c = 0, ans;
    cin >> a >> b;
    int x = b-a;
    for(int i = 1; i <= 999; i++){
        c += i;
        if(i == x) ans = c-b;
    }
    cout << ans << endl;

}

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

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, list) for(auto i : list)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define fi first
#define se second
#define mp make_pair

using namespace std;

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;

const int INF = 1e9;
const int MOD = 1e9+7;

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

const int MAX = 510000;
ll 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;
    }
}
ll 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;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    COMinit();
    ll N, K; cin >> N >> K;
    vl A(N); REP(i, N) cin >> A[i];
    sort(ALL(A));
    ll ans = 0;
    REP(i, N)
    {
        ans += A[i] * COM(i, K-1);
        ans -= A[i] * COM(N-i-1, K-1);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13056
n = int(input())
t1 = 0
x1 = 0
y1 = 0
boolean = True

for __ in range(n):
    t, x, y = [int(_) for _ in input().split()]
    if boolean:
        temp1 = x
        temp2 = t
        x = abs(x - x1) + abs(y - y1)
        t -= t1
        x1 = temp1
        y1 = y
        t1 = temp2
        if x > t or (x + t) % 2 == 1:
            boolean = False
if boolean:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
from collections import Counter

def main():
    n,k=map(int,input().split())
    a=map(int,input().split())
    c = Counter(a)
    d = len(c) - k
    minic = sorted(c.items(), key=lambda x: x[1])
    ans = 0
    for m in minic[:d]:
        ans += m[1]
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 45676
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	s := make([]string, N)
	t := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&s[i])
		fmt.Scan(&t[i])
	}
	var X string
	fmt.Scan(&X)
	sleep := false
	ans := 0
	for i := 0; i < N; i++ {
		if !sleep {
			if s[i] == X {
				sleep = true
			}
		} else {
			ans += t[i]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512