akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}
//int frq[123];
//int arr[107];
int main(){
	Lancer();
	ll n, m, p, nw, sum = 0,res;
	cin >> n;
	vector<ll> vec(n + 2);
	for (int i = 1; i <= n; i++){
		cin >> vec[i];
		sum += vec[i];
	}
	cin >> m;
	while (m--)
	{
		cin >> p >> nw;
		res = sum;
		res -= vec[p];
		res += nw;
		cout << res << endl;
	}
	//cout << endl;
	return 0;
}


Measured memory_bytes: 3616
using System;

class A
{
    static void Main()
    {
        long X = long.Parse(Console.ReadLine());
        double XT = 100;
        int c = 0;
        for (;XT <= X ; )
        {
            XT = Math.Floor(XT * 1.01);
            if (XT >= X) {
              c++;
              break;
            }
          
            else c++;
        }
        Console.WriteLine(c);
    }
}

Measured memory_bytes: 27396
N = int(input())
A = []
B = []
ans = 0

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

for i in range(N-1, -1, -1):
    a, b = (A[i] + ans), B[i]
    if a % b != 0:
        ans += b - a % b

print(ans)

Measured memory_bytes: 11064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

int main()
{
    int n;
    while(1){
        cin >> n;
        if(n == 0) break;
        int t[20][20];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n + 1; j++){
                cin >> t[i][j];
            }
        }
        vector<int> result(1 << n);
        fill(result.begin(), result.end(), 100000000);
        result[0] = 0;
        for(int i = 0; i < (1 << n); i++){
            for(int j = 0; j < n; j++){
                if((i & (1 << j)) != 0) continue;
                result[i | (1 << j)] = min(result[i | (1 << j)], result[i] + t[j][0]);
                for(int k = 0; k < n; k++){
                    if((i & (1 << k)) == 0) continue;
                    // cout << i << " " << (i | (1 << j))<< " " << k << endl;
                    result[i | (1 << j)] = min(result[i + (1 << j)], result[i] + t[j][k + 1]);
                }
            }
            // cout << result[i] << endl;
        }
        cout << result[(1 << n) - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1452
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;

int count2(int x) {
    int ret = 0;
    while (x % 2 == 0) {
        ++ret;
        x /= 2;
    }
    return ret;
}

void main() {
    size_t n;
    string s;
    readf("%d\n%s\n", &n, &s);
    auto c = s.split().map!(a => a.to!int.count2).reduce!min;
    writeln(c);
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;

int mycount(long num){
  int count=0;

  for(count=0;;){
    if(num % 2 == 0){
      num /= 2;
      count++;
    }else
      break;

  }


  return count;
}


int main(){
  int n;

  cin >> n;

  long row[n];

  for(int i=0; i < n; i++)
    scanf("%ld", &row[i]);

  int count=0;

  for(int i=0; i < n; i++){
    int tmp;
    tmp = mycount(row[i]);
    //cout << tmp << endl;
    count += tmp;
  }


  cout << count << endl;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl


int main(){
    int s,w;
    cin >> s >> w;
    if(w>=s)COUT("unsafe");
    else COUT("safe");
    return 0;
}


Measured memory_bytes: 3636
h,w,k=map(int,input().split())
c=''
for i in range(h):
    c+=input()
# print(c)
# row_dot_cnt=[c.count() for _ in range(h)]
# col_dot_cnt=[0]*w
ans=0
for i in range(2**h): # 行
    i_bin=format(i,'06b')
    for j in range(2**w): # 列
        j_bin=format(j,'06b')
        cnt=0
        # print(i_bin,j_bin)
        for s in range(h):
            if i_bin[5-s]=='0':
                for t in range(w):
                    if j_bin[5-t]=='0' and c[s*w+t]=='#':
                        # print(s,t)
                        cnt+=1
        if cnt==k:
            ans+=1
            # print(f'        {cnt}   {ans}')
print(ans)


Measured memory_bytes: 68540
#include<iostream>
using namespace std;
int main(){
string s,t;
  int ans=0;
  cin >> s >> t;
  if(s.at(0)==t.at(0)){
  ans++;
  }
  if(s.at(1)==t.at(1)){
  ans++;
  }
  if(s.at(2)==t.at(2)){
  ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

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

  vector<int> l(2*n);

  for(int i = 0; i < 2*n; i++){
    int temp;
    cin >> temp;
    l[i] = temp;
  }

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

  int ans;
  for(int i = 0; i < n; i++){
    ans += l[2*i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <memory.h>

using namespace std;

#define MAX_N 1000000

int Q;
int l[MAX_N+1], r[MAX_N+1];

bool prime[MAX_N+2];
int similar[MAX_N+2];

void solve() {
  memset(prime, 1, sizeof(prime));
  prime[0] = prime[1] = false;
  for (int i = 2; i <= MAX_N+1; i++) {
    if (prime[i]) {
      for (int j = i*2; j <= MAX_N+1; j+=i) {
        prime[j] = false;
      }
    }
  }

  memset(similar, 0, sizeof(similar));
  for (int i = MAX_N; i >= 0; i--) {
    if (i % 2 == 1 && prime[i] && prime[(i+1)/2]) {
      similar[i] += similar[i+1] + 1;
    } else {
      similar[i] = similar[i+1];
    }
  }

  for (int i = 0; i < Q; i++) {
    cout << similar[l[i]] - similar[r[i]+1] << endl;
  }
}

int main() {
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> l[i] >> r[i];
  }
  solve();
}


Measured memory_bytes: 8832
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, std::vector<long long> L){
    sort(L.begin(), L.end());
    ll ans = 0;
    rep(i, N){
        ans += L[2*i];
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(2*N);
    for(int i = 0 ; i < 2*N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 256
#python3
from collections import deque
INF = int(1e9)
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]

def main():
    h, w = map(int, input().split())
    maze = [input() for _ in range(h)]

    ans = -1
    for si in range(h):
        for sj in range(w):
            if maze[si][sj] == '#':
                continue
            
            dist = [[INF for _ in range(w)] for _ in range(h)]
            Q = deque()
            Q.append((si, sj))
            dist[si][sj] = 0
            while len(Q) > 0:
                pi, pj = Q.popleft()

                for di, dj in d:
                    x = pi + di
                    y = pj + dj
                    if (x < 0) | (y < 0) | (x >= h) | (y >= w):
                        continue
                    if maze[x][y] == '#':
                        continue 
                    if dist[x][y] != INF:
                        continue

                    Q.append((x, y))
                    dist[x][y] = dist[pi][pj] + 1                

            for i in range(h):
                for j in range(w):
                    if dist[i][j] == INF:
                        continue            

                    ans = max(ans, dist[i][j])
    
    print(ans)
main()

Measured memory_bytes: 3316
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
    int n;cin>>n;
    bool ok=false;
    for(int a=0;a<25;a++){
        for(int b=0;b<15;b++){
            if(4*a+7*b==n)ok=true;
        }
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
def main():
    n = int(input()) % 10
    if n in (2, 4, 5, 7, 9):
        return 'hon'
    elif n in (0, 1, 6, 8):
        return 'pon'
    else:
        return 'bon'


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 9164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int a[] = new int[26];
		for (int i=0;i<s.length();i++ ) {
			a[s.charAt(i)-'a']++;
		}
		for (int i=0;i<a.length;i++ ) {
			if (a[i]%2==1) {
				System.out.println("No");
				return ;
			}
		}
		System.out.println("Yes");
		return ;
	}
}

Measured memory_bytes: 35628
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#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 all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1e9+7;

string s;
int k;

int main()
{
    cin >> s;
    cin >> k;
    rep(i, s.size()){
        int p = 1 - (s[i] - 'z');
        if(p <= k && s[i] != 'a'){
            k -= p;
            s[i] = 'a';
        }
    }
    if(k > 0){
        int p = s[s.size()-1] - 'a';
        s[s.size()-1] = (char)('a'+((k%26)+p)%26);
    }
    cout << s << endl;
}


Measured memory_bytes: 512
N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if M <= N :
    ans = 0
else:
    Y = []
    for i in range(M-1):
        Y.append(X[i+1] - X[i])
    Y.sort(reverse=True)
    ans = X[-1] - X[0]
    Y = Y[:N-1]
    for i in Y:
        ans -= i
print(ans)

Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int i,j,m,n=0;
    cin>>m;
    for(i=1;;i++)
    {
        n+=i;
        if(n>=m)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		//LinkedList<Integer> array = new LinkedList<Integer>();
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		//ArrayList<Integer> num = new ArrayList<Integer>();
		Deque<Integer> num = new ArrayDeque<Integer>();
		for(int i = 0; i < n; i++) {
			String s = scan.next();
			if(s.equals("insert")) {
				num.push(Integer.parseInt(scan.next()));
			}else if(s.equals("delete")) {
				int key = Integer.parseInt(scan.next());
				num.remove(key);
			}else if(s.equals("deleteFirst")) {
				num.removeFirst();
			}else if(s.equals("deleteLast")) {
				num.removeLast();
			}
		}

//		for(int i = 0; i < n; i++) {
//			String s = scan.next();
//
//			if(s.equals("insert")) {
//				int k = Integer.parseInt(scan.next());
//				array.addFirst(k);
//			}else if(s.equals("delete")) {
//				int k = Integer.parseInt(scan.next());
//				int t = array.indexOf(k);
//				if(t != -1) {
//					array.remove(t);
//				}
//			}else if(s.equals("deleteFirst")) {
//				array.remove(0);
//			}else if(s.equals("deleteLast")) {
//				array.remove(array.size() - 1);
//			}
//		}
		scan.close();
//		PrintWriter out = new PrintWriter(System.out);
//		for(int i = 0; i < num.size() - 1; i++) {
//			out.print(num.get(i));
//			out.print(" ");
//		}
//		out.flush();
		int t = num.getFirst();
		int k = num.size() - 1;
		//System.out.println(num.size());
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < k; i++) {
			sb.append(num.poll());
			sb.append(" ");
		}

		if(num.size() != 0) {
			System.out.print(sb.toString());
			System.out.println(num.poll());

		}else {
			System.out.print(t);
			System.out.println();
		}

	}
}


Measured memory_bytes: 324596
//code by 27.
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>
#include<memory.h>
using namespace std;
long long gcd(long long a,long long b)
{
	long long t1=a;
	long long t2=b;
	while(t1!=0)
	{
		if(t1<t2)swap(t1,t2);
		t1=t1%t2;
	}
	return t2;
}
int main()
{
	int n;
	cin>>n;
	long long s;
	cin>>s;
	long long t;
	for(int i=2;i<=n;i++)
	{
		cin>>t;
		s=s/gcd(s,t)*t;
	}
	cout<<s;
    return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint nCr(int n, int r) {
	mint ans = 1;
	for (int i=(r+1);i<=n;i++) ans *= i;
	mint div = 1;
	for (int i=1;i<=n-r;i++) div *= i;
	ans /= div;
	return ans;
}

int main() {
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(), a.end());
	mint ans = 0;
	vector<mint> count(n+1,0); // n_C_(k-1)
	count[k-1] = 1;
	for (int i=k;i<=n;i++) {
		count[i] = count[i-1] * (mint)(i) / (mint)(i-k+1);
	}
	rep(i,n) {
		//printf("%d\n",i);
		// max X = a[i]となる選び方
		mint num_max = 0;
		if (i >= k-1) {
			//num_max = nCr(i, k-1);
			num_max = count[i];
		}
		//printf("num_max:%d\n", num_max);
		ans += num_max * (mint)(a[i]);
		// min X = a[i]となる選び方
		mint num_min = 0;
		if (n-i>=k) {
			//num_min = nCr(n-i-1,k-1);
			num_min = count[n-i-1];
		}
		//printf("num_min:%d\n", num_min);
		ans -= num_min * (mint)(a[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

    int n, a; cin >> n >> a;
    int x[n];
    rep(i, n){
        cin >> x[i];
    }
    
    static ll dp[51][51][2501];

    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;

    reps(j, 1, n+1){
        reps(k, 0, n+1){
            reps(s, 0, 2501){
                dp[j][k][s] += dp[j-1][k][s];
                if(s >= x[j-1] && k > 0){
                    dp[j][k][s] += dp[j-1][k-1][s-x[j-1]];
                }
            }
        }
    }

    ll sum = 0;
    reps(k, 1, n+1){
            sum += dp[n][k][k*a];
    }
    cout << sum;

    // rep(j, 4){
    //     rep(k, 4){
    //         rep(s, 10){
    //             cout << j << k << s << " " << dp[j][k][s] <<endl;
    //         }
    //     }
    // }

    return 0;
}

Measured memory_bytes: 51072
import sys


def euc(n,m):
    if max(n,m)%min(n,m) == 0:
        return min(n,m)
    else:
        return euc(min(n,m), max(n,m)%min(n,m))


for line in sys.stdin:
    a,b = [int(i) for i in line.split()]
    print(euc(a,b),int(a*b/euc(a,b)))



Measured memory_bytes: 5600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<int> operator+(const vector<int> x, const vector<int> y) {
  vector<int> ret(x);
  rep(i, 0, ret.size()) ret[i] += y[i];
  return ret;
}
vector<int> operator-(const vector<int> x, const vector<int> y) {
  vector<int> ret(x);
  rep(i, 0, ret.size()) ret[i] -= y[i];
  return ret;
}
ostream &operator<<(ostream &os, const vector<int> &x) {
  os << x[0];
  rep(i, 1, x.size()) {
    os << ' ' << x[i];
  }
    return os;
  }

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

    enum mark { J, O, I };

    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<vector<int>>> v(
        N + 1, vector<vector<int>>(M + 1, vector<int>(3, 0)));
    rep(i, 0, N) {
      string s;
      cin >> s;
      rep(j, 0, M) {
        if (s[j] == 'J')
          v[i + 1][j + 1][J] = 1;
        else if (s[j] == 'O')
          v[i + 1][j + 1][O] = 1;
        else
          v[i + 1][j + 1][I] = 1;
      }
    }

    rep(i, 0, N + 1) rep(j, 1, M + 1) v[i][j] = v[i][j] + v[i][j - 1];
    rep(j, 0, M + 1) rep(i, 1, N + 1) v[i][j] = v[i][j] + v[i - 1][j];

    rep(i, 0, K) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      cout << v[c][d] + v[a - 1][b - 1] - v[a - 1][d] - v[c][b - 1] << endl;
    }

    return 0;
  }



Measured memory_bytes: 88176
#include <iostream>
#include <stdio.h>
#define N_MAX 500000
using namespace std;
//thik&solve easy 

int n;//num of input

class node{//将来を見据えて動的にしています
public:
	int *key;
	node *parent;
	node *l_chld;
	node *r_chld;

	node(int n){
		key =new int(n);
		
		parent = NULL;
		l_chld = NULL;
		r_chld = NULL;
	}

	~node(){
		delete key;
		delete parent;
		delete l_chld;
		delete r_chld;
	}
};

void insert(node **root,node *z){
	node *y;
	node *x;
	y = NULL;
	x = *root;
	while(x != NULL){
		y = x;
		if(*(z->key) < *(x->key))
			x = x->l_chld;
		else
			x = x->r_chld;
		z->parent = y;
	}

	if(y == NULL)
		*root = z;
	else if(*(z->key) < *(y->key))
		y->l_chld = z;
	else
		y->r_chld = z;
	
}

void preorder(node* u){
	node* pos;
	cout <<" " <<*(u->key);

	if(u->l_chld != NULL){
		pos = u->l_chld;
		preorder(pos);
	}

	if(u->r_chld != NULL){
		pos = u->r_chld;
		preorder(pos);
	}
}

void inorder(node* u){
	node* pos;
	
	if(u->l_chld != NULL){
		pos = u->l_chld;
		inorder(pos);
	}
	cout <<" " <<*(u->key);

	if(u->r_chld != NULL){
		pos = u->r_chld;
		inorder(pos);
	}
}

void print(node *u){
	inorder(u);
	cout <<endl;

	preorder(u);
	cout <<endl;

}

bool find(node* u,int k){
	node* pos;
	bool b;
	if(k == *(u->key)) return true;

	//if(u->l_chld == NULL && u->r_chld == NULL) return false;

	if(k < *(u->key)){
		if(u->l_chld == NULL) return false;
		pos = u->l_chld;
		b = find(pos,k);
	}else{
		if(u->r_chld == NULL) return false;
		pos = u->r_chld;
		b = find(pos,k);
	}
	return b;
}

int main(){
	char type[100];
	int z;
	node* root;
	root = NULL;

	node** rtroot = &root;

	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		scanf("%s",&type);
		if(type[0] == 'i'){
			scanf("%d",&z);

			//ポインタの作成(ちなみにndの寿命(=スコープ)はfor文の内部)
			node* nd;
			//新しく挿入するオブジェクトを作成し，ndの指す先に指定
			nd = new node(z);

			insert(rtroot,nd);
		}else if(type[0] == 'p'){
			print(root);
		}else{
			scanf("%d",&z);

			if(find(root,z))cout <<"yes" <<endl;
			else cout <<"no" <<endl;
		}
	}

	return 0;
}

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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define debug(x) cout << #x << ":" << x << endl;
#define debug2(x) for(auto a : x) cout << a << " "; cout << endl;
#define debug3(x) rep(i, sizeof(x)) cout << x[i] << " "; cout << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

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

template<class Abel = ll> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int N = limit, Abel SUM_UNITY = 0) {
        init(N, SUM_UNITY);
    }

    void init(int N = limit, Abel SUM_UNITY = 0) {
        par.resize(N);
        rank.resize(N);
        diff_weight.resize(N);
        for (int i = 0; i < N; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool unite(int x, int y, Abel w) { //weight[y] = weight[x] + w
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q;
    cin >> n >> q;
    UnionFind<> uf;

    rep(i, q) {
        ll query;
        cin >> query;
        if (query == 0) {
            ll x, y, z;
            cin >> x >> y >> z;
            uf.unite(x, y, z);
        } else {
            ll x, y;
            cin >> x >> y;
            if (uf.issame(x, y)) cout << uf.diff(x, y) << endl;
            else cout << "?\n";
        }
    }
    return 0;
}




Measured memory_bytes: 4420
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.E
{
    internal static class CR
    {
        public static string GetText() { return Console.ReadLine(); }
        public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long GetLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
    }

    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = CR.GetLongs();
            var X = inputs[0];
            var Y = inputs[1];
            var A = inputs[2];
            var B = inputs[3];
            var C = inputs[4];
            var p = CR.GetLongs();
            var q = CR.GetLongs();
            var r = CR.GetLongs();

            var oishisa = new List<long>();
            oishisa.AddRange(p.OrderByDescending(x => x).Take((int)X).ToList());
            oishisa.AddRange(q.OrderByDescending(x => x).Take((int)Y).ToList());
            oishisa.AddRange(r);

            return oishisa.OrderByDescending(x => x).Take((int)X + (int)Y).Sum();
        }
    }
}


Measured memory_bytes: 53960
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

struct Graph(T)
{
    T L, R;
    T[][] adj;

    this(T L, T R)
    {
        this.L = L;
        this.R = R;
        adj.length = L + R;
    }

    void add_edge(T u, T v)
    {
        adj[u] ~= v+L;
        adj[v+L] ~= u;
    }

    T maximum_matching()
    {
        bool[] visited;
        T[] meta;
        visited.length = L;
        meta.length = L + R;
        meta[] = -1;

        bool augment(T u) {
            if (visited[u]) return false;
            visited[u] = true;
            foreach (w; adj[u]) {
                auto v = meta[w];
                if (v < 0 || augment(v)) {
                    meta[u] = w;
                    meta[w] = u;
                    return true;
                }
            }
            return false;
        }

        auto match = 0;
        foreach (u; 0..L) {
            visited[] = false;
            if (augment(u)) ++match;
        }
        return match;
    }
}

void main()
{
    auto xye = readln.split.to!(int[]);
    auto X = xye[0];
    auto Y = xye[1];
    auto E = xye[2];

    auto G = Graph!int(X, Y);
    foreach (_; 0..E) {
        auto xy = readln.split.to!(int[]);
        G.add_edge(xy[0], xy[1]);
    }
    writeln(G.maximum_matching());
}


Measured memory_bytes: 3472
n=int(input())
#w,h,x,y,r=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
#素因数分解した結果を2次元配列にして返す
def prime_factorize(n):
    n_origin=n+0
    primelist=[]
    a=2
    while a*a<=n_origin:
        if n%a!=0:
            a+=1
            continue
        ex=0
        while n%a==0:
            ex+=1
            n=n//a
        primelist.append([a,ex])
        a+=1
    if n!=1:
        primelist.append([n,1])
    return primelist
dic={}
for i in range(1,n+1):
    pfs=prime_factorize(i)
    for pf in pfs:
        dic[pf[0]]=dic.get(pf[0],0)+pf[1]
#print(dic)
ans=1
mod=10**9+7
for v in dic.values():
    ans=(ans*(v+1))%mod
print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int sum = 0;

  for (int i = 1; i <= N; i++) {
    int l, r;
    cin >> l >> r;
    sum += (r-l+1);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	puts(a+b>=c?"Yes":"No");
}

Measured memory_bytes: 128
S = input()[::-1]
T = input()[::-1]
n = len(S);m = len(T)
a = []
for i in range(0, n - m + 1):
    f = 1
    s = S[i:i+m]
    for j in range(m):
        if s[j] not in ["?",T[j]]:
            f = 0
            break
    if f:
        a = S[:i] + T + S[i+m:]
        break

if a:
    print(a.replace('?','a')[::-1])
else:
    print('UNRESTORABLE')


Measured memory_bytes: 3064
A, B, K = map(int, input().split())


def kansuu(A, B, K):
    if A < K:
        K -= A
        A = 0
        if B < K:
            B = 0
            return A, B
        else:
            B -= K
            return A, B
    else:
        A -= K
        return A, B


a = kansuu(A, B, K)
print(a[0], a[1], sep=" ")

Measured memory_bytes: 3064
n = int(input()[-1])

if n == 2:   print("hon")
elif n == 4: print("hon")
elif n == 5: print("hon")
elif n == 7: print("hon")
elif n == 9: print("hon")
elif n == 0: print("pon")
elif n == 1: print("pon")
elif n == 6: print("pon")
elif n == 8: print("pon")
else:        print("bon")


Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
  string s; cin>>s;
  int m,c;m=c=0;
  for(int i=0;i<3;i++){
    if(s[i]=='S'){m=max(m,c);c=0;}
    else{c++;}
  }
  m=max(m,c);
  
  cout<<m;
  
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll solve() {
    ll L;
    cin >> L;
    vector<ll> A(L);
    for ( int i = 0; i < L; i++ ) {
        cin >> A[i];
    }
    ll INF = 1LL << 60;
    vector<vector<ll>> dp(L+1, vector<ll>(5, INF));
    for ( int i = 0; i < 5; i++ ) {
        dp[0][i] = 0;
    }
    for ( int i = 0; i < L; i++ ) {
        ll a = A[i];
        vector<ll> b(5);
        b[0] = b[4] = a;
        b[1] = b[3] = a > 0 ? a % 2 : 2;
        b[2] = (a+1) % 2;
        for ( int j = 0; j < 5; j++ ) {
            for ( int k = 0; k <= j; k++ ) {
                dp[i+1][j] = min(dp[i+1][j], dp[i][k] + b[j]);
            }
        }
    }
    ll ans = INF;
    for ( int i = 0; i < 5; i++ ) {
        ans = min(ans, dp[L][i]);
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323


#define TST 0

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int x,n;
    cin >> x >>n;
    if(n == 0){
        cout << x << endl;
        return 0;
    }
    vector<int> p(n);
    for(int i = 0 ; i < n;i++){
        cin >> p[i];
    }
    //sort(p.begin(), p.end());
    //vector<int>::iterator iter = lower_bound(p.begin(), p.end(), x);
    for(int i = 0;i < 200;i++){
        int x_lower = x-i;
        vector<int>::iterator lower = find(p.begin(), p.end(), x_lower);
        if(lower == p.end()){
            cout << x_lower << endl;
            return 0;
        }
        x_lower = x + i;
        lower = find(p.begin(), p.end(), x_lower);
        if(lower == p.end()){
            cout << x_lower << endl;
            return 0;
        }
    }


#if TST==1

#endif
}



Measured memory_bytes: 3632
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<vector<ll>> a(n-1, vector<ll>(3));
    for (int i=0; i<n-1; i++) {
        cin >> a.at(i).at(0) >> a.at(i).at(1) >> a.at(i).at(2);
    }
    a.push_back({0, 0, 1});
    for (int i=0; i<n; i++) {
        ll time = 0;
        for (int j=i; j<n; j++) {
            if (time < a.at(j).at(1)) {
                time = a.at(j).at(1);
            }
            if (time%a.at(j).at(2) != 0) {
                time += a.at(j).at(2) - time%a.at(j).at(2);
            }
            time += a.at(j).at(0);
        }
        cout << time << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    hs = list(map(int, input().split()))
    lower = float("-inf")
    ans = 0
    for h in hs:
        lower = max(lower, h)
        if lower <= h:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
# coding: utf-8

def Ser():
    S = input()
    for s in S:
        yield s

def main():
    S = []
    Si = ""
    for s in Ser():
        Si += s
        if len(S) == 0 or Si != S[-1]:
            S.append(Si)
            Si = ""
    print(len(S))

main()

Measured memory_bytes: 8296
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
int main() {
	vector<int> num(3); rep(i, 3)cin >> num[i];
	sort(num.rbegin(), num.rend());
	vector<int> d(3);
	int sum = 0;
	rep(i, 2) {
		d[i+1] = num[0] - num[i+1];
		sum += d[i + 1];
	}
	if (sum % 2 == 0) {
		cout << sum / 2 << endl;
		return 0;
	}
	else {
		cout << (sum + 3) / 2 << endl;
		return 0;
	}
}


Measured memory_bytes: 256
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# slist = "abcdefghijklmnopqrstuvwxyz"
N,M = map(int,input().split())
arrA = list(map(int,input().split()))
# arrA = np.array(input().split(),dtype=np.int64)

ans = max(N - sum(arrA),-1)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9880
#include <cstdio>
#include <cstring>

#include <vector>
#include <algorithm>

using namespace std;

#define NMAX 200000

static int n, dist[NMAX + 10];
static vector<int> G[NMAX + 10];
static bool f[NMAX + 10];

void dfs(int x, int fa) {
    for (int v : G[x]) if (v != fa) {
        dist[v] = dist[x] + 1;
        dfs(v, x);
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dist[1] = 1;
    dfs(1, 0);
    int u = 0;
    for (int i = 1; i <= n; i++) if (dist[i] > dist[u]) u = i;
    dist[u] = 1;
    dfs(u, 0);
    int v = 0;
    for (int i = 1; i <= n; i++) if (dist[i] > dist[v]) v = i;
    f[1] = true;
    for (int i = 3; i <= n; i++) f[i] = !f[i - 1] || !f[i - 2];
    puts(f[dist[v]] ? "First" : "Second");
    return 0;
}


Measured memory_bytes: 21504
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] x = new int[n];
    int[] y = new int[n];
    double d = 0.0;

    for (int i = 0; i < n; i++) {
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      for (int j = i+1; j < n; j++) {
        d += Math.sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
      }
    }

    System.out.println(d*2/n);
  }

}


Measured memory_bytes: 21844
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
vector<int>g[110000];
int v[110000][2];
void dfs(int a,int b){
	for(int i=0;i<g[a].size();i++){
		int to=g[a][i];
		if(!v[to][!b]){
			v[to][!b]=1;
			dfs(to,!b);
		}
	}
}
int main(){int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int p,q;
		scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	v[0][0]=1;
	dfs(0,0);
	int A=0;
	int B=0;
	for(int i=0;i<a;i++){
		if(v[i][0]&&v[i][1]){
			printf("%lld\n",(long long)a*(a-1)/2-b);
			return 0;
		}
		if(v[i][0])A++;
		else B++;
	}
	printf("%lld\n",(long long)A*B-b);
}

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

int main(void){
    vector<char> s(100000);
    int i, one_count, zero_count;

    i = 0;
    while((s[i] = getchar()) != '\n'){
        i++;    
    }
    s[i] = -1;

    i = 0;
    one_count = 0;
    zero_count = 0;
    while(s[i] != -1){
        if(s[i] != (i%2 ? '0' : '1')){
            one_count++;
        }
        if(s[i] != (i%2 ? '1' : '0')){
            zero_count++;
        }
        i++;
    }
    
    if(one_count > zero_count)  cout << zero_count << endl;
    else                        cout << one_count << endl;


    return 0;
}

Measured memory_bytes: 384
h, w = map(int, input().split())

ans = 10 ** 10
for i in range(1, h + 1):
    a = i * w
    b = (h - i) * (w // 2)
    c = ((h - i) * w) - b
    ans = min(ans, max(a, b, c) - min(a, b, c))
for i in range(1, w + 1):
    a = i * h
    b = (w - i) * (h // 2)
    c = ((w - i) * h) - b
    ans = min(ans, max(a, b, c) - min(a, b, c))
for i in range(1, h + 1):
    a = i * w
    b = ((h - i) // 2) * w
    c = ((h - i) * w) - b
    ans = min(ans, max(a, b, c) - min(a, b, c))
for i in range(1, w + 1):
    a = i * h
    b = ((w - i) // 2) * h
    c = ((w - i) * h) - b
    ans = min(ans, max(a, b, c) - min(a, b, c))
print(ans)


Measured memory_bytes: 42800
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

char mp[100][100];

int main()
{
	int n;cin >> n;
	int now = 0;
	
	REP(i,1000000)
	{
		now +=i;
		if(now >= n)
		{
			cout << i << endl;
			return 0;
		}
	}
	
	
	return 0;
}


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

int main(){
	vector<int> vec(5);
	for(int i = 0; i < 5; i++) {
    	cin >> vec.at(i);
        if(vec.at(i) == 0){
         cout << i+1 << endl;
        }       
    }
}

Measured memory_bytes: 3564
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static BigInteger MOD = BigInteger.valueOf((long) 1e9 + 7);

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] a = new int[n+1];
        int[] b = new int[n];

        long total = 0;
        for (int i=0; i <= n; i++)
            a[i] = in.nextInt();
        for (int i=0; i < n; i++)
            b[i] = in.nextInt();

        for (int i=0; i < n; i++) {
            int max = Math.min(a[i], b[i]);
            total += max;
            b[i] -= max;
            a[i] -= max;

            max = Math.min(a[i+1], b[i]);
            total += max;
            a[i+1] -= max;
        }

        out.println(total);
    }


}


Measured memory_bytes: 65600
#include<bits/stdc++.h>
using namespace std;
string s;
bool ok[101010];
int main()
{
	ok[0]=true;
	cin>>s;
	for(int i=0;i<=s.size()+1;i++)
	{
		if(i+5<=s.size() && s.substr(i,5)=="dream")
		{
			ok[i+5]=(ok[i+5] || ok[i]);
		}
		if(i+5<=s.size() && s.substr(i,5)=="erase")
		{
			ok[i+5]=(ok[i+5] || ok[i]);
		}
		if(i+7<=s.size() && s.substr(i,7)=="dreamer")
		{
			ok[i+7]=(ok[i+7] || ok[i]);
		}
		if(i+6<=s.size() && s.substr(i,6)=="eraser")
		{
			ok[i+6]=(ok[i+6] || ok[i]);
		}
	}
	if(ok[s.size()])
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

int N;
int L[111111],R[111111];

signed main(){
	cin>>N;
	rep(i,N)cin>>L[i]>>R[i];
	sort(L,L+N);reverse(L,L+N);

	sort(R,R+N);

	int ans=0;
	int sum=0;
	for(int i=0;i<N;i++){
		if(i==0||L[i]>R[0])chmax(ans,sum+L[i]*2);
		if(i==0||R[i]<L[0])chmax(ans,sum-R[i]*2);
		if(L[i]<R[i])continue;
		sum+=(L[i]-R[i])*2;
		chmax(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
import math

a, b, x = map(int, input().split())
if (a**2)*b/2 <= x:
	y = 2 * ((a**2) * b - x) / a**3
	print(math.degrees(math.atan(y)))
else:
	y = 2*x/((a)*(b**2))
	print(90-math.degrees(math.atan(y)))

Measured memory_bytes: 3060
#include <stdio.h>

int main () {
    int n;
    long long int L[101];
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%lld",L + i);
    }
    int ans = 0;
    long long int max, sum;

    for(int i=0; i<n; i++) {
        for(int j=i+1; j<n; j++) {
            for (int k=j+1; k<n; k++) {
                if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
                    // max 
                    if(n<3) break;
                    int max = L[i];
                    if (L[j] > max) max = L[j];
                    if (L[k] > max) max = L[k];
                    sum = L[i] + L[j] + L[k];
                    if (sum - max*2 > 0) ans ++;
                }
            }
        }
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1688