akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  int min = MIN(b, d);
  int max = MAX(a, c);
  if (min - max < 0) printf("%d\n", 0);
  else               printf("%d\n", min - max);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<string>
using namespace std;
typedef long long int ll;
//#pragma GCC optimize "trapv"
#define fi first
#define sec second
#define pb push_back
//#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solve(){
	int  n;
	cin>>n;
	vector<bool> pr(n+1,1);
	vector<ll> div(n+1,1);
	for(int i=2;i<=n;i++){
		if(pr[i]){
			div[i]=2;
			for(int k=2;k*i<=n;k++){
				pr[k*i]=0;
				int count=0;
				int temp=k*i;
				while(temp%i==0){
					temp/=i;
					count++;
				}
				div[k*i]*=count+1;
			}
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		ans+=(ll(i))*div[i];
	}
	cout<<ans<<endl;
}
int main(){
	fio;
	int test;
	//cin>>test;
	test=1;
	while(test--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 82620
N = gets.to_i
A = gets.split.map &:to_i

Yes = "Yes"
No = "No"

m = A.max

case m - A.min
when 0
  puts(0 <= m && m <= N/2 || m == N-1 ? Yes : No)
when 1
  x = A.count m-1
  puts(m > x && N-x >= (m-x) * 2 ? Yes : No)
else
  puts No
end


Measured memory_bytes: 10116
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))

A.sort()
if n&1:
    a = -sum(A[:n//2+1])*2 + sum(A[n//2+1:])*2 + A[n//2] + A[n//2-1]
    b = -sum(A[:n//2])*2 + sum(A[n//2:])*2 - A[n//2] - A[n//2+1]
    print(max(a,b))
else:
    ans = sum(A[n//2:])*2 - sum(A[:n//2])*2 - A[n//2] + A[n//2 - 1]
    print(ans)


Measured memory_bytes: 51416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


// https://ei1333.hateblo.jp/entry/2017/04/10/224413
// ある頂点を根としたものを構成
// すべての頂点を根としたものを構成
struct edge { int to, cost; };
int n;
const int maxn = 150005;
vector<edge> G[maxn];
double E[maxn];
vector<double> ans(maxn);

void dfs(int v, int p) {
  double E2 = 0;
  int cnt = 0;
  for (edge& e : G[v]) {
    if (e.to == p) continue;
    dfs(e.to, v);
    // dfs から上がってきたタイミングで
    E2 += E[e.to] + 1;
    cnt++;
  }
  if (cnt) E[v] = E2 / cnt;
}

// v を根とする答え
void dfs2(int v, double Epar, int p) {
  double ret = 0;
  for (edge& e : G[v]) {
    // 親との距離と, 親方向の部分木で一番遠い頂点との距離の和
    if (e.to == p) ret += Epar + e.cost;
    // 部分木の, ある頂点 j への距離と, j と j の部分木内での一番遠い頂点との距離の和
    else ret += e.cost + E[e.to], e.to;
  }
  ans[v] = ret / sz(G[v]);

  for (edge& e : G[v]) {
    if (e.to == p) continue;
    dfs2(e.to, sz(G[v]) == 1 ? 0 : (ret - (E[e.to] + 1)) / (sz(G[v]) - 1), v);
    // sz(G[v]) == 1, 葉
    // 0 = 0/1

  }
}

void solve() {
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--; // debuged
    G[a].eb(edge{b, 1});
    G[b].eb(edge{a, 1});
  }
  dfs(0, -1);
  // rep(i, n) cout << E[i] << " "; cout << endl;
  dfs2(0, 0, -1);
  rep(i, n) cout << ans[i] << endl;
}


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

using namespace std;

int main (void) {
    int N, M;
    cin >> N >> M;
    vector<int> city(N, 0);
    int city_a, city_b;

    for ( int i=0; i<M; i++ ) {
        cin >> city_a >> city_b;
        city.at(city_a - 1)++;
        city.at(city_b - 1)++;
    }

    for ( int i=0; i<N; i++ )
        cout << city.at(i) << endl;

    return 0;
}


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

int main() {
    double v;
    while (cin >> v) {
        int N = 0;
        for ( ; ; ++N) {
            int y = 5 * N - 5;
            if (v * v * 10 <= 196 * y) break;
        }
        cout << N << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define INF 1930000000

long long int N;
int get_digit(long long int n){
    int keta = 0;
    while(n > 0){
        n /= 10;
        keta++;
    }
    return keta;
}

int Func(long long int a,long long int b){
    int ans = max(get_digit(a), get_digit(b));
    return ans;
}

int main(){
    cin >> N;
    long long int min = INF;
    for(int d = sqrt(N)+1; d > 0; d--){
        if(N % d == 0){
            if(min > Func(d, N / d)){
                min = Func(d,N / d);
            }
        }
    }
    cout << min << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

#define MOD 1e9+7;
#define INF 1e17+9;

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];
		}
	}
	
	char t[h+2][w+2];
	
	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			t[i][j]='.';
		}
	}
	
	for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
			t[i][j]=s[i-1][j-1];
		}
	}
	
	for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
			if(t[i][j]=='#'){
				if(t[i-1][j]=='.' && t[i+1][j]=='.' && t[i][j-1]=='.' && t[i][j+1]=='.'){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	
	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256
array1 = [int(input()) for i in range(5)]
array2 = [i for i in array1 if i % 10 == 0]
array3 = [i for i in array1 if i % 10 != 0]
array4 = [i % 10 for i in array3]
sum1 = 0
sum2 = sum(array2)
if (len(array3) != 0):
  idx = array4.index(min(array4))
  for k, i in enumerate(array3):
    if (k == idx):
      sum1 += i
    else:
      sum1 += i + (10 - i % 10)
print(sum1 + sum2)

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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

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

// End of Template //

int main() {

    int N;
    cin >> N;

    vi brick(N);
    int p;
    rep(i, N) {
        cin >> p;
        brick[i] = p;
    }
    int min_break = N;
    int cnt = 0;

    rep(i, N) {
        if (brick[i] == cnt + 1) {
            cnt++;
        }
    }
    cout << (cnt == 0 ? -1 : (int)brick.size() - cnt) << endl;

}

Measured memory_bytes: 1024
#include<stdio.h>
int dat[100];
int main(){
	int a;
	while(scanf("%d",&a),~a){
		int now=0;
		if(a==0)dat[now++]=0;
		while(a){
			dat[now++]=a%4;
			a/=4;
		}
		for(int i=now-1;i>=0;i--)printf("%d",dat[i]);
		printf("\n");
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#define NXMAX 50
int main(void)
{
  int i, j, n, a, x;
  long long dp[2][NXMAX*NXMAX*2+1];
  scanf("%d %d", &n, &a);
  dp[0][NXMAX*NXMAX] = 1;
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    x -= a;
    for (j = NXMAX; j + NXMAX <= NXMAX * NXMAX * 2; j++) {
      dp[(i+1)&1][j] = dp[i&1][j] + dp[i&1][j-x];
    }
  }
  printf("%lld\n", dp[i&1][NXMAX*NXMAX] - 1);
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {

    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    rep(i,n)
        cin>>v[i];
    int ans=0;
    int lim=min(n,k);//最少能够操作的次数，也就是k有可能大于n 
    for(int l=0;l<=lim;l++){//枚举，从左边和右边一起操作。从0到lim，应为左边可以取0个和所以的 
        for(int r=0;r<=lim-l;r++){
            vector<int> te;//相当于每一次循环te的初始化 
            int sum=0;
            for(int i=0;i<l;i++){//从左边操作，拿的珠宝的价值 
                sum+=v[i];
                te.push_back(v[i]);
            }
           /* for(int i=0;i<r;i++){//从右边操作，拿的珠宝的价值 
                sum+=v[n-i-1];         
                te.push_back(v[n - i - 1]);
            }*/
            for(int i=n-1;i>n-1-r;i--){
            	sum+=v[i];
            	te.push_back(v[i]);
			}
            int a=k-(l+r);//也就是还剩下的操作数，就是可以从自己的手上拿掉珠宝的次数 
            int b=te.size();//b==l+r已操作数 
            sort(te.begin(),te.end());//从小到大排序 
		   for (int tt = 0; tt <=min(a, b); tt++) {//由于剩下的操作数可能会大于已操作数，也就是te.size()，所以就要取最小的。 
			    if(tt!=0){ sum -= te[tt-1];}//由于这个获得的数列有可能就是最大的，也就是不需要拿掉，
				//所以说就是此操作，空开一个，然后由后面那个开始算减去前面的那个。而不是sum-=te[tt];
				if (ans < sum) {
                    ans = sum;
                }
            }
        }
    }

    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
    int r;

    cin >> r;

    double S1 = M_PI;
    double Sr = (double)r * (double)r * M_PI;

    int ans = r*r;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします！
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/

#include <bits/stdc++.h>


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


#define inf (int)(3e18)
#define int long long
#define mod (int)(1000000007)

#define intt long long
#define P pair<int,int>

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

using namespace std;

//Library
//モッドパウ
int modpow(int x, int y, int m = mod) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
            res %= m;
        }
        x = x * x % mod;
        y /= 2;
    }
    return res;
}

int mypow(int x, int y) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
        }
        x = x * x;
        y /= 2;
    }
    return res;
}
//is the number (x) a prime number?
bool prime(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (!(x % i)) {
            return false;
        }
    }
    return true;
}


//saidai-kouyakusuu
inline int gcd(int x, int y) {
    if (!y) {
        return x;
    }
    return gcd(y, x % y);
}


//number of keta
int keta(int x) {
    int ans = 0;
    while (x) {
        x /= 10;
        ans++;
    }
    return ans;
}

//sum of keta
int ketasum(int x) {
    int ans = 0;
    while (x) {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

inline int lcm(int x, int y) {
    int ans = x / gcd(x, y) * y;
    return ans;
}
int twobeki(int x) {
    int ans = 0;
    while (1) {
        if (!(x & 1)) {
            ans++;
            x /= 2;
        }
        else {
            break;
        }
    }
    return ans;
}


template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
    if (lhs < rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
    if (lhs > rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
void Yes(){
    cout<<"Yes"<<endl;
}
void No(){
    cout<<"No"<<endl;
}
void YES(){
    cout<<"YES"<<endl;
}
void NO(){
    cout<<"NO"<<endl;
}


#define fin(i) scanf("%lld",&i)
#define fout(i) printf("%lld\n",i)
#define fendl printf("\n")
//Library-End


string s;

int cnt[30],cc,l,nv[30];
vector<int> n;
signed main() {
    cin>>s;
    rep(i,s.size()){
        cnt[s[i]-'a']++;
    }
    if (abs(cnt[0]-cnt[1])<=1&&abs(cnt[0]-cnt[2])<=1&&abs(cnt[1]-cnt[2])<=1) {
        YES();
    }else{
        NO();
    }
}


Measured memory_bytes: 512
using System;

namespace abc127_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            if(a >= 13)
            {
                Console.WriteLine(b);
            }
            else if(a >= 6 && a <= 12)
            {
                Console.WriteLine(b/2);
            }
            else
            {
                Console.WriteLine(0);
            }
            Console.Read();
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int ret=0;
	for (char ch : s)
	if (ch=='1') ret++;
	cout<<ret<<endl; 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int n,m;
vector<P> vec;
vector<int> answer;
int par[100010],rankh[100010],size[100010];
int ans=1;
void init(int n) {
	for(int i=0; i<=n;i++){
		par[i]=i;
		rankh[i]=0;
		size[i]=1;
	}
}
int find(int x){
	if(par[x]==x)return x;
	else return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	if(rankh[x]<rankh[y]){
		par[x]=y;
		size[y]+=size[x];
	}
	else{
		par[y]=x;
		if(rankh[x]==rankh[y])rankh[x]++;
		size[x]+=size[y];
	}
}
bool same(int x,int y){
	return find(x)==find(y);
}
signed main(){
	cin>>n>>m;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		vec.push_back({a,b});
	}
	reverse(vec.begin(),vec.end());
	int ans=n*(n-1)/2;
	init(n);
	answer.push_back(ans);
	for(P p:vec){
		if(!same(p.first,p.second)){
			ans-=size[find(p.first)]*size[find(p.second)];
			unite(p.first,p.second);
		}
		answer.push_back(ans);
	}
	answer.pop_back();
	reverse(answer.begin(),answer.end());
	for(int i:answer)cout<<i<<endl;
	return 0;
}

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

int main() {
    int N, K;
	cin >> N >> K;
    
    long long x[N];
    for (int i = 0; i < N; ++i){
		cin >> x[i];
	}

    long long res;
    for(int i=0;i<(N-K+1);i++){
//        vector<int> vec{};
//        for(int j=0;j<K;j++){
//            vec.push_back(x[i+j]);
//        }
        
        long long d;
        if(x[i]>0 || x[i+K-1]<0){
            d = max(abs(x[i]),abs(x[i+K-1])) - 0;
        }
        else{
            d = min(abs(x[i]), abs(x[i + K-1])) + (min(abs(x[i]), abs(x[i+K-1])) + max(abs(x[i]), abs(x[i+K-1])));
        }

        if(i == 0) res = d;
        else res = min(res,d);
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, u, v = map(int, input().split())

E = [[] for _ in range(N+1)]
for _ in range(N-1):
	ta, tb = map(int, input().split())
	E[ta].append(tb)
	E[tb].append(ta)
E = np.array(E)

inf = 10**9
taka = np.full(N+1, inf, dtype = np.int64)
ao = np.full(N+1, inf, dtype = np.int64)
taka[u] = 0
ao[v] = 0
def solve(dist, start):
	q = [start]
	while q:
		cp = q.pop()
		for nep in E[cp]:
			if dist[nep] != inf:
				continue
			else:
				dist[nep] = dist[cp] + 1
				q.append(nep)

solve(taka, u)
solve(ao, v)
ind = taka < ao
ao_max = np.max(ao[ind])
print(ao_max - 1)

Measured memory_bytes: 36904
#include <iostream>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll>P;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll mod = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool fl = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
struct edge1 { ll from, to, cost; };
double pai = 3.141592653589793;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (abs(a - b)%2 == 1)cout << "Borys" << endl;
	else cout << "Alice" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define H 501
#define W 101
#define K 101

using namespace std;
int h,n,p,m,k;
double mem[H][W][K];
bool used[H][W][K];
int bar[H];

double dfs(int y,int x,int cnt){
  if(y == 0) return (x == p)*(cnt == 0);
  if(used[y][x][cnt]) return mem[y][x][cnt];
  used[y][x][cnt] = 1;
  double res = 0;

  if(bar[y]!=-1){
    if(bar[y] == x) res += dfs(y-1,x+1,cnt);
    else if(bar[y] == x-1) res += dfs(y-1,x-1,cnt);
    else res += dfs(y-1,x,cnt);
  }

  else if(bar[y] == -1){
    double numh = h - m  - (k - cnt);
    double div = (n-1) * numh/cnt;
    int c = 0;
    if(x < n-1 && cnt) res += dfs(y-1,x+1,cnt-1)/div,c++;
    if(x > 0 && cnt) res += dfs(y-1,x-1,cnt-1)/div,c++;
    if(cnt) res += (dfs(y-1,x,cnt-1) * (n-1-c))/div;
    res += dfs(y-1,x,cnt);
  }
  return mem[y][x][cnt] = res;
}

signed main(){
  cin>>h>>n>>p>>m>>k;
  p--;
  memset(bar,-1,sizeof(bar));
  for(int i=0,a,b;i<m;i++)cin>>a>>b,bar[h-a+1] = b-1;

  double ans = 0;
  for(int i=0;i<n;i++){
    double res = dfs(h,i,k);
    ans = max(ans,res);
  }
  printf("%.10lf\n",ans);

  return 0;
}

Measured memory_bytes: 48072
N = int(input())
A = []
B = []
AB = []
for i in range(N):
    a, b = map(int, input().split(' '))
    A.append(a)
    B.append(b)
    AB.append((a, b))

# print(AB)
AB = sorted(AB, key=lambda x: x[1])
# print(AB)

sumab = 0
flag = True
for ab in AB:
    sumab += ab[0]
    if sumab > ab[1]:
        flag = False
        break

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


Measured memory_bytes: 36588
import sys
input = sys.stdin.readline

def main():
    X, Y = map(int, input().split())
    ans = 0
    t = [300000, 200000, 100000]

    if X <= 3:
        ans += t[X-1]
    if Y <= 3:
        ans += t[Y-1]
    if X == 1 and Y == 1:
        ans += 400000
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
n,m,q = map(int,input().split())

res = [[0]*n for i in range(n)]
for i in range(m):
    L,r = map(int,input().split())
    L -= 1
    r -= 1
    res[r][0] += 1
    if L != n-1:
        res[r][L+1] -= 1

for i in range(n):
    for j in range(1,n):
        res[i][j] += res[i][j-1]
for i in range(n):
    for j in range(1,n):
        res[j][i] += res[j-1][i]
for i in range(q):
    p,q = map(int,input().split())
    print(res[q-1][p-1])


Measured memory_bytes: 9660
#include<cstdio>

long long h, w, ans;

long long min(long long x, long long y) {
	return x < y ? x : y;
}

long long max(long long x, long long y) {
	return x > y ? x : y;
}

long long f(long long x, long long y, long long z) {
	return max(max(x, y), z) - min(min(x, y), z);
}

int main() {
	scanf("%lld %lld", &h, &w);
	ans = h * w;
	if (w != 2) ans = min(ans, w % 3 ? h : 0);
	if (h != 2) ans = min(ans, h % 3 ? w : 0);
	for (int i = 1; i < h; i++)
		ans = min(ans, f(w * i, (w / 2) * (h - i), ((w + 1) / 2) * (h - i)));
	h ^= w ^= h ^= w;
	for (int i = 1; i < h; i++)
		ans = min(ans, f(w * i, (w / 2) * (h - i), ((w + 1) / 2) * (h - i)));
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
N = gets.to_i
a = gets.chomp.split.map(&:to_i).sort.reverse
h = Hash.new(0)
a.each do |v|
    h[v] += 1
end

b = [1]
1.upto(32){|i| b[i] = b[i-1]<<1} 
b.reverse!

ans = 0

used = Hash.new(0)

a.each do |v|
    next if h[v] == 0
    h[v] -= 1
    flag = 0
    b.each do |w|
        if h[w - v] > 0
            ans += 1
            h[w - v] -= 1
            flag = 1
            break
        end
    end
    h[v] += 1 if flag == 0
end
puts ans

Measured memory_bytes: 33460
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
int main()
{
	char s[100],ss[100];
	int i=0,j=0,a=0;
	int b[100];
	for(i = 0 ; i < 10 ; i++)b[i] = 1;
	scanf("%s",s);
	a = strlen(s);
	for(i=0;i<a;i++)
	{
		if(s[i]=='B')
		{
			b[i]=0;
			for(j = i; j >=0 ;j--)
			{
				if(b[j]!=0)
				{
					b[j]=0;
					break;
				}
			}
		}
	}
	j = 0;
	for(i=0;i<a;i++)
	{
		if(b[i]==1){
			ss[j]=s[i];
			j++;
		}
	}
	ss[j] = 0;
	printf("%s\n", ss);
	return 0;
}

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

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

    string S,T;
    cin>>S>>T;

    string ans;
    for (int i = 0; i < N; i++)
    {
        ans.push_back(S[i]);
        ans.push_back(T[i]);
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
import sys
# from collections import defaultdict, deque
# import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10 ** 9 + 7
def solve():
    n = getN()
    nums = getList()
    kaijyo = [1, 1]

    for i in range(2, n + 3):
        kaijyo.append((kaijyo[-1] * i % MOD))
    # print(kaijyo)

    ans = 1
    cnt = 0
    for num in nums:
        cnt +=1
        if num <= (cnt - 1) * 2:
            # ans *= kaijyo[cnt]
            ans *= cnt
            ans %= MOD
            cnt -= 1

        prev = num
    ans *= kaijyo[cnt]
    ans %= MOD
    print(ans)
    # print((11 * kaijyo[10]) % MOD)
    # print(pow(311014372, MOD -2, MOD))

def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    # main()
    solve()


Measured memory_bytes: 90540
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

def calc_min(a, b):
    if a>=0 and b>=0:
        return a
    elif a<0 and b<0:
        return abs(b)
    else:
        return 0

N, K = mi()
x = li()
ans = 10**13 + 1
'''
sum_k = X[K-1] - X[0]
min_k = calc_min(x[0], x[K-1])
ans = sum_k
print(sum_k)
for i in range(1, N-K+1):
    sum_k -= abs(x[i-1]) + min_k
    sum_k += abs(x[K-1+i])
    min_k = calc_min(x[i], x[K-1+i])
    sum_k += min_k
    print(sum_k)
    ans = min(ans, sum_k)

print(ans)
'''

for i in range(N-K+1):
    #sum_k = x[K-1+i] - x[i] + calc_min(x[i], x[K-1+i])
    sum_k = x[K-1+i] - x[i] + min(abs(x[i]), abs(x[K-1+i]))
    #min_k = calc_min(N[i], N[K-1+i])
    #sum_k += min_k
    #print(sum_k)
    ans = min(ans, sum_k)

print(ans)




Measured memory_bytes: 14252
object Main extends App{

  val n = io.StdIn.readLine().toInt
  
  for (i <- 1 to n) {
    val sideAry = io.StdIn.readLine().split(' ').map { _.toInt }.sorted

    if (sideAry(2) * sideAry(2) == (sideAry(0) * sideAry(0) + sideAry(1) * sideAry(1)))
      println("YES")
    else
      println("NO")
  }
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){

  int n,m;cin>>n>>m;
  int p[n+10];rep(i,0,n)cin>>p[i];
  int x[m+10],y[m+10];

  UnionFind tree(n);

  rep(i,0,m){
    cin>>x[i]>>y[i];
    tree.unite(x[i]-1,y[i]-1);
  }

  int ans=0;
  rep(i,0,n){
    if(tree.same(i,p[i]-1)){
      ans++;
    }
  }

  out(ans);

  return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  if(a>b) cout << a-1 << endl;
  else cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
        
    #define ll long long int
     int main()
    {
          ll r,a,b;
          cin>>r;
          b=sqrt(3);
          a=r/b;
          a=3*a*a;
          cout<<a<<endl;
          return 0;
    }

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>
#include<limits.h>

int main()
{
	char buf[256];
	int num, i, num1[10000]={0}, num2[10000]={0};

	while(fgets(buf, 256, stdin) != NULL){
		if(strcmp(buf, "\n") == 0)
			break;
		sscanf(buf, "%d,%d", &num, &i);
		num1[num]++;
	}

	while(fgets(buf, 256, stdin) != NULL){
		sscanf(buf, "%d,%d", &num, &i);
		num2[num]++;
	}

	for(i=0; i<10000; i++){
		if(num1[i] != 0 && num2[i] != 0)
			printf("%d %d\n", i, num1[i] + num2[i]);
	}

	return 0;
}

Measured memory_bytes: 692
#include <stdio.h>

int main() {
	char a[10];
	char b[10] = "ABC";
	char c[10] = "ARC";
	
	scanf("%s", a);
	
	if(a[1] == 66) {
		printf("%s", c);
	} else {
		printf("%s", b);
	}
	
	
	return 0;
}

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

int main (){
	int n,l;
	cin>>n>>l;
	
	if(n+l-1<0)
		cout<<((2*l+n-1)*n/2-(n+l-1))<<'\n';
	else if (l<=0 && n+l-1>=0)
		cout<<(2*l+n-1)*n/2<<'\n';
	else if (n>0 && l>0)
		cout<<((2*l+n-1)*n/2-l)<<'\n';
	return 0;
	
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
const int INF = 1001001001;

int main()
{
    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];
    int alice=0, bob=0;
    Sort2(a);
    rep(i ,n){
        if(i % 2 == 0) alice += a[i];
        else bob += a[i];
    }
    cout << alice - bob << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 256
import math
A, B, N = list(map(int,input().split()))

def keisan(A, B, x):
    return (math.floor(A*x/B)-A*math.floor(x/B))

if B > N:
    print(keisan(A, B, N))
else:
    print(keisan(A, B, B-1))

Measured memory_bytes: 9172
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(ll i=0;i<(n);i++)
int main() {
	ll n, a[200020];
	cin >> n;
	ll ma = -1, mai = -1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] > ma) {
			ma = a[i];
			mai = i;
		}
	}
	ll ansa = ma, ansb = -1, yojo = -1;
	for (int i = 0; i < n; i++) {
		if (i == mai)continue;
		ll yan = min(ma - a[i], a[i]);
		if (yojo < yan) {
			ansb = a[i];
			yojo = yan;
		}
	}
	cout << ansa << ' ' << ansb << endl;
	return 0;
}

Measured memory_bytes: 1024
#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> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}
ll a[1000001];
pll b[100001];
bool comp(pll x, pll y) {
	return x.second > y.second;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); /*cout.tie(NULL);*/
	int n, m; cin >> n >> m;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	rep(i, m) {
		cin >> b[i].first >> b[i].second;
	}
	sort(b, b + m, comp);
	ll ans = 0;
	int j = 0;

	rep(i, n) {
		while (j < m && b[j].first == 0)j += 1;
		if (j < m && a[i] < b[j].second) {
			b[j].first -= 1;
			ans += b[j].second;
		}
		else {
			ans += a[i];
		}
	}

	cout << ans << '\n';




}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 510000;

ll addM(ll a, ll b){
	return (a + b) % MOD;
}

ll mulM(ll a, ll b){
	return (a % MOD) * (b % MOD) % MOD;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a%MOD;
  	else if(b%2==0) return mulM(powM(a,b/2),powM(a,b/2));
  	else return mulM(a,mulM(powM(a,(b-1)/2),powM(a,(b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a,powM(b,MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(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;
}

/*** MOD CALCULATION ここまで ***/
void Main(){
	ll n, k;
	cin >> n >> k;

	auto f = [&](ll x){
	    ll res = (n - x + 1) * x + 1;
	    return res;
	};
	
	//cout << f(2) << endl;
	//cout << f(3) << endl;
	//cout << f(4) << endl;

	ll ans = 0;
	rep3(i, k, n+1){
	    ans = addM(ans, f(i));
	}
	cout << ans << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;
import java.util.ArrayDeque;

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

    while (in.hasNext()) {
      String S = in.next();
      ArrayDeque<Character> stack = new ArrayDeque<Character>();

      for (int i = 0; i < S.length(); ++i) {
        char cube = S.charAt(i);
        if (stack.isEmpty()) {
          stack.push(cube);
        } else if (cube == '1' && stack.peek() == '0') {
          stack.pop();
        } else if (cube == '0' && stack.peek() == '1') {
          stack.pop();
        } else {
          stack.push(cube);
        }
      }

      System.out.println(S.length() - stack.size());
    }
  }
}

Measured memory_bytes: 27696
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int,input().split()))
    
    A = sorted(A)
    K = 0
    while A[-1] >= N:
        M = A[-1]
        p = M//N
        K += p
        for i in range(N-1):
            A[i] += p
        A[-1] -= p*N
        A = sorted(A)
        
    print(K)
    
    
main()

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

bool palin(string s , int start , int end){
    
    int j = end-1;

    for(int i = start ; i < (start + end)/2 ; i++){
        if(s[i] == s[j]){
            
            j--;
            
        }
        else{
            
            return false;
        }
    }
    return true;
}
int main(){
  
  string s;
  cin>>s;
  int n = s.length();
    
  if(palin(s , 0 , n) == true && palin(s , 0 , (n-1)/2) && palin(s , (n+3)/2-1 , n))
    cout<<"Yes";

  else
  cout<<"No";

  
  
  return 0;
}

Measured memory_bytes: 256
const Main = (input) => {
  const tmp = input.trim().split(' ').map(n => parseInt(n))
  const A = tmp[0]
  const B = tmp[1]
  const N = tmp[2]

  let x = Math.min(B - 1, N)

  const result = Math.floor(A * x / B) - (A * Math.floor(x / B))

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main(){
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs(void);
void visit(int);

int a[100][100];
int color[100];
int f[100];
int d[100];
int time;
int n;

int main(){
  int u,i,j,k,v;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      a[u-1][v-1] = 1;
    }
  }

  dfs();

  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }

  return 0;
}

void dfs(){//printf("in\n");
  int i;

  for(i=0;i<n;i++) color[i] = WHITE;

  time = 0;

  for(i=0;i<n;i++){
    if(color[i] == WHITE) visit(i);
  }
}

void visit(int u){
  int i;
  
  color[u] = GRAY;
  d[u] = ++time;
  
  for(i=0;i<n;i++){
    if(a[u][i]==1){
      if(color[i]==WHITE) visit(i);
    }
  }

  color[u] = BLACK;
  f[u] = ++time;
}

Measured memory_bytes: 636
// #include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <limits>
#include <algorithm>
#include <string>

using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<string, string> P;

int main() {
    ll N;
    string str;
    cin >> N >> str;
    string left = str.substr(0,N);
    string right = str.substr(N);
    map<P, int> mp;
    for(int i=0;i < (1<<N);i++){
        string bt,rt;
        for(int j = 0;j < N; j++){
            if(( i >> j ) & 1){
                bt += left[j];
            } else {
                rt += left[j];
            }
        }
        mp[P(bt,rt)]++;
    }

    reverse(right.begin(), right.end());

    ll ans=0;
    for(int i=0;i < (1<<N);i++){
        string bt,rt;
        for(int j = 0;j < N; j++){
            if(( i >> j ) & 1){
                bt += right[j];
            } else {
                rt += right[j];
            }
        }
        ans += mp[P(bt,rt)];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 91904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '[';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "");
    return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

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

    int k, a, b;
    cin >> k >> a >> b;
    while (a <= b) {
        if (a % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
        ++a;
    }
    cout << "NG" << endl;

    return 0;
}


Measured memory_bytes: 3652
import java.util.*;

import static java.lang.System.*;

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

        // Cだけ
        long priceOnlyC = Math.max(X, Y) * 2 * C;

        // C + 残り A or B
        long priceCwithAB = Math.min(X, Y) * 2 * C;
        if (X > Y) {
            int xTmp = X - Y;
            priceCwithAB += xTmp * A;
        } else {
            int yTmp = Y - X;
            priceCwithAB += yTmp * B;
        }

        // C使わない
        long priceOnlyAB = A * X + B * Y;

        out.println(Math.min(priceOnlyC, Math.min(priceCwithAB, priceOnlyAB)));
    }
}

Measured memory_bytes: 23380
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000007
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;


#define endl '\n'
// #define int ll

signed main() {
	fast;

	int h,w;
	cin>>h>>w;

	pii v[200002];
	for(int i=0;i<h;i++) cin>>v[i].f>>v[i].s;

	map<int,int> mp;
	for(int i=1;i<=w;i++) mp[i] = 0;

	map<int,int> mini = {{0,w}};

	for(int i=0;i<h;i++) {
		int r = v[i].s;

		auto it = mp.lower_bound(v[i].f);


		if(r==w) {
			while(it!=mp.end() && it->f <= r) {
				auto it1 = it++;
				auto it2 = mini.find(it1->s);
				if(it2->s==1) mini.erase(it2);
				else it2->s --;
				mp.erase(it1);
			}

			if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
			else cout<<-1<<endl;
		}
		else {
			int mn = inf;

			while(it!=mp.end() && it->f <= r) {
				mn = min(mn, r+1-(it->f)+(it->s));
				auto it1 = it++;
				auto it2 = mini.find(it1->s);
				if(it2->s==1) mini.erase(it2);
				else it2->s --;
				mp.erase(it1);
			}

			if(mn<inf) {
				if(it!=mp.end() && it->f == r + 1) {
					if(it->s > mn) {
						auto it1 = mini.find(it->s);
						if(it1->s ==1) mini.erase(it1);
						else it1->s --;
						mini[mn]++;
						it->s = mn;
					}
				}
				else {
					mp.insert({r+1,mn});
					mini[mn]++;
				}
				cout<<mini.begin()->f+i+1<<endl;
			}
			else {
				if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
				else cout<<-1<<endl;
			}

		}

	}
}

Measured memory_bytes: 14540
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

const int MAX = 510000;
long long 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;
}

long long FAC(int n){
  return fac[n];
}


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  COMinit();
  int N,K;
  cin>>N>>K;
  if(N!=K){
    for(int i=1;i<=K;i++){
      cout<<COM(K-1,i-1)*(((COM(N-K-1,i-1)*2+COM(N-K-1,i))%MOD+COM(N-K-1,i-2))%MOD)%MOD<<endl;
    }
  }else{
    cout<<1<<endl;
    for(int i=2;i<=K;i++){
      cout<<0<<endl;
    }
  }

}


Measured memory_bytes: 12160
import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline

class SegmentTree():
    f = max
    unit = 0

    def __init__(self,array):
        self.N = len(array)
        self.tree = [self.unit] * (2*self.N)
        for i,x in enumerate(array,self.N):
            self.tree[i] = x
        for i in range(self.N - 1,0,-1):
            self.tree[i] = self.f(self.tree[i << 1],self.tree[i << 1|1])
    
    def update(self,k,x):
        k += self.N
        self.tree[k] = x
        while k > 1:
            k >>= 1
            self.tree[k] = self.f(self.tree[k << 1],self.tree[k << 1|1])
    
    def query(self,l,r):
        l += self.N
        r += self.N
        vl = self.unit
        vr = self.unit
        while l < r:
            if l&1: 
                vl = self.f(vl,self.tree[l])
                l += 1
            if r&1:
                r -= 1
                vr = self.f(self.tree[r],vr)
            l >>= 1
            r >>= 1
        return self.f(vl,vr)
    
    def __str__(self):
        return '\n'.join(' '.join(str(v) for v in self.tree[1<<i:1<<(i + 1)]) for i in range((2*self.N).bit_length()))

N = int(input())
A = list(map(int,input().split()))
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

B = sorted(list(set(A)))
M = len(B)
toID = {i:j for i,j  in zip(B,range(1,M + 1))}
dp = SegmentTree([0] * (M + 1))
ans = [0] * N
before = [0] * N

def dfs(v,p = -1):
    idx = toID[A[v]]
    a = dp.query(0,idx) + 1
    before[v] = dp.query(idx,idx + 1)
    flag = False
    if before[v] < a:
        flag = True
        dp.update(idx,a)
    before_max = dp.query(0,M + 1)
    ans[v] = max(before_max,a)
    for e in G[v]:
        if e == p:
            continue
        dfs(e,v)
    if flag:
        dp.update(idx,before[v])

dfs(0)
print('\n'.join(map(str,ans)))

Measured memory_bytes: 552336
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
ll k (ll a){
    a--;
    ll ans =0;
    while(a != 0){
        ans += a;
        a--;
        
    }
    return ans;
}

int main(){
    ll n,t;
    cin >> n >> t;

    ll ans=0,l,r;
    cin >> l;
    FOR(i,1,n){
        cin >> r;

        ans += min((r -l),t);
        l = r;
    }
    ans += t;
    cout << ans << endl;
}






Measured memory_bytes: 384
#include <iostream>
#include<set>
#define INF 1e8
using namespace std;
int main(void){
    // Your code here!
int n;
cin>>n;

for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(a%2==0 && a%3!=0 && a%5!=0)
        {
            cout<<"DENIED";
            return 0;
        }
}

cout<<"APPROVED";
}


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

int num;
int a[21][21];

int retcost(int Island){
	int x=0;
	for(int i=1;i<=num;i++){
		if(a[Island][i]){
			a[i][Island]=0;
			x=max(x,a[Island][i]+retcost(i));
		}
	}
	return x;
}

int main(void){
	while(cin>>num,num){
		int I1,I2,t,ans,I[num+1]={},Cost=0;
		memset(a,0,sizeof(a));
		for(int i=1;i<num;i++){
			cin>>I1>>I2>>t;
			a[I1][I2]=a[I2][I1]=t;
			I[I1]++,I[I2]++;
			Cost+=t*2;
		}
		for(int i=1;i<=num;i++){
			for(int j=1;j<=num;j++){
				if((I[i]==1||I[j]==1)&&!((i==1&&I[i]==1)||(j==1&&I[j]==1))){
					Cost-=a[i][j]*2;
					a[i][j]=a[j][i]=0;
				}
			}
		}
		ans=Cost-retcost(1);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3084
/**
*    author:  Dooloper
*    created: 05.07.2020 21:03:47
**/

#include <bits/stdc++.h>

#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  string judge[4] = {"AC","WA","TLE","RE"};
  vector<int> cnt(4);
  rep(i,4) cnt[i] = 0;

  rep(i,n){
    string str;
    cin >> str;
      if(str == "AC") cnt[0]++;
      if(str == "WA") cnt[1]++;
      if(str == "TLE") cnt[2]++;
      if(str == "RE") cnt[3]++;
  }
  rep(i,4) cout <<judge[i] << " x " << cnt[i] << endl;

  return 0;
}

Measured memory_bytes: 3656