akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

struct point { double x, y; };

point  operator+(point a,  point b) { return {a.x+b.x, a.y+b.y}; }
point  operator-(point a,  point b) { return {a.x-b.x, a.y-b.y}; }
point  operator*(double t, point b) { return {t*b.x, t*b.y}; }
point  operator/(point a, double t) { return {a.x/t, a.y/t}; }

double operator*(point a,  point b) { return a.x*b.x + a.y*b.y; } // dot product
double operator%(point a,  point b) { return a.x*b.y - a.y*b.x; } // cross product

bool operator<(point a, point b) { // lexicographical compare
	if (abs(a.x-b.x) > eps) return a.x < b.x;
	return a.y + eps < b.y;
}

ostream &operator<<(ostream &out, point a) { // for debugging
	return out << "(" << a.x << "," << a.y << ")";
}

double abs(point a) { return hypot(a.x,a.y); }
point perp(point a) { return {-a.y,a.x}; } // rotate 90 degrees counterclockwise
point normalize(point a) { return a/abs(a); }

double angle(point a, point b) { // angle between two vectors (0 to pi)
	double d = normalize(a)*normalize(b);
	return acos(max(-1.0,min(1.0,d)));
}

ll ccw(point a, point b, point c) { // returns 1|0|-1 if c is left|straight|right of ab
	double res = (b-a)%(c-a);
	return abs(res) > eps ? (res > 0 ? 1 : -1) : 0;
}

bool on_segment(point p, point a, point b) {
	return (a-p)*(b-p) < eps && ccw(a,b,p) == 0;
}
void convex_hull(vector<point> &p) {
	partial_sort(begin(p), begin(p)+1, end(p));
	sort(begin(p)+1, end(p), [&](point a, point b) {
		if (ll c = ccw(p[0],a,b)) return c == 1;
		return abs(a-p[0]) < abs(b-p[0]);
	});
	ll n = sz(p), k = 2;
	FOR(i,2,n) {
		p[k++] = p[i];
		while (k >= 3 && ccw(p[k-3],p[k-2],p[k-1]) <= 0) p[k-2] = p[k-1], k--;
	}
	p.resize(k);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;

	vector<point> p = {{0,0}};
	FOR(i,0,n) {
		point a;
		cin >> a.x >> a.y;
		
		vector<point> q = p;
		for (point b: p) q.pb(a+b);
		convex_hull(q);
		p = q;
	}

	double res = 0;
	for (point a: p) res = max(res, abs(a));
	cout << fixed << setprecision(20) << res << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int e = c - (d - b);
    int f = d + (c - a);
    int g = e - (f - d);
    int h = f + (e - c);
    cout << e << ' ' << f << ' ' << g << ' ' << h << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int main(){

    int L;
    cin >> L;

   // cout << (long double)L;

    long double s = ((long double)L)/3;
    long double v = s*s*s;
     cout << setprecision(14)<<v;
}


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

using namespace std;

int main(void) {
  string A, B, C; cin >> A >> B >> C;

  if (*A.rbegin() == *B.begin() && *B.rbegin() == *C.begin()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    ll n;
    cin >> n;



    string nstr=to_string(n);
    bool check=true;
    for(int i=1;i<nstr.size();i++){
        if(nstr[i]!='9'){
            check=false;
            break;
        }
    }
    if(check){
        int top=nstr[0]-'0';
        cout << 9*(nstr.size()-1)+top << endl;
    }else{
        int top=(nstr[0]-'0')-1;
        int ans=9*(nstr.size()-1)+top;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll M = 1e9 + 7;
ll mypw(ll n, ll m)
{
    if(m <= 1) return n;
    ll k = mypw(n, m/2) % M;
    k = (k*k) % M;
    if(m & 1) return (k*n)%M;
    else      return k;
}
int main()
{
    ll n, k, ans = 0;
    cin >> n >> k;
    vector<ll> c(k+1);
    for(ll i = k; i >= 1; i--) {
        c[i] = mypw(k/i, n);
        for(ll j = i*2; j <= k; j+=i) {
            c[i] -= c[j];
            if(c[i] < 0) c[i] += M;
        }
        ans = (ans + (c[i]*i)%M) % M;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define LL long long
using namespace std;
deque<int>q;
LL n;
int idx=0;
void dfs(LL x){
    if(!x)return;
    if(x&1){
        dfs((x-1)>>1);
        q.push_back(++idx);
    }
    else{
        dfs(x-1);
        q.push_front(++idx);
    }
}
int main()
{
    int i,j;
    cin>>n;
    dfs(n);
    deque<int>::iterator it;
    cout<<2*idx<<endl;
    for(it=q.begin();it<q.end();it++)cout<<*it<<" ";
    for(i=1;i<=idx;i++)cout<<i<<" ";
    cout<<endl;
    return 0;
}


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

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

  sort(s.begin(),s.end());
  if (s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

long int saisyokoubai(long int c, long int d);

int main() {
	long int i, A, B, C, D, s, count = 0;
	long int AC, AD, As, BC, BD, Bs;

	scanf("%ld %ld %ld %ld", &A, &B, &C, &D);

	s = saisyokoubai(C, D);

	BC = B / C;
	BD = B / D;
	Bs = B / s;

	AC = (A - 1) / C;
	AD = (A - 1) / D;
	As = (A - 1) / s;

	printf("%ld\n", (B - (BC + BD - Bs)) - ((A - 1) - (AC + AD - As)));

	return 0;
}

long int saisyokoubai(long int c, long int d) {
	long int koubai, r, temp;

	koubai = c * d;

	if (c < d) {
		temp = c;
		c = d;
		d = temp;
	}

	r = c % d;

	while (r != 0) {
		c = d;
		d = r;
		r = c % d;
	}

	koubai /= d;

	return koubai;
}

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

int main() {
    long long int n, ans = 0;
    cin >> n;
    long long int a[n], diff;
    for(int i = 0; i < n; ++i) cin >> a[i];

    map<long long int, vector<long long int>> mp;

    for(int i = 0; i < n; ++i) {
        diff = a[i] - i;
        mp[diff].push_back(i);
    }
    auto begin = mp.begin(), end = mp.end();
    for(auto iter = begin; iter != end; iter++) {
        sort(iter->second.begin(), iter->second.end());
    }
    for(int i = 0; i < n; ++i) {
        long long int I = i + a[i];
        if(!mp[-I].empty()) {
            ans += distance(lower_bound(mp[-I].begin(), mp[-I].end(), I), mp[-I].end());
        }
    }
    cout << ans << '\n';
     
    return 0;
}


Measured memory_bytes: 39444
def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        # G 点に満たなければ nokori のうち一番大きいものを解く
        if sum < g:
            use = max(nokori)
            # 解く問題が問題数を超えないように注意
            n = min(pc[use - 1][0], -(-(g - sum) // (use * 100))) #ムダに-演算子を重ねているのは切り上げしたいから
            count += n
            sum += n * use * 100
        if sum >= g:
            ans = min(ans, count)
    else:
        # 総合スコア、解いた問題数、まだ解いてない問題を更新
        dfs(i + 1, sum, count, nokori)
        dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]
ans = float("inf")
dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int *sum;
    int n,q,i,max=0;
    int a[20],m[200];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&m[i]);
        if(max<m[i]){
            max = m[i];
        }
    }
    sum = (int*)malloc(sizeof(int)*(max+1));
    sum[0]=1;
    for(i=1;i<=max;i++){
        sum[i]=0;
    }
    for(i=0;i<n;i++){
        for(int j=max;j>=a[i];j--){
            if(sum[j-a[i]]==1){
                sum[j]=1;
            }
        }
    }
    for(i=0;i<q;i++){
        if(sum[m[i]]==1){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
}



Measured memory_bytes: 2100
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A = [I() for i in range(5)]
num = 0
tmp = 0
for i in range(5):
    if str(A[i])[-1] != "0":
        num = max(num,10 - int(str(A[i])[-1]) )
        tmp += 10
    if len(str(A[i]))!=1:
        tmp += 10*int(str(A[i])[:-1])

print(tmp-num)

Measured memory_bytes: 18844
import java.util.*

fun main(args: Array<String>) = agc043a()

fun agc043a() {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val board = Array(h) { readLine()!!.map { it == '.' } }

    val distances = Array(h) { IntArray(w) { Int.MAX_VALUE / 100 } }
    val queue = ArrayDeque(listOf(Triple(Position(0, 0), 0, true)))

    while (queue.isNotEmpty()) {
        val (position, beforeDist, isBeforeWall) = queue.pollFirst()
        val (y, x) = position
        val dist = beforeDist + if (isBeforeWall == board[y][x]) 0 else 1

        if (dist < distances[y][x]) {
            distances[y][x] = dist

            around.map { Position(y + it.first, x + it.second) }
                .filter { it.y in 0 until h && it.x in 0 until w }
                .map { Triple(it, dist, board[y][x]) }
                .map { if (board[y][x]) queue.addFirst(it) else queue.addLast(it) }
        }
    }

    val answer = Math.ceil(distances.last().last().toDouble() / 2).toInt()

    println(answer)
}

private val around = listOf(1 to 0, 0 to 1)

private data class Position(val y: Int, val x: Int)


Measured memory_bytes: 62576
/*
ソートするためにswap関数を作る
*/

#include<iostream>
using namespace std;

int swap(int *a, int *b){
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(a >= b){					//else ifにしないこと。
		swap(&a, &b);			//else ifにすると三つの条件全てを通らなくなる。
	}
	if(a >= c){
		swap(&a, &c);
	}
	if(b >= c){
		swap(&b, &c);
	}

	cout << a << " " << b << " " << c << endl;
	return 0;
}

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

namespace ABC103D
{
    class ABC103D
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);

            var map = new Dictionary<int, int>();

            int min = 0;
            for (int i = 0; i < m; ++i)
            {
                var req = Console.ReadLine().Split(' ');
                var a = int.Parse(req[0]);
                var b = int.Parse(req[1]);
                var d = b;

                if (!map.ContainsKey(a))
                {
                    map.Add(a, d);
                } else
                {
                    var v = map[a];
                    map[a] = (v > d) ? d : v;
                }
            }

            var prev = n;
            for (int i = (n - 1); i > 0; --i)
            {
                if (!map.ContainsKey(i)) continue;

                var v = map[i];
                if (v <= prev)
                {
                    ++min;
                    prev = i;
                }
            }

            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 21068
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int N = 1e5 + 5, MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s, t;
    cin>>s>>t;
    int cnt = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == t[i])    cnt++;
    }
    cout<<cnt;




    return 0;
}


Measured memory_bytes: 764
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

long long median(long long N, long long A[]) {
	long long med;
	if (N % 2 == 0) {
		med = (A[(N / 2) - 1] + A[N / 2]) / 2;
	}
	else {
		med = A[N / 2];
	}
	return med;
}

int main() {
	long long N;
	long long A[200001];
	long long b;
	long long ans = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i] -= i;
	}

	sort(A, A + N);
	b = median(N, A);
	for (int i = 0; i < N; i++) {
		ans += abs(A[i] - b);
	}
	cout << ans << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;
const int MAX = 110000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long PER(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n-k] % MOD;
}

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

    if (m == 1) {
        cout << 1 << endl;
        exit(0);
    }

    COMinit();

    map<int, int> mp;

    int i = 2;
    while (i * i <= m) {
        if (m % i == 0) {
            mp[i]++;
            m /= i;
        }
        else {
            i++;
        }
    }
    if (m > 1) mp[m]++;

    lint res = 1;

    for (auto&& p : mp) {
        int k = p.first, v = p.second;

        res *= COM(v+n-1, v);
        res %= MOD;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2816
#include <vector>
#include <stdio.h>
#include <queue>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int MAXN = (int)1e5 + 5;
const ll INF = (ll)1e18;

vector<P> G[MAXN];
ll dist[MAXN];

void dijkstra(int s) {
  for (int i = 0; i < MAXN; ++i) dist[i] = INF;
  priority_queue<P, vector<P>, greater<P> > q;
  dist[s] = 0;
  q.push(P(0, s));
  while (!q.empty()) {
    P cur = q.top(); q.pop();
    ll d = cur.first;
    int v = cur.second;
    if (d > dist[v]) continue;
    for (P next: G[v]) {
      ll d2 = next.first + d;
      int u = next.second;
      if (d2 < dist[u]) {
	dist[u] = d2;
	q.push(P(d2, u));
      }
    }
  }
}

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

  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    ll c;
    scanf("%d %d %lld", &a, &b, &c);
    a--; b--;
    G[a].push_back(P(c, b));
    G[b].push_back(P(c, a));
  }
  
  int q, k;
  scanf("%d %d", &q, &k);
  k--;
  dijkstra(k);
  ll ans[q];
  for (int i = 0; i < q; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--; y--;
    ans[i] = dist[x] + dist[y];
  }

  for (int i = 0; i < q; ++i) printf("%lld\n", ans[i]);
  return 0;
}



Measured memory_bytes: 11120
import sys
A=[]
fp =0
bp =0

n=int(raw_input())
while n:
    s = raw_input()

    if s[0] == 'i':
        A.append(int(s[7:]))
        fp += 1
    elif s[6] == ' ':
        try:
            i = A[::-1].index(int(s[7:]))
            if i!=-1:
                del A[-i-1]
                fp -=1
        except:
            pass
    elif s[6] == 'F':
        A.pop()
        fp -=1
    elif s[6] == 'L':
        bp +=1
    n -=1

for e in A[bp:fp+1][::-1]:
    print int(e),

Measured memory_bytes: 42372
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9
#define vint vector<int>

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

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

int gcd_three(int x, int y, int z){
    return gcd(gcd(x, y), z);
}

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                ans += gcd_three(i, j, k);
            }
        }
    }

    p(ans);
}

Measured memory_bytes: 3636
#include <assert.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <string>
#include <vector>

 
using namespace std;
 
typedef string str;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;




#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define trav(a, x) for (auto &a : x)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define PRINT_ARRAY(a, N)        \
  F0R(z, N) cout << a[z] << " "; \
  cout << "\n"
 
const int MOD = 1000000007;  // 998244353
const ll INF = 1e18;
const ld PI = 4 * atan((ld)1);


ll H, W;
char grid[1001][1001];
ll ways[1001][1001];

int main() {
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cout.tie(NULL);
		cin >> H >> W;
		F0R(i, H) cin >> grid[i];


		ways[0][0] = 1;

		for (int i = 1; i < W; i++) {
				if (grid[0][i] == '#') {
						ways[0][i] = 0;
						continue;
				}
				ways[0][i] = ways[0][i - 1];
		}

		for (int i = 1; i < H; i++) {
				if (grid[i][0] == '#') {
						ways[i][0] = 0;
						continue;
				}
				ways[i][0] = ways[i - 1][0];
		}

		for (int i = 1; i < H; i++) {
				for (int j = 1; j < W; j++) {
						if (grid[i - 1][j] != '#') ways[i][j] = (ways[i][j] + ways[i - 1][j]) % MOD;
						if (grid[i][j - 1] != '#') ways[i][j] = (ways[i][j] + ways[i][j - 1]) % MOD;
				}
		}

		cout << ways[H - 1][W - 1] << endl;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 2e6  +100;
int fat[N],inv[N];
// long long ? ?
const int M = 1e9 + 7;

int C(int n,int k){
	if(k>n)return 0;
	return mod(fat[n]*mod(inv[k]*inv[n-k],M),M);
}

int32_t main(){
  fastio;
  fat[0] = inv[0] = 1;
  for(int i=1;i<N;i++){
  	fat[i] = (fat[i-1]*i)%M;
  }
  inv[N-1] = exp(fat[N-1],M-2,M);
  for(int i=N-2;i>0;i--){
  	inv[i] = (inv[i+1]*(i+1))%M;
  }
  int x,y;
  cin>>x>>y;
  int i = (2*x - y)/3;
  int j = (2*y - x)/3;
  if(i<0 or j<0 or (2*x - y)%3!=0 or (2*y - x)%3!=0){
  	cout<<0<<endl;
  	return 0;
  }
  cout<< C(i+j,i) << endl;

}

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

long P = 998244353L;
long[(10^^5)*3+50] F, RF;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

long inv(long x)
{
    return pow(x, P-2);
}

void init()
{
    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long comb(N)(N n, N k)
{
    if (k > n) return 0;
    auto n_b = F[n];    // n!
    auto nk_b = RF[n-k]; // 1 / (n-k)!
    auto k_b = RF[k];    // 1 / k!

    auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!

    return (n_b * nk_b_k_b) % P;  // n! / (n-k)!k!
}

void main()
{
    init();
    auto nabk = readln.split.to!(long[]);
    auto N = nabk[0];
    auto A = nabk[1];
    auto B = nabk[2];
    auto K = nabk[3];

    long r;
    foreach (a; 0..N+1) {
        auto ap = A * a;
        auto bp = K - ap;
        if (bp < 0 || bp%B != 0 || bp/B > N) continue;
        auto b = bp/B;
        (r += comb(N, a) * comb(N, b) % P) %= P;
    }
    writeln(r);
}

Measured memory_bytes: 7444
// Date: 2020-03-22

#include <bits/stdc++.h>
#include <iomanip>
#include <ios>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout<<#x<<" = "<<x<<endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int main() {
    double x;
    cin >> x;
    x /= 3;
    double y = x*x*x;
    cout << fixed << setprecision(10) << y;

    return 0;
}

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

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

  bool flag = true;
  for (int i = 0; i < S.size(); i++) {
    if ((i % 2) == 0) {
      if (S.at(i) != 'R' && S.at(i) != 'U' && S.at(i) != 'D') {
        flag = false;
        break;
      }
    }
    else {
      if (S.at(i) != 'L' && S.at(i) != 'U' && S.at(i) != 'D') {
        flag = false;
        break;
      }
    }
  }

  if (flag == true) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;

const int maxn = 100100;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int T = 1; // cin >> T;
    while(T--){
       string s,t; cin >> s >> t;
       int n = int(s.length());
       int m = int(t.length());
       int ans = m;
       for(int i = 0; i < n - m + 1; i++){
          int val = 0;
          for(int j = 0; j < m; j++){
             if(s[j + i] != t[j]) val += 1;
          }
          ans = min(ans, val);
       }
       cout << ans << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;
const int MAX_N=1e5;
int divup(int x,int y){
    if(x%y==0)return x/y;
    else return x/y+1;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
typedef pair<int,int>P;

signed main(){
    int a,b,c;cin>>a>>b>>c;
    cout<<(b-a==c-b?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int64_t a[n]={0};
  int64_t sum=0;
  int64_t num[1000000]={0};
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum+=a[i];
    num[a[i]]++;
  }
  int q;
  cin >> q;
  int64_t b[q]={0},c[q]={0};
  int64_t sum2=0;
  for(int i=0;i<q;i++){
    cin >> b[i] >> c[i];
    sum2+=(c[i]-b[i])*num[b[i]];
    cout << sum+sum2 << endl;
    num[c[i]]+=num[b[i]];
    num[b[i]]-=num[b[i]];
    
  }
}
  


Measured memory_bytes: 13712
/*Saurav Paul*/
#include<bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int nax = 1e3 + 5;
char s[nax][nax] ;

int main()
{
	int n , m;
	scanf("%d%d",&n,&m);
	for(int i  = 0 ; i < n; i++) scanf("%s",s[i]);
	
	vector< vector<int> > dp(n,vector<int>(m) ) ;
	dp[0][0] = 1;
	for(int i = 0 ; i < n; i++){
		for(int j = 0 ; j < m ; j++){
			if(s[i][j] == '#') continue ;
			if(i) dp[i][j] = (dp[i-1][j]%mod + dp[i][j]%mod)%mod;
			if(j) dp[i][j] = (dp[i][j-1]%mod + dp[i][j]%mod)%mod;
		}
	}
	
	printf("%d\n",dp[n-1][m-1] );
    return 0;
}


Measured memory_bytes: 5120
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数
//if(cin.eof()) break; 入力数が決まってないとき
//ifstream  whilwee(ifs>>data)

// 浮動小数点
// cout << fixed; 以下と組fみ合わせで小数点以下n桁
// cout << setprecision(n) << 値; n桁表記
// defaultfloat

// 文字列d→int型　変換
// stoi(s)
// int s - '0'

///////////////// Queue /////////////

#define LEN 100005

struct pp{
    string name;
    int t;
};

pp Q[LEN];
int head, tail, n;

int isEmpty(){
    return head == tail;
}

int isFull(){
    return head == (tail + 1) % LEN;
}

void enqueue(struct pp x){
    Q[tail] = x;
    tail = (tail+1) % LEN;
}

pp dequeue(){
    pp x = Q[head];
    head = (head+1) % LEN;
    return x;
}

int main (){
    int c,elaps = 0;
    int n,q;
    cin >> n >> q;

    for(int i=1;i<=n;i++){
        string s;
        int aa;
        cin >> s;
        cin >> aa;
        Q[i].name = s;
        Q[i].t = aa;
    }

    head = 1; 
    tail = n+1;

    while(head!=tail){
        pp u = dequeue();
        c = min(q,u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0){
            enqueue(u);
        }else{
            cout << u.name << " " << elaps << endl;
        }
    }

}


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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    string s[3];
    rep(i,3) cin >> s[i];
    cout << s[0][0] << s[1][1] << s[2][2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(){
    long long n,p,ans=1;
    cin>>n>>p;
    long long e=p;
    for(int i=2;i<=sqrt(e);i++){
        int x=0;
        while(p%i==0){
            p=p/i;
            x++;
        }
        ans=ans*pow(i,x/n);
    }
    if(n>=2) cout<<ans;
    else cout<<e;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n , k;
    cin >> n >> k;

    int p = (n - 1) * (n - 2) / 2;

    if (p < k) {
        cout << -1;
        return 0;
    }

    set<array<int , 2> > pairs;
    vector<array<int , 2> > edges;

    for (int i = 2 ;i < n ;i++)
        for (int j = i + 1 ;j <= n ;j++)
            pairs.insert({i , j});

    for (int i = 2 ;i <= n ;i++)
        edges.push_back({1 , i});

    while (p > k) {
        edges.push_back(*pairs.begin());
        pairs.erase(pairs.begin());
        p--;
    }

    cout << edges.size() << '\n';
    for (auto &e : edges)
        cout << e[0] << ' ' << e[1] << '\n';
}

Measured memory_bytes: 512
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for x in range(1, H+1):
            if x % 2 != 0:
                for j in range(1, W+1):
                    if j % 2 != 0:
                        print('#', end='')
                    else:
                        print('.', end='')
                print('')
            else:
                for z in range(1, W+1):
                    if z % 2 != 0:
                        print('.', end='')
                    else:
                        print('#', end='')
                print('')
    print('')



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

int main(){
    int n;
    cin >> n;
    char s[n+1];
    rep(i,n) cin >> s[i];
    s[n] = s[0];
    int a[4][n+2];
    vector<bool> can(4, false);
    a[0][0] = 0; a[0][1] = 0;
    a[1][0] = 0; a[1][1] = 1;
    a[2][0] = 1; a[2][1] = 0;
    a[3][0] = 1; a[3][1] = 1;
    int c = -1;
    rep(i,4){
        for(int j = 1; j <= n; j++){
            if(s[j] == 'o' && a[i][j] == 0) a[i][j+1] = a[i][j-1];
            else if(s[j] == 'o' && a[i][j] == 1) a[i][j+1] = 1 ^a[i][j-1];
            else if(s[j] == 'x' && a[i][j] == 0) a[i][j+1] = 1 ^a[i][j-1];
            else if(s[j] == 'x' && a[i][j] == 1) a[i][j+1] = a[i][j-1];
         }
         if(a[i][n] == a[i][0] && a[i][n+1] == a[i][1]) c = i;
    }
    if(c == -1) cout << "-1" << endl;
    else{
        rep(i,n){
            if(a[c][i] == 0) cout << "S";
            else cout << "W";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 2048
//ALDS1_8C
#include <iostream>
#include <string>
using namespace std;

struct Node{
 int key;
 Node *right,*left,*parent;
};

Node *root,*NIL;

Node *treeMinimum(Node *x){
 while(x->left!=NIL) x=x->left;
 return x;
}

Node* find(Node *u,int k){
 while(u!=NIL && k!=u->key){
  if(k<u->key) u=u->left;
  else u=u->right;
 }
 return u;
}

Node *treeSuccessor(Node *x){
 if(x->right!=NIL) return treeMinimum(x->right);
 Node *y=x->parent;
 while(y!=NIL && x==y->right){
  x=y;
  y=y->parent;
 }
 return y;
}

void treeDelete(Node *z){
 Node *y;
 Node *x;
 if(z->left==NIL || z->right==NIL) y=z;
 else y=treeSuccessor(z);
 if(y->left!=NIL){
  x=y->left;
 }else{
  x=y->right;
 }
 if(x!=NIL){
 x->parent=y->parent;
 }
 if(y->parent==NIL){
  root=x;
 }else{
  if(y==y->parent->left){
   y->parent->left=x;
  }else{
   y->parent->right=x;
  }
 }
 if(y!=z){
  z->key=y->key;
 }
 delete y;
}

void insert(int k){
 Node *y=NIL;
 Node *x=root;
 Node *z;
 z=new Node;
 z->key=k;
 z->left=NIL;
 z->right=NIL;
 while(x!=NIL){
  y=x;
  if(z->key<x->key){
   x=x->left;
  }else{
   x=x->right;
  }
 }
 z->parent=y;
 if(y==NIL){
  root=z;
 }else{
  if(z->key<y->key){
   y->left=z;
  }else{
   y->right=z;
  }
 }
}

void inorder(Node *u){
 if(u==NIL) return;
 inorder(u->left);
 cout<<" "<<u->key;
 inorder(u->right);
}

void preorder(Node *u){
 if(u==NIL) return;
 cout<<" "<<u->key;
 preorder(u->left);
 preorder(u->right);
}

int main(){
 int n,x;
 string com;
 cin>>n;
 for(int i=0;i<n;i++){
  cin>>com;
  if(com=="find"){
   cin>>x;
   Node *t=find(root,x);
   if(t!=NIL) cout<<"yes"<<endl;
   else cout<<"no"<<endl;
  }else if(com=="insert"){
   cin>>x;
   insert(x);
  }else if(com=="print"){
   inorder(root);
   cout<<endl;
   preorder(root);
   cout<<endl;
  }else if(com=="delete"){
   cin>>x;
   treeDelete(find(root,x));
  }
 }
 return 0;
}

Measured memory_bytes: 19960
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static final long MAX = 10000000000l;
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            int a = Integer.parseInt(strArr[0]);
            int b = Integer.parseInt(strArr[1]);
            int c = Integer.parseInt(strArr[2]);
            if (b - a == c - b) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static int digit(long num) {
        return String.valueOf(num).length();
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define  INF 1100000000
using namespace std;

int main(){
	long long N, ans=0;
	cin >> N;
	vector<long long> A(N) ,B(N), C(N);
	for(int i=0;i<N;i++) cin >> A[i];
	for(int i=0;i<N;i++) cin >> B[i];
	for(int i=0;i<N;i++) cin >> C[i];
	
	sort(A.begin(),A.end());
	sort(C.begin(),C.end());
	for(int i=0;i<N;i++){
		long long Aans = lower_bound(A.begin(),A.end(),B[i]) - A.begin();
		long long Cans = upper_bound(C.begin(),C.end(),B[i]) - C.begin();
		ans += (N - Cans) * Aans;
	}	
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
    /* Dear Judge :i Tried Hard for Solving this problem
      please accept My solution I will remain grateful for that */
#define ON(x, k)    ((x)|(1<<(k)))
#define isOn(x, k)    ((x)&(1<<(k)))
//#define isOn(x, k)    ((x>>k)&1)
#define OFF(x, k)   ((x)&(~(1<<(k))))
#define TOGGLE(x, k)   ((x)^(1<<(k)))

    using namespace std ;
    int const c =1e4+5;
    int A[c];
     int main (){


    int n ;
    cin >> n ;
    if(n%2==0)
        cout << n ;
    else
        cout << n*2;
   /* int n , d ;
    cin >> n >> d ;
    if(n<1)
     cout << d;
    else
    cout << d*pow(100,n);
     */return 0;
     }


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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    string S, T;
    cin >> S >> T;
    int N = S.size();
    int M = T.size();
    vector<int> NOW;
    for(int i = 0; i <= N - M; i++){
        int now = i;
        bool ok = true;
        for(int j = 0; j < M; j++){
            if(S[now + j] != T[j] and S[j + now] != '?') ok = false;
        }
        if(ok) NOW.push_back(now);
    }
    if(NOW.empty()) puts("UNRESTORABLE");
    else{
        for(int i = 0; i < N; i++){
            if(S[i] == '?') S[i] = 'a';
            if(i == NOW.back()){
                for(int j = 0; j < M; j++){
                    S[i + j] = T[j];
                }
            }
        }
        cout << S << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

    int n,x;
    cin>>n>>x;

    int count = 1;

    int sum = 0,k;
    forn(i,0,n)
    {
        cin>>k;
        sum += k;
        if(sum <= x) count++;
    }

    cout<<count;

    return 0;
}   

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

int cnt[1000000];


int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) {
        cin >> a[i];
        cnt[a[i]]++;
        cnt[a[i]+1]++;
        if (a[i] > 0) {
            cnt[a[i]-1]++;
        }
    }
    int ma=-1;
    rep(i, 1e5+1) { ma = max(ma, cnt[i]); }
    cout << ma << endl;

}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
        int a;
        cin >> a;

        int b,bb,bbb;
        b = a / 100;
        bb = (a - b * 100) / 10;
        bbb = (a - b * 100 - bb * 10);
        if ( b == 7 || bb == 7 || bbb == 7){
                cout << "Yes" << endl;
        }
        else {
                cout << "No" << endl;
        }
}


Measured memory_bytes: 3592
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int N; LL M; int A[101010];

LL Count(int tot) {
	LL count = 0;
	for (int i = 0; i < N; ++i) {
		int Ay = tot - A[i];
		int idx = std::lower_bound(A, A + N, Ay) - A;
		count += N - idx;
	}
	return count;
}

LL Sum(int tot) {
  LL As[101010];
	for (int i = 0; i < N; ++i)    As[i] = A[i];
	for (int i = N-2; i >= 0; --i) As[i] += As[i + 1];

	LL sum = 0;
  for (int i = 0; i < N; ++i) {
		int Ay = tot - A[i];
		int idx = std::lower_bound(A, A + N, Ay) - A;
		int cnt = N - idx;
		sum += 1LL * A[i] * cnt;
		sum += As[idx];
	}
	return sum;
}

int main() {
  std::cin >> N >> M;
	for(int i = 0; i < N; ++i) std::cin >> A[i];
  std::sort(A, A + N);

	int l = 0, r = INT_MAX;
	while (l + 1 != r) {
		int mid = (l + r) / 2;
		if (M <= Count(mid)) l = mid;
		else r = mid;
	}

	LL ans = (M - Count(l + 1)) * l + Sum(l + 1);
  std::cout << ans << std::endl;
}


Measured memory_bytes: 1408
from collections import deque, defaultdict, Counter
from math import ceil, floor
import sys
def input():
    return sys.stdin.readline().strip()

H, W = map(int, input().split())

if H == 1 or W == 1:
    print(1)
    exit()

if H > W:
    H, W = W, H

# print(H, W)
ans = W * (H // 2)
# print(ans)
if H % 2 == 1:
    # print(ans)
    # print(W // 2 + 1)
    ans += ceil(W / 2)  # W // 2 + 1
print(ans)

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

#define ll long long
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;


int main() {
    int N,D;
    cin >> N >> D;
    int cnt=0;
    int a[20][20];
    for(int x=0;x<N;x++){
        for(int y=0;y<D;y++){
            cin >> a[x][y];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            double d =0;
            for(int h=0;h<D;h++){
                d += (a[i][h]-a[j][h])*(a[i][h]-a[j][h]);
            }
            d = sqrt(d);
            double dd = d;
            int ddd = dd;
            double dddd = ddd;
            if(d - dddd == 0) cnt++;
        }
    }
    cout << cnt << endl;
    
}

Measured memory_bytes: 256
n,p[1<<17][4];j,k;*d;main(a){for(scanf("%d",&n);n--;j=0)for(d=p[n];j<3;j++)for(k=-scanf("%d",&a);++k<3;)d[j]=fmax(d[j],j-k?p[n+1][k]+a:0);printf("%.f",fmax(*d,fmax(d[1],d[2])));}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int maxof(const int a[], int n){
  int i;
  int max = a[0];

  for(i = 1; i < n; i++){
    if(a[i] > max) max = a[i];
  }
  return max;
}
int main(){
    int N ; cin >> N ;
    int L[N];
    for(int i = 0; i <= N - 1;i=i+1) {
        cin >> L[i];
    }
    int nx = sizeof(L)/sizeof(L[0]);
    int max = maxof(L,nx);
    int sum =0 ;
    for (int i =0;i<N;i=i+1){
        sum += L[i];
    }
    
    int d_sum=sum - max ;
    if(max >= d_sum){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
p=[int(x) for x in input().split()]
s=[1 if i+1==element  else 0 for i,element in enumerate(p)]
ans=0
for i in range(n):
    if s[i]==1:
        ans+=1
        if i!=n-1:
            s[i+1]=0
print(ans)

Measured memory_bytes: 57644
#include <cstdio>
#include <string>
#include <map>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	int room[4][3][10] = {0};
	for (int i=0; i < n; i++) {
		int b, f, r, v;
		scanf("%d %d %d %d", &b, &f, &r, &v);
		room[b-1][f-1][r-1] += v;
	}
	for (int j=1; j <= 4; j++) {
		for (int k=1; k <= 3; k++) {
			for (int l=1; l <= 10; l++) {
				printf(" %d", room[j-1][k-1][l-1]);
			}
			printf("\n");
		}
		if (j != 4) {
			printf("%s\n", "####################");
		}
	}
}


Measured memory_bytes: 2752
#include<stdio.h>
#define abs(a) (a>0) ? (a) : (-(a))

int main()
{
    int n,x,i,sa,karisa,karisamin,city[100010],flag=1;
	scanf("%d %d",&n,&x);
	city[0]=x;
	if(x!=1)sa=x-1;
	sa=1000000000;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&(city[i]));
		karisa=abs((city[i]-city[i-1]));
		if(sa>karisa)sa=karisa;
	}
	karisamin=sa;
	while(flag)
	{
		flag=0;
		for(i=1;i<=n;i++)
		{
			karisa=abs((city[i]%sa-city[i-1]%sa));
			if(karisa!=0)
			{
				flag=1;
				if(karisamin>karisa)karisamin=karisa;
			}
		}
		if(flag==1)sa=karisamin;
		if(sa==1)flag=0;
	}
	
    printf("%d",sa);
}

Measured memory_bytes: 512
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = arr_data[0][0]


print("Yes" if n[0]==n[2] else "No")
    
    

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
const int mod = 1e9 + 7;
signed main()
{
    IOS
    int n,k; cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    int temp = 0;
    for(int i = 1;i < n;i++)
    {
        for(int j=0;j<i;j++)
        {
            if(arr[j] > arr[i]) temp++;
        }
    }
    int ans = (k*temp)%mod;
    temp = 0;
    sort(arr,arr+n);
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<i;j++)
        {
            if(arr[j] < arr[i]) temp++;
        }
    }
    int tans = ((k*(k-1))/2)%mod;
    tans = (tans*temp)%mod;
    ans = (ans + tans)%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256