akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    int ans = 0;
    int times = min(N, K);
    for (int t = 1; t <= times; t++) {
        for (int l = 0; l <= t; l++) {
            int r = t - l;
            vector<int> onHand;
            onHand.insert(onHand.end(), a.begin(), a.begin() + l);
            onHand.insert(onHand.end(), a.rbegin(), a.rbegin() + r);
            sort(onHand.begin(), onHand.end());
            int remainingTimes = min(K - t, t);
            int sum = accumulate(onHand.begin(), onHand.end(), 0);
            for (int i = 0; i < remainingTimes; i++) {
                if (onHand[i] < 0) sum -= onHand[i];
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << '\n';
}


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

int main(){
	int N;
	scanf("%d", &N);
	char huruf[1000000];
	scanf("%s", huruf);
	for(int i = 0; i < strlen(huruf); i++){
		huruf[i] += N;
		if(huruf[i] > 'Z'){
			huruf[i] -= 26; 
		}
	}
	printf("%s", huruf);
	
	
	return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll x;
  scanf("%lld", &x);

  cout << (x == 0 ? 1 : 0) << endl;
}


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

int main()
{
    int N;
    cin>>N;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;

    vector<int> T(1000001);
    for (int a: A)
        T[a]++;
    for (int i=1; i<=1000000; i++)
        if (T[i]>0)
            for (int j=i+i; j<=1000000; j+=i)
                T[j] = 0;
    for (int &t: T)
        if (t>=2)
            t = 0;
    int ans = 0;
    for (int t: T)
        ans += t;
    cout<<ans<<endl;
}


Measured memory_bytes: 7632
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
	ll h,m;
	cin>>h>>m;
	if(h>2&&m>2){cout<< (h-2)*(m-2);}
	else if(h==2||m==2){cout << 0;}
	else if(h==1&&m==1){cout << 1;}
	else {cout << h*m-2;}
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))

t = sum(a)/(4*m)
a = sorted(a, reverse=True)
for i in range(n):
    if a[i] >= t:
        m -= 1

if m <= 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61968
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <set>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n;
map<int,int> mp;

int main(void){
    cin >> n;
    REP(i,n){
        int a;
        cin >> a;
        auto itr = mp.find(a);
        if(itr == mp.end()){
            mp[a] = 1;
        }else{
            mp.erase(a);
        }
    }
    put(mp.size());
    return 0;
}


Measured memory_bytes: 4864
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static System.Console;

namespace A_D2019
{
    class MainClass
    {

        static int[] s;
        static long[] n;

        public static void Main(string[] args)
        {

            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            
            int a = Max(s[0],s[1]);
            int b = Min(s[0],s[1]);




    

            WriteLine(a-b+1);


        }
    }
}


Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 333
#else
#define SIZE 333
#endif

int N,K;

/*
 ■塗る回数のカウント
 左から見ていって、、
 上がっている間は差分を+
   (一度下がってから上がった場合も含む)
 下がっている間は+0
 ■変化の方向
 隣に高さを合わせると、カウントに影響しなくできる
 */
// i番目のブロックまでみた、残り変化回数、直前の高さ(ブロック番号)→最小の塗る回数
int DP[SIZE][SIZE][SIZE];
int LAST = SIZE-1;
int H[SIZE];
void solve() {
    cin>>N>>K;
    REP(i,N)cin>>H[i];
    
    REP(i,N)REP(k,K+1)REP(j,SIZE) {
        DP[i][k][j] = LONG_LONG_MAX/3;
    }
    if (K) DP[0][K-1][LAST] = 0;
    DP[0][K][0] = H[0];
    FOR(i,1,N)REP(k,K+1)FOR(_j,-1,i) {
        int j = (_j<0) ? LAST : _j;
        if (k<K) DP[i][k][j] = min(DP[i][k][j], DP[i-1][k+1][j]); // 操作→直前の高さはjのまま
        int lastH = (_j<0) ? 0 : H[_j];
        DP[i][k][i] = min(DP[i][k][i], DP[i-1][k][j] + max(0LL, H[i]-lastH)); // 普通に塗る→直前の高さはi
    }
    int ans = LONG_LONG_MAX;
    REP(k,K+1)FOR(_j,-1,N) {
        int j = (_j<0) ? LAST : _j;
        ans = min(ans, DP[N-1][k][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 260224
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll dp[100005];
vector<ll>v[100005];
ll dfs(ll u,ll p)
{
    if(dp[u]!=-1)
        return dp[u];
    ll l=0;
    for(int i=0;i<v[u].size();i++)
    {
        if(v[u][i]==p)
            continue;
        else
            l=max(l,1+dfs(v[u][i],u));
    }
    return (dp[u]=l);
}
int main()
{
    memset(dp,-1,sizeof(dp));
    ll n,m;
    cin>>n>>m;
    while(m--)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        if(dp[i]==-1)
            dfs(i,-1);
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 30;
const ll MOD = 1000000007;

ll dp[101010];

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    string a, b, c; cin >> a >> b >> c;
    int a_index = 0, b_index = 0, c_index = 0;
    int a_size = a.size(), b_size = b.size(), c_size = c.size();

    char next_c = 'a';
    while(true){
        if(a_index == a_size + 1){
            cout << "A" << endl;
            break;
        }
        else if(b_index == b_size + 1){
            cout << "B" << endl;
            break;
        }
        else if(c_index == c_size + 1){
            cout << "C" << endl;
            break;
        }

        if(next_c == 'a'){
            next_c = a[a_index];
            ++a_index;
        }
        else if(next_c == 'b'){
            next_c = b[b_index];
            ++b_index;
        }
        else if(next_c == 'c'){
            next_c = c[c_index];
            ++c_index;
        }
    }

    return 0;
}



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

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	multiset<int> st;
	for (int i=0;n>i;i++) {
		int x;
		cin >> x;
		st.insert(x);
	}
	int m;
	cin >> m;
	bool can=true;
	for (int i=0;m>i;i++) {
		int x;
		cin >> x;
		if (st.find(x) == st.end()) can=false;
		else {
			st.erase(st.find(x));
		}
	}
	if (can) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  ll l, r;
  cin >> l >> r;
  ll ans = 3000;
  for (ll i = l; i < r; ++i) {
    for (ll j = i + 1; j <= r; ++j) {
      ll res = (i * j) % 2019;
      ans = min(ans, res);
      if (ans == 0) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	int X; cin >> X;
	int num_500 = X / 500;
	X %= 500;
	int num_5 = X / 5;

	int ans = num_500 * 1000 + num_5 * 5;
	cout << ans << endl;
	


	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string str;
  cin >> str;
  int i,count=0;
  for(i=0;i<str.size()/2;i++){
    if(str.at(i)!=str.at(str.size()-i-1)){
      count++;
    }
  }
  cout << count << endl;
}
    

Measured memory_bytes: 256
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
    I LOVE CLARICE STARLING

     ♥LOVE♥        ♥LOVE♥
  ♥LOVE♥♥LOVE♥  ♥LOVE♥♥LOVE♥
♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
   ♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
      ♥LOVE♥♥LOVE♥♥LOVE♥
         ♥LOVE♥♥LOVE♥
            ♥LOVE♥
               ♥


    EXPLAINATION BELOW->
    1)Testcase to prove why Greedy fails
      A)4
        1 7 5 11
      Greedy approach of choosing at each step one which finds to have min |hi-hj| at a point fails here
      B)6
        1 2 10 3 0 1
     Greedy of approach of always jumping from i to i+2 so that min jumps lead to min addition of differences fails for this testcase
     
    In testcase B after handrunning bottom to top i.e right to left
    You can observe
    Optimal substructure as well as Overlapping Subproblems so Definitely Dynamic Programming
    
    State is only position
    position indicates if I start from this position what is the optimal Answer
*/
/*
 * 
 * 
 *   ITERATIVE SOLUTION
 * 
 * */
//
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
int N,i;
int H[100005];
ll dp[100005];//long long since sum can surpass limits of int
void solve()
{
  cin>>N;
  fo(i,0,N)cin>>H[i];
  
  dp[N-1]=0;
  dp[N-2]=abs(H[N-1]-H[N-2]);
  for(i=N-3;i>=0;i--)
  dp[i]=min(abs(H[i]-H[i+1])+dp[i+1],abs(H[i]-H[i+2])+dp[i+2]);
  
  cout<<dp[0]<<"\n";
}
int main()
{
   fastio
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 1408
num = input()
if num.isdecimal():
    if int(num) <= 999:
        first_class_num = int(num[-1])
        if first_class_num in {2, 4, 5, 7, 9}:
            print("hon")
        elif first_class_num in {0, 1, 6, 8}:
            print("pon")
        elif first_class_num is 3:
            print("bon")


Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    string S;
    cin >> S;
    int count = 0, a = S.size();
    for (int i = 0; i < a; i++) {
        if (S.at(i) == '0') {
            count++;
        }
    }
    cout << min(a - count, count) * 2 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
    // insert code here...
    int n,l,k,p;
    long long answer=0;
    cin>>n;
    k=0;
    cin>>p;
    answer+=abs(p);
    if(p<0)k++;
    for (int i=0; i<n-1; i++) {
        cin>>l;
        if(l<0)k++;
        if(abs(l)<abs(p))p=l;
        answer+=abs(l);
    }
    if (k%2==1) {
        answer-=(abs(p)*2);
    }
    cout<<answer<<endl;
    
    return 0;
}

Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let mut xl = (0..n)
        .map(|_| (sc.read::<i64>(), sc.read::<i64>()))
        .collect::<Vec<_>>();
    xl.sort();
    let mut max = -(1 << 50);
    let mut count = 0;
    for (x, l) in xl.into_iter() {
        if max <= x - l {
            count += 1;
            max = x + l;
        } else if x + l <= max {
            max = x + l;
        }
    }
    println!("{}", count);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6396
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int main(){
    INIT;
    int n, w, z;
    cin >> n >> z >> w;
    V<int> v(n);
    REP(i,n) cin >> v[i];

    if(n == 1) cout << std::abs(v[0]-w);
    else cout << std::max(std::abs(v[n-1]-w),std::abs(v[n-2]-v[n-1]));
}


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


//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[200010];//適宜変える
	int id[100010];//適宜変える
}G;

int csort(const void*a,const void*b){
	ll p=(*(E*)a).c,q=(*(E*)b).c;
	return p<q?-1:p>q?1:0;
}

G g;
void readgraph(){
	//適宜変える
	ll n;
	ll m=0;
	scanf("%lld",&n);
	rep(i,0,n)rep(j,0,n){
		ll c;
		scanf("%lld",&c);
		if(c!=-1){
			g.e[m].s=i;
			g.e[m].g=j;
			g.e[m].c=c;
			m++;
		}
	}
	g.vcnt=n;
	g.ecnt=m;
	qsort(g.e,g.ecnt,sizeof(E),csort);
}

//union-find
#define UFLIMIT (1<<17)
int unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int root(int x){return unicnt[x]<=0?-(unicnt[x]=-root(-unicnt[x])):x;}
int same(int x,int y){return root(x)==root(y);}
void uni(int x,int y){if((x=root(x))==(y=root(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT

//クラスカル法
//最小全域木を構成する辺とそのコストの合計を求める
//union findが必要、事前にコストでソートが必要
//O(ElogE)
//*
//ll saishou[100010];
ll kurasukaru(G g){
	ll ans=0;
	ufinit(g.vcnt);
	rep(i,0,g.ecnt){
		if(!same(g.e[i].s,g.e[i].g)){
			uni(g.e[i].s,g.e[i].g);
//			saishou[i]=1;
			ans+=g.e[i].c;
		}
	}
	return ans;
}
//*/

int main(){
	readgraph();
	printf("%d\n",kurasukaru(g));
}


Measured memory_bytes: 7008
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < s.length; j++) {
                if (s[j] == 'Z') {
                    s[j] = 'A';
                } else {
                    s[j]+=1;
                }
            }
        }

        System.out.println(String.valueOf(s));
    }
}


Measured memory_bytes: 23380
s = input()

ans = 0
if s.count("R") == 3:
    print(3)
elif s.count("R") == 2:
    if s[0] == s[1] or s[1] == s[2]:
        print(2)
    else:
        print(1)
elif s.count("R") == 1:
    print(1)
else:
    print(0)

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  string s;
  cin >> n >> s;
  vector<int> v(n+1,0);
  rep(i,n){
    v[i+1]=v[i]+(s[i]=='.');
  }
  int ans=n;
  rep(i,n+1){
    int l=i-v[i];
    int r=v[n]-v[i];
    ans=min(ans,r+l);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1412
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(string, s, t);
    Cout((s[0] == t[0]) + (s[1] == t[1]) + (s[2] == t[2]));
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int i = 0; i < n; i++) {
        cout << arr[i];
        if (i == n - 1) cout << endl;
        else cout << ' ';
    }
    for (int i = 1; i < n; i++) {
        int tmp = arr[i];
        int j;
        for (j = i - 1; j >= 0; j--) {
            if (arr[j] < tmp) break;
            arr[j + 1] = arr[j];
        }
        arr[j + 1] = tmp;
        for (int k = 0; k < n; k++) {
            cout << arr[k];
            if (k == n - 1) {}
            else cout << ' ';
        }
        cout << endl;
    }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> data(n);
    for(int i = 0; i < n; i++){
        cin >> data[i];
    }

    int sum = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            sum += data[i] * data[j];
        }
    }
    cout << sum << endl;
}



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

int main(){
    string s1, s2, s3;

    cin >> s1 >> s2 >> s3;
    cout << (char)(s1[0] - 32) << (char)(s2[0] - 32) << (char)(s3[0] - 32) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
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;}
#define N_MAX 200
#define V_MAX 200000
ll dp[N_MAX][V_MAX];

int main() {
  ll N, W; cin >> N >> W;
  vector<ll> w(N+1), v(N+1);
  rep(i,N) cin >> w[i] >> v[i];
  rep(i,N_MAX) {
    rep(j,V_MAX) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  rep(i,N) {
    rep(j,V_MAX) {
      if(j-v[i] >=0) chmin(dp[i+1][j], dp[i][j-v[i]] + w[i]);
      chmin(dp[i+1][j], dp[i][j]);
    }
  }
  ll ans = 0;
  for(int j=0; j<V_MAX; ++j) {
    if(dp[N][j] <= W) ans = j;
  }
  cout << ans << endl;
}


Measured memory_bytes: 312832
//Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
// #include<unordered_map>
using namespace std;
int bin[40],lg[1<<21];
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void writeln(int num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<int,int>
	#define PB push_back
	#define vc vector
	inline void chmax(int &x,const int y) {x=x>y?x:y;}
	inline void chmin(int &x,const int y) {x=x<y?x:y;}
	const int MAX_N=2e5+10;
	const int MOD=1e9+7;
	void add(int &x,int y) {x+=y;if(x>=MOD) x-=MOD;if(x<0) x+=MOD;}

	ll ans;
	void T(ll x,ll y)//x<y
	{
		if(x>y) swap(x,y);
		ll a=y/x,b=y%x;
		if(b==0) ans+=(a*2-1)*x;
		else ans+=(a*2)*x,T(x,b);
	}
	void main()
	{
		ll n=qread(),x=qread();ans=n;
		T(x,n-x);write(ans);
	}
};
int main()
{
	srand(time(0));
	bin[0]=1;for(int i=1;i<=30;i++) bin[i]=bin[i-1]<<1;
	lg[1]=0;for(int i=2;i<(1<<21);i++) lg[i]=lg[i>>1]+1;
	mine::main();
}


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

int main()
{
	long long mod = 1000000007;
	long long s;
	cin >> s;

	vector<long long> t(s + 1, 1);
	t[0] = 0;
	t[1] = 0;
	t[2] = 0;
	for (long long i = 4; i <= s; ++i) {
		for (long long j = 3; j <= i; ++j) {
			t[i] = (t[i] + t[i - j]) % mod;
		}
	}
	cout << t[s] << endl;

	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define endl "\n"
#define loop(i,s,e) for(int i=s;i<e;i++)
#define int long long
#define mp make_pair
#define pii pair<int,int>
#define mset(a,f)  memset(a , f , sizeof(a))
#define pb push_back
const int N = 3e5 + 6;
const int M = 1e9 + 7;
const int inf = 1e17;


// bool J27 = 1;
#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
 

int A[N];
int n,a,b;
int dp[101][N];


void solve()
{
	cin >> n >> a;

	loop(i,1,n+1)cin >> A[i];

	mset(dp,0);

	dp[0][0] = 1;

	loop(i,1,n+1)
	{
		loop(j,0,a+1)
		{
			int ans = 0;
			ans += dp[(i-1)%2][j];
			if(j-1 >= 0)ans += dp[i%2][j-1] , ans%M;
			if(j-1 >= A[i])ans -= dp[(i-1)%2][j-1-A[i]];
			ans += M;
			dp[i%2][j] = ans%M;
		}
	}

	cout << dp[n%2][a];

	// cout << alpha(n,a);
}
 
int32_t main()
{
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}


Measured memory_bytes: 237952
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    for i in range(M):
        a, b = map(lambda x: int(x) - 1, input().split())
        G[a].append(b)
        G[b].append(a)

    ans = "IMPOSSIBLE"
    for v in G[0]:
        if N - 1 in G[v]:
            ans = "POSSIBLE"
            break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> sum(n+1);
    for(int i = 0; i < n; i++){
        sum[i+1] = sum[i] + a[i];
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll s = (sum[n] - sum[i+1]) % mod;
        ans += a[i] * s;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6388
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;

const int Inf = 100000;
const int mod = 1000000007;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void Solve()
{
	int k, n, ans = 0;
	int A[200005];
	cin >> k >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> A[i];
	}	
	A[0] = A[n] - k;
	for(int i = 0; i < n; i++)
	{
		ans = max(ans, A[i + 1] - A[i]);
	}
	cout << k - ans;
}

signed main()
{
	Solve();
}


Measured memory_bytes: 1024
use std::io;
//use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
use std::cmp; // cmp::max,cmp::min

// Rustメモ: https://hackmd.io/i0lQY1OKTDW1t66TECOmiw?both

#[allow(dead_code)]
fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char>{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read_int() -> i64{
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String{
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n:i64) -> Vec<String>{
    let mut xs = Vec::new();

    for _i in 0..n{
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n:i64) -> Vec<i64>{
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

////////////////////////////////////////////////

fn calc(v:i64,p:i64)->i64{
    v*(100+p)/100
}

fn solve() -> bool{
    // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1192&lang=jp
    let inputs = read_ints();
    let (x,y,s) = (inputs[0],inputs[1],inputs[2]);

    if x == 0{
        return false;
    }

    let vs : Vec<i64> = (0..(s+1)*(s+1))
        .into_iter()
        .filter(|a|{
            let left = a / (s+1) + 1;
            let right = a % (s+1) + 1;
            let left_p = calc(left,x);
            let right_p = calc(right,x);
            let ret = (left_p+right_p) == s;

            ret
        })
        .map(|a|{
            let left = a / (s+1) + 1;
            let right = a % (s+1) + 1;
            let left_p = calc(left,y);
            let right_p = calc(right,y);

            left_p+right_p
        })
        .collect();
    let max_value = vs
        .into_iter()
        .fold(-1,|a,b| cmp::max(a,b));
    println!("{}",max_value);

    true
}

fn main(){
    while solve(){}
}



Measured memory_bytes: 5040
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int h, w;
    cin >> h >> w;

    char c[101][100];
    char d[101][100];

    for (int i = 0; i < h; i++) {
        cin >> c[i];
    }

    int x = 0;
    for (int i = 0; i < h; i++) {
        int b = 1;
        for (int j = 0; j < w; j++) {
            if (c[i][j] != '.') b = 0;
        }
        for (int j = 0; j < w; j++) {
            d[x][j] = c[i][j];
        }
        if (!b) x++;
    }

    int y = 0;
    for (int j = 0; j < w; j++) {
        int b = 1;
        for (int i = 0; i < x; i++) {
            if (d[i][j] != '.') b = 0;
        }
        for (int i = 0; i < x; i++) {
            c[i][y] = d[i][j];
        }
        if (!b) y++;
    }

    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            cout << c[i][j];
        }
        cout << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
long long get_op_num(long long p){
  long long ret = 1;
  while(true){
    if(ret * (ret + 1) / 2 > p){
      return ret -1;
    }
    ret ++;
  }
  return -1;
}
int main(){
  long long N;
  cin >> N;

  map <long long, int> divisor_counts;
  long long tmp_N = N;
  for(long long i = 2; i < sqrt(N) + 1; i++){
    if(tmp_N % i == 0){
      divisor_counts[i] = 1;
      tmp_N /= i;
      while(tmp_N % i == 0){
        divisor_counts[i] ++;
        tmp_N /= i;
      }
    }
  }
  if(tmp_N != 1){
    divisor_counts[tmp_N] = 1;
  }

  long long ans = 0;
  for(auto it = divisor_counts.begin(); it != divisor_counts.end(); it++){
    ans += get_op_num(it->second);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
//#define ls x<<1
//#define rs x<<1|1
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-10;
const ull hashp=131;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e3+100;

void solve(){
	int l,r,d;scddd(l,r,d);
	cout<<r/d-(l-1)/d<<'\n';
}
int main(){
    //IOS;
    //freopen("D:\\data.txt","r",stdin);
    //freopen("D:\\out.txt","w",stdout);
    solve();
 
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;                                             ;;
    ;;         ;;            ;;;;;;;;;       ;;    ;;
    ;;        ;; ;;        ;;                ;;    ;;
    ;;       ;;   ;;       ;;                ;;    ;;
    ;;      ;;;;;;;;;      ;;                ;;    ;;
    ;;     ;;       ;;     ;;                      ;;
    ;;    ;;         ;;      ;;;;;;;;;       ;;    ;;
    ;;                                             ;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
    return 0;
}

Measured memory_bytes: 3252
#include <stdio.h>
#include <stdbool.h>
#define true 1
#define false 0
#define MAX 1000
#define VMAX 10000

int n,A[MAX],s;
int B[MAX],T[VMAX+1];

void sort(int C[])
{
	
	int tmp;
	int flag = 1;
	while(flag == 1){
		flag = 0;
		for( int j = n-1; j >= 1; j--){
			if(C[j] < C[j-1])
			{
				tmp = C[j];
				C[j] = C[j-1];
				C[j-1] = tmp;
				flag = 1;
			}
		}
	}
}


int min(int a , int b)
{
	if(a < b) return a;
	else return b;
}


int solve()
{
	int ans = 0;
	
	bool V[MAX];
	for( int i = 0; i < n; i++){
		B[i] = A[i];
		V[i] = false;
	}
	sort(B);
	for( int i = 0; i < n; i++) T[B[i]] = i;
	for( int i = 0; i < n; i++){
		if(V[i])continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int c = 0;
		while(1){
			V[cur] = true;
			c++;
			int v = A[cur];
			m = min(m,v);
			S += v;
			cur = T[v];
			if(V[cur])break;
		}
		ans += min(S+(c-2)*m, m+S+(c+1)*s);
	} 
	return ans; 
}


int main(void)
{
	scanf("%d",&n);
	s = VMAX;
	for( int i = 0; i < n; i++){
		scanf("%d",&A[i]);
		s = min(s, A[i]);
	}
	int ans = solve();
	printf("%d\n",ans);
	
	return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int s,u,l;
  cin >> s;
  u = s/100;
  l = s%100;
  
  if(u>=1 && u<=12){
    if(l>=1 && l<=12) cout << "AMBIGUOUS";
    else cout << "MMYY";
  }else{
    if(l>=1 && l<=12) cout << "YYMM";
    else cout << "NA";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Union_Find_Tree{
	public:
	vi p,r,s;
	Union_Find_Tree(int n){
		p=r=vi(n);
		s=vi(n,1);
		for(int i=0;i<n;i++) p[i]=i;
	}
	int Par(int x){
		if(p[x]==x) return x;
		return p[x]=Par(p[x]);
	}
	int Size(int x){return s[Par(x)];}
	bool Unite(int x,int y){
		x=Par(x);
		y=Par(y);
		if(x==y) return 0;
		if(r[x]<r[y]){
			p[x]=y;
			s[y]+=s[x];
		}
		else{
			p[y]=x;
			s[x]+=s[y];
			if(r[x]==r[y]) r[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){return Par(x)==Par(y);}
};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		vd x(n),y(n),z(n),r(n);
		vector<pair<double,P>> a;
		for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>z[i]>>r[i];
		for(int i=0;i<n;i++) for(int j=i+1;j<n;j++){
			double X=x[j]-x[i],Y=y[j]-y[i],Z=z[j]-z[i];
			double d=sqrt(X*X+Y*Y+Z*Z);
			a.push_back(make_pair(max(0.0,d-(r[i]+r[j])),make_pair(i,j)));
		}
		sort(a.begin(),a.end());
		Union_Find_Tree uft(n);
		double res=0;
		for(auto p:a){
			int u=p.second.first,v=p.second.second;
			if(!uft.Same(u,v)){
				uft.Unite(u,v);
				res+=p.first;
			}
		}
		printf("%.3f\n",res);
	}
}


Measured memory_bytes: 3408
n,x= list(map(int, input().split()))

L=list(map(int, input().split()))
D=[0]
for i in range(0,n):
    D.append(D[i]+L[i])
ans=0
for i in range(n+1):
    if D[i]<=x:
        ans+=1
    else:
        break

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}

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

int main(){

    string s;

    string t;
    cin >> s;

    for(int i=0;i<s.size();i++){
        if(i%2==0){
            t.push_back(s[i]);
        }
    }

    cout << t << endl;

    return 0;
}

Measured memory_bytes: 512
<?php
fscanf(STDIN, "%d %d %d %d %d", $hFrom, $mFrom, $hTo, $mTo, $kMin);
// 分単位にして、起きている時間から勉強時間を引く
echo (($hTo*60 + $mTo) - ($hFrom*60 + $mFrom) - $kMin). "\n";
?>


Measured memory_bytes: 16052
#include <cstdio>
#include <cctype>
typedef long long ll;

template <typename _tp> inline void read(_tp&x){
	char ch=getchar(),ob=0;x=0;
	while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ob=1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x;
}

const int N = 201000;
struct Edge {int v, nxt;} a[N*4];
int head[N], Head[N], indeg[N];
int sz[N], pr[N];
bool vis[N];
int n, _;

inline void add(int x, int y, int*arr) {
	a[++_].v = y, a[_].nxt = arr[x], arr[x] = _;
}

const int p = 1e9+7;
int fac[N], ifac[N], inv[N];

int st[N], tp;
#define FID(i) for(int id=1,i;i=st[id],id<=tp;++id)

int X, Y;
int et, pt;

void bfs(int x, int las) {
	vis[st[++tp] = x] = true, ++pt;
	for(int i=head[x];i;++et,i=a[i].nxt)
		if(!vis[a[i].v]) bfs(a[i].v, x);
		else if(a[i].v != las) X = x, Y = a[i].v;
}

void tfs(int x, int las) {
	for(int i=head[x];i;i=a[i].nxt)
		if(a[i].v != las and a[i].v != X)
			pr[a[i].v] = x, tfs(a[i].v, x);
}

void dfs(int x, int las) {
	sz[x] = 1;
	for(int i=Head[x];i;i=a[i].nxt)
		if(a[i].v != las)
			dfs(a[i].v, x), sz[x] += sz[a[i].v];
}

int solve() {
	tfs(X, Y);
	pr[X] = Y;
	FID(i) Head[i] = indeg[i] = 0;
	FID(x) for(int i=head[x];i;i=a[i].nxt)
		if(a[i].v < pr[x]) add(x, a[i].v, Head), ++indeg[a[i].v];
	
	FID(i) if(!indeg[i]) dfs(i, i);
	int Ans = fac[pt];
	FID(i) Ans = (ll)Ans * inv[sz[i]]%p;
	return Ans;
}

int main() {
	read(n);
	for(int i=1,x,y;i<=(n<<1);++i) {
		read(x), read(y), y += n;
		add(x, y, head), add(y, x, head);
	}
	
	n <<= 1;
	fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1;
	for(int i=2;i<=n;++i) {
		fac[i] = (ll)fac[i-1] * i%p;
		inv[i] = (ll)(p-p/i) * inv[p%i]%p;
		ifac[i] = (ll)ifac[i-1] * inv[i]%p;
	}
	
	int Ans = fac[n];
	for(int i=1;i<=n;++i)
		if(!vis[i]) {
			tp = pt = et = 0;
			bfs(i, i);
			Ans = (ll)Ans * ifac[pt]%p;
			if((pt << 1) != et) return puts("0"), 0;
			int res = solve();
			X ^= Y, Y ^= X, X ^= Y;
			res += solve();
			Ans = (ll)Ans * res%p;
		}
	printf("%d\n", Ans);
	return 0;
}

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

int main() {
  int h, w, dx[8]={0,1,0,-1,1,1,-1,-1}, dy[8]={1,0,-1,0,1,-1,1,-1};
  string s[50];
  cin >> h >> w;
  for(int i=0; i<h; i++) cin >> s[i];
  for(int i=0; i<h; cout << s[i] << endl, i++){
    for(int j=0, num=0; j<w; num=0, j++){
      if(s[i].at(j) != '#'){
        for(int k=0; k<8; k++){
          int x=j+dx[k], y=i+dy[k];
          if(x>=0 && x<=w-1 && y>=0 && y<=h-1 && s[y].at(x) == '#') num++; 
        }
        s[i].at(j) = to_string(num).at(0);
      }
    }
  }
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement
CList = []
N, M, Q = map(int, input().split())
for i in range(1, M+1):
    CList.append(i)
Qtotal = []
x = 0
ans = 0

CList=list(combinations_with_replacement(CList, N))

a, b, c, d = map(int, input().split())
for i in CList:
    if CList[x][b-1]-CList[x][a-1] == c:
        Qtotal.append(d)
    else:
        Qtotal.append(0)
    x = x+1
x=0
for i in range(Q-1):
    a, b, c, d = map(int, input().split())
    for j in CList:
        if CList[x][b-1]-CList[x][a-1] == c:
            Qtotal[x] = Qtotal[x]+d
        x = x+1
    x=0

ans=max(Qtotal)
print(ans)


Measured memory_bytes: 25292
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	char s[n+1];
	cin >> s;
	int flag = 0;
	if (c > d)
	flag = 1;
	for(int i = b-1;i <= d-1;i++)
	{
	if (!(s[i-1] == '#' || s[i+1] == '#') && s[i] == '.')
	flag = 0;
	if (s[i] == '#' && s[i+1] == '#')
	{
		cout << "No";
		return 0;
	}
	}
	if (flag)
	{
		cout << "No";
		return 0;	
	}
	for(int i = a-1;i <= c-1;i++)
	{
	if (s[i] == '#' && s[i+1] == '#')
	{
		cout << "No";
		return 0;
	}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int m[4][3][10] = {0};

    int b, f, r, v;
    for (int i=0; i<n; ++i) {
        cin >> b >> f >> r >> v;
        m[b-1][f-1][r-1] += v;
    }

    for (int i=0; i<4; ++i) {
        for (int j=0; j<3; ++j) {
            for (int k=0; k<10; ++k) {
                cout << " " << m[i][j][k];
            }
            if (j != 2) {
                cout << "\n";
            }
        }
        if (i == 3) {
            cout << "\n";
        } else if (i != 3) {
            cout << "\n####################\n";
        }
    }

    return 0;
}

Measured memory_bytes: 1200
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println((int)(x-a - (x-a)/b * b));
    }
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define DEBUG true
#define $(x) {if (DEBUG) {cout << #x << " = " << (x) << endl;}}




int main() {
    string S;
    cin >> S;
    unordered_map<char, LL> m;
    EACH(s, S) {
        m[s]++;
    }
    LL minval = min(min(m['a'], m['b']), m['c']);
    m['a'] -= minval;
    m['b'] -= minval;
    m['c'] -= minval;
    EACH(mm, m) {
        if (mm.second != 0 && mm.second != 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
	
    return 0;
}


Measured memory_bytes: 512
N=int(input())
 
a=0
w=0
t=0
r=0
 
for i in range(N):
  s=input()
  if s=="AC":
    a+=1
  elif s=="WA":
    w+=1
  elif s=="TLE":
    t+=1
  else:
    r+=1

print("AC x",a)
print("WA x",w)
print("TLE x",t)
print("RE x",r)

Measured memory_bytes: 9204
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int A[101], n, cnt = 0;

void print () {
  for (int i = 0; i < n; i++)
    if (i == n - 1)
      cout << A[i] << endl;
    else
      cout << A[i] << " ";
}

void SelectionSort () {
  int minj;

  for (int i = 0; i < n; i++) {
    minj = i;

    for (int j = i; j < n; j++)
      if (A[j] < A[minj])
        minj = j;

    if (i != minj)
      cnt++;
    
    swap(A[i], A[minj]);
  }
}

int main () {
  cin >> n;

  for (int i = 0; i < n; i++)
    cin >> A[i];

  SelectionSort();
  print();
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3104
#include<iostream>
#include<vector>
#include<cmath>
#include<stdio.h>
#include<string>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	int cnt = 0;

	for (int a = 1; a <  n; a++) {
		if (n % a == 0) {
			cnt += n / a - 1;
		}
		else {
			cnt += n / a;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3600
s = input()

ans = 0
tmp = 0
flag = 0

for i, j in enumerate(s):
    if flag == 0 and j == 'A':
        tmp = i
        flag = 1
    elif flag == 1 and j == 'Z':
        ans = max(ans, i-tmp+1)
        flag = 2
    elif flag == 2:
        if j == 'Z':
            ans = max(ans, i-tmp+1)
        elif j == 'A':
            flag = 1

print(ans)

Measured memory_bytes: 3512