akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
	int h,w;
	char s;
	cin>>h>>w;
	int map[101][101]={0};
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>s;
			if(s=='.'){
				map[i][j]=-1;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(map[i][j]==0){
				int p=1;
				for(int z=j+1;z<w;z++){
					if(map[i][z]==0)break;
					map[i][z]=p;
					p++;
				}
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(j!=0)cout<<" ";
			cout<<map[i][j];
		}
		cout<<endl;
	}
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;

int main(){
  int ans = 0,maxi = 11;
  vector<int> a(5);

  REP(i, 5){
    cin >> a[i];
    if(a[i] % 10 == 0){
      ans += a[i];
    }
    else{
      ans += a[i] + 10 -(a[i] % 10);
      maxi = min (maxi, a[i] % 10);
    }
  }
  if(maxi != 11){
    ans -= 10 - maxi;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
void input(){
    fast_io();
    cin >> N;
}

int solve(){
    if(N==1){cout << "Hello World" << endl;}
    else{
        int a,b; cin >> a >> b;
        cout << (a+b) << endl;
    }
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
static const int MAX=100;
static const int INFTY=(1<<30);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

int prim(){
    int i,u,minv,sum;
    int d[MAX],p[MAX],color[MAX];

    for(i=0;i<n;i++){
        d[i]=INFTY;
        p[i]=-1;
        color[i]=WHITE;
    }
    d[0]=0;
    while(1){
        minv=INFTY;
        u=-1;
        for(i=0;i<n;i++){
            if(minv>d[i] && color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1)
            break;
        color[u]=BLACK;
        for(i=0;i<n;i++){
            if(color[i]!=BLACK && M[u][i]!=INFTY){
                if(d[i]>M[u][i]){
                    d[i]=M[u][i];
                    p[i]=u;
                    color[i]=GRAY;
                }
            }
        }
    }
        sum=0;
        for(i=0;i<n;i++)
            if(p[i]!=-1)
                sum+=M[i][p[i]];
    return sum;
}

int main(void){
    int i,o,e;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        for(o=0;o<n;o++){
            scanf("%d",&e);
            M[i][o]=(e==-1)?INFTY:e;
        }
    printf("%d\n",prim());
    return 0;
}

Measured memory_bytes: 2692
#include <iostream>
#include <math.h>
using namespace std; 
int main(void){
  	int K;
  scanf("%d",&K);
    string S;
  	cin >> S;
  	int hoge = (int)(S.length());
	if(hoge>K){
      std::string substr = S.substr(0,K);
      std::cout << substr;
      printf("...");
    }else{
    cout << S;
    }
}

Measured memory_bytes: 3256
#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 2000005
class node {
public:
	int vis[26];
	int end;
}nodes[maxn];
int cnt = 0;
int kase = 0;

void Init(int a) {
	memset(nodes[a].vis, 0, sizeof(nodes[a].vis));
	nodes[a].end = 0;
}

void Build(string str, int num) {
	int l = str.length();
	int now = 0;
	for (int i = 0; i < l; i++) {
		//没有这个子节点，构造出来
		if (nodes[now].vis[str[i] - 'a'] == 0) {
			nodes[now].vis[str[i] - 'a'] = ++cnt;
			Init(cnt);
		}
		now = nodes[now].vis[str[i] - 'a'];
	}
	if (nodes[now].end == 0) {
		nodes[now].end = num;
		kase++;
	}
}
int main() {
	int n;
	string s;
	scanf("%d", &n);
	Init(0);
	for (int i = 1; i <= n; i++) {
		cin >> s;
		Build(s, i);
	}
	printf("%d", kase);
}

Measured memory_bytes: 147772
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var K = cin.ReadInt;
			var A = cin.ReadInt;
			var B = cin.ReadInt;
			var Res = (A/K)*K>=A || (A/K)*K+K<=B;
			Console.WriteLine(Res?"OK":"NG");
		}
	}
	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}

}

Measured memory_bytes: 27912
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      998244353
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    ppl                      pair <long long int , pll>              //pair of ll and pair ll 
#define    sp(x)                    setprecision(x)


int32_t main()
{
    speed upp
   int n,k=0;
   cin>>n;
   string s;
   cin>>s;
   f(i,0,sz(s)-3)
   {
       if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
        k++;
   }
   cout<<k;
}

Measured memory_bytes: 256
import sys

def check(pos, s, SW):
    N = len(s)
    pre  = (pos - 1) % N
    post = (pos + 1) % N
    if(s[pos] == 'o' and SW[pre]+SW[pos]+SW[post] in ['WSW', 'SSS', 'SWW', 'WWS']):
        return True
    if(s[pos] == 'x' and SW[pre]+SW[pos]+SW[post] in ['WSS', 'SSW', 'SWS', 'WWW']):
        return True
    return False

if __name__=="__main__":
    N = int(input())
    s = input()
    li = ["SS", "SW", "WS", "WW"]
    for SW in li:
        for i in range(1,N-1):
            if(s[i] == 'o'):
                if(SW[i] == 'W'):
                    if(SW[i-1] == 'W'):
                        SW += 'S'
                    else:
                        SW += 'W'
                else:
                    SW += SW[i-1]
            else:
                if(SW[i] == 'S'):
                    if(SW[i-1] == 'W'):
                        SW += 'S'
                    else:
                        SW += 'W'
                else:
                    SW += SW[i-1]

        if(check(0, s, SW) and check(N-1, s, SW)):
            print(SW)
            sys.exit()
    print(-1)


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

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int ans[h][w];
  int x=0,y=0;
  for(int i=0;i<n;i++){
    while(a[i]>0){
      ans[x][y]=i+1;
      a[i]--;
      if(x%2==0&&y==w-1) x++;
      else if(x%2==1&&y==0) x++;
      else if(x%2==0) y++;
      else y--;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
program main
	implicit none
	integer n, i
	integer, allocatable :: a(:)
	read(*, *) n
	allocate(a(1: n))
	read(*, *) a(1: n)
	if(n == 1) then
		write(*, *)	a(1)
	else
		if(mod(n,2) == 0) then
			do i = n, 2, -2
				write(*, '(I0)', advance = 'NO') a(i)
				write(*, '(a)', advance = 'NO') ' '
			end do
			do i = 1, n-3, 2
				write(*, '(I0)', advance = 'NO') a(i)
				write(*, '(a)', advance = 'NO') ' '
			end do
			write(*, '(I0)') a(n-1)
		else
			do i = n, 1, -2
				write(*, '(I0)', advance = 'NO') a(i)
				write(*, '(a)', advance = 'NO') ' '
			end do
			do i = 2, n-3, 2
				write(*, '(I0)', advance = 'NO') a(i)
				write(*, '(a)', advance = 'NO') ' '
			end do
			write(*, '(I0)') a(n-1)
		end if
	end if
end program main

Measured memory_bytes: 3456
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,x,y=map(int, readline().rstrip().split())
    ans = [0] * (n-1)
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            d1 = abs(i-x) + abs(j-x)
            d2 = abs(i-y) + abs(j-y)
            d3 = abs(i-x) + abs(j-y) + 1
            d4 = abs(i-y) + abs(j-x) + 1
            d5 = abs(i-j)
            d=min(d1,d2,d3,d4,d5)
            ans[d-1]+=1
    for a in ans:
        print(a)
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 79080
from fractions import gcd

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:

        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a, b = map(int, input().split())
maxDiv = gcd(a, b)

#print(maxDiv)

arr = prime_factorize(maxDiv)
sets = set()

for i in range(len(arr)):
    sets.add(arr[i])

#print(prime_factorize(maxDiv))
print(len(sets)+1)


Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int x;
    cin >> x;
    int z = x / 500;
    int y = (x - z * 500) / 5;
    cout << (ll)z * 1000LL + y * 5 << endl;
}

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

using namespace std;

int x, y, N, M, K, d[809][809];
char sir[809][809];
queue < pair < int, int > > cc;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d\n", &N, &M, &K);
for (int i=1; i<=N; i++)
{
    scanf ("%s", sir[i] + 1);
    for (int j=1; j<=M; j++)
    {
        if (sir[i][j] == 'S')
            x = i, y = j, sir[i][j] = '.';
        d[i][j] = -1;
    }
}
d[x][y] = 0;
cc.push ({x, y});
while (!cc.empty ())
{
    auto curr = cc.front ();
    cc.pop ();
    for (int k=0; k<4; k++)
    {
        int x = curr.first + dx[k], y = curr.second + dy[k];
        if (sir[x][y] == '.' && d[x][y] == -1)
            d[x][y] = d[curr.first][curr.second] + 1,
            cc.push ({x, y});
    }
}
int ans = 2 * N + 2 * M + 2 * K;
for (int i=1; i<=N; i++)
    for (int j=1; j<=M; j++)
        if (d[i][j] != -1 && d[i][j] <= K)
        {
            int fromHere = min (min (i - 1, N - i), min (j - 1, M - j)), t = fromHere / K + (fromHere % K != 0);
            if (t + 1 < ans)
                ans = t + 1;
        }
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 3584
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	string s;
	cin >> s;
	cout << (s.length() >= 4 && s.substr(0, 4) == "YAKI" ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int INF = 1e9+7;
ll N;
int h[100+5];

int main() {
    int N;
    cin >> N;
    for (int i=0;  i < N; i++) {
        cin >> h[i];
    }

    int ans = 0;
    int count = 0;
    int min = INF;
    int s = 0;

    while(1) {
        count = 0;
        min = INF;
        s = 0;
        for (int i = 0; i < N; i++) {
            if (h[i] == 0 && min != INF) {
               ans += min;
               count++;
               for (int j=s; j <= i; j++) {
                   if (h[j] != 0) h[j] -= min;
               }
               min = INF;
               s = i+1;
            }
            if (i == N-1) {
                if (h[i] != 0) {
                    if (h[i] < min) {
                        min = h[i];
                    }
                    ans += min;
                    count++;
                    for (int j=s; j <= i; j++) {
                       if (h[j] != 0) h[j] -= min;
                    }
                    min = INF;
                    s = i+1;
                }
                else if (min != INF) {
                    ans += min;
                    count++;
                    for (int j=s; j < i; j++) {
                       if (h[j] != 0) h[j] -= min;
                    }
                    min = INF;
                    s = i+1;
                }
            }
            if (h[i] == 0) {
                s = i+1;
            }
            else if (h[i] < min) {
                min = h[i];
            }
        }
        if (count == 0) {break;}
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  ll l,r;
  cin >> l >> r;
  if(r - l > 2019){
    cout << 0 << endl;
    return 0;
  }
  ll mx = 5000000;
  ll m;
  for(int i = l; i < r ; ++i){
    for(int j = i+1 ; j <= r; ++j){
      m = (ll)i % 2019 * (ll)j % 2019;
      mx = min(m,mx);

      //cout << i << " " << j <<endl;
    }
  }

  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 3620
/*
 Author : Bisma
 @ copy from bisma template 1.0
 */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>
#include <fstream>
#include <cstdio>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define repn(a,b,c) for(int a=b; a>=c; a--)
#define ll long long
#define mem(a, b) memset(a, (b), sizeof(a))
#define loop(a,b,c) for(int a = b ;a<c;a++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define FOR(a,b,c) for(int a = b ; a<c ; a++ )
ll max(ll a, ll b){
    if(a>b) return a;
    return b;
}

ll min(ll a, ll b){
    if(a>b) return b;
    return a;
}

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

const int lim = 1e5;

ll __gcd(ll a, ll b){

	if(b > a) swap(a,b);

	if(b == 0) return a;

	return __gcd(b, a % b);

}


ll a[(int)1e5 + 10];

int main(){

	fast();
	bool ada = false;

	ll n;

	cin>>n;

	ll pl = 0;
	ll mi = 0;

	rep(i,1,n){
		cin>>a[i];

		if(a[i] > 0 ){
			pl ++;
		}else{
			mi++;
		}

		if(a[i] == 0) ada = true;
	}

	if(ada){

		ll tot = 0;

		rep(i,1,n){
			tot += abs(a[i]);
		}

		cout<<tot<<endl;

	}else{
		//cout<<"LL"<<endl;
		ll tot = 0;

		//cout<<mi<<endl;

		if(mi % 2 == 0){

			rep(i,1,n){
				tot += abs(a[i]);
			}

		}else if(mi % 2 == 1){

			rep(i,1,n) a[i] = abs(a[i]);

			sort(a+1,a+n+1);

			rep(i,1,n){
				if(i == 1){
					tot-=a[i];
				}else{
					tot+=a[i];
				}
			}

		}


		
		cout<<tot<<endl;
	}
	
return 0;
}
 


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

int main(){
   int N;
   cin >> N;
   vector<int> A(N+1);
   vector<int> result(N+1, 0);

   for (int i=2; i<N+1; i++){
      cin >> A.at(i);
   }

   for (int i=2; i<N+1; i++)
      result.at(A.at(i))++;

   for (int i=1; i<N+1; i++)
      cout << result.at(i) << endl;
}



Measured memory_bytes: 4800
#include <cstring>
#include <iostream>
#include <algorithm>

#define INF 0x3f3f3f3f

using namespace std;

int n, ma, mb;
int a[43], b[43], c[43];
int dp[443][443];
int ans = INF;

int main(int argc, char const *argv[]) {
  cin >> n >> ma >> mb;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
  }

  memset(dp, INF, sizeof(dp));

  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 400; j >= a[i]; --j) {
      for (int k = 400; k >= b[i]; --k) {
        dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i]);
      }
    }
  }

  for (int i = 1; i * max(ma, mb) <= 400; ++i) {
    ans = min(ans, dp[i * ma][i * mb]);
  }

  cout << (ans == INF ? -1 : ans) << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 20005;

int par[MAX_N];
int nrank[MAX_N];

void initial(int n){		//?????????
	for(int i=0;i<n;i++){
		par[i] = i;
		nrank[i] = 0;
	}
}

int find(int x){		//??¨??????????±???????
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

void unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(nrank[x] < nrank[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(nrank[x] == nrank[y])
			nrank[x]++;
	}
}

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

int main()
{
    while(1){
        int n,m;
        cin >> n >> m;
        if(n == 0){
            break;
        }
        initial(n);
        vector<int> from(m),to(m);
        vector<P> vec(m);
        rep(i,m){
            int a;
            cin >> a >> from[i] >> to[i];
            from[i]--,to[i]--;
            vec[i] = P(a,i);
        }
        sort(all(vec));
        rep(i,m){
            int id = vec[i].se;
            if(same(from[id],0)){
                unite(to[id],0);
            }
        }
        int ans = 0;
        rep(i,n){
            if(same(i,0)){
                ans++;
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3332
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)1e5+100;


int main(void) {
   ll N;
   cin>>N;
   // vector<ll> P(N);
   // rep(i,0,N)cin>>P[i];
   //num, idx
   map<ll,ll> P;
   rep(i,0,N) {
      ll p;
      cin>>p;
      P[p-1] = i;
   }
   set<ll> vP;
   ll range[4] = {0,0,0,0};
   ll ans = 0;
   for(int i = N-1; i>=0;i--) {
      auto itr = vP.upper_bound(P[i]);
      if (itr != vP.end()) {
         range[2] = *itr - P[i];
         auto itr2 = itr;
         itr2++;
         if (itr2!= vP.end()) {
            range[3] = *itr2 - *itr;
         } else {
            range[3] = N -1 - *itr + 1;
         }
      } else {
         range[2] = N-1 - P[i] + 1;
         range[3] = 0;
      }
      itr = vP.upper_bound(P[i]);
      if (itr != vP.begin()) {
         itr--;
         range[0] = P[i] - *itr;
         auto itr2 = itr;
         if (itr2 != vP.begin()) {
            itr2--;
            range[1] = *itr - *itr2;
         } else {
            range[1] = *itr - 0 + 1;
         }
      } else {
         range[0] = P[i] - 0 + 1;
         range[1] = 0;
      }
      vP.insert(P[i]);
      // cout<<i<<" "<<range[0]<<" "<<range[1]<<endl;
      // cout<<i<<" "<<range[2]<<" "<<range[3]<<endl;
      ans += (i+1) * (range[3] * range[0]);
      ans += (i+1) * (range[2] * range[1]);
   }
   cout<<ans<<endl;








   return 0;
}

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

const ll MOD=1000000007;

// a^n mod を計算する
ll mod_pow(ll a, ll b, ll p) {
    if (b == 0) return 1;
    if (b & 1) return (a * mod_pow(a, b - 1, p)) % p;
    ll t = mod_pow(a, b / 2, p);
    return (t * t) % p;
}

ll mod_inv(ll a, ll p) { return mod_pow(a, p - 2, p); }
 
ll mod_comb(ll n, ll r, ll p) {
    ll tn = 1, tr = 1;
    for (int i = n; i > n - r; i--) {
        tn *= i;
        tn %= p;
    }
    for (int i = r; i > 0; i--) {
        tr *= i;
        tr %= p;
    }
    return tn * mod_inv(tr, p) % p;
}

int main(void){
    ll n;
    int a,b;
    cin >> n >> a >> b;
    if(n==2 && a ==1 && b==2)
        cout << '0' << endl;
    else{
        ll ans = mod_pow(2, n, MOD) - 1 - mod_comb(n, a, MOD) - mod_comb(n, b, MOD);
        while (ans < 0) ans += MOD;
        cout << ans << endl;
    }
}


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

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	int a[3];
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	sort(a,a+3);
	printf("%d\n",a[2]*10+a[1]+a[0]);
	return 0;
}

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

int main()
{
    string s;
    cin >> s;

    int price = 700;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == 'o')
        {
            price += 100;
        }
        
    }

    cout << price << endl;
    return 0;
}

Measured memory_bytes: 256
#from pprint import pprint
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from copy import deepcopy
#from itertools
#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。
 
# = map(int,input().split())
 
# = list(map(int,input().split()))
 
# = [list(map(int,input().split())) for _ in range(XXXX)]
from sys import stdin


def main():
    input = stdin.readline
    
    h,n = map(int,input().split())
    
    ab= [list(map(int,input().split())) for _ in range(n)]
    
    dp = [[float("inf") for _ in range(h+1)] for _ in range(n+1)]
    #dp[i][j]はi番目のものを選んだ時かつダメージ送料がjだったときの最小MP、
    
    
    for i in range(1,n+1):
        dp[i][0] = 0
        for j in range(h+1):
            a = ab[i-1][0]
            b = ab[i-1][1]
            dp[i][j] = min(dp[i][j],dp[i-1][j])
            if j+a <= h:
                dp[i][j+a] = min(dp[i][j] + b, dp[i-1][j+a], dp[i][j+a])
            elif j+a > h:
                dp[i][h] = min(dp[i][j] + b, dp[i-1][h], dp[i][h])

    
    print(dp[-1][-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 295688
n = gets().to_i()
while (n != 0)
  factorial = 1
  for i in 1..n
    factorial *= i
  end
  count = 0
  while (factorial % 10 == 0)
    count += 1
    factorial /= 10
  end
  puts(count)
  
  n = gets().to_i()
end

Measured memory_bytes: 13712
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

signed main()
{
    int N; cin>>N;
    vint a(N);
    REP(i,N) cin>>a[i];

    int ans=a[0];
    REP(i,N){
        ans=gcd(ans,a[i]);
    }
    cout<<ans<<endl;

}


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

int main() {

  int n;
  cin >> n;
  int a[n+1];
  for(int i=0;i<n;i++)cin >> a[i];
  sort (a,a+n);
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
#include<cmath>//sin

using namespace std;
int main()
{ 
    double a,b,x,ans;
    cin>>a>>b>>x;
    if(2*x>a*a*b){
        ans=atan2(2*b*a*a-2*x,a*a*a)/(asin(1))*90;
    }
    else{
        ans=90-atan2(2*x,a*b*b)/(asin(1))*90;
    }
    cout<<fixed<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
dat = dict()
dat["AC"] = 0
dat["WA"] = 0
dat["RE"] = 0
dat["TLE"] = 0
for i in range(n):
    s = input()
    dat[s] += 1
print("AC x", dat["AC"])
print("WA x", dat["WA"])
print("TLE x", dat["TLE"])
print("RE x", dat["RE"])



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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'
#define int long long

signed main()
{
    

    int n,x,m;
    cin>>n>>x>>m;

    vector<int> cycle;
    int sum=0;

    int vis[m+1];
    mem(vis,0);

    while(!vis[x])
    {
        cycle.pb(x);
        sum+=x;
        vis[x]=1;
        x=x*x%m;
    }

    int before=0;
    sum=0;
    int ans=0;
    while(cycle[before]!=x) before++;


    if(n<=before)
    {
        ffor(i,0,n) ans+=cycle[i];
        cout<<ans;
        return 0;
    }
    else
    {
        ffor(i,0,before) ans+=cycle[i];
        n-=before;
        ffor(i,before,sz(cycle)) sum+=cycle[i];
    }

   // cout<<before<<" "<<sum<<endl;

    int len=sz(cycle)-before;

    ans+=sum*(n/len);
    ffor(i,before,before+(n%len)) ans+=cycle[i];
    cout<<ans;
    
    return 0;
}



Measured memory_bytes: 4608
import sys
count = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(sys.stdin.readline().strip())

for _ in range(n):
    array = sys.stdin.readline().strip().split(' ')
    b, f, r, v = [int(i) for i in array]
    count[b-1][f-1][r-1] += v
for b in range(4):
    for f in range(3):
        for r in range(10):
            print(' %d' % count[b][f][r], end='')
        print()
    if b != 3:
        print('#'*20)


Measured memory_bytes: 5628
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
 const int mod=1000000007;

 //mod演算ライブラリ
 //mod=1000000007

 LL add(LL a,LL b){
   return (a+b)%mod;
 }

 LL sub(LL a,LL b){
   return (a+mod-b)%mod;
 }

 LL mul(LL a,LL b){
   return ((a % mod) * (b % mod)) % mod;
 }

 LL power(LL x,LL y){//繰り返し二乗法 単品利用可
   if(y==0)return 1;
   else if(y==1)return x%mod;
   else if(y%2==0){
     LL tmp=power(x, y/2) % mod;
     return tmp*tmp%mod;
   }else {
     LL tmp=power(x, y/2) % mod;
     return ((tmp*tmp)%mod)*x%mod;
   }
 }

 LL dvs(LL a,LL b){
   return mul(a,power(b,mod-2));
 }

 const int SIZE_mod=200075;
 int invfact[SIZE_mod];
 int fact[SIZE_mod];

 LL factset(int a){//aまでの階乗%mod表を作成
   fact[0]=1;
   FORQ(i,1,a){
     fact[i]=mul(fact[i-1],i);
   }
 }

 LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
   factset(a);
   invfact[a]=power(fact[a],mod-2);
   invfact[0]=1;
   FORD(i,a,1){
     invfact[i]=mul(invfact[i+1],i+1);
   }

 }

 LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
   if(n<r||r<0||n<0)return 0;
   return mul(fact[n],mul(invfact[r],invfact[n-r]));
 }

 LL prm(int n,int r){//nPr%mod
     return mul(cmb(n,r),fact[n]);
 }

 LL homo(int n,int r){//nHr%mod
   return cmb(n+r-1,r);
 }



 int prime[100002]={};
 int Er_N=100001;
 void Er(){//Eratosthenes  1:PRIME  0:NOT PRIME
 	for(int i = 2; i < Er_N; i++){
 		prime[i] = 1;
 	}
 	int limit_Er_roop=sqrt(Er_N);
 	for(int i = 2; i < limit_Er_roop; i++){
 		if(prime[i]){
 			for(int j = 0; i * (j + 2) < Er_N; j++){
 				prime[i *(j + 2)] = 0;
 			}
 		}
 	}
 }

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

 long long lcm(long long a,long long b){
 	long long g=gcd(a,b);
 	return a/g*b;
 }



 int main(){
 	int n,m;
	cin>>n>>m;
	Er();
	vector<int> p;
	FOR(i,1,Er_N){
		if(prime[i]&&m%i==0)p.PB(i);
	}
	int ss=p.size();
	//cerr<<ss<<endl;
	vector<int> c(ss,0);
	LL ans=1LL;
	cmbset(SIZE_mod-2);
	FOR(i,0,ss){
		while(m%p[i]==0&&m!=0){
			c[i]++;
			m=m/p[i];
			//cerr<<tmp<<endl;
		}
		//cerr<<i<<" p:"<<p[i]<<" c:"<<c[i]<<endl;
		ans=mul(ans,(homo(n,c[i])));
	}
	if(m!=1)ans=mul(ans,n);
	cout<<ans<<endl;
   return 0;
 }


Measured memory_bytes: 2304
#pragma region Macros
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define REV(x) reverse(ALL(x))
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define SP << " " <<
#define INF2 1000000000000000037
#define INF  1000000007
#define lwb(x,n) distance(x.begin(),lower_bound(ALL(x),(n)))
#define upb(x,n) distance(x.begin(),upper_bound(ALL(x),(n)))
#define fora(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#ifdef _MY_DEBUG
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define de(...) CHOOSE((__VA_ARGS__,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define de(...)
#endif
using namespace std;
using ll = long long;
using ld = long double;
template<class T = ll> using v = vector<T>;
template<class T = ll> using vv = vector<vector<T>>;
template<class T = ll> using vvv = vector<vector<vector<T>>>;
template<class T> bool maxi(T &a, const T &b){ if(a<b){a=b;return 1;}return 0;}
template<class T> bool mini(T &a, const T &b){ if(b<a){a=b;return 1;}return 0;}
template<class T> ll sumer(const T& a){ return accumulate(ALL(a),0LL); }
template<class T> void UNIQUE(vector<T> &a){ SORT(a);a.erase(unique(ALL(a)),a.end());}
template<class T, class U> ostream &operator<<(ostream &os, const pair<T,U> &pe) { os << pe.first << " " << pe.second; return os;}
template<class T> ostream &operator<<(ostream &os, const v<T> &ve) { rep(i,ve.size()) os<< (i?" ":"")<<ve[i]; return os;}
ll topbit(ll a) { return a==0?-1:63-__builtin_clzll(a);}
ll botbit(ll a) { return a==0?64:__builtin_ctzll(a);}
ll popcount(ll a) { return __builtin_popcountll(a);}
#define dame {cout<< retword <<"\n"; return;}
#pragma endregion
//--MODIFS---------------------------------
#pragma region Modifs
#define retword "-1"
#define MOD  1000000007
using P  = pair<ll,ll>;
using TP  = tuple<ll,ll,ll>;
#pragma endregion
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll A,B,C,D;
    cin>>A>>B>>C>>D;
    while(1){
        C-=B;
        if(C<=0){cout<< "Yes" <<"\n"; return;}
        A-=D;
        if(A<=0){cout<< "No" <<"\n"; return;}
    }
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // ll Qkai; cin>>Qkai; rep(QQ,Qkai) Main();
    Main();
}
//-----------------------------------------

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

int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  int dp[n];
  for(int i=0;i<n;i++)
  {
      dp[i]=INT_MAX;
  }
  dp[0]=0;
  for(int i=0;i<n;i++)
  {
    if(i+1<n)
    {
      dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
    }
    if(i+2<n)
    {
      dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
    }
  }
  cout<<dp[n-1]<<"\n";
  return 0;
}

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


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

    long long X = N / (A + B);
    long long Y = A * X;
    long long Z = min(N % (A + B), A);


    cout << Y + Z << endl;


}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>

using namespace std;

char s[10];

int main() {
    cin >> s;
    int ans = 700;
    for (int i = 0; i <= 2; i++) if (s[i] == 'o') ans += 100;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  if(a+b==c+d)cout<<"Balanced\n";
  else if(a+b>c+d)cout<<"Left\n";
  else cout<<"Right\n";
  return 0;
}

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

vector<long long> create_table(vector<long long> pattern) {
    vector<long long> table(pattern.size()+1, 0);
    
    long long j = 0;
    for (long long i = 1; i < pattern.size(); i++) {
        if (pattern[i] == pattern[j])
            table[i] = j++;
        else {
            table[i] = j;
            j = 0;
        }
    }
    table[pattern.size()] = j;
    
    return table;
}

vector<long long> kmp_search(vector<long long> target, vector<long long> pattern) {
    vector<long long> table = create_table(pattern);
    /*
    for (int i = 0; i < table.size(); i++)
        cout << table[i] << " ";
    cout << endl;
    */
    
    vector<long long> result;
    long long p = 0;
    for (long long i = 0; i < target.size(); i++) {
        if (target[i] == pattern[p])
            p++;
        else if (p != 0 && target[i] != pattern[p]) {
            p = table[p];
            i--;
        }
        //cout << i << " " << p << endl;
        
        if (p == pattern.size()) {
            result.push_back((i+1)-p);
            p = table[p];
        }
    }
    
    return result;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    
    vector<ll> copy_a(a);
    copy_a.insert(copy_a.end(), a.begin(), a.end()-1);
    vector<ll> new_a(2*n-2), new_b(n-1);
    rep(i, 2*n-2) new_a[i] = copy_a[i] ^ copy_a[i+1];
    rep(i, n-1) new_b[i] = b[i] ^ b[i+1];
    
    vector<ll> kmp = kmp_search(new_a, new_b);
    rep(i, kmp.size())
        cout << kmp[i] << " " << (a[kmp[i]] ^ b[0]) << endl;
}

Measured memory_bytes: 21604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> S(2, vector<int>(n + 1, 0));
    for(int i = 0; i < n; ++i){
        if(s[i] == 'W') S[0][i + 1] = 1;
        else    S[1][i + 1] = 1;
    }
    for(int i = 0; i < 2; ++i){
        for(int j = 0; j < n; ++j){
            S[i][j + 1] += S[i][j];
        }
    }
    int ans = INF;
    for(int i = 0; i <= n; ++i){
        chmin(ans, max(S[0][i], S[1][n] - S[1][i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 5988
#include <iostream>
using namespace std;
using ull = unsigned long long;

ull getResult(const ull height, const ull width){
  if(height <= 1 || width <= 1) return 1;
  return (height * width + 1) / 2;
}

int main(){
  ull H, W;
  cin >> H >> W;
  
  ull result = getResult(H, W);
  cout << result;
  return 0;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
X, Y = map(int, input().split(' '))

ans = 0

prices = [0, 300000, 200000, 100000]
if X < 4:
    ans += prices[X]

if Y < 4:
    ans += prices[Y]

if X == 1 and Y == 1:
    ans += 400000

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 2000;

bool prime[MAX_N];

int main()
{
	int n;
	cin >> n;
	fill(prime,prime+n+1,true);
	for(int i=2;i<=n;i++){
		if(prime[i] == true){
			for(int j=2;i*j<=n;j++){
				prime[i*j] = false;
			}
		}
	}
	ll res=1;
	ll cnt;
	for(int i=2;i<=n;i++){
		if(prime[i] == true){
			cnt = 0;
			int c = i;
			while(n/c > 0){
				cnt += n/c;
				c *= i;
			}
			res = res*(cnt+1) % MOD;
		}
	}
	cout << res;
}


Measured memory_bytes: 256
//59
#include<iostream>
#include<vector>
#include<queue>
#include<utility>

using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> e[101];
  for(int i=0;i<n;i++){
    int r,k;
    cin>>r>>k;
    while(k--){
      int t;
      cin>>t;
      e[r].push_back(t);
    }
  }
  int p;
  cin>>p;
  while(p--){
    int s,d,v;
    cin>>s>>d>>v;
    queue<pair<int,int> > que;
    que.push(make_pair(1,s));
    bool p[101]={};
    while(!que.empty()){
      int c=que.front().second;
      if(c==d||que.front().first>v)break;
      if(!p[c]){
	for(int i=0;i<e[c].size();i++){
	  que.push(make_pair(que.front().first+1,e[c][i]));
	}
      }
      p[c]=true;
      que.pop();
    }
    if(que.empty()||que.front().first>v){
      cout<<"NA"<<endl;
    }else{
      cout<<que.front().first<<endl;
    }
  }
  return 0;
}
      

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define chmax(a,b) if(a<b)a=b;
#define chmin(a,b) if(b<a)a=b;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
int isPrime(int x) {
	if(x == 2) return 1;
	else if(x < 2 || x % 2 == 0) return 0;
	for(int i = 3; i * i <= x; i += 2) {
		if(x % i == 0) return 0;
	}
	return 1;
}
int main() {
	int n; cin >> n;
	int x, cnt = 0;
	rep(i, 0, n) {
		cin >> x;
		if(isPrime(x)) ++cnt;
	}
	P(cnt);
	return 0;
}

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

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            int[] XN = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int X = XN[0], N = XN[1];
            string[] str = Console.ReadLine().Split(' ');
            if (N == 0)
            {
                Console.WriteLine(X);
                return;
            }
            int[] nums = str.Select(int.Parse).ToArray();
            if (!nums.Contains(X)) Console.WriteLine(X);
            else
            {
                int m = X;
                int p = X;
                while (true)
                {
                    m--;
                    p++;
                    if (!nums.Contains(m))
                    {
                        Console.WriteLine(m);
                        break;
                    }
                    if (!nums.Contains(p))
                    {
                        Console.WriteLine(p);
                        break;
                    }
                }
            }
        }
    }
}


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

int main() {
	vector<bool>hantei(1000000, true);
	vector<int>sosuu(1000000);
	int s = 0;
	for (int a = 2; a < 1000000; a++) {
		if (hantei[a]) {
			s++;
			for (int b = a * 2; b < 1000000; b += a)hantei[b] = false;
		}
		sosuu[a] = s;
	}
	int c;
	while (cin >> c) {
		cout << sosuu[c] << endl;
	}
}

Measured memory_bytes: 6544
import collections
N=int(input())
S=[input() for i in range(N)]

C=collections.Counter(S)
C_S=C.most_common()
m=C.most_common()[0][1]
ans=[]

for i in range(len(C_S)):
    if C_S[i][1]!=m:
        break
    else:
        ans.append(C_S[i][0])

ans.sort()

for i in ans:
    print(i)

Measured memory_bytes: 59376
/* 
    AtCoder Beginner Contest 081
    A:Shift only
    AC
*/

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main(void)
{
    int i;
    int count = 0;
    bool can_divide = true;
    int num;
    cin >> num;
    int ntr_num[num];
    for (i = 0; i < num; i++)
    {
        cin >> ntr_num[i];
    }
    while (can_divide)
    {
        for (i = 0; i < num; i++)
        {
            if (ntr_num[i] % 2 == 0)
            {
                ntr_num[i] = ntr_num[i] / 2;
            }
            else
            {
                can_divide = false;
            }
        }
        count++;
    }
    cout << count - 1 << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<double> V(N);
  for(int i=0; i<N; i++){
    cin >> V.at(i);
  }
  sort(V.begin(), V.end());
  double Ans=(V.at(0)+V.at(1))/2;
  for(int i=2; i<N; i++){
    Ans=(Ans+V.at(i))/2;
  }
  cout << setprecision(10) << Ans << endl;
}

Measured memory_bytes: 256