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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

int main(){
    string s; cin>>s;
    s = strReplace(s,"?","D");
    cout << s << "\n";
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define REP(i,x,y) for(ll i=x; i<=y; i++)
#define vll vector<ll>
using namespace std;
typedef long long ll;
ll const MAX = 1e5 + 5;

vll a(30);

ll f(ll l,ll x, ll r, ll y){
	if(r - l == 1){
		return 0;
	}
	ll ans = 1e18;
	REP(i, l + 1, r - 1){
		ans = min(ans, f(l, x, i, x + y) + f(i, x + y, r, y) + (x + y) * a[i]);
	}
	return ans;
}

int main(){
	ll n;
	cin >> n;
	REP(i,1,n){
		cin >> a[i];
	}
	cout << f(1,1,n,1) + a[1] + a[n] << endl; 
}

Measured memory_bytes: 256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()


int main() {
	int n, y;
	cin >> n >> y;
	rep(i, n + 1) {
		for (int j = 0; j < n - i + 1; j++) {
			int v = 1000 * i + 5000 * j + 10000 * (n - j - i);
			if (v == y) {
				cout << n - j - i << " " << j << " " << i << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}





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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n;
  unordered_map<int, int> D, T;
  for (int i = 0, d; i < n; ++i) {
    cin >> d;
    D[d]++;
  }
  cin >> m;
  for (int i = 0, t; i < m; ++i) {
    cin >> t;
    T[t]++;
  }
  bool ok = true;
  for (auto&& [i, cnt] : T) {
    if (!D.count(i) || D[i] < cnt) {
      ok = false;
    }
  }
  if (ok) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
  return 0;
}

Measured memory_bytes: 19696
import java.util.Scanner;

public class Main {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        for(int i=n-1;i>=0;i--){
            if(i==0) System.out.println(a[i]);
            else System.out.print(a[i]+" ");
        }
        sc.close();
    }
}


Measured memory_bytes: 26284
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace GreedyTakahashi
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split();
 
            long takahashiCookies = long.Parse(input[0]);
            long aokiCookies = long.Parse(input[1]);
            long requiredActions = long.Parse(input[2]);
 
            takahashiCookies = takahashiCookies - requiredActions;
            if(takahashiCookies < 0)
            {
                aokiCookies = aokiCookies + takahashiCookies;
                takahashiCookies = 0;
            }
            
            if(aokiCookies < 0)
            {
                aokiCookies = 0;
            }            
            Console.WriteLine(takahashiCookies + " " + aokiCookies);
        }
    }
}

Measured memory_bytes: 13140
import sys
from math import pi

def solve():
    input = sys.stdin.readline
    N, T = map(int, input().split())
    S = [int(i) for i in input().split()]
    count = 0
    S.append(10 ** 20)
    for i in range(1, N+1):
        if S[i] > S[i-1] + T: count += T
        else: count += S[i] - S[i-1]
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 26740
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N, R;  cin >> N >> R;
    if(N >= 10)
      cout << R << endl;
    else
      cout << R + 100 * (10 - N) << endl;
    
	return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    string s, t;
    cin >> s >> t;

    if (int(s.size()) < int(t.size())) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    bool tmp;
    int i;
    for (i = int(s.size()) - int(t.size()) ; i >= 0; i--) {
        tmp = true;
        for (int j = 0; j < int(t.size()); j++) {
            if (s[i+j] != t[j] and s[i+j] != '?') tmp = false;
        }
        if (tmp) {
            for (int j = 0; j < int(t.size()); j++) s[i+j] = t[j];
            break;
        }
    }

    if (!tmp) {
        cout << "UNRESTORABLE" << endl;
        return 0;        
    }

    for (int i = 0; i < int(s.size()); i++) {
        if (s[i] == '?') s[i] = 'a';
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
a=[int(i) for i in input().split()]
sum=0
for i in range(0,n):
    sum += a[i]
x = [a[0]]*n
xy = [None]*(n-1)
for i in range(1,n):
    x[i] = x[i-1]+a[i]
for i in range(0,n-1):
    xy[i] = abs(sum - 2*x[i])
print(min(xy))

Measured memory_bytes: 27864
S = input()
S1 = int(S[0] + S[1])
S2 = int(S[2] + S[3])

if 0 < S1 <= 12 and 0 < S2 <= 12:
    print('AMBIGUOUS')
elif 0 < S1 <= 12:
    print('MMYY')
elif 0 < S2 <= 12:
    print('YYMM')
else:
    print('NA')
    

Measured memory_bytes: 2940
from math import sqrt

X = int(input())

def is_prime(n):
    m = int(sqrt(n) + 1)
    for i in range(2, m):
        if n % i == 0:
            return False
    return True

ans = X
while True:
    if is_prime(ans):
        break
    ans += 1

print(ans)


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string S; cin >> S;
    int q; cin >> q;
    bool rev = false;
    list<char> chars(S.begin(), S.end());
    for(int i=0;i<q;i++){
        int t; cin >> t;
        if(t == 1){
            rev = !rev;
        }else{
            int f; char c;
            cin >> f >> c;
            if(rev){
                if(f == 1){
                    chars.push_back(c);
                }else{
                    chars.push_front(c);
                }
            }else{
                if(f == 1){
                    chars.push_front(c);
                }else{
                    chars.push_back(c);
                }
            }
        }
    }
    if(rev){
        reverse(chars.begin(), chars.end());
    }
    for(char c: chars){
        cout << c;
    }
    cout << endl;
}

Measured memory_bytes: 10064
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
const ll MAXN = 1e5;
vector<bool> used(MAXN,false);

int main(){
    int a,b;
    int sum = 1;
    int cnt = 0;
    cin >> a >> b;
    while(sum < b){
        sum += (a-1);
        cnt++;
    }
    if(sum >= b){
        cout << cnt << endl;
    }
    else{
        cout << cnt+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
char s[5];
int i,n;
int main()
{
    cin >>s;
    n=strlen(s);
    for (i=0;i<n-1;i++) if (s[i]==s[i+1])
    {
        cout <<"Bad";
        return 0;
    }
    cout <<"Good";
    return 0;
}


Measured memory_bytes: 256
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, A, B = rl()

if A*N <= B:
	print(A*N)
else:
	print(B)



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  LL sum=0;
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
  }
  sum/=2;
  for(int i=2;i<n;i+=2){
    sum-=a[i];
  }
  vector<LL> ans(n);
  ans[0]=sum*2;
  LL pre=sum;
  for(int i=1;i<n;i++){
    ans[i]=(a[i]-pre)*2;
    pre=a[i]-pre;
  }
  cout << ans[n-1] << " ";
  rep(i,n-1) cout << ans[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 2432
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int s[210][210];//水路
int l[210][210];//?路
int d[1010][210];//dp
int b[1010];//目?路?

const int INF = 0x3f3f3f3f;

void Floyd(int n) 
{
	for (int k = 1; k <= n; ++k) 
	{
		for (int i = 1; i <= n; ++i) 
		{
			for (int j = 1; j <= n; ++j) 
			{
				s[i][j] = min(s[i][j], s[i][k] + s[k][j]);
				l[i][j] = min(l[i][j], l[i][k] + l[k][j]);
			}
		}
	}
}

int main() 
{
	int n, m, r;
	int u, v, c;
	char tp[2];

	while (scanf("%d%d", &n, &m) != EOF && n) 
	{
		memset(s, INF, sizeof(s));
		memset(l, INF, sizeof(l));
		memset(d, INF, sizeof(d));

		while (m--) 
		{
			scanf("%d%d%d%s", &u, &v, &c, tp);
			if (tp[0] == 'L') 
			{
				l[u][v] = min(l[u][v], c);
				l[v][u] = min(l[v][u], c);
			}
			else 
			{
				s[u][v] = min(s[u][v], c);
				s[v][u] = min(s[v][u], c);
			}
		}

		for (int i = 1; i <= n; ++i) 
		{
			l[i][i] = 0;
			s[i][i] = 0;
		}

		scanf("%d", &r);

		for (int i = 1; i <= r; ++i) 
		{
			scanf("%d", &b[i]);
		}

		Floyd(n);

		for (int i = 1; i <= n; ++i) 
		{
			d[1][i] = min(d[1][i], s[b[1]][i] + l[i][b[1]]);
		}

		for (int i = 1; i <= r; ++i) 
		{
			for (int j = 1; j <= n; ++j) 
			{
				//if (l[j][b[i]] >= INF) continue;
				for (int k = 1; k <= n; ++k) 
				{
					//if (d[i - 1][k] >= INF) continue;
					if (j == k) 
					{
						if (l[b[i - 1]][b[i]] < INF) 
						{
							d[i][j] = min(d[i][j], d[i - 1][k] + l[b[i - 1]][b[i]]);
						}
					}
					else 
					{
						//三个INF可能上溢
						if (l[b[i - 1]][k] < INF && s[k][j] < INF && l[j][b[i]] < INF) 
						{
							d[i][j] = min(d[i][j], d[i - 1][k] + l[b[i - 1]][k] + s[k][j] + l[j][b[i]]);
						}
					}
				}
			}
		}

		int ans = INF;
		for (int j = 1; j <= n; ++j) 
		{
			ans = min(ans, d[r][j]);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3904
# coding: utf8

import math

const = 10 ** 9 + 7

def read_int_n():
    return list(map(int, input().split()))

def comb(n, m):
    return math.factorial(n) // (math.factorial(m) * math.factorial(n - m)) 

def power(x, y):
    """
        ２分累乗法
    """
    if      y == 0      :   return 1
    elif    y == 1      :   return x % const
    elif    y % 2 == 0  :   return power(x, y/2) ** 2 % const
    else                :   return power(x, math.floor(y/2)) ** 2 * x % const

if __name__ == "__main__":
    n, m = read_int_n()
    # mを素因数分解する
    cnts = {}
    for i in range(2, math.ceil(math.sqrt(m)) + 1):
        while m % i == 0:
            if i not in cnts:
                cnts[i] = 1
            else:
                cnts[i] += 1
            m //= i
    else:
        if m > 1:
            if m not in cnts:
                cnts[m] = 1
            else:
                cnts[m] += 1
    ans = 1
    for key, value in cnts.items():
        num = 1
        for i in range(value):
            num *= (n + value - 1 - i)
        num //= math.factorial(value)
        # ans *= comb(value + n - 1, value) % const
        ans *= num % const
        ans = ans % const
    print(ans)

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

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


Measured memory_bytes: 3644
n, x = map(int, input( ).split())
a = list(map(int, input().split()))
counter = 0
for i in sorted(a):
  x -= i
  counter += 1
  if x<0:
    print(counter-1)
    break
  elif x==0:
    print(counter)
    break
  else:
    if counter==n:
      print(counter-1)

Measured memory_bytes: 3060
def change(n, word):
    for i in range(len(ans)-1, n, -1):
        ans[i] = ans[i-1]
    ans[n] = word

s = input()
k = int(input())
p = min(len(s), k)
key = s[:p]

for i in range(1, len(s)+1-p):
  if key > s[i:i+k]:
    key = s[i:i+k]

ans = [0]*k
for i in range(k):
  if i < p:
    ans[i] = key[:i+1]
  else:
    ans[i] = "zzzzzz"
for i in range(len(s)-p, len(s)):
    for j in range(i+1, len(s)+1):
        for t in range(k):
            if s[i:j] < ans[t] and s[i:j] not in ans:
                change(t, s[i:j])
print(ans[k-1])

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
  int a[5], index, i;
  for(i=0; i<5; i++)
  {
      cin >> a[i];
      if(a[i] == 0)
        index = i + 1;
  }
  cout << index << "\n";
  
  return 0;
}

Measured memory_bytes: 3568
import java.util.Scanner;
class Main{
	
    public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int A=sc.nextInt();
int B=sc.nextInt();
 if(A==1) {
	A=14;
  }
 if(B==1) {
	B=14;
  }
 String ans="";
 if(A>B) {
	ans="Alice";
  }
 if(A<B) {
 ans="Bob";
  }
 if(A==B) {
	ans="Draw";
 }

System.out.println(ans);
 }
}

Measured memory_bytes: 23764
(* Vicfred
 * https://atcoder.jp/contests/abc138/tasks/abc138_b
 * implementation
 * *)
let n = Scanf.scanf "%d\n" ( + ) 0
let a = Array.init n @@ fun _ -> Scanf.scanf " %f" ( +. ) 0.0
let main = Printf.printf "%.9f\n" @@
((/.) 1.0) @@
Array.fold_left (fun x y -> x +. (1.0 /. y)) 0.0 a



Measured memory_bytes: 3968
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static final long MOD = (long) (1e9 + 7);
    static int n;
    static long[] a;
    static long[] f;
    static long[] inv;
    static long[] C;
    static long[] P;
    static long[] F;

    private static long modPow(long b, long e) {
        if(e == 0) return 1;
        if(e == 1) return b;
        return modPow(b*b % MOD, e >> 1) * modPow(b, e & 1) % MOD;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        // Setup
        f = new long[n + 1];
        f[0] = 1;
        for(int i = 1; i <= n; i++) f[i] = f[i-1] * i % MOD;
        inv = new long[n + 1];
        inv[0] = 1;
        for(int i = 1; i <= n; i++) inv[i] = modPow(f[i], MOD - 2);
        C = new long[n + 1];
        for(int i = 1; i <= n; i++) C[i] = f[n] * inv[n - i] % MOD * inv[i] % MOD;
        P = new long[2 * n  + 10];
        P[0] = 1;
        for(int i = 1; i < P.length; i++) {
            P[i] = P[i-1] * 2 % MOD;
        }
        F = new long[Integer.max(n + 1, 3)];
        F[0] = 0;
        F[1] = 1;
        F[2] = 4;
        for(int i = 3; i <= n; i++) {
            F[i] = F[i-1] * (F[i-1] - F[i-2]) % MOD * modPow(F[i-2] - F[i-3], MOD - 2) % MOD;
        }
        a = new long[n + 1];
        for(int i = 1; i <= n; i++) a[i] = sc.nextInt();
        Arrays.sort(a);
        for(int i = 1; i <= n / 2; i++) {
            long tmp = a[i];
            a[i] = a[n - i + 1];
            a[n - i + 1] = tmp;
        }


        long ans = 0;
        for(int i = 1; i <= n; i++) {
            ans += (F[i-1] + P[i-1]) * a[i] % MOD * P[n - i] % MOD;
            ans %= MOD;
        }

        ans *= P[n];
        ans %= MOD;
        if(ans < 0) ans += MOD;
        System.out.println(ans);
    }
}


Measured memory_bytes: 101832
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int n;
  cin >> n;
  vector<pair<int, int> > vr, vb;
  rep(i, 0, n) {
    int a, b;
    cin >> a >> b;
    vr.push_back(make_pair(b, a));
  }

  rep(i, 0, n) {
    int c, d;
    cin >> c >> d;
    vb.push_back(make_pair(c, d));
  }

  vsort(vr);
  vsort(vb);

  int rsl = 0;
  for(int i = n - 1; i >= 0; --i) {
    for(int j = 0; j < n; ++j) {
      if(vr[i].second < vb[j].first && vr[i].first < vb[j].second) {
        ++rsl;
        vb[j].first = -1;
        vb[j].second = -1;
        break;
      }
    }
  }
  cout << rsl << endl;
}


Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N;
map< vector<int>, int > dp;

int solve(vector<int>& vec, int sum = 0, int id = 1) {
    int res = 0;
    if(sum == 10) {
        res++;
        sum = 0; id = 1;
    }
    if(sum == 0 and dp.count(vec)) return dp[vec];
    if(id > 9 or sum + id > 10) return 0;

    int add = 0;
    if(vec[id] > 0) {
        vec[id]--;
        chmax(add, solve(vec, sum + id, id));
        vec[id]++;
    }
    chmax(add, solve(vec, sum, id + 1));
    res += add;

    if(sum == 0) dp[vec] = res;
    return res;
}

signed main() {
    while(cin >> N, N) {
        dp.clear();
        vector<int> countManju(11);

        for(int i=0; i<N; i++) {
            int val; cin >> val;
            countManju[val]++;
        }
        
        int ans = 0;
        for(int i=1; i<5; i++) {
            int add = min(countManju[i], countManju[10 - i]);
            ans += add;
            countManju[i     ] -= add;
            countManju[10 - i] -= add;
        }
        ans += countManju[5] / 2;
        countManju[5] %= 2;

        ans += solve(countManju);
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
  long long A, B, C;
  cin >> A >> B >> C;
  if(A%2==0 || B%2==0 || C%2==0) cout << 0 << endl;
  else cout << min(A*B, min(A*C, B*C)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n),cnt(1e6+10);
    for(auto &i:a) cin>>i;
    for(auto &i:cnt) i=0;
    
    //全体のGCDを取って2以上ならnot coprime
    int tmp = a[0];
    for(auto i:a){
        tmp = __gcd(tmp,i);
    }
    if(tmp>=2){
        cout<<"not coprime"<<endl;
        return 0;
    }

    //1を除き、同じ値があるならばsetwise coprime
    for(auto i:a){
        if(cnt[i]){
            cout<<"setwise coprime"<<endl;
            return 0;
        }
        if(i!=1){
            cnt[i]=1;
        }
    }

    //因数について、その倍数が配列中に複数存在するならsetwise coprime
    for(int i=2; i<=1e6; i++){
        int c = 0;
        for(int j=1; j*i<1e6; j++){
            c += cnt[j*i];
            //1以上の時点でsetwise coprime
            if(c>1){
                cout<<"setwise coprime"<<endl;
                return 0;
            }
        }
    }
    cout<<"pairwise coprime"<<endl;
}

Measured memory_bytes: 11040
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define PR pair
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define REP(i, x, y)   for(int i = (int)(x); i <= (int)(y); i++)
#define FOR(i, x, y)   for(int i = (int)(x); i <  (int)(y); i++)
#define PER(i ,x, y)  for(int i = (int)(x); i >= (int)(y); i--)
#define CH	         ch = getchar()
#define Exit(...)    printf(__VA_ARGS__), exit(0)
#define dln()        fprintf(stderr,"\n")
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef double	  db;
typedef long long LL;
typedef vector<int> VI;
typedef vector<VI > VII;
typedef PR<int,int> PII;
typedef vector<PII> VPI;
const	int inf=2e9;
const	LL Inf=1e10;
const	int P=1e9+7;
const	int N=200005;

inline LL IN(){
	LL x = 0;
	int ch = 0, f = 0;
	for (CH; ch != -1 && (ch < 48 || ch > 57); CH) f = (ch == '-');
	for (; ch >= 48 && ch <= 57; CH) x = (x << 1) + (x << 3) + ch - '0';
	return f ? (-x) : x;
}
template<typename T> inline int chkmin(T &a, const T &b){if(b < a) return a = b, 1; return 0;}
template<typename T> inline int chkmax(T &a, const T &b){if(b > a) return a = b, 1; return 0;}

void renew(int &x, const int &y){
	x += y;
	if(x >= P) x -= P;
	if(x <  0) x += P;
}

int Pow(int x, int y, int p){
	int a = 1;
	for (; y; y >>= 1, x = (LL)x * x %p) if(y & 1) a=(LL)a * x%p;
	return a;
}

int n;
int a[N], zro = 1e6, dp[2000005];
int main(){
	scanf("%d", &n);
	FOR(i, 1, n) scanf("%d", a + i);
	REP(i, 0, 1e6) dp[zro + i] = i;
	int sum = 0;
	FOR(i, 3, n){
		zro -= a[i];
		sum += a[i];
		FOR(j, 0, a[i]) dp[zro + j] = dp[zro + a[i] + a[i] - j];
	}
	int Q;
	scanf("%d", &Q);
	while(Q--){
		int x;
		scanf("%d", &x);
		if(x > sum){
			x -= sum;
		}else{
			x = dp[x + zro];
		}
		x += a[1] - a[2];
		printf("%d\n", x);
	}
	return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    int n; int k;
    cin >> n >> k;
    int ret = (n-1)/(k-1) + (int)((n-1)%(k-1)>0);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
n=int(input())
a=tuple(input().split())
b=tuple(input().split())

a2=0
b2=0
seq=[]

for i in range(n):
    seq.append(str(i+1))

an=list(itertools.permutations(seq))

c=0
while a2==0 or b2==0:
    if a==an[c]:
        a2=c+1
    
    if b==an[c]:
        b2=c+1
    
    c+=1

print(abs(a2-b2))

Measured memory_bytes: 8052
A = []
b = []
output = []
n, m = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for j in range(m)]
output = [0 for p in range(n)]

for k in range(n):
    for l in range(m):
        output[k] += A[k][l] * b[l]

for o in range(n):
    print(output[o])

Measured memory_bytes: 8104
#include <algorithm>
#include <chrono>
#include <iostream>
#include <random>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int t = 0;
  for (auto i = 0; i < s.size(); i++) {
    t += (s[i] - '0');
  }
  auto res = (t % 9 == 0);
  if (res) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Measured memory_bytes: 3740
a,b = map(int, input().split())
if a%2 == 0:
    if (b-a)%4 == 0:
        print(b)
    elif (b-a)%4 == 1:
        print(1)
    elif (b-a)%4 == 2:
        print(b+1)
    else :
        print(0)
else:
    if (b-a-1)%4 == 0:
        print(a^b) # aとbの排他的論理和
    elif (b-a-1)%4 == 1:
        print(a^1) # aと1の排他的論理和
    elif (b-a-1)%4 == 2:
        print(a^(b+1)) # aとb+1の排他的論理和
    else:
        print(a) # aと0の排他的論理和

Measured memory_bytes: 38256
using static System.Math;
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int p1 { get; set; }
    public int p2 { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var s = getArray(a);
        var t = getArray(b);
        var q = int.Parse(line[2]);
        for (int i = 0; i < q; i++)
        {
            var x = long.Parse(Console.ReadLine().Trim());
            var ss = getPos(s, a, x);
            var tt = getPos(t, b, x);
            Console.WriteLine(getAns(ss.p1, ss.p2, tt.p1, tt.p2, x, s, t));
        }
    }
    static long getAns(int a1, int a2, int b1, int b2, long x, long[] s, long[] t)
    {
        var ans = new List<long>();
        ans.Add(Abs(s[a1] - x) + Abs(s[a1] - t[b1]));
        ans.Add(Abs(s[a1] - x) + Abs(s[a1] - t[b2]));
        ans.Add(Abs(s[a2] - x) + Abs(s[a2] - t[b1]));
        ans.Add(Abs(s[a2] - x) + Abs(s[a2] - t[b2]));
        ans.Add(Abs(t[b1] - x) + Abs(t[b1] - s[a1]));
        ans.Add(Abs(t[b1] - x) + Abs(t[b1] - s[a2]));
        ans.Add(Abs(t[b2] - x) + Abs(t[b2] - s[a1]));
        ans.Add(Abs(t[b2] - x) + Abs(t[b2] - s[a2]));
        return ans.Min();
    }
    static P getPos(long[] a, int aL, long x)
    {
        var ans = new P();
        var p = LowerBound(a, x);
        if (p == 0)
        {
            if (x < a[0]) { ans.p1 = 0; ans.p2 = 0; }
            else { ans.p1 = 0; ans.p2 = 1; }
        }
        else if (p == aL) { ans.p1 = aL - 1; ans.p2 = aL - 1; }
        else { ans.p1 = p - 1; ans.p2 = p; }
        return ans;
    }
    static long[] getArray(int n)
    {
        var ans = new long[n];
        for (int i = 0; i < n; i++) ans[i] = long.Parse(Console.ReadLine().Trim());
        return ans;
    }
    public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) < 0)
                low = mid + 1;
            else
                high = mid;
        }
        return low;
    }
    public static int LowerBound<T>(T[] arr, T value) where T : IComparable
    {
        return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    }
}

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

#define pb push_back
#define MP make_pair 
#define MAX_N 1000
#define all(c) (c).begin(),(c).end()
#define ck(a,b) (0<=(a) && (a)<(b))

int W, H, N;
int X1[MAX_N], Y1[MAX_N], X2[MAX_N], Y2[MAX_N];

int compress(int *x1, int *x2, int w) {
  vector<int> xs;
  
  for(int i=0; i<N; i++) {
	for(int j=-1; j<=1; j++) {
	  int tx1 = x1[i] + j, tx2 = x2[i] + j;
	  if(0 <= tx1 && tx1 < w) xs.pb(tx1);
	  if(0 <= tx2 && tx2 < w) xs.pb(tx2);
	}
  }
  sort(all(xs));
  xs.erase(unique(all(xs)), xs.end());
  
  for(int i=0; i<N; i++) {
	x1[i] = lower_bound(all(xs), x1[i]) - xs.begin();
	x2[i] = lower_bound(all(xs), x2[i]) - xs.begin();
  }
  
  return xs.size();
}

void Fill(vector<vector<bool> > &mp, int x1, int y1, int x2, int y2) {
  for(int i=y1; i<y2; i++)
	for(int j=x1; j<x2; j++)
	  mp[i][j] = 1;
}

void bfs(vector<vector<bool> > &mp, int i, int j, int h, int w) {
  const int dx[] = {-1,1,0,0};
  const int dy[] = {0,0,-1,1};
  typedef pair<int, int> PII;
  queue<PII> q;
  q.push(MP(i, j));
  
  while(!q.empty()) {
	const PII no = q.front(); q.pop();
	
	if(!mp[no.first][no.second]) {
	  mp[no.first][no.second] = 1;
	  
	  for(int k=0; k<4; k++) {
		PII nx = no;
		nx.first += dy[k];
		nx.second+= dx[k];
		if(ck(nx.first,h) && ck(nx.second,w)) q.push(nx);
	  }
	}
  }
}

int main() {
  while(cin >> W >> H, (W|H) ) {
	cin >> N;
	for(int i=0; i<N; i++)
	  cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
	int w = compress(X1, X2, W);
	int h = compress(Y1, Y2, H);
	
	vector<vector<bool> > M(h, vector<bool>(w, 0));
	for(int i=0; i<N; i++)
	  Fill(M, X1[i], Y1[i], X2[i], Y2[i]);
	
	int ans = 0;
	for(int i=0; i<h; i++) {
	  for(int j=0; j<w; j++) {
		if(!M[i][j]) {
		  ans++;
		  bfs(M, i, j, h, w);
		}
	  }
	}
	cout << ans << endl;
  }
  return 0;
}

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

int main(){
  string s; cin >> s;
  if(s[2] == s[3] && s[4] == s[5]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll pos[5], k;
    REP(i, 0, 5) {
        cin >> pos[i];
    }
    cin >> k;
    bool ok = true;
    if (pos[4] - pos[0] > k) {
        ok = false;
    }
    if (ok) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a;
  cin>>a;
  if(a==22)
    cout<<"Christmas Eve Eve Eve";
  else if(a==23)
    cout<<"Christmas Eve Eve";
  else if(a==24)
    cout<<"Christmas Eve";
  else 
    cout<<"Christmas";
    
    return 0;
}


Measured memory_bytes: 3528
#include <iostream>

using namespace std;

int main()
{
	int pasta[3];
	int juice[2];
	int i, j;
	int pmin = 2000;
	int	jmin = 2000;
	
	for (i = 0; i < 3; i++){
		cin >> pasta[i];
		if (pmin > pasta[i]){
			pmin = pasta[i];
		}
	}
	for (j = 0; j < 2; j++){
		cin >> juice[j];
		if (jmin > juice[j]){
			jmin = juice[j];
		}
	}
	
	cout << jmin + pmin - 50 << endl;
	
	return (0);
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define Int int64_t
using namespace std;

Int N;

int main()
{
   string S;cin>>S;
   int i=0,j=S.length()-1;
   Int ans=0;
   while(i<=j){
       ans+=S[i]!=S[j];
       i++,j--;
   }
   cout<<ans<<"\n";
}

Measured memory_bytes: 3588
if __name__ == "__main__":
	num = int(input().strip())
	last_digit = num%10
	if last_digit == 3:
		print("bon")
	elif last_digit == 0 or last_digit == 1 or last_digit == 6 or last_digit == 8:
		print("pon")
	else:
		print("hon")

Measured memory_bytes: 9168
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define endl ('\n')
//#define MOD 1000000007LL
#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
//inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
//inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

int main(){
    lint s,w;
    cin>>s>>w;
    if(s<=w)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define endl "\n"
#define PI 3.14159265
const int mod=1e9+7;
//const int mod=1e9+7;
const int INF =LONG_LONG_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
const int N = (int)2e5 + 10;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n][n];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
           cin>>a[i][j];

    int dp[(1<<n)];
    memset(dp,0,sizeof(dp));
    dp[0]=1;


    for(int mask=0;mask<(1<<n);mask++)
    {
        int x=__builtin_popcount(mask);

      for(int j=0;j<n;j++)
      {
          if((mask&(1<<j))==0&&a[x][j])
          {
              dp[mask|(1<<j)]=(dp[mask|(1<<j)]%mod+dp[mask]%mod)%mod;
          }
      }
    }
  // for(int i=0;i<(1<<n);i++)
   //cout<<dp[i]<<" ";
    cout<<dp[(1<<n)-1]%mod<<endl;

    return 0;
}


Measured memory_bytes: 16640
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>

using namespace std;
using ll = long long;

int n, m;
ll a[100005];
priority_queue<ll>Q;
ll sum = 0;

void input(){
  cin >> n >> m;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    Q.push(a[i]);
    sum += a[i];
  }
}

ll solve(){
  ll num = m;
  while(num > 0){
    num--;
    ll tmp = Q.top();
    Q.pop();
    double diff = tmp / (pow(2, 1));
    //sum -= tmp;
    sum -= tmp - diff;
    tmp = diff;
    Q.push(tmp);
  }
  return sum;
}

int main(){
  input();
  cout << solve() << endl;
}

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

int main() {
  int n;
  cin >> n;
  pair<int,int> a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i].first >> a[i].second;
  }
  vector<int> ar(n);
  for(int i = 0; i < n; i++){
    ar[i] = i;
  }
  double len = 0;
  int cnt = 0;
  do{
    for(int i = 0; i < n-1; i++){
      double x = a[ar[i]].first - a[ar[i+1]].first;
      double y = a[ar[i]].second - a[ar[i+1]].second;
      len += sqrt(x*x+y*y);
    }
    cnt++;
  }while(next_permutation(ar.begin(), ar.end()));
  double ans = len / cnt;
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#if !defined(ONLINE_JUDGE)
    #include "prettyprint.hpp" 
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 1729
    #define cer(x) 13
#endif
const bool testcase=0;
typedef long long int ll;
#define INF LONG_MAX
#define MINF LONG_MIN 
#define MAXR 111111
const ll mod1 = 1000000007;
const ll mod2 = 998244353;



//loop 
#define loop(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define loope(i,L,R) for (int i = L; i <= R; i++)
#define rloop(i,L,R) for (int i = L; i > R; i--)
#define rloope(i,L,R) for (int i = L; i >= R; i--)
#define nl cout<<'\n'



//misc
#define sz(x) ((int)((x).size()))
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL) 
#define checkbit(n,b) ( (n >> b) & 1)
#define test int _T_=1;if(testcase){cin>>_T_;}while(_T_--)



//vector
#define lastEle(vec) vec[vec.size()-1]
#define all(ve) ve.begin(),ve.end()
#define rall(x) x.rbegin(),x.rend()
#define fi first
#define se second



template<typename T>inline T mmod(T a,T b,T mod){return ((a%mod)*(b%mod))%mod;}
template<typename T>inline T smod(T a,T b,T mod){return ((a%mod)+(b%mod))%mod;}
template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}
template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a){in>>a.fi>>a.se;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a){for(auto &x : a)in>>x;return in;}

ll lcm(ll a,ll b){return (max(a,b)/__gcd(a,b))*min(a,b);} 

// MAIN
void solve();
int main(){
    std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
    start = std::chrono::high_resolution_clock::now();
    fast;
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
        // for debug in error.txt
        freopen("error.txt", "w", stderr);
    #endif
    test {
        solve();
    }
    end = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
    cerr << "\nElapsed Time: " << elapsed_time << "ms\n";
    return 0;
}


// SOLVE 
ll find(ll x, ll m=mod2) {
    x %=m;
    return (x < 0)?(x+m):x;
}
void solve() {
    ll n, k;
    cin >> n >> k;
    ll inp[k][2] = {{0}};
    vector<ll> dp(n,0);
    loop(i,0,k) {
        cin >> inp[i][0] >> inp[i][1];
        inp[i][1]++;
    }
    dp[0] = 1, dp[1] = -1;
    loop(i,0,n){
        if(i > 0){
            dp[i] = find(dp[i]+dp[i-1]);
        }
        loop(j,0,k){
            if(i+inp[j][0] < n) dp[i+inp[j][0]] = find(dp[i+inp[j][0]]+dp[i]);
            if(i+inp[j][1] < n) dp[i+inp[j][1]] = find(dp[i+inp[j][1]]-dp[i]);
        }
    }
    cout << dp[n-1] << '\n';
}



Measured memory_bytes: 4808
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll x[N];
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    ll ans = 0;
    for (int i = 1; i < N; i++) {
        ll d = x[i] - x[i - 1];
        if (d * A < B) {
            ans += d * A;
        } else {
            ans += B;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

class Hp_neg
  def initialize(len = 200000)
    @main = na(len,[99999999,nil])
    @ind = 1
    @size = len - 5
  end

  def push(n)
    p "wa" if(@ind > @size)
    @main[@ind] = n
    sind = @ind
    while(sind >= 2)
      nind = sind/2
      if(@main[sind][0] < @main[nind][0])
        @main[sind], @main[nind] = @main[nind], @main[sind]
      else
        break
      end
      sind /= 2
    end
    @ind += 1
  end

  def put()
    return @main
  end

  def pop()
    ans = @main[1]
    @ind -= 1
    @main[1] = @main[@ind]
    @main[@ind] = [99999999,nil]
    sind = 1
    while(true)
      nind = sind*2
      break if(nind > @ind)
      l = @main[nind]
      nind += 1
      if(nind > @ind)
        ind = nind-1
        if(@main[ind][0] < @main[sind][0])
          @main[sind], @main[ind] = @main[ind], @main[sind]
        end
        break
      end
      r = @main[nind]
      ind = (l[0] > r[0])? nind : nind-1
      if(@main[ind][0] < @main[sind][0])
        @main[sind], @main[ind] = @main[ind], @main[sind]
      end
      sind = ind
    end

    return ans
  end

  def res()
    @ind = 1
    push([99999999,nil])
  end
end

hp = Hp_neg.new()
n,m = inp
a = inp
a.each do |d|
  hp.push([d*-1,0])
end
m.times do
  u = hp.pop
  hp.push([((u[0]*-1)/2)*-1,0])
end
ans = 0
while true
  u = hp.pop

  break if(u[1] == nil)
  ans += u[0]
end
p ans * -1


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	string s; cin>>s;
	int hist[128]={};
	for(char c:s) hist[c]++;

	bool ok=true;
	rep(c,128) if(hist[c]%2==1) ok=false;
	cout<<(ok?"Yes":"No")<<'\n';

	return 0;
}


Measured memory_bytes: 256