akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

#define PIAR pair<int, int>
int field[52][52];
int dx[] = { -1,  0, 1, 0, -1,  1, 1, -1};
int dy[] = {0 , -1, 0, 1, -1, -1, 1,  1};

void rec(int x, int y) {
	field[x][y] = 0;
	for (int i = 0; i < 8; i++) {
		int nextX = x + dx[i];
		int nextY = y + dy[i];
		if (field[nextX][nextY] == 1) rec(nextX, nextY);
	}
}

int main() {
	int w, h;
	while (cin >> w >> h, w != 0 && h != 0) {
		for (int i = 0; i < 52; i++) {
			for (int j = 0; j < 52; j++) {
				field[i][j] = 0;
			}
		}

		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				cin >> field[i][j];
			}
		}

		int island = 0;
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				//??¶?????¢???
				if (field[i][j] == 1) {
					rec(i, j);
					island++;
				}
			}
		}
		cout << island << endl;
	}
}

Measured memory_bytes: 1236
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()) {
			TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
			String[] numbersStr = scan.nextLine().split(",");
			for(int i = 0; i < 5; i++) {
				Integer input = Integer.parseInt(numbersStr[i]);
				if(map.containsKey(input)) {
					map.put(input, map.get(input) + 1);
				} else {
					map.put(input, 1);
				}
			}
			outputHand(map);
		}
		scan.close();
	}

	public static void outputHand(TreeMap<Integer, Integer> map) {
		if(isFourCard(map)) {
			System.out.println("four card");
		} else if(isFullHouse(map)) {
			System.out.println("full house");
		} else if(isStraight(map)) {
			System.out.println("straight");
		} else if(isThreeCard(map)) {
			System.out.println("three card");
		} else if(isTwoPair(map)) {
			System.out.println("two pair");
		} else if(isOnePair(map)) {
			System.out.println("one pair");
		} else {
			System.out.println("null");
		}
	}

	private static boolean isOnePair(TreeMap<Integer, Integer> map) {
		if(map.containsValue(2)) return true;
		return false;
	}

	private static boolean isTwoPair(TreeMap<Integer, Integer> map) {
		int pairNum = 0;
		for(Integer value : map.keySet()) {
			if(map.get(value) == 2) pairNum++;
		}
		if(pairNum == 2) return true;
		return false;
	}

	private static boolean isThreeCard(TreeMap<Integer, Integer> map) {
		if(map.containsValue(3)) return true;
		return false;
	}

	private static boolean isStraight(TreeMap<Integer, Integer> map) {
		if(map.size() == 5) {
			int consecutiveNum = 0, lastNum = 0;
			for(Integer value : map.keySet()) {
				if(value == lastNum + 1) {
					consecutiveNum++;
					if(consecutiveNum == 4 && value == 13) {
						if(map.containsKey(1)) consecutiveNum++;
					}
				} else {
					consecutiveNum = 1;
				}
				lastNum = value;
			}
			if(consecutiveNum == 5) return true;
		}
		return false;
	}

	private static boolean isFullHouse(TreeMap<Integer, Integer> map) {
		if(map.containsValue(3) && map.containsValue(2)) return true;
		return false;
	}

	public static boolean isFourCard(TreeMap<Integer, Integer> map) {
		if(map.containsValue(4)) return true;
		return false;
	}
}



Measured memory_bytes: 26424
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100 + 5;
const int mo = 1000000007;

int n, m, k;
std::vector<int> v[N];
int f[N], fa[N], sz[N], rt[N];
LL fac[N], inv[N];
int dep[N];

int find(int x) {return f[x] == x ? x : f[x] = find(f[x]);}

void dfs(int x, int p) {
	f[x] = p ? x : p; sz[x] = p ? 1 : 0; rt[x] = 0; fa[x] = p;
	dep[x] = dep[p] + 1;
	for (int i = 0; i < v[x].size(); i++) {
		int y = v[x][i];
		if (y == p) continue;
		if (!dep[y]) dfs(y, x);
		else if (dep[y] < dep[x]) {
			// printf("F %d %d\n", x, y);
			int A, B = find(x); int mx = rt[B];
			while (1) {
				A = find(fa[B]);
				if (dep[fa[B]] <= dep[y]) break;
				sz[A] += sz[B]; f[B] = A;
				mx = max(mx, rt[A]);
				B = A;
			}
			rt[B] = min(2, mx + 1);
			sz[B]++;
		}
	}
}

LL getpow(LL a, LL b) {
	LL ans = 1;
	while (b) {
		if (b & 1) ans = ans * a % mo;
		a = a * a % mo;
		b >>= 1;
	}
	return ans;
}

LL C(int n, int m) {return fac[n] * inv[m] % mo * inv[n - m] % mo;}

LL POLYA(int n) {
	LL ans = 0;
	for (int i = 1; i <= n; i++) (ans += getpow(k, __gcd(i, n))) % mo;
	ans = ans * getpow(n, mo - 2) % mo;
	return ans;
}

int main() {
	read(n), read(m), read(k);
	for (int i = 1, x, y; i <= m; i++) {
		read(x), read(y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	fac[0] = 1;
	for (int i = 1; i <= 100; i++) fac[i] = fac[i - 1] * i % mo;
	for (int i = 0; i <= 100; i++) inv[i] = getpow(fac[i], mo - 2);
	for (int i = 1; i <= n; i++) if (!dep[i]) dfs(i, 0);
	LL ans = 1;
	for (int i = 1; i <= n; i++) {
		if (!f[i]) continue;
		int x = find(i);
		if (x != i) continue;
		// printf("type %d %d\n", rt[x], sz[x]);
		if (rt[x] == 0) ans = ans * k % mo;
		if (rt[x] == 1) ans = ans * POLYA(sz[x]) % mo;
		if (rt[x] == 2) {
			LL tmp = 0;
			for (int j = 1; j <= min(k, sz[x]); j++) {
				// printf("%lld %lld\n", C(k, j), C(sz[x] - 1, j - 1));
				(tmp += C(k, j) * C(sz[x] - 1, j - 1) % mo) %= mo;
			}
			ans = ans * tmp % mo;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map>       // pair
#include <string>
#include <stdio.h>
#include <numeric>
using namespace std;

int main(int argc, char const *argv[])
{

    int A ,B;
    cin>>A>>B;

    int num = 3*A+B;

    cout<<num/2;
    
    return 0;
}


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

using namespace std;
using ll = long long;

using Graph = vector<vector<int>>;

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

  int n, m;
  cin >> n >> m;
  Graph g(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
  }

  // dp[v] := ノードvを始点としたときの、Gの有効パスの長さの最大値
  vector<int> dp(n, 0);

  function<int(int)> rec = [&](int i) -> int {
    if (dp[i] > 0)
      return dp[i];

    int res = 0;
    for (auto v : g[i]) {
      res = max(res, rec(v) + 1);
    }

    dp[i] = res;
    return res;
  };
  for (int i = 0; i < n; i++) 
    rec(i);

  cout << *max_element(dp.begin(), dp.end()) << endl;

  return 0;
}


Measured memory_bytes: 12344
import java.io.*;
import java.io.IOException;
import java.util.*;

class Main {
    final static int INF = 1 << 28;
    final static long LNF = 1L << 60;
    final static double EPS = 1e-9;
    final static double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

    static final long MOD = 1_000_000_007;

    public static void main(String[] args) throws Exception {
        final MyScanner sc = new MyScanner();
        long X;
        X = sc.nextLong();
        solve(X);
    }

    static void solve(long X){
        int n = (int) (X / 100);
        int target = (int) (X % 100);

        int hoge = target / 5;
        int fuga = target % 5;
        if(fuga != 0) hoge++;

        if(hoge > n)System.out.println(0);
        else System.out.println(1);

    }


    static class MyScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
 
        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String next() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }
 
        char nextChar() {
            return nn().charAt(0);
        }
 
        int nextInt() {
            return Integer.parseInt(nn());
        }
 
        long nextLong() {
            return Long.parseLong(nn());
        }
 
        double nextDouble() {
            return Double.parseDouble(nn());
        }
 
        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
 
        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
    }

}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
vector<int> memo(100001, -1);
template<typename T>
class Graph
{
	map<T, list<T> >adjList;
public:

	void addEdge(int u, int v, bool bidir = false)
	{
		adjList[u].push_back(v);
		if (bidir)
			adjList[v].push_back(u);
	}

	int  DFShelper(T src, map < T, bool> &visited)
	{
		//visited[src] = true;
		//	cout << src << endl;
		if (memo[src] != -1)
			return memo[src];
		int cur_dist = 0;
		bool flag = false;
		for (auto child : adjList[src])
		{
			flag = true;
			//if (!visited[child])
			//{
			int x = DFShelper(child, visited);
			cur_dist = max(cur_dist, x);
			//}
		}
		//cout << cur_dist << endl;
		if (!flag)
			return 0;
		memo[src] = 1 + cur_dist;
		return memo[src];
	}

	int DFS(T src)
	{
		map<T, bool> visited;
		if (memo[src] != -1)
			return memo[src];
		return DFShelper(src, visited);
	}
};



int main()
{


	Graph<int> g;
	int n, m;
	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		g.addEdge(a, b);
	}

	int ans = 0;

	for (int i = 1; i <= n; i++)
	{
		ans = max(ans, g.DFS(i));
	}
	cout << ans << endl;

}













Measured memory_bytes: 11520
def count(l,r,d)
  r / d - (l - 1) / d
end
A,B,C,D = gets.split.map(&:to_i)

if C == D
  puts (B - A + 1) - count(A,B,C)
else
  puts (B - A + 1) - count(A,B,C) - count(A,B,D) + count(A,B, C.lcm(D))
end


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

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    rep(i, M) cin >> B[i];
    vector<vector<int>> A(N, vector<int>(M));
		int ans = 0;

    rep(n, N) {
			int check = C;
        rep(m, M) {
					int a;
					cin >> a;
					check+=(a*B[m]);
        }
				if(check > 0) ans++;
    }
		cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
w = int(input())
a = ""
b = 0
c = 0
if len(s) % w == 0:
  c = len(s)//w
else:
  c = (len(s)//w)+1
for i in range(c):
  a = a + s[b]
  b = b + w
print(a)

Measured memory_bytes: 8956
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

void solve_dp(int N, int P, const string& S){
  vector<ll> v(P, 0);

  ll ret = 0;
  rep(i,N){
    vector<ll> nv(P, 0);
    rep(j,P){
      int nj = (j*10+(int)(S[i]-'0'))%P;
      nv[nj] += v[j];
    }
    nv[((int)(S[i]-'0'))%P]++;
    ret += nv[0];
    swap(v, nv);
  }

  cout << ret << endl;
}

int main(){
  int N, P;
  cin >> N >> P;
  string S;
  cin >> S;

  if(P==2 || P==5){
    solve_dp(N, P, S);
    return 0;
  }
  
  reverse(ALLOF(S));
  vector<int> v(N, 0);
  int base = 1;
  rep(i,N){
    v[i] = base * (int)(S[i]-'0');
    v[i] %= P;
    base *= 10;
    base %= P;
  }

  vector<int> sum(N+1,0);
  rep(i,N){
    sum[i+1] = (sum[i] + v[i])%P;
  }

  ll ret = 0;
  map<int,ll> memo;
  rep(i,N){
    if(sum[i+1]==0) ret++;
    ret += memo[sum[i+1]];
    memo[sum[i+1]]++;
  }
  
  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 2564
#include<bits/stdc++.h>
using namespace std;
int main(){
  int q;
  cin >> q;
  vector<int> l(q),r(q),sum(100000);
  vector<bool> p(100010,true);
  for(int i=0;i<q;i++){
    cin >> l[i] >> r[i];
  }
  p[0]=false;
  p[1]=false;
  for(int i=2;i<=100000;i++){
    for(int j=2;j*i<=100000;j++){
      p[i*j]=false;
    }
  }
  for(int i=2;i<=100000;i++){
    if(p[i]&&p[(i+1)/2]&&i%2==1){
      sum[i]=sum[i-1]+1;
    }
    else{
      sum[i]=sum[i-1];
    }
  }
  for(int i=0;i<q;i++){
    cout << sum[r[i]]-sum[l[i]-1] << endl;
  }
}

Measured memory_bytes: 2172
import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product

# input = sys.stdin.readline

N = int(input())
ans = [0 for _ in range(105**3)]
for i in range(1, 105):
    for j in range(1, 105):
        for k in range(1, 105):
            idx = i**2 + j**2 + k **2 + i*j + i*k + j*k
            ans[idx-1] += 1
for i in range(N):
    print(ans[i])






Measured memory_bytes: 35996
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M, X = MAP()
C = [0] * N
A = [[]] * N
for i in range(N):
    C[i], *A[i] = MAP()

ans = INF
for bit in range(1<<N):
    skills = [0] * M
    cost = 0
    for i in range(N):
        if bit>>i & 1:
            cost += C[i]
            for j in range(M):
                skills[j] += A[i][j]
    if min(skills) >= X:
        ans = min(ans, cost)
if ans == INF:
    print(-1)
else:
    print(ans)


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

int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  for(int i = 0; i < n; i++) {
    cin >> w.at(i);
  }
  
  bool ans = true;
  
  for(int i = 0; i < n-2; i++) {
    for(int j = i+1; j < n; j++) {
      if(w.at(i) == w.at(j))
       ans = false;
    }
  }
  
  vector<char> top(n);
  vector<char> last(n);
  top.at(0) = w.at(0).at(0);
  last.at(0) = w.at(0).at(w.at(0).size()-1);
  
  for(int i = 1; i < n; i++) {
    top.at(i) = w.at(i).at(0); 
    last.at(i) = w.at(i).at(w.at(i).size()-1);
    if(top.at(i) != last.at(i-1)) {
      ans = false;
      break;
    }
  }
  
  if(ans)  cout << "Yes" << endl;
  else     cout << "No" << endl;
}

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

int main() {
    int n;
    while (cin >> n, n) {
        
        function<int(int)> count = [&](int x) -> int {
            if (x == 1) return 0;

            if (x % 2) x = x * 3 + 1;
            else x /= 2;
            return count(x) + 1; 
        };
        
        cout << count(n) << endl;
    }

    return 0;
}

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A = [0] + A + [0]
    all = 0
    for i in range(1, len(A)):
        all += abs(A[i-1] - A[i])
    for i in range(1, len(A)-1):
        print(all + abs(A[i+1] - A[i-1]) -
              abs(A[i+1] - A[i]) - abs(A[i] - A[i-1]))
    # for i in range(1, len(A)-1):

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15688
n,m=map(int,input().split())
p=[list(map(int,input().split()))for _ in range(n)]
s=[list(map(int,'0'*m))for _ in range(n)]
for j in range(m):
  c,d=map(int,input().split())
  for i in range(n):
    s[i][j]=abs(p[i][0]-c)+abs(p[i][1]-d)
else:
  for i in range(n):print(1+s[i].index(min(s[i])))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String... nui) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int ans = 0;
		
		for (int i = 1; i <= n; i++) {
			
			int tmp = i, sum = 0;
			
			while (tmp > 0) {
				
				sum += tmp % 10;
				tmp /= 10;
				
			}
			
			if (sum >= a && sum <= b) ans += i;
			
		}
		
		System.out.println(ans);
		
	}

}

Measured memory_bytes: 23380
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  int k;
  cin >> k;

  vector<string> list;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j + i <= s.length() && j <= 5; j++) {
      list.push_back(s.substr(i, j));
    }
  }
  sort(list.begin(), list.end());
  list.erase(unique(list.begin(), list.end()), list.end());

  cout << list[k - 1] << endl;
}

Measured memory_bytes: 1160
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
#include <tuple>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

unordered_map<string, int> ids;
vector<P> roads[6000];
vector<int> st;
int cap;
int N;
int M;
int dist[6000];
vector<P> road2[302];
void exec()
{
	fill(roads,roads+6000, vector<P>());
	fill(road2,road2+302, vector<P>());
	st.clear();
	ids.clear();
	cin >> N >> M >> cap;
	cap*=10;
	if((N|M|cap)==0)exit(0);
	string in;
	cin >> in;
	int id=0;
	ids[in]=id++;
	cin >> in;
	ids[in]=id++;
	for(int i=0;i<N;i++){
		string c;
		int d;
		cin >> in >> c >> d;
		if(ids.find(in)==ids.end())
		{
			ids[in]=id++;
		}
		if(ids.find(c)==ids.end()){
			ids[c]=id++;
		}
		int a=ids[in];
		int b=ids[c];
		roads[a].push_back(P(b,d));
		roads[b].push_back(P(a,d));
		//cout << a << ", " << b << ":: " << d << endl;
	}
	/*
	for(auto a:ids)
	{
		cout << a.first << ": " << a.second << endl;
	}*/
	st.push_back(0);
	st.push_back(1);
	for(int i=0;i<M;i++){
		cin >> in;
		int a=ids[in];
		if(a>1){
			st.push_back(a);
		}
	}
	for(int i=0;i<st.size();i++){
		fill(dist,dist+ids.size(),cap+1);
		priority_queue<P, vector<P>, greater<P> > q;
		q.push(P(0,st[i]));
		dist[st[i]]=0;
		while(q.size()){
			int f=q.top().second;
			int d=q.top().first;
			q.pop();
			if(dist[f]<d)continue;
			for(auto p:roads[f]){
				int b=p.first;
				int dd=d+p.second;
				if(dd<dist[b]){
					q.push(P(dd,b));
					dist[b]=dd;
				}
			}
		}
		for(int j=0;j<st.size();j++){
			if(dist[st[j]]<=cap)
			{
				road2[i].push_back(P(j,dist[st[j]]));
				//cout << i << ", " << j << ": " << dist[st[j]] << ", " << st[j] << ": " << ids.size() << endl;
			}
		}
	}
	{
		fill(dist,dist+st.size(),INT_MAX);
		priority_queue<P, vector<P>, greater<P> > q;
		q.push(P(0,0));
		dist[0]=0;
		while(q.size()){
			int f=q.top().second;
			int d=q.top().first;
			q.pop();
			if(dist[f]<d)continue;
			for(auto p:road2[f]){
				int b=p.first;
				int dd=d+p.second;
				if(dd<dist[b]){
					q.push(P(dd,b));
					dist[b]=dd;
				}
			}
		}
	}
	if(dist[1]<INT_MAX){
		cout << dist[1] << endl;
	}
	else
	{
		cout << -1 << endl;
	}
}
int main() {
	while(1)exec();
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
using P=pair<int,int>;

int i,j;
vector<int> w,s;

void pre_process(vector<int> &a,vector<int> &s){//累積和のvector
    int n=(int)a.size();
    s.assign(n+1,0);
    for(i=0;i<n;i++){
        s[i+1]=s[i]+a[i];
    }
}

int query(int i,int j,vector<int> &s){//区間[i,j]の和
    return (s[j]-s[i]);
}

int main(){
    int n;cin>>n;
    w.resize(n);
    s.resize(n+1);
    for(i=0;i<n;i++){
        cin>>w[i];
    }
    pre_process(w,s);
    int mini=s[n];//差の最小を考える
    for(i=1;i<n;i++){
        mini=min(mini,abs(query(0,i,s)-query(i,n,s)));
    }
    cout<<mini<<endl;
    return 0;
}

Measured memory_bytes: 256
#! python3
# prime_number.py

import math

def is_prime_number(x):
    if x < 2: return False
    elif x == 2: return True
    elif x%2 == 0: return False

    sqrt_upper_bound = math.floor(math.sqrt(x))+1
    for i in range(3, sqrt_upper_bound, 2):
        if x % i == 0:
            return False

    return True

n = int(input())
prime_num = 0
for i in range(n):
    x = int(input())
    if is_prime_number(x):
        prime_num += 1

print(prime_num)



Measured memory_bytes: 5680
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
using namespace std;

int main(int argc, const char * argv[]) {
    int N;
    cin>>N;
    long long L[N];
    for(int i=0;i<N; ++i){
        cin>>L[i];
    }
    int count=0;
    for(int i=0;i<N; ++i){
        for(int j=i+1;j<N; ++j){
            for(int k=j+1;k<N; ++k){
                if((L[i]+L[j]>L[k] && L[i]+L[k]>L[j] && L[j]+L[k]>L[i]) && L[i]!=L[j] && L[i]!=L[k] && L[j]!=L[k]){
                    ++count;

                }
                    
            }
        }
    }

    cout << count << endl;
}



Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;long int m=0;cin>>n;
  vector<int>a(n+1),b(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;i++){
    if(a.at(i)<b.at(i)){
      b.at(i)-=a.at(i);
      m+=a.at(i);
      if(a.at(i+1)<b.at(i)){
        m+=a.at(i+1);
        a.at(i+1)=0;
      }
      else{
        m+=b.at(i);
        a.at(i+1)-=b.at(i);
      }
    }
    else{
      m+=b.at(i);
      b.at(i)=0;
    }
  }
  cout<<m<<endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll h, w; cin >> h >> w;
    vector<string> a(h);
    REP(i, h) cin >> a[i];

    vector<vector<ll>> dp(h, vector<ll>(w, INF));
    REP(i, h) REP(j, w) {
        if (a[i][j] == '#') dp[i][j] = 0;
    }

    REP(i, h) {
        REP(j, w-1) {
            chmin(dp[i][j+1], dp[i][j] + 1);
        }
        DSRNG(j, w-1, 1) {
            chmin(dp[i][j-1], dp[i][j] + 1);
        }
        if (i < h-1) {
            REP(j, w) {
                chmin(dp[i+1][j], dp[i][j] + 1);
            }
        }
    }

    DSRNG(i, h-1, 0) {
        REP(j, w-1) {
            chmin(dp[i][j+1], dp[i][j] + 1);
        }
        DSRNG(j, w-1, 1) {
            chmin(dp[i][j-1], dp[i][j] + 1);
        }
        if (i > 0) {
            REP(j, w) {
                chmin(dp[i-1][j], dp[i][j] + 1);
            }
        }
    }

    ll ans = 0;
    REP(i, h) REP(j, w) chmax(ans, dp[i][j]);

    cout << ans << endl;
    
}

Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)
#define INF 10000000

int main() {
    unsigned int n, q;
    cin >> n >> q;
    multiset<int> s;
    multimap<int, int> m;
    map<int, int> mp;
    
    vector<int> ans(n, 0);
    vector<pair<int, int>> ab(n-1);
    vector<int> rank(n-1, INF);
    vector<vector<int>> list(n);
    rank[0] = 0;
    rep(i, 0, n-1) {
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(a-1, b-1);
        list[a-1].push_back(b-1);
        list[b-1].push_back(a-1);
    }
    rep(i, 0, q) {
        int p, x;
        cin >> p >> x;
        ans[p-1] += x;
    }
    queue<int> que;
    que.push(0);
    vector<int> check(n);
    check[0] = 1;
    while(!que.empty()) {
        int u = que.front();
        que.pop();
        for(auto i : list[u]) {
            if(check[i] == 1) continue;
            check[i] = 1;
            ans[i] += ans[u];
            que.push(i);
        }
    }

    rep(i, 0, n) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, a, b;
  cin >> n >> a >> b;
  
  if (a * b < n || n + 1 < a + b) {
    cout << -1 << '\n';
    return 0;
  }
  
  int res = n;
  vector<int> x(a);
  x.at(0) = b;
  for (int i = 1; i < a; i++) x.at(i) = 1;
  res -= b + (a - 1);
  
  for (int i = 1; i < a; i++) {
    if (res == 0) break;
    if (res < b) {
      x.at(i) += res;
      res = 0;
    }
    else {
      x.at(i) += b - 1;
      res -= b - 1;
    }
  }
  
  int now = 1;
  for (int i = 0; i < a; i++) {
    now += x.at(i);
    for (int j = 0; j < x.at(i); j++) {
      now--;
      if (i || j) cout << " ";
      cout << now;
    }
    now += x.at(i);
  }
  cout << '\n';
}

Measured memory_bytes: 4252
import java.util.*;

class Main {
    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long debt = 100;

        for (int x = 0; x < n; x++) {
            int residue = 0;
            if(debt % 20 != 0)  residue = 1;
            debt += debt / 20 + residue;
        }

        System.out.print(debt);
        System.out.println("000");
    }
}

Measured memory_bytes: 12000
#include <stdio.h>
int main(){
	int h,a,i,total;
	scanf ("%d",&h);
	scanf ("%d",&a);
	if (h%a==0){
		i=h/a;
		printf ("%d",i);
	}
	else{
		total = (h/a)+1;
		printf ("%d",total);
	}
	return 0;
}

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

typedef long long lli;

const lli INF = 1LL << 59;
const int INFI = 1 << 29;

bool compare(string a, string b){
  return a.size() == b.size() ? a < b : a.size() < b.size();
}

int main(){
  int n;
  while(cin >> n){
    int keta[4], max, maxn;
    string str;
    vector<string> s[4],ss;
    vector<lli> ans;
    bool f = false;
    fill(keta,keta+4,INFI);
    for(int i=0;i<n;i++){
      max=keta[0];
      maxn=0;
      cin >> str;

      for(int j=1;j<4;j++){
        if(max < keta[j]){
          max = keta[j];
          maxn = j;
        }
      }

      if(keta[maxn] >= str.size()){
        f = false;
        for(int j=0;j<4;j++){
          if(str.size() == keta[j]){
            f = true;
            s[j].push_back(str);
            sort(s[j].begin(), s[j].end(), compare);
            if(s[j].size() > 4) s[j].pop_back();
            break;
          }
        }

        if(!f){
          keta[maxn] = str.size();
          vector<string> v;
          v.push_back(str);
          s[maxn] = v;
        }
      }
    }


    for(int i=0;i<4;i++)
      for(int j=0;j<s[i].size();j++)
        ss.push_back(s[i][j]);

    for(int i=0;i<ss.size();i++){
      for(int j=0;j<ss.size();j++){
        if(i == j) continue;
        str = ss[i] + ss[j];
        lli a = 0;
        for(int k=0;k<str.size();k++){
          a *= 10;
          a += str[k] - '0';
        }
        ans.push_back(a);
      }
    }
    sort(ans.begin(),ans.end());

    cout << ans[2] << endl;
  }
}

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

#define MAX_VERTEX 100
#define INF 1000000

int vertex_num; // ???????????°
int d[MAX_VERTEX][MAX_VERTEX];  // ???????????¢???d[?§????][??????]??§?§??????????????????????????????¢?????¨???

void Input() {
  cin >> vertex_num;

  // (a1) ??\???????????¶??§?????????
  // d?????¨???INF?????????????§??????¨????????????????????´???0
  for (int i = 0; i < vertex_num; i++){
	  for (int j = 0; j < vertex_num; j++){
		  if (j == i){
			  d[i][j] = 0;
		  }else{
			  d[i][j] = INF;
		  }
	  }
  }


  for (int i = 0; i < vertex_num; i++) {
    int vertex, out;
    cin >> vertex >> out;
    for(int j = 0; j < out; j++) {
      int to, c;
      cin >> to >> c;
      d[vertex][to] = c;
    }
  }
}

void WarshallFloyd() {
	for (int k = 0; k < vertex_num; k++){
		for (int i = 0; i < vertex_num; i++){
			for (int j = 0; j < vertex_num; j++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

void Output() {
  for(int i = 0; i < vertex_num; i++) {
    cout << i << " " << d[0][i] << endl;
  }
}

int main() {

  Input();
  WarshallFloyd();
  Output();

  return 0;
}

Measured memory_bytes: 3112
def solve():
  ans = 0
  V, E = map(int, input().split())
  edge = [[] for _ in range(V)]
  for i in range(E):
    s,t,d = map(int, input().split())
    edge[s].append([t,d])
  dp = [[float('inf')]*V for _ in range(1<<V)]
  for v,d in edge[0]:
    dp[1<<v][v] = min(dp[1<<v][v],d)
  for S in range(2,1<<V,2):
    for u in range(V):
      if (S>>u)&1:
        for v,d in edge[u]:
          if not (S>>v)&1:
            dp[S+(1<<v)][v] = min(dp[S+(1<<v)][v],dp[S][u]+d)
  return dp[-1][0] if dp[-1][0]<float('inf') else -1
print(solve())


Measured memory_bytes: 16736
#include <cstdio>
#include <vector>
#include <queue>
#include <climits>
using namespace std;
#define PB push_back
typedef pair<int,int> P;

int main(){
    int V,E,r;
    scanf("%d%d%d",&V,&E,&r);
    vector<vector<pair<int,int>>> edges(V);
    for(int i=0;i<E;i++){
        int s,t,d;
        scanf("%d%d%d",&s,&t,&d);
        edges[s].PB(P(t,d));
    }
    vector<int> dist(V,INT_MAX);
    dist[r]=0;
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.push(P(0,r));
    while(!pq.empty()){
        P now=pq.top();pq.pop();
        int nd=now.first,nat=now.second;
        if(dist[nat]<nd) continue;
        for(int i=0;i<edges[nat].size();i++){
            int ned=nd+edges[nat][i].second,neat=edges[nat][i].first;
            if(ned < dist[neat]){
                dist[neat]=ned;
                pq.push(P(ned,neat));
            }
        }
    }
    for(int i=0;i<V;i++){
        if(dist[i]==INT_MAX) printf("INF\n");
        else printf("%d\n",dist[i]);
    }
}

Measured memory_bytes: 11088
#include <stdio.h>
int main(void)
{
	int i, n;
	char t[4];
	int c[4];
	for (i=0; i<4; ++i) c[i]=0;
	while (scanf("%d,%s", &n, t) != EOF) {
		switch (t[0]) {
			case 'A': if (t[1]=='B') c[2]++; else c[0]++; break;
			case 'B': c[1]++; break;
			case 'O': c[3]++; break;
		}
	}
	if (c[0] < 10) return 1;
	for (i=0; i<4; ++i) printf("%d\n", c[i]);
	return 0;
}

Measured memory_bytes: 0
while true
    n, m, p = gets.chomp.split.map(&:to_i)
    break if [n, m, p] == [0, 0, 0]
    arr = [0]
    n.times{arr << gets.to_i}
    sum = arr.inject(:+) * 100
    sum = sum * (100 - p) / 100
    puts (arr[m] == 0) ? 0 : sum / arr[m]
end


Measured memory_bytes: 6880
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int N, cnt[15];

signed main() {
    cin >> N;
    rep(i,0,N) {
        int p; cin >> p;
        cnt[p]++;
    }

    vector<int> decided, tasks;
    decided.push_back(0);
    repq(k,0,12) {
        int lim = 2;
        if(k == 0) lim = 0;
        if(k == 12) lim = 1;

        if(lim < cnt[k]) {
            cout << 0 << endl;
            return 0;
        }

        if(cnt[k] == 2) {
            decided.push_back(k);
            decided.push_back(24-k);
        }
        else if(cnt[k] == 1) {
            tasks.push_back(k);
        }
    }

    int M = tasks.size(), ans = 0;
    rep(bit,0,1<<M) {
        vector<int> temp = decided;
        rep(k,0,M) {
            if(bit >> k & 1) {
                temp.push_back(tasks[k]);
            }
            else {
                temp.push_back(24 - tasks[k]);
            }
        }
        sort(temp.begin(), temp.end());

        int S = temp.size(), mi = INF;
        rep(i,0,S) {
            int diff = abs(temp[i] - temp[(i+1)%S]);
            chmin(mi, min(diff, 24 - diff));
        }
        chmax(ans, mi);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n, m;
    cin >> n >> m;
    
    vector<pair<int, int>> v;
    rep (m) {
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    
    sort(v.begin(), v.end(), []
        (pair<int, int> p, pair<int, int> q) -> bool {
            return p.snd < q.snd;
        });
    
    int t = 0;
    int ans = 0;
    repeat (i, m) {
        int a = v[i].fst;
        int b = v[i].snd;
        if (t < a) {
            t = b - 1;
            ++ans;
        }
        else continue;
    }
    cout << ans << endl;
    
}

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

if n % 2 == 1:
    ans = []
    count = 0

    for i in range(1, n):
        ans.append((i, n))
        count += 1

    for i in reversed(range(1, n)):
        for j in range(1, i):
            if i + j == n:
                continue
            ans.append((j, i))
            count += 1

    print(count)
    for a, b in ans:
        print(a, b)
else:
    ans = []
    count = 0

    for i in reversed(range(1, n+1)):
        for j in range(1, i):
            if i + j == n+1:
                continue
            ans.append((j, i))
            count += 1

    print(count)
    for a, b in ans:
        print(a, b)


Measured memory_bytes: 3984
def nyu():
    L,R = map(int,input().split())
    return L,R


# def convert(LL,LR):
#     LL = LL % 2019
#     LR = LR % 2019

#     return LL,LR

def kansu(LL,LR):

    ans = 2020
    flg = False

    for ll in range(LL,LR):
        for lr in range(ll+1,LR+1):
            tmp  = (ll * lr) % 2019
            if ans > tmp:
                ans = tmp
                if ans == 0:
                    flg =True
                    break
        if flg == True:
            break

    print(ans)

ML,MR = nyu()
#ML,MR = convert(ML,MR)
kansu(ML,MR)


Measured memory_bytes: 3060
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()



Measured memory_bytes: 7000
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)  
#define rep(i,n) for(long long int (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long int (i)=(a); (i)<=(b); ++(i))
//const long long INF=1e18;
#define endl '\n'
const unsigned int mod = 1e9+7;
const int maxInt = 2147483647;
const int mx=405;
ll n,val[mx],dp[mx][mx];
ll inff=1e18;
ll dfs(int l,int r){
	if(l==r)return 0;
	if(dp[l][r])return dp[l][r];
	ll cnt=inff;
	for(long long int i=l;i<r;++i){
		ll a=0,b=0;
		for(ll j=l;j<=r;++j){
			if(j<=i)a+=val[j];
			else b+=val[j];
		}
		cnt=min(cnt,a+b+dfs(l,i)+dfs(i+1,r));
	}
	return dp[l][r]=cnt;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n;
    ref(i,1,n)cin >> val[i];
    cout << dfs(1,n);
    return 0;
}


Measured memory_bytes: 1536
N = int(input())
S = input()

T = 0
ans = []

for s in S:
    if s == "(":
        T += 1
        ans.append("(")
    else:
        T -= 1
        ans.append(")")
        if T < 0:
            ans.insert(0, "(")
            T = 0

for i in range(T):
    ans.append(")")
print("".join(ans))

Measured memory_bytes: 3064
import java.io.*;
import java.util.StringTokenizer;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;


		try {
			while (!(buf = br.readLine()).equals("0")) {
				int n = Integer.parseInt(buf);
				int p_m = 0;
				int sum = 0;
				for (int i=0;i<n;i++) {
					StringTokenizer st = new StringTokenizer(br.readLine());
					int p = Integer.parseInt(st.nextToken());
					int dd = Integer.parseInt(st.nextToken())+Integer.parseInt(st.nextToken());
					if (sum<dd) {
						p_m = p;
						sum = dd;
					}
				}
				System.out.println(p_m+" "+sum);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 62604
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();
        int[] d = new int[N];
        
        sc.nextLine();
        
        for(int i = 0; i < N; i++){
            d[i] = sc.nextInt();
        }
        
        int sum = 0;
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j < N; j++){
                sum += ( d[i] * d[j]);
            }
        }
        
        System.out.println(sum);
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr);
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 

int32_t main(){
    // boost;
    
    
        int x;
        cin>>x;
        
        int fi = x/500;
        int rem = x - fi*500;
        
        
        int se = rem/5;
        int ans = fi*1000 + se*5;
        cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (int i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (int i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll n;
    cin >> n;
    vector<ll> a(n + 2);
    REP(i, 1, n + 1)
    cin >> a[i];
    ll money = 1000, stock = 0;

    REP(i, 1, n + 1)
    {
        if (a[i - 1] < a[i])
        {
            money += stock * a[i];
            stock = 0;
        }
        if (a[i] < a[i + 1])
        {
            stock += money / a[i];
            money %= a[i];
        }
        // cerr << i << "," << money << endl;
    }
    cout << money << endl;
}

Measured memory_bytes: 3652
X = int(input())
#print('X=', X)

p = 0

while X > 4:
  if X > 499:
    N = X // 500
    X = X - 500 * N
    p = p + 1000 * N
  if X > 4:
    n = X // 5
    X = X - 5 * n
    p = p + 5 * n

print(p)


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N;
    cin>>N;
    vector<vector<pint>> G(N);
    REP(i, 0, N-1){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    
    queue<plong> que;
    que.push({0, 0});
    vector<int> Map(N, -1);
    Map[0] = 0;
    while(!que.empty()){
        auto cur = que.front(); que.pop();
        long v = cur.first;
        long d = cur.second;
        //cout << v << " " << d << endl;
        if(d%2) Map[v] = 1;
        else Map[v] = 0;

        for(auto x: G[v]){
            long next_v = x.first;
            long next_d = d + x.second;
            if(Map[next_v] == -1){
                que.push({next_v, next_d});
            }
        }
    }
    REP(i, 0, N) cout << Map[i] << endl;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int ap = 0;
    int bp = 0;
    rep(i, n ) {
        if ( i % 2 == 0 ) ap += a[i];
        else              bp += a[i];
    }
    cout << ap - bp << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

ok,ng=(10**16+1000)*n,-1
while ok-ng>1:
    mid=(ok+ng)//2
    cnt=0
    for i in range(n):
        cnt+=celi(a[i]+mid-n+1,n+1)
    if cnt<=mid:
        ok=mid
    else:
        ng=mid
    # print(ok,ng)
# print(ok)
# print(sum(a)-(n-1)*n)
tmp=sum(a)-(n-1)*n
for i in range(max(0,tmp),ok+1):
    cnt=0
    for j in range(n):
        cnt+=celi(a[j]+i-n+1,n+1)
    if cnt<=i:
        print(i)
        break

Measured memory_bytes: 74808
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;

int a[15][15];
int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int>c(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }   
    }
    ll ans = INF;
    for(int bit=1;bit<(1<<n);bit++){
        bool flag = true;
        vector<int>tmp(m);
        ll now = 0;
        rep(i,n){
            if((bit>>i)&1){
                now += c[i];
                rep(j,m){
                    tmp[j]+=a[i][j];
                }
            }
        }
        rep(i,m){
            if(tmp[i]<x)flag=false;
        }
        if(flag){
            chmin(ans,now);
        }
    }
    if(ans==INF){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rt return
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
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;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll s,n;
map<ll,int> m;
int main()
{
    cin>>s;
    m[s]=1;
    n=s;
    repd(i,2,maxn)
    {
    	if(n&1)
    	{
    		n=n*3+1;
    	}else
    	{
    		n=n/2;
    	}
    	if(m[n]==1)
    	{
    		printf("%d\n",i );
    		break;
    	}else
    	{
    		m[n]=1;
    	}
    }
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 256
use std::io;
use std::cmp::Ordering;
use std::str::FromStr;
use std::f64::consts::PI;

fn get_line() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok();
    line
}

fn get_vector() -> Vec<i32> {
    let line = get_line();
    let vec : Vec<i32> = line.split_whitespace().map(|x| i32::from_str(x).unwrap()).collect();
    return vec;
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let r: f64 = line.trim().parse().unwrap();
    println!("{} {}", r * r * PI, 2 as f64 * r * PI);
}



Measured memory_bytes: 5060