akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
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

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

K,N = inputIL()
l = inputIL()
l.append(l[0]+K)

dist = []
for i in range(N):
  dist.append(l[i+1]-l[i])

m = max(dist)

print(K-m)


Measured memory_bytes: 106824
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),(OUT(YES),1),(OUT(NO),0))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p998 = 998244353;
const LL p107 = 1000000007;
const LL p = p107;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
LL A[SIZE],B[SIZE],C[SIZE];
LL able(LL x){
	LL ans=0;
	REP(i,N){
		ans+=(A[i]-1)/x;
	}
	return ans<=K;
}
LL solve(){
	cin >>N >>K;
	LL sum=0;
	REP(i,N){
		cin >> A[i];
		sum+=A[i]-1;
	}
	if(sum<=K) return 1;
	LL ok=INF,ng=1;
	while(abs(ok-ng)>1){
		LL f=(ok+ng)/2;
		if(able(f)){
			ok=f;
		}else{
			ng=f;
		}
	}
	return ok;
	return NONE;
}
 signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	LL T=1;

	REP(i,T){
		DEFAULT;
	}
	
//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;
 
}


Measured memory_bytes: 16852
str = input()
q = int(input())

for i in range(q):
    x, a, b, *p = input().split()
    a = int(a)
    b = int(b)

    if x == 'replace':
        str = str[:a]+p[0] +str[b+1:]

    elif x == 'reverse':
        tmp = str[a:b+1]
        str = str[:a]+tmp[::-1]+str[b+1:]

    elif x == 'print':
        print(str[a:b+1])


Measured memory_bytes: 5616
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left
import random
from itertools import permutations, accumulate, combinations
import sys
import string


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 10 ** 9 + 7


n, c = LI()
L = [0] * (10 ** 5 + 2)
each_channel = [[] for _ in range(c)]
for s, t, k in LIR(n):
    each_channel[k - 1] += [(s, t)]



for i in each_channel:
    i.sort()


for i in range(c):
    pre_t = -1
    for j in range(len(each_channel[i])):
        s, t = each_channel[i][j]
        if j >= 1 and pre_t == s:
            L[pre_t + 1] += 1
            L[t + 1] -= 1
        else:
            L[s] += 1
            L[t + 1] -= 1
        pre_t = t


print(max(accumulate(L)))


Measured memory_bytes: 65628
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int f = sc.nextInt();

        int waterX = 0;
        int ansWater = 100;
        int ansSugar = 0;
        while (100 * a * waterX <= f) {
            int waterY = 0;
            while (100 * a * waterX + 100 * b * waterY <= f) {
                int water = 100 * a * waterX + 100 * b * waterY;
                int sugarX = 0;
                while (water + c * sugarX <= f) {
                    int sugarY = 0;
                    while (water + c * sugarX + d * sugarY <= f) {
                        int sugar = c * sugarX + d * sugarY;
                        if (sugar * (100 + e) <= e * (water + sugar)) {
                            if (sugar * (ansWater + ansSugar) >= ansSugar * (water + sugar)) {
                                ansWater = water;
                                ansSugar = sugar;
                            }
                        }
                        sugarY++;
                    }
                    sugarX++;
                }
                waterY++;
            }
            waterX++;
        }

        System.out.println(ansWater + ansSugar + " " + ansSugar);
    }
}


Measured memory_bytes: 23124
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            String word = sc.nextLine();
            if(word.equals(".")){
                break;
            }
            word = word.replaceAll("[a-zA-Z. ¥]","");
            while(!word.equals("")){
                String s =new String(word);
                word = word.replaceAll("\\(\\)|\\[\\]","");
                if(s.equals(word)){
                    break;
                }
            }
            if(word.equals("")){
                System.out.println("yes");
            }else{
                System.out.println("no");
            }
        }
    }
}


Measured memory_bytes: 68056
n=int(input())
d=n%10
c=(n//10)%10
b=(n//100)%10
a=n//1000

for i in range(8):
    k=[1,1,1]
    for j in range(3):
        if ((i>>j)&1):
            k[j]=-1
    if a+k[0]*b+k[1]*c+k[2]*d==7:
        for j in range(3):
            if k[j]==1:
                k[j]="+"
            else:
                k[j]="-"
        print(str(a)+k[0]+str(b)+k[1]+str(c)+k[2]+str(d)+"=7")
        break


Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    ll n = s.size();
    vector<vector<ll>> dp(2, vector<ll>(2019,0));
    ll res = 0;
    rep(i,n) {
        ll pls = s[i] - '0';
        rep(j,2019) {
            dp[(i+1)%2][(j*10+pls) % 2019] = dp[i%2][j];
        }
        dp[(i+1)%2][pls]++;
        res += dp[(i+1)%2][0];
    }
    // repr(i,1,n+1) {
    //     res += dp[i][0];
    // }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3740
import java.util.Scanner;

class Main{
	static int N;
	static int K;

	static int[] h;

	static int[] memo;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		N = sc.nextInt();
		K = sc.nextInt();

		h = new int[N];
		memo = new int[N];
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
			memo[i] = -1;
		}

		int ans = dp(N - 1);

		System.out.println(ans);
		sc.close();
	}

	static int dp(int i) {
		if(i == 0)
			return 0;
		if(memo[i] == -1) {
			int min = Integer.MAX_VALUE;
			for(int k = 1; k <= K; k++) {
				if(i >= k) {
					int jump = dp(i - k) + Math.abs(h[i] - h[i - k]);
					if(min > jump) {
						min = jump;
					}
				}
			}
			memo[i] = min;
		}
		return memo[i];
	}
}

Measured memory_bytes: 68056
//author : raghav_0901
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
//#define int long long int
#define f(i,s,e) for(i=s;i<e;++i)
#define fr(i,s,e) for(i=s;i>=e;i--)
#define all(x) (x).begin(),(x).end()
#define all_r(x) (x).rbegin(),(x).rend()
#define _in(v) for(auto &x:v) cin>>x;
#define ffr(i,s,e,f) for(i=s;i>=e && f;i--)
#define ff(i,s,e,f) for(i=s;i<e && f;++i)
#define mem(arr,val) memset(arr, val, sizeof(arr));
#define _out(v) for(auto x:v) cout<<x<<' '; cout<<'\n';
#define ARENA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
 
const int lim = 1000000;
const int mod = 1e9;

typedef vector<double> vec;
typedef pair<int,int> pr;

//-----------------------------------------functions---------------------------------------------------------------------------------
int gcd(int a,int b) { return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
inline int n_sum(int n){return (n*(n+1))/2;}
int power(int a,int b){int res=1;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
int powmod(int a,int b){int res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcdExtended(int a,int b,int &x,int &y){if(a==0){x=0;y=1;return b;}int x1,y1,gcd=gcdExtended(b%a,a,x1,y1);x=y1-((b/a)*x1);y=x1;return gcd;}
int modInv(int a,int m){int x,y;gcdExtended(a,m,x,y);return (x%m + m)%m;}
int divM(int a,int b){return (modInv(b,mod)*(a%mod))%mod;}
//------------------------------------------------------------------------------------------------------------------------------------


void _main(void)
{
    int i,num,n,m;cin>>n>>m;
    f(i,0,m)
    {
        cin>>num;n-=num;
    }
    cout<<max(-1,n)<<endl;
    return;
} 

signed main(void)
{
    ARENA
    int t=1,i;//cin>>t;
    f(i,1,t+1)
    {
        //cout<<"Case #"<<i<<": ";
        _main();
    }
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  string s;
  cin >> s;
  string r_s = s;
  reverse(r_s.begin(), r_s.end());
  
  int l = s.size();

  int n1 = (l-1)/2;
  string f1 = s.substr(0, n1);
  string r_f1 = f1;
  reverse(r_f1.begin(), r_f1.end());

  int n2 = (l+3)/2-1;
  string f2 = s.substr(n2);
  string r_f2 = f2;
  reverse(r_f2.begin(), r_f2.end());
  
  string result = "No";
  if (s == r_s && f1 == r_f1 && f2 == r_f2) result = "Yes";
  cout << result << endl;

  return 0;
}

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

using namespace std;

#define EPS 1e-10

struct Point{
    double x,y;

    Point(){}
    Point(double x,double y) : x(x),y(y) {}
    Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
    Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
    Point operator * (const double &k)const{ return Point(x*k,y*k); }
};

double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double norm(const Point &p){ return dot(p,p); }

#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
typedef Point Vector;

int ccw(Point p0,Point p1,Point p2){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if(cross(a,b) > EPS) return COUNTER_CLOCKWISE;
    if(cross(a,b) < -EPS) return CLOCKWISE;
    if(dot(a,b) < -EPS) return ONLINE_BACK;
    if(norm(a) < norm(b)) return ONLINE_FRONT;
    return ON_SEGMENT;
}

bool sortY(Point p1,Point p2){
    if(p1.y != p2.y){
        return (p1.y - p2.y < -EPS);
    }else{ 
        return (p1.x - p2.x < -EPS);
    }
}

#define prev(G,i) (G[(i-1+G.size())%G.size()])
#define curr(G,i) (G[i%G.size()])
#define next(G,i) (G[(i+1)%G.size()])

typedef vector<Point> Polygon;

Polygon convex_hull(Polygon &ps){
    int N = ps.size(),j = 0;
    Polygon pg(N*2);
    sort(ps.begin(),ps.end(),sortY);
    for(int i = 0 ; i < N ; i++,j++){
        while(j >= 2 && ccw(pg[j-2],pg[j-1],ps[i]) == -1){
            j--;
        }
        pg[j] = ps[i];
    }
    int k = j+1;
    for(int i = N-2 ; i >= 0 ; i--,j++){
        while(j >= k && ccw(pg[j-2],pg[j-1],ps[i]) == -1){
            j--;
        }
        pg[j] = ps[i];
    }
    pg.resize(j-1);
    return pg;
}

int main(){
    int N;
    cin >> N;
    Polygon pg(N);
    for(int i = 0 ; i < N ; i++){
        cin >> pg[i].x >> pg[i].y;
    }
    pg = convex_hull(pg);
    N = pg.size();
    cout << N << endl;
    for(int i = 0 ; i < N ; i++){
        cout << pg[i].x << " " << pg[i].y << endl;
    }
    return 0;
}

Measured memory_bytes: 5688
n = int(input())

dp = [[0]*3 for i in range(n)]
a,b,c = map(int,input().split())
dp[0] = [a,b,c]
for i in range(1,n):
    a,b,c = map(int,input().split())
    dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a
    dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b
    dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c

print(max(dp[-1]))

Measured memory_bytes: 60268
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
#include<stdio.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

bool prime[1000010];

void furui() {
	prime[0]=true;
	prime[1]=true;
	int i = 2;
	while (i <= 1000000) {
		int j = 2;
		while (j <= sqrt(i) && !prime[i]) {
			if (i%j == 0) {
				prime[i] = true;
				break;
			}
			else j++;
		}
		int z = 2;
		while (!prime[i]) {
			if (i*z <= 1000000) {
				prime[i*z] = true;
				z++;
			}
			else break;
		}
		i++;
	}
}

int main(void){
	furui();
	int n,a,d;
	while(true){
		cin>>a>>d>>n;
		if(a==0 &&d==0&&n==0)break;
		ll index=0;
		while(index<=n){
			if(!prime[a]){
				index++;
				if(index==n){
					cout<<a<<endl;
					break;
				}
				a+=d;
			}
			else a+=d;
		}
	}
    return 0;
}


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

typedef long long s64;

const int MaxN = 100000;
const int MaxTN = 2154;

const int L = 100000;

int n;
s64 a[MaxN][3];

map<s64, int> tab;

int pri_n, pri[MaxTN];
bool book[MaxTN + 1];

int pro[MaxTN][3];

int res = 0;
bool used[MaxN];

inline void init_sieve(int n = MaxTN)
{
	for (int i = 2; i <= n; ++i)
	{
		if (!book[i])
		{
			pro[pri_n][0] = 1;
			pro[pri_n][1] = i;
			pro[pri_n][2] = i * i;
			pri[pri_n++] = i;
		}

		for (int j = 0; j < pri_n; ++j)
		{
			int p = pri[j], d = i * p;
			if (d > n)
				break;
			book[d] = true;

			if (i % p == 0)
				break;
		}
	}
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	init_sieve();

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		scanf("%lld", &a[i][0]);

		s64 now = a[i][0];
		s64 simp = 1, anti = 1;
		for (int k = 0; k < pri_n; ++k)
			if (now % pri[k] == 0)
			{
				int d = 0;
				while (now % pri[k] == 0)
					now /= pri[k], ++d;
				d %= 3;

				simp *= pro[k][d];
				anti *= pro[k][(3 - d) % 3];
			}

		simp *= now;

		s64 v = (s64)sqrt(now);
		if (v * v == now)
			anti *= v;
		else
		{
			if (now > L)
			{
				res += (used[i] = true);
				continue;
			}

			anti *= now * now;
		}

		++tab[simp];
		a[i][1] = simp;
		a[i][2] = anti;
	}

	int cnt = 0;
	for (int i = 0; i < n; ++i)
		if (!used[i])
		{
			s64 u = a[i][1], x = tab[u];
			s64 v = a[i][2], y = tab[v];
			res += x > y || (x == y && u < v);
			cnt += u == 1 && v == 1;
		}

	cout << res + (cnt > 0) << endl;

	fclose(stdin);
	fclose(stdout);
	return 0;
}

Measured memory_bytes: 12928
package main
import (
  "fmt"
)
func getNextIndices(hIndex, wIndex, h, w int)(int, int) {
  if hIndex%2 == 0 {
    if wIndex == w-1 {
      return hIndex+1, wIndex
    } else {
      return hIndex, wIndex+1
    }
  } else {
    if wIndex == 0 {
      return hIndex+1, wIndex
    } else {
      return hIndex, wIndex-1
    }
  }
}
func main() {
  var h, w, n int
  fmt.Scan(&h, &w, &n)
  as := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&as[i])
  }
  hws := make([][]int, h)
  for i := 0; i < h; i++ {
    hws[i] = make([]int, w)
  }
  hIndex := 0
  wIndex := 0
  for i, a := range as {
    for j := 0; j < a; j++ {
      hws[hIndex][wIndex] = i+1
      hIndex, wIndex = getNextIndices(hIndex, wIndex, h, w)
    }
  }
  for _, hw := range hws {
    for i, num := range hw {
      if i == len(hw)-1 {
        fmt.Println(num)
      } else {
        fmt.Printf("%d ", num)    
      }
    }
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >>N >>M;
  vector<int> A(M);

  for(int i=0; i<M; i++){
    cin >> A.at(i);
  }

  int needDays =0;

  for(int i=0;i<M;i++){
    needDays += A.at(i);
  }

  if(needDays <=N){
    cout << N - needDays <<endl;
  }
  else{
    cout << -1 << endl;
  }
}

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

using namespace std;
#define pb push_back

const long long mod = 1e9 + 7;

long long n, k, dp[100005], ans;
vector<long long> divisor;

long long BinPow(long long m, long long t){
    if(t == 0)
        return 1;
    else if(t == 1)
        return m % mod;
    else{
        long long sum = BinPow(m, t / 2);
        sum *= sum; sum %= mod;
        if(t % 2 == 1){
            sum *= m;
            sum %= mod;
        }
        return sum % mod;
    }
}

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> k;
    for(long long i = 1; i <= sqrt(n); i++){
        if(n % i == 0){
            divisor.pb(i);
            if(i != n / i)
                divisor.pb(n / i);
        }
    }
    sort(divisor.begin(), divisor.end());
    for(int i = 0; i < divisor.size(); i++){
        dp[i] = BinPow(k, (divisor[i] + 1) / 2);
        for(int j = 0; j < i; j++){
            if(divisor[i] % divisor[j] == 0){
            //cout << dp[i] << " " << dp[j] << " " << i << " " << j << "\n";
                dp[i] = dp[i] - dp[j];
                dp[i] %= mod;
            }
        }
        dp[i] = (dp[i] % mod + mod) % mod;
        long long times = divisor[i];
        if(times % 2 == 0)
            times /= 2;
        ans += (times * dp[i]) % mod;
        ans %= mod;
    }
    cout << ans % mod << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=13)
    {
        cout<<b<<endl;
    }
    else if(a>=6 && a<=12)
    {
        cout<<b/2<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  long int i,n;
  cin>>n;
  long int a[1000000];
    for(long int j=1;j<1000000;j++)
    {
        a[j]=j;
    }
    long int sum;
    sum=0;
  for(i=1;i<=n;i++)
  {
    if (a[i]%15!=0 and a[i]%5!=0 and a[i]%3!=0)
    {
      sum=sum+a[i];
    }
  }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 11400
// ayy
// ' lamo
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld; //CARE
typedef complex<ld> pt;
#define fi first
#define se second
#define pb push_back
const ld eps=1e-8;
const int inf=1e9+99;
const ll linf=1e18+99;
const int P=1e9+7;






const int N=100<<10;

int n,m;
vector<int> adj[N];
int c[N];

bool dfs(int u,int p=-1,int _c=1) {
	if(c[u]) {
		return c[u]==_c;
	}
	c[u]=_c;
	for(int v:adj[u]) if(v!=p) if(!dfs(v,u,3-_c)) return 0;
	return 1;
}


int32_t main() {
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++) {
		int u,v; scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);
	}
	int s=(int)dfs(1);
	if(s) s=accumulate(c+1,c+n+1,0)-n;
	else s=-1;

	if(~s) printf("%lld\n",1LL*s*(n-s)-m);
	else printf("%lld\n",1LL*n*(n-1)/2-m);
}













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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1000000000;

int main(){
   int N,M,C;
   cin >> N >> M >> C;
   int B[M];
   rep(i,M){
      cin >> B[i];
   }
   int A[N][M];
   rep(i,N){
      rep(j,M){
         cin >> A[i][j];
      }
   }
   int sum = 0;
   int ans = 0;
   rep(i,N){
      sum = 0;
      rep(j,M){
         sum += A[i][j]*B[j];
      }
      sum += C;
      if(sum > 0)ans++;
   }
   cout << ans;
   return 0;
}

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

int main() {
  int N, T; cin >> N >> T;
  int t[N], ans;
  for(int i = 0; i < N; i++) cin >> t[i];
  ans = t[0];
  for(int i = 1; i < N; i++) {
    if(T >= t[i] - t[i-1]) {
      ans = ans + (t[i] - t[i-1]);
    } else {
      ans = ans + T;
    }
  }
  ans += T;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
n, k, q = map(int, input().split())
scores = [0] * (n+1)
for i in range(q):
    a = int(input())
    scores[a] += 1
for i in range(1, n+1):
    if k - (q - scores[i]) > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 50904
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, X;
    cin >> N >> X;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    ll ret = 0;
    rep(i, N){
        if(A[i] > X) {
            ret += A[i] - X;
            A[i] = X;
        }
        if(i > 0 && A[i] + A[i - 1] > X){
            ret += A[i] + A[i - 1] - X;
            A[i] = X - A[i - 1];
        }
    }
    output(ret);
    
    return 0;
}

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

using namespace std;

int main(){

    int N,K;

    cin >> N >> K;

    int a[N];

    for(int i = 0;i < N;i++){
    	cin >> a[i];
    }

    sort(a,a+N);

    int ans = 0;

    for(int i = 0;i < K;i++){
    	ans += a[N-1-i];
    }

    cout << ans;

    return 0;

}


Measured memory_bytes: 256
n=int(input())
w=[]
dup=False
for _ in range(n):
    s=input()
    if s in w:
        dup=True
    w.append(s)
if dup:
    print('No')

else:
    last=w[0][0]
    for wi in w:
        if last!=wi[0]:
            print('No')
            break
        last=wi[-1]
    else:
        print('Yes')


Measured memory_bytes: 3060
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let (n, d) = {
        let t: Vec<usize> = read_vec();
        (t[0], t[1])
    };
    let xy: Vec<Vec<i64>> = read_vec2(n);
    println!("{}", xy.into_iter().filter(|v| v[0] * v[0] + v[1] * v[1] <= (d * d) as i64).count());
}

Measured memory_bytes: 12792
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t, d, s;
	cin >> d >> t >> s;
	s = s * t;
	if (s >= d)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}



Measured memory_bytes: 3636
#!/usr/bin/env python3
def main():
    import sys
    import numpy as np

    read = sys.stdin.read

    N, W = map(int, input().split())
    wv = np.array(read().split(), dtype=np.int64)
    w = wv[::2]
    v = wv[1::2]

    dp = np.zeros(W + 1, dtype=np.int64)
    for can_w, can_v in zip(w, v):
        dp[can_w:] = np.maximum(dp[can_w:], dp[:-can_w] + can_v)

    print(dp[-1])


if __name__ == '__main__':
    main()


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

int main() {
	int n,m,i,j,k,ans,cur;
	string s;
	cin >> s;
	if(s[0]==s[1] && s[1]==s[2]){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n, m = [int(x) for x in input().split()]
l = []
for i in range(m):
    tmp = [int(x) for x in input().split()]
    l.append([i, tmp[0], tmp[1]])
l.sort(key=lambda x: x[2])

prefecture = [0 for _ in range(n)]
city = [[] for _ in range(m)]

for info in l:
    i, p, y = info
    tmp = [p, prefecture[p-1]+1]
    prefecture[p-1] += 1
    city[i] = tmp

for x in city:
    p_str = str(x[0])
    c_str = str(x[1])
    p_add = '0'*(6 - len(p_str))
    c_add = '0' * (6 - len(c_str))
    p_str = p_add + p_str
    c_str = c_add + c_str
    print(p_str + c_str)

Measured memory_bytes: 38388
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

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

	set<int> a;
	REP (i, n)
	{
		int x;
		cin >> x;
		a.insert(x);
	}
	
	int mx = *a.rbegin();
	auto it = lower_bound(a.begin(), --a.end(), mx / 2);
	if (*it == mx)
		--it;
	auto it2 = it;
	if (it != a.begin())
		--it2;
	cout << mx << ' ' << (*it + *it2 < mx ? *it : *it2) << 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 a = sc.nextInt();
		int b = sc.nextInt();

		if(a < b) {
			System.out.println("a < b");
		} else if(a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}
}



Measured memory_bytes: 26212
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,a,s=0;
	scanf("%d%d",&n,&m);
	for(int i=1; i<=m; i++)
		scanf("%d",&a),s+=a;
	int ans=n-s;
	printf("%d\n",ans>=0?ans:-1);
    return 0;
}

Measured memory_bytes: 3816
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;
bool sr(ll a, ll b)
{
	return a > b;
}
bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(ll n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	int dis=b-a-1;
	if(dis%2==0){
		cout<<"Borys"<<endl;
	}else{
		cout<<"Alice"<<endl;
	}
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 23 21:12:01 2018

@author: masato
"""

N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.sort()
y.sort()
xmin = x[0]
ymin = y[0]
xmax = x[-1]
ymax = y[-1]

z = max(xmax,ymin)

iswar = 0

for i in range(len(x)):
    if min(ymin,Y) <= x[i]:
        iswar = 1
        break
        
for j in range(len(y)):
    if max(xmax,X) >= y[j]:
        iswar = 1
        break

if iswar == 1:
    print("War")
else:
    print("No War")
        


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n;cin>>n;
    vl a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    ll LCM=a[0];
    rep(i,n){
        LCM=lcm(LCM,a[i]);
    }
    cout<<LCM<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

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

const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
vector<int> g[maxn];
int dp[maxn][2];
bool vis[maxn];

int add(int a, int b) {
    return (a + b) % mod;
}

int mul(int a, int b) {
    return 1LL * a * b % mod;
}

void dfs(int u) {
    // 0: white, 1: black
    if (vis[u]) return;
    vis[u] = true;
    dp[u][0] = dp[u][1] = 1;
    for (int v : g[u]) if (!vis[v]) {
        dfs(v);
        dp[u][0] = mul(dp[u][0], add(dp[v][0], dp[v][1]));
        dp[u][1] = mul(dp[u][1], dp[v][0]);
    }
}

int main() {
    int n;
    scanf("%d", &n);
    int x, y;
    REP(i, n - 1) {
        scanf("%d%d", &x, &y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1);
    int ans = add(dp[1][0], dp[1][1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10752
#include <iostream>
#include <cstdio>
#include <queue>
#define N 55

using namespace std;

char pmap[N][N];
int integer[N][N];

int main()
{
    int H,W;
    scanf("%d %d",&H,&W);
    for(int i=0;i<H;i++)
    {
        scanf("%s",&pmap[i]);
    }
    for(int i =0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            if(pmap[i][j]=='#')
            {
                if(i-1>=0)
                {
                    integer[i-1][j]++;
                }
                if(j-1>=0)
                {
                    integer[i][j-1]++;
                }
                if(i+1<H)
                {
                    integer[i+1][j]++;
                }
                if(j+1<W)
                {
                    integer[i][j+1]++;
                }
                if(i-1>=0&&j-1>=0)
                {
                    integer[i-1][j-1]++;
                }
                if(i+1<H&&j+1<W)
                {
                    integer[i+1][j+1]++;
                }
                if(i+1<H&&j-1>=0)
                {
                    integer[i+1][j-1]++;
                }
                if(i-1>=0&& j+1<W)
                {
                    integer[i-1][j+1]++;
                }
            }
        }
    }
    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            if(pmap[i][j]=='#')
            {
                printf("#");
            }
            else
            {
                printf("%d",integer[i][j]);
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

#define ALNUM 26
static bool alphabets[ALNUM];

int32_t main()
{
  string str;
  cin >> str;

  for (uint32_t i = 0; i < str.size(); i++) {
    alphabets[str[i] - 'a'] = true;
  }

  for (uint32_t i = 0; i < ALNUM; i++) {
    if (!alphabets[i]) {
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }

  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
from operator import itemgetter
import sys

input = sys.stdin.readline

inf = float('inf')

N, Q = map(int, input().split())

es = []
for _ in range(N):
    s, t, x = map(int, input().split())
    es.append((s - x, 1, x))
    es.append((t - x - 0.5, -1, x))

es.sort(key=itemgetter(0))
st = set()
cur_min_stop = inf
check_needed = True

# print(es)
i = 0
for _ in range(Q):
    d = int(input())
    while i < N * 2:
        time, typ, pos = es[i]
        # print(es[i])
        if time > d:
            break
        if typ == 1:
            st.add(pos)
            if pos < cur_min_stop:
                cur_min_stop = pos
        else:
            st.remove(pos)
            if pos == cur_min_stop:
                check_needed = True
        i = i + 1

    if check_needed:
        if st:
            cur_min_stop = min(st)
        else:
            cur_min_stop = inf
        check_needed = False
    print(cur_min_stop if cur_min_stop < inf else -1)


Measured memory_bytes: 125832
#include <iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<map>
#include<queue>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>d;
	vector<int>ans;
	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		d.push_back(p);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			ans.push_back(d[i] * d[j]);
		}
	}
	int g = ans.size();
	int ans2 = 0;
	for (int i = 0; i < g; i++) {
		ans2 += ans[i];
	}
	cout << ans2 << endl;
}

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

int main() {
	int a,b;
	string s;
	cin >> a >> b >> s;
	string k = "Yes";
	for(int i = 0 ;i < s.size() ;i++)
	{
		if(i == a)
		{
			if(s.at(i) != '-')
			{
				k = "No";
				break;
			}
		}
		else
		{
			if(s.at(i) < '0' || s.at(i) > '9')
			{
				k = "No";
				break;
			}
		}
	}
	cout << k << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String[] line = in.nextLine().split(" ");
        final int r = Integer.parseInt(line[0]);
        final int c = Integer.parseInt(line[1]);
        final int K = Integer.parseInt(line[2]);
        final int[][] matrix = new int[r][c];
        for (int i = 0; i < K; i++) {
            line = in.nextLine().split(" ");
            final int row = Integer.parseInt(line[0]);
            final int col = Integer.parseInt(line[1]);
            final int v = Integer.parseInt(line[2]);
            matrix[row - 1][col - 1] = v;
        }
        final long[][][] dp = new long[r][c][4];
        dp[0][0][1] = matrix[0][0];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                for (int k = 0; k < 4; k++) {
                    if (i > 0) { dp[i][j][k] = Math.max(dp[i][j][k], dp[i - 1][j][k]); }
                    if (j > 0) { dp[i][j][k] = Math.max(dp[i][j][k], dp[i][j - 1][k]); }
                    if (i > 0) { dp[i][j][1] = Math.max(dp[i][j][1], dp[i - 1][j][k] + matrix[i][j]); }
                    if (k > 0 && j > 0) {
                        dp[i][j][k] = Math.max(dp[i][j][k], dp[i][j - 1][k - 1] + matrix[i][j]);
                    }
                }
            }
        }
        long res = 0;
        for (long ans : dp[r - 1][c - 1]) {
            res = Math.max(res, ans);
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 672020
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] array = new long[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        long countA = 0;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += array[i];
            if (i % 2 == 0) {
                if (sum <= 0) {
                    countA += sum * (-1) + 1;
                    sum = 1;
                }
            } else {
                if (sum >= 0) {
                    countA += sum + 1;
                    sum = -1;
                }
            }
        }
        
        long countB = 0;
        sum = 0;
        for (int i = 0; i < n; i++) {
            sum += array[i];
            if (i % 2 == 1) {
                if (sum <= 0) {
                    countB += sum * (-1) + 1;
                    sum = 1;
                }
            } else {
                if (sum >= 0) {
                    countB += sum + 1;
                    sum = -1;
                }
            }
        }
        
        System.out.println(Math.min(countA, countB));
    }
}


Measured memory_bytes: 50588
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	ll r1 = 0 ;
	ll sum = 0 ;
	for(int i=0;i<n;i++){
		if(i&1){
			sum += a.at(i) ;
			if(sum>=0){
				r1 += sum+1 ;
				sum = -1 ;
			}
		}else{
			sum += a.at(i) ;
			if(sum<=0){
				r1 += 1-sum ;
				sum = 1 ;
			}
		}
	}
	ll r2 = 0 ;
	sum = 0 ;
	for(int i=0;i<n;i++){
		if((i+1)&1){
			sum += a.at(i) ;
			if(sum>=0){
				r2 += sum+1 ;
				sum = -1 ;
			}
		}else{
			sum += a.at(i) ;
			if(sum<=0){
				r2 += 1-sum ;
				sum = 1 ;
			}
		}
	}
	cout << min(r1,r2) << endl ;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define rev(a,b,c) for(int a=b;a>=c;a--)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define F first
#define S second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define get(a) cin>>a
#define nextl cout<<"\n"
#define deb(x) cout<<#x<<"="<<x<<"\n";
const ll mod = 1000000007;
const ll maxn = 500005;
const ll mm = 1e+18;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
ll ncr(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%mod;
    }
    return C[k];
}
void solve()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) pr("bust");
    else pr("win");
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nextl;
    }
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
  long a,b,r,ans;
  
  cin >> a >> b;
  
  if(a<b){
    swap(a,b);
  }
  
  ans = a*b;
  
  while(b>0){
    r = b;
    b = a % b;
    a = r;
  }
  cout << ans/a << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,m;
   cin>>n>>m;
   int a[n];
   map<int,int>mp;
   mp[0]=1;
   int sum=0;
   int cnt=0;
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
       sum+=a[i];
       int rem=(sum%m);
       cnt+=mp[rem];
       mp[rem]++;
   }
   cout<<cnt<<endl;

}



Measured memory_bytes: 4992