akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int M, D;
    cin >> M >> D;
    int ans = 0;
    for(int i = 1; i <= D; i++){
        int d1 = i / 10, d2 = i % 10;
        if(d1 >= 2 && d2 >= 2 && d1 * d2 <= M){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

res = 0

for i in range(N - 1, -1, -1):
    d = B[i] - A[i + 1]

    if d >= 1:
        res += A[i + 1]
        if A[i] >= d:
            A[i] -= d
            res += d
        else:
            res += A[i]
            A[i] = 0
    else:
        res += B[i]

print(res)

Measured memory_bytes: 82020
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

double DP[1100000] = {};

long long int p10(int num){
	if(num == 0){
		return 1LL;
	}
	return p10(num - 1) * 10LL;
}

int main(){
	
	long long int K;
	cin >> K;
	/*
	for(int i = 1; i <= 1000000; i++){
		int ret = 0;
		int hoge = i;
		for(int j = 0; j < 6; j++){
			ret += hoge % 10;
			hoge /= 10;
		}
		DP[i] = double(i) / ret;
	}
	
	for(int i = 1000000 - 1; i >= 1; i--){
		if(DP[i] <= DP[i + 1]){
			cout << i << " ";
		}
		DP[i] = min(DP[i], DP[i + 1]);
	}
	*/
	
	//string ans = "", piyo = " ";
	int ans[18] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99};
	
	for(int i = 0; i < min(18LL, K); i++){
		cout << ans[i] << endl;
	}
	
	K -= 18;
	
	if(K <= 0){
		return 0;
	}
	
	long long int aa = 0;
	
	for(int i = 0; i < 18; i++){
		for(int j = 100; j < 1000; j++){
			int ret = 9 * i;
			int hoge = j;
			for(int k = 0; k < 4; k++){
				ret += hoge % 10;
				hoge /= 10;
			}
			DP[j] = double(aa + j * p10(i)) / ret;
			//cout << aa + j * p10(i) << " " << DP[j] << endl;
		}
		DP[1000] = 1e18;
		bool flag = false;
		vector<long long int> v;
		for(int j = 1000 - 1; j >= 100; j--){
			if(DP[j] <= DP[j + 1]){
				v.push_back(aa + j * p10(i));
			}
			DP[j] = min(DP[j], DP[j + 1]);
		}
		sort(v.begin(), v.end());
		for(int j = 0; j < v.size(); j++){
			cout << v[j] << endl;
			K--;
			if(K == 0){
				flag = true;
				break;
			}
		}
		aa *= 10;
		aa += 9;
		if(flag){
			break;
		}
	}
	
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		
		if(a == 1){
		    System.out.println("Yes");
		}
		else
		{
		    int grid[] = new int[a];
		    
		    //準備
    		for(int i = 0; i < a; i++){
    		    grid[i] = sc.nextInt();
    		}
    		
    		//操作
    		for(int i = 0; i < a; i++){
    		    if(i == 0){
    		        if(grid[0] > grid[1] && grid[0] > 1){
    		            grid[0]--;
    		        }
    		    }
    		    else
    		    {
    		        if(grid[i] > grid[i-1] && grid[i] > 1){
    		            grid[i]--;
    		        }
    		    }

    		}
    		
    		//検査
    		boolean flg = true;
    		for(int i = 0; i < a; i++){
    		    if(i == 0){
    		        if(grid[0] > grid[1]){
    		            flg = false;
    		            break;
    		        }
    		    }
    		    else
    		    {
    		        if(grid[i] < grid[i-1]){
    		            flg = false;
    		            break;
    		        }
    		    }

    		}
    		
    		if(flg == true){
    		    System.out.println("Yes");
    		}
    		else
    		{
    		    System.out.println("No");
    		}
    	    
            
		}
		
	}
}

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

int main() {
  int N;
  cin >> N ;
  int x=0 ;
  for (int i=0 ; i < N ; i++){
    int l , r ;
    cin >> l >> r ;
    x+=( r - l ) + 1 ;
  }
  cout << x << endl;
    
 
    
}
    

 








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

int main() {
    int K;
    cin >> K;
    queue<long long> que;
    for (int i = 1; i < 10; ++i) que.push(i);
    for (int i = 0; i < K-1; ++i) {
        long long s = que.front();
        que.pop();
        for (int j = -1; j <= 1; ++j) {
            long long add = (s % 10) + j;
            if (add >= 0 && add <= 9) que.push(s * 10 + add);
        }
    }
    cout << que.front() << endl;
}

Measured memory_bytes: 5052
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
 
ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47408
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int dimension = scan.nextInt();
        int[] x = new int[dimension];
        int[] y = new int[dimension];

        for (int i = 0; i < dimension; i++) {
            x[i] = scan.nextInt();
        }
        for (int j = 0; j < dimension; j++) {
            y[j] = scan.nextInt();
        }

        System.out.println(manhattan_distance(dimension, x, y));
        System.out.println(euclid_distance(dimension, x, y));
        System.out.println(minkowski_three(dimension, x, y));
        System.out.println(chebyshev_distance(dimension, x, y));
    }

    public static double manhattan_distance(int dim, int[] x_vector, int[] y_vector) {
        double d_xy = 0.0;
        for (int i = 0; i < dim; i++) {
            d_xy += Math.abs(x_vector[i] - y_vector[i]);
        }
        return d_xy;
    }

    public static double euclid_distance(int dim, int[] x_vector, int[] y_vector) {
        double d_xy = 0.0;
        for (int i = 0; i < dim; i++) {
            d_xy += Math.pow(Math.abs(x_vector[i] - y_vector[i]), 2);
        }
        return Math.sqrt(d_xy);
    }

    public static double minkowski_three(int dim, int[] x_vector, int[] y_vector) {
        double d_xy = 0.0;
        for (int i = 0; i < dim; i++) {
            d_xy += Math.pow(Math.abs(x_vector[i] - y_vector[i]), 3);
        }
        return Math.cbrt(d_xy);
    }

    public static double chebyshev_distance(int dim, int[] x_vector, int[] y_vector) {
        double d_xy = 0.0;
        for (int i = 0; i < dim; i++) {
            if (Math.abs(x_vector[i] - y_vector[i]) > d_xy)
                d_xy = Math.abs(x_vector[i] - y_vector[i]);
        }
        return d_xy;
    }
}

Measured memory_bytes: 20324
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int n;
    cin >> n;
    vector<int> d(n,0);
    rep(i,n) cin >> d[i];
    sort(d.begin(),d.end());
    if(n%2 == 1){
        cout << 0 << endl;
    }else{
        cout << d[n/2] - d[n/2-1] << endl;
    }
    
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 640
import java.util.Scanner;

class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int a,b,c;
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		scan.close();
		
		Boolean flag = false; 
		for(int i = 1; i <= b; i++){
			if(a * i % b == c)flag = true;
		}
		
		System.out.print(flag ? "YES":"NO");
		
	}
}

Measured memory_bytes: 23124
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int x=a+b;
int y=c+d;
  if(x==y)
    cout<<"Balanced";
  if(x<y)
    cout<<"Right";
  if(x>y)
    cout<<"Left";
return 0;
}

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

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

  maximum = max(a+b, max(a-b, a*b));
  cout << maximum << endl;

}


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

using namespace std;

#define llong long long int
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s, t;
    cin >> s >> t;
    int n = (int)s.size(), m = (int)t.size();
    vector<vector<int> > dp(n + 1, vector<int> (m + 1, 0));

    rep(i, n) {
        rep(j, m) {
            if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
            else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
        }
    }

    int x = n, y = m;
    string LCS;
    while (x > 0 && y > 0) {
        if (dp[x][y] == dp[x - 1][y]) {
            --x;
        } else if (dp[x][y] == dp[x][y - 1]) {
            --y;
        } else {
            --x;
            --y;
            LCS.push_back(s[x]);
        }
    }

    reverse(all(LCS));

    cout << LCS << endl;
    
    return 0;
}

Measured memory_bytes: 35584
/*
  Contest 076
  A - Rating Goal
  Rakesh Kumar --> 11/09/2020
 */

#include <bits/stdc++.h>

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

    int r = 0, g = 0;
    std::cin >> r >> g;
    std::cout << ((g << 1) - r) << std::endl;

    return 0;
}


Measured memory_bytes: 3660
/*
-------関数一覧--------
arr1dto2d(Array) 一次元配列を二次元配列にします
pf(N)因数分解した結果をオブジェクトで返します
gcd(a,b)最大公約数を返します
lcm(a,b)最小公倍数を返します
num(a,b)a-bを返します。ソート用です
*/
function Main(input) {
  //write here!
  input = input.split(" ").map(Number);
  var now = input[2];
  for(var i=0;i<10;i++){
    now = (now*input[0])-input[1];
  console.log(now);
  }
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split(" ").map(Number);
    }
  return arr;
}
function pf(n) {
    var result = {};
    
    if (n === 1) {
        return {"1":1}
    }

    var init = 2;

    while (n !== 1) {
        var i = init;
        while (i < Number.MAX_SAFE_INTEGER) {
            if (n % i === 0) {
                n /= i;
                if (!(result[i] > 0)) {
                    result[i] = 0;
                }
                result[i]++;
                break;
            }
            i++;
        }
        init = i;
    }
    return result;
}
function gcd(a, b) {
    if (b === 0){
        return a
    }
    return gcd(b, a % b)
}
function lcm(a,b) {
    var g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}
function num(a, b) {
  return a - b;
}


Measured memory_bytes: 7628
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int k = sc.nextInt();
		// スペース区切りの整数の入力
		int x = sc.nextInt();
       	int start = x-k+1;
      	int end = x+k-1;
      	if(start<-1000000){
          start=-1000000;
        }
      	if(end>1000000){
          end=1000000;
        }
     for(int i=start;i<=end;i++){
       System.out.print(i + " ");
    }
    }
}

Measured memory_bytes: 23892
use std::io;

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    loop {
        let x: Vec<u32> = read_vec();
        if x[0] == 0 && x[1] == 0 {
            break;
        }
        if x[0] <= x[1] {
            println!("{} {}", x[0], x[1]);
        } else {
            println!("{} {}", x[1], x[0]);
        }
    }
}



Measured memory_bytes: 5024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b,k;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0) return cout<<"OK",0;
	} 
	cout<<"NG";
	return 0;
} 

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

int main()
{
	ll h,w,n,x,y;
	cin >> h >> w >> n >> x >> y;
	string s,t;
	cin >> s >>t;
	ll xx = x,yy = y;
	for(int i = 0;i<n;i++)//高橋くんができるだけ右に寄せる
	{
		if(s[i]=='R')yy++;
		if(yy>w)
		{
			cout<<"NO"<<endl;
			return 0;
		}
		if(t[i]=='L')yy--;
		yy = max(1LL,yy);
	}
	xx = x;
	yy = y;
	for(int i = 0;i<n;i++)//高橋くんができるだけ右に寄せる
	{
		if(s[i]=='L')yy--;
		if(yy==0)
		{
			cout<<"NO"<<endl;
			return 0;
		}
		if(t[i]=='R')yy++;
		yy = min(w,yy);
	}
	xx = x;
	yy = y;
	for(int i = 0;i<n;i++)//高橋くんができるだけ右に寄せる
	{
		if(s[i]=='D')xx++;
		if(xx>h)
		{
			cout<<"NO"<<endl;
			return 0;
		}
		if(t[i]=='U')xx--;
		xx = max(1LL,xx);
	}
	xx = x;
	yy = y;
	for(int i = 0;i<n;i++)//高橋くんができるだけ右に寄せる
	{
		if(s[i]=='U')xx--;
		if(xx==0)
		{
			cout<<"NO"<<endl;
			return 0;
		}
		if(t[i]=='D')xx++;
		xx = min(h,xx);
	}
	cout<<"YES"<<endl;
}

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

using namespace std;

typedef long long ll;

int main(){
        ll H, W;
        cin>>H>>W;
        if(H%3==0||W%3==0){
                cout<<0<<endl;
                return 0;
        }
        ll res=100000000110;
        for(ll i=1;i<=W-1;i++){
                ll mx, mn;
                mx=max(H*i, max((H/2)*(W-i), (H-H/2)*(W-i)));
                mn=min(H*i, min((H/2)*(W-i), (H-H/2)*(W-i)));
                res=min(mx-mn, res);
        }
        for(ll i=1;i<=H-1;i++){
                ll mx, mn;
                mx=max(W*i, max((W/2)*(H-i), (W-(W/2))*(H-i)));
                mn=min(W*i, min((W/2)*(H-i), (W-(W/2))*(H-i)));
                res=min(mx-mn, res);
        }
        res=min((W/3+1)*H-(W/3)*H, res);
        res=min((H/3+1)*W-(H/3)*W, res);
        cout<<res<<endl;
        return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if (A%3 == 0 || B%3 == 0 || (A+B)%3 == 0)
    cout << "Possible\n";
  else
    cout << "Impossible\n";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int tmp;
bool n[31];

int main(){

	REP(i, 1, 31)n[i] = true;

	REP(i, 1, 29) {
		cin >> tmp;
		n[tmp] = false;
	}

	REP(i, 1, 31) {
		if (n[i])cout << i << endl;
	}


	return 0;
}


Measured memory_bytes: 3112
#define FNAME ""
 
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cassert>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <string>
 
#define hash padjf9srpi
#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < (n); i++)
#define fornr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (a); i < (b); i++)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
 
#ifdef _WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif
 
using namespace std;
 
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;                                                                                                                                                                                      
typedef vector <int> vi;
 
template <class T> T sqr(const T &a) {return a * a;}

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

    ll s, c;
    cin >> s >> c;
    if (2 * s >= c) {
        cout << c / 2 << endl;
        return 0;
    }
    cout << s + (c - 2 * s) / 4 << endl;
   
 
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
using namespace std;
#define ll long long
/*
//recursive approach
ll vacation(ll d[][4],ll b,ll j,ll l){
    //base condition
    //select all a,b,c
    if(l==0)
    return 0;
    if(l==1 and j==1)
    return d[l][j];
    if(l==1 and j==2)
    return d[l][j];
    if(l==1 and j==3)
    return d[l][j];
    else{
  //  cout<<max(max(d[l][1]+max(vacation(d,b,l-1,2,l-1),vacation(d,b,l-1,3,l-1)),d[l][2]+max(vacation(d,b,l-1,1,l-1),vacation(d,b,l-1,3,l-1))),d[l][3]+max(vacation(d,b,l-1,2,l-1),vacation(d,b,l-1,1,l-1)))<<" ";
   return max(max(d[l][1]+max(vacation(d,b,2,l-1),vacation(d,b,1,l-1)),d[l][2]+max(vacation(d,b,3,l-1),vacation(d,b,3,l-1))),d[l][3]+max(vacation(d,b,1,l-1),vacation(d,b,2,l-1)));
}}
//top down approach
ll vacation(ll d[][4],ll b,ll j,ll l,ll dp[][4]){
   ll ans=0;
    if(l==0)
    return 0;
      if(l==1 and j==1)
    return d[l][j];
    if(l==1 and j==2)
    return d[l][j];
    if(l==1 and j==3)
    return d[l][j];
    if(dp[b][j]!=0)
    return dp[b][j];
    else{
        ll ans1=d[l][1]+max(vacation(d,b,2,l-1,dp),vacation(d,b,1,l-1,dp));
        ll ans2=d[l][2]+max(vacation(d,b,3,l-1,dp),vacation(d,b,3,l-1,dp));
        ll ans3=d[l][3]+max(vacation(d,b,1,l-1,dp),vacation(d,b,2,l-1,dp));
        ans=max((ans1,ans2),ans3);
    }
    return dp[b][3]=ans;
    
}*/
ll vacation(ll d[][4],ll b,ll dp[][4]){
    dp[1][1]=d[1][1];
    dp[1][2]=d[1][2];
    dp[1][3]=d[1][3];
    for(int i=2;i<=b;i++){
        dp[i][1]=d[i][1]+max(dp[i-1][2],dp[i-1][3]);
        dp[i][2]=d[i][2]+max(dp[i-1][1],dp[i-1][3]);
        dp[i][3]=d[i][3]+max(dp[i-1][1],dp[i-1][2]);
    }
    return max(max(dp[b][1],dp[b][2]),dp[b][3]);
}
int main(){
    ll b,l;
	    cin>>b;
	    ll d[b+1][4];
	    ll dp[100001][4]={0};
	    for(ll i=1;i<=b;i++){
	    for(ll j=1;j<=3;j++){
	    cin>>d[i][j];}}
	    cout<<vacation(d,b,dp)<<endl;
	
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
vector <int> son[maxn];
int col[maxn], cnt[2];
void dfs(int u, int fath, int dps) {
    col[u] = dps;
    cnt[dps]++;
    for (int i = 0; i < (int)son[u].size(); i++) {
        int v = son[u][i];
        if (v != fath) {
            dfs(v, u, dps ^ 1);
        }
    }
}
int ans[maxn], lim[5];
int main() {
    int n;  cin >> n;
    for (int i = 1; i <= 3; i++) {
        lim[i] = (n - 1) / 3 + (i <= ((n - 1) % 3 + 1));
        // cout << lim[i] << ' ';
    }
    for (int i = 1; i < n; i++) {
        int u, v;   cin >> u >> v;
        son[u].push_back(v);
        son[v].push_back(u);
    }
    dfs(1, 1, 0);
    set <int> st;
    for (int i = 1; i <= n; i++)    st.insert(i);
    if (cnt[0] <= n / 3) {
        int now = 1;
        for (int i = 1; i <= n; i++) {
            if (!col[i]) {
                ans[i] = 3 * now;
                st.erase(3 * now);
                now++;
            }
        }
        for (int i = 1; i <= n; i++) {
            if (col[i]) {
                ans[i] = *st.begin();
                st.erase(st.begin());
            }
        }
    }
    else if (cnt[1] <= n / 3) {
        int now = 1;
        for (int i = 1; i <= n; i++) {
            if (col[i]) {
                ans[i] = 3 * now;
                st.erase(3 * now);
                now++;
            }
        }
        for (int i = 1; i <= n; i++) {
            if (!col[i]) {
                ans[i] = *st.begin();
                st.erase(st.begin());
            }
        }
    }
    else {
        int now[4] = {0};
        for (int i = 1; i <= n; i++) {
            if (col[i]) {
                if (now[1] < lim[1]) {
                    ans[i] = 3 * now[1] + 1;
                    now[1]++;
                }
                else {
                    ans[i] = 3 * now[3] + 3;
                    now[3]++;
                }
            }
            else {
                if (now[2] < lim[2]) {
                    ans[i] = 3 * now[2] + 2;
                    now[2]++;
                }
                else {
                    ans[i] = 3 * now[3] + 3;
                    now[3]++;
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << ' ';
    }
    getchar(); getchar();
    return 0;
}

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

int main() {
    int r, s, p; cin >> r >> s >> p;
    vector<int> ds;
    for (int _ = 0; _ < p; _++) {
        int i, j; cin >> i >> j;
        int d = abs(r - i) + 1;
        d += j <= s ? s - j + 1 : j - s;
        ds.emplace_back(d);
    }
    sort(ds.rbegin(), ds.rend());
    int ma = 0;
    for (int i = 0; i < p; i++) ma = max(ma, ds[i] + i);
    cout << ma << endl;
    return 0;
}


Measured memory_bytes: 4888
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s[s.size() - 1] == 's')
		cout << s + "es" << endl;
	else
		cout << s + "s" << endl;
}

Measured memory_bytes: 3632
dbflag=""

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = -1

S = readline().rstrip()

import re
#pat = re.compile(pattern)
#pat.match(content)
ismatch = re.match(r'^(dream|dreamer|erase|eraser)*$',S)

if ismatch:
	result = "YES"
else:
	result = "NO"

print(result)


Measured memory_bytes: 6464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,H,D;
    cin >> N >> H >> D;
    vec<mint> fact(N+1,1);
    for(int i=1;i<=N;i++) fact[i] = fact[i-1]*i;
    mint sum = accumulate(fact.begin()+1,fact.begin()+N,(mint) 0);
    vvec<mint> dp(H+1,vec<mint>(2,0));
    dp[0][1] = 1;
    for(int i=1;i<=H;i++){
        dp[i][0] = (dp[i-1][0]+dp[i-1][1]*fact[N])*sum;
        if(i-D-1>=0) dp[i][0] -= (dp[i-D-1][0]+dp[i-D-1][1]*fact[N])*sum;
        dp[i][1] = dp[i-1][0]+dp[i-1][1]*fact[N];
        if(i-D-1>=0) dp[i][1] -= dp[i-D-1][0]+dp[i-D-1][1]*fact[N];
        dp[i][0] += dp[i-1][0];
        dp[i][1] += dp[i-1][1];
    }
//    for(int i=1;i<=H;i++) cerr << i << " " << dp[i][0]-dp[i-1][0] << " " << dp[i][1]-dp[i-1][1] << "\n";
    cout << dp[H][1]-dp[H-1][1] << "\n";
}

Measured memory_bytes: 65772
import sys

for user in sys.stdin:
    hit = 0
    blow = 0
    a = list(map(int, user.split()))
    user = input()
    b = list(map(int, user.split()))
    for i in range(4):
        for j in range(4):
            if b[i] == a[j]:
                if i == j:
                    hit += 1
                else:
                    blow += 1

    print(hit, blow)

Measured memory_bytes: 7548
# https://atcoder.jp/contests/agc036/tasks/agc036_a
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    S = int(input())

    y = -(-S // (10 ** 9))
    x = y * (10 ** 9) - S

    print(0, 0, 10 ** 9, 1, x, y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
a,b = map(int,input().split())
s = input()
moji = [str(i) for i in range(0,10)]
ans = 'Yes'
if len(s) != a+b+1:
    ans = 'No'
for i in range(len(s)):
    if i == a:
        if s[i] != '-':
            ans = 'No'
    else:
        if s[i] not in moji:
            ans = 'No'
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int a[120][120],b[120][2],u,k,v,n,cou=1;
void dfs(int i){
  b[i][0]=cou;
  cou++;
  for(int j=1;j<=n;j++){
    if(a[i][j]==1&&b[j][0]==0)dfs(j);
  }
  b[i][1]=cou;
  cou++;
}

int main(){
  cin>>n;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      a[i][j]=0;
      b[i][0]=0;
      b[i][1]=0;
    }
  }
  for(int i=1;i<=n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      a[u][v]=1;
    }
  }
  for(int i=1;i<=n;i++){
    if(b[i][0]==0)dfs(i);
  }
  for(int i=1;i<=n;i++){
    cout<<i<<" "<<b[i][0]<<" "<<b[i][1]<<endl;;
  }
  return 0;
}

Measured memory_bytes: 3088
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n):
    if button == 2:
        print(count)
        break
    button = a[button]
    count += 1

if count == n:
    print(-1)

Measured memory_bytes: 7852
#include<iostream>

// Print all elemets in array
void print(int A[], int N)
{
	for (int i = 0; i < N; i++) {
		if (i != 0)
			std::cout << " ";
		std::cout << A[i];
	}
	std::cout << std::endl;
}

// Insertion sort
void insertion(int A[], int N)
{
	for (int i = 1; i < N; i++) {
		// Value to insert
		int v = A[i];

		int j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j+1] = v;
		print(A, N);
	}
}

// MAIN FUNCTION
int main()
{
	// Input
	int n;
	int A[1000];
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> A[i];
	}

	print(A, n);
	// Insertion sort
	insertion(A, n);
	return 0;
}

Measured memory_bytes: 3092
import statistics
n = int(input())
a = list(map(int,input().split()))

for i in range(n):
    a[i] -= i+1

a.sort()

mid = statistics.median_low(a)
mid1 = statistics.median_high(a)
ans = [0,0]

for i, aa in enumerate(a):
    ans[0] += abs(aa - mid)
    ans[1] += abs(aa - mid1)
print(min(ans))


Measured memory_bytes: 27252
import java.util.*;
import java.math.*;
public class Main {
	static int x;
	static int ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		Map<Integer, Integer> map = new HashMap<>();
		int[] a = new int[N];
		int[] b = new int[N];
		
		for(int i=0; i<N; i++) {
		    a[i] = Integer.parseInt(sc.next());
		    b[i] = Integer.parseInt(sc.next());
		    if(map.containsKey(b[i])) {
		        map.put(b[i], map.get(b[i])+a[i]);
		    }else {
		        map.put(b[i], a[i]);
		    }
		}
	
		Object[] mapkey = map.keySet().toArray();
        Arrays.sort(mapkey);
        
		String ans = "Yes";
		long sum = 0;
		for(Object ob : mapkey) {
		    String s = ob.toString();
		    int key = Integer.parseInt(s);
		    sum += map.get(key);
		    if(sum > key) {
		        ans = "No";
		        break;
		    }
		}
        System.out.println(ans);
	}
} 

Measured memory_bytes: 110640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	int nowx = 0, nowy = 0, prevt = 0;
	bool yes = true;
	for(int i = 0; i < n; ++i) {
		int t, x, y;
		cin >> t >> x >> y;
		
		int dL = abs(nowx - x) + abs(nowy - y);
		int dT = t - prevt;
		
		if( (dL % 2 != dT % 2) || (dL > dT) ) {
			yes = false;
		}
		
		nowx = x; nowy = y; prevt = t;
	}
	
	if( yes ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_Q 50
i64 N, M, Q;
i64 A[MAX_Q];
i64 B[MAX_Q];
i64 C[MAX_Q];
i64 D[MAX_Q];

i64 rec(i64 i, vector<i64> seq) {
    if (i == N) {
        i64 score = 0;
        REP(i, Q) {
            if (seq[B[i]] - seq[A[i]] == C[i]) {
                score += D[i];
            }
        }
        return score;
    }

    i64 max_score = 0;
    i64 num = (seq.size() == 0) ? 1 : seq[i - 1];
    for (; num <= M; num++) {
        seq.pb(num);
        chmax(max_score, rec(i + 1, seq));
        seq.pop_back();
    }
    return max_score;
}


int main() {
    cin >> N >> M >> Q;
    REP(i, Q) {
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--;
        B[i]--;
    }

    vector<i64> seq(0);
    i64 maxs = rec(0, seq);
    cout << maxs << endl;

    return 0;
}

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

typedef pair<int,int> P;

int n;
int t[10][10];
long long v;
map<long long,bool> m;
vector<P> can;
int dy[] = {-1,0,1,0} , dx[] = {0,1,0,-1};

bool rec(int id);

bool dfs(int id,int y,int x,int sum){
  if(sum == 0)return rec(id+1);
  if(sum>0)return false;

  for(int i=0;i<4;i++){
    int ty = y+dy[i], tx = x+dx[i];
    if(ty<0 || tx<0 || n<=ty || n<= tx)continue;
    if( (v>>(ty*n+tx)) & 1LL || t[ty][tx]<0)continue;
    v |= 1LL << (ty*n+tx);
    if(dfs(id,ty,tx,sum+t[ty][tx]))return true;
    v -= 1LL << (ty*n+tx);
  }
  return false;
}

bool rec(int id){
  if(id == can.size())return true;
  if(m[v])return false;
  m[v] = true;
  int y = can[id].first, x = can[id].second;
  v |= 1LL << y*n+x;
  return dfs(id,y,x,t[y][x]);
}

int main(){
  while(cin >> n,n){
    int sum = 0; can.clear(); m.clear();
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
	cin >> t[i][j];
	sum += t[i][j];
	if(t[i][j]<0)can.push_back(P(i,j));
      }
    v = 0LL;

    cout << ( (!sum && rec(0))?"YES\n":"NO\n" );
  }
}

Measured memory_bytes: 2496
import java.util.Scanner;
import java.util.*;

public class Main {
        public static void main(String[] args) {
          Scanner scan = new Scanner(System.in);
                String h = scan.nextLine();
                if(Character.isUpperCase(h.charAt(0))) {

                  System.out.println("A");
                } else {
                  System.out.println("a");
                }

    }
}


Measured memory_bytes: 35808
/*
author: shah_entrance
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,j,sum=0,count=0;
    cin>>n;
    char str[5][n+5];
    for(i=0;i<3;i++)
        for(j=0;j<n;j++)
            cin>>str[i][j];
    for(i=0;i<n;i++)
    {
        if(str[0][i]==str[1][i] && str[0][i]==str[2][i])
            count+=0;
        else if((str[0][i]==str[1][i])||(str[0][i]==str[2][i])||(str[1][i]==str[2][i]))
            count+=1;
        else
            count+=2;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n,k,ans=0;
  scanf("%d%d",&n,&k);
  int a[n],i;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]>=k) ans++;
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
static const int MAX_N=10e5;
struct P{int maxs,num;};
pair<int,int > A[MAX_N+1];
P B[MAX_N+1];
bool C[MAX_N+1];
stack <int>D;


int main(void){
	int N,K;
		cin >> N >> K;
	for(int i=0;i<N;i++)
		B[i].num=-1;
	
	for(int i=0;i<N;i++){
		int s,o;
			cin >> s >> o;
		s--;
		A[i].first=o*-1;
		A[i].second=i;
		if(B[s].maxs<o){
			B[s].maxs=o;
			B[s].num=i;
		}
	}
	for(int i=0;i<N;i++){
		if(B[i].num==-1)continue;
		C[B[i].num]=true;
	}
	sort(A,A+N);
	
	
	
	long long res=0,typer=0;
	for(int i=0;i<K;i++){
		res+=(long long)A[i].first*(-1);
		typer+=C[A[i].second];
		if(!C[A[i].second])
			D.push(A[i].first);
	}
	long long ans=res+typer*typer;
	for(int i=K;i<N && D.size();i++){
		if(C[A[i].second]){
			res-=D.top()*(-1);
			res+=(long long)A[i].first*(-1);
			D.pop();
			typer++;
			ans=max(ans,res+typer*typer);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String str = sc.nextLine();

		char[] str1 = str.toCharArray();

		for (int i = 0; i < str1.length; i++) {
			if (Character.isUpperCase(str1[i])) {
				str1[i] = Character.toLowerCase(str1[i]);
			}else if(Character.isLowerCase(str1[i])){
				str1[i] = Character.toUpperCase(str1[i]);
			}
			System.out.print(str1[i]);
		}
        System.out.println();


	}

}

Measured memory_bytes: 26632
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_B
# Maximum Heap
# Result:
import sys

def max_heapify(ary, nary, i):
    left = i * 2
    right = left + 1
    if left <= nary and ary[left] > ary[i]:
        largest = left
    else:
        largest = i
    if right <= nary and ary[right] > ary[largest]:
        largest = right
    if largest != i:
        tmp = ary[i]
        ary[i] = ary[largest]
        ary[largest] = tmp
        max_heapify(ary, nary, largest)

def build_max_heap(ary, nary):
    for i in reversed(range(1, nary / 2 + 1)):
        max_heapify(ary, nary, i)

_nary = int(sys.stdin.readline())
_ary = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
assert _nary == len(_ary)
_ary.insert(0, -1)

build_max_heap(_ary, _nary)
_ary.pop(0)
str_ = ''
for x in _ary:
    str_ += ' %d' % (x)
print str_

Measured memory_bytes: 49488
#include<bits/stdc++.h>
using namespace std;
int n,A[1<<20],F[1<<20];
long long k;
int cmp(int x,int y){return x>y;}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	for(int i=1;i<=n;i++)scanf("%d",&F[i]);
	sort(A+1,A+1+n,cmp);
	sort(F+1,F+1+n);
	long long L = -1,R = 1LL*A[1]*F[n];
	while(R-L>1){
		long long mid = (L+R)/2;
		long long required = 0;
		for(int i=1;i<=n;i++){
			required += max(0LL,A[i]-(mid/F[i]));
		}
		if(required <= k){
			R = mid;
		}else{
			L = mid;
		}
	}
	printf("%lld\n",R);
	return 0;
}

Measured memory_bytes: 3072
#!/usr/bin/env python3
import sys
 
inf = float('inf')
 
def solve(N: int, K: int, x: "List[int]", y: "List[int]"):
    V = [(x[i], y[i]) for i in range(N)]
    V.sort()
    X = [v[0] for v in V]
    Y = [v[1] for v in V]
    res = inf
    for k in range(K, N+1):
        for i in range(N-k+1):
            delta_x = X[i+k-1] - X[i]
            yy = sorted(Y[i:i+k])
            for j in range(k-K+1):
                delta_y = yy[j+K-1] - yy[j]
                s = delta_x * delta_y
                if s < res:
                    res = s
 
    print(res)
    return
 
 
# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, K, x, y)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include "stdio.h"

struct rect
{
  int W, H;
};

int main()
{
  auto list = std::vector<rect>{};
  int w, h;
  std::string s;
  while (std::cin >> h >> w)
  {
    auto r = rect{w, h};
    list.push_back(r);
  }

  for (auto r : list)
  {
    if (r.W == 0 && r.H == 0)
      break;

    auto frame_line = std::string{};
    auto line = std::string{};
    for (auto wi = 0; wi < r.W; wi++)
    {
      if (wi == 0 || wi == r.W - 1)
      {
        line += "#";
      }
      else
      {
        line += ".";
      }

      frame_line += "#";
    }

    for (auto hi = 0; hi < r.H; hi++)
    {
      if (hi == 0 || hi == r.H - 1)
      {
        std::cout << frame_line << std::endl;
      }
      else
      {
        std::cout << line << std::endl;
      }
    }

    if (&r != &list[list.size() - 1])
    {
      std::cout << std::endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3192
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>

using namespace std;  typedef long long ll;
inline int qr(){
	int ret=0,f=0,c=getchar();
	while(!isdigit(c)) f|=c==45,c=getchar();
	while( isdigit(c)) ret=ret*10+c-48,c=getchar();
	return f?-ret:ret;
}
const int maxn=1e5+5;
const int inf=1e9;
struct E{
	int to,nx;
}e[maxn<<2];
int head[maxn],ans[maxn<<1],usd[maxn],n,m,cnt,D[maxn];
char col[maxn];
void add(int fr, int to){
	static int cnt=1;
	e[++cnt]=(E){to,head[fr]}; head[fr]=cnt;
	e[++cnt]=(E){fr,head[to]}; head[to]=cnt;
}
priority_queue< pair<int,int> > q;

int main(){
	n=qr(); m=qr();
	for(int t=1;t<=n;++t)D[t]=qr();
	for(int t=1,a,b;t<=m;++t){
		a=qr(),b=qr(),add(a,b);
		if(D[a]==D[b]&&!col[a]&&!col[b]) q.emplace(D[a],a),q.emplace(D[b],b),col[a]='W',col[b]='B',ans[t]=D[a];
	}
	while(q.size()){
		int now=q.top().second; q.pop();
		for(int t=head[now];t;t=e[t].nx)
			if(!col[e[t].to]&&D[e[t].to]>=D[now])
				col[e[t].to]="WB"[col[now]=='W'],ans[t>>1]=D[e[t].to],q.emplace(D[e[t].to],e[t].to);
	}//gjhasdgjhafs
	for(int t=1;t<=n;++t)
		if(col[t]==0)
			return puts("-1"),0;
	puts(col+1);
	for(int t=1;t<=m;++t)
		printf("%d\n",ans[t]?ans[t]:inf);
	return 0;
}


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

int M[105][100005];
int A[105];

inline void filly(int n, int k)
{
    for(int i = 1; i < n; i++)
    {
        M[i][0] = 1;
        for(int j = 1; j <= k; j++)
        {
                M[i][j] = M[i][j-1];
                M[i][j] += (M[i-1][j] - (j - A[i] - 1 >= 0 ? M[i-1][j - A[i] - 1] : 0)) % 1000000007;
                M[i][j] %= 1000000007;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int n, k;
    cin >> n >> k;

    for(int i = 0; i < n; i++)
        cin >> A[i];
    for(int i = 0; i <= A[0]; i++)
        M[0][i] = i+1;
    for(int i = A[0]+1; i <= k; i++)
        M[0][i] = M[0][A[0]];

    filly(n, k);
    cout << (M[n-1][k] - M[n-1][k-1] + 1000000007) % 1000000007;

    return 0;
}

Measured memory_bytes: 41216
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main() {
    int n;
    while(cin >> n, n){
        int x, y, h, w, ans = 0;
        rep(i, 0, n){
            cin >> x >> y >> h >> w;
            int size = -1, l = x + y + h;
            if(l <= 60 && w <= 2) size = 0;
            else if(l <= 80 && w <= 5) size = 1;
            else if(l <= 100 && w <= 10) size = 2;
            else if(l <= 120 && w <= 15) size = 3;
            else if(l <= 140 && w <= 20) size = 4;
            else if(l <= 160 && w <= 25) size = 5;
            //if(l > 160 || w > 25) size = -1;
            //o(size);
            if(size != -1) ans += (2*size + 6)*100;
        }
        cout << ans << endl;
    }
}

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

public class Main{

	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public String next(){
			try{
				while(st==null||!st.hasMoreElements()){
					st = new StringTokenizer(br.readLine());
				}
			}catch(Exception e){
				e.printStackTrace();
			}
			return st.nextToken();
	
		}
		public int nextInt(){
			return Integer.parseInt(next());
		}
		public long nextLong(){
			return Long.parseLong(next());
		}
		public double nextDouble(){
			return Double.parseDouble(next());
		}
		public String nextLine(){
			String s = "";
			try{
				s = br.readLine();
			}catch(Exception e){
				e.printStackTrace();
			}	
			return s;		
		}
	} 

	public static void main(String[] args){
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		long x = in.nextLong();
		for(int i = 1; i <=x ; i++){
			if((i*(i+1))/2>=x){
				out.println(i);
				break;
			}
		}
		out.flush();
		out.close();  
	}

}





Measured memory_bytes: 22228
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)x.size())
using namespace std;
const int M = 420000;
typedef long long ll;
int n,m,k;
vector<int> g[M];
vector<int> p[2];
int ans[M];
void dfs(int u,int c,int f){
    p[c].push_back(u);
    for(int to:g[u]){
        if(to==f) continue;
        dfs(to,c^1,u);
    }
}
int t[3];
int num(int x){
    if(x==0) return t[0]--*3;
    return --t[x]*3+x;
}
int num(){
    if(t[1]) return num(1);
    if(t[0]) return num(0);
    if(t[2]) return num(2);
    return -1;
}
int main(){
    cin>>n;
    int u,v;
    fo(i,1,n-1){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,0,1);
    int b=0,w=1;
    if(SZ(p[b])>SZ(p[w]))
        swap(b,w);
    t[0]=n/3;t[1]=(n+2)/3;t[2]=(n+1)/3;
    if(SZ(p[b])<=t[0]){
        for(int val:p[b])
            ans[val]=num(0);
        for(int val:p[w])
            ans[val]=num();
    }
    else{
        for(int val:p[b])
            ans[val]=num();
        for(int val:p[w])
            ans[val]=num();
    }
    fo(i,1,n) cout<<ans[i]<<' ';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 26740
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,K = MI()
ans = 0
for i in range(1,N+1):
    r = 0
    while i <= K-1:
        i *= 2
        r += 1
    ans += 1/(N*2**r)

print(ans)


Measured memory_bytes: 65248
S = input().strip()

MOD = 10**9 + 7
dp = [[0 for i in range(13)] for j in range(100005)]
N = len(S)

dp[0][0] = 1
for i in range(N):
    c = -1
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])

    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]

    for j in range(13):
        dp[i+1][j] %= MOD

res = int(dp[N][5])

print(res)


Measured memory_bytes: 67116
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m;
    cin >> n >> m;
    int d[n+5] = {};
    memset(d,-1,sizeof(d));
    for(int i = 0 ; i < m ; i++) {
        int x, y;
        cin >> x >> y;
        if(d[x] == -1) {
            d[x] = y;
        }
        else if(d[x] != y) {
            cout << -1 << endl;
            exit(0);
        }
    }
    if (d[1] == 0 && n != 1) {
        cout << -1 << endl;
        exit(0);
    }
    for (int i = 1 ; i <= n ; i++) {
        if(d[i] == -1) {
            if(i == 1) {
                if(n == 1) {
                    cout << 0;
                }
                else {
                    cout << 1;
                }
            }
            else {
                cout << 0;
            }
        }
        else {
            cout << d[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 256