akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  codeforcesTraining
//
//  Created by Pranav Jangir on 04/09/19.
//  Copyright © 2019 Pranav Jangir. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cassert>
#define pb push_back
using namespace std;
typedef long long ll;

string s;
ll n, m;
ll a[200005];
ll p[200005];
ll fs(ll x)
{
    return p[x] == x ? p[x] : p[x] = fs(p[x]);
}
void ms(ll x,ll y)
{
    x = fs(x); y = fs(y);
    p[y] = x;
}
ll c[200005];
int main(int argc, const char * argv[]) {
    
    cin >> s;
    cin >> m;
    n = s.length();
    s = "a" + s;
    s = s + "a";
    for(ll i=1;i<=n + 1;i++) p[i] = i;
    for(ll i=1;i <= n + 1;i++){
        a[i] = s[i] - 'a';
        a[i] = a[i] - (s[i - 1] - 'a');
        a[i] += 26;
        a[i] %= 26;
    }
    //for(ll i=1;i<=n+1;i++) cout << a[i] << " "; cout << endl; return 0;
    ll lst = n + 1;
    for(ll i=1;i < lst ;i++) {
        ms(i, lst);
        lst--;
    }
    while(m--) {
        ll l, r;
        cin >> l>> r;
        ms(l , r+1);
    }
    for(ll i=1;i<=n+1;i++) {
        //cout << i <<  " --> " << fs(i) << endl;
        c[fs(i)] += a[i];
        c[fs(i)] %= 26;
    }
    for(ll i=1;i<=n;i++) {
        if(c[i] != 0) {
            cout << "NO\n"; return 0;
        }
    }
    cout << "YES\n";
    return 0;
}


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

typedef long long int lli;
#define pb push_back
#define gcd __gcd
#define MOD 1000000007
#define mod2 998244353
#define forz(i,n) for(long long int i=0;i<n;i++)

double mod(double a){
    if(a<0) return -1*a;
    return a;
}

bool prime[100000000+1];

void SieveOfEratosthenes() 
{ 
    lli n=100000000;
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    }  
}

bool aa(string a,string b){
    for(int i=0;i<7;i++){
        if(a[i]=='?') continue;
        else if(a[i]==b[i]) continue;
        else return 0;
    }
    return 1;
}

bool bb(string t2){
    map<string,lli> solve;
    map<string,lli>::iterator itr;
    for(int i=0;i<t2.size()-6;i++){
        solve[t2.substr(i,7)]++;
    }
    string s="abacaba";
    if(solve[s]==1) return 1;
    return 0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t=1,u,j;
    
    
    //cin>>t;
    ///SieveOfEratosthenes();
    for(u=1;u<=t;u++){
        lli m,n, i,j,a,b,c,k,p=0,q=0,p1=0,p2=0,p3=0,ans=0,l,r,index=-1;
        cin>>n;
        lli A[n];
        for(i=0;i<n;i++) cin>>A[i];
        lli current=1000;

        for(i=1;i<n;i++){
            if(A[i]>A[i-1]){
                j=current/A[i-1];
                current-=(j*A[i-1]);
                current=current+j*A[i];
            }
        }

        cout<<current<<endl;
    }
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,d,a;cin>>n>>d>>a;
    vector<pair<ll,ll>> p(n);
    rep(i,n) cin>>p[i].first>>p[i].second;
    sort(p.begin(),p.end());
    ll cnt=0,dmg=0;
    queue<pair<ll,ll>> que;
    rep(i,n){
        ll x=p[i].first,h=p[i].second;
        while(que.size()){
            ll b=que.front().first,c=que.front().second;
            if(b>=x)break;
            que.pop();
            dmg-=c;
        }
        h-=dmg;
        if(h<=0)continue;
        ll tmp=(h+a-1)/a;
        cnt+=tmp;
        tmp*=a;
        dmg+=tmp;
        que.push({x+d*2,tmp});
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] N = new int[4];
        int[] Y = new int[10];
        for (int i = 0; i < 4; i++) {
            N[i] = sc.nextInt();
            Y[N[i]]++;
        }
        if (Y[1] > 0 && Y[4] > 0 && Y[7] > 0 && Y[9] > 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

        sc.close();
    }
}


Measured memory_bytes: 23380
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int h=sc.nextInt();
            int w=sc.nextInt();
            if(h==0&&w==0) break;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(i%2==j%2) System.out.printf("#");
                    else System.out.printf(".");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 59480
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	
	static int [][]grid;
	static int h,w;
	static List<Point> ans;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		 h = Integer.parseInt(sc.next());
		 w = Integer.parseInt(sc.next());
		 
		 grid = new int [h+1][w+1];
		 
		 for(int i = 1 ; i <= h ;i++) {
			 for(int j = 1 ; j <= w ; j++) {
				 grid[i][j] = Integer.parseInt(sc.next());
			 }
		 }
		 
		 ans = new ArrayList<Point>();
		 boolean flag = false;
		
		 for(int i = 1 ; i < h ; i++) {
			 for(int j = 1 ; j <= w ; j++) {
				 if(grid[i][j] % 2 == 1) {
					 grid[i+1][j]++;
					 ans.add(new Point(i,j,i+1,j));
				 }
			 }
		 }
		 
		 for(int i = 1 ; i < w ; i++) {
			 if(grid[h][i] % 2 == 1) {
				 ans.add(new Point(h,i,h,i+1));
				 grid[h][i+1]++;
			 }
		}
	
		System.out.println(ans.size());
		for(Point e : ans) {
			System.out.println(e.getY()+" "+e.getX()+" "+e.getYy()+" "+e.getXx());
		}
	}	
}
class Point {
	private int y;
	private int x;
	private int yy;
	private int xx;
	
	public Point (int y, int x , int yy, int xx) {
		this.y = y;
		this.x = x;
		this.yy = yy;
		this.xx = xx;
	}

	public int getY() {
		return y;
	}

	public int getX() {
		return x;
	}

	public int getYy() {
		return yy;
	}

	public int getXx() {
		return xx;
	}
	
	
}


Measured memory_bytes: 70588
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8,i8[:],i8)", cache=True)
def binary_search(N, A, K):
    """Meguru type binary search"""
    ng = 0
    ok = 10 ** 9 + 1

    def is_ok(N, A, K, min_v):
        Q = A // min_v
        R = A % min_v
        count = np.sum(Q + (R > 0)) - N
        if count <= K:
            return True
        else:
            return False

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(N, A, K, mid):
            ok = mid
        else:
            ng = mid

    return ok


def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)

    ans = binary_search(N, A, K)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 131592
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        int[] tmp = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            tmp[i] = x[i];
        }

        Arrays.sort(x);
        int can1 = x[n/2];
        int can2 = x[n/2 - 1];
        for (int i = 0; i < n; i++) {
            if (tmp[i] <= can2) {
                System.out.println(can1);
            } else {
                System.out.println(can2);
            }
        }
    }
}

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

int shortest(int i,int j,int x,int y){

int mini= min(abs(i-j),abs(x-i)+1+abs(j-y));
mini = min(mini,abs(y-i)+1+abs(x-j));
return mini;

}
using namespace std;

int main()
{
   int n,x,y;
   cin>>n>>x>>y;
   map<int,int>m;
   for(int i=1;i<n;i++){
        int count=0;
    for(int j=i+1;j<=n;j++){
       int f = shortest(i,j,x,y);
       if(m.count(f)) m[f]++;
       else m[f]=1;


    }


   }

   for ( int i=1;i<n;i++){
    if(!m.count(i))cout<<0<<endl;
    else cout<<m[i]<<endl;

   }
    return 0;
}


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

public class Main {
    static long mod = (int)Math.pow(10,9)+7;
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int level = 1;
		boolean is1 = false;
		int tmp = n;
		while(tmp != 1){
		    level++;
		    if(tmp % 2 != 0) is1 = true;
		    tmp >>= 1;
		}
		if(!is1)level--;
		//int[][] roads = new int[n][n];
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        for(int k = 0; k < level; k++){
		            if(((i >> k) % 2)+((j >> k) % 2) == 1){
		                sb.append((k+1) + " ");
		                break;
		            }
		        }
		    }
		    pw.println(sb.toString().trim());
		    sb.setLength(0);
		}
		pw.close();
	}
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}



Measured memory_bytes: 37844
n, k = list (map (int, input ().split ()))
p = [0] + list (map (int, input ().split ()))
s = [0 for i in range (n + 1)]
mx = 0
tag = 0
f = [0.0 for i in range (n + 1)]
for i in range (1, n + 1) :
    s[i] = s[i - 1] + (p[i] + 1) * p[i] / 2 / p[i]
    if (i >= k and s[i] - s[i - k] > mx) :
        mx = s[i] - s[i - k]
print (mx)



Measured memory_bytes: 24812
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"OK"<<endl;}else cout<<"NG"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
int main(){
    int k,a,b;
    cin>>k>>a>>b;
    bool ans=false;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            ans = true;
            break;
        }
    }
    YN(ans);
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
 
#define ll long long int 
#define endl '\n'
#define PI  3.14159265358979323846
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define MAX 1000
using namespace std;
 
//ll gcd(ll n,ll m){
//	if(m==0)
//	return n;
//	if(n<m)
//	swap(n,m);
//	while(n%m!=0)
//	{
//		ll temp=n;
//		n=m;
//		m=temp%m;
//	}
//	return m;
//}

//bool sortbysec(pair<int,int> &a,pair<int,int> &b) 
//{ 
//    return (a.second < b.second); 
//} 


int main() {
    ll n,w,i,j;
    cin>>n>>w;
    ll a[n][2],dp[n+1][w+1];
    for(i=0;i<n;i++)
    {
    	for(j=0;j<2;j++)
    	cin>>a[i][j];
	}
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=w;j++)
		{
			if(i==0 || j==0)
			dp[i][j]=0;
		   	else if(a[i-1][0]>j)
			dp[i][j]=dp[i-1][j];
			else
			{
				dp[i][j]=max(a[i-1][1]+dp[i-1][j-a[i-1][0]],dp[i-1][j]);
			}
		}
	}
	cout<<dp[n][w];
}






Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N,M;cin>>N>>M;

    if(N>=13) cout<<M<<endl;
    else if(6<=N && N<= 12) cout<<M/2<<endl;
    else cout<<0<<endl;

    return 0;
}


Measured memory_bytes: 384
# A - Rotation
# https://atcoder.jp/contests/abc077/tasks/abc077_a

a = input()
b = input()

result = 'YES'
i = 0
j = -1
while i < len(a):
    if a[i] != b[j]:
        result = 'NO'
        break
    i += 1
    j -= 1

print(result)


Measured memory_bytes: 8808
def f(x):
    if x == "r":
        return "p"
    elif x == "s":
        return "r"
    else:
        return "s"

def g(x):
    if x == "r":
        return r
    elif x == "s":
        return s
    else:
        return p 

n,k = map(int,input().split())

r,s,p = map(int,input().split())

t = str(input())

m = n
a = 0
ss = [' '] * m

if m <= k:
    for i in range(m):
        a += g(f(t[i]))
    print(a)
else:
    for i in range(k):
        a += g(f(t[i]))
        ss[i] = f(t[i])
    for i in range(k,m):
        if t[i-k] != t[i]:
            a += g(f(t[i]))
            ss[i] = f(t[i])
        elif (t[i-k] == t[i]) and (ss[i-k] != f(t[i])):
            a += g(f(t[i]))
            ss[i] = f(t[i])
    print(a)

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

using namespace std;


#define MAXN 101
#define MAXT 20001
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  int t[MAXN], v[MAXN];
  int mn[MAXT*2];
  memset(mn, 0x3f, sizeof(mn));
  cin >> n;
  t[0] = 0;
  v[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> t[i];
    t[i] *= 2;
    t[i] += t[i-1];

  }
  t[n+1] = MAXT*2-1;
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
    v[i] *= 2;
  }
  v[n+1] = 0;
  for (int i = 0; i <= n+1; ++i) {
    if (i) {
      for (int x = t[i-1]; x <= t[i]; ++x) {
        mn[x] = min(mn[x], v[i]);
      }
      if (i<n+1) {
        for (int x = 0; x <= t[i]; ++x) {
          mn[x] = min(mn[x], v[i+1]+t[i]-x);
        }
      }
    }
    if (i<n+1) {
      for (int x = t[i]; x < MAXT*2; ++x) {
        mn[x] = min(mn[x], v[i]+x-t[i]);
      }
    }
  }
  double ans = 0;
  for (int x = 1; x < MAXT*2; ++x) {
    ans += (double)min(mn[x], mn[x-1]);
    ans += (double)abs(mn[x] - mn[x-1])/2;
  }
  cout << setprecision(11) << ans/4 << endl;
  return 0;
}


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


int main(){
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  sort(a.begin(),a.end());
  int ans=0;
  for(int i=0;i<2;i++){
    ans+=a.at(i) -a.at(i+1);
  }
  cout << abs(ans) << endl;
  }

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [sys.stdin.readline()[:-1] for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

H, W = LI()
a = LSR(H)

#dp[H][W]
dp = [[0]*W for i in range(H)]

for i in range(W):
    if (a[0][i] == "#"):
        break
    dp[0][i] = 1
for i in range(H):
    if (a[i][0] == "#"):
        break
    dp[i][0] = 1

for i in range(1, H):
    for j in range(1, W):
        if (a[i][j] == "#"):
            continue
        if (a[i][j-1] != "#"):
            dp[i][j] += dp[i][j-1]
        if (a[i-1][j] != "#"):
            dp[i][j] += dp[i-1][j]
        if (dp[i][j] >= mod):
            dp[i][j] %= mod

print(dp[H-1][W-1])

Measured memory_bytes: 52848
// AOJ 3006: Chairs
// 2017.10.4 bal4u@uu

#include <stdio.h>

#define MAX		100003
int p[MAX];
int spool[MAX], *pt;
int *q[MAX], hi[MAX], hh[MAX];
int sp[MAX], top;
int ans[MAX];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

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

	n = in();
	for (i = 1; i <= n; i++) p[i] = j = in(), hh[j]++;

	pt = spool;
	for (i = 1; i <= n; i++) q[i] = pt, pt += hh[i];

	for (i = 1; i <= n; i++) j = p[i], q[j][hi[j]++] = i;

	top = 0;
	j = 2; while (j--) {
		for (i = 1; i <= n; i++) {
			while (hi[i]) sp[top++] = q[i][--hi[i]];
			if (!ans[i] && top) ans[i] = sp[--top];
		}
    }
 
	for (i = 1; i <= n; i++) printf("%d\n", ans[i]);
	return 0;
}


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

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

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

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void dfs(VVI &es, VLL &cnt, int par, int i) {
    for (auto &&dst: es[i]) {
        if (dst == par) continue;
        cnt[dst] += cnt[i];
        dfs(es,cnt,i,dst);
    }
}

void solve() {
    LL n,q;
    cin >> n >> q;
    VVI es(n);
    int a,b,p,x;
    VLL cnt(n);
    REP(i,0,n-1) {
        cin >> a >> b;
        --a; --b;
        es[a].push_back(b);
        es[b].push_back(a);
    }
    REP(i,0,q) {
        cin >> p >> x;
        --p;
        cnt[p] += x;
    }
    dfs(es,cnt,-1,0);
    REP(i,0,n) cout << cnt[i] << " ";
    cout << endl;
}

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

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

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;}
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T lcm(T a,T b){return a*b/gcd(a,b);}

const int INF=1e9;
const double eps=0.0000000001;


int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
   
  if(k%2==0){
    cout << a-b << endl;
  }else{
    cout << b-a << endl;
  }
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   string s, t;
   cin >> s >> t;

   int n = s.size();
   rep (i, n) {
      char c = s.back();
      s.pop_back();
      s = c + s;
      if (s == t) {
         puts("Yes");
         return 0;
      }
   }
         puts("No");

   return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;

  vll as(n);
  rep(i, n) cin >> as[i];

  vvll to(n);
  rep(i, m){
    ll x, y;
    cin >> x >> y;
    to[x].push_back(y);
    to[y].push_back(x);
  }

  if(n < 2*(n-m-1)){
    cout << "Impossible" << endl;
    return 0;
  } else if(m == n - 1){
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;

  vll lst;
  vll seen(n, 0);
  rep(i, n){
    if(seen[i]) continue;
    queue<ll> que;
    que.push(i);
    seen[i] = 1;
    vll ilst;
    ll mv = INF, midx = -1;
    while(!que.empty()){
      ll u = que.front();
      que.pop();
      if(as[u] < mv){
        mv = as[u];
        midx = ilst.size();
      }
      ilst.push_back(as[u]);
      for(ll v : to[u]){
        if(seen[v]) continue;
        seen[v] = 1;
        que.push(v);
      }
    }
    ans += mv;
    rep(j, (ll)ilst.size()){
      if(j != midx) lst.push_back(ilst[j]);
    }
  }
  Sort(lst);
  rep(i, n-m-2) ans += lst[i];

  cout << ans << endl;

  return 0;
}


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

/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/

using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int D, T, S;
    cin >> D >> T >> S;
    if ((D + (S - 1)) / S > T)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3608
import numpy as np

n=int(input())
l=np.array(list(x for x in input()))
w_left=0
e_right=n-(len(l[l=='W']))
ans=n

for i in range(n):
  if l[i]=='E':
    e_right-=1
  ans=min(ans,w_left+e_right)
  if l[i]=='W':
    w_left+=1

print(ans)

Measured memory_bytes: 30664
#include<bits/stdc++.h>
using namespace std;
int r[90001],c[90001],s[90001];
#define reps(i,n,m) for (int i = (n); i < m; i++)

int main() {
  int h,w,d; cin>>h>>w>>d;
  reps(i,0,h){
    reps(j,0,w){
      int n; cin >> n;
      r[n]=i;c[n]=j;
    }
  }
  reps(i,d+1,h*w+1) {
    s[i]=s[i-d]+abs(r[i]-r[i-d])+abs(c[i]-c[i-d]);
  }
  int q;cin>>q;
  while(q--){
    int a,b;cin>>a>>b;
    cout<<s[b]-s[a]<<endl;
  }
}


Measured memory_bytes: 2176
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		 new B().doIt();
	}
	
	class B{
		void doIt(){
			int n = in.nextInt();
			int input[] = new int[n];
			for(int i=0;i<n;i++)input[i] = in.nextInt();
			ArrayList<Integer> list = new ArrayList<Integer>();
//			list.add(input[1]-input[0]);
			for(int i=0;i<n-1;i++){
				int num = input[i+1]-input[i];
				if(i == 0 || list.get(list.size()-1)!=num)list.add(num);
			}
//			System.out.println(list);
			
			int kubo = 0;
			int sanp = 0;
			int mine = 0;
			int kougen = 0;
			int bon = 0;
			for(int i=0;i<list.size()-1;i++){
				int a = list.get(i);
				int b = list.get(i+1);
				if(a<0 && b>0)kubo++;
				else if(a>0 && b<0)mine++;
			}
			
			for(int i=0;i<list.size()-2;i++){
				int a = list.get(i);
				int b = list.get(i+1);
				int c = list.get(i+2);
				if(a<0 && b == 0 && c<0)sanp++;
				if(a>0 && b == 0 && c>0)sanp++;
				if(a>0 && b == 0 && c<0)kougen++;
				if(a<0 && b == 0 && c>0)bon++;
			}
			System.out.println(kougen+" "+bon + " " + sanp +" "+mine +" "+kubo);
			
		}
	}
	
}


Measured memory_bytes: 63900
x1, y1, x2, y2 = map(int, input().split())
x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (x2 - x1)
y4 = y3 - (y2 - y1)
print(' '.join(map(str, [x3, y3, x4, y4])))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

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

    int r = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] != l[j] && l[j] != l[k] && l[i] + l[j] > l[k]) r++;
            }
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define repprev(i,a,b) for(ll i=b-1;i>=a;i--)
#define reprev(i,n) repprev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1<<1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1<<2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1<<3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1<<4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1<<5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1<<6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1<<7) // 0000 0000 1000 0000
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    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;
    }
}
 
// 二項係数計算
long long COM(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;
}
 
struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
 
    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }
 
    ll root(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
 
    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }
 
    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
 
    ll size(ll x) {
        return -par[root(x)];
    }
};
 
template <typename T>
vector<T> dijkstra(int s,vector<vector<pair<int, T> > > & G){
   const T INF = numeric_limits<T>::max();
   using P = pair<T, int>;
   int n=G.size();
   vector<T> d(n,INF);
   vector<int> b(n,-1);
   priority_queue<P,vector<P>,greater<P> > q;
   d[s]=0;
   q.emplace(d[s],s);
   while(!q.empty()){
     P p=q.top();q.pop();
     int v=p.second;
     if(d[v]<p.first) continue;
     for(auto& e:G[v]){
       int u=e.first;
       T c=e.second;
       if(d[u]>d[v]+c){
         d[u]=d[v]+c;
         b[u]=v;
         q.emplace(d[u],u);
       }
     }
   }
   return d;
}
 
int main(){
    int a,b;
  	cin >> a >> b;
  	int ans = max(a,b);
  	if(a >= b) --a;
  	else --b;
  	ans += max(a,b);
  	cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    from collections import Counter
    def check(l):
        ll=[]
        for i in range(24):
            if l[i]:
                ll.append(i)
                ll.append(i+24)
        ll.sort()
        return min([ll[i+1]-ll[i] for i in range(len(ll)-1)])

    def dfs(d_dfs,l_dfs):
        if len(d_dfs)==0:
            return check(l_dfs)
        l_dfs1=[i for i in l_dfs]
        l_dfs2=[i for i in l_dfs]
        d_dfs1=[i for i in d_dfs]
        i=d_dfs1.pop()
        l_dfs1[i]=True
        l_dfs2[24-i]=True
        return max(dfs(d_dfs1,l_dfs1),dfs(d_dfs1,l_dfs2))

    n=int(input())
    a=list(map(int,input().split()))
    a=Counter(a)
    d=[]
    now=[False]*24
    now[0]=True
    if a[0]>0 or a[12]>1:
        print(0)
        return 0
    if a[12]==1:
        now[12]=True
    for i in range(1,12):
        if a[i]>2:
            print(0)
            return 0
        elif a[i]==2:
            now[i]=True
            now[24-i]=True
        elif a[i]==1:
            d.append(i)
    print(dfs(d,now))
main()

Measured memory_bytes: 3316
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
s = gets
w = inp[0]
i = 0
while (i < s.length)
  print s[i]
  i += w
end
puts 
#n = inp[0]
=begin
t = []
n.times do
  t.push(inp)
end  
=end


=begin
=end

Measured memory_bytes: 1788
n,m,c = map(int,input().split())

bl = list(map(int,input().split()))
al = [list(map(int,input().split())) for i in range(n)]
cnt = 0

for i in range(n):
    total = 0
    for j in range(m):
        total+=bl[j]*al[i][j]
    total+=c
    if 0 < total:
        cnt+=1
print(cnt)



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

int main() {
	int s;
	double w, h;
	char c;
	std::vector <int> fat;
	while (std::cin >> s >> c >> w >> c >> h) {
		if (w / h / h >= 25){
			fat.push_back(s);
		}
	}
	for (int i = 0; i < fat.size(); i++){
		cout << fat[i] << endl;
	}
	cin >> c;
	return 0;
}

Measured memory_bytes: 3036
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int a[3];
    for(int i = 0; i < 3; i++) cin >> a[i];
    sort(a, a+3);
    cout << a[2]*10 + a[1] + a[0];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int i;
  vector<int> l(n);
  for(i=0;i<n;i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  int sum = 0;
  for(i=0;i<n-1;i++){
    sum += l[i];
  }
  if(sum > l[n-1]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import math

N=int(input())

Nmax=round(math.sqrt(N))
Fmin=10000

for i in range(1,Nmax+1):
    if N%i==0 :
        Fmin=min(Fmin, max(len(str(int(i))), len(str(int(N/i)))))

print(Fmin)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include <string>
#include <utility>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
ll mod=1e9+7;
int cnt[100000];
int main(){
 	int n; cin >>n;
 	vector<int> p(n);
 	int cnt[n+1];
 	for(int i=1;i<=n;i++){
 		cin >>p[i];
 	}
 	int ans=0;
 	for(int i=1;i<n;i++){
 		if(p[i]==i){
 			swap(p[i],p[i+1]);
 			ans++;
 		}
 	}
 	if(p[n]==n) ans++;
 	cout << ans << endl;
 }

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n;
    cin>> n;
    int a[n+1],b[n];
    rep(i,n+1)cin >> a[i];
    rep(i,n)cin >> b[i];
    int ans = 0;
    int res;
    rep(i,n){
        res = min(b[i],a[i]);   
        b[i] -= res;
        ans += res;
        a[i] -= res;
        

        res = min(b[i],a[i+1]);
        b[i] -= res;
        ans += res;
        a[i+1] -= res;
        


    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline

N, K, *ab = map(int, read().split())
mod = 10 ** 9 + 7

graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(ab)] * 2):
    graph[a].append(b)
    graph[b].append(a)

queue = deque([1])
checked = [False] * (N + 1)
checked[1] = True
answer = K
colors = K - 1

while queue:
    v = queue.popleft()
    for go in graph[v]:
        if not checked[go]:
            checked[go] = True
            answer *= colors
            answer %= mod
            queue.append(go)
            colors -= 1
    colors = K - 2

print(answer)

Measured memory_bytes: 25964
n = int(input())
graph = [[0 for i in range(n)] for j in range(n)]
d = [0] * n
f = [0] * n
queue = [0]


for i in range(n):
   a = list(map(int, input().split()))
   for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1

f[0] = 1
while len(queue) != 0:
    i = queue.pop(0)
    for j in range(n):
        if (graph[i][j] == 1) & (f[j] == 0):
            queue.append(j)
            f[j] = 1
            d[j] = d[i] + 1

[print(i+1, d[i] if (i == 0) | (d[i] != 0) else -1) for i in range(n)]


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

using namespace std;

using ll = long long;

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

    int n;
    string s;
    cin >> n >> s;

    map<char, int> c;

    for (char e : s) {
        c[e]++;
    }
    
    ll res = 1;
    for (auto e: c) {
        res *= e.second + 1;
        res %= (ll) 1e9 + 7;
    }

    cout << res - 1 << '\n';

    return 0;
}


Measured memory_bytes: 512
a = [int(input()) for i in range(4)]
sum=0

for i in range(a[0]+1):
    for j in range(a[1]+1):
        for k in range(a[2]+1):
            if (i * 500 + j * 100 + k * 50) == a[3]:
                sum += 1
print(sum)


Measured memory_bytes: 2940
mod = 10**9 + 7
k = 5


class Lagrange:
    def __init__(self, lst):
        self.lst = lst
        self.mod = mod

    def prd(self, j, x):
        tmp = 1
        for i, (xi, yi) in enumerate(self.lst):
            if j != i:
                tmp *= (x - xi)
                tmp %= self.mod
        return tmp

    def pln(self, x):
        tmp = 0
        for i, (xi, yi) in enumerate(self.lst):
            tmp += yi * (self.prd(i, x) *
                         pow(self.prd(i, xi), self.mod - 2, self.mod))
            tmp %= self.mod
        return tmp


def cmb(x, y):
    if x < y:
        return 0
    tmp = 1
    for i in range(y):
        tmp *= x - i
        tmp *= pow(y - i, mod - 2, mod)
        tmp %= mod
    return tmp


def pln(n):
    tmp = 0
    for x in range(n):
        tmp += cmb(x + k - 1, k - 1) * cmb(n - (2 * x) + k, 2 * k)
        tmp %= mod
    return tmp


lst_eve = [(i, pln(i)) for i in range(0, 2 * (3 * k + 1), 2)]
lst_odd = [(i, pln(i)) for i in range(1, 2 * (3 * k + 1) + 1, 2)]

lag_eve = Lagrange(lst_eve)
lag_odd = Lagrange(lst_odd)

t = int(input())
for _ in range(t):
    n = int(input())
    if n % 2 == 0:
        print(lag_eve.pln(n))
    else:
        print(lag_odd.pln(n))


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    ll sumA = 0, sumB = 0;
    ll behB = 0;
    ll A[N],B[N];
    ll num_op = 0;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N){
        sumA += A[i]; sumB += B[i];
        if(A[i] > B[i]) behB += A[i]-B[i];
        else num_op += (B[i]-A[i])/2;
    }
    if(num_op - behB >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  ll M;
  cin >> M;
  ll ans = 0;
  ll keta = 0, sum = 0;
  REP(i, M){
    ll d; ll c;
    cin >> d >> c;
    keta += c;
    sum += d * c;
    // if(sum <= 9) continue;
    // ans += (sum-1) / 9;
    // sum %= 9;
    // if(sum == 0) sum++;
  }
  // assert(sum <= 9);
  ans += (sum-1) / 9;
  ans += keta-1;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    ll a, b;
    cin >> a >> b;
    cout << a * b << newl;

    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
 
#define NL '\n'
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define ll long long
#define sz(x) x.size()
#define all(x) (x).begin(), (x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define async() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 
//#define _debug 
void d(){cerr<<NL;}template<typename H,typename... T> void d(H h,T... t){cerr<<' '<<h;d(t... );}
#ifdef  _debug
#define debug(...) cerr<<"("<<#__VA_ARGS__<<"):",d(__VA_ARGS__)
#else
#define debug(...) 
#endif

const ll N = 43;
ll n, k, x, l = 41, cnt[N], dp[N][2];

ll f(ll pos, bool status){
	ll cur = !!(k&(1LL<<(l-pos)));
	if(pos == l) {
		if(status) {
			if(cur == 1) return max(cnt[0], n - cnt[0]);
			return cnt[0];
		}
		return max(cnt[0], n - cnt[0]);
	}
	ll &ret = dp[pos][status];
	if(ret > -1LL) return ret;
	ll m = (1LL << (l-pos)), val = 0;
	if(status) {
		if(cur == 0) val = m*cnt[l-pos] + f(pos + 1, true);
		else val = max(m*cnt[l-pos]+f(pos+1, false), m*(n-cnt[l-pos])+f(pos+1, true));
	}
	else val = max(m*cnt[l-pos]+f(pos+1, false), m*(n-cnt[l-pos])+f(pos+1, false));
	return ret = val;
}

int main() {
	async();
	mem(dp, -1LL);
	cin >> n >> k; 
	rep(ix, 0, n) {cin >> x; for(ll i = N - 1; i >= 0;i--) if(x&(1LL<<i)) cnt[i]++;} 
	cout << f(0, true);
}    


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


int main()
{
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int count = 0;
  for(int i = 0;i <= a;i++){
    for(int j = 0;j <= b;j++){
      for(int k = 0;k <= c;k++){
        if(x == (i*500 + j*100 + k*50)) count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.Unboxed          as AU
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n =
  replicateM n (map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine)

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n =
  replicateM n (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n (map BS.unpack . BS.words <$> BS.getLine)

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main :: IO ()
main = do
  s <- getLine
  print $ solve s

solve s = sum $ [f (tail nums) b [head nums] | b <- bit]
  where
    nums = map (read . (: "")) s
    bit = replicateM (length s - 1) [True, False]
    f :: Integral a => [a] -> [Bool] -> [a] -> a
    f [] [] acc = sum acc
    f (x:xs) (t:ts) acc@(a:as)
      | t = f xs ts (x : acc)
      | otherwise = f xs ts (a * 10 + x : as)


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n, k, q;
  cin >> n >> k >> q;

  vll a(n);
  set<ll> values;
  rep(i, n) {
    cin >> a[i];
    values.insert(a[i]);
  }

  ll ans = INF;

  // mv以上の値だけを取り出した場合のX-Yの値
  for (const auto mv : values) {
    ll l = 0, r = 0;

    vll cand;

    while (l < n) {
      priority_queue<ll, vll, greater<ll>> que;

      while (r < n && a[r] >= mv) {
        que.push(a[r]);
        r++;
      }

      if (r - l >= k) {
        ll cnt = r - l + 1 - k;
        while (cnt--) {
          ll v = que.top();
          que.pop();

          cand.push_back(v);
        }
      }

      l = r + 1;
      r = l;
    }

    if (cand.size() >= q) {
      sort(all(cand));
      chmin(ans, cand[q - 1] - cand[0]);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc127_a
{
    class Program
    {
        static void Main(string[] args)
        {         
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            if (a<=5)
            {
                Console.WriteLine("0");
            }
            else if(a<=12)
            {
                Console.WriteLine(b/2);
            }
            else
            {
                Console.WriteLine(b);
            }
            Console.Read();
        }
    }
}


Measured memory_bytes: 13140
from itertools import accumulate
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
odd = list(accumulate([0] + A[::2]))
even = list(accumulate([0] + A[::-1][::2]))
ans = max(odd[i] + even[N//2-i] for i in range(N//2+1))
if N % 2 == 1:
    dp = [0] * (N//2+1)
    for i in range(0, N-1, 2):
        dp[i//2+1] = max(odd[i//2+1], dp[i//2] + A[i+1])
    ans2 = max(dp[i] + even[N//2-i] for i in range(N//2+1))
    ans = max(ans, ans2)
print(ans)

Measured memory_bytes: 111208
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int a,b,c,d;
	string s;
	cin>>a>>b>>c;
	d = b*10+c;
	if(d%4==0){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}
	

Measured memory_bytes: 256