akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
	int m,f,r;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		if(m==-1||f==-1){
			puts("F");
		}
		else if(m+f>=80){
			puts("A");
		}
		else if(m+f>=65){
			puts("B");
		}
		else if(m+f>=50||r>=50){
			puts("C");
		}
		else if(m+f>=30){
			puts("D");
		}
		else{
			puts("F");
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

vector<pair<double, double>> crosspoint(double x1, double y1, double r1, double x2, double y2, double r2) {
	x1 -= x2;
	y1 -= y2;
	double S = x1 * x1 + y1 * y1;
	double a = (S + r2 * r2 - r1 * r1) / 2.0;
	double D = S * r2 * r2 - a * a;
	if (D < 0) { return {}; }

	double A1 = a * x1;
	double B1 = y1 * sqrt(D);
	double A2 = a * y1;
	double B2 = x1 * sqrt(D);
	return {
		{ (A1 + B1) / S + x2, (A2 - B2) / S + y2 },
		{ (A1 - B1) / S + x2, (A2 + B2) / S + y2 }
	};
}

int main() {
	const double EPS = 1e-9;
	int N, K;
	cin >> N >> K;
	vector<double> x(N), y(N), c(N);
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i] >> c[i];
	}

	auto check = [&](double mid) {
		vector<double> r(N);
		for (int i = 0; i < N; ++i) { r[i] = mid / c[i]; }
		vector<pair<double, double>> ps;
		for (int i = 0; i < N; ++i) {
			ps.emplace_back(x[i], y[i]);
			for (int j = i + 1; j < N; ++j) {
				auto vec = crosspoint(x[i], y[i], r[i], x[j], y[j], r[j]);
				for (auto p : vec) { ps.push_back(p); }
			}
		}
		for (auto p : ps) {
			int cnt = 0;
			double X = p.first, Y = p.second;
			for (int i = 0; i < N; ++i) {
				if (r[i] + EPS >= hypot(X - x[i], Y - y[i])) { ++cnt; }
			}
			if (cnt >= K) { return true; }
		}
		return false;
	};

	double ok = 1e9, ng = 0;
	int loop = 0;
	while (loop++ < 100) {
		double mid = (ok + ng) / 2;
		(check(mid) ? ok : ng) = mid;
	}
	cout.precision(15);
	cout << fixed << ok << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
 
int main(){
	int n;
	vector<int> num;
	cin >> n;
	for (int i = 0; i < n-1; i++){
		int a;
		cin >> a;
		num.push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < n-2; i++ )
	{
		ans += min(num[i],num[i+1]);
	}
	ans+=num[0]; ans+=num[n-2];
	cout << ans;
	
} 

Measured memory_bytes: 256
#!/usr/bin/perl

my $s = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51';

my @a = split(/,\s*/,$s);

my $k = <STDIN>;
$k = $k - 0;

print "$a[$k-1]\n";

exit(0);


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

int h[100005];
int d[100005];

int main(){
  int V,E;
  cin>>V>>E;
  vector<int> g[100005];
  vector<P> v[100005];
  rep(i,E){
    int from,to,dst;
    cin>>from>>to>>dst; from--; to--;
    g[from].push_back(to);
    v[from].push_back({to,dst});
    h[to]++;
  }

  queue<int> q;
  rep(i,V) if(h[i]==0){
    q.push(i);
  }
  vector<int> ans;
  while(q.size()){
    int p1=q.front(); q.pop();
    ans.push_back(p1);
    for(int p2:g[p1]){
      h[p2]--;
      if(h[p2]==0){
	q.push(p2);
      }
    }
  }

  if(ans.size()!=V){
    puts("No");
    return 0;
  }
  
  for(int p1:ans){
    for(auto x:v[p1]){
      int p2,dst;
      tie(p2,dst)=x;
      if(d[p2]==0) d[p2]=d[p1]+dst;
      else if(d[p2]!=d[p1]+dst){
	puts("No");
	return 0;
      }
    }
  }
  puts("Yes");
  return 0;
}

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    rep(i, a, b + 1){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)

ll MIN(ll a, ll b){
    if(a>b){
        return b;
    }else{
        return a;
    }
}

int main() {
    ll T;
    cin>>T;
    vector <ll> ans(T,-1);
    
    rep(i,T){
        ll N;
        cin>>N;
        vector<ll> A(N,-1);
        rep(j,N){
            cin>>A[j];
        }
        string S;
        cin>>S;
        vector< vector<ll> > cand(N+1,vector<ll>());
        //cand[N].push_back(0);
        bool flag=false;
        for(ll j = N-1; j >= 0; j--){
            ll x=A[j];
            for(auto y: cand[j+1]){
                x=MIN(x,x^y);
            }
            cand[j]=cand[j+1];
            if (x!=0) {
                if( S[j] == '0'){
                    cand[j].push_back(x);
                }else{
                    flag=true;
                    break;
                }
            }
        }
        if (flag){
            ans[i]=1;
        }else{
            ans[i]=0;
        }
    }
    rep(i,T){
        cout<<ans[i]<<endl;
    }
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, b, aa, bb;
string s;

int main() {
	cin >> n >> a >> b >> s;
	rep(i,n) {
		if (s[i]=='c') cout << "No" << ln;
		else if (s[i]=='a') {
			if (aa+bb < a+b) {
				cout << "Yes" << ln;
				aa++;
			}
			else cout << "No" << ln;
		} else {
			if (aa+bb < a+b && bb < b) {
				cout << "Yes" << ln;
				bb++;
			}
			else cout << "No" << ln;
		}
	}
}

Measured memory_bytes: 848
N = int(input())
a_s = input().split(" ")
a_s = list(map(int, a_s))
asum = sum(a_s)

mod = 10**9 +7
ans = 0
for i in range(len(a_s)-1):
  asum -= a_s[i]
  ans += (asum*a_s[i])%mod
  if ans > mod:
    ans = ans%mod
      
print(ans)

Measured memory_bytes: 31564
let () =
    try
        while true do
            let a1, b1, c1, a2, b2, c2 = Scanf.scanf "%f %f %f %f %f %f\n" (fun a1 b1 c1 a2 b2 c2 -> a1, b1, c1, a2, b2, c2) in
            let a = (a1*.b2 -. a2*.b1) in
            let x = (c1*.b2 -. c2*.b1) /. a +. 0.0 in
            let y = (a1*.c2 -. a2*.c1) /. a +. 0.0 in
            Printf.printf "%.3f %.3f\n" x y
        done
    with
        End_of_file -> ()

Measured memory_bytes: 2388
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner s = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
		long n = s.nextLong();
		long k = s.nextLong();
        n -= k*(n/k);
        out.println(Math.min(n, Math.abs(n-k)));

        out.close();
    }

    static class FastScanner {
		
		BufferedReader br; StringTokenizer st;
		FastScanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
			st = new StringTokenizer("");
		}
		String next() {
			while(!st.hasMoreElements()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch(Exception e) {}
			}
			return st.nextToken();
		}
		
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() {return Long.parseLong(next()); }
		
	}
}

Measured memory_bytes: 21204
import java.util.*;
import static java.lang.System.*;

public class Main {
	
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int num = 0;
		while (sc.hasNext()) {
			if (isPalindrome(sc.next())) {num++;}
		}
		out.println(num);
	}
	
	static boolean isPalindrome (String s) {
		int n = s.length();
		for (int i=0; i<n/2; i++) {
			if (s.charAt(i)!=s.charAt(n-i-1)) {return false;}
		}
		return true;
	}
	
}


Measured memory_bytes: 26024
import java.util.Scanner;

public class Main {

    static int NOT_FOUND = 99999999;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] sArr = new int[n];
        for (int i = 0; i < n; i++) {
            sArr[i] = sc.nextInt();
        }

        int q = sc.nextInt();
        int[] tArr = new int[q];
        int count = 0;
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            tArr[i] = x;
            if (binarySearch(sArr, x) != NOT_FOUND) count++;
        }
        System.out.println(count);
    }

    public static int binarySearch(int[] arr, int key) {
        int n = arr.length;
        int left = 0;
        int right = n;

        while (left < right) {
            int mid = (left + right) / 2;
            if (arr[mid] == key) {
                return mid;
            } else if (key < arr[mid]) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return NOT_FOUND;
    }
}



Measured memory_bytes: 68276
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn main(){
    let line = read_as_vec::<u64>();
    let (n, y) = (line[0], line[1]);

    for num_1k in 0..n+1{
        for num_5k in 0..n+1-num_1k{
            if y < 1000* num_1k + 5000 * num_5k{
                continue;
            }
            let rest = y - 1000* num_1k - 5000 * num_5k;
            if rest%10000 == 0 && n == rest/10000 + num_1k + num_5k{
                println!("{} {} {}", rest/10000, num_5k, num_1k);
                return;
            }
        }
    }

    println!("-1 -1 -1");
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
int a[405];
int dp[405][405];
int pre[405];
void solve()
{
    int n;
    cin >>  n;
    for(int i=0;i<n;i++)cin >>a[i];
    for(int i=0;i<n;i++)
    {
        pre[i+1] = pre[i]+a[i];
    }

   for(int i=n-1;i>=0;i--)
   {
       for(int j=i+2;j<=n;j++)
       { 
           dp[i][j] = (int)1e17;
          for(int k=i+1;k<j;k++)
          {
              dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]+pre[j]-pre[i]);
          }
       }
   }
   cout << dp[0][n]<<"\n";

}
int32_t main()
{

  ios::sync_with_stdio(false);
  
  solve();


}



Measured memory_bytes: 1536
l = gets.split
ln = l.map{|w| w.length}
lm = {:mx => 0, :wd => ""}
l.each{|w|
  if lm[:mx] < l.count(w)
    lm[:mx] = l.count(w)
    lm[:wd] = w
  end
}
puts "#{lm[:wd]} #{l[ln.index(ln.max)]}"

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

using namespace std;

#define PI 3.1415926535897932


int main(){
    int mod=1000000007;
    int n,m;
    char o[50],e[50];
    scanf("%s",o);
    scanf("%s",e);
    for (int i=0;i<50;i++) {
        if (o[i]>='a' && o[i]<='z' && e[i]>='a' && e[i]<='z') {
            printf("%c%c",o[i],e[i]);
        } else if (o[i]>='a' && o[i]<='z') {
            printf("%c",o[i]);
        } else {
            break;
        }
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define BUFSIZE         (1024)

char buf[BUFSIZE];

long
readnum()
{
    long        ret;
    char        *bp;

    bp = fgets(buf, BUFSIZE, stdin);
    if (bp == NULL) goto err;
    ret = atol(buf);
    return ret;

  err:
    perror("error fgets");
    exit(EXIT_FAILURE);
}

#define MAX(a, b)       ((a) < (b) ? (b) : (a))
#define MIN(a, b)       ((a) > (b) ? (b) : (a))

int
main()
{
    long        num;
    long        minnum;
    long        dif;
    long        maxdif;
    long        tn;
    int         idx;

    tn = readnum();

    minnum = readnum();
    --tn;
    maxdif = -1000 * 1000 * 1000;
    for (idx = 0; idx < tn; ++idx) {
        num = readnum();
        dif = num - minnum;
        maxdif = MAX(maxdif, dif);
        minnum = MIN(minnum, num);

//        printf("num = %ld, dif = %ld, max = %ld, min = %ld\n", num, dif, maxdif, minnum);
    }
    printf("%ld\n", maxdif);
}



Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define N 300005
using namespace std;

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

map<int,int> chk,cc;


int n,a[N],t[N];
char s[N];
int daps[N];


int main(void){
    int i,j,x,y,z;
    //freopen("in.txt","r",stdin);
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0;i<n;i++) a[i+1]= a[i] + (s[i]=='E'?1:0);

    x=N+100;
    for(i=1;i<=n;i++){
        y=(i-1-a[i-1])+(a[n]-a[i]);
        x=min(x,y);
    }
    printf("%d\n",x);



    return 0;

}



Measured memory_bytes: 1664
//Solve C

using System;
using System.Linq;
using System.Collections.Generic;

public class Class
{
    static void Main()
    {
        int N = Convert.ToInt32(Console.ReadLine());
        string[] S = new string[N];
        int i = 0;
        while (i < N)
        {
            S[i] = Console.ReadLine();
            i++;
        }
        int M = Convert.ToInt32(Console.ReadLine());
        string[] T = new string[M];
        i = 0;
        while (i < M)
        {
            T[i] = Console.ReadLine();
            i++;
        }
        int a = 0;
        int b = 0;
        int points = 0;
        i = 0;
        while (i < N)
        {
            a = S.Count(n => n == S[i]);
            b = T.Count(n => n == S[i]);
            if (points < a - b) points = a - b;
            i++;
        }
        Console.Write(points);
    }
}


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

int main(void){
  int n;
  cin >> n;
  int c = 0;
  bool flag = true;
  for(int i = 0; i < n; i++){
    string input; cin >> input;
    if(input[0] == 'A') c++;
    else c--;
    if(c < 0) flag = false;
  }

  if(flag && c == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3160
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000

int main(){
  unsigned short *n1,*n2;
  int ntime,i,array[MAX+1];

  scanf("%d",&ntime);

  n1=(short*)malloc((ntime+1)*sizeof(short));
  n2=(short*)malloc((ntime+1)*sizeof(short));

  for(i=1;i<=ntime;i++) scanf("%hu",&n1[i]);

  for(i=0;i<=MAX;i++) array[i]=0;
  

  for(i=0;i<ntime;i++) array[n1[i+1]]++;
  

  for(i=1;i<MAX;i++) array[i]=array[i]+array[i-1];
  

  for(i=ntime;i>0;i--){
    n2[array[n1[i]]]=n1[i];
    array[n1[i]]--;
  }

  for(i=1;i<ntime;i++) printf("%d ",n2[i]);
  printf("%d\n",n2[i]);

  free(n1);
  free(n2);

  return 0;
}


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

using namespace std;

int main(){

  int H, W;
  cin >> H >> W;

  int cnt = 0;
  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      char c;
      cin >> c;
      if ( c == '#' ) cnt++;
    }
  }

  if ( cnt == H+W-1 ) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  
  return 0;
}


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

int main(){
    int n;
    char s;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> s;
        if(s == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x, a, b;
  cin >> x >> a >> b;
  
  if (x + a < b) {
    cout << "dangerous" << endl;
  } else if (a >= b) {
    cout << "delicious" << endl;
  } else {
    cout << "safe" << endl;
  }
  
  return 0;
}

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

using namespace std;

int main(){
  int N; cin >> N; vector<int> T(N); int sum = 0;
  for(int i = 0; i < N; i++){cin >> T[i]; sum += T[i];}
  
  int M; cin >> M;vector<pair<int, int>> PX(M);
  for(int j = 0; j < M; j++){cin >> PX[j].first >> PX[j].second;}
  
  for(int k = 0; k < M; k++){ //M種類のanswer出力
    cout << sum - T[PX[k].first - 1] + PX[k].second << endl;}
  
  return 0;}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    ll N, W;
    cin >> N >> W;

    vector<ll> weights(N), values(N);
    rep(i, 0, N) cin >> weights[i] >> values[i];

    vector<ll> dp(W+3, 0);
    rep(i, 0, N)
    {
        rrep(weight, W, 0)
        {
            int next_weight = min(W+1, weight + weights[i]);
            dp[next_weight] = max(dp[next_weight], dp[weight] + values[i]);
        }
    }
    cout << dp[W] << endl;
    return 0;
}

Measured memory_bytes: 1152
def solve(n, a_list):
    cum_max = 0
    res = 0
    for i in range(n):
        a = a_list[i]
        if a < cum_max:
            res += cum_max - a
        cum_max = max(a, cum_max)
    return res


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    res = solve(n, a_list)
    print(res)


def test():
    assert solve(5, [2, 1, 5, 4, 3]) == 4
    assert solve(5, [3, 3, 3, 3, 3]) == 0


if __name__ == "__main__":
    test()
    main()


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

int main() {

    int first = 0;
    int second = 0;
    int third = 0;
    int height;

    for(int i = 0; i < 10; i++) {
        cin >> height;
        if (height >= first) {
            third = second;
            second = first;
            first = height;
        } else if (height >= second) {
            third = second;
            second = height;
        } else if (height >= third) {
            third = height;
        }

    }

    cout << first << endl << second << endl << third << endl;
     
    return 0;
}

Measured memory_bytes: 0
process.stdin.resume();
process.stdin.setEncoding('utf8');
var input = '';
process.stdin.on('data', function (chunk) {
  input += chunk;
});
process.stdin.on('end', function () {
  var lines = input.split('\n');
  var l = 0;
  while (true) {
    var loan = parseInt(lines[l++]);
    if (loan === 0) {
      break;
    }
    var ans = 'NA';
    for (var i = 0; i < 12; i++) {
      var vs = lines[l++].split(' ');
      loan -= vs[0] - vs[1];
      if (ans === 'NA' && loan <= 0) {
        ans = i + 1;
      }
    }
    console.log(ans);
  }
});

Measured memory_bytes: 10720
import std.stdio;

void main() {
    long N; readf("%s\n", &N);
    if (N == 0) {
        writeln(0);
        return;
    }
    int x = 0; long n = 1;
    while (n <= N) {
        x++;
        n <<= 1;
    }
    writeln(x);
}

Measured memory_bytes: 2516
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int n,m,x,y;
    cin>>n>>m;
    int a1[n+1]={0};
	int a2[n+1]={0};
	bool chk=false;
	loop(i,0,m){
		cin>>x>>y;
		if(x==1) a1[y]=1;
		if(y==n) a2[x]=1;
		if(a1[x] && a2[x])
            chk = true;
		if(a1[y] && a2[y])
		 chk =true;
	}
    if(chk)
    cout<<"POSSIBLE";
	else
	cout<<"IMPOSSIBLE";
    return 0;
}



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

int gcd(int x, int y) {
  if(x < y) swap(x, y);
  
  if(x % y == 0) {
    return y;
  } else {
    return gcd(y, x % y);
  }
}

int main() {
  int x, y;
  cin >> x >> y;
  cout << gcd(x, y) << endl;
  return 0;
}



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

#define PI 3.14159265359
#define eps 1e-8
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,n) FOR(i,0,n)
typedef long long int ll;
const int INF = 1<<29;
typedef long long ll;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double tick() { 
	static clock_t oldticks;
	clock_t newticks = clock();
	double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC; 
	oldticks = newticks;
	return diff;
}

inline int toInt(string s){
	return atoi(s.c_str());
}

inline int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}

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

inline bool isPrime(int n){
	ll j;
	j=sqrt(n);

	if(n<2)
		return 0;
	for(int i=2;i<=j;i++){
		if(n%i==0)
			return false;
	}
	return true;
}

inline long long nCr(long long n,long long m){
    ll res=1;
    if(n-m < m) m=n-m;

    for(ll i=1;i<=m;i++,n--){
        res=res*n;
        res=res/i;
    }
    return res;
}

int a,b;

int main(){
	ios_base::sync_with_stdio(false); //Fast I/O
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("output.txt","w",stdout);	

	cin >> a >> b;

	if(a+b==15)
		cout << '+';
	else if(a*b==15)
		cout << '*';
	else
		cout << "x";

    //cerr << tick();

	return 0;
	
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int cnt=0;
  int i=0;
  while(1){
    int b[64];
    int len=0;
    int t=i;
    while(t>0){
      b[len++]=t%4;
      t/=4;
    }
    int used[4]={0,0,0,0};
    int64 s=0;
    for(int j=len-1;j>=0;j--){
      s=10*s+(b[j]==3?7:b[j]==2?5:b[j]==1?3:0);
      used[b[j]]=1;
    }
    if(s>n) break;
    if(!used[0] && used[1] && used[2] && used[3]){
      cnt++;
    }
    i++;
  }
  printf("%d\n",cnt);
}

int main(void){
  run();
  return 0;
}


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

int main() {
  int N, M, D;
  cin >> N >> M;
  vector<int> A(M);
  D = N;
  
  for (int i = 0; i < M; i++) {
    cin >> A.at(i);
  }
  
  for (int i = 0; i < M; i++) {
    D = D - A.at(i);
  }
  
  if (D < 0) {
    cout << "-1";
  }
  else {
    cout << D;
  }
}

Measured memory_bytes: 3668
#include<stdio.h>
#define N 100
#define INF 1000000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n, w[N][N];
// void init(void);
void prim(void);

int main() {
	int i, j, in;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &in);
			if (in == -1) w[i][j] = INF;
			else          w[i][j] = in;
		}
	}
	prim();

	return 0;
}
// void init(void) {
// 	int i, j;
// 	for (i = 0; i < n; i++) {
// 		color[i] = WHITE;
// 		d[i] = INF;
// 		parent[i] = -1;
// 	}
// }
void prim(void) {
	int i, j, minCost, u, sum;
	int d[N], color[N], parent[N];

	for (i = 0; i < n; i++) {
		d[i] = INF;
		color[i] = WHITE;
		parent[i] = -1;
	}
	d[0] = 0;

	while (1) {
		u = -1;
		minCost = INF;
		for (i = 0; i < n; i++) {
			if (color[i] != BLACK  && d[i] < minCost) {
				minCost = d[i];
				u = i;
			}
		}
		if (u == -1) break;
		color[u] = BLACK;
		for (i = 0; i < n; i++) {
			if (color[i] != BLACK && w[u][i] != INF) {
				if (w[u][i] < d[i]) {
					d[i] = w[u][i];
					parent[i] = u;
					color[i] = GRAY;
				}
			}
		}
	}

	sum = 0;
	for (i = 0; i < n; i++) {
		if (parent[i] != -1) sum += w[i][parent[i]];
	}

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

Measured memory_bytes: 636
#include<iostream>
using namespace std;
int main(void){
  string s;
  char c;
  int count = 0;
  cin >> s;
  for(int i = 0;i < s.length();i++){
    c = s[i];
    if(c == '1'){
      count++;
    }
  }
  cout << count;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def main():
    n=int(input())
    graph = [[] for _ in range(n)]
    for _ in range(n-1):
        a,b,w=map(int,input().split())
        a-=1
        b-=1
        graph[a].append((b,w))
        graph[b].append((a,w))
    graph = tuple(graph)
    q,k = map(int,input().split())
    que = deque([k-1])
    dis = [-1 for _ in range(n)]
    dis[k-1]=0
    while que:
        i = que.pop()
        for j in range(len(graph[i])):
            go = graph[i][j][0]
            d = graph[i][j][1]
            if dis[go]==-1:
                dis[go] = dis[i] + d
                que.append(go)
    for _ in range(q):
        x,y = map(int,input().split())
        print( dis[x-1] + dis[y-1] ) 

if __name__ == "__main__":
    main()

Measured memory_bytes: 73640
n = gets.to_i
e = gets.split.map(&:to_i)
(n-1).times{ |i|
  puts e.join(" ")
  i.downto(0){ |j|
    e.insert(j,e.slice!(j+1)) if (e[j] > e[j+1])
    break if (e[j] > e[j-1])
  }
}
puts e.join(" ")

Measured memory_bytes: 8740
#include <stdio.h>
#include <string.h>

int main()
{
    char s[5][5];
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            scanf("%c",&s[i][j]);
            if(i==j)
                printf("%c",s[i][j]);
        }
        getchar();
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
import numpy as np
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
bs = [int(input()) for _ in range(N)]

A = np.array([A1, A2, A3])
mask = np.zeros_like(A)
for b in bs:
    mask += (A==b).astype(int)

mask = mask>0
if np.any(np.all(mask, axis=0)):
    print('Yes')
elif np.any(np.all(mask, axis=1)):
    print('Yes')
elif np.all(np.diag(mask)):
    print('Yes')
elif np.all(np.diag(mask[::-1])):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 12444
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
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; }
typedef long long ll;
int main(void){
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(a.rbegin(),a.rend());
    ll x=-1,y=0;
    rep(i,n-1){
        if(a[i]!=a[i+1])continue;
        if(x==-1){
            x=a[i];
            i++;
            continue;
        }else{
            y=a[i];
            break;
        }
    }
    ll res=x*y;
    cout<<res<<endl;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let s = i.read_line();
    let n0 = u8::from_str(&s[..2]).unwrap();
    let n1 = u8::from_str(&s[2..]).unwrap();

    fn is_month(value: u8) -> bool {
        1 <= value && value <= 12
    }
    let ans = match (is_month(n0), is_month(n1)) {
        (true, true) => "AMBIGUOUS",
        (true, false) => "MMYY",
        (false, true) => "YYMM",
        (false, false) => "NA",
    };

    writeln!(o, "{}", ans).unwrap();
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <cassert>

#include <vector>
#include <algorithm>
using namespace std;

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

void Main()
{
	int N, K;
	cin >> N >> K;
	vector<int> L(N);
	rep(i, N)
	{
		cin >> L[i];
	}

	sort(L.begin(), L.end(), greater<int>());
	int sum = 0;

	rep(i, K)
	{
		sum += L[i];
	}

	cout << sum << endl;
}

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

	Main();
	return 0;
}

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

int main(){
  std::string str;
  int counter[26]={};

  while(getline(std::cin, str)){

    for(int i=0; i<str.size(); i++){
      if(str[i] >= 'a' &&  str[i] <= 'z') counter[str[i]-'a']++;
      else if(str[i] >= 'A' && 'Z' >= str[i]) counter[str[i]-'A']++;
    }
  }

  for(int i=0; i<26; i++){
    std::cout << (char)( 'a'+i ) << " : " << counter[i] << std::endl;
  }

  return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() 
{
    ll a,b,c;
    cin>>a>>b>>c;
    if((c-a-b)<0)
    {
        cout<<"No";
        return 0;
    }
    if(4*a*b<(c-a-b)*(c-a-b))
        cout<<"Yes";
    else
        cout<<"No";
}

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


def solve(N: int, A: int, B: int):
    print(sum([check_sum_digit(num, A, B) for num in range(N + 1)]))
    return

def check_sum_digit(num: int, A: int, B: int):
    sum = sum_digit(num)
    return num if sum >= A and sum <= B else 0

def sum_digit(num: int):
    return sum([int(n) for n in str(num)])

# Generated by 1.1.5 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))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


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

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

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

    rep(i, 10000) {
        // cout << (int) (i * 0.08) << " " << (int) (i * 0.1) << endl;
        if ((int) (i * 0.08) == a && (int) (i * 0.1) == b) {
            cout << i << endl;
            return 0;
        }

    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
using namespace std;
char ka[734567];
struct node
{
    char a;
    struct node * next;
    struct node * rnext;
};
int main()
{
    scanf("%s", ka);
    struct node *head = (struct node*)malloc(sizeof(struct node));
    head->next = head->rnext = NULL;
    struct node *tail = (struct node*)malloc(sizeof(struct node));
    tail = head;
    for(int i=0; ka[i]; i++)
    {
        struct node *p = (struct node *)malloc(sizeof(struct node));
        p->a = ka[i];
        p->next = NULL;
        p->rnext = tail;
        tail->next = p;
        tail = p;
    }
    int num = 0;
    int f = 0;
    while(1)
    {
        if(head->next == tail)
        {
            f = 1;
            break;
        }
        else
        {
            struct node * p = head->next;
            while(p)
            {
                if(p==head->next)
                    p = p->next;
                if(p->next!=NULL)
                {
                    if(p->rnext->a!=p->next->a)
                    {
                        p->rnext->next = p->next;
                        p->next->rnext = p->rnext;
                        num++;
                        free(p);
                        break;
                    }
                    else
                        p = p->next;
                }
                else
                {
                    f = 1;
                    break;
                }
            }
            if(f)
                break;
        }
    }
    if(num%2)
        printf("First\n");
    else
        printf("Second\n");
    return 0;
}


Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

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

		for(;;) {
			if(primeJudg(x)) {
				System.out.print(x);
				return;
			}
			else {
				x++;
			}
		}
	}

	//素数を判断するメソッド
	public static boolean primeJudg(int a){
		for(int i=2 ; i<a ; i++) {
			if(a%i == 0) {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 27092
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
            }
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    if(i == 0 || i == (H - 1)){
                        System.out.print("#");
                    }else{
                        if(j == 0 || j == (W - 1)){
                            System.out.print("#");
                        }else{
                            System.out.print(".");
                        }
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 33944
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	long add = 0;
    	long ans = 0;
    	
		int N = sc.nextInt();
		long arry[]=new long[N+1];
		HashMap<Long, Long> map = new HashMap<Long, Long>();
		for(int i=1;i<=N;i++){
			long key1=sc.nextInt();
			arry[i]=key1;
			if (map.containsKey(key1)){
				map.put(key1,map.get(key1)+1);
			}
			else{
				map.put(key1,(long) 1);
			}
		}
//		for (Integer val : map.values()) {
//			add=add+val;
//		}
		for (Long key : map.keySet()) {
			add=add+(map.get(key)*(map.get(key)-1)/2);
		}
		for(int i=1;i<=N;i++){
			ans=add-(map.get(arry[i])-1);
			System.out.println(ans);
		}
    }
}

Measured memory_bytes: 108288
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    int n;
    const int maxN = 2 * (int)1e5 + 10;
    int a[maxN];
    set < pair < int, int > > all;
    bool check(int c) {
        all.clear();
        for (int i = 1; i + 1 <= n; i++) {
            if (a[i + 1] > a[i]) {
                continue;
            }
            int pos = a[i + 1];
            while (true) {
                if (all.empty()) {
                    all.insert(make_pair(pos, 2));
                    break;
                }
                auto it = all.lower_bound(make_pair(pos, -1));
                if ((it == all.end()) || ((it->first) != pos)) {
                    all.insert(make_pair(pos, 2));
                    break;
                } else {
                    auto t = *it;
                    if (t.second != c) {
                        all.erase(it);
                        all.insert(make_pair(pos, t.second + 1));
                        break;
                    }
                    else {
                        if (pos == 1) return false;
                        all.erase(it);
                        pos--;
                    }
                }
            }
            while (true) {
                if (all.empty()) break;
                auto it = --all.end();
                if ((it -> first) > a[i + 1]) {
                    all.erase(it);
                }
                else {
                    break;
                }
            }
        }
        return true;
    }
    int main() {
        //freopen("input.txt", "r", stdin);
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        srand(239);
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        bool ok = true;
        for (int i = 1; i < n; i++) {
            if (a[i] >= a[i + 1]) ok = false;
        }
        if (ok) {
            cout << 1;
            return 0;
        }
        int l = 1;
        int r = n + 10;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if (check(mid)) r = mid;
            else l = mid;
        }
        cout << r;
        return 0;
    }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

  deque<char> d;
  for (char c : s) d.push_back(c);

  bool flip = false;
  rep(_,q) {
    int ty;
    cin >> ty;
    if (ty == 1) {
      flip = !flip;
    }
    else {
      int f; char c;
      cin >> f >> c;
      if (flip) f = 3-f;
      if (f == 1) {
        d.push_front(c);
      }
      else {
        d.push_back(c);
      }
    }
  }

  if (flip) reverse(rng(d));
  string ans;
  for (char c : d) ans += c;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

ll a[100001]={};

int main() {
	int n;
	cin>>n;
	rep(i,n+1)cin>>a[i];
	ll res1=0;
	rep(i,n+1)res1+=a[i];
	ll res=0;
	int b;
	rep(i,n){
		cin>>b;
		if(a[i]>b){
			a[i]-=b;
		}else if(a[i+1]+a[i]<b){
			a[i]=0;
			a[i+1]=0;
		}else{
			a[i+1]-=b-a[i];
			a[i]=0;
		}
	}
	rep(i,n+1)res+=a[i];

	cout<<res1-res<<endl;
	return 0;
}


Measured memory_bytes: 1024
n=gets.to_i
as=gets.split.map(&:to_i)
m=1
check=true
n.times do |i|
  if m<=10**18
    m*=as[i]
  end
  if as[i]==0
    check=false
  end
end
if check
  puts m<=10**18 ? m:-1
else
  puts 0
end


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll a,b,c,d;
  string s;
  //cin>>a;
  cin>>a>>b;
  //cin>>a>>b>>c;
  //cin>>a>>b>>c>>d;
  //cin>>s;
  ans1((a*b)&1);
  return 0;
}

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

int main() {
	int n, x, d = 0;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		int l;
		cin >> l;
		d += l;
		if (d > x) {
			cout << i + 1 << endl;
			break;
		}
	}
	if (d <= x) cout << n + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666;
int n,m;char s[N][N],t[N][N];
int main() {
	read(n);read(m);
	rep(i,1,n)scanf("%s",s[i]+1);
	rep(i,1,n)rep(j,1,m)t[i][j]=s[i][j];
	rep(i,1,n)s[i][1]='#',t[i][m]='#';
	rep(i,1,n)rep(j,2,m-1)if(i&1)s[i][j]='#';else t[i][j]='#';
	rep(i,1,n){rep(j,1,m)printf("%c",s[i][j]);puts("");}
	puts("");
	rep(i,1,n){rep(j,1,m)printf("%c",t[i][j]);puts("");}
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

string S;
int K;

int dp[305][305][305];

signed main(){
    cin>>S;
    int N=S.size();
    cin>>K;

    rep(i,K+1){
        for(int len=0;len<=N;len++){
            for(int l=0;l+len<=N;l++){
                int r=l+len;
                if(len==1)dp[i][l][r]=1;
                chmax(dp[i+1][l][r],dp[i][l][r]);
                if(l)chmax(dp[i][l-1][r],dp[i][l][r]);
                if(r!=N)chmax(dp[i][l][r+1],dp[i][l][r]);
                if(l&&r!=N){
                    chmax(dp[i+(S[l-1]!=S[r])][l-1][r+1],dp[i][l][r]+2);
                }
            }
        }
    }

    cout<<dp[K][0][N]<<endl;
    return 0;
}


Measured memory_bytes: 221440
import java.util.Scanner;

public class Main {

    int solve(String s, boolean flip) {
        int n = s.length();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = s.charAt(i) == '0' ? 0 : 1;
        }
        if (flip) {
            as[0] = as[0] == 0 ? 1 : 0;
        }
        int ans = flip ? 1 : 0;
        for (int i = 1; i < n; i++) {
            if (as[i] == as[i - 1]) {
                as[i] = as[i] == 0 ? 1 : 0;
                ans++;
            }
        }
        return ans;
    }


    void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        System.out.println(Math.min(solve(s, false), solve(s, true)));
    }

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


Measured memory_bytes: 26256