akhauriyash/Code-Regression huggingface dataset:
#include<iostream> 
#include<cstring>
#include<vector>
using namespace std;
int main(){
	int k;
	cin >> k;
	int t = 7 % k;
	int ten = 10%k;
	int tmp = 7 % k;
	if(t == 0){
		cout << 1;
		return 0;
	}
	for(int i = 2; i<=1e7; i++){
		tmp = (tmp * ten + t);
		tmp %= k;
		if(tmp == 0){
			cout << i;
			return 0;
		}
	}
	cout << -1;
	 return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>

int main(void)
{

    int H,W,i,j;

    while (1) {

        scanf("%d %d", &H, &W);

        if (H == 0 && W == 0)break;

        for (i = 0; i < H; i++) {
            for (j = 0; j < W; j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2036
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<int> p(m);
    for (int i = 0; i < m; i++) cin >> p[i];

    sort(p.begin(), p.end());

    vector<int> diff(m - 1);
    long long sumDiff = 0;
    for (int i = 1; i < m; i++) {
        diff[i - 1] = p[i] - p[i - 1];
        sumDiff += diff[i - 1];
    }

    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }

    sort(diff.rbegin(), diff.rend());
    for (int i = 0; i < n - 1; i++) sumDiff -= diff[i];

    cout << sumDiff << endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
	os << "[ "; for(auto v : V) os << v << " "; return os << "]";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1> void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << endl;
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1<<" | ";
	__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mems(x, y) memset(x, y, sizeof(x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define irep(i, n) for (int i = 1; i <= n; ++i)
#define print(x) cout << x << '\n'
#define err(x) clog << x << '\n'
typedef long long ll;
#define int ll
typedef long double ld;
#define double ld
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 0x3f3f3f3f;
const int M = 1e9+7;
const int N = 1e5+5;

bool dp[N];
bool done[N];
int n;
int a[N];

bool win(int k) {
	if (done[k]) return dp[k];

	if (k < a[0]) return false;
	bool c = true;
	rep(i, n) if (k >= a[i]) c = c & win(k - a[i]);

	dp[k] = !c;
	done[k] = true;
	return dp[k];
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int k; cin >> n >> k;
	rep(i, n) cin >> a[i];
	print((win(k) ? "First" : "Second"));
}


Measured memory_bytes: 2944
import sys, math
from collections import deque

readline = sys.stdin.readline

N = int(readline())
A = [int(readline()) for i in range(N)]


heads = []

for a in A:
    if len(heads) == 0:
        heads.append(a)
    else:
        left = 0
        right = len(heads) - 1
        while right - 1 > left:
            mid = (left + right) // 2
            if a <= heads[mid]:
                left = mid + 1
            else:
                right = mid

        if a > heads[left]:
            heads[left] = a
        elif a > heads[right]:
            heads[right] = a
        else:
            heads.append(a)

print(len(heads))
    

Measured memory_bytes: 47452
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;


void solve(){

    ll k;
    cin >> k;
    ll a[100010];
    rep(i,k){
        cin >> a[i];
    }
    ll l=2;
    ll r=2;
    for(ll i=k-1; i>=0; i--){
        if(r<a[i]) {
            cout << -1 << endl;
            return;
        }
        if(l/a[i]==r/a[i]&&0<(l%a[i])&&0<(r%a[i])){
            cout << -1 << endl;
            return;
        }

        l = ((l+a[i]-1)/a[i])*a[i];
        r = (r/a[i])*a[i] + a[i]-1;
    }
    cout << l << " " << r << endl;

}

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


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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int N, K;
    cin>>N>>K;
    if(N+(N%2)>=2*K)puts("YES");
    else puts("NO");

    return 0;
}

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


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

int main(){
    int N;
    scanf("%d", &N);
    int d[N];
    for (int i = 0; i < N; i++) scanf("%d", &d[i]);
    int sum;
    int j = 0;
    while (j < N) {
        for (int i = j + 1; i < N; i++) {
            sum += d[j] * d[i];
        }
        j++;
    }
    
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define inf (int)(3e18)
#define mod (int)(1e9+7)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int n;
vector<int>G[20000];
int con[20000],ans[20000];
int c[20000];
signed main(){
	cin>>n;
	rep(i,n-1){
		int a,b;cin>>a>>b;a--;b--;
		G[a].push_back(b);G[b].push_back(a);
		con[a]++;con[b]++;
	}
	rep(i,n)cin>>c[i];
	sort(c,c+n);
	int sum=0;
	rep(i,n){
		int mi=inf,ind;
		rep(j,n){
			if(mi>con[j]){
				mi=con[j];ind=j;
			}
		}
		ans[ind]=c[i];sum+=mi*c[i];
		con[ind]=inf;
		for(int j:G[ind]){
			con[j]--;
		}
	}
	cout<<sum<<endl;
	rep(i,n)cout<<ans[i]<<" ";
	cout<<endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include <vector>
#include<math.h>
using namespace std;

int main(void){
    long long N = 0;
    cin >> N;
    long long biggest = N;
    for(long long i = 1; i < sqrt(N) + 1; i++){
        if(N % i == 0){
            long long curr = i + (N/i) - 2;
            if(curr < biggest) biggest = curr;
        }
    }
    cout << biggest << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll = long long;
const ll MOD = 1000000007; 
using plong = pair<ll,ll>;
 
 
int main(){
    double A,B;
    cin>>A>>B;
    for(ll i=1;i<=1000;i++){
        if(floor(i*0.08)==A&&floor(i*0.1)==B){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def compute(bs):
    return sum(i % 2 == b % 2 == 1 for i, b in enumerate(bs, start=1))


def main():
    _ = int(input())
    bs = [int(b) for b in input().split()]
    res = compute(bs)
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

int num[1000005];

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

   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, 0, n) {
      cin >> a[i];
      num[a[i]]++;
   }

   int ans = 0;
   rep(i, 0, n) {
      bool ok = true;
      for (int b = 2; b * b <= a[i]; b++) {
         if (a[i] % b == 0) {
            if (num[b] >= 1) ok = false;
            if (num[a[i] / b] >= 1) ok = false;
         }
      }

      if (num[a[i]] > 1) ok = false;
      if (a[i] == 1 && num[1] > 1 || a[i] != 1 && num[1] >= 1) ok = false;
      if (ok) ans++;
   }
   cout << ans << endl;
   return 0;
}

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

int main(){
  string S;
  int K;
  cin>>S>>K;
  int N=S.size();
  std::vector<string> subst(25000);
  for(int j=0;j<K;j++){
    for(int i=0;i<N-j;i++){
      subst[5000*j+i]=S.substr(i,j+1);
    }
  }
  sort(subst.begin(),subst.end());
  int j=0;
  for(int i=1;i<25000;i++){
    if(subst[i]!=""&&subst[i]!=subst[i-1])j++;
    if(j==K){
      cout<<subst[i]<<endl;
      break;
    }
  }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000*3+10;
long long r, c, k, t[MAX][MAX], dp[MAX][MAX][4], a, b, x;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> r >> c >> k;
    for(long long i = 1; i <= k; i++)
    {
        cin >> a >> b >> x;
        t[a][b] = x;
    }
    for(long long i = r; i >= 1; i--)
    {
        for(long long j = c; j >= 1; j--)
        {
            dp[i][j][0] = max(dp[i][j + 1][0], dp[i + 1][j][3]);
            dp[i][j][1] = max(max(dp[i][j + 1][0], dp[i + 1][j][3]) + t[i][j], dp[i][j + 1][1]);
            dp[i][j][2] = max(max(dp[i][j + 1][1], dp[i + 1][j][3]) + t[i][j], dp[i][j + 1][2]);
            dp[i][j][3] = max(max(dp[i][j + 1][2], dp[i + 1][j][3]) + t[i][j], dp[i][j + 1][3]);
            //cout << i << " " << j << ": " << dp[i][j][0] << " " << dp[i][j][1] << " " << dp[i][j][2] << " " << dp[i][j][3] << "\n";
        }
    }
    cout << max(dp[1][1][0], max(dp[1][1][1], max(dp[1][1][2], dp[1][1][3]))) << "\n";
}


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

const int MAX_RC = 1005;
int R, C;
bool grid[MAX_RC][MAX_RC];
int ids[MAX_RC][MAX_RC];
bool seen[MAX_RC][MAX_RC];
std::map<int, std::set<int>> adj;
std::set<int> adjseen;

int dr[4] = {0, 1, 0, -1};
int dc[4] = {-1, 0, 1, 0};


void mark(int r, int c, int id) {
  if (r < 0 || r >= R || c < 0 || c >= C) return;
  if (seen[r][c]) return;
  seen[r][c] = true;
  ids[r][c] = id;
  for (int i = 0; i < 4; ++i) {
    int rr = r + dr[i];
    int cc = c + dc[i];
    if (rr < 0 || rr >= R || cc < 0 || cc >= C) continue;
    if (!grid[rr][cc]) continue;
    mark(rr, cc, id);
  }
  for (int rr = r - 2; rr <= r + 2; ++rr) {
    for (int cc = c - 2; cc <= c + 2; ++cc) {
      if (rr < 0 || rr >= R || cc < 0 || cc >= C) continue;
      if (!seen[rr][cc]) continue;
      if (!grid[rr][cc]) continue;
      if (ids[rr][cc] != id) {
        adj[id].insert(ids[rr][cc]);
        adj[ids[rr][cc]].insert(id);
      }
    }
  }
}

struct state {
  int id;
  int count;
};

int main() {
  scanf("%d %d ", &R, &C);
    int CR, CC;
  int DR, DC;
  scanf(" %d %d %d %d ", &CR, &CC, &DR, &DC);
  CR--; CC--;
  DR--; DC--;
  for (int r = 0; r < R; ++r) {
    for (int c = 0; c < C; ++c) {
      grid[r][c] = getchar() == '.';
    }
    scanf(" ");
  }

  int count = 1;
  for (int r = 0; r < R; ++r) {
    for (int c = 0; c < C; ++c) {
      if (seen[r][c] || !grid[r][c]) continue;
      mark(r, c, count);
      count++;
    }
  }
  // for (int r = 0; r < R; ++r) {
  //   for (int c = 0; c < C; ++c) {
  //     printf("%d ", ids[r][c]);
  //   }
  //   printf("\n");
  // }
  std::deque<state> q;
  q.push_back({ids[CR][CC], 0});
  int ans = -1;
  while (q.size()) {
    auto n = q.front();
    q.pop_front();
    if (n.id == ids[DR][DC]) {
      ans = n.count;
      break;
    }
    if (adjseen.count(n.id)) continue;
    adjseen.insert(n.id);
    for (int a : adj[n.id]) {
      q.push_back({a, n.count + 1});
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 48112
n, lw = gets.split.map(&:to_i)
w, v = Array.new(n) { gets.split.map(&:to_i) }.transpose
dp = Array.new(n + 1) { Array.new(lw + 1) { 0 } }

1.upto(n) do |i|
  0.upto(lw) do |j|
    if w[i - 1] <= j
      dp[i][j] = [dp[i - 1][j - w[i - 1]] + v[i - 1], dp[i - 1][j]].max
    else
      dp[i][j] = dp[i - 1][j]
    end
  end
end

puts dp[n][lw]


Measured memory_bytes: 93404
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();

        int[] a = new int[n];
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int idx = n - 1;
        for (int i = 0, j = n - 1; i <= j; i++, j--) {
            if (idx < 0) break;
            ans[i] = a[idx--];
            if (idx < 0) break;
            ans[j] = a[idx--];
        }

        for (int i : ans) {
            System.out.print(i + " ");
        }



    }
}


Measured memory_bytes: 85804
#include<bits/stdc++.h> 
using namespace std;
const int maxn  = 100005;
map<int,int> Map;
int n;
int a[maxn],f[maxn];
bool cmp(int a,int b){
	return a > b;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		Map[a[i]]++;
	}
	for (int i=1;i<=n;i++){
		if (Map[a[i]] >= 2){
			f[++f[0]] = a[i];
			Map[a[i]] -= 2;
		}
	}
	sort(f+1,f+1+f[0],cmp);
	if (f[0] <= 1) puts("0"); else{
		printf("%lld\n",(long long)f[1] * f[2]);
	}
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

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

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

void pv(const deque<int> &deq) {
	cerr << "before" << endl;
	for(int i = 0; i < deq.size(); i++) cerr << deq[i] << " ";
	cerr << endl;
	cerr << "after" << endl;
}

int main() {
	for(int n, r; cin >> n >> r;) {
		deque<int> a, b, c;
		for(int i = 0; i < n; i++) c.push_back(i);

		for(int j = 0; j < r; j++) {
			for(int i = 0; i < n / 2; i++) {
				b.push_back(c.front());
				c.pop_front();
			}
			for(int i = n / 2; i < n; i++) {
				a.push_back(c.front());
				c.pop_front();
			}
			int t; cin >> t;
			while(!a.empty() || !b.empty()) {
				for(int i = 0; i < t && !a.empty(); i++) {
					c.push_back(a.front()); a.pop_front();
				}
				for(int i = 0; i < t && !b.empty(); i++) {
					c.push_back(b.front()); b.pop_front();
				}
			}
		}
		cout << c.back() << endl;
	}
	return 0;
}

Measured memory_bytes: 0
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]
c = [list(map(int, input().split())) for i in range(N)]
col = [[0]*C for i in range(3)]
for i in range(N):
    ci = c[i]
    for j in range(N):
        cc = col[(i+j)%3]
        dd = D[ci[j]-1]
        for k in range(C):
            cc[k] += dd[k]
ans = 10**18
c0 = col[0]
c1 = col[1]
c2 = col[2]
for i in range(C):
    for j in range(C):
        if i == j:
            continue
        for k in range(C):
            if i == k or j == k:
                continue
            ans = min(ans, c0[i] + c1[j] + c2[k])
print(ans)

Measured memory_bytes: 5620
#include<iostream>
using namespace std;
int main()
{
	int d;
	cin>>d;
	if(d==25) cout<<"Christmas"<<endl;
	if(d==24) cout<<"Christmas Eve"<<endl;
	if(d==23) cout<<"Christmas Eve Eve"<<endl;
	if(d==22) cout<<"Christmas Eve Eve Eve"<<endl;
	return 0;
}

Measured memory_bytes: 256
import heapq
n, m = map(int, input().split())
a = [-int(x) for x in input().split()]
heapq.heapify(a)

for i in range(m):
    l = -heapq.heappop(a)
    heapq.heappush(a, -(l//2))
    
print(-sum(a))

Measured memory_bytes: 72088
#数字列の逆順をSにいれる
S = input()[::-1]
#各modの値を数えるためのリスト
counts = [0]*2019
#mod==0になったら1つだけでも2019の倍数になっているので初めから＋１しておく
counts[0] = 1
#numはSの各桁の数字、dは桁数（1の位、10の位、、）
num,d = 0,1
for i in S:
    num += int(i)*d
    num %= 2019
    d *= 10
    #ここがポイント。かける桁数の値も先にmodを計算してからかけると計算量が減らせる。
    d %= 2019
    counts[num] += 1

ans = 0
for i in counts:
    ans += i*(i-1)//2

print(ans)

Measured memory_bytes: 68596
#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

int solve(unordered_map<int, vector<int>>& um, int u, int v) {
    unordered_map<int, int> ud, vd;
    {
        queue<pair<int, int>> d;
        d.push({u, 0});
        while (!d.empty()) {
            pair<int, int> p = d.front();
            ud[p.first] = p.second;
            d.pop();
            for (auto e : um[p.first]) {
                if (ud.find(e) == ud.end()) {
                    d.push({e, p.second + 1});
                }
            }
        }
    }
    {
        queue<pair<int, int>> d;
        d.push({v, 0});
        while (!d.empty()) {
            pair<int, int> p = d.front();
            vd[p.first] = p.second;
            d.pop();
            for (auto e : um[p.first]) {
                if (vd.find(e) == vd.end()) {
                    d.push({e, p.second + 1});
                }
            }
        }
    }
    int ret = 0;
    for (auto p : um) {
        if (ud[p.first] < vd[p.first]) {
            ret = max(ret, vd[p.first] - 1);
        }
    }
    return ret;
}

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    unordered_map<int, vector<int>> um;
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        um[a].push_back(b);
        um[b].push_back(a);
    }
    cout << solve(um, u, v) << endl;
}


Measured memory_bytes: 17444
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

int main() {
    double a,b,x;
    cin >> a  >> b >> x;
    if(a*a*b/2>=x){
        double ans=atan(a*b*b/(2*x));
        printf("%.12f\n",ans*180/PI);
    }
    else{
        double ans=atan((2*a*a*b-2*x)/(a*a*a));
         printf("%.12f\n",ans*180/PI);
    }
}






Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
const int maxn = 1e2 + 10;
int n; int res = 0, ans = 0;
int h[maxn];
int a[maxn];
int vis[maxn];
int h_sum() {
	int res = 0;
	for (int i = 1; i <= n; i++) {
		if (h[i]) return 1;
	}
	return 0;
}
void work(int L, int R) {
	for (int i = L; i <= R; i++) {
		h[i]--;
	}
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &h[i]);
	}
	while (h_sum()) {
		int L = 0, R = 0;
		for (int i = 1; i <= n; i++) {
			if (!L&&h[i]) L = i, R = L;
			if (L&&h[i]) R = i;
			if (L&&h[i] == 0) break;
		}
		if (L) {
			ans++;
			work(L, R);
		}
	}
	cout << ans << endl;
	return 0;
}
//_CRT_SECURE_NO_WARNINGS
//force??
//heap??



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int res = 0;
    rep(r,N+1)rep(g,N+1){
        if(r*R+g*G>N) break;
        if((N-r*R-g*G)%B==0){
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

A , B = list(map(int, sys.stdin.buffer.readline().split()))
print( int(A * B / gcd(A, B)))


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

int main(){
	unsigned long long a,b;
	string s;
	cin>>a>>s;
	
	b=(s[0]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
	cout<<a*b/100<<endl;
	return 0; 
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int A, B;
	string S;
	cin >> A >> B >> S;

	auto result = "Yes";
	for (auto i = 0; i < A + B + 1; ++i)
	{
		if (i == A)
		{
			if (S[i] != '-')
			{
				result = "No";
				break;
			}
		}
		else if(S[i] == '-')
		{
			result = "No";
			break;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 1e6 + 7;

int n;
int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); //C++关同步
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC\n";
    else cout << "ABC\n";
    return 0;
}


Measured memory_bytes: 3560
n = int(input())
t, a = map(int, input().split())
hs = list(map(int, input().split()))

h_min = 1000000000000
i_min = 0
for i, h in enumerate(hs):
    if abs(a - (t - 0.006 * h)) < h_min:
        h_min = abs(a - (t - 0.006 * h))
        i_min = i + 1
print(i_min)

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N, Y;
    cin >> N >> Y;
    
    for(int i=0;i<=N;i++){
        for(int j=0;i+j<=N;j++){
            int k = N-i-j;
            if(i*10000 + j*5000 + k*1000 == Y){
                printf("%d %d %d\n", i, j, k);
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define int ll
#define pb push_back
#define sz(i) (int)(i.size())
#define fi first
#define se second
#define ld long double
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << std::endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 1e3 + 10;
// make sure N size is correctttt!!!!!!!!!

char c[N][N];
int n, m, dp[N][N];

int solve(int x, int y){
   if(c[x][y] == '#'){
      return 0;
   }
   if(x > n){
      return 0;
   }
   if(y > m){
      return 0;
   }
   if(x == n and y == m){
      return 1;
   }
   int &ans = dp[x][y];
   if(ans != -1)
      return ans;
   ans = (solve(x+1, y) + solve(x, y+1))%mod;
   return ans;
}

int32_t main(){_

   cin>>n>>m;

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

   memset(dp, -1, sizeof dp);
   cout<<solve(1,1);

   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 9344
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const s = stdin.split('\n')[0]

const ans = () => {
  const splited = s.split('')

  let sArr = [splited[0]]

  let prev = ''

  let isSeq = false
  for (let i = 1; i < splited.length; i++) {
    const newS = `${isSeq ? prev : ''}${splited[i]}`

    if (newS === sArr[sArr.length - 1]) {
      prev = newS
      isSeq = true
    } else {
      prev = ''
      isSeq = false
      sArr.push(newS)
    }
  }

  console.log(sArr.length)
}

ans()


Measured memory_bytes: 20940
#include <iostream>
#include <cstdio>
#define il inline
#define ri register
#define Size 5500
#define intmax 0x7fffffff
using namespace std;
bool a[Size],b[Size];
int A[Size],B[Size],at,bt;
il void get(char&);
int main(){
	int n;char c;scanf("%d",&n);
	for(int i(1);i<=n;++i)get(c),a[i]=c^48;
	for(int i(1);i<=n;++i)get(c),b[i]=c^48;
	for(int i(2);i<=n;++i){
		if(a[i]!=a[i-1])A[++at]=i-1;
		if(b[i]!=b[i-1])B[++bt]=i-1;
	}A[at+1]=B[bt+1]=n;
	int ans(intmax),beg(a[A[1]]==b[B[1]]?1:0);
	for(int i(beg-n*2),j,k,sum;i<=(beg+n*2);i+=2){sum=0;
		for(j=(i<=0?1:2-i),k=(i<=0?i:1);j<=at||k<=bt;++j,++k){
			int u(j),v(k);
			if(u<0)u=0;if(u>at)u=at+1;
			if(v<0)v=0;if(v>bt)v=bt+1;
			sum+=abs(A[u]-B[v]);
		}ans=min(ans,sum);
	}printf("%d",ans);
	return 0;
}
il void get(char &c){
	while(c=getchar(),c==' '||c=='\n'||c=='\r');
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();

		if(S.equals("ABC")) {
			System.out.println("ARC");
		}else {
			System.out.println("ABC");
		}

	}

}


Measured memory_bytes: 26924
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = pair<int, ll>;
using graph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

template <typename T>
vector<int> dijkstra(int s,vector< vector< pair<int, T> > > & G){
  using P = pair<T, int>;
  int n=G.size();
  vector<T> ds(n,INF);
  vector<int> bs(n,-1);
  priority_queue<P, vector<P>, greater<P> > pq;
  ds[s]=0;
  pq.emplace(ds[s],s);
  while(!pq.empty()){
    P p=pq.top();pq.pop();
    int v=p.second;
    if(ds[v]<p.first) continue;
    for(auto& e:G[v]){
      int u=e.first;
      T c=e.second;
      if(ds[u]>ds[v]+c){
        ds[u]=ds[v]+c;
        bs[u]=v;
        pq.emplace(ds[u],u);
      }
    }
  }
  return bs;
}

int main() {
  int n, m; cin >>n>> m;
  graph g(n);
  for(int i = 0; i < m; ++i){
    int a, b; ll c;
    cin >>a>> b>> c;
    --a;--b;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  set<pint> used;
  for(int i = 0; i < n; ++i){
    auto bs = dijkstra(i, g);
    for(int i = 0; i < n; ++i){
      if(bs[i]!=-1){
        int l=min(i, bs[i]);
        int r=max(i, bs[i]);
        used.insert({l,r});
      }
    }
  }
  int ans = m-used.size();
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
//#include <algorithm>
//typedef long long LL;
using namespace std;

int main(){
    string s;
    vector<bool> unique(4);
    bool hit = true;
    cin >> s;

    
    for(int i=0; i<4; i++){
        unique[i] = true;
    }

    unique[0] = false;
    int num = 0;
    for(int i=1; i<4; i++){
        if(s[0]==s[i]){
            num++;
            unique[i] = false;
        }
    }
    if(num!=1){
        hit = false;
    }
    num = 0;
    for(int i=1; i<3; i++){
        for(int j=i+1; j<4; j++){
            if(unique[i]==true && unique[j]==true){
                if(s[i]==s[j]){
                    num++;
                }
            }

        }
    }
    if(num!=1){
        hit = false;
    }
    if(hit){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)

int main()
{
    double r;
    cin>>r;
    cout<<setprecision(10)<<2*r*pi<<endl;
}


//    #include <chrono>
//    using namespace std::chrono;
//    auto start = high_resolution_clock::now();
//    auto stop = high_resolution_clock::now();
//    auto duration = duration_cast<milliseconds>(stop - start);
//    cout << duration.count() << endl;


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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  
  vector<bool> result(K+1, false);
  for(int i = 1; i <= K; ++i) {
    for(int j = 0; j < N; ++j) {
      if((i - A[j]) < 0) continue;
      result[i] = result[i] | !(result[i-A[j]]);
    }
  }
  
  if(result[K]) cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}

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

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

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll dp[3005][3005][4];
bool seen[3005][3005][4];
ll R,C;
vector<vector<ll>> v;
ll f(ll x,ll y, ll z){
    if(seen[x][y][z]) return dp[x][y][z];
    seen[x][y][z] = true;
    if(x==R-1&&y==C-1){
        if(v[x][y]==0) dp[x][y][z] = 0;
        else if(z==0) dp[x][y][z] = 0;
        else dp[x][y][z] = v[x][y];
        return dp[x][y][z];
    }
    if(z==0) {
        if(x<R-1) chmax(dp[x][y][z],f(x+1,y,3));
        if(y<C-1) chmax(dp[x][y][z],f(x,y+1,z));
    }
    else if(v[x][y]==0LL) {
        if(x<R-1) chmax(dp[x][y][z],f(x+1,y,3));
        if(y<C-1) chmax(dp[x][y][z],f(x,y+1,z));
    }
    else {
        if(x<R-1) {
            chmax(dp[x][y][z],f(x+1,y,3)+v[x][y]);
        }
        if(y<C-1) {
            chmax(dp[x][y][z],f(x,y+1,z));
            chmax(dp[x][y][z],f(x,y+1,z-1)+v[x][y]);
        }
    }
    return dp[x][y][z];
}

int main() {
    ll K;
    cin>>R>>C>>K;
    v.assign(R,vector<ll>(C,0LL));
    rep(i,K){
        ll x,y,u;
        cin>>x>>y>>u;
        x--;
        y--;
        v[x][y] = u;
    }
  cout<<f(0,0,3)<<endl;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int k;
  cin >> s >> k;
  set<string> res;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < s.size() - i; j++) {
      res.insert(s.substr(j, i + 1));
    }
  }
  auto itr = res.begin();
  for (int i = 0; i < k - 1; i++)
    itr++;
  cout << *itr << '\n';
  return 0;
}


Measured memory_bytes: 1664
# 2019/02/02
# AtCoder Beginner Contest115 - B

# Input
n = int(input())
p = list()
max = 0
sum = 0

# Input and sum
for i in range(n):
    p.append(int(input()))
    if max < p[i]:
        max = p[i]
    sum += p[i]

sum -= int(max / 2)

# Output
print(sum)


Measured memory_bytes: 3060
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    print(700+ 100*S.count('o'))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8932
#include<iostream>

using namespace std;

int main() {
  int N, M, X;

  cin >> N >> M >> X;

  int c1 = 0;
  int c2 = 0;

  int a;

  for (int i = 0; i < M; i++) {
    cin >> a;

    if (a < X) c1 += 1;
    else c2 += 1;
  }

  int ans = (c1 <= c2) ? c1 : c2;

  cout << ans << endl;

  return 0;
}
    



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int sumA=0, sumB=0, sumAB=0, sumO=0;
  char blood1,blood2;
  int n;
  while(scanf("%d,%c%c",&n,&blood1,&blood2)!=EOF){
    if(blood1=='A' && blood2=='B') sumAB++;
    else if(blood1=='A') sumA++;
    else if(blood1=='B') sumB++;
    else if(blood1=='O') sumO++;
  }
  printf("%d\n%d\n%d\n%d\n",sumA,sumB,sumAB,sumO);
  return 0;
}

Measured memory_bytes: 596
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

a = gif
b = gif

if a > b
  puts "GREATER"
elsif a == b
  puts "EQUAL"
else
  puts "LESS"
end

Measured memory_bytes: 2044
import itertools

N, M = map(int, input().split())
ab = [0] * M
for i in range(M):
  ab[i] = list(map(int, input().split()))

perms = itertools.permutations(range(1, N+1))
ans = 0
for perm in perms:
  if perm[0] != 1:
    continue
  is_goal = True
  for i in range(N-1):
    a = perm[i]
    b = perm[i+1]
    if not a < b:
      a, b = b, a
    if not [a, b] in ab:
      is_goal = False
  if is_goal:
    ans += 1

print(ans)


Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc167/tasks/abc167_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = 0;
    if (A >= K) {
        ans = K;
    } else {
        ans = A;
        K -= A;
    }
    if (B >= K) {
        K = 0;
    } else {
        K -= B;
    }
    if (C < K) {
        ans -= C;
    } else {
        ans -= K;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            if (line[0] >= 'a' && line[0] <= 'z')
            {
                Console.WriteLine("a");
            }
            else
            {
                Console.WriteLine("A");
            }


        }
    }
}


Measured memory_bytes: 25832
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
      	long long int n;cin>>n;
      	long long int ans=0;
      	 vector<long long int>fctrs(n+1,0);
      	for(int i=1;i<=n;i++)
          for(int j=i;j<=n;j+=i)fctrs[j]++;
      	for(int i=1;i<=n;i++)ans+=(i*fctrs[i]);
      	cout<<ans<<endl;
      	return 0;
    }

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

ll power(ll x, ll n, ll m) //x^n mod m
{
    if(n==0) return 1;
    ll ret = power(x, n/2, m);
    if(n%2==0) 
    {
        ret = (ret*ret) % m;
    }
    else
    {
        ret = (((ret*ret)%m) *x)%m;
    }
    return ret;
}

int main(){
    ll n,ans=1,mx=0;
    ll mod = 998244353;
    cin>>n;
    vector<ll> d(n),ls(n);
    for (int i = 0; i < n; i++)
    {
        cin>>d[i];
        ls[d[i]]++;
        mx=max(mx,d[i]);
    }
    if(d[0]!=0 || ls[0]!=1)
    {
        ans=0;
    }
    else
    {
        for (ll i = 1; i <= mx; i++)
        {
            ans*=(power(ls[i-1],ls[i],mod));
            ans%=mod;
        }
    
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> s = new List<int>();
    static decimal result;
static Hashtable ht=new Hashtable();
static StringBuilder sb = new StringBuilder();
static int N,M,K;
static long[,] table;
    static void Main()
    {
Read4();
      result=0;
      if(N>=6)result=K/2;
      if(N>=13)result=K;
      
                    Console.WriteLine(result.ToString());

    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }
 
    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
   {
       string[] tmp = Console.ReadLine().Split(' ');
       for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {

 
    }


}

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


int main(){
	ll N;
	cin >> N;
	
	//ans[i][j]は先頭がi末尾がj
	int ans[10][10];
	
	rep(i,10){
		rep(j,10){
			ans[i][j] = 0;
		}
	}
	
	REP(i,N){
		int val = i;
		string s = to_string(i);
		ans[s[0]-'0'][s[s.size()-1]-'0']++;
	}
	
	ll res = 0;
	rep(i,10){
		rep(j,10){
			res += ans[i][j]*ans[j][i];
		}
	}
	
	cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n = i()
a = wi()
b = wi()
c = 0

for i in range(n):
    ans += min(c + b[i], a[i])
    c = max(0, c + b[i] - a[i])
    c = min(c, b[i])

ans += min(c, a[n])

print(ans)

Measured memory_bytes: 21780
#include <stdio.h>

int N;

int main()
{
    int sum=0,new_sum=0;
    scanf("%d",&N);

    for(int i=1;i<N;i++){
	new_sum=i%10+i/10%10+i/10/10%10+i/10/10/10%10+i/10/10/10/10%10+(N-i)%10+(N-i)/10%10+(N-i)/10/10%10+(N-i)/10/10/10%10+(N-i)/10/10/10/10%10;
	if(i==1 || new_sum<sum)
	    sum=new_sum;
    }

    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 128
using System;
using static System.Console;
using System.Collections.Generic;

namespace abc179
{
    class Program
    {
        static void Main()
        {
            var nxm = ReadLine().Split(' ');
            var n = long.Parse(nxm[0]);
            var x = int.Parse(nxm[1]);
            var m = int.Parse(nxm[2]);

            var set = new Dictionary<long, int>();
            var list = new List<long>();
            var a = (long)x;
            var index = 0;
            var loopStart = -1;
            var loopOpenEnd = -1;
            while (true)
            {
                if (set.ContainsKey(a))
                {
                    loopStart = set[a];
                    loopOpenEnd = index;
                    break;
                }
                set.Add(a, index);
                list.Add(a);
                a = a * a % m;
                ++index;
            }
            var loopCount = (n - loopStart) / (loopOpenEnd - loopStart);
            var lastLoopLength = (n - loopStart) % (loopOpenEnd - loopStart);

            var first = 0L;
            for (var i = 0; i < loopStart; ++i)
            {
                first += list[i];
            }
            var loopTotal = 0L;
            for (var i = loopStart; i < loopOpenEnd; ++i)
            {
                loopTotal += list[i];
            }
            var lastLoopTotal = 0L;
            for (var i = 0; i < lastLoopLength; ++i)
            {
                lastLoopTotal += list[loopStart + i];
            }
            WriteLine(first + loopTotal * loopCount + lastLoopTotal);
        }
    }
}


Measured memory_bytes: 31956
module Main where
import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List                      ( unfoldr )
main :: IO ()
main = do
  [a, b, h, m] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let th = 2 * pi * (fromIntegral h) / 12 + tm / 12 :: Double
      tm = 2 * pi * (fromIntegral m) / 60 :: Double
      ax = fromIntegral a * sin th
      ay = fromIntegral a * cos th
      bx = fromIntegral b * sin tm
      by = fromIntegral b * cos tm
  print $ sqrt $ (ax - bx) ^ 2 + (ay - by) ^ 2


Measured memory_bytes: 4352
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];
        var p = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
        UnionFind uf = new UnionFind(n);
        for (int i = 0; i < m; i++)
        {
            var xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var x = xy[0] - 1;
            var y = xy[1] - 1;
            uf.TryUnite(x, y);
        }
        var res = 0;
        foreach (var item in Enumerable.Range(0, n).GroupBy(x => uf.Find(x)))
        {
            res += item.Select(x => p[x]).Intersect(item).Count();
        }
        Console.WriteLine(res);
    }
}


class UnionFind
{
    public int Size { get; private set; }
    public int GroupCount { get; private set; }
    public IEnumerable<int> AllRepresents => Parent.Where((x, y) => x == y);
    int[] Sizes;
    int[] Parent;
    public UnionFind(int count)
    {
        Size = count;
        GroupCount = count;
        Parent = new int[count];
        Sizes = new int[count];
        for (int i = 0; i < count; i++) Sizes[Parent[i] = i] = 1;
    }
    public bool TryUnite(int x, int y)
    {
        int xp = Find(x);
        int yp = Find(y);
        if (yp == xp) return false;
        if (Sizes[xp] < Sizes[yp]) { var tmp = xp; xp = yp; yp = tmp; }
        GroupCount--;
        Parent[yp] = xp;
        Sizes[xp] += Sizes[yp];
        return true;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int GetSize(int x) => Sizes[Find(x)];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int Find(int x)
    {
        while (x != Parent[x]) x = (Parent[x] = Parent[Parent[x]]);
        return x;
    }
}


Measured memory_bytes: 37508
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int answer = a - b * 2;
        if (answer < 0 ) {
            answer = 0;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23764