akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

struct node{
  int num;
  std::vector<int> child;
};
int main(int argc, char const *argv[]) {
  int N, M, a, b;
  std::cin >> N >> M;
  std::vector<node> nd(N+1);
  std::vector<bool> checked(N+1, false);
  for(int i=1;i<=N;i++) nd[i].num = i;
  for(int i=0;i<M;i++){
    std::cin >> a >> b;
    nd[a].child.push_back(b);
    nd[b].child.push_back(a);
  }
  int now = 1;
  bool flag = true;
  checked[now] = true;
  std::vector<int> ans;
  while(flag){
    ans.push_back(now);
    for(int i=0;i<nd[now].child.size();i++){
      if(checked[nd[now].child[i]]==false){
        now = nd[now].child[i];
        checked[now] = true;
        break;
      }else if(i==nd[now].child.size()-1){
        flag = false;
      }
    }
  }
  flag = true;
  std::vector<int> ans_pre;
  now = 1;
  while(flag){
    ans_pre.push_back(now);
    for(int i=0;i<nd[now].child.size();i++){
      if(checked[nd[now].child[i]]==false){
        now = nd[now].child[i];
        checked[now] = true;
        break;
      }else if(i==nd[now].child.size()-1){
        flag = false;
      }
    }
  }
  std::cout << ans.size() + ans_pre.size() - 1 << '\n';
  for(int i=ans_pre.size()-1;i>0;i--) std::cout << ans_pre[i] << " ";
  for(int i=0;i<ans.size();i++) std::cout << ans[i] << (i==ans.size()-1?"\n":" ");
  return 0;
}


Measured memory_bytes: 7544
#include "bits/stdc++.h"
using namespace std;

int main() {

	int N, M;
	cin >> N;
	vector<string> s(N);

	for (int i = 0;i < N;i++) {
		cin >> s.at(i);
	}
	cin >> M;
	vector<string> t(M);
	for (int i = 0;i < M;i++) {
		cin >> t.at(i);
	}

	vector<int> value(N);

	for (int i = 0;i < N;i++) {
		for (int j = 0;j < N;j++) {
			if (s.at(i) == s.at(j))
				value.at(i)++;
		}
	}

	for (int i = 0;i < N;i++) {
		for (int j = 0;j < M;j++) {
			if (s.at(i) == t.at(j))
				value.at(i)--;
		}
	}

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

	if (value.at(N - 1) >= 0)
		cout << value.at(N - 1);

	else
		cout << 0;


}


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

namespace AtCoder_Project_CSharp
{
    class Program
    {
        static bool IsOk(IEnumerable<char> ie, string t)
        {
            var s = (ie.ToArray());
            for (int i = 0; i < t.Length; i++)
            {
                if (s[i] != '?')
                {
                    if (s[i] != t[i])
                    {
                        return false;
                    }
                }
            }
            return true;
        }
        static void Main(string[] args)
        {
            var s = (Console.ReadLine());
            var t = (Console.ReadLine());

            bool isUsedKeyword = false;

            s = new string(s.Reverse().ToArray());
            t = new string(t.Reverse().ToArray());

            var ans = s.ToCharArray();
            for (int i = 0; i < s.Length; i++)
            {

                var ans_ = ans;
                if (i + t.Length > s.Length) break;
                if (IsOk(s.Substring(i, t.Length), t))
                {
                    isUsedKeyword = true;
                    for (int j = 0; j < t.Length; j++)
                    {
                        ans_[i + j] = t[j];
                    }
                    ans = ans_;
                    break;
                }
            }

            if (!isUsedKeyword)
            {
                Console.WriteLine("UNRESTORABLE");
                return;
            }
            for (int i = 0; i < ans.Length; i++)
            {
                if (ans[i] == '?')
                {
                    ans[i] = 'a';
                }
            }
            Console.WriteLine(ans.Reverse().ToArray());
        }
    }
}


Measured memory_bytes: 13268
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){var e=[t.in(),t.in()];e.sort(function(t,e){return t-e}),1==e[0]&&2==e[1]?console.log(3):2==e[0]&&3==e[1]?console.log(1):console.log(2)}}]);


Measured memory_bytes: 21064
h, w = map(int,input().split())
l = list(sorted([h,w]))
hh = l[0]
ww = l[1]
kouho_1 = 9999999999999999999999999999
kouho_2 = 9999999999999999999999999999
kouho_3 = 9999999999999999999999999999
kouho_4 = 9999999999999999999999999999

for i in range(1,hh):
    a = i * ww
    b = ((hh - i) // 2) * ww
    c = hh * ww - (a + b) 
    
    mi_1 = min(a,b,c)
    ma_1 = max(a,b,c)
    
    if ma_1 - mi_1 <   kouho_1 :
        kouho_1 =ma_1 - mi_1
    
    bb = ((ww // 2)) * ((hh - i))
    cc = hh * ww - a- bb
    mi_2 = min(a,bb,cc)
    ma_2 = max(a,bb,cc)
        
    if ma_2 - mi_2 < kouho_2:
        kouho_2 = ma_2 - mi_2
            
p = hh
q = ww

hh = q
ww = p

for i in range(1,hh):
    a = i * ww
    b = ((hh - i) // 2) * ww
    c = hh * ww - (a + b) 
    
    mi_1 = min(a,b,c)
    ma_1 = max(a,b,c)
    
    if ma_1 - mi_1 <   kouho_3 :
        kouho_3 =ma_1 - mi_1
    
    bb = ((ww // 2)) * ((hh - i))
    cc = hh * ww - a- bb
    mi_2 = min(a,bb,cc)
    ma_2 = max(a,bb,cc)
        
    if ma_2 - mi_2 < kouho_4:
        kouho_4 = ma_2 - mi_2
print(min(kouho_1,kouho_2,kouho_3,kouho_4))

Measured memory_bytes: 3064
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    s = list(input())
    r = s.count('R')
    g = s.count('G')
    b = s.count('B')
    cnt = r*g*b
    for i in range(n):
        for j in range(i+1, n):
            k = 2*j - i
            if k >= n:
                break
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                cnt -= 1
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9100
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=1e9,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
const long long llinf=1e18;
int n,k,a[100005],ans,cnt;
queue<int> q;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	a[n+1]=1;
	if(n==k)
	{
		cout<<1;
		return 0;
	}
	for(int i=1;i<=n+1;i++)
	{
		if(a[i]==1)
		{
			ans+=(cnt/(k-1))+int(bool(cnt%(k-1)));
			cnt=0;
		}
		else
			cnt++;
	}
	cout<<min(ans,((n-1)/(k-1)+int(bool((n-1)%(k-1)))));
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main(){
    string str;
    cin>>str;
    for (int i=0; i<sizeof(str); i++) {
        if(str[i]=='A'&&str[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations
def main():
    N, M = map(int, input().split())
    want = []
    for _ in range(M):
        tmp = list(map(int, input().split()))
        want.append(tmp[1:])
    cond = list(map(int, input().split()))
    
    swith = [i for i in range(N)]
    choice = 0
    cnt = 0
    while choice <= N:
        for comb in combinations(swith, choice):
            inp = [0 for _ in range(M)]
            
            for c in comb:
                for i, w in enumerate(want):
                    if c+1 in w:
                        inp[i] += 1
            
            flag = True
            for i in range(M):
                if inp[i]%2 != cond[i]:
                    flag = False    
            if flag:
                cnt += 1
        choice += 1
    print(cnt)
main()

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

int gcd(int x, int y) {
  if (x % y == 0 || y % x == 0) return min(x, y);
  int ans = x > y ? gcd(y, x%y) : gcd(x, y%x);
  return ans;
}

int calc_gcd(std::vector<int> values) {
  int ans = gcd(values.at(0), values.at(1));
  
  for (size_t i = 2; i < values.size(); i++) {
    ans = gcd(ans, values.at(i));
  }
  return ans;
}

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

  int N;
  std::cin >> N;

  std::vector<int> monsters;
  for (size_t i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    monsters.push_back(tmp);
  }

  int ans = calc_gcd(monsters);

  std::cout << ans << '\n';
}


Measured memory_bytes: 1144
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort(key=lambda x : x[0])

total_money = 0

for i in range(len(AB)):
    buy_cnt = min(M, AB[i][1])
    M -= buy_cnt
    total_money += buy_cnt*AB[i][0]
    if M == 0:
        break

print(total_money)




Measured memory_bytes: 29028
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long count = b/c + b/d - b/(c * d / gcd(c,d)) - ((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d)));
        //System.out.println(b/c + b/d - b/(c * d / gcd(c,d)));
        //System.out.println(((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d))));
        System.out.println((b-a+1-count));
        
    }

    public static long gcd(long a, long b){
        if(b == 0){return a;}
        return gcd(b, a%b);
    }
}



Measured memory_bytes: 23764
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
w = [input() for _ in range(n)]
s = sorted(w)
flag = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        flag = 1
for i in range(n-1):
    #if w[i] in w[:i-1]: flag = 1
    if w[i+1][0] != w[i][-1]:flag = 1
if flag:print("No")
else: print("Yes")

Measured memory_bytes: 3064
N = int(input())
h = list(map(int, input().split()))
dp_h = [0] * N
dp_h[1] = abs(h[0] - h[1])
for i in range(2,N):
  p_1 = abs(h[i] - h[i-1]) + dp_h[i-1]
  p_2 = abs(h[i] - h[i-2]) + dp_h[i-2]
  dp_h[i] = min(p_1, p_2)
print(dp_h[N-1])

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

int main() {
  int N, c1, c2, c3, c4;

  cin >> N;

  c1 = N / 1000;
  N %= 1000;
  c2 = N / 100;
  N %= 100;
  c3 = N / 10;
  N %= 10;
  c4 = N;

  if (c1 == c2 && c2 == c3 && c3 == c4) {
    cout << "Yes" << endl;
  } else if (c1 == c2 && c2 == c3) {
    cout << "Yes" << endl;
  } else if (c2 == c3 && c3 == c4) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int mod = 1000000007;

int main()
{
    std::string s;
    std::cin >> s;
    std::vector<std::vector<long long>> dp(s.size() + 5,std::vector<long long>(13));//[s.size() + 5][13];
    dp[0][0] = 1; //0文字目まで見たときに割り切れるのは1個
    for(int i = 0; i < (int)s.size(); i++){
        int t;
        if(s[i] == '?')t = -1;
        else t = s[i] - '0';
        for(int j = 0; j < 10; j++){
            if(t != -1 && t != j)continue; //?処理
            for(int k = 0; k < 13; k++){
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }
        for(int k = 0; k < 13; k++)dp[i + 1][k] %= mod;
    }
    std::cout << dp[s.size()][5] << std::endl;
}

Measured memory_bytes: 13696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, m;
    string s;

    cin >> n >> m >> s;

    P dp[112345];

    memset(dp, -1, sizeof(dp));

    priority_queue<P, vector<P>, greater<P>> q;

    q.push({0, 0});

    for (int i = 1; i <= n; i++)
    {
        if (s[i] == '1')
            continue;

        P p = {-1, -1};

        while (q.size())
        {
            P p_ = q.top();

            if (i - p_.second <= m)
            {
                p = p_;
                break;
            }

            q.pop();
        }

        if (p.first == -1)
            continue;

        dp[i].first = p.first + 1;
        dp[i].second = p.second;

        q.push({dp[i].first, i});
    }

    V res;

    int i = n;

    if (dp[n].first == -1)
    {
        cout << -1 << endl;
        return 0;
    }

    while (i > 0)
    {
        res.push_back(i - dp[i].second);
        i = dp[i].second;
    }

    reverse(res.begin(), res.end());

    REP(i, res.size())
    cout << res[i] << (i < res.size() - 1 ? " " : "\n");

    /*
    for (int i = 1; i <= n; i++)
        cout << dp[i].first << " ";

    cout << endl;

    for (int i = 1; i <= n; i++)
        cout << dp[i].second << " ";
        */

    return 0;
}

Measured memory_bytes: 1992
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    vector<ll> cnt(n,0);
    rep(i,n) rep(j,n){
        if(i==j) continue;
        if(a[i] < a[j]){
            cnt[i]++;
        }
    }
    vector<ll> cnt2(n,0);
    rep(i,n){
        for(int j=0;j<i;j++){
            if(a[j] > a[i]){
                cnt2[i]++;
            }
        }
    }

    /* cerr << cnt << endl; */
    /* cerr << cnt2 << endl; */

    ll ans = 0;
    rep(i,n){
        ll x = cnt[i];
        ll y = cnt2[i];
        ll t = k * (k-1) / 2;
        t %= mod;
        /* cout << i << " " << t << " " << x << " " << y << endl; */
        ans += x * t % mod;
        ans %= mod;
        ans += y * k % mod;
        ans %= mod;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	sc = initScanner(os.Stdin)
	n := scanInt(sc)
	s := scanStringSlice(sc, n)

	resolve(s)
}

func resolve(s []string) {
	pt := make([]int, 4)
	for _, v := range s {
		if v == "AC" {
			pt[0]++
		} else if v == "WA" {
			pt[1]++
		} else if v == "TLE" {
			pt[2]++
		} else if v == "RE" {
			pt[3]++
		}
	}

	fmt.Printf("AC x %d\n", pt[0])
	fmt.Printf("WA x %d\n", pt[1])
	fmt.Printf("TLE x %d\n", pt[2])
	fmt.Printf("RE x %d\n", pt[3])
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}


Measured memory_bytes: 3816
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N, M, i;
    cin >> N >> M;
    vector<int> X(M);
    vector<int> D(M-1);

    for (i=0;i<M;i++){
        cin >> X[i];
    }

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

    for (i=0;i<M-1;i++){
        D[i] = X[i+1] - X[i];
    }

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

    int sum = 0;
    for (i=0; i<M-N; i++){
        sum += D[i];
    }

    cout << sum << '\n';
}

Measured memory_bytes: 1024
#include <iostream>

int main() {
	int n, a, b, c;

	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		std::cin >> a >> b >> c;
		a *= a; b *= b; c *= c;
		if (a + b == c || b + c == a || c + a == b) {
			std::cout << "YES" << std::endl;
		} else {
			std::cout << "NO" << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1148
use std::io::*;
use std::str::FromStr;

fn main() {
    let a: usize = read();
    let s: String = read();
    if a >= 3200 {
        println!("{}", s);
    } else {
        println!("red");
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N; 
  cin >> N ;
    long long int a[100010],b[100010];
  
    for (int i = 0; i < N; ++i) 
        cin >> a[i];
  
  
        sort(a,a+N);
  
    b[0] = a[0];
  
  int ans = 1, res = N;
  
  for(int i=1;i<N;i++){
    
    if(2*b[i-1] < a[i]){
      res -= ans;
      ans = 1;
      b[i] = b[i-1] + a[i];
    }
    
    else{
      b[i] = b[i-1] + a[i];
      ans++;
    }
    
  }
  
   cout << res << endl;
    
  }
    
    


Measured memory_bytes: 1792
#include <cstdio>
#include <queue>
#include <vector>

using namespace std;


int main(){
	priority_queue<int> q;
	int self;
	for(int i=0;i<10;i++){
		scanf("%d",&self);
		q.push(self);
	}
	printf("%d\n",q.top());
	q.pop();
	printf("%d\n",q.top());
	q.pop();
	printf("%d\n",q.top());
	q.pop();
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
 
/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace std;
 
#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const LL MOD = 1000000000 + 7;
const LD EPS = 0.0000001 ;
#define MPP(a, b, c) MP(MP(a, b), c)
#define PII pair<pair<LL,LL>, LL>
 
LL pows(LL a, LL b)
{
	if (b == 0) return 1LL;
	LL temp = pows(a, b / 2);
	temp = (temp * temp) % MOD;
	if (b % 2) temp = (temp * a) % MOD;
	return temp;
}

LL add(LL a, LL b)
{
	LL res = a + b;
	return res % MOD;
}

LL mult(LL a, LL b)
{
	long long res = a;
	res *= b;
	if(res >= MOD)
		return res % MOD;
	return res;
}
const int SZ = 51;
struct matrix
{
	LL arr[51][51];

	void reset()
	{
		memset(arr, 0, sizeof(arr));
	}

	void makeiden()
	{
		reset();
		for(int i=0;i<SZ;i++)
		{
			arr[i][i] = 1;
		}
	}

	matrix operator + (const matrix &o) const 
	{
		matrix res;
		for(int i=0;i<SZ;i++)
		{
			for(int j=0;j<SZ;j++)
			{
				res.arr[i][j] = add(arr[i][j], o.arr[i][j]);
			}
		}
		return res;
	}

	matrix operator * (const matrix &o) const 
	{
		matrix res;
		for(int i=0;i<SZ;i++)
		{
			for(int j=0;j<SZ;j++)
			{
				res.arr[i][j] = 0;
				for(int k=0;k<SZ;k++)
				{
					res.arr[i][j] = add(res.arr[i][j] , mult(arr[i][k] , o.arr[k][j]));
				}
			}
		}
		return res;
	}
};

matrix power(matrix a, LL b)
{
	matrix res;
	res.makeiden();
	while(b)
	{
		if(b & 1)
		{
			res = res * a;
		}
		a = a * a;
		b >>= 1;
	}
	return res;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

  	LL n, k; cin >> n >> k;

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

  	matrix mat;
  	mat.reset();
  	for (int i = 0; i < n; i++){
  		for (int j = 0; j < n; j++){
  			mat.arr[i][j] = graph[i][j];
  		}
  	}

  	mat = power(mat, k - 1LL);

  	LL cnt[n];
  	memset(cnt, 0, sizeof(cnt));
  	for (int i = 0; i < n; i++){
  		for (int j = 0; j < n; j++){
  			cnt[i] += graph[j][i];
  		}
  	}

  	LL ans = 0;

  	for (int i = 0; i < n; i++){
  		for (int j = 0; j < n; j++){
  			ans = add(ans, mult(mat.arr[i][j] , cnt[i]));
  		}
  	}

  	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
    int k,a,b;
    cin >> k;
    cin >> a >> b;
    int i;
    bool flg=false;
    for (i = a; i <= b; i++)
    {
        if (i%k==0)
        {
            cout << "OK";
            flg=true;
            break;
        }
        
    }
    if (!flg)
    {
        cout <<"NG";
    }
    

    return 0;
}


Measured memory_bytes: 3624
s = input()
k = True

for i in range(1, len(s)+1):
    if i % 2 == 1:
        if s[i-1] == 'R' or s[i-1] == 'U' or s[i-1] == 'D':
            pass
        else:
            k = False
            break
    elif i % 2 == 0:
        if s[i-1] == 'L' or s[i-1] == 'U' or s[i-1] == 'D':
            pass
        else:
            k = False
            break

if k == True:
    print("Yes")
elif k == False:
    print("No")


Measured memory_bytes: 9128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		long[] a = new long[n+1];
		a[0] = 0;
		for(int i = 1; i <= n; i++) {
			a[i] = sc.nextLong()+a[i-1];
		}
		long[] b = new long[m+1];
		b[0] = 0;
		for(int i = 1; i <= m; i++) {
			b[i] = sc.nextLong()+b[i-1];
		}
		int ans = 0;
		for(int i = 0; i <= n; i++) {
			long temp = k - a[i];
			if(temp < 0) {
				break;
			}
			int low = -1;
			int high = m+1;
			int mid ;
			while(low+1 < high) {
				mid = (low+high)/2;
				if(b[mid] > temp) {
					high = mid;
				}
				else {
					low = mid;
				}
			}
			ans = Math.max(ans, low+i);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 64580
#include <iostream>
#include <algorithm>
using namespace std;
void sort(int *c,int m){
  for(int i = 1; i < m; i++){
    int k = i;
    for(int j = i-1; j >= 0; j--){
      if(c[k] > c[j]){
        int temp = c[k];
        c[k] = c[j];
        c[j] = temp;
        k = j;
      }
    }
  }
  return;
}
int main(){
  int c[20];
  int dp[50001];
  int n,m;
  cin >> n >> m;
  for(int i = 0; i < m; i++)cin >> c[i];
  for(int i = 1; i <= n; i++)dp[i] = 500000;

  for(int i = 1; i < n+1; i++){
    for(int j = 0; j < m; j++){
      if(i-c[j] >= 0){
        dp[i] = min(dp[i],dp[i-c[j]]+1);
      }
    }
  }
  cout << dp[n] << endl;
}



Measured memory_bytes: 3288
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
vector<vector<P>> a(n);
for(int i=0;i<n;i++){
  int p;cin>>p;
  a[i].resize(p);
  for(int j=0;j<p;j++){
    cin>>a[i][j].fi>>a[i][j].se;
    a[i][j].fi--;
  }
}
ll ans=0;
for(int i=0;i<(1<<n);i++){
  bool ok=true;
   for(int j=0;j<n;j++){
     for(int k=0;k<a[j].size();k++){
       P p=a[j][k];
       if(i&(1<<j)){
         if(p.se==1){
           if(!(i&(1<<p.fi)))ok=false;
         }
         else{
           if(i&(1<<p.fi))ok=false;
         }
       }
     }
   }
   if(ok){
     ll cnt=0;
     for(int j=0;j<n;j++){
       if(i&(1<<j))cnt++;
     }
     chmax(ans,cnt);
   }
}
cout<<ans<<endl;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 整数の入力
s = list(input())
n = len(s)
v = 7

# 全bit探査:
for i in range((n-1)*(n-1)):
    summation = int(s[0])
    str_equation = [s[0]]
    for j in range(n-1):
        # bitが1なら+演算子として扱う
        if (i >> j) & 1:
            summation += int(s[j+1])
            str_equation.append("+")
            str_equation.append(s[j+1])
        # bitが0なら-演算子として扱う
        else:
            summation -= int(s[j+1])
            str_equation.append("-")
            str_equation.append(s[j+1])

    if summation == v:
        str_equation.append("=")
        str_equation.append(str(v))
        print("".join(str_equation))
        break


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main (void)
{
	int a, b;
	cin >> a >> b;
	if(a <= b){
		while(b != 0){
			cout << a;
			b--;
		}
		return 0;
	}
	if(a > b){
		while(a != 0){
			cout << b;
			a--;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Text.Printf

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

getLinesInt :: Int -> IO [Int]
getLinesInt n = fmap read <$> getLines n

getInts :: IO [Int]
getInts = map (read :: String -> Int) . words <$> getLine

getDoubles :: IO [Double]
getDoubles = map (read :: String -> Double) . words <$> getLine

main :: IO ()
main = do
    [a, b, c] <- getInts
    print $ min (b `div` a) c


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    int E=max(A,C);
    int F=min(B,D);
    if(E>=F) cout<<0<<endl;
    else cout<<F-E<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
int dp[50][3001];
int main() {
	int n,m,s;
	while(scanf("%d %d %d",&n,&m,&s),n) {
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		for(int i=1;i<=m;i++)
			for(int j=n*n;j>=1;j--)
				for(int k=i;k<=s;k++) {
					dp[j][k]+=dp[j-1][k-i];
					if(dp[j][k]>=100000)dp[j][k]-=100000;
				}
		printf("%d\n",dp[n*n][s]);
	}
}

Measured memory_bytes: 1620
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

pair<int64_t, int64_t> nearest(int64_t x, const vector<int64_t>& v) {
  if (v.size() == 1) return {v[0], v[0]};

  if (x <= v[0]) return {v[0], v[0]};

  if (v[v.size() - 1] <= x) return {v[v.size() - 1], v[v.size() - 1]};

  int a = 0;
  int b = v.size() - 1;
  while (a < b) {
    const int mid = (a + b) / 2;
    if (x == v[mid]) {
      return {v[mid], v[mid]};
    } else if (x < v[mid]) {
      b = mid - 1;
    } else {
      a = mid + 1;
    }
  }

  if (v[a] < x) {
    return {v[a], v[a + 1]};
  }
  // x < v[a]
  return {v[a - 1], v[a]};
}

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

  int a, b, q;
  cin >> a >> b >> q;

  vector<int64_t> s(a);
  vector<int64_t> t(b);

  for (int i = 0; i < a; ++i) cin >> s[i];
  for (int i = 0; i < b; ++i) cin >> t[i];

  int64_t x;
  for (int i = 0; i < q; ++i) {
    cin >> x;

    pair<int64_t, int64_t> ps = nearest(x, s);
    pair<int64_t, int64_t> pt = nearest(x, t);

    int64_t d[8] = {0};
    d[0] = abs(ps.first - x) + abs(pt.first - ps.first);
    d[1] = abs(pt.first - x) + abs(ps.first - pt.first);

    d[2] = abs(ps.second - x) + abs(pt.second - ps.second);
    d[3] = abs(pt.second - x) + abs(ps.second - pt.second);

    d[4] = abs(ps.second - x) + abs(ps.second - pt.first);
    d[5] = abs(pt.first - x) + abs(ps.second - pt.first);

    d[6] = abs(ps.first - x) + abs(ps.first - pt.second);
    d[7] = abs(pt.second - x) + abs(ps.first - pt.second);

    cout << *min_element(d, d + 8) << endl;
  }

  return 0;
}


Measured memory_bytes: 2944
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim n As Integer = NextInt()
        Dim k As Integer = NextInt()
        Dim g, m As Integer

        For i As Integer = 0 To n - 1
            Dim a As Integer = NextInt()
            If i = 0 Then
                g = a
                m = a
            End If
            g = GCD(g, a)
            m = Math.Max(m, a)
        Next

        If k Mod g = 0 AndAlso k <= m Then
            WriteLine("POSSIBLE")
        Else
            WriteLine("IMPOSSIBLE")
        End If
    End Sub

    Function GCD(x As Integer, y As Integer) As Integer
        Do While y <> 0
            x = x Mod y
            Dim tmp As Integer = x
            x = y
            y = tmp
        Loop
        Return Math.Abs(x)
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function
End Module


Measured memory_bytes: 24644
using System;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] In1 = Console.ReadLine().Split(' ');
            int n = int.Parse(In1[0]);
            int m = int.Parse(In1[1]);
            string[] In2 = Console.ReadLine().Split(' ');
            int[] A = new int[n];
            int sum = 0;

            for(int i = 0; i < n; i++)
            {
                A[i] = int.Parse(In2[i]);
                sum += A[i];
            }
            double border = sum / (4.0 * m);
            int cnt = 0;

            for(int i= 0; i < n; i++)
            {
                if (A[i] >= border)
                {
                    cnt++;
                }
            }
            if (cnt >= m) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
/*package whatever //do not write package name here */

import java.io.*;
import java.util.Scanner;

class Main {
	public static void main (String[] args) {
	    Scanner in = new Scanner(System.in);
	   for(int i=1 ; i<= 5 ; i++) {
	       int num = in.nextInt();
	       if(num == 0)
	       System.out.println(i);
	   }
	}
}

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

using namespace std;
#define ll long long
#define ff first
#define ss second

const int N=1e5+5;

ll a[N];

int main()
{
    int n,x,res=0;
    cin>>n;
    if(n==0){
        cout<<0<<endl;
        return 0;
    }
    string s;
    s="";
    while(n!=0){
        int r=n%(-2);
        n/=(-2);
        if(r<0){
            r=r+(2);
             n+=1;
        }
        s+=r+'0';
    }
    for(int i=s.size()-1;i>=0;i--){
        cout<<s[i];
    }


    return 0;
}



Measured memory_bytes: 256
N,W = map(int,input().split())
weights = []
vals = []
for _ in range(N):
  v,w = map(int,input().split())
  weights.append(w)
  vals.append(v)

dp = [ [0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
  wei, val = weights[i-1], vals[i-1]
  for w in range(W+1):
    if w >= wei:
      dp[i][w] = max(dp[i-1][w], dp[i-1][w-wei] + val)
    else:
      dp[i][w] = max(dp[i][w-1], dp[i-1][w])

print(dp[N][W]) 



Measured memory_bytes: 25500
# -*- coding: utf-8 -*-
# INF=10^7程度じゃインプットの桁数ふえた時に更新処理が正しく走らず結果エラーになってしまう..
MOD_KEY = 1000000007
n, m = map(int, input().split())
dp = [0]*(n+1)
for i in range(m):
    a = int(input())
    dp[a] = -1

dp[0] = 1

for i in range(n):
    # print("i: " + str(i))
    for j in range(1, 3):
        #print("j: " + str(j))
        if i + j < n+1:
            if (dp[i+j] >= 0) & (dp[i] >= 0):
                dp[i+j] += dp[i]
                dp[i+j] %= MOD_KEY

if dp[n] > 0:
    print(dp[n])
else:
    print(0)

Measured memory_bytes: 6880
#include<bits/stdc++.h>
using namespace std;
char s[500][500];
int n;
bool check(int x){
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			if (s[(x+i)%n][j]!=s[(x+j)%n][i]) return 0;
	return 1;
}
int main(){
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%s",s[i]);
	int ans=0;
	for (int i=0;i<n;i++)
		ans+=check(i);
	printf("%d\n",ans*n);
	return 0;
}

Measured memory_bytes: 512
a,b = map(int,input().split())

S  = (a-1)*(a-2)//2
def solve(x,y,s):
    print(a+s-y-1)
    for i in range(1,a):
        print(1,1+i)
    c = 0
    for i in range(1,a):
        for I in range(i+1,a):
            if c == s-b:exit()
            print(i+1,I+1)
            c+=1
            if c == s-b:exit()
# print(b,S)
if not 0<= b <= S:
    print(-1)
    exit()
else:
    solve(a,b,S)


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

int main() {

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <unordered_map>
#define int long long int
#define double long double
#define endl "\n"
#define PI 3.141592653589793238462643383279502884
#define sp(x)   setprecision(x)
#define ceil(a,b)   (a+(b-1))/b
#define LCM(a,b)    (a*b)/__gcd(a,b)
#define all(v)  v.begin(),v.end()
#define alls(s,v)  s.begin(),s.end(),v
#define gena(arr,n,nxt)  generate(arr,arr+n, nxt)
#define genv(v,nxt)  generate(v.begin(),v.end(), nxt)
#define base ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define exit return 0;
#define is(x) cout << #x << " = " << x << endl;
using namespace std;
const int N=500000;
bool prime[N];
void sieve(){
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<100000000; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<100000; i += p)
                prime[i] = false;
        }
    }
}
int nxt(){int x;cin >> x;return x;}
int sum=0;
void recursion(int idx,int cnt,int x,string s){
    if(idx==s.size()){
        sum+=cnt+x;
        return;
    }
    recursion(idx+1,(cnt*10)+(s[idx]-'0'),x,s);
    recursion(idx+1,0,x+cnt,s);
}
int32_t main(){
    base
    string s;
    cin>>s;
    recursion(0,0,0,s);
    cout<<sum;
    exit
}


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

int main(void){
    int n;
    cin >> n;
    long long int a[n],max[n];
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    max[0] = a[0];
    for(int i = 1;i < n;i++)max[i] = max[i-1] + a[i];
    long long int sum = max[n-1];
    for(int i = 0;i < n-1;i++){
        long long x,y;
        x = max[i];
        y = max[n-1] - max[i];
        sum = min(sum,abs(x-y));
    }
    cout << sum;
}

Measured memory_bytes: 3456
#include<stdio.h>

#define MAX 100005
#define NTL -1

struct Node{int p, l, r;};
struct Node T[MAX];

int n,H,D[MAX];

int main() {
  int i,j,d,v,c,l;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++) {
    T[i].p = T[i].l = T[i].r = NTL;
  }

  for(i = 0 ; i < n ; i++) {
    scanf("%d %d",&v,&d);
    for(j = 0 ; j < d ; j++) {
      scanf("%d",&c);
      if(j == 0)
        T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }

  H = 0;
  for(i = 0 ; i < n ; i++) {
    D[i] = getDepth(i);
    if(D[i] > H)
      H =D[i];
  }

  for(i = 0 ; i < n ; i++)
    print(i);
  return 0;
}

int getDepth(int x) {
  int d=0;

  for(; T[x].p != NTL ; d++)
    x = T[x].p;
  return d;
}

int print(int x) {
  int i,c;

  printf("node %d: ",x);
  printf("parent = %d, ",T[x].p);
  printf("depth = %d, ",D[x]);

  if(T[x].p == NTL)
    printf("root, ");
  else if(T[x].l == NTL)
    printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i = 0, c = T[x].l ; c != NTL ; i++, c = T[c].r) {
    if (i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}




Measured memory_bytes: 3360
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g);
void shellSort(int A[], int n);

int main(void)
{
    cin >> n;
    for(int i = 0; i < n; i++) scanf("%d", &A[i]);
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for(int i = G.size() - 1; i >= 0; i--)
    {
        printf("%d", G[i]);
        if(i) printf(" ");
    }
    printf("\n");
    printf("%d\n", cnt);
    for(int i = 0; i < n; i++) printf("%d\n", A[i]);

    return 0;
}

void insertionSort(int A[], int n, int g)
{

    for(int i = g; i < n; i++)
    {
        int v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v)
        {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n)
{
    for(int h = 1;;)
    {
        if(h > n) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    for(int i = G.size() - 1; i >= 0; i--)
    {
        insertionSort(A, n, G[i]);
    }
}


Measured memory_bytes: 7136
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;

/*define*/
#define rep(i, n) for(int i=0; i<n; ++i)
#define endl "\n"
typedef long long ll;

const long long mod = 1e18;
const long long INF=1e9;
int ci;

//dx[5] = {-1, 0, 1, 0, 0};
//dy[5] = {0, 1, 0, -1, 0};
//1行目を辞書順で繰り返す
//for(int i=0; i<1<<n; ++i){}
//2進数を入力
//for(int j=0; j<n; ++j) g[0][i] = (i>>j)&1==1;

/*unique文字の確認
    set<int> all;
    all.insert(a[i]);
    map<int, int> count;
    count[a[i++]]++;
    if(count[a[j++]]++==0) num++; 
*/
//typedef pair<int, int> P;

//配列
//vector<long long> v(max_n);
//vector<int> v[max_n];
//vector<vector<int>> v(max_n);
//priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q; 降順;
//priority_queue<pair<int, int>, vector<pair<int, int>>, less<>> q; 昇順;

//tips
//最大値の最小化は２分探索
//printf("IMPOSSIBLE"\n);
//printf("%d%c", opt[i][j], j+1==N? \n : '');

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll x = 1000;
    rep(i, n-1){
        int s = a[i];
        int t = a[i+1];
        if(s < t){
            ll k = x/s;
            x %= s;
            x+= k*t;
        }
    }
    cout << x << endl;
    return 0;
}

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

#define ll long long
#define f first
#define s second

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(abs(a - b) + abs(b - c), min(abs(a - c) + abs(c - b),  abs(b - a) + abs(a - c)));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

template <class I>
void radix_sort(I first, I last) {
    using T = typename iterator_traits<I>::value_type;
    static_assert(is_integral<T>::value, "");
    constexpr int L = 8, M = 1 << L, K = (sizeof(T) * 8 + L - 1) / L;

    size_t n = last - first;
    T *p[2] = { &*first, (T *)malloc(n * sizeof(T)) };
    size_t m[M];

    for (int k = 0; k < K; k++) {
        fill_n(m, M, 0);
        for (size_t i = 0; i < n; i++) {
            m[p[0][i] >> (L * k) & M - 1]++;
        }
        for (int j = M - 1; j > 0; j--) {
            m[j] = m[j - 1];
        }
        m[0] = 0;
        for (int j = 2; j < M; j++) {
            m[j] += m[j - 1];
        }
        for (size_t i = 0; i < n; i++) {
            T t = p[0][i];
            p[1][m[t >> (L * k) & M - 1]++] = t;
        }
        swap(p[0], p[1]);
    }
    if (K % 2 == 1) {
        swap(p[0], p[1]);
        copy_n(p[1], n, p[0]);
    }
    if (is_signed<T>::value) {
        T *q = upper_bound(p[0], p[0] + n, 0, greater<>());
        rotate(p[0], q, p[0] + n);
    }
    free(p[1]);
}

unsigned int a[100000];

int main() {
    int n;
    scanf("%u", &n);

    for (int i = 0; i < n; i++) {
        scanf("%u", a + i);
    }

    radix_sort(a, a + n);

    int r = 0, b = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == b) {
            r--;
            b = 0;
        } else {
            b = a[i];
        }
    }

    cout << r * 2 + n << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s,t;
  cin >> s >> t;
  
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
}

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

using namespace std;



int main() {

    int n;
    cin >> n;

    string s;
    cin >> s;

    stack <char> st;

    for (int i = 0; i<n; ++i) {
        if (s[i] == '(') {
            st.push(s[i]);
        } else {
            if (!st.empty()) { if (st.top() == '(')
                st.pop(); else st.push(s[i]);
            } else {
                st.push(s[i]);
            }
        }
    }

    while (!st.empty()) {
        char c = st.top();
        st.pop();

        if (c == ')') {
            s.insert(s.begin(), '(');
        } else {
            s.push_back(')');
        }
    }

    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
B=A[::-1]
C=[0]*(n-1)
D=[0]*(n-1)
C[0]=A[0]
D[0]=B[0]
for i in range(1,n-1):
  C[i]=C[i-1]+A[i]
  D[i]=D[i-1]+B[i]
D=D[::-1]
print(min([abs(C[i]-D[i]) for i in range(n-1)]))

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


string S,T;

void input() {
	cin>>S>>T;
}

void solve() {
	int res=0;
	for(int i=0; i<S.len; i++) {
		if(S[i]!=T[i]) res++;
	}
	cout<<res<<endl;
}

int main() {
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


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

int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n - 1; i++) {
    v.at(i + 1) = (v.at(i) + v.at(i + 1)) / 2;
  }
  cout << v.at(n - 1) << endl;
  return 0;
}


Measured memory_bytes: 3728
#include <iostream>
using namespace std;
int main() 
{
	int a,b,c;
  	cin >> a >> b >> c;
  	if(a+b<=b+c && a+b<=c+a){
  		cout << a+b << endl;
  	}
  	else if(b+c<=a+b && b+c<=c+a){
  		cout << b+c << endl;
  	}
  	else if(c+a<=b+c && c+a<=a+b){
  		cout << c+a << endl;
  	}

	return 0;
}

Measured memory_bytes: 256