akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> answer;
    vector<int> v(n, 0);
    for (int i = n; i > 1; --i) {
        if (a[i - 1] != v[i - 1]) {
            answer.push_back(i);
            v[i - 1] = 1 - v[i - 1];
            for (int j = 1; j * j <= i; ++j) {
                if (i % j == 0) {
                    v[j - 1] = 1 - v[j - 1];
                    if (j * j != i) {
                        v[i / j - 1] = 1 - v[i / j - 1];
                    }
                }
            }
        }
    }
    if (a[0] != v[0]) answer.push_back(1);

    cout << answer.size() << endl;
    if (!answer.empty()) {
        for (int i = 0, size = answer.size(); i < size; ++i) {
            cout << answer[i];
            if (i < size - 1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <cmath>
#include <climits>
#include <unordered_map>
using namespace std;

int main() {

int n;
cin>>n;


  const unsigned int M = 1000000007;

      unsigned long long f = 1;
      unsigned long long nine = 1;
      unsigned long long eight = 1;

if(n==2) {f = 2;}
else if(n==1){f = 0;}
else {
      for (int i = 1; i <= n; i++){
          f = (f*10) % M;
          nine = (nine*9) % M;
          eight = (eight*8) % M;
      }

      f = (f + M - ((nine + nine) % M) + eight) % M;
 }
      cout<<f<<endl;

return 0;
}


Measured memory_bytes: 3608
n = int(input())
a = [int(x) for x in input().split()]

#偶数番目を正にする場合

s = 0
t0 = 0

if a[0] > 0:
    s = a[0]
else:
    s = 1
    t0 = abs(a[0]) + 1

for i in range(1, n):
    if (s + a[i]) * (-1) ** i <= 0:
        t0 += abs(s + a[i]) + 1
        s = (-1) ** i
    else:
        s += a[i]

#偶数番目を負にする場合

s = 0
t1 = 0

if a[0] < 0:
    s = a[0]
else:
    s = -1
    t1 = abs(a[0]) + 1

for i in range(1, n):
    if (s + a[i]) * (-1) ** (i + 1) <= 0:
        t1 += abs(s + a[i]) + 1
        s = (-1) ** (i + 1)
    else:
        s += a[i]

ans = min(t0, t1)

print(ans)

Measured memory_bytes: 20084
ABCD = str(input())
A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]

for i in range(1):
    if int(A) + int(B) + int(C) + int(D) == 7:
        print(A + "+" + B + "+" + C + "+" + D +"=7")
        break
    if int(A) - int(B) + int(C) + int(D) == 7:
        print(A + "-" + B + "+" + C + "+" + D +"=7")
        break
    if int(A) + int(B) - int(C) + int(D) == 7:
        print(A + "+" + B + "-" + C + "+" + D +"=7")
        break
    if int(A) - int(B) - int(C) + int(D) == 7:
        print(A + "-" + B + "-" + C + "+" + D +"=7")
        break
    if int(A) + int(B) + int(C) - int(D) == 7:
        print(A + "+" + B + "+" + C + "-" + D +"=7")
        break
    if int(A) - int(B) + int(C) - int(D) == 7:
        print(A + "-" + B + "+" + C + "-" + D +"=7")
        break
    if int(A) + int(B) - int(C) - int(D) == 7:
        print(A + "+" + B + "-" + C + "-" + D +"=7")
        break
    if int(A) - int(B) - int(C) - int(D) == 7:
        print(A + "-" + B + "-" + C + "-" + D +"=7")
        break


Measured memory_bytes: 9184
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int a,b; cin>>a>>b;
    if (b%a==0) cout << a+b << '\n';
    else cout << b-a << '\n';
    return 0;
}

Measured memory_bytes: 3476
#include <iostream>

using namespace std;

const int MAX { 100010 };

int st[MAX];

int coin_change(int N)
{
    st[0] = 0;

    for (int n = 1; n <= N; ++n)
    {
        st[n] = st[n - 1] + 1;

        for (int k = 6; k <= n; k *= 6)
            st[n] = min(st[n], st[n - k] + 1);

        for (int k = 9; k <= n; k *= 9)
            st[n] = min(st[n], st[n - k] + 1);
    }

    return st[N];
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    cout << coin_change(N) << endl;

    return 0;
}


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

int main(){
  int K;cin >> K;
  string str;cin >> str;
  if (str.size()<=K){
    cout << str << endl;
  }
  else {
    for (int i=0;i<K;i++){
      cout << str.at(i);
    }
    cout << "..." << endl;
  }
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
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;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int n;
	cin >> n;
	vector<long long int> s;
	long long int b = 1;
	long long int ans = 0;
	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		ans = ans + (a - 1);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int a,b,c;
    scanf("%d%d%d", &a, &b, &c);
    if(a > b+c){
        printf("%d\n", 0);
    } else {
        printf("%d\n", c-(a-b));
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define nl printf("\n")
#define YES printf("YES\n")
#define Yes printf("Yes\n")
#define yes printf("yes\n")
#define NO printf("NO\n")
#define No printf("No\n")
#define no printf("no\n")
using namespace std;
int p[100002][4];
int a[100002][4];
int max_sum(int c,int i,int n){
    if(c>n) return 0;
    if(p[c][i]!=-1) return p[c][i];
    int j;
    int mx=0;
    for(j=0;j<3;j++){
        if(j==i) continue;
        mx=max(mx,a[c][j]+max_sum(c+1,j,n));
    }
    return p[c][i]=mx;
}
main()
{
    int n,ans;
    scanf("%d",&n);
    int i;
    for(i=1;i<=n;i++){
        scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
        p[i][0]=-1;
        p[i][1]=-1;
        p[i][2]=-1;
        p[i][3]=-1;

    }
    ans=max_sum(1,3,n);
    printf("%d\n",ans);
}


Measured memory_bytes: 14744
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

int main(){
    ll n,d; cin>>n>>d;
    vector<vector<ll>>a(n,vector<ll>(2));
    rep(i,n)cin>>a[i][0]>>a[i][1];
    ll ans=0;
    rep(i,n){
        ll b=a[i][0]*a[i][0]+a[i][1]*a[i][1];
        if(b<=d*d)ans++;
    }
    cout<<ans<<endl;
}








































Measured memory_bytes: 20320
import math

N, K = list(map(int, input().split()))
x = 1/N
ans = 0

for i in range(1, N+1):
    if i < K:
        n = math.ceil(math.log2(K/i))
        ans += (x * 0.5**n)
    else:
        ans += x

print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long N,ma=0LL,ans,i;
int main(){
    cin>>N;
    vector<long long>A(N);
    for(auto &x:A)cin>>x;
    for(ma=A[0];i<N;i++){ans+=(ma>A[i]?ma-A[i]:0LL);ma=max(ma,A[i]);}
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  ll n,x,t;
  cin >> n >> x >> t;
  
  if(n%x == 0)
    cout << t*(n/x) << endl;
  else
    cout << t*(n/x+1) << endl;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const 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 pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  string s,t,u;cin>>s>>t>>u;
  cout<<s[0]<<t[0]<<u[0]<<endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

vector<int> cumsum(const vector<int> &v) {
	int n = v.size();
	vector<int> sum(n + 1);
	for (int i = 0; i < n; i++)
		sum[i + 1] = sum[i] + v[i];
	return sum;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	int K; cin >> K;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	vector<int> sum = cumsum(a);
	vector<int> b(N);
	rep(i, 0, N)chmax(b[i], a[i]);
	vector<int> sumb = cumsum(b);
	int ans = 0;
	dump(sum);
	dump(sumb);
	rep(i, 0, N - K + 1) {
		chmax(ans, sum[i + K] - sum[i] + sumb[i] + sumb[N] - sumb[i + K]);
		chmax(ans, sumb[i] + sumb[N] - sumb[i + K]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main(){
  long i, j;
  unsigned long X;
  long long A, B;
  
  cin >> X;
  
  for(i = 1; ; i++){
    A = i*i*i*i*i;
    for(j = i; j >= -1 * i; j--){
      B = j*j*j*j*j;
      if(A-B == X){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  
}

Measured memory_bytes: 3588
import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N, M = rl()
graph = [[] for _ in range(N+1)] # 0は使わない、直接行ける頂点
for _ in range(M):
    a, b = rl()
    graph[a].append(b)
    graph[b].append(a)

# 二部グラフのチェック、各頂点に0か1の色を塗る、1の頂点に0の色
color = [None] * (N+1) # 0は使わない
color[1] = 0
stack = [1]
bool = True
while stack:
    node = stack.pop()
    for n in graph[node]:
        if color[n] == None:
            color[n] = 1 - color[node]
            stack.append(n)
        elif color[n] == color[node]:
            bool = False
        else:
            continue

if bool:
    # 二部グラフ
    print((color.count(1) * color.count(0)) - M)
else:
    print(N*(N-1)//2 - M)
#29


Measured memory_bytes: 25688
import java.io.*; 
import java.util.*; 

public class Main{ 
	
	static class FastReader{ 
		BufferedReader br; 
		StringTokenizer st; 

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

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

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

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

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

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	}
  
  	static int findd(int n){
		int res = 0;
		while(n>0){
			res++;
			n/=10;
		}
		return res;
	}

	public static void main(String[] args) 
	{ 
		FastReader sc = new FastReader(); 
		int n = sc.nextInt(), ans=0;
		
		for(int i=1;i<=n;i++)
			if(findd(i)%2==1)
				ans++;
      
		System.out.println(ans); 
	} 
} 


Measured memory_bytes: 21588
def main():
    N, A, B= [int(x) for x in input().split()]
    if A == 0:
        print(0)
        return

    count = N // (A + B)
    left = N % (A + B)
    blue = count * A
    blue += A if left >= A else left
    print(blue)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<deque>
#include<queue>
#include<complex>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>

using namespace std;

#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;

int n, m;
bool dp[5002][4100];
string e[20];

vector<int> g[5002];

/*
int *buildFail(const string &p){
  int M = p.length();
  int *fail = new int[M + 1];
  int j = fail[0] = -1;

  for(int i = 1; i <= M; i++){
    while(j >= 0 && p[j] != p[i - 1]){
      j = fail[j];
    }
    fail[i] = ++j;
  }
  return fail;
}

void match(int id, const string &t, const string &p, int *fail){
  int N = t.length(), M = p.length();

  for(int i = 0, k = 0; i < N; i++){
    while(k >= 0 && p[k] != t[i]){
      k = fail[k];
    }
    if(++k >= M){
      g[i - M + 1].push_back(id);
      k = fail[k];
    }
  }
}

void makeG(const string &s){
  for(int i = 0; i < s.length(); i++){
    g[i].clear();
  }

  int *fail = buildFail(s);
  for(int i = 0; i < n; i++){
    match(i, s, e[i], fail);
  }
}
*/

void makeG(const string &s){
  int len = s.length();

  for(int i = 0; i < len; i++){
    g[i].clear();
  }

  for(int i = 0; i < n; i++){
    int lene = e[i].length();

    for(int j = 0; j <= len - lene; j++){
      bool flg = true;

      for(int k = j; k < j + lene; k++){
        if(e[i][k - j] != s[k]){
          flg = false;
          break;
        }
      }

      if(flg){
        g[j].push_back(i);
      }
    }
  }
}

ll solve(const string &s){
  makeG(s);

  ll res = 0;
  int FIN = (1 << n) - 1;
  int len = s.length();

  memset(dp, 0, sizeof(dp));

  for(int i = 0; i < len; i++){
    dp[i][0] = true;

    for(int j = 0; j < (1 << n) - 1; j++){
      if(!dp[i][j]) continue;

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

        if((j & (1 << to)) == 0){
          int ni = i + e[to].length();
          int nj = (j | (1 << to));
          dp[ni][nj] = true;
        }
      }
    }
  }

  for(int i = 0; i <= len; i++){
    //trueツつェツ陛環づ個値ツ？ -> trueツづ?づ債づ按つュ1ツづーツ堕ォツつオツつアツづ楪づヲツつ、ツづ可つオツつス
    if(dp[i][FIN]){
      res++;
    }
  }

  return res;
}

int main(){
  while(cin >> n >> m, n || m){
    for(int i = 0; i < n; i++){
      cin >> e[i];
    }

    string s = "";

    for(int i = 0; i < m; i++){
      string ts;
      cin >> ts;
      s += ts;
    }

    cout << solve(s) << endl;
  }
}

Measured memory_bytes: 20000
def main():
    n = int(input())
    a = list(map(int,input().split()))
    x = 1
    if 0 in a:
        print(0)
        return
    for i in a:
        x *= i
        if x > 1000000000000000000:
            print(-1)
            return
    print(x)
main()

Measured memory_bytes: 21668
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
ans = 1000000

for i, h in enumerate(H):
    temp = T - h * 0.006
    if abs(temp - A) < ans:
        ans = min(ans, abs(temp - A))
        idx = i+1
print(idx)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll now[26];
ll ma[26];
int main() {
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		ll no=s[i]-'a';
		ll sa=(i)-now[no];
		ma[no]=max(sa,ma[no]);
		now[no]=i+1;
	}
	for(int i=0;i<26;i++){
		if(s.size()-now[i]>ma[i]&&now[i]!=0){
			ma[i]=s.size()-now[i];
		}
	}
	ll ans=INF;
	for(int i=0;i<26;i++){
		if(ma[i]==0){
			continue;
		}
		ans=min(ans,ma[i]);
	}
	cout << (ans==INF? 0:ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T ll
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b, ll m){
    ll ans=1;
    a%=m;
    while(b){
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}

int main(){
    IOS

    int a,b;
    cin>>a>>b;
    cout<<max(a*b,max(a+b,a-b));
    

    return 0;
}

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

using namespace std;

int KnapsackProblem(int c, int s, vector<int> &v, vector<int> &w){
	int dp[s+1][c+1];
	int a, b;
	for(a = 0; a <= s; a++){
		for(b = 0; b <= c; b++){
			if(a == 0 || b == 0){
				dp[a][b] = 0;
			} else if(w[a-1] <= b){
				dp[a][b] = max(v[a-1]+dp[a-1][b-w[a-1]], dp[a-1][b]);
			} else {
				dp[a][b] = dp[a-1][b];
			}
		}
	}
	return dp[s][c];
}

int main(){
	int N, W;
	cin >> N >> W;
	vector<int> v(N);
	vector<int> w(N);
	for(int i = 0; i < N; i++){
		cin >> v[i] >> w[i];
	} //Finished Resolving Inputs
	cout << KnapsackProblem(W, N, v, w) << endl; //Perform Solve Function
}



Measured memory_bytes: 7028
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n,q;
	while(cin>>n>>q&&!(n==0&&q==0))
	{
		//各年号の元年を入れる
		pair<ll,string> a[1000];
		pair<ll,ll> b[1000];
		REP(i,n){
			int x,y;string s;
			cin >> s>>x>>y;
			a[i]=make_pair(y-x+1,s);
			b[i]=make_pair(y-x+1,y);
		}
		//各元号の初年度を昇順に整列
		sort(a,a+n);
		sort(b,b+n);
		
		REP(i,q)
		{
			ll age;cin>>age;
			
			if(age<a[0].first)
			{
				cout<<"Unknown"<<endl;
			}
			else if(age>=a[n-1].first)
			{
				if(age<=b[n-1].second)
				{
					cout<<a[n-1].second<<" "<<age-a[n-1].first+1<<endl;
				}
				else
				{
					cout<<"Unknown"<<endl;
				}
			}
			else
			{
				REP(j,n-1)
				{
					if(a[j].first<=age&&a[j+1].first>age)
					{
						if(age<=b[j].second)
						{
							cout<<a[j].second<<" "<<age-a[j].first+1<<endl;
						}
						else
						{
							cout<<"Unknown"<<endl;
						}
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1304
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)



int main(){
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	REP(i,n) cin >> p[i];
	REP(i,n) cin >> q[i];
	
	int count=0;
	bool issame;
	
	REP(i,n){
		if(p[i] > q[i]){
			REP(j,n){
				int tmp = p[j];
				p[j] = q[j];
				q[j] = tmp;
			}
			break;
		}else if(p[i] < q[i]){
			break;	
		}
	}
	
	while(true){
		issame=true;
		REP(i,n){
			if(p[i]!=q[i]) issame=false; 
		}
		if(issame) break;
		count++;
		next_permutation(p.begin(), p.end());	
	};
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
int h,w;
vector<string> board;
vector<vector<int>> dist;
queue<pair<int,int>> q;

bool is_valid_move(vector<string> &board, vector<vector<int>> &dist, int y, int x){
  if(y<0 || y>=h || x<0 || x>=w) return false;
  if(board.at(y).at(x) == '#') return false;
  if(dist.at(y).at(x) != -1) return false;
  return true;
}

int main(){
  int longest_of_longest = 0;
  cin>>h>>w;
	board.resize(h);
  dist.resize(h,vector<int>(w,-1));
  
	rep(i,h) cin >> board.at(i);
  
  rep(i,h) rep(j,w){
    if(board.at(i).at(j) == '#') continue;
    rep(k,h) rep(l,w) dist.at(k).at(l) = -1;
    q.push(make_pair(i,j));
    dist.at(i).at(j) = 0;
    int longestlength = 0;

    while(q.size()){
      pair<int,int> p = q.front();
      q.pop();
      int cy = p.first, cx = p.second;
      if(is_valid_move(board,dist,cy+1,cx)){
        dist.at(cy+1).at(cx) = dist.at(cy).at(cx) + 1;
        longestlength = max(longestlength,dist.at(cy).at(cx) + 1);
        q.push(make_pair(cy+1,cx));                
      }
      if(is_valid_move(board,dist,cy,cx+1)){
        dist.at(cy).at(cx+1) = dist.at(cy).at(cx) + 1;
        longestlength = max(longestlength,dist.at(cy).at(cx) + 1);        
        q.push(make_pair(cy,cx+1));                
      }      
      if(is_valid_move(board,dist,cy-1,cx)){
        dist.at(cy-1).at(cx) = dist.at(cy).at(cx) + 1;
        longestlength = max(longestlength,dist.at(cy).at(cx) + 1);        
        q.push(make_pair(cy-1,cx));                
      }
      if(is_valid_move(board,dist,cy,cx-1)){
        dist.at(cy).at(cx-1) = dist.at(cy).at(cx) + 1;
        longestlength = max(longestlength,dist.at(cy).at(cx) + 1);
        q.push(make_pair(cy,cx-1));                
      }
    }
    /*
    rep(k,h){
      rep(l,w){
        cout << dist.at(k).at(l);
      }
      cout << endl;
    }
    cout << endl;
    */
    longest_of_longest = max(longest_of_longest,longestlength);
  }
  cout << longest_of_longest;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
 
class Main
{
	static class Pair
	{
		int first, second;
		public Pair(int f, int s)
		{
			first = f;
			second = s;
		}
		
		public String toString()
		{
			return first + " " + second;
		}
	}
	
	static class PairComparator implements Comparator <Pair>
	{
		public int compare(Pair p1, Pair p2)
		{
			if(p1.first < p2.first)
				return -1;
			if(p1.first > p2.first)
				return 1;
			if(p1.second < p2.second)
				return -1;
			if(p1.second > p2.second)
				return 1;
			return 0;
		}
	}
	
	static int log2(double a)
	{
		return (int)(Math.log(a) / Math.log(2));
	}
	
	static long gcd(long a, long b)
	{
		long r;
		while((r = a % b) > 0)
		{
			a = b;
			b = r;
		}
		return b;
	}
	
	static class TrieNode
	{
		TrieNode z, o;
		boolean end;
		long count;
		
		public TrieNode()
		{
			 z = null;
			 o = null;
			 count = 0;
			 end = false;
		}
		
		
	}
	
	public static void main(String[] args) throws IOException
	{
		Hashtable <Integer, Integer> v = new Hashtable <Integer, Integer> ();
		int n = in.nextInt();
		for(int i = 0; i < n; i ++)
		{
			int k = in.nextInt();
			if(!v.containsKey(k))
				v.put(k, 0);
			v.put(k, v.get(k) + 1);
		}
		Enumeration <Integer> e = v.keys();
		int ans = 0;
		while(e.hasMoreElements())
		{
			if(v.get(e.nextElement()) % 2 != 0)
				ans ++;
		}
		sop(ans);
	}
    
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	
    static FastReader in = new FastReader();
  
    public static void sop(Object o)
    {
    	System.out.print(o);
    }
}

Measured memory_bytes: 43912
#include<stdio.h>

int main(){
  int a,b,c;

  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  if(a+b==c)printf("Yes\n");
  else if(a+c==b)printf("Yes\n");
  else if(c+b==a)printf("Yes\n");
  else { printf("No\n");}
  return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val (n, h) = readLine()!!.split(' ').map(String::toLong)
    var aMax = 0L
    val bList = mutableListOf<Long>()
    (1..n).forEach {
        val (a, b) = readLine()!!.split(' ').map(String::toLong)
        aMax = Math.max(aMax, a)
        bList.add(b)
    }
    val fbList = bList.filter { it > aMax }.sortedDescending()

    var totalD = 0L
    for (i in fbList.indices) {
        totalD += fbList[i]
        if (totalD >= h) {
            println(i + 1)
            return
        }
    }
    val addAttack = Math.ceil((h - totalD).toDouble() / aMax.toDouble()).toLong()
    println(fbList.size + addAttack)
}


Measured memory_bytes: 58088
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
// const int INF=4e18+10;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}


void solve()
{
    int a, b, c;
    cin>>a>>b>>c;
    vector<int> cnt(10);
    cnt[a]++;
    cnt[b]++;
    cnt[c]++;
    for(int i=0;i<10;i++)
    {
        if(cnt[i]==2)
        {
            cout<<"Yes"<<endl;
            return;
        }
    }
    cout<<"No"<<endl;
    return;
}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int h[n];
    bool good[n];

    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
        good[i] = true;
    }
    int a, b;
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b;
        if (h[a - 1] > h[b - 1])
        {
            good[b - 1] = false;
        }
        else if (h[a - 1] < h[b - 1])
        {
            good[a - 1] = false;
        }
        else
        {
            good[a - 1] = false;
            good[b - 1] = false;
        }
    }
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        if (good[i] == true)
            res++;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4060
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var ans = "NO";

            var S = cin.ReadLine;
            var end = 0;


            for(var i = S.Length; true; i = i)
            {
                if (0 <= i - 5 && (S.Substring(i - 5, 5) == "dream" || S.Substring(i - 5, 5) == "erase"))
                {
                    i = i - 5;
                }
                else if (0 <= i - 6 && (S.Substring(i - 6, 6) == "dreamer" || S.Substring(i - 6, 6) == "eraser"))
                {
                    i = i - 6;
                }
                else if (0 <= i - 7 && (S.Substring(i - 7, 7) == "dreamer"))
                {
                    i = i - 7;
                }
                else
                {
                    end = i;
                    break;
                }
            }

            if (end == 0)
            {
                ans = "YES";
            }

            WriteLine(ans.ToString());
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.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; }
    }
}

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

int main() {

  long long N,K,R,S,P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;


  vector<char> player;
  for(long long i=0;i<N;i++){
    if(T[i] == 'r'){
      if(i >= K && player[i-(K)] == 'p'){
        player.push_back('a');
      }else{
        player.push_back('p');
      }
    }else if(T[i] == 's'){
      if(i >= K && player[i-(K)] == 'r'){
        player.push_back('a');
      }else{
        player.push_back('r');
      }
    }else if(T[i] == 'p'){
      if(i >= K && player[i-(K)] == 's'){
        player.push_back('a');
      }else{
        player.push_back('s');
      }
    }
  }

  long long score=0;
  for(int i=0;i<player.size();i++){
    if(player[i] == 'r'){
      score += R;
    }else if(player[i] == 's'){
      score += S;
    }else if(player[i] == 'p'){
      score += P;
    }
  }

  cout << endl << score << endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード

ll n,m,a,b,cnt;
ll h[100010];
bool J[100010];






int main() {
	cin >> n >> m;
	REP(i,1, n + 1) {
		cin >> h[i];
		J[i] = true;
	}
	rep(i, m) {
		cin >> a >> b;
		if (h[a] < h[b]) J[a] = false;
		else if (h[b] < h[a]) J[b] = false;
		else {
			J[a] = false;
			J[b] = false;
		}
	}
	REP(i,1,n + 1) {
		if (J[i]) cnt++;
	}
	cout << cnt << endl;



	return 0;
}



Measured memory_bytes: 4472
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
using namespace std;

int insertionSort(vector<int> &A, int &g) // N個の要素を含む0-オリジンの配列A
{
    int cnt = 0;
    int N = A.size();
    for (int i = g; i <= N - 1; ++i)
    {
        int v = A[i];
        int j = i - g;

        while (j >= 0 && A[j] > v)
        {
            A[j + g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j + g] = v;
    }
    return cnt;
}

vector<int> shellSort(vector<int> &A, int &cnt)
{
    int n = A.size();
    int g = 1;
    vector<int> G;
    while (n >= g)
    {
        G.push_back(g);
        g = (3 * g) + 1;
    }
    int m = G.size();
    reverse(G.begin(), G.end());
    for (int i = 0; i < m; i++)
    {
        cnt += insertionSort(A, G[i]);
    }
    return G;
}

int main()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
    }
    int cnt = 0;
    vector<int> G = shellSort(A, cnt);
    int m = G.size();
    cout << m << endl;
    cout << G[0];
    for (int i = 1; i < m; i++)
    {
        cout << " " << G[i];
    }
    cout << endl;
    cout << cnt << endl;
    for (int i = 0; i < n; i++)
    {
        cout << A[i] << endl;
    }
}


Measured memory_bytes: 6700
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, n)
    {
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    rep(i,n){
        cout << s[i];
    }
    cout << flush;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	int n, m, a, sum = 0;
	cin >> n  >> m;
	for (int i = 0; i < m; i++) {
		cin >> a;
		sum += a;
	}
	if (sum > n) {
		cout << -1 ;
	}
	else {
		cout << (n - sum);
	}
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e=0,f=0,ans,S;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  e = a/c;
  f = b/d;
  ans = a * b - (c * d * e * f);
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,d; cin>>n>>d;
  if(2*d+1>=n) cout<<1<<endl;
  else if(n%(2*d+1)==0) cout<<n/(2*d+1)<<endl;
  else cout<<n/(2*d+1)+1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 1e5+233;
char s[maxn];
int n,last[maxn];
int main(){
	scanf("%s",s+1);
	n = strlen(s+1);
	Rep(i,1,n){
		s[i] -= '0';
	}
	last[n] = n;
	Dep(i,n-1,1){
		last[i] = last[i+1];
		if(s[i]) last[i] = i;
	}
	Rep(i,1,n-1){
		if(s[i] && !(s[n-i])){
			puts("-1");
			return 0;
		}
	}
	if(s[1] == 0){
		puts("-1");
		return 0;
	}
	if(s[n] == 1){
		puts("-1");
		return 0;
	}
	Rep(i,1,n-1){
		if(s[i]){
			printf("%d %d\n",i,last[i+1]);
		} else{
			printf("%d %d\n",i,last[i]);
		}
	}
	return 0;
}


Measured memory_bytes: 1920
fun <T> splitReadLine(f: ((String) -> T)) = readLine()?.split(" ")?.map(f) ?: TODO()
fun main(args: Array<String>) {
    val (h, w) = splitReadLine(String::toInt)
    val maze = mutableListOf<String>()
    repeat(h) { y ->
        val f = readLine() ?: return
        maze.add(f)
    }
    val dp = Array(h) { Array(w) { -1 } }

    fun calc(c: Char, x: Int, y: Int, xx: Int, yy: Int) {
        val p = maze[yy][xx]
        if (c == '.' && p == '#') {
            if (dp[yy][xx] == -1) {
                dp[yy][xx] = dp[y][x] + 1
            } else {
                dp[yy][xx] = Math.min(dp[yy][xx], dp[y][x] + 1)
            }
        } else {
            if (dp[yy][xx] == -1) {
                dp[yy][xx] = dp[y][x]
            } else {
                dp[yy][xx] = Math.min(dp[yy][xx], dp[y][x])
            }
        }
    }
    (0).until(w).forEach { x ->
        (0).until(h).forEach { y ->
            val c = maze[y][x]
            if (dp[y][x] == -1) {
                dp[y][x] = 0
            }
            if (y + 1 < h) {
                calc(c, x, y, x, y + 1)
            }
            if (x + 1 < w) {
                calc(c, x, y, x + 1, y)
            }
        }
    }
    if (maze[0][0] == '#') {
        dp[h - 1][w - 1]++
    }
    println(dp[h - 1][w - 1].toString())
}

Measured memory_bytes: 38000
#include <iostream>

int main() {
  long long a, b, c, x, y;
  long long sum = 0;
  std::cin >> a >> b >> c >> x >> y;
  if (a + b < c * 2) {
    std::cout << a * x + b * y << "\n";
    return 0;
  } else {
    if (x < y) {
      sum += c * x * 2;
      y -= x;
      if (b < c * 2) {
        sum += b * y;
      } else {
        sum += c * y * 2;
      }
    } else {
      sum += c * y * 2;
      x -= y;
      if (a < c * 2) {
        sum += a * x;
      } else {
        sum += c * x * 2;
      }
    }
  }
  std::cout << sum << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef pair<long long int, long long int> P;

int main()
{
	long long int h, w, a, b;
	int n;
	long long int wn[10]={};
	scanf("%lld %lld %d", &h, &w, &n);
	if(n==0){
		printf("%lld\n", (h-2)*(w-2));
		for(int i=1; i<10; i++){
			printf("%d\n", 0);
		}
	}else{
		set<P> v;
		set<P> s;
		for(int i=0; i<n; i++){
			scanf("%lld %lld", &a, &b);
			s.insert(P(a, b));
			if(2<=a && a<=h-1 && 2<=b && b<=w-1) v.insert(P(a, b));
			if(2<=a-1 && a-1<=h-1 && 2<=b-1 && b-1<=w-1) v.insert(P(a-1, b-1));
			if(2<=a-1 && a-1<=h-1 && 2<=b && b<=w-1) v.insert(P(a-1, b));
			if(2<=a-1 && a-1<=h-1 && 2<=b+1 && b+1<=w-1) v.insert(P(a-1, b+1));
			if(2<=a && a<=h-1 && 2<=b-1 && b-1<=w-1) v.insert(P(a, b-1));
			if(2<=a && a<=h-1 && 2<=b+1 && b+1<=w-1) v.insert(P(a, b+1));
			if(2<=a+1 && a+1<=h-1 && 2<=b-1 && b-1<=w-1) v.insert(P(a+1, b-1));
			if(2<=a+1 && a+1<=h-1 && 2<=b && b<=w-1) v.insert(P(a+1, b));
			if(2<=a+1 && a+1<=h-1 && 2<=b+1 && b+1<=w-1) v.insert(P(a+1, b+1));
		}
		long long int m=v.size();
		wn[0]=(h-2)*(w-2)-m;
		for(auto itr=v.begin(); itr!=v.end(); itr++){
			int k=0;
			P p=*itr;
			long long int x=p.first, y=p.second;
			if(s.find(P(x-1, y-1))!=s.end()) k++;
			if(s.find(P(x-1, y))!=s.end()) k++;
			if(s.find(P(x-1, y+1))!=s.end()) k++;
			if(s.find(P(x, y-1))!=s.end()) k++;
			if(s.find(P(x, y))!=s.end()) k++;
			if(s.find(P(x, y+1))!=s.end()) k++;
			if(s.find(P(x+1, y-1))!=s.end()) k++;
			if(s.find(P(x+1, y))!=s.end()) k++;
			if(s.find(P(x+1, y+1))!=s.end()) k++;
			wn[k]++;
		}
		for(int i=0; i<10; i++){
			printf("%lld\n", wn[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 62720
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define pb push_back
#define eb emplace_back

using ld = double;
const ld EPS = 1e-8;
typedef vector<ld> vec;
typedef vector<vec> mat;

vec GaussJordan(mat A){
    int n = A.size();
    int m = A[0].size();
    for(int i = 0; i < n; i++){
        int pivot = i;
        for(int j = i; j < n; j++) {
            if(abs(A[j][i]) > abs(A[pivot][i])) pivot = j;
        }
        swap(A[i], A[pivot]);
        if(abs(A[i][i]) < EPS) return {};
        for(int j = i + 1; j < m; j++) A[i][j] /= A[i][i];
        for(int j = 0; j < n; j++) {
            if(i != j) {
                for(int k = i + 1; k < m; k++) A[j][k] -= A[j][i] * A[i][k];
            }
        }
    }
    vec x(n);
    for(int i = 0; i < n; i++) x[i] = A[i].back();
    return x;
}

int d;
vec b;

auto y = [](const vec &f, ld x){
    ld res = 0, cur = 1;
    rep(i,d+1){
        res += cur * f[i];
        cur *= x;
    }
    return res;
};

int solve(){
    mat A(d+3, vec(d+2));
    rep(i,d+3){
        ld cur = 1;
        rep(j,d+1){
            A[i][j] = cur;
            cur *= i;
        }
        A[i][d+1] = b[i];
    }
    vector<int> cnt(d+3);
    rep(i,d+3)rep(j,i){
        mat P;
        vector<pair<int,ld>> test;
        rep(k,d+3){
            if(k == i || k == j){
                test.eb(k,b[k]);
            } else {
                P.pb(A[k]);
            }
        }
        vec c = GaussJordan(P);
        rep(k,2){
            int x = test[k].first;
            ld resy = y(c, x);
            ld expy = test[k].second;
            cnt[x] += abs(expy - resy) > 1e-3;
        }
    }
    return max_element(all(cnt)) - cnt.begin();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(cin >> d && d){
        b.resize(d+3);
        rep(i,d+3) cin >> b[i];
        cout << solve() << endl;
    }
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu long long unsigned
int main()
{
    int t,a,b,x,y,z,n,mx,mn,tmp;
        int cnt=0,ans=0;
        string s="";
        vector<int>vc;
        map<int,int>mp;
        map<char,int>mc;
        cin>>s;
        n=s.size();
        for(int j=0;j<n;j++){
            ans+=(s[j]-'0');
        }
        if(ans%9==0) puts("Yes");
        else puts("No");


    return 0;
}




Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int p[100];
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    int count=0;
    for(int i=1; i<n-1; i++){
        if((p[i-1]<p[i]&&p[i]<p[i+1]) || (p[i-1]>p[i]&&p[i]>p[i+1])) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
// 22
#include <bits/stdc++.h>
using namespace std;
#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define endl '\n'
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) \
  M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) \
  for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
// 4
template <class A, class B>
ostream &operator<<(ostream &o, const pair<A, B> &p) {
  return o << "(" << p.fi << ", " << p.se << ")";
}
// 5
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  rep(i, len(v)) o << setw(7) << left << v[i];
  return o << endc << endl << coutc;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &o, const map<A, B> &m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 7
template <class T, class... Ts>
void debug(const T &e, const Ts &... r) {
#ifdef DEBUG
  cerr << coutc << e;
  ((cerr << " " << r), ..., (cerr << endc << endl));
#endif
}
// 3
void _main(int tc) {
  int s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
ll M = 998244353;

int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n; cin>>n;
	vector < pair <ll,ll> > v;
	for(int i=0;i<n;i++)
	{
		ll p,q; cin>>p>>q;
		v.pb(mp(p,q));
	}
	sort(v.begin(),v.end());
	ll dp[n+1]={0};
	dp[n] = 1;
	stack < pair <ll,int> > s;
	s.push(mp(1e12,n));
	for(int i=n-1;i>=0;i--)
	{
		while( !s.empty() )
		{
			ll a=s.top().first;
			
			if( v[i].first + v[i].second <= a ) break;
			s.pop();
		}
		ll b=s.top().second;
		dp[i] = (dp[b] + dp[i+1])%M;
		s.push( mp( v[i].first, i ) );
		
	}
	//for(auto it:dp) cout<<it<<' '; cout<<endl;
	cout<<dp[0]%M;
	return 0;
}


Measured memory_bytes: 6636
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(s[k-1])


Measured memory_bytes: 9192