akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		int ki = 0;
		int si = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] % 2 != 0) {
				ki++;
			}
			if (a[i] % 4 == 0) {
				si++;
			}
		}
		if(n>si+ki){
		if (ki <= si) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}}else{
			if (ki <= si+1) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}	
		}
	}
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  loop {
    vi as(4);
    vector<bool> isin(10, false);
    rep (i, 4) {
      int a; cin >> a;
      as[i] = a;
      isin[a] = true;
    }
    int hit = 0;
    int blow = 0;
    rep (i, 4) {
      int b; cin >> b;
      if (isin[b]) ++blow;
      if (as[i] == b) ++hit;
    }
    blow -= hit;
    if (!cin) break;

    cout << hit << ' ' << blow << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
n = int(input())
ans = 1
maxcnt = 0
for i in range(1, n+1):
    cnt = 0
    now = i
    while (now % 2 == 0):
        now //= 2
        cnt += 1
    if cnt > maxcnt:
        maxcnt = cnt
        ans = i
print(ans)

Measured memory_bytes: 3060
n = int(input())
a = []
for i in range(n):
  ai = int(input())
  a.append(ai)

mx = max(a)
count = a.count(mx)

mx2 = -1
for i in a:
  if(mx2 < i and i != mx):
    mx2 = i

if(mx2 == -1):
  mx2 = mx
  
for i in a:
  if(i!=mx):
    print(mx)
  else:
    if(count>1):
      print(mx)
    else:
      print(mx2)

Measured memory_bytes: 12532
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    string s,t;
    cin >> s >> t;
    vector<int> p1(10000),p2(10000);
    int n = s.size();
    rep(i,n){
        if(p1[s[i]]==0){
            p1[s[i]] = t[i];
        }else{
            if(p1[s[i]]!=t[i]){
                cout << "No" << endl;
                return 0;
            }
        }
        if(p2[t[i]]==0){
            p2[t[i]] = s[i];    
        }else{
            if(p2[t[i]]!=s[i]){
                cout << "No" << endl;
                return 0;
            }

        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P=pair<int,int>;
using G=vector<vector<int>>;

int N, K;

int main(){
  cin >> N >> K;

  double prob = 0;

  for( int i=1; i<=N; i++){
    int p = i;
    double prob_i= 1; 
    while( p < K ){
      p *= 2;
      prob_i /= 2;
    }
  prob += (prob_i / N);
  }

  cout << fixed << setprecision(10);
  cout << prob<< endl;
}


Measured memory_bytes: 3784
use std::io::*;
use std::i64;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let n: i64 = read();
    let mut count: i64 = 0;
    for i in 0.. n{
	let m: i64 = read();
	if m != i+1{
	    count+=1;
	}
    }
    if count==0 || count==2{
	println!("YES");
    }else {
	println!("NO");
    }
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = (1 << 31) - 1;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, ans = 0, w, l;
vl A;
struct segtree {
	int N;
	vl dat;
	void init(int n) {
		N = 1;
		while (N < n) N *= 2;
		dat = vl(N * 2 + 1);
		for (int i = 0; i < 2 * N - 1; i++)
			dat[i] = 0;
	}
	// update k th element
	void add(int k, int a) {
		k += N - 1; // leaf
		dat[k] += a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
		}
	}
	// min [a, b)
	int query(int a, int b) { return query(a, b, 0, 0, N); }
	int query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return 0;
		if (a <= l and r <= b) return dat[k];
		int m = (l + r) / 2;
		return (query(a, b, k * 2 + 1, l, m) + query(a, b, k * 2 + 2, m, r));
	}
};

void input() {
	cin >> n >> q;
}


void solve() {
	segtree SEG;
	SEG.init(n);
	while (q--) {
		cin >> a >> b >> c;
		if (a == 0)SEG.add(b - 1, c);
		else cout << SEG.query(b-1, c) << endl;
	}
}

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


Measured memory_bytes: 7024
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
 
A, B = input().split()
A = int(A)
B = int(B.replace(".", "")) # 100倍
 
ans = A * B // 100
print(ans)

Measured memory_bytes: 9216
nn = 2002002
P = 10**9+7
fa = [1] + [0] * nn
for i in range(nn): fa[i+1] = fa[i] * (i+1) % P
f = lambda a, b: fa[a+b+2] * pow(fa[a+1] * fa[b+1], P-2, P) % P - 1
r1, c1, r2, c2 = map(int, input().split())
print((f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)) % P)

Measured memory_bytes: 71664
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
int A[3][200010], B[3];
int f(int x) {
    int ans = 0;
    while (x != 0) {
        x %= __builtin_popcount(x);
        ans++;
    }
    return ans;
}
int main() {
    int N; cin >> N;
    string X; cin >> X;
    int cnt = 0;
    for (auto c : X) if (c == '1') cnt++;
    A[0][0] = A[2][0] = 1;
    for (int i = 1; i < N; i++) {
        if (cnt >= 2) A[0][i] = A[0][i - 1] * 2 % (cnt - 1);
        A[2][i] = A[2][i - 1] * 2 % (cnt + 1);
    }
    for (int i = 0; i < N; i++) {
        if (X[N - 1 - i] == '0') continue;
        if (cnt >= 2) B[0] = (B[0] + A[0][i]) % (cnt - 1);
        B[2] = (B[2] + A[2][i]) % (cnt + 1);
    }
    for (int i = 0; i < N; i++) {
        if (X[i] == '0') {
            int a = (B[2] + A[2][N - 1 - i]) % (cnt + 1);
            cout << f(a) + 1 << '\n';
        } else if (cnt == 1) {
            cout << 0 << '\n';
        } else {
            int a = (B[0] - A[0][N - 1 - i] + cnt - 1) % (cnt - 1);
            cout << f(a) + 1 << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 5268
#include <iostream>
#include <vector>
#define llint long long

using namespace std;

llint W, N;
llint x[50005];
llint sumx[50005];
bool dp[50005];
vector<llint> vec;

bool check(llint m)
{
	vec.clear();
	vec.push_back(0);
	for(int i = 1; i <= N; i++) dp[i] = false;
	dp[0] = true;
	
	for(int i = 1; i < N; i++){
		llint ub = i, lb = 0, mid;
		while(ub - lb > 1){
			mid = (ub + lb) / 2;
			if(sumx[i]-sumx[mid-1]+(i-mid) <= W) ub = mid;
			else lb = mid;
		}
		auto p = lower_bound(vec.begin(), vec.end(), lb);
		if(p == vec.end()) continue;
		if(*p <= i-2){
			llint cost = (W - (sumx[i]-sumx[*p]) + (i-*p-2)) / (i-*p-1);
			if(cost <= m){
				dp[i] = true;
				vec.push_back(i);
			}
		}
	}
	{
		llint ub = N, lb = 0, mid;
		while(ub - lb > 1){
			mid = (ub + lb) / 2;
			if(sumx[N]-sumx[mid-1]+(N-mid) <= W) ub = mid;
			else lb = mid;
		}
		auto p = lower_bound(vec.begin(), vec.end(), lb);
		if(p != vec.end() && *p < N){
			dp[N] = true;
			vec.push_back(N);
		}
	}
	
	return dp[N];
}

int main(void)
{
	while(1){
		cin >> W >> N;
		if(W == 0 && N == 0) break;
		for(int i = 1; i <= N; i++) cin >> x[i];
		for(int i = 1; i <= N; i++) sumx[i] = sumx[i-1] + x[i];
		
		llint ub = W, lb = 0, mid;
		while(ub - lb > 1){
			mid = (ub + lb) / 2;
			if(check(mid)) ub = mid;
			else lb = mid;
		}
		cout << ub << endl;
	}
	return 0;
}


Measured memory_bytes: 4364
#include <iostream>

using namespace std;

int memo[100];

int fibonacci(int n) {
    if (memo[n] != -1) {
        return memo[n];
    }
    if (n == 0) { return 1; }
    if (n == 1) { return 1; }
    memo[n] = fibonacci(n - 1) + fibonacci(n - 2);
    return memo[n];
}

int main() {
    int n;
    cin >> n;
    fill(memo, memo + 100, -1);
    cout << fibonacci(n) << endl;
}

Measured memory_bytes: 3088
N = int(input())
A = []
B = []
C = []
for i in range(N):
    n,a=input().split()
    A.append(n)
    B.append(int(a))  
    C.append(i)
for i in range(N):
    c = i
    for k in range(i+1,N):
        if A[i] > A[k]:
            l = B[k]
            B[k] = B[i]
            B[i] = l
            l = A[k]
            A[k] = A[i]
            A[i] = l
            l = C[k]
            C[k] = C[i]
            C[i] = l
            
        elif A[i] == A[k]:
            if B[i] < B[k]:
                l = B[k]
                B[k] = B[i]
                B[i] = l
                l = A[k]
                A[k] = A[i]
                A[i] = l
                l = C[k]
                C[k] = C[i]
                C[i] = l
               

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



Measured memory_bytes: 3064
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
c = 0
for i in '0'*N:
    A = list(map(int, input().split()))
    res = sum(map(lambda ar:ar[0]*ar[1], zip(B,A))) + C
    c = c + 1 if res > 0 else c
print(c)

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def Z_algorithm(s):
    n = len(s)
    Z = [0]*n
    Z[0] = n
    i,j = 1,0
    while i < n:
        while i+j < n and s[j] == s[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
 
        #再利用部分
        while i+k < n and k+Z[k] < j:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z

n = I()
a = LI()
b = LI()

x = [a[i%n]^a[(i+1)%n] for i in range(2*n)]
y = [b[i%n]^b[(i+1)%n] for i in range(n)]
z = Z_algorithm(y+x)
for i in range(n,2*n):
    if z[i] >= n:
        k = i-n
        x = a[k] ^ b[0]
        print(k,x)


Measured memory_bytes: 119244
N = int(input())
R = 0

if N < 10:
	print(N)

elif N < 100:
	print(9)

elif N < 1000:
	print(N -90)

elif N < 10000:
	print(999-90)

elif N < 100000:
	print(N - 9090)

else:
	print(99999 - 9090)


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

int main(){
    int N;
    cin >> N;
    vector<int> boxes(N+1);
    vector<int> a(N+1);
    bool flag = false;
    for(int i = 0; i < N; i++) cin >> a.at(i+1);

    for(int i = N; i > 0; i--){
        int sum = 0;
        for(int j = 2* i; j <= N; j += i){
            sum += boxes.at(j);
        }
        if(sum % 2 != a.at(i)) boxes.at(i)++; 
    }
    vector<int> answer;
    for(int i = 1; i <= N; i++){
        if(boxes.at(i) == 1)answer.push_back(i);
    }
    cout << answer.size() << endl;
    for(int x:answer) cout << x << endl;
}

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<< name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define end_time()
#endif


#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007


void solve(){
	int n;
	cin>>n;
	double ans;
	if(n%2==0){
		ans = 0.5;
	}
	else{
		trace(n);
		ans = (double)((n/2)+1)/(double)n;
	}
	cout<<fixed<<setprecision(6)<<ans<<"\n";
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	end_time();
	return 0;
}

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

struct State{
  int x1, y1, x2, y2;
  State(int x1, int y1, int x2, int y2): x1(x1), y1(y1), x2(x2), y2(y2){}
};

const int MAX = 55;

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

int H, W;
char grid[2][MAX][MAX];
bool used[MAX][MAX][MAX][MAX];
int sx1, sy1, sx2, sy2;
int gx1, gy1, gx2, gy2;

bool isValid(int x, int y){
  return 0 <= x && x < W && 0 <= y && y < H;
}

bool solve(){
  queue<State> que;
  que.push(State(sx1, sy1, sx2, sy2));
  
  while(!que.empty()){
    State q = que.front(); que.pop();

    if(used[q.y1][q.x1][q.y2][q.x2]) continue;
    used[q.y1][q.x1][q.y2][q.x2] = true;
    
    for(int i = 0 ; i < 4 ; i++){
      int nx1 = q.x1 + dx1[i], ny1 = q.y1 + dy[i];
      int nx2 = q.x2 + dx2[i], ny2 = q.y2 + dy[i];      
      
      if(!isValid(nx1, ny1)) nx1 = q.x1, ny1 = q.y1;
      if(!isValid(nx2, ny2)) nx2 = q.x2, ny2 = q.y2;
      if(grid[0][ny1][nx1] == '#' && grid[1][ny2][nx2] == '#') continue;      
      if(grid[0][ny1][nx1] == '%' && grid[1][ny2][nx2] != '%') continue;      
      if(grid[0][ny1][nx1] != '%' && grid[1][ny2][nx2] == '%') continue;      
      
      if(grid[0][ny1][nx1] == '#') nx1 = q.x1, ny1 = q.y1;
      if(grid[1][ny2][nx2] == '#') nx2 = q.x2, ny2 = q.y2;
      
      que.push(State(nx1, ny1, nx2, ny2));
    }
  }
  return used[gy1][gx1][gy2][gx2];
}

void init(){
  memset(used, false, sizeof(used));
  memset(grid, '.', sizeof(grid));
}

int main(){
  while(cin >> W >> H, H|W){  
    init();
    
    for(int i = 0 ; i < H ; i++)
      for(int j = 0 ; j < 2 ; j++) cin >> grid[j][i];

    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	if(grid[0][i][j] == 'L') sx1 = j, sy1 = i;
	if(grid[0][i][j] == '%') gx1 = j, gy1 = i;
      }
    }
    
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	if(grid[1][i][j] == 'R') sx2 = j, sy2 = i;
	if(grid[1][i][j] == '%') gx2 = j, gy2 = i;
      }
    }    
    cout << (solve() ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 13448
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long N, long long M, std::vector<long long> H, std::vector<long long> A, std::vector<long long> B){
  vector<int> f(N+1);
  REP(x, M) {
    int a = H.at(A.at(x)-1);
    int b = H.at(B.at(x)-1);

    if (a > b) {
      f.at(B.at(x)) = true;
    } else
    if (a < b) {
      f.at(A.at(x)) = true;
    } else
    if (a == b) {
      f.at(A.at(x)) = true;
      f.at(B.at(x)) = true;
    }
  }

  da(f);
  int sum = 0;
  FOR1(x, N){
    if (f.at(x) == false) sum++;
  }
  cout << sum << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> H(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&H[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&A[i]);
    scanf("%lld",&B[i]);
  }
  solve(N, M, std::move(H), std::move(A), std::move(B));
}


Measured memory_bytes: 6428
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int n;
int m;
int q;

vector<int> a;
vector<int> b;
vector<int> c;
vector<LL> d;

vector<int> A(12);

LL dfs(vector<int> A, int idx){
    if(idx==n-1){
        //cout << idx << endl;
        LL ans=0;
        //cout << "list" << endl;
        //for(int i=0; i<n; i++){
        //    cout << A[i] << endl;
        //}
        //cout << "start" << endl;
        for(int i=0; i<q; i++){
            if(A[b[i]]-A[a[i]]==c[i]){
                ans+=d[i];
                //cout << i << " " << d[i] << " " << ans << endl;
            }
        }
        //cout << "end" << endl; 
        return ans;
    }

    LL ans=0;
    LL tmp_ans;
    for(int i=A[idx]; i<=m; i++){
        A[idx+1]=i;
        tmp_ans = dfs(A, idx+1);
        if(tmp_ans>ans){
            ans=tmp_ans;
        }
    }

    return ans;
}

int main() {
    int tmp_a;
    int tmp_b;
    int tmp_c;
    int tmp_d;
    LL ans=0;

    cin >> n >> m >> q;

    for(int i=0; i<q; i++){
        cin >> tmp_a >> tmp_b >> tmp_c >> tmp_d;
        tmp_a--;
        tmp_b--;
        a.push_back(tmp_a);
        b.push_back(tmp_b);
        c.push_back(tmp_c);
        d.push_back(tmp_d);
    }

    LL tmp_ans;
    for(int i=1; i<=m; i++){
        A[0]=i;
        tmp_ans = dfs(A, 0);
        if(tmp_ans>ans){
            ans=tmp_ans;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <map>

const int MAX = 3005;
const int MAX2 = MAX*MAX;

int n;
std::pair<int, int> AB[MAX];
int A[MAX];
int B[MAX];
int t;
int P[MAX][2*MAX];

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin >> n >> t;
    for (int i=1;i<=n;++i) std::cin >> AB[i].first >> AB[i].second;
    std::sort(AB+1, AB+n+1);
    for (int i=1;i<=n;++i) { A[i] = AB[i].first; B[i] = AB[i].second; }
    int result = 0;
    for (int i=1;i<=n;++i)
    {
        for (int j=0;j<t+MAX;++j)
        {
            if (j < A[i] || j-A[i] >= t) P[i][j] = P[i-1][j];
            else P[i][j] = std::max(P[i-1][j-A[i]] + B[i], P[i-1][j]);
            result = std::max(result, P[i][j]);
        }
    }
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;



int main(){
    ll x;
    cin >> x;
    if(x == 1){
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }
}

Measured memory_bytes: 3560
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int n, m, t, s, a[101], b[101], u, v;

  while(cin>>n>>m && (n+m)){
    bool f = true;
    u = v = 0;
    for(int i = 0; i < n; i++){
      cin >> a[i];
      u += a[i];
    }
    for(int j = 0; j < m; j++){
      cin >> b[j];
      v += b[j];
    }
    sort(a, a+n);
    sort(b, b+m);
    t = s = 101;

    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
	if((u-a[i]+b[j]) == (v-b[j]+a[i]) && t+s > a[i]+b[j]){
	  s = a[i];
	  t = b[j];
	  f = false;
	}
      }
    }

    if(f){
      cout << -1 << endl;
    } else {
      cout << s << " " << t << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
typedef long long ll;

int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n+10], b[m+10];
    for(ll i=0; i<n; ++i){cin >> a[i];}
    for(ll i=0; i<m; ++i){cin >> b[i];}

    ll t = 0; 
    for(ll i=0; i<m; ++i){t += b[i];}

    ll res = 0;
    ll j = m;
    for(ll i=0; i<=n; ++i){
        while(j>0 && t>k){
            --j; t -= b[j];
        }
        if(t>k){break;}
        res = max(res, i+j);
        if(i==n){break;}
        t += a[i];
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6708
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 0;
	string S; cin >> S; 

	long mylen = S.length();
	for (int i = 1; i < mylen; i++) if (S[i - 1] != S[i]) res++;

	cout << res << endl;
}

Measured memory_bytes: 512
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "math"
  "sort"
)

// 行単位で読み込む場合
var sc = bufio.NewScanner(os.Stdin)

func main() {
  nums, a, b, c := nextLine(), nextLine(), nextLine(), nextLine()
  X, _ := strconv.Atoi(strings.Fields(nums)[0])
  Y, _ := strconv.Atoi(strings.Fields(nums)[1])
  // Z := strings.Fields(nums)[2]
  K, _ := strconv.Atoi(strings.Fields(nums)[3])
  As := arrayAtoi(strings.Fields(a))
  Bs := arrayAtoi(strings.Fields(b))
  Cs := arrayAtoi(strings.Fields(c))

  ABs := []int{}
  for _, A := range As {
    for _, B := range Bs {
      ABs = append(ABs, A + B)
    }
  }
  sort.Ints(ABs)
  ABs = reverseNum(ABs)
  AB3000 := ABs[:int(math.Min(float64(X * Y), 3000))]

  ABCs := []int{}
  for _, C := range Cs {
    for _, AB := range AB3000 {
      ABCs = append(ABCs, C + AB)
    }
  }
  sort.Ints(ABCs)
  ABCs = reverseNum(ABCs)
  
  for i:=0; i<K; i++ {
    fmt.Println(ABCs[i])
  }
}

// 行を読む
func nextLine() string {
  sc.Scan()
  return sc.Text()
}

// 配列中の文字列を全て数値に変換
func arrayAtoi(array []string) []int {
  retarray := []int{}
  for _, v := range array {
    num, e := strconv.Atoi(v)
    if e != nil {
      panic(e)
    }
    retarray = append(retarray, num)
  }
  return retarray
}

// 配列を逆転する
func reverseNum(array []int) []int {
  for i, j := 0, len(array) - 1; i < j; i, j = i + 1, j - 1 {
    array[i], array[j] = array[j], array[i]
  }
  return array
}

Measured memory_bytes: 112256
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include<string>
#include <bitset>

#define SIZE 20
typedef long long ll;
 
using namespace std;


int main(){
    int N,Y;
    int flg = 1;
    cin >> N >> Y;
    for(int i = 0 ; i <= N ;i++){
        for(int j = 0 ; j <= (N-i) ; j++){
            if(10000*i + 5000*j + 1000*(N-i-j) == Y){
                cout << i <<" "<< j <<" "<< (N-i-j) ;
                flg--;
            }

        }
        if(!flg){
            break;        
        }
    }
    if(flg){
        cout << "-1 -1 -1";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int a,b,v,w,t;
    cin >> a >> v;
    cin >> b >> w;
    cin >> t;
    if(v <= w)puts("NO");
    else if((double)abs(a-b)/abs(v-w) > t) puts("NO");
    else puts("YES");

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;


}

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

int N = 100010;

int min(int a, int b)
{
    return a < b ? a : b;
}

int main()
{
    int n;
    int h[N];
    int dp[N];

    // initialize array
    memset(h, 0, sizeof(h));
    memset(dp, 0, sizeof(h));

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

    // dp
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    if (n == 2)
    {
        cout << dp[1];
        return 0;
    }

    for (int i = 2; i < n; i++)
    {
        dp[i] = min(
            dp[i - 2] + abs(h[i - 2] - h[i]),
            dp[i - 1] + abs(h[i - 1] - h[i]));
    }

    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1272
def main():
    from builtins import int, map, list, print
    from collections import defaultdict, deque
    from bisect import bisect_left
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number_list = (lambda: list(map(int, input_list())))

    N, M = input_number_list()
    pref = [[0] for i in range(N + 1)]
    q = deque()
    for i in range(M):
        p, y = map(int, input_number_list())
        pref[p].append(y)
        q.append((p, y))
    for p in pref:
        p.sort()
    for p, y in q:
        print('{:06}{:06}'.format(p, bisect_left(pref[p], y)))


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;

int main(void) {
	int num, m, a, b, i, j = 0;
	ll ans = 0;
	cin >> num >> m;
	vector<pair<int, int>> d(num);
	priority_queue<int> que;
	for (i = 0; i < num; i++) {
		scanf("%d%d", &a, &b);
		d[i] = make_pair(a, b);
	}
	sort(d.begin(), d.end());
	j = 0;
	for (i = 1; i <= m; i++) {
		while (j < num && d[j].first == i) {
			que.push(d[j].second);
			j++;
		}
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);

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

  vi taste(n);
  int mi = INF;
  int x;
  rep(i,n) {
    taste[i] = l + i;
    if (mi > abs(l+i)) {
      mi = abs(l+i);
      x = l+i;
    }
  }

  int sum = 0;
  rep(i,n) {
    sum += taste[i];
  }
  int ans = sum - x;

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

Measured memory_bytes: 256
using System;
using System.Linq;

class AtCoder {
  public static void Main() {
    var inputs = Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToList();
    var H = inputs[0];
    var A = inputs[1];
    var ans = 0;
    while(H > 0) {
      H -= A;
      ans++;
    }
    Console.WriteLine(ans);
  }
}

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

int main(){
    string str = "";
    cin >> str;
    std::map<char, char> dna;
    dna['A'] = 'T';
    dna['C'] = 'G';
    dna['G'] = 'C';
    dna['T'] = 'A';

    for(int i = 0; i < str.size(); i++){
        cout << dna[str.at(i)];
    }
    cout << endl;
}

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

using namespace std;

int main(){
  int K=0;
  auto sum=0ll;
  cin>>K;
  sum+=3*K*K-3*K+1;

  for(auto i=2;i<=K;++i)
    for(auto j=2;j<=K;++j)
      for(auto l=2;l<=K;++l)
        sum+=gcd(gcd(i,j),l);
  cout<<sum<<endl;
}

Measured memory_bytes: 3644
#pragma GCC optimize(3)
#include<iostream>
#include<cstdio>
#define re register
using namespace std;
int t[100000+10];
inline int read()
{
	re int n=0,ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')
		{
			n=(n<<3)+(n<<1)+ch-'0';
			ch=getchar();
		}
	return n;
}
void write(int n)
{
	if(n>=10)write(n/10);
	putchar(n%10+'0');
}
int main()
{
	re int s=0,N,M;
	N=read();
	for(re int i=1;i<=N;++i)
		{
			t[i]=read();
			s+=t[i];
		}
	M=read();
	re int p,x;
	for(re int i=1;i<=M;++i)
		{
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << abs(a - b) + abs(b - c) + abs(c - a) - max({abs(a - b), abs(b - c), abs(c - a)}) << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

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

using namespace std;

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

int top[3][3];
int front[3][3];
int rights[3][3];

set<int> s;


const int dice[6][6]={
	{0,3,5,2,4,0},
	{4,0,1,6,0,3},
	{2,6,0,0,1,5},
	{5,1,0,0,6,2},
	{3,0,6,1,0,4},
	{0,4,2,5,3,0}
};
const int val[6][4]={{2,3,4,5},{1,3,4,6},{1,2,5,6},{1,2,5,6},{1,3,4,6},{2,3,4,5}};

bool check(int f1,int f2,int f3,int t1,int t2,int t3){
	rep(mask,1<<6){
		int t[3]={t1,t2,t3},f[3]={f1,f2,f3};
		rep(i,3) if(f[i]==0)  f[i]=val[rights[i][0]-1][mask>>(2*i)&3];	
		rep(j,3) if(t[j]==0)  t[j]=7-dice[rights[0][j]-1][f[0]-1];
		
		bool ok=true;
		rep(j,3) if(t[j]==7) ok=false;
		if(ok==false) continue;

		rep(i,3)rep(j,3) if(dice[t[j]-1][f[i]-1]!=rights[i][j]) ok=false;
		if(ok) return true;
	}
	return false;
}

void dfs(vector<int> ary,int idx){
	if(idx==6){
		rep(i,3)rep(j,3) rights[i][j]=dice[ary[j+3]-1][ary[i]-1];
		rep(i,3)rep(j,3) if(rights[i][j]==0) return;


		// rep(i,3){
		// 	rep(j,3) cout << rights[i][j] << " ";
		// 	cout << endl;
		// }
		// cout << "----" << endl;

		rep(i,3) if(check(front[0][i],front[1][i],front[2][i],top[2][i],top[1][i],top[0][i])==false) return;
		int sum=0;
		rep(i,3)rep(j,3) sum+=rights[i][j];
		s.insert(sum);
		return ;
	}

	if(ary[idx]!=0){
		dfs(ary,idx+1);
		return;
	}
	
	for(int i=1;i<=6;++i){
		ary[idx]=i;
		dfs(ary,idx+1);
	}
}


int main(void){
	int t;
	cin >> t;
	while(t--){
		s.clear();
		rep(i,3)rep(j,3) cin >> top[i][j];
		rep(i,3)rep(j,3) cin >> front[i][j];
		
		vector<int> ary={front[0][0],front[1][0],front[2][0],top[2][0],top[1][0],top[0][0]};

		dfs(ary,0);

		if(int(s.size())==0)
			cout << 0 << endl;
		else{
			bool first=true;
			for(auto &it:s) cout <<  (first?"":" ") << it,first=false;
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3100
n = int(input())
A = list(map(int, input().split()))
count = 0

for i in range(n):
    j = i
    while(j>=1):
        if A[j] < A[j-1]:
            v = A[j-1]
            A[j-1] = A[j]
            A[j] = v
            count += 1
        j -= 1

print(" ".join(map(str, A)))
print(str(count))


Measured memory_bytes: 5596
n = int(input())
a = [[0 for i in range(10)] for j in range(10)]
for i in range(1, n+1):
    s = str(i)
    if s[-1] != '0':
        a[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += a[i][j] * a[j][i]
print(ans)

Measured memory_bytes: 9156
s,c=[int(i) for i in input().split()]

def cul(s,c):
  if s < c // 2:
    x = min(s,c//2)
    x += max(c - s * 2, 0)//4
  else:
    x = min(s,c//2)
  return x
print(cul(s,c))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666;
int n,c[N],mx[N],fa[N],dep[N],dl[N],dr[N],num;Vi e[N];
void dfs(int u,int Fa,int Dep,int Mx){
	fa[u]=Fa;dep[u]=Dep;mx[u]=Mx;dl[u]=++num;
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=Fa)dfs(e[u][i],u,Dep+1,max(Mx,e[u][i]));
	dr[u]=num;
}
Vi dot[N];int f[N],sz[N],tag[N],v[N];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
void add(int p, int x){while(p<=n)v[p]+=x,p+=p&-p;}
int query(int p){int r=0;while(p)r+=v[p],p-=p&-p;return r;}
void merge(int x, int y){x=find(x);y=find(y);f[x]=y;}
int qrysz(int u){return sz[u]+query(dr[u])-query(dl[u]-1);}
void modify(int u){
	sz[u]=1;
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa[u]&&sz[e[u][i]])
		sz[u]+=qrysz(e[u][i]),merge(e[u][i],u);
	if(sz[fa[u]]){merge(u,fa[u]);int v=find(u);add(dl[fa[u]],sz[u]);if(fa[v])add(dl[fa[v]],-sz[u]);}
}
void dfs1(int u){
	c[u]+=tag[u];
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa[u])tag[e[u][i]]+=tag[u],dfs1(e[u][i]);
}
int main() {
	read(n);rep(i,2,n){int u,v;read(u);read(v);e[u].pb(v);e[v].pb(u);}
	dfs(1,0,0,1);rep(i,2,n)c[i]=dep[i];
	rep(i,2,n)if(dep[i]>=2)dot[mx[fa[fa[i]]]].pb(i);
	rep(i,1,n)f[i]=i;
	rep(i,1,n){
		modify(i);rep(j,0,SZ(dot[i])-1){
			int u=dot[i][j];int r=qrysz(u);
			tag[fa[u]]+=r;tag[u]-=r;
		}
	}
	dfs1(1);rep(i,2,n)printf("%d ",c[i]);
	return 0;
}


Measured memory_bytes: 77816
using System;

class ABC070A
{
	static public void Main(string[] args)
	{
		int A,B,C,D;

		string[] vals = Console.ReadLine().Split(' ');
		A = int.Parse(vals[0]);
		B = int.Parse(vals[1]);
		C = int.Parse(vals[2]);
		D = int.Parse(vals[3]);
		

		if(D < A || B < C )
		{
			Console.WriteLine(0);
		}
		else
		{
			int s, e;

			if(A <= C)
			{
				s = C;
			}
			else
			{
				s = A;
			}

			if(B <= D)
			{
				e = B;
			}
			else
			{
				e = D;
			}
			Console.WriteLine(e - s);
		}
		

	}
}


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

int main(){
  long long N;
  cin >> N;
  if(N<=9){
    cout << N << endl;
  }
  else if(N<=99){
    cout << 9 << endl;
  }
  else if(N<=999){
    cout << N-90 << endl;
  }
  else if(N<=9999){
    cout << 909 << endl;
  }
  else if(N<=99999){
    cout << N-9090 << endl;
  }
  else if(N<=999999){
    cout << 90909 << endl;
  }
}
    
  


Measured memory_bytes: 256
N = int(input())
say = []
for i in range(N):
    A = int(input())
    t = []
    for j in range(A):
        s = list(map(int,input().split()))
        t.append(s)
    say.append(t)

a = 0
for i in range(2**N):
    judge = 1 
    
    for j in range(N):
        if judge == 0:
            break
        if ((i >> j) & 1):
            for k in range(len(say[j])):
                if ((i>>(say[j][k][0]-1))&1) != say[j][k][1]:
                    judge = 0
    
    if judge:
        c = bin(i).count("1")
        a = max(a,c)
print(a)

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

int main() {
    int D;
    cin >> D;
    int d[26];
    vector<int> last(26, 1);

    rep(i, 26) {
        cin >> d[i];
    }

    vector<vector<int>> s(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    ll level = 0;
    rep(i, D) {
        int t;
        cin >> t;
        t--;

        level += s[i][t];
        last[t] = 0;

        rep(j, 26) {
            level -= d[j] * last[j];
            last[j]++;
        }

        cout << level << "\n";
    }

    return 0;
}

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

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble
    ll r;
    cin>>r;
    ld x=2*(3.14)*r;
    cout<<preci(3)<<x<<nl;
    return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> VI;
typedef vector<ll> VLL;

int main(){
    ll n,k,ans=0;
    cin >> n >> k;
    VLL h(n);
    for(ll i=0; i<n; ++i)cin >> h[i];

    for(ll i=0 ; i<n; ++i){
        if(h[i] >= k){
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	int a[3];
	for(int i=1;i<=3;i++){
		cin>>a[i];
	}
	for(int i=1;i<=3;i++){
		for(int j=i+1;j<=3;j++){
			if(a[i]>a[j])swap(a[i],a[j]);
		}
	}
	cout<<a[1]+a[2];
	return 0;
}

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

using namespace std;

int main(){
	int a, b, takahashi;
	cin >> a >> b;

	takahashi = a - 1;
	if(a<=b) takahashi += 1;
	cout << takahashi;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std ;
template< class T > inl T read() {
	T x = 0 ; int f = 1 ; char k = getchar() ;
	for( ; k > '9' || k < '0'; k = getchar() ) if( k == '-' ) f = -1 ;
	for( ; k >= '0' && k <= '9'; k = getchar() ) x = x * 10 + k - '0' ;
	return x * f ;
}
template< class T > inl T read( T &x ) { return x = read<T>() ; }
int _num, _buf[20];
template< class T > il print( T x ) {
   	if( x == 0 ) return putchar( '0' ) ,void() ;
	if( x < 0 ) putchar( '-' ), x = -x ;
	while( x ) _buf[++_num] = x % 10, x /= 10 ;
	while( _num ) putchar( _buf[_num--] + '0' ) ;
}
ll mul( ll a, ll b, ll mod ) { long double c = 1. ; return ( a * b - (ll)( c * a * b / mod ) * mod ) % mod ; }
it qpow( int x, int m, int mod ) {
	int res = 1, bas = x ;
	while(m) {
		if( m & 1 ) res = ( 1ll * res * bas ) % mod ;
		bas = ( 1ll * bas * bas ) % mod, m >>= 1 ;
	}
	return res ;
}
ll n, m, sum, pw[100];
vector<int> vec;
int main() {
//	freopen( ".in", "r", stdin ) ;
//	freopen( ".out", "w", stdout ) ;
	n = read<ll>() ;
	pw[0] = 1 ;
	for( m = 1; sum < n; ++m ) {
		pw[m] = pw[m - 1] * 26 ;
		sum += pw[m] ;
	}
	for( ri i = 0; i < m - 1; ++i )
		n -= pw[i] ;
	for( ri i = 1; i < m; ++i ) {
		vec.push_back( n % 26 ) ;
		n /= 26 ;
	}
	for( ri i = m - 2; i >= 0; --i )
		putchar( vec[i] + 'a' ) ;
	puts( "" ) ;
	return 0;
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A,B,C=map(int,input().split())
    YesNo(A+B>=C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>
#include<utility>
#include<iomanip>

using ULLI = unsigned long long int;
using LLI = long long int;

using namespace std;

template<class T>
class ModCal{
private:
    const ULLI MAX = 1000000;
    ULLI mod;

    std::vector<T> fac;
    std::vector<T> finv;
    std::vector<T> inv;

    void COMinit() {
        fac.resize(MAX);
        finv.resize(MAX);
        inv.resize(MAX);

        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
public:
    ModCal(ULLI _mod){
        this->mod = _mod;
        ModCal<T>::COMinit();
    }
    ModCal(){
        this->mod = 0;
    }

    T add(T a, T b){
        T tmp;
        tmp = a + b;
        if(mod != 0) tmp %= mod;
        return tmp;
    }

    T sub(T a, T b){
        T tmp;
        tmp = a - b;
        if(mod != 0){
            if(tmp < 0) tmp += mod;
            tmp %= mod;
        }
        return tmp;
    }

    T mul(T a, T b){
        T tmp;
        tmp = a * b;
        if(mod != 0) tmp %= mod;
        return tmp;
    }

    T modinv(T a, T m){
        T b = m, u = 1, v = 0;
        while (b) {
            T t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }

    T div(T a, T b){
        if(mod == 0){
            return a / b;
        }
        a %= mod;
        T tmp = a * ModCal<T>::modinv(b, mod) % mod;
        return tmp;
    }

    T pow(T a, T b){
        T tmp = 1;
        while(b > 0){
            if(mod != 0){
                if(b & 1) tmp = tmp * a % mod;
                a = a * a % mod;
            }else{
                if(b & 1) tmp *= a;
                a *= a;
            }
            b >>= 1;
        }
        return tmp;
    }

    // 以下の関数はMODを設定しない限り使えない
    // 無理やり使う場合は "ModCal<T> cal(Tの最大値)" でオブジェクトを作る
    T com(T n, T k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }

    T fact(T n){
        return fac[n];
    }
};

struct S{
    int A;
    int B;
    double v;

    S(int A, int B){
        this->A = A;
        this->B = B;
    }

    bool operator<(const S &l) const{
        return static_cast<double>(B)/A < static_cast<double>(l.B)/l.A;
    };
};

int main() {
    int N;
    vector<ULLI> A;
    cin >> N;

    for(int i=0;i<N;i++){
        ULLI _A;
        cin >> _A;
        A.push_back(_A);
    }

    ULLI l_sum = 0;
    ULLI r_sum = std::accumulate(A.begin(), A.end(), 0LL);
    ULLI predif = llabs(l_sum-r_sum);
    int idx=0;

    for(int i=0;i<N;i++){
        l_sum += A[idx];
        r_sum -= A[idx];
        if(predif < llabs(l_sum-r_sum)) break;
        predif = llabs(l_sum-r_sum);
        idx++;
    }
    cout << predif << endl;
    return 0;
}

Measured memory_bytes: 2420