akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 100005, M = N << 1, mo = 1e9 + 7 ; 
using namespace std ;

int n, e, ter[M], nxt[M], lnk[N], opt[N], h[N], ans, d[N], q[N], f[N], deg[N] ;
bool vis[N] ;

void add(int x, int y) {
	ter[++ e] = y, nxt[e] = lnk[x], lnk[x] = e ;
}

bool check(int x) {
	vis[x] = false ;
	int he = 0, ta = 1 ;
	opt[1] = x ;
	for ( ; he != ta ; ) {
		++ he ;
		int u = opt[he] ;
		for (int i = lnk[u] ; i; i = nxt[i]) {
			int v = ter[i] ;
			if (vis[v]) {
				vis[v] = false ;
				opt[++ ta] = v ;
			}
		}
	}
	rep(i, 1, ta) {
		int u = opt[i] ;
		for (int j = lnk[u]; j; j = nxt[j]) if (j & 1) {
			int v = ter[j] ;
			++ deg[v] ;
		}
	}
	bool flg = true ;
	rep(i, 1, ta) {
		int u = opt[i] ;
		flg &= deg[u] > 0 ;
	}
	if (flg) {
		++ h[ta] ;
		return true ;
	}
	int heq = 0, taq = 0 ;
	rep(i, 1, ta) {
		int u = opt[i] ;
		d[u] = deg[u] ;
		if (!d[u]) q[++ taq] = u ;
		if (d[u] > 2) return false ;
	}
	for ( ; heq != taq ; ) {
		++ heq ;
		int u = q[heq] ;
		for (int i = lnk[u]; i; i = nxt[i]) if (i & 1) {
			int v = ter[i] ;
			-- d[v] ;
			if (!d[v]) q[++ taq] = v ;
		}
	}
	rep(i, 1, ta) {
		int u = opt[i] ;
		if (!d[u] && deg[u] > 1) return false ;
	}
	heq = taq = 0 ;
	rep(i, 1, ta) {
		int u = opt[i] ;
		if (!deg[u]) q[++ taq] = u, f[u] = 0 ;
	}
	for ( ; heq != taq ; ) {
		++ heq ;
		int u = q[heq] ;
		for (int i = lnk[u]; i; i = nxt[i]) if (i & 1) {
			int v = ter[i] ;
			-- deg[v] ;
			f[v] = f[u] + 1 ;
			if (!deg[v]) q[++ taq] = v ;
		}
	}
	rep(i, 1, ta) {
		int u = opt[i] ;
		if (deg[u]) {
			x = u ;
			break ; 
		}
	}
	d[0] = 0 ;
	d[++ d[0]] = x ;
	for ( ; ; ) {
		int u = d[d[0]] ;
		for (int i = lnk[u]; i; i = nxt[i]) if (i & 1) {
			int v = ter[i] ;
			d[++ d[0]] = v ;
			break ;
		}
		if (d[d[0]] == d[1]) {
			-- d[0] ;
			break ;
		}
	}
	int las = 0 ;
	rep(i, 1, d[0]) if (f[d[i]]) las = i ;
	rep(i, 1, d[0]) if (f[d[i]]) {
		int l1 = f[d[i]], l2 = las >= i ? d[0] - las + i : i - las ;
		if (l1 < l2) ans = ans * 2 % mo ; else
		  if (l1 > l2) ans = 0 ;
		las = i ;
	}
	return true ;
}

inline void upd(int &x, int y) {
	x = (x + y) % mo ; 
}

int main() {
	scanf("%d", &n) ;
	int x ;
	rep(i, 1, n) {
		scanf("%d", &x) ;
		add(i, x), add(x, i) ;
	}
	rep(i, 1, n) vis[i] = true ;
	ans = 1 ;
	rep(i, 1, n) if (vis[i]) {
		if (!check(i)) {
			printf("0\n") ;
			return 0 ;
		}
	}
	rep(L, 1, n) if (h[L]) {
		f[0] = 1 ;
		rep(i, 1, h[L]) {
			f[i] = 0 ;
			upd(f[i], f[i - 1]) ;
			if ((L > 1) && (L & 1)) upd(f[i], f[i - 1]) ;
			if (i > 1) upd(f[i], (ll) (i - 1) * f[i - 2] % mo * L % mo) ;
		}
		ans = (ll) ans * f[h[L]] % mo ;
	}
	printf("%d\n", ans) ;
	return 0 ; 
}

Measured memory_bytes: 4096
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		List<Integer> A=new ArrayList<>();
		
		for(int i=0;i<10;i++)A.add(in.nextInt());
		Collections.sort(A, Collections.reverseOrder());
		for(int i=0;i<3;i++)System.out.println(A.get(i));
	}
}



Measured memory_bytes: 26204
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	ll n,i,a,m=0,d=1001;
	  cin>>n;
	  for(i=0;i<n;i++){
	  	cin>>a;
	  	m=max(m,a);
	  	d=min(d,a);
	  }cout<<m-d;
}


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

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

    bool flag = true;

    for( int n = 0 ; n < N; n++ ) {
        int k = 0;
        std::cin >> k;

        if( k % 2 == 0 )  {
            if( !( k % 3 == 0 || k % 5 == 0 ) ) {
                flag = false;
                break;
            }
        }
    }
    if( flag ) {
        std::cout << "APPROVED" << std::endl;
    } else {
        std::cout << "DENIED" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,n){
    if(i == 0){
      int tmp = max(a[i] - x,0);
      ans += tmp;
      a[i] -= tmp;
    }
    if(i > 0){
      int tmp = max(a[i] + a[i-1] - x,0); 
      ans += tmp;
      a[i] -= tmp;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

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

        int N = Integer.parseInt(scan.next()); 
        List<String> targets = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            targets.add(scan.next());
        }
        scan.close();

        Map<String, Long> tmp = new HashMap<String, Long>();
        for (String target : targets) {
            char[] c = target.toCharArray();
            Arrays.sort(c);
            String sortTarget = new String(c);
            if (tmp.containsKey(sortTarget)) {
                tmp.put(sortTarget, tmp.get(sortTarget) + 1);
            } else {
                tmp.put(sortTarget, 0L);
            }
        }
        
        long result = 0;
        for (Long l : tmp.values()) {
            for (long t = 1; t < l + 1; t++) {
                result += t;
            }
        }

        System.out.println(result);
    }
}

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

int toI(char ch){
  if(isdigit(ch)) return ch - '0';
  if(ch == 'T') return 10;
  if(ch == 'J') return 10;
  if(ch == 'Q') return 10;
  if(ch == 'K') return 10;
}

int flg;
int calc(int sum,char ch){
  if(ch == 'A'&&sum+11<=21){flg++; return sum+11;}
  if(ch == 'A') return sum+1;
  return sum + toI(ch);
}


int main(){
  int q;
  cin>>q;
  while(q--){
    int sum = 0;
    char ch[2];
    cin>>ch[0]>>ch[1];
    flg=0;
    sum = calc(sum,ch[0]);
    sum = calc(sum,ch[1]);
    
    char card[8];
    for(int i=0;i<8;i++)cin>>card[i];
    if(sum == 21){cout<<"blackjack"<<endl;continue; }

    for(int i=0;i<8;i++){
      if(sum <= 16) sum = calc(sum,card[i]);
      else if(sum==17 && flg) sum = calc(sum,card[i]);
      while(sum>21&&flg)flg--,sum-=10;
    }
    if(sum>21) cout<<"bust"<<endl;
    else cout<< sum<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> p(N+1,0);
    for(int i=1;i<=N;i++) cin >> p[i];
    int max = 0;
    int maxp;
    for(int i=1;i<=N;i++){
        if(p[i]>max){
            max = p[i];
            maxp = i;
        }
    }
    int sum = 0;
    for(int i=1;i<=N;i++){
        if(i == maxp) sum += p[i]/2;
        else sum += p[i];
    }
    cout << sum << endl;
    return 0;
}

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

int dp[maxn][maxn];
char pr[maxn][maxn];
char s[maxn], t[maxn];

void print(int i, int j)
{
    if (i <= 0 || j <= 0){
        return;
    }

    if (pr[i][j] == 'd'){
        print(i - 1, j - 1);
        cout << s[i];
    }

    else if (pr[i][j] == 'u'){
        print(i - 1, j);
    }

    else {
        print(i, j - 1);
    }

}

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

    //freopen("d.in", "r", stdin);



    cin >> (s + 1) >> (t + 1);

    int n = strlen(s + 1);
    int m = strlen(t + 1);

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            if (s[i] == t[j]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
                pr[i][j] = 'd';
            }
            else {
                if (dp[i - 1][j] >= dp[i][j - 1]){
                    dp[i][j] = dp[i - 1][j];
                    pr[i][j] = 'u';
                }
                else {
                    dp[i][j] = dp[i][j - 1];
                    pr[i][j] = 'l';
                }
            }
        }
    }

    print(n, m);

    return 0;
}


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

int main() {

    int N;
    cin >> N;

    int h;
    int hl = 0;
    string ans = "Yes";
    for (int i = 0; i < N; i++) {
        cin >> h;
        if (h + 1 < hl) {
            ans = "No";
        }
        else if (h + 1 == hl) {
            h++;
        }
        hl = h;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
const funcB = (input: string): void => {
    const hoge: number[] = input.trim().slice(1).split(/\n/).map(Number);
    const hogeSum: number = hoge.reduce((a, x) => a+=x, 0);
    const hogeDis: number = Math.max(...hoge) / 2;
    console.log(hogeSum - hogeDis);
}

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

Measured memory_bytes: 7500
#include <stdio.h>
#include <math.h>
 
int main(void){
    double x1,y1,x2,y2,dis;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    dis = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
    printf("%lf\n", dis);
    return 0;
}


Measured memory_bytes: 2056
N = int(input())
TXY = [list(map(int, input().split())) for _ in range(N)]

ans = True

for i in range(N):
    if i == 0:
        t = TXY[i][0]
        x = TXY[i][1]
        y = TXY[i][2]

    else:
        t = TXY[i][0] - TXY[i - 1][0]
        x = abs(TXY[i][1] - TXY[i - 1][1])
        y = abs(TXY[i][2] - TXY[i - 1][2])

    xy = x + y
    if t == xy or (t > xy and (t - xy) % 2 == 0):
        pass
    else:
        ans = False
        break

if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27132
import java.io.*;
import java.util.*;

public class  Main{
	static int mod=(int)1e9+7;
	
    public static void main(String[] args) throws Exception{
        //MScanner sc = new MScanner("chess.in");
        MScanner sc = new MScanner(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();
        int[]in=new int[n];
        TreeMap<Integer,Integer>occ=new TreeMap<Integer, Integer>();int ans=0;
        for(int i=0;i<n;i++) {
        	in[i]=sc.nextInt();
        	Integer f=occ.floorKey(in[i]-1);
        	if(f==null) {
        		ans++;
        	}
        	else {
        		int x=occ.get(f);
        		if(x==1) {
        			occ.remove(f);
        		}
        		else {
        			occ.put(f,x-1);
        		}
        	}
        	occ.put(in[i],occ.getOrDefault(in[i],0)+1);
        }
        pw.println(ans);
        
        pw.flush();
    }
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 48936
import itertools

N,M = list(map(int,input().split(" ")))

# graph = [list(map(int,input().split(" "))) for _  in range(M)]
used = [False] * M
INF = 10**20
cost = [[INF for _ in range(N+1)] for _ in range(N+1)]
edges = []
for i in range(M):
    a,b,c = list(map(int,input().split(" ")))
    cost[a][b] = c
    cost[b][a] = c
    edges.append((a,b,c))
for i in range(1,N+1):
    cost[i][i] = 0
for k in range(1,N+1):
    for i in range(1,N+1):
        for j in range(1,N+1):

            cost[i][j] = min(cost[i][j],cost[i][k] + cost[k][j])
            cost[j][i] = min(cost[j][i], cost[j][k] + cost[k][i])
ans = 0
for k,edge in enumerate(edges):
            a,b,c = edge
            if  cost[a][b] !=c:
                ans += 1
print(ans)


Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#define SIZE 100001
using namespace std;
class point {
public:
	int num;
	int count;
};

bool compare(point&a, point&b) {
	return a.count > b.count;
}
int main() {
	vector<point> counter[2];
	for (int i = 0; i < 2; ++i) {
		counter[i].resize(SIZE);
		for (int j = 0; j < SIZE; ++j) {
			counter[i][j].count = 0;
			counter[i][j].num = j;
		}
	}
	int time;
	cin >> time;
	for (int i = 0; i < time; ++i) {
		int a;
		cin >> a;
		counter[i % 2][a].count++;
	}
	for (int i = 0; i < 2; ++i) {
		sort(counter[i].begin(), counter[i].end(), compare);
	}
	int ans = time;
	for (int i = 0; i < SIZE; ++i) {
		int j;
		for (j = 0; counter[0][i].num == counter[1][j].num; ++j);
		ans = min(ans, time - counter[0][i].count - counter[1][j].count);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict
d = defaultdict(int)

rec = [0,0]

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

for key in A:
	d[key] += 1
	if d[key] == 2:
		if key > rec[0]:
			rec[0] = key
			rec = sorted(rec)
		d[key] = 0

print(rec[0] * rec[1])

Measured memory_bytes: 18600
package main

import "fmt"

func nextInt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	n := nextInt()
	dic := map[int]struct{}{}

	cnt := 0
	for range make([]struct{}, n) {
		a := nextInt()
		if a < 3200 {
			dic[a/400] = struct{}{}
		} else {
			cnt++
		}
	}
	fmt.Println(max(1, len(dic)), len(dic)+cnt)
}


Measured memory_bytes: 512
#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 pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)
/*
tree<
       int,
     null_type,
     less<int>,
     rb_tree_tag,
     tree_order_statistics_node_update>t;
*/

int main()
{
    fast_in_out

    int k;
    cin>>k;
    int cn=1;

    string v;
    v="1";

    while(cn!=k)
    {
        if(v.size()==1)
        {
            if(v[0]!='9')
                v[0]+=1;
            else
                v="01";
        }

        else if(v.size()>1)
        {


            bool valid=0;

            for(int i=0; i<v.size()-1; i++)
            {
                if(v[i]<=v[i+1] && v[i]!='9')
                {
                    v[i]+=1;
                    valid=1;

                    for(int j=i-1; j>=0; j--)
                    {
                       if(v[j+1]-1<48)
                            v[j]='0';
                        else
                            v[j]=v[j+1]-1;
                    }
                    break;
                }
            }
            if(valid==0)
            {
                if(v[v.size()-1]!='9')
                {

                    v[v.size()-1]+=1;

                    for(int j=v.size()-2; j>=0 ; j--)
                    {
                        if(v[j+1]-1<48)
                            v[j]='0';
                        else
                            v[j]=v[j+1]-1;
                    }
                }
                else
                {

                    v.pb('1');
                    for(int i=0; i<v.size()-1; i++)
                    {
                        v[i]='0';

                    }

                }

            }

        }
        cn++;
        //string t=v;
    //reverse(all(t));
    //cout<<t<<" ";
    }

    reverse(all(v));
    cout<<v<<endl;

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

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

const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9+7;

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
	fastio;
	int n;
	cin >> n;
	string s;
	cin >> s;
	int i = 0, j = n/2;
	if(n&1){
		cout << "No\n";
		return 0;
	}
	while(s[j] != '\0'){
		if(s[i] != s[j]){
			cout << "No\n";
			return 0;
		}
		i++, j++;
	}
	cout << "Yes\n";	
	return 0;
}

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


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll d, a;
    cin >> n >> d >> a;

    vector<ll> x(n), h(n);
    vector<int> ids(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> h[i];
        ids[i] = i;
    }

    sort(ids.begin(), ids.end(), [&](const int i1, const int i2){
        return x[i1] < x[i2];
    });

    vector<ll> cnt(n + 1, 0);
    ll ans = 0;
    for (int ii = 0, jj = 0; ii < n; ++ii) {
        int i = ids[ii];
        h[i] -= a * cnt[ii];
        if (h[i] > 0) {
            ll rest = (h[i] + a - 1) / a;
            while (jj < n) {
                if (x[ids[jj]] - x[i] > 2 * d) break;
                ++jj;
            }
            ans += rest;
            cnt[ii] += rest;
            cnt[jj] -= rest;
        }
        cnt[ii + 1] += cnt[ii];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5760
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b = LI()
    r = [['.']*50+['#']*50 for _ in range(100)]
    a -= 1
    b -= 1
    for i in range(0,100,2):
        for j in range(0,40,2):
            if b < 1:
                break
            r[i][j] = '#'
            b -= 1
        for j in range(60,100,2):
            if a < 1:
                break
            r[i][j] = '.'
            a -= 1



    return '100 100\n' + '\n'.join(map(lambda x: ''.join(x),r))


print(main())




Measured memory_bytes: 7816
x = parse(Int, readline())
function fizzbuzz(n)
    a = div(n,3)
    b = div(n,5)
    c = div(n,15)
    A = (3 + a*3)/2*a
    B = (5 + b*5)/2*b
    C = (15+ c*15)/2*c
    N = (1+n)*n/2
    return Int(N - A - B + C)
end

println(fizzbuzz(x))


Measured memory_bytes: 156928
#include <iostream>
#include <cstdio>
#include <bitset>

using namespace std;

typedef long long ll;

const ll M = 13000;
ll h, w;
ll a[85][85];
bitset<M * 2 + 5> d[85][85];

int main()
{
    scanf("%lld%lld", &h, &w);
    for(ll i = 1; i <= h; i++)
    {
        for(ll j = 1; j <= w; j++)
        {
            scanf("%lld", &a[i][j]);
        }
    }
    for(ll i = 1; i <= h; i++)
    {
        for(ll j = 1; j <= w; j++)
        {
            ll t;
            scanf("%lld", &t);
            a[i][j] -= t;
            if(a[i][j] < 0) a[i][j] = -a[i][j];
        }
    }
    d[0][1][M] = true;
    for(ll i = 1; i <= h; i++)
    {
        for(ll j = 1; j <= w; j++)
        {
            d[i][j] |= (d[i - 1][j] << a[i][j]);
            d[i][j] |= (d[i - 1][j] >> a[i][j]);
            d[i][j] |= (d[i][j - 1] << a[i][j]);
            d[i][j] |= (d[i][j - 1] >> a[i][j]);
        }
    }
    for(ll i = 0; i <= 12800; i++)
    {
        if(d[h][w][M - i] || d[h][w][M + i])
        {
            printf("%lld\n", i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 22528
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    var N = scn.nextInt()
    val K = scn.nextInt()

    var ans = K
    var cnt = 1
    while(N>=ans){
        ans *=  K
        cnt++
    }

    println(cnt)
}

Measured memory_bytes: 29472
#include <stdio.h>

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

	if (a < b && b < c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2112
#include <iostream>

using namespace std;

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <tuple>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> b;
	for (int i = 0; i < n; ++i) {
		int bi;
		cin >> bi;
		bi--;
		b.push_back(bi);
	}
	vector<int> ans;
	bool possible = true;
	for (int m = n-1; m >= 0; m--) {
		int can = -1;
		for (int i = 0; i < b.size(); ++i) {
			if (b[i] <= m && b[i] == i) {
				can = i;
			}
		}
		if (can == -1) {
			cout << "-1" << endl;
			return 0;
		}
		ans.push_back(can + 1);
		b.erase(b.begin() + can);
	}
	for (int i = ans.size() - 1; i >= 0; --i) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int N;int K;
    cin >> N >> K;
    char s[100];
    cin >> s;
    s[K - 1] += 32;
    cout << s;
}

Measured memory_bytes: 256
(defun good-integer (x)
  (cond ((let (q) 
           (setf (values q) (floor (/ x 10)))
           (= (mod q 111) 0)) "Yes")
        ((let (r)
           (setf (values r) (mod x 1000))
           (= (mod r 111) 0)) "Yes")
        (t "No")))

 (format t "~A~%" (good-integer (read)))


Measured memory_bytes: 10088
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    int ans = 0;
    int tmp = 0;
    rep(i,n){
        if(s[i] == 'I') tmp++;
        else tmp--;

        ans = max(ans,tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
using namespace std;
long long int n;
int main()
{
    scanf("%lld",&n);
    for(int i=sqrt(n);i>=1;i--)
    {
        if(n%i==0)
		{
            int t=i,l=n/i;
            int s=1;
            while(l>=10)
			{
                s++;
                l/=10;
            }
        printf("%d\n",s);
        return 0;
        }
    }
}

Measured memory_bytes: 128
n, x = map(int, input().split())
a = [1]
p = [1] # レベル0バーガーは パティ1 枚
# レベル1バーガーは BPPPB
# レベル2バーガーは B,BPPPB,P,BPPPB,B  
for i in range(n):
  a.append(a[i]*2+3)
  p.append(p[i]*2+1)
  
def rec(n, x):
  if n==0:
    return 0 if x<=0 else 1
  elif x <= 1+a[n-1]:
    return rec(n-1, x-1)
  else:
    return p[n-1]+1+rec(n-1, x-2-a[n-1])
print(rec(n, x))
  
  

Measured memory_bytes: 3064
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

struct P {
  int to, from;
  long long yen, snu;
};

struct N {
  int now;
  long long cost;
};
bool operator<(const N &lhs, const N &rhs) { return lhs.cost < rhs.cost; }

int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  vector<vector<P>> p(n), inv(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    long long a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    p[u].push_back(P{v, u, a, b});
    p[v].push_back(P{u, v, a, b});
  }
  vector<long long> minSnu(n);
  for (int i = 0; i < n; i++)
    minSnu[i] = -1;
  multiset<N> q;
  q.insert(N{t, 0});
  while (q.size() > 0) {
    N now = *q.begin();
    q.erase(q.begin());
    if (minSnu[now.now] >= 0)
      continue;
    minSnu[now.now] = now.cost;
    for (int i = 0; i < p[now.now].size(); i++) {
      if (minSnu[p[now.now][i].to] >= 0)
        continue;
      q.insert(N{p[now.now][i].to, now.cost + p[now.now][i].snu});
    }
  }
  vector<long long> ans(n);
  q.clear();
  q.insert(N{s, 0});
  long long minC = -1;
  vector<long long> dist(n);
  for (int i = 0; i < n; i++)
    dist[i] = -1;
  while (q.size() > 0) {
    N now = *q.begin();
    q.erase(q.begin());
    if (dist[now.now] >= 0)
      continue;
    dist[now.now] = now.cost;
    for (int i = 0; i < p[now.now].size(); i++) {
      if (dist[p[now.now][i].to] >= 0)
        continue;
      q.insert(N{p[now.now][i].to, now.cost + p[now.now][i].yen});
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (minC < 0) {
      minC = minSnu[i] + dist[i];
    } else {
      minC = min(minC, minSnu[i] + dist[i]);
    }
    ans[i] = 1000000000000000ll - minC;
  }
  for (int i = 0; i < n; i++)
    cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 17536
# 入力
N = int(input())
A = list(map(int, input().split()))

S = sum(A)

# A_{i + 1} - A_i から解を求める
ans = (
    'YES' if (2 * S) % (N * (N + 1)) == 0 and all(
        k % N == 0 and k >= 0
        for k in (
            (2 * S) // (N * (N + 1)) - (A[i] - A[i - 1])
            for i in range(N)
        )
    ) else
    'NO'
)

# 出力
print(ans)


Measured memory_bytes: 14196
N = int(input())
A = []
B = []
for i in range(N):
    a = int(input())
    b = int(input())
    A.append(a)
    B.append(b)

for i in range(N):
    if A[i] >= 10 ** 80 or B[i] >= 10 ** 80:
        print("overflow")
    elif A[i] + B[i] >= 10 ** 80:
        print("overflow")
    else:
        print(str(A[i] + B[i]))

Measured memory_bytes: 7532
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))
    res = 0
    for i in range(N):
        res += max(0, V[i]-C[i])
    print(res)

if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin >> n;
  map<char, int> cnt;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    int l = s.size();
    map<char, int> next, now;
    for(int j = 0; j < l; j++){
      char c = s.at(j);
      now[c]++;
      if(i == 0) cnt[c]++;
    }
    for(auto a : now){
      if(!cnt.count(a.first)) continue;
      int k = min(a.second, cnt.at(a.first));
      next[a.first] = k;
    }
    cnt = next;
  }
  
  vector<char> ans(0);
  for(auto a : cnt){
    for(int i = 0; i < a.second; i++){
      ans.push_back(a.first);
    }
  }
  sort(ans.begin(), ans.end());
  
  for(auto a : ans) cout << a;
  cout << endl;
}

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

bool check(string s){
    int n= s.size();
    rep(i,n){
        if(s[i]!=s[n-i-1]){
            return false;
        }
    }
    return true;
}

int main(){
    string s;
    cin>>s;
    string f,l;
    f = s.substr(0,(s.size()-1)/2);
    l = s.substr((s.size()+1)/2);
    if(check(s)&&check(f)&&check(l)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4

int main(){
  int N; cin >> N;
  int A;
  
  bool flag = true;
  rep(i,N){
    cin >> A;
    if (A%2==0 && (A%3>0 && A%5>0)) flag = false; 
  }

  cout << (flag? "APPROVED" : "DENIED") << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int countDigitSum(int number) {
    int sum = 0;
    while (number != 0) {
        int digit = number % 10;
        number /= 10;
        sum += digit;
    }
    return sum;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    int count = 0;
    repeat (i, N + 1) {
        if (i == 0) {
            continue;
        }
        int digitSum = countDigitSum(i);
        if (A <= digitSum && digitSum <= B) {
            count += i;
        }
    }
    cout << count << endl;
    return 0;
}


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

int main(){
	
	int N;
	vector<int> h;
	int K;

	cin >> N;
	cin >> K;

	h.resize(N);

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

	int count = 0;
	for (int i = 0; i < N; i++){
		if (h[i] >= K){
			count++;
		}
	}
	cout << count;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    int n;
    cin >> n;
    if(n==7||n==5||n==3) out("YES");
    else out("NO");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>


int main()
{
  int len;
  scanf("%d", &len);
  char a[len+1];
  scanf("%s", a);

    int ans = 1;
    if(len%2!=0) ans=0;
    else {
      for(int i=0; i<len/2; i++){
        // printf("%c, %c\n", a[i], a[i+len/2]);
        if(a[i]!=a[i+len/2]) ans=0;
      }
    }

    if(ans==0) printf("No");
    else printf("Yes");

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);


// #define int long long

using namespace std;
int main() {


    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin高速化

    int price[10];
    int sum = 0;
    int n;

    cin>>n;

    int price_max = -1;
    for(int count = 0; count < n; count++) {
        cin>>price[count];
        price_max = max(price_max, price[count]);
        sum += price[count];
    }

    cout<<sum-price_max/2<<endl;

    return 0;
}

Measured memory_bytes: 256
tensu=[None]*4
ten=[None]*2
for i in range(4):
    tensu[i]=input()
tensu=list(map(int,tensu))

for i in range(2):
    ten[i]=input()
ten=list(map(int,ten))

if ten[0]<ten[1]:
    b=0
    b=ten[0]
    ten[0]=ten[1]
    ten[1]=b

for i in range(4):
    if tensu[3]>tensu[i]:
        k=0
        k=tensu[i]
        tensu[i]=tensu[3]
        tensu[3]=k
    i+=1
    
s=0
i=0
for i in range(3):
    s+=tensu[i]
    i+=1

c=s+ten[0]

print(c)
    



Measured memory_bytes: 5600
#include<stdio.h>

int min(int a,int b){
  if(a > b) return b;
  else return a;
}

int main(){
  int n,m,i,j,k;

  scanf("%d",&n);

  int P[n];
  int A[n+1][n+1];

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

  for(i = 1;i <= n;i++){
    for(j = 1;j <= n;j++){
      A[i][j] = 0;
    }
  }

  for(j = 2;j <= n;j++){
    for(i = j-1;i > 0;i--){
      A[i][j] = 1000001;
      for(k = i;k < j;k++){
        m = A[i][k] + A[k+1][j] + P[i-1]*P[k]*P[j];
        A[i][j] = min(A[i][j],m);
      }
    }
  }
  printf("%d\n",A[1][n]);
  return 0;
}
/*
金の時計
運命数　３５

右上がり
人脈
人脈の整理

社交的多趣味

長く使えるもの
成功者か羅話を聞く
紹介する

藤色　黄色

キャンプ　人が集まる場所
*/



Measured memory_bytes: 2112
# -*- coding: utf-8 -*-                                                                                                                                                                                                                               

def BFS(adj, start):
    n = len(adj)
    d = [-1] * n
    flag = [0] * n
    Q = []

    Q.append(start)
    d[start] = 0
    flag[start] = 1

    while len(Q) != 0:
        u = Q.pop(0)
        v = [i for i, x in enumerate(adj[u]) if (x == 1) and (flag[i] == 0)] # v <= ??£??\???????????????????????¢?´¢??????????????????
        
        for i in v:
            Q.append(i)
            d[i] = d[u] + 1
            flag[i] = 1
    
    return d

def main():
    n = int(input())
    adj = [[0 for i in range(n)] for j in range(n)]
    
    for i in range(n):
        tmp = list(map(int, input().split()))
        u = tmp[0]
        u = u -1
        k = tmp[1]
        v = tmp[2:]
        for j in range(k):
            adj[u][v[j]-1] = 1
    
    d = BFS(adj, 0)
    for i in range(n):
        print(i+1, d[i])


if __name__ == "__main__":
    main()

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

int A, B;
char s[15];

int main(){
    scanf("%d%d", &A, &B);
    scanf("%s", s);
    bool ok = true;
    for(int i=0; i<A; i++){
        if(!('0'<= s[i] && s[i] <= '9')) ok = false;
    }
    if(!(s[A] == '-')) ok = false;
    for(int i=A+1; i<A+B+1; i++){
        if(!('0'<= s[i] && s[i] <= '9')) ok = false;
    }
    if(ok) printf("Yes");
    else printf("No");
}


Measured memory_bytes: 256
from subprocess import*
cmd=['pypy3','-c',"""
def solve(p,q):
  return sorted(i+j for i in p for j in q)[-k:]
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in solve(solve(a,b),c)[::-1]:
  print(i)
"""]
call(cmd)

Measured memory_bytes: 150040
/* _________________________________________________________________________________________________
  |                                                                                                 |
  |                             Author      : Aditya Ahuja                                          |
  |                             Date        : Sun, 19th Jan 2020                                    |
  |_________________________________________________________________________________________________|
*/
 
#include<bits/stdc++.h>
using namespace std;

#define int long long

#define pb          push_back
#define F           first
#define S           second
#define endl        "\n"
#define rep(i,a,b)  for(int i = a; i < (int)b; i++)
#define req(i,a,b)  for(int i = (int)b - 1; i >= a; i--)
#define all(a)      (a).begin(),(a).end()
#define ret(x)      {cout << x << endl; return;}
#define sz(x)       (int)x.size()
#define type(x)     typeid(x).name()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;

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

#ifdef LOCAL
	#define wa(x)       cerr << (#x) << " --- " << (x) << endl
	#define pvi(v)      {for(auto it:v) cerr << it << " "; cerr << endl;}
	#define line1	    cerr << "---------------------------" << endl;
#else
	#define wa //
	#define line1 //
	#define pvi //
	#define printf //
#endif

void solve();
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout << fixed << setprecision(10);

	int t=1; 
	// cin>>t;
	while(t--) solve();
	return 0;
}

//___________________________________________________________________________________________________

int mod = 1e9+7;
int o(int num){
	return num%mod;
}

int mpow(int b, int p){
	if(b == 0 || b == 1) return b;
	if(p == 0) return 1;
	if(p == 1) return o(b);

	int h = mpow(b,p/2);
	h = o(h*h);
	if(p%2) h = o(h*b);
	return h;
}

bool isprime(int p){
	if(p < 2) return false;
	for(int i=2; i*i<=p; i++) if(p%i==0) return false;
	return true;
}

map<int,int> prime_factors(int num){
	map<int,int> facs;
	for(int i=2; i*i<=num; i++){
		while(num%i==0) facs[i]++, num /= i;
	}

	if(num != 1) facs[num]++;
	return facs;
}

void solve() {

	int n; cin >> n;
	vi a(n); rep(i,0,n) cin >> a[i];
	
	map<int,int> mx;

	for(int e:a){
		auto m = prime_factors(e);
		for(auto p:m) mx[p.F] = max(mx[p.F], p.S);
	}

	int lcm = 1;
	for(auto p:mx) lcm = o(lcm * mpow(p.F, p.S));

	int tot = 0;
	for(int e:a) tot = o(tot + o(lcm*mpow(e,mod-2))); 
	ret(tot);
}


Measured memory_bytes: 1024
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())


def main():
    N = i_input()
    ans = False
    z = 0
    for _ in range(N):
        D1, D2 = i_map()
        if D1 == D2:
            z += 1
            if z >= 3:
                ans  = True
        else:
            z = 0
    print("Yes" if ans else "No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 62112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll h[100005];
ll n, a, b;
bool valid (ll k) {
  ll temp = 0;
   for (int i = 0; i < n; i++) {
     if (b * k < h[i]) {
        //temp += (h[i] - b * k) / (a - b) + 1;
        temp += (h[i] - k * b + a - b - 1) / (a - b);
     }
  }
  return temp <= k;
}
int main() {
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  ll lo = 0, hi = 1e9;
  ll mid;
  while (lo <= hi) {
     mid = (lo + hi) / 2;
     if (valid(mid)) {
        hi = mid - 1;
     } else {
       lo = mid + 1;
     }
  }
  cout << lo << endl;
  //cout << lo << " " << mid << " " << hi << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int n,m;
	string aindex, bindex, ans;
	cin >> m;
	n = 0;
	string a,b;
	for(int j = 0; j < m; j++){
		cin >> a >> b;
		if(a.size() > 80||b.size() > 80){
			cout << "overflow" << endl;
		}else{
			for(int i = 0; i< max(a.size(),b.size()); i++){
				if(a.size()>= i+1){
					aindex = a[a.size()-i-1];
				}else{
					aindex = "0";
				}
				if(b.size() >= i+1){
					bindex = b[b.size()-i-1];
				}else{
					bindex = "0";
				}
				n = stoi(aindex) + stoi(bindex) + (n-n%10==10);
				aindex = to_string(n%10);
				ans = aindex + ans;
			}

			if(n-n%10 == 10){
				ans = '1' + ans;
			}

			if(ans.size() > 80){
				cout << "overflow" << endl;
			}else{
				cout << ans << endl;
			}

		}
		ans ="";
		n = 0;
	}
	return 0;
}

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

using namespace std;
#define ll long long int

int main() 
{
	int n;
	ll v;
	cin>>n>>v;
	vector<pair<int,int>> A;
	for(int i = 0;i<n;i++)
	{
		int value, weight;
		cin>>weight>>value;
		A.push_back({weight, value});
	}

	vector<vector<ll>> dp(v+1, vector<ll> (n+1, 0));
	for(ll i = 1;i<=v;i++)
	{
		for(int j = 1;j<=n;j++)
		{
			
			if(i >= A[j-1].first)
			{

				dp[i][j] = max(dp[i][j-1], A[j-1].second + dp[i-A[j-1].first][j-1]);
			}
			else
				dp[i][j] = dp[i][j-1];
		}
	}

	cout<<dp[v][n]<<endl;

}

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define For(i, a, b) for (ll i = (a); i < (b); i++)
#define all(A) (A).begin(), (A).end()

int main(){
    ll N, M;
    cin >> N >> M;
    ll ans = 0;
    if (N * 2 >= M) {
        cout << M / 2 << endl;
        return 0;
    }
    ans = N;
    M -= 2 * N;
    ans += M / 4;

    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 < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<vector<pair<int,int>>> e(n);
  vector<int> ans(n,-1);
  int u,v,w;
  rep(i,n-1){
    cin >> u >> v >> w;
    u--,v--;
    e[u].push_back({v,w});
    e[v].push_back({u,w});
  }
  ans[0]=0;
  queue<pair<int,int>> q;
  q.push({0,0});
  while(!q.empty()){
    auto now = q.front();
    q.pop();
    for(auto nx:e[now.first]){
      if(ans[nx.first]!=-1) continue;
      q.push({nx.first,(now.second+nx.second)%2});
      ans[nx.first]=(now.second+nx.second)%2;
    }
  }
  rep(i,n){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

/*
レート 1-399：灰色 0
レート 400-799：茶色 1
レート 800-1199：緑色 2
レート 1200-1599：水色 3
レート 1600-1999：青色 4
レート 2000-2399：黄色 5
レート 2400-2799：橙色 6
レート 2800-3199：赤色 7
*/

int color[10];

int main() {
    int N;
    cin >> N;
    
    mem(color,0);
    
    rep(i,N){
        int r; cin >> r;
        
        if(r<400) color[0]++;
        else if(r<800) color[1]++;
        else if(r<1200) color[2]++;
        else if(r<1600) color[3]++;
        else if(r<2000) color[4]++;
        else if(r<2400) color[5]++;
        else if(r<2800) color[6]++;
        else if(r<3200) color[7]++;
        else color[8]++;
    }
    
    int a=0,b=color[8];
    rep(i,8){ if(color[i])a++;}
    
    int minv,maxv;
    minv = max(1,a);
    maxv = a+b;
    
    cout2(minv,maxv);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void ABC80(void);
void ABC81(void);
void ABC83(void);
void ABC85(void);
void ABC86(void);
void ABC87(void);
void ABC88(void);
void ABC89(void);

int main(void){
    ABC88();
}

void ABC88(){
    int n,a;
    cin>>n>>a;
    if((n%500)<=a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
a = []
l = []
gets.to_i.times do
  a << gets.to_i
end

l[0] = a[0]
length = 1

(1...a.size).each do |i|
  if l[length-1] < a[i]
    l[length] = a[i]
    length += 1
  else
    j = (0...l.size).bsearch { |k| a[i] <= l[k] }
    l[j] = a[i]
  end
end
puts length

Measured memory_bytes: 10460