akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long sum = 0;
        for (int i = 1; i <= N; i++) {
            if (i % 3 == 0 && i % 5 == 0) {
                continue;
            } else if (i % 3 == 0) {
                continue;
            } else if (i % 5 == 0) {
                continue;
            } else {
                sum += i;
            }
        }
        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 35580
# coding: utf-8
# Here your code !

num_j = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]

n = int(input())

for _ in range(n):
    b,r,f,v = [int(x) for x in input().split()]
    num_j[b-1][r-1][f-1] += v

for i in range(4):
    for f in num_j[i]:
        print(""," ".join([str(x) for x in f]))
    
    if i != 3:
        print("#"*20)

Measured memory_bytes: 7712
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    H,W,K = map(int, readline().split())
    S = [readline().strip() for j in range(H)]

    white = []
    for line in S:
        white.append(line.count("1"))
    white_total = sum(white)

    if white_total <= K:
        print(0)
        exit()

    ans = 10**5
    for i in range(2**(H-1)):
        impossible = False
        x = 0
        ly = bin(i).count("1")
        y_sum = [0]*(ly + 1)
        j = 0
        while j < W:
            m = 0
            y = [0]*(ly + 1)
            for k in range(H):
                if S[k][j] == "1":
                    y[m] += 1
                    if y[m] > K:
                        impossible = True
                        break
                    y_sum[m] += 1
                    if y_sum[m] > K:
                        x += 1
                        y_sum = [0]*(ly + 1)
                        j -= 1
                        break
                if (i >> k) & 1:
                    m += 1
            j += 1
            if impossible:
                x = 10**6
                break

        ans = min(ans, x + ly)

    print(ans)


if __name__ == "__main__":
    main()


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

int main()
{
int n,k;
cin>>n;
string temp;
map<int,int>  str;
for(int i=0;i<n;i++)
{
cin>>temp;
if(temp=="AC")
{
k=1;
}
if(temp=="WA")
{
k=2;
}
if(temp=="TLE")
{
k=3;
}
if(temp=="RE")
{
k=4;
}
str[k]++;
}
int a,w,t,r;
a=str[1];
w=str[2];
t=str[3];
r=str[4];
cout<<"AC"<<" "<<"x"<<" "<<a<<endl;
cout<<"WA"<<" "<<"x"<<" "<<w<<endl;
cout<<"TLE"<<" "<<"x"<<" "<<t<<endl;
cout<<"RE"<<" "<<"x"<<" "<<r<<endl;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
    private static FastScanner fs = new FastScanner();
    public static void main(String[] args) {

       int n = fs.nextInt();
       int arr[] = new int[101];
       int flag =0;
       boolean isTrue = false;
       for(int i=3;i<(n+3);i++)
       {
           int a = fs.nextInt();
           int b = fs.nextInt();
           if(a==b && flag==0)
           {
               flag=1;
           }
           else if(flag==1 && a==b)
           {
               flag =2;
           }
           else if(flag ==2 && a==b)
           {
               flag =3;
               isTrue = true;
           }
           else if(a==b || a !=b)
           {
               flag=0;
           }
       }
       if(isTrue) System.out.println("Yes");
       else System.out.println("No");
    }


    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

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

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
        int  gcd(int a,int b)
        {
            while (b > 0)
            {
                int  temp = b;
                b = a % b;
                a = temp;
            }
            return a;
        }
        private int upper(int arr[],int key){
            int low = 0;
            int high = arr.length-1;
            while(low < high){
                int mid = low + (high - low+1)/2;
                if(arr[mid] <= key){
                    low = mid;
                }
                else{
                    high = mid-1;
                }
            }
            return low;
        }
        public int lower(int arr[],int key){
            int low = 0;
            int high = arr.length-1;
            while(low < high){
                int mid = low + (high - low)/2;
                if(arr[mid] >= key){
                    high = mid;
                }
                else{
                    low = mid+1;
                }
            }
            return low;
        }
    }
}

Measured memory_bytes: 32876
#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int even = 0, odd = 0;
    for(int i = 0; i < N; i++){
    	long long A; cin >> A;
    	if(A%2 == 0) even++;
    	else odd++;
    }
    if(odd%2 == 1) cout << "NO" << endl;
	else cout << "YES" << endl;
    return 0;
}

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

using namespace std;

char sw_state(char state){
  if(state == '1'){
    return '0';
  }
  else {
    return '1';
  }
}

int main(){
  
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;

  char state = '1';
  
  vector<int> v;
  /* 最初が0から始まる場合は、１が0個という意味で、0を入れておく */
  int count = 0;
  if(S[0] == '0'){
    state = '0';
    v.push_back(0);
  }
  else{
    state = '1';
  }

  for(int i=0;i<N;i++){
    if(S[i] == state){
      count++;
      if(i == (N-1)){
        v.push_back(count);
        break;
      }
    }
    else{
      state = sw_state(state);
      v.push_back(count);
      count = 1;
    }
  }

  if(S[(N-1)] == '0'){
    v.push_back(0);
  }

  /* For Debug */
  /*
  cout << "v" << endl;
  for(int i=0;i<v.size();i++){
    cout << v[i] << endl;
  }
  */

  vector<int> csum(v.size() + 1); //0から始める
  for(int i=0;i<v.size();i++){
      csum[i+1] = csum[i] + v[i];
  }

  /* For Debug */
  /*
  cout << "csum" << endl;
  for(int i=0;i<v.size();i++){
    cout << csum[i] << endl;
  }
  */
  
  int result = 0;
  for(int i=0;i<v.size();i+=2){
    int left = i;
    int right = min(i+2*K+1,(int)(v.size()));
    result = max(result,(csum[right]- csum[left]));
  }
  /*cout << "result" << endl;*/
  cout << result << endl;
  return 0;

}
  
  
  


Measured memory_bytes: 1272
#include <set>
#include <map>
#include <list>
#include <queue>
#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;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 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++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    int n,k,ans=0;
	cin >> n;
	vint v(n);
	vint t(n);
	rep(i,n){
		cin >> v[i];
		t[i] = v[i];
	}

	std::sort(t.begin(),t.end());


	rep(i,n){
		int l=n;
		if(v[i]==t[l-1]){
			l--;
			cout << t[l-1] << endl;
		}
		else{
			cout << t[l-1] << endl;
		}
	}
}

Measured memory_bytes: 3200
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, k;
    cin >> n >> k;
    VL a(n);
    REP(i,n) a[i] = in();
    VL s(n+1);
    REP(i,n) s[i+1] = s[i] + a[i];
    VL d;
    REP(i,n) FOR(j,i+1,n){
        d.push_back(s[j] - s[i]);
    }
    ll ans = 0;
    FORR(i,50,0){
        VL e;
        int cnt = 0;
        for (ll x : d){
            if ((x >> i) & 1){
                cnt++;
                e.push_back(x);
            }
        }
        if (cnt >= k){
            ans += (1LL << i);
            d = e;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n; cin >> n;
    for (int i = 0; i < s.size(); i += n) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    string s;cin>>s;
    int dp[s.size()][13]={},i,j,num;
    for(i=0;i<13;i++)dp[0][i]=(s[0]-'0'==i||s[0]=='?'&&i<10);
    for(i=1;i<s.size();i++){
        for(j=0;j<13;j++){
            for(num=0;num<10;num++){
                if(s[i]=='?'||s[i]-'0'==num){
                    dp[i][(j*10+num)%13]+=dp[i-1][j];
                    dp[i][(j*10+num)%13]%=1000000007;
                }
            }
        }
    }
    cout<<dp[s.size()-1][5]<<endl;
    return 0;
}

Measured memory_bytes: 5504
import java.util.*;

class Int implements Comparable<Int>{
	public int i;
	Int(int i){this.i = i;}
	public int compareTo (Int I){return I.i - this.i;}
}

public class Main {
	
	public static void main(String[] args) {

		//input
		Scanner sc = new Scanner(System.in).useDelimiter(System.getProperty("line.separator"));
		String[] s = sc.next().split("\\s");
		Int[] ar = new Int[5];
		for(int i=0;i<5;i++){ar[i] = new Int(Integer.parseInt(s[i]));}
		
		//calculation
		Arrays.sort(ar);
		
		//output
		for(int i=0;i<5;i++){
			System.out.print(ar[i].i);
			if(i < 4){System.out.print(" ");}
		}
		System.out.println();
	}
}

Measured memory_bytes: 17136
#include <bits/stdc++.h>
using namespace std;
map<string,int> mp;
void solve(){
    int N; cin>>N;
    long long res=0;
    while(N--){
        string s; cin>>s;
        sort(s.begin(),s.end());
        res += mp[s];
        mp[s]++;
    }

    cout << res;
    

}


int main(){
   solve();
}

Measured memory_bytes: 11136
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int a;
    int h;
    int m;
    int s;
    cin >> a;
    h = a/3600;
    m = (a%3600)/60;
    s = (a%3600)%60;
    
    cout << h << ":" << m << ":" << s <<endl;
    return 0;
}

Measured memory_bytes: 3092
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
string s,t;
int main(){
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		s=s[s.size()-1]+s.substr(0,s.size()-1);
		if(s==t){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<sstream>
using namespace  std;
vector<string> split(const string &s, char delimiter)
{
	vector<string> ret;
	size_t now = 0, find;
	while ((find = s.find_first_of(delimiter, now)) != string::npos)
	{
		ret.push_back(string(s, now, find - now));
		now = find + 1;
	}
	ret.push_back(string(s, now, s.size() - now));
	return ret;
}
int main()
{
	string s;
	int ave = 0;
	int sum = 0;
	int count = 0;
	while (cin >> s)
	{
		vector<string> line = split(s, ',');
		stringstream ss1;
		stringstream ss2;
		int a;
		int b;
		ss1 << line[0];
		ss1 >> a;
		ss2 << line[1];
		ss2 >> b;
		sum += a * b;
		ave += b;
		count++;
	}
	cout << sum << endl;
	double a, b;
	a = (ave / count) - ave * 1.0 / count;
	if (a < 0)a = -a;
	b = ((int)(ave * 1.0 / count + 0.5)) - ave * 1.0 / count;
	if (b < 0)b = -b;
	if (a >= b )cout << (int)(ave * 1.0 / count + 0.5) << endl;
	else cout << (ave /count) << endl;
	return 0;
}

Measured memory_bytes: 1232
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int sg(int x, int y) {
    while (1) {
        if (x < y) return 0;
        if (x % y == 0) return x / y;
        int z = x / y * y;
        int v = max((x - z) / (x / y + 1), 1);
        x -= v * (x / y + 1);
    }
}
int t;
int main() {
    scanf("%d", &t);
    int ans = 0;
    while (t --) {
        int x, y;
        scanf("%d %d", &x, &y);
        ans ^= sg(x, y);
    }
    ans?puts("Takahashi"):puts("Aoki");
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int h = sc.nextInt();
                int w = sc.nextInt();
                String[] s = new String[h];
                for(int i = 0 ; i < h ; i++){
                        s[i] = sc.next();
                        System.out.println(s[i]);
                        System.out.println(s[i]);
                }
        }
}
//鶏になれ


Measured memory_bytes: 37232
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int main(){
	int N, K;
	string S;
	cin >> N >> K >> S;
	if(S[K-1] == 'A') S[K-1] = 'a'; 
	if(S[K-1] == 'B') S[K-1] = 'b';
	if(S[K-1] == 'C') S[K-1] = 'c';
	cout << S << endl;
}

Measured memory_bytes: 256
#include<iostream>	// 入出力
#include<stdio.h>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか


using namespace std;

using ll = long long;

ll N, M;

int main()
{
	cin >> N >> M;

	if (N == 1 && M == 1) { cout << 1 << endl; return 0; }

	if (N == 1 && M != 1) { cout << M - 2 << endl; return 0; }

	if (N != 1 && M == 1) { cout << N - 2 << endl; return 0; }

	cout << (N - 2)*(M - 2) << endl;

	return 0;
}

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



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

    string n;
    cin >> n;
    int total = 0;
    for(auto i : n){
        total += (i-'0');
        total %= 9;
    }
    !total ? cout<<"Yes\n" : cout<<"No\n";

    return 0;
}

Measured memory_bytes: 3720
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	long long int A, B, N; cin >>B >> A >> N;
	long long int ans = 1e18;
	for (int l = 1; l <= N; ++l) {
		if (A%l)continue;
		for (int r = 1; r <= N; ++r) {
			ans = min(ans, abs(B - A / l*r));
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    int c1 = 0, c2 = 0, c3 = 0;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        if (x <= A)
            c1 += 1;
        else if (x <= B)
            c2 += 1;
        else
            c3 += 1;
    }
    cout << min(c1, min(c2, c3)) << endl;
}

Measured memory_bytes: 256
// -*- coding: utf-8 -*-
// Last-Updated : <2014/06/20 07:48:53 by samui>

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <bitset>

#define MP(a, b) std::make_pair(a, b)
#define X first
#define Y second
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); ++(i))
#define rer(i,l,n) for(int (i) = l; (i) <= (int)(n); ++(i))
#define reu(i,l,n) for(int (i) = l; (i) < (int)(n); ++(i))
template<typename T,typename U> inline void amin(T &x,U y){ if(y<x) x = y;}
template<typename T,typename U> inline void amax(T &x,U y){ if(x<y) x = y;}
template<typename TYPE,std::size_t SIZE>
std::size_t len(const TYPE (&array)[SIZE]){return SIZE;}

// 幾何ライブ
typedef long double LD;
const LD INF = 1e100;
const LD EPS = 1e-8;
const LD PI = acos(-1);
typedef std::pair<LD,LD> PLD;
typedef std::vector<std::pair<LD,LD>> VPLD2;

class Point{
public:
  LD x,y;
  Point(LD x = 0,LD y = 0): x(x),y(y){ };
  Point operator + (Point p) {return Point(x+p.x,y+p.y);};
  Point operator - (Point p) {return Point(x-p.x,y-p.y);};
  Point operator * (LD a) {return Point(x*a,y*a);};
  Point operator / (LD a) {return Point(x/a,y/a);};
  LD abs(){return std::sqrt(x*x+y*y);};
  Point unit(){LD u = abs();return Point(x,y)/u; };
};
typedef Point Vector2D;
LD dotProduct(const Vector2D a,const Vector2D b){
  return a.x*b.x+a.y*b.y;
}
LD angle(Vector2D a,Vector2D b){
  return acos(dotProduct(a,b)/(a.abs()*b.abs()));
}
LD norm(Vector2D a){return a.x*a.x+a.y*a.y;}
Point projection(Point a1,Point a2,Point a3){
  // 点a3にたいする線分a1-a2上への射影をもとめる。
  LD d = dotProduct(a3-a1,a2-a1)/norm(a2-a1);
  return (a1+(a2-a1)*d);
}
Point reflection(Point a1,Point a2,Point a3){
  return (a3+(projection(a1,a2,a3)-a3)*2);

}

int main(int argc, char *argv[])
{
  Vector2D c,d;
  int x0,x1,y0,y1;
  std::cin>>x0>>y0>>x1>>y1;
  c = Vector2D(x1-x0,y1-y0);
  int t;
  int a,b;
  std::cin>>t;
  while(t>0){
    std::cin>>a>>b;
    Vector2D e = reflection(Point(x0,y0),Point(x1,y1),Point(a,b));
    printf("%.10Lf %.10Lf\n",e.x,e.y);
    t--;
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int p = accumulate(all(x), 0) / n;
  int q = (accumulate(all(x), 0) + n - 1) / n;
  ll ans1 = 0, ans2 = 0;
  for (int i = 0; i < n; i++) {
    ans1 += pow(x[i] - p, 2);
    ans2 += pow(x[i] - q, 2);
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
constexpr int MOD = 1e9;


int main() {
    ll S, x, y; cin >> S;

    // 1e9 * y - x = S
    // 1e9 * y = S + x
    x = (MOD - S%MOD)%MOD;
    y = (S + x) / MOD;
    cout << "0 0 1000000000 1 " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
m = A[0]
seg = [1]

t = 1
while(True):
    t *= 2
    if t > m:
        break
    seg.append(t)

c = 0
for i in range(-1,-len(seg)-1,-1):
    for j in range(N):
        if A[j] < seg[i]:
            break
        A[j] = A[j]//2
        c += 1
        if c == M:
            print(sum(A))
            sys.exit()
    A.sort(reverse=True)

print(sum(A))

Measured memory_bytes: 63984
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    array<array<int, 10>, 10> v{};
    for (auto &&i : v) fill(i.begin(),i.end(), -1);
    for (int _ = 0; _ < n; ++_) {
        printf("Data %d:\n", _+1);
        string s;
        for (int i = 0; i < 8; ++i) {
            cin >> s;
            for (int j = 0; j < 8; ++j) {
                v[i+1][j+1] = s[j]-'0';
            }
        }
        array<int, 4> dy{-1, 1, 0, 0}, dx{0, 0, -1, 1};
        int x, y;
        cin >> x >> y;
        queue<pair<int, int>> Q;
        Q.emplace(y, x);
        v[y][x] = 0;
        while(!Q.empty()){
            int i, j; tie(i, j) = Q.front(); Q.pop();
            for (int k = 0; k < 4; ++k) {
                for (int l = 1; l <= 3; ++l) {
                    if(v[i+l*dy[k]][j+l*dx[k]] == -1) break;
                    if(v[i+l*dy[k]][j+l*dx[k]] == 1){
                        v[i+l*dy[k]][j+l*dx[k]] = 0;
                        Q.emplace(i+l*dy[k], j+l*dx[k]);
                    }
                }
            }
        }
        for (int i = 0; i < 8; ++i) {
            for (int j = 0; j < 8; ++j) {
                cout << v[i+1][j+1];
            }
            puts("");
        }
    }
    return 0;
}


Measured memory_bytes: 3204
#include <stdio.h>
#define MAX 4
int main(void) {
    int i, j, k, a[4], tmp;
    char s[4], m[3];
    scanf("%s", s);
    
    for(i=0; i<4; i++) {
        a[i] = s[i] - '0';
    }
    
    for(i=0; i<1<<3; i++) {
        tmp=a[0];
        for(k=0; k<3; k++)
            m[k]='\0';
        k=0;
        for(j=0; j<3; j++) {
            if(1&i>>j) {
                tmp += a[j+1];
                m[k] = '+';
                k++;
            }else {
                tmp -= a[j+1];
                m[k] = '-';
                k++;
            }
        }
        if(tmp==7) {
            printf("%d%c%d%c%d%c%d=7\n", a[0], m[0], a[1], m[1], a[2], m[2], a[3]);
            return 0;
        }
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long int sum = 0;
  vector<long long int> vc(n);
  for(int i=0; i<n; i++) cin>>vc[i];
  sort(vc.rbegin(), vc.rend());
  int i = 2, j = 1;
  sum += vc[0];
  while(i < n)
  {
  	if(i == n-1) sum += vc[j];
    else sum += vc[j] * 2;
    i += 2;
    j++;
  }
  cout<<sum;
}

Measured memory_bytes: 4836
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 i=0;
      int max=1;
      int mmax=0;
      for(i=0;i<N;i++){
        A[i] = sc.nextInt();
        if(A[i]>=mmax){
          mmax=A[i];
          if(A[i]>=max){
            mmax=max;
            max=A[i];
          }
        }
      }
      for(i=0;i<N;i++){
        if(A[i]==max){
          System.out.println(mmax);    
        }else{
          System.out.println(max);    
        }
      }
    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}

Measured memory_bytes: 86692
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int a; cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<cstdio>
#define MAXN 1005
#define LL long long
#define INF 1000000000
int n,k,ans=1;
int main()
{
	scanf("%d %d",&n,&k);
	ans=k;
	for(int i=2;i<=n;i++)
		ans*=(k-1);
	printf("%d\n",ans);
}

Measured memory_bytes: 128
S = list(input())

def check_humiyasu(S):
    count = 0

    for i in range(len(S)):
        if (i+1) % 2 == 0:
            if S[i] == "L" or S[i] == "U" or S[i] == "D":
                continue
            else:
                count += 1
                
                

        elif (i+1) % 2 != 0:
            if S[i] == "R" or S[i] == "U" or S[i] == "D":
                continue
            else:
                count += 1
                
                
    if count == 0:
        print("Yes")
    else:
        print("No")

check_humiyasu(S)
        

Measured memory_bytes: 3060
#include<stdio.h>

void drawFrame( int H, int W)
{
	int i,j;
	char pattern[]={'#','.'};
	int d=0;
	
	for( i=0; i<H; i++) {
		d=i%2;
		for( j=0; j<W; j++) {
			printf( "%c", pattern[d]);
			d=!d;
		}
		printf( "\n");
	}
	printf( "\n");
	return;
}

int main( void ) 
{
	int H,W;

	for( ; ; ) {
		scanf( "%d%d", &H, &W ); 
		if( 0==H && 0==W ) { break; }

		drawFrame( H, W );
	}

	return 0;
}

Measured memory_bytes: 572
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if (a+b+c>=22) {
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

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

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
i64 mn,n,k;
cin>>n>>k;
mn=n;
if(k>=n)
{
  mn=min(mn,abs(n-k));
}
else
{
  n=n%k;
  mn=min(mn,n);
  mn=min(mn,abs(n-k));
}
cout<<mn;


    return 0;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	for(int i=0; i<n; ++i) cin >> h[i];

	vector<int> flg(n,1);
	for(int i=0; i<m; ++i){
		int a, b;
		cin >> a >> b;
		--a; --b;
		if(h[a]<=h[b]) flg[a]=0;
		if(h[b]<=h[a]) flg[b]=0;
	}

	cout << count(flg.begin(),flg.end(),1) << endl;
}

Measured memory_bytes: 4048
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

int main(){
	int q1, b, c1, c2, q2;
	while(cin >> q1 && q1){
		cin >> b >> c1 >> c2 >> q2;
		int m = min(q2, b / c1);
		//cout << m << endl;
		int res[2] = {0, 0};
		rep2(i, 1, m + 1){
			int p2 = (b - i * c1) / c2;
			//cout << i << " " << p2 << endl;
			if(i + p2 >= q1){
				res[0] = i;
				res[1] = p2;
			}
		}
		if(res[0] == 0) cout << "NA" << endl;
		else cout << res[0] << " " << res[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bitset>
#include <math.h>

typedef long long ll;
typedef unsigned long long ull;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    std::string w;
    std::vector<char> key;
    std::map<char, int> cnt;

    std::cin >> w;
    int len = w.length();

    for(int i = 0; i < len; ++i)
    {
        if(w[i] >= 97 && w[i] <= 122)
        {
            if(cnt.count(w[i]))
                cnt[w[i]]++;
            else
            {
                cnt[w[i]] = 1;
                key.push_back(w[i]);
            }
        }
    }

    for(int i = 0; i < key.size(); ++i)
    {
        if(cnt[key[i]] % 2 == 1)
        {
            print("No");
            return 0;
        }
    }
    
    print("Yes");
    return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

int compare(string a, string b) {
	if (a.length() < b.length()) return 1;
	if (a.length() > b.length()) return 0;
	REP(q, a.length()) {
		if (a[q] < b[q]) {
			return 1;
		}
		else if (a[q] > b[q]) {
			return 0;
		}
	}
	return 1;
}

void solve() {
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0) return;
		vector<string> inputs;
		REP(i, h) {
			string a;
			cin >> a;
			inputs.push_back(a);
		}
		string dp[70][70];
		string ans = "0";
		REP(i, h) {
			REP(q, w) {
				if (inputs[i][q] >= 'A' && inputs[i][q] <= 'Z') continue;
				if (i >= 1) {
					if (compare(dp[i - 1][q], dp[i][q]) == 0) {
						dp[i][q] = dp[i - 1][q];
					}
				}
				if (q >= 1) {
					if (compare(dp[i][q - 1], dp[i][q]) == 0) {
						dp[i][q] = dp[i][q - 1];
					}
				}
				if (inputs[i][q] == '0') {
					if (dp[i][q] == "") continue;
				}
				dp[i][q].push_back(inputs[i][q]);
				if (compare(dp[i][q], ans) == 0) {
					ans = dp[i][q];
				}
			}
		}
		cout << ans << endl;
	}
}

int main() {
	init();
	solve();
}


Measured memory_bytes: 3296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray(int n)
        {
            var array = Array();
            var result = new int[n];
            for (int i = 0; i < n; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }


        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }

        public uint NextUint()
        {
            return uint.Parse(Next());
        }
    }

    class Program
    {
        private int N;
        private int[] A;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            A = sc.IntArray();
        }


        public void Solve()
        {
            Scan();
            Console.WriteLine(Calc(Min(-1000000000, 1000000000)));
        }

        private int Min(int from, int to)
        {
            while (to - from > 1)
            {
                int mid = (from + to) / 2;
                if (Calc(mid) - Calc(mid - 1) < 0)
                {
                    from = mid;
                }
                else
                {
                    to = mid;
                }
            }

            return from;
        }

        private long Calc(int b)
        {
            long result = 0;
            for (int i = 0; i < N; i++)
            {
                result += Math.Abs(A[i] - (b + i + 1));
            }

            return result;
        }


        static void Main() => new Program().Solve();
    }
}

Measured memory_bytes: 30684
N = int(input())
x=[0]*N
y=[0]*N
L=[0]*N

flag = "No"

if N <3:
  flag = "No"

else:

  for i in range(N):
      x[i],y[i] = map(int, input().split())

  for i in range(N):
    if x[i]==y[i]:
      L[i]=1

  #print(L)

  for i in range (N-2):
    #print(i)
    if L[i] == L[i+1] == L[i+2] == 1:
      flag = "Yes"



print(flag)
    

Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
typedef long long int llint;

int main(void){

  llint n, k;

  std::cin >> n >> k;

  std::cout << int(std::log(n) / std::log(k) + 1) << std::endl;
  
  return 0;
}


Measured memory_bytes: 512
from collections import defaultdict
import sys

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
d = defaultdict(lambda: int())
to_str = "".join

for _ in range(N):
    row = to_str(sorted(input()))
    d[row] += 1

def solve():
    ans = 0
    for _, v in d.items():
        ans += v * (v - 1) // 2
    return ans

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 62040
package main

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

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	// writer  = bufio.NewWriterSize(os.Stdout, 1000000)
)

func main() {
	scanner.Split(bufio.ScanWords)
	// scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	// defer writer.Flush()
	n := scanInt()
	a := make([]int, n)
	all := 0
	for i := 0; i < n; i++ {
		a[i] = scanInt()
		all += a[i]
	}

	l := 0
	ans := math.MaxInt64
	for i := 0; i < n-1; i++ {
		l += a[i]
		r := all - l
		t := abs(l - r)
		if t < ans {
			ans = t
		}
	}

	fmt.Println(ans)
}

func scanInt() int {
	i, _ := strconv.Atoi(scanString())
	return i
}

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

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanString() string {
	scanner.Scan()
	return scanner.Text()
}

func scanStrings(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanString()
	}
	return s
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

// greatest common divisor(最大公約数)
func gcd(a, b int) int {
	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}

func fact(n int) int {
	ret := 1
	for i := 1; i <= n; i++ {
		ret *= i
	}
	return ret
}

func perm(n, r int) int {
	ret := 1
	for i := 0; i < r; i++ {
		ret *= n
		n--
	}
	return ret
}

func isPrimeNum(n int) bool {

	if n <= 1 {
		return false
	}

	l := int(math.Sqrt(float64(n)) + 1.)
	for i := 2; i < l; i++ {
		if n%i == 0 {
			return false
		}
	}

	return true
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define mp make_pair
inline double sq(double a) { return a*a; }

int n, ox[200], oy[200];

int main() {
    for(;;) {
        scanf("%d", &n);
        if(n==0) return 0;
        rep(i, n) scanf("%d%d", ox+i, oy+i);
        vector<int> ys;
        rep(i, n) ys.push_back(oy[i]);
        sort(ys.begin(), ys.end());
        ys.erase(unique(ys.begin(), ys.end()), ys.end());
        vector<double> x;
        vector<int> y;
        rep(i, n) {
            x.push_back(ox[i]);
            y.push_back(oy[i]);
            if(i==n-1) break;
            if(oy[i]<oy[i+1]) {
                rep(j, ys.size()) if(oy[i]<ys[j] && ys[j]<oy[i+1]) {
                    const double dx = ox[i+1]-ox[i], dy = oy[i+1]-oy[i];
                    x.push_back(ox[i]+dx/dy*(ys[j]-oy[i]));
                    y.push_back(ys[j]);
                }
            }
            else if(oy[i]>oy[i+1]) {
                const int m = ys.size();
                for(int j=m-1; j>=0; j--) if(oy[i+1]<ys[j] && ys[j]<oy[i]) {
                    const double dx = ox[i+1]-ox[i], dy = oy[i+1]-oy[i];
                    x.push_back(ox[i]+dx/dy*(ys[j]-oy[i]));
                    y.push_back(ys[j]);
                }
            }
        }
        typedef pair<int, int> node;
        set<node> vis;
        priority_queue<pair<double, node> > q;
        q.push(mp(0, mp(0, x.size()-1)));
        while(!q.empty()) {
            pair<double, node> vv(q.top());
            q.pop();
            const double c = -vv.first;
            const double l = vv.second.first;
            const double r = vv.second.second;
            if(vis.find(mp(l, r))!=vis.end()) continue;
            vis.insert(mp(l, r));
            if(l==r) {
                printf("%.9f\n", c);
                break;
            }
            for(int i=-1; i<=1; i++) if(0<=l+i && l+i<(int)x.size()) {
                for(int j=-1; j<=1; j++) if(0<=r+j && r+j<(int)x.size()) {
                    if(y[l+i]==y[r+j]) {
                        const double d1 = sqrt(sq(x[l]-x[l+i])+sq(y[l]-y[l+i]));
                        const double d2 = sqrt(sq(x[r]-x[r+j])+sq(y[r]-y[r+j]));
                        q.push(mp(-c-d1-d2, mp(l+i, r+j)));
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 1904
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		
		int n = stdIn.nextInt();
		int[]a = new int[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt(); //それぞれのたこやきの回復量
		}
		int sum = 0;
		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				sum+= a[i]*a[j];
			}
		}
		
		System.out.println(sum);
		
		
	}

}


Measured memory_bytes: 21844
"use strict";

function main(input) {
  input = input.split(/\n|\s/);
  const n = ~~input[0];
  const m = ~~input[n + 1];
  const blue = input.slice(1, n + 1);
  const red = input.slice(n + 2);

  let obj = new Object();
  for (let i in blue) {
    obj[blue[i]] = obj[blue[i]] + 1 || 1;
  }

  for (let i in red) {
    obj[red[i]] = obj[red[i]] - 1 || -1;
  }

  let max = 0;
  for (let v in obj) {
    max = Math.max(max, obj[v]);
  }
  max = max >= 0 ? max : 0;

  console.log(max);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15304
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, Ma, Mb; cin >> N >> Ma >> Mb;
    vl a(N), b(N), c(N);
    REP(i, N) cin >> a[i] >> b[i] >> c[i];
    
    vvvl dp(N+1, vvl(410, vl(410, LINF)));
    dp[0][0][0] = 0;
    REP(i, N){
        REP(A, 410) REP(B, 410){
            if(A >= a[i] && B >= b[i]){
                dp[i+1][A][B] = min(dp[i][A][B], dp[i][A-a[i]][B-b[i]] + c[i]);
            }
            else{
                dp[i+1][A][B] = dp[i][A][B];
            }
        }
    }
    ll ans = LINF;
    FOR(k, 1, 500){
        ll ma = k*Ma, mb = k*Mb;
        if( ma < 410 && mb < 410) ans = min(ans, dp[N][ma][mb]);
    }
    cout << (ans==LINF ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 56064
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define VM 200000
#define l_ength size
using ll = long long;
using namespace std;

// ペアの候補となる数を返す
// 具体的には ( x の 2 進数表記の最上位の桁の 1 つ左に 1 が立っていて残り 0 であるような数 ) - x
int f( int x ){
	int k = 0;
	while( true ){
		if( x == (1<<k) ){
			return x;
		} else if( x < (1<<k) ){
			return (1<<k)-x;
		} else {
			++k;
		}
	}
}

int main(){

	int n; cin >> n;
	if( n == 1 ){
		cout << 0 << endl;
		return 0;
	}
	vector<int> a(n);
	for( auto &k : a ) cin >> k;
	sort( a.begin(), a.end() );
	// 番兵
	a.push_back(INF);
	
	// uniq した上で個数を記録
	int cnt = 1;
	vector<int> b;
	vector<int> g;
	for( int i = 1; i <= n; ++i ){
		if( a[i-1] == a[i] ){
			++cnt;
		} else {
			b.push_back( a[i-1] );
			g.push_back( cnt );
			cnt = 1;
		}
	}
	// 番兵を消す
	a.pop_back();
	
	/*
	for( auto &k : b ) cout << k << " "; cout << endl;
	for( auto &k : g ) cout << k << " "; cout << endl;
	*/
	
	// 大きい方から貪欲に
	int ans = 0;
	for( int i = n-1; i >= 0; --i ){
		int aindex = lower_bound( b.begin(), b.end(), a[i] ) - b.begin();
		if( g[aindex] == 0 ) continue;
		int phi = f(a[i]);
		int phindex = lower_bound( b.begin(), b.end(), phi ) - b.begin();
		if( phi > 0 && phindex != b.l_ength() && b[phindex] == phi ){
			--g[aindex];
			if( g[phindex] >= 1 ){
				--g[phindex];
				++ans;
			} else {
				++g[aindex];
			}
		}
		/*
		cout << "==" << endl;
		for( auto &k : b ) cout << k << " "; cout << endl;
		for( auto &k : g ) cout << k << " "; cout << endl;
		*/
	}

	cout << ans << endl;

}

Measured memory_bytes: 4080
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC043A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;  //人数
            int s;　//必要な個数
            int i;
            //人数nを入力
            n = int.Parse(Console.ReadLine());

            //必要な個数ｓを求める
            //（合計を求めるアルゴリズム）
            s = 0;　//合計を０に初期化

            for (i=1; i<=n; i++) //１→ｎの繰り返し
            {
                s = s + i; //sをi増やす（s+=i;でもよい）
            }

            //sを出力（表示）
            Console.WriteLine(s);
            //入力待ちに
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define sz(x) (int) x.size()
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
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) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<str> vstr;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

//

int32_t main() {
  FAST_IO;
  int x;
  cin >> x;
  int v = 100;
  for (int i = 0; i <= 3800; i++) {
    if (v >= x) {
      cout << i << '\n';
      rtn 0;
    }
    v += v / 100;
  }
  rtn 0;
}


Measured memory_bytes: 3620