akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0207

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def solve(w, h, xs, ys, xg, yg, blocks):
    # ????????????????????±????????°???????????????l
    field = [[0] * (w+1) for _ in range(h+1)]
    for c, d, x, y in blocks:
        field[y][x] = c
        field[y][x+1] = c
        field[y+1][x] = c
        field[y+1][x+1] = c

        if d == 0:              #  ?¨????
            field[y][x+2] = c
            field[y][x+3] = c
            field[y+1][x+2] = c
            field[y+1][x+3] = c
        else:                   #  ??????
            field[y+2][x] = c
            field[y+3][x] = c
            field[y+2][x+1] = c
            field[y+3][x+1] = c

    # ????????????????§????????????´????????§?¨??????????
    dy = [-1, 1, 0, 0]
    dx = [0, 0, -1, 1]

    explored = set()            #  ??¢?´¢????????§?¨?(x, y)????¨????
    explored.add((xs, ys))
    Q = deque()
    Q.append((xs, ys))
    color = field[ys][xs]       #  ?????????????????¨?????§?????????????????????????????°?????¨???????????????

    while Q:
        xc, yc = Q.popleft()        #  ?????¨??°?????§?¨?
        if xc == xg and yc == yg:
            return 'OK'
        for i in range(len(dx)):
            xn = xc + dx[i]
            yn = yc + dy[i]
            #  ?§????????????§???????????? ?????? ??¢?????¢?´¢?????§???????????°??????????????§?????¢?´¢????¶???????
            if 0 < xn <= w and 0 < yn <= h and field[yn][xn] == color and (xn, yn) not in explored:
                Q.append((xn, yn))
                explored.add((xn, yn))
    return 'NG'


def main(args):
    while True:
        w, h = map(int, input().split())
        if w == 0 and h == 0:
            break
        xs, ys = map(int, input().split())
        xg, yg = map(int, input().split())
        n = int(input())
        blocks = [list(map(int, input().split())) for _ in range(n)]

        result = solve(w, h, xs, ys, xg, yg, blocks)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8104
data_num = int(input())
cnt = 0
deff_price = -999999999
min_price = 0
tmp_price = 0

for i in range(data_num):
    price = int(input())
 
    if i ==0:
        min_price = price
    elif price - min_price > deff_price:
        deff_price = price - min_price
    
    if price < min_price:
        min_price = price

print(str(deff_price))

Measured memory_bytes: 7648
open Printf
open Str

let inputs string =
	let l_of_str = Str.split (Str.regexp " ") string in
	let nums = Array.of_list (List.map int_of_string l_of_str) in
	Array.sort(compare) nums;
	printf "%d %d\n" nums.(0) nums.(1);;

let isEnd = ref false in
while not !isEnd do
	let s = read_line() in
		if "0 0" = s then
			isEnd := true
		else
			inputs s
done;;

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

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

        int L = Integer.parseInt(sc.next());
        int R = Integer.parseInt(sc.next());
        sc.close();

        long min = 2019;
        for (int i = L; i <= R - 1; i++) {
            for (int j = i + 1; j <= R; j++) {
                long calc = ((long)i * j) % 2019;
                if (calc < min) {
                    min = calc;
                }
                if (min == 0) {
                    break;
                }
            }
            if (min == 0) {
                break;
            }
        }
        out.printf("%d\n", min);
        out.flush();
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;

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

    cin>>a>>b>>c>>d;

    long long pat1=a*c;
    long long pat2=a*d;
    long long pat3=b*c;
    long long pat4=b*d;

    cout<<max(pat1,max(pat2,max(pat3,pat4)))<<endl;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> a(N+1);
  
  for (int i = 1; i <= N; ++i) {
    cin >> a.at(i);
  }
  
  int now = 1;
  int count = 0;
  while (true) {
    now = a.at(now);
    count++;
    if (now == 2) break;
    if (count > N) {
      count = -1;
      break;
    }
  }
  cout << count << endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 A, B, C;
	cin >> A >> B >> C;
	cout << B+min(A+B+1, C) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100100
#define eps 1e-9
#define For(i,a,b) for(int i=a;i<=b;i++) 
#define Fore(i,a,b) for(int i=a;i>=b;i--) 
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e9+9
#define Vector Point
#define fir first
#define sec second
#define fxx(a) cout<<fixed<<setprecision(a)
#define flu cout.flush()
typedef pair<int,int> pii;
const int Mod=1000000007;
typedef unsigned long long ull;
typedef long long ll;
const int base=227;
const int base1=123;
const int maxn=2005;
char s[3000006];
int suml[300005],sumr[300005];
int n;
void solve(){
	cin>>n;
	cin>>s+1;
	int l=strlen(s+1);suml[0]=0;sumr[l+1]=0;
	For(i,1,l) {
		if(s[i]=='W') suml[i]=suml[i-1]+1;
		else suml[i]=suml[i-1];
	}
	Fore(i,l,1) {
		if(s[i]=='E') sumr[i]=sumr[i+1]+1;
		else sumr[i]=sumr[i+1];
	}
	int ans=suml[1]+sumr[2];;
	For(i,1,l) {
		ans=min(suml[i-1]+sumr[i+1],ans);
	}cout<<ans<<endl;
}
int main(){
	iossy;
	int t=1;
	For(i,1,t) solve();
	return 0;
}

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

using ll = long long;

ll n, m, v, p;

bool can (ll pos, vector <ll> a) {
	ll left = m*(max(0ll, v-(n-pos+1)-p+1));
	int cnt = 0;
	a[pos] += m;
	for (int i=pos-1; i>=p; i--) {
		if (a[i] <= a[pos]) {
			left -= a[pos]-a[i];
			a[i] = a[pos];
		} else {
			cnt ++;
		}
	}
	return (left <= 0 && !cnt);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m >> v >> p;
	vector <ll> a(n+1);
	for (int i=1; i<=n; i++) {
		cin >> a[i];
	}
	a[0] = 1e9+1;
	sort (a.begin(), a.end(), 
		[](const ll& x, const ll& y) {
			return (x > y);
		}
	);
	int bs = 0;
	for (int i=(1<<16); i>=1; i=(i>>1)) {
		if (i+bs > n) continue;
		if (can(i+bs, a)) {
			bs += i;
		}
	}
	cout << bs;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	string s;
	cin >> s;
	if (s.size() == 3) reverse(ALL(s));
	cout << s << endl;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate
N, M, Q = map(int, sys.stdin.readline().split())
 
LR = [[0 for _ in range(N-i)] for i in range(N)]
for i in range(M):
  L, R = map(int, sys.stdin.readline().split())
  LR[L-1][R-L] += 1
 
for i in range(N-2,-1,-1):
  acc = accumulate(LR[i])
  next(acc)
  for j in range(1, N-i):
    LR[i][j] = next(acc) + LR[i+1][j-1]
 
for i in range(Q):
  p, q = map(int, sys.stdin.readline().split())
  sys.stdout.write(str(LR[p-1][q-p])+"\n")

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    int N, M, K;
    std::cin >> N >> M >> K;

    for(int i=0;i<=N;++i){
        for(int j=0;j<=M;++j){
            if(i * M + j * N - 2 * i * j == K){
                std::cout << "Yes" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "No" << std::endl;    
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=[0]*(n+1)
b=[0]*(n+1)
for i in range(m):
  x,y=map(int,input().split())
  if x==1:
    a[y]=1
  if y==n:
    b[x]=1
ans=0
for i in range(n+1):
  ans+=a[i]*b[i]
if ans==0:
  print('IMPOSSIBLE')
else:
  print('POSSIBLE')

Measured memory_bytes: 77876
#include<iostream>

using namespace std;

int main(){
  long long n, r[200009];
  cin >> n;
  for(int i=0;i<n;i++)cin >> r[i];
  long long mx_prof = -1e9;
  long long mn=r[0];
  for(int i=1;i<n;i++){
    mx_prof = max(mx_prof, r[i] - mn);
    mn = min(mn, r[i]);
  }
  cout << mx_prof << endl;
}


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

#define N 1300000
bool prime[N];

int solve(int n){
    if(prime[n]) return 0;
    int l=n,r=n;
    while(!prime[l])l--;
    while(!prime[r])r++;
    return r-l;
}

int main(void){
    rep(i,N) prime[i] = true;
    prime[0] = prime[1] = false;
    for(int i=2; i<N; i++){
        if(!prime[i]) continue;
        for(int j=i*2; j<N; j+=i){
            prime[j] = false;
        }
    }

    int n;
    while(cin>>n,n){
        cout<<solve(n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 4324
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   ll n, d;
   cin >> n >> d;
   vector<ll> x(n), y(n);
   ll cnt = 0;
   for (int i = 0; i < n; i++) {
       cin >> x[i] >> y[i];
       if(pow(x[i], 2)+pow(y[i], 2)<= pow(d, 2)) {
           cnt++;
       }
   }
   cout << cnt << endl;
}

Measured memory_bytes: 6348
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define pb push_back
#define fi first
#define se second
#define SIZE 100333
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

int main () {
	char str[100111];
	int n, chk[100111];
	scanf("%d",&n);
	scanf("%s",str);
	for(int cnt=3;cnt>=0;cnt--) {
		memset(chk,0,sizeof(chk));
		// printf("cnt %d\n",cnt);
		// 1 : sheep, 0 : wolf
		chk[0] = (cnt & 1) ? 1 : 0;
		chk[1] = (cnt & 2) ? 1 : 0;
		for(int i=1;i<n-1;i++) {
			if((str[i] == 'o' && chk[i]) || (str[i] == 'x' && !chk[i]))	chk[i+1] = chk[i-1];
			else													chk[i+1] = 1 - chk[i-1];
		}
		// last chk
		if (((!chk[n-1] && str[n-1] == 'x') || (chk[n-1] && str[n-1] == 'o')) && chk[n-2] != chk[0])		continue;
		if (((!chk[n-1] && str[n-1] == 'o') || (chk[n-1] && str[n-1] == 'x')) && chk[n-2] == chk[0])		continue;
		if (((!chk[0] && str[0] == 'o') || (chk[0] && str[0] == 'x')) && chk[n-1] == chk[1])				continue;
		if (((!chk[0] && str[0] == 'x') || (chk[0] && str[0] == 'o')) && chk[n-1] != chk[1])				continue;
		for(int i=0;i<n;i++)	printf("%c",chk[i] ? 'S' : 'W');
		printf("\n");
		return 0;
	}
	printf("-1\n");
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;

  if (U == S)
  {
    A--;
  }
  else
  {
    B--;
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		ArrayList<Pair> list = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			list.add(new Pair(sc.nextInt(), sc.nextInt()));
		}
		Collections.sort(list, new ComparatorByValue());
		int index = m - 1;
		int count = list.get(index).key;
		long value = list.get(index).value;
		for (int i = 0; i < n; i++) {
			if (a[i] > value) {
				break;
			}
			a[i] = value;
			count--;
			if (count == 0) {
				index--;
				if (index == -1) {
					break;
				}
				count = list.get(index).key;
				value = list.get(index).value;
			}
		}
		long sum = 0;
		for (int i = 0; i < n; i++) {
			sum += a[i];
		}
		System.out.println(sum);
	}
}

class Pair {
	public int key;
	public long value;
	public Pair(int key, long value) {
		this.key = key;
		this.value = value;
	}
}

class ComparatorByValue implements Comparator<Pair> {
	@Override
	public int compare(Pair sort1, Pair sort2) {
		if (sort1.value == sort2.value) {
			return 0;
		} else if (sort1.value > sort2.value) {
			return 1;
		} else {
			return -1;
		}
	}
}

class ComparatorByKey implements Comparator<Pair> {
	@Override
	public int compare(Pair sort1, Pair sort2) {
		if (sort1.key == sort2.key) {
			return 0;
		} else if (sort1.key > sort2.key) {
			return 1;
		} else {
			return -1;
		}
	}
}

Measured memory_bytes: 98716
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

int main() {
  size_t N;
  intmax_t P, Q;
  scanf("%zu %jd %jd", &N, &P, &Q);

  std::vector<intmax_t> C(N);
  intmax_t S = 0;
  for (auto& ci: C) {
    scanf("%jd", &ci);
    S += ci;
  }

  std::vector<intmax_t> D(N);
  for (size_t i = 0; i < N; ++i) {
    intmax_t j = i;
    D[i] = j*P + C[i];
  }
  std::sort(D.begin(), D.end());

  intmax_t res = S;
  intmax_t cur = res;
  for (size_t i = 0; i < N; ++i) {
    cur -= D[i];
    intmax_t j = i+1;
    cur += P*(Q+j+j-2);
    res = std::max(res, cur);
  }
  printf("%jd\n", res);
}



Measured memory_bytes: 10120
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <map>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

map<pair<ll,ll>,int> black;//1マスでも黒く塗られた3*3マス空間の左上の座標とそのうち塗られたマスの数
ll ans[10];

int main()
{
	ll h,w;
	int n;
	cin>>h>>w>>n;
	for(int i=0;i<n;i++)
	{
		ll a,b;
		cin>>a>>b;

		//周囲25マスを黒く塗りつぶす
		for(ll j=a-2;j<min(a+1,h-1);j++)
		{
			for(ll k=b-2;k<min(w-1,b+1);k++)
			{
				if(j>0 && k>0)
				{
					auto temp=make_pair(j,k);
					black[temp]=black[temp]+1;
				}
			}
		}
	}

	fill(ans,ans+10,0);
	//できあがったmapの要素全てについて色を調べる
	for(auto i=black.begin();i!=black.end();i++)
	{
		ans[i->second]++;
	}
	//塗られていないものの個数
	ans[0]=(h-2)*(w-2)-black.size();


	for(int i=0;i<10;i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 56448
#include <iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
map <int,int>mp;
void precalculation()
{
    for(int a=0;a<=9;a++){
        for(int b=0;b<=9;b++){
            for(int c=0;c<=9;c++){
                for(int d=0;d<=9;d++){
                    mp[a+b+c+d]++;
                }
            }
        }
    }
}

int main()
{
    for(int i=0;i<=50;i++) mp[i]=0;
    precalculation();
    int n;
    while(scanf("%d",&n)==1){
        printf("%d\n",mp[n]);
    }
    return 0;
}

Measured memory_bytes: 1188
#include <cctype>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int main () {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  s[b-1] = tolower(s[b-1]);
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N, C;
    cin >> N >> C;
    auto D = make_vec<int>(C, C);
    auto c = make_vec<int>(N, N);
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            cin >> D[i][j];
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> c[i][j];
            c[i][j]--;
        }
    }

    auto num = make_vec<int>(3, C);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            int a = (i + j + 2) % 3;
            num[a][c[i][j]]++;
        }
    }

    long long ans = 1e18;
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            for (int k = 0; k < C; k++) {
                if (i == j || j == k || k == i) continue;
                long long sum = 0;
                for (int l = 0; l < C; l++) {
                    sum += D[l][i] * num[0][l];
                }
                for (int l = 0; l < C; l++) {
                    sum += D[l][j] * num[1][l];
                }
                for (int l = 0; l < C; l++) {
                    sum += D[l][k] * num[2][l];
                }
                chmin(ans, sum);
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;  
  string s; cin >> s;
  int x = 0, ans = 0;
  for(int i = 0; i < n; ++i){
    if(s[i] == 'I')x++;
    else x--;
    ChangeMax(ans,x);
  }
  cout << ans << endl;
  return 0;
}


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

public class Main {
    // 最小非負剰余
    static void divmod (int[] vi, int a, int b) {
        // int q;
        // int r;
        if (b < 0) {
            b = -b;
            a = -a;
        }
        // q = 0;
        // r = a;
        if (a > 0) {
            int q = 0;
            int r = a;
            while (r - b >= 0) {
                q += 1;
                r -= b;
            }
            vi[0] = q;
            vi[1] = r;
        } else if (a < 0) {
            int q = 0;
            int r = a;
            do {
                q -= 1;
                r += b;
            } while (r < 0);
            vi[0] = q;
            vi[1] = r;
        } else {
            vi[0] = 0;
            vi[1] = a;
        }
    }
    public static void main (String[] args) throws IOException {
        final String s;
        try (BufferedReader reader =
                 new BufferedReader (new InputStreamReader (System.in))) {
            s = reader.readLine();
        }
        int[] vi           = new int[2];
        int           N    = Integer.parseInt (s);
        StringBuilder sb   = new StringBuilder();
        int           base = 2;
        while (0 != N) {
            // base = 3 でうまくいかない
            // 例えば 7
            // base = 2 は OK
            // sb.insert (0, String.valueOf (Math.abs (N % base)));
            // N -= Math.abs (N % base);
            // N /= -base;

            // base = 3 でもうまくいく
            divmod (vi, N, base);
            sb.insert (0, String.valueOf (vi[1]));
            N -= vi[1];
            divmod (vi, N, -base);
            N = vi[0];
        }
        if (sb.length() == 0) sb.append ("0");
        System.out.println (sb);
    }
}


Measured memory_bytes: 21332
/*
   AtCoder Submission
*/

#include<bits/stdc++.h>

using namespace std;

/* typedefs */
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <string,string> mss;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, X;
    cin >> N >> X;

    vi grams;
    int sol = N;
    int x;
    for(int i = 0; i < N; i++){
        cin >> x;
        grams.push_back(x);
        X -= x;
    }
    sort(grams.begin(), grams.end());
    
    
    cout << sol + X / grams[0] << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}cout<<endl;}

int main() {
    ll n,m;
    cin>>n;
    vector<ll> v(n);
    rep(i, n){
        cin >> v[i];
    }
    rep(i, n-1){
        while(1){
            if(v[i+1]==0 || v[i]==0) break;
            v[i+1]%=v[i];
            if(v[i+1]==0 || v[i]==0) break;
            v[i]%=v[i+1];
        }
        if (v[i+1]==0) {
            v[i+1]=v[i];
        }
    }
    pr(v[n-1]);
    // prr(v);
    
}



Measured memory_bytes: 1024
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, i;
		int s[] = new int[1000];
		double myu, bunsan;
		ArrayList<Double> sigma = new ArrayList<Double>();
		
		while(true){
			myu = 0;
			bunsan = 0;
			n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			for(i = 0; i < n; i++){
				s[i] = sc.nextInt();
				myu += s[i];
			}
			
			myu /= n;
			
			for(i = 0; i < n; i++){
				bunsan += Math.pow((s[i] - myu), 2);
			}
			bunsan /= n;
			sigma.add(Math.abs(Math.sqrt(bunsan)));
		}
		
		for(double d : sigma){
			System.out.println(d);
		}
	}
}

Measured memory_bytes: 31272
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.io.StreamTokenizer

fun main(args: Array<String> ) {
    val st = StreamTokenizer( BufferedReader( InputStreamReader( System.`in` ) ) )
    val n = st.nextInt()
    val a = IntArray( n + 2, { if ( it == 0 || it == n + 1 ) 0 else st.nextInt() } )
    var l = 0L
    for ( i in a.indices.take( n + 1 ) ) {
        l += Math.abs( a[i] - a[i + 1] )
    }
    val out = PrintWriter( System.out )
    for ( i in 1 .. n ) {
        out.println( l - Math.abs( a[i] - a[i - 1] ) - Math.abs( a[i] - a[i + 1] ) + Math.abs( a[i - 1] - a[i + 1] ) )
    }
    out.close()
}

private fun StreamTokenizer.nextInt(): Int {
    nextToken()
    return nval.toInt()
}


Measured memory_bytes: 41220
#Grouping
x, y = map(int, input().split())
list1 = [1,3,5,7,8,10,12]
list2 = [4,6,9,11]
list3 = [2]
if x in list1:
    i = 1
elif x in list2:
    i = 2
else:
    i = 3
if i == 1:
    if y in list1:
        print("Yes")
    else:
        print("No")
elif i == 2:
    if y in list2:
        print("Yes")
    else:
        print("No")
else:
    if y in list3:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

double n, d;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n >> d;
  cout << ceil(n / (2.0 * d + 1.0)) << endl;
  return 0;
}




Measured memory_bytes: 256
import itertools
k, s = map(int, input().split())

#data = [i for i in range(k + 1)]
# print(data)
#dd = itertools.product(data, repeat=3)
# print(dd)
#dd = list(dd)
#target = s / 3
ans = 0
if (k * 3 < s):

    pass
else:
    for x in range(0, k + 1):
        #temp = s - x
        # 2なら、（０、２）（１、１）（２、０）
        for y in range(0, k + 1):
            if (0 <= s - (x + y) <= k):
                ans += 1

print(ans)

'''
ans = 0
for i in dd:
    #print(sum(i))
    if (sum(i) == s):
        ans += 1

print(ans)
'''


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

#define INF INT_MAX/2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

   int n;
   cin>>n;
   vector<ll>a(n);
   for(int i=0;i<n;i++)cin>>a[i];

   ll min_0 = 0;
   ll now=0;
   for(int i=0;i<n;i++){
      now+=a[i];
      if(i%2==0){
         if(now<=0){
            min_0 += 1-now;
            now = 1;
         }
      }
      else{
         if(now>=0){
            min_0 += 1+now;
            now = -1;  
         }
      }
   }

   ll min_1 = 0;
   now = 0;
   for(int i=0;i<n;i++){
      now+=a[i];
      if(i%2==1){
         if(now<=0){
            min_1 += 1-now;
            now = 1;
         }
      }
      else{
         if(now>=0){
            min_1 += 1+now;
            now = -1;  
         }
      }
   }

   cout<<min(min_0,min_1)<<endl;
   return 0; 
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int k,a,b,answer;
  cin >> k >> a >> b;
  if(b-a > 2 && a < k){
    answer = ((k-a+1)/2)*b-((k-a+1)/2-1)*a+ ((k-a+1)%2);
  }else{
    answer = k+1;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<62)-1
#define MAX 1000000000
signed main(){
    int N,Q; cin>>N>>Q;
    vi A(N);
    rep(i,0,N) cin>>A[i];
    A.pb(INF);
    vii dp(2,vi(N+1));
    rep(i,0,N){
        dp[0][i+1]=dp[0][i];
        dp[1][i+1]=dp[1][i];
        dp[i%2][i+1]+=A[i];
    }
    rep(_,0,Q){
        int X; cin>>X;
        int left=0,right=MOD,memo=-1;
        while(left<right){
            int mid=(left+right)/2,Y=disup(A,X+mid)-dislow(A,X-mid),Z=N-disup(A,X+mid);
            if(abs(Y-Z)<=1){
                memo=mid;
                break;
            }
            if(Y>Z) right=mid;
            else left=mid;
        }
        int Y=disup(A,X+memo)-dislow(A,X-memo),Z=N-disup(A,X+memo);
        int P=disup(A,X+memo),Q=dislow(A,X-memo);
        int ans=dp[0][N]+dp[1][N]-dp[0][P]-dp[1][P];
        //cout<<ans<<" "<<memo<<endl;
        if(Y+1==Z){
            ans+=dp[1-N%2][max(0ll,Q-1)];
        }
        else if(Y==Z){
            ans+=dp[1-N%2][Q];
        }
        else{
            if(P>0&&A[P-1]-X>=X-A[Q]){
                ans+=A[P-1];
                ans+=dp[1-N%2][max(0ll,Q-1)];
            }
            else{
                ans+=A[Q];
                ans+=dp[1-N%2][max(0ll,Q-1)];
            }
        }
        cout<<ans<<endl;
    }
}


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

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

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

int main()
{
    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
    return 0;
}

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

const int maxn = 1e6 + 10;
struct edge {
	int from, to, cost;
	edge(int _from, int _to, int _cost) : from(_from), to(_to), cost(_cost) {}
	bool operator < (const edge &other) const { return cost < other.cost; }
};
vector<edge> es;
int n, father[maxn];
pair<int, int> x[maxn], y[maxn];

int find(int x) {
	if (x == father[x]) {
		return father[x];
	} else {
		return father[x] = find(father[x]);
	}
}

int unite(int x, int y) {
	x = find(x);
	y = find(y);
	father[x] = y;
}

long long kruskal() {
	sort(es.begin(), es.end());
	long long res = 0;
	int _count = 0;
	for (int i = 0; i < es.size(); i++) {
		if (find(es[i].from) != find(es[i].to)) {
			unite(es[i].from, es[i].to);
			res += es[i].cost;
			_count++;
		}
		if (_count == n - 1) break;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x[i].first >> y[i].first;
		x[i].second = y[i].second = i;
	}
	for (int i = 1; i <= n; i++) {
		father[i] = i;
	}
	sort(x + 1, x + n + 1);
	sort(y + 1, y + n + 1);
	for (int i = 2; i <= n; i++) {
		es.push_back(edge(x[i - 1].second, x[i].second, x[i].first - x[i - 1].first));
		es.push_back(edge(y[i - 1].second, y[i].second, y[i].first - y[i - 1].first));
	}
	cout << kruskal() << endl;
	return 0;
}

Measured memory_bytes: 11892
N, M = map(int, input().split())
ferry = [list(map(int, input().split())) for i in range(M)]

from_1 = [0 for i in range(N)]
to_N = [0 for i in range(N)]

for f in ferry:
    if f[0]==1:
        from_1[f[1]-1] = 1
    if f[1]==N:
        to_N[f[0]-1] = 1


flag = 0

for k in range(N):
    if from_1[k]==1 and to_N[k]==1:
        print('POSSIBLE')
        flag = 1
        break

if flag==0:
    print('IMPOSSIBLE')


Measured memory_bytes: 55040
#include<stdio.h>
int main()
{
    int i,j,k,l,m;

    scanf("%d %d",&m,&k);

    l=m+k;
    if(m%3==0)
    {
        printf("Possible");


    }
     else if(k%3==0)

            printf("Possible");
    else if (l%3==0)
       printf("Possible");
       else
        printf("Impossible");
    return 0;
}



Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
    char s[10];
    scanf("%s",s);
    int a=1;
    if(s[0]==89)
    {
        if(s[1]==65)
        {
            if(s[2]==75)
            {
                if(s[3]==73)
                {
                    a=2;
                }
            }
        }
    }
    if(a==1)
      printf("No");
    else if(a==2)
      printf("Yes");
}


Measured memory_bytes: 128
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize, d: i64,
        xy: [(i64, i64); n],
    }
    let ans = xy.iter().filter(|&(x, y)| x * x + y * y <= d * d).count();
    println!("{}", ans);
}


Measured memory_bytes: 7888
S = input()
N = len(S) - 1

def add(n, s):
    if n == 0:
        tmp = 0
        for i in s.split('+'):
            tmp += int(i)
        return tmp
    else:
        st = s[:n] + '+' + s[n:]
        return add(n-1, st) + add(n-1, s)

print(add(N, S))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

struct edge{
    int to;
    ll cap;
    int rev;
};

const int MAX_V = 1e3;
vector<edge> es[MAX_V];
int d[MAX_V], pos[MAX_V];

void add_edge(int from, int to, ll cap){
    edge e1 = {to, cap, (int)es[to].size()}, e2 = {from, 0, (int)es[from].size()};
    es[from].emplace_back(e1), es[to].emplace_back(e2);
}

//sから各点への最短距離をbfsで計算する
void bfs(int s){
    fill(d, d+MAX_V, -1);
    queue<int> que;
    d[s] = 0;
    que.push(s);
    while(!que.empty()){
        int i = que.front();
        que.pop();
        for(auto &e: es[i]){
            if(e.cap > 0 && d[e.to] < 0){
                d[e.to] = d[i]+1;
                que.push(e.to);
            }
        }
    }
}

//最短距離での増加パスをdfsで探す
ll dfs(int now, int goal, ll flow){
    if(now == goal) return flow;
    for(int &i = pos[now]; i < es[now].size(); i++){
        edge &e = es[now][i];
        if(e.cap > 0 && d[now] < d[e.to]){
            ll f = dfs(e.to, goal, min(flow, e.cap));
            if(f > 0){
                e.cap -= f;
                es[e.to][e.rev].cap += f;
                return f;
            }
        }
    }
    return 0;
}

//sからtへの最大流を最大でO(V^2*E)で計算
ll max_flow(int s, int t){
    ll flow = 0;
    while(true){
        bfs(s);
        //sからtへの経路が存在しないとき
        if(d[t] < 0) break;
        fill(pos, pos+MAX_V, 0);
        while(true){
            ll f = dfs(s, t, INF);
            if(f == 0) break;
            flow += f;
        }
    }
    return flow;
}

int main(){
    int N; cin >> N;
    rep2(i, 1, N){
        rep2(j, 2, N/i) add_edge(i, i*j, INF);
    }
    ll ans = 0;
    rep2(i, 1, N){
        ll A; cin >> A;
        if(A > 0) add_edge(i, N+1, A), ans += A;
        else add_edge(0, i, -A);
    }
    cout << ans-max_flow(0, N+1) << endl;
}

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

int main()
{
	int a,b,c,k,sum=0;
	cin>>a>>b>>c>>k;
	while(b<=a)
	{
		sum++;
		b+=b;
	}
	while(c<=b)
	{
		sum++;
		c+=c;
	}
	if(sum<=k)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forv(v,a) for(auto &v:a)
#define fi first
#define se second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(a) a.begin(),a.end()
int re(){int x=0; char c; bool neg=false;while(c!='-'&&(c<'0'||'9'<c)) c=getchar();if (c=='-'){neg=true; c=getchar();}while ('0'<=c && c<='9'){x=x*10+c-'0';c=getchar();}if (neg) x=-x;return x;}
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int ran(int l, int r) {return l+rng()%(r-l+1);}
typedef long long ll;
const int N=100010;
int n,m,kq;
vi ke[N];
int f[N];
bool dd[N],pa[N];
void dfs(int u)
{
    if (dd[u]) return;
    dd[u]=true;
    forv(v,ke[u])
    {
        dfs(v);
        f[u]=max(f[v]+1,f[u]);
    }
    kq=max(kq,f[u]);
}
int main()
{
    //freopen("g.inp","r",stdin);
    cin>>n>>m;
    forinc(i,1,m)
    {
        int u,v; cin>>u>>v;
        ke[u].pb(v); pa[v]=true;
    }
    forinc(i,1,n) if (!dd[i] && !pa[i]) dfs(i);
    cout<<kq;
}


Measured memory_bytes: 9472
n=int(input())
a=[]
b=[]
c=[]

for i in range(n):
    a.append(str(input()))
m=int(input())
for s in range(m):
    b.append(str(input()))
for k in range(n):
    c.append(a.count(a[k])-b.count(a[k]))
for l in range(m):
    c.append(a.count(b[l]) - b.count(b[l]))
c.append(0)
print(max(c))

Measured memory_bytes: 3064
require 'date'
f=nil;while(a,b=gets.split.map(&:to_i))!=[0,0]do
	if f then puts end;f=1
	z=a.step(b).select{|i|Date.leap?(i)}
	if z.size==0 then puts'NA'else z.each{|e|p e}end
end

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main () {
	cin >> a >> b >> c;
if(a == b) {
	cout << c << endl;
}
else if (a==c){
	cout << b << endl;
}
else if (b == c){
	cout << a << endl;
}
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
using namespace std;
 


int main() 
{ 
    string s;
    cin>>s;
    int q;
    cin>>q;
    int flag=0;
    int a=0,b=0,c=0;
    pan(i,q){
        int t,f1;
        string f2;
        cin>>t;
        if(t==1){
            // reverse(s.begin(),s.end());
            flag++;
        }
        if(t==2) {
            cin>>f1>>f2;
            // int n=s.size();
            if(flag%2==1){
                if(f1==1) s.insert(s.size(),f2);
                else if(f1==2) s.insert(0,f2);
            }
            else{
                if(f1==1) s.insert(0,f2);
                else if(f1==2) s.insert(s.size(),f2);
            }
        }
        /*if(i==q-1){
            if((t==2 && a==1) || t==a==1){ 
                reverse(s.begin(),s.end());
                cout<<s;
            }
            else cout<<s;
        }
        a=t;*/
    }
    if(flag%2==0) cout<<s;
    else {
        reverse(s.begin(),s.end());
        cout<<s;
    }
} 


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    vector<bool> dp(100);
    dp.at(0) = false, dp.at(1) = false, dp.at(2) = false, dp.at(3) = true,dp.at(4) = false, dp.at(5) = false, dp.at(6) = true;
    for (int i = 7; i < 100; i++) {
        dp.at(i) = dp.at(i - 4) || dp.at(i - 7);
    }
    if (dp.at(N - 1)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray()[1];
            var ls = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            var dis = 0;
            var count = 0;
            for(var i=0;dis<=x;i++)
            {
                count++;
                if (ls.Count() <= i) break;
                dis += ls[i];
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13396
n, h = map(int, input().split())
a_ls = []
b_ls = []

for i in range(n):
    a, b = map(int, input().split())
    a_ls.append(a)
    b_ls.append(b)

a_ls.sort()
a_ls.reverse()

b_ls.sort()
b_ls.reverse()

tmp = 0
cnt = 0

for i in range(n):
    dmg = b_ls[i]
    if dmg < a_ls[0]:
        break
    else:
        cnt += 1
        tmp += dmg
        if tmp >= h:
            print(cnt)
            exit()

left = h - tmp

cnt += (left + a_ls[0] - 1) // a_ls[0]
print(cnt)


Measured memory_bytes: 11296
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

N,X = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
dist = []

if X == 1:
    print(abs(x[0]-X))
    exit()

tmp = []
for i in range(N):
    tmp.append(abs(x[i]-X))
mindist = min(tmp)
for i in range(N-1):
    dist.append(abs(x[i]-x[i+1]))

ans = mindist

for i in range(N-1):
    ans = gcd(ans,dist[i])

print(ans)

Measured memory_bytes: 15020
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned char uchar;
#define umap unordered_map
const static ull INVALID_DIGIT = ~(ull)0;

int main()
{
    int P, Q, R;

    cin >> P >> Q >> R;

    cout << std::min(P + Q, std::min(Q + R, P + R)) << endl;

    return 0;
}

Measured memory_bytes: 256
mod = 10**9 + 7
def solve():
    x, k, d = map(int, input().split())
    t = min(abs(x) // d, k)
    if x < 0:
        x += t * d
    else:
        x -= t * d
    k -= t
    k %= 2
    ans = x
    if k > 0:
        ans = min(abs(x + d), abs(x - d))
    else:
        ans = abs(x)
    print(abs(ans))
t = 1
while t > 0:
    solve()
    t -= 1

Measured memory_bytes: 61728
import sys
input = sys.stdin.readline
N,M,P = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]

es = [[] for _ in range(N)]
rs = [[] for _ in range(N)]
for a,b,c in ABC:
    a,b = a-1,b-1
    es[a].append(b)
    rs[b].append(a)

stack = [0]
vis_go = set([0])
while stack:
    v = stack.pop()
    for to in es[v]:
        if to in vis_go: continue
        vis_go.add(to)
        stack.append(to)
stack = [N-1]
vis_bk = set([N-1])
while stack:
    v = stack.pop()
    for to in rs[v]:
        if to in vis_bk: continue
        vis_bk.add(to)
        stack.append(to)
use = vis_go & vis_bk

INF = float('inf')
dist = [INF] * N
dist[0] = 0
for i in range(len(use)):
    for a,b,c in ABC:
        a,b,c = a-1,b-1,P-c
        if a not in use or b not in use: continue
        if dist[b] > dist[a] + c:
            dist[b] = dist[a] + c
            if i==len(use)-1:
                print(-1)
                exit()
print(max(0,-dist[-1]))

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

int main()
{
    int n;
    cin >> n;
    long long sum = 0;
    for(int i = 1; i <= n; i++) {
        long long k = n/i;
        sum += i*k*(k+1)/2;
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;


int main() {

    int a, b, q;
    cin >> a >> b >> q;

    vector<ll> sha_list(a);
    vector<ll> tera_list(b);

    rep(i, a) {
        ll s;
        cin >> s;
        sha_list[i] = s;
    }

    rep(i, b) {
        ll t;
        cin >> t;
        tera_list[i] = t;
    }

    rep(i, q) {
        ll x;
        cin >> x;

        auto sha_left = MINF;
        auto sha_right = INF;
        auto sha_it = upper_bound(sha_list.begin(), sha_list.end(), x);
        if (sha_list[0] >= x) {
            sha_right = sha_list[0];
        } else if (sha_list[a - 1] <= x) {
            sha_left = sha_list[a - 1];
        } else if (*sha_it == x) {
            sha_left = *sha_it;
            sha_right = *sha_it;
        } else {
            sha_right = *sha_it;
            sha_left = *(sha_it - 1);
        }


        auto tera_left = MINF;
        auto tera_right = INF;
        auto tera_it = upper_bound(tera_list.begin(), tera_list.end(), x);
        if (tera_list[0] >= x) {
            tera_right = tera_list[0];
        } else if (tera_list[b - 1] <= x) {
            tera_left = tera_list[b - 1];
        } else if (*tera_it == x) {
            tera_left = *tera_it;
            tera_right = *tera_it;
        } else {
            tera_right = *tera_it;
            tera_left = *(tera_it - 1);
        }

        ll ans = INF;
        {
            // 寺右 神社右
            ll now = max(tera_right, sha_right) - x;
            ans = min(ans, now);
        }
        {
            // 寺右 神社左
            ll sha_dis = x - sha_left;
            ll tera_dis = tera_right - x;
            ll back = min(sha_dis, tera_dis);

            ll now = sha_dis + tera_dis + back;
            ans = min(ans, now);
        }
        {
            // 寺左 神社右
            ll sha_dis = sha_right - x;
            ll tera_dis = x - tera_left;
            ll back = min(sha_dis, tera_dis);

            ll now = sha_dis + tera_dis + back;
            ans = min(ans, now);
        }
        {
            // 寺左 神社左
            ll now = x - min(tera_left, sha_left);
            ans = min(ans, now);
        }

        cout << ans << endl;

    }

}



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

int main() {
    ll A, B, C, D, T, M, N;
    cin >> A >> B >> C >> D;

    if (C > D) {
        M = C;
        N = D;
    } else {
        M = D;
        N = C;
    }

    while (T = M % N) {
        M = N;
        N = T;
    }

    ll G = N;
    ll L = (C * D) / G;

    ll ans_B = B - (B / C) - (B / D) + (B / L);
    ll ans_A = (A - 1) - ((A - 1) / C) - ((A - 1) / D) + ((A - 1) / L);

    cout << ans_B - ans_A << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using sqvec = vector<vector<int>>;
int main(){
  string s,t;
  cin >> s;
  cin >> t;
  string tmp;
  if(s.size() >= t.size()){
    tmp = s; s = t; t = tmp;
  }
  int dp[s.size()+1][t.size()+1];
  for(int i = 0; i < t.size()+1; i++) dp[0][i] = 0;
  for(int i = 0; i < s.size()+1; i++) dp[i][0] = 0;
  
  
  for(int i = 1; i < s.size() + 1 ; i++){
    for(int j = 1; j < t.size() + 1; j ++){
      if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
      else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
    }
  }
  int target = dp[s.size()][t.size()];
  int i = s.size()-1;
  int j = t.size()-1;

  string ans = "";
  while(target > 0){
    if(s[i] == t[j]){
      ans += s[i];
      i--;
      j--;
      target--;
    }else if(dp[i+1][j+1] == dp[i+1][j]){
      j--;
    }else{
      i--;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


Measured memory_bytes: 35456