akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, C, D, S):

    C = (C[0]-1, C[1]-1)
    D = (D[0]-1, D[1]-1)
    q = deque()
    q.append((0, C))
    memo = {}
    while q:
        c, (x, y) = q.popleft()
        if (x, y) in memo:
            continue
        memo[(x, y)] = c
        for nx, ny in [(x, y-1), (x, y+1), (x-1, y), (x+1, y)]:
            if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.':
                if (nx, ny) not in memo:
                    q.appendleft((c, (nx, ny)))

        for nx in range(x-2, x+3):
            for ny in range(y-2, y+3):
                if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.':
                    if (nx, ny) not in memo:
                        q.append((c+1, (nx, ny)))


    return -1 if tuple(D) not in memo else memo[D]


def main():
    H, W = read_int_n()
    C = read_int_n()
    D = read_int_n()
    S = [read_str() for _ in range(H)]
    print(slv(H, W, C, D, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 204676
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; string S; cin >> N >> S;
    bool dp[N + 1][4][1000] = {};
    REP(i, 0, N + 1) dp[i][0][0] = true;
    REP(i, 0, N) {
        int cur = S[i] - '0';
        REP(j, 0, 4) {
            REP(k, 0, 1000) {
                dp[i + 1][j][k] = (dp[i + 1][j][k] | dp[i][j][k]);
                int next = 10 * k + cur;
                if (next < 1000 && j < 3) {
                    dp[i + 1][j + 1][next] = (dp[i + 1][j + 1][next] | dp[i][j][k]);
                }
            }
        }
    }
    int ans = 0;
    REP(i, 0, 1000) {
        if (dp[N][3][i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 117504
#include <iostream>

using namespace std;

typedef unsigned int uint32;

uint32 gcd(uint32 x, uint32 y) {
  uint32 r = 0;
  uint32 a = 0;
  if (x >= y) {
    r = x % y;
    a = y;
  } else {
    r = y % x;
    a = x;
  }

  if (r == 0) {
    return a;
  }
  return gcd(a, r);
}

int main() {
  uint32 x, y;
  cin >> x >> y;
  cout << gcd(x, y) << endl;
  return 0;
}

Measured memory_bytes: 1152
dp = [[0]*6000 for n in range(55)]

# dp[i][0]: -2500をつくれる

dp[0][2500]=1

N, A = [int(n) for n in input().split()]
X = [int(n) for n in input().split()]

for n, x in enumerate(X):
  t = x - A
  for i in range(6000):
    dp[n+1][i] = dp[n][i]
  for i in range(6000):
    if i+t < 6000 and i+t >= 0:
      dp[n+1][i+t] += dp[n][i]

print(dp[N][2500]-1)

Measured memory_bytes: 6132
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define rep(I, N) for (int I = 1; I <= (N); ++I)
#define repp(I, N) for (int I = 0; I < (N); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORR(I, A, B) for (int I = (A); I >= (B); I--)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
const int N = 2e5 + 5;
const double eps = 1e-7;
const int mod = 1e9 + 7;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
LL gcd(LL a,LL b){return b>0?gcd(b,a%b):a;}
LL ksm(LL a,LL b){LL ans = 1;while(b){if(b&1) ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans % mod;}
LL a[N];
int main() {
    int n;
    cin >> n;
    rep(i,n) cin >> a[i];
    a[n + 1] = 2e9;
    LL maxn = 0;
    rep(i,n)
    {
        maxn = max(maxn, a[i]);
        if(maxn - a[i] > 1)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;

void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}

const int N=1e6+3,M=1e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;

int n,a,b,c;

int& get(char cc){
    if (cc == 'A')
        return a;
    else if (cc == 'B')
        return b;
    else
        return c;
}

bool in(char c,string& s){
    return s[0] == c || s[1] == c;
}

int main(){
    //IO();
    cin >> n >> a >> b >> c;
    int zeros = (a == 0) + (b == 0) + (c == 0);
    vector<char> v;
    vector<string> ss(n + 1);
    for(int i = 0 ; i < n ; i++)
        cin >> ss[i];
    for(int i = 0 ; i < n ; i++){
        string& s = ss[i];
        int& x = get(s[0]);
        int& y = get(s[1]);
        if (x == 1 && y == 1){
            if (in(s[0],ss[i+1])){
                x++;
                y--;
                v.push_back(s[0]);
            }
            else{
                y++;
                x--;
                v.push_back(s[1]);
            }
        }
        else if (x < y){
            x++;
            y--;
            v.push_back(s[0]);
        }
        else{
            x--;
            y++;
            v.push_back(s[1]);
        }
        
        if (a < 0 || b < 0 || c < 0){
            assert(zeros >= 2);
            return !printf("No\n");
        }
    }
    printf("Yes\n");
    for(auto c : v)
        printf("%c\n",c);
}


Measured memory_bytes: 6736
#include <cmath>
#include <cstring>
#include <iostream>

using namespace std;
typedef long long ll;

int main() {
  ll a;
  string b;
  cin >> a >> b;
  string c;
  for (char ch : b)
    if (ch != '.')
      c.push_back(ch);
  cout << a * stoll(c) / 100;
}

Measured memory_bytes: 3192
S = gets.chomp
Q = gets
Qs = readlines.map{|l| l.split}

face, l, r = true, '', ''
Qs.each do |t, f, c|
  if t == '1'
    face = !face
  else
    (face ^ (f == '1') ? r : l) << c
  end
end
ans = l.reverse + S + r
puts face ? ans : ans.reverse

Measured memory_bytes: 65148
import java.util.*;

public class Main {
    static int MAX = 500000;
    static int MOD = 1000000007;
    static long[] fac;
    static long[] finv;
    static long[] inv;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        COMinit();
        
        long tmp = modpow(2, n) - 1;
        long tmp2 = 1;
        for (int i = 1; i <= a; i++) {
            tmp2 = (tmp2 * ((n + 1) - i)) % MOD;
            tmp2 = (tmp2 * inv[i]) % MOD;
        }
        long tmp3 = 1;
        for (int i = 1; i <= b; i++) {
            tmp3 = (tmp3 * ((n + 1) - i)) % MOD;
            tmp3 = (tmp3 * inv[i]) % MOD;
        }
        
        
        long ans = tmp -tmp2 -tmp3;
        while (ans < 0) {
            ans += MOD;
        }
        System.out.println(ans);
        
    }
    
    // テーブルを作る前処理
    public static void COMinit() {        
        fac = new long[MAX];
        finv = new long[MAX];
        inv = new long[MAX];
        
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    // 二項係数計算
    public static long nCkMOD(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
    
    public static long modpow(long a, long n) {
        long res = 1;
        while (n > 0) {
            long tmp = n & 1;
            if (tmp > 0) res = res * a % MOD;
            a = a * a % MOD;
            n >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 34260
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
// 10min
int main(void){
  int n, k;
  int l[51];
  int tmp = 0;
  int sum = 0;

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

  for(int i = 1; i <= n; i++){
    scanf("%d", &l[i]);
  }

  for (int i=1; i<= n; i++) {
    for (int j = i; j <= n; j++) {
      if (l[i] < l[j]) {
        tmp =  l[i];
        l[i] = l[j];
        l[j] = tmp;
      }
    }
  }

  for(int i = 1; i <= k; i++){
    sum += l[i];
    //    printf("sum = %d\n", sum);
  }
      
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	int n,ans=0;
	cin>>n;
	vector<long long int>a(100000000);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
		ans+=a[i];
	}
	cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 781568
output = []
for looop in range(10000):
    tmp = input()
    if tmp == '-':
        break
    else:
        num = int(input())
        for x in range(num):
            change = int(input())
            tmp = tmp[change:len(tmp)] + tmp[0:change]
        output.append(tmp)
for x in range(len(output)):
    print(output[x])


Measured memory_bytes: 7660
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff first
#define INF 1000000001
#define inf1 1000000000000000001
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 300000+5;
const lli mod= 1000000007;
vector<lli> catlan(int n) {vector<lli> dp(n + 1, 0);dp[0] = 1;dp[1] = 1;for (int i = 2; i <= n; i ++) {for (int j = 0; j < i; ++ j) {dp[i] += dp[j] * dp[i - j - 1];}}return dp;}
lli digit(lli n){int res=(int)log10(n)+1;return res;}
lli lcm(lli a,lli b){lli ans=(a*b)/(__gcd(a,b));return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n){int c=0;if(n==0)return 0;while(n){if((n&1)==1){cout<<c<<" ";}c++;n=n>>1;}return c;}

/// RULESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS////
/// READ THEM ALOUD......................................................................................................
/// 1. If the constraints are low think brute force :3................
/// 2. Always cheack with customed testcases .. i.e = Base cases 0 or 1 or similar cases
/// 3. Always use lli :)
/// 4. Read the question again if the solution isnt gatting ac xD
/// 5. Work ur way through solutions :)
/// 6. :D


void solve()
{
    int  n;cin>>n;
    bool works=false;
    int c=0;
    while(n--)
    {
        int a,b;cin>>a>>b;
        if(a!=b)c=0;
        else c++;
        if(c==3)works=true;
    }
    if(works)cout<<"Yes\n";
    else cout<<"No\n";

}
int main()
{
    solve();
}


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

const int mod = 998244353;

struct mint {
    ll x;

    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 {
      mint res(*this);
      return res += a;
    }

    mint operator-(const mint a) const {
      mint res(*this);
      return res -= a;
    }

    mint operator*(const mint a) const {
      mint res(*this);
      return res *= a;
    }

    mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t >> 1);
      a *= a;
      if (t & 1) a *= *this;
      return a;
    }

    mint inv() const {
      return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
      return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
      mint res(*this);
      return res /= a;
    }
};

mint dp[3030][3030];

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;

  rep(i,3030) rep(j,3030) dp[i][j] = 0;
  dp[a][b] = 1;

  for (int h = a; h <= c; h++) {
    for (int w = b; w <= d; w++) {
      if(h > a) dp[h][w] += dp[h - 1][w] * w;
      if(w > b) dp[h][w] += dp[h][w - 1] * h;
      if(h > a && w > b) dp[h][w] -= dp[h - 1][w - 1] * (h - 1) * (w - 1);
    }
  }

  cout << dp[c][d].x << '\n';
  return 0;
}


Measured memory_bytes: 75364
import math
a,b,h,m=map(int,input().split())
theta_h=30*h+1/2*m
theta_m=6*m
theta=abs(theta_h-theta_m)
c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(theta)))
print(c)

Measured memory_bytes: 9572
#include <stdio.h>
#include <stdbool.h>

int main(){
    int i, j, n;
    char mark;
    char marks[4]={'S', 'H', 'C', 'D'};
    int num;
    bool cards[4][13]={false};

    scanf("%d ", &n);
    for(i=0;i<n;i++){
        scanf("%c %d ", &mark, &num);
        for(j=0;j<4;j++){
            if(mark==marks[j]){
                cards[j][num-1]=true;
                break;
            }
        }
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(!cards[i][j]){
                printf("%c %d\n", marks[i], j+1);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <stdio.h>
#include <cstdlib>

using namespace std;
#define LEN 1000000

struct P{
  char name[100];
  int time;
};

P Q[LEN];
int head = 0;
int tail = 0;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int main(int argc, const char * argv[]) {
  int n, q;
  int elaps = 0;

  cin >> n >> q;
  
  for(int i=0; i<n; i++){
    cin >> Q[i].name >> Q[i].time;
    enqueue(Q[i]);
  }
  tail = n;
  while(head != tail){
    P p = dequeue();
    int mtime = min(p.time, q);
    elaps += mtime;
    p.time -= mtime;
    if(p.time > 0){
      enqueue(p);
    }else{
      cout << p.name << " " << elaps << endl;
    }
  }
  
  return 0;
}



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

#define X first
#define Y second
#define ll long long
#define MP make_pair
#define PB push_back

using namespace std;

const int MAXN=1e5;

ll n;
double niz[3005],dp[3005][3005];
double rj;

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

	cin>>n;
	for(int i=0; i<n; i++){
		cin>>niz[i];
	}
	dp[0][1]=niz[0];
	dp[0][0]=1-niz[0];
	for(int i=1; i<n; i++){
		dp[i][0]=dp[i-1][0]*(1-niz[i]);
		for(int j=1; j<=3000; j++){
			dp[i][j]=dp[i-1][j]*(1-niz[i])+dp[i-1][j-1]*niz[i];
		}
	}
	for(int i=(n+1)/2; i<=n; i++){
		rj+=dp[n-1][i];
	}
	printf("%.15lf\n", rj);
	
	return 0;
}

Measured memory_bytes: 74120
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    array<int, 3> a, b;
    for (auto &&i : a) scanf("%d", &i);
    for (auto &&j : b) scanf("%d", &j);
    if(a > b) swap(a, b);
    cout << b[0]-a[0]+(a[1] < b[1] || (a[1] == b[1] && a[2] < b[2])) << "\n";
    return 0;
}


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

typedef long long ll;

const int N = 5e3 + 7;
const int INF = 1e18 + 7;
pair<ll, ll> p[N];
ll dp[N][N];

#define F first
#define S second

bool cmp(pair<int, int> a, pair<int, int> b)
{
	return a.F + a.S < b.F + b.S;
}

int main()
{
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	for (int i=0; i<n; i++)
		cin >> p[i].F >> p[i].S;
	sort(p, p+n, cmp);
	memset(dp, 63, sizeof dp);
	dp[0][0] = 0;
	for (int i=0; i<n; i++)
		for (int j=0; j<=i; j++)
		{
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			if (dp[i][j] <= p[i].F)
				dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + p[i].S);
		}
	for (int i=n; i>=0; i--)
		if (dp[n][i] <= INF) 
		{
			cout << i << "\n";
			return 0;
		}


	return 0;
}


Measured memory_bytes: 196352
import java.util.*;

class Main {

    static void solve (int n) {
        int [][] square = new int [n][n];
        int x = (n-1)/2;
        int y = (n+1)/2;

        for(int i = 1; i <= n*n; i++) {
            square[y][x] = i;
            y += 1;
            if (y >= n) y = 0;
            x += 1;
            if (x >= n) x = 0;
            if (square[y][x] != 0) {
                x -= 1;
                y += 1;
                if (x == -1)    x = n-1;
                if (y == n)     y = 0;
            }
        }

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                System.out.printf("%4d", square[i][j]);
            }
            System.out.println("");
        }
        
    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        while(true) {
            int n = sc.nextInt();
            if (n == 0) break;

            solve(n);
        }
    }
}

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

long long N,M;
int color[100010] = {0};
bool judge = true;
vector<vector<int>> v(100010);

bool dfs(long long n,long long c){
	color[n] = c;
	for(int i=0;i<v[n].size();i++){
		if(color[v[n][i]] == c) return false;
		else if(color[v[n][i]] == 0 && !dfs(v[n][i],-c)) return false;
	}
	return true;
}

int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	//for(int i=1;i<=N;i++) color[i] = 0;
	if(dfs(1,1)){
		long long b = 0,m = 0;
		for(int i=1;i<=N;i++){
			if(color[i] == 1) b++;
			else if(color[i] == -1) m++;
		}
		cout << b*m - M << endl;
	}else cout << N*(N-1)/2-M << endl;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int main(){
  int h,w;cin>>h>>w;
  int white = h * w;
  bool m[50][50];
  rep(i,h)rep(j,w){
    char c;cin>>c;
    white -= (c == '#');
    m[j][i] = (c == '.');
  }
  int memo[52][52];rep(i,52)rep(j,52)memo[i][j] = -1;
  queue<pair<int,int>> q;q.push(make_pair(1,1));memo[1][1] = 0;
  while(!q.empty()){
    pair<int,int> a = q.front();q.pop();
    if(a.first == w && a.second == h)break;
    if(a.first == 0 || a.first == w+1 || a.second == 0 || a.second == h+1)continue;
    rep(i,4){
      int f = a.first + fd[i].first, s = a.second + fd[i].second;
      if(memo[f][s] >= 0 || (!m[f-1][s-1]))continue;
      q.push(make_pair(f,s));
      memo[f][s] = memo[a.first][a.second] + 1;
    }
  }
  if(memo[w][h] == -1)cout << -1 << endl;
  else cout << white - memo[w][h] -1 << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll M;
ll d, c;
ll sd = 0, sc = 0;

int main() {
    fastio();
    cin >> M;
    REP(i, M) {
        cin >> d >> c;
        sd += d * c; sc += c;
    }
    cout << sc - 1 + (sd-1) / 9 << "\n";
	return 0;
}

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

int main(){
    int n;
    string s;
    cin>>n>>s;
    if(n<=2){
        cout<<0<<endl;
        return 0;
    }
    long long int c=0;
    long long int r=0,g=0,b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            r++;
        }
        else if(s[i]=='G'){
            g++;
        }
        else{
            b++;
        }
    }
    int j,k;
    long long int x = 0;
    for(int i=0;i<n-2;i++){
        k = i + 2;
        while(k<n){
            j = (i+k)/2;
            if(s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i]){
                x++;
            }
            k = k + 2;
        }
    }
    c = r*g*b - x;
    cout<<c<<endl;
}

Measured memory_bytes: 3588
def gcd(a, b):
    if b == 0:
        return a
    elif a == 0:
        return b
    else:
        return gcd(b, a % b)


def solve(n, a):
    l, r = [], []
    l = [0 for i in range(n + 1)]
    r = [0 for i in range(n + 1)]
    r[n] = 0

    for i in range(0, n):
        if i == 0:
            l[0] = 0
        else:
            l[i] = gcd(l[i - 1], a[i - 1])

    for i in range(n, 0, -1):

        if i == n:
            r[i] = 0
        else:
            r[i] = gcd(r[i+1], a[i])
    m = 0
    for i in range(n):
        # print('m', m)
        m = max(m, gcd(l[i], r[i + 1]))
    return m


def input_from_console():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    vector<vector<int>> road(n);
    int a, b;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        a--; b--;
        road[a].push_back(b);
        road[b].push_back(a);
    }

    int res = 0;
    for (int i = 0; i < n; ++i) {
        bool flag = true;
        for (int j = 0; j < road[i].size(); ++j) {
            if (h[i] <= h[road[i][j]]){
                flag = false;
                break;
            }
        }
        if (flag) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 8748
#include <iostream>
#include <stdio.h>
#include <array>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <algorithm>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <string.h>
#include <stack>

using namespace std;

typedef double db;
typedef long long ll;
typedef pair<int, int> PII;

int a, b;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
#define MAX(a,b) a>b? a:b
#define MIN(a,b) a>b? b:a


const int MOD = 1e9 + 7;
const ll INF=1e10;
const db PI = acos(-1.0);
const db EPS = 1e-10;


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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


ll MAXX(vector<ll> a,ll k) {
	ll max = 0;
	REP(i, k) {
		if (a[i] >= max) max = a[i];
	}
	return max;
}

ll MINN(vector<ll> a,ll k) {
	ll min = INF;
	REP(i, k) {
		if (a[i] <= min)min = a[i];
	}
	return min;
}

ll SUM(vector<ll> a, ll k) {
	ll sum = 0;
	REP(i, k) {
		sum += a[i];
	}
	return sum;
}

db AVE(vector<ll> a, ll k) {
	db ave = SUM(a,k)/(db)k;
	return ave;
}

db VAR(vector<ll> a, ll k) {
	db ave,ave2,var;
	db sum = 0;
	REP(i, k) {
		sum += a[i] * a[i];
	}
	ave2 =sum/ k;
	ave = AVE(a,k);
	ave = pow(ave,2);
	var = ave2 - ave;
	return var;
}


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


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


void prime(int k) {
	int cnt = 0;
	for (int i = 2;i<k;i++) {
		if (k % i == 0) { cnt++; }
	}
	if (cnt == 0) cout << k << "は素数です。" << endl;
	else cout << k << "は素数ではありません。" << endl;
}


int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (n * a >= b)cout << b;
	else cout << n * a;

	
	return 0;
}

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


int main()
{
    int l,r,d,cnt=0;
    scanf("%d%d%d",&l,&r,&d);
    for(int i=1;i<=100;++i) if(i*d>=l&&i*d<=r) cnt++;
    cout<<cnt;
}

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

const int MAX_N = 100;

int main() {
	int n,x;
	int score[MAX_N];

	while(cin >> n) {
		if(n == 0) return 0;

		int max = -1,max_i,min = 1001,min_i;
		for(int i = 0;i < n;i++) {
			cin >> x;
			score[i] = x;

			if(max < x) {
				max = x;
				max_i = i;
			}

			if(min > x) {
				min = x;
				min_i = i;
			}
		}

		//??¨??????????????°
		if(max_i == min_i) {
			cout << max << endl;
			continue;
		}

		int total = 0;
		for(int i = 0;i < n;i++) {
			if(i != max_i && i != min_i) total += score[i];
		}

		cout << total / (n - 2) << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

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

    int k, a, b;
    cin >> k >> a >> b;

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

    cout << "NG" << endl;

    return 0;
}

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

int main() {
	
	int N, X;
	cin >>N >>X;
	
	vector<int> bound(N);
	
	for(int i=0; i<N; i++){
		
		cin >>bound.at(i);
		
	}
	
	int coord=0;
	int count=0;
	
	for(int i=0; i<N; i++){
		
		coord+=bound.at(i);
		
		if(coord>X){
			
			break;
			
		}
		
		count++;
		
	}
	
	cout <<count+1 <<endl;
	
}

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

int main(){
    int n;
    cin >> n;
    vector<int> d;
    for (auto i = 0; i < n; i++)
    {
        int d_i;
        cin >> d_i;
        d.push_back(d_i);
    }

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

    int border_bf = n / 2 - 1;
    int border_af = n / 2;

    cout << d[border_af] - d[border_bf] << endl;

}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
//#define push push_back
//#define endl cout << "\n"
typedef long long ll;
int main(){ 
	//map<string, int> m;
	int n;
	cin >> n;
	int rem = n%1000;
	if(rem>0) cout << 1000-rem << endl;
	else cout << rem << endl;
   bye;
}
 

Measured memory_bytes: 3632
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int C=sc.nextInt();
		int[][] iwakan=new int[C][C];
		for(int i=0; i<C; i++) {
			for(int j=0; j<C; j++) {
				iwakan[i][j]=sc.nextInt();
			}
		}
		int[] mod0_color=new int[C];
		int[] mod1_color=new int[C];
		int[] mod2_color=new int[C];
		for(int i=0; i<C; i++) {
			mod0_color[i]=0;
			mod1_color[i]=0;
			mod2_color[i]=0;
		}
		for(int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {
				if((i+j)%3==0) {
					mod0_color[sc.nextInt()-1]++;
				}
				else if((i+j)%3==1) {
					mod1_color[sc.nextInt()-1]++;
				}
				else if((i+j)%3==2) {
					mod2_color[sc.nextInt()-1]++;
				}
			}
		}
		//mod 0 基準
		long sum_iwa=Long.MAX_VALUE;
		long tmp_iwa=0;
		for(int i=0; i<C; i++) {		//mod 0の色
			for(int j=0; j<C; j++) {	//mod 1の色
				for(int k=0; k<C; k++) {//mod 2の色
					tmp_iwa=0;
					if(i!=j && j!=k && k!=i) {
						for(int l=0; l<C; l++) {
							if(i!=l) {
								tmp_iwa+=mod0_color[l]*iwakan[l][i];
							}
						}
						for(int l=0; l<C; l++) {
							if(j!=l) {
								tmp_iwa+=mod1_color[l]*iwakan[l][j];
							}
						}
						for(int l=0; l<C; l++) {
							if(k!=l) {
								tmp_iwa+=mod2_color[l]*iwakan[l][k];
							}
						}
						sum_iwa=Math.min(tmp_iwa, sum_iwa);
					}
				}
			}
		}
		System.out.println(sum_iwa);
	}
}

Measured memory_bytes: 73680
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
int n,x;
int a[1000],ans=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){scanf("%d",&a[i]);ans+=a[i];}
	scanf("%d",&x);
	int temp,camp;
	for(int i=1;i<=x;i++)
	{
		scanf("%d%d",&temp,&camp);
		printf("%d\n",ans-a[temp]+camp);
	}
    return 0;
}

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


int main() {
    int n,m;
    cin>>n>>m;
    
    int max_l=0,min_r=n;
    for(int i=1;i<=m;i++)
    {
        int l,r;
        cin>>l>>r;
        
        max_l=max(max_l,l);
        min_r=min(min_r,r);
    }
    
    if(min_r- max_l <0)
    {
        cout<<"0"<<endl;
    }
    else
    {
        cout<<min_r-max_l + 1<<endl;

    }
    
	return 0;
}

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

int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  if( a % 2 == 0 || b % 2 == 0 || c % 2 == 0){
    cout << 0 << endl;
  }else{
    cout << min({a,b,c}) * (a+b+c-min({a,b,c})-max({a,b,c})) << endl;
  }
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 2005
using namespace std;
int n,k;
long long c[maxn][maxn];
long long da=1000000000+7;

void getc(){
    for(int i=0;i<=n;i++){
        c[i][i]=1;
        c[i][1]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++)
            if(c[i][j]==0) c[i][j]=(c[i-1][j]+c[i-1][j-1]) % da;
    }
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>k;
    cout<<n-k+1<<endl;
    getc();
    for(int i=2;i<=k;i++){
        long long ans= c[n-k+1][i] * c[k-1][i-1] % da;
        cout<<ans<<endl;
    }
    return 0;
}


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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  string s;
  cin >> s;
  bool yes = false;
  if (s[0] != s[1] or s[0] != s[2])
    yes = true;
  if (s[1] != s[2])
    yes = true;
  if (yes)
    cout << "Yes";
  else
    cout << "No";
}

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

int main(){
 
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  int x,y;
  
  
  x=(a+d-1)/d;
  
  y=(b+c-1)/b;
  
  if (x>=y){
    cout<<"Yes"<<endl;
  }
  
  else {
    cout<<"No"<<endl;
  }
  
  

 

  return 0;
}
  













Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int heap[250+1];

int main (void) {
    int H; 
    cin >> H;
    
    for (int i = 1; i < H+1; i++){
        cin >> heap[i];
    }
    
    for (int i = 1; i <= H; i++) {
        cout << "node " << i << ": ";
        cout << "key = " << heap[i] << ", ";
        int parent_idx = floor(i/2);
        if (parent_idx > 0) cout << "parent key = " << heap[parent_idx] << ", "; 
        int left_idx = i*2;
        if (left_idx <= H) cout << "left key = " << heap[left_idx] << ", "; 
        int right_idx = i*2 + 1;
        if (right_idx <= H) cout << "right key = " << heap[right_idx] << ", ";
        cout << endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;
const long long M = 67280421310721LL;

vector<string> split(string in, char sp = ' '){
	vector<string> ret;
	stringstream ss(in);
	string s;
	while(getline(ss, s, sp)){
		ret.emplace_back(s);
	}
	return ret;
}

void modmod(vector<string> sp, int s){
	range(i,s,10){
		vector<long long> a(3,0);
		rep(j,3){
			for(auto c : sp[j]){
				(a[j] *= 10) %= M;
				if(c == 'X') a[j] += i;
				else a[j] += c - '0';
			}
		}
		if((a[0] + a[1]) % M == a[2] % M){
			cout << i << endl;
			return;
		}
	}
	cout << "NA" << endl;
	return;
}

int main(){
	string s;
	while(cin >> s){
		rep(i,s.size()) if(s[i] == '+') s[i] = '=';
		vector<string> sp = split(s, '=');

		int start = 0;
		for(auto& i : sp) if(i.front() == 'X' and i.size() > 1) start = 1;
		modmod(sp, start);
	}
}



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

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

	int h, w;
	int judge = 0;
	cin >> h >> w;
	while(h != 0 || w != 0){
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				cout << '#';
			}
			cout << '\n';
		}
		cout << '\n';
		cin >> h >> w;
	} 

	return 0;
}


Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final long number = scanner.nextLong();
        long min = Long.MAX_VALUE;

        for (int i = 0; i < 5; i++) {
            final long l = scanner.nextLong();
            if (min >= l) {
                min = l;
            }
        }

        System.out.println((number + min - 1)/min + 4);
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <cmath>
#define EPS (1e-10)
using namespace std;

int main() {
  int n;
  double v, h;
  double g = 9.8;
  while (cin >> v) {
    h = (v * v) / (2 * g);
    n = (int)ceil((h + 5) / 5 + EPS);
    cout << n << endl;
  }
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    if (N < 1000) cout << "ABC" << endl;
    else cout << "ABD" << endl;
    return 0;
}


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

using namespace std;
using namespace atcoder;

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

  dsu d(n);

  for (int i = 0; i < q; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0) {
      d.merge(u, v);
    } else {
      cout << (d.same(u, v) ? 1 : 0) << endl;
    }
  }
}


Measured memory_bytes: 3920
//#if 1
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
//#endif
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int A, B, K;
	cin >> A >> B >> K;
	
	if (A + K - 1 >= B - K + 1) {
		for (int i = 0; i <= B - A; i++) {
			cout << A + i << endl;
		}
	}
	else {
		for (int i = 0; i < K; i++) {
			cout << A + i << endl;
		}
		for (int i = 0; i < K; i++) {
			cout << B - K + 1 + i << endl;
		}
	}

	return(0);
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))

for i in range(H):
    for j in range(W):
        cnt = 0
        if S[i][j] != "#":
            if i>0:
                if S[i-1][j] == "#":
                    cnt += 1
                if j>0 and S[i-1][j-1] == "#":
                    cnt += 1
                if j<W-1 and S[i-1][j+1] == "#":
                    cnt += 1
            if i<H-1:
                if S[i+1][j] == "#":
                    cnt += 1
                if j>0 and S[i+1][j-1] == "#":
                    cnt += 1
                if j<W-1 and S[i+1][j+1] == "#":
                    cnt += 1
            if j>0 and S[i][j-1] == "#":
                cnt += 1
            if j<W-1 and S[i][j+1] == "#":
                cnt += 1
            S[i][j] = str(cnt)
for i in range(H):
    print("".join(S[i]))


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

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

int main()
{
  int N;

  cin >> N;
  vector<int> a(3 * N);
  for (int i = 0; i < 3 * N; i++) {
    cin >> a[i];
  }

  vector<ll> dsum(N + 1, 0);
  priority_queue<int, vector<int>, greater<int>> dpq;
  vector<ll> lsum(N + 1, 0);
  priority_queue<int> lpq;
  for (int i = 0; i < N; i++) {
    dsum[0] += a[i];
    dpq.push(a[i]);

    lsum[0] += a[2 * N + i];
    lpq.push(a[2 * N + i]);
  }
  for (int i = 1; i <= N; i++) {
    dsum[i] = dsum[i - 1] + a[N + i - 1];
    dpq.push(a[N + i - 1]);
    dsum[i] -= dpq.top(); dpq.pop();

    lsum[i] = lsum[i - 1] + a[2 * N - i];
    lpq.push(a[2 * N - i]);
    lsum[i] -= lpq.top(); lpq.pop();
  }

  ll ans = -110000000000000;
  for(int i = 0; i <= N; i++) {
    ans = max(ans, dsum[i] - lsum[N - i]);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3964
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define PR       pair<ll, ll>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<ll> go;

ll toNum(string s) {
    ll x = 0;
    for (int i = 0; i < s.size(); i++) {
        x *= 10;
        ll y = (int)(s[i] - '0');
        x += y;
    }
    return x;
}

void genLunlun(string num, int last = 0) {
    if (num.size() > 10) {
        return;
    }
//    cout << num << endl;
    if (num != "") {
        go.push_back(toNum(num));
    }
    int start = num == "" ? 1 : 0;
    for (int i = start; i < 10; i++) {
        if (abs(last - i) > 1 && num != "") {
            continue;
        }
        genLunlun(num + (char)(i + '0'), i);
    }
}

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    genLunlun("");
//    cout << go.size() << endl;
    sort(go.begin(), go.end());
    int k;
    cin >> k;
    cout << go[k - 1] << '\n';
    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

void max_heapify(vector<ll> &A, ll i) {
	ll H = A.size() - 1; // size of 1-origin array A
	ll lc, rc;
	lc = 2*i;
	rc = 2*i + 1;
	ll largest = i;
	if (lc <= H && A[lc] > A[i]) {
		largest = lc;
	}
	if (rc <= H && A[rc] > A[largest]) {
		largest = rc;
	}

	if (largest != i) {
		ll temp = A[i];
		A[i] = A[largest];
		A[largest] = temp;
		max_heapify(A, largest); 
	}
}

void build_max_heap(vector<ll> &A) {
	ll H = A.size() - 1;
	for (ll i=H/2; i>0; --i) {
		max_heapify(A, i);
	}
}

int main() {
	ll H;
	cin >> H;
	vector<ll> A(H+1);
	for (ll i=1; i<A.size(); ++i) cin >> A[i];
	build_max_heap(A);
	for (ll i=1; i<A.size(); ++i) cout << " " << A[i];
	cout << endl;
	return 0;
}




Measured memory_bytes: 6700
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = 1000000;
    repf(i,1,101) {
        int tmp = 0;
        rep(j,n) {
            tmp += (x[j]-i)*(x[j]-i);
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/
int main(){
	int k;
	string S;
	cin >> S;
	k = S.length();
	int o = 0;
	REP(i,k){
	    if (S[i] == 'o') o++;
	}

	if (15 - k + o >= 8) puts("YES");
	else puts("NO");


}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    A=sorted(list(map(int,input().split())))

    tot=0
    maxind=-1
    for i in range(N-1):
        tot+=A[i]
        if tot*2<A[i+1]:
            maxind=i
    print(N-(maxind+1))


resolve()

Measured memory_bytes: 63856
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    auto f = [&] {
        vector<int> sum(m + 1);
        rep(i, m) sum[i + 1] += sum[i] + b[i];
        int ans = 0, res = 0;
        rep(i, n) {
            res += a[i];
            if (res > k) break;
            if (res == k) {
                maxs(ans, i + 1);
                break;
            }
            int idx = (--upper_bound(all(sum), k - res)) - sum.begin();
            maxs(ans, i + 1 + idx);
        }
        return ans;
    };
    int ans = f();
    swap(n, m);
    swap(a, b);
    maxs(ans, f());
    cout << ans << endl;
}

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

Measured memory_bytes: 7948
if __name__ == '__main__':
    b, c = map(int, input().split())
    a = [int(i) for i in input().split()]
    a.sort(reverse=True)
    count = 0

    for i in a:
        if c >=1:
            c = c -1
        else:
            count = count + i
    print(count)


Measured memory_bytes: 25768