akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
//関数
const long INF=1000000000000000;
bool check=false;

int main(void){
    long ans=0,preans=0;
    long N;
    cin>>N;
    vector<long> H(N+1);
    for(int i=0;i<N;i++) cin>>H.at(i);
    H.at(N)=INF;
    
    for(int i=0;i<N;i++){
        if(H.at(i)>=H.at(i+1)) preans++;
        else preans=0;
        ans=max(ans,preans);
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 1010
bool f[N][N];
ll n,c[N],w[N],cs[N];
ll g[N];
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>c[i]>>w[i];
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)f[i][j]=0;
    for(int i=0;i<n;i++)f[i][i]=1;
    cs[0]=0; for(int i=0;i<n;i++)cs[i+1]=cs[i]+w[i];
    for(int l=0;l<n;l++){
	for(int i=0;i+l<n;i++){
	    int j=i+l;
	    if(i-1>=0&&c[i-1]>=cs[j+1]-cs[i])f[i-1][j]|=f[i][j];
	    if(j+1<n&&c[j+1]>=cs[j+1]-cs[i])f[i][j+1]|=f[i][j];
	}
    }
    for(int i=0;i<=n;i++)g[i]=1e17; g[0]=0;
    for(int i=0;i<n;i++){
	for(int j=i;j<n;j++){
	    if(f[i][j]==1)g[j+1]=min(g[j+1],g[i]+1);
	}
    }
    cout<<g[n]<<endl;
    return 0;
}



Measured memory_bytes: 4100
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;

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

    int n;
    cin >> n;
    int p[SIZE], q[SIZE];
    int cnt_f = 0, cnt_b = 0;
    for( int i = 0; i < n; ++i ) { cin >> p[i]; q[i] = p[i]; }

    for( int i = 0; i < n - 1; ++i ) {
        if( p[i] == i + 1 ) { swap( p[i], p[i + 1] ); ++cnt_f; }

    }

    if( p[n - 1] == n ) ++cnt_f;

    cout << cnt_f << endl;
    return 0;
}



Measured memory_bytes: 640
A,B,N=map(int,input().split())
if B==1:
    print(0)
    exit()

if N==1:
    ans=(A//B)-A*(1//B)
    print(ans)
    exit()
if A==1:
    print(0)
    exit()

if B<N:
    val=B-1
    ans=(A*val)//B-A*(val//B)
elif N<B:
    val=N
    #print("ON")
    ans=(A*val)//B-A*(val//B)
else:
    val=B-1
    ans=(A*val)//B-A*(val//B)

print(ans)

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

vector<int> A;
vector<int> B;
vector<int> C;

vector<pair<long long int, int> > rest;

int main() {
	int n;
	cin >> n;
	long long int sumA = 0;
	long long int sumB = 0;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		A.push_back(a);
		sumA += a;
	}
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		B.push_back(a);
		sumB += a;
	}
	if (sumA < sumB) {
		puts("-1");
		return 0;
	}
	int cnt = 0;
	long long int need = 0;
	for (int i = 0; i < A.size(); i++) {
		if (A[i] > B[i]) {
			rest.push_back(make_pair(A[i] - B[i], i));
		}
		else {
			if (A[i] == B[i])continue;
			need += B[i] - A[i];
			cnt++;
		}
	}
	sort(rest.begin(), rest.end());
	while (need > 0) {
		need -= rest.back().first;
		rest.pop_back();
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 2168
import numpy as np

N = int(input())
vn_list = input().split()

vn = np.sort(np.array(vn_list, dtype="float"))[::-1]
w = np.logspace(1, N, base=1/2, num = N)
w[N-1] = w[N-2]
result = np.dot(vn, w)
print(result)

Measured memory_bytes: 12504
def main():
    h, w = [int(x) for x in input().split()]
    n1 = w//2 + (w&1)
    n2 = w//2

    if h == 1 or w == 1:
        print(1)
    else:
        ans = (n1+n2)*(h//2)
        if h&1:
            ans += n1
        print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define p push
#define p1 pop
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair<ll,ll>
#define e 1000000007
using namespace std;
int main()
{
    ll memo[3][100001];
    ll n;cin>>n;
    ll a[n],b[n],c[n];
    for(int i=0;i<n;++i)
        cin>>a[i]>>b[i]>>c[i];
    for(int i=1;i<=n;++i)
    {
        memo[0][i]=max(memo[1][i-1]+a[i-1],memo[2][i-1]+a[i-1]);
        memo[1][i]=max(memo[0][i-1]+b[i-1],memo[2][i-1]+b[i-1]);
        memo[2][i]=max(memo[1][i-1]+c[i-1],memo[0][i-1]+c[i-1]);
    }
    cout<<max(memo[0][n],max(memo[1][n],memo[2][n]));
}

Measured memory_bytes: 4992
#include<stdio.h>

int main(void){
  int A, B, C, D;

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

  while (A > 0 && C > 0){
    C = C - B;
    if (C <= 0){
      printf("Yes");
      break;
    }else{}
    A = A - D;
    if (A <= 0){
      printf("No");
      break;
    }else{}
  }
  return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int* arr = new int[n];
  for(int i = 0;i < n;i++)
  {
    cin>>arr[i];
  }
  long* dp = new long[n];
  dp[0] = 0;
  dp[1] = abs(arr[1] - arr[0]);
  for(int i = 2;i < n;i++)
  {
    dp[i] = min(dp[i-2] + abs(arr[i] - arr[i-2]),dp[i-1] + abs(arr[i] - arr[i-1]));
  }
  cout<<dp[n-1]<<endl;
  return 0;
}
  
  
   
    


Measured memory_bytes: 1408
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
vector<int> e[100010];
int u[200010], v[200010], w[200010], d[100010];
char c[100010];
int fi[100010], nw;
pair<int, int> p[100010];
int dfs(int x) {
	int res = 0;
	for (int i = 0; i < e[x].size(); i++) {
		int z = e[x][i], y = u[z] + v[z] - x;
		if (!fi[y] || c[y]) continue;
		c[y] = 3 - c[x];
		w[z] = nw;
		dfs(y);
		res = 1;
	}
	return res;
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &d[i]);
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &u[i], &v[i]);
		--u[i]; --v[i];
		e[u[i]].push_back(i);
		e[v[i]].push_back(i);
	}
	for (int i = 0; i < n; i++) {
		p[i] = make_pair(d[i], i);
	}
	sort(p, p + n);
	int st = 0;
	while (st < n) {
		int ed = st;
		while (ed < n && p[st].first == p[ed].first) {
			fi[p[ed].second] = 1;
			ed++;
		}
		nw = p[st].first;
		for (int i = st; i < ed; i++) {
			int x = p[i].second;
			if (c[x]) continue;
			for (int j = 0; j < e[x].size(); j++) {
				int z = e[x][j], y = u[z] + v[z] - x;
				if (c[y]) {
					c[x] = 3 - c[y];
					w[z] = nw;
					dfs(x);
					break;
				}
			}
		}
		for (int i = st; i < ed; i++) {
			int x = p[i].second;
			if (c[x]) continue;
			c[x] = 1;
			if (!dfs(x)) {
				puts("-1");
				return 0;
			}
		}
		st = ed;
	}
	for (int i = 0; i < n; i++) {
		c[i] = c[i] == 1 ? 'B' : 'W';
	}
	puts(c);
	for (int i = 0; i < m; i++) {
		if (!w[i]) w[i] = 1000000000;
		printf("%d\n", w[i]);
	}
	return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    ll a[n], b[n];
    rep(i, n) { cin >> a[i] >> b[i]; }
    sort(a, a + n);
    sort(b, b + n);

    if (n % 2 == 0) {
        ll index0 = n / 2 - 1, index1 = index0 + 1;
        ll mid2_small = a[index0] + a[index1];
        ll mid2_big = b[index0] + b[index1];
        ll num = mid2_big - mid2_small + 1;
        cout << num << endl;
    } else {
        ll index = n / 2;
        ll mid_small = a[index];
        ll mid_big = b[index];
        ll num = mid_big - mid_small + 1;
        cout << num << endl;
    }
    return 0;
}



Measured memory_bytes: 6724
using System;
using System.Linq;
using System.Text;

namespace test
{
    class Program
    {
        struct Card
        {
            internal char suit;
            internal int value;
        }


        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Card[] A1 = new Card[n];
            Card[] A2 = new Card[n];

            
            string[] input;
            for(int i = 0; i < n; i++)
            {
                input = Console.ReadLine().Split(' ');
                A1[i].suit = input[0][0];
                A2[i].suit = input[0][0];
                A1[i].value = int.Parse(input[1]);
                A2[i].value = int.Parse(input[1]);
            }

            QuickSort(A1, 0, n - 1);

            A2 = A2.OrderBy(a => a.value).ToArray();

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(IsStabel(A1, A2, n) ? "Stable" : "Not stable");
            foreach (var a in A1)
            {
                sb.AppendLine(a.suit + " " + a.value);
            }
            Console.Write(sb);
        }


        static void QuickSort(Card[] A, int p, int r)
        {
            if (p < r)
            {
                int q = Partition(A, p, r);
                // 前パーテーションを再度クイックソート
                QuickSort(A, p, q - 1);
                // 後ろパーテーションを再度クイックソート
                QuickSort(A, q + 1, r);
            }
            
        }

        static int Partition(Card[] A, int p, int r)
        {
            int x = A[r].value;
            // iが前パーテーションの末尾
            int i = p - 1;

            // jが後ろパーテーションの末尾
            for (int j = p; j < r; j++)
            {
                if (A[j].value <= x)
                {
                    i++;
                    var tmp = A[j];
                    A[j] = A[i];
                    A[i] = tmp;
                }
            }
            var tmp2 = A[i + 1];
            A[i + 1] = A[r];
            A[r] = tmp2;
            // パーテーションで区切られた場所のkeyを返す
            return i + 1;
        }

        static bool IsStabel(Card[] A1, Card[] A2, int n)
        {
            for (int i = 0; i < n; i++)
            {
                if (A1[i].suit != A2[i].suit) return false;
            }
            return true;
        }
    }
}



Measured memory_bytes: 17300
//#typedef int ll
// include
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <tuple>
// namespace
using namespace std;
// typedef
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
// const
const int inf = 1e9;
const int mod = ((int)1e9 + 7);
// loop
#define rep(i, n) for(int i = 0, i##_mx = n; i < i##_mx; i++)
#define brep(i, b, e) for(int i = b; i < e; i++)
#define erep(i, b, e) for(int i = b; i <= e; i++)
#define rrep(i, b, e) for(int i = b; i >= e; i--)
// STL
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
// function
int gcd(int a, int b){return b ? gcd(b, a % b) : a;}
void prime(vint& v, int n){brep(i, 2, n){bool fg = false; for(auto e : v){if(i % e == 0){fg = true;}} if(fg){continue;} v.pb(i);}}
void in(vint& v){for(auto& i : v){cin >> i;}}

signed main(){
    int n, m;
    cin >> n >> m;
    
    vint a;
    a.resize(m);
    in(a);
    
    int step[100001] = {1, 0};
    auto min_a = a.begin();
    for(int i = 1; i <= n; i++){
        if(min_a != a.end() && i == *min_a){
            step[i] = 0;
            min_a++;
            continue;
        }
        
        step[i] += step[i - 1];
        step[i] %= mod;
        
        if(i >= 2){
            step[i] += step[i - 2];
        }
        
        step[i] %= mod;
    }
    
    cout << step[n] << endl;
	
	return 0;
}

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

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;
	vector<int> ht(n);
	vector<int> good(n, 1);
	for (int i = 0; i < n; i++)
	{
		cin >> ht[i];
	}
	for (int i = 0; i < m; i++)
	{
		int A, B;
		cin >> A >> B;
		if (ht[A - 1] <= ht[B - 1])
		{
			good[A - 1] = 0;
		}
		if (ht[A - 1] >= ht[B - 1])
		{
			good[B - 1] = 0;
		}
	}
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		count += (good[i] == 1);
	}
	cout << count;
	return 0;

}

Measured memory_bytes: 4028
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

int main() {
	long long N;
	cin >> N;
	vector<int> MARCH(5);
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		if (s.at(0) == 'M') MARCH.at(0)++;
		else if(s.at(0) == 'A') MARCH.at(1)++;
		else if (s.at(0) == 'R') MARCH.at(2)++;
		else if (s.at(0) == 'C') MARCH.at(3)++;
		else if (s.at(0) == 'H') MARCH.at(4)++;
	}

	long long ttl = 0;
	
	for (int i = 0; i < (1 << 5); i++) {
		long long ans = 1;
		bitset<5> X(i);
		int sum = 0;
		for (int j = 0; j < 5; j++) {
			if (X.test(j)) sum++;
		}
		if (sum == 3) {
			for (int k = 0; k < 5; k++) {
				if (X.test(k) == 0) continue;
				else if (X.test(k) == 1 && MARCH.at(k) != 0) ans *= X.test(k) * MARCH.at(k);
				else if (X.test(k) == 1 && MARCH.at(k) == 0) {
					ans = 0;
					break;
				}
			}
		}
		else continue;
		ttl += ans;
	}
	cout << ttl << endl;
}

Measured memory_bytes: 3472
n = int(input())
y = [input().split() for i in range(n)]
for i in range(n):
    y[i][1] = int(y[i][1])
    y[i].append(i+1)
y.sort(key=lambda x:(x[0],-x[1]))
for i in range(n):
    print(y[i][2])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6;
int n, m, a[maxN];
long long s[maxN], s_t, ans;
map <int, int> mp;

int main(){
	cin >> n >> m;
	mp[0] = 1;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i){
		s_t += a[i];
		s[i] = s_t;
		int r = s[i] % m;
		ans += mp[r];
		mp[r]++;
	}
	cout << ans;
}

Measured memory_bytes: 8064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>

using namespace std;

long long x = 1000000000+7;

long long n_pow(long long a, long long n) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 1) {
		return (a*n_pow(a, n - 1)) % x;
	}
	else {
		long long t = n_pow(a, n / 2);
		return (t*t) % x;
	}
}

long long combination(long long n, long long a) {
	long long ans;
	long long p = 1;
	long long q = 1;
	for (long long i = 0; i < a; i++) {
		p *= n - i;
        p %= x;
		q *= a - i;
        q %= x;
	}
	ans = p * n_pow(q, x - 2);
	return ans % x;
}

int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	long long ans = n_pow(2, n) - 1;
	ans-=combination(n,a);
    if(ans < 0)ans += x;
    ans-=combination(n,b);
    if(ans < 0)ans += x;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
RC = [list(map(int, input().split())) for _ in range(N)]

memo = [[-1] * (N + 1) for _ in range(N + 1)]
inf = 10**18


def mult(l, r):
    """
    半開区間[l, r)
    """
    if memo[l][r] != -1:
        return memo[l][r]
    if r - l <= 1:
        memo[l][r] = 0
        return 0

    res = inf
    for m in range(l + 1, r):
        prod = RC[l][0] * RC[m - 1][1] * RC[r - 1][1]
        tmp = mult(l, m) + mult(m, r) + prod
        res = min(res, tmp)
    memo[l][r] = res
    return res


ans = mult(0, N)
print(ans)


Measured memory_bytes: 5732
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll mod=1000000007;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) cout<<"Bad\n";
	else cout<<"Good\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int pos[200200];

signed main() {
    cin >> N;
    rep(i, N) {
        int p;
        cin >> p;
        p--;
        pos[p] = i;
    }
    int start = 0;
    int prev_pos = pos[0];
    int max_len = 1;
    for (int i = 1; i < N; ++i) {
        if (pos[i] < prev_pos) {
            max_len = max(max_len, i - start);
            start = i;
        };
        prev_pos = pos[i];
    }
    max_len = max(max_len, N - start);
    cout << N - max_len << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  sx, sy, tx, ty = na()

  ans = ""
  y = ty - sy
  x = tx - sx
  ans += y * "U"
  ans += x * "R"
  ans += y * "D"
  ans += x * "L"
  ans += "L"
  ans += (y + 1) * "U"
  ans += (x + 1) * "R"
  ans += "DR"
  ans += (y + 1) * "D"
  ans += (x + 1) * "L"
  ans += "U"
  print(ans)

main()

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

num = [str(x) for x in range(10)]

flag = False

if s[a] == "-":
    list_s = list(s)
    del list_s[a]
    if all([x in num for x in list_s]):
        flag = True
print("Yes" if flag else "No")


Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <queue>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;

#define pb emplace_back
#define forn(i, x, n) for(auto i = (int)x; i < (int)n; ++i)

#define int long long

struct init {
    init() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cout << fixed << setprecision(10);
    }

    ~init() {
        cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n";
    }
} init;

const int N = 1005000 * 1, MOD = 1000 * 1000 * 1000 + 7;
//const ldb EPS = 5e-12, HALF = 0.5;

int a[N];
int pos;

signed main() {
    int n, k;
    cin >> n >> k;
    int ans = 1;
    n -= k;
    --k;
    cout << ans + n / k + (n % k == 0 ? 0 : 1);

}

Measured memory_bytes: 256
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
l = []

for i in range(len(a)):
  l += [(i+1)]*a[i]
  
for i in range(h):
  if i%2 == 0:
    print(*l[i*w:(i+1)*w])
  else:
    print(*list(reversed(l[i*w:(i+1)*w])))

Measured memory_bytes: 9600
import sys
input = sys.stdin.readline

def slove():
    n = int(input())
    ans = ""
    abc = "zabcdefghijklmnopqrstuvwxy"
    count = 0
    while n != 0:
        k = n % 26
        if k == 0:
            n -= 1
        n = n // 26
        ans = abc[k] + ans
        
    print(ans)


if __name__ == "__main__":
    slove()
    

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
long long a, b;
int main() {
 scanf("%lld %lld",&a,&b);
 if ((a * b) %2 == 0) {
    cout << "Even" << endl;
  }
  else {
  	cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N;
  cin >> N;
  if(N % 1000 == 0) cout<< 0 << endl;
  else cout << 1000 - (N % 1000) << endl;
}

Measured memory_bytes: 3540
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      string[] str=Console.ReadLine().Split(' ');
      int a=int.Parse(str[0]);
      int b=int.Parse(str[1]);
      
      if(a<=b){
        Console.WriteLine(a);

  }else{
        Console.WriteLine(a-1);
}
}
  }
}

Measured memory_bytes: 11092
#include<stdio.h>
int main(void){
  int k,l,n,s;
  int sum;
  int point;
  int a[9]; //0~8???9??????????????´??°
  while(1){
    scanf("%d %d",&n,&s);
    if(n==0 && s==0) break;
    point = 0;
    for(a[0]=0 ; a[0]<=9 ; a[0]++){
      if(n==1){
        sum = 0;
        for(k=1;k<=n;k++){
          sum += a[k-1];
        }
        if(sum == s) point++;
      }
      for(a[1]=a[0]+1 ; a[1]<=9 ; a[1]++){
        if(n==2){
          sum = 0;
          for(k=1;k<=n;k++){
            sum += a[k-1];
          }
          if(sum == s) point++;
        }

        for(a[2]=a[1]+1 ; a[2]<=9 ; a[2]++){
          if(n==3){
            sum = 0;
            for(k=1;k<=n;k++){
              sum += a[k-1];
            }
            if(sum == s) point++;
          }

          for(a[3]=a[2]+1 ; a[3]<=9 ; a[3]++){
            if(n==4){
              sum = 0;
              for(k=1;k<=n;k++){
                sum += a[k-1];
              }
              if(sum == s) point++;
            }

            for(a[4]=a[3]+1 ; a[4]<=9 ; a[4]++){
              if(n==5){
                sum = 0;
                for(k=1;k<=n;k++){
                  sum += a[k-1];
                }
                if(sum == s) point++;
              }
              for(a[5]=a[4]+1 ; a[5]<=9 ; a[5]++){
                if(n==6){
                  sum = 0;
                  for(k=1;k<=n;k++){
                    sum += a[k-1];
                  }
                  if(sum == s) point++;
                }

                for(a[6]=a[5]+1 ; a[6]<=9 ; a[6]++){
                 if(n==7){
                   sum = 0;
                   for(k=1;k<=n;k++){
                     sum += a[k-1];
                   }
                   if(sum == s) point++;
                 }

                  for(a[7]=a[6]+1 ; a[7]<=9 ; a[7]++){
                    if(n==8){
                      sum = 0;
                      for(k=1;k<=n;k++){
                        sum += a[k-1];
                      }
                      if(sum == s) point++;
                    }
                    for(a[8]=a[7]+1 ; a[8]<=9 ; a[8]++){
                      if(n==9){
                        sum = 0;
                        for(k=1;k<=n;k++){
                          sum += a[k-1];
                        }
                        if(sum == s) point++;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    printf("%d\n",point);
  }
  return 0;
}

Measured memory_bytes: 600
N = int(input())
FF = [list(map(int, input().split())) for _ in range(N)]
PP = [list(map(int, input().split())) for _ in range(N)]

from itertools import combinations

mm = None
for i in range(1, 11):
  for ss in combinations(range(0, 10), i):
    m = 0
    for j in range(N):
      c = sum(f for k, f in enumerate(FF[j]) if k in ss)
      m += PP[j][c]
    if mm is None:
      mm = m
    else:
      mm = max(mm, m)
print(mm)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

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

// gcd, lcm
ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

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


int main() {
    int n;
    cin >> n;
    vector<int> list({105, 135, 165, 189, 195});
    int ans = 0;
    for(int i : list) {
        if (n >= i) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}


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

while True:
    if a + 1 <= n and a + 1 != b:
        a += 1
    else:
        print("Borys")
        break
    if b >= 2 and b - 1 != a:
        b -= 1
    else:
        print("Alice")
        break


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

/*区間スケジューリング問題。区間の終点が原点に近い順に並べ、区間の最後の橋を貪欲的に取り除いていく。KEYENCE2020/b 参照。*/
int main(void){
    int N,M;
    cin >> N >> M;
    vector<pair<int,int>> section;
    rep(i,M){
        int left, right;
        cin >> left >> right;
        section.emplace_back(right, left);
    }
    sort(section.begin(),section.end());
    int ans = 0;
    int left_limit = -INT_MAX;
    rep(i,M){
        if(left_limit > section[i].second)continue;
        ans++;
        left_limit = section[i].first;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

int n;
string s;

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	scanf("%s", buff);
	s = buff;
	return true;
}

void solve()
{
	vector<int> ans(n + 1);

	for (ans[0] = 0; ans[0] <= 1; ++ans[0])
		for (ans[1] = 0; ans[1] <= 1; ++ans[1])
		{
			for (int i = 1; i < n; ++i)
			{
				ans[i + 1] = ans[i] ^ ans[i - 1];

				if (s[i] == 'x')
					ans[i + 1] ^= 1;
			}

			if (ans[n] == ans[0])
			{
				bool good = true;

				forn (i, n)
				{
					int l = (i - 1 + n) % n;
					int r = (i + 1) % n;
					int cur = ans[l] ^ ans[r];
					if (ans[i] == 1) cur ^= 1;
					good &= ((cur == 1 && s[i] == 'x') || (cur == 0 && s[i] == 'o'));
				}

				if (good)
				{
					forn (i, n)
						if (ans[i] == 1)
							printf("W");
						else
							printf("S");

					printf("\n");
					return ;
				}
			}
		}

	printf("-1\n");
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e9 + 7;
using namespace std;

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

	vector<long long> a(n), ans(n,0);
	map<long long,vector<long long>> m;
	rep(i,n){
		cin >> a[i];
		m[a[i]].emplace_back(i);
	}
	m[0].emplace_back(-1);

	long long cur = INF; //加算される対象
	long long num = 0; //今処理している値と同じ数値を持つ要素の個数
	for(auto it = m.rbegin(); it->first != 0; it++){
		num += it->second.size();
		cur = min(cur, it->second.front());

		long long dif = it->first - (*next(it,1)).first;
		ans[cur] += num * dif;
	}

	for(auto i : ans){
		cout << i << endl;
	}
}


Measured memory_bytes: 13568
use std::io::stdin;

fn main() {
    loop {
        let n = read::<usize>();
        if n == 0 {
            return;
        }
        let values: Vec<i32> = (0..n).map(|_| read::<i32>()).collect();
        let mut max_sum = get_sum(&values[0..n]);
        for i in 0..n {
            for j in i + 1..n + 1 {
                let sum = get_sum(&values[i..j]);
                if sum > max_sum {
                    max_sum = sum;
                }
            }
        }
        println!("{}", max_sum);
    }
}

fn get_sum(values: &[i32]) -> i32 {
    values.into_iter().fold(0, |x, sum| x + sum)
}

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



Measured memory_bytes: 5032
def bitcount(N):  # 立ってるbitの数
    bitcnt = [0]
    for _ in range(N):
        bitcnt += [i + 1 for i in bitcnt]
    return bitcnt


n, x = int(input()), input()

num, cnt = int(x, 2), x.count('1')
num0, num1 = num % (cnt + 1), num % max(cnt - 1, 1)
lbit = bitcount(18)
for i in range(n):
    ans = 1
    if x[i] == '0':
        ctmp = cnt + 1
        tmp = num0 + pow(2, n - (i + 1), cnt + 1)
    elif x[i] == '1':
        if cnt == 1:
            print(0)
            continue
        ctmp = cnt - 1
        tmp = num1 - pow(2, n - (i + 1), cnt - 1)
    tmp %= ctmp
    ctmp = lbit[tmp]
    while tmp > 0:
        ans += 1
        tmp %= ctmp
        ctmp = lbit[tmp]
    print(ans)


Measured memory_bytes: 13008
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

int main(void) {
	uint32_t A, B, C;

	scanf("%"PRIu32" %"PRIu32" %"PRIu32, &A, &B, &C);

	for (uint32_t cnt = 0; cnt < 2; cnt++) {
		if (A > B) {
			const uint32_t tmp = B;
			B = A;
			A = tmp;
		}
		if (B > C) {
			const uint32_t tmp = C;
			C = B;
			B = tmp;
		}
	}

	const uint32_t diff = (C - B) + (C - A);
	printf("%"PRIu32, diff % 2 == 0 ? diff / 2 : diff / 2 + 2);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> mypair;
int main(){
	int n,t;
	cin>>n>>t;
	vector<mypair> a(n);
	for(int i=0;i<n;i++){
	int b,c;
	cin>>b>>c;
	a[i] = mypair(c,b);
	}
	sort(a.begin(),a.end());
	int ans =1001;
	for(int i=0;i<n;i++){
		if(a[i].first>t)break;
	ans = min(ans,a[i].second);
	}
	if(ans ==1001)cout<<"TLE"<<endl;
	else	cout<<ans<<endl;
	return 0;
}


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

int main(void){
  int x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int x3, y3, x4, y4;

  int vec1_2x, vec1_2y, vecRotx, vecRoty;

  vec1_2x = x2 - x1;
  vec1_2y = y2 - y1;

  vecRotx = -vec1_2y;
  vecRoty = vec1_2x;

  x3 = x2 + vecRotx;
  y3 = y2 + vecRoty;
  x4 = x1 + vecRotx;
  y4 = y1 + vecRoty;

  cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
}


Measured memory_bytes: 256
n = int(input())
h = [int(i) for i in input().split()]

c = [0] * n
c[0] = 0

for i in range(1, n):
    if i != 1:
        c[i] = min(c[i - 1] + abs(h[i - 1] - h[i]),
                   c[i - 2] + abs(h[i - 2] - h[i]))
    else:
        c[i] = c[i - 1] + abs(h[i - 1] - h[i])
print(c[-1])


Measured memory_bytes: 13928
#include <stdio.h>
int main() {
	char S[7];
	int i;
	int ans = 0;
	scanf("%s", &S);
	for (i = 0; i < 6; i++) {
		if('1' == S[i])
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vl p(n);
    rep(i, n) {
        cin >> p[i];
        p[i]--;
    }

    vl b(n);
    b[n-1] = 1;
    for(ll i = n-2; i >= 0; i--) {
        b[i] = 3*(n-1-i)*10000;
    }

    vl c(n);
    ll ma = 1e9;
    for(ll i = n-1; i >= 0; i--) {
        c[p[i]] = ma;
        ma--;
    }

    vl a(n);
    rep(i, n) {
        a[i] = c[i] - b[i];
    }

    rep(i, n) {
        cout << a[i];
        if(i < n-1) {
            cout << " ";
        }
    }
    cout << "\n";
    
    rep(i, n) {
        cout << b[i];
        if(i < n-1) {
            cout << " ";
        }
    }
    cout << "\n";
    
    re0;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String next;
		int op1, op2;
		Stack<Integer> stack = new Stack<Integer>();

		while(scanner.hasNext()){
			next = scanner.next();
			switch(next){
				case "+":
					op1 = stack.pop();
					op2 = stack.pop();
					stack.push(op2+op1);
					break;
				case "-":
					op1 = stack.pop();
					op2 = stack.pop();
					stack.push(op2-op1);
					break;
				case "*":
					op1 = stack.pop();
					op2 = stack.pop();
					stack.push(op2*op1);
					break;
				default :
					stack.push(Integer.parseInt(next));
			}
		}

		System.out.println(stack.pop());

	}
}

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

struct Bridge
{
	int cost;
	int edge[ 2 ];
};

class BridgeAsc
{
public:
	bool operator()( const Bridge& a, const Bridge& b ) const
	{
		if( a.cost < b.cost ) return true;
		return false;
	};
};

int main()
{
	int n, m;
	while( cin >> n >> m && ( n || m ) ){
		vector< Bridge > bridge;
		for( int i = 0; i < m; ++i ){
			Bridge b;
			cin >> b.edge[ 0 ] >> b.edge[ 1 ] >> b.cost;
			bridge.push_back( b );
		}
		sort( bridge.begin(), bridge.end(), BridgeAsc() );

		int city[ 100 ] = {0};
		int id = 1;
		int cntBridge = 0;
		int index = 0;
		int ans = 0;
		while( cntBridge < n - 1 ){
			Bridge b = bridge[ index ];
			int con = 0;
			int x = b.edge[ 0 ];
			int y = b.edge[ 1 ];
			if( city[ x ] != 0 && city[ x ] == city[ y ] ){
				++index;
				continue;
			}
			if( city[ x ] == 0 && city[ y ] == 0 ){
				city[ x ] = city[ y ] = id++;
			}else if( city[ x ] == 0 ){
				city[ x ] = city[ y ];
			}else if( city[ y ] == 0 ){
				city[ y ] = city[ x ];
			}else{
				int tmp = city[ y ];
				for( int i = 0; i < n; ++i ){
					if( city[ i ] == tmp ){
						city[ i ] = city[ x ];
					}
				}
			}
			ans += b.cost;
			++cntBridge;
			++index;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1228
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, k, t;
    cin >> n >> k >>  t;
    cout << (n + k - 1) / k * t;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <queue>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    priority_queue<int> que[n];

    for(int i = 0; i < q; i++) {
        int p;
        cin >> p;
        if(p == 0) {
            int t, x;
            cin >> t >> x;
            que[t].push(x);
        }
        else if(p == 1) {
            int t;
            cin >> t;
            if(que[t].size() == 0){
                continue;
            }
            cout << que[t].top() << endl;;
        }
        else {
            int t;
            cin >> t;
            if(que[t].size() == 0){
                continue;
            }
            que[t].pop();
        }
    }

}


Measured memory_bytes: 4096
n = gets.to_i
e = gets.split.map(&:to_i)
puts e.join(' ')
(n-1).times{ |i|
  i.downto(0){ |j|
    e.insert(j,e.slice!(j+1)) if (e[j] > e[j+1])
    break if (e[j] > e[j-1])
  }
  puts e.join(' ')
}

Measured memory_bytes: 8720
from collections import Counter

N = int(input())
al = list(map(int, input().split()))

C_al = Counter(al)

al.sort(reverse=True)

tate = 0
yoko = 0

lst = list(C_al.keys())
lst.sort(reverse=True)

for edge in lst:
    if C_al[edge] >= 2:
        if tate == 0:
            tate = edge
            if C_al[edge] >= 4 and yoko == 0:
                yoko = edge
                print(tate * yoko)
                exit()
            else:
                pass
        else:
            yoko = edge
            print(tate * yoko)
            exit()
print(tate * yoko)


Measured memory_bytes: 22324
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;

int main()
{
    int A;
    cin >> A;
    vector<int> input(A);
    int sum = 0;
    int max = 0;
    rep0(i,A){
        cin >> input[i];
        if(max<input[i]){
            max = input[i];
        }
        sum+=input[i];
    }
    if(sum-max>max){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main() {
    double n,m,k;
    cin>>n>>m>>k;
    double tmp=n/k;
    if(tmp<=m) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    return 0;
}

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

#define MOD 998244353
#define ll long long

int n;

struct A{
    int X, D;
    int r_idx;
    ll f;
};

int tree[800010], S;
void update(int i, int v){
    i += S; tree[i] = v; i/=2;
    while(i){
        tree[i] = max(tree[i*2], tree[i*2+1]);
        i/=2;
    }
}
int get_max(int l, int r){
    l += S; r += S;
    int ret = 0;
    while(l<r){
        if(l%2 == 1){ ret = max(ret, tree[l]); ++l; }
        if(r%2 == 0){ ret = max(ret, tree[r]); --r; }
        l/=2; r/=2;
    }
    if(l==r) ret = max(ret, tree[l]);
    return ret;
}

int main()
{
    scanf("%d", &n);
    for(S=1;S<n;S<<=1);
    vector<A> arr(n);
    for(int i=0; i<n; ++i){
        scanf("%d%d", &arr[i].X, &arr[i].D);
    }
    sort(arr.begin(), arr.end(), [](A &a, A &b)->bool{
        return a.X < b.X;
    });
    A tmp; tmp.f = 1; tmp.X = 1111111111; tmp.D = 1000000000; tmp.r_idx = n;
    arr.push_back(tmp);
    vector<int> Xs;
    for(auto t : arr){
        Xs.push_back(t.X);
    }
    arr[n-1].r_idx = n-1; update(n-1, n-1);
    for(int i=n-2; i>=0; --i){
        int key = arr[i].X + arr[i].D;
        int idx = lower_bound(Xs.begin(), Xs.end(), key) - Xs.begin();
        if(idx <= i+1) arr[i].r_idx = i;
        else arr[i].r_idx = get_max(i+1, idx-1);
        update(i, arr[i].r_idx);
    }
    //for(int i=S; i<=S+n-1; ++i) printf("%d ", tree[i]);
    //printf("\n\n");
    //for(int i=0; i<=n; ++i) printf("%10d %10d %d %lld\n", arr[i].X, arr[i].D, arr[i].r_idx, arr[i].f);
    for(int i=n-1; i>=0; --i){
        arr[i].f = (arr[i+1].f + arr[arr[i].r_idx+1].f) % MOD;
    }
    printf("%lld\n", arr[0].f);
}

Measured memory_bytes: 11520
#include <iostream>

void solve( int N, int L ) {
    int total = N*(L - 1) + ( N * (N + 1) / 2 );
    int diff  = std::abs( total ), ans = total;
    for (int i=1; i<=N; ++i) {
        int taste = L + i - 1;
        if (diff >= std::abs( taste )) {
            diff = std::abs( taste );
            ans = total - taste;
        }
    }
    std::cout << ans << std::endl;
}

int main() {
    int N, L;
    std::cin >> N >> L;
    solve( N, L );
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main (void)
{
    int gr[101][101],gou,gyo,retu;
    int a,b; 
 
    scanf("%d %d",&gyo,&retu);
 
    for(a=0;a<=gyo;a++)//?????????
    {
        for(b=0;b<=retu;b++)
        {
            gr[a][b]=0;
        }
    }
    for(a=0;a<gyo;a++)//??\???
    {
        for(b=0;b<retu;b++)
        {
            scanf("%d",&gr[a][b]);
        }
    }
 
    gou=0;
    for(a=0;a<gyo;a++)//????????????
    {
        gou=0;
        for(b=0;b<retu;b++)
        {
            gr[a][retu]+=gr[a][b];
        }
     
    }
 
    gou=0;
    for(b=0;b<retu;b++)
    {
        gou=0;
        for(a=0;a<gyo;a++)//????????????
        {
            gr[gyo][b]+=gr[a][b];
        }
        gr[gyo][retu]+=gr[a][b];
    }
 
     
    for(a=0;a<=gyo;a++)
    {
        for(b=0;b<=retu;b++)
        {
            printf("%d",gr[a][b]);
            if(b!=retu)printf(" ");
        }
        if(a!=gyo)printf("\n");
         
    }
 
    printf("\n");
    return 0;
}

Measured memory_bytes: 644
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n = in();
	vector<ll>inp(n);
	ll sum = 0;
	REP(i, n) {
		inp[i] = in();
		sum += inp[i];
	}
	bool flag = true;
	REP(i, n) {
		flag &= inp[i] * 2 < sum;
	}
	cout << (flag ? "Yes" : "No") << endl;
}

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

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> f(n);
    ll sum_a = 0;
    for(auto& ai:a) { cin >> ai; sum_a += ai; }
    for(auto& fi:f) cin >> fi;
    sort(a.begin(), a.end(), greater<ll>());
    sort(f.begin(), f.end());

    if(k >= sum_a) {
        cout << 0 << endl;
        return 0;
    }

    ll ok = 0;
    rep(i,n) ok = max(ok, a[i]*f[i]);
    ll ng = -1;

    auto is_ok = [&](ll mid){
        ll sum = 0;
        rep(i,n) {
            if(a[i]*f[i] > mid)
                sum += a[i]-mid/f[i];
            if(sum > k) return false;
        }
        return sum <= k;
    };

    while(abs(ok-ng)>1) {
        ll mid = (ok+ng)/2;
        if(is_ok(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 3328
fn main() {
    let (n,m,v,p) = {
        let s = rv::<usize>();
        (s[0],s[1]as i64,s[2],s[3])
    };
    let mut a = rv::<i64>();
    a.sort();
    let mut s = vec![0;n+1];
    for i in 0..n {
        s[i+1] = s[i]+a[i];
    }
    let mut t=p;
    for i in 0..n-p {
        let r=std::cmp::max(0,v as i64-(p+i) as i64);
        t += if a[n-p]>a[i]+m || (m*r+s[n-p+1]-s[i+1])>(a[i]+m)*(n-p-i)as i64 {0} else {1};
    }
    println!("{}",t);
}
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T>
  where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

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

using namespace std;

static bool is_outside_maze (pair<int, int> coord, int height, int width) {
    return (coord.first < 0 || width-1 < coord.first ||
            coord.second < 0 || height-1 < coord.second );
}

static int dfs_maze (vector<vector<int>> &maze, int height, int width, int start_col, int start_row) {
    /* 上下左右移動用の table */
    pair<int, int> all_move[] = {
        make_pair(0, 1),
        make_pair(0, -1),
        make_pair(-1, 0),
        make_pair(1, 0)
    };

    int largest = 0;
    pair<int, int> coord = make_pair(start_col, start_row);
    queue<pair<int, int>> q;
    q.push(coord);

    while ( !q.empty() ) {
        coord = q.front(); q.pop();

        for ( auto move : all_move ) {
            pair<int, int> cur;
            cur.first = coord.first + move.first;
            cur.second = coord.second + move.second;

            if ( is_outside_maze(cur, height, width) ||
                 maze.at(cur.second).at(cur.first) == -1 )
                continue;

            if ( maze.at(cur.second).at(cur.first) == INT_MAX ) {
                maze.at(cur.second).at(cur.first) = maze.at(coord.second).at(coord.first) + 1;
                largest = max(largest, maze.at(cur.second).at(cur.first));
                q.push(cur);
            }
        }
    }

    return largest;
}

static void clear_maze (vector<vector<int>> &maze, int height, int width) {
    for ( int row=0; row<height; row++ ) {
        for ( int col=0; col<width; col++ ) {
            if ( maze.at(row).at(col) != -1 )
                maze.at(row).at(col) = INT_MAX;

        }
    }
}

int main (void) {
    int H, W;
    cin >> H >> W;

    string line;
    /* 壁の場所を -1, そのほかの場所に start 位置からの距離を入れる */
    vector<vector<int>> maze(H, vector<int> (W, INT_MAX));
    for ( int row=H-1; row>=0; row-- ) {
        cin >> line;
        assert(line.size() == W);
        for ( int col=0; col<W; col++ ) {
            if ( line.at(col) == '#' )
                maze.at(row).at(col) = -1;
        }
    }

    int ans = 0;
    int longest;
    for ( int start_row=0; start_row<H; start_row++ ) {
        for ( int start_col=0; start_col<W; start_col++ ) {
            /* 壁の位置からは始められない */
            if ( maze.at(start_row).at(start_col) == -1 )
                continue;
            maze.at(start_row).at(start_col) = 0;
            longest = dfs_maze(maze, H, W, start_col, start_row);
            if ( longest > ans )
                ans = longest;
            clear_maze(maze, H, W);
        }
    }

    cout << ans << endl;
    return 0;
}


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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int D;
int A;
pair<int, int> a[N];
queue<pair<int, long long>> q;
int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        /// freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    cin >> n >> D >> A;
    for(int i = 1; i <= n; i ++){
        cin >> a[i].fr >> a[i].se;
    }
    long long res = 0;
    long long  damage = 0;
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; i ++){
        while(!q.empty() && a[i].fr > q.front().fr){
            damage -= q.front().se;
            q.pop();
        }
        long long hp = a[i].se - damage;
        if(hp > 0){
            long long bombs = (hp + A - 1) / A;
            res += bombs;
            damage += bombs * A;
            q.push({a[i].fr + 2 * D, bombs * A});
        }
    }
    cout << res << "\n";
}



Measured memory_bytes: 3456