akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, x, t;
	cin >> n >> x >> t;
	cout << ((n+x-1)/x*t) << "\n";
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200005;
const int INF = 1001001001;

vector<int> a, ans;
vector<int> to[MAX_N];
int dp[MAX_N];

void dfs(int v, int p = -1) {
    int i = lower_bound(dp, dp + MAX_N, a[v]) - dp;
    int old = dp[i];
    dp[i] = a[v];
    ans[v] = lower_bound(dp, dp + MAX_N, INF) - dp - 1;
    for (auto u : to[v])
    {
        if(u == p) continue;
        dfs(u, v);
    }
    dp[i] = old;
}

int main() {
    int N; cin >> N;
    a = ans = vector<int>(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    vector<vector<int>> G(N);
    for (int i = 0; i < N-1; i++)
    {
        int u, v; cin >> u >> v;
        u--; v--;
        to[u].push_back(v);
        to[v].push_back(u);
    }

    for(int i = 0; i < MAX_N; i++) dp[i] = INF;
    dp[0] = -INF;
    dfs(0);
    for (int i = 0; i < N; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 35172
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)					// repeat
#define repr(i, begin, end) for (ll i = begin - 1; end <= i; i--)		// repeat reverse

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif


int main(void)
{
	ll r; cin >> r;
	ll g; cin >> g;
	ll b; cin >> b;	
	ll n; cin >> n;

	ll ans = 0;
	rep(bi, 0, (n / b) + 1)
	{
		rep(gi, 0, ((n - b * bi) / g) + 1)
		{
			if ((n - b * bi - g * gi) % r == 0)
				ans++;
		}
	}

	cout << ans;
	
	return 0;
}

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

signed main() {
  int n, x, t;
  cin >> n >> x >> t;
  int ans = 0;
  while (n > 0) {
    n -= x;
    ans += t;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
int main(void)
{
int n,i,ai,min,max;
long sum;
sum = 0;
min=1000000;
max=-1000000;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&ai);
sum+=ai;
if(min>ai){
min=ai;
}
if(max<ai){
max=ai;
}
}
printf("%d %d %lld\n",min,max,sum);
return 0;
}

Measured memory_bytes: 600
let () = Scanf.scanf "%d" @@ fun n ->
  let xyhs = Array.init n @@ fun _ ->
    Scanf.scanf "\n%d %d %d" @@ fun x y h -> x, y, h in
  let (cx, cy, h) :: _ =
    List.concat @@ Array.to_list @@ Array.init 101 @@ fun cx ->
      List.concat @@ Array.to_list @@ Array.init 101 @@ fun cy ->
        let (l, r) = Array.fold_left (fun (l, r) -> function
          | (xi, yi, 0) -> (l, min r (abs (xi - cx) + abs (yi - cy)))
          | (xi, yi, hi) ->
              let h = hi + abs (xi - cx) + abs (yi - cy) in
              (max l h, min r h)) (1, max_int) xyhs in
        if r <> l then [] else [(cx, cy, l)] in
  Printf.printf "%d %d %d\n" cx cy h


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

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

int main() {
  int N, mod = 1000000007;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  ll sum = 0;
  ll ans = 0;
  for (int i = 0; i < A.size(); i++) {
    ans += sum * A[i];
    ans %= mod;
    sum += A[i];
    sum %= mod;
  }

  cout << ans << endl;

  return 0;
}

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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for(int a = 1; a <= 9; ++a)
    {
        for(int b=1; b<=9; ++b)
        {
            if(a*b == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int C;
  for (int i = 0; i < S.size(); i++) {
    C = S.at(i) + N;
    if (C > 'Z') {
      C = C - 26;
    }
    S.at(i) = C;
    cout << S.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N,T = map(int,input().split())
arrT = list(map(int,input().split()))

start = arrT[0]
end = 0
ans = 0
for i in range(N):
    if i == N-1:
        if arrT[i-1]+T>=arrT[i]:
            end = arrT[i]
            num = end-start+T
            ans += num
        else:
            ans += T
    elif arrT[i]+T>=arrT[i+1]:
        end = arrT[i]
        continue
    else:
        end = arrT[i]
        num = end-start+T
        ans += num
        start = arrT[i+1]

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 25712
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
ll ara[Max+10];

ll dp[3002][3002];

ll call(ll i,ll j)
{
    if(i>j)
        return 0;

    ll &ret=dp[i][j];


      if(~ret)
        return ret;




       ret=max(ara[i]-call(i+1,j),ara[j]-call(i,j-1));



       return ret;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

      bool flag=false;

      string str;


       cin>>n;

       input(ara,n);

       memset(dp,-1,sizeof(dp));

       cout<<call(0,n-1)<<endl;





}



Measured memory_bytes: 74220
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    string s; cin >> s;
    ll ud = 0;
    ll lr = 0;
    rep(i,s.size()){
        char c = s[i];
        if('A'<=c && c<='M') ud++;
        if('N'<=c && c<='Z') ud--;
        if('a'<=c && c<='m') lr++;
        if('n'<=c && c<='z') lr--;
    }
    ll ans = abs(ud) + abs(lr);
    cout << ans << endl;
    if(ans==0) return 0;
    rep(i,abs(ud)){
        if(ud>0) cout << 'A';
        else cout << 'Z';
    }
    rep(i,abs(lr)){
        if(lr>0) cout << 'a';
        else cout << 'z';
    }
    cout << endl;
}



Measured memory_bytes: 3340
def calculate(arr):

    if len(arr) <= 1:
        return True

    index = len(arr) - 1
    while index >= 1:
        if arr[index - 1] - arr[index] > 1:
            return False
        if arr[index - 1] - arr[index] == 1:
            arr[index - 1] = arr[index -1 ] - 1
        index = index - 1
    return True




N = int(input())
arr = list(map(int, input().split()))

if len(arr) != N:
    print("No")
else:
    result = calculate(arr)
    if result:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14252
import math
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, M, L = IL()
abc = [IL() for _ in range(M)]
Q = I()
q = [IL() for _ in range(Q)]

dp1 = [[MAX_INT]*N for _ in range(N)]
for a, b, c in abc:
  dp1[a - 1][b - 1] = c
  dp1[b - 1][a - 1] = c

for k in range(N):
  for i in range(N):
    for j in range(N):
      if i == j:
        dp1[i][j] = 0
      else:
        dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j])

dp2 = [[MAX_INT]*N for _ in range(N)]
for i in range(N):
  for j in range(N):
    if dp1[i][j] <= L:
      dp2[i][j] = 1

for k in range(N):
  for i in range(N):
    for j in range(N):
      if i == j:
        dp2[i][j] = 0
      else:
        dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j])

for s, t in q:
  if dp2[s - 1][t - 1] == MAX_INT:
    print(-1)
  else:
    print(dp2[s - 1][t - 1] - 1)

Measured memory_bytes: 84824
def solve(N):
    if N < 10:
        return N
    num = int("9" * (len(str(N)) - 1))
    k = int(str(N)[0] + str(num))
    if k <= N:
        return sum(int(c) for c in str(k))
    else:
        k = k - num - 1
        return sum(int(c) for c in str(k))


assert (solve(799) == 25)
assert (solve(999) == 27)
assert (solve(200) == 19)
assert (solve(100) == 18)
assert (solve(99) == 18)
assert (solve(89) == 17)
assert (solve(5) == 5)

if __name__ == "__main__":
    N = int(input())
    print(solve(N))


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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N;
    ll ans;
    cin>>N;
    vector<ll> A(N);
    ll sum=0;
    REP(i,N){
        cin>>A[i];
        sum^=A[i];
    }

    REP(i,N){
        cout<<(sum^A[i]);
        if(i!=N-1) cout<<" ";
    }
    cout<<endl;

}

Measured memory_bytes: 4812
#include <cstdio>
#include <cstdlib>
#include <vector>

using namespace std;

int main()
{
    int n,d;

    scanf("%d %d\n", &n, &d);

    int i=0,res=0;
    while(res<n)
    {
        res+=2*d+1;
        i++;
    }

    printf("%d\n", i);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

char a[52][52];
ll dx[4] = {0,1,0,-1};
ll dy[4] = {1,0,-1,0};

int main(){FIN
    ll h,w;cin>>h>>w;
    ll white=0;
    REP(i,h)REP(j,w) {
        cin>>a[i][j];
        if (a[i][j]=='.') white++;
    }
    vvll dist(h, vll(w,-1));
    queue<P> q;
    q.push(make_pair(0,0));
    dist[0][0]=0;

    while(q.size()){
        P now=q.front();
        q.pop();
        ll x = now.first;
        ll y = now.second;
        REP(i,4){
            ll nx = x + dx[i];
            ll ny = y + dy[i];
            if (nx>=h || nx<0 || ny>=w || ny<0) continue;
            if (dist[nx][ny]!=-1) continue;
            if (a[nx][ny]=='#') continue;
            dist[nx][ny] = dist[x][y]+1;
            q.push(make_pair(nx,ny));
        }
    }
    if (dist[h-1][w-1]==-1) cout<<-1<<endl;
    else cout<< white - dist[h-1][w-1]-1 <<endl;
    return 0;
}

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

using namespace std;

const int maxn=1e2+5;
const int inf=(1<<21);
const int white=0;
const int gray=1;
const int black=2;

int n,m[maxn][maxn];

int prim()
{
    int d[maxn],p[maxn],book[maxn];
    for(int i=0;i<n;i++){
        d[i]=inf;
        p[i]=-1;
        book[i]=0;
    }
    d[0]=0;
    int u,minv,sum=0;
    while(1){
        minv=inf;
        u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&book[i]==0){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1){
            break;
        }else{
            sum+=d[u];
        }
        book[u]=1;
        for(int v=0;v<n;v++){
            if(book[v]==0&&d[v]>m[u][v]){
                d[v]=m[u][v];
                p[v]=u;
            }
        }
    }
//    int sum=0;
//    for(int i=0;i<n;i++){
//        if(p[i]!=-1){
//            sum+=m[i][p[i]];
//        }
//    }
    return sum;
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int e;
            cin>>e;
            m[i][j]=(e==-1)?inf:e;
        }
    }
    cout<<prim()<<endl;
    return 0;
}
/*
5
-1 2 3 1 -1
2 -1 -1 4 -1
3 -1 -1 1 1
1 4 1 -1 3
-1 -1 1 3 -1
*/



Measured memory_bytes: 3224
/*
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i = 0;i<n;i++){
        cout<<setw(10);
        for(int j = 0;j<n-1-i;j++){
            cout<<" ";
        }

        for(int k = 0;k<2*i+1;k++){
            cout<<k+1;
        }
        cout<<endl;
    }

    for(int i=0;i<n-1;i++){
        cout<<setw(10);
        for(int j = 0;j<i+1;j++){
            cout<<" ";
        }
        for(int k = 0;k<(n-i-1)*2-1;k++){
            cout<<k+1;
        }
        cout<<endl;
    }

    return 0;
}
*/
/*
#include<iostream>
#include<stdio.h>
#include<bitset>
using namespace std;
int main(){
    char c;
    c = getchar();
    bitset<32>t(c);
    if(( c >= 'a' ) && ( c <='z' ))
    {
        if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        {
            cout<<c<<"   "<<t.to_string();
        }
    }


    return 0;
}
*/
/*
#include<iostream>
using namespace std;
int main(){
    int k;
    cin>>k;
    if (k<=20) cout<<"是20或小于20";
    else if (k!=20 && k<30) cout<<"大于20且小于30";
    else if (k!=30 && k<100) cout<<"大于30且不超过100";
    else if (k>100) cout<<"大于100";

    return 0;
}
*/

#include<iostream>
using namespace std;
int main(){
    int i,j,k;
    cin>>i;
    j = i%10;
    k = i/10;

    if((j==9)||(k==9)){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;

}


Measured memory_bytes: 888
D,N = map(int,input().split())
if (D == 0):
  if (N != 100):
    print(N)
  else:
    print('101')
elif (D == 1):
  if (N != 100):
    print(100*N)
  else:
    print('10100')
else:
  if (N != 100):
    print(10000*N)
  else:
    print('1010000')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define MAX_N 100005
#define ll long long
const int NINF = -1e9;
const int INF = 1e9+7;
using namespace std;

int main()
{
 //freopen("t.txt","r",stdin);
 ll n,m; 
 cin>>n>>m;
 ll a=1,b=1,kq=0;
 if (abs(n-m)>=2){
 	cout<<0; return 0;
 }
 
 else{
 	
 	if (n==m){
 		for (ll i=1;i<=n;i++){
 		a= ((a%INF) * (i%INF)) %INF;
	 }
	 for (ll i=1;i<=m;i++){
	 	b= ((b%INF) * (i%INF)) %INF;
	 }
	 kq=  (((a%INF) * (b%INF) ) %INF *(2%INF)) %INF; 
	 }
	 
	 else{
	 		for (ll i=1;i<=n;i++){
 		a= ((a%INF) * (i%INF)) %INF;
	 }
	 for (ll i=1;i<=m;i++){
	 	b= ((b%INF) * (i%INF)) %INF;
	 }
	 kq=  ((a%INF) * (b%INF)) %INF;
	 }
 	
 }
 cout<<kq;
 
}


Measured memory_bytes: 256
from queue import Queue
import copy
import collections

R, C = map(int, input().split(' '))
M = [[s for s in input()] for _ in range(R)]
trial = 0


Sy = 1
Sx = 1
Gy = R
Gx = C

cnt  = 0
for i in range(R):
  cnt += M[i].count('#')

L = copy.deepcopy(M)

move = [(0, -1), (0, 1), (1, 0), (-1, 0)]
q = Queue()
ans = 0

q.put([(Sy, Sx)])
L[Sy-1][Sx-1] = '#'

while not q.empty():
  pos = q.get()
  valid_pos = []
  for p in pos:
      for m in move:
          y, x = p[0]+m[0], p[1]+m[1]
          if y == Gy and x == Gx:
            ans += 1
            print(R*C-ans-1-cnt)
            exit()            
          if 1<= y  <= R and 1<= x <= C:
            if L[y-1][x-1] == '.':
              L[y-1][x-1] = '#'
              valid_pos.append((y, x))
  if len(valid_pos) != 0:
      q.put(valid_pos)
  ans += 1
print(-1)

Measured memory_bytes: 4072
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<set>
#define inf 0x3f3f3f3f
typedef long long ll;

const int maxn=2e5+5;

using namespace std;
int a[maxn],n,k,ans;

int main()
{
    scanf("%d%d",&k,&n);
    ans=inf;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if(n==2)
        ans=min(a[2]-a[1],a[1]+k-a[2]);
    else
    {
        for(int i=2;i<=n;i++)
            ans=min(a[i-1]+k-a[i],ans);
        ans=min(ans,a[n]-a[1]);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int a,b,r,tmp;
  
  scanf("%d%d",&a,&b);
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  
  r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  printf("%d\n",b);
}



Measured memory_bytes: 2732
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
int N, M;
double P;
int A[100];
int B[100];
int hit(int k) {
    return 1 << k;
}

const double None = 1e-100;

double prob(int s, int V);

// sが連結になる確率
double memo[1 << 14];
double calc(int s) {
    double& res = memo[s];
    if(res != None) return res;
    res = 1.0;
    int sub = s;
    do{
        //if(sub != s) printf("s = %d sub = %d prob = %f\n", s, sub, prob(sub, s));
        if(sub != s) res -= prob(sub, s);
        // do something here
        sub = (sub - 1) & s;
    } while(sub != s);
    //printf("calc(%d) -> %f\n", s, res);
    return res;
}

// V(v0) が s になる確率
//map<int, double> memo2[1 << 14];
double prob(int s, int V) {
    if(!(s >> 0 & 1)) return 0.0;

    //if(memo2[V].count(s)) return memo2[V][s];

    double res = calc(s);

    for(int i = 0; i < M; i++) {
        if(!(V & hit(A[i]))) continue;
        if(!(V & hit(B[i]))) continue;
        int fa = (s & hit(A[i]) ? 1 : 0);
        int fb = (s & hit(B[i]) ? 1 : 0);
        if(fa != fb) {
            res *= P;
        }
    }

    return res;
}

int main(){
    while(cin >> N >> M >> P && N > 0) {
        REP(i, 1 << N) memo[i] = None;
       // REP(i, 1 << N) memo2[i].clear();

        P /= 100.0;

        REP(i, M) cin >> A[i] >> B[i];
        REP(i, M) A[i] --;
        REP(i, M) B[i] --;

        printf("%.12f\n", calc((1 << N) - 1));
    }
    return 0;
}

Measured memory_bytes: 1364
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 110000;

ll A,B,C;

bool cmp(ll x,ll y,ll z){return (x&1)|(y&1)|(z&1);}
bool same(ll x,ll y,ll z) {return x==y&&y==z;}

int main()
{
	scanf("%lld%lld%lld",&A,&B,&C);
	ll K=(A+B+C)/2ll;
	int ans=0;
	while(!cmp(A,B,C))
	{
		A=K-A/2,B=K-B/2,C=K-C/2;
		ans++;
		if(same(A,B,C)) return puts("-1"),0;
	}
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
//for (int i = 0; i < N; i++){}
int N;

int main() {
    cin >> N;
    int h[N];
    for (int i = 0; i < N; i++){
        cin >> h[i];
    }

    int c[N];
    c[0] = 0;
    c[1] = abs(h[1] - h[0]);
    for(int i = 2; i < N; i++){
		c[i] = min(c[i-2] + abs(h[i] - h[i-2]), c[i-1] + abs(h[i] - h[i-1]));
	}

    cout << c[N-1] << endl;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

int c1[100001];
int c2[100001];

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

	int n;
	cin >> n;
	rep(i,n) {
		int a;
		cin >> a;
		if (i % 2) {
			c1[a]++;
		}
		else {
			c2[a]++;
		}
	}
	
	vector<pair<int, int>> v1, v2;
	rep(i, 100001)if (c1[i])v1.emplace_back(c1[i], i);
	v1.emplace_back(0, -1);
	rep(i, 100001)if (c2[i])v2.emplace_back(c2[i], i);
	v2.emplace_back(0, -1);
	sort(all(v1));
	sort(all(v2));
	reverse(all(v1));
	reverse(all(v2));

	int ans = INF;
	rep(i, min<int>(2,v1.size())) {
		rep(j, min<int>(2, v2.size())) {
			if (v1[i].second != v2[j].second) {
				ans = min(ans, n - v1[i].first - v2[j].first);
			}
		}
	}

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>

int main(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);

  if(a <= b){
    if(b <= c)//a<=b<=c
      printf("%d %d %d\n",a,b,c);
    else{
      if(c < a)//c<a<=b
	printf("%d %d %d\n",c,a,b);
      else//a<c<b
	printf("%d %d %d\n",a,c,b);
    }
  }
  else{
    if(c <= b)//c<=b<a
      printf("%d %d %d\n",c,b,a);
    else{
      if(a <= c)//b<a<=c
	printf("%d %d %d\n",b,a,c);
      else//b<c<a
	printf("%d %d %d\n",b,c,a);  
    }
  }
  
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

const ll N_MAX = 222222;

ll nxt[N_MAX];
ll pre[N_MAX];
ll v[N_MAX];
ll ans[N_MAX];
ll n, k, cycle, itre;
vector<ll> pass;

void makeNxt(){

	REP(i, N_MAX){
		pre[i] = -1;
	}

	REP(time, 2){
		REP(i, n){
			int now = v[i];
			if(pre[now] != -1){
				nxt[pre[now]] = i;
			}
			pre[now] = i;
		}
	}
}

int makePass(){
	pass.PB(0);
	int now = 0;
	cycle = 1;

	while(1) {
		if(nxt[now] <= now){
			cycle++;
		}
		now = nxt[now];
		now = (now + 1) % n;
		pass.PB(now);
		if(now == 0){
			break;
		}
	}

	k %= cycle;
	now = 0;

	while(k > 1) {
		if(nxt[now] <= now){
			k--;
		}
		now = nxt[now];
		now = (now + 1) % n;
	}

	return now;
}

void makeAns(int start){
	//cout << "start " << start << endl;
	REP(i, N_MAX){
		pre[i] = -1;
	}

	for(int i = start;i < n;i++){
		int now = v[i];
		if(pre[now] != -1){
			while(1){
				itre--;
				pre[ans[itre]] = -1;
				if(ans[itre] == now){
					break;
				}
			}
		}
		else {
			ans[itre] = now;
			pre[now] = itre;
			itre++;
		}
		//cout << "makeAns " << i << endl;
		//REP(i, itre)cout << ans[i] << " ";cout << endl;
	}
}

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

	cin >> n >> k;
	REP(i, n)cin >> v[i];

	if(n == 1){
		if(k % 2){
			cout << v[0];
		}
		cout << endl;
		return 0;
	}

	makeNxt();
	int start = makePass();
	makeAns(start);
	REP(i, itre){
		cout << ans[i] << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 9840
#include<stdio.h>
int main()
{
     int i,n,j,ara[100],count,sum=0;
     scanf("%d",&n);
     for(i=0;i<n;i++)
     {
          scanf("%d",&ara[i]);
     }
     for(i=0;i<n;i++)
     {
          for(j=i+1;j<n;j++)
          {
              count=ara[i]*ara[j];
              sum=count+sum;
          }
     }
     printf("%d\n",sum);
}


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

int main(){
  int n;
  int flag[4] = {0};

  for (int i = 0; i < 4; i++) {
    cin >> n;
    if (n == 1) {
      flag[0] = 1;
    }
    if (n == 9) {
      flag[1] = 1;
    }
    if (n == 7) {
      flag[2] = 1;
    }
    if (n == 4) {
      flag[3] = 1;
    }
  }

  if (flag[0] == 1 && flag[1] == 1 && flag[2] == 1 && flag[3] == 1) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
def check(i,A,B):
    k = 0
    for j in range(len(str(i))):
        k += i % 10
        i = int(i/10)
    if k >= A and k <= B:
        return 1
    else:
        return 0

N,A,B = map(int,input().split())
num = 0
for i in range(N + 1):
    c = check(i,A,B)
    if c == 1:
        num += i
print(num)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

////////////////////////////////////////////////////////////////

int main(void) {
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	for(int i=0; i<N; i++) cin >> A[i];
	sort(A.begin(), A.end());

	vector<ll> plus, minus;
	for(int i=0; i<N; i++){
		if(A[i]<0) minus.push_back(A[i]);
		else plus.push_back(A[i]);
	}

	const ll MAX = ll(1e18) + 1;
	ll left = -MAX, right = MAX;
	//ある値xについて，x未満になる個数は，xに対して明らかに(おおよそ)単調増加なので
	//「x未満がK個未満」であるxの最大値を2分探索する
	//ここで「x以下がK個」とはしないのは　例えば　nC2個の積が 
	// -5  -4  -3  -2  0  0 ...(0は全部で30個)  0  6  8  10  ...
	//となるとき(入力例2)，x=6もx=7も当てはまってしまう(実際の答えは6)
	//また，もし入力例2のKが40ではなく 35とかだと　当てはまるものがない（答えとしては0となってほしいが0が複数個ありちょうどK個となるxがみつからない)
	//0が複数個あるので「K個以下」としたら，最後に K個になってるか K個以下になってるかの判定が必要で，xとなるペアを探す必要が生じる(と思う それにはO(N^2)かかる??)
	while(left + 1 < right){
		ll mid = (left+right) /2;
		bool ok;
		ll cnt = 0;
		for(int i=0; i<N; i++){
			//A[i]>=0のときの各A[i]に対してA[0]~A[N-1]との積は昇順(おおよそ単調増加)
			//A[i]<0 のときの各A[i]に対してA[0]~A[N-1]との積は降順(おおよそ単調減少)
			//各A[i]に対して，A[0]~A[N-1]との積でmid未満になる個数は2分探索で求められる
			if(A[i] >= 0){
				int ok_id = -1, bad_id = N;//idはAのインデックスを意味する
				while(ok_id+1 < bad_id){
					int center = (ok_id+bad_id)/2;
					if(A[i] * A[center] < mid) ok_id = center;
					else bad_id = center; 
				}
				cnt += ok_id+1;// インデックス+1個
			}
			else{
				int bad_id = -1, ok_id = N;
				while(bad_id+1 < ok_id){
					int center = (ok_id+bad_id) /2;
					if(A[i] * A[center] < mid) ok_id = center;
					else bad_id = center;
				}
				cnt += N - (ok_id);//例：ok_id=N-1なら +1される
			}
			
			if(A[i]*A[i] < mid) cnt--; //自分自身との掛け算はカウントしちゃだめなので，-1する
		}
		cnt /= 2;
		if(cnt < K) ok = true;
		else ok = false;

		if(ok) left = mid;
		else right = mid;
		mid = (left + right) /2;
	}

	cout << left << endl;

}


Measured memory_bytes: 7168
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  if s[-1:]=='s':
    return s+'es'
  return s+'s'

# main()
print(main())


Measured memory_bytes: 10620
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, a, b;
	cin >> n >> a >> b;
	vector<ll> x(n);
	rep(i, n) cin >> x[i];
	ll ans = 0;
	repn(i, 1, n) ans += min(b, a * (x[i] - x[i - 1]));
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1152
# dp[i][t_sum]: i番目までの品物で時間がt_sumを超えないように選んだときの、満足度の総和の最大値
N, T = map(int, input().split())
items = sorted([tuple(map(int, input().split()))
                for i in range(N)], key=lambda x: x[0])

dp1 = [[0 for t_sum in range(T+1)] for i in range(N+2)]

for i in range(N):
    for t_sum in range(T+1):
        if t_sum-items[i][0] >= 0:
            dp1[i+1][t_sum] = max(dp1[i+1][t_sum], dp1[i]
                                  [t_sum-items[i][0]]+items[i][1])
        dp1[i+1][t_sum] = max(dp1[i+1][t_sum], dp1[i][t_sum])

ans = 0
for i in range(N):
    for t in range(T):
        ans = max(ans, dp1[i][t]+items[i][1])
print(ans)


Measured memory_bytes: 124120
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;

int main() {

  int h, w;
  cin >> h >> w;
  vector<string>s(h);
  for(int i=0; i<h; i++) cin >> s[i];

  vector<string> t = s;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if( s[i][j] == '#' ) continue;
      int cnt = 0;
      for(int x =-1; x<=1; x++){
        for(int y=-1; y<=1; y++){
          if( x == 0 && y == 0 ) continue;
          if( i+y < 0 || i+y >= h || j+x < 0 || j+x >= w ) continue;
          if( s[i+y][j+x] == '#' ) cnt++;
        }
      }
      char c = '0' + cnt;
      t[i][j] = c;
    }
  }

  for(int i=0; i<h; i++){
    cout << t[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val T = listOf(0) + nextIntList()
    val sum = T.sum()
    val M = nextInt()
    repeat(M) {
        val (P, X) = nextIntList()
        println(sum - T[P] + X)
    }
}

Measured memory_bytes: 36020
#[allow(unused_imports)]
use proconio::{
    fastout, input,
};

#[fastout]
fn main() {
    input! {
        x: i32,
        y: i32,
    }
    if y % 2 != 0 {
        println!("No");
    }
    else {
        println!("{}", if 2 * x <= y && y <= 4 * x { "Yes" } else { "No" });
    }
}


Measured memory_bytes: 2196
import random
import functools
import itertools
import math

R = lambda type_ = "int": list(map(eval(type_), input().split(' ')))

n = int(input())
a = R()
b = R()

pos, neg = 0, 0

for i in range(n):
    if a[i] > b[i]:
        neg += a[i] - b[i]
    else:
        pos += (b[i] - a[i]) // 2

#print('{} {}'.format(pos, neg))
print('Yes' if pos >= neg else 'No')
        


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

using namespace std;

const int rdx[] = {1, 1, 2, 1, 2, 3, 1, 2, 1};
const int rdy[] = {2, 1, 1, 0, 0, 0, -1, -1, -2};
const int ldx[] = {-1, -1, -2, -1, -2, -3, -1, -2, -1};
const int ldy[] = {2, 1, 1, 0, 0, 0, -1, -1, -2};

const int INF = 1 << 30;

int W, H;

using tup = tuple<int, int, bool>;

vector<vector<vector<int>>> dijkstra(int sx, int sy, bool left, const vector<vector<char>> &grid)
{
    priority_queue<pair<int, tup>, vector<pair<int, tup>>, greater<pair<int, tup>>> que;
    vector<vector<vector<int>>> dist(H, vector<vector<int>>(W, vector<int>(2, INF)));
    que.push(make_pair(0, make_tuple(sx, sy, left)));
    dist[sy][sx][left] = 0;
    while (!que.empty())
    {
        auto p = que.top();
        que.pop();
        int d = p.first;
        int x = get<0>(p.second);
        int y = get<1>(p.second);
        int left = get<2>(p.second);
        if (dist[y][x][left] < d)
            continue;
        for (int i = 0; i < 9; i++)
        {
            int nx = x + (left ? ldx[i] : rdx[i]);
            int ny = y + (left ? ldy[i] : rdy[i]);
            if (nx < 0 || nx >= W || ny < 0 || ny >= H || grid[ny][nx] == 'X')
                continue;
            int cost = grid[ny][nx] - '0';
            if (grid[ny][nx] == 'T' || grid[ny][nx] == 'S')
                cost = 0;
            if (dist[y][x][left] + cost < dist[ny][nx][!left])
            {
                // cout << nx << ' ' << ny << endl;
                que.push(make_pair(dist[y][x][left] + cost, make_tuple(nx, ny, !left)));
                dist[ny][nx][!left] = dist[y][x][left] + cost;
                // cout << dist[ny][nx][!left] << endl;
            }
        }
    }
    return dist;
}

int main()
{
    while (cin >> W >> H, W | H)
    {
        vector<vector<char>> grid(H, vector<char>(W));
        vector<pair<int, int>> sp, tp;
        for (int i = 0; i < H; i++)
            for (int j = 0; j < W; j++)
            {
                cin >> grid[i][j];
                if (grid[i][j] == 'T')
                {
                    tp.push_back(make_pair(j, i));
                }
                else if (grid[i][j] == 'S')
                {
                    sp.push_back(make_pair(j, i));
                }
            }
        int res = INF;
        for (auto s : sp)
        {
            for (int l = 0; l < 2; l++)
            {
                auto dist = dijkstra(s.first, s.second, l, grid);
                // for (int i = 0; i < H; i++)
                // {
                //     for (int j = 0; j < W; j++)
                //     {
                //         cout << dist[i][j][0] << ' ';
                //     }
                //     cout << endl;
                // }
                for (auto t : tp)
                {
                    res = min(res, min(dist[t.second][t.first][0], dist[t.second][t.first][1]));
                }
            }
        }
        cout << (res == INF ? -1 : res) << endl;
    }
}


Measured memory_bytes: 3280
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




/*
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		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)];
	}


};*/


long long N, M, K, a, b, c, d, e, H, W, L;
ll A[2][200005] = {};
ll B[100005] = {};
ll C[300005] = {};
bool f, ff;
string S,T;
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[30] = {};


string ss, sss;


int main() {


	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> a >> b;
		bufpl.first = b;
		bufpl.second = a;
		vpl.push_back(bufpl);

	}

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

	a = 0;
	f = true;

	for (int i = 0; i < N; i++) {
		a += vpl[i].second;
		if (a > vpl[i].first) {
			f = false;
			break;
		}

	}

	if (f) {
		cout <<"Yes"<< endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;

}


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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int N = 505;
int d[N][N];
char used[N][N];

const int xx[4] = {-1, 0, 1, 0};
const int yy[4] = {0, -1, 0, 1};

int n;
void relax(int x, int y) {
	for (int t = 0; t < 4; ++t) {
		int nx = x + xx[t], ny = y + yy[t];
		if (nx < 0 || nx >= n || ny < 0 || ny >= n) {
			continue;
		}
		if (d[nx][ny] > d[x][y] + used[nx][ny]) {
			d[nx][ny] = d[x][y] + used[nx][ny];
			relax(nx, ny);
		}
	}
}

int main() {
	n = nxt();
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			d[i][j] = min({i + 1, n - i, j + 1, n - j});
			used[i][j] = 1;
		}
	}
	int ans = 0;
	for (int i = 0; i < n * n; ++i) {
		int pos = nxt() - 1;
		int x = pos / n, y = pos % n;
		used[x][y] = false;
		--d[x][y];
		relax(x, y);
		ans += d[x][y];
		// for (int x = 0; x < n; ++x) {
		// 	for (int y = 0; y < n; ++y) {
		// 		cerr << d[x][y] << " ";
		// 	}
		// 	cerr << "\n";
		// }
		// cerr << "\n";
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 23872
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int pas[3];
	int ju[2];
	for (int i = 0; i < 3; i++){
		int x;
		while (1){
			cin >> x;
			if (x <= 2000 && x >= 100){
				break;
			}else{
				continue;
			}
		}
		pas[i] = x;
	}
	for (int j = 0; j < 2; j++){
		int x;
		while (1){
			cin >> x;
			if (x <= 2000 && x >= 100){
				break;
			}
			else{
				continue;
			}
		}
		ju[j] = x;
	}
	sort(pas, pas + 3);
	sort(ju, ju + 2);
	cout << pas[0] + ju[0] - 50 << endl;
	return 0;
}

Measured memory_bytes: 1176
// IN THE NAME OF GOD "HEAD"
//OM NAMAHA SHIVAYA


    #include <iostream>
    using namespace std;
    int main() {
    	int s,w;
    	cin>>s>>w;
    	if(w>=s)
        {
            cout<<"unsafe";
        }
        else
        {
            cout<<"safe";
        }

    }














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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld EPS = 1e-9;


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

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

    for (;;) {
        int w, h; cin >> w >> h;
        if (w == 0) break;

        vector<string> s(h);
        int si, sj;
        REP(i, h) {
            cin >> s[i];
            REP(j, w) {
                if (s[i][j] == '@') {
                    si = i, sj = j;
                    s[i][j] = '.';
                }
            }
        }

        int ans = 0;
        vvi vis(h, vi(w));
        function<void(int,int)> dfs = [&](int i, int j) {
            vis[i][j] = 1;
            ++ans;
            REP(k, 4) {
                int y = i + dy[k], x = j + dx[k];
                if (y < 0 or x < 0 or y >= h or x >= w) continue;
                if (s[y][x] == '#') continue;
                if (vis[y][x]) continue;
                dfs(y, x);
            }
        };

        dfs(si, sj);

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3176
#include<iostream>
#include<vector>
#include <deque>

using namespace std;

int main(){
    int N;
    cin >> N;
    deque<int> deq;
    vector<int> A(N);

    for (int i = 0; i < N;i++){
        cin >> A[i];
        if(i%2==(N-1)%2){
            deq.push_front(A[i]);
        }else{
            deq.push_back(A[i]);
        }
    }
    for (auto num:deq){
        cout << num << " ";
    }
    return 0;
}

Measured memory_bytes: 3840
h, w = gets.split.map(&:to_i)
s = []
h.times do
  s.push gets.chomp.split('')
end
def boundary(i, j, rows, columns)
  if i >= 0 && j >= 0 && i < rows && j < columns
    true
  else
    false
  end
end

def count(s, i, j)
  bombs = 0
  rows = s.size
  columns = s[0].size
  [-1, 0, 1].each do |row|
    [-1, 0, 1].each do |column|
      if boundary(i+row, j+column, rows, columns)
        if s[i+row][j+column] == '#'
          bombs += 1
        end
      end
    end
  end
  bombs
end

s.each_index do |i|
  s[i].each_index do |j|
    s[i][j] = count(s, i, j) if s[i][j] == '.'
  end
end
s.each do |r|
  puts r.join
end


Measured memory_bytes: 2172
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container;

void main() {
  int[32] a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
  a[readln.chomp.to!int-1].writeln;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n,m; cin >> n >> m;
    if(m <= n) return cout << 0 << endl,0;
    vector<int>v(m);
    for(auto & e : v) cin >> e;
    sort(all(v));
    priority_queue<int,vector<int>>que;
    rep(i,m-1){
        que.push(abs(v[i] - v[i+1]));
    }
    int ans = 0;
    rep(i,n-1){
        que.pop();
    }
    while(!que.empty()){ans += que.top(); que.pop();}
    cout << ans << endl;
}




Measured memory_bytes: 2168
#include <stdio.h>
int primes[1000000];
void eratstenes() {
	int i, j;
	for(i = 0; i < 1000000; ++ i) primes[i] = 1;
	primes[0] = 0; primes[1] = 0;
	for(i = 2; i < 1000; ++ i) {
		if(primes[i] != 1) continue;
		for(j = i * i; j < 1000000; j += i) {
			primes[j] = 0;
		}
	}
}
int main() {
	int i, j, N;
	eratstenes();
	while(1) {
		scanf("%d", &N);
		if(N == 0) break;
		int count = 0;
		for(i = 3; i <= N / 2; ++ i) {
			if(primes[i] != 1) continue;
			if(primes[N - i] == 1) count ++;
		}
		printf("%d\n", count);
	}
	return 0;
}

Measured memory_bytes: 4504