akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=list(map(int,input().split()))

x=[a[0]]

for i in range(1,n-1):
    x.append(x[i-1]+a[i])
y=[sum(a)-a[0]]
for i in range(1,n-1):
    y.append(y[i-1]-a[i])
#print(x)
#print(y)

ans=10**100
for i in range(n-1):
    ans=min(ans,abs(x[i]-y[i]))
print(ans)

Measured memory_bytes: 28576
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<string> s(N);
    vector<int> t(N);
    rep(i,N) cin >> s[i] >> t[i];
    string T; cin >> T;

    bool flag = false;
    int ans = 0;
    rep(i,N) {
        if (flag) {
            ans += t[i];
        } else {
            if (s[i] == T) flag = true;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = (n) - 1; i >= 0; i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define devec(a,n) { cout << #a << " = "; rep(_,n) cout << a[_] << ' '; cout << '\n'; }
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define sz(x) ((long long)x.size())
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
 
auto clk=clock();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll INF = 1e18L+5;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<int> vint;
typedef vector<string> vs;
typedef vector<vi> vvi;

ll gcd(ll a, ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void solve(){
    string s;
    cin>>s;
    ll n = sz(s);
    n--;
    if(s[n]=='s'){
        s += "es";
    }
    else{
        s += 's';
    }
    cout<<s;
}
 
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(11);
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
 
    // cout<<endl<<endl<<"Time elapsed: "<<((double)(clock()-clk)/CLOCKS_PER_SEC)*1000<<"ms"<<endl;
    return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a, b, k;
  cin >> a >> b >> k;
 
  if(a>k){
    cout << a-k << " " << b << endl;
  }
  else if(b>k-a){
    cout << 0 << " " << a+b-k << endl;
  }
  else{
    cout << 0 << " " << 0 << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ps push
#define pf push_front
#define mp make_pair
#define And &&
#define Or ||
#define inf INT_MAX
#define sz(name) name.size()
#define len(name) name.length()
#define ig cin.ignore()
#define sc(name) scanf("%d",&name)
#define ssc(name1,name2) scanf("%d%d",&name1,&name2)
#define sssc(name1,name2,name3) scanf("%d%d%d",&name1,&name2,&name3)
#define scl(name) scanf("%lld",&name)
#define sscl(name1,name2) scanf("%lld%lld",&name1,&name2)
#define ssscl(name1,name2,name3) scanf("%lld%lld%lld",&name1,&name2,&name3)
#define Sort(name) sort(name.begin(),name.end())
#define For(name,start,finish) for(int name=start;name<finish;name++)
#define Forr(name,start,finish) for(int name=start;name>=finish;name--)
#define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


//int row[]={-1,0,1,0};
//int col[]={0,1,0,-1};

const ll N=1e3+10;
const ll M=1e9+7;

ll logx(ll a,ll b){return log(a)/log(b);}
ll Max(ll a,ll b){if(a>b)return a;return b;}
ll Min(ll a,ll b){if(a>b)return b;return a;}
ll big_mul(ll a,ll b,ll m){ll x=0,y=a%m;while(b>0){if(b&1)x=(x+y)%m;y=(2*y)%m;b>>=1;}return x%m;}
ll big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=(x*y)%m;y=(y*y)%m;b>>=1;}return x%m;}
ll Big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=big_mul(x,y,m);y=big_mul(y,y,m);b>>=1;}return x%m;}
ll mod_inverse(ll a,ll m){return big_mod(a,m-2,m);}  //a^-1 mod m = a^(m-2) mod m


int main()
{

    string str;
    cin>>str;

    if(str=="Sunny")
        cout<<"Cloudy"<<endl;

    else if(str=="Cloudy")
        cout<<"Rainy"<<endl;

    else
        cout<<"Sunny"<<endl;


    return 0;
}


//cf 439 C
//cf 489 C
//cf 465 div 2 E
// cc sep17 fill the array

/*

1
3 1000000000
1231 1200
1000 800
1 100
*/


Measured memory_bytes: 256
// cf.) https://qiita.com/drken/items/dc53c683d6de8aeacf5a

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

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {a = b; return 1;}
    return 0;
}

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

    int N, K; cin >> N >> K;
    vector<int> h(N), dp(N+K, 1e9);
    for (int i = 0; i < N; i++) cin >> h[i];

    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i+j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[N - 1] << endl;
    return 0;
}

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


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

struct edge {int to; ll cost; };

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

ll GCD(ll a, ll b){
  if(b==0) return a;
  else return GCD(b, a%b);
}

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}

int main(){
  string a, b;
  cin >> a >> b;
  int c=0;
  for(int i=0; i<a.length(); i++){
    c *= 10;
    c+=a[i]-'0';
  }
  for(int i=0; i<b.length(); i++){
    c *= 10;
    c+=b[i]-'0';
  }
  int cnt = 1;
  while(cnt*cnt<=c){
    if(cnt*cnt==c){
      cout << "Yes" << endl;
      return 0;
    }
    cnt += 1;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

int main() {
  int A, B, K, M;
  cin >> A >> B >> K;
  M=min(A,B);
  vector<int> C(M);
  for (int i=0; i<M; i++) {
    if (A%(i+1)==0 && B%(i+1)==0) {
      C[i]=i+1;
    }
    else {
      C[i]=-1;
    }
  }
  sort(C.begin(),C.end());
  reverse(C.begin(),C.end());
  cout << C[K-1] << endl;
}

Measured memory_bytes: 3616
import java.util.*;



public class Main {
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int max = 0;
		 Map<String, Integer> mMap = new HashMap<String, Integer>();
		 while(N > 0) {
			 String str = sc.next();
			if(mMap.containsKey(str)) {
				mMap.put(str,(mMap.get(str)+1));
			}
			else {
                mMap.put(str,1);
            }
			 if (mMap.get(str) > max) {
	                max = mMap.get(str);
	            }
			N--;
		 }
	        List<String> result = new ArrayList<>();
	        for (String str: mMap.keySet()){
	            if(mMap.get(str) == max){
	                result.add(str);
	            }
	        }
	        Collections.sort(result);
	        for(String s : result) {
	        	System.out.println(s);
	        }
	}
}


Measured memory_bytes: 81880
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans ;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
    int n ;
    cin >> n ;
    vector < int > a(n);
    for( int i = 0 ; i < n ; i++) cin >> a[i] ;
     vector < int > l_gcd(n,0);
     vector < int > r_gcd(n,0);
     vector < int > gcd(n);
     l_gcd[0] = a[0] ;
     r_gcd[n-1] = a[n-1];
     for( int i = 1 ; i < n ; i++) l_gcd[i] = __gcd(l_gcd[i-1],a[i]);
     for( int i = n -2 ; i >=0 ; i--) r_gcd[i] = __gcd(r_gcd[i+1],a[i]);
     gcd[0] = r_gcd[1];
     gcd[n-1] = l_gcd[n-2];
     for( int i = 1 ; i < n-1 ; i++){
            gcd[i] = __gcd(l_gcd[i-1],r_gcd[i+1]);
     }
     int maxm = 0 ;
     int id ;
     for( int i = 0 ; i < n ; i++){
            if(maxm<gcd[i]){
                id = i ;
                maxm = gcd[i] ;
            }
     }
     int minm = INT_MAX;
     for( int i = 0 ; i < n ; i++){
        if(i!=id){
            minm = min(minm,a[i]);
        }
     }
    a[id] = minm ;
    int g = a[0] ;
     for(int i = 1 ; i < n ; i++) g = __gcd(g,a[i]);
     cout << g;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
    string N;
    long long int sum=0,i;
    cin>>N;
    for(i=0;i<N.length();i++)
    {
        sum=sum+N[i]-'0';
    }
    if(sum%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3756
type point = Pt of float * float

let sub_vector (Pt (x1, y1)) (Pt (x2, y2)) = Pt (x2 -. x1, y2 -. y1)

let cross_sign v1 v2 vp =
  let Pt (xv, yv), Pt (xu, yu) = (sub_vector v1 v2), (sub_vector v1 vp) in
  compare 0. (xv *. yu -. yv *. xu)

let rec loop () =
  try
    let line = read_line () in
    Scanf.sscanf
      line "%f %f %f %f %f %f %f %f"
      begin
        fun x1 y1 x2 y2 x3 y3 xp yp ->
        let p1 = Pt (x1, y1) in
        let p2 = Pt (x2, y2) in
        let p3 = Pt (x3, y3) in
        let pp = Pt (xp, yp) in
        let sign = cross_sign p1 p2 pp in
        let point_is_in_triangle =
          List.for_all (fun (p1, p2) -> sign = cross_sign p1 p2 pp)
                       [(p2, p3); (p3, p1)] in
        print_endline @@ if point_is_in_triangle then "YES" else "NO"
      end;
    loop ()
  with End_of_file -> ()

let () = loop ()

Measured memory_bytes: 2388
#include<iostream>

using namespace std;

int main(){
    int n, a[109], mn=10009, mx=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        mn = min(mn, a[i]);
        mx = max(mx, a[i]);
    }
    cout << mx - mn << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include <iomanip>

using namespace std;

long saiki(long N,long K,long count){


    if(N>=K){
        return count;
    }else if(N<K){
        count++;
        N=N*2;
        count = saiki(N,K,count);
        return count;
    }
}

int main(){

    long N;
    long K;
    long count;

    double pro;

    cin >>N >> K;

    for(long i=1;i<=N;i++){
        count = saiki(i,K,0);
        pro += (1.0/double(N)) *(pow(0.5,double(count)));
    }

    cout << setprecision(40) <<pro << endl;

    return 0;

}

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

struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
//static const int INF = 2147483647;
//static const long long INf = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define int ll

int n;
VL a,b,c;
 
signed main(){
    scanf("%lld",&n);
    int tmp;
    for(int i=0;i<n;i++) scanf("%lld",&tmp), a.pb(tmp);
    for(int i=0;i<n;i++) scanf("%lld",&tmp), b.pb(tmp);
    for(int i=0;i<n;i++) scanf("%lld",&tmp), c.pb(tmp);
    sort(all(a)),sort(all(c));

    int ans = 0;

    for(int i=0;i<n;i++){
        int val = b[i];
        VL::iterator A = lower_bound(all(a),val);
        VL::iterator C = upper_bound(all(c),val);
        //printf("%lld %lld %lld\n",val,A-a.begin(),c.end()-C);
        ans += (A-a.begin())*(c.end()-C);
    }

    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 3316
program main
	implicit none
	integer :: N, M, C
	integer, allocatable :: A(:, :), B(:)
	integer :: counter, i
	read(*, *) N, M, C
	allocate(A(1:N, 1:M), B(1:M))
	read(*, *) B
	do i = 1, N
		read(*, *) A(i, 1:M)
	end do
	B = MATMUL(A,B)+C
	counter = 0
	do i = 1, N
		if(B(i) > 0) then
			counter = counter + 1
		end if
	end do
	write(*, *) counter
end program main

Measured memory_bytes: 384
from collections import deque, defaultdict
from heapq import heapify, heappop, merge, heapreplace


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self._root(self.table[x])
            return self.table[x]

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2


def solve(aa, uft):
    roots = defaultdict(list)
    for x, a in enumerate(aa):
        roots[uft._root(x)].append(a)
    if len(roots) == 1:
        return 0
    if n < (len(roots) - 1) * 2:
        return 'Impossible'
    ans = 0
    queue = []
    for l in roots.values():
        l.sort()
        ans += l[0]
        queue.append(l[1:])
    lm = n - m - 2
    if lm > 0:
        mm = merge(*queue)
        for _ in range(lm):
            ans += next(mm)
    return ans


n, m = map(int, input().split())
aa = list(map(int, input().split()))
uft = UnionFind(n)
for _ in range(m):
    uft.union(*map(int, input().split()))
print(solve(aa, uft))


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif


ll best_move(vector<int> group, int scores[]){
    // r -> 0, s -> 1, p -> 2
    // group: 理想的には何を出すべきかの配列
    // dp[i][j]: i個目にjを出すときの最大スコア
    int N = group.size();
    ll dp[N+1][3];
    rep(i, 3){dp[0][i] = 0;}
    rep(i, group.size()){
        if (group.at(i) == 0){
            dp[i + 1][0] = scores[0] + max(dp[i][1], dp[i][2]);
            dp[i + 1][1] = max(dp[i][0], dp[i][2]);
            dp[i + 1][2] = max(dp[i][0], dp[i][1]);
        } else if (group.at(i) == 1){
            dp[i + 1][0] = max(dp[i][1], dp[i][2]);
            dp[i + 1][1] = scores[1] + max(dp[i][0], dp[i][2]);
            dp[i + 1][2] = max(dp[i][0], dp[i][1]);
        } else {
            dp[i + 1][0] = max(dp[i][1], dp[i][2]);
            dp[i + 1][1] = max(dp[i][0], dp[i][2]);
            dp[i + 1][2] = scores[2] + max(dp[i][0], dp[i][1]);
        }
    }
    return max(dp[N][0], max(dp[N][1], dp[N][2]));
}

void Main() {
    int N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    // modKで分けてDP
    int scores[] = {R, S, P};
    vector<vector<int>> groups(K);
    rep(i, T.size()){
        int tmp = INF;
        if (T[i] == 'r'){tmp = 2;}
        if (T[i] == 's'){tmp = 0;}
        if (T[i] == 'p'){tmp = 1;}
        groups.at(i % K).push_back(tmp);
    }
    ll ans = 0;
    for (auto g : groups){ans += best_move(g, scores);}
    cout << ans << endl;
}

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


Measured memory_bytes: 5200
import java.util.Scanner;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int y = x % 10;
		
		switch(y){
			case 2:
			case 4:
			case 5:
			case 7:
			case 9: System.out.println("hon"); break;
			case 0:
			case 1:
			case 6:
			case 8: System.out.println("pon"); break;
			case 3: System.out.println("bon"); break;
		}
		
	}

}

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


using namespace std;


using ll = long long;


mt19937 mt(736);

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


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;

	cin >> n;

	vector<int> ord(n * n);

	for (auto &it : ord)
	{
		cin >> it;
		it--;
	}

	vector<vector<bool>> alive(n, vector<bool>(n, true));
	vector<vector<int>> ans(n, vector<int>(n));

	for (int y = 0; y < ans.size(); y++)
		for (int x = 0; x < ans[y].size(); x++)
			ans[y][x] = min(min(y, (int) ans.size() - 1 - y), min(x, (int) ans.size() - 1 - x)) + 1;

	int sum = 0;

	function<void(int, int, int)> dfs = [&ans, &alive, &dfs](int x, int y, int ns)
	{
		if (y < 0 || y >= ans.size() ||
		    x < 0 || x >= ans[y].size())
			return;

		if (alive[y][x])
			ns++;

		if (ns >= ans[y][x])
			return;

		ans[y][x] = ns;

		for (int i = 0; i < 4; i++)
			dfs(x + dx[i], y + dy[i], ns);
	};

	for (auto it : ord)
	{
		int y = it / (int) ans.size();
		int x = it % (int) ans.size();

		auto add = ans[y][x] - 1;
		sum += add;
		alive[y][x] = false;

		dfs(x, y, add);
	}

	cout << sum << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	auto st = clock();

	ifstream fin("../input.txt");

	solve(fin);

	cout << "clock: " << setprecision(4) << (clock() - st) / (double) CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}


Measured memory_bytes: 31864
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define mp(x,y)         make_pair(x,y)
#define all(c)          c.begin(), c.end()
#define ff              first
#define ss              second
#define nl              '\n'
#define inf             1e9+7
 
bool myway(const pii& a,const pii& b){
	return a.ss<b.ss;
}
int main()
{
	ninja
	int n; cin>>n;
	vector<pii> vp(n);
	bool f=1;
	for(int i=0;i<n;i++){
		cin>>vp[i].ff>>vp[i].ss;
		if(vp[i].ff>vp[i].ss){
			f=0; 
		}
	}
	if(!f){
		cout<<"No"; return 0;
	}
	f=1;
	sort(all(vp),myway);
	int t=0;
	for(int i=0;i<n;i++){
		t+=(vp[i].ff);
		if(t>vp[i].ss)
		{
			f=0; break;
		}
	}
	if(f)
		cout<<"Yes";
	else
		cout<<"No";
}


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

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

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



int main(){
    int N, ans = 0;
    cin >> N;
    ans = N * 100 / 108;
    if(int(ans * 1.08) == N) cout << ans << endl;
    else if (int((ans + 1) * 1.08) == N) cout << ans + 1 << endl;
    // if(N <= ans * 1.08 && ans * 1.08 < N + 1) cout << ans << endl; 
    else cout << ":(" << endl;
    return 0;
}


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

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

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, k, a[200005] = {};

#define SEG_LEN (1 << 18)

int seg[SEG_LEN * 2];

// one point
long long int get(int ind) {
	ind += SEG_LEN;
	long long int sum = 0;
	sum += seg[ind];
	while (true) {
		ind /= 2;
		if (ind == 0)break;
		sum += seg[ind];
	}
	return sum;
}

// range
void add(int l, int r, int x) {
	l += SEG_LEN;
	r += SEG_LEN;
	while (l < r) {
		if (l % 2 == 1) {
			seg[l] += x;
			l++;
		}
		l /= 2;
		if (r % 2 == 1) {
			seg[r - 1] += x;
			r--;
		}
		r /= 2;
	}
}

int main() {
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	rep(i, k) {
		ll ok = true;
		rep(j, n) {
			if (a[j] < max((ll)j, n - j - 1))ok = false;
			add(max((ll)0, j - a[j]), min(n - 1, j + a[j]) + 1, 1);
		}
		rep(j,n)a[j] = get(j);
		rep(j, SEG_LEN * 2)seg[j] = 0;
		if (ok) {
			rep(j, n)cout << n << endl;
			return 0;
		}
	}
	rep(i, n)cout << a[i] << endl;
	return 0;
}

Measured memory_bytes: 7176
N = int(input())
T = list()
for _ in range(N):
    a, b = map(int, input().split())
    T.append((a, b))
T = sorted(T, key=lambda x:x[1])

Time = 0 
for task in T:
    taskTime, deadline = task
    Time += taskTime
    if deadline < Time:
        print("No")
        exit()
print("Yes")



Measured memory_bytes: 39116
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<tr1/unordered_map>
#include<ctime>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
    int f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return f*x;
}
#define INF 0x3f3f3f3f
#define MAXN 200000
#define Mod int(1e9+7)
int s[MAXN+5];
char Re[MAXN+5];
int main(){
	scanf("%s",Re+1);
	int cnt=0,n=strlen(Re+1);
	for(int i=1;i<=n;i++)
		if(Re[i]=='W')
			s[++cnt]=i;
	LL ans=0;
	for(int i=1;i<=cnt;i++)
		ans+=s[i]-i;
	printf("%lld\n",ans);
    return 0;
}


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


int main()
{
	int n, k;
	cin >> n >> k;
	long long h[n];
	for (int i = 0; i < n; i++)
		cin >> h[i];
	long long ans[n];
	ans[0] = 0;
	ans[1] = abs(h[1]-h[0]);
	for (int i = 2; i < n; i++) {
		ans[i] = 1e10;
		for (int j = i-1; j >= max(i-k, 0); j--) {
			ans[i] = min(ans[i], ans[j]+abs(h[j]-h[i]));
		}
	}
	cout << ans[n-1];
}






Measured memory_bytes: 1792
#include <stdio.h>

int dp[2][10001];
int len;
int p[100];

int main(){
  int n, i, j, k, l;
  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%d", p+i);
  len = 1;
  for(i=0;i<n;i++){
    int b = i&1;
    for(j=k=l=0;j<len&&k<len;){
      if(dp[b][j] < dp[b][k] + p[i]) dp[b^1][l++] = dp[b][j++];
      else if(dp[b][j] > dp[b][k] + p[i]) dp[b^1][l++] = dp[b][k++] + p[i];
      else { dp[b^1][l++] = dp[b][j++]; k++; }
    }
    while(k<len) dp[b^1][l++] = dp[b][k++] + p[i];
    while(j<len) dp[b^1][l++] = dp[b][j++];
    len = l;
  }
  for(i=len-1;i>=0;i--){
    if(dp[n&1][i] % 10){
      printf("%d\n", dp[n&1][i]); return 0;
    }
  }
  puts("0");
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    string s1,s2;
    cin>>s1>>s2;
    int k1=s1.length();
    int k2=s2.length();
    if(k1!=k2){
        printf("NO\n");
    }
    else{
        for(int i=0;i<k1;i++){
            if(s1[i]!=s2[k2-i-1]){
                printf("NO\n");
                return 0;
            }
        }
        printf("YES\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int a;
    cin>>a;
    vector<int > v;
    for(int i=0;i<a;i++)
    {
        int t;
        cin>>t;
        v.push_back(t);
    }
    
    int q;
    cin>>q;
    while(q--)
    {
        int t;
        cin>>t;
        int pos=lower_bound(v.begin(),v.end(),t)-v.begin();
        cout<<pos<<endl;
    }
    
}


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

int f[2][110];
int n, a[2][110];

int main(){
	scanf("%d" , &n);
	for(int i = 0 ; i < 2 ; i++)
		for(int j = 0 ; j < n ; j++)
			scanf("%d" , &a[i][j]);
	memset(f, -1, sizeof(f));
	f[0][0] = a[0][0];
	for(int i = 0 ; i < 2 ; i ++){
		for(int j = 0 ; j < n ; j++){
			if(j > 0)f[i][j] = max(f[i][j], f[i][j - 1] + a[i][j]);
			if(i > 0)f[i][j] = max(f[i][j], f[i - 1][j] + a[i][j]);
		}
	}
	printf("%d\n" , f[1][n - 1]);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
int num[10001];
using namespace std;
int main()
{
	int n; cin >> n;
	for (int i = 1; i <= 100; i++)
	{
		for (int j = 1; j <= 100; j++)
		{
			for (int k = 1; k <= 100; k++)
			{
				int x = i * i + k * k + j * j + i * j + i * k + j * k;
				if (x > n)
					break;
				num[x]++;
			}
		}
	}
	for (int i = 1; i <= n; i++)
	{
		cout << num[i] << endl;
	}

}

Measured memory_bytes: 3156
#D ときなおし
#の規則性に着目。1からAまでのXORはx,1,x+1,0の4パターンの連続。
#AからBまでの総和を求める→1からBの総和-(1からA-1)の総和。そしてXORでは引き算も足し算と同じことなのでAまでのXORとBまでのXORのXORをとる。

def souwa(s):
    return [s, 1, s + 1, 0] [s % 4] #右の[]で左のリストのインデックスを指定できる。

a, b = map (int, input().split())
print(souwa(b) ^ souwa(a - 1))

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

void printArr(int* a, int len){
	for(int i=0; i<len; ++i){
		if(i != 0) cout << " ";
		cout << *(a + i);
	}
	cout << "\n";
}

int main(){
	
	int n;
	cin >> n;
	
	int a[n];
	for(int i=0; i<n; ++i) cin >> a[i];
	
	printArr(a, n);	
	for(int i=1; i<n; ++i){
		int t = a[i];
		if(a[i-1] > t){
			int j=i;
			do{
				a[j] = a[j-1];
				j--;
			} while(j > 0 && a[j-1] > t);
			a[j] = t;
		}	
		printArr(a, n);
	}
	
	return 0;
}



Measured memory_bytes: 3084
// Problem : B - Distance 
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int long long
const int N = 1e6;
const ll mod = 1e9+7;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 10000000;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(9);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
//1. Ends here

//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}



void solve()
{
	int n;
	cin>>n;
	
	int d;
	cin>>d;
	
	int cnt=0;
	
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		
		if(sqrt(x*x+y*y)<=d)cnt++;
	}
	
	cout<<cnt;
	
	
    return;
}
// how r u bro

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() 
{
 ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N;
 cin>>N;
vector<ll> a; 
for(ll i=0;i<N;i++)
{
    ll data;
    cin>>data;
  a.push_back(data);
}
map<ll,ll> ia,ja,ka;
ll ans=0;
for(ll i=0;i<a.size();i++)
{
    for(ll j=i;j<a.size();j++)
    {
        for(ll k=j;k<a.size();k++)
        {
          if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i])
          {
              if(a[i]+a[j]>a[k] && a[j]+a[k]>a[i] && a[k]+a[i]>a[j])
              {
                
                  ans++;
              }
          }
        }
    }
}
cout<<ans<<endl;
return(0);
}

Measured memory_bytes: 3616
# sys.stdin.readline()
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
l = [0]*m
r = [0]*m
for i in range(m):
    l[i], r[i] = map(int, input().split())
if max(l) > min(r):
    ans = 0
else:
    ans = min(r)-max(l) + 1
print(ans)

Measured memory_bytes: 10996
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}
const Int N = 310;

Int n, m;
int mem[N][N][N];
bool used[N][N][N];

Int dfs(Int pos, Int num, Int cnt){

  if(pos == n-1 && num == n-1 && cnt == m) return 1;
  if(pos == n || cnt == m) return 0;
  if(used[pos][num][cnt]) return mem[pos][num][cnt];
  used[pos][num][cnt] = 1;
  
  // つなぐ
  Int a = dfs(pos, pos, cnt+1) * (num+1);
  
  // ループ
  Int b = dfs(pos, num, cnt + 1) * (pos - num);
  
  // 進む
  Int c = dfs(pos + 1, num, cnt + 1);
  
  Int res = (a + b + c) % mod;
  
  return mem[pos][num][cnt] = res;
}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  cin>>n>>m;

  Int k = 1;
  for(Int i = n-1;i>=1;i--) k = k * i % mod;

  Int ans = dfs(0, 0, 0) * k % mod;
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 141696
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int n,x;
	int A;

	while(1){
		cin>>n>>x;
		if (n==0&&x==0)break;
		A=0;
		for (int i=1;i<=n-2;i++){
			for (int j=i+1;j<=n-1;j++){
				for (int k=j+1;k<=n;k++){
					if ((i+j+k)==x)A+=1;
				}
			}
		}
		cout<<A<<endl;

	}



	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n;
  cin >>n;
  map<int,int>mp;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    mp[a]++;
    mp[a]%=2;
  }
  long long kotae=0;
  auto begin=mp.begin(),end=mp.end();
  for(auto iter=begin;iter!=end;iter++){
    int x=iter->second;
    if(x==1)kotae++;
  }
  cout<<kotae<<endl; 
  return 0;
}
  
  


Measured memory_bytes: 8276
N = int(input())
X = list(map(int, input().split()))
c = sum([x**2 for x in X])

ans = 100 * (100) ** 2
for i in range(1, 101):
    c += 2 * sum([i-x for x in X]) - N
    ans = min(c, ans)

print(ans)


Measured memory_bytes: 2940
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7 ;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
 
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}
void norm(ll &n)
{
    n%=MOD;
    n+=MOD;
    n%=MOD;
}


void solve()
{
    ll n,k;
    cin>>n>>k;
    v64 arr(n+1);
    for (int i=1; i<=n; i++)
        cin>>arr[i];
    sort(arr.begin()+1,arr.end());
    ll ans=0;
    for (int i=n-k; i>=1; i--)
        ans+=arr[i];
    cout<<ans<<endl;

}
 
int main() {
    fast_cin();
    int t=1;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
L = sorted([int(x) for x in input().split()])
def f(i, j, k):
    l, m, n = L[i], L[j], L[k]
    if l == m or m == n:
        return False
    return n < l + m
ans = 0
if len(L) < 3:
    print(0)
    exit()
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            ans += f(i, j, k)
print(ans)


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        a[i]--;
    }
    vector<int> idx(n);
    for(int i=0; i<n; i++){
        idx[a[i]]=i;
    }
    set<int> s;
    ll ans = 0;
    for (int x = n-1; x >= 0; --x) {
        int i = idx[x];
        ll c = 0;
        {
            s.insert(i);
            vector<int> l(2,-1);
            vector<int> r(2,n);
            {
                auto it = s.find(i);
                rep(j,2) {
                if (it == s.begin()) break;
                    it--;
                    l[j] = *it;
                }
            }
            {
                auto it = s.find(i);
                rep(j,2) {
                    ++it;
                    if (it == s.end()) break;
                    r[j] = *it;
                }
            }
            vector<int> ls(2);
            ls[0] = i-l[0]; ls[1] = l[0]-l[1];
            vector<int> rs(2);
            rs[0] = r[0]-i; rs[1] = r[1]-r[0];
            c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
        }
        ans += c*(x+1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(m);
  long long ans = 0;

  for (int i = 0; i < m; ++i) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());

  if (n >= m) {
    cout << ans << "\n";
    return 0;
  }

  vector<int> diff(m - 1);
  for (int i = 0; i < diff.size(); ++i) {
    diff[i] = (v[i + 1] - v[i]);
  }
  sort(diff.begin(), diff.end());

  for (int i = 0; i < m - n; ++i) {
    ans += diff[i];
  }
  cout << ans << endl;
}

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

int V[1500][10500];

int main()
{
    int N,W;
    cin >> N >> W;
    int v[1000],w[1000];
    int V[101][10001];
    for(int i=1;i<=N;i++)
    {
        cin >> v[i] >> w[i];
    }
    int i,j;
    for(i=0;i<=N;i++)
       for(j=0;j<=W;j++)
          V[i][j]=0;
    for(i=1;i<=N;i++)
       for(j=1;j<=W;j++)
       {
           if(j-w[i]<0)
             V[i][j]=V[i-1][j];
           else
           {
               int v1=v[i]+V[i-1][j-w[i]];
               int v2=V[i-1][j];
               if(v1>v2)
                 V[i][j]=v1;
               else V[i][j]=v2;
           }
       }
    cout << V[N][W] << endl;
}


Measured memory_bytes: 7048
//In the name of Allah
#include <bits/stdc++.h>
using namespace std; 

const int maxN = 300 + 10; 

int a[maxN][maxN]; 
bool bad[maxN];
int ptr[maxN]; 
int cnt[maxN]; 
set<pair<int,int>> curr; 

int main() { 
    int n, m; 
    cin >> n >> m;

    for( int i = 0 ;i < n ; i++ ) { 
        for( int j = 0 ; j < m ; j++ ) { 
            cin >> a[i][j]; 
            a[i][j]--; 
        }
        cnt[a[i][0]]++; 
    }

    for( int i = 0 ; i < m ; i++ ) 
        curr.insert( { cnt[i] , i } ); 

    int ans = n; 

    while( curr.size() ) { 
        ans = min( ans , curr.rbegin()->first );
        int val = curr.rbegin()->second;
        bad[val] = true;
        curr.erase( *curr.rbegin() );

        if( curr.empty() ) break;

        for( int i = 0 ; i < n ; i++ ) 
            if( a[i][ptr[i]] == val ) { 
                ptr[i]++;
                while( bad[a[i][ptr[i]]] )
                    ptr[i]++;
                int x = a[i][ptr[i]];
                curr.erase( { cnt[x] , x } );
                cnt[x]++;
                curr.insert( { cnt[x] , x } ); 
            }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        n: usize,
        ab: [(usize, usize); n],
    }

    let mut mins = ab.iter().map(|e| e.0).collect::<Vec<_>>();
    mins.sort();
    let mut maxs = ab.iter().map(|e| e.1).collect::<Vec<_>>();
    maxs.sort();

    if n % 2 == 0 {
        let min_median = mins[n / 2 - 1] + mins[n / 2];
        let max_median = maxs[n / 2 - 1] + maxs[n / 2];
        echo!(max_median - min_median + 1);
    } else {
        let min_median = mins[(n + 1) / 2 - 1];
        let max_median = maxs[(n + 1) / 2 - 1];
        echo!(max_median - min_median + 1);
    }
}


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

int main() {
  string S;
  cin >> S;
  int n = 0;
  for(int i = 0; i < S.size(); i++) {
    if(i % 2 == 0) {
      if(S.at(i) == 'R' || S.at(i) == 'U' || S.at(i) == 'D') {
        n += 0;
      }
      else n++;
    }
    if(i % 2 == 1) {
      if(S.at(i) == 'L' || S.at(i) == 'U' || S.at(i) == 'D') {
        n += 0;
      }
      else n++;
    }
  }
  if(n == 0) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 10 19:49:51 2019

@author: plosi
"""

def main(): 
    N=int(input()) 
    ws=input().split(" ")
    for i in range(N): 
        ws[i]=int(ws[i]) 
    S1=[0 for i in range(N+1)] 
    S2=[0 for i in range(N+1)] 
    for i in range(1,N+1): 
        S1[i]=S1[i-1]+ws[i-1] 
    for i in range(N-1,-1,-1): 
        S2[i]=S2[i+1]+ws[i] 
    m=S2[0]-S1[0]
    for i in range(1,N): 
        m=min(m,abs(S2[i]-S1[i])) 
    print(m)
main()
        

Measured memory_bytes: 3064
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

class Hoge(object):
    
    def __init__(self):
        pass

    def func(self):
        '''
        insert your code
        '''
        h = reversed(sorted(input() for i in range(10)))
        for i, e in enumerate(h):
            if i <= 2:
                print e
        return None

if __name__ == '__main__':
    h = Hoge()
    h.func()
    

Measured memory_bytes: 4220
N = int(input())
C = {'AC':0 , 'WA':0, 'TLE':0 , 'RE':0 }

for i in range(N):
  C[input()] += 1

print('AC x', C['AC'] )
print('WA x', C['WA'] )
print('TLE x', C['TLE'] )
print('RE x', C['RE'] )


Measured memory_bytes: 9224
#include<stdio.h>
int main(){
	
	int x,n,a;
	int i,j,k;
	
	while(1){
	a=0;	
	scanf("%d %d",&n,&x);
	
	if(n == 0 && x == 0)
		break;
		
		for(i = 1;i <= n;i++){
			for(j = i + 1;j <= n;j++){
				for(k = j + 1;k <= n;k++){
					if (i + j + k == x)
						a++;
				}
			}
		}
		printf("%d\n",a);
	}
	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int l,r,d;
    cin >> l >> r >> d;
    int sum = 0;
    REP(i,l,r+1) {
        sum += (i % d == 0);
    }
    cout << sum << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int main(){
    int a,b;
    int s;
    cin >> a >> b;
    s = a + b;
    if (s % 2 == 1){
        cout << "IMPOSSIBLE" <<endl;
    }
    else{
        int k = s/2;
        if(k < 0){
            k = (-1) * k;
            
        }
         cout << k << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int n,m;    cin >> n >> m;
    vector<pair<int, int> >tmp(m);
    rep(i, m){
        int x,y;    cin >> x >> y;
        --x;    --y;
        tmp[i] = pair<int, int>(x, y);
    }
    //solve
    vector<pair<bool, int> >table(n, pair<bool, int>(false, 1));  //<red, count>
    table[0].first = true;
    rep(i, m){
        if(table[tmp[i].first].first){
            table[tmp[i].second].first = true;
            table[tmp[i].first].second--;
            table[tmp[i].second].second++;
            if(table[tmp[i].first].second == 0)    table[tmp[i].first].first = false;
        }else{
            table[tmp[i].first].second--;
            table[tmp[i].second].second++;
        }
    }
    int ans = 0;
    rep(i, n){
        if(table[i].first)  ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == ',') s[i] = ' ';
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
	int n; cin >> n;
	vector<pair<int, int>> P(n);
	rep(i, n) cin >> P[i].second >> P[i].first;
	sort(P.begin(), P.end());
	long long time = 0;
	rep(i, n) {
		time += P[i].second;
		if (time > P[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void)
{
    int ans[3];
    int n, m;
    rep(i, 3)
        ans[i] = -1;

    int flag = 1;
    scanf("%d%d", &n, &m);
    rep(i, m)
    {
        int s, c;
        scanf("%d%d", &s, &c);
        if (ans[s - 1] == -1 || ans[s - 1] == c)
            ans[s - 1] = c;
        else
            flag = 0;
    }
    if (n != 1 && ans[0] == 0)
        flag = 0;

    if (flag)
        rep(i, n)
        {
            if ((ans[i] == -1 && n == 1) || (ans[i] == -1 && i > 0))
                printf("0");
            else if (ans[i] == -1 && n != 1 && i == 0)
                printf("1");
            else
                printf("%d", ans[i]);
        }
    else
        printf("-1");
    printf("\n");

    return 0;
}

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

using namespace std;

int N;
int A[100010];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		A[i]--;
	}
	int x = 0;
	for (int i = 0; i < 100010; i++) {
		if (x == 1) {
			cout << i << endl;
			return 0;
		}
		x = A[x];
	}
	cout << -1 << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d", &a, &b);
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else if(a==b){
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main(){
    int q, c;
    char ch;
    bool flag=0;
    string str;
    list<char> ls;

    cin >> str;
    cin >> q;
    for(int i=0;i<str.size();i++) ls.push_back(str[i]);
    for(int i=0;i<q;i++){
        cin >> c;
        if(c==1) flag=!flag;
        else {
            cin >> c >> ch;
            if(c==1) {
                if(!flag) ls.push_front(ch);
                else ls.push_back(ch);
            }
            else {
                if(flag) ls.push_front(ch);
                else ls.push_back(ch);
            }
        }
    }
    if(flag) reverse(ls.begin(), ls.end());
    for(list<char>::iterator it=ls.begin(); it!=ls.end();it++) cout << *it;

    return 0;
}

Measured memory_bytes: 9984
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
const int MAXN = 2e6+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 
signed main(){
	int m1,m2,d1,d2; cin>>m1>>d1>>m2>>d2;
	if(d1==a[m1]) puts("1"); else puts("0");
    return 0;
}


Measured memory_bytes: 256