akhauriyash/Code-Regression huggingface dataset:
class BinarySearchTree:

    def __init__(self):
        self.root = None

    def insert(self, z):
        p = None
        x = self.root
        while x != None:
            p = x
            if z.key < x.key : x = x.left
            else             : x = x.right
        z.p = p
        if p == None      : self.root = z
        elif z.key < p.key: p.left  = z
        else              : p.right = z

    def get_inorder_list(self):
        def _get_inorder_list(root):
            l = root.left
            r = root.right
            if l: yield from _get_inorder_list(l)
            yield root.key
            if r: yield from _get_inorder_list(r)
        yield from _get_inorder_list(self.root)

    def get_preorder_list(self):
        def _get_preorder_list(root):
            l = root.left
            r = root.right
            yield root.key
            if l: yield from _get_preorder_list(l)
            if r: yield from _get_preorder_list(r)
        yield from _get_preorder_list(self.root)

    def find(self, k):
        z = self.root
        while z:
            if k == z.key: return z
            if k <  z.key: z = z.left
            else         : z = z.right
        return None

    def delete(self, k):
        def ldelete(z):
            if z.left and z.right:
                c = z.right
                while c:
                    next_node = c
                    c = c.left if c.left else c.right
                z_key_n = next_node.key
                ldelete(next_node)
                z.key = z_key_n
            else:
                c = z.left if z.left else z.right
                if   z.p == None    : self.root = c
                elif z.key < z.p.key: z.p.left  = c
                else                : z.p.right = c
                if c: c.p = z.p
        z = self.find(k)
        if z: ldelete(z)
# end class BinarySearchTree:

class Node:
    def __init__(self, k):
        self.key = k
        self.p = None
        self.left = None
        self.right = None
#end class Node:
       

if __name__=='__main__':
    m = int(input())

    T = BinarySearchTree()
    for _ in range(m):        
        op = input().split()
        if   op[0] == 'insert': T.insert( Node(int(op[1])) )
        elif op[0] == 'delete': T.delete( int(op[1]) )
        elif op[0] == 'find'  : print("yes" if T.find(int(op[1])) else "no")
        else:
            print("",*T.get_inorder_list())
            print("",*T.get_preorder_list())

Measured memory_bytes: 130740
import bisect
import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n = getint()
values = getints()

def solve(values, prev):
    res = 0
    for v in values:
        s = prev + v
        add = 0
        if prev > 0 and s >= 0:
            add = -s - 1
        if prev < 0 and s <= 0:
            add = -s + 1
        res += abs(add)
        prev = s + add
    return res

res1, res2 = 0, 0
if values[0] <= 0:
    add = abs(values[0]) + 1
    res1 = solve(values[1:], values[0] + add) + abs(add)
    add = -1 if values[0] == 0 else 0
    res2 = solve(values[1:], values[0] + add) + abs(add)
else:
    add = 1 if values[0] == 0 else 0
    res1 = solve(values[1:], values[0] + add) + abs(add)
    add = -(values[0] + 1)
    res2 = solve(values[1:], values[0] + add) + abs(add)

print(min(res1, res2))


Measured memory_bytes: 63216
n = int(input())
a = []
for i in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        a.append(True)
    else:
        a.append(False)
a.append(False)
a.append(False)
for h, i in enumerate(a):
    if i == True:
        if a[h+1] and a[h+2]:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 9088
N=int(input())
A=sorted(int(input())for _ in[0]*N)
n=N//2-1
b=A[n+1]
print(2*sum(A[n+2:])-2*sum(A[:n])+b-A[n]-(min(A[n]+A[n+2],2*b)if N%2>0 else 0))

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if ((a+b) < (c+d)){
  	cout << "Right" << endl;
  }
  else if((a+b) > (c+d)){
  	cout << "Left" << endl;
  } 
  else{
  	cout << "Balanced" << endl;
  }
}
  


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

int k,q;
ll d[5005];
ll times[5005];
int main(){
	cin>>k>>q;
	
	for (int x=0;x<k;x++) cin>>d[x];
	
	
	int len,seed,mod;
	while (q--){
		cin>>len>>seed>>mod;
		
		len--;
		for (int x=0;x<k;x++) times[x]=len/k+(len%k>x);
		
		ll total=seed%mod;
		ll ans=0;
		
		for (int x=0;x<k;x++){
			total+=times[x]*(d[x]%mod);
			if (d[x]%mod) ans+=times[x];
		}
		
		ans-=total/mod;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n,k;
    cin>>n>>k;
    int l[k],r[k];
    for(int i=0;i<k;i++){
        cin>>l[i]>>r[i];
        r[i]++;
    }
    ll dp[n+1]={};
    ll mod = 998244353;
    dp[1] = 1;
    for(int i=1;i<=n;i++){
        dp[i] += dp[i-1];
        dp[i] %= mod;
        for(int j=0;j<k;j++){
            if(i+l[j] <= n) (dp[i+l[j]] += dp[i]) %= mod;
            if(i+r[j] <= n) (dp[i+r[j]] += mod - dp[i] ) %= mod;
        }
        //cerr << dp[i] << endl;
    }
    cout << (dp[n] + mod - dp[n-1])%mod << endl;
}

Measured memory_bytes: 5212
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i;
	int a;
	int array[100];
    int syou, amari;
	
	while (1){
		
        scanf("%d", &a);
        if (a == 0){
            break;
        }
        
		i = 0;
		
        memset(array, 0, sizeof(array));
        
        while (a != 0 || array[i + 1] != 0){
            syou = a / -10;
            amari = a - syou * -10;
            array[i] += amari;
            if (array[i] < 0){
                array[i] += 10;
                array[i + 1] += 1;
            }
            else if (array[i] > 9){
                array[i] -= 10;
                array[i + 1] -= 1;
            }
            a /= -10;
			i++;
		}
        
        if (array[i] != 0){
            if (array[i] < 0){
                array[i] += 10;
                array[i + 1] += 1;
                i++;
            }
            i++;
        }
        while (i--){
            printf("%d", array[i]);
        }
        printf("\n");
	}
    
	return (0);
	
}

Measured memory_bytes: 0
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()

	x := lowerBound(0, n, func(x int) bool {
		return x*x+x >= 2*n
	})

	for n != 0 {
		println(x)
		n -= x
		x--
		if n < x {
			x = n
		}
	}
}

func lowerBound(low, high int, f func(int) bool) int {
	if low+1 == high {
		return high
	}
	m := (low + high) / 2
	if f(m) {
		return lowerBound(low, m, f)
	} else {
		return lowerBound(m, high, f)
	}
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <vector>

using namespace std;
typedef long long ll;
template <class T = ll>
T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T>
void print(T &x) {
    cout << x << "\n";
}
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define reps(x, c) for (auto x : c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a)
#define mp(a, b) make_pair((a), (b))
#define pl pair<ll, ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cerr << #x "=" << (x) << "\n"
#define dbgv(x) \
    cerr << #x << "\n"; \
    reps(y, x) { cerr << y << " "; } \
    cerr << "\n"

int main() {
    vector<int> a(5);
    rep(i, 5) { cin >> a[i]; }
    int k = in();
    if (a[4] - a[0] > k) {
        print(":(");
        return 0;
    }
    print("Yay!");
    return 0;
}

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

const int MAXN = 200005;

int n, a[MAXN];

bool can(int c){
	map <int, int> mp;
	for(int i = 0; i < n; i++){
		if(a[i] <= a[i - 1]){
			auto d = mp.lower_bound(a[i]);
			while(d != mp.end()){
				auto nxt = next(d);
				mp.erase(d);
				d = nxt;
			}
			
			int x = a[i] - 1;
			while(true){
				if(x < 0)return false;
				
				if(mp[x] + 1 < c){
					mp[x]++;
					break;
				}else{
					mp.erase(x);
					x--;
				}
			}
		}
	}
	return true;
}
int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	
	bool ok = true;
	for(int i = 1; i < n; i++){
		if(a[i] <= a[i - 1]){
			ok = false;
			break;
		}
	}
	
	if(ok){
		printf("1\n");
		return 0;
	}
	
	int L = 2, R = n;
	while(L < R){
		int mid = (L + R) / 2;
		if(can(mid))R = mid;
		else L = mid + 1;
	}
	printf("%d\n", L);
	
	return 0;
}


Measured memory_bytes: 4568
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>

using namespace std;

inline bool ok(const string & v){
    for (int i = 1; i < v.size(); i++){
        if (v[i] != v[0]) return false;
    }
    return true;
};

inline char other(char a, char b){
    if (a>b)swap(a, b);
    if (a == 'g' && b == 'r'){
        return 'b';
    }
    if (a == 'b' && b == 'g'){
        return 'r';
    }
    if (a == 'b' && b == 'r'){
        return 'g';
    }
    throw "";
}

struct state {
    string str;
    int n;
};

int main(){
    string s;
    while (cin >> s, s != "0"){
        queue<state> q;
        set<string> dp;
        q.push({ s, 0 });

        int ans = -1;
        while (q.size()){
            state sta = q.front();
            q.pop();
            string & sv = sta.str;
            auto pr = dp.insert(sv);
            if (!pr.second){
                continue;
            }
            if (ok(sv)){
                ans = sta.n;
                break;
            }
            for (int i = 1; i < sv.size(); i++){
                if (sv[i] != sv[i - 1]){
                    char a = sv[i];
                    char b = sv[i - 1];
                    sv[i] = sv[i - 1] = other(a, b);
                    q.push({ sv, sta.n + 1 });
                    sv[i] = a;
                    sv[i - 1] = b;
                }
            }
        }
        if (ans == -1){
            cout << "NA" << endl;
        }
        else{
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 2948
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#include <math.h> /* M_PI */
int main()
{
    int r;
    cin >> r;
    cout << 2 * r * M_PI;
}


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

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
template<class T, class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void){
    string s,t;cin>>s>>t;
    map<char,char> p,q;
    rep(i, s.size()){
        char a=s[i],b=t[i];
        if(p.find(a)!=p.end()){
            if(p[a]!=b){
                cout << "No" << endl;
                return 0;
            }
        }else{
            p[a]=b;
        }
    }
    rep(i,t.size()){
        if(q.find(t[i])!=q.end()){
            if(q[t[i]]!=s[i]){
                cout << "No" << endl;
                return 0;
            }
        }else q[t[i]]=s[i];
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 776
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int n, W;
int w[maxn], v[maxn];

vector<int> ve[5];
ll ans = 0;
void solve(int pos, ll left, ll sum) {
    if (pos == 4) {
        ans = max(ans, sum);
        return ;
    }
    ll prefix = 0;
    ll amount = 0;
    solve(pos + 1, left, sum);
    for (int i = 0; i < ve[pos].size(); i++) {
        prefix += 1LL * ve[pos][i];
        amount += w[1] + pos;
        if (left >= amount) solve(pos + 1, left - amount, sum + prefix);
        else break;
    }
}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    scanf("%d%d", &n, &W);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &w[i], &v[i]);
        ve[w[i] - w[1]].pb(v[i]);
    }
    for (int i = 0; i < 4; i++) {
        sort(ve[i].begin(), ve[i].end(), greater<int>());
    }
    solve(0, W, 0);
    printf("%lld\n", ans);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 256
n,x = map(int, input().split())

pl = [1]
pa = [1]

for i in range(n):
    tmpp = pl[-1]
    tmpa = pa[-1]
    pl.append(tmpp*2+1)
    pa.append(tmpa*2+3)

def largest(n,x):
    if x <= 0:
        return 0
    else:
        if n <= 0:
            if x >= 4:
                return 3
            else:
                return x
        else:
            if x > pa[n]:
                return pl[n] + 1 + largest(n-1, x-2-pa[n])
            elif x == pa[n]:
                return pl[n]
            else:
                return largest(n-1,x-1)

print(largest(n,x))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int mex=100001;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++)

int main()
{
    string s;
    cin>>s;
    int c1=0,c2=0;
    fo(i,0,sz(s))
    if(s[i]=='A') c1++;
    else c2++;
    if(c1&&c2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] a = new int[n];
		for (int i = 1; i < n; i++) {
			if(s[i-1]=='A'&&s[i]=='C') a[i] += 1;
			a[i] += a[i-1];
		}
		int l = 0, r = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			l = Integer.parseInt(sc.next())-1;
			r = Integer.parseInt(sc.next())-1;
			if(l == 0) {
				sb.append(a[r]);
			}else {
				n = (s[l]=='C'&&s[l-1]=='A')?1:0;
				sb.append(a[r]-a[l-1]-n);
			}
			sb.append('\n');
		}
		System.out.println(new String(sb));
	}
}

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

// input
int H, W, K;
int sx, sy, ex, ey;
vector<string> C;

const int INF = 1e9;
int n;
vector<bool> poss;


void input() {
    cin >> H >> W >> K;
    cin >> sx >> sy >> ex >> ey;
    sx--; sy--; ex--; ey--;
    C = vector<string>(H);
    rep(i, H) cin >> C[i];
}


int to_id(int x, int y, int d) {
    return 4 * (W * x + y) + d;
}


void set_init() {
    n = 4 * H * W;
    poss = vector<bool>(n, true);
    rep(i, H) rep(j, W) {
        if (C[i][j] == '@') {
            rep(k, 4) poss[to_id(i, j, k)] = false;
        }
    }
}


int forward(int i) {
    int x = i / 4 / W;
    int y = i / 4 - W * x;
    int v = i % 4;
    if (v == 0 && x != 0) return i - 4 * W;
    if (v == 1 && y != W - 1) return i + 4;
    if (v == 2 && x != H - 1) return i + 4 * W;
    if (v == 3 && y != 0) return i - 4;
    return INF;
}


int solve() {
    vector<P> w;
    vector<bool> dicision(n, false);
    priority_queue<pair<P, int>, vector<pair<P, int>>, greater<pair<P, int>>> pq;
    w = vector<P>(n, make_pair(INF, 0));
    rep(i, 4) {
        int id = to_id(sx, sy, i);
        w[id] = make_pair(1, 0);
        pq.push(make_pair(make_pair(1, 0), id));
    }
    while (!pq.empty()) {
        int cost = pq.top().first.first;
        int k = pq.top().first.second;
        int i = pq.top().second;
        pq.pop();
        if (dicision[i]) continue;
        dicision[i] = true;
        int j = forward(i);
        if (j != INF && poss[j]) {
            P p;
            if (k < K) p = make_pair(cost, k + 1);
            else p = make_pair(cost + 1, 1);
            if (p < w[j]) {
                w[j] = p;
                pq.push(make_pair(p, j));
            }
        }
        P p = make_pair(cost + 1, 0);
        rep(d, 4) {
            j = i - i % 4 + d;
            if (p < w[j]) {
                w[j] = p;
                pq.push(make_pair(p, j));
            }
        }
    }
    int ans = INF;
    rep(d, 4) ans = min(ans, w[to_id(ex, ey, d)].first);
    if (ans == INF) return -1;
    else return ans;
}


int main() {
    input();
    set_init();
    int ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 43004
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int s = n % 10;
    if(s == 2 || s == 4 || s == 5 || s == 7 || s == 9)puts("hon");
    else if(s == 3)puts("bon");
    else puts("pon");
}

Measured memory_bytes: 1616
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	char s[4+2];


	while(scanf("%4[0-9]\n", s)==1)
	{
		int ans=1;

		for(int i=1;i<4;i++)
		{
			if(s[i]==s[i-1]) ans=0;
		}
		printf("%s\n", ans?"Good":"Bad");
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include<queue>

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n; ++i)
#define ALL(a) (a).begin(),(a).end()
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

bool dpx[8010][20000] = {false};
bool dpy[8010][20000] = {false};

int main(){
    string s;
    int x, y;
    cin >> s;
    cin >> x >> y;

    bool flag = true;
    vector<ll> vx, vy;
    rep(i, s.size()){
        int fc = 0;
        while(s[i] == 'F')fc++, i++;
        if(flag)vx.push_back(fc), flag = false;
        else vy.push_back(fc), flag = true;
    }

    dpx[0][8000] = true;
    dpy[0][8000] = true;
    rep(i,vx.size())rep(j, 16020){
        if(dpx[i][j]){
            dpx[i+1][j+vx[i]] = true;
            if(j >= vx[i] && i != 0)dpx[i+1][j-vx[i]] = true;
        }
    }
    rep(i,vy.size())rep(j, 16020){
        if(dpy[i][j]){
            dpy[i+1][j+vy[i]] = true;
            if(j >= vy[i])dpy[i+1][j-vy[i]] = true;
        }
    }
    if (dpx[vx.size()][x+8000] && dpy[vy.size()][y+8000])cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 156416
#include <cstdio>
using namespace std;
int main(){
	int n,sum=0,i;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=1;i*i<=n;i++){
			if(n!=i){if(n%i==0){
					sum+=i;
					if(i!=n/i){
						sum+=n/i;}
					if(sum>2*n){
						break;
					}
			}}}
		if(sum<2*n){
			printf("deficient number\n");
		}else if(sum==2*n){
			printf("perfect number\n");
		}else{
			printf("abundant number\n");
		}
		sum=0;
	}
	return 0;
}

	

Measured memory_bytes: 1012
#include <bits/stdc++.h>
#define N 505
#define C 35
#define INF 1e9
using namespace std;
int main(){
	long long n,k,d[C][C],c[N][N],i,j,l,r,s,ans=INF,num[3];
	vector<pair<long long,long long> > to[3];
	cin>>n>>k;
	for(i=1;i<=k;i++)
	{
		for(j=1;j<=k;j++)
		{
			cin>>d[i][j];
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			cin>>c[i][j];
		}
	}
	for(i=1;i<=k;i++)
	{
		memset(num,0,sizeof(num));
		for(j=0;j<n;j++)
		{
			for(l=0;l<n;l++)
			{
				num[(j+l)%3]+=d[c[j][l]][i];
			}
		}
		for(j=0;j<3;j++)
		{
			to[j].push_back(make_pair(num[j],i));
		}
	}
	for(i=0;i<3;i++)
		sort(to[i].begin(),to[i].end());
	for(i=0;i<to[0].size();i++)
	{
		for(j=0;j<to[1].size();j++)
		{
			if(to[0][i].second==to[1][j].second)
			{
				continue;
			}
			for(l=0;l<to[2].size();l++)
			{
				if(to[1][j].second!=to[2][l].second&&to[2][l].second!=to[0][i].second)
				{
					ans=min(ans,to[0][i].first+to[1][j].first+to[2][l].first);
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

vector<vector<int>> g;
vector<bool> visit;
int ans = 0;


int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    g.resize(n);
    visit.resize(n);
    REP(i,m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);        
    }

    REP(i,n) {
        if (visit[i]) continue;
        set<int> s{i};
        vector<int> next(g[i]);
        while(!next.empty()) {
            vector<int> tmp;
            swap(tmp,next);
            for (auto x:tmp) {
                auto ret = s.insert(x);
                if (ret.second) {
                    for (auto y:g[x]) {
                        next.push_back(y);
                    }
                }
            }
        }
        for (auto x:s) visit[x] = true;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11640
#include <stdio.h>

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

    if(scanf("%d %d %d", &a, &b, &c) != 3){
        return 0;
    }

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

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

int main() {
  string S;
  int W;
  cin >> S >> W;
  int N = S.size();
  for (int i = 0; i < N;) {
    cout << S.at(i);
    i += W;
  }
  cout << "\n";
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int x, y;
	cin >> x >> y;
	vector<int> v;
	if (x <= y) v.push_back(y - x);
	if (-x <= y) v.push_back(1 + y + x);
	if (x <= -y) v.push_back(1 - y - x);
	if (-x <= -y) v.push_back(2 - y + x);
	cout << *min_element(v.begin(), v.end()) << endl;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
ll ppow(ll x, ll n) {
	ll ans = 1;
	while (n > 0) {
		if ((n & 1) == 1)ans = ans * x;
		x = x * x;
		n >>= 1;
		x %= mod;
		ans %= mod;
	}
	return ans;
}
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll sz, fact[N], inv[N];
void setinv() {
	fact[0] = 1; inv[0] = 1;
	for (int i = 1; i <= sz; i++) {
		fact[i] = (fact[i - 1] * i) % mod;  //階乗を求める
		inv[i] = ppow(fact[i], (ll)mod - 2) % mod; // フェルマーの小定理で逆元を求める
	}
}
ll conv(ll r) {//nCr
	return fact[sz] * inv[r] % mod * inv[sz - r] % mod;
}
int d[1000][1000];
void reset() {
	rep(i, 1000)rep(j, 1000)d[i][j] = INF;
}
int main() {
	int h, w, n;
	pp s, g, pos[10];
	cin >> h >> w >> n;
	char m[1010][1010];
	rep(i, h)rep(j, w) {
		cin >> m[i][j];
		if (m[i][j] == 'S')pos[0] = pp{ i,j };
		if (m[i][j] == char('0' + n - 1))g = pp{ i,j };
		if (m[i][j] >= '0'&&m[i][j] <= '9')pos[m[i][j] - '0'] = pp{ i,j };
	}
	int ans = 0;
	rep(i, n) {
		reset();
		queue<pp>q; q.push(pos[i]);
		d[pos[i].fi][pos[i].se] = 0;
		while (!q.empty()) {
			pp p = q.front(); q.pop();
			if (p == pos[i + 1]) { ans += d[p.fi][p.se]; break; }
			if (p.fi > 0 && m[p.fi - 1][p.se] != 'X'&&d[p.fi - 1][p.se] == INF) { q.push(pp{ p.fi - 1,p.se }); d[p.fi - 1][p.se] = d[p.fi][p.se] + 1; }
			if (p.fi < h - 1 && m[p.fi + 1][p.se] != 'X'&&d[p.fi + 1][p.se] == INF) { q.push(pp{ p.fi + 1,p.se }); d[p.fi + 1][p.se] = d[p.fi][p.se] + 1; }
			if (p.se > 0 && m[p.fi][p.se - 1] != 'X'&&d[p.fi][p.se - 1] == INF) { q.push(pp{ p.fi,p.se - 1 }); d[p.fi][p.se - 1] = d[p.fi][p.se] + 1; }
			if (p.se < w - 1 && m[p.fi][p.se+1] != 'X'&&d[p.fi][p.se+1] == INF) { q.push(pp{ p.fi,p.se+1 }); d[p.fi][p.se+1] = d[p.fi][p.se] + 1; }
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 8040
#include<cstdio>
int main(){
  int i;
  int a[11]={1},n;
  char s[9]="01235789";
  for(i=1;i<11;++i)
    a[i]=a[i-1]*8;
  while(scanf("%d",&n),n){
    for(i=0;a[i]<=n;++i);
    for(--i;i>=0;--i){
      printf("%c",s[n/a[i]]);
      n%=a[i];
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 0
n=int(input())
t=[int(input()) for _ in range(n)]

import fractions
if n==1: print(t[0])
else:
    a,b=t[0],t[1]
    res=a*b//fractions.gcd(a,b)
    for i in range(2,n):
        tmp=t[i]
        res = res*tmp//fractions.gcd(res,tmp)
    print(res)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n, m;
    cin >> n >> m;
    vector<ll> x(m);
    for(int i = 0; i < m; i++) {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    vector<ll> delta(m - 1);
    for(int i = 0; i < m - 1; i++) {
        delta[i] = x[i + 1] - x[i];
    }
    ll ans = 0;
    sort(delta.begin(), delta.end());
    for(int i = 0; i < m - n; i++) {
        ans += delta[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    A, B, C = li_input()

    for i in range(1, B + 1):
        if A * i % B == C:
            print("YES")
            return
    
    print("NO")


main()


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

using namespace std;
int main (){
  long long n,ans = 0;
  cin >> n;
  for(int a =sqrt(n);a>0;a--){
    if(n%a==0){
      int b = n/a;
      while(b>0){
        ans++;
        b/=10;
      }
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import math
(a,b,x)=input().split()
(a,b,x)=(int(a),int(b),int(x))
c=(2*b)-((2*x)/(a**2))
if c<=b:
  d=((a**2)+(c**2))**(1/2)
  cos=c/d
  deg=math.acos(cos)
else:
  c=(2*x)/(a*b)
  d=((b**2)+(c**2))**(1/2)
  cos=b/d
  deg=math.acos(cos)
print(90-math.degrees(deg))

Measured memory_bytes: 38768
<?php
$ans =  0;
$s = str_split(trim(fgets(STDIN)));
$t = str_split(trim(fgets(STDIN)));
$k = count($s);
for($i=0; $i<$k; $i++){
	if($s[$i] != $t[$i]){
		$ans ++;
	}
}

echo $ans . "\n";

Measured memory_bytes: 41308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		double[] A = new double[N];

		for (int i = 0; i < N; i++)
			A[i] = sc.nextDouble();

		double x = 0;

		for (int i = 0; i < N; i++) {
			x += 1 / A[i];
		}

		double ans = 1 / x;
		System.out.println(ans);
	}

}

Measured memory_bytes: 23252
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

#define ll long long
const int N = 3*1e5;

ll n,m;
struct node{
	ll a,b;
}f[N];

bool cmp(node a,node b){
	return a.b < b.b;
}

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++)
		scanf("%lld%lld",&f[i].a,&f[i].b);
	sort(f+1,f+1+n,cmp);
	for(int i = 1; i <= n; i++){
		m += f[i].a;
		if(m > f[i].b){
			cout << "No";
			return 0;
		}
	}
	cout <<"Yes";
	return 0;
}

Measured memory_bytes: 4352
A,B = map(int, input().split())

w = '.'
b = '#'

ans = [ [b]* 20 + [w] * 20 for _ in range(100)]

for i in range(A-1):
    x = 2 * (i//50)
    y = (i%50) * 2
    ans[y][x] = w
    
for i in range(B-1):
    x = 2 * (i//50) + 21
    y = (i%50) * 2
    ans[y][x] = b
    
print('100 40')
for i in range(100):
    print(''.join(ans[i]))

Measured memory_bytes: 38384
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    int N, x;
    cin >> N;
    vector<int> lengths;
    int counter = 0;
    for (int i = 0; i < N; i++) {
        cin >> x;
        lengths.push_back(x);
    }
    sort(lengths.begin(), lengths.end());
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            for (int k = 0; k < j; k++) {
                if (lengths[i] != lengths[j] && lengths[j] != lengths[k] && lengths[k] + lengths[j] > lengths[i]) {
                    counter++;
                }
            }
        }
    }
    cout << counter;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int next = N;
        int sum = 0;
        for (int i = 0; i < String.valueOf(N).length(); i++) {
            sum += next % 10;
            next /= 10;
        }
        if (N % sum == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}

Measured memory_bytes: 21204
program abc144b
   implicit none
   integer :: N, i

   read(*,*) N

   do i = 1, 9
      if (mod(N,i) == 0) then
         if (N/i <= 9) then
            write(*,*) "Yes"
            stop
         end if
      end if
   end do

   write(*,*) "No"

end program abc144b


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

int main()
{
  int total = 0;
  int N, K;
  cin >> N >> K;
  
  for(int i = N; i > 0; i--)
  {
    int x;
    cin >> x;
    
    int A, B;
    A = x * 2;
    B = (K - x) * 2;
    
    total += (A < B) ? A : B;
  }
  
  cout << total << endl;
}

Measured memory_bytes: 256
/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();
 

    int n; cin >> n;
    cout << ceil(((double)n / 2.0)) << endl;    

    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define mp(...) make_pair(__VA_ARGS__)
#ifdef DEBUG
#define DEBUG_PRINT(...) printf(__VA_ARGS__)
#else
#define DEBUG_PRINT(...)
#endif

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const long double INF = (long double)3*1000000000;

int N;
ll x[1002], y[1002], r[1002];
long double dist[1002][1002];
long double d[1002];

long double solve(){
  priority_queue<pair<long double, int>, vector<pair<long double, int> >, greater<pair<long double, int> > > Q;
  fill(d, d+1002, INF);
  d[0] = 0;
  Q.push(mp(0, 0));
  while (Q.empty() == false) {
    pair<long double, int> point = Q.top();Q.pop();
    if(point.first>d[point.second])continue;
    REP(N+2){
      DEBUG_PRINT("distance %Lf\n", point.first+dist[point.second][i]);
      if (point.first+dist[point.second][i]<d[i]) {
        d[i] = point.first+dist[point.second][i];
        Q.push(mp(d[i], i));
        DEBUG_PRINT("push:(%Lf, %d)", d[i], i);
      }
    }
  }
  return d[1];
}

int main(){
  DEBUG_PRINT("%Lf\n", INF);
  scanf("%lld %lld %lld %lld", &x[0], &y[0], &x[1], &y[1]);
  scanf("%d", &N);
  REP(N)scanf("%lld %lld %lld", &x[i+2], &y[i+2], &r[i+2]);
  REP(N+2)DEBUG_PRINT("%lld %lld %lld\n", x[i], y[i], r[i]);
  For(i, N+2)For(j, N+2){
    dist[i][j] = max((long double)0.0,(long double)sqrt(powl(static_cast<long double>(x[i]-x[j]), 2)+powl((long double)y[i]-y[j], 2))-r[i]-r[j]);
    assert(dist[i][j]>=0);
    DEBUG_PRINT("%lld**2 = %Lf ", x[i]-x[j], powl((long double)x[i]-x[j], 2));
    DEBUG_PRINT("%d:%d;%Lf\n", i, j, dist[i][j]);
  }
  printf("%.10Lf\n", solve());
  return 0;
}



Measured memory_bytes: 25964
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

int main(){
  int n;
  scanf("%d", &n);

  vector<long long> a(n), b(n);
  for(int i = 0; i < n; i++){
    scanf("%lld %lld", &a[i], &b[i]);
  }

  long long ans = 0;
  for(int i = n - 1; i >= 0; i--){
    long long num = a[i] + ans;
    if(num % b[i] == 0){
      continue;
    }else{
      if(num < b[i]){
        ans += b[i] - num;
      }else{
        ans += (b[i] * ((num / b[i]) + 1)) - num;
      }
    }
  }

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



Measured memory_bytes: 1792
<?php
while(true){
    list($n,$x) = explode(" ",trim(fgets(STDIN)));
    if($n == 0 && $x == 0) break;
    for($i = 0; $i < $n; $i++) $arr[$i] = ($i + 1);
    $count = 0;
    for($i = 0; $i < $n; $i++){
        for($j = 0; $j < $n; $j++){
            for($k = 0; $k < $n; $k++){
                if($i == $j || $j == $k || $k == $i) continue;
                $s = $arr[$i]+$arr[$j]+$arr[$k];
                if($s == $x){
                    // echo ($i+1)." ".($j+1)." ".($k+1)."\n";
                    $count++;
                }
            }
        }
    }
    echo ($count / 6)."\n";
}

Measured memory_bytes: 15472
C = [list(map(int, input().split())) for i in range(3)]
x = [0,0,0]
y = [0,0,0]
for i in range(3):
    y[i] = C[0][i] - x[0]
for i in range(3):
    x[i] = C[i][0] - y[0]
flag = True
for i in range(3):
    for j in range(3):
        if x[i] + y[j] != C[i][j]:
            flag = False
print('Yes' if flag else 'No')


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

int r[100000];
map<int, int>d;

int main() {
	int n; cin >> n;
	rep(i, n) {
		scanf("%d", &r[i]);
		d[r[i]] = i & 1;
	}
	sort(r, r + n);
	int cnt = 0;
	rep(i, n)
		if ((i & 1) != d[r[i]])
			cnt++;
	printf("%d\n", cnt / 2);
}

Measured memory_bytes: 5376
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static final int MOD = 1000000007;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		long ans = 1;
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 2; i <= N; i++) {
			primeFactors(map, i);
		}
		for (Map.Entry<Integer, Integer> m : map.entrySet()) {
			ans = (ans % MOD * (m.getValue() + 1)) % MOD;
		}
		System.out.println(ans);
		in.close();

	}

	static Map<Integer, Integer> primeFactors(Map<Integer, Integer> res, int n) {
		if (n == 1) { // n=1 の素因数分解は n^1
			res.put(n, 1);
			return res;
		}
		for (int i = 2, _n = n; i * i <= _n; ++i) {
			while (n % i == 0) {
				res.put(i, res.get(i) == null ? 1 : 1 + res.get(i));// 素数i^{res[i]}
				n /= i;
			}
		}
		if (n != 1)
			res.put(n, res.get(n) == null ? 1 : 1 + res.get(n));
		return res;
	}
}

Measured memory_bytes: 22356
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    int H,N;
    int a;
    int sum=0;
    cin>>H>>N;
    for(int i=0;i<N;i++){
        cin>>a;
        sum+=a;
    }

    if(H<=sum){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

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

 int main(){
     long long int ans=0;
     long long int n,m;
     cin >> n >> m;
     vector<pair<long long int,long long int>> a(n);
     for(int i=0;i<n;i++){
         cin >> a.at(i).first >> a.at(i).second;
     }
     sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        if(a.at(i).second>=m){
            
            ans=ans+a.at(i).first * m;
            break;
        }
        else{
            ans+=a.at(i).first*a.at(i).second;
            m-=a.at(i).second;
            }
    }
    cout << ans << endl;
 }




Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		int N = Integer.parseInt(in.readLine());
		int A = Integer.parseInt(in.readLine());
		if ((N % 500) <= A) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	void calc() {
	}

	void showResult() {
	}
}

Measured memory_bytes: 23252
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char s[100001];

    scanf("%s", s);

    int len = strlen(s);

    int g = 0, p = 0;
    int l = 0, w = 0;

    for(int i = 0; i < len; i++){
        if(p == g){
            g++;
            if(s[i] == 'p'){
                l++;
            }
        }else{
            p++;
            if(s[i] == 'g'){
                w++;
            }
        }
    }

    printf("%d\n", w-l);

    return 0;
}

Measured memory_bytes: 1824
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  int N;
  string result = "YES";
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) == A.at(i + 1)) {
      result = "NO";
      break;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 1024