akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    vector<int> sum(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        sum[i] = x + (i ? sum[i - 1] : 0);
    }

    int res = 1000000;
    for (int i = 0; i < n; i++) {
        if (res > abs(sum[n - 1] - 2 * sum[i])) {
            res = abs(sum[n - 1] - 2 * sum[i]);
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define db double
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define ldb long double
#define clr(x) memset(x,0,sizeof(x))
#define count_bit(x) __builtin_popcount(x)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
const int size1 = 1e5+7;
const int size2 = 1e4;

//ll fact[size1];
 
ll pw(ll x,ll y,ll mod)
{
    if(y==0)return 1;
    ll p =pw(x,y/2,mod);
    p = (p*p)%mod;
    if(y%2==1)p = (p*x)%mod;
    return p;
}
ll gcd(ll a,ll b)
{
	if(b==0)return a;
	a = a%b;
	return gcd(b,a);
}
// ll inverse(ll x,ll mod)
// {
//     return pw(x,mod-2,mod);
// }
// ll ncr(ll n,ll r,ll mod)
// {
//     ll num = fact[n];
//     ll den = (fact[r] * fact[n-r])%mod;
//     den = inverse(den,mod);
 
//     ll ans = (num*den)%mod;
//     return ans;
// }
// vector<ll> adj1[size1];
// vector<ll> adj[size1];
// ll d[size1];
// ll n,m;
// void dikstra(ll s)
// {
//     for(ll i=1;i<=n;i++)d[i]=1e9;
//     d[s] = 0;
//     priority_queue<pll, vector<pll>, greater<pll>> q;
//     q.push({0, s});
//     while(!q.empty())
//     {
//         ll v = q.top().ss;
//         ll d_v = q.top().ff;
//         q.pop();
//         if(d_v!=d[v])continue;
//         for(auto to:adj1[v])
//         {
//             ll len = 1;
//             if(d[v] + len < d[to])
//             {
//                 d[to] = d[v]+len;
//                 q.push({d[to],to});
//             }
//         }
//     }
// }
// vector<ll> adj[size1];
// void dfs(ll v,ll p)
// {
// 	for(auto u:adj[v])
// 	{
// 		if(u!=p)
// 		{
// 			dfs(u,v);
// 		}
// 	}
// }
const ll mod = 1e9+7;
int main()
{
    //cout<<setprecision(12)<<fixed;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 	
 	
    ll T;
    //cin>>T;
    T = 1;
    ll cas=1;
    while(T--)
    {
        //cout<<"Case #"<<cas<<": ";cas++;
        ll d,t,s;cin>>d>>t>>s;
        if(d<=s*t){cout<<"Yes"<<endl;}
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3632
N=int(input())
*A,=map(int,input().split())
Ar=A[::-1]
ans=[0]*(N+1)
i=0
count=0
while i<=N:
    count+=Ar[i]
    if count>2**(N-i):
        count=2**(N-i)
    ans[-(i+1)]=count
    i+=1

j=0
while j<N:
    if ans[j+1]>2*(ans[j]-A[j]):
        ans[j+1]=max(2*(ans[j]-A[j]),0)
    j+=1

k=0
while k<=N:
    if A[k]>2**k:
        ans[k]=0
    k+=1

l=0
while l<=N:
    if ans[l]<A[l]:
        ans[l]=0
    l+=1

if 0 in ans:
    print(-1)
else:
    print(sum(ans))

Measured memory_bytes: 83944
my $n = <>;
my ($d, $x) = split(' ', <>);
my @a = map { my $in=<>;$in; } (1..$n);

for my $day (1..$d) {
    for my $i (0..$n-1) {
        if ((($day-1) % $a[$i]) == 0) {
            $x++;
        }
    }
}
print $x;

Measured memory_bytes: 384
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

int i,x,y;

void solve()
{
    cin>>x>>y;
    if(y>=2*x && (y-2*x)%2==0 && 4*x>=y && (4*x-y)%2==0)
        cout<<"Yes";
    else
        cout<<"No";
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
    int l,i,j,cnt;
	char s[101],t[101];
    cin>>s>>t;
	l=strlen(s);
	for(i=0;i<l;i++){
		for(j=0;j<l;j++){
			if(s[j]==t[j]){
				cnt=cnt+1;
			}
		}
		if(cnt==l) break;
		for(j=0;j<l-1;j++){
			swap(s[j],s[l-1]);
		}
		cnt=0;
	}
	if(cnt==l) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

    return 0;
}


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

bool sqcheck(ll n){
    bool ans = false;
    rep(i,n) if(i * i == n) ans = true;
    if(n == 0 || n == 1) ans = true;
    return ans;
}

int main(){
    int n,d;
    cin >> n >> d;
    int x[n][d];
    int ans = 0;
    rep(i,n){
        rep(j,d) cin >> x[i][j];
    }
    rep(i,n){
        for(int j = i + 1; j < n; j++) {
            ll sum = 0;
            rep(k,d){
                sum += ((x[i][k] - x[j][k]) * (x[i][k] - x[j][k]));
            }
            if(sqcheck(sum)) ans++;
//            cout << sum << endl;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long int
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int k;
	cin>>k;
	for(int j=0;j<k;j++)
	  cout<<"ACL";
	cout<<endl;
}


Measured memory_bytes: 3648
s=input()
x,y=map(int, input().split())
cnt = 0; mode = 2
l = len(s) # l + 1 + l
X = Y = 1 << l
for c in s:
    if c is 'F':
        cnt += 1
    else:
        if mode == 0:
            X = (X >> cnt) | (X << cnt)
        elif mode == 1:
            Y = (Y >> cnt) | (Y << cnt)
        else:
            X = X << cnt
            mode = 0
        cnt = 0; mode ^= 1
if cnt > 0:
    if mode == 0:
        X = (X >> cnt) | (X << cnt)
    elif mode == 1:
        Y = (Y >> cnt) | (Y << cnt)
    else:
        X = X << cnt
if (X >> (l + x)) & 1 and (Y >> (l + y)) & 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
# coding: utf-8
n = int(input())
A = list(map(int, input().split()))
c = 0
for i in range(n-1):
    for j in range(n-1, i, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            c += 1
print(" ".join(map(str, A)))
print(c)

Measured memory_bytes: 7672
package main
import . "fmt"
func main() {
  var s,t string
  var j int
  Scan(&s)
  t = ""
  j = 0
  for i:=0;i<len(s);i++ {
    if s[i:i+1] != "B" {
      t += s[i:i+1]
      j++
    } else {
      if j > 0 { j-- }
      t = t[:j]
    }
  }
  Println(t)
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main() {
	int r, c;
	while (cin >> r >> c){
		if (r == 0 && c == 0)return 0; else if (r % 2 == 0 || c % 2 == 0)cout << "yes\n"; else cout << "no\n";
	}
}

Measured memory_bytes: 3012
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {

	for (int x,t=1; ; t++){
		cin>>x;
		if (x==0)break;
		cout<<"Case "<< t <<": "<< x <<endl;
	}

	return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
const int inf=1e8;
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int> >in(n,vector<int>(m));
  rep(i,n)rep(j,m){
    cin>>in[i][j];
    if(i)in[i][j]^=1;
  }
  int out=0;
  rep(i,n){
    string s="";
    rep(j,m)s+=(in[i][j]+'0');
    while(s.size()){
      int q=s.size();
      if(s[0]=='1'){
	out++;
	s=s.substr(1);
	s[0]=(s[0]=='1'?'0':'1');
      }else{
	if(s[q-1]=='1')out++;
	s[q-2]=(s[q-2]=='1'?'0':'1');
	s=s.substr(0,q-1);
      }
    }
  }
  cout<<out<<endl;
}

Measured memory_bytes: 1272
from operator import mul
from functools import reduce

def cmb(n):
  return n*(n-1)//2

N=int(input())
A=list(map(int, input().split()))

#インデックス０は除外
count=[0]*(N+1)
for a in A:
  count[a]+=1

cmbs=[0]*N
for i,c in enumerate(count):
  if i==0:
    continue
  cmbs[i-1]=cmb(c)
SUM=sum(cmbs) 
for i in range(N):
  a=A[i]
  #print(cmbs[a-1])
  ans=SUM-cmbs[a-1]+cmb(count[a]-1)
  print(ans)
  
#print(count, cmbs)

Measured memory_bytes: 27024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
ll ans;
string s;
vector<pair<ll,ll>> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}

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

#define MAX_N 100010
bool x[MAX_N];
ll num[MAX_N];

ll fibl[MAX_N]={0};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}

ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    
    return p;
}

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

void rec(ll i,ll val,ll pre){
    if (i==s.size()){
        ans+=val+pre;
    }else{
        rec(i+1,val,pre*10+s[i]-'0');
        rec(i+1,val+pre,s[i]-'0');
    }
}

int main(){
    cin >> s;
    rec(1,0,s[0]-'0');
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long 	ll;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6+5;
ll dp[N][5];
ll a[N][5];
ll n;
ll solve(ll i,ll p)
{
	if(i==n)
	{
		return 0;
	}
	if(dp[i][p]!=-1)
	{
		return dp[i][p];
	}
	ll ans=-1e9;
	for(ll j=0;j<3;j++)
	{
		if(j==p)
		{
			continue;
		}
		ans=max(ans,solve(i+1,j)+a[i][j]);
	}
	return dp[i][p]=ans;
}
 
int main() {
 
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
 
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout<<solve(0,3);
}

Measured memory_bytes: 91828
from collections import deque

def solve(n, a):
    a = sorted(a)
    return max(f(n, a), f(n, a[::-1]))

def f(n, a):
    a = deque(a)
    b = deque([])
    for i in range(n):
        if (i-1) % 4 < 2:
            v = a.popleft()
        else:
            v = a.pop()
        if i % 2 == 0:
            b.appendleft(v)
        else:
            b.append(v)
    return sum([abs(b[i+1]-b[i]) for i in range(n-1)])

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))

Measured memory_bytes: 13760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp

int N;
int A[10005];
                                                
static int b() {
   int c = 0;
   for (int i = 1; i < N; i++) {
       for (int j = N-1; j >= i; j--) {
           if (A[j] < A[j-1]) {
               swap(A[j], A[j-1]);
               c++;
           }
       }
   }
   return c;
}

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    int c = b();
    arrdump(N, A);
    cout << c << "\n";
    return 0;
}


Measured memory_bytes: 3104
import System.IO
left s1 s2 = [(c1:s1,c2:s2)| c1<-".#",c2<-".#"]
right s1 s2 = [(s1++[c1],s2++[c2])| c1<-".#",c2<-".#"]
outer f s1 s2 = do
  let inner [] = outer right s1 s2
      inner ((s1,s2):ss) = do
        putStrLn s1
        putStrLn s2
        hFlush stdout
        r <- getLine
        case r of
          "end" -> return ()
          "T" -> outer f s1 s2
          "F" -> inner ss
  inner $ f s1 s2
main = do
  getLine
  outer left "" ""

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void answer1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void answer2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void answer3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void answer(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i, j;
  ll n;
  cin >> n;
  //ll a, b, c;
  //cin >> a >> b;
  //string s; cin >> s;
  ll result = 0;
  bool judge = true;
  ll buf;
  for(i=1;i<=sqrt(n)+1;i++){
    if(n%i==0&&i<(n/i-1))
    result+=n/i-1;
  }
  cout<<result<<endl;





  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long
    #define int long long 
    #define ull unsigned long long 
    #define ld long double
    #define sb __builtin_popcount
    #define vi vector<int>
    #define vc vector<char>
    #define ii pair<int, int>
    #define pq priority_queue<ii, vector<ii>, greater<ii>>
    #define vii vector<ii>
    #define sz(a) int((a).size())
    #define f(a, b) for (int i = a; i < b; i++)
    #define fr(a, b) for (int i = a - 1; i >= b; i--)
    #define tr(x, m) for (auto x : m)
    #define in(a, b) (b.find(a) != string::npos)
    #define minin(a) *min_element(all(a))
    #define maxin(a) *max_element(all(a))
    #define X first
    #define Y second
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define rall(v) reverse(v.begin(), v.end())
    #define unq(v) v.erase(unique(all(v)), v.end())
    #define el "\n"
    #define mx3(a, b, c) max(max(a, b), c)
    #define mn3(a, b, c) min(min(a, b), c)
    #define S(v) accumulate(all(v), (ll)0)
    #define SP(n) cout.precision(n)
    const ld PI = atan(1.0) * 4.0;
    const ll MOD = 1e9 + 7;
    const ll INF = 1e18;
    const ld EPS = 0.0000001;
    const ll MD = 998244353;
    
    int32_t main() {
        fio;
        int n,m,x;
        cin>>n>>m>>x;
        int xx;
        vector<int> v[n];
        for(int i=0;i<n;i++){
            for(int j=0;j<m+1;j++){
                cin>>xx;
                v[i].pb(xx);
            }
        }
        int mn=INT_MAX;
        int tmp,cnt;
        for(int i=1;i<pow(2,n);i++){
            vector<int>nm;
            cnt=0;
            tmp=i;
            while(tmp>0){
                if(tmp%2)nm.pb(cnt);
                cnt++;
                tmp/=2;
            }
            int cst=0;
            int g=1;
            for(int j=1;j<=m && g;j++){
                int ind=0;
               for(int k=0;k<nm.size();k++){
                   ind+=v[nm[k]][j];
               }
               if(ind<x){
                   g=0;
               }
            }
            if(g){
                for(int k=0;k<nm.size();k++){
                   cst+=v[nm[k]][0];
               }
               mn=min(mn,cst);
            }
        }
        if(mn!=INT_MAX)
        cout<<mn<<el;
        else cout<<-1<<el;
        return 0;
    }


Measured memory_bytes: 4092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
    //b+c,a+c,a+b b+c-a-c=b-a 1 3 5 7
    //2a+c+b,a+2b+c,a+b+2c a-b 2 4 6 8
int a,b,c;
long long int k;
scanf("%d %d %d %lld",&a,&b,&c,&k);
if(k%(long long int)2==0){printf("%d\n",a-b);}
else{printf("%d\n",b-a);}
 
} 

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()

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

  int D, N;
  cin >> D >> N;

  if(D == 0) {
    D = 1;
  } else if(D == 1) {
    D = 100;
  } else if(D == 2) {
    D = 10000;
  }

  int ans = 0;
  if(N == 100) {
    N = 101;
  }
  ans = D * N;
  cout << ans << endl;
}


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

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define int ll
int INF = 1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
typedef pair<int, int> Vec2;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; }
template<class T> inline void chmin(T& a, T b) { if (a > b)  a = b; }

int w[110];
int v[110];
int dp[110][100100] = { 0 };
signed main() {
	ios::sync_with_stdio(false);
	int N, W;
	cin >> N >> W;
	rep(i, N)  cin >> w[i] >> v[i];
	rep(i,N){
		for (int j = 0; j <= W; j++) {
			if (j - w[i] >= 0)
				chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
			chmax(dp[i + 1][j], dp[i][j]);
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}


Measured memory_bytes: 79360
def is_palindrome(s):
	for i in range(len(s)):
		if s[i] != s[-i - 1]:
			return False

	return True

S = input()
N = len(S)
if is_palindrome(S) and is_palindrome(S[:(N - 1) // 2]) and is_palindrome(S[-(N - 1) // 2:]):
	print("Yes")
else:
	print("No")

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

int solve(vector<int> &inters){
  const size_t N= inters.size();
  if(N==1){ return 0; }
  else{
    int ret= 0;
    for(size_t i=0; i< N-1-i; i++){
      ret+= abs(inters.at(i)- inters.at(N-1-i));
    }

    return ret;
  }
}

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

  string T;
  vector<int> inters;
  int cnt= 0;
  for(auto c:S){
    if(c=='x'){
      cnt++;
    }
    else{
      T+= c;
      inters.emplace_back(cnt);
      cnt= 0;
    }
  }
  inters.emplace_back(cnt);

  string Trev;
  reverse_copy(T.begin(), T.end(), back_inserter(Trev));

  int ans= (T==Trev) ? solve(inters)
                     : -1;
  cout << ans << endl;
}

Measured memory_bytes: 4148
#include <iostream>
#include <cmath>

using namespace std;

int dp[100030];
int cost[100030];

int main () {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>cost[i];
	}
	dp[1]=abs(cost[0]-cost[1]);
	dp[2]=abs(cost[0]-cost[2]);
	for(int i=3;i<n;i++){
		dp[i]=min(dp[i-1]+abs(cost[i]-cost[i-1]),dp[i-2]+abs(cost[i]-cost[i-2]));
	}
	cout<<dp[n-1];



return 0;
}



Measured memory_bytes: 1024
#include <iomanip>
#include <string>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	long long int x, y, k, yan;
	cin >> x >> y >> k;
	if (x == 0) {
		yan = 0;
	}
	else {
		yan = (x - 1) / k + 1;
	}
	cout << y / k + 1 - yan << endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
l = []
n.times do
    l.push(gets.split.map(&:to_i))
end
l.sort_by!{|a| a[1]}
t = 0
for i in 0 .. n - 1
    if t + l[i][0] > l[i][1]
        puts "No"
        exit
    end
    t += l[i][0]
end
puts "Yes"

Measured memory_bytes: 22520
import sys
input = sys.stdin.readline
l,r=map(int,input().split())

if r-l>=2018:
    print(0)
else:
    ans=10*1000000
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            if ans>(i*j)%2019:
                ans=(i*j)%2019
    print(ans)



Measured memory_bytes: 2940
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    sort(A.begin(), A.end());
    cout << accumulate(A.begin(), A.begin() + K, 0) << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    LinkedList<Character> list = new LinkedList<>();
    for (char c : sc.nextLine().toCharArray()) {
      switch (c) {
        case 'B':
          if(list.size() > 0) {
            list.removeLast();
          }
          break;
        default:
          list.add(c);
      }
    }
    list.stream().forEach(System.out::print);
    System.out.println();
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 15308
N, M = map(int, input().split())

mod = 10 ** 9 + 7
#L = 5 * 10**5
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]

def comb(n, r):
  return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod

def perm(n, r):
  return  fac[n] * finv[n-r] % mod
 
for i in range(2, M + 1):
  fac.append( ( fac[-1] * i ) % mod )
  inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
  finv.append( finv[-1] * inv[-1]  % mod )

ans = 0

for K in range(N+1):
  ans += comb(N, K) * (-1)**(K%2) % mod * perm(M, K) % mod * pow(perm(M-K, N-K), 2, mod)
  ans %= mod

print(ans)

Measured memory_bytes: 68668
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <set>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 100005;
ll a[maxn], b[maxn];
ll f[maxn];

struct Node {
	int r;
	mutable int v;
	Node(int r, int v = 0): r(r), v(v) { }
};
inline bool operator < (Node x, Node y) { return x.r < y.r; }

typedef std::set<Node>::iterator iter;
std::set<Node> odt;

inline iter split(int k) {
	iter it = odt.lower_bound(k);
	if(it -> r == k) return it;
	return odt.insert(Node(k, it -> v)).first;
}

inline void set(int l, int r, int v) {
	if(l > r) return;
	iter li = split(l - 1), ri = split(r);
	ri -> v = v;
	odt.erase(++ li, ri);
}

inline int query(int k) {
	iter it = odt.lower_bound(k);
	return it -> v;
}

int l[maxn], r[maxn];
int main() {
	int n = read, k = read;

	for(int i = 1; i <= n; i ++) {
		a[i] = a[i - 1] + read;
		b[i] = read;
		if(b[i] == 1) {
			l[i] = (k - a[i - 1] * 2 % k) % k;
			r[i] = (k - a[i] * 2 % k) % k;
			if((a[i] - a[i - 1]) * 2 > k) return puts("-1"), 0;
		} else {
			l[i] = 0;
			r[i] = k - 1;
		}
	}

	odt.insert(Node(k, n + 1));

	for(int i = n; i; i --) {
		int j = query(l[i]);
		if(j <= n)
			f[i] = f[j] + (l[j] - l[i] + k) % k;
		if(l[i] <= r[i]) {
			set(0, l[i] - 1, i);
			set(r[i] + 1, k - 1, i);
		} else
			set(r[i] + 1, l[i] - 1, i);
		/* debug("%d : %d-%d f=%lld j=%d\n", i, l[i], r[i], f[i], j); */
	}

	ll ans = 1000000000000000000ll;
	for(Node x : odt)
		if(x.r >= 0 and x.r < k) {
			/* debug("%d %d\n", x.r, x.v); */
			if(x.v <= n)
				ans = std::min(ans, f[x.v] + (l[x.v] - x.r + k) % k);
			else
				ans = 0;
		}
	ans += a[n] * 2;

	printf("%lld\n", ans);
}


Measured memory_bytes: 12544
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/


int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	int ans = 0;
	for (int i = 1; i <= W - w; i++) {
		for (int j = 1; j <= H - h; j++) {
			ans++;
		}
	}
	cout << ans;
	return 0;
}










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

using namespace std;
using ll = long long;

#define debug(x) cerr << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

const int maxn = 2e5 + 10;

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


int main()
{
	ios::sync_with_stdio(false);
	int test = 1;
	while(test--)
	{
		string s,t;
		cin >> s >> t;
		int ans = INT_MAX;
		for(int i = 0; i < s.size(); i++)
		{
			int cnt = 0;
			int j = 0;
			for(j = 0 ; j < t.size(); j++)
			{
				if(i + j >= s.size())
					break;
				cnt += s[i+j] != t[j];
			}
			if(j == t.size())
				ans = min(ans, cnt);
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include<algorithm>
using namespace std;
 
int main()
{
    int a,b,x;
    int ans = 0;
    cin >> a >> b >> x;
    if (a < 2 * b) {
        ans += (x / 1000) * a;
        if (x % 1000 > 500)ans += a;
        else if (x % 1000 > 0)ans += min(a, b);
    }
    else {
        ans += (x / 500) * b;
        if (x % 500 > 0)ans += b;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3116
N = int(input())
A=[int(i) for i in input().split()]

# print(N,A)
# print(A)

while(True):
    A.sort()
    min_A=A[0]
    c=0
    for i in range(len(A)):
        tmp=A[i]%min_A
        if(tmp==0):
            c+=1
            A[i]=min_A
        else:
            A[i]=tmp
    if(c==len(A)):
        break

A.sort()
print(A[0])


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2000003;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1; finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  int r1, c1, r2, c2;
  cin>>r1>>c1>>r2>>c2;
  COMinit();
  long long ans =
    COM(r2 + c2 + 2, r2 + 1)
    - COM(r1 + c2 + 1, r1)
    - COM(r2 + c1 + 1, r2 + 1)
    + COM(r1 + c1, r1);
  ans = (ans + MOD) % MOD;
  cout<<ans<<endl;
}

Measured memory_bytes: 47104
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    String N = sc.next();
    if (N.equals("ABC")) {
      System.out.println("ARC");
    } else {
      System.out.println("ABC");
    } 
  }
}

Measured memory_bytes: 35612
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int a,b,k;
    cin>>a>>b>>k;
    if(2*k>=b-a+1)
    {
        for(int i=a;i<=b;i++)
            cout<<i<<endl;
        return 0;
    }
    for(int i=0;i<k;i++)
        cout<<a+i<<endl;
    for(int i=1;i<=k;i++)
        cout<<b-k+i<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  REP(i, k) {
    if(a >= b) {
      b *= 2;
    } else {
      c *= 2;
    }
  }
  if(a < b && b < c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;

int main()
{
    LL n, k;
    cin >> n >> k;
    vector<LL> a(n);
    vector<LL> cnt(45);
    rep(i, 0, n){
        cin >> a[i];
        LL t = a[i];
        LL j = 0;
        while (t)
        {
            if(t & 1)
                cnt[j]++;
            j++;
            t >>= 1;
        }
    }
    LL ans = 0;
    bool less = 0;
    for(int i = 44; i >= 0; i--){
        LL x = (1LL << i);
        // if(x <= k && x ^ ans <= k && cnt[i] * 2 < n){
        //     ans ^= x;
        // }
        if(cnt[i] * 2 >= n){
            ans += cnt[i] * x;
            if(x & k)   less = 1;
        }
        else if(x & k || less) 
            ans +=  (n-cnt[i]) * x;
        else ans += cnt[i] * x;
    }
    // LL res = 0;
    // rep(i, 0, n)
    //     res += ans ^ a[i];
    // cout << res << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
times = []
5.times {
  times.push(gets.to_i)
}

times.sort!{|a, b| (10 - a%10)%10 <=> (10 - b%10)%10 }

time = 0
times.each{|t|
  time += 10 - (time%10) if time%10 != 0
  
  time += t
}

puts time

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
	int n;
	int a, b;
	cin >> n;
	if (n == 1) {
		cout << "Hello World";
	}
	else if (n == 2) {
		cin >> a >> b;
		cout << a + b;
	}

	return 0;
}

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

const ll INF = 1LL << 60;

string S;
ll K;
int main() {
    cin >> S >> K;

    // 始めが1ではない場合
    if (S[0] != '1') {
        cout << S[0] << endl;
        return 0;
    }

    // 1が何個連続するか
    ll one_num = 0;
    bool one_in = false;
    ll ans = S[0] - '0';
    rep(i, S.size()) {
        if (one_in && S[i] - '0' != 1) {
            ans = S[i] - '0';
            break;
        }
        if (S[i] - '0' == 1) {
            one_num++;
            one_in = true;
        } 
    }

    if (K <= one_num) {
        cout << 1 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
def turn(s)
  s == "S" ? "W" : "S"
end

def solve(n,list)
  ans = [['S','S'],
         ['S','W'],
         ['W','S'],
         ['W','W']]

  (2...n).each do |i|
    ans.each do |ans_seq|
      if (ans_seq[i-1] == "S" && list[i-1] == "o") ||
         (ans_seq[i-1] == "W" && list[i-1] == "x")
        ans_seq << ans_seq[i-2]
      else
        ans_seq << turn(ans_seq[i-2])
      end
    end
  end

  ans.each do |ans_seq|
    if (ans_seq[0] == "S" && list[0] == "o") ||
       (ans_seq[0] == "W" && list[0] == "x")
      next unless (ans_seq[1] == ans_seq[n-1])
    else
      next unless (ans_seq[1] != ans_seq[n-1])
    end

    if (ans_seq[n-1] == "S" && list[n-1] == "o") ||
       (ans_seq[n-1] == "W" && list[n-1] == "x")
      next unless (ans_seq[0] == ans_seq[n-2])
    else
      next unless (ans_seq[0] != ans_seq[n-2])
    end
    # solve
    puts ans_seq.join
    return
  end
  puts "-1"
end

def main
  n = gets.to_i
  list = gets.scan(/./)
  solve(n,list)
end

main


Measured memory_bytes: 28284
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string s[101];
int t[101];

int main(void){
	scanf("%d",&n);
	int ans2=0;
	for(int i=0;i<n;i++){
		cin >> s[i] >> t[i];
		ans2+=t[i];
	}
	string g;
	cin >> g;
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=t[i];
		if(g==s[i]){
			break;
		}
	}
	printf("%d\n",ans2-ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
    char s[200];
    int i = 0;
    scanf("%s", s);
    for (i = 0; i < strlen(s); i++)
    {
        s[i] = 'x';
    }
    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int X = sc.nextInt();
   int A = sc.nextInt();
   
  if(A>X )
  {
    System.out.println(0); 
  }
   
  else
  {
    System.out.println(10); 
  }
 }
}

Measured memory_bytes: 23120
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c;
    cin >> a >> b >> c;
    string res = "NO";
    for(int i=1; i<100; i++){
        if((c+b*i)%a==0){
            res = "YES";
            break;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
input = raw_input
range = xrange
h, n = map(int, input().split(" "))

pairs = []
ratios = []
a_list = []
inputs = []
for i in range(n):
    a, b = map(int, input().split(" "))
    a_list.append(a)
    #ratio = a/b
    #ratios.append(ratio)
    #pairs.append([a, b, ratio])
    inputs.append([a, b])

#pairs = sorted(pairs, key=lambda x: -x[2])
#print(pairs)

max_a = max(a_list)

min_val = -1-max_a
costs = {}
for i in range(min_val, h+1):
    costs[i] = None
costs[h] = 0
#costs = [None for i in range(h)] + [0]

for val in range(h, min_val-1, -1):
    for a, b in inputs:
        if val+a > h:
            continue
        if costs[val+a] is None:
            continue

        if costs[val] is not None:
            costs[val] = min(costs[val+a]+b, costs[val])
        else:
            costs[val] = costs[val+a]+b

out = min([costs[val] for val in range(min_val, 1) if costs[val] is not None])
#print(costs)
print(out)

Measured memory_bytes: 33768
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
string s;
s=("ABC");
string a;
cin>>a;
cout<<s+a;
system("pause");
return 0;
}

Measured memory_bytes: 504
N,K = (int(x) for x in input().split())

taisho = set()
for j in range(K):
    d = int(input())
    A = [int(x) for x in input().split()]
    for k in range(d):
        if not A[k] in taisho:
            taisho.add(A[k])
cnt = 0
for i in range(N):
    if not i+1 in taisho:
        cnt += 1
print(cnt)


Measured memory_bytes: 9192
import java.io.BufferedReader
import java.util.*
import kotlin.math.abs
import kotlin.math.min

fun main() = abc119d()

@OptIn(ExperimentalStdlibApi::class)
fun abc119d() = SimpleFastIOWithToken_abc119d().exec {
    val n = readInt()
    val (a, b, c) = IntArray(3) { readInt() }
    val bamboos = IntArray(n) { readInt() }

    fun dfs(index: Int, lengthsA: Int, lengthsB: Int, lengthsC: Int): Int {
        if (index == n) return when {
            minOf(lengthsA, lengthsB, lengthsC) == 0 -> Int.MAX_VALUE / 100
            else -> abs(lengthsA - a) + abs(lengthsB - b) + abs(lengthsC - c) - 30
        }

        return listOf(
            dfs(index + 1, lengthsA, lengthsB, lengthsC),
            dfs(index + 1, lengthsA + bamboos[index], lengthsB, lengthsC) + 10,
            dfs(index + 1, lengthsA, lengthsB + bamboos[index], lengthsC) + 10,
            dfs(index + 1, lengthsA, lengthsB, lengthsC + bamboos[index]) + 10
        ).min()!!
    }

    val answer = dfs(0, 0, 0, 0)

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc119d(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc119d.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 44964
#include <bits/stdc++.h>
using namespace std;
long long int parallelogram(long long int, long long int);
long long int trapezium(long long int, long long int);
long long int parallelogram(long long int s1, long long int s2)
{
	if(s1 < s2)
		swap(s1, s2);
	if(s1%s2 == 0)
		return (2ll*(s1/s2) - 1)*s2;
	return (2ll*(s1/s2)*s2) + parallelogram(s1%s2, s2);
}
long long int trapezium(long long int s1, long long int s2)
{
	return s2 + parallelogram(s1, s2);
}
int main()
{
	long long int n,x;
	cin>>n>>x;
	long long int ans = x + trapezium(x, n-x);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,c=1,x=0,v=0,i,p=0;
    string s;
    cin >> n >> s;
    if(n%2!=0)
    {
        cout << "No" << endl;
        return 0;
    }
    v=n/2;
    if(s.substr(0,v)==s.substr(v))
       {
           cout << "Yes" <<endl;
       }
    else
    {
        cout << "No" << endl;
    }

    return 0;

}


Measured memory_bytes: 3572
import math

X = int(input())

ans_list = []

for i in range(2, int(math.sqrt(X)) + 1, 1):
  j = 1
  while 1:
    if i ** j <= X:
      j += 1
    else:
      ans_list.append(i ** (j - 1))
      break
else:
  if X == 1:
    print(1)
  else:
    print(max(ans_list))

Measured memory_bytes: 9036
H,W = map(int,input().split())

a = [list(input()) for i in range(H)]
cnt = 0
i = 0
while i < len(a):
    for j in range(W):
        if a[i][j] not in '#':
            cnt += 1
    if cnt == W:
        a.remove(a[i])
        i -= 1
        H -= 1
    cnt = 0
    i += 1
i = 0
cnt = 1
while i < W:
    if a[0][i] == '.':
        for j in range(1,H):
            if a[j][i] == '.':
                cnt += 1
        if cnt == H:
            for j in range(H):
                a[j].pop(i)
            W -= 1
            i -= 1
    cnt = 1
    i += 1
[print(''.join(a[i])) for i in range(H)]

Measured memory_bytes: 3188
import math

a, b = map(int, input().split())
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
ab_gcd = gcd(a, b)

gcd_sq = int(math.sqrt(ab_gcd) + 1)

ans = []
curr_num = ab_gcd
for i in range(2, gcd_sq):
    if curr_num % i != 0:
        continue
    cnt = 0
    while curr_num % i == 0:
        curr_num = curr_num // i
        cnt += 1
    ans.append([i, cnt])
if curr_num != 1:
    ans.append([curr_num, 1])
print(len(ans) + 1)    

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

int main() {
  int n; cin >> n;
  if(n%2 == 1){
    cout << "No" << endl;
    return 0;
  }

  string s;
  rep(i,n) cin >> s[i];

  bool flag = true;
  rep(i,n/2){
    if(s[i] != s[i+n/2]) flag = false;
  }

  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

using ll = long long;

#define MOD 1000000007

#define FOR(i, m, n) for (ll i = m; i <= n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)

ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
    ll N, K;
    cin >> N >> K;
    cout << (N % K > K / 2 ? (K - N % K) : (N % K)) << endl;
    return 0;
}


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

void start() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int32_t main() {
    start();
    int ans = 0;
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - 1 - i])ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(1000000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == '@':
                dfs(i,j,'@')
                count+=1
            elif field[i][j] == '#':
                dfs(i,j,'#')
                count+=1
            elif field[i][j] == '*':
                dfs(i,j,'*')
                count+=1
    print(count)

#x,y??§2??¶?????°???1?????§??\????????????????????\???????????°?????§????????¨???
f=0
while(f==0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨??????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f=1

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	string S; cin >> S;
	bool ans = false;
	if(S[0] == S[1] and S[2] == S[3] and S[0] != S[2]) ans = true;
	else if(S[0] == S[2] and S[1] == S[3] and S[0] != S[1]) ans = true;
	else if(S[0] == S[3] and S[1] == S[2] and S[0] != S[1]) ans = true;
	else if(S[1] == S[2] and S[0] == S[3] and S[1] != S[3]) ans = true;

	if(ans == true) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;

}


Measured memory_bytes: 256