akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y;
    cin >> X >> Y;
    if(abs(X - Y) < 2) {
        cout << "Brown" << endl;
    } else {
        cout << "Alice" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define NODE (20)
#define INF (100000000)

int U[NODE];
int dist[NODE];
int prev[NODE];
int cost[NODE][NODE];
int V;

void dijkstra(int s)
{
	int i, j;
	int v;
	
	dist[s] = 0;
	prev[s] = 0;
	
	for (i = 0; i < V; i++){
		U[i] = 1;
	}
	
	for (i = 0; i < V; i++){
		v = -1;
		
		for (j = 0; j < V; j++){
			if (U[j] == 1 && (v == -1 || dist[v] > dist[j])){
				v = j;
			}
		}
		
		if (v == -1){
			break;
		}
		
		U[v] = 0;
		
		for (j = 0; j < V; j++){
			if ((dist[j] > dist[v] + cost[v][j]) && U[j] == 1){
				dist[j] = dist[v] + cost[v][j];
				prev[j] = v;
			}
		}
	}
}

int main(void)
{
	int i, j;
	int n;
	int from, to, m, mm, sum;
    
	scanf("%d", &V);
	scanf("%d", &n);
	
	for (i = 0; i < V; i++){
	    for (j = 0; j < V; j++){
			cost[i][j] = INF;
		}
		dist[i] = INF;
	}
	
	while (n-- != 0){
		scanf("%d,%d,%d,%d", &from, &to, &m, &mm);
		cost[from - 1][to - 1] = m;
        cost[to - 1][from - 1] = mm;
	}
	scanf("%d,%d,%d,%d", &from, &to, &m, &mm);
	dijkstra(from - 1);
	sum = dist[to - 1];
    
    for (i = 0; i < V; i++){
        dist[i] = INF;
    }
    dijkstra(to - 1);
    sum += dist[from - 1];
    
	printf("%d\n", m - mm - sum);
    
	return (0);
}

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

int main() {

  int A, B, C;
  cin >> A >> B >> C;
  if (A == 5 && B == 5 && C == 7) {
    cout << "YES" << endl;
  }
  else if (A == 5 && B == 7 && C == 5) {
    cout << "YES" << endl;
  }
  else if (A == 7 && B == 5 && C == 5) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define int long long
int INF = 1e9+7;
signed main() {
    int N;
    string S;
    cin >> N >> S;
    int r = 0;
    int g = 0;
    int b = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] == 'R') {
            r++;
        }
        else if(S[i] == 'G') {
            g++;
        }
        else {
            b++;
        }
    }
    int ans = r*g*b;
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            int k = j+(j-i);
            if(k >= N) {
                continue;
            }
            if(S[i] != S[j] && S[j] != S[k] && S[i] != S[k]) {
                ans--;
            }
        }
    }
    cout << max(0LL,ans) << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		double f_ans = 0;

		for (int i=1; i<N+1; i++) {
			double point = i;
			double cnt=0;

			while (true) {
				if (point>=K) {
					break;
				}
				point *= 2;
				cnt += 1;
			}
			double per = 1/Math.pow(2,cnt);
			f_ans += per;
		}


		double ans = f_ans/N;
		System.out.println(ans);


	}

}

Measured memory_bytes: 21716
import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    sc.nextLine();
    int minTotalPrice = Arrays.stream(sc.nextLine().split(" "))
      .mapToInt(Integer::parseInt)
      .sorted()
      .limit(K) 
      .sum();
    System.out.println(minTotalPrice);
  }
}

Measured memory_bytes: 37832
#include <iostream>
#include <queue>
 
using namespace std;
 
int D[110]={0};
void bfs(int src,int n,int g[110][110]){
 
queue<int> Q;
Q.push(src);
D[src]=0;
while (! Q.empty()){
    int cur =Q.front();
    Q.pop();
    for(int r=0;r<n;r++){
        if (g[cur][r]==1&&D[r]==0){
            D[r]=D[cur]+1;
            Q.push(r);
        }
    }
}
}
int main() {
int n,g[110][110]={0};
cin>>n;
int j,num,t;
for(int k=0;k<n;k++){
cin>>j>>num;
for(int kk=0;kk<num;kk++){
    cin>>t;
    g[k][t-1]=1;
}
}
bfs(0,n,g);

for(int a=0;a<n;a++){
	if(a!=0){
    if(D[a]!=0){
    cout<<a+1<<" "<<D[a]<<endl;
}
else{
		cout<<a+1<<" -1"<<endl;
}
}
else{
	cout<<a+1<<" 0"<<endl;
}

}
    return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define FF first
#define SS second
#define f(a,b,c) for(int a=b;a<=c;a++)
#define fd(a,b,c) for(int a=b;a>=c;a--)
#define fspr(X) fixed<<setprecision(X)

const ll MOD=1e9+7;

//bool visited[1001][1001];
//char graph[1000][1000];
//int ans=0;
//bool path=false;
ll power(ll x, ll y , ll z)       // returns (x^y)%z
{
	ll res=1,num=x;
	while(y>0)
	{
		if(y&1)res=(res*num)%z;
		num=(num*num)%z;
		y=y>>1;
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll sum=0;
    int h,n;cin>>h>>n;int A[h];f(i,0,h-1)cin>>A[i];
    if(n>=h)cout<<0<<endl;
    
    else{
	sort(A,A+h);
	f(i,0,h-n-1){sum+=A[i];}
	cout<<sum;
}}

Measured memory_bytes: 1024
float a,b,c,d,e,f,g,h;main(){for(;~scanf("%f%f%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f,&g,&h);puts((a*d-b*c)*h>0&h*(e*b-f*a)>0?"YES":"NO"))a-=g,b-=h,c-=g,d-=h,e-=g,f-=h,h=c*f-d*e;}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<double, double>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll mod_pow(ll x, ll n, ll mod) {
	ll bit = 1;
	while (n) {
		if (n & 1)bit = bit * x % mod;
		x = x * x % mod;
		n /= 2;
	}
	return bit;
}
ll C(ll a, ll b) {
	ll x = 1, y = 1;
	rep(i, b) {
		x = x * (a - i) % inf;
		y = y * (b - i) % inf;
	}
	rep(i, inf) {
		if (x == y * i % inf) {
			return i;
		}
	}
}
signed main() {
	string s;
	cin >> s;
	if (s == "Sunny")puts("Cloudy");
	else if (s == "Cloudy")puts("Rainy");
	else puts("Sunny");
	ggr
}


Measured memory_bytes: 256
import collections


def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    color = [-1]*N
    G = [set() for i in range(N)]
    for i in range(N-1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        G[u].add((v, w))
        G[v].add((u, w))
    root = 0

    color[0] = 0
    q = collections.deque()
    q.append((root, 0))
    while(q):
        x, W = q.popleft()
        for y, w in G[x]:
            if color[y] < 0:
                if (W+w) % 2 == 0:
                    color[y] = 0
                else:
                    color[y] = 1
                q.append((y, W+w))
            else:
                continue
    print(*color, sep="\n")


main()


Measured memory_bytes: 52372
#include<iostream>
#include<vector>
#include<string>
#include<math.h> 
#include<algorithm> 
#include<sstream>
#include<fstream>  
using namespace std; 
typedef long long ll; 
typedef long double ld; 

int ceil(int a, int m){
    // division of a and m
    if(a % m == 0){
        return a/m; 
    }
    else{
        return a/m + 1; 
    }
}

vector<int> sort(vector<int> arr){
    sort(arr.begin(), arr.end()); 
    return arr; 
}





int main(){

char nl = '\n'; 
/*
For array arr use the following preamble to sort
int diff = sizeof(arr)/sizeof(arr[0]); 
sort(arr, arr + diff); 

*/

ll n; 
cin >> n;
int count1 = 0; 
     int count2 = 0;
    int count3 = 0; 
    int count4 = 0;
 while(n--){
     string s; 
     cin >> s; 
     
    if(s == "AC"){
        count1++; 
    }
    else if(s == "WA"){
        count2++; 
    }
    else if(s == "TLE"){
        count3++;
    }
    else{
        count4++; 
    }
 }

 cout << nl << "AC " << "x " << count1; 
  cout << nl << "WA " << "x " << count2;
   cout << nl <<  "TLE " << "x " << count3;
    cout << nl << "RE " << "x " << count4;   

}

Measured memory_bytes: 3640
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(A):
        res = 0
        for a,b,c,d in g:
            if A[b] == A[a]+c:
                res += d
        return res

    n,m,q = LI()
    g = LIR(q)
    for i in range(q):
        g[i][0] -= 1
        g[i][1] -= 1
    l = [([i],i) for i in range(1,m+1)]
    for i in range(n-1):
        l = [(x+[j], j) for (x,y) in l for j in range(y,m+1)]
    ans = 0
    for A,_ in l:
        s = f(A)
        if ans < s:
            ans = s
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

class P{
public:
	int price,id;
	string name,com;
	bool flg; //true:wü, false:p

	P(string _name,bool _flg,string _com,int _price,int _id){
		name = _name;
		flg = _flg;
		com = _com;
		price = _price;
		id = _id;
	}

	bool operator<(const P &p)const{
		if(price == p.price) return id < p.id;
		if(flg) return price > p.price;
		return price < p.price;
	}
};

typedef struct{int min,sum,max,n;}Com;
typedef struct{int pay,recv;}Dealer;

int main(void){
	int n;

	while(cin>>n,n){
		vector<P> buy,sell;
		map<string,Com> mc;
		map<string,Dealer> md;

		for(int i=0;i<n;i++){
			string name,flg,com;
			int price;
			cin>>name>>flg>>com>>price;

			md[name].pay += 0; //L[o^Ì½ß

			if(flg == "BUY"){
				bool buyFlg = false;
				for(int j=0;j<sell.size();j++){
					if(com == sell[j].com && name != sell[j].name && price >= sell[j].price){
						int deal = (price + sell[j].price) / 2;

						if(mc[com].min == 0){
							Com tmp = {deal,deal,deal,1};
							mc[com] = tmp;
						}
						else{
							if(mc[com].max < deal) mc[com].max = deal;
							if(mc[com].min > deal) mc[com].min = deal;
							mc[com].sum += deal;
							mc[com].n++;
						}

						md[name].pay += deal;
						md[sell[j].name].recv += deal;
						sell.erase(sell.begin()+j);
						buyFlg = true;
						break;
					}
				}

				if(!buyFlg){
					buy.push_back(P(name,true,com,price,i));
					sort(buy.begin(),buy.end());
				}
			}
			else{
				bool sellFlg = false;
				for(int j=0;j<buy.size();j++){
					if(com == buy[j].com && name != buy[j].name && buy[j].price >= price){
						int deal = (price + buy[j].price) / 2;

						if(mc[com].min == 0){
							Com tmp = {deal,deal,deal,1};
							mc[com] = tmp;
						}
						else{
							if(mc[com].max < deal) mc[com].max = deal;
							if(mc[com].min > deal) mc[com].min = deal;
							mc[com].sum += deal;
							mc[com].n++;
						}

						md[buy[j].name].pay += deal;
						md[name].recv += deal;
						buy.erase(buy.begin()+j);
						sellFlg = true;
						break;
					}
				}

				if(!sellFlg){
					sell.push_back(P(name,false,com,price,i));
					sort(sell.begin(),sell.end());
				}
			}

		}

		for(map<string,Com>::iterator i=mc.begin();i!=mc.end();i++){
			cout<<(i->first)<<" "<<(i->second).min<<" "<<(i->second).sum / (i->second).n<<" "<<(i->second).max<<endl;
		}
		cout<<"--\n";

		for(map<string,Dealer>::iterator i=md.begin();i!=md.end();i++){
			cout<<(i->first)<<" "<<(i->second).pay<<" "<<(i->second).recv<<endl;
		}
		cout<<"----------\n";
	}

	return 0;
}

Measured memory_bytes: 980
#include <stdio.h>

int main(void){
  int A,B;
  scanf("%d %d",&A,&B);
  if(A>= 13){
  printf("%d\n",B);
  }else if(A>=6){
  printf("%d\n",B/2);
  }else{
  printf("0\n");
  }
return 0;
}

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

using namespace std;

typedef struct {
	int a, b, c;
} fuku_t;

int d, n;

int t[200];
fuku_t fuku[200];

int dp[200][200];

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

	for (int i = 0; i < d; ++i) cin >> t[i];

	for (int i = 0; i < n; ++i) scanf("%d %d %d", &fuku[i].a, &fuku[i].b, &fuku[i].c);

	for (int i = 0; i < n; ++i) if (fuku[i].a <= t[1] && t[1] <= fuku[i].b) {
		for (int j = 0; j < n; ++j) if (fuku[j].a <= t[0] && t[0] <= fuku[j].b) {
			dp[1][i] = max(dp[1][i], abs(fuku[i].c - fuku[j].c));
		}
	}

	for (int i = 2; i < d; ++i) {
		for (int j = 0; j < n; ++j) if (fuku[j].a <= t[i] && t[i] <= fuku[j].b) {
			for (int k = 0; k < n; ++k) if (fuku[k].a <= t[i - 1] && t[i - 1] <= fuku[k].b) {
					dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(fuku[k].c - fuku[j].c));
			}
		}
	}

	int ans = 0;

	for (int i = 0; i < n; ++i) ans = max(ans, dp[d - 1][i]);

	printf("%d\n", ans);
}

Measured memory_bytes: 1388
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        k: i32,
        x: i32,
    }

    let min = x - (k - 1);
    let max = x + k - 1;

    for i in min..max+1{
        print!("{} ", i);
    }
    return;
}

Measured memory_bytes: 4352
void main() {
    int n = readln.chomp.to!int;
    string[] w = new string[n];
    int ok = true;
    foreach (i; 0 .. n) {
        string s = readln.chomp;
        if (i > 0) {
            if (s[0] != w[i-1][$-1] || w.canFind(s)) {
                ok = false;
                break;
            }
        }
        w[i] = s;
    }
    writeln(ok ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

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

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

    int n;
    cin >> n;

    vector<pair<ll, ll> > ab;
    REP(i, n) {
        ll a, b;
        cin >> a >> b;
        ab.push_back(make_pair(b, a));
    }

    sort(ab.begin(), ab.end());

    vector<ll> sum(n, 0);
    REP(i, n) {
        if (i == 0) sum[i] = ab[i].second;
        else sum[i] = sum[i - 1] + ab[i].second;
    }

    bool ok = true;
    REP(i, n)
        if (ab[i].first < sum[i]) ok = false;

    if (ok) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}


Measured memory_bytes: 6384
#include <iostream>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <iomanip>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef unsigned long long ull;

const int inf = 1e9 + 10;
const int maxn = 800;

int n, m, h[maxn], mat[maxn][maxn];
bool visited[maxn];

int cnt0, cnt1;
void dfs (int v) {
    visited[v] = 1;
    cnt0 += (h[v] % 2 == 0);
    cnt1 += (h[v] % 2 == 1);
    for (int u = 1; u <= n; u++) {
        if (!mat[v][u] and u != v) {
            if (!visited[u]) {
                h[u] = h[v] + 1;
                dfs (u);
            }
            if (h[u] % 2 == h[v] % 2) {
                cout << -1 << endl;
                exit (0);
            }
        }
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int v, u;
        cin >> v >> u;
        mat[v][u] = 1;
        mat[u][v] = 1;
    }
    bitset <1000> bs;
    bs[0] = 1;
    for (int i = 1; i <= n; i++) {
        if (!visited[i]) {
            cnt1 = 0, cnt0 = 0;
            dfs (i);
            bitset <1000> p = bs;
            p = (p << cnt1);
            bs = (bs << cnt0) | p;
        }
    }
    int ans = 1000000000;
    for (int i = 1; i < n; i++) {
        if (bs[i] == 1) {
            ans = min (ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2432
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 998244353;
const int N = 1600;
const int K = 26;
int b[N][N], ans[N][N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int k = 38;
    int n = k * (k - 1) + 1;
    cout << n << " " << k << endl;
    for (int i = 1; i <= k; i++){
        cout << i << " ";
    }
    int z = k;
    for (int i = 0; i < k - 1; i++){
        for (int j = 0; j < k - 1; j++){
            z++;
            b[i][j] = z;
        }
    }
    cout << endl;
    int l = 2;
    for (int i = 1; i <= k; i++){
        for (int j = 0; j < k - 1; j++){
            ans[l + j][1] = i;
        }
        if (i == 1){
            for (int j = 0; j < k - 1; j++){
                for (int q = 0; q < k - 1; q++){
                    ans[l + j][q + 2] = b[q][j];
                }
            }
        } else{
            int s = i - 2;
            for (int j = 0; j < k - 1; j++){
                for (int q = 0; q < k - 1; q++){
                    ans[l + j][q + 2] = b[(j + s * q) % (k - 1)][q];
                }
            }
        }
        l += (k - 1);
    }
    for (int i = 2; i <= 1; i++){
        for (int j = i + 1; j <= n; j++){
            int cnt = 0;
            for (int p1 = 1; p1 <= k; p1++){
                for (int p2 = 1; p2 <= k; p2++){
                    if (ans[i][p1] == ans[j][p2]) cnt++;
                }
            }
            if (cnt != 1) cout << "WRONG" << " " << cnt << endl;
        }
    }
    for (int i = 2; i <= n; i++){
        for (int j = 1; j <= k; j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }//
}


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

typedef long long ll;

using namespace std;

int main() {
	while (1) {
		ll b;
		cin >> b;
		if (b == 0)break;
		int n = 0;
		int low = 0, length = 0;
		while ((n + 1) * (n + 1) <= 2 * b) {
			if ((2 * b) % (n + 1) == 0 && ((2 * b) / (n + 1) - n) % 2 == 0) {
				ll a = ((2 * b) / (n + 1) - n) / 2;
				if (length <= n)length = n + 1, low = a;
			}
			n++;
		}
		cout << low << " " << length << endl;
	}
	return 0;
}


Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int N,K;
  cin >> N >> K;
  vector<int>vec(N);
  rep(i,N){
    cin >> vec[i];
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int sum=0;
  rep(i,K){
    sum+=vec[i];
  }
  cout << sum << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <cstring>
typedef long long ll;
using namespace std;
const long long MOD = 1e9 +7;
const ll SIZE = 500010;
class Combination{
  private:
    ll fct[SIZE];
    ll rfct[SIZE];
  public:
    Combination(){
      ll f = 1ll;
      fct[0]=1ll;
      rfct[0]=1ll;
      for(int i=1;i<SIZE;i++){
        fct[i]=(fct[i-1]*i)%MOD;
        rfct[i]=Repeat(fct[i],MOD-2);
      }
    }
    long long Repeat(long long a,long long cnt){
      if(cnt==0)return 1LL;
      if(cnt%2==1){
        long long x = Repeat(a,cnt/2);
        return (((a*x)%MOD)*x)%MOD;
      }
      else {
        long long x = Repeat(a,cnt/2);
        return (x*x)%MOD;
      }
    }

    long long fact(long long a){
      return fct[a];
    }

    long long conb(long long a, long long b){
      long long fa,fb,fab;
      fa = fact(a);
      fb = fact(b);
      fab = fact(a-b);
      fb = rfct[b];
      fab = rfct[a-b];
      return (((fa*fb)%MOD)*fab)%MOD;
    }
};

int main(){
  ll h,w,a,b,i,j;
  cin >> h >> w >> a >> b;
  ll ret = 0;
  Combination cn;

  for(i=b;i<w;i++){
    ret=(ret+(cn.conb(h-a-1+i,i)*cn.conb(a-1+w-1-i,a-1))%MOD)%MOD;
  }
  cout << ret << endl;
  return 0;
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n;
char s[N];

int main()
{
	scanf("%s", s);
	n = strlen(s);
	
	int res = 0, g = 0, p = 0;
	for (int i = 0; i < n; i ++ )
		if (g == p)
		{
			g ++ ;
			if (s[i] == 'p') res -- ;
		}
		else
		{
			p ++ ;
			if (s[i] == 'g') res ++ ;
		}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main()
{
    char a[110],b[110];
    int i,n;
    scanf("%d",&n);
    scanf("%s",a);
    scanf("%s",b);
    for(i=0;i<n;i++)
    {
        printf("%c%c",a[i],b[i]);
    }
    printf("\n");
}


Measured memory_bytes: 128
# dijkstraで解く
from heapq import heappush, heappop
from collections import defaultdict
INF = float("inf")

def dijkstra(C, g):
    '''
    各頂点からg「まで」の最小コストを求める
    C ... 隣接行列で表されたコスト
    g ... 終点
    '''
    n = len(C)
    min_cost = [INF] * n
    min_cost[g] = 0
    visited = defaultdict(bool)
    H = [(0, g)]

    while H:
        v_cost, v = heappop(H)
        if visited[v]: continue
        visited[v] = True
        for u in range(n):
            new_cost = C[u][v] + v_cost
            if new_cost < min_cost[u]:
                min_cost[u] = new_cost
                heappush(H, (new_cost, u))

    return min_cost


H, W = [int(x) for x in input().split()]
C = [[int(x) for x in input().split()] for _ in range(10)]
A = [[int(x) for x in input().split()] for _ in range(H)]

min_cost = dijkstra(C, 1)

ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == -1: continue
        ans += min_cost[A[i][j]]

print(ans)

Measured memory_bytes: 9772
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    for(int i = 0;s[i];i++)
    {
        int t = s[i] + n;
        if(t>'Z'){
            s[i] = 'A' + t -'Z'-1;
        }else{
            s[i] = s[i] + n;
        }
    }
    
    cout << s << endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll X;
ll t;
ll ret = 0;

void input() {
  IN(X);
}

void solve() {
  ll n = X / 100;
  ll r = X % 100;
  ll c = (r / 5) + ((r % 5 == 0)?0:1);
  if (c <= n) {
    PRINT(1);
  } else {
    PRINT(0);
  }
}

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


Measured memory_bytes: 256
A = input()
B = input()
C = input()
l = [A,B,C]
i = [0,0,0]
p = 0
while i[p] != len(l[p]):
  card = l[p][i[p]] 
  if card == "a":
    i[p] += 1
    p = 0
  if card == "b":
    i[p] += 1
    p = 1
  if card == "c":
    i[p] += 1
    p = 2
print(["A","B","C"][p])

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var children = new int[N];
			var A = cin.ReadIntArray(N-1);
			for(int i = 0; i<N-1; i++) {
				children[A[i]-1]++;
			}
			Console.WriteLine(children.Join("\n"));
		}

	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x]=A[y];
			A[y]=tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length);
		public static IEnumerable<int> Indices<T>(this T[,] X, int dim)
			=> Enumerable.Range(0, X.GetLength(dim));
		public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n")
			=> X.Indices(0).Select(
				i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)
			).Join(separatorD1);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}
}


Measured memory_bytes: 48688
a = input().split(' ')
tour = int(a[0])-1
no_vs = 0

if int(a[1]) != 0:
    absent = []
    for _ in range(int(a[1])):
        absent.append(int(input()))
    num = int(int(a[0])/2)
    while absent != []:
        next_absent = []
        for n in range(num):
            if 2*n in absent or 2*n+1 in absent:
                no_vs+=1
                if 2*n in absent and 2*n+1 in absent:
                    next_absent.append(n)
        absent = next_absent
        num = int(num/2)
            
print(tour-no_vs)
        


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

ll DIV = 1000000007;
ll ans[2001];

ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod)
{
  return modpow(a, mod - 2, mod);
}

ll modnCr(ll n, ll r, ll mod)
{
  ll ans = 1;
  FOR(i, 1, n + 1)
  {
    ans = (ans * i) % mod;
  }
  ll inv = 1;
  FOR(i, 1, r + 1)
  {
    inv = (inv * i) % mod;
  }
  FOR(i, 1, n - r + 1)
  {
    inv = (inv * i) % mod;
  }

  ans = (ans * modinv(inv, mod)) % mod;
  return ans;
}

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

  FOR(i, 1, k + 1)
  {
    if (i > n - k + 1)
    {
      ans[i] = 0;
      continue;
    }
    ans[i] = (modnCr(n - k + 1, i, DIV) * modnCr(k - 1, i - 1, DIV)) % DIV;
  }

  FOR(i, 1, k + 1)
  {
    cout << ans[i] << endl;
  }
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int plan1, plan2;
  plan1 = A*N;
  plan2 = B;
   
  if (plan1 < plan2)
    cout << plan1 << endl;
  else
    cout << plan2 << endl;
}

Measured memory_bytes: 256
#include<map>
#include<cstdio>
#include<iostream>
#define nc getchar
#define mp make_pair
using namespace std;
inline void read(int &x) {
	char b = nc(); x = 0;
	for (; !isdigit(b); b = nc());
	for (; isdigit(b); b = nc()) x = x * 10 + b - '0';
}
const int N = 200005;
int n, m1, m2;
struct UFS{
	int fa[N], rk[N];
	inline void init() {
		for (int i = 1; i <= n; ++i) fa[i] = i, rk[i] = 0;
	}
	int find(int x) {
		return fa[x] == x ? x : fa[x] = find(fa[x]);
	}
	inline void merge(int a, int b) {
		if ((a=find(a)) != (b=find(b))) {
			if (rk[a] < rk[b]) swap(a, b);
			fa[b] = a; rk[a] += rk[a] == rk[b];
		}
	}
} s1, s2;
map < pair < int , int > , int > cnt;
int main() {
	read(n); read(m1); read(m2);
	s1.init(); s2.init();
	for (int i = 0, u, v; i < m1; ++i)
		read(u), read(v), s1.merge(u, v);
	for (int i = 0, u, v; i < m2; ++i)
		read(u), read(v), s2.merge(u, v);
	for (int i = 1; i <= n; ++i)
		++cnt[mp(s1.find(i), s2.find(i))];
	for (int i = 1; i <= n; ++i)
		printf("%d ", cnt[mp(s1.find(i), s2.find(i))]);
	return 0;
}


Measured memory_bytes: 15104
inf = float('inf')
def main():
    n = int(input().rstrip())
    h = list(map(int, input().rstrip().split()))
    dp = [inf for i in range(n)]
    dp[0]=0
    for i in range(n):
        for j in [i+1, i+2]:
            if j<n:
                dp[j] = min(dp[j], dp[i]+ abs(h[i] - h[j]))
    print(dp[n-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 13976
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    int n;
    cin>>n;
    vll a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end(),greater<ll>());
    ll sum=a[0];
    int cnt=2;
    int i=1;
    while(cnt<n)
    {
        if(n>=cnt+2) sum+=2*a[i++],cnt+=2;
        else sum+=a[i++],cnt++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int sum=0;
    for(int i=0;i<k;i++){
        sum+=arr[i];
    }
    cout<<sum;



    return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("sse4.2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <complex>
#include <random>
#include <cassert>
#include <chrono>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#ifdef DEBUG
	mt19937 gen(857204);
#else
	mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

#ifdef DEBUG
    template<class T> T to_dbg(T x) { return x; }
    template<class T, class U> string to_dbg(pair<T, U> p) {
        stringstream ss;
        ss << '{' << p.f << ',' << p.s << '}';
        return ss.str();
    }
    string to_dbg(string s) { return "\"" + s + "\""; }
    template<class T> string to_dbg(vector<T> a) {
        stringstream ss;
        ss << '{';
        if (sz(a)) ss << to_dbg(a[0]);
        for (int i = 1; i < sz(a); ++i)
            ss << "," << to_dbg(a[i]);
        ss << '}';
        return ss.str();
    }
    template<class T>
    void dbgout(T x) { cout << to_dbg(x) << endl; }
    template<class T, class... U>
    void dbgout(T t, U... u) {
        cout << to_dbg(t) << ", ";
        dbgout(u...);
    }
    #define dbg(...) cout << "[" << #__VA_ARGS__ << "] = ", dbgout(__VA_ARGS__);
#else
    #define dbg(...) 0
#endif

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
template<class T> inline T sorted(T a) { sort(a); return a; }

signed main() {
	FAST; FIXED;
	string s;
	cin >> s;
	if (s[1] == 'B') s[1] = 'R';
	else s[1] = 'B';
	cout << s;
	#ifdef DEBUG
		cerr << "Runtime is: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}

Measured memory_bytes: 3644
def main():
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(input())

    cnt_dict = {}
    for i in range(h):
        for j in range(w):
            cnt_dict[a[i][j]] = cnt_dict.get(a[i][j], 0) + 1

    cnt_odd, cnt_even, cnt_f, max_odd = 0, 0, 0, 0
    for i in cnt_dict:
        if cnt_dict[i] % 4 == 0:
            cnt_f += 1
        if cnt_dict[i] % 2 == 0:
            cnt_even += 1
        else:
            cnt_odd += 1
            max_odd = max(max_odd, cnt_dict[i]) % 4

    if h % 2 == 0 and w % 2 == 0:
        if cnt_odd == 0 and cnt_even == cnt_f:
            print("Yes")
        else:
            print("No")
    elif h % 2 and w % 2:
        if cnt_odd == 1 and cnt_even - cnt_f <= h // 2 + w // 2 - max_odd // 2:
            print("Yes")
        else:
            print("No")
    else:
        if h % 2 == 0:
            u = h
        else:
            u = w
        if cnt_odd == 0 and cnt_even - cnt_f <= u // 2:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <algorithm>
//#include <stdio.h>
//#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

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

int n;
int c[500],s[500],f[500];

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

	cin>>n;
	REP(i,n-1) cin>>c[i]>>s[i]>>f[i];

	REP(i,n-1) {
		int sum=s[i]+c[i],now=s[i]+c[i];
		FOR(j,i+1,n-1) {
			if(sum<=s[j]) sum=s[j]+c[j];
			else {
				sum=(sum/f[j]+(sum%f[j]?1:0))*f[j]+c[j];
			}
		}
		cout<<sum<<endl;
	}
	cout<<0<<endl;

	return 0;
}


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

int main() 
{
	long long int n,a[1000],i,j,ans=0,f;
	
	cin>>n;
	
	for(i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	
	ans=1;
	
	for(i=1;i<n;i++)
	{
	    f=0;
	    for(j=0;j<i;j++)
	    {
	        if(a[i]<a[j])
	        {
	            f=1;
	        }
	    }
	    if(f==0)
	    {
	       ans++;
	    }
	}
	
	cout<<ans;
	
	return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    if(s=="RRR") cout << 3 << endl;
    else if(s=="RSS"||s=="SRS"||s=="SSR"||s=="RSR") cout << 1 << endl;
    else if(s=="SSS") cout << 0 << endl;
    else cout << 2 << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int n;
vector<int> res;
vector<int> l;
const int INF = 1e18;
int calc(vector<int> v){
	vector<int> p(4,0);
	vector<int> cnt(4,0);
	rep(i,n){
		p[v[i]] += l[i];
		cnt[v[i]]++;
	}
	int ret = 0;
	rep(i,3)ret += max(0ll,(cnt[i]-1)*10);
	rep(i,3)ret += abs(res[i] - p[i]);
	// if(ret <= 243)trace(v,p,cnt,ret);
	rep(i,3)if(cnt[i] == 0)return INF;
	return ret;
}
int dfs(int d,vector<int> &v){
	if(d == n)return calc(v);
	int ret = INF;
	rep(i,4){
		v.push_back(i);
		ret = min(ret,dfs(d+1,v));
		v.pop_back();
	}
	return ret;
}
signed main(){
	res.resize(4);
	cin >> n >> res[0] >> res[1] >> res[2];
	l.resize(n);
	rep(i,n)cin >> l[i];
	vector<int> v;
	cout << dfs(0,v) << endl;
	
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <stdio.h>

using namespace std;

int a[4], b[4];

int main(void) {
    while(~scanf("%d%d%d%d%d%d%d%d", &a[0], &a[1], &a[2], &a[3], &b[0], &b[1], &b[2], &b[3])) {
        int hit = 0, blow = 0;
        for(int i = 0; i < 4; i++) {
            if(a[i] == b[i]) {
                hit += 1;
            } else if(count(a, a + 4, b[i]) > 0) {
                blow += 1;
            }
        }
        printf("%d %d\n", hit, blow);
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<ll> b(n);
    rep(i, n) cin >> b[i];
    

    ll res = 0;
    rep(bit, 30) {
        vector<ll> A = a;
        vector<ll> B = b;
        rep(i, n) A[i] &= (1LL << (1+bit)) - 1;
        rep(i, n) B[i] &= (1LL << (1+bit)) - 1;
        sort(all(A));
        sort(all(B));

        ll cnt = 0;
        rep(i, n) {
            // 0b01XXX
            ll low = (1LL << bit) - A[i];
            ll high = (1LL << (1+bit)) - A[i];
            // low <= x < high
            ll idx1 = lower_bound(all(B), low) - B.begin();
            ll idx2 = lower_bound(all(B), high) - B.begin();
            cnt += idx2 - idx1;

            // 0b11XXX
            low = (1LL << (1+bit)) + (1LL << bit) - A[i];
            high = (1LL << (1+bit)) + (1LL << (1+bit)) - A[i];
            // low <= x < high
            idx1 = lower_bound(all(B), low) - B.begin();
            idx2 = lower_bound(all(B), high) - B.begin();
            cnt += idx2 - idx1;
        }
        if (cnt % 2 == 1) {
            res += 1LL << bit;
        }
    }

    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 9596
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T> &v) {
	T ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}

ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}

class UnionFind {
public:
	vl parent;
	UnionFind(ll n) {
		parent = vl(n, -1);
	}

	ll root(ll n) {
		if (parent.at(n) < 0)return n;
		parent.at(n) = root(parent.at(n));
		return parent.at(n);
	}

	ll size(ll n) {
		return -parent.at(root(n));
	}

	bool connect(ll a, ll b) {
		if (root(a) == root(b))return false;
		a = root(a); b = root(b);
		if (size(a) < size(b))swap(a, b);
		parent[a] += parent[b];
		parent[b] = a;
		return true;
	}
};

int main() {
	ll n, m;
	cin >> n >> m;
	auto ls = vvt(ll(0), m, 2);
	rep(i, 0, m) {
		cin >> ls[i][0] >> ls[i][1];
		ls[i][0]--; ls[i][1]--;
	}
	ll ans = 0;
	rep(i, 0, m) {
		UnionFind uni = UnionFind(n);
		rep(j, 0, m) {
			if (i == j)continue;
			uni.connect(ls[j][0], ls[j][1]);
		}
		ll count = 0;
		rep(i, 0, n) {
			if (uni.parent[i] < 0)count++;
		}
		if (count >= 2)ans++;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
using namespace std;
 
ll a,b,c,d;
inline ll solve()
{
	--a,--b,--c,--d;
	ll res=abs(a-c)+abs(b-d),t=1LL;
	for(rgi i=1;i<=33;++i) t*=3LL;
	for(rgi i=33;i>=0;--i)
	{
		for(rgi j=0;j<2;++j)
		{
			if(a/t==c/t&&(a/t)%3LL==1LL&&abs(b/t-d/t)!=1LL&&abs(b-d)>=t)
			{
				ll mn=std::min(a,c),mx=std::max(a,c);
				return res+std::min(mn-mn/t*t+1LL,(mx/t+1LL)*t-mx)*2LL;
			}
			std::swap(a,b),std::swap(c,d);
		}
		t/=3LL;
	}
	return res;
}
 
signed main()
{
	rgi q;
	std::cin>>q;
	while(q--)
	{
		std::cin>>a>>b>>c>>d;
		std::cout<<solve()<<std::endl;
	}
	return 0;
}
// ----------------------------
// by imzzy


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define adrep(i,s,n) for (int i=(s);i<(n);i++)
using namespace std;
typedef long long ll;

int main(){

  int N;
  cin>>N;
  double a=0;
  
  double sumrep=0;
  rep(i,N){

    cin>>a;
    
    sumrep+=1/a;

  }

  double sum=1/sumrep;
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int n;
	int i, v,j;
	int last;
	int a[100];
	scanf("%d", &n);
	
	for(i =0;i<n;i++){
		scanf("%d", &a[i]);
	}
	
	for(i = 1;i<n;i++){
		for(last =0;last<n;last++){
			printf("%d", a[last]);
		if(last != n-1)
		printf(" ");
		}
		printf("\n");
		v=a[i];
		j=i-1;
		while(j>=0 && a[j]>v){
			a[j+1] = a[j];
			j--;
		}
	a[j+1] = v;
	}
	for(last =0;last<n;last++){
			printf("%d", a[last]);
		if(last != n-1)
		printf(" ");
		}
	printf("\n");
	return 0;
}



Measured memory_bytes: 2036