akhauriyash/Code-Regression huggingface dataset:
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

struct UnionFind {
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    int N,M,K;
    cin >> N >> M >> K;
    vecveci F(N);
    vecveci B(N);
    UnionFind UF(N); UF.init(N);
    REP(i,M) {
        int a,b; cin >> a >> b;
        --a; --b;
        F[a].push_back(b);
        F[b].push_back(a);
        UF.merge(a,b);
    }
    REP(i,K) {
        int a,b; cin >> a >> b;
        --a;--b;
        if(UF.issame(a,b)) {
            B[a].push_back(b);
            B[b].push_back(a);
        }
    }
    REP(i,N) {
        cout << UF.size(i) - B[i].size() - F[i].size() - 1 << " ";
    }
    cout << endl;
}

Measured memory_bytes: 13432
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
const int MAX = 5000;
const int MOD = 1e+9+7;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n,int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
ll NHK(ll n,ll k){
	return COM(n+k-1,k)%MOD;
}
int main(){
	ll K,N;
	COMinit();
	scan(N>>K);
	rep1(i,K){
		prin(NHK(i,K-i)*NHK(i+1,N-K-i+1)%MOD);
	}
	return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> h(n+1);
	vector<int> k(n+1, 1);
	for(int i = 1; i <= n; i++) cin >> h.at(i);
	for(int i = 1; i <= m; i++){
		int a, b;
		cin >> a >> b;
		if(h.at(a) > h.at(b)) k.at(b) = 0;
		else if(h.at(a) < h.at(b)) k.at(a) = 0;
		else {
			k.at(a) = 0;
			k.at(b) = 0;
		}
	}
	cout << accumulate(k.begin(), k.end(), 0)-1 << endl;
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

int main()
{
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < 3; i++)
    {
        if (S[i] == 'R')
        {
            ans = 1;
            if (i - 1 > -1)
            {
                if (S[i - 1] == 'R')
                {
                    ans = 2;
                    if (i - 2 > -1)
                    {
                        if (S[i - 2] == 'R')
                        {
                            ans = 3;
                        }
                    }
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin >> h >> w;
  bool bw[w]={0};
  bool bh[h]={0};
  vector<vector<char>> data(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    int cnt_w=0;
    for (int j = 0; j < w; j++) {
      cin >> data.at(i).at(j);
      if (data.at(i).at(j)=='#') {
        bw[j] = 1;
        ++cnt_w;
      }
    }
    if (cnt_w !=0) bh[i] = 1;
  }
  for (int i = 0; i < h; i++) {
    if (!bh[i]) continue;
    else {
    for (int j = 0; j < w; j++) {
      if (!bw[j]) continue;
      else {
        cout << data.at(i).at(j);
      }
    }
    cout << endl;
  }
}
}

Measured memory_bytes: 3632
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a,b;
        a = input.nextInt();
        b = input.nextInt();
        int int_ans = a/b;
        int mod_ans = a%b;
        double float_ans = (double)a/b;
        System.out.printf("%d %d %f\n",int_ans,mod_ans,float_ans);
    }
}


Measured memory_bytes: 26528
N,K = map(int, input().split())
mod = 998244353

LR = []
for _ in range(K):
  LR.append(list(map(int, input().split())))

step = [0 for _ in range(N)]
step[0] = 1
step[1] = -1
answer = 0

for i in range(N):
  answer = (answer+step[i])%mod
  for L,R in LR:
    if i+L < N:
      step[i+L] += answer
    if i+R+1 < N:
      step[i+R+1] -= answer

print((answer)%mod)

Measured memory_bytes: 81040
#include <iostream>
#include <vector>

int main(){
  int N, K, d, s;
  std::cin >> N >> K;
  std::vector<int> S(N, 0);
  
  for (int i = 0; i < K; i++){
    std::cin >> d;
    for (int j = 0; j < d; j ++){
      std::cin >> s;
      S[s - 1]++;
    }
  }
  
  int answer = 0;
  for (int i = 0; i < N; i++){
    if (S[i] == 0) answer++;
  }
  
  std::cout << answer;
  

  return 0;
}

Measured memory_bytes: 3168
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

class RangeMinimumQuery:
    def __init__(self, n, F=min, e=float("inf"), fill=None):
        self.n0 = 2**(n-1).bit_length()
        self.F = F
        self.e = e
        if fill is None:
            fill = e
        self.data = [fill]*(2*self.n0)

    def construct(self, a):
        for i, x in enumerate(a):
            self.data[i+self.n0-1] = x
        for i in range(self.n0-2, -1, -1):
            self.data[i] = self.F(self.data[2*i+1], self.data[2*i+2])

    def query(self, l,r):
        l += self.n0
        r += self.n0
        res = self.e
        while l < r:
            if r&1:
                r -= 1
                res = self.F(res, self.data[r-1])
            if l&1:
                res = self.F(res, self.data[l-1])
                l += 1
            l >>=1
            r >>=1
        return res

    def update(self, i, x):
        i += self.n0-1
        self.data[i] = x
        while i:
            i = ~-i//2
            self.data[i] = self.F(self.data[2*i+1], self.data[2*i+2])


from bisect import bisect_left

mod = 998244353

n = int(input())
xd = [list(map(int, input().split())) for i in range(n)]
xd.sort()
xs = [i for i,j in xd]

RMQ = RangeMinimumQuery(n, max,0,0)
RMQ.construct(list(range(n)))

for i in reversed(range(n)):
    r = sum(xd[i])
    j = bisect_left(xs, r)
    k = RMQ.query(i, j)
    RMQ.update(i, k)

DP = [0]*(n+1)
DP[-1] = 1
for i in reversed(range(n)):
    j = RMQ.query(i, i+1)
    DP[i] = DP[i+1]+DP[j+1]
    DP[i] %= mod
print(DP[0])


Measured memory_bytes: 101412
#include <stdio.h>

int main(void)
{
	char c;
	int s[26]={0},i,j;
	while(scanf("%c",&c)!=EOF)for(j=0;j<26;j++)if(c==j+'a'||c==j+'A')s[j]++;
	for(i=0;i<26;i++)printf("%c : %d\n",i+'a',s[i]);
	return 0;
}


Measured memory_bytes: 2136
import sys

N = int(input())
nodes = [set() for _ in range(N)]
for line in sys.stdin:
    u, v, w = map(int, line.split())
    u, v = (u - 1, v - 1)
    nodes[u].add((v, w))
    nodes[v].add((u, w))


ans = [-1 for _ in range(N)]
q = [(0, 0, -1)]

while q:
    v, dist, parent = q.pop()

    if dist % 2 == 0:
        ans[v] = 0
    else:
        ans[v] = 1

    for u, w in nodes[v]:
        if u == parent:
            continue

        q.append((u, dist + w, v))

print("\n".join(map(str, ans)))


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

namespace ForAtCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            string[] str = Console.ReadLine().Split(' ');

            List<int> xi = str.Select(int.Parse).ToList();

            int min = xi.Min();
            int max = xi.Max();

            long dist = long.MaxValue;

            for (int p = min; p <= max; p++)
            {
                long tmpdist = 0;

                for (int i = 0; i < n; i++)
                {
                    tmpdist += (long)(Math.Pow((xi[i] - p), 2));
                }

                if (tmpdist < dist)
                {
                    dist = tmpdist;
                }
            }

            Console.WriteLine(dist);
        }
    }
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

	int a=0;
	rep(i,k){
		a=(10*a+7)%k;
		if(a==0) return printf("%d\n",i+1),0;
	}
	puts("-1");

	return 0;
}


Measured memory_bytes: 3788
#include<iostream>
using namespace std;
int main(){
  int a[31]={},i,b;
    for(i=0;i<28;i++){
      cin>>b;
      a[b]=1;
    }
    for(i=1;i<=30;i++)
      if(a[i]==0)
	cout<<i<<endl;
    return 0;
  }

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int a[200010];
int b[200010];

int main() {
    int N, K;
    cin >> N >> K;
    rep(i, N) {
        cin >> a[i];
        b[a[i]]++;
    }

    sort(b, b + N+1);
    int cou = 0;
    for(int i=1;i<=N;i++) {
        if (b[i] != 0)cou++;
    }
    int ans = 0;
    for(int i=1;i<=N;i++) {
        if (K >= cou)break;
        if (b[i] == 0)continue;
        ans += b[i];
        cou--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scl1(a) scanf("%lld",&a)
#define scl2(a,b) scanf("%lld%lld",&a,&b)
#define scl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pr1(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d ",a,b)
#define pr3(a,b,c) printf("%d %d %d ",a,b,c)
#define mii map<int,int>
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pair<int,int>>
#define mii map<int,int>
#define ll long long
#define ii pair<int,int>
#define loop(i,a,b) for(int i=(a);i<(b);i++)
#define rloop(i,a,b) for(int i=(a);i>(b);i--)
#define tr(it,c) for(decltype((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define ft first
#define sd second
#define mod 998244353
#define mod2 1000000007
#define mem(a,b) memset(a,b,sizeof(a))
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL)
 
using namespace std;
int gcd(int a,int b)
{
	if(a<b)
	swap(a,b);
	if(b==0)
	return a;
	while((a=a%b)!=0)
	{
		swap(a,b);
	}
	return b;
}
ll modpow(ll x,int y)
{
	ll res=1;
	while(y>0)
	{
		if(y&1)
		res=res*x%mod2;
		y=y>>1;
		x=x*x%mod2;
	}
	return res;
}
ll ncr(int n,int r)
{
	ll f1=1,f2=1;
	loop(i,n-r+1,n+1)
	f1=f1*i%mod;
	loop(i,1,r+1)
	f2=f2*i%mod;
	return f1*modpow(f2,mod-2)%mod;
}
int *sieve(int n)
{
	int *lpf=new int[n+1];
	for(int i=1;i<=n;i++)
	lpf[i]=i;
	int rt=(int)floor(sqrt(n))+1;
	loop(i,2,rt)
	{
		if(lpf[i]!=i)
		continue;
		for(int j=i*i;j<=n;j+=i)
		{
			if(lpf[j]==j)
			lpf[j]=i;
		}
	}
	return lpf;
}









void solve()
{
	ll n,d;
	cin>>n>>d;
	ll x,y;
	int cnt=0;
	while(n--)
	{
		cin>>x>>y;
		if(sqrt(x*x+y*y)<=d)
		cnt++;
	}
	cout<<cnt;
	
}

int main()
{
	SYNC;
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int t=1;
	//cin>>t;
	while(t--)
	{
		//cout<<"Case #"<<z+1<<": ";
		solve();
		cout<<"\n";
	}
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll V = 100000;
const ll INF = 1LL << 60;
using P = pair<ll, ll>;
vector<P> G[V];	//pair<辺の距離, 行き先の頂点>
ll dist[V]; //dist[i]はsから頂点iへの最短距離が入る
bool used[V];
void dijkstra(ll s) {	//s : 始点
	//初期化
	fill_n(dist, V, INF);
	fill_n(used, V, false);

	priority_queue<P, vector<P>, greater<P>> q;
	q.push(P(0, s));
	while (!q.empty()) {
		ll d;	//d : sからの距離
		ll t;	//t ; 行き先
		tie(d, t) = q.top();
		q.pop();
		if (used[t]) {	//もう探索済みか
			continue;
		}
		used[t] = true;
		dist[t] = d;
		for (P e : G[t]) {
			if (dist[e.second] <= d + e.first) {	//枝刈り
				continue;
			}
			q.push(P(d + e.first, e.second));
		}
	}
}

int main() {
	ll n;

	cin >> n;

	cout << n / 3 << endl;
}

Measured memory_bytes: 2560
A=input()
B=input()
C=input()
ListA=list(A)
ListB=list(B)
ListC=list(C)
pile = "a"
res = ""
for i in range(400):
  if pile == "a":
    pile = ListA.pop(0)
  elif pile == "b":
    pile = ListB.pop(0)
  else:
    pile = ListC.pop(0)
  if len(ListA) == 0 and pile == "a":
    res = "A"
    break
  elif len(ListB) == 0 and pile == "b":
    res = "B"
    break
  elif len(ListC) == 0 and pile == "c":
    res = "C"
    break
  else:
    pass
print(res)

Measured memory_bytes: 9052
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
# n = II()
# dp = [INF] * n
# h = LI()
# dp[0], dp[1] = 0, abs(h[1] - h[0])
# for i in range(2, n):
    # dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i])
    # dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i])
# P(dp[n-1])
a = II()
b = II()
c = II()
d = II()
e = II()
k = II()
list = sorted([a,b,c,d,e])[::-1]
for i in range(len(list)):
    for j in range(i+1,len(list)):
        if list[i] - list[j] > k:
            print(':(')
            exit()
print('Yay!')


Measured memory_bytes: 5376
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    if (n % k == 0) {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
N,a = map(int, input().split())
if a <= 0 and a+N-1 >= 0:
    print(int(N*(2*a+N-1)/2))
elif a+N-1 < 0:
    print(int((N-1)*(2*a+N-2)/2))
else:
    print(int((N-1)*(2*a+N)/2))

Measured memory_bytes: 3060
#include<iostream>
#include<map>
using namespace std;
int main() {
    int h, w; cin >> h >> w;
    char s[h][w];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> s[i][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int flg = 0;
            if (s[i][j] == '#') {
                if (i - 1 >= 0 && s[i - 1][j] == '.') {
                    flg++;
                }
                if (i + 1 < h && s[i + 1][j] == '.') {
                    flg++;
                }
                if (j - 1 >= 0 && s[i][j - 1] == '.') {
                    flg++;
                }
                if (j + 1 < w && s[i][j + 1] == '.') {
                    flg++;
                }
                if (flg == 4) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}




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

using namespace std;

void solve()
{
	string S;
	cin >> S;
	cout << (S > "2019/04/30" ? "TBD" : "Heisei") << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, M, K, A, C{}; cin >> N >> M;
  map<int, int> m; while (cin >> K) while (K--) cin >> A, ++m[A];
  for (auto [_, c] : m) C += c == N;
  cout << C;}

Measured memory_bytes: 3528
import itertools

n,m=map(int,input().split())
ks=[]
for i in range(m):
    ksi=list(map(int,input().split()))
    ks.append(ksi)
p=list(map(int,input().split()))
    
icnt=0
for i in itertools.product([0,1], repeat=n):
    yn=""
    mcnt=0
    for j in range(m):
        ksum=0
        for k in range(ks[j][0]):
            if i[ks[j][k+1]-1]==1:
                ksum+=1
        if ksum%2==p[j]:
            mcnt+=1
    if mcnt==m:
        icnt+=1
#    print(icnt,mcnt,i)
print(icnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (autaaaaaaaaaaaaaaaaaaaaaaao &&itr : k)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;


const ll INF = 1ll << 60;
const ll MOD = 1000000007;
int n;
vector<int> v(100000);


int main()
{
    int n,w;
    cin >> n >> w;
    vector<vector<ll>> dp(n+1,vector<ll>(n*1000+1,INF));
    dp[0][0]=0;
    pair<int,int> inp[n];
    REP(i,n){
        cin >> inp[i].first >> inp[i].second;
    }
    REP(i,n){
        REP(j,1000*n+1){
            if(j-inp[i].second>=0) dp[i+1][j]=min(dp[i+1][j],dp[i][j-inp[i].second]+inp[i].first);
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
        }
    }
    ll ans=0;
    REP(i,1000*n){
        if(dp[n][i+1]<=w){
            ans=i+1;
        }
    }
    cout << ans << endl;
}

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

void solve(long long N, long long D, long long X, std::vector<long long> A){
    ll ans = X;
    for(ll i=0; i< N; i++){
        ans += (D-1)/A[i]+1;
    }
    cout << ans << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, D, X, std::move(A));
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
from math import sqrt

def area(a, b, c):
        d = (a + b + c) / 2.0
        return sqrt(d * (d - a) * (d - b) * (d - c))

for line in stdin:
        (a, l, x) = map(int, line.split())
        print "%.6f" % (area(a, l, l) + 2 * area(l, (l + x) / 2.0, (l + x) / 2.0))

Measured memory_bytes: 4400
/*
 * シカのAtCoDeerくんは選挙速報を見ています。選挙には二人の候補高橋くんと青木くんが出ています。速報では、現在の二人の得票数の比が表示されていますが、得票数そのものは表示されていません。
 * AtCoDeerくんは N 回画面を見て、 i(1≦i≦N) 回目に見たときに表示されている比は Ti:Ai でした。
 * ここで、AtCoDeerくんが選挙速報の画面を1回目に見た段階で既にどちらの候補にも少なくとも一票は入っていたことがわかっています。
 * N 回目に画面を見たときの投票数(二人の得票数の和)として考えられるもののうち最小となるものを求めてください。ただし、得票数が途中で減ることはありません。
 */

import java.util.*;
	public class Main{
		public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int n = Integer.parseInt(sc.next());
            
            long t = 1;
            long a = 1;
            
            // 
            for(int i=0; i<n; i++){
            	// 
            	int ti = Integer.parseInt(sc.next());
                int ai = Integer.parseInt(sc.next());
                long temp = (long)Math.max(ceil(t, ti), ceil(a, ai));
                t = temp * ti;
                a = temp * ai;
            }
            
            System.out.println(t + a);
            sc.close();
		}
		
		public static long ceil(long a, long b){
			long ret = a/b;
			
            if(a%b != 0){
            	ret ++;
            }
            
            return ret;
		}
    }
	

Measured memory_bytes: 24532
#include<cstdio>
#include<cstring>
using namespace std;
char s[111111];
char s1[111111];
int l;
int main()
{
	gets(s);
	l=strlen(s);
	for(int i=0;i<l;++i)
	{
		switch(s[l-i-1])
		{
			case 'b':s1[i]='d';break;
			case 'd':s1[i]='b';break;
			case 'p':s1[i]='q';break;
			case 'q':s1[i]='p';break;
		}
	}
	if(strcmp(s,s1))printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,d,c;
    cin>>n>>d;
    long long int x[n],y[n];
    c=0;
    for(int i=0; i<n; i++)
    {
        cin>>x[i]>>y[i];
        if((sqrt(pow(x[i],2)+pow(y[i],2)))<=d)
        {
            c++;
        }
    }

    cout<<c<<endl;

}


Measured memory_bytes: 6732
if __name__ == '__main__':
    S = input()
    d = {'SUN':7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRI":2, "SAT":1}
    if d.get(S, False):
        print(d[S])
    else:
        res = -1
        for i in d.keys():
            if i in S or i.lower() in S:
                res = d[i]
                break
        print(res)

Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int N,T,ans=100000;cin>>N>>T;
    bool b=false;
    for(int i=0;i<N;i++){
        int c,t;
        cin>>c>>t;
        if(t<=T){
            ans=min(ans,c);
            b=true;
        }
    }
    if(b)cout<<ans<<endl;
    else cout<<"TLE"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
using namespace std;
int main() {
  intc(n);
  vector<int> a(n);
  string s="APPROVED";
  r1(i, n) {
    cin >> a.at(i);
    if(a.at(i)%2==0 && a.at(i)%3!=0 && a.at(i)%5!=0) s="DENIED";
  }
  cout << s << endl;
}


Measured memory_bytes: 256
while(True):
    m,n = map(int,input().split())
    if not m: break
    a = [True]*m
    j = -1
    for i in range(1,n+1):
        if sum(a) < 2: input(); continue
        j = (j+1+((a+a)[j+1:]).index(True))%m
        s = input()
        if not i%15:
            if s == "FizzBuzz": continue
            else: a[j] = False; continue
        if not i%5:
            if s == "Buzz": continue
            else: a[j] = False; continue
        if not i%3:
            if s == "Fizz": continue
            else: a[j] = False; continue
        if s != str(i): a[j] = False;continue
    print(" ".join(str(e+1) for e in range(m) if a[e]))


Measured memory_bytes: 5648
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():
 
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'
 
    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5
 
 
    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]
 
        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
 
 
    def equals(self,another):
 
        ret = False;
 
        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True
 
        return ret
 
 
 
num_dice = int(input())
DICE = []
 
for i in range(num_dice):
    table = list(map(int,input().split()))
    tmp_dice = Dice()
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    DICE.append(tmp_dice)
 
FLG = True
 
for i in range(num_dice-1):
    for k in range(i+1,num_dice):
        if DICE[i].equals(DICE[k]) == True:
            FLG = False
            break
 
 
if FLG == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 6404
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N, M;
	List<Pair> answers;
	Set<Integer> accepts;
	Map<Integer, Integer> penalties;

	static class Pair {
		int p;
		String S;

		Pair(int p, String S) {
			this.p = p;
			this.S = S;
		}
	}

	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 {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		this.answers = new ArrayList<>(M);
		for (int i = 0; i < M; ++i) {
			tokens = in.readLine().split(" ");
			this.answers.add(new Pair(Integer.parseInt(tokens[0]), tokens[1]));
		}
	}

	void calc() {
		this.accepts = new HashSet<>();
		this.penalties = new HashMap<>();
		for (Pair pair : answers) {
			if (!this.penalties.containsKey(pair.p)) {
				this.penalties.put(pair.p, 0);
			}
		}
		for (Pair pair : answers) {
			if (pair.S.equals("AC")) {
				this.accepts.add(pair.p);
			} else {
				if (!this.accepts.contains(pair.p)) {
					this.penalties.put(pair.p, this.penalties.get(pair.p) + 1);
				}
			}
		}

	}

	void showResult() {
		int acceptNum = this.accepts.size();
		int penaltyNum = 0;
		for (Integer key : this.accepts) {
			penaltyNum += this.penalties.get(key);
		}
		System.out.println(acceptNum + " " + penaltyNum);
	}
}

Measured memory_bytes: 52520
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
const ll M=1e9+7;
const int MAXN=3e5+4;
const int MAXN2=5e4;






int main(){

	string s;
	cin>>s;

	int d;
	cin>>d;

	int len=s.length();

	vector<vector<int>> dp(d,vector<int>(2));

	dp[0][0]=1;




	for(int i=0;i<len;i++){
		vector<vector<int>> dp_new(d,vector<int>(2));
		for(int sum=0;sum<d;sum++){
			for(bool smal:{false,true}){



				for(int digit=0;digit<10;digit++){

					if(digit>(s[i]- '0') && smal==0){
						break;
					}

					dp_new[(sum+digit)%d][smal || (digit<(s[i]-'0'))]+=dp[sum][smal];
					dp_new[(sum+digit)%d][smal || (digit<(s[i]-'0'))]%=M;
				}
			}
		}

		dp=dp_new;
	}


	
	ll ans=(dp[0][0] + dp[0][1])%M;
	ans=(ans-1+M)%M;
	
	pfln(ans)
	
	return 0;	
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

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

		String S = sc.next();
		switch (S) {
		case "Sunny":
			System.out.println("Cloudy");
			break;
		case "Cloudy":
			System.out.println("Rainy");
			break;
		case "Rainy":
			System.out.println("Sunny");
			break;
		}
	}
}

Measured memory_bytes: 21716
//042
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int n, l;
    cin >> n >> l;
    vector<string>S(n);
    rep(i, n) cin >> S[i];
    sort(S.begin(), S.end());
    rep(i, n) cout << S[i];
}

Measured memory_bytes: 256
S=input()
N=len(S)
list1=list(S)[::-1]

flag=True

if list(S)!=list1:
    flag=False

list2=list(S)[:(N-1)//2]
if list2!=list2[::-1]:
    flag=False

list3=list(S)[(N+3)//2-1:]
if list3!=list3[::-1]:
    flag=False

if flag:
    print('Yes')
else:
    print('No')

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

int N;

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

	cin >> N;

	vector<int> H(N);

	for(auto &x: H) cin >> x;

	int ans = 0,under = H[0];
	REP(i,N){
		if(H[i] >= under){
			ans++;
		 	under = H[i];
		}		
	}
	cout << ans << endl;

}

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

#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DBG         cerr << __LINE__ << " Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction


int freq[300];
int main()
{
    //freopen("maxon.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    string s;
    cin >> s;
    if(s.size() < 26)
    {
        for(int i = 0; i<s.size(); i++)
            freq[s[i]-'a']++;
        char c;
        for(int i = 0; i<26; i++)
        {
            if(freq[i] == 0)
            {
                c = i+'a';
                break;
            }
        }
        s += c;
        cout << s << endl;
    }
    else
    {
        string a = s;
        next_permutation(all(a));
        if(a > s)
        {
            for(int i = 0; i<a.size(); i++)
            {
                printf("%c",a[i]);
                if(a[i] != s[i])
                    break;
            }
        }
        else
            cout << -1 << endl;
    }
    return 0;
}




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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	
	if(a==b&&c!=a)
		cout<<"Yes";
	else if(a==c&&b!=a)
		cout<<"Yes";
    else if(b==c&&a!=b)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;int main() {int n;while(cin>>n) {int jwb=0;for(int i=0;i<10;i++) {for(int j=0;j<10;j++) {for(int k=0;k<10;k++) {for(int l=0;l<10;l++) {if(i+j+k+l==n) jwb++;}}}}cout<<jwb<<endl;}return 0;}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    string s;
    cin >> s;
    int month = (s[5]-'0')*10 + s[6]-'0';
    int day = (s[8]-'0')*10 + s[9]-'0';
    //cout << month << " " << day << endl;
    if(month >= 5){
        cout << "TBD" << endl;
    }else{
        cout << "Heisei" << endl;
    }



    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val Array(n, k) = io.StdIn.readLine().split(' ').map(_.toInt)
  val hn = io.StdIn.readLine().split(' ').map(_.toInt).sorted(Ordering[Int].reverse)
  println(hn.drop(k).foldLeft(0: Long)((acc, x) => acc + x))
}

Measured memory_bytes: 73072
#include <iostream>
#include <set>
#include <algorithm>

int main() {
    int N;
    std::cin >> N;

    std::multiset<int> A;
    std::set<int> A_unique;
    for (int i = 0; i < N; i ++) {
        int a;
        std::cin >> a;
        A.insert(a);
        A_unique.insert(a);
    }

    int n_remove = 0;
    for (int a : A_unique) {
        int count = A.count(a);
        if (count < a) {
            n_remove += count;
        } else if (count > a) {
            n_remove += count - a;
        }
    }
    std::cout << n_remove << std::endl;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
typedef long long ll;
const ll MOD = 1000000007;
// long long a;
bool isprime(ll n){
  // n >  2 
  if(n == 2||n == 3) return true;
  for(ll i = 2; i <= (ll)sqrt(n); i ++){
    if(n%i == 0){
      return false;
    }
  }
  return true;
}
ll count(ll a, ll b){
  ll c = 0;
  while(a%b == 0){
    a /= b;
    c++;
  }
  return c;
}
int main(){
  ll N;
  cin >> N;
  long num = 0;
  long tot = 1;
  for(ll i = 2; i <= N; i++ ){
    if(isprime(i)){
      // cout << "i = " << i << ", isprime(i) = "<< isprime(i) << endl;
      num = 0;
      for(ll j = i; j <= N; j++ ){
	num += count(j, i);
	// cout << "count(" << j << "," <<i<<")="<< count(j, i) << endl;
      }
      // cout << "num = " << num << endl;
      tot *= (num + 1);
      tot %= MOD;
    }
  }
  cout << tot << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

int N, M;
int ans = 1;

int main() {
	register int i;
	scanf("%d%d", &N, &M);
	if(abs(N - M) > 1) return puts("0"), 0;
	for(i = 1; i <= N; ++i) ans = 1ll * ans * i % 1000000007;
	for(i = 1; i <= M; ++i) ans = 1ll * ans * i % 1000000007;
	if(N == M) ans = 1ll * ans * 2 % 1000000007;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int d(int w, int x, int y, int z)
{
	if((y-w)*(z-x)>=0)
	{
		return max(abs(y-w), abs(z-x));
	}
	else
	{
		return abs(y-w)+abs(z-x);
	}
}
int W, H, N;
int w[1000], h[1000];
int ans;
int main()
{
	ans=0;
	cin >> W >> H >> N;
	for(int i=0; i<N; i++)
	{
		cin >> w[i] >> h[i];
	}
	for(int i=0; i<N-1; i++)
	{
		ans+=d(w[i], h[i], w[i+1], h[i+1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1168
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=1e5+10;
int sum[L];
int main() {
	int N,M;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		int u=r+1;
		for(int i=1;i<u;i++){
			int a=(l-1)/i+1;
			int b=r/i+1;
			if(a<b){
				sum[i]++;
				sum[i+1]--;
				b=min(b,u);
				u=a;
				a=max(a,i+1);
				if(a<b){
					sum[a]++;
					sum[b]--;
				}
			}
		}
	}
	for(int i=1;i<=M;i++){
		sum[i]+=sum[i-1];
		printf("%d\n",sum[i]);
	}

	return 0;
}



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

#define mod 1000000007
const int O=2001;
long long fac[10010],inv[10010];
int n,x,y,f[4010][4010],ans=0;
int a[2000005],b[2000005];

inline int C(int n,int m){
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

inline int Add(int x,int y){
	if(x+y<mod)return x+y;
	else return x+y-mod; 
}

int main(){
//	freopen("in.cpp","r",stdin);
	scanf("%d",&n);
	inv[0]=inv[1]=fac[0]=1;
	for(int i=1;i<=10001;i++)fac[i]=fac[i-1]*i%mod;
	for(int i=2;i<=10001;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<=10001;i++)(inv[i]*=inv[i-1])%=mod;
	for(int i=1;i<=n;i++){
		scanf("%d%d",a+i,b+i);
		f[-a[i]+O][-b[i]+O]++;
		ans=ans-C(a[i]+b[i]<<1,a[i]<<1)+mod;
		if(ans>=mod)ans-=mod; 
	}
	for(int i=1;i<=4001;i++)
	for(int j=1;j<=4001;j++){
		f[i][j]=Add(f[i][j],Add(f[i-1][j],f[i][j-1]));
	}
	for(int i=1;i<=n;i++)
		ans=Add(ans,f[a[i]+O][b[i]+O]);
	printf("%d",ans*inv[2]%mod);
}

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

int main(){
	ll a, b;
	cin >> a >> b;
	int f = 100;
	if (a<=0) {
		if (b>=0) f = 0;
		else {
			if ((b-a)%2 == 1) f = 1;
			else f = -1;

			if (b==a) f = 1;
		}
	}
	else f = 1;

	switch (f) {
		case 1:
			cout << "Positive" << endl;
			break;
		case -1:
			cout << "Negative" << endl;
			break;
		case 0:
			cout << "Zero" << endl;
			break;
	}
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
int main(){
    ll n, a, b, check=0;
    bool flag = true;
    cin >> n;
    vector<pair<ll, ll>> BA(n);
    for(ll i=0;i<n;i++){
        cin >> a >> b;
        BA[i] = make_pair(b, a);
    }
    sort(BA.begin(), BA.end());
    for(auto itr=BA.begin();itr!=BA.end();itr++){
        check += itr->second;
        if(check>(itr->first)){
            flag = false;
            break;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
 
}


Measured memory_bytes: 3328
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        p: [usize; n],
    }

    let mut counts = vec![0; n+1];
    for v in p {
        counts[v] = counts[v-1] + 1;
    }
    let ans = n - counts.iter().max().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 6536
#include <bits/stdc++.h>
using namespace std ;
char ch[ 110 ] ;
int k , len ;
signed main () {
    cin >> k ;
    cin >> ch + 1 ;
    len = strlen ( ch + 1 ) ;
    if ( len <= k ) cout << ch + 1 << endl ;
    else {
        for ( int i = 1 ; i <= k ; i ++ ) cout << ch[ i ] ;
        cout << "...\n" ;
    }
    return 0 ;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 1e5 + 7;
const int maxm = 1e6 + 7;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-10;
int n;
int fa[maxn];
struct node
{
    long long u, v, w;
};
vector<node> edge;
bool operator<(node a, node b)
{
    return a.w < b.w;
}
struct node2
{
    long long x, y, id;
} city[maxn];

bool cmp1(node2 a, node2 b)
{
    return a.x < b.x;
}

bool cmp2(node2 a, node2 b)
{
    return a.y < b.y;
}
void init()
{
    for (int i = 1; i < maxn; i++)
        fa[i] = i;
}
int get(int x)
{
    return fa[x] == x ? x : fa[x] = get(fa[x]);
}
long long ans;
int main(int argc, char const *argv[])
{
    init();
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld%lld", &city[i].x, &city[i].y);
        city[i].id = i;
    }
    sort(city + 1, city + 1 + n, cmp1);
    for (int i = 1; i < n; i++)
        edge.push_back(node{city[i].id, city[i + 1].id, abs(city[i].x - city[i + 1].x)});

    sort(city + 1, city + 1 + n, cmp2);
    for (int i = 1; i < n; i++)
        edge.push_back(node{city[i].id, city[i + 1].id, abs(city[i].y - city[i + 1].y)});

    sort(edge.begin(),edge.end());

    for(int i=0;i<edge.size();i++)
    {
        int x=get(edge[i].u);
        int y=get(edge[i].v);
        if(x==y)
            continue;
        fa[x]=y;
        ans+=edge[i].w;
    }
    
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 11248
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

ll mod;

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

/*

// a bit of NT

const int _N = 1234567;

ll F[_N];
ll IF[_N];

void init() {
	F[0] = 1;
	for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
	IF[_N-1] = power(F[_N-1], mod-2);
	for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}

ll ncr(ll x, ll y) {
	if(y > x || y < 0) return 0;
	return mul(F[x], mul(IF[x-y], IF[y]));
}

ll euler(ll m) {
	ll res = 1;
	for(ll i = 2; i*i <= m; i++) {
		if(m%i == 0) {
			m /= i;
			res *= (i - 1);
			while(m % i == 0) {
				m /= i;
				res *= i;
			}
		}
	}
	if(m > 1) res *= (m-1);
	return res;
}

/**/

#define max_n 100001

int n;
ll phi;
ll dp1[max_n];
vector <int> g[max_n];

void dfs(int u, int p) {
	ll res = 1;
	for(int v : g[u]) {
		if(v == p) continue;
		dfs(v, u);
		res = mul(res, add(dp1[v], 1));
	}
	dp1[u] = res;
}

ll dp[max_n];

void DFS(int u, int p, ll up) {
	dp[u] = mul(dp1[u], add(1, up));
	vector <ll> all;
	all.pb(1);
	for(int v : g[u]) {
		if(v == p) continue;
		all.pb(add(1, dp1[v]));
	}
	all.pb(1);
	vector <ll> pre(sz(all), 1);
	for(int i=1; i<sz(all); i++) {
		pre[i] = mul(pre[i-1], all[i]);
	}
	vector <ll> suf(sz(all), 1);
	for(int i = sz(all)-2; i>=0; i--) {
		suf[i] = mul(suf[i+1], all[i]);
	}
	int i = 0;
	for(int v : g[u]) {
		if(v == p) continue;
		i++;
		ll L = pre[i-1];
		ll R = suf[i+1];
		DFS(v, u, mul(mul(L, R), add(1, up)));
	}
}

int main() {
	// ll start = clock();
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n >> mod;
	for(int i=1; i<n; i++) {
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}

	dfs(1, 0);
	DFS(1, 0, 0);

	for(int i=1; i<=n; i++) cout << dp[i] << endl;

	// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
	return 0;
}

Measured memory_bytes: 25472
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello
{
    public static void Main()
    {
        //入力を保持する
        var N = int.Parse(Console.ReadLine());
        var As = Console.ReadLine().Split().Select(e => int.Parse(e)).OrderBy(e => e).ToArray();
        //As配列内に1が1つ存在している場合は1以外は1によりすべて割り切れるため1が回答となる
        if ((As.Count(e => e == 1) == 1))
        {
            Console.WriteLine("1");
            return;
        }
        //1が1よりも多く存在している場合、1も1で割り切れるため0が回答となる
        if ((As.Count(e => e == 1) > 1))
        {
            Console.WriteLine("0");
            return;
        }

        //As配列に含まれる数字の数をカウントするためNがとりうる最大の数分配列を準備する
        var cnt = new int[1000001];
        for (var num = 0; num < N; num++)
        {
            cnt[As[num]] = cnt[As[num]] + 1;
        }
        //Asに含まれる数字の倍数すべてをbool型で保持する
        //-->割り切れないというのは言い換えればAiがその他の数の倍数にならないということ
        var baisuFlgs = new bool[1000001];
        for (var num = 0; num < N; num++)
        {
            var temp = As[num];
            while(temp + As[num] <= 1000000)
            {
                //Console.WriteLine("before : "+temp);
                temp = temp + As[num];
                //Console.WriteLine("after : "+temp);
                baisuFlgs[temp] = true;
            }
            //Console.WriteLine("---------------------");

        }

        //cnt配列内にAiの数が1であり、かつbaisuFlags配列内にAiの倍数のインデックスがFalseであればカントアップしていく
        var ans = 0;
        foreach (var i in As)
        {
            if (baisuFlgs[i] == false && cnt[i] == 1)
            {
                ans = ans + 1;
            }
        }
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 49960
k,n=map(int,input().split())
a=list(map(int,input().split()))
max_da=0

for i in range(n-1):
    d=abs(a[i]-a[i+1])
    max_da=max(d,max_da)

d=k-abs((a[0]-a[n-1]))
max_da=max(d,max_da)

print(k-max_da)

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

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int a[200000],b[200000],c[200000];

int main(){
	int n;ll m;int q;cin>>n>>m>>q;
	UnionFind uf(n);
	rep(i,q){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		if(c[i]==0)uf.unite(a[i],b[i]);
	}
	bool f=true;
	rep(i,q){
		if(c[i]==1){
			f=false;
			if(uf.same(a[i],b[i])){
				puts("No");return 0;
			}
		}
	}
	int Min=0;
	int cnt=0;
	rep(i,n){
		if(uf.find(i)!=i)continue;
		cnt++;
		Min+=uf.size(i)-1;
	}
	if(cnt==1){
		if(m==Min)puts("Yes");
		else puts("No");
	}
	else if(cnt==2){
		if(f&&m==Min)puts("Yes");
		else puts("No");
	}
	else if(n-f<=m&&m<=Min+cnt*ll(cnt-1)/2){
		puts("Yes");
	}
	else{
		puts("No");
	}
}

Measured memory_bytes: 2176
using System;

class Program
{
  static void Main()
  {
    int h, w;
    string[] ary;

    while (true)
    {
      ary = Console.ReadLine().Split();
      h = int.Parse(ary[0]);
      w = int.Parse(ary[1]);

      if (h == 0 && w == 0) break;

      for (int i = 0; i < h; i++)
      {
        for (int j = 0; j < w; j++)
        {
          Console.Write("#");
        }
        Console.WriteLine();
      }
      Console.WriteLine();
    }
  }
}

Measured memory_bytes: 8896