akhauriyash/Code-Regression huggingface dataset:
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}
use std::collections::HashMap;
fn main(){
    input!{
        n:usize,
        an:[i64;n],
    }
    let mut target:Vec<_> = an.iter().fold(HashMap::new(),|mut map:HashMap<_,_>,x| {
        let y = map.get(&x).map(|&i| i+1).unwrap_or(1);
        map.insert(x,y);
        map
    })
    .into_iter()
    .flat_map(|(k,v)| {
        if v >= 4 {
            vec![k,k]
        } else if v >= 2 {
            vec![k]
        } else {
            vec![]
        }
    })
    .collect();
    target.sort();
    target.reverse();
    let ans = if target.len() >= 2{ target[0] * target[1] } else { 0 };
    println!("{}",ans);
}

Measured memory_bytes: 12540
N = int(input())
As = []

for i in range(N):
    a = int(input())
    As.append(a)

sorted_As = sorted(As, reverse=True)
top_As = sorted_As[:2]

for i in range(N):
    if As[i] == top_As[0]:
        print(top_As[1])
    else:
        print(top_As[0])


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

using namespace std;
typedef long long ll;

#define N 100005

vector <tuple<int, int, int>> graph[N];

int position[N];
bool positioned[N];
int visited[N];

void dfs (int v){
    if (visited[v]) return;
    visited[v] = true;
    if (!positioned[v]){
        position[v] = 0;
        positioned[v] = true;
    }
    for (auto x: graph[v]){
        int u, d, p;
        tie(u, d, p) = x;
        int l = v, r = u;
        if (p == 1)
            swap(l, r);
       // cout << position[l] << " " << l << " " << position[r] << " " << r << " " << d << endl;
        if (!positioned[r]){
            positioned[r] = true;
            position[r] = position[l] + d;
        }
        if (!positioned[l]){
            positioned[l] = true;
            position[l] = position[r] - d;
        }
        if (position[r] - position[l] != d){
            printf ("No\n");
            exit(0);
        }
        dfs(u);

    }
}

int main(){
    int n, m;
    scanf ("%d %d", &n, &m);

    for (int i = 0; i < m; i++){
        int a, b, d;
        scanf ("%d %d %d", &a, &b, &d);
        graph[a].emplace_back (b, d, 0);
        graph[b].emplace_back (a, d, 1);
    }

    for (int i = 1; i <= n; i++){
        dfs(i);
    }
    printf ("Yes\n");
    return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel";
  }
  else {
    cout << "consonant";
  }
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 5005;
const int INF = 1e9 + 7;

int n, ans;
int h[maxn], sz[maxn];
int f[maxn][maxn][2], g[maxn][maxn][2];
vector<int> nei[maxn];

inline int mul(int x, int y){ return 1ll * x * y % INF; }
inline void uadd(int &x, int y){ (x += (y + INF) % INF) %= INF; return; }

inline void dfs(int u, int par){
	vector<int> son;
	FOR(i, 0, nei[u].size()){
		int v = nei[u][i];
		if(v == par)
			continue;
		dfs(v, u);
		son.PB(v);
	}
	int p = 0, q = 1;
	memset(g[p], 0, sizeof(g[p]));
	g[p][0][0] = 1;
	FOR(i, 0, son.size()){
		memset(g[q], 0, sizeof(g[q]));
		int v = son[i];
		REP(j, 0, sz[u]) FOR(o, 0, 2) if(g[p][j][o]) REP(j_, 0, sz[v]) FOR(o_, 0, 2) if(f[v][j_][o_]){
			uadd(g[q][j + j_][o ^ o_], mul(g[p][j][o], f[v][j_][o_]));
			uadd(g[q][j][o ^ o_ ^ 1], mul(g[p][j][o], mul(f[v][j_][o_], h[j_])));
		}
		sz[u] += sz[v];
		swap(p, q);
	}
	++sz[u];
	REP(j, 0, sz[u]) FOR(o, 0, 2)
		f[u][j + 1][o] = g[p][j][o];
	return;
}

int main(){
	scanf("%d", &n);
	FOR(i, 1, n){
		int u, v;
		scanf("%d%d", &u, &v);
		--u; --v;
		nei[u].PB(v);
		nei[v].PB(u);
	}
	h[0] = 1;
	REP(i, 2, n)
		h[i] = mul(i - 1, h[i - 2]);
	dfs(0, -1);
	REP(i, 0, n) FOR(o, 0, 2)
		uadd(ans, mul((o ? -1 : 1), mul(f[0][i][o], h[i])));
	printf("%d\n", ans);
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int x[200100], sortedX[200100];
    for(int i=0; i<n; i++){
        cin >> x[i];
    }
    for(int i=0; i<n; i++){
        sortedX[i] = x[i];
    }
    sort(sortedX, sortedX+n);
    for(int i=0; i<n; i++){
        if(sortedX[n/2] == sortedX[n/2 - 1]){
            cout << sortedX[n/2] << endl;
        }else{
            if(x[i] <= sortedX[n/2 - 1]){
                cout << sortedX[n/2] << endl;
            }else if(x[i] >= sortedX[n/2]){
                cout << sortedX[n/2 - 1] << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

int main() {
	int n, a, b[100005];
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a);
		b[a] = i;
	}
	for (int i = 1; i <= n; i++) {
		if (i > 1)
			putchar(' ');
		printf("%d", b[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<limits.h>

#define MAX 150

int m[MAX][MAX];
int r,c,n;
int p[MAX];
main(){
  int i,tocost=0;
  //int p[MAX];
  scanf("%d",&n);
  for(i = 1;i < n;i++){
    scanf("%d%d",&r,&c);
    p[i] = r;
  }
  scanf("%d%d",&r,&c);
   p[i] = r;
  p[i+1] = c;
  

 
  MatrixChainOrder(p,n);
  return 0;
  //printf("%d\n",tocost);
}
int MatrixChainOrder(int *a,int b){
  int i,j,l,k,q,n;
  n = b+1;
  for(i = 1;i <= n;i++)
    m[i][i] = 0;
  for(l = 2;l<=n;l++){
    for(i = 1;i <= n-l+1;i++){
      j = i+l-1;
      m[i][j] = INT_MAX;
      for(k = i;k <= j-1;k++){
	q = m[i][k] + m[k+1][j] + a[i - 1]*a[k]*a[j];
	m[i][j] = min(m[i][j],q);

      }
    }
  }
  printf("%d\n",m[i][j]);
}

int min(int a,int q){
if(a >= q)return q;
 else return a;
}

Measured memory_bytes: 656
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int A, B; std::cin >> A >> B;
  for (int i = 1; i <= 3; ++i) {
    if (A != i && B != i) {
      std::cout << i << std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9 + 5

int main()
{
    int n, k, i, a;

    cin >> n >> k;
    vector<int> h;
    vector<int> dp(n, INF);
    for (i = 0; i < n; i++)
    {
        cin >> a;
        h.push_back(a);
    }

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

    cout << dp[n - 1] << endl;
}

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


int main() {
  int X,Y;
  cin>>X>>Y;
  
  
  if(X%Y==0)
    cout<<-1<<endl;
  else if(Y%X==0)
    cout<<X<<endl;
  else
    cout<<X<<endl;
  
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	run()
}

func run() {
	setSpace()
	n, limit := int(readN()), readN()
	dp := make([][]int, n+1)
	// dp[i][sum_w] = v の最大値
	// dp[i][j] = i 番目までの品物を、重さを j 以下になるように選んだときの価値の最大値
	// chmax(dp[i-1][sum_w], dp[i-1][sum_w - w[i]] + v[i])
	dp[0] = make([]int, limit+1)
	for i := 0; i < n; i++ {
		w, v := readN(), readN()
		dp[i+1] = make([]int, limit+1)
		for sumW := 0; sumW <= limit; sumW++ {
			if sumW-w >= 0 {
				// i 番目の重さ以上の j で、価値の最大値を選択する
				chmax(&dp[i+1][sumW], dp[i][sumW-w]+v)
			}
			// i 番目の品物は使えない
			chmax(&dp[i+1][sumW], dp[i][sumW])
		}
	}

	fmt.Println(dp[n][limit])
}

func chmax(a *int, b int) {
	if *a > b {
		return
	}
	*a = b
}

// ------以下、ユーティリティ------

var sc = bufio.NewScanner(os.Stdin)

func setSpace() {
	sc.Split(bufio.ScanWords)
}

func read() string {
	sc.Scan()
	return sc.Text()
}

func readN() int {
	n, err := strconv.Atoi(read())
	if err != nil {
		panic(err)
	}
	return n
}


Measured memory_bytes: 81536
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    int stack_a;
    int stack_b;
    int judge = -1;

    if(a.equals(b)) judge = 0;
    else if(a.length() > b.length()) judge = 1;
    else if(a.length() < b.length()) judge = 2;
   	else if(a.length() == b.length()){
      for(int i = 0; i < a.length() && judge == -1; i++){
        stack_a = (int)a.charAt(i) - 48;
        stack_b = (int)b.charAt(i) - 48;
        if(stack_a > stack_b) judge = 1;
        else if(stack_a < stack_b) judge = 2;
      }
    }
    
    if(judge == 0) System.out.println("EQUAL");
    else if(judge == 1) System.out.println("GREATER");
    else if(judge == 2) System.out.println("LESS");
  }
}


Measured memory_bytes: 35552
using System;

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

			Console.WriteLine(a * b + " " + (a + b) * 2);
		}
	}
}



Measured memory_bytes: 15880
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
//struct edge{int to,cost;};
struct edge{int from,to,cost;};
typedef pair<int,int> P;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}
int l;
vector<edge>v;
signed main(){
	cin>>l;
	for(int i=1;i<=18;i++){
		v.pb({i,i+1,0});
		v.pb({i,i+1,(1<<(i-1))});
	}
	int sum=0;
	for(int i=19;i>=1;i--){
		while(l>=(1<<(i-1))){
			v.pb({i,20,sum});
			sum+=(1<<(i-1)),l-=(1<<(i-1));
		}
	}
	cout<<20<<" "<<v.size()<<endl;
	for(edge e:v)cout<<e.from<<" "<<e.to<<" "<<e.cost<<endl;
	return 0;
}


Measured memory_bytes: 256
n = input()
a = list(map(int, input().split()))


def chk(a, positive):
    ans = tmp = 0
    for x in a:
        tmp += x
        if positive and tmp < 1:
            ans += 1-tmp
            tmp = 1
        elif not positive and tmp > -1:
            ans += abs(-1-tmp)
            tmp = -1

        positive = not positive
    return ans

print(min((chk(a, True), chk(a, False))))

Measured memory_bytes: 14332
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,S[100000],q,T[50000],c=0,i,i2,toread,cnt;
	cin>>n;
	for(i=0;i<n;i++)cin>>S[i];
	cin>>q;
	for(i=0;i<q;i++)cin>>T[i];
	/*for(i=0;i<n;i++){
		for(i2=0;i2<n;i2++){
			if(S[i]<S[i2]){
				toread=S[i];
				S[i]=S[i2];
				S[i2]=toread;
			}
		}
	}*/
	sort(S,S+n);
	for(i=0;i<q;i++){
		cnt=0;
		toread=n;
		while(toread>1){
			if(toread%2==0)toread/=2;
			else toread=(toread+1)/2;
			if(S[(toread-1)+cnt]<T[i])cnt+=toread;
			else if(S[(toread-1)+cnt]==T[i]){
				c++;
				break;
			}
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 3616
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.function.BiConsumer;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int N = Integer.parseInt(in.next());
            int[] P = new int[N];
            int[] Q = new int[N];
            for (int i = 0; i < N; i++) {
                P[i] = Integer.parseInt(in.next());
            }
            for (int i = 0; i < N; i++) {
                Q[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            int[] array = new int[N];
            for (int i = 0; i < N; i++) {
                array[i] = i + 1;
            }
            int i = 0;
            int a = 0, b = 0;
            do {
                if (Arrays.equals(array, P)) {
                    a = i;
                }
                if (Arrays.equals(array, Q)) {
                    b = i;
                }
                i++;
            } while (nextPermutation(array));

            ans = Math.abs(b - a);
            // 出力
            out.println(ans);

        }

        static boolean nextPermutation(int[] array) {
            if (array.length <= 1) {
                return false;
            }
            BiConsumer<Integer, Integer> swap = (a, b) -> {
                int temp = array[a];
                array[a] = array[b];
                array[b] = temp;
            };
            int last = array.length;
            int i = last - 1;
            while (true) {
                int j = i;
                i--;
                if (array[i] < array[j]) {
                    int k = last;
                    while (array[i] >= array[--k]) ;
                    swap.accept(i, k);
                    while ((j != last) && (j != --last)) {
                        swap.accept(j++, last);
                    }
                    return true;
                }
                if (i == 0) {
                    int first = 0;
                    while ((first != last) && (first != --last)) {
                        swap.accept(first++, last);
                    }
                    return false;
                }
            }
        }

    }
}



Measured memory_bytes: 29140
#include <cstdio>
#include <algorithm>
using namespace std;
int A,B,C,K;

int main()
{
	scanf("%d%d%d%d",&A,&B,&C,&K);
	printf("%d",max(max((A<<K)+B+C,A+(B<<K)+C),A+B+(C<<K)));
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
long long n,sum,a[13]; //记得开long long
long long dfs(long long x,long long sum,long long sum1)
{
	if(x==1)
		return 2*sum+sum1+a[x]+sum1*10+a[x];
	return dfs(x-1,sum,sum1*10+a[x])+dfs(x-1,sum+sum1,a[x]); //分两种情况dfs
}
int main()
{
	cin>>n;
	while(n!=0)
		sum++,a[sum]=n%10,n/=10;
	cout<<dfs(sum,0,0)/2;
	return 0;
}

Measured memory_bytes: 3640
long long n,a,b,c,f[5006][5006],i,j,r,y,s,m=1000000007;main(){scanf("%llu%llu%llu%llu",&n,&a,&b,&c);if(b%2)exit(!puts("0"));for(f[0][0]=1;++i<=n;s=c+3)for(f[i][j=0]=1;++j<=i;)f[i][j]=(f[i-1][j-1]+f[i-1][j])%m;for(i=0;(s-=3)>=0;r+=y%m*f[a+b/2+i][i]%m,i++)if(b)for(y=j=0;j<=a&&j<=s;j++)y+=f[a][j]*f[s+b/2-1-j][b/2-1]%m;else if(s<=a)y=f[a][s];printf("%lld\n",r%m*f[a+b/2][a]%m);}

Measured memory_bytes: 193920
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main(){
  string s;
  ll l,d,i,j,k,mod=1e9+7;
  char z;
  cin>>s;
  l=s.length();
  vector<vector<ll>> m(6,vector<ll>(13)),dp(l+1,vector<ll>(13));
  for(j=1;j<13;j++){
    m[0][j]=j;
    for(i=1;i<6;i++) m[i][j]=10*m[i-1][j]%13;
  }
  dp[0][0]=1;
  for(i=0;i<l;i++){
    z=s[l-1-i];
    if(z=='?'){
      for(d=0;d<10;d++){
        k=m[i%6][d];
        for(j=0;j<13;j++) dp[i+1][(j+k)%13]=(dp[i+1][(j+k)%13]+dp[i][j])%mod;
      }
    }
    else{
      d=z-'0';
      k=m[i%6][d];
      for(j=0;j<13;j++) dp[i+1][(j+k)%13]=dp[i][j];
    }
  }
  cout<<dp[l][5]<<endl;
}

Measured memory_bytes: 16644
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
typedef long long ll;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int h,w,a,b;
    ll ans = 1;
    cin >> h >> w >> a >> b;
    COMinit();
    for(int i = b;i < w;i++){
        ll tmp = COM(h-a-1+i,i)*COM(a-2+w-i,w-1-i)%MOD;
        ans += tmp;
        ans %= MOD;
    }
    cout << ans-1 << endl;
}


Measured memory_bytes: 12160
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>

int main() {
  size_t N, K;
  scanf("%zu %zu", &N, &K);

  std::map<int, size_t> f;
  for (size_t i = 0; i < N; ++i) {
    int ai;
    scanf("%d", &ai);
    ++f[ai];
  }

  std::vector<size_t> B;
  for (const auto& p: f)
    B.push_back(p.second);

  std::sort(B.begin(), B.end());
  if (B.size() <= K) {
    puts("0");
  } else {
    printf("%d\n", std::accumulate(B.begin(), B.begin()+(B.size()-K), 0));
  }
}


Measured memory_bytes: 14960
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;


ll get_length(ll min_x, ll max_x){
    // printf("---- x_min=%lld, x_max=%lld ", min_x, max_x);
    ll length;
    if(min_x == 0){
        length = - max_x;
    }else{
        length = 2 * min_x * (max_x / min_x);
        // printf("mid length = %lld \n", length);
        length += get_length(max_x % min_x, min_x);
    }
    // printf("after length = %lld ----- \n", length);

    return length;
}

int main(){
    ll N, X, a, b;
    scanf("%lld %lld", &N, &X);
    a = min(X, N - X);
    b = N - a;
    ll ans = get_length(a, b) + N;
    printf("%lld\n", ans);
}

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

int main(){
	ll N,M; cin>>N>>M;

	vector<pair<ll,ll>> AB;
	rp(i,N){
		ll a,b; cin>>a>>b;
		AB.emplace_back(a,b);
	}

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

	ll yen = 0;
	rp(i,N){
		ll a,b; tie(a,b) = AB[i];
		ll c = min(M,b);
		yen += c*a;
		M -= c;
		if(M<=0)break;
	}
	cout<< yen <<endl;
}

Measured memory_bytes: 2420
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    char buf[64];
    int n, x;

    while(1){
        fgets(buf, sizeof(buf), stdin);
        sscanf(buf, "%d %d", &n, &x);
        if(n == 0 && x == 0) break;

        int count = 0;
        for(int i = 1; i <= n-2; i++){
            for(int j = i + 1; j <= n-1; j++){
                int k = x - i - j;
                if(k < 1 || k == i || k <= j || k > n) continue;
                count++;
            }
        }
        printf("%d\n", count);
    }

    return 0;
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)    cerr<<#x<<" : "<<x<<endl;
#define trace2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<" | "<<#z<<" : "<<z<<endl;
#define fast_io 	std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;


int main()
{
	fast_io;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(c-a)<=d){cout<<"Yes";return 0;}
	if(abs(b-a)<=d && abs(c-b)<=d){cout<<"Yes";return 0;}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from itertools import accumulate
import numba
import numpy as np


def debug(*x):
    print(*x)


# @numba.njit
# def solve(N, M, K, sA, sB):
#     "void()"

#     last_can_read = 0
#     for i in range(N + 1):
#         for j in range(M + 1):
#             if sA[i] + sB[j] <= K:
#                 if last_can_read < i + j:
#                     last_can_read = i + j
#             else:
#                 break

#     print(last_can_read)


@numba.njit
def solve(N, M, K, sA, sB):
    "void()"

    last_can_read = 0
    last_max_j = M
    for i in range(N + 1):
        j = last_max_j
        while j >= 0:
            if sA[i] + sB[j] <= K:
                if last_can_read < i + j:
                    last_can_read = i + j
                last_max_j = j
                break
            j -= 1

    print(last_can_read)


def main():
    N, M, K = map(int, input().split())

    AS = list(map(int, input().split()))
    BS = list(map(int, input().split()))

    sA = np.array([0] + list(accumulate(AS)))
    sB = np.array([0] + list(accumulate(BS)))
    # debug("s:sA,sB", sA, sB)
    solve(N, M, K, sA, sB)


T1 = '''
3 4 240
60 90 120
80 150 80 150
'''

T2 = '''
3 4 730
60 90 120
80 150 80 150
'''


def _test():
    """
    >>> as_input(T1)
    >>> main()
    3
    >>> as_input(T2)
    >>> main()

    """
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 127644
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	vector<int> vec;
	int c = 1;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] != s[i + 1]) {
			vec.emplace_back(c);
			c = 1;
		}
		else {
			c++;
		}
	}
	vec.emplace_back(c);
	for (int i = 0; i < vec.size(); i++) {
		if (i % 2 == 1) {
			if (vec[i] >= m) {
				cout << "-1" << endl;
				return 0;
			}
		}
	}
	vector<int> a;
	int now = vec.size() - 1;
	int co = m, ans = 0;
	for (now; now >= 0; now--) {
		if (now % 2 == 1) {
			co -= vec[now];
			if (co <= 0) {
				a.emplace_back(ans);
				co = m;
				ans = 0;
				now++;
				continue;
			}
			ans += vec[now];
		}
		else {
			if (co <= vec[now]) {
				vec[now] -= co;
				a.emplace_back(m);
				co = m;
				ans = 0;
				now++;
				continue;
			}
			else {
				co -= vec[now];
				ans += vec[now];
			}
		}
	}
	if (ans != 0) {
		a.emplace_back(ans);
	}
	for (int i = a.size() - 1; i >= 0; i--) {
		cout << a[i];
		if (i != 0) {
			cout << " ";
		}
	}
	cout << endl;
}

Measured memory_bytes: 3888
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    ll n,mod=pow(10,9)+7;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++) cin>>a[i];
    vector<ll> v(n);
    v[n-1]=a[n-1];
    for(ll i=n-2;i>=0;i--)  v[i]=(v[i+1]+a[i])%mod;
    ll ans=0;
    for(ll i=0;i<n-1;i++){
        ans += ((a[i]%mod) * (v[i+1]%mod))%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6424
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define INF (1<<30)-1
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> a(n); rep(i,n) cin >> a[i];
  ll ans = 0, tall = a[0];
  rep(i,n){
    if(a[i] < tall) ans += tall - a[i];
    chmax(tall,a[i]);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 4772
from bisect import bisect_left
import math
n = int(input())
lst = []
lst.append(1)
for i in range(2, int(math.sqrt(1000)) + 1):
    for j in range(2, 10):
        if i ** j <= 1000 and i ** j not in lst:
            lst.append(i ** j)

lst.sort()
print(lst[bisect_left(lst, n) - 1] if n not in lst else lst[bisect_left(lst, n)])

Measured memory_bytes: 3064
n,m,x,y=map(int,input().split())
Lx = sorted(list(map(int,input().split())))
Ly = sorted(list(map(int,input().split())))

if x >= y or Lx[-1] >= Ly[0] or Lx[-1] >= y or Ly[0] <= x:
        print('War')
else:
        print('No War')

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

# Union-Find木
class UnionFind:
    def __init__(self, n):
        self.n = n
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)
        # あるノードを根とする集合に属するノード数
        self.size = [1] * (n+1)
        # あるノードを根とする集合が木かどうか
        self.tree = [True] * (n+1)

    # 根の検索(グループ番号と言えなくもない)
    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # 木かどうかの判定用
        if x == y:
            self.tree[x] = False
            return
        if not self.tree[x] or not self.tree[y]:
            self.tree[x] = self.tree[y] = False

        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # あるノードの属する集合のノード数
    def get_size(self, x):
        return self.size[self.find(x)]

    # 木かどうかの判定
    def is_tree(self, x):
        return self.tree[self.find(x)]

    # 集合の数
    def len(self):
        res = set()
        for i in range(self.n+1):
            res.add(self.find(i))
        # グループ0の分を引いて返却
        return len(res) - 1

N,M=MAP()
uf=UnionFind(N)
for i in range(M):
    s,t=MAP()
    uf.union(s, t)

Q=INT()
for _ in range(Q):
    s,t=MAP()
    if uf.same(s, t):
        print('yes')
    else:
        print('no')



Measured memory_bytes: 12408
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.Scanner;
import java.util.TreeSet;


public class Main {

	private static int[] xDelta = {-1, 1, 0, 0},
						 yDelta = {0, 0, -1, 1};
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		while (n != 0)
		{
			ArrayList<Rect> rects = new ArrayList<Rect>();
			TreeSet<Integer> 	xCoors = new TreeSet<Integer>(),
								yCoors = new TreeSet<Integer>();
			
			for (int i = 0; i < n; i++)
			{
				int l = in.nextInt(),
						t = in.nextInt(),
						r = in.nextInt(),
						b = in.nextInt();
				
				Rect rec = new Rect(l, t, r, b);
				rects.add(rec);
				
				xCoors.add(l);
				xCoors.add(r);
				yCoors.add(t);
				yCoors.add(b);
			}
			
			ArrayList<Integer> uniqueX = new ArrayList<Integer>(xCoors);
			ArrayList<Integer> uniqueY = new ArrayList<Integer>(yCoors);
			
			Collections.sort(uniqueX);
			Collections.sort(uniqueY);
			
			int xn = uniqueX.size()*2 + 1,
				yn = uniqueY.size()*2 + 1;
			
			int[][] g = new int[xn][yn];
			
			for (Rect r : rects)
			{
				int x1i = uniqueX.indexOf(r.x1)*2 + 1,
					x2i = uniqueX.indexOf(r.x2)*2 + 1,
					y1i = uniqueY.indexOf(r.y1)*2 + 1,
					y2i = uniqueY.indexOf(r.y2)*2 + 1;
				
				for (int xi = x1i; xi <= x2i; xi++)	
				{
					g[xi][y1i] = -1;
					g[xi][y2i] = -1;
				}
				for (int yi = y1i; yi <= y2i; yi++)	
				{
					g[x1i][yi] = -1;
					g[x2i][yi] = -1;
				}
			}
			
			int regions = 0; 
			for (int x = 0; x < xn; x++)
			{
				for (int y = 0; y < yn; y++)
				{
					if (g[x][y] == 0)
					{
						g[x][y] = 1;
						
						Tuple p = new Tuple(x,y);
						regions++;
						Queue<Tuple> q = new ArrayDeque<Tuple>();
						q.add(p);
						
						while (!q.isEmpty())
						{
							Tuple t = q.poll();
							
							for (int i = 0; i < 4; i++)
							{
								int newX = t.x + xDelta[i],
									newY = t.y + yDelta[i];
								
								if (newX >= 0 && newX < xn && newY >= 0 && newY < yn)
								{
									if (g[newX][newY] == 0)
									{
										g[newX][newY] = 1;
										q.add(new Tuple(newX, newY));
									}
								}
							}
						}
					}
				}
			}
			
			System.out.println(regions);
			
			n = in.nextInt();
		}
	}
	
	private static class Tuple
	{
		int x, y;
		
		public Tuple(int x, int y)
		{
			this.x = x;
			this.y = y;
		}
	}
	
	private static class Rect
	{
		int x1, y1, x2, y2;
		
		public Rect(int x1, int y1, int x2, int y2)
		{
			this.x1 = Math.min(x1, x2);
			this.y1 = Math.min(y1, y2);
			this.x2 = Math.max(x1, x2);
			this.y2 = Math.max(y1, y2);
		}
	}
}

Measured memory_bytes: 77520
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int a,b,k;
    cin >> a >> b >> k;
    if(a >= k){
        cout << a-k << " " << b << endl;
    }else{
        int t = k-a;
        int t2 = b-t;
        if(t2 < 0)t2 = 0;
        cout << 0 << " " << t2 << endl;

    }

}


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

int main(){
  int N, X;
  
  cin >> N >> X;
  
  vector<int> L(N+1);
  L[0] = 0;
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    L[i+1] = L[i] + x;
  }
  
  int ans = 0;
  
  for (int i = 0; i <= N; i++){
    if(L[i] <= X){
      ans++;
    }
  }
  
  cout << ans;
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1; i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i >= 0;i--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back

#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second

const int INF = (INT_MAX/2);
const double eps = 1e-14;
const double PI = M_PI;

#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl



int main(){
  int N;
  vi input;
  cin >> N;
  REP(i,2 * N){
    int temp; cin >> temp;
    input.pb(temp);
  }
  sort(ALL(input));
  int ans = 0;
  REP(i,N){
    ans += min(input[2* i],input[2*i + 1]);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    const ll mod = 1e9+7;
    int n, m;
    cin >> n >> m;
    vector<bool> oks(n+1, true);
    rep(i, m) {
        int a; cin >> a;
        oks[a] = false;
    }

    vector<ll> dp(n+1);
    dp[0] = 1;
    rep(now, n) {
        for (int next = now+1; next <= min(n, now+2); next++) {
            if (oks[next]) {
                dp[next] += dp[now];
                dp[next] %= mod;
            }
        }
    }

    cout << dp[n] << endl;
    return 0;
}


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

struct Point{
    double x, y;
    Point(){}
    Point(double x, double y):x(x), y(y){}
    void initialize(double xi, double yi){ x = xi; y = yi;}

    double det(Point other){
        return x*other.y - y*other.x;
    }

    Point operator-(Point other){
        return Point(x-other.x, y-other.y);
    }
    Point operator+(Point other){
        return Point(x+other.x, y+other.y);
    }
    bool operator<(Point other){
        return make_pair(x, y) < make_pair(other.x, other.y);
    }
};

bool intersect(Point p1, Point p2, Point p3, Point p4){
    return (p1-p2).det((p3-p1)) * (p1-p2).det((p4-p1)) <= 0 && (p3-p4).det((p1-p3)) * (p3-p4).det((p2-p3)) <= 0;
}

Point rot(Point p, double theta){
    double cs = cos(theta);
    double sn = sin(theta);
    return Point(cs*p.x - sn*p.y, sn*p.x + cs*p.y);
}

int main(){
    int N;
    cin >> N;
    vector<double> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> B[i];

    int mxp = max_element(A.begin(), A.end()) - A.begin();
    rotate(A.begin(), A.begin()+mxp, A.end());
    A.push_back(A[0]);
    rotate(B.begin(), B.begin()+mxp, B.end());
    B.push_back(B[0]);

    vector<double> C(N+1);
    for(int i=1; i<N; i++) C[i+1] = 2*(C[i]+B[i]) - C[i-1];
    vector<Point> qs;
    for(int i=0; i<=N; i++){
        int k = qs.size();
        Point p(i, A[i]-C[i]);
        while(k>1 && (qs[k-1] - qs[k-2]).det(p - qs[k-1]) >= 0){
            qs.pop_back();
            k--;
        }
        qs.push_back(p);
    }
    vector<double> E(N);
    for(int i=0; i<N; i++){
        auto pl = *(lower_bound(qs.begin(), qs.end(), Point(i+1, -1e18))-1);
        auto pr = *(lower_bound(qs.begin(), qs.end(), Point(i, -1e18)));
        if(pl.x == i){
            E[i] = pl.y;
        }else{
            double l = i-pl.x, r = pr.x-i;
            E[i] = (r*pl.y + l*pr.y)/(l+r);
        }
        E[i] += C[i];
    }
    double ans = accumulate(E.begin(), E.end(), 0.0) / N;
    cout << fixed << setprecision(20) << ans << endl;
    return 0;
}


Measured memory_bytes: 14144
#include <iostream>
#include <map>
#include <vector>
#include <cmath>

#define point pair<double, double>

using namespace std;

int n;
vector<pair<double, double> > points;

void makeCurve(pair<double, double> p1, pair<double, double> p2, int n);

point makeVector(point a, point b);

int main() {
    cin>>n;
    //pair<double, double> start = make_pair(0.0,0.0);
    point start = make_pair(0,0);
    pair<double, double> end = make_pair(100.0,0.0);
    makeCurve(start, end, n);
    points.push_back(end);
    for (int i=0; i<points.size(); i++) {
        cout<<points[i].first<<" "<<points[i].second<<endl;
    }
    return 0;
}

point makeVector(point a, point b){
    point vec;
    vec = make_pair(b.first-a.first, b.second-a.second);
    return vec;
}

void makeCurve(pair<double, double> p1, pair<double, double> p2, int n){
    if (n>0) {
        point vec = makeVector(p1,p2); //p1??????p2??????????????????
        point s = make_pair(p1.first+vec.first/3, p1.second+vec.second/3);
        point t = make_pair(p1.first+vec.first*2/3, p1.second+vec.second*2/3);
        point vec1 = make_pair(vec.first/3, vec.second/3); //s??????t??????????????????
        point u = make_pair(s.first+cos(60*M_PI/180)*vec1.first-sin(60*M_PI/180)*vec1.second, s.second+sin(60*M_PI/180)*vec1.first+cos(60*M_PI/180)*vec1.second);
        makeCurve(p1, s, n-1);
        makeCurve(s, u, n-1);
        makeCurve(u, t, n-1);
        makeCurve(t, p2, n-1);
    }
    else if(n==0){
        points.push_back(p1);
    }
}

Measured memory_bytes: 1404
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>

using namespace std;

char c;

void solve(map<int,int> *num, map<int,int> *ans,int a)
{
	int n=0;
	for(int i=1;i<=9;i++)
	{
		n+=(*num)[i];
	}
	if(n==0)
	{
		(*ans)[a]++;
		return;
	}
	for(int i=1;i<=9;i++)
	{
		if((*num)[i]>=3)
		{
			(*num)[i]-=3;
			solve(num,ans,a);
			(*num)[i]+=3;
		}
	}
	for(int i=3;i<=9;i++)
	{
		if((*num)[i]&&(*num)[i-1]&&(*num)[i-2])
		{
			(*num)[i]--;
			(*num)[i-1]--;
			(*num)[i-2]--;
			solve(num,ans,a);
			(*num)[i]++;
			(*num)[i-1]++;
			(*num)[i-2]++;
		}
	}
}

int main(void)
{
	string s;
	while(getline(cin,s))
	{
		map<int,int> ans;
		map<int,int> num;
		for(int i=0;i<s.size();i++)
		{
			num[s[i]-'0']++;
		}
		for(int i=1;i<=9;i++)
		{
			if(num[i]!=4){
				num[i]++;
				for(int j=1;j<=9;j++)
				{
					if(num[j]<2)
					{
					}else{
						num[j]-=2;
						solve(&num,&ans,i);
						num[j]+=2;
					}
				}
				num[i]--;
			}
		}
		vector<int> tmp;
		for(int i=1;i<=9;i++)
		{
			if(ans[i]>0) tmp.push_back(i);
		}
		if(tmp.size()==0) cout<<0<<endl;
		else
		{
			for(int i=0;;i++)
			{
				cout<<tmp[i];
				if(i==tmp.size()-1)
				{
					cout<<endl;
					break;
				}
				cout<<' ';
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1200
n = int(input())
s = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

import itertools as it

stat = [i for i in it.product([0, 1], repeat=10)]
stat.pop(0)
ans = -10**9
for t_stat in stat:
    x = 0
    for i in range(n):
        tmp=[min(j, k) for j, k in zip(t_stat, s[i])]
        lll=tmp.count(1)
        x+=p[i][lll]
    ans = max(ans, x)
print(ans)


Measured memory_bytes: 43356
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main(){
    int n; cin >> n;
    long long sum = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            for (int k = 1; k <= n; k++)
            {
                int first = __gcd(i,j);
                sum += __gcd(first, k);
            }
        }
    }
    cout << sum;
        
}

Measured memory_bytes: 3636
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int k = sc.nextInt();
    int count = 0;
    for(int i=100;i>=1;i--){
      if(a%i == 0 && b%i == 0){
        count++;
      }
      if(count == k){
        System.out.println(i);
        break;
      }
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,t;
  cin >> n >> t;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  sort(a,a+n);
  ll dp[6666];
  fill(dp,dp+6666,-MAXL);
  dp[0]=0;
  rep(i,n) {
    rrep(j,t) dp[j+a[i].F]=max(dp[j+a[i].F],dp[j]+a[i].S);
  }
  ll ans=0;
  rep(i,6666) ans=max(ans,dp[i]);
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui M = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);i++)
#define FOR2(i,a,b) for (int i=(a);i<(b);i++)
#define MP make_pair
#define FAST ios_base::sync_with_stdio(false); cin.tie(0)

template<class T,class U>
 ostream &operator<<(ostream &os,const pair<T,U> &x) {
 return os<<"("<<x.first<<","<<x.second<<")";
 }

template<class T>
 ostream &operator<<(ostream &os,const vector<T> &x) {
    os << '[';
    if ( !x.empty() ) {
        std::copy (x.begin(), x.end(), std::ostream_iterator<T>(os, ","));
        os << "\b";
    }
    os << "]";
  return os;
 }
template<class T>
 ostream &operator<<(ostream &os,const vector<vector<T> > &x) {
    os << '[';
    if ( !x.empty() ) {
        for (auto v: x) os << v << ",";
        os << "\b";
    } else os << "[]";
    os << "]";
  return os;
 }


int main() {
    FAST;
  //  freopen ("in.txt", "r", stdin);
    int n; cin>> n;
    vi a(n+2);
    for(int i=1;i<=n;i++) cin>>a[i];
    a[0]=a[n+1]=0;
    ll s=0;
    for(int i=1;i<=n+1;i++) s += abs(a[i]-a[i-1]);
    for(int i=1;i<=n;i++){
        ll ss=s - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i-1]-a[i+1]);
        cout << ss << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n, k;
    cin >> n >> k;
    cout << (n % k ? 1 : 0) << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
class UF{
public:
	vector<int> par,num;
	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UF(int N):par(N),num(N,1){
		iota(all(par),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return;
		if(num[u]<num[v])swap(u,v);
		num[u]+=num[v];
		par[v]=u;
	}
	bool same(int u,int v){
		return find(u)==find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};
int main(){
    int n,q;
    cin>>n>>q;
    UF uf(n);
    while(q--){
        int t,a,b;
        cin>>t>>a>>b;
        if(t){
            cout<<uf.same(a,b)<<"\n";
        }else{
            uf.unite(a,b);
        }
    }
}

Measured memory_bytes: 4680