akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

map<ll,ll> pfmp;
vector<ll> pfv(0);

void PF(ll N){
  ll n=N;
  if(n%2==0) pfv.push_back(2);
  while(n%2==0){
    n/=2;
    pfmp[2]++;
  }
  if(n==1) return;
  for(ll i=3;i<=sqrt(N);i+=2){
    if(n%i==0) pfv.push_back(i);
    while(n%i==0){
      n/=i;
      pfmp[i]++;
    }
  }
  if(n!=1){
    pfv.push_back(n);
    pfmp[n]++;
  } 
}

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

int main(){
  ll A,B;
  cin >> A >> B;
  PF(gcd(A,B));
  cout << pfv.size()+1 << endl;
  
}

Measured memory_bytes: 256
//                                                              ۡمِ ٱللهِ ٱلرَّحۡمَـٰنِ ٱلرَّحِيمِ‎
//created by --------> Aslan Nesipbay;

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef stringstream SS;
typedef pair< ll, ll > pll;

const ll N = 10e5 + 5;
const ll NN = 105;
const double pi = 3.14159;
const ll MAX = 2e5 + 123;
const ll MOD = 1e9 + 7;
const ll INF = 1000000000000000000;
const ll pw = 31;

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

void hajime()
{
    ll n, a[105], sum = 0;
    cin >> n;
    for (ll i = 1; i <= n; i ++)
    {
        cin >> a[i];
        sum += a[i];
    }
    if (sum % 10)
    {
        cout << sum;
        return;
    }
    sort (a + 1, a + 1 + n);
    for (ll i = 1; i <= n; i ++)
    {
        if (a[i] % 10 != 0)
        {
            cout << sum - a[i];
            return;
        }
    }
    cout << 0;
}
int main()
{
    ll miyagi = 1;
    //scanf ("%I64d", &miyagi);
    speed();
    //cin >> miyagi;
    while( miyagi --) hajime();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=5e3+5,M=5e3+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
char s[N];
int sum[N],r[N],f[N][N],m,n;
int main(){
	read(n,m);
	scanf("%s",s+1);
	rep(i,1,n)sum[i]=(s[i]=='1')+sum[i-1];
	rep(i,1,n)r[i]=i;
	rep(i,1,m){
		int x,y;read(x,y);
		gmax(r[x],y);
	}rep(i,1,n)gmax(r[i],r[i-1]);
	f[0][0]=1;
	rep(i,0,n-1){
		rep(j,0,sum[r[i]])if(f[i][j]){
			if(sum[r[i+1]]>j)(f[i+1][j+1]+=f[i][j])%=mod;
			if(sum[r[i+1]]-j<r[i+1]-i)(f[i+1][j]+=f[i][j])%=mod;
		}
	}cout<<f[n][sum[n]]<<endl;
}

Measured memory_bytes: 58112
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int gcd(int a, int b) {
	//cout << a << " " << b << endl;
	if (b > a) return gcd(b, a);
	else if (b == 0) return a;
	else return gcd(b, a % b);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int T; cin >> T;
	rep(i, T) {
		int A, B, C, D;
		cin >> A >> B >> C >> D;
		if (B > A) {
			cout << "No" << endl;
		}
		else if (B > D) {
			cout << "No" << endl;
		}
		else if (C >= B) {
			cout << "Yes" << endl;
		}
		else {
			int g = gcd(B, D);
			//cout << g << endl;
			int X = B - g + A % g;
			if (X > C) {
				cout << "No" << endl;
			}
			else {
				cout << "Yes" << endl;
			}
		}


	}
 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a,b,s;

int main()
{
    cin >> a >> b;
    s = (a+b)/2;
    if((a+b)%2==1) s++; 
    cout << s;
    
//    if((a+b)%2==0)
//        cout << s;
//    else
//        cout << s+1;
    return 0;
}


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

int main() {
  ll L, R;
  cin >> L >> R;

  ll minv = 2019;
  for (ll i = L; i < min(L+2019, R); i++) {
    for (ll j = i+1; j <= min(L+2019, R); j++) {
      minv = min(minv, (i*j)%2019);
      if (minv == 0) {
        cout << 0 << endl;
        return 0;
      }
    }
  }

  cout << minv << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int n, k;
        n = cin.nextInt();
        k = cin.nextInt();

        int product = k;
        int count = 1;

        while(product <= n) {
            count++;
            product *= k;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 22484
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+n)

int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	a += b;
	if (a >= c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
N,M = gets.split(' ').map(&:to_i)
ac = Array.new(N,0)
pen = Array.new(N,0)
# p pen
sum_pen = 0
M.times do
  q, res = gets.split(' ')
  if res == 'WA'
    pen[q.to_i-1] += 1
  else # ACのとき
    if ac[q.to_i-1] == 0
      ac[q.to_i-1] = 1
      sum_pen += pen[q.to_i-1]
    end
  end
end
# p ac
# p pen
print ac.inject(:+).to_s + ' ' + sum_pen.to_s

Measured memory_bytes: 3324
#include <stdio.h>

int main(void) {
    double w, h;
    int x, y;
    scanf("%lf%lf%d%d", &w, &h, &x, &y);
    if(2*x == w && 2*y == h) {
        printf("%f %d\n", w*h/2, 1);
    } else {
        printf("%f %d\n", w*h/2, 0);
    }
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Y;
  cin >> N >> Y;
  bool ok = false;
  for(int a = 0; a <= N; a++){
    for(int b = 0; b <= N; b++){
      if(10000*a+5000*b+1000*(N-a-b) == Y && N-a-b >= 0){
        cout << a << " " << b << " " << N-a-b << endl;
        ok = true;
        break;
      }
    }
    if(ok) break;
  }
  if(!ok) cout << -1 << " " << -1 << " " << -1 << endl; 
  return 0;
}


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

#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)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    ll K; cin >> K;
    ll num = 7 % K;
    REP(i,K+2){
        if (num == 0){
            cout << i + 1 << endl;
            return 0;
        }
        num = (10 * num + 7) % K;

    }
    cout << -1 << endl; 
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String num = scan.nextLine();
		String str = scan.nextLine();
		String str_cha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

		int number = Integer.parseInt(num);
		for(int i = 0; i < str.length(); i++) {
			for(int j = 0; j < str_cha.length(); j++) {
				if(str.charAt(i) == str_cha.charAt(j)) {
					System.out.print(str_cha.charAt((j + number) % 26));
				}
			}
		}
		System.out.print("\n");
	}

}


Measured memory_bytes: 24300
#include<bits/stdc++.h>
using namespace std;
 
const int N = 2e5 + 5;
typedef long long ll;
 
int n;
ll a[N], f[N], sum;
 
int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) {
		cin>>a[i];
		if(i&1) sum += a[i];
		if(i == 1) continue;
		if(i&1) f[i] = max(f[i - 2] + a[i], f[i - 1]);
		else f[i] = max(f[i - 2] + a[i], sum);
	}
	cout<<f[n]<<endl;
}

Measured memory_bytes: 6752
package main

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

func main() {
	N := nextInt()

	facts := make([]int, N+1)
	counts := make([]int, N+1)
	for i := 1; i <= N; i++ {
		facts[i] = i
	}
	for i := 1; i <= N; i++ {
		if facts[i] == 1 {
			continue
		}
		// debug(i, facts)
		// debug(i, counts)
		f := facts[i]
		for j := i; j <= N; j += i {
			// debug(facts[j], "/", f)
			counts[f]++
			facts[j] = facts[j] / f
		}
	}
	// debug(facts)
	// debug(counts)
	ans := mint(1)
	for i := 2; i <= N; i++ {
		if counts[i] == 0 {
			continue
		}
		ans = ans.mul(mint(counts[i] + 1))
	}

	fmt.Println(ans)
}

type mint int64

var mod = mint(1e9 + 7)

// add は a + bを返します
func (a mint) add(b mint) mint {
	return (a + b) % mod
}

// sub は a - bを返します
func (a mint) sub(b mint) mint {
	return (a - b + mod) % mod
}

// mul は a * bを返します
func (a mint) mul(b mint) mint {
	return (a * (b % mod)) % mod
}

// div は a/bを返します
func (a mint) div(b mint) mint {
	return a.mul(b.inv())
}

// inv は aの逆元を返します
func (a mint) inv() mint {
	// 拡張ユークリッドの互除法
	b := mod
	u := mint(1)
	v := mint(0)
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	return (u + mod) % mod
}

// pow は a ^ bを返します
func (a mint) pow(b mint) mint {
	ans := mint(1)

	for b != 0 {
		if b&1 == 1 {
			ans = ans.mul(a)
		}
		a = a.mul(a)
		b = b >> 1
	}
	return ans
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

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


Measured memory_bytes: 1816
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <vector>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define in insert
#define er erase
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int) x.size()
using namespace std;
typedef vector <int> vi;
typedef vector <vector<int>> vii;
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
typedef long double ld;

const long double PI=3.141592653589793238462643383279502884;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
    fast;
    ll a,b;
    cin>>a>>b;
    if (b>2){
    cout<<(b-2)/(a-1)+1;
    } else {
        if (b==1){
            cout<<0;
        } else {
            cout<<1;
        }
    }
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define max_n 1000000

using namespace std;

void solve()
{
	ll n,k;
	cin>>n>>k;
	set<ll> s;
	for (int i = 0; i < n; ++i)
	{
		s.insert(i+1);
	}
	for (int i = 0; i < n; ++i)
	{
		ll d;
		cin>>d;
		for (int j = 0; j < d; ++j)
		{
			ll x;
			cin>>x;
			if(s.find(x)!=s.end())
			{
				s.erase(x);
			}
		}
	}
	cout<<s.size()<<endl;
}

int32_t main() 
{
	IOS	
	ll T=1;
	// cin>>T;
	for(ll i=1;i<=T;++i)
	{		
		// cout<<"Case #"<<i<<": ";
    	solve();
	}
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <sstream>
#include<ctime>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define mii map<int,int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rep(i,l,r) for(int i=l;i<r;i++) 
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mod 998244353 
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define INF 0x3f3f3f3f
ll MOD(ll a, ll b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;      
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%p;
        y = y>>1; 
        x = (x*x)%p;  
    }
    return res;
}
ll logg(ll a)
{
    ll x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
 
}
int main()
{
    fastio;
    int n;
    cin>>n;
    string A;
    cin>>A;
    string B;
    B.pb(A[0]);
    rep(i,1,n)
    {
        if(B[B.size()-1]==A[i])
            continue;
        else
            B.pb(A[i]);
    }
    cout<<B.size();
}

Measured memory_bytes: 592
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	double r,g;
	cin>>r>>g;
	cout<<2*g-r<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(),vecto.end()
typedef long long ll;

int main(){
    int n,k;
    int count = 0;
    cin >> n >> k;
    vector<int> vec(n);
    rep(i, n)
    {
        cin >> vec[i];
        if(vec[i]>=k){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 640
#include <iostream> 
using namespace std;
 
int main(){
	string s;
	cin >> s;
	int foundC = false;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'C'){
			foundC = true;
		}else if(s[i] == 'F' && foundC){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
L = LIST()
L.sort(reverse=True)

if L[0] < sum(L[1:]):
    print('Yes')
else:
    print('No')
 

Measured memory_bytes: 5540
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int data[10];
  for(int i=0;i<10;i++){
    scanf("%d",&data[i]);
  }
  sort(data,data+10);
  printf("%d\n",data[9]);
  printf("%d\n",data[8]);
  printf("%d\n",data[7]);
  return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	int T,A;
	ll N,X=1LL,Y=1LL;
	cin>>N;

	REP(i,N){
		scanf("%d %d",&T,&A);
		ll n=max(X/T+(X%T!=0),Y/A+(Y%A!=0));
		X=n*T;
		Y=n*A;
	}
	print(X+Y);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

ll mod_pow(ll a, ll n) {
	if(n == 0) return 1;
	ll res = mod_pow(a, n / 2);
	if(n % 2 == 0) return res * res % mod;
	else return a * res % mod * res % mod;
}

ll invf(ll a) {
	return mod_pow(a, mod - 2);
}

ll N, M, K;

void solve() {
	cin >> N >> M >> K;
	ll c = 1, d = 1;
	for(ll i = 0; i < K - 2; i++) {
		MUL(d, M * N - 2 - i);
		MUL(c, i + 1);
	}
	ll res = d * invf(c) % mod;
	ll tmp = 0;
	ADD(tmp, N * N % mod * (M + 1) % mod * M % mod * (M - 1) % mod * invf(6) % mod);
	ADD(tmp, M * M % mod * (N + 1) % mod * N % mod * (N - 1) % mod * invf(6) % mod);
	cout << res * tmp % mod << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 384
#include <stdio.h>

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


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	unordered_map<int, bool> m;
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		m[a] = !m[a];
		if (m[a] == true) c++;
		else c--;
	}
	cout << c << endl;
	return 0;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n;cin>>n;
    long double result = 0;

    REP(i,n){
        long double a;
        string s;
        cin>>a>>s;
        if(s == "JPY"){
            result += a;
        }
        else{
            result += a*380000;
        }
    }
    cout<<result<<endl;
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int N = n % 10;
  if(N == 2 || N == 4 || N == 5 || N == 7 || N == 9) cout << "hon" << endl;
  else if(N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
  else cout << "bon" << endl;
  return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    auto r = make_vec<int>(m, 0);
    rep(i, n) r[a[i] % m].push_back(a[i]);
    vector<pair<int, int>> cnt(m);
    rep(i, m) {
        cnt[i].first = r[i].size();
        map<int, int> mp;
        rep(j, r[i].size()) mp[r[i][j]]++;
        for (auto&& p : mp) cnt[i].second += p.second / 2;
    }
    // rep(i, m) cout << i << " " << cnt[i].first << " " << cnt[i].second << endl;

    int ans = 0;
    ans += cnt[0].first / 2;
    for (int i = 1; i <= m-i; ++i) {
        int j = m-i;        
        if (i == j) {
            ans += cnt[i].first / 2;
        } else {
            int k = min(cnt[i].first, cnt[j].first);
            ans += k;
            cnt[i].first -= k;
            cnt[j].first -= k;
            ans += min(cnt[i].first, cnt[i].second * 2) / 2;
            ans += min(cnt[j].first, cnt[j].second * 2) / 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 9592
n = gets.strip.to_i
s = gets.strip.split("")

count = s.count("R") * s.count("G") * s.count("B")

(0...n).each do |i|
  ((i+1)...n).each do |j|
    k = j * 2 - i
    if k < n && i < j && j < k && s[i] != s[j] && s[i] != s[k] && s[j] != s[k]
      count -= 1
    end
  end
end
puts count


Measured memory_bytes: 14352
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
	s=input()
	len_s=len(s)
	T=[0]*(len_s+1)
	T[-1],T[-2]=0,int(s[-1])
	mod=2019
	for i in range(len_s-2,-1,-1):
		T[i]=(T[i+1]+int(s[i])*pow(10,len_s-i-1,mod))%mod
	tc=list(Counter(T).values())
	ans=0
	for tcc in tc:
		ans+=tcc*(tcc-1)//2
	print(ans)

if __name__=='__main__':
    main()

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

using namespace  std;

int main(void)
{
    int N;
    cin >> N;
    unsigned long long ans = 0;

    for(int i = 1; i <= N; i++){
        //cout << ((unsigned long long)N / i) * ((1+N/i) / 2) * i << endl;
        ans += (unsigned long long)(N / i) * (1+N/i) / 2 * i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3552
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j,r,c,k=0,l=0,row[200]={0},colomn[200]={0},flag;
scanf("%d %d",&r,&c);
char a[100][100];
for(i=0;i<r;i++){scanf("%s",a[i]);}
for(i=0;i<r;i++){for(j=0;j<c;j++){if(a[i][j]==35){break;}}if(j==c){row[i]=1;k++;}}
for(j=0;j<c;j++){for(i=0;i<r;i++){if(a[i][j]==35){break;}}if(i==r){colomn[j]=1;l++;}}
for(i=0;i<r;i++){for(j=0;j<c;j++){if(row[i]==0&&colomn[j]==0){printf("%c",a[i][j]);flag=1;}}if(flag==1){printf("\n");flag=0;}}
return 0;
}


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

int main() {
	int a, b;

	cin >> a >> b;

	if (a < b) {
		cout << "a < b" << endl;
	}
	else if (a > b) {
		cout << "a > b" << endl;
	}
	else if (a == b) {
		cout << "a == b" << endl;
	}

	return 0;
}

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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

string s, t;
vector<vector<pair<int, pair<int, int> > > > dp(3000, vector<pair<int, pair<int, int> > >(3000, {-1, {0, 0}}));

// {length, {first i, first j} }
pair<int, pair<int, int> > ans(int i, int j) {
    if (i >= (int)s.length() || j >= (int)t.length()) {
        return {0, {i, j}};
    } else if (dp[i][j].first != -1) {
        return dp[i][j];
    }
    if (s[i] == t[j]) {
        dp[i][j] = ans(i + 1, j + 1);
        dp[i][j].first++;
        dp[i][j].second = {i + 1, j + 1};
        return dp[i][j];
    }
    auto temp1 = ans(i, j + 1);
    auto temp2 = ans(i + 1, j);
    if (temp1.first > temp2.first) {
        dp[i][j] = temp1;
        dp[i][j].second = {i, j + 1};
        return dp[i][j];
    } else {
        dp[i][j] = temp2;
        dp[i][j].second = {i + 1, j};
        return dp[i][j];
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s >> t;
    int i = 0, j = 0;

    while (i < (int)s.length() && j < (int)t.length()) {
        if (s[i] == t[j]) {
            cout << s[i];
            i++;
            j++;
        } else {
            auto temp = ans(i, j).second;
            i = temp.first;
            j = temp.second;
        }
    }

    return 0;
}

Measured memory_bytes: 106752
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX_N = 200005;

typedef long long ll;

int n,h[MAX_N],a[MAX_N],pos[MAX_N];
ll dp[MAX_N],tree[4*MAX_N];

void set(int i, int l, int r, int si, ll v)
{
	if (l==r)
	{
		tree[i]=v;
		return;
	}
	if ((l+r)/2>=si)
		set(2*i,l,(l+r)/2,si,v);
	else
		set(2*i+1,(l+r)/2+1,r,si,v);
	tree[i]=max(tree[2*i],tree[2*i+1]);
}
void set(int i, ll v) { set(1,1,n,i,v); }

ll get(int i, int l, int r, int sl)
{
	if (r<sl)
		return 0;
	if (l>=sl)
		return tree[i];
	return max(get(2*i,l,(l+r)/2,sl),get(2*i+1,(l+r)/2+1,r,sl));
}
ll get(int l) { return get(1,1,n,l); }

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
	{
		scanf("%d",h+i);
		pos[h[i]]=i;
	}
	for (int i=1; i<=n; i++)
		scanf("%d",a+i);
	ll ans=0;
	for (int x=n; x>=1; x--)
	{
		int i=pos[x];
		dp[i]=a[i]+get(i+1);
		set(i,dp[i]);
		ans=max(ans,dp[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


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

int N;

int main(){
  cin >> N;
  int a = 1;
  int cnt = 0;
  int cp, cntcp;
  
  for(int i = 1; i <= N; i++, cnt=0){
    cp = i;
    while(true){
     if (cp % 2  == 0) cp = cp/2;
     else break;
     cnt++;
    }
    cntcp < cnt ? a = i, cntcp = cnt :0;
  }
  
  cout << a << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    const int mod = 1000000007;

    static void Main() {
#if DEBUG
        var exStdIn = new System.IO.StreamReader("./../../TestStdin.txt");
        Console.SetIn(exStdIn);
#endif
        var ints = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        var N = ints[0];
        var M = ints[1];
        var X = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        Array.Sort(X);
        var D = new int[X.Length - 1];
        for (int i = 0; i < D.Length; i++) {
            D[i] = Math.Abs(X[i + 1] - X[i]);
        }

        Array.Sort(D);

        if (M <= N) {
            Console.WriteLine(0);
            return;
        } else if (N == 1) {
            var total = 0;
            foreach (var v in D) {
                total += v;
            }

            Console.WriteLine(total);
            return;
        }

        var ans = 0;
        for (int i = 0; i < D.Length - N + 1; i++) {
            ans += D[i];
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 17504
package main

import "fmt"

func main() {
	var n, m, q int
	fmt.Scan(&n, &m, &q)
	ar := make([][]int, n+1)
	for i := range ar {
		ar[i] = make([]int, n+1)
	}
	for i := 0; i < m; i++ {
		var l, r int
		fmt.Scan(&l, &r)
		for j := 0; j <= l; j++ {
			ar[j][r]++
		}
	}
	for i := 0; i < q; i++ {
		var l, r int
		fmt.Scan(&l, &r)
		sum := 0
		for j := l; j <= r; j++ {
			sum += ar[l][j]
		}
		fmt.Println(sum)
	}
}


Measured memory_bytes: 8204
import numpy as np
import copy
from operator import itemgetter

n,m=map(int,input().split())
l=[0]*m
for i in range(m):
    p,y=map(int,input().split())
    l[i]=[p*10**10+y,i,0]#p,y,index,code
buf=sorted(l,key=lambda x:x[0])
id=10**10
counter=1
#print(buf)
for i in range(m):
    #print(id)
    if id!=buf[i][0]//(10**10):
        id=buf[i][0]//(10**10)
        counter=1
    else:
        counter+=1
    buf[i][2]=id*10**6+counter
l=sorted(l,key=lambda x:x[1])
for i in range(m):
    print(str(0)*(12-len(str(l[i][2])))+str(l[i][2]))

Measured memory_bytes: 36188
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int a[3002][3002];
int dp[3003][3002][4];

int32_t main(){
	fastio();
	int r,c,k;
	cin >> r >> c >> k;

	for(int i = 1; i <= k; i++){
		int x,y,c;
		cin >> x >> y >> c;
		a[x][y] = c;
	}
	for(int i = 1; i <= r; i++){
		for(int j = 1; j <= c; j++){
			for(int k = 0; k <= 3; k++){
				dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k]);
				dp[i][j][1] = max(dp[i][j][1] , a[i][j] + dp[i - 1][j][k]);
			}
			dp[i][j][0] = max(dp[i][j][0],dp[i][j - 1][0]);
			for(int k = 1; k <= 3; k++){
				dp[i][j][k] = max({dp[i][j][k], a[i][j] + dp[i][j - 1][k - 1],dp[i][j - 1][k]});
			}
		}
	}
	cout << max({dp[r][c][0],dp[r][c][1],dp[r][c][2],dp[r][c][3]});
}

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

//const int INF = 1001001001;
//const ll INF18 = 1000000000000000000;
const ll INF15 = 1000000000000000;

int main() {
	int d, t, s;
	cin >> d >> t >> s;

	string ans = "Yes";
	if (d > t*s) ans = "No";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S;
const ll MOD = (1e+9) + 7;
const ll INF = 1000;//1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    vector<string> c(3);
    rep(i,3) cin>>c[i];
    vec a(3);
    rep(i,3) a[i] = c[i][0] - 'a';
    rep(i,3) cout<<char(65 + a[i]);
    cout<<endl;
}

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

string a, b, c;
int m = 6000;
bool ab[20000], ac[20000], bc[20000];

int main()
{
	cin >> a >> b >> c;

	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < b.size(); j++)
			if (!(a[i] == '?' || b[j] == '?' || a[i] == b[j]))
				ab[i - j + 10000] = true;

	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < c.size(); j++)
			if (!(a[i] == '?' || c[j] == '?' || a[i] == c[j]))
				ac[i - j + 10000] = true;

	for (int i = 0; i < b.size(); i++)
		for (int j = 0; j < c.size(); j++)
			if (!(b[i] == '?' || c[j] == '?' || b[i] == c[j]))
				bc[i - j + 10000] = true;

	int A = a.size();
	int B = b.size();
	int C = c.size();

	for (int i = -4000; i <= 4000; i++) {
		for (int j = -4000; j <= 4000; j++) {
			if (!ab[i + 10000] && !ac[j + 10000] && !bc[j - i + 10000]) {
				int L = min(0, min(i, j));
				int R = max(A, max(B + i, C + j));
				m = min(m, R - L);
			}
		}
	}

	cout << m << endl;
}


Measured memory_bytes: 384
#include<iostream>
#define int long long
using namespace std;
int n,W;
int wt[101];
int val[101];
int dp[101][100005];

int knapsack1(int i,int W){

	//Base Case
	if(i==0 || W==0)
	{
		dp[i][W]=0;
	}

	if(dp[i][W]!=-1)
		return dp[i][W];

	//Recursive Case
	if(wt[i-1]>W)
		return dp[i][W] = knapsack1(i-1,W);

	else
	{
		int op1 = val[i-1] + knapsack1(i-1,W-wt[i-1]);
		int op2 = knapsack1(i-1,W);
		return dp[i][W] = max(op1,op2);
	}

}


int32_t main(){

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
	cin>>n>>W;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=W;j++)
			dp[i][j]=-1;

	for(int i=0;i<n;i++){
		cin>>wt[i]>>val[i];
	}
	
	cout<<knapsack1(n,W)<<endl;

}

Measured memory_bytes: 82516
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String[] tmpArray = br.readLine().split(" ");

			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);
			
			if(a == 0 && b == 0){
				break;
			}
			
			int n = Integer.parseInt(br.readLine());
			
			int[][] pattern = new int[b + 1][a + 1];
			
			boolean[][] uc = new boolean[b + 1][a + 1];
			
			for(int i = 0; i < n; i++){
				tmpArray = br.readLine().split(" ");

				int tmp1 = Integer.parseInt(tmpArray[0]);
				int tmp2 = Integer.parseInt(tmpArray[1]);
				
				uc[tmp2][tmp1] = true;
			}
			
			for(int i = 1; i <= b ; i++){
				for(int j = 1; j <= a; j++){
					if(i == 1 && j == 1){
						pattern[i][j] = 1;
					}
					else if(uc[i][j] == false){
						pattern[i][j] = pattern[i-1][j] + pattern[i][j-1];
					}
				}
			}
			
			System.out.println(pattern[b][a]);
			
		}
	}

}

Measured memory_bytes: 24068
class Node:
    def __init__(self, num, parent, children):
        self.id = num
        self.parent = -1
        self.children = children
        self.depth = 0
        
    def show_info(self):
        print('node {0}: '.format(self.id), end = '')
        print('parent = {0}, '.format(self.parent), end = '')
        print('depth = {0}, '.format(self.depth), end = '')
        if self.children and self.parent != -1:
            print('internal node, ', end = '')
        elif self.parent != -1:
            print('leaf, ', end = '')
        else:
            print('root, ', end = '')
        print(self.children)


def set_node(i_s):
    i_l = list(map(int, i_s.split()))
    num = i_l[0]
    children = i_l[2:]
    node = Node(num, -1, children)
    T[num] = node
    for n in children:
        T[-1] -= n

def set_pd(n_i, parent, depth):
    node = T[n_i]
    node.parent = parent
    node.depth = depth
    for n in node.children:
        set_pd(n, n_i, depth + 1)


import sys

n = int(sys.stdin.readline())

T = [None] * n

T.append(int(n * (n - 1) / 2))

for x in sys.stdin.readlines():
    set_node(x)

set_pd(T[-1], -1, 0)

for n in T[:-1]:
    n.show_info()

Measured memory_bytes: 55584
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{

	int n, temp;
	cin >> n;
	pair<int, int> max = {n,0}; //i,j
	for (int i = n; i >= 1; i--) {
		for (int j = 6; j >= 1; j--) {
			temp = pow(2, j);
			if(i%temp == 0 && j>max.second){
				max.first = i;
				max.second = j;
			}
		}
	}

	cout << max.first << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	// "fmt"
	"sort"
)

type plane struct {
	x int
	y int
	dx int
	dy int
}

type pair struct {
	x int
	y int
}

type mt struct {
	x int
	y int
	dc int
}

func min(a,b int) int{
	if(a>b){
		return b
	}
	return a
}

func chg(a []plane, dx,dy int){
	n:=len(a)
	for i:=0;i<n;i++{
		a[i].dx+=dx
		a[i].dy+=dy
	}
}

func getL(a []int, x int) int {
	if len(a)==0 || a[0]>x {
		return 1000000000
	}

	l,r := 0,len(a)
	for r-l>1{
		m:=(l+r)/2
		if a[m]>x{
			r=m
		} else {
			l=m
		}
	}
	return x-a[l]
}

func solve(a []plane, dx,dy int) int {
	chg(a,dx,dy)
	defer chg(a,-dx,-dy)
	mm := make(map[mt][]int)
	aa := make([]pair,0)
	for _,v := range(a){
		if v.dx == 0 {
			if v.dy == 0{
				aa=append(aa,pair{v.x,v.y})
			} else if v.dy<0{
				mm[mt{v.dx,v.dy,v.x}]=append(mm[mt{v.dx,v.dy,v.x}],-v.y)
			} else {
				mm[mt{v.dx,v.dy,v.x}]=append(mm[mt{v.dx,v.dy,v.x}],v.y)
			}
		} else if v.dy==0 {
			if v.dx<0 {
				mm[mt{v.dx,v.dy,v.y}]=append(mm[mt{v.dx,v.dy,v.y}],-v.x)
			} else {
				mm[mt{v.dx,v.dy,v.y}]=append(mm[mt{v.dx,v.dy,v.y}],v.x)
			}
		} else if v.dx == v.dy {
			if v.dx<0{
				mm[mt{v.dx,v.dy,v.y-v.x}]=append(mm[mt{v.dx,v.dy,v.y-v.x}],-v.x)
			} else {
				mm[mt{v.dx,v.dy,v.y-v.x}]=append(mm[mt{v.dx,v.dy,v.y-v.x}],v.x)
			}
		} else {
			if v.dx >0 {
				mm[mt{v.dx,v.dy,v.y+v.x}]=append(mm[mt{v.dx,v.dy,v.y+v.x}],v.x)
			} else {
				mm[mt{v.dx,v.dy,v.y+v.x}]=append(mm[mt{v.dx,v.dy,v.y+v.x}],-v.x)
			}
		}
	}


	// fmt.Println(mm)
	ans:=1000000000
	for id := range(mm) {
		sort.Ints(mm[id])
	}

	for _, v := range(aa){
		var bb [] int

		bb=mm[mt{0,1,v.x}]
		ans=min(ans,getL(bb,v.y))

		bb=mm[mt{0,-1,v.x}]
		ans=min(ans,getL(bb,-v.y))

		bb=mm[mt{1,0,v.y}]
		ans=min(ans,getL(bb,v.x))

		bb=mm[mt{-1,0,v.y}]
		ans=min(ans,getL(bb,-v.x))

		bb=mm[mt{0,2,v.x}]
		ans=min(ans,getL(bb,v.y)/2)

		bb=mm[mt{0,-2,v.x}]
		ans=min(ans,getL(bb,-v.y)/2)

		bb=mm[mt{2,0,v.y}]
		ans=min(ans,getL(bb,v.x)/2)

		bb=mm[mt{-2,0,v.y}]
		ans=min(ans,getL(bb,-v.x)/2)


		bb=mm[mt{-1,-1,v.y-v.x}]
		ans=min(ans,getL(bb,-v.x))

		bb=mm[mt{1,1,v.y-v.x}]
		ans=min(ans,getL(bb,v.x))

		bb=mm[mt{1,-1,v.y+v.x}]
		ans=min(ans,getL(bb,v.x))

		bb=mm[mt{-1,1,v.y+v.x}]
		ans=min(ans,getL(bb,-v.x))
	}

	return ans
}

// Credits - github.com/EndlessCheng/codeforces-go
func solve2(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	n:=0
	Fscan(in,&n)
	a:=make([]plane,n)

	for i:=0;i<n;i++{
		var x,y int
		var c string
		Fscan(in,&x,&y,&c)
		// Fprintln(out,x,y,c)
		x*=10
		y*=10

		if c=="U"{
			a[i]=plane{x,y,0,1}
		}

		if c=="D"{
			a[i]=plane{x,y,0,-1}
		}

		if c=="R"{
			a[i]=plane{x,y,1,0}
		}

		if c=="L"{
			a[i]=plane{x,y,-1,0}
		}
	}

	ans:=1000000000
	// Fprintln(out,a)

	ans=min(ans,solve(a,0,1))
	ans=min(ans,solve(a,0,-1))
	ans=min(ans,solve(a,1,0))
	ans=min(ans,solve(a,-1,0))

	if 2*ans >= 1000000000 {
		Fprintln(out,"SAFE")
	} else {
		Fprintln(out,ans)
	}
}

func main() { solve2(os.Stdin, os.Stdout) }



Measured memory_bytes: 79628
#include<cstdio>
#include<set> 
using namespace std;
int main()
{
	int N,t;
	scanf("%d",&N);
	set<int> a;
	for(int i=0;i<N;i++)
	{
		scanf("%d",&t);
		a.insert(t);
	}
	if(N==a.size())	printf("YES\n");
	else	printf("NO\n");
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
//　35min
int main(void){
  int n, m;
  char a[51][51];
  char b[51][51];
  int check = 1;

  scanf("%d%d", &n, &m);
  
  for(int i = 0; i < n; i++){
    scanf("%s", a[i]);
  }

  for(int i = 0; i < m; i++){
    scanf("%s", b[i]);
  }

  //縦軸にずらす
  for(int i = 0; i < n - m + 1; i++){
    //横軸にずらす
    for(int j = 0; j < n - m + 1; j++){
      for(int k = 0; k < m; k++){
	for(int l = 0; l < m; l++){
	  if(a[i + k][j + l] == b[k][l]){
	    if(check == 1 && k == m - 1 && l == m - 1){
	      printf("Yes\n");
	      return 0;
	    }
	  }else{
	    check = 0;
	    break;
	  }

	}
      }
      check = 1;
    }
  }

  printf("No\n");

  return 0;
}

Measured memory_bytes: 128
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

pre = [[] for i in range(k)]

for i in range(n):
    #print(i, pre[i%k], t[i])
    pre[i%k].append(t[i])
#print(pre)

def score(h):
    c_r = 0
    c_s = 0
    c_p = 0
    num = "".join(h)
    count = 1
    result = ''

    # 配列全体のループ
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
                count = count + 1
            else:
                result = result + str(num[i]) + str(count)
                ko = num[i]
                wa = count 
                if wa%2 == 0:
                    if ko == "r":
                        c_r += wa//2
                    elif ko == "s":
                        c_s += wa//2
                    else:
                        c_p += wa//2
                else:
                    if ko == "r":
                        c_r += 1 + (wa-1)//2
                    elif ko == "s":
                        c_s += 1 + (wa-1)//2
                    else:
                        c_p += 1 + (wa-1)//2
                count = 1
        except:
            # 最後の文字セットがOutOfRangeになるので結果に出力
            result = result + str(num[i]) + str(count)
            ko = num[i]
            wa = count 
            if wa%2 == 0:
                if ko == "r":
                    c_r += wa//2
                elif ko == "s":
                    c_s += wa//2
                else:
                    c_p += wa//2
            else:
                if ko == "r":
                    c_r += 1 + (wa-1)//2
                elif ko == "s":
                    c_s += 1 + (wa-1)//2
                else:
                    c_p += 1 + (wa-1)//2

    #print(result,c_r * p + c_s * r + c_p * s )
    return c_r * p + c_s * r + c_p * s

ans = 0
for i in range(len(pre)):
    ans += score(pre[i])
print(ans)

Measured memory_bytes: 13464
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int k,a,b;
  cin >> k >> a >> b;
  if(a%k == 0){
    printf("OK\n");
    return 0;
  }
  if((k - a%k) + a <= b) printf("OK\n");
  else printf("NG\n");
  return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

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

Measured memory_bytes: 3632