akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    // vector<int> b;
    // for (int i = n - 1; i >= 0; i -= 2) {
    //     b.push_back(a[i]);
    // }
    // for (int i = n % 2; i < n; i += 2) {
    //     b.push_back(a[i]);
    // }
    deque<int> b;
    rep(i, n) {
        if (i % 2 == n % 2) {
            b.push_back(a[i]);
        } else {
            b.push_front(a[i]);
        }
    }
    rep(i, n) {
        printf("%d ", b[i]);
    }
    printf("\n");
    
}

Measured memory_bytes: 4744
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize
    }
    let d = 1000000007;
    let ps = primes(1000);
    let mut v: Vec<usize> = Vec::new();
    for p in ps {
        let mut m = n;
        let mut c = 1;
        while m > 0 {
            c += m / p;
            m /= p;
        }
        v.push(c);
    }
    let ans = v.iter().fold(1, |ac,x| ac * x % d);
    println!("{}",ans);
}

fn primes(n: usize) -> Vec<usize> {
    let mut ps = vec![2];
    let mut p = 3;
    while p <= n {
        let mut f = true;
        for x in ps.clone() {
            if x * x > p {
                break;
            } else if p % x == 0 {
                f = false;
                break;
            }
        }
        if f {
            ps.push(p);
        }
        p += 2;
    }
    ps
}


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

typedef long long int ll;

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define endl "\n"

int gcd(int m,int n)
{
	int rem;
	while(n!=0)
	{
		rem=m%n;
		m=n;
		n=rem;
	}
	return(m);
}
 
int main()
{
	fast;
	ll i,j,k,gcd1,gcd2,n,sum=0;
 
	cin>>n;

	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			for(k=1;k<=n;k++)
			{
				gcd1=gcd(i,j);
				gcd2=gcd(k,gcd1);
				sum+=gcd2;
			}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <cstring>
using namespace std;

bool used[1000];
bool ok(int x) {
	while (x) {
		if (used[x % 10]) return false;
		x /= 10;
	}
	return true;
}

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < k; i++) {
		int u;
		scanf("%d", &u);
		used[u] = true;
	}
	for (int i = n; i <= 99999; i++) 
		if (ok(i)) {
			printf("%d\n", i);
			return 0;
		}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;

  ll res = 0;
  REP(i, 0, N) {
    res += i;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
N=int(input())

for i in range (N):
    A,B,C = map(int,input().split())
    if A>B>=C:
        if A**2==B**2+C**2:
            print("YES")
        else:
            print("NO")
    elif A>C>=B:
            if A**2==C**2+B**2:
                print("YES")
            else:
                print("NO")
    elif B>A>=C:
        if B**2==A**2+C**2:
            print("YES")
        else:
            print("NO")
    elif B>C>=A:
        if B**2==A**2+C**2:
            print("YES")
        else:
            print("NO")
    elif C>A>=B:
        if C**2==A**2+B**2:
            print("YES")
        else:
            print("NO")
    else:
        if C**2==B**2+A**2:
            print("YES")
        else:
            print("NO")



Measured memory_bytes: 5604
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int h,w,d;
  cin >> h >> w >> d;
  vector<P> p(h*w);
  rep(i,h)rep(j,w){
    int a;
    cin >> a;
    p[a-1] = P(i,j);
  }
  vector<ll> s(h*w);
  rep(i,h*w-d){
    s[i+d] += s[i] + abs(p[i].first-p[i+d].first) + abs(p[i].second-p[i+d].second);
  }
  int q;
  cin >> q;
  rep(_,q){
    int l,r;
    cin >> l >> r;
    --l; --r;
    cout << s[r]-s[l] << endl;
  }
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll N,rs=0,ans=0;
    cin >> N;
    vector<string> S(N);
    string hako;

    for(ll i = 0;i < N;i++){
        cin >> S.at(i);
        sort(S.at(i).begin(),S.at(i).end());
    }
    sort(S.begin(),S.end());

    for(ll i = 0;i < N;i++){
        if(i == 0)
            hako = S.at(i);
        else{
            if(hako == S.at(i)){
                rs++;
                ans +=rs; 
            }else{
                rs = 0;
                hako = S.at(i);
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

const long long MOD = 1000000000 + 7;

inline long long modpow(long long n, long long p) {
    if (p == 0) {
        return 1;
    }

    long long half = modpow(n, p/2);
    long long mul = (n-1)*(p%2) + 1;

    return half * half % MOD * mul % MOD;
}

int main() {
    int N;
    int K;

    cin >> N >> K;
    vector <long long> ans(K+1);
    long long res = 0;

    for (int g = K; g >= 1; --g) {
        long long base = K/g;

        ans[g] = modpow(base, N);

        for (int j = 2*g; j <= K; j += g) {
            ans[g] -= ans[j];
        }

        ans[g] %= MOD;
        ans[g] = (ans[g]+MOD) % MOD;
        res = (res + ans[g]*g) % MOD;
    }

    cout << res << endl;

    return 0;
}

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

int main()
{
	int x,n;
	cin >> n;

	for (int i = 3; i <= n; i++)
	{
		x = i;

		if (x % 3 == 0)
		{
			cout << " " << i;
			continue;
		}

		while (x)
		{
			if (x % 10 == 3)
			{
				cout << " " << i;
				break;
			}
			x /= 10;
		}
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 123456789012345
#define int ll
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e5 + 10;

//initialization here
//

//
//initialization finish


// your function is here
//

//
// your function finished

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//

	int a,b; cin >> a >> b;
	
	if(a <= b) a++;

	a--;
	
	Print(a);

	//
	// your code finished


	return 0;
}

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

int main(){
    int N,D;
    cin >> N >> D;
    double d=0;
    int sum = 0;
    vector<vector<int>> X(N,vector<int>(D));
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin >> X.at(i).at(j);
        }
    }
    
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            double dis = 0;
            for(int k=0;k<D;k++){
                dis += (X.at(i).at(k)-X.at(j).at(k))*(X.at(i).at(k)-X.at(j).at(k));
            }
            dis = sqrt(dis);
            // cout << dis << endl;
            // cout << "int_dis"<< (int)dis << endl;
            if(dis == (int)dis){
                sum++;
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import math
n = int(input())
p = list(map(int, input().split()))

x = 0
ans = 0
for i in range(n):
    if i + 1 == p[i]:
        x += 1
    else:
        ans += math.ceil(x / 2)
        x = 0
ans += math.ceil(x / 2)

print(ans)


Measured memory_bytes: 13812
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n;
    cin>>n;
    int A=0;
    int T=0;
    for(int i=0;i<n;i++){
        int a,t;
        cin>>a>>t;
        if(i==0){
            A=a;
            T=t;
        }
        else{
            int e=(A-1)/a+1;
            int f=(T-1)/t+1;
            int g=max(e,f);
            A=a*g;
            T=t*g;
        }
    }
    cout<<A+T<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> xorsum;
vector<int> realsum;
int n;
int binsearch (int a, int b, int startsum, int startxor){
    int m = (a+b)/2;
    if((xorsum[m+1]^startxor) != (realsum[m+1]-startsum)){
        return binsearch(a,m, startsum, startxor);
    }
    if(m == n-1||(xorsum[m+2]^startxor)!=(realsum[m+2]-startsum)){
        return m;
    }
    return binsearch(m+1, b, startsum, startxor);
}
signed main()
{
    cin>>n;
    vector<int> a(n,0);
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    xorsum.resize(n+1, 0);
    realsum.resize(n+1, 0);
    for(int i = 1; i<n+1; i++){
        xorsum[i] = xorsum[i-1]^a[i-1];
        realsum[i] = realsum[i-1]+a[i-1];
    }
    int c = 0;
    for(int i = 0; i<n; i++){
        int r = binsearch(i, n, realsum[i], xorsum[i]);
        c += r-i+1;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 4992
// {{{ include and macros
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i, a, b) for(int i=a; i < b;i++)
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <deque>
#include <set>
using namespace std;
// }}}

// {{{ io
void newline() {cout << endl;}
template <typename T>
void display(T input){cout << input;}
template <typename T>
void put(T input){display(input); newline();}
  // }}}

const int n_max = 100000;
const int prime_number_max = 200270;
const int p_max = 100;
vector<int> prime_numbers;
int n, p;

void reserve_prime_numbers(){
   const int sievesize = prime_number_max;
   std::vector<int> sieve(prime_number_max, 1);
   sieve.reserve(prime_number_max);
   prime_numbers.reserve(prime_number_max);
   for (int i = 2; i * i < sievesize; i++)
      if (sieve[i])
         for (int j = i + i; j < sievesize; j += i)
            sieve[j] = 0;
   for (int j = 2; j < sievesize; j++)
      if (sieve[j])
        prime_numbers.push_back(j);
}

int get_index(){
  int i=0;
  for(; prime_numbers[i]<=n; i++){}
  return i;
}

int binary_search_index_rec(int s, int e){
  int i=(s+e)/2;
  if(s==e-1){return i;}
  if(prime_numbers[i]==n){return i;}
  if(prime_numbers[i]>n) return binary_search_index_rec(s, e-(e-s)/2);
  if(prime_numbers[i]<n) return binary_search_index_rec(s+(e-s)/2, e);
}

int binary_search_index(){
  return binary_search_index_rec(0, prime_numbers.size()-1);
}

int solve(){
  vector<int> prime_numbers_sum;
  int index = get_index();
  // int index = binary_search_index();
  for(int i=0+index; i<25+index; i++){
    for(int l=i; l<25+index; l++){
      int sum = prime_numbers[i] + prime_numbers[l];
        prime_numbers_sum.push_back(sum);
    }
  }
  sort(prime_numbers_sum.begin(), prime_numbers_sum.end());
  return prime_numbers_sum[p-1];
}

int main(){
  ios::sync_with_stdio(false);
  prime_numbers.reserve(prime_number_max);
  reserve_prime_numbers();
  while(cin >> n >> p && n != -1 && p != -1)
    put(solve());
}

Measured memory_bytes: 3424
#include<cstdio>
#include<algorithm>
using namespace std;
int n, K, w[101000], res = 1e9;
int main() {
	int i;
	scanf("%d%d", &n,&K);
	for (i = 1; i <= n; i++)scanf("%d", &w[i]);
	for (i = 1; i <= n - K + 1; i++) {
		int b = w[i], e = w[i + K - 1], t;
		if (b >= 0) t = e;
		else if (e <= 0)t = -b;
		else t = e - b + min(-b, e);
		res = min(res, t);
	}
	printf("%d\n", res);
}

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


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;

/* vector<ll> v(N);
  小さい順: sort(v.begin(), v.end());
  逆順: reverse(v.begin(), v.end());
  vector<pair<ll, ll> > p; ＃ソートした場合、１つ目でソート
  tie(b, a) = p.at(i); #pairを分割
  tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
  xの二乗:  pow(x, 2.0);
  int: -2,147,483,648 ～ 2,147,483,647(2×10^9)
  ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807(9×10^18)
  long long型の2次元配列(3×4要素の)の宣言
  vector<vector<ll>> data(3, vector<ll>(4));
  string -> int : stoi(S);
  int -> string : to_string(N);
  Sのn文字以降をm文字取り出す : S.substr(n,m)
*/
 
 //126~
 //

int main() {
  
  ll N,n1,n2,K, count=0, ans=0;
  string S,s1,s2;
  
  cin >> S;
  s1=S.substr(0,2);
  s2=S.substr(2.2);
  n1=stoi(s1);
  n2=stoi(s2);

  if(1<=n1&&n1<=12)count++;
  if(1<=n2&&n2<=12)count+=10;

  switch(count){
    case 0: cout << "NA" << endl; break;
    case 1: cout << "MMYY" << endl; break;
    case 10: cout << "YYMM" << endl; break;
    case 11: cout << "AMBIGUOUS" << endl; break;

  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
     
       if(a > b){
           int t = a;
           a = b;
           b = t;
       }
       
       if(b > c){
    	   int t = b;
    	   b = c;
    	   c = t;
       }
       
       if(a > b){
           int t = a;
           a = b;
           b = t;
       }
       
       System.out.printf("%d %d %d\n",a ,b ,c);
   }
}


Measured memory_bytes: 26324
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
   
   int n, flag = 0;
   cin >> n;
   while(n)
   {
   	if(n%10 == 7)
   		flag++;
   	n /= 10;
   }
   if(flag)
  	cout << "Yes";
   else
   cout << "No";
    return 0;
}


Measured memory_bytes: 3568
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> ns(5);
    for(int i = 0; i < 3; i++){
        int a, b;
        cin >> a >> b;
        ns[a]++;
        ns[b]++;
    }
    cout << (*max_element(ns.begin(), ns.end()) == 3 ? "NO" : "YES") << '\n';
}


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

int main(){
 string s;
 cin >> s;
 int a = 0, b = 0;
 rep(i,3){
   if(s.at(i) == 'B') ++b;
   if(s.at(i) == 'A') ++a;
 }
 if(a == 3 || b == 3) cout << "No" << endl;
 else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/b;
    printf("%d\n",d);
    printf("%d\n",r);
    printf("%f\n",f);
    
    return 0;
    }

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

using namespace std;

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

  for (int i = 0; i < k; i++) {
    if (s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python
# coding: UTF-8

from math import *
import os
import sys

#import scipy.optimize
import numpy as np


##################################################################
if __name__ == "__main__":
    Input = [input() for i in range(2)]
    N = int(Input[0])
    B = list(map(int,Input[1].split()))
    B.reverse()

    A = [1+1E5]*N
    for i in range(N-1):
        if B[i] <= A[i]:
            A[i] = B[i]
        A[i+1] = B[i]
    print(sum(A))


Measured memory_bytes: 12420
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define MAX ((ll)(1e17+100))
#define MX ((ll)(1e6+100))
#define ARRS ((ll)(2e6+100))
#define HS ((ll)(233))
#define MOD ((ll)(1e9+7))
#define EP ((double)(1e-9))
#define LG 21
#define mul(a,b) a=((a)*(b))%MOD
using namespace std;
ll n,s;
ll a[ARRS];

int main(){
	cin>>n>>s;
	for(int i=0; i<n; i++)cin>>a[i];
	sort(a,a+n);
	ll i;
	for(i=0; i<n; i++){
		s-=a[i];
		if(s<0){s+=a[i];break;}
	}
	if(s!=0&&i==n)
		cout<<n-1<<endl;
	else
		cout<<i<<endl;


}


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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007

signed main()
{
	init();
	solve();
}

int a, b, h;


void init()
{
	cin >> a >> b >> h;
}

void solve()
{
	int res = (a + b) * h;
	res /= 2;
	cout << res << endl;

}



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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  deque<char> S;
  string s;
  cin >> s;
  rep(i,s.length()) S.push_back(s[i]);
  int q;
  cin >> q;
  int revcount = 0;
  rep(i, q) {
    int t;
    cin >> t;
    if (t==1) revcount++;
    else {
      int f;
      char c;
      cin >> f >> c;
      if (revcount % 2 == 0) {
        if (f == 1) S.push_front(c);
        else S.push_back(c);
      }
      else {
        if (f == 2) S.push_front(c);
        else S.push_back(c);
      }
    }
  }
  if (revcount % 2 == 1) {
    while(!S.empty()) {
      cout << S.back();
      S.pop_back();
    }
  }
  else {
    while(!S.empty()) {
      cout << S.front();
      S.pop_front();
    }
  }
  cout << "\n";
  return 0;
}

Measured memory_bytes: 976
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int x, y;
	int result = 0;

	cin >> x >> y;
	if (x%y == 0) {
		result = -1;
	}
	else {
		while (1) {
			if (result%x == 0 && result%y != 0) {
				break;
			}
			result += x;
		}

	}
	cout << result;
	system("pause");
	return 0;
}

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

using namespace std;

int64_t mmc(int64_t a, int64_t b)
{
  return (a / __gcd(a, b)) * b;
}

int main(int argc, char* argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, M;
  cin >> N >> M;

  string S;
  cin >> S;

  string T;
  cin >> T;

  const int64_t L = mmc(N, M);
  const int64_t s_step = L / N;
  const int64_t t_step = L / M;
  const int64_t step = mmc(s_step, t_step);

  bool check = true;
  for (int64_t p = 0; check && p < L; p += step)
  {
    int i = p / s_step;
    int j = p / t_step;
    if (S[i] != T[j]) check = false;
  }

  cout << (check ? L : -1) << "\n";

  return 0;
}


Measured memory_bytes: 640
n, d = map(int, input().split())
distances = [list(map(int, input().split())) for _ in range(n)]
ans = 0

for i in range(n):
    for j in range(i + 1, n):
        diff_total = 0
        for k in range(d):
            diff = abs(distances[i][k] - distances[j][k])
            diff_total += diff * diff

        flag = False
        for k in range(diff_total + 1):
            if (k * k) == diff_total:
                flag = True
        if flag:
            ans += 1
print(ans)


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

int main()
{
	int N;
	string S,T;
	cin>>N;
	cin>>S>>T;
	
	int i,sz1=S.size(),sz2=T.size(),j,overlap=0;
	
	for (i=0;i<S.size();i++)
	{
		int st=i;
		for (j=0;j<T.size();j++)
		{
			if(S[st]==T[j])
			{
				st++;
			}
			
			else break;
		}
		
		if(st==S.size())
		{
			overlap=S.size()-i;
			break;
		}
		
	}
	
	printf("%d",sz1+sz2-overlap);
	
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iostream>
#include <list>
#include <functional>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
typedef long long ll;
const ll mll = 9223372036854775807;
const int mint = (2 << 31) - 1;
using namespace std;

int main()
{
	string s1, s2, s3 = "";
	cin >> s1 >> s2;
	for (int i = 0; i < s1.length(); i++)
	{
		s3 += s1[s1.length() - 1];
		for (int i = 0; i < s1.length() - 1; i++)s3 += s1[i];
		s1 = s3;
		if (s1 == s2)
		{
			printf("Yes\n");
			return 0;
		}
		s3 = "";
	}
	printf("No\n");

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
signed main() {
    string S;
    cin >> S;
    int ans = 1000000000;
    for(int i=0; i<S.length()-2; i++) {
        int n = abs(stoi(S.substr(i, 3)) - 753);
        ans = min(ans, n);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S; cin >> S;
	if (S == "ARC")cout << "ABC" << endl;
	else cout << "ARC" << endl;

	return 0;
}



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

const int MAX_N=1<<17;

typedef long long ll;

using namespace std;

ll n,dat[2*MAX_N-1];

void init(int n_){
	n=1;
	while(n<n_)n*=2;
}

void update(int k,ll a){
	k+=n-1;
	dat[k]=a;
	
	while(k>0){
		k=(k-1)/2;
		dat[k]=max(dat[2*k+1],dat[2*k+2]);
	}
}

ll query(int a,int b,int k,int l,int r){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k];
	else {
		ll vl=query(a,b,k*2+1,l,(l+r)/2);
		ll vr=query(a,b,k*2+2,(l+r)/2,r);
		return max(vl,vr);
	}
}

int main(void){
	
	ll in,m,ans=0;
	
	cin >> m;
	
	init(m);
	
	for(int i=0;i<m;i++){
		cin >> in;
		update(in,in+query(1,in,0,0,n));
	}
	cout << m*(m+1)/2-query(1,m+1,0,0,n) << endl;
	
	return 0;
}

Measured memory_bytes: 2744
#2005_c

n = int(input())
k = list("mcxi")
for i in range(n):
    d = {"m":0,"c":0,"x":0,"i":0}
    a,b  = input().split()
    a = list(a)
    b = list(b)
    a.insert(0,1)
    b.insert(0,1)
    for j in range(1,len(a)):
        if a[j] in k:
            if a[j-1] in k:
                d[a[j]] += 1
            else:
                d[a[j]] += int(a[j-1])
    for j in range(1,len(b))[::-1]:
        if b[j] in k:
            if b[j-1] in k:
                d[b[j]] += 1
            else:
                d[b[j]] += int(b[j-1])
            if d[b[j]] >= 10:
                l = b[j]
                while d[l] >= 10:
                    d[l] -= 10
                    l = k[k.index(l)-1]
                    d[l] += 1
    for j in k:
        if d[j]:
            if d[j] == 1:
                print(j,end = "")
            else:
                print(str(d[j])+j,end = "")
    print()



Measured memory_bytes: 5620
n = int(input())
v_list = list(map(int, input().split()))
count1 = [[0, i] for i in range(10**5)]
count2 = [[0, i] for i in range(10**5)]  # [v-1][数, 数値]

for i in range(0, n, 2):
    count1[v_list[i]-1][0] += 1
    count2[v_list[i+1]-1][0] += 1

count1 = sorted(count1)[::-1]
count2 = sorted(count2)[::-1]
if count1[0][1] == count2[0][1]:
    if count1[0][0] > count2[0][0]:
        ans = n - count1[0][0] - count2[1][0]
    elif count1[0][0] < count2[0][0]:
        ans = n - count2[0][0] - count1[1][0]
    else:
        ans = min(n - count2[0][0] - count1[1][0], n - count1[0][0] - count2[1][0])
else:
    ans = n - count1[0][0] - count2[0][0]
print(ans)


Measured memory_bytes: 73092
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    ll t;
//    cin >> t;
//    while(t--){
       int ans[4]={0};
       ll n;
       cin >> n;
       string s[n];
       for(int i=0;i<n;i++){
        cin >> s[i];
        if(s[i]=="AC"){
            ans[0]++;
        }
        if(s[i]=="WA"){
            ans[1]++;
        }
        if(s[i]=="TLE"){
            ans[2]++;
        }if(s[i]=="RE"){
            ans[3]++;
        }
       }
       cout << "AC x " << ans[0] << endl << "WA x " << ans[1] << endl << "TLE x " << ans[2] << endl << "RE x " << ans[3] << endl;
   // }
    return 0;
}


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

using namespace std;

vector<int> d(101, -1), f(101, -1);
vector<vector<int> > c;

int n, u, k, v;
int dfs(int node, int time) {
    d[node] = time;
    for(int i=0; i<n; ++i) {
        if(c[node][i]==1&&d[i]==-1) time = dfs(i, time+1);
    }
    time++;
    f[node] = time;
    return time;
}

int main() {
    cin >> n;
    for(int i=0; i<n; ++i) {
        cin >> u >> k;
        vector<int> tmp(100, 0);
        for(int j=0; j<k; ++j) {
            cin >> v;
            tmp[v-1] = 1;
        }
        c.push_back(tmp);
    }

    bool isFinished = false;
    int node = 0;
    int time = 0;
    while(isFinished==false) {
        time++;
        time = dfs(node, time);
        isFinished = true;
        for(node=0; node<n; node++) {
            if(d[node]==-1) {
                isFinished=false;
                break;
            }
        }
    }
    for(int i=0; i<n; ++i) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a,b,n;
  cin>>a>>b>>n;
  long ans,x;
  if(n<b)
    x=n;
  else x=b-1;
  long double t=x/b;
  cout<<(long)(a*x/b);
}

Measured memory_bytes: 3588
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#include <cmath>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll n, inp[105];
double ans;
int main(void) {
	double x;
	scanf("%d", &n);
	while (n--) {
		scanf("%lf", &x);
		ans += 1 / x;
	}
	printf("%lf\n", 1 / ans);
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n=5;
    REP(i,n){
        int a;cin>>a;
        if(a==0){
            cout<<i+1<<endl;
            return;
        }
    }
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3536
(let ((n (read))
    (ans 0))
    (loop for i from 1 while (<= (* i i) n) do
        (if (zerop (rem n i))
            (progn
                (if (zerop ans)
                    (setq ans (+ i (/ n i)))
                    (if (< (+ i (/ n i)) ans)
                        (setq ans (+ i (/ n i)))   
                    )
                )
                (if (not (= (* i i) n))
                ;;約数のときの処理((/ n i)が約数)
                    (if (< (* (/ n i) 2) ans)
                        (setq ans (* (/ n i) 2))
                    )
                )
            )
        )
    )
    (format t "~D~%" (- ans 2))
)

Measured memory_bytes: 24596
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處
const int MAXN = 2e5 + 2;
LL A[MAXN];
LL dp[MAXN][2];  // /2, /2+1

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    memset(dp, 0, sizeof(dp));
    dp[N-1][0] = 0;
    dp[N-1][1] = A[N-1];
    for (int i = N-2; i >= 0; --i) {
        int left = N-1-i+1;
        if (left % 2) {
            dp[i][0] = max(A[i] + dp[i+2][0], dp[i+1][0]);
            dp[i][1] = A[i] + dp[i+2][1];
        } else {
            dp[i][0] = max(A[i] + dp[i+2][0], dp[i+1][1]);
            dp[i][1] = 0;
        }
    }
    // for (int i = 0; i < N; ++i) {
    //     cout << dp[i][0] << ' ' << dp[i][1] << endl;
    // }
    cout << dp[0][0] << endl;
    return 0;
}


Measured memory_bytes: 8280
#include<stdio.h>

void clear(int *A, int N) {
	int i;
	for (i = 0; i < N - 1; i++)
		printf("%d ", A[i]);
	printf("%d", A[N - 1]);
	printf("\n");
}

void insertionSort(int *A, int N) {
	int i, v, j;
	for (i = 1; i < N; i++) {
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		clear(A, N);
	}
}

int main() {
	int N = 0;
	int A[1024];
	scanf("%d", &N);
	int i;
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	clear(A, N);
	insertionSort(A, N);
	return 0;
}

Measured memory_bytes: 1760
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<int> x(N), y(N), a(N);
  rep(i, N) cin >> x[i] >> y[i] >> a[i];
  int xmn = 0, xmx = W, ymn = 0, ymx = H;
  rep(i, N) {
    switch (a[i]) {
      case 1:
        chmax(xmn, x[i]);
        break;
      case 2:
        chmin(xmx, x[i]);
        break;
      case 3:
        chmax(ymn, y[i]);
        break;
      case 4:
        chmin(ymx, y[i]);
        break;
    }
  }
  int ans = max(0, xmx - xmn) * max(0, ymx - ymn);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

namespace fake
{
	typedef long long ll;

	const int N=101000;

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

	void initialize()
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			scanf("%d%d",L+i,R+i);
		std::sort(L+1,L+n+1),std::sort(R+1,R+n+1);
	}
	void solve()
	{
		initialize();

		ll ans=0,sum=0;

		for(int i=1;i<=n;i++)
		{
			ans=std::max(ans,(sum+L[n-i+1])*2);
			ans=std::max(ans,(sum-R[i])*2);

			sum=sum+L[n-i+1]-R[i];

			ans=std::max(ans,sum*2);
		}

		printf("%lld\n",ans);
	}
}

int main()
{
	fake::solve();
	return 0;
}


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

int main(){
    ll x;
    cin>>x;
    for(ll a=-118;a<=119;a++){
        for(ll b=-118;b<=119;b++){
            if(pow(a,5)-pow(b,5)==x){
                cout<<a<<" "<<b;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4000
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::VecDeque;

fn main() {
	input! {
		w: usize,
		h: usize,
		c: [[usize; 10]; 10],
		a: [[isize; w]; h],
	}

	// let inf = 999999999999999999usize;
	// let mut d: Vec<usize> = vec![inf; 10];
	// let mut q = VecDeque::new();
	// for i in 0..10 {
	// 	d[i] = c[i][1];
	// 	q.push_back(i);	// スタートノード, 距離
	// }
	// while q.len() > 0 {
	// 	let tmp = q.pop_front().unwrap();
	// 	for i in 0..10 {
	// 		if d[tmp] > c[tmp][i] + d[i] {
	// 			d[tmp] = c[tmp][i] + d[i];
	// 			q.push_back(tmp);
	// 		}
	// 	}
	// }
	let inf = 999999999999999999usize;
	let mut d: Vec<usize> = vec![inf; 10];
	d[1] = 0;
	for _i in 0..10 {
		for from in 0..10 {
			for to in 0..10 {
				if d[from] > d[to] + c[from][to] {
					d[from] = d[to] + c[from][to];
				}
			}	
		}
	}
	//println!("{:?}", d);
	let mut ans = 0;
	for i in 0..h {
		for j in 0..w {
			if a[i][j] != -1 {
				ans += d[a[i][j] as usize];
			}
		}
	}
	println!("{}", ans);
}



Measured memory_bytes: 2540
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba"){
    printf("Yes");
  }
  else{
    printf("No");
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  vector<ll> l(n);
  rep(i, n) {cin >> l[i];}
  int d = 0;
  int cnt = 1;
  rep(i, n) {
    d += l[i];
    if (d <= x) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define invrep(i, n) for(int i = (n)-1; i >= 0; i--)        // n-1, n-2, ..., 0
#define invREP(i, x, n) for(int i = (n)-1; i >= (x; i--)    // n-1, n-2, ..., x
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define PB push_back

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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

ll dp[100010];

int main(){
    int N, K; cin >> N >> K;
    vi h(N);
    rep(i, N) cin >> h[i];
    rep(i, 100010) dp[i] = INF;

    dp[0] = 0;

    rep(i, N){
        REP(j, 0, K + 1){
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    COUT(dp[N - 1]);
}

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

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

ll N;

int main(){
	cin>>N;
	ll res = 1000 - N % 1000;;
	res %= 1000;
	cout<<res<<endl;
    return 0;
}






Measured memory_bytes: 3632
import sys

n, *s = sys.stdin.readlines()
a = 0
b = 0
ba = 0
ans = 0
for i in s:
    if i[0] == 'B' and i[-2] == 'A':
        ba += 1
    elif i[0] == 'B':
        b += 1
    elif i[-2] == 'A':
        a += 1
    ans += i.count('AB')
if a == 0 and b == 0 and ba > 0:
    ba -= 1
ans += ba + min(a, b)
print(ans)


Measured memory_bytes: 3700
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

N = int(sys.stdin.readline())

a = []
b = list(map(int, sys.stdin.readline().rstrip().split()))

# print(b)
# aはbよりも1項多い
for i in range(N):
  
  if i == 0:
    a.append(b[i])
  elif i == N - 1:
    a.append(b[i-1])
  else:
    a.append(min(b[i-1], b[i]))


print(sum(a))

Measured memory_bytes: 3064
import java.util.*;class Main{public static void main(String[]z){int[]c=new int[4];String x;for(Scanner s=new Scanner(System.in);s.hasNext();)++c[(x=s.next()).contains("AB")?2:x.contains("A")?0:x.contains("B")?1:3];for(int i:c)System.out.println(i);}}

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

using namespace std;

const int maxn = 1e5 +  5;

int a[maxn];

int main()
{
   int n;
   cin >> n;
   int ans = 0;
   for(int i=1;i<=n;i++)
   {
       cin >> a[i];
       ans += abs(a[i] - a[i-1]);
   }
   ans += abs(a[n]);
   for(int i=1;i<=n;i++)
   {
       cout << ans - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i-1] - a[i+1]) << endl;
   }
   return 0;
}

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

static const int N = 1000;

int lcs(string X,string Y){
    int c[N+1][N+1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for(int i=1; i<=m; i++) c[i][0]=0;
    for(int j=0; j<=n; j++) c[0][j]=0;
    
    for(int i=1; i<=m; i++){
        for(int j=1; j<=n; j++){
            if(X[i]==Y[j]){
                c[i][j] = c[i-1][j-1]+1;
            }else{
                c[i][j] = max(c[i-1][j], c[i][j-1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }
    
    return maxl;
}

int main(){
    string s1,s2;
    int n; cin >> n;
    
    for(int i=0; i<n; i++){
        cin >> s1 >> s2;
        cout << lcs(s1,s2) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 7044
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

#一筆書きで動くことで必ず偶数のマス目最大化出来る(すべてなぞれれば良い)
H,W = map(int,input().split())
c = [list(map(int,input().split())) for i in range(H)]
bool = 0
op = 0
res = deque()
for i in range(H):
    if bool == 0:
        for j in range(W):
            if c[i][j] % 2:
                if i==H-1 and j==W-1:
                    continue
                elif j < W-1:
                    res.append((i+1,j+1,i+1,j+2))
                    c[i][j+1] += 1
                    op += 1
                else:
                    res.append((i+1,j+1,i+2,j+1))
                    c[i+1][j] +=1
                    op += 1
        bool = 1
    else:
        for j in range(W)[::-1]:
            if c[i][j]%2:
                if i==H-1 and j == 0:
                    continue
                elif j > 0:
                    res.append((i+1,j+1,i+1,j))
                    c[i][j-1] += 1
                    op += 1
                else:
                    res.append((i+1,j+1,i+2,j+1))
                    c[i+1][j] += 1
                    op += 1
        bool = 0
print(op)
while res:
    a,b,c,d = res.popleft()
    print(a,b,c,d)


Measured memory_bytes: 73820
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

struct edge {int to, i;};
vector<edge> G[100010];

int color[100010];

int dfs(int i=0, int p=-1, int c=-1) {
    int cnt = 1, maxc = 0;
    for (auto g:G[i]) {
        if (g.to == p) continue;
        if (cnt == c) cnt++;
        maxc = max(maxc, dfs(g.to, i, cnt));
        color[g.i] = cnt;
        cnt++;
    }
    return max(maxc, cnt-1);
}

int main() {
    int n;
    cin >> n;
    for (int i=0, a, b; i<n-1; i++) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back({b, i});
        G[b].push_back({a, i});
    }
    cout << dfs() << '\n';
    for (int i=0; i<n-1; i++) {
        cout << color[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 9344
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();
		long ans = 0;
		if(n >= 2) {
			ans += n * (n - 1) / 2;
		}
		if(m >= 2) {
			ans += m * (m - 1) / 2;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21716