akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var s = cin.next();

            var ans = 0;
            var now = 0;
            for (int i = 0; i < n; i++)
            {
                now += s[i] == 'I' ? 1 : -1;
                ans = Math.Max(now, ans);
            }

            Console.WriteLine(ans);
        }
    }    

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}

Measured memory_bytes: 11092
{-# LANGUAGE OverloadedLists     #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Monad
import           Data.IORef
import           Data.Maybe
import qualified Data.Text     as T
import qualified Data.Text.IO  as T
import           GHC.Base
import           System.IO

import qualified Data.Array    as A
import qualified Data.IntMap   as I
import           Data.List
import qualified Data.Map      as M
import qualified Data.Set      as S
import qualified Data.Vector   as V

-- for IO
readT :: Read a => T.Text -> a
readT = read . T.unpack

getLineSpc :: Read a => IO [a]
getLineSpc = do
  t <- T.getLine
  let xs = map readT $ T.split (== ' ') t
  return xs

-- main
main :: IO ()
main = takahashisInformation

takahashisInformation :: IO ()
takahashisInformation = do
  c1 :: [Int] <- getLineSpc
  c2 :: [Int] <- getLineSpc
  c3 :: [Int] <- getLineSpc
  let [c11, c12 ,c13] = c1
      [c21, c22 ,c23] = c2
      [c31, c32 ,c33] = c3
      cond1 = c21 - c11 == c22 - c12 && c21 - c11 == c23 - c13
      cond2 = c31 - c11 == c33 - c13 && c31 - c11 == c32 - c12
  if cond1 && cond2
    then
    putStrLn "Yes"
    else
    putStrLn "No"

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

int main() {
  string s, t; cin >> s >> t;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != t[i]) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    int x[5];
    REP(i, 5) {
        cin >> x[i];
        if (x[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3608
#include<stdio.h>

#define MAX 2000000

int E,T[MAX+1];

void heap(int i){
  int lo,ro,bigest,temp;
  
  lo=2*i;
  ro=2*i+1;
  
  if(lo <= E && T[lo]>T[i]){
    bigest=lo;
  }
  
  else bigest=i;
  
  if(ro<=E && T[ro]>T[bigest]){
    bigest=ro;
  }
  
  if(bigest != i){
    temp=T[i];
    T[i]=T[bigest];
    T[bigest]=temp;
    heap(bigest);
  }
}





int main(){
  int i;
  
  scanf("%d",&E);


  for(i=1;i<=E;i++){
    scanf("%d",&T[i]);
  }

  for(i=E/2;i>=1;i--){
    heap(i);
  }

  for(i=1;i<=E;i++){
    printf(" %d",T[i]);
  }

  printf("\n");

  return 0;
}






Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

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

		int n = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		int sumAll = 0;

		for(int i = 1; i <= n; i++) {
			String iString = String.valueOf(i);
			int digitSum = 0;

			// 各桁の和を計算
			for(int j = 0; j < iString.length(); j++) {
				digitSum += iString.charAt(j) - '0';
			}

			// 各桁の和がA以上B以下であるか判定
			if(a <= digitSum && digitSum <= b)
				sumAll += i;
		}
		System.out.println(sumAll);
		scan.close();

	}

}

Measured memory_bytes: 23636
fn read_lines() -> Vec<String> {
    use std::io::Read;

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    return buf.lines().map(|e| e.to_string()).collect::<Vec<_>>();
}

static mut COMP_COUNT: u32 = 0;

fn main() {
    let input = read_lines();
    let n: usize = input[0].parse().unwrap();
    let mut series = input[1].split_whitespace().map(|s| s.parse().unwrap()).collect::<Vec<u32>>();

    merge_sort(&mut series, 0, n);

    println!("{}", series.into_iter().map(|e| format!("{}", e)).collect::<Vec<String>>().join(" "));
    unsafe {
        println!("{}", COMP_COUNT);
    }
}

fn merge_sort(series: &mut Vec<u32>, left: usize, right: usize) {
    if 1 >= right - left {
        // 対象の配列の長さが1以下なら何もしない
    } else {
        let mid = (left + right) / 2;
        merge_sort(series, left, mid);
        merge_sort(series, mid, right);
        merge(series, left, mid, right);
    }
}

fn merge(series: &mut Vec<u32>, left: usize, mid: usize, right: usize) {
    let mut ls = series[left..mid].to_vec();
    ls.push(std::u32::MAX); // 番兵
    let mut rs = series[mid..right].to_vec();
    rs.push(std::u32::MAX); // 番兵

    let mut li = 0;
    let mut ri = 0;
    for i in left..right {
        unsafe {
            COMP_COUNT += 1;
        }
        if ls[li] > rs[ri] {
            series[i] = rs[ri];
            ri += 1;
        } else {
            series[i] = ls[li];
            li += 1;
        }
    }
}


Measured memory_bytes: 37656
using System;
using System.IO;
using System.Collections.Generic;

namespace _132
{
    class Program
    {
        static void Main(string[] args)
        {
            solve_132C();
        }


        public static void solve_132C()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] test = Console.ReadLine().Split(' ');

            int[] p = Array.ConvertAll(test, int.Parse);
            Array.Sort(p);

            int midL = p.Length / 2 - 1;

            int midR = p.Length / 2;

            int k = p[midR] - p[midL];
            Console.WriteLine(k);
        }

        public static void solve_132B()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] test = Console.ReadLine().Split(' ');

            int[] p = Array.ConvertAll(test, int.Parse);
            int count = 0;
            for (int i = 1; i < n; i++)
            {
                if (i < n - 1 && ((p[i] > p[i - 1] && p[i] < p[i + 1]) || (p[i] > p[i + 1] && p[i] < p[i - 1])))
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
        public static void solve_132A()
        {
            string a = Console.ReadLine();

            char[] str = a.ToCharArray();

            Array.Sort(str);
            
            string ansewr = "Yes";
            if (str[0] != str[1] || str[2] != str[3] || str[0] == str[2])
            {
                ansewr = "No";
            }

            Console.WriteLine(ansewr);
        }
    }
}


Measured memory_bytes: 18912
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

int main()
{

    int n, m;
    cin >> n >> m;

    map<int, int> mp;

    for (int i = 0; i < n; i++)
    {
        int aux;
        cin >> aux;
        mp[aux]++;
    }

    for (int i = 0; i < m; i++)
    {
        int B, C;
        cin >> B >> C;
        mp[C] += B;
    }

    int picked = 0;
    long long int sum = 0;
    for (auto i = mp.rbegin(); i != mp.rend(); i++)
    {
        sum += (long long)i->first * min(i->second, n - picked);
        picked += min(i->second, n - picked);
    }

    cout << sum;
}

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

int n, x;
int cnt = 0;

int main() {
  while(1){
    cin >> n >> x;
    if(n == 0 && x == 0) break;

    for(int i = 1; i <= n; i++){
      for(int j = i + 1; j <= n; j++){
        for(int k = j + 1; k <= n; k++){
          if (i + j + k == x){
             cnt++;
           }
        }
      }
    }
    cout << cnt << endl;
    cnt = 0;
  }
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
  string T;
  T="Yes";
    int len = S.size();
    for(int i = 0; i < (len-1)/2; i++){
        if(S.at(i) != S.at(((len-2)/2)-i) || S.at(i) != S.at(len-1-i)) {
          T="No";
          cout << "No" << endl;
          break;
        }
    }
      if(T=="Yes"){
       cout << "Yes" << endl;
       return 0;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> v(n);
    loop(i,0,n){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    ll p = 1, x= 1E18;
    loop(i,0,n){
        if(p == 0)
            break;
        ll y = x/p;
        if(v[i] > y){
            p = -1;
            break;
        }
        else p = p*v[i];
    }
    cout<<p<<endl;

}   

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template<class T> inline void YES(T condition) { 
    if(condition) cout << "YES" << endl;
    else cout << "NO" << endl;
}
template<class T> inline void Yes(T condition) {
    if(condition) cout << "Yes" << endl;
    else cout << "No" << endl;
}
template<class T> T gcd(T a, T b) {
    if(a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); }
    else { return a; }
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}

const int MOD = 2019;
long long qpow(long long a, long long b) {
    if (b == 0) return 1;
    long long res = 1;
    while (b) {
        if (b & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

int lookup[2020];
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    LL cur = 0;
    lookup[cur]++;
    int n = s.size();
    int ans = 0;
    int idx = 0;
    for (int i = n - 1; i >= 0; i--, idx++) {
        int num = s[i] - '0';
        cur = (qpow(10, idx) * num + cur) % MOD;
        ans += lookup[cur];
        lookup[cur]++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3768
a,b,c,x,y=map(int,input().split())
if a+b<=2*c: print(a*x+b*y)
else:
    ans=min(x,y)*2*c
    dif=abs(x-y)
    if x>y:
        if a>=2*c:
            ans+=2*dif*c
        else:
            ans+=a*dif
    else:
        if b>=2*c:
            ans+=2*dif*c
        else:
            ans+=b*dif
    print(ans)

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

namespace ABC141_C
{
    class Program
    {
        static void Main(string[] args) {
            //以下は解説を見て実装した部分
            string[] input = Console.ReadLine().Split();
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            int q = int.Parse(input[2]);

            int[] ansCount = new int[n];
            for(int i = 0; i < n; i++) {
                ansCount[i] = k - q;
            }
            for(int i = 0; i < q; i++) {
                int answerIndex = int.Parse(Console.ReadLine()) - 1;
                ansCount[answerIndex]++;
            }
            for(int i = 0; i < n; i++) {
                if(ansCount[i] > 0) {
                    Console.WriteLine("Yes");
                } else {
                    Console.WriteLine("No");
                }
            }

            //以下は自分で実装した部分

            //string[] input = Console.ReadLine().Split();
            //int n = int.Parse(input[0]);
            //int k = int.Parse(input[1]);
            //int q = int.Parse(input[2]);

            //int[] ansCount = new int[n];
            //for (int i = 0; i < q; i++) {
            //    int ansIndex = int.Parse(Console.ReadLine()) - 1;
            //    ansCount[ansIndex]++;
            //}

            //for (int index = 0; index < n; index++) {
            //    int count = 0;
            //    for (int j = 0; j < n; j++) {
            //        if (j != index) {
            //            count += ansCount[j];
            //        }

            //        if (count >= k) break;
            //    }

            //    if (count >= k) {
            //        Console.WriteLine("No");
            //    } else {
            //        Console.WriteLine("Yes");
            //    }
            //}
        }
    }
}

Measured memory_bytes: 17600
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N = 0, M =0;
    cin(N);cin(M);

    vll S(M), C(M); 
    REP(i,M) cin >> S[i] >> C[i];


    //本文
    REP(i,1000){
        string str = to_string(i);
        if(N!=str.size()) continue;
        bool ok = true;
        REP(j,M){
            ll k = S[j]-1;
            string l = to_string(C[j]);
            char m = l[0];
            if(str[k]-'0'!=C[j]){ok = false;}
        }
        if(ok){cout << str;return 0;}
    }

    //出力
    cout << -1 << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

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

#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}

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



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

    if(S == "SUN"){
        cout << 7 << endl;
    }

    else if(S == "MON"){
        cout << 6 << endl;
    }

    else if(S == "TUE"){
        cout << 5 << endl;
    }
    
    else if(S == "WED"){
        cout << 4 << endl;
    }
    
    else if(S == "THU"){
        cout << 3 << endl;
    }
    
    else if(S == "FRI"){
        cout << 2 << endl;
    }
    
    else if(S == "SAT"){
        cout << 1 << endl;
    }

}


Measured memory_bytes: 3584
#include<stdio.h>
#include<math.h>

int main(){
  int n;
  int counter = 0;
  scanf("%d\n",&n);
  for(int i=0;i<n;i++){
    int num;
    scanf("%d\n",&num);
    //sqrtはfloatを返す。1で割っても同じ
    int end = sqrt(num)+1;
    if(num==2 || num==3){
      counter ++;
    }else{
      for(int j=2; j<end; j++){
        if(num%j==0){
          break;
        }
        if(j==end-1){
          counter ++;
        }
      }
    }
  }
  printf("%d\n", counter);
}



Measured memory_bytes: 2148
s = input()
t = input()

ls = len(s)
lt = len(t)

if ls == lt:
    tmp = s[0:lt]
    score = 0
    for j in range(lt):
        if tmp[j] != t[j]:
            score += 1
    print(score)
    exit()

ans = 10000000
for i in range(ls - lt):
    tmp = s[i:i+lt]
    score = 0
    for j in range(lt):
        if tmp[j] != t[j]:
            score += 1
    ans = min(ans, score)

print(ans)

Measured memory_bytes: 67668
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,m,a[N],tr[N],ans[N],vis[N];
struct node
{
    int l,r,num;
}p[N];
bool cmp(node s1,node s2)
{return s1.r<s2.r;}
void add(int i,int k)
{
    while(i<=n)
    {
        tr[i]+=k;
        i+=(i&-i);
    }
}
int sum(int i)
{
    int s=0;
    while(i)
    {
        s+=tr[i];
        i-=(i&-i);
    }
    return s;
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=m;i++)
    {
        cin>>p[i].l>>p[i].r;
        p[i].num=i;
    }
    sort(p+1,p+m+1,cmp);
    int L=1;
    for(int i=1;i<=m;i++)
    {
        int num=p[i].num;
        int l=p[i].l;
        int r=p[i].r;
        for(int j=L;j<=r;j++)
        {
            int x=a[j];
            if(vis[x])add(vis[x],-1);
            add(j,1);
            vis[x]=j;
        }
        L=r+1;
        ans[num]=sum(r)-sum(l-1);
    }
    for(int i=1;i<=m;i++)
        printf("%d\n",ans[i]);
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int c=0, t=N;
    while(t > 0){
        c += t%10;
        t /= 10;
    }
    if (N % c == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))
import sys
for i in range(N):
    for l in range(N-3*i):
        if P[l] <= A:
            del P[l]
            break
        elif l == N-3*i-1:
            print(i)
            sys.exit()
    for l in range(N-3*i-1):
        if A < P[l] <= B:
            del P[l]
            break
        elif l == N-3*i-2:
            print(i)
            sys.exit()
    for l in range(N-3*i-2):
        if B < P[l]:
            del P[l]
            break
        elif l == N-3*i-3:
            print(i)
            sys.exit()
    if not P:
        print(i+1)
        sys.exit()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <map>
#include <list>
#include <cstdlib>

using namespace std;

typedef pair<int, int> P;

#define MAX 128

int main()
{
	while(1) {
		int n;
		bool know[MAX][MAX] = {false};
		bool leak[MAX];

		for(int i = 0; i < MAX; i++) {
			leak[i] = true;
		}
		
		scanf("%d", &n);
		if(!n) break;
		for(int i = 1; i <= n; i++) {
			int m;
			scanf("%d", &m);
			while(m--) {
				int p;
				scanf("%d", &p);
				know[i][p] = true;
			}
		}

		int k;
		scanf("%d", &k);
		while(k--) {
			int l;
			scanf("%d", &l);
			for(int i = 1; i <= n; i++) {
				if(!leak[i]) continue;
				if(!know[i][l]) {
					leak[i] = false;
				}
			}
		}

		int ans = -1;
		for(int i = 1; i <= n; i++) {
			if(!leak[i]) continue;
			if(ans > 0) {
				ans = -1;
				break;
			}
			ans = i;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1212
/*
[soundhound2018-summer-qual] A - F
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

char solve(int a, int b) {
    if (a + b == 15) {
        return '+';
    } else if (a * b == 15) {
        return '*';
    }
    return 'x';
}

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

    cout << solve(a, b) << endl;

    return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b >= c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

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

a,b,x=map(int, input().split())

c=a//x
cc=b//x
if a%x==0:
    cc+=1
print(cc-c)

Measured memory_bytes: 9188
while True:
	try:
		msg = map(str, raw_input().split())
		ans = []
		for word in msg:
			if word[-1] == "," or word[-1] == ".":
				word = word[:-1]
			if 3 <= len(word) <= 6:
				ans.append(word)
		print " ".join(map(str, ans))
	except:
		break

Measured memory_bytes: 4212
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))
K=min(N,K)

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:i])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])

Measured memory_bytes: 130444
#include <iostream>

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

using namespace std;

int main()
{
    int h1,h2,m1,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int ans = h2*60+m2-(h1*60+m1);
    
    cout << ans-k << endl;
    

    return 0;
}

Measured memory_bytes: 3636
#if 1
#pragma GCC optimize "O3"
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <random>
#include <cassert>
#include <cmath>
#include <cstring>
#include <chrono>
using namespace std;
using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using f32 = float; using f64 = double;
template <class T> inline T sq(T a) { return a * a; }
template <class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; }
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
void _u() { cerr << endl; } template <class H, class... T> void _u(H&& h, T&&... t) { cerr << h << ", "; _u(move(t)...); }
#define _polyfill(v) v
#define _overload3(a, b, c, d, ...) d
#define _rep3(i, a, b) for (i32 i = i32(a); i < i32(b); ++i)
#define _rep2(i, b) _rep3(i, 0, b)
#define _rep1(i) for (i32 i = 0; ; ++i)
#define rep(...) _polyfill(_overload3(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__))
#define A(a) begin(a), end(a)
#define S(a) i32((a).size())
#define U(...) { cerr << #__VA_ARGS__ << ": "; _u(__VA_ARGS__); }
#define lin U(__LINE__)
#define exi exit(0);
#endif

class timer {
    vector<timer> timers;
    int n = 0;
public:
    double limit = 2.95;
    double t = 0;
    timer() {}
    timer(int size) : timers(size) {}
    bool elapses() const {
        return time() - t > limit;
    }
    void measure() {
        t = time() - t;
        ++n;
    }
    void measure(char id) {
        timers[id].measure();
    }
    void print() {
        if (n % 2)
            measure();
        for (int i = 0; i < 128; ++i) {
            if (timers[i].n)
                cerr << (char)i << ' ' << timers[i].t << 's' << endl;
        }
        cerr << "  " << t << 's' << endl;
    }
    static double time() {
#ifdef LOCAL
        return __rdtsc() / 3.3e9;
#else
        using namespace std::chrono;
        return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() / 1000.0;
#endif
    }
} timer(128);

constexpr bool Deterministic = 0;
class rando {
    unsigned y;
public:
    rando(unsigned y) : y(y) {}
    unsigned next() {
        return y ^= (y ^= (y ^= y << 13) >> 17) << 5;
    }
    int next(int b) {
        return next() % b;
    }
    int next(int a, int b) {
        return next(b - a) + a;
    }
    double nextDouble(double b = 1) {
        return b * next() / 4294967296.0;
    }
    double nextDouble(double a, double b) {
        return nextDouble(b - a) + a;
    }
    int operator() (int b) {
        return next(b);
    }
} rando(Deterministic ? 2463534242 : random_device()());

i32 main() {
    i32 a, b;
    cin >> a >> b;
    if (a <= 5) {
        cout << 0 << endl;
    } else if (a <= 12) {
        cout << b / 2 << endl;
    } else {
        cout << b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
  char letter;
  int number;
} card;

int partition(card a[], int p, int r)
{
  card x = a[r];
  int i = p-1;
  for (int j = p; j <= r-1; j++) {
    if (a[j].number <= x.number) {
      i++;
      card temp = a[i];
      a[i] = a[j];
      a[j] = temp;
    }
  }
  card temp = a[i+1];
  a[i+1] = a[r];
  a[r] = temp;
  return i+1;
}

void quicksort(card a[], int p, int r) {
  if (p < r) {
    int q = partition(a, p, r);
    quicksort(a, p, q-1);
    quicksort(a, q+1, r);
  }
}

void merge(card a[], int left, int mid, int right) {
  int n1, n2, i;
  card l[100000], r[100000];
  n1 = mid - left;
  n2 = right - mid;
  for (i = 0; i < n1; i++)
    l[i] = a[left+i];
  for (i = 0; i < n2; i++)
    r[i] = a[mid+i];
  l[n1].number = 2000000000;
  r[n2].number = 2000000000;
  i = 0;
  int j = 0;
  int k;
  for (k = left; k < right; k++) {
    if (l[i].number <= r[j].number) {
      a[k] = l[i++];
    } else {
      a[k] = r[j++];
    }
  }
}

void mergesort(card a[], int left, int right) {
  if (left+1 < right) {
    int mid = (left + right) / 2;
    mergesort(a, left, mid);
    mergesort(a, mid, right);
    merge(a, left, mid, right);
  }
}

int main(void)
{
  int n, i, v, stable = 1;
  char a[10];
  card s[100000], t[100000];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %d", a, &v);
    s[i].letter = t[i].letter = a[0];
    s[i].number = t[i].number = v;
  };
  quicksort(s, 0, n-1);
  mergesort(t, 0, n);
  for (i = 0; i < n; i++) {
    if (s[i].letter != t[i].letter) {
      puts("Not stable");
      stable = 0;
      break;
    } 
  }
  if (stable == 1)
    puts("Stable");
  for (i = 0; i < n; i++)
    printf("%c %d\n", s[i].letter, s[i].number);
  return 0;
}



Measured memory_bytes: 4176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class A { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		var num = GetLongs(5);
		var k = GetLong();
		for(long i = 0; i < 5; i++)
		{
			for(long j = 0; j < 5; j++)
			{
				if(Abs(num[i] - num[j]) > k)
				{
					WriteLine(":(");
					return;
				}
			}
		}
		WriteLine("Yay!");
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 11348
#coding:utf-8
import sys

sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

def index(a,b):
    return str(min(a,b)) + "," +  str(max(a, b))

def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    H, W = LMIIS()
    s = [[] for _ in range(H+2)]
    s[0] = "#" * (W+2)
    s[H+1] = "#" * (W+2)
    for i in range(1, H+1):
        s[i] = "#" + input() + "#"

    g = [[] for _ in range(H*W)]
    for i in range(1, H+1):
        for j in range(1, W+1):
            if s[i][j] == "#":
                g[(i-1)*W + j -1] = [-1]
            else:
                if s[i-1][j] == ".":
                    g[(i-1)*W + j -1].append((i-2)*W + j - 1)
                if s[i][j-1] == ".":
                    g[(i-1)*W + j -1].append((i-1)*W + j - 2)
                if s[i+1][j] == ".":
                    g[(i-1)*W + j -1].append(i*W + j - 1)
                if s[i][j+1] == ".":
                    g[(i-1)*W + j -1].append((i-1)*W + j)


    ans = 0
    for i in range(H*W):
        if g[i][0] == -1:
            continue
        m = [-1] * (H*W)
        m[i] = 0
        q = g[i]
        l = 1
        while len(q) > 0:
            tmp = []
            for a in q:
                m[a] = l
                for b in g[a]:
                    if m[b] == -1 and not b in tmp:
                        tmp.append(b)
                    else:
                        m[b] = min(l+1, m[b])

            l += 1
            q = tmp[:]

        ans = max(ans, max(m))
    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 43628
#include <stdio.h>
int main(void){
    int n, a, b, total_a, total_b;
    while(1){
        scanf("%d", &n);
        if(n == 0){
            break;
        }
        total_a = 0;
        total_b = 0;
        for(int i=1; i<=n; i++){
            scanf("%d %d", &a, &b);
            if(a > b){
                total_a += a + b;
            }
            else if(b > a){
                total_b += a + b;
            }
            else{
                total_a += a;
                total_b += b;
            }
        }
        printf("%d %d\n", total_a, total_b);
    }
    return 0;
}



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

const int mod = 1000000007;

int main(){
    int n;
    string x;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i, n) cin >> s[i] >> t[i];
    cin >> x;
    int id;
    rep(i,n){
        if(s[i] == x){
            id = i;
        }
    }
    int ans = 0;
    for (int i = id + 1; i < n; i++){
        ans += t[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, S=0;
  cin >> N;
  for(int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    S+=(r-l+1);
  }
  cout << S << endl; 
}

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

int main() {
  int N;
  int fX;
  int t;
  cin >> N;

  fX = N % 10;
  for (int i = 1; i <= 8; i++)
  {
    t = 1;
	for (int j = 0; j < i; j++)
    {
	  t = 10 * t;
    }
    //cout << "t = " << t << endl;
    //cout << "fX = " << N / t % 10 << endl;
    fX += N / t % 10;
  }
  //cout << fX << endl;
  if (N % fX == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

ll n, m;

struct edge{
	ll to, cost;
};

ll pre[110];

int d[110];
vector<edge> G[110];

void djikstra(int start){
	fill(d, d + 110, INF);
	fill(pre, pre + 110, -1);
	d[start] = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0, start));

	while (!que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;

		if (d[v] < p.first)continue;//更新する必要のない点

		for (int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				pre[e.to] = v;
				que.push({ d[e.to], e.to });
			}
		}
	}
	//REP(i, 4){
	//	cout <<"!"<< d[i] << endl;
	//	cout << pre[i] << endl;
	//}
	//cout << endl;
}

bool ans[110][110];

int main(){
	cin >> n >> m;
	REP(i, m){
		ll a, b, c;
		cin >> a >> b >> c;
		G[a].push_back({ b, c });
		G[b].push_back({ a, c });
		ans[a][b] = 1;
		ans[b][a] = 1;
	}
	REP(i, n + 1){
		djikstra(i);
		FOR(j, i + 1, n + 1){
			for (ll v = j; pre[v] != -1; v = pre[v]){
				ans[v][pre[v]] = 0;
				ans[pre[v]][v] = 0;
			}
		}
	}
	ll res = 0;
	REP(i, n + 1){
		FOR(j, i + 1, n + 1){
			if (ans[i][j]){
				res++;
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%2==0)
    {
        double t=n;
        cout<<(t/2.0)/t;
    }
    else
    {
        double t=((n+1.0)/2.0)/n;
        cout<<t;
    }
}


Measured memory_bytes: 3728
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, k;
int succ[61][200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> succ[0][i];
	
	for(int i = 1; i <= 60; i++){
		for(int j = 1; j <= n; j++) succ[i][j] = succ[i-1][succ[i-1][j]];
	}
	
	llint ans = 1;
	for(int i = 0; i < 60; i++){
		if(k & (1LL<<i)) ans = succ[i][ans];
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 51308
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0) {
            cout << " " << i;
            continue;
        }
        int j = i;
        while (j) {
            if (j % 10 == 3) break;
            j /= 10;
        }
        if (j % 10 == 3) cout << " " << i;
    }
    cout << endl;
}


Measured memory_bytes: 3060
import math

r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(raw_input())
    if not n:
        break
    i, num, sum = 0, 0, 0
    while num < n:
        if p[i] == 1:
            num += 1
            sum += i+1
        i += 1
    print sum

Measured memory_bytes: 6692
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;

int main() {
    ll N,M,K,cnt;
    cin>>N>>M>>K;
    rep0(i,N+1){
        rep0(j,M+1){
            cnt=0;
            cnt+=i*M;
            if(j>=1){cnt+=j*N-2*j*i;}
            //cout<<i<<" "<<j<<" "<<cnt<<endl;
            if(cnt==K){cout<<"Yes"<<endl; break;}
        }
        if(cnt==K){break;}
    }
    if(cnt!=K){cout<<"No"<<endl;}
}



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

using namespace std;
int main(){

	int N; cin >> N;
	map<int, int>M;
	for (int i = 0; i < N; i++){
		int tmp; cin >> tmp;
		M[tmp]++;
	}
	int ans = 0;
	for (auto it = M.begin(); it != M.end(); it++){
		if (it->second % 2 == 1)
			ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <fstream>
#include <numeric>


using namespace std;

#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b


long long int X;

int main() {

    cin >> X;

    long long int X0 = 100;

    long long int cnt = 0;
    while(1)
    {
        cnt++;
        X0 *= 1.01;

        if (X0 >= X)
        {
            cout << cnt << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
	double w,h,x,y;
	int flag=0;
	cin >> w >> h >> x >> y;
	if(w/2==x && h/2==y) flag=1;
	cout << w*h/2 << ' ' << flag << '\n';
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int64, n + 1)
	b := make([]int64, n)
	for i := 0; i < n+1; i++ {
		fmt.Scanf("%d", &a[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
	}
	count := int64(0)
	for i := 0; i < n; i++ {
		if a[i] > b[i] {
			count += b[i]
			b[i] = 0
			a[i] -= b[i]
		} else {
			count += a[i]
			b[i] -= a[i]
			a[i] = 0
		}
		if a[i+1] > b[i] {
			count += b[i]
			a[i+1] -= b[i]
		} else {
			count += a[i+1]
			a[i+1] = 0
		}
	}
	fmt.Println(count)
}


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

class Main{
    public static void main(String[] args){
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String line;
	int energy,x,y,z,conse;
	int barrier,maxb;
	try{
	    while(0!=(conse=Integer.valueOf(br.readLine()))){
		maxb = 1000000;
		if(Math.pow(z=(int)Math.cbrt(conse),3.0)<=conse&&z>1.0){
		    barrier = z;
		}else {
		    z = 0;
		    barrier = 0;
		}
		do{
		    energy = conse-(z*z*z);
		    if(Math.pow(y=(int)Math.sqrt(energy),2.0)<=energy&&y>1.0){
			energy-=(y*y);
		    }else y = 0;
		    x = energy;
		    barrier = x+y+z;
		    if(barrier<maxb){
			maxb = barrier;
		    }
		    z--;

		}while(z>=0);
		System.out.println(Integer.toString(maxb));

	    }
	}
	catch(Exception e){
	    System.exit(0);
	}
    }
}

Measured memory_bytes: 20492
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = 1 << 30;
// static const ll INF = 1LL << 62;
// --------------------------------------------------------

static const int MAX_N = 200000;
using mint = modint998244353;
vector<mint> base(MAX_N + 1);
struct S {
    mint x; int d;
};
struct F {
    mint D;
};
S op(S a, S b) { return S{a.x * mint(10).pow(b.d) + b.x, a.d + b.d}; }
S e() { return S{0, 0}; }
S mapping(F f, S a) { return (f.D == 0) ? a : S{base[a.d] * f.D, a.d}; }
F composition(F f, F g) { return (f.D == 0) ? g : f; }
F id() { return F{mint(0)}; }

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

    int N, Q; cin >> N >> Q;
    base[0] = 0;
    FOR(i,1,N+1) base[i] = base[i-1] + mint(10).pow(i-1);

    lazy_segtree<S,op,e,F,mapping,composition,id> seg(N);
    REP(i,N) {
        seg.set(i, S{mint(1), 1});
    }

    REP(_, Q) {
        int L, R; cin >> L >> R;
        ll D; cin >> D;
        seg.apply(L-1, R, F{mint(D)});
        cout << seg.all_prod().x.val() << '\n';
    }

    return 0;
}


Measured memory_bytes: 10544
//abc059_b.cpp
//Tue Oct 30 21:38:05 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	if (a.size() > b.size()){
		cout << "GREATER" << endl;
	}else if (a.size() < b.size()){
		cout << "LESS" << endl;
	}else {
		int flag = 0;
		for (int i=0;i<a.size();i++){
			if (a[i]>b[i]){
				cout << "GREATER" << endl;
				flag = 1;
				break;
			}else if (a[i]<b[i]){
				cout << "LESS" << endl;
				flag = 1;
				break;
			}
		}
		if (flag == 0){
			cout << "EQUAL" << endl;
		}
	}
}

Measured memory_bytes: 256
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
n,k = map(int,input().split())
a = list(map(int,input().split()))
r = a[0]
for i in range(n):
    r = gcd(r,a[i])
if max(a) < k:
    print('IMPOSSIBLE')
elif max(a) == k:
    print('POSSIBLE')
else:
    if (max(a) - k ) % r == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

Measured memory_bytes: 14252