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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define for_each(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = __INT_MAX__;               // 2^31 - 1
const long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    vl va(a);
    vl vb(b);
    rep(i, a) cin >> va[i];
    rep(i, b) cin >> vb[i];

    vector<pair<ll, ll>> xy(n);
    vl c(n);
    rep(i, n) {
        ll x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        xy[i] = make_pair(x, y);
        c[i] = z;
    }

    ll ans = INF;
    rep(i, n) {
        ans = min(ans, va[xy[i].first] + vb[xy[i].second] - c[i]);
    }

    sort(all(va));
    sort(all(vb));
    if (ans > va[0] + vb[0])
        ans = va[0] + vb[0];

    out(ans);

    return 0;
}


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

int main(void){ 
    string S; //1-10文字
    cin >> S;
    
    //
    if(S == "hi")
    {
        cout << "Yes" << endl;
        return 0;
    }
    else if(S == "hihi")
    {
        cout << "Yes" << endl;
        return 0;
    }
    else if(S == "hihihi")
    {
        cout << "Yes" << endl;
        return 0;
    }
    else if(S == "hihihi")
    {
        cout << "Yes" << endl;
        return 0;
    }
    else if(S == "hihihihi")
    {
        cout << "Yes" << endl;
        return 0;
    }
    else if(S == "hihihihihi")
    {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class C
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var cs = Enumerable.Range(0, h[1]).Select(i => new { i, a = read() }).ToArray();

		var q = cs.GroupBy(c => c.a[0]).SelectMany(g => g.OrderBy(c => c.a[1]).Select((c, j) => new { c.i, id = $"{g.Key:D6}{j + 1:D6}" })).OrderBy(c => c.i);
		foreach (var c in q) Console.WriteLine(c.id);
	}
}


Measured memory_bytes: 48068
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int k = sc.nextInt();
		int s[] = new int[n+1];
		
		for(int i=0; i<n; i++) {
			int val = Integer.parseInt(sc.next());
			s[val]++;
		}
		Arrays.sort(s);
		
		int ans = 0;
		int cnt = 0;
		for(int i=n; i>0; i--) {
			ans += s[i];
			cnt++;
			
			if(cnt == k) {
				break;
			}
		}
		System.out.println(n-ans);

	}

}


class FastScanner{
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			if (buflen <= 0) {
				return false;
			}
			
		}
		
		return true;
	}
	
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		
		return sb.toString();
	}
	
	public long nextLong() {
		if(!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		
		while(true) {
			if('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
			throw new NumberFormatException();
		}
		
		return (int)nl;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}	
	
}

Measured memory_bytes: 41472
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] d1 = new int[n];
		int[] d2 = new int[n];
		for (int i = 0; i < n; i++) {
			d1[i] = sc.nextInt();
			d2[i] = sc.nextInt();
		}
		boolean flag = false;
		for(int i=0;i<n-2;i++){
			if(d1[i]==d2[i]&&d1[i+1]==d2[i+1]&&d1[i+2]==d2[i+2]){
				flag=true;
			}
		}
		if(flag){System.out.println("Yes");}
		else{
			System.out.println("No");}
       	}
}

Measured memory_bytes: 36052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int r,d,x;
    cin>>r>>d>>x;
    rep(i,10){
        x=r*x-d;
        cout<<x<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys
import heapq

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, K = inm()
A = inl()
F = inl()
A.sort()
F.sort(reverse=True)


def check(val):
    k = K
    for i in range(N):
        tmp = A[i] * F[i]
        if tmp <= val:
            continue
        dec = ((tmp - val) + F[i] - 1) // F[i]
        assert A[i] >= dec
        assert (A[i] - dec) * F[i] <= val
        k -= dec
        if k < 0:
            return False
    return True


def solve():
    ng, ok = -1, max([A[i] * F[i] for i in range(N)])
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok


print(solve())


Measured memory_bytes: 122264
using System;
using System.Collections.Generic;

class MyClass
{
    static void Main(string[] args)
    {
        int n = 0;
        int i = 1;
        while ((n = int.Parse(Console.ReadLine())) != 0)
        {
            Console.WriteLine("Case {0}: {1}", i, n);
            i++;
        }
    }
}


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

int main() {
  int N, K;
  int x = 1;
  cin >> N >> K;
  
  for (int i = 0; i<N; i++) {
    if (x < K)
      x *= 2;
    else
      x += K;
  }
  
  cout << x << endl;
  
}

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

int main(){
  int n, ans = 0;
  string a, b, c;
  cin >> n;
  cin >> a >> b >> c;
  
  for(int i = 0; i < n; i++){
    if(a[i] == b[i] && b[i] == c[i]){
    }else if(a[i] == b[i] || b[i] == c[i] || a[i] == c[i]){
      ans++;
    }else{
      ans += 2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, ans=0; cin>>n; int a[n]; for(int i=0; i<n; i++) {cin>>a[i]; ans+=a[i];}
	if(ans%10!=0){cout<<ans<<endl; return 0;}
	sort(a, a+n); int i=0;
	while(ans%10==0 && i<n){
		if(a[i]%10!=0){ans-=a[i]; cout<<ans<<endl; return 0;}
		i++;
	}
	cout<<"0\n";
	return 0;
}


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

// calculate |gcd|.
// if  ether num is 0, return 0
long long GCD(long long left, long long right) {
  if(left == 0 || right == 0) return 0;
  if(left < 0) left *= -1;
  if(right < 0) right *= -1;
  if(left < right) swap(left, right);
  long long nextnum, ansgcd = -1;
  while(ansgcd == -1) {
    nextnum = left % right;
    if(nextnum == 0) ansgcd = right;
    left = right;
    right = nextnum;
  }
  return ansgcd;
}

long long LCM(long long left, long long right) {
  return left / GCD(left, right) * right;
}

long long a, b;

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

  cout << LCM(a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;    
const int N = 1e5+6, M = 1e5+5, OO = 0x3f3f3f3f;

int main()
{
    int x;
    char s[150];
    scanf("%d%s",&x, s);
    if(x%2 != 0) printf("No\n");
    else
    {
        for(int i=0,j=x/2; j <x; i++,j++)
        {
            if(s[i]!=s[j]) 
            {
                printf("No\n");
                return 0;
            }
        }
        printf("Yes\n");
    }
    return 0;
}

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

int main () {
  int N;
  cin >> N;
  vector <int> A(N);
  vector <int> B(N);
  vector <int> C(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  for (int i = 0; i < N-1; i++) cin >> C.at(i);
  int ans = 0;
  for (int i = 0; i < N; i++){
    int a = A.at(i)-1;
    ans += B.at(a);
    if (i == 0) continue;
    if (a == A.at(i-1)) ans += C.at(a-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    i64 a,b,k;
    cin>>a>>b>>k;
    i64 tk = a - min(k,a);
    i64 zero = 0;
    i64 ao = max(b - max(k-a,zero) , zero);
    cout<<tk<<" "<<ao<<endl;
    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000

long long int sum(long long int input){
    long long int k = 0;
    while(input > 0) {
        k += input % 10;
        input /= 10;
    }
    return k;
}


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

    long long int N;
    cin >> N;

    long long int temp = 1, temp2 = 1;

    cout << temp << endl;
    for(int i = 0; i < N - 1; i++) {
        if(sum(temp + temp2) * (temp + temp2 * 10) < sum(temp + temp2 * 10) * (temp + temp2)) temp2 *= 10;
        temp += temp2;
        cout << temp << endl;
    }
}


Measured memory_bytes: 256
# A(300)
N, K = map(int, input().split())
A_list = list(map(int, input().split()))


def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x = y
        y = r

    return x

# find LCM
LCM = A_list[0]
for i in range(1, N):
    LCM = gcd(LCM, A_list[i])
    
if K % LCM == 0 and K <= max(A_list):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 14196
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>


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

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

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    int n;cin >> n;
    int pSum=0,sum=0;
    int Max = -1;
    vector<int> a(101),b(101);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];

    vector<int> s(n+1,0);
    rep(i,n) s[i+1] = s[i] + b[i];

    rep(i,n){
        pSum += a[i];
        Max = max(Max,pSum + (s[n]-s[i]));
    }
    cout << Max;


    return 0;
}











Measured memory_bytes: 3604
#include <stdio.h>

int main(void)
{
  int a, b, c, d;

  scanf("%d %d %d", &a, &b, &c);

  if(a <= b){
    if(b <= c){
    } else {
      d = c;
      c = b;
      b = d;
    }
  } else {
     d = b;
     b = a;
     a = d;
     if(b <= c){
    } else {
      d = c;
      c = b;
      b = d;
    }
 }

  if(a <= b){
  } else {
    d = b;
    b = a;
    a = d;
  }

  printf("%d %d %d\n", a, b, c);

  return 0;
}

Measured memory_bytes: 1816
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();
        long[] list = new long[N];
        for (int i = 0; i < N; i++) {
            list[i] = (long)scanner.nextInt();
        }
        long sum = 0;
        for (int i = 0; i < N; i++) {
            sum += list[i]-1;
        }
        System.out.println(sum);
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	int n;cin>>n;
	int s=0,m,p,x;vector<int>t(n);
	rep(i,n){
		cin>>t[i];
		s+=t[i];
	}
	cin>>m;
	rep(i,m){
		cin>>p>>x;
		cout<<s+x-t[p-1]<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
 
using namespace std;
 
typedef pair<int, int> P;
 
const int N = 500;
const int M = 1000000;
 
int n, u, v, m;
P data[2][M];
int tate[2][N], yoko[2][N], naname[2][2], cnt[2];
 
string solve(){
  for(int k=0;k<2;k++){
    cnt[k] = 0;
    naname[k][0] = naname[k][1] = n;
    for(int i=0;i<n;i++){
      tate[k][i] = yoko[k][i] = n;
    }
  }
  bool fin = false;
  string res = "DRAW";
  for(int i=0;i<m;i++){
    int in;
    cin >> in;
    if(fin) continue;
    for(int k=0;k<2;k++){
      int x = data[k][in-1].second, y = data[k][in-1].first;
      if(x == -1 && y == -1) continue;
      tate[k][x]--;
      if(tate[k][x] == 0) cnt[k]++;
      yoko[k][y]--;
      if(n > 1 && yoko[k][y] == 0) cnt[k]++;
      if(x == y){
        naname[k][0]--;
        if(n > 1 && naname[k][0] == 0) cnt[k]++;
      }
      if(x + y == n-1){
        naname[k][1]--;
        if(n > 1 && naname[k][1] == 0) cnt[k]++;
      }
    }
    if(cnt[0] >= u && cnt[1] < v){
      fin = true;
      res = "USAGI";
    }
    if(cnt[0] < u && cnt[1] >= v){
      fin = true;
      res = "NEKO";
    }
  }
  return res;
}
 
int main(){
  while(cin >> n >> u >> v >> m){
    fill(data[0], data[2], P(-1, -1));
    for(int k=0;k<2;k++){
      for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
          int in;
          cin >> in;
          data[k][in-1] = P(i, j);
        }
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

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

double BottomUp(double* a,int n){
	double dp[3001][3001] = {0};
	for(int i=0;i<=n;i++){
		dp[i][0] = 1;
	}
	
	for(int i=1;i<=n;i++){
		for(int head = 0;head<=i;head++){
			if(head == 0){
				dp[i][head] = 1;
			}
			else
				dp[i][head] = a[i]*dp[i-1][head-1] + (1-a[i])*dp[i-1][head];

		}
	}
	return dp[n][(n+1)/2];
}

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

	double *coins = new double[n+1];

	for(int i=1;i<=n;i++){
		cin>>coins[i];
	}

	cout<<fixed<<setprecision(10)<<BottomUp(coins,n)<<endl;
	return 0;
}


Measured memory_bytes: 70656
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {


        static void Main(string[] args)
        {
            checked
            {
                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                Console.SetOut(sw);

                var vals = Console.ReadLine().Split(' ').
                    Select(x => int.Parse(x)).ToList();

                var N = vals[0];
                Console.WriteLine(10 - N / 200);







                Console.Out.Flush();
            }




        }
    }
}




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

const long long w = 1000000000000000000;

int main()
{
	long long n, sum=1;
	vector<long long> a;
	cin >> n;
	int flag = 0;
	for (int i = 0; i < n; i++)
	{
		long long b;
		cin >> b;
		if (b == 0)
		{
			flag = 1;
		}
		a.push_back(b);
	}
	if (flag == 1)
	{
		cout << 0;
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		if (sum > w / a[i])
		{
			cout << -1;
			return 0;
		}
		sum *= a[i];
		if (sum > w)
		{
			cout << -1;
			return 0;
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 4320
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  enum Query : int64_t { kNone_1 = 0, kRevese, kAdd };
  enum SubQuery : int64_t { kNone_2 = 0, kFront, KBack };

  string S;
  int64_t Q;
  cin >> S >> Q;
  list<string> A;
  bool reverted = false;
  const int64_t L = static_cast<int64_t>(S.length());
  for (int64_t i = 0; i < L; ++i) {
    A.push_back(S.substr(i, 1));
  }
  for (int64_t i = 0; i < Q; ++i) {
    int64_t query;
    cin >> query;
    if (query == kRevese) {
      reverted = !reverted;
      // const string temp = A.front();
      // A.front() = A.back();
      // A.back() = temp;
    } else {
      int64_t sub_query;
      string s;
      cin >> sub_query >> s;
      if (!reverted) {
        if (sub_query == kFront) {
          A.push_front(s);
        } else {
          A.push_back(s);
        }
      } else {
        if (sub_query == kFront) {
          A.push_back(s);
        } else {
          A.push_front(s);
        }
      }
    }
  }
  string result = "";
  if (!reverted) {
    for (const string &x : A) {
      result += x;
    }
  } else {
    auto itr = A.end();
    itr--;
    while (true) {
      result += *itr;
      if (itr == A.begin()) {
        break;
      }
      itr--;
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 24532
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a[3], k;
    cin >> a[0] >> a[1] >> a[2] >> k;
    sort(a, a+3);
    for(int i=0; i<k; i++){
        a[2]*=2;
    }
    cout << a[0]+a[1]+a[2] << endl;
    return 0;
}

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

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

  while (true) {
    s = s.substr(0, s.size() - 1);
    if (s.size() % 2 != 0) continue;
    if (s.substr(0, s.size() / 2) == s.substr(s.size() / 2, s.size() / 2)) {
      cout << s.size() << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
const int N=1e5+20,mod=1e9+7;
typedef long long ll;
int n,m,dp[N];
vector<int>adj[N];
void dfs(int u){

    dp[u]=0;
    for(auto v:adj[u]){
        if(dp[v]==-1)
         dfs(v);
        dp[u]=max(dp[u],1+dp[v]);
    }
}
int main()
{
    input();
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v;cin>>u>>v;
        adj[u].push_back(v);
    }
    memset(dp,-1,sizeof dp);
    for(int i=1;i<=n;i++){
        if(dp[i]==-1)dfs(i);
    }
    int mx=0;
    for(int i=1;i<=n;i++)
        mx=max(mx,dp[i]);
    cout<<mx<<endl;




}


Measured memory_bytes: 11316
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    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 ans = 0;
    rep(i,n) {
        int total = c;
        rep(j,m) {
            total += b[j] * a[i][j];
        }
        if (total > 0) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
// z[i] is the length of the longest common prefix between s and the suffix of s starting at i
vector<int> make_z_function(const string& s) {
    vector<int> z(s.length());
    z[0] = s.length();
    for(int i = 1, L = 0, R = 0; i < s.length(); i++) {
        z[i] = i < R ? min(z[i - L], R - i) : 0;
        while(i + z[i] < s.length() and s[i + z[i]] == s[z[i]]) {
            z[i]++;
        }
        if(R < i + z[i]) {
            L = i, R = i + z[i];
        }
    }
    return z;
}
map<char, vector<int>> make_occ(string& S) {
    map<char, vector<int>> occ;
    for(char c = 'a'; c <= 'z'; c++) {
        occ[c] = vector<int>(S.size() + 1);
        for(int i = 1; i <= S.size(); i++) {
            occ[c][i] = S[i - 1] == c;
        }
        partial_sum(occ[c].begin(), occ[c].end(), occ[c].begin());
    }
    return occ;
}
void solve(std::string S, long long l, long long r) {
    bool fibo_type = false;
    string T;
    auto z = make_z_function(S);
    for(int i = S.size() / 2 + 1; i < S.size() and not fibo_type; i++) {
        if(z[i] == S.size() - i) {
            fibo_type = true;
            T = S.substr(0, i);
            T += T;
        }
    }
    auto occ0 = make_occ(S), occ1 = make_occ(T);
    map<pair<ll, char>, ll> memo;
    function<ll(ll, char)> C = [&](ll i, char c) -> ll {
        if(not memo.count({i, c})) {
            ll& ans = memo[{i, c}];
            if(fibo_type) {
                if(i <= S.size()) {
                    ans = occ0[c][i];
                } else {
                    ll f2 = S.size(), f1 = T.size(), c2 = occ0[c][f2], c1 = occ1[c][f1];
                    while(i > f1) {
                        ll f = f1 + f2, c = c1 + c2;
                        f2 = f1, f1 = f, c2 = c1, c1 = c;
                    }
                    ll offset = f2 - f1 / 2;
                    ans = c2 + C(i - f2 + offset, c) - C(offset, c);
                }
            } else {
                ans = i / S.size() * occ0[c][S.size()] + occ0[c][i % S.size()];
            }
        }
        return memo[{i, c}];
    };
    for(char c = 'a'; c <= 'z'; c++) {
        cout << C(r, c) - C(l - 1, c) << " \n"[c == 'z'];
    }
}
int main() {
    std::string S;
    std::cin >> S;
    long long l;
    scanf("%lld",&l);
    long long r;
    scanf("%lld",&r);
    solve(S, l, r);
    return 0;
}


Measured memory_bytes: 63040
#include <stdio.h>

int main(void)
{
	int menu[100],ex[100];
	int sum=0;
	int max=0;
	
	for(int i=0;i<5;i++){
		
		scanf("%d",&(menu[i]));
		
	}
			
		for(int i=0;i<5;i++){
			
			sum=sum+menu[i];
			
		}
		
		for(int i=0;i<5;i++){
			
			if(menu[i]%10==0){
				
				ex[i]=0;
				
			}else{
				
				ex[i]=10-(menu[i]%10);
				
			}
			
			if(max<ex[i]){
				
				max=ex[i];
				
			}
			
			sum=sum+ex[i];
			
		}
		
		printf("%d\n",sum-max);
		
		return 0;
}
		

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>

class Point{
public:
	Point();
	Point(double _x, double _y);
	double x, y;
};

Point::Point() : x(0), y(0){}
Point::Point(double _x, double _y) : x(_x), y(_y){}

class Vector{
	//private:

public:
	Vector();
	Vector(double _x, double _y);
	Vector(Point p1, Point p2);
	double x, y;
};

Vector::Vector() : x(0), y(0){}
Vector::Vector(double _x, double _y) : x(_x), y(_y){}
Vector::Vector(Point p1, Point p2) : x(p1.x-p2.x), y(p1.y-p2.y){}

int extproduct(Vector v1, Vector v2){
	return v1.x*v2.y - v1.y*v2.x;
}

int main(){
	Point ps[4];
	while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &ps[0].x, &ps[0].y, &ps[1].x, &ps[1].y, &ps[2].x, &ps[2].y, &ps[3].x, &ps[3].y)){
		int res = 0;
		for(int i=0;i<4;i++){
			int count = 0;
			Vector vs[4];
			vs[0] = Vector(ps[(i+1)%4], ps[(i+2)%4]);
			vs[1] = Vector(ps[(i+2)%4], ps[(i+3)%4]);
			vs[2] = Vector(ps[(i+1)%4], ps[(i+3)%4]);
			for(int j=0;j<3;j++){
				vs[3] = Vector(ps[(i+j+1)%4], ps[i]);
				if(extproduct(vs[j], vs[3]) > 0)count++;
				else count--;
			}
			if(count == 3 || count == -3)res++;
		}
		if(res == 4)puts("YES");
		else puts("NO");
	}
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

int main(void) {
    int a, b, t;
    cin >> a >> b >> t;

    int ans;
    ans = t / a;
    ans *= b;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  vector<int> vec(3);
  for(int i=0;i<3;i++){
    cin >>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  if(vec.at(0)==5 && vec.at(1)==5 && vec.at(2)==7) cout<<"YES";
  else cout<<"NO";
  
  
}

Measured memory_bytes: 256
import math
import collections

N = int(input())
S = input()

S = list(S)
def bit_add(A,a,w): #リストAのa番目にwを足す
    ind = a

    while len(A) > ind:
        A[ind] += w
        lsb = ind & (-ind)
        # print(ind)
        ind += lsb

    return

def bit_sum(A, a):  # リストAのa番目までの和を取る
    s = 0
    ind = a
    while ind != 0:
        s += A[ind]
        lsb = ind & (-ind)
        ind -= lsb

    return s
# cs = set(list(S))
li = {}
for c in "abcdefghijklmnopqrstuvwxyz":
    li[c] = [0] * (N + 1)

for i in range(1,N + 1):
    char = S[i - 1]
    bit_add(li[char],i,1)

# li → 1 スタート
# S → 0スタート
Q = int(input())
queries = [input().split() for _ in range(Q)]
for query in queries:
    a,b,c = query
    a = int(a)
    b = int(b)
    if a == 1: # 書き換え
        i = b

        c_org = S[i - 1] # 元の文字
        # li[c_org][i] -= 1
        S[i - 1] = c
        bit_add(li[c_org], i,  -1)#元の文字をbiマイナス
        bit_add(li[c], i, 1) #新たな文字をbiプラス

    if a == 2:
        ans = 0
        l = b
        r = int(c)
        for c in "abcdefghijklmnopqrstuvwxyz":
            temp = li[c]
            r_sum = bit_sum(temp,r)
            l_sum = bit_sum(temp,l - 1)
            diff = r_sum-l_sum
            if diff > 0: # ある文字
                ans += 1
        print(ans)




Measured memory_bytes: 167452
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main () {

    int n;
    cin >> n;
    
    vector<int> h;
    for (int i = 0; i < n; ++i) {
        int a=0;
        cin >> a;
        h.push_back(a);
    }

    int nCnt = 1;
    for (int i = 1; i < n; ++i) {
        bool low = false;
        for (int j=0; j < i; ++j) {
            if (h[i] < h[j]) {
                low = true;
                break;
            }
        }

        if (!low) nCnt++;
    }

    cout << nCnt << endl;
    return 0;
}

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

int main(){
	int N, T;
	cin>>N>>T;
	vector<int> cost;
	int c, t;
	for(int i=0;i<N;i++){
		cin>>c>>t;
		if(t<=T){
			cost.push_back(c);
		}
	}
	if(cost.size()!=0){
		sort(cost.begin(), cost.end());
		cout<<*cost.begin();
	}	else{
		cout<<"TLE";
	}
	return 0;
}	


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


//ABC076_b
int main() {
	int N, K;
	cin >> N >> K;

	int out = 1;
	rep(i, N) {

		if (out * 2  < out + K) {
			out = out * 2;
		}
		else {
			out = out + K;
		}
	}
	cout << out << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  N++;
  vector<i64> cnt(N, 1);
  rep(i,2,N) {
    for(int j = i; j < N; j += i) {
      cnt[j] += 1;
    }
  } 
  i64 ans = 0;
  rep(i,1,N) {
    ans += i * cnt[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 81408
n=int(input())
num = list(map(int, input().split()))

def culc(pattern):
    sum=0
    cost=0
    for i in range(n):
        sum+=num[i]
        if i%2==pattern:
            if sum>=0:
                cost+=sum+1
                sum=-1
        else:
            if sum<=0:
                cost+=-sum+1
                sum=1
        #print("sum is ", sum, "cost is ", cost)
    #print("")
    return cost


print(min(culc(0), culc(1)))

Measured memory_bytes: 20052
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def is_prime(num):
    if num<1:
        return False
    if num==1 or num==2 or num==3:
        return True
    for i in range(2,int(num**0.5)+1):
        if num%i==0:
            return False
    return True
 
def main():
    a,b=map(int,input().split())
    GCD=gcd(a,b)
    ans=0
    for i in range(1,int(GCD**0.5)+1):
        if GCD%i==0:
            if is_prime(i):
                ans+=1
            if i!=GCD and is_prime(GCD//i):
                ans+=1
    print(ans)
    
main()

Measured memory_bytes: 41580
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#n = int(input())
	n, m, k = tin()
	#s = input()
	for ni in range(n+1):
		for mi in range(m+1):
			nb = ni*(m-mi) + (n-ni)*mi
			if k == nb:
				return 'Yes'
	return 'No'

	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

string replace(string a,string b,int pos){
  for(int i=0;i<(int)b.size();i++)a[pos+i] = b[i];
  return a;
}

int main(){
  char str[1025];
  string ans;

  while(fgets(str,1025,stdin)!=NULL){
    ans = str;
 
    for(int i=0;i<(int)ans.size()-4;i++){
      string tmp = ans.substr(i,5);
      if(tmp == "apple")ans = replace(ans,"peach",i);
      if(tmp == "peach")ans = replace(ans,"apple",i);
    }
    cout << ans;
  }
}

Measured memory_bytes: 0
/**
* @author khokharnikunj8
**/
#include <bits/stdc++.h>

using namespace std;

//macros
#define ll long long
#define endl "\n"
#define pb push_back

//debug

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template<typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template<typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }


template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    ll a, b, k;
    cin >> a >> b >> k;
    if (k >= a + b) {
        cout << "0 0" << endl;
    } else if (k >= a) {
        cout << 0 << " " << (b - (k - a)) << endl;
    } else {
        cout << (a - k) << " " << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())
Sn = [input() for i in range(n)]

ans = ""
for i in range(97, 97+26):
    c = chr(i)
    mn = float("inf")
    for j in range(n):
        mn = min(mn, Sn[j].count(c))
    for j in range(mn):
        ans += c
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
	int n,p,i;
	int max = 0;
	int ans = 0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&p);
		if (max <p){
			max = p;
		} 
		ans += p;
	}
	ans -= max/2;
	printf("%d",ans);
	return 0;
}



Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Arrays;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int num[] = new int[n];
        for(int i = 0; i < n;i++)
            num[i] = scan.nextInt();

        int sum = 0;
        for (int i=0; i<n; i++) {
            sum += num[i];
        }
      
        int cnt = 0;
        for (int i=0; i<n; i++) {
           if (num[i]*4*m >= sum) {
                cnt++;  
            }
        }
        if (cnt >= m) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
    
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


// LRUD
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
// const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
// const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    string s;
    ll k;
    cin >> s >> k;

    ll non_one_idx = 0;
    while (s[non_one_idx] == '1') non_one_idx++;

    if (non_one_idx == s.size()){
        cout << 1 << endl;
        return 0;
    }

    // use k, wrong!
    if (k - 1 < non_one_idx){
        cout << s[k-1] << endl;
    }else{
        cout << s[non_one_idx] << endl;
    }

    return 0;
}





















Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>

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 REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999

int main() {
	int a,b,c,d = 0;
	cin >> a >> b;
	REP(i, b) {
		cin >> c;
		d += c;
	}
	cout << (d + a) / (a + 1) << endl;
}


Measured memory_bytes: 3104
#include <iostream>
using namespace std;
int main()
{
    int data, hasil;
    cin >> data;
    if (data % 2 == 0)
    {
        hasil = data / 2;
    }
    else
    {
        hasil = data / 2 + 1;
    }
    cout << hasil;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define s second
#define f first
#define N (1<<19)
int bit[N+1];
using namespace std;
typedef pair<int,int> P;
typedef pair<P,string> PP;
 
int sum(int i){
  int s=0;
  while(i>0){
    s+=bit[i];
    i-=i&-i;
  }
  return s;
}
 
void add(int i,int x){
  while(i<=N){
    bit[i]+=x;
    i+=i&-i;
  }
}
 
vector <PP> used;
int get_pos(PP a){
  int L=0,M,R=used.size();
  while(L<R){
    M=(L+R)/2;
    if(used[M]<a)R=M;
    else L=M+1;
  }
  return L-1;
}
 
int search(int x){
  int L=0,M,R=used.size();
  while(L<R){
    M=(L+R)/2;
    if(sum(get_pos(used[M]))>=x) R=M;
    else L=M+1;
  }
  return L;
}
 
void Stop(string a){cout <<a<<" is not working now."<<endl;}
void Begin(string a){cout <<a<<" is working hard now."<<endl;}

vector <PP> in;
map <string,int> M,M2;
set <PP> S;
 
int main(){
  int n;
  cin>>n;
  S.insert(PP(P(1e9,1e9),""));
  for(int i=0;i<n;i++){
    string str;
    int a;
    cin>>str>>a;
    M[str]=a,M2[str]=i;
    in.push_back(PP(P(a,i),str));
    S.insert(in.back());
}
  
  int m;
  cin>>m;
  char ch[20021];
  string str[20021];
  int sc[20021];
  for(int i=0;i<m;i++){
    cin>>ch[i]>>str[i];
    if(ch[i]=='+')cin>>sc[i];
    if(ch[i]=='+')S.insert(PP(P(sc[i],(i+n)),str[i]));
  }
  
  for(set<PP>::iterator it=S.begin();it!=S.end();it++)used.push_back(*it);
  reverse(used.begin(),used.end());
  for(int i=0;i<n;i++) add(get_pos(in[i]),1);
  
  int num=n;
  for(int i=0;i<m;i++){
    PP nx=PP(P(sc[i],(i+n)),str[i]);
    if(ch[i]=='+'){
      int a=search(num*0.2);
      M[str[i]]=sc[i],M2[str[i]]=(n+i);
      int c=get_pos(nx);
      add(c,1);
      int b=search((++num)*0.2);
      b>=c? Begin(str[i]):Stop(str[i]);
      if(b&&a<b&&used[b].s!=str[i])Begin(used[b].s);
      if(a&&a>b&&used[a].s!=str[i])Stop(used[a].s);
    }
 
    else if(ch[i]=='-'){
      nx.f=P(M[str[i]],M2[str[i]]);
      nx.s=str[i];
      
      int a=search(num*0.2);
      M.erase(str[i]),M2.erase(str[i]);
      add(get_pos(nx),-1);
      int b=search((--num)*0.2);
      if(a&&b<a&&used[a].s!=str[i])Stop(used[a].s);
      if(b&&b>a)Begin(used[b].s);
    }
  }
  return 0;
}

Measured memory_bytes: 19020
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long X,Y=0;
  bool S=true;
  cin >> X;
  for(Y=X;X>0;Y++){
    S=true;
    for(long long i=2;i<=Y/2;i++){
      if(Y%i == 0){
        S=false;
      }
    }
    if (S == true){
      break;
    }
  }
  cout << Y << endl;
}


Measured memory_bytes: 3604
# -*- coding: utf-8 -*-
#mathをインポート
import math
#n円が金額、嫌いな数がk個。入力
n,k=map(int,input().split(" "))
#嫌いな文字リスト
klist=input().split(" ")
def hantei(n,kl):
    if len(str(n))==4:
        while math.floor(n/1000)==kl or \
        math.floor(n/100)-10*math.floor(n/1000)==kl or \
        math.floor(n/10)-10*math.floor(n/100)==kl or \
        n-10*math.floor(n/10)==kl:
            n=n+1
    if len(str(n))==5:
        while math.floor(n/10000)==kl or \
        math.floor(n/1000)-10*math.floor(n/10000)==kl or \
        math.floor(n/100)-10*math.floor(n/1000)==kl or \
        math.floor(n/10)-10*math.floor(n/100)==kl or\
        n-10*math.floor(n/10)==kl:
            n=n+1
    elif len(str(n))==3:
        while math.floor(n/100)==kl or \
        math.floor(n/10)-10*math.floor(n/100)==kl or \
        n-10*math.floor(n/10)==kl:
            n=n+1
    elif len(str(n))==2:
        while math.floor(n/10)==kl or \
        n-10*math.floor(n/10)==kl:
            n=n+1
    elif len(str(n))==1:
        while n==kl:
            n=n+1
    return int(n)
n2=n
for kl in klist:
    kl=int(kl)
    n=hantei(n,kl)
while n!=n2:
    n2=n
    for kl in klist:
        kl=int(kl)
        n=hantei(n,kl)
print(n)

Measured memory_bytes: 3316
import itertools

N = int(input())
X = []
for i in range(N):
  X.append([int(j) for j in input().split()])

def distance(X1, X2):
  return ((X1[0] - X2[0])**2 + (X1[1] - X2[1])**2)**0.5

def mean(array):
  return sum(array)/len(array)

p = itertools.permutations(X, N)

ans = []
for X in p:
  D = []
  for i in range(N-1):
    X1, X2 = X[i], X[i+1]
    D.append(distance(X1, X2))
  ans.append(sum(D))
print(mean(ans))

Measured memory_bytes: 4376
import java.util.Scanner;

class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int N;
			int re = 9999999;
			int S1 = 0;
			int S2 = 0;
			int[] W;

			N = sc.nextInt();
			W = new int[N];
			for(int i = 0;i < N; i++) {
					W[i] = sc.nextInt();
					S2 += W[i];
			}

			for (int i = 0; i < N; i++ ){
					S1 += W[i];
					S2 -= W[i];
					if(S1 > S2){
							if(re > S1 - S2){
									re = S1 - S2;
							}
					}else {
							if(re > S2 - S1){
									re = S2 - S1;
							}
					}
			}
			System.out.println(re);
    }
}


Measured memory_bytes: 21844
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int cnt = 0;
    REP(i,n){
        int a;
        cin >> a;
        if(a%2==0) cnt++;
    }
    int ans = 1;
    REP(i,n){
        ans*=3;
    }
    int t = 1;
    REP(i,cnt){
        t*=2;
    }
    ans -= t;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652