akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}


struct State {
  ll n;
  ll cost;
  bool operator < (const State& o) const {
    return cost > o.cost;
  }
};

int main2() {
  ll N = nextLong();
  ll A = nextLong();
  ll B = nextLong();
  ll C = nextLong();
  ll D = nextLong();

  priority_queue<State> pq;
  pq.push((State){ N, 0 });
  map< ll, ll > dp;

  ll ans = -1;
  while (!pq.empty()) {
    auto s = pq.top(); pq.pop();

    if (s.n == 0) {
      ans = s.cost;
      break;
    }

    const ll n = s.n;

    vector<State> nxts;
    if ((double)n * (double)D <= 1e17) {
      State nxt = { 0, s.cost + n * D };
      nxts.push_back(nxt);
    }

    {
      ll m = n / 2 * 2;
      nxts.push_back((State){ m/2, s.cost + abs(n-m) * D + A });
    }
    {
      ll m = (n + 1) / 2 * 2;
      nxts.push_back((State){ m/2, s.cost + abs(n-m) * D + A });
    }

    {
      ll m = n / 3 * 3;
      nxts.push_back((State){ m/3, s.cost + abs(n-m) * D + B });
    }
    {
      ll m = (n + 2) / 3 * 3;
      nxts.push_back((State){ m/3, s.cost + abs(n-m) * D + B });
    }


    {
      ll m = n / 5 * 5;
      nxts.push_back((State){ m/5, s.cost + abs(n-m) * D + C });
    }
    {
      ll m = (n + 4) / 5 * 5;
      nxts.push_back((State){ m/5, s.cost + abs(n-m) * D + C });
    }


    for (State nxt : nxts) {
      if (dp.count(nxt.n) == 0 || dp[nxt.n] > nxt.cost) {
        dp[nxt.n] = nxt.cost;
        pq.push(nxt);
      }
    }

  }


  cout << ans << endl;

  return 0;
}

int main() {
  int t = nextLong();
  while (t--)
    main2();
  return 0;
}

Measured memory_bytes: 4220
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int ans = scanner.nextInt();
			if (ans == 0)
				break;
			for (int i = 0; i < 9; i++)
				ans -= scanner.nextInt();
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 17188
import java.util.Scanner;

public class Main {
	int[] a;
	int n=2;
	public static void main(String[] args){
		Main test = new Main();
		Scanner inputScanner = new Scanner(System.in).useDelimiter("\\s");
		int n1 = inputScanner.nextInt();
		int q = inputScanner.nextInt();
		
		
		while (test.n < n1){
			test.n *= 2;
		}
	//	System.out.println(Integer.toString(test.n));
		test.a = new int[(2 * test.n)-1 ]; 
	//	System.out.println(test.a.length);
		for(int i=0;i<test.a.length;i++){
			test.a[i]=0;
		}
		
		
		
		
		int cmd=-1;
		int arg1;
		int arg2;
		for(int j =0;j<q;j++){
			cmd = inputScanner.nextInt();
			arg1=inputScanner.nextInt();
			arg2=inputScanner.nextInt();
			
			if(cmd ==0)
				test.update(arg1, arg2);
			else if(cmd ==1)
				System.out.println(test.findSum(arg1, arg2));
		}
	}
	
	public void update(int k, int b){
		k += (n-2);
		a[k] += b;
		while(k > 0){
			k = (k-1)/2;
			a[k] = Integer.min(a[(k*2)+1], a[(k*2)+2]);
		}
	}
	
	public int findMin(int b, int c){
		
		return query(b,c+1,0,0,n);
	}
	
	public int query(int b, int c, int k, int l, int r){
		if (r <= b || c <= l)
			return Integer.MAX_VALUE;
		if((b<=l && r<=c))
			return a[k];
		
		int o1 = query(b,c,(k*2)+1,l,(l+r)/2);
		int o2 = query(b,c,(k*2)+2,(l+r)/2,r);
		return Integer.min(o1, o2);	
	}
	
	public int findSum(int b, int c){
// 		if(b==c)
// 			return a[b+n-2];
// 		if(b>c)
// 			return findSum(c,b);
// 		return a[b+n-2]+ findSum(b+1,c);
int i=0;
		while(b<=c){
			i += a[b+n-2];
			b++;
		}
		return i;
	}
}





Measured memory_bytes: 103520
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;


int main() {

	
	int ans = 0;
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		a = min(a, k - a);
		ans += 2 * a;
	}
	cout<<ans<<endl;

	return 0;
	
}


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

struct UniFi {
    vector<int> par;
    UniFi (int n) {
        par.resize(n);
        for (int i = 0; i < n; i++) par[i] = i;
    };

    int is_par(int x) {
        if (x == par[x]) return x;
        else return (par[x] = is_par(par[x]));
    }

    void unite(int x, int y) {
        x = is_par(x);
        y = is_par(y);

        if (x < y) par[y] = x;
        else par[x] = y;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<double> x(N), y(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    vector<int> p(M), q(M);
    vector<pair<double,int> > len(M);
    for (int i = 0; i < M; i++) {
        cin >> p[i] >> q[i];
        p[i]--, q[i]--;
        int a = p[i];
        int b = q[i];
        len[i] = pair<double,int>(-sqrt(pow(x[a] - x[b], 2.) + pow(y[a] - y[b], 2.)), i);
    }
    sort(len.begin(),len.end());

    UniFi ff(N);
    double ans = 0.0;
    for (int i = 0; i < M; i++) {
        int a = p[len[i].second];
        int b = q[len[i].second];
        if (ff.is_par(a) != ff.is_par(b)) {
            ff.unite(a, b);
        } else {
            ans -= len[i].first;
        }
    }

    printf("%.8f\n", ans);

    return 0;
}

Measured memory_bytes: 3680
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.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

#A
def A():
    n = I()
    print((n-(n>>1))/n)
    return

#B
def B():
    n,k = LI()
    h = LI()
    ans = 0
    for i in h:
        if i >= k:
            ans += 1
    print(ans)
    return

#C
def C():
    n = I()
    a = LI()
    b = [(a[i],i+1) for i in range(n)]
    b.sort()
    ans = [b[i][1] for i in range(n)]
    print(*ans)
    return

#D
def D():
    def divisor(n):
        if n < 4:
            return set([n])
        res = set([1])
        i = 2
        m = n
        while i**2 <= n:
            if m%i == 0:
                while m%i == 0:
                    m //= i
                res.add(i)
            i += 1
        res.add(m)
        return res
    a,b = LI()
    if min(a,b) == 1:
        print(1)
        return
    s = divisor(a)
    t = divisor(b)
    s &= t
    print(len(s))
    return

#E
def E():
    n,m = LI()
    v = []
    for i in range(m):
        a,b = LI()
        c = LI()
        s = 0
        for j in c:
            s |= 1<<(j-1)
        v.append((a,s))
    l = 1<<n
    dp = [[float("inf")]*l for i in range(m+1)]
    dp[0][0] = 0
    for i in range(m):
        ni = i+1
        a,c = v[i]
        for b in range(l):
            if dp[i][b] == float("inf"):
                continue
            nb = b|c
            nd = dp[i][b]+a
            if nd < dp[ni][nb]:
                dp[ni][nb] = nd
            nd = dp[i][b]
            if nd < dp[ni][b]:
                dp[ni][b] = nd
    if dp[m][-1] == float("inf"):
        print(-1)
    else:
        print(dp[m][-1])
    return

#F
def F():

    return

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


Measured memory_bytes: 135948
n = int(input())
s = [list(input()) for _ in range(n)]

s_dict = dict([])

for i in s:
    key = ''.join(sorted(i))
    try:
        s_dict[key] += 1
    except KeyError:
        s_dict[key] = 1

ans = 0
for v in s_dict.values():
    ans += v * (v - 1) // 2
print(ans)

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

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


    string s,s2;
    cin >> s >> s2;
    ll ans = 0;
    for(int i=0; i<s.size(); i++)
    {
        if (s[i] != s2[i]) ans++;
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 3800
#include<stdio.h>
 
int main(){
     
char number[1001]={0};
int i,sum=0;
 
 
while(1){
    sum=0;
    scanf("%s",&number);
    if(number[0]== '0' ) break;
     
    for(i=0;number[i]!='\0';i++){
            sum=sum+(number[i]-'0');
    }
    printf("%d\n",sum);
}
return 0;
 
}

Measured memory_bytes: 536
#include<stdio.h>
#include<iostream>
#include<math.h> 
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n;
ll a[100000+100];
bool cmp(int a,int b)
{
	return a>b;
 } 
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	int ss=a[1],minn=ss;
	sort(a+1,a+n+1,cmp);
	while(a[2]!=0)
	{
		ss=min(ss,minn);
		minn=0x3f3f3f3f;
		for(int i=1;i<n;i++)
		{
			if(a[i]==0)
			break;
			if(a[i]==ss&&a[i+1]==0)
			break;
			a[i]=a[i]%ss;
			if(minn>a[i]&&a[i]!=0)
			{
				minn=a[i];
			}
			
		}
		sort(a+1,a+n+1,cmp);
	}
	printf("%lld\n",a[1]);
	return 0;
}

Measured memory_bytes: 1024
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素



signed main(){
  int a,b;
  cin>>a>>b;
  string A,B;
  for(int i=0;i<b;i++)A+=to_string(a);
  for(int i=0;i<a;i++)B+=to_string(b);
  if(A<B)cout<<A<<endl;
  else cout<<B;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#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 trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);

        int n,m;
        cin >> n >> m;
        int i,j;
        char a[n+1][m+1];
        for(i=1; i<=n; i++){
            for(j=1; j<=m; j++){
                cin >> a[i][j];
            }
        }
        int dp[n+1][m+1];
        memset(dp,0,sizeof(dp));
        dp[1][1]=1;
        for(i=1; i<=n; i++){
            for(j=1; j<=m; j++){
                if(a[i][j]=='.')
                dp[i][j]+=(dp[i][j-1]%mod+dp[i-1][j]%mod)%mod;
                
            }
        }


        cout << dp[n][m] << '\n';

        

}

Measured memory_bytes: 9088
import Control.Applicative
import Control.Monad
import Data.Char (digitToInt)

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> replicateM n getLine >>= print
    main

solve :: [String] -> Int
solve = snd . head . foldr f []
  where
    f s st
      | c == '+' = (l, sum . map snd $ as): bs
      | c == '*' = (l, product . map snd $ as): bs
      | otherwise = (l, digitToInt c):st
      where
        l = length s
        c = last s
        (as, bs) = span ((== l+1) . fst) st



Measured memory_bytes: 4060
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

const int INF = 100000000;

vector<int> IntegerToVerctor(int bit, int N)
{
    vector<int> S;
    for (int i = 0; i < N; ++i)
    {
        if (bit & (1 << i))
        {
            S.push_back(i);
        }
    }
    return S;
}

int main()
{
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
        for (int j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }
    int mincost = INF;
    int cost;
    bool flag;
    vector<int> sum(M);
    for (int bit = 0; bit < (1<<N); ++bit)
    {
        cost = 0;
        flag = 1;
        for (int j = 0; j < M; j++)
        {
            sum[j] = 0;
        }
        vector<int> S = IntegerToVerctor(bit, N);
        for (int i : S)
        {
            cost += C[i];
            for (int j = 0; j < M; j++)
            {
                sum[j] += A[i][j];
            }
        }
        for (int i = 0; i < M; i++)
        {
            if(sum[i] < X)
            {
                flag = 0;
                break;
            }
        }
        if(flag == 1)
        {
            mincost = min(cost, mincost);
        }

    }

    if (mincost == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << mincost << endl;
    }
    
    return 0;
}




Measured memory_bytes: 3612
let nk = readLine()!.split(separator: " ").map {Int($0)!}
let n = nk[0] , k = nk[1]

let devidor = 998244353

var lrArray = [[Int]]()
for _ in 0..<k {
    lrArray.append(readLine()!.split(separator: " ").map {Int($0)!})
}

var dpTableOfAnswer = [Int](repeating: 0, count: n+1)
dpTableOfAnswer[1] = 1

var cumulativeSumOfdpTable = [Int](repeating: 0, count: n+1)
cumulativeSumOfdpTable[1] = 1
cumulativeSumOfdpTable[0] = 0

for i in 2...n {
    for j in 0..<k {
        var smallest = i - lrArray[j][1] // i - r
        let largest = i - lrArray[j][0] // i - l
        if largest < 1 {
            continue
        } else {
            smallest = max(smallest, 1)
            dpTableOfAnswer[i] += (cumulativeSumOfdpTable[largest] - cumulativeSumOfdpTable[smallest-1]) % devidor
        }
    }
    dpTableOfAnswer[i] %= devidor
    cumulativeSumOfdpTable[i] = (cumulativeSumOfdpTable[i-1] + dpTableOfAnswer[i]) % devidor
}

print((dpTableOfAnswer[n]+devidor)%devidor)


Measured memory_bytes: 11444
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn pow(mut s: usize, mut n: usize, m: usize) -> usize {
    if m == 0 {
        return 1;
    }
    let mut temp = s;
    s = 1;
    while n > 0 {
        if n & 1 != 0 {
            s *= temp;
            s %= m;
        }
        n >>= 1;
        temp *= temp;
        temp %= m;
    }
    s
}

fn func(n: usize) -> usize {
    if n == 0 {
        return 0;
    }
    1 + func(n % n.count_ones() as usize)
}

#[fastout]
fn main() {
    input! {
        n:usize,
        x:Chars
    }
    let one_count = x.iter().filter(|&&z| z == '1').count();

    if one_count == 0 {
        for _ in 0..n {
            println!("{}", 1);
        }
        return;
    }

    let mut table = vec![0_usize; n + 1];
    let mut tablep1 = vec![0_usize; n + 1];
    let mut tablem1 = vec![0_usize; n + 1];
    for i in 0..n {
        if x[i] == '1' {
            table[i + 1] = pow(2, n - i - 1, one_count);
            tablep1[i + 1] = pow(2, n - i - 1, one_count + 1);
            tablem1[i + 1] = pow(2, n - i - 1, one_count - 1);
        }
    }

    for i in 1..=n {
        table[i] = (table[i - 1] + table[i]) % one_count;
        tablep1[i] = (tablep1[i - 1] + tablep1[i]) % (one_count + 1);
        tablem1[i] = if one_count == 1 {
            0
        } else {
            (tablem1[i - 1] + tablem1[i]) % (one_count - 1)
        };
    }

    for i in 0..n {
        if x[i] == '1' {
            if one_count == 1 {
                println!("{}", 0);
            } else {
                let buf =
                    (tablem1[i] + tablem1[n] + (one_count - 1) - tablem1[i + 1]) % (one_count - 1);
                println!("{}", 1 + func(buf));
            }
        } else {
            let buf = (tablep1[i] + tablep1[n] + (one_count + 1) - tablep1[i + 1]
                + pow(2, n - i - 1, one_count + 1))
                % (one_count + 1);
            println!("{}", 1 + func(buf));
        }
    }
}


Measured memory_bytes: 7828
from functools import reduce

def obsession(n, disliked):
    def nearest(digit):
        for i in range(digit, digit + 10):
            mod10 = i % 10
            if mod10 not in disliked:
                return (mod10, i != mod10)

    will_pay = list(map(int, str(n)))
    index = 0
    while index < len(will_pay):
        digit = will_pay[index]
        if digit in disliked:
            substitute, carry = nearest(digit)
            will_pay[index] = substitute

            # Propagate zeroes (or nearest) to the right
            i = index + 1
            substitute, _ = nearest(0)
            while i < len(will_pay):
                will_pay[i] = substitute
                i += 1

            # Propagate carry to the left
            i = index - 1
            while carry and i >= 0:
                substitute, carry = nearest(will_pay[i] + 1)
                will_pay[i] = substitute
                i -= 1
            if carry:
                will_pay.insert(0, nearest(1)[0])
                index += 1
        index += 1
    return reduce(lambda x, y: x * 10 + y, will_pay, 0)


if __name__ == '__main__':
    n, _ = map(int, input().split())
    disliked = set(map(int, input().split()))
    print(obsession(n, disliked))

Measured memory_bytes: 3572
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var pi = new int[n];
            for (var i = 0; i < n; i++)
            {
                pi[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(pi);
            pi[n - 1] /= 2;
            Console.WriteLine(pi.Sum());
        }
    }
}


Measured memory_bytes: 13268
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int a = rint, b = rint;
	(6 - a - b).writeln;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

x,y = na()
count = 1
for _ in range(10000):
    x = x*2
    if x > y:
        break
    count += 1
print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define maxn 200001
using namespace std;
int arr[maxn];
int main(int argc, char const *argv[])
{
	memset(arr, 0, sizeof(arr));
	ios_base::sync_with_stdio(false);
	int n,k; cin>>n>>k;
	for (int i = 0; i < n; ++i)
	{
		int t; cin>>t;
		arr[t]++;
	}
	priority_queue <pair<int, int> > pq;
	for (int i = 0; i < maxn; ++i)
	{
		if(arr[i] != 0)
			pq.push(make_pair(arr[i], i));
	}
	for (int i = 1; i <= k && pq.size() != 0; ++i){
		int t = pq.top().second;
		pq.pop();
		// cout<<t<<endl;
	}
	int answer = 0;
	while(pq.size() != 0)
	{
		answer += pq.top().first;
		pq.pop();
	}
	cout<<answer<<endl;
	return 0;
}

// 5 2
// 1 1 2 2 5

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

void Main()
{
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  ll sumHW = 0;
  rep(i,M) {
    cin >> A[i]; 
    sumHW+=A[i];
  }
  if (sumHW > N) {cout << -1 << endl; return;}
  cout << N-sumHW << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

Measured memory_bytes: 11088
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int d;
    while(cin >> d, d){
        int n, m;
        cin >> n >> m;
        vector<int> v(n+1,0), k(m);
        for(int i = 0; i < n-1; i++) cin >> v[i+1];
        v[n] = d;
        sort(v.begin(),v.end());
        int ans = 0;
        for(int i = 0; i < m; i++){
            int k;
            cin >> k;
            int j = 0;
            while(!(v[j] <= k && k <= v[j+1]) && j < n)j++;
            ans += min(abs(v[j]-k),abs(v[j+1]-k));
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3368
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	cin >> n;
	vll a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	LL ans = LLONG_MAX;
	for(LL t = -100; t <= 100; ++t){
		LL s = 0;
		for(LL x : a){
			s += (x - t) * (x - t);
		}
		ans = min(ans, s);
	}
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,T,A = map(int, input().split(' '))
ab = [list(map(int, input().split(' '))) for i in range(n-1)]
graph = [[] for i in range(n+1)]
parent = [0 for i in range(n+1)]
dist = [0 for i in range(n+1)]
root = A
order = []
stack = [root]
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if parent[x] == y:
            continue
        parent[y] = x
        stack.append(y)
for x in order:
    if x == root:
        continue
    dist[x] = 1+dist[parent[x]]
#print(dist)
dist_ini = dist[T]
ans = 0
if dist_ini > 2:
    ans += (dist_ini-1)//2
    for i in range(ans):
        T = parent[T]
    dist_n = (dist_ini-1)%2+1
else:
    dist_n = dist_ini
#print(dist_n,T)
stack = [(T,0)]
dist_final = 0
while stack:
    x,cnt = stack.pop()
    dist_final = max(dist_final,cnt)
    for y in graph[x]:
        if parent[x] == y:
            continue
        stack.append((y,cnt+1))
ans += dist_final
if dist_ini % 2 == 0:
    ans += 1
print(ans)


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

//pair<int int> 
#define pir pair<int, int>
vector<pair<pir,pir>> ans;
int main(){
    int H, W;
    int tmp;
    int Num[500][500] = {0};

    cin >> H >> W;

    for (int i= 0; i < H; i++){
        for (int j=0; j < W; j++){
            if (i == H - 1 && j == W - 1) break;
            cin >> tmp;
            Num[i][j] += tmp;
            if (Num[i][j] % 2 != 0){
                if (j != W - 1){
                    ans.push_back({{i+1, j+1}, {i+1, j+2}});
                    Num[i][j+1]++;
                }else {
                    ans.push_back({{i+1, j+1}, {i+2, j+1}});
                    Num[i+1][j]++;
                }
            } 
        }
    }
    cout << ans.size() << endl;
    for (auto p:ans){
        cout << p.first.first << " " << p.first.second << " " << p.second.first << " " << p.second.second << endl;
    }
}

Measured memory_bytes: 5104
#ABC 096 C Grid Repainting 2

#数字の入力
#外枠を作ってカウントをやりやすくする
h, w = map(int, input().split())
s = []
waku = "a"*(w+2)
s.append(waku)
for i in range(h):
    kari = "a" + input() + "a"
    s.append(kari)
s.append(waku)
#ここまでで枠付きの文字列を入力した。調べるべきはs[1~h][1~w]
#検索対象は(i-1,j),(i,j-1),(i+1,j),(i,j+1)
k = [-1,0,1,0]
l = [0,-1,0,1]
#s[i + k[0~3]][j + l[0~3]]で検索可能

#"#"マークがある上下左右に#マークがあればセーフ。孤立しているのが一つでもあるとアウト
flag = 1#1なら成功、0なら失敗
for i in range(1,h + 1):
    for j in range(1,w+1):
        count = 0
        if s[i][j] == "#":
            for m in range(4):#前後探しループ
                if s[i+k[m]][j+l[m]] == "#":
                    count = 1 #1つでも見つけたフラグを立てる
            if count == 0:
                flag = 0 #1度でもcountが0にならずに前後探しループが終わったらアウト
if flag == 0:
    print("No")
if flag == 1:
    print("Yes")         
                
            


Measured memory_bytes: 3064
import numpy as np

N = int(input())
task = []
for i in range(N):
    a, b =map(int, input().split())
    task.append([a, b])

task = np.array(task)
task = task[np.argsort(task[:, 1])]

time = 0
for i in range(N):
    time += task[i, 0]
    if time > task[i, 1]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 46916
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int a[N];

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	ll ans=0;
	int last=0,num=0;
	for(int i=1;i<=n;i++){
		/*if(num&&a[i])ans++,a[i]--;
		ans=ans+1ll*a[i]/2;
		if(a[i]%2)num=1;*/
		ans+=a[i]/2;
		a[i]%=2;
		if(a[i]&&a[i+1])a[i]--,a[i+1]--,ans++;
		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
  int i=0,j;
  char str,ch[20];

  while(scanf("%c",&str)!=EOF)
    {
      ch[i]=str;
      //printf("%c",ch[i]);
      i++;
    }

  for(j=i-2;j>=0;j--)
    {
      printf("%c",ch[j]);
    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <memory.h>
using namespace std;

struct matrix {
	int row;
	int col;
};
int main()
{
	int N;
	scanf("%d", &N);
	matrix vec[100];
	memset(vec, 0, sizeof(vec));
	for (int i = 0; i < N; ++i) {
		scanf("%d %d", &vec[i].row, &vec[i].col);
		//cin >> vec[i].row >> vec[i].col;
	}
	//vector<vector<int>> dp(N, vector<int>(N));
	int dp[100][100];
	memset(dp, 0, sizeof(dp));
	for (int len = 1; len < N; ++len) {
		for (int i = 0; i + len < N; ++i) {
			int j = i + len;
			dp[i][j] = 2147483647;
			for (int k = i; k < i + len; ++k) {
				dp[i][j] = min(dp[i][k] + dp[k + 1][j] + vec[i].row * vec[k].col * vec[j].col, dp[i][j]);
			}
		}
	}
	printf("%d\n", dp[0][N - 1]);
	//cout << dp[0][N - 1] <<endl;
	return 0;
}


Measured memory_bytes: 3248
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main(){
  ll n;
  cin >> n;
  string s;
  long double amount;
  long double sum=0;
  for(int i=0;i<n;i++){
    cin >> amount >> s;
    if(s == "JPY"){
      sum += amount;
    }else{
      sum += amount * 380000.0;
    }
  }
  cout << sum;
}


Measured memory_bytes: 256
import fractions as f
a,b,c,d=map(int,input().split())
x=b-a+1
l=c*d//f.gcd(c,d)
i=b//c-(a-1)//c
j=b//d-(a-1)//d
k=b//l-(a-1)//l
if d%c==0 or c%d==0:
  print(x-max(i,j))
else:
  print(x-i-j+k)


Measured memory_bytes: 5048
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int n,a,b,i,min=1000000000005;
	cin >> n;
	for(i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			a=i;
			b=n/i;
			if(a+b-2<min)
				min=a+b-2;
		}
	}
	cout << min << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	char c;
	cin>>c;
	if(c=='A'){
		cout<<"T"<<endl;
	}
	if(c=='T'){
		cout<<"A"<<endl;
	}
	if(c=='G'){
		cout<<"C"<<endl;
	}
	if(c=='C'){
		cout<<"G"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<string> str;
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string tmp;
        cin >> tmp;
        str.push_back(tmp);
    }
    sort(str.begin(), str.end());
    str.erase(unique(str.begin(), str.end()), str.end());
    cout << str.size();
    return 0;
}

Measured memory_bytes: 11600
intarray = STDIN.gets.split(" ")
a,b,c = intarray
a.to_i;b.to_i;c.to_i;
max = a
if b>max
 mid=max;max=b;
else
 mid=b
end

if c>max
 min=mid;mid=max;max=c;
else
 if c>mid
  min=mid;mid=c;
 else
  min=c
 end
end
puts "#{min} #{mid} #{max}"

Measured memory_bytes: 8608
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int A = in.nextInt();
    int B = in.nextInt();
    if (A <= 8 && B <= 8) {
      System.out.println("Yay!");
    } else {
      System.out.println(":(");
    }
  }
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s, t;
  cin >> s >> t;
  bool sysflag = false;

  ll n = s.size();
  REP(i, n){
    if(s == t)
      sysflag = true;
    s = s[n-1] + s.substr(0, n-1);
  }

  if(sysflag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  
}


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

int main(){
    vector<int> A(5);
    int k;
    for(int i=0; i<5; i++){
        cin >> A.at(i);
    }
    cin >> k;

    for(int i=0; i<5; i++){
        for(int j=i; j<5; j++){
            if(A.at(j)-A.at(i) > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#ifdef RUBICK
#include "dbg.h"
#else
#define dbg(exp) /* nop; */
#endif

// F cin/cout
#define cin nullptr
#define cout nullptr

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
using ld = long double;

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

    vector<vector<int>> graph(n);
    while (m--) {
        int x, y;
        scanf("%d %d", &x, &y);
        x --, y --;

        graph[x].push_back(y);
    }

    vector<int> dp(n, -1);

    const function<int(int)> f = [&](int node) {
        if (dp[node] != -1)
            return dp[node];

        int rc = 0;
        for (int child : graph[node]) {
            rc = max(rc, 1 + f(child));
        }

        return dp[node] = rc;
    };

    int ans = 0;
    for (int i = 0; i < n; i ++)
        ans = max(ans, f(i));

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

    return 0;
}



Measured memory_bytes: 8832
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#define MAX_INT 2100000000
using namespace std;
typedef long long int ll;
//#include "Header.h"
int main()
{
	int a, b,c;
	cin >> a >> b;
	c = max(a, b);
	cout << c + max(c - 1, a + b - c) << endl;
}


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

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scahf("%c",&a);
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}


const int N = 2e5 + 10;

struct Seg_Tree {
    struct T {
        int l, r, ans, add;
    } t[N * 4];

    void build(int p, int l, int r) {
        t[p].l = l, t[p].r = r, t[p].ans = t[p].add = 0;
        if (l == r) return;
        int mid = (l + r) >> 1;
        build(p << 1, l, mid);
        build(p << 1 | 1, mid + 1, r);
    }

    void spread(int p) {
        if (t[p].add) {
            t[p << 1].ans = t[p].l - t[p].add;
            t[p << 1].add = t[p].add;
            t[p << 1 | 1].ans = ((t[p].l + t[p].r) >> 1) + 1 - t[p].add;
            t[p << 1 | 1].add = t[p].add;
            t[p].add = 0;
        }
    }

    void change(int p, int l, int r, int c) {
        if (l <= t[p].l && t[p].r <= r) {
            t[p].ans = t[p].l - c, t[p].add = c;
            return;
        }
        spread(p);
        int mid = (t[p].l + t[p].r) >> 1;
        if (l <= mid)change(p << 1, l, r, c);
        if (r > mid)change(p << 1 | 1, l, r, c);
        t[p].ans = min(t[p << 1].ans, t[p << 1 | 1].ans);
    }

    int ask(int p, int x) {
        if (t[p].l == t[p].r)return x-t[p].ans;
        spread(p);
        int mid = (t[p].l + t[p].r) >> 1;
        return x <= mid ? ask(p << 1, x) : ask(p << 1 | 1, x);
    }
} tr;

int n, m, now = 1;

int main() {
    n = qr(), m = qr();
    tr.build(1, 1, m);
    repi(i, 1, n) {
        int l = qr(), r = qr();
        if (now >= l && now <= r)tr.change(1, now, r, -INF), now = r + 1;
        else if (now < l)tr.change(1, l, r, tr.ask(1, l - 1));
        if (now > m) {
            repi(j, i, n)puts("-1");
            return 0;
        }
        pi(i + tr.t[1].ans);
    }
    return 0;
}

Measured memory_bytes: 11964
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np


s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


def search(target):
    if len(target) == 0:
        return 0
    elif len(target) == 1:
        return target[0]
    else:
        count = 0
        if 0 not in target:
            for i in range(len(target)):
                target[i] -= 1
            count += 1
        cand = []
        while 0 in target:
            idx = target.index(0)
            cand.append(target[:idx])
            target = target[idx+1:]
        cand.append(target)
        for s in cand:
            count += search(s)
        return count


N = d_in()
h_list = ds_in()

print(search(h_list))


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


const int N = 3005;
int in[N];
int n;


int f(int x) {
    int rv = 0;
    for (int i = 0; i < n; ++i) rv += x % in[i];
    return rv;
}

int main() {
    scanf("%d", &n);
    long long res = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%d", in + i);
        res += in[i];
    }

    cout << res - n << endl;
}

Measured memory_bytes: 256
# from https://atcoder.jp/contests/abc142/submissions/7778197
n,m = gets.split.map!(&:to_i)

bin = Array.new(n+2)
bin[1] = 1
2.upto(n+1) {|i| bin[i] = bin[i-1] * 2}

dp = Array.new(bin[n+1],-1)

m.times do 
    a,_ = gets.split.map!(&:to_i)
    c = 0
    # cはいま対象としている鍵が開けれる箱をbitで表現したもの
    gets.split.each {|e| c += bin[e.to_i]}
    dp[c] = a if dp[c] == -1 || dp[c] > a

    x = dp.dup
    x.each_with_index do |e,i|
      next if e == -1
      # i | c は今の状態i(今持っている鍵で開けられる箱の種類数を保持しているbit)に対してc(今から手に入れる鍵で開けられる箱の種類数)をビット和を取っている。
      # これによっていま対象としている鍵を購入するとどの箱が開けられるようになるかの状態を取得した
      z = i | c

      # dpの中には値段が書かれている、with_index によるindexはすなわち状態を表している
      # dp[z]は遷移先、もし未記入(dp[z]=-1)だったり、今見ている鍵を利用したほうが安くなるなら結果を置き換える
      dp[z] = e + a if (dp[z] == -1 || dp[z] > e + a)
    end

    # いま対象としている鍵単体での値段も考える。
#    dp[c] = a if dp[c] == -1 || dp[c] > a
#    p dp
end

puts dp.last


Measured memory_bytes: 8700
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );

double rad(double deg){
  return deg * M_PI / 180.0;
}

int main(void){

  ll a,b,x;
  cin>>a>>b>>x;
  double theta_l=0.0;
  double theta_r=90.0;

  double theta=180.0;
  //double h1=a*sin( rad(theta) );
  //double h2=b*cos( rad(theta) );
  double vol=INT_MAX;

  cout << setprecision(10);

  double prev_theta=-180.0;

  //while(abs(x-vol)>1e-12){
  while(abs(prev_theta-theta)>1e-9){
    prev_theta=theta;
    theta=theta_l+(theta_r-theta_l)/2;
    double h1=a*sin( rad(theta) );
    double h2=b*cos( rad(theta) );
    if(h1>h2){
      vol=a*b*b/tan(rad(theta))/2;
    }
    else{
      vol=a*a*( b- a*tan(rad(theta))/2 );
    }
    //cout << x << "," << theta << "," << vol << endl;
    if(x>vol) theta_r=theta;
    else theta_l=theta;
  }
  cout << theta << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ld long double
#define tc() ll t;cin>>t;while(t--)
#define inp(n) ll n;cin>>(n)
#define inp2(n,m) ll n,m;cin>>(n);cin>>(m)
#define inp3(n,m,g) ll n,m,g;cin>>(n);cin>>(m);cin>>(g)
#define inps(s) string s;cin>>(s)
#define fr(i,n) for(ll i=0;i<n;i++)
#define rf(n,i) for(ll i=n-1;i>=0;i--)
#define vi vector<int >
#define vl vector<ll>
#define vd vector<ld>
#define vs vector<string >
#define pii pair<int,int>
#define pci pair<char ,int>
#define pic pair<int ,char>
#define psi pair<string ,int>
#define mii map<int ,int >
#define mci map<char ,int>
#define msi map<string ,int>
#define si set<int >
#define ss set<string>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007

int main() {
    fast
    int n; 
    cin>> n;
    vi a(n), b(n);
    for(int i=0;i<n;i++)
    cin >>a[i]>>b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if (n & 1)
        cout << b[n / 2] - a[n / 2] + 1 << endl;
    else {
        cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1 << endl;
    }
}


Measured memory_bytes: 4692
#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    int x[n];
    int y[n];
    int b[n];
    int p[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &x[i]);
        scanf("%d", &y[i]);
        scanf("%d", &b[i]);
        scanf("%d", &p[i]);
    }
    for(int i = 0; i < n; i++){
        int l = (x[i] * b[i]);
        int r = (y[i] * p[i]);
        if(5 <= b[i] && 2 <= p[i]){
            printf("%d\n", ((l + r) * 4) / 5);
        }
        else{
            if(b[i] < 5){
                b[i] = 5;
            }
            if(p[i] < 2){
                p[i] = 2;
            }
            int num = (x[i] * b[i]) + (y[i] * p[i]);
            if((l + r) > ((num * 4) / 5)){
                printf("%d\n", (num * 4) / 5);
            }
            else{
                printf("%d\n", l + r);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=1<<18;

int main(){
    int n,m;
    cin>>n>>m;
    vector<bool> a(n+1,true);
    for(int i=0;i<m;i++){
        int b;
        cin>>b;
        a[b]=false;
    }

    vector<ll> dp(n+3,0);
    dp[0]=1;

    for(int i=0;i<=n;i++){
        if(a[i+1]) dp[i+1]+=dp[i];
        if(a[i+2]) dp[i+2]+=dp[i];
        dp[i+1]%=MOD;
        dp[i+2]%=MOD;
    }
    cout<<dp[n]<<endl;

}

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define y1 dhwjdshg

using namespace std;

const int N = 200000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

ll get(ll n, ll k)
{
    if (n < k)
        return 0;
    else if (n % k == 0)
        return n / k;
    else if (k * k < n)
        return get(n - n / k - 1, k);
    else
    {
        ll del = n / k + 1;
        ll cnt = (n % k + del - 1) / del;
        return get(n - del * cnt, k);
    }
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    /*int n = 20, k = 6;
    int dp[n + 1];
    rep(i, 0, n + 1)
    {
        dp[i] = 0;
        set<int> was;
        rep(j, 1, i / k + 1)
            was.insert(dp[i - j]);
        while (was.count(dp[i]))
            dp[i]++;
    }
    rep(i, 0, n + 1)
        cout << i << " " << dp[i] << "\n";*/
    int t;
    cin >> t;
    ll ans = 0;
    rep(i, 0, t)
    {
        ll n, k;
        cin >> n >> k;
        ans ^= get(n, k);
    }
    cout << (ans != 0 ? "Takahashi\n" : "Aoki\n");
    return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
q = 2
flag = true
a.each do |i|
  q = i.lcm(q)
end
a.each do |i|
  flag = false if (q/2) % i == 0
end
puts flag ? (m + q/2) / q : 0

Measured memory_bytes: 25820
H,W=map(int,input().split())
if (H*W)%3==0:
    print(0)
else:
    s=10**10
    t=10**10
    for i in range(H):
        x=max(abs(W*i-(H-i)*(W//2)),abs(W*i-(H-i)*(W//2+W%2)),(H-i)*(W%2))
        y=max(abs(W*i-W*((H-i)//2)),abs(W*i-W*((H-i)//2+(H-i)%2)),W*((H-i)%2))
        b=min(x,y)
        if b<=s:
            s=b
        else:
            break
    for j in range(W):
        v=max(abs(H*j-(W-j)*(H//2)),abs(H*j-(W-j)*(H//2+H%2)),(W-j)*(H%2))
        w=max(abs(H*j-H*((W-j)//2)),abs(H*j-H*((W-j)//2+(W-j)%2)),H*((W-j)%2))
        c=min(v,w)
        if c<=t:
            t=c
        else:
            break
    
    print(min(s,t))

Measured memory_bytes: 3064