akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
p = list(map(int, input().split()))
s = 0
for i in range(0,K):
    s = s+p[i]
u = s
for i in range(0,N-K):
    t = s+p[i+K]-p[i]
    if u < t:
        u = t
    s = t
print ((u+K)/2)

Measured memory_bytes: 25060
/**
 *   Author:  Wasi Ur Rahman
 *   FROM RMSTU
**/
#include            <bits/stdc++.h>
#define             fast            ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define             ll           long long
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define             fast           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define             min3(a,b,c)    min(a,min(b,c))
#define             max3(a,b,c)    max(a,max(b,c))
#define             all(v)         v.begin(),v.end()
#define             revall(v)      v.rbegin(),v.rend()
#define             pb             push_back
#define             eb             emplace_back
#define             setbits(x)     __builtin_popcountll(x)
#define             zrobits(x)     __builtin_ctzll(x)
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set os;
vector<ll> v,v1,v2,v3,v4;
/*
void solve(){
    ll a,b;
    cin >> a >> b;
    if(b >= a)
        cout << 1 << endl;
    else {
        if(a == b)
            cout << 1 << endl;
        else if(b == 1)
            cout << a << endl;
        else{
            for(ll i = 2;i*i<=b;i++){
                if(a % i == 0){
                    v.pb(i);
                }
            }
            sort(all(v));
            cout << v[0] << endl;
        }
    }

}
*/
int main(){
    fast;
    int n;
    cin >> n;
    if(n %10 == 2 or n %10 == 4 or n %10 == 5 or n %10 == 7 or n %10 == 9)
        cout << "hon" << endl;
    else if(n % 10 == 0 or n % 10 == 1 or n % 10 == 6 or n % 10 == 8)
        cout << "pon" << endl;
    else cout << "bon" << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>

using namespace std;

int main(void) {
    int h, w;
    while (true) {
        scanf("%d%d", &h, &w);
        if (h == 0 || w == 0) break;
        char g[w][h];
        int t[w][h];
        for (int j = 0; j < h; j++) {
            for (int i = 0; i < w; i++) {
                scanf(" %c", &g[i][j]);
            }
        }
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                int c = 0;
                for (int k = i; k < w; k++) {
                    if (g[k][j] == '.') {
                        c++;
                    } else {
                        break;
                    }
                }
                t[i][j] = c;
            }
        }
        int max_s = 0;
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                int min_t = t[i][j];
                for (int k = j; k < h; k++) {
                    if (t[i][j] == 0) break;
                    min_t = min(min_t, t[i][k]);
                    max_s = max(max_s, min_t * (k - j + 1));
                }
            }
        }
        printf("%d\n", max_s);
    }
    return 0;
}

Measured memory_bytes: 2244
import sys


def main() -> None:
    x = input()
    s_cnt = 0
    ans = 0

    for v in x:
        if v == 'S':
            s_cnt += 1
        if v == 'T':
            if s_cnt == 0:
                ans += 1
            else:
                s_cnt -= 1

    ans += s_cnt
    print(ans)


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

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

    int ans = n;// INF
    for(int i=0; i<=n; i++){
        int count = 0;
        int total6 = i;
        int total9 = n-i;
        while(total6 > 0){
            count += total6 % 6;// 6, 36, 216, ...
            total6 /= 6;
        }
        while(total9 > 0){
            count += total9 % 9;// 9, 81, 729, ...
            total9 /= 9;
        }
        if(ans > count) ans = count;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fn main() {
    let (_y, m, _d): (usize, usize, usize) = {
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s.truncate(10);
        let mut iter = s.split('/');
        let y = iter.next().unwrap().parse().unwrap();
        let m = iter.next().unwrap().parse().unwrap();
        let d = iter.next().unwrap().parse().unwrap();
        (y, m, d)
    };

    println!("{}", if m <= 4 {"Heisei"} else {"TBD"});
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#define LEN 100005
typedef struct pp{
  char name[100];
  int t;
} P;
P Q[LEN+1],x;
int tail ,head,n;

void enqueue(P);
P dequeue(void );


int main(int argc, char const *argv[]) {
  int q,total=0,i,time;
  P kari;
      scanf("%d%d\n", &n,&q);
  for (i = 1; i <= n; i++) {
    scanf("%s%d\n", Q[i].name, &Q[i].t);
  }
  tail = n+1;
  head = 1;

  while(head != tail) {
    kari = dequeue();
 if(kari.t < q )  time = kari.t;
  else time = q;
   kari.t -= time;
    total += time;
    if(kari.t > 0) enqueue(kari);
 else  printf("%s %d\n", kari.name , total);

/* else {
   Q[head].t -= q;
   total += q;
   kari = dequeue();
  enqueue(kari);
 }
 */
  }
  return 0;
}

void enqueue(P x) {
  //if(head == (tail + 1) % n) printf("error\n");
  Q[tail] = x;
   if(tail + 1 == LEN)
      tail = 0;
  else tail++;
}

P dequeue(void ) {
  //if(head == tail) printf("error\n");
  x = Q[head];
  if(head + 1 == LEN) head = 0;
  else head++;
  return x;
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<long long> a(30, 0);
    long long ans = (long long)n*(n+1)/2;
    for (auto c : s) ++a[c-'a'];
    for (auto c : a) ans -= c*(c+1)/2;
    cout << ++ans << endl;
    return 0;
}

Measured memory_bytes: 640
// Aizu 2400: You Are the Judge
// 2017.9.25 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { int id, p[11], solved, penalty; } T;
T team[52];

int cmp(T *a, T *b)
{
	if (b->solved - a->solved) return b->solved - a->solved;			// ????????°??§??????
	if (a->penalty - b->penalty) return a->penalty - b->penalty;	// ??????????????£??§??????
	return a->id - b->id;											// ?????????id??§??????
}

int main()
{
	int t, p, r, tid, pid, tm; char msg[10];		// ???????????????????????°???
	int i;
	T *tp;

	while (scanf("%d%d%d", &t, &p, &r) && t > 0) {
		memset(team, 0, sizeof(T) * (t+1));			// ?????????
		for (i = 1; i <= t; i++) team[i].id = i;

		while (r-- > 0) {
			scanf("%d%d%d%s", &tid, &pid, &tm, msg);
			tp = team + tid;
			if (*msg == 'W') tp->p[pid]++;				// ????????°
			else {
				tp->solved++;							// ?§£??????????????°
				tp->penalty += tp->p[pid] * 1200 + tm;	// ??????????????£?????´??°
			}
		}
		qsort(team+1, t, sizeof(T), cmp);
		for (i = 1; i <= t; i++) 
			printf("%d %d %d\n", team[i].id, team[i].solved, team[i].penalty);
	}
	return 0;
}

Measured memory_bytes: 1800
#include <iostream>
#include <vector>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

const int kNil = -1;

enum class Color {
  kWhite,
  kGrey,
  kBlack,
};

template <class T>
struct Edge {
  using w_type = T;
  Edge(int u, int v, w_type w): u(u), v(v), w(w) { }
  int u, v;
  w_type w;
  bool operator<(const Edge<T> & rhs) const {
    if (w != rhs.w) { return w < rhs.w; }
    if (u != rhs.u) { return u < rhs.u; }
    return v < rhs.v;
  }
};

template <class Edge>
void DFSVisitTopological(const typename vector<Edge>::size_type node_now,
       typename vector<Edge>::size_type & time,
       const vector<vector<Edge>> & adjacency_list,
       vector<int> & d,
       vector<int> & f,
       vector<Color> & color,
       vector<int> & parent,
       vector<typename vector<Edge>::size_type> & result) {
  color[node_now] = Color::kGrey;
  d[node_now] = time++;
  for (const auto & e: adjacency_list[node_now]) {
    if (color[e.v] == Color::kWhite) {
      parent[e.v] = node_now;
      DFSVisitTopological(e.v, time, adjacency_list, d, f, color, parent, result);
    }
  }
  color[node_now] = Color::kBlack;
  f[node_now] = time++;
  result.push_back(node_now);
}

template <class Edge>
vector<typename vector<Edge>::size_type> DFSTopological(
    const vector<Edge> & edges,
    typename vector<Edge>::size_type node_num) {
  using size_type = typename vector<Edge>::size_type;

  vector<vector<Edge>> adjacency_list(node_num, vector<Edge>());
  for (const auto & e: edges) {
    adjacency_list[e.u].push_back(e);
  }

  vector<int> d(node_num);
  vector<int> f(node_num);
  vector<Color> color(node_num, Color::kWhite);
  vector<int> parent(node_num);
  vector<size_type> result;
  size_type time = 0;

  for (unsigned i = 0; i < node_num; ++i) {
    if (color[i] == Color::kWhite) {
      DFSVisitTopological(i, time, adjacency_list, d, f, color, parent, result);
    }
  }

  reverse(result.begin(), result.end());
  return result;
}

int main(int argc, char const *argv[]) {
  using w_type = unsigned;

  vector<Edge<w_type>> edges;
  unsigned V, E;
  cin >> V >> E;
  for (unsigned i = 0; i < E; ++i) {
    unsigned u, v;
    w_type w;
    cin >> u >> v;
    edges.emplace_back(u, v, 1);
  }

  auto result = DFSTopological(edges, V);
  for (const auto & e: result) {
    cout << e << endl;
  }

  return 0;
}

Measured memory_bytes: 4672
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def solve(arr, positive):
    num_op = 0
    cumul = 0
    #  print('current cumul:', cumul)

    for a in arr:
        cumul += a

        if positive and cumul >= 0:
            num_op += 1 + cumul
            cumul = -1
        elif not positive and cumul <= 0:
            num_op += 1 - cumul
            cumul = 1

        positive = not positive

    return num_op


def main():
    read_h()
    arr = read_h()

    op_plus = solve(arr, True)
    #  print('op plus:', op_plus)
    op_minus = solve(arr, False)
    #  print('op minus:', op_minus)

    print(min(op_plus, op_minus))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14468
#C
n, m = list(map(int,input().split()))
a = [0]*(n+1)
w = [0]*(n+1)
wrong = 0
for _ in range(m):
    p, s = list(map(str,input().split()))
    p = int(p)
    if s == "WA":
        w[p] +=1
    if s == "AC":
        if a[p] == 0:
            a[p] = 1
            wrong += w[p]
print(sum(a),wrong)

Measured memory_bytes: 4596
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	as := intSliceScanner(n)
	am := make(map[int]int)
	for i := 0; i < n; i++ {
		am[as[i]]++
	}
	if _, ok := am[1]; ok {
		if am[1] > 1 {
			fmt.Println(0)
		} else {
			fmt.Println(1)
		}
	} else {
		ans := 0
		for _, v := range as {
			f := true
			if am[v] > 1 {
				continue
			}
			for i := 2; i*i <= v; i++ {
				if v%i == 0 {
					if _, ok := am[v/i]; ok {
						f = false
					}
					if _, ok := am[i]; ok {
						f = false
					}
				}
			}
			if f {
				ans++
			}
		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 14976
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  string s;
  cin>>s;
  bool flag = true;
  for(int i = 0; i < s.length(); i++){
    if(i%2==0){
      if(s[i]=='L') flag = false;
    }
    else{
      if(s[i]=='R') flag = false;
    }
  }
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   int N, K; cin >> N >> K;
   map<int, int> A;
   rep(i, 0, K) {
     int d; cin >> d;
     rep(j, 0, d) {
       int tmp; cin >> tmp;
       A[tmp]++;
     }
   }
   cout << N - A.size() << endl;
 }


Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main(void){
    int x, y, w, h, r;
    cin >> w >> h >> x >> y >> r; cin.ignore();
    if (r <= x && x <= (w - r) && r <= y && y <= (h - r)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1160
N, M = map(int, input().split())
for num in range(M):
    l, r = map(int, input().split())
    if num == 0:
        minimam = l
        maximam = r
    else:
        minimam = max(minimam, l)
        maximam = min(maximam, r)
result = maximam - minimam + 1
if result >= 0:
    print(maximam - minimam + 1)
else:
    print(0)

Measured memory_bytes: 3060
#include <cstdio>

bool max_truck_load_is_enough_for_the_trucks(int w[], int n, int k, int P) {
  int c = 0;
  int e = 0;
  // printf("k=%d, P=%d\n", k, P);
  for (int i = 0; i < n; i++) {
    if (w[i] > P) {
      return false;  // P is too small for the packet
    }
    if (e + w[i] > P) {
      e = 0;
      c++;
    }
    e += w[i];  // load of this truck
  }
  c++;
  return c <= k;
}

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

  int avg = 0;
  int w[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &w[i]);
    avg += w[i];
  }
  avg /= k;
  int a = avg / 2;  // lower bound of P
  while (max_truck_load_is_enough_for_the_trucks(w, n, k, a)) {
    a /= 2;
  }
  int b = avg * 2;  // upper bound of P
  while (!max_truck_load_is_enough_for_the_trucks(w, n, k, b)) {
    b *= 2;
  }

  while (a + 1 < b) {
    int d = (a + b) / 2;  // P at this iteration
    // printf("a=%d, b=%d, d=%d\n", a, b, d);

    if (max_truck_load_is_enough_for_the_trucks(w, n, k, d)) {
      // printf("enough\n");
      b = d;
    } else {
      // printf("not enough\n");
      a = d;
    }
  }

  printf("%d\n", b);
}


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

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    vector<int>a;
    rep(i,n){
        if(i == 0){
            if(s[i] == '0') a.push_back(0);
            a.push_back(1);
        }
        else{
            if(s[i-1] == s[i]) a[a.size()-1]++;
            else a.push_back(1);
        }
        if(i == n-1 && s[i] == '0') a.push_back(0);
    }
    int m = a.size();
    int ans = 0;
    if(m <= 2*k+1) ans = n;
    int b = 0;
    rep(i,m){
        b += a[i];
        if(i-2*k-1 >= 0) b -= a[i-2*k-1];
        if(i%2 == 0) ans = max(ans,b);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int MOD = 1000000007;
int flag[8];
int graph[8][8],N,M,cnt;
void dfs(int next){
    for(int i = 0;i < N;i++){
        if(graph[next][i] && !flag[i]){
            flag[i] = 1;
            dfs(i);
            flag[i] = 0;
        }
    }
    for(int i = 0;i < N;i++){
        if(flag[i] == 0)return;
    }
    cnt++;//flagが全部１の場合
}
main(){
    cin >> N >> M;
    for(int i = 0;i < M;i++){
        int a,b;
        cin >> a >> b;
        graph[a-1][b-1] = 1;
        graph[b-1][a-1] = 1;
    }
    flag[0] = 1;
    dfs(0);
    cout << cnt << endl;
}

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

int N, M;
int S[2000], T[2000];
const long long mod = 1e9 + 7;
long long dp[2003][2003] = {};


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

  for(int i = 1; i <= N + 1; i++){
    for(int j = 1; j <= M + 1; j++){
      dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      if(i > 1 && j > 1 && S[i - 2] == T[j - 2]){
	dp[i][j] += 1 + dp[i - 1][j - 1];
      }
      dp[i][j] += mod;
      dp[i][j] %= mod;
    }
  }

  cout << (dp[N + 1][M + 1] + 1) % mod << endl;
}


Measured memory_bytes: 31616
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int MOD = 1e9+7;
using namespace std;

int N;
int dp[100010][4][4][4];

// A:0 G:1 C:2 T:3
ll WeLikeAGC(int n,int a,int b,int c){
    if(dp[n][a][b][c]>0) return dp[n][a][b][c];
    int res=0;
    if(n==N) res=1;
    else {
        rep(i,4){
            if(a==0 && b==1 && i==2) continue;
            if(a==0 && c==1 && i==2) continue;
            if(b==0 && c==1 && i==2) continue;
            if(b==1 && c==0 && i==2) continue; 
            if(b==0 && c==2 && i==1) continue;
            res += WeLikeAGC(n+1,b,c,i);
            res %= MOD;
        }
    }
    return dp[n][a][b][c] = res;
}

signed main() {
    cin >> N;
    cout << WeLikeAGC(0,3,3,3) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  int a,z;
  cin>>s;
  int i,j;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
      a=i+1;
      break;
    }
  }
  for(int j=i+1;j<=s.size();j++){
    if(s[j]=='Z'){
      z=j+1;
    }
  }
  cout<<z-a+1<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	int l=0,i=0,ls[64],max=0;
	char bun[64][64],mo[64];
	while(scanf("%s",bun[i])!=EOF){
		for(int j=0;j<strlen(bun[i]);j++){
			if(isupper(bun[i][j])){
				bun[i][j]=tolower(bun[i][j]);
			}
		}
		if(strlen(bun[i])>l){
			l=strlen(bun[i]);
			strcpy(mo,bun[i]);
		}
		i++;
	}
	for(int j=0;j<i-1;j++){
		for(int k=0;k<i-1;k++){
			if(k!=j){
				if(strcmp(bun[k],bun[j])==0){
					ls[j]++;
				}
			}
		}
	}
	for(int j=0;j<i;j++){
		if(ls[max]<=ls[j]){
			max=j;
		}
	}
	printf("%s %s\n",bun[max+1],mo);
	return 0;
}

Measured memory_bytes: 2576
#include<bits/stdc++.h>
#include<iomanip>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
typedef long long ll;

int main(){
  ll ans=0,time,n,work=0;
  bool ok=true;
  cin>>n;
  pair<ll,ll> ask[n];
  for(int i=0;i<n;i++){
    cin>>ask[i].second>>ask[i].first;
    ans+=ask[i].second;
  }
  sort(ask,ask+n);
  if(ans>ask[n-1].first)
  ok=false;
  for(int i=0;i<n;i++){
    work+=ask[i].second;
    if(work>ask[i].first){
      ok=false;
      break;
    }
  }
  if(ok){
    cout<<"Yes"<<endl;
  }
  else
  cout<<"No"<<endl;
}
/*int main(){
int n,m,ans=0,nn=0;
cin>>n>>m;
int x[n];
for(int i=m;i<m+n;i++){
  ans+=i;
  x[nn]=abs(i);
  nn++;
}
sort(x,x+n);
if(n+m>=0)
cout<<ans-x[0]<<endl;
else
cout<<ans+x[0]<<endl;
}*/


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<sstream>
#include<stdio.h>

using namespace std;

int main(){
	string s;
	getline(cin,s);
	stringstream ss(s);
	stack<int> st;
	while(true){
		string t;
		ss>>t;
		if(!ss)break;
		if(t=="+"){
			int a,b;
			a=st.top();
			st.pop();
			b=st.top();
			st.pop();
			st.push(a+b);
		}
		else if(t=="-"){
			int a,b;
			a=st.top();
			st.pop();
			b=st.top();
			st.pop();
			st.push(b-a);
		}
		else if(t=="*"){
			int a,b;
			a=st.top();
			st.pop();
			b=st.top();
			st.pop();
			st.push(a*b);
		}
		else{
			int num;
			sscanf(t.c_str(),"%d",&num);
			st.push(num);
		}
	}
	cout << st.top() << endl;
	return 0;		
}


Measured memory_bytes: 3276
#include <stdio.h>
int main()
{
	int n,i,a,b,c,d;
	scanf("%d",&n);
	a=n%10;
	b=(n%100)/10;
	c=n/100%10;
	d=n/1000;
	if(a==b&&b==c||b==c&&c==d||a==b&&b==c&&c==d)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = 10**9 + 7


def fact(N):
    res = {}
    tmp = N
    for i in range(2, int(N ** 0.5 + 1) + 1):
        cnt = 0
        while tmp % i == 0:
            cnt += 1
            tmp //= i
        if cnt > 0:
            res[i] = cnt
    if tmp != 1:
        res[tmp] = 1
    if res == {}:
        res[N] = 1
    return res


def modpow(n, p):
    res = 1
    while p > 0:
        if p & 1:
            res = res * n % MOD
        n = n * n % MOD
        p >>= 1
    return res


def modinv(n):
    b, u, v = MOD, 1, 0
    while b > 0:
        t = n // b
        n -= t * b
        n, b = b, n
        u -= t * v
        u, v = v, u
    u %= MOD
    if u < 0:
        u += MOD
    return u


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    L = defaultdict(int)
    for i in range(N):
        for k, v in fact(A[i]).items():
            L[k] = max(L[k], v)
    lcm = 1
    for k, v in L.items():
        lcm *= modpow(k, v)
        lcm %= MOD
    ans = 0
    for i in range(N):
        x = lcm * modinv(A[i]) % MOD
        ans += x
        ans %= MOD
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 11960
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
int Search(vector <long long int>v8,long long int n,long long int x){
    int z;
    for(z=0;z<n&&v8[z]<=x;z++){
        if(v8[z]==x)
           return z;}
    return -1;
}
int main()
{
    long long int n,k,x,i,count=500,h,g=0,l,ish=500,r,sum=0;
    string s;
    vector<string> v;
    vector<long long int> v2;
    vector<long long int> v3;
    vector<long long int> fv;
    cin>>n;
    for(i=0;i<n;i++){
       cin>>x;
      sum+=x;
      v2.push_back(x);
    }
  long long int avg=sum/n;
  float davg=(float)sum/(float)n;
  if((davg-avg)<0.5){avg=sum/n;}
  else{avg=(sum/n)+1;}
  for(k=0;k<n;k++){
     g+=(abs(avg-v2[k])*abs(avg-v2[k]));
  }
  cout<<g;
    return 0;
}


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

using namespace std;

long long f(long long a) {
     long long res[] = {a, 1, a + 1, 0};
     return res[a % 4];
}

long long getXor(long long a, long long b) {
     return f(b) ^ f(a - 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long a, b;
    cin >> a >> b;
    if (a == 0) {
        cout << (0 ^ getXor(a + 1, b)) << '\n';
    } else {
        cout << getXor(a, b) << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

K = int(readline())


def gcd(a,b):
    if a < b:
        a,b = b,a
    while a % b != 0:
        r = a % b
        a, b = b, r

    return b


ans = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(a, gcd(b, c))


print(ans)

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

// Global Variables
long long N, Y;

void input(void){
    cin >> N >> Y;
}

void solve(void){
    long long x = -1, y = -1, z = -1;
    for (long long  i = 0; i <= N; i++){
        for (long long j = 0; j <= N - i; j++) {
            long long k = N - (i + j);
            long long otoshidama = i * 10000 + j * 5000 + k * 1000;
            if(otoshidama == Y) {
                x = i; y = j; z = k;
            }
            else { /* Do nothing */  }
        }
    }

    cout << x << " " << y << " " << z << endl;
}

int main(void) {
    input();
    solve();

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int s;
    int h,m,sec;
    scanf("%d",&s);
    h   = s / 3600;
    m   = (s - (h*3600))/60;
    sec = s - h*3600 - m*60;
    printf("%d:%d:%d\n",h,m,sec);
    
    
}


Measured memory_bytes: 2096
object Main extends App {

  import scala.io.StdIn._

  val n = readLine.trim.toInt
  val words = Array.tabulate(n){_ ⇒ readLine.trim}
  println(
    if (words.distinct.length == words.length && words.foldLeft(Some(words(0).charAt(0)) : Option[Char]){
      case (Some(c), str) if c == str.charAt(0) ⇒ Some(str.charAt(str.length - 1))
      case _ ⇒ None
    }.isDefined) "Yes"
    else "No"
  )
}


Measured memory_bytes: 25424
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define N 200005
char s[N]; 
int a[10];
bool ck=0;
int main() 
{
	int n;
	cin>>n;
	for(int i=1;i<=4;i++) scanf("%d",&a[i]);
	scanf("%s",s+1);
	int z=max(a[3],a[4]);
	int len=strlen(s+1);
	for(int i=a[1]+1;i<=a[3];i++)
	{
		if(s[i]=='#'&&s[i]==s[i-1]) 
		{
			printf("No\n");
			return 0;
		}
	}
	for(int i=a[2]+1;i<=a[4];i++)
	{
		if(s[i]=='#'&&s[i]==s[i-1]) 
		{
			printf("No\n");
			return 0;
		}
	}
	if(a[4]<a[3])
	{
	    for(int i=a[2];i<=a[4];i++)
		{
			
		    if(s[i]=='.'&&s[i-1]=='.'&&s[i+1]=='.')
			{
					printf("Yes\n");
			return 0;
				}	
		}	
			printf("No\n");
			return 0;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 3856
import collections as c
n=int(input())
a=list(map(int,input().split()))
d=c.Counter(a)
k=d.keys()
x=0
for i in k:
  if d[i]>i:
    x+=d[i]-i
  elif d[i]<i:
    x+=d[i]
print(x)

Measured memory_bytes: 18672
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using ull = unsigned long long;

int gcd(int x, int y);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n, k;
    cin >> n >> k;
    int ans = k;
    ans *= pow(k - 1, n - 1);
    cout << ans << endl;
    return 0;
}
/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <math.h>
#include <limits.h>
using namespace std;
int main()
{
    long long a, b, x;
    while(cin>>a>>b>>x){
        if(a%x==0&&b%x==0){
            cout<<b/x-a/x+1<<endl;
        }
        else if(a%x==0){
            cout<<b/x-a/x+1<<endl;
        }
        else if(b%x==0){
            cout<<b/x-a/x<<endl;
        }
        else {
            cout<<b/x-a/x<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

struct ff{
    int l,r,idx;
    ff(int a,int b,int c){
        l=a; r=b; idx=c;
    }
};
vector<ff> v;
int K;
bool cmp(ff a,ff b){
    int b1=a.l/K; int b2=b.l/K;
    if(b1==b2) return a.r<b.r;
    return b1<b2;
}
int a[500005];

int dist=0;
int cnt[500005];
void add(int x){
    cnt[x]++;
    if(cnt[x]==1) dist++;
}
void del(int x){
    cnt[x]--;
    if(cnt[x]==0) dist--;
}

int main()
{
    int n,q,x,y;
    scanf("%d %d",&n,&q);
    K=sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=q;i++){
        scanf("%d %d",&x,&y);
        v.pb(ff(x,y,i));
    }

    sort(v.begin(),v.end(),cmp);

    int l=1,r=0;
    int ans[q+1]={0};
    for(auto it:v){
        while(r<it.r){
            r++;
            add(a[r]);
        }
        while(r>it.r){
            del(a[r]);
            r--;
        }
        while(l<it.l){
            del(a[l]);
            l++;
        }
        while(l>it.l){
            l--;
            add(a[l]);
        }
        ans[it.idx]=dist;
    }

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


    return 0;
}




Measured memory_bytes: 15540
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;
 
void testCase() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    // store prefix
    ll cnt[n+2][3];
    cnt[n][0] = cnt[n][1] = cnt[n][2] = 0;
    for (int i=n-1; i>=0; i--) {
        cnt[i][0] = cnt[i+1][0];
        cnt[i][1] = cnt[i+1][1];
        cnt[i][2] = cnt[i+1][2];
        if (s[i] == 'B')
            cnt[i][2]++;
        else if (s[i] == 'R')
            cnt[i][0]++;
        else
            cnt[i][1]++;
    }
    //find ans
    //ll ans = 0;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            if (s[i] == s[j])
                continue;
            map <char, int> match;
            match[s[i]]=1;
            match[s[j]]=1;
            int k = 2*j-i;
            if (k >= n) {
                k = -1;
            }
            if (match['R']==0) {
                ans += (cnt[j+1][0]);
                if (k != -1) {
                    if (s[k]=='R')
                        ans--;
                }
            }
            else if (match['G']==0) {
                ans += (cnt[j+1][1]);
                if (k != -1) {
                    if (s[k]=='G')
                        ans--;
                }
            }
            else {
                ans += (cnt[j+1][2]);
                if (k != -1) {
                    if (s[k]=='B')
                        ans--;
                }
            }
        }
    }
    cout << ans << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;




long long power(long long x, long long y, long long p)
{
long long res = 1;


x = x % p;


while (y > 0)
{
if (y & 1)
res = (res*x) % p;


y = y>>1;
x = (x*x) % p;
}
return res;
}

long long modInverse(long long n, long long p)
{
return power(n, p-2, p);
}



void solve()
{
    ll n,a,b;
    cin>>n>>a>>b;

    ll res = power(2ll,n,mod);
    res--;
    res+=mod;
    res%=mod;

    ll no1=1;
    ll i,j;
    for(i=n;i>(n-a);i--)
    {
        no1*=i;
        no1%=mod;
    }   
    for(i=1;i<=a;i++)
    {
        no1*=modInverse(i,mod);
        no1%=mod;
    }
    res-=no1;
    res+=mod;
    res%=mod;
    no1=1;
     for(i=n;i>(n-b);i--)
    {
        no1*=i;
        no1%=mod;
    }   
    for(i=1;i<=b;i++)
    {
        no1*=modInverse(i,mod);
        no1%=mod;
    }
    res-=no1;
    res+=mod;
    res%=mod;
    cout<<res<<"\n";


}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


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


return 0;
}

Measured memory_bytes: 3608
import time
import random
import math
def sigmoid(x):
  if x<-100:
    return 0
  return 1/(1+math.exp(-x))
def score(a,c,s,d):
  l=[-1 for i in range(26)]
  r=0
  for i in range(d):
    l[a[i]]=i
    r+=s[i][a[i]]
    for j in range(26):
      r-=c[j]*(i-l[j])
  return r
  
st=time.time()
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
  s.append(list(map(int,input().split())))

ans=[]
l=[-1 for i in range(26)]
ld=[]
for i in range(d):
  ms=-10**9
  mt=None
  for j in range(26):
    js=c[j]*(i-l[j])+s[i][j]
    if ms<js:
      ms=js
      mt=j
  l[mt]=i
  ans.append(mt)
  ld.append([l[mt],d])
  if l[mt]>=0:
    ld[l[mt]][1]=i

os=score(ans,c,s,d)
nt=st
rate=50
while nt-st<1.50:
  nt=time.time()
  na=[ans[i] for i in range(d)]
  na[random.randint(1,d-1)]=random.randint(0,25)
  ns=score(na,c,s,d)
  if sigmoid((ns-os)/rate/((2-nt+st)**4))>random.random():
    os=ns
    ans=na
 
  


for i in ans:
  print(i+1)


Measured memory_bytes: 85244
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  cin>>s;
  int k;
  cin>>k;
  int n = s.size();
  rep(i,n){
    if(k==0)break;
    if(s[i]=='a'&&i!=n-1)continue;
    int t=('z'-s[i])+1;
    if(i<n-1&&k>=t){
      k-=t;
      s[i]='a';
    }else if(i==n-1){
      k=k%26;
      if(k>=t)s[i]='a',k-=t;
      s[i]=(char)(s[i]+k);
      k=0;
    }
  }
  cout<<s<<endl;
}


Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class AMultiplication1 {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int A, B;
        cin >> A >> B;
        vector<int> v(A, 1);
        cout << A * B;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    AMultiplication1 solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		final Scanner sc= new Scanner(System.in);
		int sum=0;
		for(int i=0;i<5;i++){
			int num=sc.nextInt();
			if(num<40) sum+=40;
			else sum+=num;
		}
		
		System.out.println(sum/5);
	}
}

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

int main(){
  vector<int> As(3);
  cin>>As.at(0) >> As.at(1) >> As.at(2);

  sort(As.begin(), As.end());
  
  int ans = 0;
  ans = abs(As.at(1) - As.at(0)) + abs(As.at(2) - As.at(1));
   
  cout << ans << endl;

  return 0;
}

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

const int MX = 100005;

int main(){
  int n;
  cin >> n;
  vector<long long> cnt(MX);
  rep(i, n){
    int a;
    cin >> a;
    cnt.at(a)++;
  }
  long long tot = 0;
  rep(i, MX){
    tot += i*cnt.at(i);
  }
  int q;
  cin >> q;
  rep(i, q){
    int b, c;
    cin >> b >> c;
    tot -= b*cnt.at(b);
    tot -= c*cnt.at(c);
    cnt.at(c) += cnt.at(b);
    cnt.at(b) = 0;
    tot += b*cnt.at(b);
    tot += c*cnt.at(c);
    cout << tot << endl;
  }
  return 0;
}
  


Measured memory_bytes: 4032
from itertools import accumulate
from operator import add
N, K = map(int, input().split())
S = input()

Nums = []

tmp = "1"
cnt = 0
for s in S:
  if s == tmp:
    cnt += 1
  else:
    Nums.append(cnt)
    tmp = s
    cnt = 1
else:
  Nums.append(cnt)
  if tmp == "0":
    Nums.append(0)

T = list(accumulate(Nums))
T.insert(0,0)

ans = 0
len_t = len(T)
for i in range(0, len_t, 2):
  left = i
  right = min(len_t - 1, (2 * K + 1) + i)
  ans = max(ans, T[right] - T[left])

print(ans)

Measured memory_bytes: 8180
n=int(input())
d=[]
for _ in range(n):
  a,b=map(int,input().split())
  d.append([a,b])
l=sorted(d,key=lambda x: x[1])
z='Yes'
s=0
for i in range(n):
  s+=l[i][0]
  if s>l[i][1]:
    z='No'
    break
print(z)

Measured memory_bytes: 39692
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,x,t;
  cin>>n>>x>>t;
  if((n/x)*x-n==0){
  cout<<(n/x)*t<<'\n';}
  else
  cout<<((n/x)+1)*t<<'\n';
  return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
struct UnionFind
{
  vector< int > data;
  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }
  int find(int x)
  {
    if(data[x] < 0) return(x);
    return(data[x] = find(data[x]));
  }
  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return(false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return(-data[x] == data.size());
  }
};
  
struct edge
{
  int u, v, cost;
  bool operator<(const edge& e) const
  {
    return(cost < e.cost);
  }
};

int main()
{
  int N, M;
  while(scanf("%d %d", &N, &M), N) {
    vector< edge > edges;
    for(int i = 0; i < M; i++) {
      int u, v, w;
      scanf("%d %d %d", &u, &v, &w);
      --u, --v;
      edges.push_back((edge){u, v, w});
    }
    sort(edges.begin(), edges.end());
    int ret = INF;
    for(int i = 0; i <= M - N + 1; i++) {
      UnionFind uf(N);
      for(int j = i; j < M; j++) {
        if(uf.unite(edges[j].u, edges[j].v)) {
          ret = min(ret, edges[j].cost - edges[i].cost);
          break;
        }
      }
    }
    if(ret == INF) printf("-1\n");
    else printf("%d\n", ret);
  }
}

Measured memory_bytes: 1344
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long i,j,k,l,r,d;
    cin>>l>>r>>d;
    j=0;
    for (i=l;i<=r;i++)
    {
    	if (i%d==0)
    	{
    		j++;
		}
	}
	cout<<j<<endl;
}

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

int main()
{
    string s;
    cin>>s;
    int flag=0,i;
    
    for(i=0;i<s.length()/2;i++)
    {
        if(s[i]!=s[s.length()-1-i]) flag++;
    }

    for(i=0;i<s.length()/4;i++)
    {
        if(s[i]!=s[s.length()/2-1-i]) flag++;
    }

    for(i=s.length()-1;i>s.length()/2+1;i--)
    {
        if(s[i]!=s[s.length()/2+i-s.length()]) flag++;
    }

    if(flag==0) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
while True:
    mid, end, re = map(int, input().split())
    if mid == -1 and end == -1 and re == -1:
        break
    elif mid == -1 or end == -1:
        print("F")
    elif mid + end >= 80:
        print("A")
    elif 80 > mid + end >= 65:
        print("B")
    elif 65 > mid + end >= 50:
        print("C")
    elif 50 > mid + end >= 30:
        if re >= 50:
            print("C")
        else:
            print("D")
    elif 30 > mid + end:
        print("F")



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

//MACROS
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

int orcol[1<<20], pos[1<<20], col[1<<20], n, k;
vector <int> g[1<<20];

int dfs1(int v, int p) {
    for (auto u : g[v])
        if (u != p) col[v] = max(col[v],dfs1(u,v)-1);
    return col[v];
}

void dfs2(int v, int p) {
    for (auto u : g[v])
        if (u != p) {
            col[u] = max(col[u],col[v]-1);
            dfs2(u,v);
        }
}

int main() {
	cin >> n;
	rep(i,0,n) col[i] = -(1<<20);
	rep(i,0,n-1) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
	}
	cin >> k;
	rep(i,0,k) {
        int p, cl;
        cin >> p >> cl;
        p--;
        pos[i] = p;
        orcol[i] = cl;
        col[p] = cl;
	}

	dfs1(0,-1);
	dfs2(0,-1);
	rep(i,0,k)
        if (col[pos[i]] != orcol[i]) {
            cout << "No\n";
            return 0;
        }
	rep(v,0,n)
	    for (auto u : g[v])
            if (abs(col[v] - col[u]) != 1) {
                cout << "No\n";
                return 0;
            }
    cout << "Yes\n";
	rep(i,0,n) cout << col[i] << "\n";
}


Measured memory_bytes: 39424
from itertools import product
from collections import defaultdict, Counter
import sys
input = sys.stdin.readline
h,w,n = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
pls = defaultdict(int)
for x,y in a:
  for arx,ary in product(list(range(x-1,x+2)),list(range(y-1,y+2))):
    if 2<=arx<=h-1 and 2<=ary<=w-1:
      pls[(arx,ary)] += 1
c = Counter(pls.values())
print((h-2)*(w-2)-sum(c.values()))
for i in range(1,10):
  print(c[i])

Measured memory_bytes: 162516
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vii vector<int,int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
const int mod=1e9+7;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
double pi=acos(-1);
int main(){
    fast;
    ll n;
    cin>>n;
    ll step=0;
    ll des=100;
    while(des<n){
        des+=(des/100);
        step++;
    }
    cout<<step;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> l(n);
  for(int i=0;i<n;i++) cin >> l.at(i);
  sort(l.begin(),l.end());
  int ans=0;
  for(int i=0;i<k;i++) ans+=l.at(n-i-1);
  cout << ans << endl;
}

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

constexpr long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define rrep(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) rep(i,0,n)
#define RREP(i,n) rrep(i,n,0)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n;
vector<pair<int,int>> G[100010];
int color[100010];
bool used[100010];

void f(int k) {
  if (used[k]) return;
  used[k] = 1;
  REP(i,G[k].size()) {
    int to = G[k][i].fi;
    int dist = G[k][i].se;
    if (dist & 1) {
      color[to] = (color[k]? 0 : 1);
    } else {
      color[to] = color[k];
    }
    f(to);
  }
}

int main(){
  cin >> n;
  REP(i,n-1) {
    int a,b,c;
    cin >> a >> b >> c;
    G[a].pb({b,c});
    G[b].pb({a,c});
  }

  f(1);
  REP(i,n) {
    cout << color[i+1] << endl;
  }
  return 0;
}


Measured memory_bytes: 8448