akhauriyash/Code-Regression huggingface dataset:
# abcde    s=input()    s='abcde'
# abcde    s=list(input())    s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)    a=int(input())    a=5
# 1 2    | x,y = s_inpl()   |    x=1,y=2
# 1 2 3 4 5 ... n 　    li = input().split()    li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　    li = inpl()    li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　    li = input().split('T')    li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
MAX_DIGIT = 50

############
############
############

X, Y, Z, K = l_inpl()
A = l_inpl()
B = l_inpl()
C = l_inpl()

top_k_AB = []
for i in range(X):
    for j in range(Y):
        top_k_AB.append(A[i] + B[j])

top_k_AB.sort(reverse=True)
top_k_AB = top_k_AB[:K]

top_k_ABC = []
for i in range(len(top_k_AB)):
    for j in range(Z):
        top_k_ABC.append(top_k_AB[i]+C[j])

top_k_ABC.sort(reverse=True)
print("\n".join([ str(s) for s in top_k_ABC[:K]]))


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

int main(){
    int N,X,L;
    int i = 0,sum = 0;
    cin >> N >> X;
    for(; i<N;i++){
        cin >> L;
        sum += L;
        if (sum>X)break;
    }
    cout << i+1 << endl;
}

Measured memory_bytes: 256
n, a, b, c = [int(i) for i in input().split(" ")]
l = [0] * n
for i in range(0, n):
    l[i] = int(input())
    
mp_min = 8000

for i in range(0, 4**n):
    ls = [0, 0, 0, 0]
    sc = [0, 0, 0, 0]
    it = i
    for j in range(0, n):
        if ls[it % 4] > 0:
            sc[it % 4] += 1
        ls[it % 4] += l[j]
        it = it // 4
    mp = 10 * (sc[1] + sc[2] + sc[3]) + abs(a - ls[1]) + abs(b - ls[2]) + abs(c - ls[3])
    if mp < mp_min and ls[1] > 0 and ls[2] > 0 and ls[3] > 0:
        mp_min = mp
print(mp_min)

Measured memory_bytes: 3188
//#include "SaveFuncs.cpp"

/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
//#define int long long
constexpr int INF = 2000000100;
constexpr int DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divUp(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

int Main()
{
	int M, D;
	cin >> M >> D;

	ll ret = 0;
	for (int m = 1; m <= M; m++)
	{
		for (int d = 1; d <= D; d++)
		{
			int d1 = d % 10;
			int d10 = d / 10;
			if (d1 >= 2 && d10 >= 2 && d1 * d10 == m)
			{
				//cout << "m:" << m << " d:" << d << endl;
				ret++;
			}
		}
	}

	cout << ret;

	return 0;
}

/*****/

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

	//std::cout << std::fixed << std::setprecision(10);

	Main();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    int a,b;
    cin >> a >> b;
    cout << (a<6 ? 0 :(a<=12 ? b/2 : b)) << endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
n = len(S)
k = 2019

# Let S = s[0]s[1]....s[n - 1] and
# let A[i] = s[i]s[i+1]...s[n-1] = s[i]*10^(n-i-1) + ... + s[n-1]*10^0
A = [0] * (n + 1) # A[n] = 0
d = {0:1}

w = 1
for i in range(n - 1, -1, -1):
    A[i] = (A[i + 1] + w * int(S[i])) % k
    w = w * 10 % k
    if A[i] in d:
        d[A[i]] += 1
    else:
        d[A[i]] = 1

ans = 0
for j in d:
    ans += d[j] * (d[j] - 1) // 2

print(ans)

Measured memory_bytes: 16184
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e6+10;
int fa[N],siz[N];
inline int find(int x){
	if(x==fa[x])
		return x;
	else
		return fa[x]=find(fa[x]);
}
inline void merge(int x,int y){
	int fx=find(x),fy=find(y);
	if(fx==fy) return ;
	else if(siz[fx]<siz[fy]) fa[fx]=fy,siz[fy]+=siz[fx];
	else fa[fy]=fx,siz[fx]+=siz[fy];
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		fa[i]=i,siz[i]=1;
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		merge(x,y);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,siz[i]);
	cout<<ans<<'\n';
}

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

int main() {

	long long a, b, c, k;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
	if(k % 2 == 0) {
		long long d = a - b;
		if(d >= 1e18) {
			printf("%s\n", "Unfair");
		}else {
			printf("%lld\n", d);
		}
	}else {
		long long d = b - a;
		if(d >= 1e18) {
			printf("%s\n", "Unfair");
        }else {
			printf("%lld\n", d);
		}
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;

	cout << (a - b & 1 ? "Borys" : "Alice");
	cout << endl;

	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int init = 1;

  for (int i= 0; i < N; i++) {
    if (2*init < init + K) {
      init = 2*init;
    } else {
      init = init + K;
    }
  }

  cout << init;
}


Measured memory_bytes: 3592
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

string S;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> S;
    solve();
}

// S は ABC または ARC

// string S
// 今週開催されるコンテストを表す文字列を出力せよ。
void solve(){
    if(S=="ABC")cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}


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

int n,m,q,ans=-1e9-7;
int now[100005];

struct node{
	int a,b,c,d;
}que[100005];

signed main(){
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++)  
        cin>>que[i].a>>que[i].b>>que[i].c>>que[i].d;
    
	for(int i=1;i<=n;i++)  
        now[i]=1;
	
	while (now[0]==0){
		int sumv=0;
		for(int i=1;i<=q;i++){
			if(now[que[i].b]-now[que[i].a]==que[i].c)  
                sumv+=que[i].d;
		}
		ans=max(ans,sumv);
		
		for(int i=n;i>=0;i--){
			if(now[i]<m){
				now[i]++;
				for(int j=i+1;j<=n;j++)  
                    now[j]=now[j-1];
				break;
			}
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int N;
ll A[200005];
ll B[200005];
ll C[200005];
ll D[35];

//! under以上になる最小のindex
int getUnder(ll under)
{
    if (under <= 0)
        return 0;
    int ok = N, ng = -1;
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        if (C[mid] >= under)
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    return ok;
}
//! top未満になる最大のindex
int getTop(ll top)
{
    int ok = -1, ng = N;
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        if (C[mid] < top)
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    return ok;
}

int main()
{
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    REP(i, N)
    {
        cin >> B[i];
    }
    ll ans = 0;
    REP(i, 30)
    {
        D[i] = 0;
        ll u = pow((ll)2, i);
        ll t = pow((ll)2, (i + 1));
        REP(j, N)
        {
            C[j] = (B[j] % t);
        }
        sort(C, C + N);
        REP(j, N)
        {
            ll a = A[j] % t;
            {
                int ui = getUnder(u - a);
                int ti = getTop(t - a);
                if (ui <= ti)
                {
                    D[i] += (ti - ui + 1);
                }
            }
            {
                int ui = getUnder(u + t - a);
                int ti = getTop(2 * t - a);
                if (ui <= ti)
                {
                    D[i] += (ti - ui + 1);
                }
            }
        }
        ans |= ((D[i] % 2) << i);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();

		System.out.println(z + " " + x + " " + y);
	}
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
    int r, c, matrix[120][120];
    cin >> r >> c;
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            cin >>matrix[i][j];
        }
    }
    
    for(int j=0; j<c+1; j++){
        matrix[r][j]=0;
    }
    for(int i=0; i<r+1; i++){
        matrix[i][c]=0;
    }
    
    for(int j=0; j<c; j++){
        for(int i=0; i<r; i++){
            matrix[r][j]+=matrix[i][j];
        }
    }
    for(int i=0; i<r+1; i++){
        for(int j=0; j<c; j++){
            matrix[i][c]+=matrix[i][j];
        }
    }
    
    for(int i=0; i<=r; i++){
        for(int j=0; j<=c; j++){
            cout << matrix[i][j];
            if(j!=c) cout <<" ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C = MAP()
if A <= C and C <= B:
    print("Yes")
else:
    print("No")


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

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void) {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll x, y, z, lc = lcm(c, d);
  x = b / c;
  y = b / d;
  z = b / lc;
  ll ans = x + y - z, ans2;
  x = (a - 1) / c;
  y = (a - 1) / d;
  z = (a - 1) / lc;
  ans2 = x + y - z;
  a--;
  cout << b - ans + ans2 - a << '\n';
  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s; cin >> s;
	string str;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == '0')str += '0';
		else if (s[i] == '1')str += '1';
		else if (s[i] == 'B'&&str.size() != 0)str.pop_back();
	}
	cout << str << endl;
}

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

#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

vector<int> top_sorted={};
vector<bool> seen;
int ans=0;

int dfs(vector<vector<int>> &G,int v){
  ans++;
  seen.at(v)=true;
  for(int next_v : G.at(v)){
    if(seen.at(next_v)) continue;
    dfs(G,next_v);
  }
  return ans;
}

int main(){
  int maxans=0;
  int n,m;
  cin>>n>>m;
  seen.assign(n,false);
  vector<vector<int>> G(n);
  rep(i,m){
    int a,b;
    
    cin>>a>>b;
    a--;b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  rep(i,n){
    ans = 0;
    if(seen.at(i)) continue;
    int sub_ans=dfs(G,i);
    //cout<<"(i,sub_ans) "<<i<<" , "<<sub_ans<<endl;
    maxans=max(maxans,sub_ans);
  }
  cout<<maxans<<endl;
}

Measured memory_bytes: 23432
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<string>
#include<string.h>
#include<limits.h>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#define int long long
using namespace std;

int n;
int MAX;
int a[101];
bool k[101];//false 使わない true 使う
void saiki(int b) {
	if (b == 24||b==n+1) {
		int t = 0;
		for (int i = 1; i <= 23; i++) { if (k[i])t += a[i]; }
		for (int i = 24; i <= n; i++) {
			for (int j = 1; j <= 23; j++) {
				if (i%j == 0 && k[j]) {
					t += a[i];
					k[i] = true;
					break;
				}
				else {
					k[i] = false;
				}
			}
		}
		for (int i = n; i > 23; i--) {
			if (k[i])continue;
			bool OK = true;//自由に使えるか？
			for (int j = i*2; j <= n; j+=i) {
				if (!k[j])OK = false;
			}
			if (OK) {
				if (a[i] >= 0) {
					k[i] = true;
					t += a[i];
				}
			}
			else {
				int o = 0;
				if (a[i] >= 0) {
					for (int j = i; j <= n; j+=i) {
						if(!k[j])o += a[j];
					}
					if (o >= 0) {
						for (int j = i; j <= n; j += i) {
							k[j] = true;
						}
						t += o;
					}
				}
			}
		}
		MAX = max(MAX, t);
		return;
	}
	for (int i = 1; i < b; i++) {
		if (b%i == 0 && k[i]) {
			k[b] = true;
			saiki(b + 1);
			return;
		}
	}
	k[b] = false;
	saiki(b + 1);
	k[b] = true;
	saiki(b + 1);
}
signed main() {
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i + 1];
		sum += a[i + 1];
		a[i + 1] *= -1;
	}
	saiki(1);
	cout << sum + MAX << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; 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 ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i, n) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  rep(b, n) rep(a, b)
  {
    int ab = L[a] + L[b];
    int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
    int l = b + 1;
    // c=[l,r)
    ans += r - l;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
#define ll long long

int main(void){
    ll n, a, b;
    cin >> n >> a >> b;
    ll x[n];
    for(ll i = 0; i < n; i++)   
        cin >> x[i];
    ll ans = 0;
    for(ll i = 0; i < n-1; i++){
        if((x[i+1]-x[i])*a > b)
            ans += b;
        else
            ans+=(x[i+1]-x[i])*a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
//Littleboy123 Template 1.6
#include <bits/stdc++.h>
using namespace std;
 
//pragmas
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
 
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
 
const long double pi = acos(-1.0);
 
#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
 
void init(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
void infile(){
    freopen("input.in", "r", stdin);
}
 
void outfile(){
    freopen("output.out", "w", stdout);
}
 
ll modex(ll a, ll b, ll mod){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = modex(a, b/2, mod);
    tmp = (tmp * tmp) % mod;
    if(b & 1)
        tmp = (tmp * a) % mod;
    return tmp;
}
 
//End of template
 
int main(){
    init();
 
    int a, b;
    cin >> a >> b;
    if(a < 10 && b < 10)
        cout << a*b << endl;
    else
        cout << -1 << endl;
    return 0;   
}

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

int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    vector<int> water;
    for (auto i = 0; i <= f / 100 * a; i++) {
        for (auto j = 0; j <= f / 100 * b; j++) {
            if(i == 0 and j == 0) continue;
            if(i * a * 100 + j * b * 100 > f) continue;
            water.push_back(i * a * 100 + j * b * 100);
        }
    }

    vector<int> sugar;
    for (auto i = 0; i <= f / c; i++) {
        for (auto j = 0; j <= f / d; j++) {
            if(i == 0 and j == 0) continue;
            if(i * c + j * d > f) continue;
            sugar.push_back(i * c + j * d);
        }
    }

    double max = 0.0;
    int ans1 = 0, ans2 = 0;
    for (int i : water) {
        for (int j : sugar) {
            if((double)j / e * 100 > i) continue;
            if(i + j <= f) {
                if((double)100.0 * j / (i + j) > max){
                    max = (double)100.0 * j / (i + j);
                    ans1 = i + j;
                    ans2 = j;
                }
            }
        }
    }

    if(max == 0.0) ans1 = a * 100;
    cout << ans1 << " " << ans2 << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int N,K;
	cin>>N>>K;
	if(N%K==0)cout<<0;
	else cout<<1;
}

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

#define N (200)

using namespace std;

typedef long long int Int;
typedef pair<int,int> P;

Int cost[N+10][N+10];

int main(void)
{
    int n,m,r;
    vector<Int> city;
    cin>>n>>m>>r;

    for(int i = 0;i < N+10;i++)
	for(int j = 0;j < N+10;j++)
	    cost[i][j] = 1e9;

    for(int i = 1;i <= n;i++)
	cost[i][i] = 0;

    for(int i = 0;i < r;i++)
    {
	Int temp;
	cin>>temp;
	city.push_back(temp);
    }

    sort(city.begin(),city.end());
    
    for(int i = 0;i < m;i++)
    {
	int a,b,c;
	cin>>a>>b>>c;
	cost[a][b]=cost[b][a] = c;
    }

    for(int i = 1;i <= n;i++)
	for(int j = 1;j <= n;j++)
	    for(int k = 1;k <= n;k++)
		cost[j][k] = min(cost[j][k],cost[j][i]+cost[i][k]);

    Int ans = 1e9;
    do
    {
	Int c = 0;
	for(int i = 0;i < r-1;i++)
	    c += cost[city[i]][city[i+1]];

	ans = min(ans,c);

    }while(next_permutation(city.begin(),city.end()));

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int s,n,v[20],x[20][20],y[20][20];
int sol(int x)
{
    if(x==0) return 0;
    return sol(x/2)+(x%2);
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        for(int j=1;j<=v[i];j++)
            cin>>x[i][j]>>y[i][j];
    }
    for(int k=1;k<(1<<n);k++)
    {
        int o=1;
        for(int i=1;i<=n;i++)
            if(k&(1<<(i-1)))
                for(int j=1;j<=v[i];j++)
                    if(((k&(1<<(x[i][j]-1)))>0)^y[i][j]) o=0;
        if(o) s=max(s,sol(k));
    }
    cout<<s;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

const ll mod = 998244353;

const ll INF = 1e15;

template<typename T>
void cmpmax(T & reference, T value) {
	reference = max(reference, value);
}

template<typename T>
void cmpmin(T& reference, T value) {
	reference = min(reference, value);
}

int main() {
	ll n, w;
	cin >> n >> w;
	vector<P> as(n);
	rep(i, n) {
		cin >> as[i].first >> as[i].second;
	}
	vector<ll> dp(w+1, 0);
	rep(i, n) {
		for (int j = w; j >= as[i].first; j--) {
			cmpmax(dp[j], dp[j - as[i].first] + as[i].second);
		}
	}
	cout << dp[w] << endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import deque

n,q = tuple([int(i) for i in input().split()])
lines = [input().split() for i in range(n)]
pro = deque([[i[0], int(i[1])] for i in lines])
time = 0

while True:
    left = pro.popleft()

    if left[1] - q > 0:
        time += q
        pro.append([left[0], left[1] - q])
    else:
        time += left[1]
        print(' '.join([left[0], str(time)]))

    if len(pro) == 0:
        break;

Measured memory_bytes: 25196
N = int(input())
if(N in [1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,30,32,35,36,40,42,45,48,49,54,56,63,64,72,81]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>

using namespace std;

int main(){
  int N;
  vector<int> W;
  int w;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> w;
    W.push_back(w);
  }
  int ans = 100000000;
  for(int t=0; t<N; t++){
    int l=0;
    int r=0;
    for(int i=0; i<N; i++){
      if(i<t) l += W[i];
      else r += W[i];
    }
    ans = min(ans, abs(l-r));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#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,ans=0;
    cin>>n;
    vector<int> A(n);
    map<int,int> num;
    rep(i,n) cin>>A[i],num[A[i]]++;
    sort(A.begin(),A.end(),greater<int>());
    rep(i,A.size()){
        num[A[i]]--;
        if(num[A[i]]<0) continue;
        int a=pow(2,int(log2(A[i]))+1)-A[i];
        if(num[a]>0) ans++,num[a]--;
    }
    cout<<ans;
}

Measured memory_bytes: 19712
#include<iostream>

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2], R[MAX / 2 + 2] ,A[MAX];

llong merge(int A[], int n, int left, int mid, int right) {
  int i, j, k;
  llong cnt = 0;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++) L[i] = A[left + i];
  for ( i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
      cnt += n1 - i;
    }
  }
  return cnt;
}

llong mergeSort(int A[], int n, int left, int right) {
  int mid;
  llong v1, v2, v3;
  if (left + 1 < right) {
    mid = (left + right) / 2;
    v1 = mergeSort(A, n, left, mid);
    v2 = mergeSort(A, n ,mid, right);
    v3 = merge(A, n, left, mid, right);
    return v1+v2+v3;
  } else return 0;
}

int main() {
  int n, i;

  std::cin >> n;
  for ( i = 0; i < n; i++) {
    std::cin >> A[i];
  }

  llong ans = mergeSort(A, n, 0, n);
  std::cout << ans << '\n';

  return 0;
}



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



int main(){
    int n; cin >> n;
    vector<long long > L(87);
    L[0] = 2; L[1] = 1;
    for(int i = 2; i <= n; ++i){
        L[i] = L[i-1] + L[i-2];
    }

    cout << L[n] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[3001],b,c,d,n,m,p,q,x,y,k,h,w,sum,mi,ma,ans,l,r,res;
string s;
typedef vector<int> VI;
typedef vector<pair<int,int> > VP;

int main(){
    cin>>n;
    rep(i,n){cin>>x;sum+=x-1;}
    p(sum);
    return 0;
}


Measured memory_bytes: 256
Cube = [int(i) for i in input().split(" ")]
# 一番長い辺で切れば断面の数は最小
L = max(Cube)
plane = [i for i in Cube if i!=L]
if len(plane)==0:
    A = L
    B = L
elif len(plane)==1:
    A = plane[0]
    B = L
else:
    A,B = map(int,plane)
print(abs((A*B*(L//2))-(A*B*(L-(L//2)))))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

#include <boost/multiprecision/cpp_int.hpp>
using Z = boost::multiprecision::cpp_int;

template<typename T> using LPQ = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using GPQ = priority_queue<T, vector<T>,    less<T>>;

int main() {
	IN(int, t);
	inc(qq, t) {
		IN(Z, n, a, b, c, d);
		LPQ<pair<Z, Z>> q;
		map<Z, Z> mp;
		auto add = [&](Z s, Z v) {
			if(mp.count(v) == 0 || s < mp[v]) {
				mp[v] = s;
				q.emplace(s, v);
			}
		};
		
		add(0, n);
		until(q.empty()) {
			auto [s, v] = q.top(); q.pop();
			if(v == 1) { break; }
			
			add(s + d * (v - 1), 1);
			
			add(s + d * (    v % 2) + a, v / 2    );
			add(s + d * (2 - v % 2) + a, v / 2 + 1);
			
			add(s + d * (    v % 3) + b, v / 3    );
			add(s + d * (3 - v % 3) + b, v / 3 + 1);
			
			add(s + d * (    v % 5) + c, v / 5    );
			add(s + d * (5 - v % 5) + c, v / 5 + 1);
		}
		OUT(mp[1] + d);
	}
}


Measured memory_bytes: 5616
def sum_xor(n)
  n = n+1
  ret = 0
  ret += 1 if [2, 3].include?(n % 4)
  (1...n.bit_length).each{|i|
    wk = n % (2<<i)
    if wk > 1<<i then
      ret += (1<<i) if (wk - (1<<i)).odd?
    end
  }
  ret
end

A, B = gets.chomp.split(" ").map(&:to_i)

puts sum_xor(B) ^ sum_xor(A-1)


Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    int ans = 0;
    int max = Integer.MIN_VALUE;
    int min = Integer.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      arr[i] = sc.nextInt();
      max = Math.max(max, arr[i]);
      min = Math.min(min, arr[i]);
    }

    System.out.println(sovle(arr, min, max));
    System.out.flush();
    sc.close();
  }

  private static int sovle(int[] arr, int min, int max) {
    int ans = 0;
    Set<Integer> canBeDivided = new HashSet<>();
    for (int i = 0; i < arr.length; i++) {
      int j = 2;
      while ((j * arr[i]) <= max) {
        canBeDivided.add(j * arr[i]);
        j++;
      }
    }
    Set<Integer> allElem = new HashSet<>();
    for (int i = 0; i < arr.length; i++) {
      if (!allElem.contains(arr[i])) {
        allElem.add(arr[i]);
      } else {
        canBeDivided.add(arr[i]);
      }
    }
    for (int i = 0; i < arr.length; i++) {
      if (!canBeDivided.contains(arr[i])) {
        ans++;
      }
    }
    return ans;
  }

  private static int solve(int[] arr) {
    int ans = 0;
    boolean[] checked = new boolean[arr.length];
    Arrays.sort(arr);
    for (int i = arr.length - 1; i >= 0; i--) {
      boolean found = false;
      //      for (int j = 0; j < arr.length && !found; j++) {
      int j = 0;
      while (j < arr.length && arr[j] <= arr[i] && !found) {
        if (i != j && arr[i] % arr[j] == 0) {
          //          System.out.println(arr[i]+" "+arr[j]);
          found = true;
        }
        j++;
      }
      if (!found) {
        ans++;
      }
    }
    return ans;
  }
}


Measured memory_bytes: 135788
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let m: usize = read();
    println!("{}", 24 + (24 - m));
}


Measured memory_bytes: 4352
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		Console.WriteLine(Calc(ReadLine(), ReadLine()) ?? "UNRESTORABLE");
	}
	string Calc(string S, string T)
	{
		int N = S.Length, M = T.Length;
		if (N < M) return null;
		string ans = null;
		for (var i = 0; i <= N - M; i++)
		{
			var flag = true;
			var u = S.Replace('?', 'a').ToArray();
			for (var j = 0; flag && j < M; j++)
			{
				u[i + j] = T[j];
				flag &= S[i + j] == '?' || S[i + j] == T[j];
			}
			if (!flag) continue;
			var U = new string(u);
			//Console.WriteLine(U);
			if (ans == null) ans = U;
			else if (ans.CompareTo(U) > 0) ans = U;
		}
		return ans;
	}
}


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

using namespace std;

int absolute(int num){
	return ((num < 0) ? -num : num);
}

int main(){
	int n;
	cin >> n;
	int h[n];
	for (int i = 0; i < n; i++){
		cin >> h[i];
	}
	int dp[n];
	dp[0] = 0;
	dp[1] = absolute(h[0] - h[1]);
	for (int i = 2; i < n; i++){
		dp[i] = min(dp[i-1] + absolute(h[i] - h[i-1]), dp[i-2] + absolute(h[i] - h[i-2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1024
import bisect as bs
def prime(m):
  N = range(1,m+1, 2)
  N[0] = 2
  for i in range(1, len(N)):
    x = N[i]
    if x: N[i+x::x] = [0]*len(N[i+x::x])
  return filter(None, N)
 
P = prime(10000)
x = []
a = P[0]
x = [a for a,b in zip(P[1:],P[:-1]) if a-b==2]
while 1:
  n = int(raw_input())
  if n==0: break
  a = x[bs.bisect_right(x, n)-1]
  print a-2, a

Measured memory_bytes: 4600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;


long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


int main() {
    int n;
    cin >> n;
    vector<int> num(n);
    for (int i = 0; i < n; i++) num[i] = i + 1;
    vector<int> P(n);
    vector<int> Q(n);
    for (int i = 0; i < n; i++) cin >> P[i];
    for (int i = 0; i < n; i++) cin >> Q[i];
    int countP, countQ, cnt = 0;
    do {
        cnt++;
        if (P == num) countP = cnt;
        if (Q == num)countQ = cnt;
    } while (next_permutation(num.begin(), num.end()));
    cout << abs(countP - countQ) << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};

int main() {
  ll N;
  cin >> N;
  int a[N];
  REP(i, N) cin >> a[i];
  int b[N] = {};
  int M = 0;
  for (int i = N; i >= 1; i--) {
    int count = 0;
    for (int j = N / i; j >= 1; j--) {
      if (j >= 2 && b[i * j - 1] == 1) {
        count++;
        continue;
      }
      if (j == 1) b[i - 1] = (a[i - 1] + count) % 2;
    }
  }
  REP(i, N) M += b[i];
  cout << M << '\n';
  int k = 0;
  REP(i, N) {
    if (b[i] == 1) {
      cout << i + 1;
      k++;
      if (k < M) cout << ' ';
      else cout << '\n';
    }
  }
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N,M;

void func(){

	int ans = 0;

	int A,pay = M/N;

	for(int i = 0; i < N; i++){

		scanf("%d",&A);

		ans += min(A,pay);
	}

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

}

int main(){

	while(true){

		scanf("%d %d",&N,&M);

		if(N == 0 && M == 0){
			break;
		}

		func();
	}

	return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000




int main(){
    
	int N;
	cin>>N;
	
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==N){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	
	cout<<"No"<<endl;
	
    return 0;
}



Measured memory_bytes: 256
import math

N = int(input())

XY = [list(map(int, input().split())) for _ in range(N)]
X = [i[0] for i in XY]
Y = [i[1] for i in XY]

WS = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    for j in range(N):
        WS[i][j] = math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2)

result = 0.0

for s in range(0, N-1):
    for d in range(s+1,N):
        result += WS[s][d]

print(2*result/(N))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int main()
{
    int k,s,ans;
    cin >> k >> s;
    
    for(int i = 0; i <= k; i++)
    {
        
        for(int j = 0; j <= k; j++)
        {
            
            if(s-i-j <= k && s-i-j >=0)ans++;
            
        } 
        
    }
    cout << ans <<endl;
    
    return 0;
}


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

int main() {
  int n;
  vector<string> key;
  map<string, int> m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string tmp_s;
    int tmp_i;
    cin >> tmp_s >> tmp_i;
    if (m.count(tmp_s) == 0) {
      m[tmp_s] = tmp_i;
      key.push_back(tmp_s);
    } else {
      m[tmp_s] += tmp_i;
    }
  }
  sort(key.begin(), key.end(), [](string a, string b) {
    return (a.length() == b.length()) ? (a < b) : (a.length() < b.length());
  });
  for (auto& v : key) {
    cout << v << " " << m[v] << endl;
  }

  return 0;
}



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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

string s;
int main(){
  cin >> s;
  map<char, int>mp;
  for(int i = 0; i < 4; i++){
    mp[s[i]]++;
  }
  string ans = "Yes";
  for(int i = 0; i < 4; i++){
    if(mp[s[i]] != 2)ans = "No";
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 8
#define F -1
#define NOF 1

int row[N],c[N],dpos[2*N-1],dneg[2*N-1],T[N][N];

void tofree(){
  int i,j;
  for(i=0;i<N;i++) for(j=0;j<N;j++) T[i][j]=0;
  for(i=0;i<N;i++)row[i]=c[i]=F;
  for(i=0;i<2*N-1;i++)dpos[i]=dneg[i]=F;
}

void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(T[i][j]==1){
	if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void put(int i){
  int j;
  if(i==N){
    print();
    return;
  }
  for(j=0;j<N;j++){
    if(c[j]==NOF || dpos[i+j]==NOF || dneg[i-j+N-1]==NOF)continue;
    row[i]=j;
    c[j]=dpos[i+j]=dneg[i-j+N-1]=NOF;
    put(i+1);
    c[j]=dpos[i+j]=dneg[i-j+N-1]=F;
  }
}

int main(){
  int i,j,n,m,v;
  tofree();

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&m,&v);
    T[m][v]=1;
  }
  put(0);
  return 0;
}


Measured memory_bytes: 2112
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val ss = mutableListOf<Int>()
    
    for (i in 1..N) {
        ss.add(readInputLine().toInt())
    }
    
    ss.sort()
    
    val sum = ss.sum()
    
    if (sum % 10 != 0) {
        println(sum)
        return
    }
    
    for (s in ss) {
        if (s % 10 != 0) {
            println(sum - s)
            return
        }
    }
    
    println(0)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 33652
#include <stdio.h>

int main(){
	int a,n,i,m;
	scanf("%d",&n);
	scanf("%d",&a);
	m = n/500;
	for (i=0;i<m;i++) {
		n = n - 500;
	}
	if (a >= n){
		printf("Yes");
	} else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
x = int(input())

if x <= 3:
  print(x)
  exit()

ans = 0
for i in range(2, int(x**0.5)+1):
  s = i
  t = 1
  while s < x:
    t += 1
    s = i**t
    if ans < s and s <= x: ans = s
print(ans)

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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;

  int tmp, x_max = -100, y_min = 100;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    x_max = max(tmp, x_max);
  }
  for (int i = 0; i < M; i++) {
    cin >> tmp;
    y_min = min(tmp, y_min);
  }

  if (x_max < y_min && x_max >= X && y_min <= Y)
    cout << "No War" << endl;
  else
    cout << "War" << endl;
  return 0;
}

Measured memory_bytes: 888
import sys
readline = sys.stdin.readline

from bisect import bisect_left

sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    As = list(map(int, input().split()))

    edges = (map(int, readline().strip().split()) for _ in range(N-1))

    tree = [[] for _ in range(N)]
    for u, v in edges:
        tree[u-1].append(v-1)
        tree[v-1].append(u-1)

    inf = 10 ** 12
    dp = [inf] * (N+1)
    ans = [0] * N

    def dfs(node, parent):
        v = As[node]
        lb = bisect_left(dp, v)
        old = dp[lb]
        dp[lb] = v
        ans[node] = bisect_left(dp, inf)
        for child in tree[node]:
            if child == parent:
                continue
            dfs(child, node)
        dp[lb] = old

    dfs(0, 0)

    for k in range(N):
        print(ans[k])


if __name__ == "__main__":
    main()


Measured memory_bytes: 283820
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,i,mx,r[200001],sum[200001],x;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	scanf("%d",&r[i]);
	x=r[n];
	mx=-2100000000;
	for(i=n-1;i>0;i--)	{
		x=max(x,r[i+1]);
		mx=max(mx,x-r[i]);
	}
	printf("%d\n",mx);
	return 0;
}


Measured memory_bytes: 3504
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[]:
        arr.append([n, 1])
 
    return arr
 
n = int(input())
if n==1:
  print(0)
else:
  arr = factorization(n)
  trial_list = []
  for p in arr:
    i = p[0]
    j = p[1]
    for k in range(1,j+1):
      trial_list.append(i**k)
  sorted(trial_list)
  cnt=0
  for i in trial_list:
    if n%i==0:
      cnt+=1
      n//=i
  print(cnt)

Measured memory_bytes: 9516
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30

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

int H,W;
char masu[400][400];
bool visited[400][400];
ll black = 0LL, white = 0LL;

ll dfs(int i, int j, bool was_black){


    if((was_black && masu[i][j]=='.') || (!was_black && masu[i][j]=='#')){
            visited[i][j] = true;
    }

    if(was_black && masu[i][j] == '.'){
        white++;
        REP(k,4){
            if(i+dx[k]>=0 && i+dx[k]<H && j+dy[k]>=0 && j+dy[k]<W && !visited[i+dx[k]][j+dy[k]]){
                dfs(i+dx[k], j+dy[k], false);
            }
        }
    } else if(!was_black && masu[i][j] == '#'){
        black++;
        REP(k,4){
            if(i+dx[k]>=0 && i+dx[k]<H && j+dy[k]>=0 && j+dy[k]<W && !visited[i+dx[k]][j+dy[k]]){
                dfs(i+dx[k], j+dy[k], true);
            }
        }
    }
    return black*white;
}

int main(){
    std::ios_base::sync_with_stdio(false);
    cin >> H >> W;

    REP(i,H){
        string s; cin >> s;
        REP(j,s.length()){
            masu[i][j] = s[j];
            visited[i][j] = false;
        }
    }
    ll ans = 0LL;

    REP(i,H){
        REP(j,W){
            if(!visited[i][j] && masu[i][j]=='#'){
                ans+=dfs(i, j, false);
                black = 0LL; white = 0LL;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5632
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >>= putStrLn . map toUpper . map head . words


Measured memory_bytes: 380