akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int R0, W0, C, R;
	while (true) {
		cin >> R0 >> W0 >> C >> R;
		if (R0 == 0 && W0 == 0 && C == 0 && R == 0)break;
		int ans = (max(C*W0 - R0,0)) / R;
		if ((max(C*W0 - R0,0) % R != 0)) ans++;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3120
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
    int k;
    unsigned long long sum=0;
    cin>> k;
    for (int i=1;i<k+1;i++)
    {
        if((i%3!=0)&&(i%5!=0))
        {
            sum=sum+i;
        }
    }
    cout << sum;
}


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

using namespace std;

const int N = 1e5 + 5;
int ans[N] , k;
vector<pair<int , int> > adj[N];

void dfs (int node , int par , int col) {
    int nxt = 1;
    for (auto &c : adj[node]) {
        if (c.first == par) continue;
        nxt += nxt == col;
        k = max(k , nxt);
        ans[c.second] = nxt;
        dfs(c.first , node , nxt);
        nxt++;
    }
}

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

    int n;
    cin >> n;

    for (int i = 0 ;i < n - 1 ;i++) {
        int u , v;
        cin >> u >> v;
        adj[u].push_back({v , i});
        adj[v].push_back({u , i});
    }

    dfs(1 , 1 , -1);

    cout << k << '\n';
    for (int i = 0 ;i < n - 1 ;i++)
        cout << ans[i] << '\n';
}

Measured memory_bytes: 12484
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3, y3, x4, y4;
  int x = x2 - x1;
  int y = y2 - y1;
  cout <<  x2 - y << " " << y2 + x << " " << x2 - y - x << " " << y2 + x - y << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int X;
	scanf("%d", &X);
	for (int y = 1;; ++y) {
		if (X * y % 360 == 0) {
			printf("%d\n", y);
			return 0;
		}
	}
}


Measured memory_bytes: 3780
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        String s = sc.nextLine();
        _out.println(new StringBuilder().append(s.charAt(0)).append(s.length() - 2).append(s.charAt(s.length() - 1)));
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

int main() {
  int K, S;
  cin >> K >> S;

  int answer = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - (x + y);
      if (0 <= z && z <= K) answer++;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int N;
  cin>>N;
  if(N==22)cout<<"Christmas Eve Eve Eve"<<endl;
  if(N==23)cout<<"Christmas Eve Eve"<<endl;
  if(N==24)cout<<"Christmas Eve"<<endl;
  if(N==25)cout<<"Christmas"<<endl;
}


Measured memory_bytes: 256
//
//AtCoder Beginner Contest 124
//B
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> h(n);
    REP(i, n) cin >> h[i];

    int hNow=0;
    int ans=0;
    REP(i,n){
        if (hNow<=h[i]){
            hNow=h[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

bool g1(int x) {
	return (x <= 7 && x&1) || (x >= 8 && x%2==0);
}

void solve() {
	int x, y; scanf("%d%d", &x, &y);
	if (x == 2 || y == 2) {
		puts("No");
		return;
	}
	if (g1(x)^g1(y)) puts("No");
	else puts("Yes");
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::vector<long double> x, std::vector<std::string> u){
    long double BTC = 380000.0;
    long double ans = 0.0;

    REP(i, N){
        if(u[i] == "JPY") {
            ans += x[i];
        }else{
            ans += BTC * x[i];
        }
    }

    printf("%.9Lf\n", ans);
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long double> x(N);
    std::vector<std::string> u(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%Lf",&x[i]);
        std::cin >> u[i];
    }
    solve(N, std::move(x), std::move(u));
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def divisors(N: int) -> set:
    """ 約数の列挙・個数 """
    from math import sqrt

    # 1とその数はデフォで入れとく
    s = {1, N}
    # 終点はルート切り捨て
    for i in range(2, int(sqrt(N))+1):
        # 割り切れるなら、iとN/iを追加
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s

N, M = MAP()

# 約数列挙
divs = sorted(divisors(M), reverse=1)
# 約数を大きい方から見ていって、N個以上作れるならそれが最善
for div in divs:
    cnt = M // div
    if cnt >= N:
        print(div)
        exit()


Measured memory_bytes: 3188
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> d(n); //d[i]は、絶対値の差がiであるものの個数
    rep(i,n){
        cin >> a[i];
        d[a[i]]++;
    }
    bool ok=true;
    if(n%2==1){
        for(ll i=0;i<=n-1;i+=2){
            if(i==0){
                if(d[i]!=1){
                    ok=false;
                    break;
                }
            }
            else{
                if(d[i]!=2){
                    ok=false;
                    break;
                }
            }
        }
        if(ok){
            ll ans=1;
            rep(i,n/2){
                ans*=2;
                ans%=mod;
            }
            cout << ans << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    else{
        for(ll i=1;i<=n-1;i+=2){
            if(d[i]!=2){
                ok=false;
                break;
            }
        }
        if(ok){
            ll ans=1;
            rep(i,n/2){
                ans*=2;
                ans%=mod;
            }
            cout << ans << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 4844
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> par;
  vector<int> sz;
  ll ans;
  
  UnionFind(int n = 0) {
    if (n > 0) {
      initialize(n);
    }
  }
  
  void initialize(int n) {
    par.resize(n);
    sz.resize(n);
    for(int i = 0; i < n; i++) {
      par[i] = i;
      sz[i] = 1;
    }
    ans = (ll) n * (n -1) / 2;
  }
  
  int find(int x) {
    if (par[x] == x) {
      return x;
    }
    return par[x] = find(par[x]);
  }
  
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return;
    }
    ans -= (ll) sz[x] * sz[y];
    if (sz[x] < sz[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
    }
  }
  
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  vector<ll> ans(M);
  UnionFind uf(N);
  
  for (int i = M - 1; i >= 0; i--) {
    ans[i] = uf.ans;
    uf.unite(A[i], B[i]);
  }
  
  for (int i = 0; i < M; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        sc.close();
        int sum1;
        int sum2;
        int sum3;
        int min;
        // x=yのとき
        if (x == y) {
            sum1 = 2*c*x;
            sum2 = a*x + b*y;
            min = Math.min(sum1,sum2);
            System.out.println(min);
        }
        // x>yのとき
        if (x > y) {
            sum1 = 2*c*x;
            sum2 = 2*c*y + (x-y)*a;
            sum3 = a*x + b*y;
            min = Math.min(sum1,sum2);
            min = Math.min(min,sum3);
            System.out.println(min);
        }
        // x<yのとき
        if (x < y) {
            sum1 = 2*c*y;
            sum2 = 2*c*x + (y-x)*b;
            sum3 = a*x + b*y;
            min = Math.min(sum1,sum2);
            min = Math.min(min,sum3);
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 21460
import sys
sys.setrecursionlimit(10 ** 6)

LI = lambda: list(map(int, input().split()))

N = int(input())
AB = [LI() for _ in range(N - 1)]

link = [[] for _ in range(N)]
children = [[] for _ in range(N)]
w = [1] * N
visit = [False] * N

MOD = 10 ** 9 + 7


def create_link():
    for a, b in AB:
        link[a - 1].append(b - 1)
        link[b - 1].append(a - 1)


def dfs(s):
    visit[s] = True
    for t in link[s]:
        if visit[t]:
            continue
        children[s].append(t)
        dfs(t)
        w[s] += w[t]


def modinv(x):
    return pow(x, MOD - 2, MOD)


def main():
    create_link()
    dfs(0)
    p2 = [None] * (N + 1)
    p2[0] = 1
    for i in range(N):
        p2[i + 1] = 2 * p2[i] % MOD
    
    x = 0
    for i in range(N):
        s = p2[N - w[i]]
        for j in children[i]:
            s = (s + p2[w[j]] - 1) % MOD
        x = (x + p2[N - 1] - s) % MOD
    y = p2[N]

    ans = x * modinv(y) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 221024
#include<stdio.h>

int main()
{
	int height[10];
	int i,j,tmp;
	
	for(i=0;i<10;i++)
	{
		scanf("%d",(height+i));
	}
	
	
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			if(height[i]>height[j])
			{
				tmp=height[i];
				height[i]=height[j];
				height[j]=tmp;
			}
		}
	}
	
	for(i=0;i<3;i++)
	{
		printf("%d\n",height[i]);
	}
	
	return 0;
}

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

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

  string str[n];
  for(int i = 0; i < n; i++){
    cin >> str[i];
  }

  sort(str, str+n);

  string ans;
  for(int i = 0; i < n; i++){
    ans += str[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    L = [A,B,C]
    L.sort()

    print(L[0]+L[1]+L[2]*(2**K))


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <utility>
#define chmin(x, y) x = min(x , y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long int ll;

ll gcd(ll x, ll y){return y ? gcd(y, x%y): x;}

vector<pair<ll, int> > num(ll n) {
  vector<pair<ll, int> > res;
  for (ll i=2;i*i <= n;i++){
    if(n%i) continue;
    res.emplace_back(i, 0);
    	while(n%i == 0){
      	n /= i;
      	res.back().second++;
  		}
  }
  if (n != 1) res.emplace_back(n, 1);
  return res;
}
  
ll N,M;

void input(){
  cin >> N >> M;
}

void solve() {
  input();
  ll a = gcd(N, M);
  auto f = num(a);
  int ans = f.size() + 1;
  cout << ans << endl;
  return;
}
int main(){
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

ll power(ll a, ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}

vector<ll> v[1001];
ll vis[1001];
ll p[1001];
int indeg[1001],outdeg[1001];
bool f;
vector<int> ans;

void dfs(int x)
{
    vis[x]=1;
    // cout<<x<<endl;
    for(auto i:v[x])
    {
        if(f) break;
        if(vis[i]==1)
        {
            ll tmp=x;
            ans.clear();
            while(tmp!=i)
            {
                ans.pb(tmp);
                tmp=p[tmp];
            }
            ans.pb(i);
            map<int,bool> mp;
            for(auto j:ans) 
            {
                mp[j]=true,indeg[j]=outdeg[j]=0;
                // cout<<j<<" ";
            }
            // cout<<endl;
            for(auto j:ans)
            {
                for(auto k:v[j]) if(mp.find(k)!=mp.end()) indeg[k]++,outdeg[j]++;
            }
            bool t=true;
            for(auto j:ans) t&=(indeg[j]==1 && outdeg[j]==1);
            f=t;
        }
        else if(vis[i]==0)
        {
            p[i]=x;
            dfs(i);
        }
    }
    vis[x]=2;
}

int main()
{
    IOS;
    ll n,m;
    cin>>n>>m;
    while(m--)
    {
        ll a,b;
        cin>>a>>b;
        v[a].pb(b);
    }
    memset(vis,0,sizeof vis);
    f=false;
    repf(i,1,n+1)
    {
        if(vis[i]==0) 
        {
            p[i]=-1;
            dfs(i);
        }
    }
    if(f)
    {
        cout<<ans.size()<<endl;
        for(auto i:ans) cout<<i<<endl;
    }
    else cout<<-1<<endl;
    return 0;  
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
   int N,D,X,A[110],eat;
   cin>>N>>D>>X;
   for(int i=0;i<N;i++){
      cin>>A[i];
      int j=0;
      while(j*A[i]+1<=D){
         j++;
      }
      eat+=j;
   }
   cout<<eat+X<<endl;
   return 0;
}

Measured memory_bytes: 256
n, c, k = gets.split.map(&:to_i)
ts = n.times.map { gets.to_i }.sort!.reverse!

ans = 1
base = ts.first
passengers = 1

1.upto(n - 1) do |i|
  if ts[i] + k < base || passengers == c
    ans += 1
    base = ts[i]
    passengers = 1
  else
    passengers += 1
  end
end

puts ans


Measured memory_bytes: 4016
#include<iostream>
#include<cstdio>
#define Abs(x) ((x)<0?-(x):(x))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=10001000;
int n,fl,ans,a[N];
char s[N];
int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	scanf("%d%s",&n,s);
	n-=2;
	FOR(i,0,n) a[i]=Abs(s[i+1]-s[i]);//cerr<<a[i];
	fl=2;
	FOR(i,0,n)if(a[i]==1) fl=1;
	FOR(i,0,n)if(a[i]==fl) ans^=(n&i)==i;
	ans*=fl;
	cout<<ans<<'\n';
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
ll a,b,k;
bool vis[maxn];
int isprime[maxn];
int tot;
void prime()
{
    for(int i=2;i<maxn-2;i++)
    {
        if(!vis[i])
        isprime[++tot]=i;
        for(int j=i*2;j<maxn-2;j+=i)
            vis[j]=true;
    }

}
int x;
int main()
{
    prime();
    cin>>x;
    for(int i=x;i<=maxn;i++)
    {
        if(!vis[i])
        {
            cout<<i<<endl;
            break;
        }
    }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll x,y;cin>>x>>y;
	ll d=abs(abs(x)-abs(y));
	if(x*y>0){
		if(x<y){
			cout<<d<<endl;
		}
		else{
			cout<<d+2<<endl;
		}
	}
	if(x==0){
		if(y>0){
			cout<<d<<endl;
		}
		else{
			cout<<d+1<<endl;
		}
	}
	if(y==0){
		if(x<0){
			cout<<d<<endl;
		}
		else{
			cout<<d+1<<endl;
		}
	}
	if(x*y<0){
		cout<<d+1<<endl;
	}
}

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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int64_t a, b, c, d; cin >> a >> b >> c >> d;
	cout << max({a * c, a * d, b * c, b * d}) << '\n';
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N;cin>>N;
    string C;
    cin>>C;
    int red = 0,white = 0;
    REP(i,N){
        if(C[i] == 'R')red++;
        else white++;
    }
    int ans = 0;
    REP(i,red){
        if(C[i] == 'W')ans++;
    }
    cout<<ans<<endl;
}

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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

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


void solve(long long N, long long M, std::vector<long long> x, std::vector<long long> y, std::vector<long long> z){
  ll ans = 0;
  rep(i,8) {
    vector<ll> v;
    rep(j,N) {
      ll sum = 0;
      if(i&1) sum+=x[j];
      else sum-=x[j];
      if(i&2) sum+=y[j];
      else sum-=y[j];
      if(i&4) sum+=z[j];
      else sum-=z[j];
      v.push_back(sum);
    }
    sort(v.rbegin(), v.rend());
    ll tmp = 0;
    rep(j,M) tmp+=v[j];
    ans = max(ans, tmp);
  }
  std::cout << ans << std::endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    std::vector<long long> z(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        scanf("%lld",&z[i]);
    }
    solve(N, M, std::move(x), std::move(y), std::move(z));
    return 0;
}


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

mt19937_64 llrand((int) chrono::steady_clock::now().time_since_epoch().count());

#define st first
#define nd second
#define pb push_back

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

typedef long long ll;
typedef long double ld;

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

const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

vector<int> adj[N];
int dist[N];
int resp[N];
int n, m, a, b;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  while(m--) {
    cin >> a >> b;
    adj[a].pb(b);
    adj[b].pb(a);
  }

  queue<int> q;
  memset(dist, 63, sizeof dist);
  dist[1] = 0;
  q.push(1);
  while(q.size()) {
    int u = q.front();
    q.pop();

    for(auto v : adj[u]) 
      if(dist[v] == INF) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
  
  }

  for(int i = 2; i <= n; i++) {
    for(auto v : adj[i]) if(dist[v] + 1 == dist[i]) resp[i] = v;
  }

  int ok = 1;
  for(int i = 2; i <= n; i++) if(!resp[i]) ok = 0;

  if(!ok) cout << "No\n";
  else {
    cout << "Yes\n";
    for(int i = 2; i <= n; i++) cout << resp[i] << "\n";
  }
}

Measured memory_bytes: 10868
def find_root(x):
    if parent[x] == x:
        return x
    else:
        return find_root(parent[x])


# x,yの属する集合の併合
def unite(x, y):
    x = find_root(x)
    y = find_root(y)

    if x != y:
        if rank[x] < rank[y]:
            parent[x] = y
            size[y] += size[x]
        else:
            parent[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1


# xとyが同じグループかどうか判定
def same(x, y):
    return find_root(x) == find_root(y)


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

parent = [i for i in range(N)]  # 根
rank = [1] * N  # 深さ
size = [1] * N  # iを根とするグループのサイズ

# 前処理
edge = [[ab[M - 1 - i][0] - 1, ab[M - 1 - i][1] - 1] for i in range(M)]

res = []
for i in range(M):
    a = find_root(edge[i][0])
    b = find_root(edge[i][1])
    if a == b:
        res.append(0)
    else:
        res.append(size[a] * size[b])
        unite(a, b)
ans = 0
for i in range(M):
    ans += res[M - 1 - i]
    print(ans)

Measured memory_bytes: 48436
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010],b[100010];
int MIN(int a,int b){return a<b?a:b;}
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,m,i,a,c;
  scanf("%d %d",&n,&m);
  while(m--){
    scanf("%d %d",&a,&b[R]);
    hin(a);
  }
  c=hout();
  for(i=1;C-1;i++){
    a=c;
    m=b[a];//printf("a:%d %d\n",N[a],m);
    while(C-1&&N[c]<m){
      c=hout();
      m=MIN(m,b[c]);//printf("c:%d %d\n",N[c],m);
    }
    if(N[c]<m)break;
  }
  printf("%d\n",i);
  return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, T; cin >> N >> T;
    int ans = INF;
    REP(i, N)
    {
        int c, t; cin >> c >> t;
        if(t > T) continue;
        ans = min(ans, c);
    }
    if(ans == INF) cout << "TLE" << endl;
    else cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;



int main()
{
    int a1, a2, b1, b2, k;
    int output = 0;
    cin >> a1 >> a2 >> b1 >> b2 >> k;

    int time = (b1 - a1) * 60 + b2 - a2;
    output = time - k;
    cout << output;
    


    return 0;
}


Measured memory_bytes: 3160
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


#a=[int(x) for x in input().split()]
#n=int(input())

def main():
    n,m,xk=[int(x) for x in input().split()]
    books=[ [int(x) for x in input().split()] for _ in range(n)]
    ans=10**8

    for msk in range(2**n):
        cst=0
        bk=[0]*m
        for i in range(n):
            if not msk&1<<i:
                continue
            cst+=books[i][0]
            for i,x in enumerate(books[i][1:]):
                bk[i]+=x
        # print(msk,bk)
        for k in bk:
            if k<xk:
                break
        else:
            # print("True",msk,bk,xk)
            ans=min(ans,cst)

    print(ans if ans<10**8 else -1)

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 68772
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int k,x;
  cin>>k>>x;
  if(500*k >= x){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using Graph=vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;


int main(void)

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

	double a, b;
	cin >> a >> b;

	for (int i = 0; i < 100000; i++)
	{
		int tmp1 = i * 0.08;
		int tmp2 = i * 0.1;
		if (tmp1 == a && tmp2 == b)
		{
			cout << i << endl;
			ret;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

a, b, c = input_nums()

from decimal import *
getcontext().prec = 500

if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
    print('Yes')
else:
    print('No')

Measured memory_bytes: 5076
#include<iostream>
#include<string>
#include<algorithm>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#include<iostream>
#include<fstream>

using namespace std;

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

  n--;

  long long ans;
  ans = (n * (1 + n)) / 2;

  cout << ans << endl;
}



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

int main() {
  int a,b;

  cin >> a >> b;

  if((a*b)%2)
    cout << "Odd\n";
  else
    cout << "Even\n";

  return 0;
}


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

int main() {
    int n, cnt, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i+=2)
    {
        cnt = 0;
        for (int j = 1; j <= i; j+=2)
        {
            if (i % j == 0) cnt++;
        }
        
        if (cnt == 8) ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
bool solve(int N){
	string s_[500];
	rep(i,N) cin>>s_[i];
	bool e[26][26]={};
	rep(i,N-1){
		string s=s_[i],t=s_[i+1];
		int S=s.size(),T=t.size();
		int j=0;
		while(j<S&&j<T&&s[j]==t[j]) j++;
		if(j==S) continue;
		if(j==T) return 0;
		e[s[j]-'a'][t[j]-'a']=1;
	}
	rep(i,26) rep(j,26) rep(k,26) if(e[j][i]&&e[i][k]) e[j][k]=1;
	rep(i,26) if(e[i][i]) return 0;
	return 1;
}
int main(){
	while(true){
		int N;
		cin>>N;
		if(N==0) break;
		if(solve(N)) puts("yes");
		else puts("no");
	}
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
#include<algorithm>
#include <assert.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define ll long long
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pii pair <int, int>
#define pll pair <long long, long long >
#define plp pair <int, pll >
#define pb push_back
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define ll long long 
#define sum(a,b) a=a+b
#define repn(a,b,c) for(int a = b ; a>=c ; a--)
#define mem(a, b) memset(a, (b), sizeof(a))

int  grid[101][101];

int R,C;


int cnt ;

int lol ;

ll a[101*101];


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    cin>>R>>C;

    ll n;
    cin>>n;

    rep(i,1,n) cin>>a[i];

    int dex = 1;



    rep(i,1,R){
      if(i % 2 == 1){
        rep(j,1,C){
          grid[i][j] = dex;
          a[dex]--;
          if(a[dex] == 0){
            dex++;
          }
        }
      }else if(i % 2 == 0){
        repn(j,C,1){
          grid[i][j] = dex;
          a[dex]--;
          if(a[dex] == 0){
            dex++;
          }
        }
      }
    }


    rep(i,1,R){
      rep(j,1,C){
        cout<<grid[i][j]<<" ";
      }
      cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
   int x,y;
   cin>>x>>y;
   int sum=0;
   sum=0;
   if(x<=3)sum+=(3-x+1)*100000;
   if(y<=3)sum+=(3-y+1)*100000;
   if(y==1&&x==1)sum+=400000;
    cout<<sum;
}


Measured memory_bytes: 256
def slove():
    import sys
    import heapq
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    for i in range(len(a)):
        a[i] = a[i] * - 1
    heapq.heapify(a)
    for i in range(m):
        p = heapq.heappop(a)
        p /= 2
        heapq.heappush(a, p)
    t = 0
    for i in range(len(a)):
        t += int(a[i])
    print(-t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 88576
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  string S,T;
  cin>>S>>T;
  string answer;
  int num=0;
  if(T.size()<=S.size()){
    for(int i=S.size()-T.size();i>=0;i--){
      int judge=0;
      for(int j=0;j<T.size();j++){
        if(S[i+j]==T[j]||S[i+j]=='?') judge++;
      }
      if(judge==T.size()){
        answer=S.substr(0,i)+T+S.substr(i+T.size(),S.size()-T.size()-i);
        num++;
        i-=100;
      }
    }
  }
  if(num==0) cout<<"UNRESTORABLE"<<endl;
  else{
    for(int i=0;i<S.size();i++){
      if(answer[i]=='?') answer[i]='a';
    }
    cout<<answer<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl v(n),a(n),b(n);
	rep(i,n){
		cin>>v[i];
		if(i+v[i]<n)a[i+v[i]]++;
		if(i-v[i]>=0)b[i-v[i]]++;
	}
	ll ans=0;
	rep(i,n)ans+=a[i]*b[i];
	puta(ans);
}


Measured memory_bytes: 7928
#include<cstdio>
int x,a,b,c,t;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++)
				if(i*500+j*100+k*50==x)
					t++;
	printf("%d",t);
}

Measured memory_bytes: 888
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var l = readLine()!!
    var whiteOnRight = l.count{it == '.'}
    var blackonLeft = 0
    var a = Int.MAX_VALUE

    for(i in 0 until n){
        if (l[i] == '.') {
            whiteOnRight -= 1
        }
        a = Math.min(whiteOnRight + blackonLeft, a)
        if (l[i] == '#'){
            blackonLeft += 1
        }
    }
    println(a)
}

Measured memory_bytes: 34392
mod = 10**9 + 7

N = int(input())
A = [int(x) for x in input().split()]
S = sum(A) % mod

ans = 0
for i in range(N):
    S -= A[i]
    if S < 0: S += mod

    ans += S * A[i]
    ans %= mod
print(ans)

Measured memory_bytes: 31364
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define INF 100000000
using namespace std;
int keta(int n,int k){return (n/int(pow(10,double(k-1)))) % 10;} //n????????????k??????
ll gcd(ll n,ll m){
	if(n<m){ll a=m;m=n;n=a;}
	ll r=n%m;
	while(r!=0){
		n=m;
		m=r;
		r=n%m;
	}
	return m;
}
ll lcm(ll n,ll m){
	return n*m/gcd(n,m);
}
int main(){
	
	int x[10];
	rep(i,10){
		cin>>x[i];
	}
	sort(x,x+10);
	cout<<x[9]<<endl<<x[8]<<endl<<x[7]<<endl;
}

Measured memory_bytes: 3156
package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		x, _ := strconv.Atoi(buf[1])
		if n == 0 && x == 0 {
			break
		}
		prime_table := make([]int, 1000001)
		prime_table[0] = -1
		prime_table[1] = -1
		for i := 2; i < 1000001; i++ {
			if prime_table[i] != -1 {
				prime_table[i] = 1
				for j := 2*i; j < 1000001; j += i {
					prime_table[j] = -1 // -1 means "not prime"
				}
			}
		}
		dp := make([]int, x+1)
		dp[0] = 1
		menu := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			menu[i], _ = strconv.Atoi(scanner.Text())
		}
		for i := 0; i < n; i++ {
			for j := 0; j <= x; j++ {
				if menu[i] <= j && dp[j-menu[i]] != 0 {
					// log.Println(dp)
					dp[j] = 1
				}
			}
		}
		flag := true
		for j := x; j >= 0; j-- {
			if prime_table[j] == 1 && dp[j] == 1 {
				flag = false
				fmt.Println(j)
				break
			}
		}
		if flag {
			fmt.Println("NA")
		}
	}
}


Measured memory_bytes: 42100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const int N = 200010;
int f[N], g[N], n, h[N][26], c[26], nx[N], ch[N];
string *str[N];
char s[N];
int main()
{
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    fill(c, c + 26, n + 1);
    for (int i = n; i >= 1; i--)
    {
        copy(c, c + 26, h[i]);
        c[s[i] - 'a'] = i;
    }
    copy(c, c + 26, h[0]);
    for (int i = 1; i <= n + 1; i++)
        f[i] = inf;
    //for (int i = 0; i < 26; i++)
    //   printf("%c %d\n", i + 'a', h[0][i]);
    str[0] = new string("");
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j < 26; j++)
        {
            if (f[i] + 1 > f[h[i][j]])
                continue;
            string tmp = *str[i];
            tmp.push_back(j + 'a');
            if (f[i] + 1 == f[h[i][j]] && tmp >= *str[h[i][j]])
                continue;
                
            f[h[i][j]] = f[i] + 1;
            delete str[h[i][j]];
            str[h[i][j]] = new string(tmp);
            g[h[i][j]] = i;
            ch[h[i][j]] = j;
        }
        delete str[i];
    }
    for (int i = n + 1; i != 0; i = g[i])
        nx[g[i]] = i;
    //for (int i = 0; i <= n + 1; i++)
    //    printf("%d %c\n", i, ch[i] + 'a');
    //  for (int i = 0; i <= n; i++)
    //{
    // printf("nx[%d] = %d\n", i, nx[i]);
    //}
    for (int i = 0; i != n + 1; i = nx[i])
        printf("%c", ch[nx[i]] + 'a');
    puts("");
    return 0;
}

Measured memory_bytes: 26028
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, x;
	cin >> n >> x;
	vi a(n);
	for (auto &i : a) cin >> i;
	ll ans = 0;
	FOR(i, 1, n)
	{
		int t = a[i] + a[i - 1] - x;
		if (t > 0)
		{
			ans += t;
			a[i] = max(0ll, a[i] - t);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    Node[] nodes = new Node[N];
    for (int i = 0; i < N; i++) nodes[i] = new Node(i);
    for (int i = 0; i < N - 1; i++) {
      int a = scanner.nextInt() - 1;
      int b = scanner.nextInt() - 1;
      nodes[a].edges.add(nodes[b]);
      nodes[b].edges.add(nodes[a]);
    }

    List<Node> path = findPath(null, nodes[0], nodes[N - 1]);
    Node endWhite = path.get(path.size() / 2 - 1);
    Node endBlack = path.get(path.size() / 2);
    endBlack.edges.remove(endWhite);
    endWhite.edges.remove(endBlack);

    int countBlack = count(null, nodes[0]);
    int countWhite = count(null, nodes[N - 1]);

    if (countBlack > countWhite) {
      System.out.println("Fennec");
    } else {
      System.out.println("Snuke");
    }
  }

  private static List<Node> findPath(Node from, Node node, Node goal) {
    if (node == goal) {
      List<Node> path = new ArrayList<>();
      path.add(node);
      return path;
    }
    for (Node e : node.edges) {
      if (e != from) {
        List<Node> found = findPath(node, e, goal);
        if (found != null) {
          found.add(node);
          return found;
        }
      }
    }
    return null;
  }

  private static int count(Node from, Node node) {
    int count = 1;
    for (Node e : node.edges) if (e != from) count += count(node, e);
    return count;
  }

  static class Node {
    final int id;
    List<Node> edges = new ArrayList<>();

    Node(int id) {
      this.id = id;
    }
  }
}


Measured memory_bytes: 117300