akhauriyash/Code-Regression huggingface dataset:
from itertools import *

N, M, X = map(int, input().split())

C =[]
A = []
for _ in range(N):
    temp = list(map(int, input().split()))
    C.append(temp[0])
    A.append(temp[1:])




res = []

for a in product((0,1), repeat=N):
    P = [0] * M
    cost = 0
    for i in range(N):
        if a[i]:
            cost += C[i]
            for j in range(M):
                P[j] += A[i][j]
    for j in range(M):
        if P[j] < X:
            break
        if j == M-1:
            res.append(cost)

if not res:
    print(-1)
else:
    print(min(res))

Measured memory_bytes: 73916
#cording: utf-8

s = int(input())

def func(prog):
    if prog%2 == 0:
        return prog/2
    else:
        return 3*prog+1

progression = []
count = 0
while len(progression) == len(set(progression)):
    if count == 0:
        progression.append(10**5)
    if count == 1:
        progression.append(s)
    if count >= 2:
        f = func(progression[count-1])
        progression.append(f)
    count += 1

print(count-1)


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

int n, m, d[100005], p[100005];
vector<int> c[100005];

int Find (int X) {
	if(p[X] == X) return X;
	return p[X] = Find(p[X]);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) {
		p[i] = i;
		c[i].push_back(i);
	}
	while(m--) {
		int L, R, C;
		scanf("%d%d%d",&L,&R,&C);
		int LL = Find(L), RR = Find(R);
		if(LL == RR) {
			if(d[R] - d[L] != C) {
				puts("No");
				return 0;
			}
			continue;
		}
		if(c[LL].size() < c[RR].size()) {
			swap(LL, RR);
			swap(L, R);
			C *= -1;
		}
		int D = d[L] + C - d[R];
		for(auto &T : c[RR]) {
			c[LL].push_back(T);
			d[T] += D;
		}
		p[RR] = LL;
		c[RR].clear();
	}
	puts("Yes");
}


Measured memory_bytes: 10236
#include <iostream>                                             
using namespace std;                                            
                                                                
int main() {                                                    
  int a, b, c;                                                  
  cin >> a >> b >> c;                                           
  if (a<b && b<c) {                                             
    cout << "Yes" << endl;                                      
  } else {                                                      
    cout << "No" << endl;                                       
  }                                                             
  return 0;                                                     
}                                                               
                      

Measured memory_bytes: 3084
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){var e=t.in(),n=t.in();e>=13||(e>=6?n/=2:n=0),console.log(n)}}]);

Measured memory_bytes: 21192
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    int a,b,k;cin>>a>>b>>k;
    
    int i = 1;
    vector<int> num;
    while(i<=1000){
        if(a%i==0&&b%i==0)num.push_back(i);
        i++;
    }
    reverse(all(num));
    cout<<num[k-1]<<endl;
    return 0;
}





Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] num = {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};
        int k = sc.nextInt();
        System.out.println(num[k-1]);
    }
}

Measured memory_bytes: 21844
import sys
A = []
for i in range(3):
  a,b = map(int,input().split())
  A.append(a)
  A.append(b)
if A.count(1) == 1:
  if A.count(4) == 1:
    if A.count(2) == 2:
      print("YES")
      sys.exit()
print("NO")

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

int n;
char str[100100];

int main() {
    scanf("%s",str+1);
    n=strlen(str+1);
    if(str[n]=='1' || str[1]=='0') { puts("-1"); return 0; }
    for(int i=1;i<n;i++) if(str[i]!=str[n-i]) { puts("-1"); return 0;}

    int p=1;
    for(int i=1;i<n;i++) {
        printf("%d %d\n",p,i+1);
        if(str[i]=='1') p=i+1;
    }
    
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    string s;
    cin >> s;
    int ans = 1000;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'x') ans -= 100;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s;
	if (s=="A") cout<<"T";
	else if (s=="G") cout<<"C";
	else if (s=="T") cout<<"A";
	else if (s=="C") cout<<"G";
	return 0;
}

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

typedef pair<int, int> P;

int main() {

    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,n-1) cin >> b[i];
    ll ans = b[0];
    rep(i,n-1){
        ans += min(b[i],b[i+1]);
    }
    ans += b[n-2];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll S;
ll Sqrt(ll a) {
    ll ok = 1e9;
    ll ng = 0;
    while(ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if(mid * mid >= a) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    cin >> S;
    ll dx = Sqrt(S);
    ll delta = dx * dx - S;
    for(ll i = 1; i <= 1e9; i++) {
        if(delta % i != 0) continue;
        if(i * 1e9 < delta) continue;
        cout << "0 0 " << i << " " << dx << " " << dx << " " << delta / i << endl;
        cerr << dx * dx - delta << endl;
        return 0;
    }
    return 0;
}


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

using namespace std;

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

int main(void)
{
  int K;
  cin >> K;

  int ans = 0;
  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        ans += gcd(gcd(a, b), c);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int kari1 = 0;
  int kari4 = 0;
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < N; i++) {
    if (a[i] % 2 == 1) kari1++;
    else if (a[i] % 4 == 0) kari4++;
  }
  if (kari1 > (kari4+1)) cout << "No" << endl;
  else if (kari1 > kari4 && (kari1+kari4)<N) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 640
w = list(map(str, input()))
flg = 0
w.sort()
if len(w) % 2 == 1:
    flg += 1

else:
    for i in range(0, len(w)-1, 2):
        if w[i] != w[i+1]:
            flg += 1
            break

if flg == 1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 38256
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
GA, SA, BA = list(map(int, sys.stdin.readline().split()))
GB, SB, BB = list(map(int, sys.stdin.readline().split()))

values = []
weights = []
if GB / GA > 1:
    values.append(GB - GA)
    weights.append(GA)
if SB / SA > 1:
    values.append(SB - SA)
    weights.append(SA)
if BB / BA > 1:
    values.append(BB - BA)
    weights.append(BA)
# dp[i]: 重さ i 以下で選ぶのの価値の最大値
dp = [0] * (N + 1)
dp[0] = N
if values:
    for i in range(1, N + 1):
        x = dp[i - 1]
        for w, v in zip(weights, values):
            if i - w >= 0:
                x = max(x, dp[i - w] + v)
        dp[i] = x
    N = dp[N]

values = []
weights = []
if GA / GB > 1:
    values.append(GA - GB)
    weights.append(GB)
if SA / SB > 1:
    values.append(SA - SB)
    weights.append(SB)
if BA / BB > 1:
    values.append(BA - BB)
    weights.append(BB)
# dp[i]: 重さ i 以下で選ぶのの価値の最大値
dp = [0] * (N + 1)
dp[0] = N
if len(values) == 3:
    for i in range(1, N + 1):
        x = dp[i - 1]
        for w, v in zip(weights, values):
            if i - w >= 0:
                x = max(x, dp[i - w] + v)
        dp[i] = x
    N = dp[N]
if len(values) == 2:
    w1, w2 = weights
    v1, v2 = values
    if (v1 + w1) / w1 < (v2 + w2) / w2:
        v1, v2 = v2, v1
        w1, w2 = w2, w1
    c1 = N // w1
    c2 = (N - w1 * c1) // w2
    ret = N + v1 * c1 + v2 * c2
    while c1 >= 0:
        a = N - w1 * c1 - w2 * c2
        c1 -= max(1, math.ceil((w2 - a) / w1))
        c2 = (N - w1 * c1) // w2
        ret = max(ret, N + v1 * c1 + v2 * c2)
        if w1 * c1 + w2 * c2 == N:
            break
    N = ret
if len(values) == 1:
    N += N // weights[0] * values[0]
print(int(N))


Measured memory_bytes: 229020
#include<bits/stdc++.h>
#define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const long long mod = 1e9 + 7;
const double PI = acos(-1);
const double EPS = 1e-9;


int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	Abra_Ka_Dabra

	int n;
	cin >> n;
	vector<ll> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	vector<ll> y = x;
	for (int i = 1; i < n; i++) {
		x[i] = x[i] + x[i - 1];
	}
	ll res = 0;
	for (int i = 0; i < n - 1; i++) {
		ll tmp = (x[n - 1] - x[i]) % mod;
		tmp = (tmp * y[i]) % mod;
		res = (res + tmp) % mod;
	}
	cout << res % mod << "\n";

	return 0;
}



Measured memory_bytes: 6356
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int n;cin >> n;
    for(int i=0;i<=n/4;i++){
        for(int j=0;j<=n/7;j++){
            if(4*i+7*j==n){
                out("Yes");
                return 0;
            }
        }
    }
    out("No");
    return 0;
}




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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int dp[101][10]={};
	dp[0][a[0]%10]=a[0];
	for(int i=1;i<n;i++){
		for(int j=0;j<10;j++){
			if(dp[i-1][j]!=0){
				dp[i][(j+a[i])%10] = max(dp[i-1][(j+a[i])%10],dp[i-1][j]+a[i]);
			}else{
				if(j==0){
					dp[i][(j+a[i])%10] = a[i];
				}else{
					dp[i][(j+a[i])%10] = dp[i-1][(j+a[i])%10];
				}
			}
		}
	}
	int ans=0;
	for(int i=1;i<10;i++){
		ans = max(ans,dp[n-1][i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int n,m;
    cin>>n>>m;
  	cout<<(n+m)%24;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;
const int N=2005,Mod=1e9+7;
int f[N]={1},n;

int main()
{
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=i-3;j++)
		{
			f[i]=(f[i]+f[j])%Mod;
		}
	}
	printf("%d\n",f[n]);
	return 0;
}

Measured memory_bytes: 3772
N = int(input())
info = sorted([tuple(map(int, input().split())) for _ in range(N)])
ans = info[0][0]
for i in range(1, N):
    ans += min(info[i][0] - info[i-1][0], info[i-1][1] - info[i][1])
ans += info[-1][1]
print(ans)

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

int main() {
  string S;
  cin >> S;
  
  int x = S.size();
  
  if (x == 1 || x == 3 || x == 5 || x == 7 || x == 9) {
    cout << "No" << endl;
  }
  
  else if (x == 2) {
    if (S == "hi") {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  
  else if (x == 4) {
    if (S == "hihi") {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  
  else if (x == 6) {
    if (S == "hihihi") {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
    
  else if (x == 8) {
    if (S == "hihihihi") {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  
  else if (x == 10) {
    if (S == "hihihihihi") {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<set>

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define sPRINT(str) printf(#str "\n")
#define yOUT sPRINT(Yes)
#define nOUT sPRINT(No)
#define YOUT sPRINT(YES)
#define NOUT sPRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
 
using namespace std;

int main(void)
{   
    int h,w;
    cin >> h >> w;
    vector<string> a(h);

    vector<bool> row(h, false);
    vector<bool> col(w, false);

    REP(i, h){
        cin >> a[i];
    }

    REP(i, h){
        REP(j, w){
            if(a[i][j] == '#'){
                row[i] = true;
                col[j] = true;
            }
        }
    }

    REP(i,h){
        if(row[i]){
            REP(j, w){
                if(col[j]){
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }

}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

dp = [0] * N
dp[1] = abs(H[0] - H[1])

for i in range(2, N):
  cost1 = abs(H[i-1] - H[i])
  cost2 = abs(H[i-2] - H[i])
  dp[i] = min(dp[i-1]+cost1, dp[i-2]+cost2)

print(dp[N-1])

Measured memory_bytes: 13908
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(),x.end()
#define ld long double
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 3001;
int dp[N][N][4];
int R,C,K;
int val[N][N];
bool valid(int x,int y){
	if(x>R || y>C || x<=0 || y<=0)
		return 0;
	return 1;
}
int solve(int x,int y,int cnt){
	if(x == R && y == C){
		if(cnt <= 3)
			return 0;
		return -1e18;
	}
	if(!valid(x,y)) return -1e18;
	if(cnt>3) return -1e18;
	if(dp[x][y][cnt]!=-1) return dp[x][y][cnt];
	int ans = 0;
	if(valid(x+1,y)){
		if(val[x+1][y] == 0){
			ans = solve(x+1,y,0);
		}
		else{
			ans = val[x+1][y] + solve(x+1,y,1);
			ans = max(ans,solve(x+1,y,0));
		}
	}
	if(valid(x,y+1)){
		if(val[x][y+1] == 0){
			ans = max(ans,solve(x,y+1,cnt));
		}
		else{
			if(cnt == 3){
				ans = max(ans,solve(x,y+1,cnt));
			}
			else{
				ans = max(ans,val[x][y+1] + solve(x,y+1,cnt+1));
			}
			ans = max(ans,solve(x,y+1,cnt));
		}
	}
	dp[x][y][cnt] = ans;
	return ans;
}
signed main(){
    fast;
  	cin>>R>>C>>K;
  	for(int i = 1;i<=K;i++){
  		int x,y,v;
  		cin>>x>>y>>v;
  		val[x][y] = v;
  	}
  	for(int i = 1;i<=R;i++){
  		for(int j = 1;j<=C;j++)
  			for(int k = 0;k<=3;k++)
  				dp[i][j][k] = -1;
  	}
  	int ans = val[1][1] + solve(1,1,(val[1][1]>0));
  	ans = max(ans,solve(1,1,0));
  	cout<<ans;
}

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

#define int long long
const int MAX_N = 100000;

int N, A[MAX_N], B[MAX_N];

signed main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i] >> B[i];
	}
	int sum = 0;
	for (int i = N - 1; i >= 0; i--)
	{
		sum += B[i] - (A[i] + sum + B[i] - 1)%B[i] - 1;
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        sc.close();

        while (true) {
            C -= B;
            if (C <= 0) {
                System.out.println("Yes");
                break;
            }
            A -= D;
            if (A <= 0) {
                System.out.println("No");
                break;
            }
        }

    }

}


Measured memory_bytes: 35768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    cout << pow(n,3) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
#define MAXN 1000
int n;
long long T,A,G,K;
int main()
{
    scanf("%d",&n);
    scanf("%d%d",&T,&A);
    G=T,K=A;
    for(int i=2;i<=n;i++)
    {
        scanf("%lld%lld",&T,&A);
        long long p1=(G-1)/T+1,p2=(K-1)/A+1;
        long long P=max(p1,p2);
        G=P*T;
        K=P*A;
    }
    printf("%lld",G+K);//
}


Measured memory_bytes: 256
n, q = gets.split.map(&:to_i)
a = Array.new(n){[]}
n.pred.times do
  x, y = gets.split.map(&:to_i)
  a[x - 1] << y - 1
  a[y - 1] << x - 1
end
p = Array.new(n, 0)
q.times do |i|
  x, y = gets.split.map(&:to_i)
  p[x - 1] += y
end
c = Array.new(n, 0)
c[0] = 1
que = []
que << 0
while que.size > 0
  e = que.shift
  a[e].each do |i|
    next if c[i] > 0
    c[i] = 1
    p[i] += p[e]
    que << i
  end
end
puts p

Measured memory_bytes: 37772
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[0])
count = 0
for i in range(n):
    a, b = ab[i][0], ab[i][1]
    count += b
    if count >= k:
        print(a)
        exit()

Measured memory_bytes: 64600
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 998244353
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
void _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,s,p;
    cin >> n >> s ;
    ll a[n];
    for (int i = 0; i < n; ++i)
    {
    	cin >> a[i];
    }
    ll dp[n+1][s+1];ll ans=0;
    memset(dp, 0, sizeof(dp));
    // for(ll i=0;i<=n;i++)
    // {
    // 	dp[i][0]=i;
    // }
    for(ll i=1;i<=n;i++)
    {
    	for(ll j=1;j<=s;j++)
    	{
    		dp[i][j]=dp[i-1][j];ll d=0;
    		if(j>a[i-1]){_(dp[i][j],dp[i-1][j-a[i-1]]);_(d,dp[i-1][j-a[i-1]]);}
    		else if(j==a[i-1]){_(dp[i][j],i);_(d,i);}
    		if(j==s)_(ans,(d*(n-i+1))%mod);
    	}
    }
    //cout << dp[1][1] << " ";
    // for(ll i=1;i<=n;i++)
    // {
    // 	for(ll j=0;j<=s;j++)
    // 	{
    // 		cout << dp[i][j] << " ";
    // 	}
    // 	cout << "\n";
    // }
    cout << ans;
    }

Measured memory_bytes: 70656
# coding: utf-8
# Your code here!

li = [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(li[K-1])


Measured memory_bytes: 2940
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, K = MAP()
D = LIST()
 
q = deque([""])

s = set([i for i in range(0, 10)]) 
d = set(D)
kouho = s - d
kouho = sorted(list(set(kouho)))
while q:
    a = q.popleft()
    if len(a) != 0:
        if int(a) >= N:
            print(a)
            break
    for d in kouho:
        b = deepcopy(a)
        if len(b) == 0:
            if d == 0:
                continue
        b += str(d)
        q.append(b)

Measured memory_bytes: 7396
//↓template↓

#include "bits/stdc++.h"
using namespace std;
/*#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()*/
typedef long long ll;
//typedef complex<double>P;
/*const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;*/
/*int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];*/
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

/*ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS*(abs(a) + abs(b))) { return 0; }
	return a + b;
}*/


//↑template↑

int n, k[55], mon;
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
		if (k[i] != i + 1) { ++mon; }
	}
	if (mon <= 2) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
   cin>>a[i];
   ll stock=0;
   ll yen=1000;
  int i=0;
       while(i<n)
       {
           while(i+1<n&&a[i]>=a[i+1])
           {
               i++;
               
           }
           if(i<n)
           {
           stock+=yen/a[i];
           yen=yen%a[i];
           }
           
           while(i+1<n&&a[i]<=a[i+1])
           {
               i++;
              
           }
           if(i<n)
           {
           yen+=stock*a[i];
           stock=0;
           }
           if(i==n-1)
           break;
       }
       if(yen>1000)
   cout<<yen;
   else
   cout<<"1000";
   return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int debug = 0;

int main(void){
	int n;
	int i, j;
	int len, tmp, carry;
	string str1, str2, str3, hoge;
	vector<int> num1, num2, sum;

	cin >> n;
	for(i=0;i<n;i++){


		//getline(cin, str1);
		cin >> str1;

		len = str1.size();
		for(j=0;j<len;j++){
			num1.push_back(str1[len - j - 1] - 48); //convert ascii to digit
			if(debug) cout << num1[j] << endl;
		}

		//getline(cin, str2);
		cin >> str2;

		len = str2.size();
		for(j=0;j<len;j++){
			num2.push_back(str2[len - j - 1] - 48); //convert ascii to digit
			if(debug) cout << num2[j] << endl;
		}
		
		len = max(num1.size(), num2.size());
		carry = 0;
		for(j=0;j<len;j++){
			if(num1.size() > (unsigned int)j && num2.size() > (unsigned int)j){
				tmp = num1[j] + num2[j] + carry;
			}else if(num1.size() <= j){
				tmp = num2[j] + carry;
			}else{
				tmp = num1[j] + carry;
			}
			sum.push_back(tmp % 10);
			if(tmp >= 10){
				carry = 1;
			}else{
				carry = 0;
			}
		}
		
		if(carry) sum.push_back(carry);

		if(debug){
			for(j=0;(unsigned int)j<sum.size();j++){
				cout << sum[j];
			}
			cout << endl;
		}

		if(sum.size() > 80){
			cout << "overflow" << endl;
		}else{
			tmp = sum.size();
			str3.reserve(tmp + 1);
			for(j=0;j<tmp;j++){
				str3 += sum[tmp - j - 1] + 48; //convert digit to ascii
			}
			cout << str3 << endl;
		}
		
		if(debug) while(1);
		num1.clear();
		num2.clear();
		sum.clear();
		str1.erase();
		str2.erase();
		str3.erase();
	}

	return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using namespace std;

int main(void) {

	int N = 0, M = 0,ans = 0;
	int edge[50][2] = { 0 };
	queue<int> q;

	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++) {
		int a = 0, b = 0;
		scanf("%d%d", &a, &b);
		edge[i][0] = a - 1;
		edge[i][1] = b - 1;
	}

	for (int i = 0; i < M; i++) {
		int node[50] = { 0 };
		node[0] = 1;
		q.push(0);
		while (!q.empty()) {
			for (int j = 0; j < M; j++) {
				int a = -1;
				if (q.front() == edge[j][0] && j != i)
					a = edge[j][1];
				if (q.front() == edge[j][1] && j != i)
					a = edge[j][0];

				if (a != -1 && node[a] == 0) {
					q.push(a);
					node[a] = 1;
				}
			}
			q.pop();
		}
		bool frag = true;
		for (int j = 0; j < N; j++) {
			if (node[j] == 0)
				frag = false;
		}
		if (!frag)
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
    int a,b,c=0;
    while(cin>>a>>b){
        c=0;
        bool flg[120] = {false};
        flg[a] = 1 - flg[a];
        flg[b] = 1 - flg[b];
        flg[a] ? c++ : c--;
        flg[b] ? c++ : c--;
        while(true){
            cin>>a>>b;
            if(a==0)break;
            flg[a] = 1 - flg[a];
            flg[b] = 1 - flg[b];
            flg[a] ? c++ : c--;
            flg[b] ? c++ : c--;
        }
        if(c==2&&flg[1]&&flg[2])cout<<"OK"<<endl;
        else cout<<"NG"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<cassert>

using namespace std;

typedef long long ll;
typedef pair<ll,int> P;

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

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

	int h,n,a[1123],b[1123];
	cin>>h>>n;
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];

	static int dp[1010][10100];
	for(int i=0;i<=n;i++)
		for(int j=0;j<=h;j++)
			dp[i][j]=1e9;
	for(int i=0;i<=n;i++) dp[i][0]=0;

	int res=1e9;

	for(int i=0;i<n;i++)
		for(int j=0;j<=h;j++)
		{
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			if(j<h)
				dp[i][min(h,j+a[i])]
					=min(dp[i][min(h,j+a[i])],dp[i][j]+b[i]);
		}

	cout<<dp[n][h]<<endl;

	return 0;
}



Measured memory_bytes: 39808
#include<bits/stdc++.h>
#define cy cout << "YES" << endl;
#define cn cout << "NO" << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{

long long a,b,c,d,e,f,x,n,h=0,k,i,j;
   cin >> a ;
   vector<long long >vec;
   while(a--)
   {
       cin >> d;
       vec.push_back(d);




   }
   long long y=10000000000000000;

   for(i=-100;i<=100;i++)
   {
       long long sum=0;

       for(j=0;j<vec.size();j++)
       {
           sum+=(vec[j]-i)*(vec[j]-i);




       }
       y=min(sum,y);





   }
   cout << y << endl;







}


Measured memory_bytes: 3608
program infinite_sequence
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer(8) :: dp(0:1000000) = 0_8, m, s
  integer :: n, i
  read(*,*) n
  dp(1) = int(n,8)
  dp(2) = mod(int(n,8)*int(n,8),md)
  s = dp(1)+dp(2)
  m = mod(int(n-1,8)*int(n-1,8),md)
  do i = 3, n
    dp(i) = modulo(m+s+int(n-i+2,8)-dp(i-2),md)
    s = mod(s+dp(i),md)
  end do
  write(*,'(i0)') dp(n)
end program infinite_sequence

Measured memory_bytes: 8064
from heapq import heapify, heappop, heappush

def next_num(n):
    if n == 0:
        return [0, 1]
    elif n == 9:
        return [8, 9]
    else:
        return [n-1, n, n+1]

K = int(input())
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapify(queue)

for _ in range(K-1):
    now = heappop(queue)
    for next_i in next_num(now%10):
        heappush(queue, now*10 + next_i)

print(queue[0])

Measured memory_bytes: 19564
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


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

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            int[] A = new int[N];
            A = cin.ReadIntArray(N);
            int x = 0;
                int y = 0;
            x = A.Max() - A.Min();



            Console.WriteLine(x);
            Console.Read();

        }
    }

    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: 13396
#include <iostream>
#include <vector>

using namespace std;

int main()
{

    int x;
    cin >> x;

    vector<vector<bool>> vs(6, vector<bool>(x + 1, false));

    for (int i = 0; i <= x; i += 100)
    {
        vs[0][i] = true;
    }

    for (int i = 1; i < 6; i++)
    {
        const int cost = 100 + i;
        for (int j = 0; j <= x; j++)
        {
            if (vs[i - 1][j])
            {
                vs[i][j] = true;
            }
            if (cost <= j && vs[i - 1][j - cost])
            {
                vs[i][j] = true;
            }
            if (cost <= j && vs[i][j - cost])
            {
                vs[i][j] = true;
            }
        }
    }
    cout << (vs[5][x] ? 1 : 0) << endl;
}

Measured memory_bytes: 384
#include <algorithm> // max
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    int l, i=0, a[10];
    while(cin>>l){
        a[i] = l;
        i++;
    }
int x;
int y;
double z;
x=a[0];
y=a[0];
for(int i = 0; i <= 3; ++i){
if(x>a[i])x=a[i];
}
for(int i = 0; i <= 3; ++i){
if(y<a[i])x=a[i];
}
z=sqrt(x*x-y*y);
cout << y*z/2 <<endl;
}

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

const ll INF = pow(10, 9) + 7;


int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> map(H,vector<char>(W));
  rep(i,H)rep(j,W) cin >> map[i][j];
  
  int ans = 0;
  rep(si,H)rep(sj,W){
    if(map[si][sj] == '#') continue;
    vector<vector<int>> a(H,vector<int>(W,-1));
    queue<P> q;
    
    auto update = [&](int i,int j,int x){
      if(i<0 || i>=H || j<0 || j>=W) return;
      if(map[i][j] == '#' || a[i][j] != -1) return;
      q.push(P(i,j));
      a[i][j] = x;
      return;
    };
    
    update(si,sj,0);
    
    while(!q.empty()){
      P pp = q.front();q.pop();
      int i = pp.first,j=pp.second;
      update(i+1,j,a[i][j]+1);
      update(i-1,j,a[i][j]+1);
      update(i,j+1,a[i][j]+1);
      update(i,j-1,a[i][j]+1);
      if(q.empty()) ans = max(ans,a[i][j]);
    }
  }
  
  cout << ans << endl;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    string ans="";
    for(int i=0;i<s.length();i++){
        char c=s[i];
        int val=s[i]-'A';
        val+=n;
        val=val%26;
        c='A'+val;
        ans+=c;
    }
    cout<<ans;
	return 0;
}

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

int main() {
    long long n; cin >> n;
    long long ans = 0;

    if(n%2 == 0){
        n /= 2;
        while(n){
            ans += n/5;
            n /= 5;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N, M;
  cin >> N >> M;
  
  int K, i, j, A, num[M] = {};
  for (i = 0; i < N; i++) {
    cin >> K;
    for (j = 0; j < K; j++) {
      cin >> A;
      num[A - 1] += 1;
    }
  }
  
  int ans = 0;
  for (i = 0; i < M; i++) {
    if (num[i] == N) {
      ans += 1;
    }
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  if (k <= a) cout << a - k << " " << b << endl;
  else if (k <= a + b) cout << 0 << " " << a + b - k << endl;
  else cout << 0 << " " << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    ll n; cin>>n;
    ll p[n];
    ll cnt = 0;
    for(ll i=0; i<n; i++){
        ll p; cin>>p;
        if(p != i+1)
            cnt++;
    }
    if(cnt <= 2)
        OUT("YES");
    else
        OUT("NO");
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define MN 210000
#define lp p<<1
#define rp (p<<1)|1
using namespace std;
int read_p,read_ca,read_f;
inline int read(){
	read_p=0;read_ca=getchar();read_f=1;
	while (read_ca<'0'||read_ca>'9') read_f=read_ca=='-'?-1:read_f,read_ca=getchar();
	while (read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
	return read_p*read_f;
}
const int MOD=1e9+7;
inline void M(int &x){while(x>=MOD)x-=MOD;while(x<0)x+=MOD;}
inline int _M(int x){M(x);return x;}
struct si{int l,r;}w[MN];
struct na{int x,v;}p[MN];
bool operator < (si a,si b){return a.l<b.l;}
bool operator < (na a,na b){return a.v<b.v;}
int n,m,qi[MN][20],hou[MN][20],s[MN<<2],c[MN<<2];
inline int min(int a,int b){return a<b?a:b;}
inline int max(int a,int b){return a>b?a:b;}
inline void hb(int p,int C){s[p]=1LL*s[p]*C%MOD;c[p]=1LL*c[p]*C%MOD;}
inline void pd(int p){if (c[p]-1) hb(lp,c[p]),hb(rp,c[p]),c[p]=1;}
inline int ask(int p,int l,int r,int L,int R){
	if (l==L&&r==R) return s[p];
	pd(p);
	int mid=l+r>>1;
	if (R<=mid) return ask(lp,l,mid,L,R);else
	if (L>mid) return ask(rp,mid+1,r,L,R);else
	return _M(ask(lp,l,mid,L,mid)+ask(rp,mid+1,r,mid+1,R));
}
inline void add(int p,int l,int r,int x,int v){
	if (l==r) M(s[p]+=v);else{
		pd(p);
		int mid=l+r>>1;
		if (x<=mid) add(lp,l,mid,x,v);else add(rp,mid+1,r,x,v);
		M(s[p]=s[lp]+s[rp]);
	}
}
inline void cc(int p,int l,int r,int L){
	if (L<=l) M(s[p]+=s[p]),M(c[p]+=c[p]);else{
		pd(p);
		int mid=l+r>>1;
		if (L<=mid) cc(lp,l,mid,L);cc(rp,mid+1,r,L);
		M(s[p]=s[lp]+s[rp]);
	}
}
int main(){
	int i,j;
	n=read();
	for (i=1;i<=n;i++)
	p[i].x=read(),p[i].v=read();
	sort(p+1,p+1+n);
	for (i=1;i<=n;i++)
	for (qi[i][0]=p[i].x,j=1;j<20;j++) if (i>>j) qi[i][j]=min(qi[i][j-1],qi[i-(1<<(j-1))][j-1]);
	for (i=n;i;i--)
	for (hou[i][0]=p[i].x,j=1;j<20;j++) if ((n-i+1)>>j) hou[i][j]=max(hou[i][j-1],hou[i+(1<<(j-1))][j-1]);
	
	for (i=1;i<=n;i++){
		w[i].l=1;
		for (j=19;j>=0;j--) if (((n-w[i].l+1)>>j)&&(hou[w[i].l][j]<p[i].x)) w[i].l+=1<<j;
		w[i].r=n;
		for (j=19;j>=0;j--) if ((w[i].r>>j)&&(qi[w[i].r][j]>p[i].x)) w[i].r-=1<<j;
	}
	for (i=1;i<=(n+1<<2);i++) c[i]=1;
	sort(w+1,w+1+n);add(1,1,n+1,1,1);
	for (int i=1;i<=n;i++) cc(1,1,n+1,w[i].r+1),add(1,1,n+1,w[i].r+1,ask(1,1,n+1,w[i].l,w[i].r));
	
	printf("%d\n",ask(1,1,n+1,n+1,n+1));
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

vector<ll> vratiDelioce(ll n)
{
    vector<ll> v;

    for(ll i = 1LL; i * i <= n; ++i)
    {
        if(n % i == 0)
        {
            v.pb(i);

            if(n/i != i)
            {
                v.pb(n/i);
            }
        }
    }

    return v;
}

void debug(vector<ll> &v)
{
    for(auto e : v)cout << e << ' ';
    cout << '\n';
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> prviNiz = vratiDelioce(n-1);
    vector<ll> drugiNiz = vratiDelioce(n);

    //debug(prviNiz);
    //debug(drugiNiz);

    set<int>res;

    for(auto e : prviNiz)
    {
        if(e==1)continue;
        res.insert(e);
    }

    for(auto e : drugiNiz)
    {
        if(e == 1)continue;
        ll vrednost = n;

        while(vrednost % e == 0)
        {
            vrednost /= e;
        }

        if(vrednost % e == 1)
        {
            res.insert(e);
        }
    }

    cout << (int)res.size() << '\n';

    return 0;
}


Measured memory_bytes: 384
//In the name of Allah the Most Merciful
//Astagfirullahil laji Rabbi Minkulli Jamio Watubi elai
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define MX 10000008
#define cs int t;cin>>t;while(t--)
int i,j,k;
int r,s;
main()
{
 int n;cin>>n;int a[n];
 int s=0;for(i=0;i<n;i++)cin>>a[i];
 for(i=0;i<n;i++)
 {
     for(j=i+1;j<n;j++)
     {
        s+=(a[i]*a[j]);
        //cout<<i*j<<endl;
     }
 }
 cout<<s<<endl;

}


Measured memory_bytes: 3660
import sys
readline = sys.stdin.readline

S = readline().rstrip()
D = int(readline())
DIV = 10 ** 9 + 7
N = len(S)

dp = [[[0] * D for j in range(2)] for i in range(N)]
# dp[i][smaller][d]

x0 = S[0]
dp[0][0][int(x0) % D] = 1
for i in range(int(x0)):
  dp[0][1][i % D] += 1

last = int(x0) % D
for i in range(1, len(S)):
  x = S[i]
  dp[i][0][(last + int(x)) % D] += dp[i - 1][0][last]
  dp[i][0][(last + int(x)) % D] %= DIV
  
  for j in range(int(x)):
    dp[i][1][(last + j) % D] += dp[i - 1][0][last]
    dp[i][1][(last + j) % D] %= DIV
  
  for j in range(D):
    for k in range(10):
      dp[i][1][(j + k) % D] += dp[i - 1][1][j]
      dp[i][1][(j + k) % D] %= DIV
  last = (last + int(x)) % D
    
print((dp[-1][0][0] + dp[-1][1][0] - 1) % DIV)

Measured memory_bytes: 92416
#include<stdio.h>
int main(void)
{
	int n,cnt;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		n=1000-n; cnt=0;
		if(n>=500){
			cnt+=n/500; n=n%500;
		}
		if(n>=100){
			cnt+=n/100; n=n%100;
		}
		if(n>=50){
			cnt+=n/50; n=n%50;
		}
		if(n>=10){
			cnt+=n/10; n=n%10;
		}
		if(n>=5){
			cnt+=n/5; n=n%5;
		}
		if(n>=1) cnt+=n/1;
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 2660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S[] = new String[3];
		for (int i = 0; i < 3; i++) {
			S[i] = sc.next();
		}
		int a[] = new int[3];
		int now = 0;
		while (true) {
			int temp = now;
			if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			}
			switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			}
			a[temp]++;
		}
	}
}


Measured memory_bytes: 22228
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if (op == '?'):break
    
    if (op == '+'):
        print(a+b)
    elif (op == '-'):
        print(a-b)
    elif (op == '*'):
        print(a*b)
    elif (op == '/'):
        print(a//b)


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

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

  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a.at(i);
  }

  vector<int> order(n);
  for (int i = 0; i < n; i++){
    order.at(a.at(i) - 1) = i + 1;
  }

  for (int i = 0; i < n; i++){
    cout << order.at(i) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1536
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}

inline void solve(void){
  int N,A,B;
  in(N,A,B);
  vector<int>C(3);
  rep(i,N){
    int P;
    in(P);
    if(P<=A)C[0]++;
    else if(P<=B)C[1]++;
    else C[2]++;
  }
  out(*min_element(all(C)));
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	static public void main(String args[]){
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int x = 0;
		int y = 0;

		while(true){
			x = sc.nextInt();
			y = sc.nextInt();

			if(x==0 && y==0)
				break;
			if(x>y)
				sb.append(y + " " + x + "\n");
			else
				sb.append(x + " " + y + "\n");
		}

		System.out.print(sb);
	}
}

Measured memory_bytes: 35612