akhauriyash/Code-Regression huggingface dataset:
import math

q, h, s, d = [int(i) for i in input().split()]
n = int(input())
size = [0.25, 0.5, 1., 2.]
money = [[0.25 / q, q, 0.25], [0.5 / h, h, 0.5],
         [1 / s, s, 1.], [2 / d, d, 2.]]
# コスパ高い順にソート
money = list(reversed(sorted(money)))
# print(money)
totalMoney = 0
while True:
    totalMoney += int(n / money[0][2]) * money[0][1]
    # print("add:{} {}cup {}yen".format(int(n / money[0][2]) * money[0][1], int(n / money[0][2]), money[0][1]))
    n %= money[0][2]
    # print("totalmoney:{}".format(totalMoney))
    if n == 0:
        print(totalMoney)
        exit()
    del money[0]

"""
leftFlag = True
while True:
    # 確定分のお金を加算
    totalMoney += int(n/money[0][2])*money[0][1]
    print("add:{} {}cup {}yen".format(int(n/money[0][2])*money[0][1], int(n/money[0][2]), money[0][1]))
    n %= money[0][2]
    print("totalmoney:{}".format(totalMoney))
    if n == 0:
        print(totalMoney)
        exit()
    # [お金, どの容器か(q,h,s,d)]
    over = [money[0][1], money[0][2]]
    moreGoodExist = False
    for i in range(1, len(money)):
        if math.ceil(n/money[i][2])*money[i][1] < over[0]:
            over =[math.ceil(n/money[i][2])*money[i][1], money[i][2]]
            moreGoodExist = True
    if moreGoodExist:
        del money[0]
    else:
        print(totalMoney + over[0])
        exit()
"""

Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)

	n := oneInt()

	var t, nt, x, nx, y, ny int
	for i := 0; i < n; i++ {
		nt, nx, ny = oneInt(), oneInt(), oneInt()

		dt := nt - t
		dist := abs(nx-x) + abs(ny-y)
		if dt < dist || dt%2 != dist%2 {
			fmt.Println("No")
			return
		}
		t, x, y = nt, nx, ny
	}
	fmt.Println("Yes")
}

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

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

func scanNums(len int) (nums []int) {
	for i := 0; i < len; i++ {
		nums = append(nums, oneInt())
	}
	return nums
}

func scanStrings(len int) (strs []string) {
	for i := 0; i < len; i++ {
		strs = append(strs, oneStr())
	}
	return strs
}

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

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums []int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums []int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

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

func sum(nums []int) int {
	sum := 0
	for i := 0; i < len(nums); i++ {
		sum += nums[i]
	}
	return sum
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}

func sumOfEachDigit(num int) int {
	sum := 0
	for num > 0 {
		sum += num % 10
		num /= 10
	}
	return sum
}


Measured memory_bytes: 1792
N,M = [int(i) for i in input().split()]
L_max ,R_min = [int(i) for i in input().split()]
for _ in range(M-1):
    temp = [int(i) for i in input().split()]
    if L_max < temp[0]:
        L_max = temp[0]
    if R_min > temp[1]:
        R_min = temp[1]
print(max(R_min - L_max + 1,0))

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

int main(){
 
 int a,b,c,x,y,p;
 cin>>a>>b>>c>>x>>y;
  
 if((a>=b)&&(b>=c))
  p=c-50;
 if((a>=c)&&(c>=b))
  p=b-50;
 if((b>=c)&&(c>=a))
  p=a-50;
 if((b>=a)&&(a>=c))
  p=c-50;
 if((c>=a)&&(a>=b))
  p=b-50;
 if((c>=b)&&(b>=a))
  p=a-50;
 
 if(x>=y)
  cout<<p+y<<'\n';
 else
  cout<<p+x<<'\n';

return 0;
}

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

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define str string
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Forrev(i,s,e) for (ll i=(s); i>=(e); i--)
#define all(v) v.begin(),v.end()

#define vll vector<ll>
#define vs vector<string>
#define mapll map<ll,ll>
#define pll pair<ll,ll>
#define initialise(a, x) memset(a, x, sizeof(a))
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>

#define ff first
#define ss second
#define endl "\n"
#define mp make_pair
const ll mod=1e9 + 7;

ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}

ll gcd(ll a, ll b) { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);        
}

ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}

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

void solve()
{
    string s,t;
    cin>>s>>t;

    For(i,0,s.size())
    {
        if(s[i]!=t[i])
        {
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;

}

signed main() 
{
    fast_cin();
    // #ifndef ONLINE_JUDGE
    // freopen("C:/IO/in.txt", "r", stdin);
    // freopen("C:/IO/out.txt", "w", stdout);
    // #endif
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    
    
    return 0;    
}

Measured memory_bytes: 3652
program main
  implicit none
  integer(8) :: N,K
  integer(8) :: i_max, i_min
  integer(8) :: out, i
  read(*,*) N,K
  i_min = 0
  do i = 0,K-1
     i_min = i_min + i
  end do
  i_max = 0
  do i = N,N-K+1,-1
     i_max = i_max + i
  end do
  out = 0
  out = out + mod( i_max - i_min + 1,10**9+7) 
  do i = K+1,N+1
     i_min = i_min + i-1 
     i_max = i_max + (N-i+1 )
     out = out + mod(i_max - i_min + 1,10**9+7) 
  end do
  write(*,'(i0)') mod(out,10**9+7)
end program main


Measured memory_bytes: 2928
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		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();
		}
		sc.close();
		
		long ans = a[0] - 1;
		int p = 2;
		
		for(int i=1; i<n; i++){
			if(a[i] != p){
				ans += (a[i]-1)/p;
			}else{
				p++;
			}
		}
		System.out.println(ans);
	}

}

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

int main(){
    double n, N;
    const double tax_rate = 1.08;
    cin >> n;
    N = n / tax_rate;
    if((int) N * tax_rate == n){
        cout << (int) N << endl;
    }else if((int) ((int) (N+1) * tax_rate) == n){
        cout << (int) N+1 << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

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

long long calc(int pat, const vector<long long> &vec){
    long long ans = 0;
    long long tmp = vec[0];
    for (int i = 1; i != vec.size(); ++i){
        if (pat & 1){
            ans += tmp;
            tmp = vec[i];
        }else{
            tmp *= 10;
            tmp += vec[i];
        }
        pat >>= 1;
    }
    ans += tmp;
    return ans;
}

int main() {
    long long S;
    cin >> S;
    vector<long long> vec;
    while (S){
        vec.push_back(S % 10);
        S /= 10LL;
    }
    reverse(vec.begin(), vec.end());
    int n = vec.size();
    long long ans = 0LL;
    for (int pat = 0; pat != (1 << (n - 1)); ++pat){
        ans += calc(pat, vec);
    }
    cout << ans << endl;
    return 0;
}

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

int func(string s, int n){
	int a = 1, ans = 0;
	for(int i = s.size()-1;i >= 0;i--){
		if(s[i] == 'X')ans += n * a;
		else ans += (s[i]-'0') * a;
		a *= 10;
	}
	return ans;
}

int check(string s1, string s2, string s3){
	if(s1.size() > 1 && s1[0] == 'X')return 1;
	if(s2.size() > 1 && s2[0] == 'X')return 1;
	if(s3.size() > 1 && s3[0] == 'X')return 1;
	return 0;
}

int sub(string s1, string s2, string s3){
	for(int i= 0;i < 10;i++){
		if(!i && check(s1, s2, s3))continue;
		int n1 = func(s1, i);
		int n2 = func(s2, i);
		int n3 = func(s3, i);
		//cout << n1 << " " << n2 << " " << n3 << endl;
		if(n1 + n2 == n3){cout << i;return 1;}
	}
	return 0;
}

int main(){
	string str, s1, s2, s3;
	while(cin >> str){
		s1 = s2 = s3 = "\0";
		int p = 0;
		for(p;str[p] != '+';p++)s1 += str[p];p++;
		for(p;str[p] != '=';p++)s2 += str[p];p++;
		for(p;p < str.size();p++)s3 += str[p];
		
		if(!sub(s1, s2, s3))cout << "NA";cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# arc058_b

# input
H, W, A, B = map(int, input().split())
mod = 1000000007
# fermat
N = 0
fac = [1]
inv = [1]

def mypow(a, b):
    return _mypow(a, a, b)

def _mypow(p, a, b):
    if b == 1:
        return p
    n = (p*p) % mod
    c, r = divmod(b, 2)
    if r == 0:
        return _mypow(n, a, c)
    else:
        ret = _mypow(n, a, c) * p
        return ret % mod

def init_cmb(_N):
    global N, fac, inv
    N=_N
    fac = [1]
    for i in range(1, N+1):
        n = (fac[i-1] * i) % mod
        fac.append(n)
    inv = (N+1) * [1]
    inv[N] = mypow(fac[N], mod-2)
    for i in range(1, N)[::-1]:
        inv[i] = (inv[i+1] * (i+1)) % mod

def cmb(n, r):
    if (r<0 or n<r): raise Exception(n, r)
    if n>N: raise Exception(n)
    ret = fac[n] * inv[r] * inv[n-r]
    return ret % mod
init_cmb(100000*2)
# getans
def calc(h, w):
    h += -1
    w += -1
    return cmb(h+w, h)
ans = 0
for y in range(1, H-A+1):
    left = calc(y, B)
    right = calc((H-y+1), (W-B))
    ans += left*right
    ans %= mod
# output
print(ans)


Measured memory_bytes: 19116
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int h, w;
	cin >> h >> w;
	char s[51][51];

	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	string ans = "Yes";
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			bool f = false;
			if (i + 1 != h && s[i + 1][j] == '#')f = true;
			else if (i - 1 != -1 && s[i - 1][j] == '#')f = true;
			else if (j + 1 != w && s[i][j + 1] == '#')f = true;
			else if (j - 1 != -1 && s[i][j - 1] == '#')f = true;
			if (!f && s[i][j] == '#') ans = "No";
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

    if ((n % 4 == 0) || (n % 7 == 0) || (n % 11 == 0)) {
        puts("Yes");
        return 0;
    }

    bool flg = false;
    for (int i = 0; i < n; i++) {
        int tmp = n;
        tmp = max(tmp - (i * 4), 0);
        if (tmp == 0) {
            break;
        }

        if (tmp % 7 == 0) {
            flg = true;
            break;
        }
    }
    cout << (flg ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

n,m = map(int,input().split())
e = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    e[a-1].append(b-1)
dis = [0]*n

def dfs(x):
    num = 0
    for nex in e[x]:
        if dis[nex] < 0:
            dfs(nex)
        num = max(num,dis[nex]+1)
    dis[x] = num
    return 
dis = [-1]*n
for i in range(n):
    if e[i] and dis[i] < 0 :
        dfs(i)
print(max(dis))

Measured memory_bytes: 59040
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	static class Dice {
		private int[] sides;

		Dice(String line) {
			String[] sides = line.split(" ");
			this.sides = new int[sides.length];
			for (int i = 0; i < sides.length; i++) {
				this.sides[i] = Integer.parseInt(sides[i]);
			}
		}

		Dice(int[] sides) {
			this.sides = sides;
		}

		private static int[][] eastTable = {
			{6, 2, 4, 1, 3, 6},
			{3, 6, 0, 5, 6, 2},
			{1, 5, 6, 6, 0, 4},
			{4, 0, 6, 6, 5, 1},
			{2, 6, 5, 0, 6, 3},
			{6, 3, 1, 4, 2, 6}
		};

		public static int getEast(Dice dice, final int tnum, final int snum) {
			boolean tflag = false;
			boolean sflag = false;
			int top = 0;
			int south = 0;
			int[] sides = dice.sides;
			for (int i = 0; i < sides.length; i++) {
				if (tnum == sides[i]) {
					top = i;
					tflag = true;
					if (sflag) {
						break;
					}
				} else if (snum == sides[i]) {
					south = i;
					sflag = true;
					if (tflag) {
						break;
					}
				}
			}

			int east;
			int eastSide = eastTable[top][south];

			if (eastSide == 6) {
				east = -1;
			} else {
				east = sides[eastSide];
			}

			return east;
		}

		public static boolean isIdentification(Dice dice1, Dice dice2) {
			boolean isEqual = false;

			for (int i = 0; i < 6; i++) {
				if (isEqual) {
					break;
				}

				if (dice1.sides[0] == dice2.sides[i] && dice1.sides[5] == dice2.sides[5-i]) {
					for (int j = 0; j < 6; j++) {
						if (isEqual) {
							break;
						} else if (j == i) {
							continue;
						}

						if (dice1.sides[1] == dice2.sides[j] && dice1.sides[4] == dice2.sides[5-j]) {
							for (int k = 0; k < 6; k++) {
								if (isEqual) {
									break;
								} else if (k == i || k == j) {
									continue;
								}

								if (dice1.sides[2] == dice2.sides[k] && dice1.sides[3] == dice2.sides[5-k]) {
									if (dice1.sides[2] == Dice.getEast(dice2, dice2.sides[i], dice2.sides[j])) {
										isEqual = true;
									} else if (dice2.sides[k] == dice2.sides[5-k]) {
										isEqual = true;
									}
								}
							}
						}
					}
				}
			}

			return isEqual;
		}
	}

	public static void main(String[] args) {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			boolean isEqual = false;

			int n = Integer.parseInt(in.readLine());
			Dice[] dices = new Dice[n];
			for (int i = 0; i < n; i++) {
				dices[i] = new Dice(in.readLine());
			}
			in.close();

			for (int i = 0; i < n; i++) {
				if (isEqual) break;
				
				for (int j = i+1; j < n; j++) {
					if (Dice.isIdentification(dices[i], dices[j])) {
						isEqual = true;
						break;
					}
				}
			}

			System.out.println(isEqual ? "No" : "Yes");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}






Measured memory_bytes: 24316
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int N; cin>>N;
    priority_queue<ll, vec, greater<ll>> plus;
    PQ minus;
    rep(i,N){
        ll A; scanf("%lld",&A);
        if(A>=0) plus.push(A);
        else     minus.push(A);
    }
    if(minus.empty()){
        ll p=plus.top(); plus.pop();
        minus.push(p);
    }
    if(plus.empty()){
        ll m=minus.top(); minus.pop();
        plus.push(m);
    }
    vector<P> v;
    rep(i,N-1){
        ll p=plus.top(); plus.pop();
        ll m=minus.top(); minus.pop();
        if(SZ(plus) > SZ(minus)){
            v.pb({m,p});
            minus.push(m-p);
        }
        else{
            v.pb({p,m});
            plus.push(p-m);
        }
    }
    cout<<plus.top()<<endl;
    rep(i,N-1){
        cout<<v[i].st<<" "<<v[i].nd<<endl;
    }
    return 0;
}

Measured memory_bytes: 4720
import math
a, b, C = map(float, input().split())

S = a*b*math.sin(math.radians(C))/2
r = (a**2 + b**2 - 2*a*b*math.cos(math.radians(C)))**(1/2)
L = a + b + r
h = 2*S/a
print(S, L, h, sep="\n")



Measured memory_bytes: 5704
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
			int ans=0;
			int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt();
			if(a+b<=c*2)
			
				System.out.println(a*x+b*y);
			else
			{	
				int min=Math.min(x, y);
				ans+=min*2*c;
				ans+=(x-min)*Math.min(a, 2*c);
				ans+=(y-min)*Math.min(b, 2*c);
				System.out.println(ans);
			}
		
	}

}
class Scanner 
{
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

	public String next() throws IOException 
	{
		while (st == null || !st.hasMoreTokens()) 
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public int nextInt() throws IOException {return Integer.parseInt(next());}
	
	public long nextLong() throws IOException {return Long.parseLong(next());}

	public String nextLine() throws IOException {return br.readLine();}
	
	public double nextDouble() throws IOException
	{
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if(x.charAt(0) == '-')
		{
			neg = true;
			start++;
		}
		for(int i = start; i < x.length(); i++)
			if(x.charAt(i) == '.')
			{
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			}
			else
			{
				sb.append(x.charAt(i));
				if(dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg?-1:1);
	}
	
	public boolean ready() throws IOException {return br.ready();}


} 

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


int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        int a;
        cin >> a;
        ans += a-1;
    }
    cout << ans << endl;
    return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    deque<ll> q;
    bool f=0;
    rep(i, N){
        ll a; cin >> a;
        if(f==0) q.push_back(a);
        if(f==1) q.push_front(a);
        f = !f;
    }
    while(!q.empty()){
        if(f==0){
            ll res = q.front(); q.pop_front();
            cout << res;
        }else{
            ll res = q.back(); q.pop_back();
            cout << res;
        }
        if(!q.empty()) cout << " ";
        else cout << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7936
N, M = map(int, input().split())
kLst = [list(map(int, input().split())) for i in range(M)]
pLst = list(map(int, input().split()))
ans = 0
dLst = [0] * N

def dfs(n, v, ans):
    dLst[n - 1] = v
    if N == n:
        tLst = [0] * M
        for i in range(M):
            cnt = 0
            for j in range(kLst[i][0]):
                if dLst[kLst[i][j + 1] - 1] == 1:
                    cnt += 1
            tLst[i] = cnt % 2
        s = True
        for i in range(M):
            if tLst[i] != pLst[i]:
                s = False
                break
        if s:
            ans += 1
        return ans
    ans = dfs(n + 1, 0, ans)
    ans = dfs(n + 1, 1, ans)
    return ans

print(dfs(0, 0, ans))



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll c; cin >> c;
    vector<ll> cnt(c+1,0LL);
    for(int i=1;i<=c;i++){
        int sum=0;
        for(int j=i;j<=c;j++){
            sum+=j;
            if(sum>c)break;
            cnt[sum]++;
        }
    }
    ll res=0;
    vector<int> div;
    for(int i=1;i*i<=c;i++){
        if(c%i==0){
            div.push_back(i);
            if(c/i!=i)div.push_back(c/i);
        }
    }
    for(int d:div){
        res+=cnt[d]*cnt[c/d];
    }
    cout << res << endl;
}


Measured memory_bytes: 3640
/*
Created on Fri Aug 25 16:34:06 2020

@author: roastedcoder

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
const int mod = 1e9+7;
#define endl "\n"
#define append push_back
#define roastedcoder ios_base::sync_with_stdio(false); cin.tie(NULL);
//__________________________________________________________________

string a, b;

string weird(int n, int m) {
	int dp[n+1][m+1];
  	for(int i = 0; i<n+1; i++) {
  		for(int j = 0; j<m+1; j++) {
  			if(i == 0 || j == 0) dp[i][j] = 0;
  			
  			else if(a[i-1] == b[j-1]) dp[i][j] = 1+dp[i-1][j-1];
  			
  			else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
		}
	}
	int i = n, j = m;
	string res = "";
	while(i>0 && j>0) {
		if(a[i-1] == b[j-1]) {
			res.append(a[i-1]);
			i--;
			j--;
		}
		else {
			if(dp[i-1][j] < dp[i][j-1]) {
				j--;
			}
			else i--;
		}
	}
	reverse(res.begin(), res.end());
	return res;
}

int main() {
	roastedcoder
	cin>>a>>b;
  	int n = a.length(), m = b.length();
	cout<<weird(n, m);
}

//__________________________________________________________________
/*
Sample Input:
axyb
abyxb

Sample Output:
ayb

*/

Measured memory_bytes: 38776
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
// #define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }
  void solve()
  {
int n;
string s;
cin>>n>>s;
int cr=0,tr=0,rw=0,cw=0;
forn(i,n)
{
	if(s[i]=='W')break;
	cw++;
}
forn(i,n)
{
if(s[i]!='R')break;
cr++;	
}
forn(i,n)tr+=(s[i]=='R');
int ans=INT_MAX;
uin(ans,n-cr);
int no=0;
forn(i,tr)no+=(s[i]!='R');
uin(ans,no);

bool is=false;
ford(i,n)
{
if(s[i]=='R')is=true;
if(is&&s[i]=='W')rw++;
}
uin(ans,rw-cw);


cout<<max(ans,0);


  }
  
  int main()
  {
ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
    #endif
int t=1;
while(t--)
{
  solve();
}

    return 0;
  }


Measured memory_bytes: 3764
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int count = 1;
        int dubMinus = 0;
        int ascMinus = 0;
        int listIndex = 0;
        int prev = sc.nextInt();
        TreeSet<Integer> numSet = new TreeSet<>();
        List<Integer> list = new ArrayList<>();
        numSet.add(prev);
        list.add(prev);
        for(int i = 1; i < N; i++){
            boolean ascFlg = false;
            boolean dubFlg = false;
            int P = sc.nextInt();
            if(prev < P){
                count++;
            }else{
                count = 1;
            }
            if(count == K){
                ascFlg = true;
                ascMinus++;
                count--;
            }
            // K個になるまでSetに溜め込む
            int max = numSet.last();
            numSet.add(P);
            list.add(P);
            if(numSet.size() == K + 1){
                int min = numSet.first();
                int newMax = numSet.last();
                numSet.remove(list.get(listIndex));
                listIndex++;
                int newMin = numSet.first();
                if(min != newMin && max != newMax){
                    dubFlg = true;
                }
            }
            if(!ascFlg && dubFlg){
                dubMinus++;
            }
            prev = P;
        }
        ascMinus = ascMinus > 0 ? ascMinus - 1 : 0;
        System.out.println(N - K + 1 - ascMinus - dubMinus <= 0 ? 1 : N - K + 1 - ascMinus - dubMinus);
    }
}


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

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

    int slen = s.size(), tlen = t.size();

    int lcs[slen + 1][tlen + 1];
    for(int i = 0; i <= slen; ++i) {
        for(int j = 0; j <= tlen; ++j) {
            if(i == 0 || j == 0) lcs[i][j] = 0;
            else if(s[i-1] == t[j-1]) lcs[i][j] = lcs[i-1][j-1] + 1;
            else lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);

            // cout << lcs[i][j] << ' ';
        }
        // cout << endl;
    }
    int tar = lcs[slen][tlen];

    string res;

    int i = slen, j = tlen;
    while(i >= 1 && j >= 1) {
            if(s[i-1] == t[j-1] && lcs[i][j] == tar) {
                res += s[i-1];
                --i, --j;
                tar--;
            } else if(lcs[i][j] == lcs[i-1][j]) --i;
            else --j;
    }

    reverse(res.begin(), res.end());
    cout << res << endl;
}

Measured memory_bytes: 35456
import sys
import math
import itertools
import collections

def solve(X,Y):
    for i in range(X+1):
        j = X - i
        if(i * 2 + j * 4 == Y):
            return "Yes"
    else:

        return "No"
def main():
    X,Y = map(int,input().split())
    # solve()
    print(solve(X,Y))

if __name__ == "__main__":
    main()


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);
template <typename T>
void MACRO_VAR_Scan(T &t)
{
    std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &... rest)
{
    std::cin >> first;
    MACRO_VAR_Scan(rest...);
}

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define yes() printf("yes\n")
#define no() printf("no\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

ll ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
long long a, b, c, d, n;
int x, y;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;
    cin >> n;
    vi p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n)
    {
        while (p[i] % 2 == 0)
        {
            p[i] /= 2;
            q[i] += 1;
        }
    }

    sort(ALL(q));
    pr(q[0]);
    return 0;
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cerr << "\n";
#define HOISE           cerr << "hoise " << __LINE__ << "\n"
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << "\n"
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

typedef long long ll;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

int32_t main()
{
    FASTIO;

    int ans;
    int n;
    cin >> n;
    if(n <= 599) ans = 8;
    else if( n <= 799) ans = 7;
    else if(n <= 999) ans = 6;
    else if(n <= 1199) ans = 5;
    else if(n <= 1399) ans = 4;
    else if(n <= 1599) ans = 3;
    else if(n <= 1799) ans = 2;
    else ans = 1;

    cout << ans;

    return 0;
}

Measured memory_bytes: 3652
N = int(input())
S = [0]*N
for i in range(N):
    a = int(input())
    a -= 1
    if a == 0:
        S[0] = 1
    else:
        if S[a-1] == 0:
            S[a] = 1
        else:
            S[a] = S[a-1] + 1
print(N-max(S))

Measured memory_bytes: 76452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
const int MAXM=1e6+10;
int F[maxn];
struct node
{
    int x,y,id;
}sp[maxn];
bool cmp2(node a,node b)
{
    return a.x<b.x;
}
bool cmp3(node a,node b)
{
    return a.y<b.y;
}
struct Edge
{
    int u,v,w;
}e[MAXM];
int tol;
void addedge(int u,int v,int w)
{
    e[tol].u=u;
    e[tol].v=v;
    e[tol++].w=w;
}
bool cmp(Edge a,Edge b)
{
    return a.w<b.w;
}
int Find(int x)
{
    if(F[x]==-1)return x;
    else return F[x]=Find(F[x]);
}
int Krustal(int n)
{
    memset(F,-1,sizeof(F));
    sort(e,e+tol,cmp);
    int cnt=0;
    int ans=0;
    for(int i=0;i<tol;++i)
    {
        int u=e[i].u;
        int v=e[i].v;
        int w=e[i].w;
        int t1=Find(u);
        int t2=Find(v);
       // cout<<t1<<' '<<t2<<endl;
        if(t1!=t2)
        {
            ans+=w;
            F[t1]=t2;
            cnt++;
        }
        if(cnt==n-1) break;
    }
   // cout<<cnt<<endl;
    if(cnt<n-1)return -1;
    else return ans;
}
int main()
{
    int n;
    cin>>n;
    tol=0;
    for(int i=1;i<=n;++i)
    {
        cin>>sp[i].x>>sp[i].y;
        sp[i].id=i;
    }
    sort(sp+1,sp+1+n,cmp2);
    for(int i=1;i<n;++i)
    {
        addedge(sp[i].id,sp[i+1].id,sp[i+1].x-sp[i].x);
    }
    sort(sp+1,sp+1+n,cmp3);
    for(int i=1;i<n;++i)
    {
        addedge(sp[i].id,sp[i+1].id,sp[i+1].y-sp[i].y);
    }
    int ans=Krustal(n);
    cout<<ans<<endl;
    return 0;
}


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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define lim 100010
#define mod 1e9 + 7
#define INF 1e9
#define REP(i, n) for (int i = 0; i < n; i++)

ll GCD(int x, int y) { return x % y == 0 ? y : GCD(y, x % y); }

double expect(double p) { return (1 + p) * 0.5; }

int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  double p[N];
  double P;
  for (int i = 0; i < N; i++) {
    scanf("%lf", &P);
    p[i] = expect(P);
  }

  double ans = 0;
  for (int i = 0; i < K; i++) {
    ans += p[i];
  }
  int l = 0;
  double tmp = ans;
  for (int i = K; i < N; i++, l++) {
    tmp -= p[l];
    tmp += p[i];
    ans = tmp > ans ? tmp : ans;
  }
  printf("%lf", ans);
  return 0;
}

Measured memory_bytes: 1792
n = int(input())
A = list(map(int,input().split()))

def gcd(x,y):
  if y == 0:
    return x
  else:
    return gcd(y,x%y)

accum_gcd = A[0]
for i in range(n):
    accum_gcd = gcd(accum_gcd,A[i])
print(accum_gcd)  

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

int main(){
	int N;
	cin>>N;
	vector<int> B(N+1,2*100000);
	for (int i=1;i<N;i++){
		cin>>B.at(i);
	}
	int sum = 0;
	for(int i = 0;i<N;i++){
		sum+=(min(B.at(i),B.at(i+1)));
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

const long long int INF = 1e18;

using namespace std;


int main() {
    int n;
    cin >> n;
    long long int a;
    long long int minimum = INF;
    long long int profit = -INF;
    REP(i, n) {
        cin >> a;
        profit = max(profit, a - minimum);
        minimum = min(minimum, a);
    }

    cout << profit << endl;

    return 0;
}

Measured memory_bytes: 1164
from heapq import heapify, heappop, heappush

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

while len(a) > 1:
    a1, a2 = heappop(a), heappop(a)
    m = a2 % a1
    heappush(a, a1)
    if m:
        heappush(a, m)
print(heappop(a))

Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>> way[100009];
vector<int> ans(100009);
int n;
//start->dfs(-1,0)
void dfs(int from,int to){
    for(int i=0;i<way[to].size();i++)
    {
        if(from==way[to][i].first)
        continue;
        ans[way[to][i].first]=(ans[to]+way[to][i].second)%2;
        dfs(to,way[to][i].first);
    }
}
int main(){
    ans[0]=0;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        way[a].push_back(make_pair(b,c%2));
        way[b].push_back(make_pair(a,c%2));
    }
    dfs(-1,0);
    for(int i=0;i<n;i++)
    cout<<ans[i]<<endl;

    return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
int n;
int mod = 1e9+7;
int main() {
    cin >> n;
    vector<int> a(n, 0);
    for(int i = 0; i < n; ++i) cin >> a.at(i);

    sort(a.begin(), a.end());
    int ans = 1;
    if(n % 2 == 0) {
        bool eflg = true;
        for(int i = 0; i < n; i+=2) {
            if(a.at(i) != a.at(i+1)) {
                eflg = false;
                break;
            }
        }

        if(eflg) {
            int limit = n/2;
            for(int i = 0; i < limit; ++i) {
                ans *= 2;
                ans %= mod;
            }
        }else {
            ans = 0;
        }
    }else {
        bool oflg = true;
        for(int i = 0; i < n;) {
            if(i == 0) {
                if(a.at(i) != 0) {
                    oflg = false;
                    break;
                }else {
                    i++;
                }
            }else {
                if(a.at(i) != a.at(i+1)) {
                    oflg = false;
                    break;
                }
                i += 2;
            }
        }

        if(oflg) {
            int limit = n/2;
            for(int i = 0; i < limit; ++i) {
                ans *= 2;
                ans %= mod;
            }
        }else {
            ans = 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
typedef int number;
typedef vector<number> Array;
typedef vector<Array> Matrix;

int m;

// O( n )
Matrix ident(int n) {
	Matrix A(n, Array(n));
	for (int i = 0; i < n; ++i) A[i][i] = 1;
	return A;
}
// O( n )
number inner_product(const Array &a, const Array &b) {
	number ans = 0;
	for (int i = 0; i < a.size(); ++i)
		ans += a[i] * b[i];
	return ans;
}
// O( n^2 )
Array mul(const Matrix &A, const Array &x) {
	Array y(A.size());
	for (int i = 0; i < A.size(); ++i)
		for (int j = 0; j < A[0].size(); ++j)
		{
			y[i] += (A[i][j] * x[j]);
			y[i] %= m;
		}
	return y;
}
// O( n^3 )
Matrix mul(const Matrix &A, const Matrix &B) {
	Matrix C(A.size(), Array(B[0].size()));
	for (int i = 0; i < C.size(); ++i)
		for (int j = 0; j < C[i].size(); ++j)
			for (int k = 0; k < A[i].size(); ++k)
			{
				C[i][j] += A[i][k] * B[k][j];
				C[i][j] %= m;
			}
	return C;
}
// O( n^3 log e )
Matrix pow(const Matrix &A, int e) {
	return e == 0 ? ident(A.size()) :
		e % 2 == 0 ? pow(mul(A, A), e / 2) : mul(A, pow(A, e - 1));
}

// O(n)
number tr(const Matrix &A) {
	number ans = 0;
	for (int i = 0; i < A.size(); ++i)
		ans += A[i][i];
	return ans;
}

int main()
{
	int n, a, b, c, t;
	while (cin >> n >> m >> a >> b >> c >> t, n)
	{
		Array v(n);
		REP(i, n) cin >> v[i];
		Matrix mat(n, Array(n));
		REP(i, n)
		{
			if (i - 1 >= 0) mat[i][i - 1] = a;
			mat[i][i] = b;
			if (i + 1 < n) mat[i][i + 1] = c;
		}
		if (t > 0) 
		{
			Matrix mat2 = pow(mat, t);
			v = mul(mat2, v);
		}
		REP(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\n" : " ");
	}
	return 0;
}

Measured memory_bytes: 3352
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A;
int B;
int main(){
  rd(A);
  rd(B);
  if(B%A){
    wt_L(B -A);
    wt_L('\n');
  }
  else{
    wt_L(B +A);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// int A, B;
// {
//   rd(A,B);
//   wt( B if[B%A,-,+] A );
// }


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

//BEGIN CUT HERE
//Binary Indexed Tree
//1-indexed
//1-indexed
//1-indexed
class Bit{
public:
    //tbl[1]...tbl[n]
    explicit Bit(int n):size(static_cast<unsigned int>(n+1)){//1-indexed
        tbl.resize(size+10,0);
    }
    void add(int a,ll w){//tbl[a]+=w , 1-indexed , 1-indexed!!!!!!!!!!!!!!!
        for(int i=a;i<=size;i+=i&-i)tbl[i]+=w;
    }
    ll sum(int a){//v[1]+...+v[a] , 1-indexed ,1-indexed!!!!!!!!!!!!!
        ll ret=0;
        for(int i=a;i>0;i-=i&-i){
            ret+=tbl[i];
        }
        return ret;
    }
    int lower_bound(ll w){
        if(w<=0)return 0;
        int x=0;
        int k=1;
        while(true){
            if(k*2>size){
                break;
            }
            k*=2;
        }
        for(k;k>0;k/=2){
            if(x+k<=size && tbl[x+k]<w){
                w-=tbl[x+k];
                x+=k;
            }
        }
        return x+1;//1-indexed , 1-indexed!!!!!!!!!!!!
    }
private:
    unsigned int size;
    vector<ll> tbl;
};
//END CUT HERE

//AOJ->library->Range Query->RSQ
int main(){
    int n,q;
    cin>>n>>q;
    Bit bit(n);
    for(int i=0;i<q;i++){
        int a,b,c;cin>>a>>b>>c;
        if(a==0){
            bit.add(b,c);
        }else{
            cout<<bit.sum(c)-bit.sum(b-1)<<endl;
        }
    }
}


Measured memory_bytes: 3604
import java.util.*;
 
public class Main {
    public static void main(String args[]) {
       ///値を取得
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
       int K = sc.nextInt();    
       int Q = sc.nextInt();    
       
       int[] A = new int[Q];
       int[] count = new int[N+1];    
       
       for(int i = 0; i < Q; ++i) {
           A[i] = sc.nextInt(); 
           count[A[i]-1]++;
       }
       
       for(int j = 0; j < N; ++j) {
            if(K - Q + count[j] > 0) {
                System.out.println("Yes");
            } else {
               System.out.println("No");
            }
       }
    }
}

Measured memory_bytes: 60400
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  char c;std::cin >> c;
  int i = c - 'a';
  i++;
  c = 'a' + i;
  std::cout << c << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int gcd(int p,int q){
  while(q!=0){
    int r=p%q;
    p=q;
    q=r;
  }
  return p;
}
int main(){
  int K;
  cin >> K;
  long long S =0;
  for(int a=1;a<=K;a++){
    for(int b=1;b<=K;b++){
      for(int c=1;c<=K;c++){
        S=S+gcd(a,gcd(b,c));
      }
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<cmath>
using namespace std;
int Prime(int a) {
	if (a == 2) return 1;
	else if (a > 2 && a % 2 == 0) return 0;
	else {
		int i = 3;
		while (i <= sqrt(a)) {
			if (a % i == 0) return 0;
			i += 2;
		}
		return 1;
	}
}
int main() {
	int n, a[10000], prime_cnt = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		prime_cnt += Prime(a[i]);
	}
	printf("%d\n", prime_cnt);
}


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

int main() {
  int s,w;
  cin >> s >> w;
  cout << (w>=s ? "unsafe" : "safe") << endl;
}


Measured memory_bytes: 3652