akhauriyash/Code-Regression huggingface dataset:
def e_travel_by_car(INF=float('inf')):
    from copy import deepcopy
    from scipy.sparse.csgraph import floyd_warshall
    N, M, L = [int(i) for i in input().split()]
    Roads = [[int(i) for i in input().split()] for j in range(M)]
    Q = int(input())
    Queries = [[int(i) for i in input().split()] for j in range(Q)]

    graph = [[INF] * N for _ in range(N)]
    for k in range(N):
        graph[k][k] = 0
    fuel = deepcopy(graph)

    for a, b, c in Roads:
        graph[a - 1][b - 1] = graph[b - 1][a - 1] = c
    dist = floyd_warshall(graph)

    for i in range(N):
        for j in range(i):
            fuel[i][j] = fuel[j][i] = int(dist[i][j] <= L)
    fuel = floyd_warshall(fuel)

    ans = [-1 if fuel[s - 1][t - 1] == INF else int(fuel[s - 1][t - 1]) - 1 for s, t in Queries]
    return '\n'.join(map(str, ans))

print(e_travel_by_car())

Measured memory_bytes: 41652
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <assert.h>
typedef int64_t ll;
typedef uint64_t ull;
int acs(const void *a, const void *b){return *(ll*)a - *(ll*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(ll*)b - *(ll*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (200001)
#define MOD (1000000007)

ll a[MAXN];
ll f[MAXN];
int main(void)
{
    ll n,k;
    scanf("%ld %ld",&n,&k);
    for(int i=0;i<n;i++) scanf("%ld",&a[i]);
    qsort(a,n,sizeof(ll),des);
    for(int i=0;i<n;i++) scanf("%ld",&f[i]);
    qsort(f,n,sizeof(ll),acs);

    ll s = 0;
    for(int i=0;i<n;i++) s = max(s,a[i]*f[i]);

    ll l = 0,r = s;
    while(l!=r)
    {
        ll m = (l+r)/2;
        ll nk = 0;
        for(int i=0;i<n;i++) nk += max(0,a[i]-(m/f[i]));
        if(nk<=k)
        {
            r = m;
        }else
        {
            l = m+1;
        }
    }
    
    printf("%ld\n", l);
    return 0;
}


Measured memory_bytes: 4832
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

A, B, N = map(int, input().split())

# m = -1

# for x in range(1, N+1):
#     res = math.floor(A * x / B) - A * math.floor(x / B)
#     print(res)

if B > N:
    x = N
    res = math.floor(A * x / B) - A * math.floor(x / B)
    print(res)
else:
    x = B - 1
    res = math.floor(A * x / B) - A * math.floor(x / B)
    print(res)


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

using namespace std;

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

void solve() {
  int xa, ya, xb, yb;
  cin >> xa >> ya >> xb >> yb;
  int dx = xb - xa;
  int dy = yb - ya;
  cout << (xb - dy) << " " << (yb + dx) << " " << (xa - dy) << " " << (ya + dx) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC087A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, a, b, c;

            x = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            c = (x - a) % b;

            Console.WriteLine(c);

            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<math.h>

int main(void)
{
  int i,j,h,s[10],tmp;

  for(i=0;i<10;i++)
    scanf("%d",&s[i]);

  for(h=0;h<2;h++){
    for(i=0;i<10;i++){
      for(j=0;j<10;j++){
        if(s[i]<s[j]){
          tmp=s[i];
          s[i]=s[j];
          s[j]=tmp;
        }
      }
    }
  }

  printf("%d\n%d\n%d\n",s[9],s[8],s[7]);

  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if (s == u) cout << a - 1 << " " << b << endl;
	else cout << a << " " << b - 1 << endl;
    
    return 0;
}



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

public class Main
{
    static class Node{
        int b = 0;
        int w = 0;
        List<Integer> child;
    }
    static int subsetSum(int[] arr, int target){
        int n = arr.length;
        int m = target + 1;
        boolean[][] dp = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            if (arr[i] > target) continue;
            dp[i][arr[i]] = true;
        }
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (dp[i-1][j]){
                    dp[i][j] = true;
                    if (j + arr[i] <= target){
                        dp[i][j+arr[i]] = true;
                    }
                }
            }
        }
        for (int i = m-1; i >= 0;i--) {
            if (dp[n-1][i]){
                return i;
            }
        }
        return 0;
    }

    static Node[] nodes;
    static int[] X;
    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc= new Scanner(System.in);
        int N = sc.nextInt();
        nodes = new Node[N];
        X = new int[N];
        for (int i = 0; i < N; i++) {
            nodes[i] = new Node();
            nodes[i].child = new ArrayList<>();
        }
        for (int i = 1; i < N; i++) {
            int par = sc.nextInt();
            nodes[par - 1].child.add(i);
        }
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
        }
        System.out.println(recur(0) ? "POSSIBLE": "IMPOSSIBLE");
    }

    public static boolean recur(int nodeIdx){
        Node cur = nodes[nodeIdx];
        if (cur.child == null || cur.child.size() == 0){
            cur.b = 0; cur.w = X[nodeIdx];
            return true;
        }
        for (int i = 0; i < cur.child.size(); i++) {
            if (!recur(cur.child.get(i))) {
                return false;
            }
        }
        int b = 0, w = 0;
        int[] swap = new int[cur.child.size()];
        for (int i = 0; i < cur.child.size(); i++) {
            int black = nodes[cur.child.get(i)].b;
            int white = nodes[cur.child.get(i)].w;
            b += Math.min(white, black);
            w += Math.max(white, black);
            swap[i] = Math.max(white, black) - Math.min(white, black);
        }
        if (b > X[nodeIdx]) {
            return false;
        }
        int sww = subsetSum(swap, X[nodeIdx] - b);
        cur.b = X[nodeIdx];
        cur.w = w - sww;
        return true;
    }

}

Measured memory_bytes: 27864
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    cout << (a-1) * (b-1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<pair<int,int>>a(n);for(int i=0;i<n;i++)cin>>a.at(i).first>>a.at(i).second;
  sort(a.begin(),a.end());
  cout<<a.at(n-1).first+a.at(n-1).second<<endl;
}


Measured memory_bytes: 1152
#! /usr/bin/python3
# ABC044_B
# B - 美しい文字列 / Beautiful Strings
"""
collectionsを使わないタイプ

制約
    1≤|w|≤100
    w は英小文字 (a-z) のみからなる文字列である。
"""

import collections
test_mode = False
use_Counter = False    # collections.Counter を使うかどうか


def judge_0(l):
    """
    collections.Counter を使うタイプ
    奇数会出現する要素があると False を返し、
    全ての要素が偶数回出現すると True を返す。
    """
    broken = False
    count_l = collections.Counter(l)    # l の各要素の出現回数をカウント

    if test_mode:
        print(count_l)

    for i in count_l:
        if count_l[i] % 2 == 1:
            if test_mode:
                print('break')
            broken = True
            break

    return not broken


def judge_1(l):
    """
    collections.Counter を使わないタイプ
    奇数会出現する要素があると False を返し、
    全ての要素が偶数回出現すると True を返す。
    """
    broken = False  # break したら True になるフラグ

    for i in l:
        if test_mode:
            print('{}:'.format(i), l.count(i))
            if l.count(i) % 2 == 1:
                print('break')
        if l.count(i) % 2 == 1:
            broken = True
            break

    return not broken



def main():
    """
    main関数
    """
    w = list(str(input()))  # 文字列をリストに変換
    if use_Counter:
        beautiful = judge_0(w)
    else:
        beautiful = judge_1(w)

    if beautiful:
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
	int h,w,num;
	char al;
	string str;

	scanf("%d %d", &h, &w);

	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			cin >> str;

			if (str == "snuke")
			{
				al = 'A' + j;
				num = i + 1;
			}
		}
	}

	printf("%c%d\n", al,num);

	return 0;
}
	

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#define lli long long int
#define pb push_back
#define ph push
using namespace std;
void A_FIZZ_BUZZ()
{
	int x,y,n; cin>>x>>y>>n;
	for(int i=1;i<=n;i++)
	{
		if(i%x==0 && i%y==0) cout<<"FizzBuzz\n";
		else if(i%x==0) cout<<"Fizz\n";
		else if(i%y==0) cout<<"Buzz\n";
		else cout<<i<<endl;
	}
}
void B_Internet_Provider()
{
	int x,n;cin>>x>>n;
	int t=x*n+x;
	int w=0;
	while(n--)
	{
		int d; cin>>d;
		w+=d;
	}
	cout<<t-w<<endl;
}
void C_TAX()
{
	int a,b,ans=-1; cin>>a>>b;
	for(int i=1;i<=1250;i++)
	{
		if((i*8)/100==a && (i*10)/100==b)
		{
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
}
int main(int argc, char *argv[])
{
	C_TAX();
}

Measured memory_bytes: 3644
N, T = map(int,input().split(' '))
CT = [list(map(int,input().split(' '))) for i in range(N)]

costv = 2000
for i in range(N):
    if CT[i][1]<= T:
        costv = min(costv,CT[i][0])

if costv == 2000:
    print('TLE')
else:
    print(costv)

Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>

double Area(int a,int b,int C){
        return a*b*sin(C*M_PI/180)/2.0;
}

double ThCos(int a,int b,int C){
        return sqrt(a*a+b*b-2*a*b*cos(C*M_PI/180));
}

double Height(int b,int C){
        return b*sin(C*M_PI/180);
}

int main(){
        int a,b,C;
        scanf("%d%d%d",&a,&b,&C);
        printf("%lf\n%lf\n%lf\n",Area(a,b,C),a+b+ThCos(a,b,C),Height(b,C));
        return 0;
}

Measured memory_bytes: 3048
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
	int n = 0;
	cin >> n;
	int a[100] = { 0 };
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = n; i > 1; i--){
		cout << a[i-1] << " ";

	}
	cout <<a[0]<< endl;
	return 0;
}

Measured memory_bytes: 3080
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N, A, B = map(int, raw_input().split())
X = map(int, raw_input().split())

ans = 0
for i in range(N - 1):
    ans += min((X[i + 1] - X[i]) * A, B)

print ans

Measured memory_bytes: 11540
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

vector<vector<ll>> V(1007);
bool C[1007];
bool com;
ll pre[1007];

int main(){
  string S;
  cin >> S;
  cout << S.substr(0,4) << " "  << S.substr(4,8) <<  endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

void test(){
	ll n,k;
	cin>>n>>k;
	ll a[n];
	f(i,n)cin>>a[i];
	for(int i=k;i<n;i++){
		if(a[i]>a[i-k]){
			cout<<"Yes\n";
		}else
			cout<<"No\n";
	}
}

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

const int MAX_N=1<<17;
const ll INF=(1ll<<31)-1;
ll dat[2*MAX_N-1];
int N;
void init(int n_){
    N=1;
    while(N<n_) N*=2;
    rep(i,2*N-1) dat[i]=INF;
}
void update(int k,ll a){
    k+=N-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
}
ll query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return INF;
    if(a<=l&&r<=b) return dat[k];
    else{
        ll vl=query(a,b,k*2+1,l,(l+r)/2);
        ll vr=query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}
int main(){
    int n,q,c,x,y;
    cin>>n>>q;
    init(n);
    rep(i,q){
        cin>>c>>x>>y;
        if(c==0) update(x,y);
        else{
            ll ans;
            ans=query(x,y+1,0,0,N);
            cout<<ans<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5108
#include <iostream>
using namespace std;
int main(){
    int mod0=0,mod2=0;
    int n;
    cin >> n;
    for (int i=0; i<n; i++){
        int x;
        cin >> x;
        if (x%4==2){
            mod2++;
        }else if (x%4==0){
            mod0++;
        }
    }
    if (mod2){
        if (n-mod2-mod0<=mod0){
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }
    else{
        if (n/2<=mod0){
            cout <<"Yes" << endl;
        }else {
            cout <<"No" << endl;
        }
    }
}

    



Measured memory_bytes: 256
import java.util.*


enum class State{
    Occupied, Danger, Safe
}
fun main(args:Array<String>): Unit {
    val (n, m, k, s) = readLine()!!.trim().split(' ').map(String::toInt)
    val (p, q) = readLine()!!.trim().split(' ').map(String::toInt)
    val routes = Array(n){Stack<Int>()}
    val towns = Array(n){State.Safe}
    val queue: Queue<Int> = LinkedList()
    repeat(k){
        val c = readLine()!!.toInt() - 1
        towns[c] = State.Occupied
        queue.add(c)
    }
    repeat(m){
        val (a, b) = readLine()!!.trim().split(' ').map{it.toInt() - 1}
        routes[a].push(b)
        routes[b].push(a)
    }
    repeat(s){
        repeat(queue.size){
            for (next in routes[queue.poll()]){
                if (towns[next] == State.Safe){
                    towns[next] = State.Danger
                    queue.add(next)
                }
            }
        }
    }
    val memo = Array(n){Long.MAX_VALUE}.apply{this[0] = 0}
    val priorityQueue = PriorityQueue<Pair<Long, Int>>(compareBy(Pair<Long, Int>::first)).apply{add(0L to 0)}
    while (priorityQueue.peek().second != n - 1){
        val (cost, town) = priorityQueue.poll()
        if (memo[town] == cost){
            for (next in routes[town]){
                when(towns[next]){
                    State.Safe ->
                        if (memo[next] > cost + p){
                            memo[next] = cost + p
                            priorityQueue.add(memo[next] to next)
                        }
                    State.Danger ->
                        if (memo[next] > cost + q){
                            memo[next] = cost + q
                            priorityQueue.add(memo[next] to next)
                        }
                    State.Occupied -> Unit
                }
            }
        }
    }
    println(priorityQueue.peek().first - if (towns.last() == State.Safe) p else q)
}


Measured memory_bytes: 123328
n = int(input())
s = list(input())
r_c = s[1:n].count('E')
min = r_c
for i in range(1,n):
    if(s[i-1] == 'W'):
        r_c += 1
    if(s[i] == 'E'):
        r_c -=1
    if(min > r_c):
        min = r_c
print(min)

Measured memory_bytes: 8140
#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mod 1000000007
#define modd 998244353
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define ar array
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
lld n,m;
lld arr[300000];
lld pref[300000];
ar<lld,2> cou1[300000],cou2[300000];
string st,tt;
int main()
{
     ios;
     lld TESTS,q,a,s,b,r,l,k,c,p,h,w,d,x,y,z,xs,ys,t;
     TESTS=1;
  // cin>>TESTS;
     while(TESTS--)
     {
         cin>>st>>tt;
         n=st.size();m=tt.size();
         cou1[0][0]=(0);
         cou1[0][1]=(0);
         cou2[0][0]=(0);
         cou2[0][1]=(0);
         rep(i,1,n){
            cou1[i]=cou1[i-1];
            cou1[i][st[i-1]-'A']++;
         }
         rep(i,1,m){
            cou2[i]=cou2[i-1];
            cou2[i][tt[i-1]-'A']++;
         }
         cin>>q;
         while(q--){
            cin>>a>>b>>c>>d;
            //a--;b--;c--;d--;
            x=(cou1[b][0]-cou1[a-1][0]-cou2[d][0]+cou2[c-1][0]);
            y=(cou1[b][1]-cou1[a-1][1]-cou2[d][1]+cou2[c-1][1]);
            //cout<<cou1[b][0]-cou1[a-1][0]-cou2[d][0]+cou2[c-1][0]<<" "<<cou1[b][1]-cou1[a-1][1]-cou2[d][1]+cou2[c-1][1]<<" ";
            a=abs(x);b=abs(y);
            if (x*y<0){((a%3+b%3)%3)?cout<<"NO\n":cout<<"YES\n";}
            else {(a%3==b%3)?cout<<"YES\n":cout<<"NO\n";}
         }
     }
    return 0;
}


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

using namespace std;

#define rep(i, j, k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define all(x) x.begin(), x.end()

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

inline void fileIO(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

template <class T, class S>
inline bool smin(T &a, S b) {
  return (T)b < a ? a = b, 1 : 0;
}
template <class T, class S>
inline bool smax(T &a, S b) {
  return a < (T)b ? a = b, 1 : 0;
}

constexpr int MOD = 924844033;
constexpr int N = 500 + 10;

template <typename T>
inline T mod(T &v) {
  return v = (v % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}

int n, a[N];
int res[N * N];

pii p[N];

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

#ifndef LOCAL
  // fileIO("superposition");
#endif

  cin >> n;
  rep(i, 0, n) {
    p[i].second = i + 1;
    cin >> p[i].first;
  }

  sort(p, p + n);

  int ptr = 1;

  rep(i, 0, n) {
    rep(j, 0, p[i].second - 1) {
      while (res[ptr]) ptr++;
      res[ptr] = p[i].second;
    }
    if (res[p[i].first]) return cout << "No\n", 0;
    res[p[i].first] = p[i].second;
  }

  ptr = n * n;
  reverse(p, p + n);

  rep(i, 0, n) {
    rep(j, 0, (n - p[i].second)) {
      while (res[ptr]) ptr--;
      res[ptr] = p[i].second;
    }
    if (ptr < p[i].first) return cout << "No\n", 0;
  }

  cout << "Yes\n";
  rep(i, 1, n * n + 1) cout << res[i] << ' ';

  return 0;
}

// 1 2 0 1 2

Measured memory_bytes: 2176
n = []
n = gets.split.map(&:to_i)
a = []
a = gets.split.map(&:to_i)
b = []
b = gets.split.map(&:to_i)
c = []
c = gets.split.map(&:to_i)
#a.sort
#b.sort
#c.sort

k=[]
for i in 0..n[0]-1
    for j in 0..n[1]-1
        k.push(a[i]+b[j])
    end
end
k.sort!
#p k
l=[]
for i in 0..[n[-1]-1,k.length-1].min
    for j in 0..n[2]-1
        l.push(k[k.length-1-i]+c[j])
    end
end
#p l
l.sort!
#p l
for i in 0..n[-1]-1
    puts l[l.length-1-i]
end


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

const int INF = 1001001001;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    --x; --y;
    vector<int> ans(n);
    rep(sv,n) {
        vector<int> dist(n, INF);
        queue<int> q;
        auto push = [&] (int v, int d) {
            if (dist[v] != INF) return;
            dist[v] = d;
            q.push(v);
        };
        push(sv,0);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            int d = dist[v];
            if (v-1 >= 0) push(v-1, d+1);
            if (v+1 < n) push(v+1, d+1);
            if (v ==x ) push(y, d+1);
            if (v == y) push(x, d+1);
        }
        rep(i,n) ans[dist[i]]++;
    }

    rep(i,n) ans[i] /= 2;
    for (int i = 1; i < n; ++i) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MAXN = 262144;
const int oo = 1E9;

int n, in[MAXN], rpos[MAXN];
pii tree[2 * MAXN];  // even, odd

void Init(){
  for(int i = 0;i < n;++i){
    tree[MAXN + i] = mp(oo, oo);
    if(i & 1) tree[MAXN + i].se = in[i];
    else tree[MAXN + i].fi = in[i];
  }
  for(int i = MAXN - 1;i > 0;--i){
    tree[i].fi = min(tree[2 * i].fi, tree[2 * i + 1].fi);
    tree[i].se = min(tree[2 * i].se, tree[2 * i + 1].se);
  }
}

pii Get(int l, int r){
  l += MAXN, r += MAXN;

  pii res = tree[l];
  relaxMin(res.fi, tree[r].fi);
  relaxMin(res.se, tree[r].se);

  while(l != r){
    int pl = l >> 1, pr = r >> 1;
    if(pl == pr) break;
    if(2 * pl == l)
      relaxMin(res.fi, tree[l + 1].fi),
      relaxMin(res.se, tree[l + 1].se);
    if(2 * pr + 1 == r)
      relaxMin(res.fi, tree[r - 1].fi),
      relaxMin(res.se, tree[r - 1].se);
    l = pl, r = pr;
  }

  return res;
}

pii Solve(const pii& u){
  int x, y;
  if(u.fi & 1){
    x = Get(u.fi, u.se).se;
    y = Get(rpos[x] + 1, u.se).fi;
  } else {
    x = Get(u.fi, u.se).fi;
    y = Get(rpos[x] + 1, u.se).se;
  }
  return {x, y};
}

int main(){
  scanf("%d", &n);
  for(int i = 0;i < n;++i){
    //in[i] = i + 1;
    scanf("%d", &in[i]);
    rpos[in[i]] = i;
  }

  Init();

  set<pair<pii, pii>> ival;
  ival.insert(mp(Solve(mp(0, n - 1)), mp(0, n - 1)));

  vi res;
  while(!ival.empty()){
    auto cur = *ival.begin();
    ival.erase(cur);

    //cout << cur.fi.fi << " : " << cur.fi.se << " | ";
    //cout << cur.se.fi << " : " << cur.se.se << endl;

    res.pb(cur.fi.fi);
    res.pb(cur.fi.se);

    int x = cur.fi.fi;
    int y = cur.fi.se;
    int px = rpos[x];
    int py = rpos[y];

    //cout << px << ' ' << py << endl;
    //system("pause");

    if(cur.se.fi < px){
      int a = cur.se.fi, b = px - 1;
      ival.insert(mp(Solve(mp(a, b)), mp(a, b)));
    }

    if(px + 1 <= py - 1){
      int a = px + 1, b = py - 1;
      ival.insert(mp(Solve(mp(a, b)), mp(a, b)));
    }

    if(py < cur.se.se){
      int a = py + 1, b = cur.se.se;
      ival.insert(mp(Solve(mp(a, b)), mp(a, b)));
    }
  }

  for(int i = 0;i < sz(res);++i)
    printf("%d%c", res[i], i + 1 == sz(res) ? '\n' : ' ');

  return 0;
}


Measured memory_bytes: 10996
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A = LI()

# A1を正に
a1 = 0
s1 = 0
for i in range(N):
    s1 += A[i]
    if i % 2 == 0:
        if s1 <= 0:
            a1 += 1-s1
            s1 = 1
    else:
        if s1 >= 0:
            a1 += 1+s1
            s1 = -1

# A1を負に
a2 = 0
s2 = 0
for i in range(N):
    s2 += A[i]
    if i % 2 == 1:
        if s2 <= 0:
            a2 += 1-s2
            s2 = 1
    else:
        if s2 >= 0:
            a2 += 1+s2
            s2 = -1

print(min(a1,a2))


Measured memory_bytes: 85472
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long x= sc.nextLong();
		Long y= sc.nextLong();
		int count = 1;
		
		while(x*2 <= y) {
			count++;
			x = x*2;
		}
		System.out.println(count);
		sc.close();

	}

}

Measured memory_bytes: 21844
N = int(input())
xy = [[int(e) for e in input().split()] for _ in range(N)]
if N == 1:
    print(1)
else:
    d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]
    items = list(set(d_list))
    s = 1
    for item in items:
        c = d_list.count(item)
        if c > s:
            s = c
    print(N - s)

Measured memory_bytes: 3444
n = int(input())
pr = list(map(int,input().split()))
#print(pr)
m = int(input())
f = lambda:map(int,input().split())
for i in range(m):
  n, d = f()
  #print(n,d)
  mot = pr[n-1]
  pr[n-1] = d
  print(sum(pr))
  pr[n-1] = mot

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll i, ll z) {
	ll sum = 1;
	for (ll j = max(z, 2LL); j <= i; j++)
		sum = (sum* j) % Mod;
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%Mod;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
struct A {
	int x, y;
};
bool operator<(A a, A b) {
	if (a.y != b.y) return a.y > b.y;
	return a.x > b.x;
}
int n;
A a[300000];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].x >> a[i].y;
	}
	sort(a, a + n);
	priority_queue<int, vector<int>, greater<int>>p;
	priority_queue<int>q;
	//入っていない、入っている
	int ans = 0, sum = 0;
	for (int i = 0; i < n; i++) {
		p.push(a[i].x);
		while (!p.empty() && !q.empty() && p.top() < q.top()) {
			int t = p.top(), y = q.top();
			sum -= y; sum += t;
			p.pop(); q.pop();
			p.push(y);
			q.push(t);
		}
		while (!p.empty() && sum + p.top() <= (ans + 1)*a[i].y) {
			q.push(p.top());
			sum += p.top();
			ans++;
			p.pop();
		}
	}
	cout << ans << endl;
	getchar(); getchar();
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll K;
    cin >> K;
    rep(i, K) cout << "ACL";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N, M;

ll count(vector<ll> &A) {
    ll lx = 0, lt;
    ll n = A.size();
    for(ll i=1; i<=n; i++) {
        lt = A[i]-A[i-1];
        lt = lt*((n-i)*i)%MOD;
        lx = (lx+lt)%MOD;
    }
    return lx;
}

int main() {
    cin >> N >> M;
    vector<ll> X(N), Y(M);
    REP(i, N) cin >> X[i];
    REP(i, M) cin >> Y[i];
    ll ans = count(X)*count(Y)%MOD;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI arccos(-1)
#define rep(i, N) for (int i = 0; i < (N); i++)
#define REP(i, a, N) for (int i = a; i < (N); i++)
#define rrep(i, N, k) for (int i = (N); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

class UnionFind {
private:
    vector<int> data;

public:
    explicit UnionFind(size_t data_size) : data(data_size, -1)  {}

    bool same(size_t x, size_t y) {
        return find(x) == find(y);
    }

    bool unite(size_t x, size_t y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int find(size_t index) {
        if (data[index] < 0) return index;
        else return (data[index] = find(data[index]));
    }

    int size(size_t index) {
        return (-data[find(index)]);
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M), B(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    auto data = UnionFind(N);

    ll temp = 0;
    vector<ll> ans(M, 0);
    for (int i = M - 1; i >= 0; i--) {
        ans[i] = N * (N - 1) / 2 - temp;
        if (data.find(A[i]) != data.find(B[i])) {
            temp += data.size(A[i]) * data.size(B[i]);
            data.unite(A[i], B[i]);
        }
    }
    for (auto now : ans) cout << now << endl;
}


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

int main() {
  int n,buf,look;
  cin >> n;
  int a[n];
  for (int i=0;i<n;i++) {
    cin >> buf;
    a[i]=buf;
  }
  bool flag=true;
  
  for (int i=n-1;i>=0;i--) {
    if (i==n-1) {
      look=a[i]+1;
      continue;
    }
    if (a[i]<look-1) look=a[i]+1;
    else if (a[i]==look-1) look=a[i]+1;
    else if (a[i]==look) continue;
    else {
      flag=false;
      break;
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long x;
  cin>>x;
  while(1){
    bool ok=true;
    for(int i=2;i<x;i++){
      if(x%i==0){
        ok=false;
        break;
      }
    }
    if(ok)break;
    x++;
  }
  cout<<x<<endl;
  return 0;
}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner reader=new Scanner(System.in);
	
		int a= reader.nextInt();
		int b= reader.nextInt();
		int c= reader.nextInt();
		int t=a+b+c;
		int tab[]= {a,b,c};
		Arrays.sort(tab);
	   if (tab[0]+tab[1]==tab[2]) {
		   System.out.print("Yes");
	   }
	   else {
		   System.out.print("No");
	   }
		
		
	}
	
	

}

Measured memory_bytes: 21972
#include <iostream>

using namespace std;

int main()
{
    int w=0,flag=0;
    char a;

    for(int i=1; i<=3; i++)
    {
        cin >> a;
        if(a!='0' && a!='1')
        {
            flag=1;
            continue;
        }
        if(a=='1')
        {
            w=w+1;
        }

    }
    if(flag==0)
    {
        cout << w;
    }

    return 0;
}


Measured memory_bytes: 256
# WIP
import sys
input = sys.stdin.readline

n, m = map(int, input().split())

py_list = \
    [list(map(int, input().split()))+[i] for i, m in enumerate(range(m))]
py_list.sort(key=lambda x: x[1])

cursor_p = 1
currents = [0] * n
city = None
addresses = []
for py in py_list:
    p = py[0]
    y = py[1]
    idx = py[2]

    if p == cursor_p:
        currents[cursor_p - 1] += 1
    else:
        cursor_p = p
        currents[cursor_p - 1] += 1
    city = str(currents[cursor_p - 1]).zfill(6)
    pref = str(cursor_p).zfill(6)

    addresses.append((idx, pref + city))

addresses.sort(key=lambda x: x[0])

for address in addresses:
    print(address[1])


Measured memory_bytes: 39052
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int64_t N, P;
    string S;
    cin >> N >> P >> S;
    vector<int64_t> dp(N);
    if (P == 2){
        int64_t ans = 0;
        for (int i = 0; i < N; i++){
            if ((S.at(N - i - 1) - '0') % 2 == 0){
                ans += N - i;
            }
        }
        cout << ans << endl;
        return 0;
    }
    if (P == 5){
        int64_t ans = 0;
        for (int i = 0; i < N; i++){
            if ((S.at(N - i - 1) - '0') % 5 == 0){
                ans += N - i;
            }
        }
        cout << ans << endl;
        return 0;
    }
    
    int64_t a = S.at(N - 1) - '0';
    int64_t pmod = 1;

    map<int64_t, int64_t> A;

    for (int i = 0; i < N; i++){
        A[a % P]++;
        a %= P;
        if (i != N - 1){
            pmod *= 10;
            pmod %= P;
            a += pmod * (S.at(N - i - 2) - '0');
        }
    }
    
    int64_t ans = 0;
    for (auto t : A){
        ans += (t.second - 1) * t.second / 2;
        if (t.first == 0){
            ans += t.second;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2564
n = int(input())
*a, = map(int, input().split())
set_a = set(a)
if 0 in set_a:
  print(0)
  exit()
  
res = 1
for elem in a:
  if elem == 0:
    print(0)
    exit()
    
  res *= elem
  
  if res > 10 ** 18:
    print(-1)
    exit()
print(res)

Measured memory_bytes: 21740
MOD = 1000000007

N = parse(Int, readline())
S = []

s1 = readline()
s2 = readline()

i = 1

while i <= N
    if s1[i] == s2[i]
        push!(S,1)
        global i += 1
    else
        push!(S,2)
        global i += 2
    end
end

ans = 1

if S[1] == 1
    global ans = 3
else
    global ans = 6
end

for i in 2:length(S)
    if S[i - 1] == 1 && S[i] == 1
        global ans *= 2
    elseif S[i - 1] == 1 && S[i] == 2
        global ans *= 2
    elseif S[i - 1] == 2 && S[i] == 1
        global ans *= 1
    elseif S[i - 1] == 2 && S[i] == 2
        global ans *= 3
    end
    ans%=MOD
end

println(ans)

Measured memory_bytes: 110368
alist=[]
clist=[0]*9
for i in range(3):
    aalist = list(map(int, input().split()))
    for aal in aalist:
        alist.append(aal)

n=int(input())
blist=[]
for i in range(n):
    b=int(input())
    if b in alist:
        numb=alist.index(b)
        clist[numb]=1

#print(clist)

answer=0
if clist[0]==1 and clist[1]==1 and clist[2]==1:
    answer=1
if clist[3]==1 and clist[4]==1 and clist[5]==1:
    answer=1
if clist[6]==1 and clist[7]==1 and clist[8]==1:
    answer=1
if clist[0]==1 and clist[3]==1 and clist[6]==1:
    answer=1
if clist[1]==1 and clist[4]==1 and clist[7]==1:
    answer=1
if clist[2]==1 and clist[5]==1 and clist[8]==1:
    answer=1
if clist[0]==1 and clist[4]==1 and clist[8]==1:
    answer=1
if clist[2]==1 and clist[4]==1 and clist[6]==1:
    answer=1

if answer==1:
    print("Yes")
else:
    print("No")

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

long long n, k;

int main ()
{
	cin >> n >> k;
	long long ans = 0;
	long long l1 = n / k;
	ans += l1 * l1 * l1;
	if (k % 2 == 0 && n - k / 2 >= 0)
	{
		long long l2 = (n - k / 2) / k + 1;
		ans += l2 * l2 * l2;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  lli a, b, c, k;
  while (scanf("%lld %lld %lld %lld", &a, &b, &c, &k) != EOF)
  {
    lli ans = min(a, k);
    k -= a;
    k -= b;
    if (k > 0) ans -= min(c, k);
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3816
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    int K;
    int c{};
    cin>>N>>K;
    for(int i=0;i<N;i++){
        int n;
        cin>>n;
        if(n>=K){
            c++;
        }
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;
template<typename T> void test(vector<T> v){for(int i=0;i<v.size();i++){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

int main(){
    int n;
    cin>>n;
    int ans=0;
    string s; cin>>s;
    rep(p,0,n){
        string t;
        cin>>t;
        rep(i,0,t.size()){ //見始める位置
            rep(k,0,50){ //幾つの間隔で見るか
                bool f=true;
                rep(j,0,s.size()){ //いざ検証
                    if(i+j*k>=t.size()){
                        f=false;
                        break;
                    }
                    if(s[j]!=t[i+j*k])f=false;
                }
                if(f){
                    ans++;
                    goto A;
                }
            }
        }
        A:;
    }
    cout<<ans<<endl;
    
    return 0;
}


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

using namespace std;

typedef long long llint;

const int MAXN = 2005;
const int MOD = 1000000007;

llint n, m, k, cnt = 1;
string s[MAXN];
llint p, a1, b1, a2, b2, a, b;
llint r[2][2][200];

void precompute () {
    for (int i=0; i<n; i++) {
        for (int j=0; j<m-1; j++) {
            if (s[i][j] == '#' && s[i][j+1] == '#') a1++;
        }
        if (0 < m-1 && s[i][0] == '#' && s[i][m-1] == '#') b1++;
    }
    for (int i=0; i<n-1; i++) {
        for (int j=0; j<m; j++) {
            if (s[i][j] == '#' && s[i+1][j] == '#') a2++;
        }
    }
    for (int i=0; i<m; i++) {
        if (0 < n-1 && s[0][i] == '#' && s[n-1][i] == '#') b2++;
    }
}

void mul (int x, int y, int z) {
    for (int i=0; i<2; i++) {
        for (int j=0; j<2; j++) {
            llint res = 0;
            for (int h=0; h<2; h++) {
                res = (res + r[i][h][x] * r[h][j][y]) % MOD;
            }
            r[i][j][z] = res;
        }
    }
}

int pot (llint e) {
    if (e == 0) return 0;
    if (e == 1) return 1;
    int t = pot(e / 2);
    cnt++;
    mul(t, t, cnt);
    if (e & 1) {
        cnt++;
        mul(cnt - 1, 1, cnt);
    }
    return cnt;
}

int main () {
    cin >> n >> m >> k;
    if (k == 0) {
        cout << 1;
        return 0;
    }
    for (int i=0; i<n; i++) {
        cin >> s[i];
        for (int j=0; j<m; j++) p += (s[i][j] == '#');
    }
    precompute();
    if (b1 > 0 && b2 > 0) {
        cout << 1;
        return 0;
    } else if (b1 == 0 && b2 == 0) {
        k--;
        llint res = 1;
        while (k > 0) {
            if (k & 1) res = (res * p) % MOD;
            p = p * p % MOD;
            k /= 2;
        }
        cout << res;
        return 0;
    } else {
        if (b2 == 0) {
            a = a1; b = b1;
        } else {
            a = a2; b = b2;
        }
    }
    r[0][0][0] = r[1][1][0] = 1;
    r[0][0][1] = p; r[0][1][1] = MOD - a; r[1][1][1] = b;
    int ind = pot(k-1);
    cout << (r[0][0][ind] + r[0][1][ind]) % MOD;
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    int curt = 0, curx = 0, cury = 0;
    for (int i = 0; i < n; ++i) {
        int t, x, y;
        cin >> t >> x >> y;
        int d = abs(x - curx) + abs(y - cury);
        int dt = t - curt;

        curt = t; curx = x; cury = y;
        if (d <= dt && d % 2 == dt % 2) continue;

        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long

ll a,b,n;
ll x;

int main()
{
	cin>>a>>b>>n;
	if(n<b) x=n;
	else x=b-1;
	cout<<floor((double)a*(double(x)/b-floor(double(x)/b)))<<endl;
	return 0;
}


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

string rev(string str) {
  reverse(str.begin(), str.end());
  return str;
}

bool evaluate(string str) {
  if (str != rev(str)) return false;
  int half = (str.size() - 1) / 2;

  string f = str.substr(0, half);
  if (f != rev(f)) return false;

  string s = str.substr(half + 1);
  if (s != rev(s)) return false;
  return true;
}

int main() {
  string s;
  cin >> s;
  string ans = evaluate(s) ? "Yes" : "No";
  cout << ans << endl;
}


Measured memory_bytes: 3648
n,d = map(int,input().split())
x_list =[]
for _ in range(n):
    x_list.append(list(map(float,input().split())))

def squares(a,b):
    return (a-b)**2

count = 0
for i in range(n):
    for j in range(i+1,n):
        total = 0
        for x in range(d):
            total = total + squares(x_list[i][x],x_list[j][x])
        if ((total)**(1/2)).is_integer():
            count = count +1

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define REP(i,n) for(int i=0;i<n;++i)
#define ll long long
#define ull unsigned long long
#define pb push_back
#define all(a) (a).begin(),(a).end()

using namespace std;
const long long int INF = 1ll<<60;

int binarySearch(ull array[], int s, int e, ll elem) {
  if(array[(s + e) / 2] == elem) {
    return ((s + e) / 2);
  } else if(s == e) {
    if(array[s] > elem) {
      return (s - 1);
    } else {
      return s;
    }
  } else if(array[(s + e) / 2] > elem) {
    return binarySearch(array, s, ((s + e) / 2) - 1, elem);
  } else {
    return binarySearch(array, ((s + e) / 2) + 1, e, elem);
  }
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a, b, q;
  ll s[100002], t[100002], x;
  ll d[8];
  cin >> a >> b >> q;
  s[0] = -INF;
  s[a + 1] = INF;
  REP(i, a) {
    cin >> s[i + 1];
  }
  t[0] = -INF;
  t[b + 1] = INF;
  REP(i, b) {
    cin >> t[i + 1];
  }
  REP(i, q) {
    cin >> x;
    ll* u = lower_bound(s, s + a + 2, x);
    ll* v = lower_bound(t, t + b + 2, x);
    d[0] = x - min(*(u - 1), *(v - 1));
    d[1] = x - *(u - 1) + *v - *(u - 1);
    d[4] = *v - x + *v - *(u - 1);
    d[2] = x - *(v - 1) + *u - *(v - 1);
    d[5] = *u - x + *u - *(v - 1);
    d[3] = max(*v, *u) - x;
    ll mini = d[5];
    REP(j, 5) {
      mini = min(mini, d[j]);
    }

    cout << mini << endl;
  }

  return 0;
}


Measured memory_bytes: 2944