akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int solve(){
    int a,p; cin>>a>>p;
    a=a*3+p;
    cout<<a/2;
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
import itertools
import sys
 
def readline():
    return sys.stdin.readline()
 
def read_int_list():
    return list(map(int, readline().split()))
 
def read_int():
    return int(readline())
 
def main():
    N, M, R = read_int_list()
 
    r = [a-1 for a in read_int_list()]
 
    d = [[float('inf')]*N for _ in range(N)]
 
    for _ in range(M):
        a, b, c = read_int_list()
        d[a-1][b-1] = c
        d[b-1][a-1] = c
 
    for a in range(N):
        d[a][a] = 0
 
    res = float('inf')
 
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if d[i][k]+d[k][j] < d[i][j]:
                    d[i][j] = d[i][k]+d[k][j]
 
    for perm in itertools.permutations(r):
        a = 0
        for i in range(len(perm)-1):
            a += d[perm[i]][perm[i+1]]
        res = min(a, res)
 
    print(res)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 4700
import collections

n = int(input())
a = list(map(int,input().split()))
q = int(input())

collect_dict = dict(collections.Counter(a))

now = sum(a)

ans = []
for i in range(q):
    b, c = map(int,input().split())
    if b not in collect_dict.keys():
        ans.append(now)
        continue
    now -= collect_dict[b] * b
    tmp = collect_dict[b]
    collect_dict.pop(b)
    if c not in collect_dict.keys():
        collect_dict[c] = 0
    collect_dict[c] += tmp
    now += c * tmp
    ans.append(now)

for i in ans:
    print(i)

Measured memory_bytes: 21992
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int x;
  cin>>x;
  int ans=0;
  ans+=(x/500)*1000;
  x%=500;
  ans+=(x/5)*5;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
while True:
    a = int(input())
    if a == 0:
        break
    word = "IO"*a+"I"
    b = int(input())
    s = input()
    count = 0
    for i in range(b-a*2):
        if word == (s[i:i+a*2+1]):
            count += 1
    print(count)


Measured memory_bytes: 7296
#include <stdio.h>

void fact(int ,int);

char c[21][21];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int w, h, count;

int main()
{
  int a, i, j, b1 , b2;

  while(1){
    scanf("%d%d\n",&w,&h);
    if(w == 0 && h == 0)
      break;
    /*scanf("%c",&c[0][0]);*/
    for(i = 0 ; i < h ; i++){
      for(j = 0 ; j < w+1 ; j++){
	scanf("%c",&c[i][j]);
	if(c[i][j] == '@'){
	  b1 = j;
	  b2 = i;
	} 
      }
    }
    count = 1;
    fact(b1,b2);
    printf("%d\n",count);
  }
  return 0;
}

void fact(int b1 ,int b2)
{
  int i, x, y;

  for(i = 0 ; i < 4 ; i++){
    y = b1 + dy[i];
    x = b2 + dx[i];
    if(y < 0 || x < 0 || y >= w || x >= h)
      continue;
    if(c[x][y] == '.'){
      c[x][y] = '#';
      count++;
      fact(y,x);
    }
  }
}

Measured memory_bytes: 616
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

int Top(int N){
  while (N >= 10){
    N /= 10;
  }
  return N;
}

int Last(int N){
  return N % 10;
}

int main(){
  int N; cin >> N;

  ll cnt[10][10];
  for (int i = 0; i < 10; i++){
    for (int j = 0; j < 10; j++){
      cnt[i][j] = 0;
    }
  }
  
  for (int i = 1; i <= N; i++){
    int T = Top(i), L = Last(i);
    cnt[T][L]++;
  }

  ll ans = 0;
  for (int i = 0; i < 10; i++){
    for (int j = 0; j < 10; j++){
      ans += cnt[i][j] * cnt[j][i];
    } 
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
s=str(input())
t=str(input())
list1=[]
c=0

for i in range(len(s)-len(t)+1):
  s2=s[i:i+len(t)]
  for i in range(len(t)):
    if t[i]==s2[i]:
      c +=1
  list1.append(c)
  c=0
print(len(t)-max(list1))

Measured memory_bytes: 9048
{-# LANGUAGE OverloadedStrings #-}

import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    [n, w] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    B.putStrLn $ B.replicate (w + 2) '#'
    replicateM_ n $ do
        s <- B.getLine
        B.putStr "#"
        B.putStr s
        B.putStrLn "#"
    B.putStrLn $ B.replicate (w + 2) '#'

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

#define forn(i,x,y) for(int i = int(x); i<int(y); i++)
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(V) V.begin(), V.end()
#define on(x, b) (x & (1LL << b))
#define trav(x, v) for(auto &x : v)

#define f first
#define s second

const int N = 1e5 + 10;

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    int k, a , b; cin >> k >> a >> b;
    if(a % k == 0 or a / k < b / k) cout << "OK\n";
    else cout << "NG\n";

    return 0;
}

/* don't forget to check:
   int overflow
   min/max cases (n = 1)
   printing index of sorted array
   limits for ans (start with inf)
   s = 'x' + s is linear! dont use it!
 */


Measured memory_bytes: 3652
#include <stdio.h>
typedef long long ll;

ll abs(ll a) {
  return a > 0 ? a : -a;
}

int main(void) {
  ll i, j, k, n;
  scanf("%lld%lld", &n, &k);
  ll dp[n], h[n];
  for(i = 0; i < n; ++i) scanf("%lld", &h[i]), dp[i] = 1e18;
  dp[0] = 0;
  for(i = 0; i < n; ++i) for(j = 1; j <= k; ++j) if(i + j < n && dp[i + j] > dp[i] + abs(h[i] - h[i + j])) dp[i + j] = dp[i] + abs(h[i] - h[i + j]);
  printf("%lld", dp[n - 1]);
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  reverse(S.begin(), S.end());
  vector<int> T(N + 1);
  T.at(0) = 0;
  int k = 1;
  for (int i = 0; i < N; i++) {
    int x = S.at(i) - '0';
    T.at(i + 1) = (T.at(i) + x * k) % 2019;
    k = k * 10 % 2019;
  }
  vector<int> V(2019, 0);
  for (int i = 0; i <= N; i++) V.at(T.at(i))++;
  long long int ans = 0;
  for (int i = 0; i < 2019; i++) {
    if (V.at(i) > 1) ans += (V.at(i) - 1) * V.at(i) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4360
import sys
input = sys.stdin.readline

a, b, c, d = [int(x) for x in input().split()]

while True:
    for i in range(2):
        if i == 0:
            c -= b
            if c <= 0:
                print("Yes")
                sys.exit()
        else:
            a -= d
            if a <= 0:
                print("No")
                sys.exit()

Measured memory_bytes: 61744
#include <iostream>

using namespace std;
#define N 7500000

bool years[N+10];

int main(){
    int m,n;
    while(cin>>m>>n){
        if(m==0 && n==0){
            break;
        }
        for(int i = m; i <= N; i++){
            years[i]=true;
        }
        

        for(int i = m; i <= N; i++){
            if(years[i]){
                if(n == 0){
                    cout<<i<<endl;
                    break;
                }
                n--;

                for(int j = i + i; j <= N; j += i){
                    years[j] = false;
                }
            }
        }
    }
}

Measured memory_bytes: 10396
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
#define inf 2e9
using namespace std;

int main(int argc, char **argv){
    int n,a[100000],m;
    cin>>n;
    rep(i,n){
        cin >> a[i];
    }
    sort(a,a+n);
    m = n/2;
    cout<<a[m]-a[m-1]<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
string str;
int mi=INF;
int main(){
  cin>>str;
  bool flag[255];
  for(int i=0;i<str.size();i++)
    flag[str[i]]=true;
  bool flag3=false;
  for(int i=0;i<str.size()-1;i++){
    if(str[i]!=str[i+1]){
      flag3=true;
      break;
    }
  }
  if(!flag3)
    cout<<0<<endl;
  if(flag3){
    for(char i='a';i<='z';i++){
      if(!flag[i])continue;
      int cnt=0;
      string str2=str;
      for(int k=str.size()-1;k>=1;k--){
	bool flag2=true;
	for(int j=0;j<k;j++){
	  if(str2[j]==i||str2[j+1]==i)
	    str2[j]=i;
	}
	for(int j=0;j<k-1;j++){
	  if(str2[j]!=str2[j+1])
	    flag2=false;
	}
	cnt++;
	if(flag2)
	  break;
      }
      mi=min(mi,cnt);
    }
    cout<<mi<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int min;

int dfs(int *a, int n, int i, int ta, int tb)
{
	if (i == n){
		if (abs(ta - tb) < min){
			min = abs(ta - tb);
		}
	}
	else {
		dfs(a, n, i + 1, ta + a[i], tb);
		dfs(a, n, i + 1, ta, tb + a[i]);
	}
	
	return (min);
}

int main(void)
{
	int n;
	int a[20];
	int ta, tb;
	int i, j;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
		}
		min = 1000000000;
		printf("%d\n", dfs(a, n, 0, 0, 0));
	}
	
	return (0);
}

Measured memory_bytes: 408
s=input()
k=int(input())

cnt=0
flag=0
if int(s[0]) > 1:
  ans=s[0]
else:
  for i in range(len(s)):
    if int(s[i])==1 and flag==0:
      cnt+=1
    else:
      flag=1

if k <= cnt:
  ans=1
else:
  ans=s[cnt]

print(ans)

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

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray();
            var S = ReadLine();
            var ans = 0L;
            var t = 0L;
            foreach (var s in S)
                if ('I' == s)
                {
                    ++t;
                    ans = Max(t, ans);
                }
                else
                {
                    --t;
                }
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 28212
#include<bits/stdc++.h>
using namespace std;
using Data=pair<long,int>;

int mmax(int a,int b,int c){
  if(a<b){
    return max(b,c);
  }else{
    return max(a,c);
  }
}

long long euclidean_gcd(long long a, long long b) {
  if(a < b) return euclidean_gcd(b, a);
  long long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  long i,a[4],N,f=0,ans=0;
  cin>>a[0]>>a[1]>>a[2]>>a[3]>>N;
  vector<Data> pp(4);
  pp[0]=Data(a[0]*8,0);
  pp[1]=Data(a[1]*4,1);
  pp[2]=Data(a[2]*2,2);
  pp[3]=Data(a[3]*1,3);
  
  sort(pp.begin(),pp.end());
  if(pp[0].second==3)f=1;
//  printf("%ld %ld %ld %ld\n",pp[0].first,pp[1].first,pp[2].first,pp[3].first);
  switch(N%2){
    case 0:
      cout << pp[0].first*N/2 << endl;
    break;
    case 1:
      N/=2;
      ans=N*pp[0].first;
  //          printf("%ld\n",ans);

      ans+=pp[0+f].first/2;
      printf("%ld\n",ans);
    break;
  }
  return 0;
}

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

int main() {
  int A, N, X;
  
  cin >> N >> A;
  
  X = N % 500;

  if (X > A){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}
    




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] line = br.readLine().split(" ");
		
		int h = Integer.parseInt(line[0]);
		int a = Integer.parseInt(line[1]);
		
		if(h%a!=0) {
			System.out.println(h/a+1);
		}else {
			System.out.println(h/a);
		}
		

		br.close();
	}
}


Measured memory_bytes: 22996
#include <stdio.h>
#include <math.h>

inline int max(int a, int b) {
    return a < b ? b : a;
}

int main() {
    int vtx[2500], sum[50][52] = {};
    int i, half, d, len, c, *v;

    i = 0;
    while ((scanf("%d,", &vtx[i++])) != EOF);
    half = (int)sqrt(i - 1);

    sum[0][1] = vtx[0];
    v = &vtx[1];
    for (i = 1, len = 1; i < (half * 2 - 1); i++) {
        d = i < half ? 1 : -1;
        len += d;
        for (c = 1; c <= len; c++) {
            sum[i][c] = *(v++);
            sum[i][c] = max(sum[i][c]+sum[i-1][c], sum[i][c]+sum[i-1][c-d]);
        }
    }
    printf("%d\n", sum[i-1][1]);

    return 0;
}

Measured memory_bytes: 628
#include<iostream>
#include<math.h>
using namespace std;

void func_C(long long L, long long R) {
	int ans = 2020;
	if ((R - L)+1 >= 2019) {
		ans = 0;
	}
	else {
		for (long long l = L; l < R; l++) {
			for (long long r = l + 1; r <= R; r++) {
				if(((l*r)%2019)<ans)
					ans = (l * r) % 2019;
			}
		}
	}
	std::cout << ans << std::endl;
}

int main() {
	long long L, R;
	std::cin >> L >> R;
	func_C(L, R);
	return 0;
}

Measured memory_bytes: 256
sub g{($d[$x=@@[@_]]-$d[$y=$@["@_"+1]])/($H[$y]-$H[$x])-$H[$x]-$H[$y]}<>=~$";map{shift@@while@@>1&&-2*$_<g 0;$d[@d]=$X=$d[$@[0]]+$'+($H[$@[0]]-$_)**2;$#@-=2while$@[@@]=$i,@@>2&&g(-2)>g-3;$i++}@H=glob<>;print$X-$'

Measured memory_bytes: 69668
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	ans := 1
	cnt := 2
	m := make(map[int]int)
	for i := 2; i*i <= N; i++ {
		n := N
		// out(i)
		for n%i == 0 {
			n /= i
		}
		if (n-1)%i == 0 {
			// out(":", i)
			m[i]++
			ans++
		}
		cnt = i
	}
	n := N - 1
	// out(m, cnt)
	for i := 1; ; i++ {
		if n/i < cnt {
			break
		}
		if n%i == 0 {
			// out(n/i, i)
			ans++
			m[n/i]++
		}
	}
	// out(m)
	out(len(m) + 1)
}


Measured memory_bytes: 1832
#include<iostream>
#include<iterator>
#include<algorithm>
#include<math.h>
#include<vector>
#include<stack>
#include<string.h>
#include<map>
#include<bitset>
#include<set>
#include<deque>
#include<sstream>
#include<queue>
#include<list>
#include <fstream>
#include <iomanip>
#define ln 1000005
#define pi acos(-1.0)
#define pb push_back
#define mp nake_pair
using namespace std;
int main()
{
    //std::ofstream outfile;
    //outfile.open("acm", std::ios_base::app);
    //outfile<<"write here"<<endl
    //outfile.close();
    
    int a,b,c;
    cin>>a>>b>>c;
    
    swap(a,b);
    swap(a,c);
    
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}



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


int n;
int m[101][101];
int p[101];

void matrixChainMultiplication() {
    for(int i = 1; i <= n; i++) {
        m[i][i] = 0;
    }

    for(int l = 2; l <= n; l++) {
        for(int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = (1<<21);
            for(int k = i; k < j ; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j]);
            }
        }
    }
    cout << m[1][n] << endl;
}

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    cin >> n;
    int _;
    rep(i, n) {
        if(i == 0) {
            scanf("%d %d", &p[i], &p[i + 1]);
        } else {
            scanf("%d %d", &_, &p[i + 1]);
        }
    }
    matrixChainMultiplication();
    return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll x;
    cin >> x;
    ll ans = x * x * x;
    cout << ans << endl;
    return 0;
}


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

#define int long long

int M=1e9+7;


void print(vector<int>& v){
  for (int i:v) cout<<i<<" ";
    cout<<endl;
}

void printv(vector<vector<int>>& v){
	for (auto x:v) print(x);
}

void add(int &a, int b){
	a+=b;
	if (a>=M) a-=M;
}

void sub(int &a, int b){
	a-=b;
	if (a<0) a+=M;
}

signed main() {
	// freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
	int N,K;
	cin>>N>>K;
	vector<int> candies(N+1);
	for (int i=0;i<N;i++){
		cin>>candies[i];
	}
	vector<vector<int>> dp(N+1,vector<int>(K+1));
	for (int i=0;i<=candies[0];i++) dp[0][i]=1;
	for (int i=1;i<N;i++){
		vector<int> prefix_sum(K+1,0);
		prefix_sum[0]=dp[i-1][0];
		for (int j=1;j<=K;j++){
			prefix_sum[j]=(prefix_sum[j-1]+dp[i-1][j])%M;
		}
		for (int j=0;j<=K;j++){	
			if (j>candies[i]) dp[i][j]=(M+prefix_sum[j]-prefix_sum[j-candies[i]-1])%M;
			else dp[i][j]=prefix_sum[j];
		}
	}
	cout<<dp[N-1][K];
    return 0; 
}


Measured memory_bytes: 83092
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
vector<int> l(8,0);
int ans=1e9,n,a,b,c;

int dist(int aa,int bb,int cc){
  vector<int> ll(3);
  ll.at(0)=aa;
  ll.at(1)=bb;
  ll.at(2)=cc;
  sort(ll.begin(),ll.end());
  return abs(ll.at(0)-c)+abs(ll.at(1)-b)+abs(ll.at(2)-a);
}

int dfs(int aa,int bb,int cc,int ad,int i){
  if(i==n){
    if(!aa||!bb||!cc) return 0;
    else{
      ans=min(ans,dist(aa,bb,cc)+ad);
      return 0;
    }
  }
  dfs(aa,bb,cc,ad,i+1);
  if(aa) dfs(aa+l.at(i),bb,cc,ad+10,i+1);
  else dfs(aa+l.at(i),bb,cc,ad,i+1);
  if(bb) dfs(aa,bb+l.at(i),cc,ad+10,i+1);
  else dfs(aa,bb+l.at(i),cc,ad,i+1);
  if(cc) dfs(aa,bb,cc+l.at(i),ad+10,i+1);
  else dfs(aa,bb,cc+l.at(i),ad,i+1);
}

int main(){
  cin>>n>>a>>b>>c;
  REP(i,n) cin>>l.at(i);
  dfs(0,0,0,0,0);
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b)
{if (a < b) {a = b; return true;} return false;}
template<class T> inline bool chmin(T& a,T b)
{if (a > b) {a = b; return true;} return false;}

int main(){
    long long N; cin >> N;
    long long ans = 1e13;
    
    for (long long i = 1; i <= sqrt(N); i++) {
        if (N % i== 0) {
            long long j = N / i;
            chmin(ans, i -1 + j-1);
        }
    }
    cout << ans << endl;
}

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

int main(void){
  char A, B;
  cin >> A >> B;
  int _A = (int)A - 55;
  int _B = (int)B - 55;
  if(_A == _B)
    cout << "=" << "\n";
  else if(_A < _B)
    cout << "<" << "\n";
  else
    cout << ">" << "\n";
  return 0;
}


Measured memory_bytes: 3612
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;

using namespace std;

int main(){ 
    long long A, B, C, D;
    cin >> A >> B >> C >> D;

    int turn_T = ceil((double)C / B);
    int turn_A = ceil((double)A / D);

    if(turn_T <= turn_A){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}



Measured memory_bytes: 3652
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()



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

int main()
{
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++)
    {
        cin >> vec.at(i);
    }
    int flag = 0;
    for (int i = 1; i < N - 1; i++)
    {
        if (i == 1)
        {
            vec.at(i)--;
        }
        if (vec.at(i) < vec.at(i + 1))
        {
            vec.at(i + 1)--;
        }
        else if (vec.at(i) > vec.at(i + 1))
        {
            flag = 1;
        }
    }
    puts(flag ? "No" : "Yes");
}

Measured memory_bytes: 640
function main()
  
  N = parse(Int,readline())
  A = map(x -> parse(Int,x), split(readline()))
  
  check = false
  count = 0
  
  for i in 1:100, j in 1:N
      
    if A[j] % 2^i != 0
      check = true
      count = i
      break
    end
    
    if check == true
      break
    end
  
  end
  
  println(count-1)
  
end

main()

Measured memory_bytes: 109428
#include <iostream> 
#include <cctype>
#include <string>
using namespace std;

int main()
{
	string s;
	int a,b;
	
	cin>>a>>b;
	cin>>s;
	
	for(int i=0;i<s.size();i++){
		if(i==a){
			if(s[i]!='-'){
				cout<<"No";
				return 0;
			}
		}
		else if(!isdigit(s[i])){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	
	return 0;
}


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

int main() {
    int n, _q, op, t, x;
    scanf("%d %d", &n, &_q);
    vector<queue<int> > q(n);
    while (_q--) {
        scanf("%d %d", &op, &t);
        if (op == 0) {
            scanf("%d", &x);
            q[t].emplace(x);
        } else if (op == 1) {
            if (!q[t].empty()) printf("%d\n", q[t].front());
        } else {
            if (!q[t].empty()) q[t].pop();
        }
    }
    return 0;
}



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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

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

    int res = ((n - m) * 100 + m * 1900) * pow(2, m);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;

#define LE(n,m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n,m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define LT(n,m) ((n) + EPS * (abs(n) + abs(m)) < (m))
#define GT(n,m) ((n) > (m) + EPS * (abs(n) + abs(m)))
#define EQ(n,m) (abs((n)-(m)) < EPS * (abs(n) + abs(m)))

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    string t = "CODEFESTIVAL2016";
    string s;
    cin >> s;
    
    int ans = 0;
    for(int i=0; i<t.size(); i++){
        ans += (t[i] != s[i]);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define e 0.00000001
using namespace std;
int func(int,int,double,int);
int p,q,a,n;
double k;
 
int main(){
  while(1){
    cin>>p>>q>>a>>n;
    if(!p&&!q&&!a&&!n) break;
    k=1.0*p/q;
    cout<<func(0,1,0,1)<<endl;
  }
  return 0;
}
 
int func(int x,int w,double y,int I){
  int r=0;
  if(-e<=k-y&&k-y<=e) r++;
  if(x==n||y>k+e) return r;
  for(int i=I;w*i<=a;i++) r+=func(x+1,w*i,1.0/i+y,i);
  return r;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define MA 10e17
int va=10e8+7;
ll int dp[100004]={0};
using namespace std;
//Conditional Operator (condition?true part:false part) eg : cout<<(y<=3?"YES":"NO")<<endl;
//string s(3,'1');
// if number of elements in array >10^5 then declare global array.
ll getmul(ll n){ll int k{0};while(n>0){k+=n%10;n=n/10;}return k;}//Sum OF n DIGITS 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t{1};
    //cin>>t;
    while(t--){
        ll n,x,t;
        cin>>n>>x>>t;
        ll ans=ceil((double)n/x);
        ans*=t;
        cout<<ans<<endl;
    }
 return 0;
}

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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ld long double
using namespace std;

const int INF = 1e9 + 7;


int main(void)
{
	FAST
	ll a;
	ld b; cin >> a >> b;

	cout << (ll)(a*b) << '\n';

	return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

#define SIZE 200005
#define MOD 1000000007
 
typedef pair <int,int> P;
 
ll inv[SIZE], fac[SIZE], finv[SIZE];

void make(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<SIZE; i++)
	{
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
    return ;
}
ll comb(ll a,ll b){
	if(a < b) return 0;
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	make();
	ll N, K; cin >> N >> K;
	vl A(N); rep(i,N) cin >> A[i];
	sort(all(A));

	ll ans = 0;
	rep1(j,N) {
		ans += comb(N-j, K-1) * A[N-j];
		ans %= MOD;
	}
	rep1(j,N) {
		ans -= comb(N-j, K-1) * A[j-1];
		ans = (ans + MOD) % MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// ビット演算
namespace Bits {
    // 整数 x を左に i ビットシフトした値を返す
    static Int LeftBitShift(Int x, Int i);
    // 整数 x を右に i ビットシフトした値を返す
    static Int RightBitShift(Int x, Int i);
    // 整数x の 下から i 桁目が1かどうかを返す
    static bool IsFlagUp(Int x, Int i);
    // 整数x の 下から i 桁目が0かどうかを返す
    static bool IsFlagDown(Int x, Int i);

    // 整数 x を左に i ビットシフトした値を返す
    Int LeftBitShift(Int x, Int i) {
        return (x << i);
    }
    // 整数 x を右に i ビットシフトした値を返す
    Int RightBitShift(Int x, Int i) {
        return (x >> i);
    }
    // 整数x の 下から i 桁目が1かどうかを返す
    bool IsFlagUp(Int x, Int i) {
        return ((x & (1 << i)) != 0);
    }
    // 整数x の 下から i 桁目が0かどうかを返す
    bool IsFlagDown(Int x, Int i) {
        return ((x & (1 << i)) == 0);
    }
}
using namespace Bits;

// 二つの値の最小値を求める関数
Int Min(const Int a, const Int b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}

struct Book {
    Int cost;
    vector<Int> a;
};

int main(void) {
    Int n, m, x;
    cin >> n >> m >> x;
    vector<Book> list(n);
    for (Int i = 0; i < n; ++i) {
        cin >> list[i].cost;
        list[i].a.resize(m);
        for (Int j = 0; j < m; ++j) {
            cin >> list[i].a[j];
        }
    }
    /*
    for (Int i = 0; i < n; ++i) {
        cout << list[i].cost << endl;
        for (Int j = 0; j < m; ++j) {
            cout << list[i].a[j] << " ";
        }
        cout << endl;
    }
    */
    Int loop = pow(2, n);
    Int min_cost = LLONG_MAX;;
    for (Int i = 0; i < loop; ++i) {
        Int now_cost = 0;
        vector<Int> level(m, 0);
        for (Int j = 0; j < n; ++j) {
            if (IsFlagUp(i, j)) {
                for (Int k = 0; k < m; ++k) {
                    level[k] += list[j].a[k];
                }
                now_cost += list[j].cost;
            }
        }
        bool can_understand = true;
        for (Int j = 0; j < m; ++j) {
            if (level[j] < x) {
                can_understand = false;
            }
        }
        if (can_understand) {
            min_cost = Min(min_cost, now_cost);
        }
    }

    if (min_cost == LLONG_MAX) {
        cout << -1 << endl;
    } else {
        cout << min_cost << endl;
    }
    return 0;
}



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

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
	//freopen("input.txt", "r", stdin);
	
	int n; cin>>n;
	
	vector<int> a(n+1, 0), b(n+1, 0);
	
	for(int i=1; i<=n; i++) cin>>a[i];
	
	for(int i=n; i>=1; i--)
	{
		int balls = 0;
		for(int j = i; j <=n; j += i)
		{
			balls += b[j];
		}
		if(a[i] != balls % 2) b[i]++;
	}
	
	vector<int> cnt;
	for(int i=1; i<=n; i++) if(b[i] > 0) cnt.push_back(i);
	
	cout<< (int) cnt.size()<<"\n";
	for(int i : cnt) cout<<i <<" "; cout<<"\n";
	
	
}

Measured memory_bytes: 5108
n,m=map(int,input().split())

A=[input() for i in range(n)]
B=[input() for i in range(m)]

ans=0        
for i in range(n-m+1):
    for j in range(n-m+1):
        if [a[j:j+m] for a in A[i:i+m]] == B:
            ans=1
        
        
if ans == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 100000;

int partition(int A[], int p, int r) {
  // A[p ... q-1] [q] [q+1 ... r]
  int x = A[r];
  int i = p - 1;
  for (int j = p; j < r; j++) {
    if (A[j] <= x) {
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i + 1], A[r]);
  return i + 1;
}

int main() {
  int data[MAX];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> data[i];

  int pivot = partition(data, 0, n - 1);

  cout << data[0];
  for (int i = 1; i < n; i++) {
    cout << " ";
    if (i == pivot)
      cout << "[";
    cout << data[i];
    if (i == pivot)
      cout << "]";
  }
  cout << endl;
}

Measured memory_bytes: 3456
import std.stdio;

void main() {
  int n, k;
  int number = 1;
  
  readf(" %s %s", &n, &k);
  
  foreach (i;0..n) {
    if (number + k < number * 2) {
      number += k;
    } else {
      number *= 2;
    }
  }

  writeln(number);
}


Measured memory_bytes: 256
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var n int
var A [][]int

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	A = make([][]int, 2)
	for i := 0; i < n; i++ {
		tmp := nextInt()
		A[0] = append(A[0], tmp)
	}
	sum := 0
	for i := 0; i < n; i++ {
		tmp := nextInt()
		sum += tmp
		A[1] = append(A[1], tmp)
	}

	upsum := make([]int, n)
	downsum := make([]int, n)
	upsum[0] = A[0][0]
	downsum[0] = sum

	ans := -1
	for i := 0; i < n; i++ {
		if upsum[i]+downsum[i] > ans {

			ans = upsum[i] + downsum[i]
		}
		if i < n-1 {
			upsum[i+1] = upsum[i] + A[0][i+1]
			downsum[i+1] = downsum[i] - A[1][i]
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
    double x,h,S;
    while(1)
    {
        scanf("%lf\n%lf",&x,&h);
        if(x==0&&h==0)
            break;
        double a=pow(x,2);
        double b=pow(h,2);
        double c=sqrt(b+a/4);
        S=2*c*x+a;
        printf("%f\n",S);
    }
    return 0;
}

Measured memory_bytes: 644
#!/usr/bin/env python

def sqroot(n):
    x = 1
    for i in range(100):
        x = (x + n/x)/2
    return x

x1, y1, x2, y2 = input().split()
x1 = float(x1)
x2 = float(x2)
y1 = float(y1)
y2 = float(y2)

distance = sqroot((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1))

print("%.8f" % distance)

Measured memory_bytes: 7448
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    int n;
    cin >> n;
    map<long long,long long>mp;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        mp[a]++;
    }
    long long ans=0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        long long f = itr->first, s = itr->second;
       if(s<f){
           ans += s;
       }else{
           ans += s-f;
       }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9448
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v(n, 0);
  vector<int> peo((n + 1) /2, 0);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }  
  long long q = pow(10, 9) + 7;
  long long ans = 1; 

  sort(v.begin(), v.end());
  if(n % 2 == 1){
    bool f = false;
    for(int i = 0; i < n; i++){
      if(i == 0){if(v[i] != 0){f = true; break;}}
      else if(i % 2 == 1){if(v[i] != i + 1){f = true; break;}}
      else{if(v[i] != i){f = true; break;}}
      }
    if(f){cout << 0 << endl;}
    else{
      while(n > 1){
        ans *= 2;
        ans %= q;
        n -= 2;
      }
      cout << ans << endl;
      }
  }
  else{
    bool f = false;
    for(int i = 0; i < n; i++){
      if(i % 2 == 0){if(v[i] != i + 1){f = true; break;}}
      else{if(v[i] != i){f = true; break;}}
    }
    if(f){cout << 0 << endl;}
    else{
      while(n > 0){
        ans *= 2;
        ans %= q;
        n -= 2;
      }
      cout << ans << endl;
      
    }
  }
    
  

}

Measured memory_bytes: 896
use std::io;
fn read<T: std::str::FromStr>() -> T{
    let mut te = String::new();
    io::stdin().read_line(&mut te).unwrap();
    te.trim().parse().ok().unwrap()
}

fn read_multi<T: std::str::FromStr>(ind : i32) -> Vec<T> {
    (0..ind).map(|_| read()).collect()
}

fn main() {
    let values : Vec<i32> = read_multi(6);
    let vala = values[0];
    let vale = values[4];
    let valx = values[5];
    if (vale - vala) <= valx{
        print!("Yay!");
    }else {
        print!(":(");
    }
}


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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int A, B, C, X, ans = 0;
    cin >> A >> B >> C >> X;
    for (int i = 0; i <= A; i++)
        for (int j = 0; j <= B; j++)
            for (int k = 0; k <= C; k++)
                if (i * 500 + j * 100 + k * 50 == X)
                    ans++;
    cout << ans;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define b 1
#define w -1

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

vi dx;
vi dy;
vi dz;

int main(void){
    range(x, -1, 2) range(y, -1, 2) range(z, -1, 2){
        if(!x && !y && !z) continue;
        dx.pb(x);
        dy.pb(y);
        dz.pb(z);
    }

    for(int n, M, p; cin >> n >> M >> p, n;){
        vector<vvi> m(n, vvi(n, vi(n, 0)));
        int turn = b, turncnt = 0;
        string res = "Draw";

        while(p--){
            if(res != "Draw"){
                cin >> n >> M;
                continue;
            }
            turncnt++;

            int xx, yy, zz = 100000; cin >> yy >> xx;
            xx--; yy--;
            for(int z = n - 1; 0 <= z; z--){
                if(m[yy][xx][z] == 0){
                    zz = z;
                    m[yy][xx][zz] = turn;
                    break;
                }
            }

            rep(i, dx.size()){
                int cnt = 1;
                for(int sign = -1; sign <= 1; sign += 2){
                    range(j, 1, n){
                        int x = xx + sign * dx[i] * j,
                            y = yy + sign * dy[i] * j,
                            z = zz + sign * dz[i] * j;
                        if(x < 0 || n <= x ||
                           y < 0 || n <= y ||
                           z < 0 || n <= z) break;
                        if(m[y][x][z] != turn) break;

                        cnt++;
                    }
                }
                if(M <= cnt) res = turn == b ? "Black":"White";
            }
            turn = turn == b ? w:b;
        }

        cout << res;
        if(res != "Draw") cout << " " << turncnt;
        cout << endl;
    }

	return 0;
}

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

using namespace std;

using ll = long long;
using db = double;
using vi = vector<int>;
#define pb push_back
#define fir first
#define sec second

ll n, x; 

ll solve(ll n, ll x) {
	if (x * 2 == n) return 2 * x; 
	ll t = n-x; 
	ll s = (x-1) / t; 
	if (s == 0) return solve(n-x, n-2*x)+n; 
	else return solve(n-s*t, x-s*t)+2*s*t; 
}

int main() {
	cin>>n>>x; 
	cout<<solve(n,x)+x<<endl; 
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::{i32, i64, u32, u64, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};
#[allow(unused_imports)]
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        n: usize,
        mut m: i64,
        ab: [(i64, i64); n],
    }
    let mut btmap = BTreeMap::new();
    let mut ans = 0;
    for (a, b) in ab { *btmap.entry(a).or_insert(0) += b; }
    for (price, stock) in btmap {
        let to_buy = min(m, stock);
        m -= to_buy;
        ans += price * to_buy;
    }
    println!("{}", ans);
}


Measured memory_bytes: 7992
#include<bits/stdc++.h>
using namespace std;
long long x[1000010],ju[100010];
int main()
{
	long long n,a,b;
	long long ans=0;
	cin>>n>>a>>b;
	x[0]=0;
	for(int i=1;i<=n;i++)
	{
	   cin>>x[i];
	   ju[i]=x[i]-x[i-1];
	}
	for(int i=2;i<=n;i++)
	{
		if(ju[i]*a<=b)
		{
			ans+=ju[i]*a;
		}
		if(ju[i]*a>b)
		{
			ans+=b;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 110;
ll arr[maxn], n, x;

int main() {
    cin>>n>>x;
    for(int i=0;i<n;i++) {
        cin>>arr[i];
    }
    sort(arr,arr+n);

    ll br = 0LL;
    for(int i=0;i<n;i++) {
        if(i == n-1) {
            if(x == arr[i]) br++;
            else break;
        }
        else {
            if(x >= arr[i]) {
                br++;
                x -= arr[i];
            }
        }
    }
    cout<<br;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    string s,t;
    cin >> s >> t;
    string ans = "Yes";
    for(int i = 0; i < s.length(); i++){
        if(s[i] != t[i]){
            ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>

int main() {
    int N, K;
    std::string S;
    std::vector<int> C;
    std::cin >> N >> K >> S;
    
    for (int i=0; i<N; i++) {
        if (i==0)
            C.push_back(0);
        else if (S[i]!=S[i-1])
            C.push_back(i);
    }
    
    int ans = 0;
    int k, temp;
    //std::cout << "Csize:" << C.size() << std::endl;
    
    int idx = 0;
    for (auto i : C) {
        if (S[i]=='1')
            k = 2 * K + 1;
        else
            k = 2 * K;
        
        if (idx+k < C.size()) {
            temp = C[idx+k]-i;
            //std::cout << i << ":" << temp << " inside" << std::endl;
        }
        else {
            temp = N-i;
            //std::cout << i << ":" << temp << " outside" << std::endl;
        }
        //std::cout << "i+k = " << i+k << std::endl;
        if (ans < temp)
            ans = temp;
        idx++;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 1020
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//define
#define i(X) cin>>X;
#define o(X) cout<<X<<endl;
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define vll(A) vector<long double> A;
#define ivect(A,n,p) vector<long long> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long mod=(long long)(1e9+7);

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll a,ll p)
{
   return power(a,p-2,p);
}

int main()
{
    // #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
    fio;
    ll testcase=1;
    //i(testcase);
    while(testcase--)
    {
        ll i=1,ans=0;
        while(i<=5)
        {
            ll x;
            i(x);
            if(!x)
            {
                ans=i;
            }
            i++;
        }
        o(ans);
    }
    return 0;
}

Measured memory_bytes: 3604
from fractions import gcd
from functools import reduce
def lcm_base(x,y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
    
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
    
N = int(input())
a = [int(i) for i in input().split(" ")]

x = lcm_list(a)-1
Sum = 0
for a_ in a:
    Sum += x%a_
print(Sum)

Measured memory_bytes: 5368