akhauriyash/Code-Regression huggingface dataset:
N,K = map(int,input().split())
l = []

for i in range(N):
    x,y = (map(int, input().split()))
    l.append((x,y))
l.sort()
cnt = 0
ans = 0
index = 0
while cnt < K:
    ans = l[index][0]
    cnt += l[index][1]
    index += 1

print(ans)

Measured memory_bytes: 16940
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;

const ll magic=500000004;
const ll MOD=1e9+7;
ll f[5005][5005];
int n;
string s;

int main() {
	#ifdef kvutxdy
	freopen("C:/Users/khanh/OneDrive/RoadtoPurple/Code/Codeforces/input.in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>n>>s;
	int sz=s.size();
	f[0][0]=1LL;
	for(int i=0;i<n;++i) 
		for(int j=0;j<=i;++j){
			if(j>0) (f[i+1][j-1]+=f[i][j])%=MOD;
			else (f[i+1][j]+=f[i][j])%=MOD;
			(f[i+1][j+1]+=2LL*f[i][j])%=MOD;
		}
	for(int i=0;i<sz;++i) (f[n][sz]*=magic)%=MOD;
	cout<<f[n][sz];
}

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

constexpr ll INF = ll(1e+18) + 1;

int main() {
    int n, m;
    int ans;

    cin >> n >> m;
    ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans << endl;

    return 0;
}

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

int main() {
	string s;
	cin >> s;
	int N = (int)s.size();
	int gn = 0, pn = 0;
	int lose = 0, draw = 0, win = 0;
	for(int i=0;i<N;i++) {
		if(gn == pn) {
			gn++;
			if(s[i] == 'p') lose++;
			else draw++;
		} else {
			// pn < gn
			if(s[i] == 'g') {
				pn++;
				win++;
			} else {
				pn++;
				draw++;
			}
		}
	}
	cout << win - lose << endl;
}

Measured memory_bytes: 512
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    t1, t2 = LI()
    a1, a2 = LI()
    b1, b2 = LI()

    if a1 < b1:
        tmp = b1
        b1 = a1
        a1 = tmp

        tmp = b2
        b2 = a2
        a2 = tmp

    l1 = (a1 - b1) * t1
    l2 = (a2 - b2) * t2
    l3 = l1 + l2

    if l3 == 0:
        print("infinity")
        return
    if l3 > 0:
        print(0)
        return
    ans = 1
    if l1 % (-l3) == 0:
        print(ans + 2 * (l1 // (-l3)) - 1)
        return
    print(ans + 2 * (l1 // (-l3)))






if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a)  memset((a), 0, sizeof (a))
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back

constexpr auto inf = numeric_limits<int>().max() - 1;
constexpr auto llinf = numeric_limits<ll>().max() - 1LL;

template<typename ForwardIterator>
void dump(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << *it << " ";
	}
	cout << endl;
}

template<typename ForwardIterator>
void dump_map(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << (*it).first << ":" << (*it).second << " ";
	}
	cout << endl;
}
template<typename T>
void debug(initializer_list<T> list) {
  for (auto el : list) {
    cout << el << " ";
  }
  cout << endl;
}

constexpr ll mod = ll(1e9 + 7);

ll mult(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll power(ll a, ll b) {
	ll result = 1LL;
	while (b) {
		if (b % 2LL) result = mult(result, a);
		a = mult(a, a);
		b /= 2LL;
	}
	return result;
}

ll divide(ll a, ll b) { return mult(a, power(b, mod - 2)); }

ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }

ll subtract(ll a, ll b) { return ((a - b) % mod + mod) % mod; }

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a), std::greater<ll>());
  ll sum = a[0];
  int cnt = n - 2;
  int idx = 1;
  while (cnt > 1) {
    sum += 2 * a[idx];
    cnt -= 2;
    ++idx;
  }
  if (cnt == 1) sum += a[idx];
  cout << sum;
	cout << "\n";
}

#define REPEAT 0
#define CASE 0

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#if REPEAT
		int t;
		cin >> t;
		repa(i, 1, t) {
			#if CASE
				cout << "Case #" << i << ": ";
			#endif
			solve();
		}
	#else
		solve();
	#endif
	return 0;
}


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

using namespace std;

#define ll long long

struct Node {
	ll value = 0; int color = 0;
};

int n;
bool isBipartite = true; // gが二分グラフかどうか
vector<vector<pair<int, ll>>> g;
vector<Node> node;

void dfs(int s) {
	static vector<bool> visited(n, false);
	visited[s] = true;
	for (auto e : g[s]) {
		int nx = e.first;
		if (visited[nx] && node[nx].color == node[s].color)
			isBipartite = false;
		else if (visited[nx]) {
			if (e.second != node[nx].value + node[s].value) {
				cout << 0 << endl;
				exit(0);
			}
		}
		else if (!visited[nx]) {
			node[nx].color = node[s].color == 0 ? 1 : 0;
			node[nx].value = e.second - node[s].value;
			dfs(nx);
		}
	}
}

bool check() {
	for (int i = 0; i < n; ++i)
		if (node[i].value <= 0)
			return false;
	for (int i = 0; i < n; ++i)
		for (auto e : g[i])
			if (e.second != node[e.first].value + node[i].value)
				return false;
	return true;
}

pair<int, int> findError() {
	for (int i = 0; i < n; ++i)
		for (auto e : g[i])
			if (e.second != node[e.first].value + node[i].value)
				return make_pair(i, e.first);
	cout << 0 << endl;
	exit(0);
}

signed main() {
	int m; cin >> n >> m;
	g.resize(n); node.resize(n);
	while (m--) {
		int u, v; ll s;
		cin >> u >> v >> s;
		--u; --v;
		g[u].emplace_back(v, s);
		g[v].emplace_back(u, s);
	}

	// 頂点0を0に、値を決定していく.
	// 同時に二分グラフかどうかの判定を行う.
	dfs(0);

	if (isBipartite) { // 二分グラフである場合
		// 頂点0の値を1増やしたとき、
		//   color == 0の頂点の値は1増える
		//   color == 1の頂点の値は1減る
		// ので、いくつ増やせるか、を求める.
		ll mn = 0, mx = 10000000000LL;
		for (auto ni : node) {
			if (ni.color == 0 && ni.value <= 0)
				mn = max(mn, -ni.value + 1);
			else if (ni.color == 1 && ni.value > 0)
				mx = min(mx, ni.value - 1);
			else if (ni.color == 1 && ni.value <= 0) {
				cout << 0 << endl;
				exit(0);
			}
		}
		cout << max(0LL, mx - mn + 1) << endl;
	}
	else { // 二分グラフでない場合
		// 和が矛盾している頂点のペアを探す.
		pair<int, int> bad = findError();
		int u = bad.first, v = bad.second;
		ll s = 0;
		for (auto e : g[u])
			if (e.first == v)
				s = e.second;
		if (node[u].value + node[v].value < s) { // コストが足りない
			if (node[u].color == 1 || node[v].color == 1) {
				cout << 0 << endl;
				exit(0);
			}
			ll need = s - (node[u].value + node[v].value);
			if (need % 2 == 1) {
				cout << 0 << endl;
				exit(0);
			}
			for (int i = 0; i < n; ++i) {
				if (node[i].color == 0)
					node[i].value += (need / 2);
				else
					node[i].value -= (need / 2);
			}
		}
		else { // コストが多い
			if (node[u].color == 0 || node[v].color == 0) {
				cout << 0 << endl;
				exit(0);
			}
			ll dec = -s + (node[u].value + node[v].value);
			if (dec % 2 == 1) {
				cout << 0 << endl;
				exit(0);
			}
			for (int i = 0; i < n; ++i) {
				if (node[i].color == 0)
					node[i].value += (dec / 2);
				else
					node[i].value -= (dec / 2);
			}
		}
		cout << (check() ? 1 : 0) << endl;
	}

	return 0;
}

Measured memory_bytes: 14080
def main():
    n,h = list(map(int, input().split()))
    bi = []
    max_attack = [0,0]
    for i in range(n):
        a, b = list(map(int, input().split()))
        bi.append(b)
        max_attack[0] = max(a, max_attack[0])
        max_attack[1] = max(b, max_attack[1])
    bi.sort(reverse=True)
    idx = 0
    count = 0
    while h > 0:
        damage = 0
        if idx < len(bi) and max_attack[0] < bi[idx]:
            damage = bi[idx]
            idx += 1
        else:
            count += h // max_attack[0]
            count += 0 if h % max_attack[0] == 0 else 1
            break
        h -= damage
        count += 1
    print(count)



if __name__ == '__main__':
    main()

Measured memory_bytes: 7552
#include <algorithm>
#include <bitset>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 7;

// log N
inline ll fast(ll n, ll k) {
  if (k == 1) {
    return n;
  } else if (k == 0) {
    return 1;
  }

  if (k % 2 == 0) {
    ll ret = fast(n, k / 2) % MOD;
    return ret * ret % MOD;
  } else {
    ll ret = fast(n, k / 2) % MOD;
    ll tmp = ret * ret % MOD;
    return tmp * n % MOD;
  }
}

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> GCD(K + 1);

  for (ll i = 1; i <= K; i++) {
    GCD[i] = fast(K / i, N) % MOD;
  }

  ll ans = 0;
  vector<ll> sum(K + 1);

  for (ll i = K; i > 0; i--) {
    ll n = GCD[i];
    for (ll j = 2; j <= (K / i); j++) {
      n -= sum[i * j];
      if (n < 0) {
        n = (n + MOD) % MOD;
      }
    }
    ans += (n * i);
    if (ans < 0) {
      ans = (ans + MOD);
    }
    ans %= MOD;
    sum[i] = n;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4832
from collections import deque
def main4():
    N, M = map(int, input().split())
    pair = [list() for i in range(N)]

    for i in range(M):
        A, B = map(int, input().split())
        pair[A - 1].append(B - 1)
        pair[B - 1].append(A - 1)

    dq = deque()
    color = ["w" for i in range(N)]

    ans = 0
    for i in range(N):
        if color[i] == "w":
            dq.append(i)
            # print("start node : {}".format(i))

            con = 1
            while True:

                if len(dq) == 0:
                    break

                idx = dq.popleft()
                color[idx] = "g"

                for j in range(len(pair[idx])):
                    if color[pair[idx][j]] == "w":
                        dq.append(pair[idx][j])
                        color[pair[idx][j]] = "g"
                        con += 1
                        # print("cur : {} / next : {}".format(idx, pair[idx][j]))

            ans = max(ans, con)

    print(ans)

if __name__ == "__main__":
    main4()

Measured memory_bytes: 45276
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int f (int a, int b){
    return a ? f(b%a,a) : b;
}
int main () {
    vector<int> x;
    int N, M, cnt=0;
    cin >> N >> M;
    x.push_back(M);
    for (int i=0;i<N;i++){
        int a;
        cin >> a;
        x.push_back(a);
    }
    sort(x.begin(),x.end());
    cnt=x[1]-x[0];
    for (int i=2;i<x.size();i++){
        cnt=f(cnt,x[i]-x[i-1]);
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 892
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 15 17:00:46 2020

@author: saito
"""

# %% import phase

# %% define phase

# %% input phase
N = int(input())
S = [0]*N
for i in range(N):
    S[i] = input()

# %% process phase
C = [0]*4
rslt = ['AC', 'WA', 'TLE', 'RE']
for i in range(4):
    C[i] = S.count(rslt[i])

# %%output phase
for i in range(4):
    print(rslt[i]+' '+'x'+' '+str(C[i]))

Measured memory_bytes: 16184
<?php
error_reporting(0);
//list($x,$t) = explode(" ",trim(fgets(STDIN)));
$N = trim(fgets(STDIN));
//$p = explode(" ",trim(fgets(STDIN)));
if (($N >= 90) || (($N-9)%10)==0) {
  printf("Yes\n");
}
else {
  printf("No\n");
}


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

class FenwickTree {
private:
    int n;
    vector<ll> dat;
public:
    FenwickTree(int _n): n(_n), dat(_n+1, 0) {}
    FenwickTree(int _n, ll init): n(_n), dat(_n+1, 0) {
        for (int i = 0; i < _n; i++) {
            add(i, init);
        }
    }
    
    void add(int idx, ll value) {
        for (idx++; idx <= n; idx += idx & -idx) {
            dat[idx] += value;
        }
    }

    ll query(int l, int r) {
        ll ans = 0;
        for (r++; r; r -= r & -r) {
            ans += dat[r];
        }
        for (; l; l -= l & -l) {
            ans -= dat[l];
        }
        return ans;
    }
};

bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.second - a.first < b.second - b.first;
}

int main(void)
{
    int n, m;
//    cin >> n >> m;
    scanf("%d%d", &n, &m);

    vector< pair<int,int> > A(n);
    for (int i = 0; i < n; i++) {
//        cin >> A[i].first >> A[i].second;
        scanf("%d%d", &A[i].first, &A[i].second);
    }
    sort(A.begin(), A.end(), comp);

    FenwickTree ft(m+1);

    int idx = 0;
    for (int d = 1; d < m+1; d++) {
        for(; idx < n && A[idx].second - A[idx].first < d; idx++) {
            ft.add(A[idx].first, 1);
            ft.add(A[idx].second+1, -1);
        }
        ll count = n - idx;
        for (int i = 0; i < m+1; i += d) {
            count += ft.query(0, i);
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 4096
#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 ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int N; cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  bool flag = true;
  REP(i, N) {
    if (a[i] % 2 == 1) flag = false;
  }
  if (flag) cout << "second" << endl;
  else  cout << "first" << endl;
  return 0;
}

Measured memory_bytes: 640
// 200220.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int K, S;
    cin >> K >> S;
    //for (int i = 0; i < N; i++) {
    //    cin >> x[i];
    //    cin >> y[i];
    //}
    
    int count = 0;
    for (int X = 0; X <= K; X++) {
        for (int Y = 0; Y <= K; Y++) {
            if (S-K <= X+Y && X + Y <= S) {
                count++;
            }
        }
    }
    cout << count << endl;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#include<stdio.h>

int main(){
 int a,b,c,d,e,k;
  scanf("%d\n%d\n%d\n%d\n%d\n%d\n",&a,&b,&c,&d,&e,&k);
  if(e-a<=k){
   printf("Yay!\n");
  }else{
   printf(":(\n");
}
  return 0;
}

Measured memory_bytes: 128
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct Node {
    int key;
    struct Node *prev, *next;
};

struct Node *nil;

void init() {
    nil = (struct Node *)malloc(sizeof(struct Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key) {
    struct Node *x = (struct Node *)malloc(sizeof(struct Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

struct Node* listSearch(int key) {
    struct Node *cur = nil->next;
    while(cur != nil && cur->key != key ) {
        cur = cur-> next;
    }
    return cur;
}

void deleteNode(struct Node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}
void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void printList() {
    struct Node *cur;
    cur = nil->next;
    int isf = 0;

    while(1) {
        if (cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}


int main(void) {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++) {
        scanf("%s%d",com, &key);
        if(com[0] == 'i') {
            insert(key);
            np ++;
            size++;
        }else if(com[0] == 'd') {
            if(strlen(com) > 6) {
                if( com[6] == 'F') {
                    deleteFirst();
                }else if(com[6] == 'L') {
                    deleteLast();
                }
            }else {
                deleteKey(key);
                nd ++;
            }
            size --;
        }
    }
    printList();
    return 0;

}

Measured memory_bytes: 31788
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
    int n,k; cin >> n >> k;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin >> h[i];
    vector<int> dp(n);
    dp[0] = 0; 
    for(int i=1; i<n; i++){

        dp[i] = -1;
        for(int j=1; j<=k; j++){
            if(i-j < 0) break;
            
            if(dp[i] == -1) dp[i] = dp[i-j] + abs(h[i]-h[i-j]);
            else dp[i] = min(dp[i],dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n-1] << endl;    
}

Measured memory_bytes: 4004
#include<iostream>
    #include <bits/stdc++.h>
    using namespace std;
    int main(){
        int N, M;
        cin >> N;
        string s[N];
        
        for(int i=0;i<N;i++){
            cin >> s[i];
        }
        cin >> M;
        string t[M];
        for(int i=0;i<M;i++){
            cin >> t[i];
        }
        
        int ans = 0;
        string x;
        int result;
        for(int i=0;i<N;i++){
            x = s[i];
            int count = 0;
            for(int k = 0;k<N;k++)
                if(s[k] == x) ++count;
                

            for(int j = 0;j<M;j++)
                if(t[j] == x) --count;
                
            ans = max(count,ans);

        }
        cout << ans << endl;
    }


Measured memory_bytes: 256
import collections, itertools, copy


class MaximumFlow:
    def __init__(self, G):
        self.G = G

    def ford_fulkerson(self, s, t):
        G = self.G
        G_residue = copy.deepcopy(G)

        def dfs(start, used):
            if start == t:
                return [start]
            for end, cap in G_residue[start].items():
                if cap > 0 and end not in used:
                    used.add(end)
                    ret = dfs(end, used)
                    if ret:
                        return ret + [start]
            return []

        flow_value = 0
        while True:
            root = dfs(s, set([s]))
            if root:
                root = root[::-1]
                residue = min(
                    [G_residue[a][b] for a, b in zip(root, root[1:])])
                flow_value += residue
                for a, b in zip(root, root[1:]):
                    G_residue[a][b] -= residue
                    G_residue[b][a] += residue
            else:
                flow_dict = collections.defaultdict(
                    lambda: collections.defaultdict(int))
                for a in G:
                    for b in G[a]:
                        if G_residue[b][a] > 0:
                            flow_dict[a][b] = G_residue[b][a]
                return (flow_value, flow_dict)


N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
CD = [[int(_) for _ in input().split()] for _ in range(N)]
G = collections.defaultdict(lambda: collections.defaultdict(int))
for a, b in AB:
    G[-1][1000 * a + b] = 1
for c, d in CD:
    G[1000 * c + d][-2] = 1
for ab, cd in itertools.product(AB, CD):
    a, b = ab
    c, d = cd
    if a < c and b < d:
        G[1000 * a + b][1000 * c + d] = 1
flow_value, G_residue = MaximumFlow(G).ford_fulkerson(-1, -2)
print(flow_value)


Measured memory_bytes: 9904
use std::io;
fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let n:u32 = s.trim().parse().unwrap();
    let mut sum:u64 = 0;
    for i in 1..n+1 {
        if i%5 != 0 && i%3 != 0 {
            sum += i as u64;
        }
    }
    println!("{}", sum);
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N); 
    string ans, yes;
    bool flag=false;
    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }

    ans="YES";
    sort(A.begin(), A.end());
    for(int i=0;i<N-1;i++){
        if(A.at(i)==A.at(i+1)){
            ans="NO";
        }
    }
    cout << ans << endl;
}

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

typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30

bool compare_by_b(pll a, pll b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{
	int N;
	cin >> N;
	vector<pll> list;
	ll A, B;
	for( int i=0; i<N; i++ ){
		cin >> A >> B;
		list.pb(mp(A,B));
	}

	sort(ALL(list), compare_by_b);

	ll total = 0;
	for( auto &val : list ){
		total += val.first;
		if( total > val.second ){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}


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

class MyScanner {
    BufferedReader br;
    StringTokenizer st;

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

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

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

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

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

    String nextLine(){
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }

}



public class Main {

    public static PrintWriter out;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        String s = sc.next();
        String t = sc.next();
        String sub = t.substring(0,t.length()-1);
        if (sub.equals(s)){
            out.println("Yes");
        }else {
            out.println("No");
        }
        out.close();
    }

}


Measured memory_bytes: 32896
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
string a, b, c;
int main(void) {
    cin >> a >> b >> c;
    cout << "A" << b[0] << "C" << endl;
    return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    int i = 0, j = n - 1;
    while(j >= i) {
        while(j >= i && s[j] != 'R') {
            j--;
        }
        while(i < n && s[i] != 'W') {
            i++;
        }
        if(j < i) break;
        ans++;
        j--;
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3672
n = int(input())
l = []
l.append(1)
for i in range(2,40):
  b = i**2
  while b <= 1000:
    l.append(b)
    b*= i
l.sort()

for i in range(len(l)):
  if n < l[i]:
    print(l[i-1])
    exit()
print(1000)  
  


Measured memory_bytes: 2940
#include <iostream>
#include <string>
using namespace std;
struct process{
    string name;
    int time;
};

class queue{
    private:
        int head;
        int tail;
        int MAX = 200000;
        int time;
        int totaltime = 0;
        process Q[200000];
    public:
        queue(int n,int t){
            time = t;
            head = tail = 0;
        }
        void enqueue(process x){
            Q[tail] = x;
            if (tail + 1 == MAX){
                tail = 0;
            }
            else{
                tail++;
            }
        }
        process dequeue(process x){
            x = Q[head];
            if (head + 1 == MAX){
                head = 0;
            }
            else{
                head++;
            }
            return x;
        }
        void process_start(){
            while(true){
                if (Q[head].time <= time){
                    totaltime += Q[head].time;
                    cout << Q[head].name << " " << totaltime;
                    dequeue(Q[head]);
                    if (head != tail){
                        cout << endl;
                    }
                }
                if (Q[head].time > time) {
                    totaltime += time;
                    Q[head].time -= time;
                    enqueue(dequeue(Q[head]));
                }
                if (head == tail){
                    break;
                }
            }
        }
};

int main(){
    process P;
    int n,time;
    cin >> n >> time;
    queue Q1(n,time);
    for (int i = 0; i < n; i++){
        cin >> P.name >> P.time;
        Q1.enqueue(P);
    }
    Q1.process_start();
    cout << endl;
    return 0;
}


Measured memory_bytes: 8648
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define VFOR(x,begin,num) for(int x=(begin);x<((begin)+(num));x++)
#define INF__ ((long long)1 << 60)
vector<int> Fr[100010], Bl[100010];int group[100010];int grsize[100010];
void grouping(int gr, int mem);
int main(){
    int N, M, K;
    cin >> N >> M >> K;
    VFOR(i,0,M){
        int a, b; cin >> a >> b;
        Fr[a].push_back(b);
        Fr[b].push_back(a);
    }
    VFOR(i,0,K){
        int a, b; cin >> a >> b;
        Bl[a].push_back(b);
        Bl[b].push_back(a);
    }
    int gr = 1;
    VFOR(i,1,N){
        if(group[i]==0) {group[i]=gr;grsize[gr]++;grouping(gr,i);gr++;}
    }
    VFOR(i,1,N){
        int ans = grsize[group[i]] - 1;
        for(auto j : Bl[i]){
            if(group[i]==group[j]) ans--;
        }
        ans -= Fr[i].size();
        cout << ans << " ";
    }
    cout << endl;
    //VFOR(i,1,N) cout << grouping[i] << " ";
    return 0;
}
void grouping(int gr, int mem){
    for(auto x : Fr[mem]){
        if(group[x]==0) {group[x] = gr;grsize[gr]++;grouping(gr,x);}
    }
}

Measured memory_bytes: 12672
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs

int n, m;
vector<int> v;
vector<int> dists;
int ans;

int main() { 

  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    v.push_back(x);
  }

  sort(all(v));

  for (int i = 1; i < sz(v); i++) {
    dists.push_back(v[i] - v[i - 1]);
  }

  sort(all(dists));
  reverse(all(dists));

  for (int i = n - 1; i < sz(dists); i++) {
    ans += dists[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define st first
#define sc second
#define arr array

using namespace std;
const ll mod = 1e9 + 7;
const int e = 1e7 + 79;
const int maxn = 10*1e6 + 69;

ll dp[e];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<ll>ans;
    int t;
    cin >> t;
    for(int i=2; i*i<=e; i++){
        if(dp[i] == 0){
            ans.pb(i);
            for(int j=i*2; j<=e; j+=i){
                dp[j] ++;
            }
        }
    }
    ll answer = 0;
    for(ll i=1; i<=t; i ++){
        ll n = i;
        int kq = 1;
        dp[1] = 1;
        for(auto j : ans){
            //cout << j <<" ";
            if(j*j*j>n || dp[n] == 0) break;
            int cnt = 1;
            while(n%j==0){
                n/=j;
                cnt ++;
            }
            kq *= cnt;
        }
        int cur = sqrt(n);
        if(!dp[n]){
            kq *= 2;
        }
        else if(cur*cur == n && !dp[cur]){
            kq *= 3;
        }
        else if(n != 1){
            kq *= 4;
        }
        answer += i*kq;
        //cout << kq <<" ";
    }
    cout << answer;
}
/*
8 1 2
-1 3 -2 5 3 -5 2 2
*/


Measured memory_bytes: 81768
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    boolean isNEven = n % 2 == 0;
    int odd = isNEven ? n / 2 : n / 2 + 1;
    pw.println((double) odd / n);
  }
}


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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

#define MOD LL(1e9 + 7)

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

bool check(string last3, const char &next) {
    if (next == 'G') {
        if (last3[1] == 'A' && last3[2] == 'C') return false;
    } else if (next == 'C') {
        if (last3[1] == 'G' && last3[2] == 'A') return false;
        if ((last3[0] == 'A' || last3[1] == 'A') && (last3[2] == 'G' || last3[1] == 'G')) return false;
    }
    return true;
}

LL recurse(const string &last3, int cur_n, int max_n, vector<unordered_map<string, LL>> &memo) {
    if (cur_n == max_n) {
        return 1;
    }

    auto itr = memo[cur_n].find(last3);
    if ( itr != memo[cur_n].end()) {
        return itr->second;
    }

    LL ret = 0;
    REP(i, 4) {
        char next = "ACGT"[i];
        if (check(last3, next)) {
            ret = (ret + recurse(last3.substr(1, 2) + next, cur_n + 1, max_n, memo)) % MOD;
        }
    }

    memo[cur_n][last3] = ret;
    return ret;
}

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

    int N; cin >> N;

    vector<unordered_map<string, LL>> memo(N);

    cout << recurse("ZZZ", 0, N, memo) << endl;
}


Measured memory_bytes: 896
using System;

class Test
{
    static void Main()
    {
        int S = Convert.ToInt32(Console.ReadLine());
        int hh = S / 3600;
        int mm = (S - (hh * 3600)) / 60;
        int ss = S - hh * 3600 - mm * 60;

        Console.WriteLine("{0}:{1}:{2}", hh, mm, ss);
    }
}


Measured memory_bytes: 18012
<?php
  $stdin = fopen('php://stdin', "r");

  fscanf($stdin, "%s", $n);

  if (strstr($n, 'a') && strstr($n, 'b') && strstr($n, 'c')) {
    echo 'Yes';
  } else {
    echo 'No';
  }

  echo PHP_EOL;


Measured memory_bytes: 4732
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int d = a + b, e = b + c, f = c + a;
	if (k & 1) {
		cout << e - f << endl;
	} else {
		cout << f - e << endl;
	}
	return 0;
}

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

int main() {
	int N, X;
	cin >> N >> X;
	int n = 0, cnt = 1;
	for(int i = 0; i < N; i++) {
		int L;
		cin >> L;
		n += L;
		if(n <= X) cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
n=int(input())
ans = 0
for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            if i==j==k:
              ans+=gcd(i+1,j+1,k+1)
            elif i<j<k:
              ans+=6*(gcd(i+1,j+1,k+1))  
            else:
              ans+=3*(gcd(i+1,j+1,k+1))
print(ans)

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

using Graph = vector<vector<int>>;
Graph G;


void dfs(int i, int p, vector<long long> &res){
  
  for(int j:G[i]) if(j != p){
     res[j] += res[i];
     dfs(j, i, res);
  }
}


int main(){
  long long N, Q;
  cin >> N >> Q;
  G.assign(N, vector<int>());
  
  for(int i=0; i<N-1; i++){
    int a, b;
    cin >> a >> b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
    
  }
  vector<long long> val(N, 0);
    
  for(int i=0; i<Q; i++){
    int p, x;
    cin >> p >> x;
    val[p-1] += x;
  }
  
  dfs(0, -1, val);
    
  for(auto v: val) cout << v << " ";
  cout << endl;
  
  
  return 0;
}

Measured memory_bytes: 28280
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

int main(){

	long long aI, aO, aT, aJ, aL, aS, aZ;
	cin >> aI >> aO >> aT >> aJ >> aL >> aS >> aZ;

	long long ans = aO;
	if (aI && aJ && aL) {
		ans += max(aI / 2 * 2 + aJ / 2 * 2 + aL / 2 * 2, 3 + (aI - 1) / 2 * 2 + (aJ - 1) / 2 * 2 + (aL - 1) / 2 * 2);
	} else {
		ans += aI / 2 * 2 + aJ / 2 * 2 + aL / 2 * 2;
	}

	cout << ans << "\n";

	return 0;
}

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

int main(){
  ll N,A,B;
  cin >> N >> A >> B;
  if((B-A)%2==0){
    cout << (B-A)/2 << endl;
  }else{
    cout << min(A-1,N-B)+1+(B-A-1)/2 << endl;
  }
}


Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	g := make([][]int, N)
	for i, _ := range g {
		g[i] = make([]int, N)
	}
	for i := 0; i < N; i++ {
		u, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			g[u-1][sc.nextInt()-1] = 1
		}
	}

	for _, r := range g {
		for i, num := range r {
			if i > 0 {
				fmt.Fprint(wtr, " ")
			}
			fmt.Fprint(wtr, num)
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}



Measured memory_bytes: 1196
a = input()
b = input()
list_a = []
list_b = []
score = 0
for n in a:
    list_a.append(n)
for m in b:
    list_b.append(m)
for i in range(0, len(list_a)):
    if list_a[i] != list_b[i]:
        score += 1
print(score)

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

int main(){
 while(1){
 int m,f,r;
 cin>>m>>f>>r;
 
 if(m==-1 && f==-1 && r==-1)break;
 string ans;
 if(m==-1||f==-1)ans="F";
 else if(m+f>=80)ans="A";
 else if(m+f>=65)ans="B";
 else if(m+f>=50)ans="C";
 else if(m+f>=30){
 if(r>=50)ans="C";
 else ans="D";
 }
 else ans="F";
 cout<<ans<<endl;
}
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main(){
	int n;
	cin>>n;
	vector <int> t(n);
	vector <int> x(n);
	vector <int> y(n);
	bool ans=true;
	rep(i,n){
		cin>>t.at(i)>>x.at(i)>>y.at(i);
	}
	rep(i,n){
		if((t.at(i)-x.at(i)-y.at(i))%2==0&&t.at(i)>=(x.at(i)+y.at(i))){
			continue;
		}else{
			ans=false;
			break;
		}
	}
	if(ans){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}  

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(void){
    int A, B, K;
    cin >> A >> B;
    
    if((A+B)%2 == 0){
        K = (A+B) / 2;
        cout << K << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    } 
    
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  if (n == 25) {
    cout << "Christmas" << endl;
  }
  else if (n == 24) {
    cout << "Christmas Eve" << endl;
  }
  else if (n == 23) {
    cout << "Christmas Eve Eve" << endl;
  }
  else {
    cout << "Christmas Eve Eve Eve" << endl;
  }
}


Measured memory_bytes: 256
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = set()
    for x in a:
        b.add(x)
    return "YES" if len(a) == len(b) else "NO"


if __name__ == "__main__":
    print(main())

Measured memory_bytes: 26184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  string s;
  cin >> s;
  ll sum=0;
  for(ll i=0;i<s.size();i++) {
    sum+=s[i]-'0';
  }
  if(sum%9==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
// #include <cfloat>

using namespace std;

long long MOD = 1000000007;

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

long long factorial(int x){
  long long tmp = 1;
  for(int i=1; i<=x; i++){
    tmp = (tmp * i) % MOD;
  }
  return tmp % MOD;
}

int main(){
  int X,Y;
  cin >> X >> Y;

  vector<vector<double>> inverse = {
    {2/3.0, -1/3.0},
    {-1/3.0, 2/3.0}
  };

  double a = inverse[0][0] * X + inverse[0][1] * Y;
  double b = inverse[1][0] * X + inverse[1][1] * Y;

	double fractpart, intpart;
	fractpart = modf(a, &intpart);
	if(to_string(fractpart) == "1.000000"){
		a = ceil(a);
	}

  double fract2, int2;
	fract2 = modf(b, &int2);
	if(to_string(fract2) == "1.000000"){
		b = ceil(b);
	}

  if(floor(a) != ceil(a) || floor(b) != ceil(b) || a < 0 || b < 0){
    cout << 0 << endl;
    exit(0);
  }

  long long n = a+b;
  long long r = min(a,b);

  long long ans = factorial(n) % MOD * modpow(((factorial(r) % MOD) * (factorial(n-r) % MOD)) % MOD, MOD-2, MOD);

  cout << ans % MOD << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    ll h,w,k;
    cin>>h>>w>>k;
    vector<string> A(h);
    for(int i=0;i<h;i++){cin>>A[i];}
    pll s;
    for(int i=0;i<h;i++){
        for(int t=0;t<w;t++){
            if(A[i][t]=='S'){s={i,t};}
        }
    }
    ll ans=E;
    queue<pll> Q;
    Q.push(s);
    vector<vector<ll>> dist(h,vector<ll>(w,E));
    dist[s.F][s.S]=0;
    vector<pll> d={{0,1},{1,0},{-1,0},{0,-1}};
    bool done=false;
    while(!Q.empty() && !done){
        pll W=Q.front(); Q.pop();
        if(dist[W.F][W.S]>=k){continue;}
        for(int i=0;i<4 && !done;i++){
            pll k=W;
            k.F+=d[i].F;
            k.S+=d[i].S;
            if(A[k.F][k.S]=='#' || dist[k.F][k.S]!=E){continue;}
            dist[k.F][k.S]=dist[W.F][W.S]+1;
            Q.push({k.F,k.S});
            if(k.F==0 || k.S==0 || k.F==h-1 || k.S==w-1){
                ans=1;
                done=true;
            }
        }
    }
    for(ll i=0;i<h;i++){
        for(ll t=0;t<w;t++){
            if(dist[i][t]!=E){
                if(ans>1+(i+k-1)/k){ans=1+(i+k-1)/k;}
                if(ans>1+(t+k-1)/k){ans=1+(t+k-1)/k;}
                if(ans>1+(w-1-t+k-1)/k){ans=1+(w-1-t+k-1)/k;}
                if(ans>1+(h-1-i+k-1)/k){ans=1+(h-1-i+k-1)/k;}
            }
        }
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define ll long long
#define N 100010
#define M 1010

using namespace std;
int x, y;

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

int main() {
	cin >> x >> y;
	int a = 2 * x, b = 4 * x;
	if (a <= y && y <= b && y % 2 == 0) {
		puts("Yes");
		return 0;
	} else {
		puts("No");
		return 0;
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
    int main(){
        int bingo[3][3];
        vector<vector<bool>> ans(3,vector<bool>(3,false));
        int N;

        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++)cin>>bingo[i][j];
        }
        cin>>N;
        int b[N];
        for(int i=0;i<N;i++){
            cin>>b[i];

        }

        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                for(int k=0;k<N;k++){
                    if(b[k]==bingo[i][j])ans[i][j]=true;
                }
            }
        }
        bool res=false;
        for(int i=0;i<3;i++){
            if(ans[i][0]==true&&ans[i][1]==true&&ans[i][2]==true)res=true;

        }
        for(int i=0;i<3;i++){
            if(ans[0][i]==true&&ans[1][i]==true&&ans[2][i]==true)res=true;
        }
        if(ans[0][0]==true&&ans[1][1]==true&&ans[2][2]==true)res=true;
        if(ans[0][2]==true&&ans[1][1]==true&&ans[2][0]==true)res=true;

        if(res)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    }






Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <stack>
#include <climits>
#include <utility>
#include <cmath>
#include <iostream>

using namespace std;

#define rep(i,n,m) for(int i=n; i<=m; i++)
#define per(i,n,m) for(int i=n; i>=m; i--)
#define printi(x) printf("%d ", x)
#define printiln(x) printf("%d\n", x)
#define printiarray(a,n) for(int i=0; i<n-1; i++){printf("%d ", a[i]);} printf("%d\n", a[n-1])
#define copyiarray(a,n,b) for(int i=0; i<n; i++){b[i] = a[i];}
#define scani(x) scanf("%d", &x)
#define scaniarray(a,n) for(int i=0; i<n; i++){scanf("%d", &a[i]);}
#define scans(str) scanf("%s",str)
#define scanc(ch) scanf("%c", &ch)
#define mk make_pair
#define printd(x) printf("%lf ", x)
#define printdln(x) printf("%lf\n", x)
#define printllln(x) printf("%lld\n", x)

typedef long long ll;

const int MaxN = 200000;
int L[MaxN/2 + 2], R[MaxN/2 + 2];

ll merge(int *A, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    ll count = 0;
    rep(i,0,n1-1) {
        L[i] = A[left+i];
    }
    rep(i,0,n2-1) {
        R[i] = A[mid + i];

    }
    L[n1] = R[n2] = INT_MAX;
    int i = 0;
    int j = 0;
    rep(k,left,right-1) {
        if(L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        }
        else {
            A[k] = R[j];
            j++;
            count += n1-i;

        }
    }
    return count;
}


ll mergesort(int *A, int left, int right) {
    if(left+1 < right){
        int mid = (left + right)/2;
        ll c1, c2, c3;
        c1 = mergesort(A, left, mid);
        c2 = mergesort(A, mid, right);
        c3 = merge(A, left, mid, right);
        return c1+c2+c3;
    } else {
        return 0;
    }
}

int main() {
    int n, B[MaxN];
    scani(n);
    scaniarray(B,n);
    // int count = 0;
    // count = bubbleSort(a,n);
    // printiln(count);
    ll count = mergesort(B,0,n);
    printllln(count);

    return 0;
}




Measured memory_bytes: 4788
n, a, b = gets.split.map(&:to_i)
if a > b
  puts '0'
elsif n == 1
  puts a == b ? "1" : "0"
elsif n == 2
  x = 2 * a
  y = 2 * b
  puts y - x + 1
else
  x = (n - 2) * a
  y = (n - 2) * b
  puts y - x + 1
end


Measured memory_bytes: 14260