akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;

class UnionFind
{
public:
    UnionFind(int N) : par(N)
    {
        for (ll i = 0; i < N; i++)
        {
            par[i] = i;
        }
    }

    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
    }

    bool same(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

private:
    vector<int> par;
};

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

struct Dish
{
    ll time;
    ll taste;
};

int main()
{
    ll X, Y, Z;
    cin >> X >> Y >> Z;

    cout << ((X - Z) / (Y + Z)) << endl;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int i;
  for (i = min(a, b); i > 0; i--) {
    if (a % i == 0 && b % i == 0) {
      k--;
      if (k == 0) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
a = int(input())
b = list(map(int, input().split()))
import bisect
ln = []
x = 0
for i in b:
    x += i
    ln.append(x)
index = bisect.bisect_left(ln, sum(b)/2)
if sum(b[0:index -1]) == sum(b)/2:
            print(0)
else:
                v =  sum(b[0:index + 1])- (sum(b)-sum(b[0:index + 1]))
                u = (sum(b)-sum(b[0:index]))-sum(b[0:index])
                print(min(v,u)) 

Measured memory_bytes: 99660
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

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


int main(void)
{
	ll n;
	while(scanf("%lld", &n)==1)
	{
		ll ans=0;

		for(ll m=1;m*(m+1)<n;m++)
		{
			if((n-m)%m==0)
			{
				ans+=(n-m)/m;
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF MOD
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int last[400][30];
Int v[400];

int main() {
    int D;
    cin >> D;
    int c[30];
    Int s[D+10][30];
    Int t[D+10];
    map<int, int> last;
    for (int i = 1; i <= 26; i++) {
        cin >> c[i];
    }
    for (int d = 1; d <= D; d++) {
        for (int i = 1; i <= 26; i++) {
            cin >> s[d][i];
        }
    }
    for (int d = 1; d <= D; d++) {
        cin >> t[d];
    }
    Int total = 0;
    for (int d = 1; d <= D; d++) {
        last[t[d]] = d;
        total += s[d][t[d]];
        for (int i = 1; i <= 26; i++) {
            total -= c[i] * (d - last[i]);
        }
        v[d] = total;
    }
    for (int d = 1; d <= D; d++) {
        cout << v[d] << endl;
    }
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>

using namespace std;

#define LL long long

string s,t;
LL pos,cnt;

int main() {
    cin>>s>>t;
    for(int i = 0 ; i < t.length() ; i++) {
        pos = s.find(t[i],pos);
        if(pos == -1) {
            pos = s.find(t[i],0);
            if(pos == -1) {
                puts("-1");
                return 0;
            }
            cnt++;
        }
        pos++;
    }
    LL ans = cnt * s.length() + pos;
    printf("%lld \n",ans);
    //system("pause");
    return 0;
}

Measured memory_bytes: 512
n =int(input())
s=input()

white =[0]
black=[0]

for i in range(n):
    white.append(white[i]+int(s[i]=='.'))
    black.append(black[i]+int(s[i]=='#'))

ans = 300000
for i in range(n+1):
    if ans>black[i]+white[n]-white[i]:
        ans=black[i]+white[n]-white[i]

print(ans)




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

int main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if(k <= a){
        ans = k;
    }else if(k <= b){
        ans = a;
    }else{
        ans = a - (k-a-b);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>

using namespace std;

long long int N;

int main() {
	cin >> N;
	if (N % 2 == 0) {
		cout << (N / 2) * (N - 1) << endl;
	}
	else {
		cout << N * ((N - 1) / 2) << endl;
	}
}

Measured memory_bytes: 256
import numpy as np
 
 
if __name__ == '__main__':
    List = [list(map(int, input().split())) for i in range(2)]
    N = List[0][0]
    buka = np.array(List[1][:])
 
 
    l_out = np.zeros(N,dtype=int)
 
    for i in range(N-1):
        l_out[buka[i]-1] += 1
 
    for i in range(N):
        print(l_out[i])
 

Measured memory_bytes: 50752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N], B[] = new int[N], C[] = new int[N];

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		for (int i = 1; i < N; i++) {
			C[i] = sc.nextInt();
		}
		int ans = 0;
		for (int i = 0; i < N; i++) {
			ans += B[i];
		}
		for (int i = 1; i < N; i++) {
			if (A[i - 1] + 1 == A[i]) {
				ans += C[A[i-1]];
			}
		}
		sc.close();
		System.out.println(ans);
	}
}


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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;

	bool operator<(const data &ri) const{
		return cost < ri.cost;
	}
	bool operator>(const data &ri) const{
		return cost > ri.cost;
	}
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};



int main(){
	int n, m;
	vector<int> cost[1001];
	int num[1001] = {};

	cin >> n >> m;
	for(int i = 0; i < n; i++){
		int in;
		cin >> in;
		for(int j = in; j <= 1000; j++){
			if(cost[j].size()) break;
			cost[j].pb(i+1);
		}
	}

	for(int i = 0; i < m; i++){
		int in;
		cin >> in;
		num[cost[in][0]]++;
	}

	int ans = 0, c = -inf;
	for(int i = 1; i <= n; i++){
		if(c < num[i]){
			ans = i;
			c = num[i];
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3200
import java.util.*;

class Main{

     public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        
        Integer[] ary = new Integer[n];
        for(int i = 0; i < n; ++i) {
            int tmp = Integer.parseInt(sc.next());
            ary[i] = tmp;
        }
        
        int j = 0;
        int sum = 0;
        
        for(int i = 1; i < n + 1; ++i) {
            while(d - (j * ary[i-1] + 1) >= 0) {
                ++sum;
                ++j;
            }
            j = 0;
        }
        
        int ans = sum + x;
        System.out.println(ans);
     }
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
	int n, x, m;
	int[][] map;
	
	void print(int[] nn){
		String ans = "";
		for(int i=0;i<nn.length;i++){
			ans += nn[i] + " ";
		}
		System.out.println(ans.trim());
		System.exit(0);
	}
	
	boolean check(int[] nn){
		boolean[] ff = new boolean[nn.length];
		for(int i=0;i<m;i++){
			int sum = 0;
			for(int j=map[i][0]-1;j<map[i][1];j++){
				ff[j] = true;
				sum += nn[j];
			}
			if(sum!=map[i][2]) return false;
		}
		
		for(int i=0;i<nn.length;i++){
			if(!ff[i]) nn[i] = x;
		}
		print(nn);
		return true;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		
		n = sc.nextInt();
		x = sc.nextInt();
		m = sc.nextInt();
		map = new int[m][3];
		for(int i=0;i<m;i++){
			map[i][0] = sc.nextInt();
			map[i][1] = sc.nextInt();
			map[i][2] = sc.nextInt();
		}
		
		int[] nn = new int[n];
		for(int a=x;a>=0;a--){
			nn[0] = a;
			if(n==1){
				check(nn);
				continue;
			}
			for(int b=x;b>=0;b--){
				nn[1] = b;
				if(n==2){
					check(nn);
					continue;
				}
				for(int c=x;c>=0;c--){
					nn[2] = c;
					if(n==3){
						check(nn);
						continue;
					}
					for(int d=x;d>=0;d--){
						nn[3] = d;
						if(n==4){
							check(nn);
							continue;
						}
						for(int e=x;e>=0;e--){
							nn[4] = e;
							if(n==5){
								check(nn);
								continue;
							}
							for(int f=x;f>=0;f--){
								nn[5] = f;
								check(nn);
							}
						}
					}
				}
			}
		}
		System.out.println(-1);
	}
	
	public static void main(String[] args) {
		new	Main().run();
	}

	
}

Measured memory_bytes: 55128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int n;
    cin >> n;
    int a[n];
    rep(i,n){
        cin >> a[i];
    }
    int count = 0;
    for(int i=0;i<n;i=i+2){
        if(a[i] % 2 == 1){
            //cout << a[i] << endl;
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3624
function Main(input){
var tmp = input.split('\n');
var size = tmp[0];
var tmp3 = [];
 for(var i = 1; i <= size ; i++){
   
   tmp3.push({
   city: tmp[i].split(' ')[0],
   score: parseInt(tmp[i].split(' ')[1]),
   index: i
   });
 }
var tmp2 = tmp3.sort(function(a,b){
if(a.city < b.city){return -1};
if(a.city > b.city){return 1};
if(a.score < b.score){return 1};
if(a.score > b.score){return -1};
return 0;
});
tmp2.forEach(function(e){
  if(e.index){
    console.log(e.index);
  }
})

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7800
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a[] = new int[3];
        for(int i=0;i<3;i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[0] + " " + a[1] + " " + a[2]);
        sc.close();
    }
}


Measured memory_bytes: 26284
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<map>
#include<vector>
using namespace std;
int a, b, c;

int main()
{
	scanf("%d %d %d", &a, &b, &c);
	int cnt1 = 0, cnt2 = 0;
	if(a == 5) cnt1++;
	if(b == 5) cnt1++;
	if(c == 5) cnt1++;
	if(a == 7) cnt2++;
	if(b == 7) cnt2++;
	if(c == 7) cnt2++;
	if(cnt1 == 2 && cnt2 == 1) printf("YES\n");
	else printf("NO\n");
	return 0;

}

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

using namespace std;

char ar[105];

int palindrome(int l,int r)
{
    for(int i=l;i<=(r-l)/2;i++)
        if(ar[i]!=ar[r-i])
            return 0;
    return 1;
}

int main(void)
{
    scanf("%s",ar);
    if(palindrome(0, strlen(ar)-1) && palindrome(0, ((strlen(ar)-2)/2)) && palindrome((strlen(ar)+2)/2, strlen(ar)))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,A,B,C,D;

string ans = "YES";

void solve(){
    N--;
    if(A>B) swap(A,B);
    LL lower = -N*D;
    LL upper = -N*C;
    for(int _=0;_<N+1;_++){
        //cout << lower << " " << upper << endl;
        if(lower<=(B-A) && (B-A)<=upper) return;
        lower += C+D;
        upper += C+D;
    }
    ans = "NO";
}

int main(){
    cin >> N >> A >> B >> C >> D;

    solve();

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

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

  vector<bool> dp(111111, false);
  dp.at(0) = true;
  for (ll i = 0; i < 100100; i++)
  {
    if (!dp.at(i))
      continue;
    for (ll j = 0; j < 6; j++)
    {
      dp.at(i + 100 + j) = dp.at(i);
    }
  }
  cout << dp.at(X) << endl;
}

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

void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
int n, w, h;
int ch[2][200005] = {0};

bool solve();

int main() {
  cin >> n >> w >> h;
  for(int i = 0; i < n; ++i) {
    int x, y, p;
    cin >> x >> y >> p;
    ch[0][max(0, 2 * (x - p))] += 1;
    ch[0][min(2 * w + 1, 2 * (x + p) + 1)] += -1;
    ch[1][max(0, 2 * (y - p))] += 1;
    ch[1][min(2 * h + 1, 2 * (y + p) + 1)] += -1;
  }
  prians(solve());
  return 0;
}

bool solve() {
  for(int i = 0; i <= 2 * w; ++i) {
    if(i != 0) ch[0][i] += ch[0][i - 1];
    if(ch[0][i] <= 0) break;
    if(i == 2 * w) return 1;
  }
  for(int i = 0; i <= 2 * h; ++i) {
    if(i != 0) ch[1][i] += ch[1][i - 1];
    if(ch[1][i] <= 0) break;
    if(i == 2 * h) return 1;
  }
  return 0;
}


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

using namespace std;

#ifdef LOCAL
#define DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) 0
#endif

using ll = long long;
using ull = unsigned long long;

const int INF = 1e9 + 7;

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

  vector<int> p(n + 1, 0);

  for (auto i = 1; i <= n; ++i) {
    cin >> p[i];
  }

  int ans = 0;

  vector<int> m(n + 1, 0);
  m[0] = INF;

  for (auto i = 1; i <= n; ++i) {
    m[i] = min(m[i - 1], p[i]);
  }

  dbg(m);

  for (auto i = 1; i <= n; ++i) {
    if (p[i] <= m[i]) {
      ++ans;
    }
  }

  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  solve();

  return 0;
}

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

int main(void) {
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    for(int i = 0; i < N; i++) {
        cin >> V[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> C[i];
    }
    int X, Y;
    X = 0; Y = 0;
    for(int i = 0; i < N; i++) {
        if(V[i] > C[i]) {
            X += V[i];
            Y += C[i];
        }
    }
    cout << X - Y << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll _gcd(ll x, ll y){
    while(1){
        if(x%y == 0)return y;
        else{
            ll z = x%y;
            x = y;
            y = z;
        }
    }
}

//ミョ(-ω- ?)
int main() {
    int h,w,c;
    cin >> h >> w >> c;
    int grid = (h/_gcd(h,w)) * (w/_gcd(h,w));
    cout << grid*c << endl;
    return 0;
}


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

    // 出力
    if(x >= a){
      System.out.println(10);   
    }else{
      System.out.println(0);   
    }
  }
}


Measured memory_bytes: 24276
from scipy.sparse.csgraph import floyd_warshall

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

G = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]

# neighborhood graph
nei_graph = [[0] * N for _ in range(N)]
for a, b, c in G:
    nei_graph[a - 1][b - 1] = c
    nei_graph[b - 1][a - 1] = c

# Warshall Floyd
nei_graph = floyd_warshall(nei_graph)

# 1 if distance is less than L
for i in range(N):
    for j in range(N):
        if nei_graph[i][j] <= L:
            nei_graph[i][j] = 1
        else:
            nei_graph[i][j] = 0

nei_graph = floyd_warshall(nei_graph)

for start, end in Query:
    if nei_graph[start - 1][end - 1] - 1 == float('inf'):
        print(-1)
    else:
        print(int(nei_graph[start - 1][end - 1] - 1))

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

int main() {
  long long H, W; cin >> H >> W;
  long long ans = 1LL << 30;
  vector<long long> s(3);
  for (int i = 0; i < 2; i++) {
    for (long long h = 1; h < H; h++) {
      s.at(0) = h * W;
      s.at(1) = (H - h) * (W / 2);
      s.at(2) = H * W - (s.at(0) + s.at(1));
      sort(s.begin(), s.end());
      ans = min(ans, s.at(2) - s.at(0));

      s.at(0) = h * W;
      s.at(1) = ((H - h) / 2) * W;
      s.at(2) = H * W - (s.at(0) + s.at(1));
      sort(s.begin(), s.end());
      ans = min(ans, s.at(2) - s.at(0));
    }
    swap(H, W);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
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[] s = new long[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextLong();
            if(i==0) {
                s[i] = a[i];
            } else {
                s[i] = s[i-1] + a[i];
            }
        }

        long sum = s[n-1];
        long min = sum;
        for(int i=0; i<n-1; i++) {
            long left = s[i];
            long right = sum - s[i];
            min = Math.min(min, Math.abs(left - right));
        }
        System.out.println(min);

    }


}


Measured memory_bytes: 90744
local s = io.read()
local t = {}
t["N"] = 0
t["W"] = 0
t["S"] = 0
t["E"] = 0
for i = 1, #s do
  sstr = s:sub(i, i)
  t[sstr] = t[sstr] + 1
end
local ok = true
if 0 < t.N and 0 == t.S then
  ok = false
end
if 0 < t.S and 0 == t.N then
  ok = false
end
if 0 < t.W and 0 == t.E then
  ok = false
end
if 0 < t.E and 0 == t.W then
  ok = false
end
print(ok and "Yes" or "No")


Measured memory_bytes: 508
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}


fn lcm(i:i64, j:i64) -> i64 {
  let x = i * j;

  /* 自然数 a > b を確認・入替 */
  let (mut a, mut b) = if i < j { (j, i) } else { (i, j) };

  /* ユークリッドの互除法 */
  let mut r = a % b;
  while r != 0 {
    a = b;
    b = r;
    r = a % b;
  }

  x/b
}

fn main() {
    let line = get_input();
    let mut split = line.split_whitespace();
    let a:i64 = split.next().unwrap().parse().unwrap();
    let b:i64 = split.next().unwrap().parse().unwrap();
    let c:i64 = split.next().unwrap().parse().unwrap();
    let d:i64 = split.next().unwrap().parse().unwrap();

    let l = lcm(c,d);

    let bc = b / c;
    let bd = b / d;
    let bl = b / l;

    let ac = (a-1) / c;
    let ad = (a-1) / d;
    let al = (a-1) / l;

    let ans = (b - bc - bd + bl) - (a-1 - ac - ad + al);
    println!("{}", ans);
}

Measured memory_bytes: 4352
def chmax(a,b):
    if a > b:
        return a
    else:
        return b

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

dp = [[0, 0, 0] for _ in range(N)]

dp[0][0] = A[0][0]
dp[0][1] = A[0][1]
dp[0][2] = A[0][2]

for i in range(1,N):
    dp[i][0] = chmax(dp[i-1][1]+A[i][0], dp[i-1][2]+A[i][0])
    dp[i][1] = chmax(dp[i-1][0]+A[i][1], dp[i-1][2]+A[i][1])
    dp[i][2] = chmax(dp[i-1][0]+A[i][2], dp[i-1][1]+A[i][2])

print(max(dp[N-1][0], dp[N-1][1], dp[N-1][2]))

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

int main() {
  int H, N, A, total=0;
  cin >> H >> N;
  for (int i = 0; i < N; i++) {
    cin >> A;
    total += A;
  }

  if (H > total) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    char bomb[H + 2][W + 2] = {'.'};
    rep(i, H) rep(j, W) cin >> bomb[i + 1][j + 1];
    for (int i = 1; i < (H + 1); i++)
    {
        for (int j = 1; j < (W + 1); j++)
        {
            if (bomb[i][j] == '.')
            {
                int counter = 0;
                if (bomb[i - 1][j - 1] == '#')
                    counter++;
                if (bomb[i - 1][j] == '#')
                    counter++;
                if (bomb[i - 1][j + 1] == '#')
                    counter++;
                if (bomb[i][j - 1] == '#')
                    counter++;
                if (bomb[i][j + 1] == '#')
                    counter++;
                if (bomb[i + 1][j - 1] == '#')
                    counter++;
                if (bomb[i + 1][j] == '#')
                    counter++;
                if (bomb[i + 1][j + 1] == '#')
                    counter++;
                bomb[i][j] = char(counter + '0');
            }
            cout << bomb[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
s=sum(l[:k])
ma=s
i=0
while i+k<len(l):
    s-=l[i]
    s+=l[i+k]
    ma=max(ma,s)
    i+=1
print((ma+k)/2)


Measured memory_bytes: 71792
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define gc getchar()
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
#define lint long long
#define db double
using namespace std;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
inline int dig(int x,int ans=0)
{
	while(x) ans+=x%10,x/=10;return ans;
}
int main()
{
	int n=inn(),ans=100000000;
	for(int i=1;i<n;i++)
		ans=min(ans,dig(i)+dig(n-i));
	return !printf("%d\n",ans);
}

Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>

using namespace std;

#define D(x) x
#define REP(i,a,b) for (int i = (a); i < (b); ++i)
#define REPR(i,a,b) for (int i = (b) - 1; i >= (a); --i)
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int> > VII;

void solve() {
    int N; cin >> N;
    int l[N], r[N];
    REP(i,0,N)
        cin >> l[i];
    REP(i,0,N)
        cin >> r[i];

    ll res = 1;
    if (r[0] != l[N-1])
        res = 0;

    REP(i, 1, N-1) {
        if (l[i] > l[i-1] && r[i] < l[i])
            res = 0;
        if (r[i] > r[i+1] && l[i] < r[i])
            res = 0;
        if (l[i] < l[i-1] || r[i] < r[i+1])
            res = 0;
        if (l[i] > l[i-1] && r[i] > r[i+1] && l[i] != r[i])
            res = 0;

        if (l[i] == l[i-1] && r[i] == r[i+1])
            res = (res * (min(l[i], r[i]))) % 1000000007ll;
    }
    cout << res << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;

    solve();

	return 0;
}


Measured memory_bytes: 1152
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

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

int main() {
	//Sの数n、cの数m
	ll n, m;
	cin >> n >> m;
	m -= 2 * n;
	if (m >= 0) {
		cout << n + m / 4 << endl;
	}
	else cout << (m+2*n)/2 << endl;
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N, M;
vi g[200010];
bool r[200010], r2[200010];

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

	rep(i, M) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].pb(b);
		g[b].pb(a);
	}

	for (int to : g[0]) {
		r[to] = 1;
	}

	for (int to : g[N-1]) {
		r2[to] = 1;
	}

	bool ok = 0;
	rep(i, N) {
		if (r[i] && r2[i]) {
			ok = 1;
		}
	}

	puts(ok ? "POSSIBLE" : "IMPOSSIBLE");

	return 0;
}

Measured memory_bytes: 12400
#include<stdio.h>

int main() {
  int i, j, x, y;

  for (i = 1; 1; i++){
    scanf("%d %d",&x,&y);
    if ( x == 0 && y == 0 )
      break;
    if ( x > y ) {
      j = x;
      x = y;
      y = j;
    }
    printf("%d %d\n",x,y);
  }

  return 0;
}

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

int dp[1003][1003];

int main() {
	int h, w;
	scanf("%d %d", &h, &w);
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			char c;
			scanf(" %c", &c);
			if (c == '.') {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
                if (i*j == 1)
                    dp[i][j] = 1;
			}
		}
	}
    printf("%d", dp[h][w]);
}

Measured memory_bytes: 4224
#include <stdio.h>
#define MAX 1000000

int A[MAX], H;

void maxHeapify(int i){
  int l, r, largest, n = 0;
  l = i * 2;
  r = i * 2 + 1;
  if(l <= H && A[l] > A[i])largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest])largest = r;
  if(largest != i){
    n = A[i];
    A[i] = A[largest];
    A[largest] = n;
    maxHeapify(largest);
  }
}

int main(){
  int i;
  scanf("%d",&H);
  for(i=1; i<=H; i++)scanf("%d",&A[i]);
  for(i=H/2; i>=1; i--)maxHeapify(i);
  for(i=1; i<=H; i++)printf(" %d",A[i]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 3668
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
int a[200009];
int main(){
    int x,a;
	cin>>x>>a;
	if(x<a){
		cout<<0<<endl;
	}else{
		cout<<10<<endl;
	}
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

vi g[100005];
int vis[100005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	queue<int> q;
	q.push(0);
	vis[0] = 1;
	vi ans(n, 0);
	while(!q.empty()){
		queue<int> q1;
		while(!q.empty()){
			int cur = q.front();
			q.pop();
			for(int u : g[cur]){
				if(!vis[u]){
					q1.push(u);
					vis[u] = 1;
					if(!ans[u]) ans[u] = cur + 1;
				}
			}
		}
		q = q1;
	}
	cout << "Yes" << endl;
	repn(i, 1, n) cout << ans[i] << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define MAX 200000

int main()
{
    int n;
    cin >> n;
    vector<int> R(n);
    REP(i, n) cin >> R[i];
    
    int maxv = -1000000000;
    int minv = R[0];

    for(int i = 1; i < n; i++)
    {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 3628
import math

N = int(input())
task = {}
tasks = []
for i in range(N):
    tmp = input().split()
    A = int(tmp[0])
    B = int(tmp[1])
    tasks.append((B,A))
    task[B] = A
    # if B in task:
    #     task[B].append(A)
    # else:
    #     task[B] = [A]

s = 0
# for b in sorted(task.keys()):    
#     s += task[b]
#     if b<s:
#         print('No')
#         exit()

for (b,a) in sorted(tasks):
    s += a
    if b<s:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 92536
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto s = readln.chomp.split.to!(int[]);
  auto ab = s[0] * s[1];
  auto f = false;
  foreach (i; 1..4) {
    if (ab * i % 2) {
      f = true;
    }
  }

  if (f) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = li_input()

    B = [-1] * N

    l = 0
    r = N - 1
    i = N - 1

    while l < r:
        B[l] = A[i]
        B[r] = A[i - 1]
        l += 1
        r -= 1
        i -= 2

    if l == r:
        B[l] = A[0]

    print(" ".join(list(map(str, B))))


main()


Measured memory_bytes: 31116
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 100010
int h,w,d;
pair<int,int> x[N];
int t[N];
int main(){
    lol(i,N)x[i]=make_pair(-1,-1);
    cin>>h>>w>>d;
    lol(i,h)lol(j,w){
	int a;cin>>a;
	x[a]=make_pair(i,j);
    }
    lol(i,N){
	if(i<d)t[i]=0;
	else{
	    if(x[i-d].first==-1)t[i]=t[i-d];
	    else t[i]=t[i-d]+abs(x[i].first-x[i-d].first)+abs(x[i].second-x[i-d].second);
	}
    }
    int q;cin>>q;
    lol(i,q){
	int l,r;cin>>l>>r;
	cout<<t[r]-t[l]<<endl;
    }
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": # "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	int res=0;
	for(string s;cin>>s;){
		rep(i,s.size())
			if(!isdigit(s[i]))
				s[i]=' ';
		istringstream iss(s);
		for(int n;iss>>n;)
			res+=n;
	}
	cout<<res<<endl;
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cstring>
#include <vector>
#define rep(i,n) for(ll i=1;i<=n;i++)
#define repn(i,n) for(ll i=n;i>=1;i--)
#define ll long long
#define mt(a,x) memset(a,x,sizeof(a))
const ll mod = 1e9+7;
const ll maxn = 1000050;
using namespace std;
int main()
{
    //freopen("data","r",stdin);
    ios::sync_with_stdio(0);
    string s;
    while(cin>>s)
    {
        int num = s.length();
        if(s[0]==s[num-1])
        {
            if(num&1) cout<<"Second"<<endl;
            else cout<<"First"<<endl;
        }
        else
        {
            if(num&1) cout<<"First"<<endl;
            else cout<<"Second"<<endl;
        }
    }
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int A, B;
  cin >> A >> B;
  cout << (A + B) % 24 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2,62);

int keta(int x){
  for(int j = 0; ; j++){
    int a = pow(10, j);int b = pow(10, j+1);
    if(a <= x && x < b){
      return j + 1;
      break;
    }else{
      continue;
    }
  }
}

int main(){
    ll n;cin >> n;
    ll ans = 0;
    for(int i = 1;i <= n;i++){
        ll oo = keta(i);
        if(oo % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4012
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        boolean[] bool = new boolean[4];
        for(char c : s){
            if(c == 'N'){
                bool[0] = true;
            }else if(c == 'S'){
                bool[1] = true;
            }else if(c == 'E'){
                bool[2] = true;
            }else{
                bool[3] = true;
            }
        }
        if(!(bool[0] ^ bool[1]) && !(bool[2] ^ bool[3])){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ll n, m;
	cin >> n >> m;
	ll res = min(n, m / 2);
	n -= res;
	m -= 2 * res;
	if (m >= 2)
	{
		res += m / 4;
	}

	cout << res << '\n';

	return 0;

}


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

using namespace std;
using namespace __gnu_pbds;
using namespace std::chrono;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
///find_by_order, order_of_key

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int MOD = 1e9 + 7;
const int MAXN = 100;
map<string,int> m[MAXN+1];
int n;

string slova = "ACGT";

int add(int a, int b)
{
    a %= MOD;
    b %= MOD;
    return (a+b) % MOD;
}

bool ok(string &s)
{
    string nesto = "AGC";
    for(int i = 0; i < 4; ++i)
    {
        string temp = s;
        if(i+1<4)
        {
            swap(temp[i], temp[i+1]);
        }
        //cout << "Ide temp " << temp << '\n';
        if(temp.find(nesto)!=string::npos)
            return 0;
    }
    return 1;
}

int dfs(int index, string &s)
{
    if(m[index].count(s))
        return m[index][s];
    if(index == n)
        return 1;
    int res=0;
    for(auto &c : slova)
    {
        string temp = s + c;
        if(ok(temp))
        {
            string novi = temp.substr(1);
            res = add(res, dfs(index+1, novi));
        }
    }

    m[index][s] = res;
    return res;
}

int main()
{
    #ifdef ljuba
    auto pocetakChronoSata123 = high_resolution_clock::now();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);       
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    string vauOnoNeRadi = "TTT";
    cout << dfs(0, vauOnoNeRadi) << '\n';

    #ifdef ljuba
    auto krajChronoSata123 = high_resolution_clock::now();
    auto trajanje = duration_cast<microseconds>(krajChronoSata123 - pocetakChronoSata123);
    cout << "----------------------------------------------------\n";
    cout << "Vreme u milisekundama: " << (ld)trajanje.count() / 1000.00 << '\n';
    #endif
    return 0;
}

Measured memory_bytes: 4088
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define Max(_A,_B) (_A>_B?_A:_B)
#define Min(_A,_B) (_A<_B?_A:_B)
#define Abs(_A) ((_A)?(_A):(-(_A))
#define INF 0x3f3f3f3f
int n,loc[100005];
double t,a,h[100005];
inline double cmp(int a,int b){
    return h[a]<h[b];
} 
void init(){
    scanf("%d",&n);
    scanf("%lf%lf",&t,&a);
    for(int i=1;i<=n;++i){
        scanf("%lf",&h[i]);
        h[i]=t-h[i]*0.006;
        h[i]-=a;
        h[i]=(h[i]<0)?(-h[i]):h[i];
        loc[i]=i;
    }
    sort(loc+1,loc+1+n,cmp);
    printf("%d",loc[1]);
}
int main(){
	init();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main(void) {
  int N;
  int X;
  int L;
  int D = 0;
  int count = 0;
  std::cin >> N >> X;
  while ((count <= N) && (D <= X)) {
    count++;
    std::cin >> L;
    D += L;
  }
  std::cout << count;
  return 0;
}
    


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    long long int sum=0;
    for (int i=1;i<=n;i++) {
        if (i%3==0||i%5==0) continue;
        sum+=i;
    }
    printf("%lld\n", sum);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e9 + 7;
int ni[] = {-1, 0, 1, 0};
int nj[] = {0, -1, 0, 1};

int main() {
  int h,w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i,h) cin >> a[i];

  queue<pair<int, int>> q;
  rep(i,h) rep(j,w) if(a[i][j] == '#') q.emplace(i,j);

  int ans = 0;
  while(!q.empty()){ 
    queue<pair<int, int>> t;
    while(!q.empty()){
      int si = q.front().first;
      int sj = q.front().second;
      q.pop();
      rep(i,4){
        int x = si + ni[i];
        int y = sj + nj[i];
        if (x < 0 || y < 0 || x >= h || y >= w) continue;
        if (a[x][y] == '.'){
          a[x][y] = '#';
          t.emplace(x,y);
        }
      }
    }
    q = t;
    if(!q.empty()){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 13584
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int n;
long a, b, c, d;

void main() {
    scan(n, a, b, c, d);

    b = b - a;
    a = 0;
    n--;

    foreach (i ; 0 .. n + 1) {
        if (i * c - (n - i) * d <= b && b <= i * d - (n - i) * c) {
            writeln("YES");
            return;
        }
    }

    writeln("NO");
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()%
//#define int long long

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<vi> f;
    for (int i = 0; i < n; i++) {
        f.push_back(vector<int>(10));
        for (int j = 0; j < 10; j++) cin >> f[i][j];
    }
    vector<vi> p;
    for (int i = 0; i < n; i++) {
        p.push_back(vector<int>(11));
        for (int j = 0; j < 11; j++) cin >> p[i][j];
    }
    ll ans = -1e9;
    for (int i = 1; i < (1 << 10); i++) {
        ll sum = 0;
        for (int j = 0; j < n; j++) {
            int cnt = 0;
            for (int k = 0; k < 10; k++) {
                if ((i & (1 << k)) && f[j][k]) cnt++;
            }
            sum += (ll) p[j][cnt];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Stack;
import java.io.*;
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String str;
		Stack<Integer> s = new Stack<Integer>();
		while (null != (str = in.readLine())){
			doit(Integer.parseInt(str),s);
		}
	}
	
	private static void doit(int n,Stack<Integer> s){
		if(n==0)
			System.out.println(s.pop());
		else s.push(n);
	}

}

Measured memory_bytes: 16868
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int t[26];
#define DIV 4
int main(void)
{
	int n, v;
	ll ans = 0;
	cin >> n;
	map<int, int>mp, mp2;
	rep(i, 0, n)cin >> v, mp[v + i]++, mp2[i - v]++;
	for (auto m : mp) {
		ans += (ll)m.second * mp2[m.first];
	}
	printf("%lld\n", ans);
}

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

using namespace std;


int a,b,x;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>a>>b>>x;
    if(a<=x && x<=a+b)puts("YES");
    else
        puts("NO");
    return 0;
}
/**
**/


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

public class Program{
    public static void Main(){
        
        string[] line = Console.ReadLine().Trim().Split();
        int[] house = new int[3];
        for(var i = 0; i < 3; i++){
            house[i] = int.Parse(line[i]);
        }
        if(house[0] > house[1]){
            var tmp = house[0];
            house[0] = house[1];
            house[1] = tmp;
        }
        
        if(house[2] > house[0] && house[2] < house[1]){
            Console.WriteLine("Yes");
        }else{
            Console.WriteLine("No");
        }
    }
}


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

int main() {
  int k,n;
  cin>>k>>n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
	cin>>vec.at(i);
  }
  
  vec.push_back(vec.at(0)+k);
  int max=0;
  for(int i=0;i<n;i++){
	if(max<vec.at(i+1)-vec.at(i)){
		max=vec.at(i+1)-vec.at(i);
    }else{
		continue;
    }
  }
  cout<<k-max<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


const float unit=0.1f;

int main(){
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << 60*(h2-h1)+(m2-m1)-k;
}


Measured memory_bytes: 3648
n, k = map(int, input().split())
pl = list(map(int, input().split()))

ave_pl = []
for i, p in enumerate(pl):
    p_sum = p*(p+1)/2
    if i == 0:
        ave_pl.append(p_sum/p)
    else:
        ave_pl.append(ave_pl[i-1]+(p_sum/p))

ans = 0
if n == k:
    print(ave_pl[-1])
else:
    for i in range(k-1, n):
        if i == 0:
            ans = max(ans, ave_pl[i])
        else:
            ans = max(ans, ave_pl[i]-ave_pl[i-k])
    print(ans)


Measured memory_bytes: 24556