akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a) 
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a) 
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) { 
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n; cin >> n;
	vs a(n);
	ll cnt = 1;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	for (int i = 0; i < n - 1; i++) {
		if (a[i] != a[i + 1]) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 9576
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;


int main()
{
	int a;
	cin >> a;
	if(a >= 30)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No"; 
	}
}



Measured memory_bytes: 3632
n,a,b = map(int,input().split())

def find_of_digits(num):
    sum = 0
    while num>0:
        sum += num % 10
        num //= 10

    return sum

total = 0
for i in range(1,n+1):
    s = find_of_digits(i)
    if s >= a and s <= b:
        total += i

print(total)

Measured memory_bytes: 9184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);

    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");
    int n = Integer.parseInt(sl[0]);

    long a[] = new long[100004];
    long b[] = new long[100004];
    long c[] = new long[100004];
    s = r.readLine();
    sl = s.split(" ");

    for (int i = 0; i < n; i++)
    {
      a[i] = Long.parseLong(sl[i]);
    }

    b[0] = a[0];
    c[n - 1] = a[n - 1];
    for (int i = 1; i < n; i++)
    {
      b[i] = gcd(b[i - 1], a[i]);
    }
    for(int i = n - 2; i >= 0; i--)
    {
      c[i] = gcd(c[i + 1], a[i]);
    }

    long m = Math.max(b[n - 2], c[1]);
    for(int i = 1; i <= n - 2; i++)
    {
      m = Math.max(m, gcd(b[i - 1], c[i + 1]));
    }
    System.out.println(m);
  }

  public static long gcd(long m, long n)
  {
    if (m < n)
      return gcd(n, m);
    if (n == 0)
      return m;
    return gcd(n, m % n);
  }

}

Measured memory_bytes: 53524
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N, D, X;	cin >> N >> D >> X;
	vector<int> A;
	int inputA;
	int answer = 0;
	for (int i = 0; i < N; ++i) {
		cin >> inputA;
		A.push_back(inputA);
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0;; ++j) {
			if (j*A[i] + 1 <= D) {
				++answer;
			}
			if (j*A[i] + 1 > D) {
				break;
			}
		}
	}
	cout << answer + X << endl;
	cin >> N;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
std::ostream& operator<<(std::ostream& os, __int128 T)
{
    if (T<0) os<<"-";if (T>=10 ) os<<T/10;if (T<=-10) os<<(-(T/10));
    return os<<( (int) (T%10) >0 ? (int) (T%10) : -(int) (T%10) ) ;
}
int w[110],sum[110];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>w[i];
		sum[i]=sum[i-1]+w[i];
	}
	int Sum=sum[n];
	int ans=0x3f3f3f3f;
	for(int i=1;i<=n;i++)
	{
		ans=min(ans,abs(sum[i]-(Sum-sum[i])));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1}; 
const int mod = 1e9+7;
const ll N = 1e6+4;

int cnt[N];

void solve(){
	int n;
	cin>>n;
	vector<int>a(n);
	int g=0;
	rep(i,n){
		cin>>a[i];
		g=__gcd(g,a[i]);
	}
	if(g>1){
		cout<<"not coprime";
		return;
	}
	sort(all(a));
	reverse(all(a));
	for(int i=0;i<n;++i){
		for(int j=2;j*j<=a[i];++j){
			if(a[i]%j==0){
				if(cnt[j]){
					cout<<"setwise coprime";
					return;
				}
				cnt[j]++;
				while(a[i]%j==0){
					a[i]/=j;
				}
			}	
		}
		if(a[i]>1){
			if(cnt[a[i]]){
				cout<<"setwise coprime";
				return;
			}
			cnt[a[i]]=1;
		}
	}
	cout<<"pairwise coprime";

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 7496
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n],ans=1;
	for(int i=0;i<n;i++)
	  cin>>a[i];
	bool up=false,down=false;
	for(int i=0;i<n-1;i++){
		if(a[i]<a[i+1])
		  up=true;
		if(a[i]>a[i+1])
		  down=true;
		if(up && down){
			up=false; down=false;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    N = si()
    S = ss()
    rr = 0
    gg = 0
    bb = 0
    ans = 0
    for i in range(N):
        if S[i] == 'R':
            rr += 1
        elif S[i] == 'B':
            bb += 1
        elif S[i] == 'G':
            gg += 1
    ans = rr*gg*bb
    for i in range(N-2):
        for j in range(i+1, N-1):
            if S[i] != S[j] and 2*j-i < N and S[i] != S[2*j-i] and S[j] != S[2*j-i]:
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68564
using System;
using System.Collections.Generic;
using System.Linq;

namespace x
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = IOUtils.ReadInt();
            var s = n.ToString().Select(c => int.Parse(c.ToString())).Sum();
            System.Console.WriteLine(n % s == 0 ? "Yes": "No");

        }
    }
    
    static class IOUtils
    {

        public static IEnumerable<int[]> ReadIntLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadInts();
            }
        }
        public static IEnumerable<long[]> ReadLongLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadLongs();
            }
        }
        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        public static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        public static ulong ReadUlong()
        {
            return ulong.Parse(Console.ReadLine());
        }
        public static int[] ReadInts()
        {
            return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        }
        public static long[] ReadLongs()
        {
            return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
        }

        public static void WriteNums(params int[] nums)
        {
            Console.WriteLine(string.Join(" ", nums));
        }
    }
}


Measured memory_bytes: 13268
n,l=gets.split.map(&:to_i)
ans = (1..n).map{|i| i+l-1}
min_i =400
ans.each do |i|
  if i.abs < min_i.abs
    min_i = i
  end
end
ans.delete_at(ans.index(min_i))
puts ans.inject(:+)

Measured memory_bytes: 1788
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			List<List<Pair>> cost = new ArrayList<List<Pair>>();
			List<List<Pair>> time = new ArrayList<List<Pair>>();
			for (int i = 0; i < m; i++) {
				cost.add(new ArrayList<Pair>());
				time.add(new ArrayList<Pair>());
			}
			for (int i = 0; i < n; i++) {
				int a = scanner.nextInt() - 1;
				int b = scanner.nextInt() - 1;
				int c = scanner.nextInt();
				int d = scanner.nextInt();
				cost.get(a).add(new Pair(b, c));
				cost.get(b).add(new Pair(a, c));
				time.get(a).add(new Pair(b, d));
				time.get(b).add(new Pair(a, d));
			}
			int s = scanner.nextInt();
			for (int i = 0; i < s; i++) {
				int a = scanner.nextInt() - 1;
				int b = scanner.nextInt() - 1;
				int c = scanner.nextInt();
				if (c == 0) {
					slove(a, b, cost);
				}else{
					slove(a, b, time);
				}
			}

		}

	}

	private void slove(int s, int g, List<List<Pair>> cost) {
		int[] map = new int[m];
		Arrays.fill(map, 1 << 24);
		map[s] = 0;
		PriorityQueue<Pair> pq = new PriorityQueue<Pair>();
		boolean[] color = new boolean[m];
		pq.add(new Pair(0, s));
		while (!pq.isEmpty()) {
			Pair pair = pq.poll();
			int a = pair.a;
			int b = pair.b;
			color[b] = true;
			if(map[b]<a)
				continue;
			for (int i = 0; i < cost.get(b).size(); i++) {
				int v = cost.get(b).get(i).b;
				int o = cost.get(b).get(i).a;
				if(color[o])
					continue;
				if (map[o] > v + a) {
					map[o] = v + a;
					pq.offer(new Pair(v + a, o));
				}
			}
		}
		System.out.println(map[g]);

	}

	int n;
	int m;

	class Pair implements Comparable<Pair> {
		int a;
		int b;

		public Pair(int a, int b) {
			super();
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Pair o) {
			return this.a - o.a;
		}

	}

}

Measured memory_bytes: 93336
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;
template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N;
    cin >> N;
    vec A(N);
    vec s(N+1, 0);
    Rep (i, N) {
        cin >> A[i];
        s[i+1] = s[i] + A[i];
    }

    ll ans = inf;
    Rep (i, N+1) {
        chmin(ans, abs(s[i] - (s[N] - s[i])));
    } 

    cout << ans << "\n";
}

Measured memory_bytes: 3328
n = int(input())
a = [[int(x) for x in input().split()] for i in range(n)]
dp = [[0 for x in range(3)] for i in range(n + 1)]
for i in range(1, n + 1):
    for j in range(3):
        for k in range(3):
            if k != j:
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i - 1][j])
print(max(dp[n]))

Measured memory_bytes: 75096
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
 
// ------------------------------------------------------------------------------------------------

const ll MOD = 1e9 + 7;

ll n, m;
vll s, t;
vvll dp;

ll dp_f(ll i, ll j) {
    if (i >= 0 && j >= 0 && i < n && j < m) {
        return dp[i][j];
    }
    return 0;
}

void func() {
    cin >> n >> m;
    s.resize(n); t.resize(m);
    for (ll i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (ll i = 0; i < m; i++) {
        cin >> t[i];
    }
    dp.assign(n, vll(m));
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < m; j++) {
            dp[i][j] = ((dp_f(i - 1, j) + dp_f(i, j - 1)) % MOD - dp_f(i - 1, j - 1)) % MOD;
            if (s[i] == t[j]) {
                (dp[i][j] += (1 + dp_f(i - 1, j - 1)) % MOD) %= MOD;
            }
        }
    }
    dp[n - 1][m - 1]++; (dp[n - 1][m - 1] += MOD) %= MOD;
    cout << dp[n - 1][m - 1] << endl;
}

int main() {
    fast_io; cout_precision;
    ll t = 1; // cin >> t;
    for (ll i = 1; i <= t; i++) {
        func();
    }
}

Measured memory_bytes: 31616
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  vector<vector<ll>> v(N, vector<ll>(3));
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &v[i][0]);
    scanf("%lld", &v[i][1]);
    scanf("%lld", &v[i][2]);
  }

  vector<vector<ll>> dp(N + 10, vector<ll>(3, 0));
  for (int i = 0; i < N; ++i)
  {
    for (int j = 0; j < 3; ++j)
    {
      dp[i + 1][j] = max({dp[i + 1][j], dp[i][(j + 1) % 3] + v[i][(j + 1) % 3], dp[i][(j + 2) % 3] + v[i][(j + 2) % 3]});
    }
  }
  cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;

  return 0;
}


Measured memory_bytes: 11904
#include<stdio.h>

int main(void)
{
  int i,j,c;
  int a[50];
  int n,p;
  
  while(1)
    {
      scanf("%d %d",&n,&p);
      if(!n && !p){break;}
      
      for(i=0;i<n;i++)a[i] = 0;
      
      i = 0;
      while(1){
	while(1){
	  a[i]++;
	  i++;
	  if(i==n)i = 0;
	  p--;
	  if(p==0)break;
	}
	
	c = 0;
	for(j=0;j<n;j++){
	  if(a[j])c++;
	  if(c>1)break;
	}

	if(c == 1){
	  if(i==0)i=n;
	  printf("%d\n",i-1);
	  break;
	}
	
	while(!a[i]){
	  i++;
	  if(i==n)i = 0;
	}
	
	p = a[i];
	a[i] = 0;
	i++;
	if(i==n)i = 0;
	
      }
      
    }
  return 0;
}

Measured memory_bytes: 408
#include <bits/stdc++.h>
using namespace std;
#define Maxn 307
int n,m;
int a[Maxn][Maxn],que[Maxn];
bool vis[Maxn];
vector<int> e[2*Maxn];
int l[Maxn];
void print()
{
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
            printf("%d ",a[i][j]);
        printf("\n");
    }
}
void insert(int x,int y)
{
    e[x].push_back(n+y);
    e[n+y].push_back(x);
}
int find(int u)
{
    for (int i=0;i<(int)e[u].size();i++)
    {
        int v=e[u][i];
        if (!vis[v])
        {
            vis[v]=true;
            if (l[v]==0||find(l[v]))
            {
                l[v]=u;
                return true;
            }
        }
    }
    return false;
}
int hungary()
{
    int ans=0;
    memset(l,0,sizeof(l));
    for (int i=n+1;i<=2*n;i++)
    {
        memset(vis,false,sizeof(vis));
        if (find(i)) ++ans;
    }
    return ans;
}
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    for (int i=1;i<=m;i++)
    {
        memset(e,0,sizeof(e));
        for (int j=1;j<=n;j++)
        {
            memset(vis,false,sizeof(vis));
            for (int k=i;k<=m;k++)
            {
                int tmp=(a[j][k]+m-1)/m;
                if (!vis[tmp])
                {
                    vis[tmp]=true;
                    insert(j,tmp);
                }
            }
        }
        hungary();
        for (int j=1;j<=n;j++)
        {
            int pos=i;
            for (int k=i;k<=m;k++)
            {
                int tmp=(a[j][k]+m-1)/m;
                if (tmp==l[j]-n)
                {
                    pos=k;
                    break;
                }
            }
            if (pos!=i) swap(a[j][pos],a[j][i]);
        }
    }
    print();
    for (int i=1;i<=m;i++)
    {
        for (int j=1;j<=n;j++)
            que[j]=a[j][i];
        sort(que+1,que+n+1);
        for (int j=1;j<=n;j++)
            a[j][i]=que[j];
    }
    print();
    return 0;
}

Measured memory_bytes: 9936
import sys
import math

# 再帰
def solve_rec(n, a, b, h_lst, ans_min, ans_max):
    if ans_min == ans_max:
        return ans_min

    if ans_min > ans_max:
        return -1

    pivot = (ans_min + ans_max) // 2
    # print("try: {}".format(pivot))
    is_beatable = beatable(a, b, h_lst, pivot)

    if is_beatable:
        # print("beatable: {} {}".format(ans_min, ans_max))
        return solve_rec(n, a, b, h_lst, ans_min, pivot)
    else:
        # print("not beatable: {} {}".format(ans_min, ans_max))
        return solve_rec(n, a, b, h_lst, pivot+1, ans_max)

def beatable(a, b, h_lst, pivot):
    # まずBずつ削る
    living = [ h - b * pivot for h in h_lst if h > b * pivot ]
    # print(living)

    # 生き残ったものを1回ずつ(A-B)ダメージずつ与えていくときに、必要な回数
    c = sum([ math.ceil(1.0 * h / (a-b)) for h in living ])
    
    return c <= pivot

def solve(n, a, b, h_lst):
    h_max = max(h_lst)
    ans_min = 0
    ans_max = h_max // b + 1

    return solve_rec(n, a, b, h_lst, ans_min, ans_max)

def main():
    line = sys.stdin.readline()
    lst = line.split()
    n = int(lst[0])
    a = int(lst[1])
    b = int(lst[2])

    h_lst = []
    for i in range(n):
        line = sys.stdin.readline()
        h = int(line)
        h_lst.append(h)
        

    ans = solve(n, a, b, h_lst)
    print(ans)

if __name__ == '__main__':
    main()


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

using ll = long long;

int main() {
    int n, k; cin >> n >> k;
    vector<ll> a(n), sum(n + 1);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }
    vector<ll> cand;
    for(int i = 0; i <= n; ++i) {
        for(int j = i + 1; j <= n; ++j) {
            cand.push_back(sum[j] - sum[i]);
        }
    }

    ll ans = 0;
    for(int b = 60; b >= 0; --b) {
        vector<ll> nxt;
        for(auto x : cand) {
            if(x & (1LL << b)) nxt.push_back(x);
        }
        if((int)nxt.size() >= k) {
            ans |= (1LL << b);
            cand = move(nxt);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 6388
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

using namespace std;

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

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    map<int, int> mp;
    set<int> st;
    int res = 0;
    for(int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        ++mp[a];
        st.insert(a);

    }

    for(auto it = st.begin(); it != st.end(); ++it) {
        if(mp[*it] >= *it) {
            res += mp[*it] - (*it);

        } else {
            res += mp[*it];

        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 9344
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

n = ni()
a = 0
b = math.ceil(math.sqrt(n))

for i in range(1,b+1):
    if n%i == 0:
        c = n//i-1
        a = a if c <= i else a+c

print(a)

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

int main()
{
    vector<int> ans;
    while (1)
    {
        int t, d, l;
        cin >> t >> d >> l;
        if (t == 0 && d == 0 && l == 0)
        {
            break;
        }

        int total = 0;
        int dryTime = 0;
        bool wet = false;
        for (int i = 0; i < t; ++i)
        {
            // int input;
            // cin >> input;
            // if (i % 2 == 0)
            // {
            //     a = (input < l ? 0 : 1);
            // }
            // else
            // {
            //     b = (input < l ? 0 : 1);
            // }
            // if (!(a == 0 && b == 0))
            // {
            //     total++;
            // }

            int input = 0;
            cin >> input;
            if (i == t - 1)
                break;
            if (input < l)
            {
                ++dryTime;
                if (dryTime < d && wet)
                    total++;
                if (dryTime >= d)
                    wet = false;
            }
            else
            {
                wet = true;
                ++total;
                dryTime = 0;
            }

            // if (dryTime == d)
            // {
            //     total += d;
            // }
        }

        ans.push_back(total);
    }

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


Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#include<vector>
#include<tuple>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

template<typename T>
std::vector<std::vector<T>> mk2d(size_t s1, size_t s2, T const& val) {
  std::vector<T> tmp(s2, val);
  return std::vector<std::vector<T>>(s1, tmp);
}

template<typename T>
std::vector<T> mk1d(size_t s, T const& val) {
  return std::vector<T>(s, val);
}

int64_t const INF = 1e18;
int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int H, W, K; std::cin >> H >> W >> K;
  int xs, ys, xg, yg; std::cin >> xs >> ys >> xg >> yg;
  auto bm = mk2d(H+2, W+2, '@');
  for(int h = 1; h <= H; ++h) for(int w = 1; w <= W; ++w) std::cin >> bm[h][w];
  auto tvis = mk2d(H+2, W+2, false);
  auto vis = mk1d(2, tvis);
  using TP = std::tuple<int,int,int>;
  std::vector<TP> q = {{0, xs, ys}, {1, xs, ys}};
  int ans = 0;
  while(!q.empty()) {
    std::vector<TP> nq;
    for(auto [d, x, y]: q) {
      vis[d][x][y] = true;
      if(x==xg && y==yg) fin(ans);
    }
    for(auto [d, x, y]: q) {
      if(d == 0) {
        for(int nx = x+1; !vis[0][nx][y] && bm[nx][y] == '.' && nx <= x+K; ++nx) {
          vis[0][nx][y] = true;
          if(!vis[1][nx][y]) nq.emplace_back(1, nx, y);
          if(nx==x+K && !vis[1][nx][y]) nq.emplace_back(0, nx, y);
        }
        for(int nx = x-1; !vis[0][nx][y] && bm[nx][y] == '.' && nx >= x-K; --nx) {
          vis[0][nx][y] = true;
          if(!vis[1][nx][y]) nq.emplace_back(1, nx, y);
          if(nx==x-K && !vis[1][nx][y]) nq.emplace_back(0, nx, y);
        }
      } else {
        for(int ny = y+1; !vis[1][x][ny] && bm[x][ny] == '.' && ny <= y+K; ++ny) {
          vis[1][x][ny] = true;
          if(!vis[0][x][ny]) nq.emplace_back(0, x, ny);
          if(ny==y+K && !vis[0][x][ny]) nq.emplace_back(1, x, ny);
        }
        for(int ny = y-1; !vis[1][x][ny] && bm[x][ny] == '.' && ny >= y-K; --ny) {
          vis[1][x][ny] = true;
          if(!vis[0][x][ny]) nq.emplace_back(0, x, ny);
          if(ny==y-K && !vis[0][x][ny]) nq.emplace_back(1, x, ny);
        }
      }     
    }
    q = move(nq);
    ++ans;
  }
  fin(-1);
  return 0;
}


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

int main(){
	long long n,ans=0,t;
	vector <int> a;
	cin>>n;
	for(int i=0;i<=n;i++){
		cin>>t;
		a.push_back(t);
	}
	int b;
	for(int i=0;i<n;i++){
		cin>>b;
		if(b<=a[i]){
			ans+=b;
		}else{
			ans+=min(b,a[i]+a[i+1]);
			a[i+1]=max(0,a[i+1]-(b-a[i]));
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int A; // 一円硬貨の枚数
    int N; // 払いたい金額
    int X; // 500円で払ったあまり

    cin >> N >> A;

    X = N % 500;

    if (X <= A) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 768
h, w = [int(_) for _ in input().split()]

if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    if h % 2 == 0:
        tyy1 = [(w//3) * h, (w - w//3) * h / 2]
        tyy2 = [(w//3 + 1) * h, (w - w//3 - 1) * h / 2]
    else:
        tyy1 = [(w//3) * h, (w - w//3) * (h // 2), (w - w//3) * (h // 2 + 1)]
        tyy2 = [(w//3 + 1) * h, (w - w//3 - 1) * (h // 2), (w - w//3 - 1) * (h // 2 + 1)]
    if w % 2 == 0:
        tty1 = [(h//3) * w, (h - h//3) * w / 2]
        tty2 = [(h//3 + 1) * w, (h - h//3 - 1) * w / 2]
    else:
        tty1 = [(h//3) * w, (h - h//3) * (w // 2), (h - h//3) * (w // 2 + 1)]
        tty2 = [(h//3 + 1) * w, (h - h//3 - 1) * (w // 2), (h - h//3 - 1) * (w // 2 + 1)]
    print(int(min(h, w, max(tyy1)-min(tyy1), max(tyy2)-min(tyy2), max(tty1)-min(tty1), max(tty2)-min(tty2))))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

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

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <chrono>
#include <functional>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No")
	{
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right)
	{
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main()
{
	int N;
	cin >> N;
	bool rule = true;
	vector<string> strarr(N);
	string stk;
	for (int i = 0; i < N; i++) {
		cin >> strarr[i];
		for (int j = 0; j < i; j++) {
			if (strarr[j] == strarr[i]) {
				rule = false;
			}
		}
		
		if (i > 0) {
			if (strarr[i][0] != strarr[i-1].back()) {
				rule = false;
			}
		}
	}
	judge_outer(rule);
	return 0;
}

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

int debug = 0;

main() {
    int n, ac = 0, wa = 0, tl = 0, re = 0;
    cin >> n;
    rep(i, 0, n) {
        string s;
        cin >> s;
        if (s == "AC") {
            ac++;
        } else if (s == "WA") {
            wa++;
        } else if (s == "TLE") {
            tl++;
        } else {
            re++;
        }
    }
    cout << "AC x " << ac << "\nWA x " << wa << "\nTLE x " << tl << "\nRE x " << re << '\n';
}

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

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var b = a.Clone() as int[];
        Array.Sort(a);
        var t = a[n / 2];
        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(b[i] >= t ? a[n / 2 - 1] : a[n / 2]);
        }
    }
}


Measured memory_bytes: 39036
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string a;
    cin>>a;
    vector<char> vec, vec1, vec2;
    int l=a.size();
    int count=0;
    
    for (int i=0; i<l; i++){
       vec.push_back(a.at(i));
    }
    for (int i=0; i<(l-1)/2; i++){
        vec1.push_back(a.at(i));
    }
    for (int i=0; i<(l+1)/2; i++){
        vec2.push_back(a.at(i));
    }
    bool t=true;
    for (int i=0; i<l; i++){
        
        if (vec[i]==vec[l-1-i]){
        }
        else{
            t=false;
            break;
        }
    }
    if (t){
        count+=1;
    }
    
    
    bool p=true;
    for (int i=0; i<(l-1)/2; i++){
        
        if (vec[i]==vec[(l-1)/2-1-i]){
        }
        else{
            p=false;
            break;
        }
    }
    if (p){
        count+=1;
    }
    
    bool q=true;
    for (int i=(l+3)/2-1; i<l; i++){
        
        if (vec[i]==vec[l+(l+3)/2-i-2]){
        }
        else{
            q=false;
            break;
        }
    }
    
    if (q){
        count+=1;
    }
    
    if (count==3){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

const int N = 100005;

int n , a[3][N];
int m[2] , b[2][N] , w[2] , c[N];
int main() {
    scanf("%d" , &n);
    for (int i = 0 ; i < 3 ; ++ i) {
        for (int j = 0 ; j < n ; ++ j) {
            scanf("%d" , &a[i][j]);
            -- a[i][j];
        }
    }
    for (int i = 0 ; i < n ; ++ i) {
        int x = a[0][i] / 3 , y = a[1][i] / 3 , z = a[2][i] / 3;
        if (a[1][i] % 3 != 1 || x != y || y != z || x != z) {
            puts("No");
            return 0;
        }
        int p = (a[0][i] + a[1][i] + a[2][i] - 3) / 9;
        if ((p ^ i) & 1) {
            puts("No");
            return 0;
        }
        b[i & 1][m[i & 1] ++] = p / 2 + 1;
        w[i & 1] ^= (a[0][i] > a[2][i]);
    }
    for (int k = 0 ; k < 2 ; ++ k) {
        memset(c , 0 , sizeof(c));
        int s = 0;
        for (int i = 0 ; i < m[k] ; ++ i) {
            //cout << b[k][i] << " \n"[i + 1 == m[k]];
            for (int j = b[k][i] ; j <= n ; j += j & -j) {
                s ^= c[j];
            }
            for (int j = b[k][i] ; j > 0 ; j -= j & -j) {
                c[j] ^= 1;
            }
        }
        //cout << s << ' ' << w[k ^ 1] << endl;
        if ((s ^ w[k ^ 1]) & 1) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <vector>
#define ll long long
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
ll n;
int i,k;
vector <int> a;
void solve(ll n,int &k)
{
	if (n==1) {a.push_back(1); k=1; return ;}
	if (n&1) {
		solve((n-1)/2,k);
		k++; a.push_back(k);
	}
	else {	
		solve(n-1,k);
		k++; a.insert(a.begin(),k);
	}
}
int main()
{
//	freopen("repeat.in","r",stdin);
//	freopen("repeat.out","w",stdout);
	scanf("%lld",&n);
	solve(n,k);
	rep(i,1,k) a.push_back(i);
	printf("%d\n",a.size());
	rep(i,0,a.size()-1) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 256
<?php
  list($n, $l) = explode(" ", trim(fgets(STDIN)));


  $aji = range($l, $l+$n-1);

  $sum_aji = array_sum($aji);

  if($l > 0){
    $sum_aji -= $l;
  }else{
    if(abs($l) >= $n){
      $sum_aji -= ($l+$n-1);
    }
  }

  echo $sum_aji;


Measured memory_bytes: 4604
def resolve():
	c = [i for i in range(2, 14)]
	c.append(1)
	a, b = map(int, input().split())
	if c.index(a) == c.index(b):
		print("Draw")
	elif c.index(a) > c.index(b):
		print("Alice")
	else:
		print("Bob")
resolve()

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    int a,b; cin>>a>>b;
    int n=600000;
    int x = 0;
    int tmp = -1;
    for(int i=1;i<n;i++){
        x+= i;
        if(x>=b&& tmp>=a&& tmp-a == x-b) { cout<<x-b<<endl; return 0;}
        //cout<<x<<endl;
        tmp = x;
    }
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.*;

class Main
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	
    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();long[] pre=new long[n+1];
		
		for(int i=1;i<=n;i++)
		{
			pre[i]=pre[i-1]+sc.nextLong();
		}
		
		long min=Long.MAX_VALUE;
		
		for(int i=1;i<n;i++)
		{
			long val1=pre[i],val2=pre[n]-pre[i];
			
			min=Math.min(min,Math.abs(val1-val2));
		}
		
		out.println(min);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}

Measured memory_bytes: 49236
def main():
    n = int(input())
    numbers = list(map(int, input().split()))
    counters = [0] * 10001
    sortedNumbers = [0] * n
    for number in numbers:
        counters[number] += 1

    for i in range(1, 10001, 1):
        counters[i] += counters[i - 1]

    for i in range(n - 1, -1, -1):
        sortedNumbers[counters[numbers[i]] - 1] = numbers[i]
        counters[numbers[i]] -= 1

    print(' '.join(map(str, sortedNumbers)))

if __name__ == '__main__':
    main()



Measured memory_bytes: 240580
#include "bits/stdc++.h"
using namespace std;

int main()
{
	pair<int,pair<int,int>> ans;
	int s;
	cin>>s;
	ans.second.second=s%60;
	s/=60;
	ans.second.first=s%60;
	s/=60;
	ans.first=s%60;
	cout<<ans.first<<":"<<ans.second.first<<":"<<ans.second.second<<endl;
	return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;
typedef long long ll;
typedef pair<int, int> P;
vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank;

    UnionFind(int n = 1)
    {
        init(n);
    }

    void init(int n = 1)
    {
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int root(int x)
    {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            return par[x] = r; // 辺の縮約（一度根をたどったら辺を直接根に向かって貼り直す）
        }
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (rank[x] < rank[y])
            swap(x, y);
        if (rank[x] == rank[y])
            ++rank[x];
        par[y] = x; // xよりyのほうが高さが小さい木
        return true;
    }
};

// 最大公約数
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

// 最小公倍数
int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y)
{
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

// 負の数にも対応した % 演算
long long mod(long long val, long long m)
{
    long long res = val % m;
    if (res < 0)
        res += m;
    return res;
}

// a^n modを計算する
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    // nを2進数表示して1が埋まっている桁に関してはa^mをかけていく
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod)
{
    return modpow(a, mod - 2, mod);
}

int main()
{
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;
    if (U == S) {
        A--;
    } else {
        B--;
    }

    cout << A << " " << B << endl;
}

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

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(c-a-b<0){
        cout<<"No"<<endl;
    }
    else if((c-a-b)*(c-a-b)-4*a*b>0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;

}

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

struct node { int t,next; }a[200010];

int head[100010],num[100010],l[100010],r[100010],n,m,rt,tot;
bool flag;

inline int rd()
{
	int x=0,f=1;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

inline void add(int x,int y) { a[++tot].t=y;a[tot].next=head[x];head[x]=tot; }

inline void dfs(int x,int y,int z)
{
	if (~num[x]&&(((num[x]&1)^(num[rt]&1))!=z)) { flag=false;return; }
	int h1=-2123333333,h2=2123333333;
	for (int i=head[x];i;i=a[i].next)
	{
		int t=a[i].t;
		if (t==y) continue;
		dfs(t,x,z^1);
		if (!flag) return;
		h1=max(h1,l[t]-1);
		h2=min(h2,r[t]+1);
	}
	if (~num[x]&&(h1>num[x]||h2<num[x])) { flag=false;return; }
	if (h1>h2) { flag=false;return; }
	if (!~num[x]) l[x]=h1,r[x]=h2;
}

inline void work(int x,int y)
{
	for (int i=head[x];i;i=a[i].next)
	{
		int t=a[i].t;
		if (t==y) continue;
		if (num[x]-1>=l[t]&num[x]-1<=r[t]) num[t]=num[x]-1;
		else num[t]=num[x]+1;
		work(t,x);
	}
}

int main()
{
	n=rd();tot=0;
	for (int i=1;i<n;i++)
	{
		int x=rd(),y=rd();
		add(x,y);add(y,x);
	}
	memset(num,-1,sizeof(num));
	for (int i=1;i<=n;i++) l[i]=-2123333333,r[i]=2123333333;
	m=rd();rt=0;
	while (m--)
	{
		int x=rd(),y=rd();
		num[x]=l[x]=r[x]=y;rt=x;
	}
	flag=true;
	dfs(rt,0,0);
	if (!flag) { puts("No");return 0; }
	work(rt,0);
	puts("Yes");
	for (int i=1;i<=n;i++) printf("%d\n",num[i]);
	return 0;
}

Measured memory_bytes: 7680
// わからん
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> ab, cd;

    int x, y;
    rep(i, N) {
        cin >> x >> y;
        ab.push_back(pair<int, int>(x, y));
    }    
    rep(i, N) {
        cin >> x >> y;
        cd.push_back(pair<int, int>(x, y));
    }    

    sort(cd.begin(), cd.end(), [](const pair<int, int> x, const pair<int, int> y){return x.first < y.first;});
    
    int done[N] = {};
    int sum = 0;

    rep(i, N) {
        int max_y = -1;
        int max_ind = -1;
        rep(j, N) {
            if (ab.at(j).first < cd.at(i).first && ab.at(j).second < cd.at(i).second) {
                if (ab.at(j).second > max_y && done[j] == 0) {
                    max_ind = j;
                    max_y = ab.at(j).second;
                }
            }
        }
        if (max_ind == -1) continue;
        else {
            done[max_ind] += 1;
            sum++;
        }
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, P> PP;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ワーシャルフロイド
  int n; cin >> n;
  ll dist[n][n];
  vector<PP> v;
  FOR(i,0,n){
    FOR(j,0,n){
      if(i==j) dist[i][j] = 0;
      else dist[i][j] = 1e15;
    }
  }
  FOR(i,0,n) {
    FOR(j,0,n) {
      int in; cin >> in;
      if(j > i) {
        v.push_back(PP(in, P(i, j)));
      }
    }
  }
  sort(v.begin(), v.end());
  ll ans = 0;
  FOR(i,0,v.size()) {
    int x = v[i].second.first;
    int y = v[i].second.second;
    ll cost = v[i].first;
    FOR(k,0,n) dist[x][y] = dist[y][x] = min(dist[x][y], dist[x][k] + dist[k][y]);
    if(dist[x][y] > cost) {
      ans += cost;
      dist[x][y] = dist[y][x] = cost;
    } else if(dist[x][y] < cost) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2168
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque


def run():
    a,b,x = map(int, input().split())
    ans = 0
    if a == 0:
        a += 1
        ans = 1
    ans += b // x - (a-1) // x
    print(ans)

if __name__ == "__main__":
    run()


Measured memory_bytes: 9072
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;

int n,k;

int main(){
	cin >> n >> k;
	
	if(n >= 10)
		cout << k;
	else
		cout << k + 100*(10-n);
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>
   
using namespace std;

class Dice
{
    public: 
    int temp1;
    int temp2;
    int a[100];
    
    Dice(int top, int south, int east, int west, int north, int bottom)
    {        
        a[1] = top;
        a[2] = south;
        a[3] = east;
        a[4] = west;
        a[5] = north;
        a[6] = bottom;
    }
    
    void RollS()
    {
            temp1 = a[1];
            temp2 = a[2];
            a[1] = a[5];
            a[2] = temp1;
            a[5] = a[6];
            a[6] = temp2;
    }
    
     void RollN()
    {
            temp1 = a[1];
            temp2 = a[5];
            a[1] = a[2];
            a[2] = a[6];
            a[5] = temp1;
            a[6] = temp2;   
    }
    
     void RollW()
    {
            temp1 = a[1];
            temp2 = a[4];
            a[1] = a[3];
            a[3] = a[6];
            a[4] = temp1;
            a[6] = temp2;
    }
    
     void RollE()
    {
            temp1 = a[1];
            temp2 = a[3];
            a[1] = a[4];
            a[3] = temp1;
            a[4] = a[6];
            a[6] = temp2;
    }
};

void Solution()
{
    int a[100] = {0};
    int n;
    int x, y;
     
    for(int i = 1; i <= 6; i++)
    {
        cin>>a[i];
    }
    
    Dice p(a[1], a[2], a[3], a[4], a[5], a[6]); 
        
    cin>>n;

    while(n--)
    {
        cin>>x>>y;
        
       // Dice p = mDice;
        
        if(y == p.a[1]) {p.RollS();}
            else if(y == p.a[3]) {p.RollW(); p.RollS();}
            else if(y == p.a[4]) {p.RollE(); p.RollS();}
            else if(y == p.a[5]) {p.RollS(); p.RollS();}
            else if(y == p.a[6]) {p.RollN();}
        
        if(x == p.a[3]) {p.RollW();}
            else if(x == p.a[4]) {p.RollE();}  // just think about the surface which next a[2] except a[1], because a[1] is no need to roll..
            else if(x == p.a[6]) {p.RollE(); p.RollE();}
        
        cout<<p.a[3] <<endl;  
    }
             
}
   
int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1160