akhauriyash/Code-Regression huggingface dataset:
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll n, d, a;
	scanf("%ld %ld %ld", &n, &d, &a);
	std::vector<P> xh(n);
	rep(i, 0, n) scanf("%ld %ld", &xh[i].fi, &xh[i].se);
	std::sort(be(xh));

	V b(n, 0);
	ll bius = 0, ans = 0;
	rep(i, 0, n){
		bius -= b[i];
		xh[i].se = std::max(0l, xh[i].se - bius * a);
		ll x = (xh[i].se + a - 1) / a;
		ans += x;
		bius += x;
		ll idx = std::upper_bound(be(xh), P(xh[i].fi+2*d,1e10)) - xh.begin();
		if(idx<n) b[idx] += x;
	}
	printf("%ld\n", ans);
	return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    long long ac = 0;
    long long pena = 0;
        
    vector<long long> wa(N, 0), isac(N, 0);
    for (int i = 0; i < M; ++i) {
        int p; string s;
        cin >> p >> s;
        --p;
        if (s == "AC") {
            if (!isac[p]) {
                ++ac;
                pena += wa[p];
                isac[p] = true;
            }
        }
        else wa[p]++;
    }
    cout << ac << " " << pena << endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
int c[4][4];
int x[8],y[8];
int ans;
int dfs(int X,int Y){
	if( X == 0 && Y == 4 ) return 1;
	if( c[Y][X] ) return dfs(X==3?0:X+1,X==3?Y+1:Y);
	int ans = 0;
	c[Y][X] = true;
	for(int i = 0 ; i < 8 ; i++){
		if( X+x[i] >= 0 && X+x[i] < 4 && Y+y[i] >= 0 && Y+y[i] < 4 ){
			if( c[Y+y[i]][X+x[i]] ){
				continue;
			}
			c[Y+y[i]][X+x[i]] = true;
			ans += dfs(X==3?0:X+1,X==3?Y+1:Y);
			c[Y+y[i]][X+x[i]] = false;
		}
	}
	c[Y][X] = false;
	return ans;
}
int main(){
	int n;
	while(1){
		for(int i = 0 ; i < 4 ; i++){
			cin >> x[i] >> y[i];
			x[4+i] = -x[i];
			y[4+i] = -y[i];
			
			if( x[i] > 4 ) return 0;
		}
		ans=dfs(0,0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    ll n;
    cin>>n;
    vector<ll> a(n+1);
    rep(i,n){
        cin>>a[i];
    }
    ll t=1000;
    for(int i=1;i<n;i++){
        if(a[i-1]>a[i]){
            
        }else if(a[i-1]<a[i]){
            t+=-t/a[i-1]*a[i-1]+t/a[i-1]*a[i];
        }
    }
    cout<<t<<endl;
}

Measured memory_bytes: 3576
n = int(input())
tt = list(map(int,input().split()))
    
ss = 1

for i in tt:
    p = []
    p.append(int(ss))
    p.append(int(i))
    q = list(sorted(p))
    while q[1] % q[0] != 0:
        r = [q[1] % q[0] , q[0]]
        s = list(sorted(r))
        q[0] = int(s[0])
        q[1] = int(s[1])

        
    ss = int(ss * i) // q[0]
num = ss
kouho = 0

for onenum in tt:
    kouho += (num-1) % onenum

print(kouho)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>

using namespace std;

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

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

    int count = 1;
    for (int i = 1; i < n; ++i) {
        bool flag = true;
        for (int j = 0; j < i; ++j) {
            if (H[j] > H[i]) {
                flag = false;
                break;
            }
        }

        if (flag)
            ++count;
    }
    cout << count << '\n';
}


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

int main()
{
    string s;
    cin >> s;
    int n = s.length() - 2, x = 0;
    rep(i,n){
        int nn = stoi(s.substr(i,3));
        if (abs(nn-753)<abs(x-753)) x = nn;
    }
    cout << abs(x - 753) << endl;
    return 0;
}

Measured memory_bytes: 256
import collections

H, W = map(int, input().split())
s = [list(input()) for i in range(H)]

z = [["b"] * W for _ in range(H)] #チェックしたマスはb(before)からa(after)にする
black = 0
for i in range(H):
    black += s[i].count("#") #最初の黒の数を数える
v = [[1,0], [0,1], [-1,0], [0,-1]] #動き方4パターン(↓ → ↑ ←)
que = collections.deque() #調べる候補リスト #調べ終わった要素は消す

#まず[0,0]
z[0][0] = "a"
s[0][0] = 1 #何歩で来れたかを代入していく #最初は1
que.append([0,0]) #最初の候補は[0,0]

#最短ルートを探す
while len(que) != 0: #候補がなくなるまで繰り返す
    i = que.popleft() #候補のうち1つを取り出し、リストから消す
    for dy, dx in v: #4パターンの動き方を考える
        y = i[0] + dy
        x = i[1] + dx
        if (0<=y<H and 0<=x<W and s[y][x]=="." and z[y][x]=="b"):
            z[y][x] = "a"
            s[y][x] = s[i[0]][i[1]] + 1
            que.append([y,x]) #進んだマスを新しく候補に入れる

if s[-1][-1] == ".": #[H,W]のマスに数字が入ってない→ゴールできない
    print(-1)
else: #「消せる白の最大数」=「全マス」-「黒マス」-「最短ルート」
    print(H*W - black - s[-1][-1])


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

deque<char> ans;

int search(int n, vector<vector<int>> &next, string &s) {
    char c = 0;
    for (int cur = 0; cur <= n; ) {
        int maxi = cur;
        for (int i = 0; i < 26; i++) {
            if (next[cur][i] == -1 || next[cur][i] > n) {
                c = 'a' + i;
                maxi = -1;
                break;
            } else maxi = max(next[cur][i], maxi);
        }
        if (maxi == -1) break;
        cur = maxi;
    }
    ans.emplace_back(c);
    for (int i = n-1; i >= 0; i--) {
        if (s[i] == c) return i;
    }
    return -1;
}

int main() {
    string s; cin >> s;
    int n = s.size();
    reverse(s.begin(), s.end());
    vector<vector<int>> next(n+1, vector<int>(26, -1));
    for (int i = 0; i < n; i++) {
        next[i][s[i]-'a'] = i+1;
    }
    for (int i = n; i > 0; i--) {
        for (int j = 0; j < 26; j++) {
            if (next[i-1][j] == -1) next[i-1][j] = next[i][j];
        }
    }
    int u = n;
    while (true) {
        int ret = search(u, next, s);
        if (ret == -1) break;
        else u = ret;
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

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

int main(void)
{
	int node[128] = {0};
	int from, to;
	int flag = 0;
	int i;
	
	while (~scanf("%d %d", &from, &to)){
		if (from + to) {
			node[from] = !node[from];
			node[to] = !node[to];
			
			flag += node[from] ? 1 : -1;
			flag += node[to] ? 1 : -1;
		}
		else {
			puts((flag == 2 && node[1] + node[2] == 2) ? "OK" : "NG");
			
			//initialize
			memset(node, 0, sizeof(node));
			flag = 0;
		}
	}
	
	return (0);
}

Measured memory_bytes: 584
using System;

namespace _5_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var hw = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                var h = hw[0];
                var w = hw[1];
                if (h == 0 && w == 0) break;
                for (var i = 0; i < h; i++)
                {
                    for (var j = 0; j < w; j++)
                    {
                        if (i == 0 || j == 0 || i == h - 1 || j == w - 1)
                        {
                            Console.Write("#");
                        }
                        else
                        {
                            Console.Write(".");
                        }
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 18016
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		long[] b = new long[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		long ans = 0;
		for(int i = n - 1 ; i >= 0 ; i--) {
			ans += (a[i] + ans + b[i] - 1) / b[i] * b[i] - (a[i] + ans);
		}
		System.out.println(ans);
	}
}


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

int main(){
    int n;
    cin>>n;
    vector<int>h;
    h.push_back(0);
    rep(i,n){
        int a; cin>>a;
        h.push_back(a);
    }
    h.push_back(0);
    int x=h.size();
    int l,r,ans=0;
    while(1){
        bool go=true;
        rep(i,x){
            if(h[i]!=0){
                l=i;
                go=false;
                break;
            }
        }
        if(go)break;
        for(int i=l; i<x; ++i){
            if(h[i]==0){
                r=i-1;
                break;
            }
        }
        for(int i=l; i<=r; ++i){
            h[i]--;
        }
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var rgb = input.Split(' ');
            var value = int.Parse(String.Join("", rgb));
            var result = value % 4 == 0 ? "YES" : "NO";
            Console.WriteLine(result);
        }
    }
}

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

// Macros
#define F  first
#define S  second
#define PB push_back

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// HELPERS
//  Tedious Grid Movements
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
inline bool move_okay(int x, int y, int n, int m) { return 0 <= x and x < n and 0 <= y and y < m; }
//  Remember:
//   * vec.assign() GOOD; vec.resize() BAD
//   * comparator uses <

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const set<T> &v)    { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T,S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T,S> &v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef SANYAM1101
	#define trace(args...) do{ cerr << "TRACE ON! (Line: " << __LINE__ << ")\n"; auto _stream = istringstream{string{#args}}; d_f(_stream, args); } while(0)
	void d_f(__attribute__((unused)) istringstream& _stream) {}
	template<typename Head, typename... Tails> void d_f(istringstream& _stream, Head H, Tails... T) { string _name; _stream >> _name; if(_name.back() == ',') _name.pop_back(); cerr << "\t" << _name << " <=> [" << H << "]\n"; d_f(_stream, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

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

	vector<int> a(n);
	for(auto& i : a) cin >> i;

	int legends = 0;

	vector<int> cou(8, 0);
	for(auto i: a){
		if(3200 <= i) ++legends;
		else ++cou[i / 400];
	}

	int diff_colors = 8 - count(cou.begin(), cou.end(), 0);

	cout << max(diff_colors, 1) << " "
	     << diff_colors + legends << "\n";
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,count=0;
    cin >> n;
    pair<ll,ll> r[n],b[n];
    for (ll i=0;i<n;i++){
        ll x,y;
        cin >> x >> y;
        r[i]=make_pair(x,y);
    }
    
    for (ll i=0;i<n;i++){
        ll x,y;
        cin >> x >> y;
        b[i]=make_pair(x,y);
    }
    
    sort(r,r+n,pairCompareSecond);
    sort(b,b+n,pairCompare);
    bool matched[n];
    fill(matched,matched+n,false);
    
    for (ll i=0;i<n;i++){
        for (ll j=0;j<n;j++){
            if (matched[n-j-1]){
                continue;
            }
            if (r[n-j-1].second<b[i].second and r[n-j-1].first<b[i].first){
                matched[n-j-1]=true;
                count++;
                break;
            }
        }
    }
    cout << count << endl;
    return 0;
}


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

int n;
vector<int> p;

int main() {
    cin >> n;
    p.resize(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    int count = 0;
    for (int i = 1; i < n-1; i++) {
        if (p[i-1] < p[i] && p[i] < p[i+1]) count++;
        else if (p[i+1] < p[i] && p[i] < p[i-1]) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import math
from scipy.misc import comb

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = map(int, input().split())

answer = 0
if N >= 2:
    answer += combinations_count(N, 2)
if M >= 2:
    answer += combinations_count(M, 2)
print(answer)

Measured memory_bytes: 13288
import itertools
from collections import defaultdict
import collections
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for i in range(n)]

ans = mod
for i in range(2 ** n):
    alg = [0] * (m+1)
    switch = [0] * n
    for j in range(n):
        if((i >> j) & 1):
            switch[j] = 1
    for k in range(n):
        for l in range(m + 1):
            if switch[k] == 1:
                alg[l] += ca[k][l]
    for y in range(m+1):
        if y != 0:
            if x > alg[y]:
                break
        if y == m:
            ans = min(ans, alg[0])

if ans == mod:
    print("-1")
else:
    print(ans)

Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
constexpr double eps = 1e-6;
constexpr ll LINF = 100200300400500600ll;
constexpr int INF = 2*((1<<30)-1)+1;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {-1,0,1,0};
constexpr int mod = 1000000007;
#define Yes(ifeq) cout<<(( ifeq )? "Yes":"No")<<endl;

void Main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(true){
    c-=b;
    if(c<1){
      cout<<"Yes"<<endl;
      return;
    }
    a-=d;
    if(a<1){
      cout<<"No"<<endl;
      return;
    }
  }
  
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	template<typename T> inline int ts(T *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 5007;

int n,sa[_],sb[_],na,nb;
vector<int> va,vb;

int main()
{
	n=ty(),ts(sa+1),ts(sb+1);

	for(int i=1;i<=n;i++)sa[i]-=48,sb[i]-=48;
	for(int i=1;i<n;i++)
	{
		if(sa[i]!=sa[i+1])va.emplace_back(i);
		if(sb[i]!=sb[i+1])vb.emplace_back(i);
	}
	na=va.size(),nb=vb.size();

	if(!na || !nb)
	{
		int cnt=0;
		for(int i=1;i<=n;i++)cnt+=sa[i]!=sb[i];
		printf("%d\n",cnt);
		
		return 0;
	}

	int ans=1e9,dlt=sa[va[0]]!=sb[vb[0]];
	for(int i=-(na+((na&1)^dlt));i<=nb+((nb&1)^dlt);i+=2)
	{
		int sum=0;
		for(int j=min(0,-i),k=j+i;j<max(na,nb-i);j++,k++)
		{
			int xa=0,xb=0;
			if(j>=0 && j<na)xa=va[j];
			else if(j>=na)xa=n;
			if(k>=0 && k<nb)xb=vb[k];
			else if(k>=nb)xb=n;
			sum+=abs(xa-xb);
		}
		ans=min(ans,sum);
	}

	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 512
n = int(input())
t, a = map(int, input().split())
(*h,) = map(int, input().split())
x = (t - a) * 1000 // 6
h_min = 10 ** 5
for i in range(n):
    if abs(h[i] - x) < h_min:
        h_min = abs(h[i] - x)
        ans = i
print(ans + 1)

Measured memory_bytes: 9268
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int count=0;
    for(int i=1;i<=n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        if (a==b){
            count++;
            if (count==3){
                printf("Yes\n");
                return 0;
            }
        }
        else{
            count=0;
        }
    }
    printf("No\n");
}

Measured memory_bytes: 3764
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  1000005

ll fact[N];

void solve()
{
	ll n;
	cin>>n;
	string s;
	cin>>s;
	string tmp="";
	rep(i,1,n)
	{
		ll ptt=abs(s[i]-s[i-1]);
		tmp+=(char)(ptt+'0');
	}
	s=tmp;
	// cout<<s<<endl;
	n--;
	fact[0]=0;
	ll num;
	rep(i,1,n+1)
	{
		num=i;
		while(num!=0)
		{
			num/=2;
			fact[i]+=num;
		}
	}
	bool f=0;
	ll ans=0;
	rep(i,0,n)
	{
		if(s[i]=='1')
		{
			num=fact[n-1]-fact[i]-fact[n-i-1];
			// cout<<num<<" ";
			if(num==0)
				ans++;
			f=1;
		}
	}
	// cout<<endl;
	if(ans&1)
	{
		cout<<1<<endl;
		return;
	}
	if(f)
	{
		cout<<0<<endl;
		return;
	}
	ans=0;
	rep(i,0,n)
	{
		if(s[i]=='2')
		{
			num=fact[n-1]-fact[i]-fact[n-i-1];
			if(num==0)
				ans++;
			f=1;
		}
	}
	if(ans&1)
	{
		cout<<2<<endl;
	}
	else
	{
		cout<<0<<endl;
	}
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 10064
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF = 100100100;
using namespace std;

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

    int H, W, h, w;
    cin >> H >> W >> h >> w;

    int ans = H * W - H * w - W * h + w * h;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int VMAX=10001;
int T[VMAX+1];
int solve(int A[],int n,int Min){
  int ans=0;
  int *B=new int[n];
  bool *v=new bool[n];
  for(int i=0;i<n;i++){
  	B[i]=A[i];
  	v[i]=false;
  }

  sort(B,B+n);
  for(int i=0;i<n;i++) T[B[i]]=i;
  for(int i=0;i<n;i++){
  	if(v[i])continue;
  	int an = 0;
	int m = VMAX;//
	int cur = i;
	int s = 0;
	if(i!=T[A[i]]){
	while(1){
	  	  an++;
	      v[cur]=true;
	      int t=A[cur];
	      m=min(m,t);
	      s+=t;
	      cur=T[t];
	      if(v[cur])break;
	   }

	   ans+=min(s+(an-2)*m,s+m+(an+1)*Min);    

  	}
  }
   return ans;
}
int main(){
	int n;
	int Min=VMAX;//
	cin>>n;
	int *A=new int[n];
	for(int i=0;i<n;i++){
		cin>>A[i];
		Min=min(Min,A[i]);
	}
	int ans=solve(A,n,Min);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m, p[50];
string str;

int main(){
	cin >> n;
	for(ll i = 1; i <= n; i++){
		cin >> p[i];
	}
	
	ll ans = 0;
	for(ll i = 2; i < n; i++){
		if(p[i-1] < p[i] && p[i] < p[i+1]){
			ans++;
		}
		if(p[i-1] > p[i] && p[i] > p[i+1]){
			ans++;
		}
	}
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define FOR(i, x, y) for(int i = x; i < y; i++)
#define endll cout << "\n"
#define For(n) for(int i = 0; i < n; i++)
const ll maxn = 1000000 + 100;
const int mod = 1e9 + 7;
int a[maxn];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, res = 0, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    for(int i = n - 1; i >= 0 && k; i --)
    {
        k --;
        res += a[i];
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)

fin = sys.stdin.readline

n, k = map(int, fin().split())


def f(i):
    if i == 1:
        ans = n - k + 1
        print(ans % (10 ** 9 + 7))
        return ans
    else:
        ans = f(i - 1) * (k - i + 1) // (i - 1) * (n - k - i + 2) // i
        print(ans % (10 ** 9 + 7))
        return ans


f(k)


Measured memory_bytes: 50928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int H,W; 
    cin>>H>>W;
    int A[H][W];
    rep(i,H){
        rep(j,W){
            cin>>A[i][j];
        }
    }

    vector<int> x,y,nx,ny;
    rep(i,H){
        rep(j,W-1){
            if(A[i][j]%2==1){
                A[i][j]--;
                A[i][j+1]++;
                x.push_back(i+1);
                y.push_back(j+1);
                nx.push_back(i+1);
                ny.push_back(j+2);
            }
        }
    }

    rep(i,H-1){
        if(A[i][W-1]%2==1){
            A[i][W-1]--;
            A[i+1][W-1]++;
            x.push_back(i+1);
            y.push_back(W);
            nx.push_back(i+2);
            ny.push_back(W);
        }
    }

    cout<<x.size()<<endl;
    rep(i,x.size()){
        cout<<x[i]<<" "<<y[i]<<" "<<nx[i]<<" "<<ny[i]<<endl;
    }
}

Measured memory_bytes: 6336
l, r = gets.chomp.split(' ').map{|i| i.to_i }

min = 2020
(r - l + 1).times{|i1|
  i = i1 + l
  (r - l + 1 - i1 - 1).times{|j1|
    j = i + j1 + 1
    im = i % 2019
    jm = j % 2019
    if im * jm == 0
      puts 0
      exit 0
    end
    mod = (im * jm) % 2019
    if mod < min
      min = mod
    end
  }
}

puts min


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

int main() {
	cin.tie(0)->sync_with_stdio(false);

	int n; cin >> n;
	vector<int> x(n), y(n), h(n);
	int t;
	REP(i, n) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] > 0) t = i;
	}

	REP(cy, 101) REP(cx, 101) {
		ll ch = h[t] + abs(x[t] - cx) + abs(y[t] - cy);
		ch = max(ch, 0LL);
		bool ok = true;
		REP(k, n) {
			ll tmp = ch - abs(x[k] - cx) - abs(y[k] - cy);
			if (h[k] != max(tmp, 0LL))
				ok = false;
		}
		if (ok) {
			cout << cx << " " << cy << " " << ch << '\n';
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	string s,t;
	cin >> s >> t;
	map<char, int> mps,mpt;
	rep(i, s.length()) mps[s[i]]++;
	rep(i, t.length()) mpt[t[i]]++;
	string ans = "No";
	string ss = "", tt = "";
	rep(i,26) {
		char c = 'a'+i;
		char d = 'z'-i;
		rep(j, mps[c]) ss += c;
		rep(j, mpt[d]) tt += d;
	}
	rep(i, max(s.length(), t.length())) {
		if(i == s.length()) {
			cout << "Yes" << endl;
			return 0;
		}
		if(i == t.length()) {
			cout << "No" << endl;
			return 0;
		}
		if(ss[i] < tt[i]) {
			cout << "Yes" << endl;
			return 0;
		}
		if(ss[i] > tt[i]) {
			cout << "No" << endl;
			return 0;
		}
	}


	cout << ans << endl;

  return 0;
}


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

long long N, M, R, r[211], A[1 << 18], B[1 << 18], C[1 << 18], dist[211][211], minx = (1 << 30);

int main() {
	cin >> N >> M >> R;
	for (int i = 1; i <= R; i++) cin >> r[i];
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) dist[i][j] = (1 << 30); dist[i][i] = 0; }
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i] >> C[i];
		dist[A[i]][B[i]] = C[i]; dist[B[i]][A[i]] = C[i];
	}
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
		}
	}
	int G[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };

	do {
		long long sum = 0;
		for (int i = 0; i < R - 1; i++) sum += dist[r[G[i]]][r[G[i + 1]]];
		minx = min(minx, sum);
	} while (next_permutation(G, G + R));

	cout << minx << endl;
	return 0;
}


Measured memory_bytes: 4864
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>

using namespace std;
typedef long long LL;
#define pb push_back
const int maxn = 200005;

int ehead[maxn],ecnt;
struct edge {
	int u,v,w,next;
}edg[maxn];
void add(int u,int v) {
	edg[++ecnt]=(edge){u,v,1,ehead[u]};
	ehead[u]=ecnt;
	edg[++ecnt]=(edge){v,u,2,ehead[v]};
	ehead[v]=ecnt;
}
int n,m,col[maxn],cnt[3],siz,tag;LL ans;
LL sqr(LL x) {return x*x;}

void dfs(int u)
{
	cnt[col[u]]++;
	for (int j=ehead[u];j;j=edg[j].next) {
		int v=edg[j].v;++siz;
		if (col[v]<0) col[v]=(col[u]+edg[j].w)%3,dfs(v);
		else if (col[v]!=(col[u]+edg[j].w)%3) tag=false;
	}
}
int main()
{
	#ifdef Amberframe
		freopen("agc006f.in","r",stdin);
		freopen("agc006f.out","w",stdout);
	#endif
	scanf("%d %d",&n,&m);
	for (int u,v,i=1;i<=m;i++)
		scanf("%d %d",&u,&v),add(u,v);
	memset(col,-1,sizeof col);
	for (int i=1;i<=n;i++)
	if (col[i]<0) {
		cnt[0]=cnt[1]=cnt[2]=siz=0;
		col[i]=0;tag=true;dfs(i);
		if (!tag) ans+=sqr(cnt[0]+cnt[1]+cnt[2]);
		else if (cnt[0]&&cnt[1]&&cnt[2])
			ans+=(LL)cnt[0]*(cnt[1]+cnt[2])+(LL)cnt[1]*cnt[2];
		else ans+=siz>>1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
	int n;cin>>n;ll a[n],s[n+1]={0};map<ll,ll> num;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s[i+1]=s[i]+a[i];
		if(i==0) num[s[i]]++;
		num[s[i+1]]++;
	}
	ll ans=0;
	for(auto i:num){
		ll sum=i.second;
		ans+=sum*(sum-1)/2;
	}
	cout<<ans<<endl;
}

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

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

  int h, w, k;
  cin >> h >> w >> k;

  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  vector<vector<int>> a(h, vector<int> (w));
  vector<vector<vector<int>>> dp(h, vector<vector<int>> (w, vector<int> (4, 1e9+1000)));

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;
      a[i][j] = (c == '@');
    }
  }

  queue<pair<pair<int, int>, int>> q;
  for (int i = 0; i < 4; ++i) {
    q.push({{x1-1, y1-1}, i});
    dp[x1-1][y1-1][i] = 0;
  }
  
  int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
  auto check = [&](int i, int j, int dir, int val) {
    if (i >= 0 && i < h && j >= 0 && j < w && !a[i][j] && dp[i][j][dir] > val) {
      dp[i][j][dir] = val;
      return 1;
    } else return 0;
  };
  
  auto val = [&](int x) {
    return ((x + k - 1) / k) * k;
  };

  while (q.size()) {
    int x = q.front().first.first, y = q.front().first.second, d = q.front().second;
    q.pop();
    for (int l = 0; l < 4; ++l) {
      if (l == d) {
        if (check(x+dx[l], y+dy[l], d, dp[x][y][d]+1)) q.push({{x+dx[l], y+dy[l]}, d});
      } else if (check(x, y, l, val(dp[x][y][d]))) q.push({{x, y}, l});
    }
  }

  int ans = 1e9 + 5;
  for (int i = 0; i < 4; ++i) ans = min(ans, dp[x2-1][y2-1][i]);
  if (ans >= 1e9) ans = -1;
  else ans = (ans + k - 1) / k;

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


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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort((c).begin(), (c).end(), greater<int>());
#define fi first
#define se second
  
typedef pair<int,int> P;
typedef vector<int> vi;

int N;
vi A;

signed main() {
    cin>>N;
    int ctn=0,sum=0;
    rep(i,0,N) {
        int a; cin>>a;
        A.pb(abs(a));
        sum+=abs(a);
        if(a<0) ctn++;
    }

    if(ctn%2==0) cout<<sum<<endl;
    else{
        SORT(A);
        cout<<sum-2*A[0]<<endl;
    }
    return 0;
}

    


Measured memory_bytes: 1400
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;



int main(){
     
    int k,s,cnt=0;
    
    cin>>k>>s;
    for(int i=0;i<=k;i++){
        for(int j=i;j<=k;j++){
            for(int l=j;l<=k;l++){
                if(i+j+l==s){
                    if(i==j&&j==l)cnt+=1;
                    else if((i==j&&j!=l)||(j==l&&i!=j)||(i==l&&i!=j))cnt+=3;
                    else cnt+=6;
                }
            }
        }
    }
    cout<<cnt<<endl;
     
    return 0;
}
 

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

int main(int argc, char const *argv[])
{
	int r, g, b, n; cin >> r >> g >> b >> n;
	int ans = 0;
	rep(i, n + 1) rep(j, n + 1) {
		int sum = r * i + g * j;
		int nokori = n - sum;
		if (nokori < 0) continue;
		// printf("nokori %d\n", nokori);
		if (nokori % b == 0) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
	long long n,m;int x;long long sum=0;
	cin>>n>>m;
	priority_queue<int,vector<int>,less<int> >qq;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		qq.push(x);
	}
	while(m--)
	{
		x=qq.top();
		qq.pop();
		qq.push(x/2);
	}
	while(qq.size())
	{
		sum=sum+qq.top();
		qq.pop();
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main(){
    ll N;
    cin >> N;

    ll b;
    ll min = 1000000000000;
    for(ll a=1; a<=sqrt(N); a++){
        if(N%a == 0){
            b = N/a;
            if((a-1) + (b-1) <= min){
                min = (a-1) + (b-1);
            }
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=800005;
char ch[MAXN];int n,K,cnt,len;
char fac(char a,int p){return ((a-'A')^p)+'A';}
deque<char> ans; 
int main()
{
//	freopen("a.in","r",stdin);
	n=read();K=read();
	scanf("%s",ch+1);len=n;int o=0;
	if(K>n*2+1)K=(K&1)?(n*2+1):(n*2+2);
	int r=n,l=1;
	for(int i=1;i<=K;i++)
	{
		if(fac(ch[l],o)=='A')ch[l]=fac('B',o);
		else ++l,o^=1,ch[++r]=fac('A',o);
	}
	for(;;++l)
	{
		putchar(fac(ch[l],o));
		if(l==r)break;
	}
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll n, x;
    cin >> n >> x;
    vi d(n+1, 0);
    repf(i, n){
        ll l; cin >> l;
        d[i] = d[i-1] + l;
    }
    auto it = upper_bound(all(d), x);
    cout << it-d.begin() << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int q = sc.nextInt();
    int[][] train = new int[n][n];
    for(int i = 0; i < m; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      train[l - 1][r - 1]++;
    }
    int[][] ruiseki = new int[n][n];
    for(int i = 0; i < n; i++) {
      ruiseki[i][0] = train[i][0];
      for(int j = 1; j < n; j++) {
        ruiseki[i][j] = ruiseki[i][j - 1] + train[i][j];
      }
    }
    for(int i = 0; i < q; i++) {
      int p = sc.nextInt();
      int t = sc.nextInt();
      int ans = 0;
      for(int j = p - 1; j < t; j++) {
        if(p > 1) {
          ans += (ruiseki[j][t - 1] - ruiseki[j][p - 2]);
        } else {
          ans += (ruiseki[j][t - 1]);
        }
      }
      System.out.println(ans);
    }
  }
}

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

int main(){
  int n,k;
  cin >> n>>k;
  int m=0,t;
  for(int i=0;i<k;i++){
    cin >> t;
    m = max(t,m);
  }
  cout << max(m-1-n+m,0)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll A,B;
  cin>>A>>B;
  int ans=0;
  if(A>=B){ans+=A;A--;}
  else{ans+=B;B--;}
  if(A>=B){ans+=A;A--;}
  else{ans+=B;B--;}
  cout<<ans;
  
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
H, W = map(int, input().split())

# 一回り大きい並びになるように、"." をパディングする
lst = ["."*(W+2)] + ["." + input() + "." for _ in range(H)] + ["."*(W+2)]

# lst と同じ形で、要素が全部 0 のリスト
lst2 = []
for _ in range(H+2):
    lst2.append([0 for _ in range(W+2)])

# パディングの内側を3x3の窓で、「. の周囲に # があるか」探索する
for i in range(1, H+1):
    for j in range(1, W+1):
        cnt = 0
        if lst[i][j] == ".":
            cnt += lst[i-1][j-1:j+2].count("#")
            cnt += lst[i][j-1:j+2].count("#")
            cnt += lst[i+1][j-1:j+2].count("#")
            lst2[i][j] = str(cnt)
        else:
            lst2[i][j] = "#"

for i in range(1, H+1):
    print("".join(lst2[i][1:W+1]))


Measured memory_bytes: 3316
fn read<T: std::str::FromStr>() -> T {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().split_whitespace()
		.map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
	(0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
	/// Return `true` if the slice was permuted, `false` if it is already
	/// at the last ordered permutation.
	fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
	/// Original author in Rust: Thomas Backman <serenity@exscape.org>
	fn next_permutation(&mut self) -> bool {
		// These cases only have 1 permutation each, so we can't do anything.
		if self.len() < 2 { return false; }

		// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
		let mut i = self.len() - 1;
		while i > 0 && self[i-1] >= self[i] {
			i -= 1;
		}

		// If that is the entire vector, this is the last-ordered permutation.
		if i == 0 {
			return false;
		}

		// Step 2: Find the rightmost element larger than the pivot (i-1)
		let mut j = self.len() - 1;
		while j >= i && self[j] <= self[i-1]  {
			j -= 1;
		}

		// Step 3: Swap that element with the pivot
		self.swap(j, i-1);

		// Step 4: Reverse the (previously) weakly decreasing part
		self[i..].reverse();

		true
	}
}

fn main() {
	let n : usize = read();

	println!("{}", n.pow(3));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	vector<lli> a(n),b(n);
	REP(i,0,n){
		a[i] = 40000*(i+1);
		b[i] = 40000*(n-i);
	}

	lli cnt = 0;
	REP(i,0,n){
		lli p;
		cin>>p;
		p--;
		b[p] += i;
	}

	REP(i,0,n)cout<<a[i]<<" ";
	cout<<endl;
	REP(i,0,n)cout<<b[i]<<" ";
	cout<<endl;


	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  set<int> S;
  for (int i=1; i<=N; i++){
    S.insert(i);
  }
  for (int i=0; i<K; i++){
    int d;
    cin >> d;
    for (int j=0; j<d; j++){
      int e;
      cin >> e;
      S.erase(e);
    }
  }
  cout << S.size() << endl;
}

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

const int N = 1e3 + 7, mod = 1e9 + 7;

int POW(int a, int b, int mod) {
	a %= mod; int r = 1;
	for(int i = b; i > 0; i >>= 1) {
		if(i & 1) r = (r * a) % mod;
		a = (a * a) % mod;
	}
	return r;
}

int f[N], n, dp[10001][1001];

vector <tuple <int, int, int> > v;

vector <int> nxt;


int g(int lft, int idx) {
	if(idx >= v.size()) {
		return (lft == 0 ? f[n] : 0);
	}
	if(~dp[idx][lft]) {
		return dp[idx][lft];
	}
	int res = g(lft, idx + 1);
	int x, y, z; tie(x, y, z) = v[idx];
	if(x * y <= lft) {
		res += g(lft - x * y, nxt[idx]) * z % mod;
		res %= mod;
	}
	return dp[idx][lft] = res;
}



int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

	f[0] = 1;
	for(int i = 1; i < N; i++) {
		f[i] = (f[i - 1] * i) % mod;
	}

	int a, b, c, d; cin >> n >> a >> b >> c >> d;

	for(int i = a; i <= b; i++) {
		int k = POW(f[i], mod - 2, mod), p = 1;
		for(int j = 1; j <= c; j++) {
			p = (p * k) % mod;
		}
		for(int j = c; j <= d; j++) {
			if(i * j <= n) {
				v.push_back(make_tuple(i, j, (p * POW(f[j], mod - 2, mod)) % mod));
			}
			p = (p * k) % mod;
		}
		while(nxt.size() < v.size()) {
			nxt.push_back(v.size());
		}
	}
	memset(dp, -1, sizeof dp);
	cout << g(n, 0) << endl;
}

Measured memory_bytes: 82220
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


class Program {

	const long mod = 1000000007;
	//public static int[] max;

	static void Main(string[] args) {

		char[] cs = new char[] { ' ', ',' };
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res="";
		//int res = 0; ;
		//int t = int.Parse(Console.ReadLine());
		//string str = Console.ReadLine();
		int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = int.Parse(Console.ReadLine());

		//int num = vals[0];


		int res = 0;

		if ( ( ( vals[0] * vals[1] ) % 2 ) == 1 ) {
			Console.WriteLine("Yes");
		} else {

			Console.WriteLine("No");
		}
		return;
	}


	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = long.Parse(str[i]); }
		return nums;
	}
	
	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
		return re;
	}

}

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

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    //*
    if( a < 10 && b < 10 ){
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }
    //*/
    
    //cout << a * a << endl;

    return 0; 
}


Measured memory_bytes: 3600
import math

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

ans = 0
if x * 2 <= x_max:
  c = ((x * 2) / b) / a
  ans = math.acos(b / ((c ** 2 + b ** 2) ** 0.5))
else:
  c = ((x_max - x) * 2) / a / a
  ans = math.acos(c / ((c ** 2 + a ** 2) ** 0.5))
print(90 - math.degrees(ans))

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

typedef long long ll;
ll const mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

int n;
int a[21][21];
vector<ll> dp(1<<22,-1);
ll rec(int s,int c) {
    if (dp[s] > -1) return dp[s];
    dp[s] = 0;
    for (int i = 0;i < n;++i) if (s&(1<<i) && a[c][i]) dp[s] += rec(s^(1<<i),c-1);
    return dp[s] %= mod;
}

int main() {
    cin >> n;
    for (int i = 0;i < n;++i) for (int j = 0;j < n;++j) cin >> a[i][j];
    dp[0] = 1;
    cout << (rec((1<<n)-1,n-1)+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 33024