akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
//#define int ll
#define pb push_back
#define __bp __builtin_popcount
using vint = vector<int>;
using pii = pair<int,int>;
using pdd = pair<ld,ld>;
using vpii = vector<pii>;
#define F first
#define S second
const int N = 2e5+5;//(1 << 18) + 5;
//const ll inf = 1e18+7;
const int Inf = 1e9+7;
const int Mod = 1e9+7;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//	freopen("sweets.in", "r", stdin);
//	freopen("sweets.out", "w", stdout);
//	cout << setprecision(2) << fixed;
}

int n, a[N];

signed main()
{
	io();
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	ll x = 1000;
	for (int i = 0; i < n - 1; ++i)
	{
		if (a[i] < a[i + 1])
		{
			x = x % a[i] + (x / a[i]) * a[i + 1];
		}
	}
	cout << x;
}

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

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    // for(int i = 0; i < n - 2; i++){
    //     if(a[i] ^ a[i + 1] ^ a[i + 2]){
    //         cout << "No" << endl;
    //         return 0;
    //     }
    // }
    // if(a[n - 2] ^ a[n - 1] ^ a[0] || a[n - 1] ^ a[0] ^ a[1]){
    //     cout << "No" << endl;
    //     return 0;
    // }

    long long xo = 0;
    for(auto x : a){
        xo ^= x;
    }

    string ans = "Yes";
    if(xo){
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define maxn 1001000
char s[2020];

int main(){
	int n;
	scanf("%d",&n);
	n--;
	long long ans = 0;
	for(int i = 1;i<=n;i++) {
		ans += n/i;
	}
	printf("%lld\n",ans);
}

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

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int last = n%10;
		if (last == 1 || last == 3 || last == 7 || last ==9) {
			int wei = String.valueOf(n).length();
			StringBuilder big = new StringBuilder();
			for (int i = 0; i < wei; i++) {
				big.append("7");
			}
			int yu = tenMod(big.toString(), n);
			for(int i = wei;i<1000000;i++) {
				if (yu == 0) {
					System.out.println(i);
					return;
				}
				yu = (yu*10+7)%n;
			}
		} else {
			System.out.println(-1);
		}
	}

	public static int tenMod(String tenString, int mod) {
		if (mod == 0) {
			return -1;
		}
		int temp = 0;
		for (int i = 0; i < tenString.length(); i++) {
			temp = temp % mod;
			temp = (temp * 10) + Integer.valueOf(String.valueOf(tenString.charAt(i)));
		}
		return temp % mod;
	}

}


Measured memory_bytes: 35672
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            int n = scanner.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = scanner.nextInt();
            }
            int q = scanner.nextInt();
            for (int i = 0; i < q; i++) {
                int k = scanner.nextInt();
                int findPosition = binarySearch(a, k, n);
                System.out.println(findPosition);
            }

        } catch (Exception e) {

        } finally {

        }

    }

    public static int binarySearch(int[] a, int q, int n) {
        int start = 0;
        int end = a.length-1;
       
        while (start <= end) {
            int midpoint = (start + end) / 2;
            if (a[midpoint] >= q) {
                end = midpoint - 1;
            } else {
                start = midpoint + 1;
            }

        }
      
        return start;
    }
}




Measured memory_bytes: 107960
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define modP 1000000007
#define MAX_N 200002

using namespace std;
typedef long long int ll;
ll ifac[MAX_N];
ll fac[MAX_N];

ll myPower(ll x,ll n){
	if(n == 0) return 1;
	if( n % 2 == 0){
		return myPower(x*x%modP,n/2);
	}else{
		return myPower(x,n-1)*x % modP;
	}
}

ll comb(ll a,ll b){
	if(a == 0 && b == 0) return 1;
	if( a < b || a < 0) return 0;
	ll tmp = ifac[a-b]*ifac[b]%modP;
	return tmp * fac[a]%modP;
}

void combInit(){
	fac[0] = 1;
	ifac[0] = 1;
	for(ll i = 0; i < MAX_N; i++){
		fac[i+1] = fac[i]*(i+1) % modP;
		ifac[i+1] = ifac[i]*myPower(i+1,modP - 2) % modP;
	}
}

int main(){
	ll N,K;
	cin>>N>>K;
	ll ans = 0;
	for(ll i = K; i <= N+1; i++){
		ll minSum = i*(i-1)/2;
		ll right = N;
		ll left = (N-i+1);
		ll maxSum = (right + left)*i/2;
		ans += maxSum - minSum + 1;
		ans = ans % modP;
	}
	cout<<ans<<endl;
	return 0;
}


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

def floor_sum(n, m, a, b):
    ans = 0
    if a >= m:
        ans += (n-1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ans += b * (b // m)
        b %= m
    
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return ans
    ans += (n - (x_max + a - 1) // a) * y_max
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ans

def main():
    t = int(input())
    for i in range(t):
        n, m, a, b =map(int, input().split())
        res = floor_sum(n, m, a, b)
        print(res)

    
if __name__ == "__main__":
    main()



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

using namespace std;

#define N 100003

long long p[N], r[N];
struct TE
{
    int ele, id;

    bool operator < (const TE &h) const
    {
        if (ele != h.ele) return ele > h.ele;
        return id < h.id;
    }
} a[N];
int n;

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i=1; i<=n; i++)
    {
        cin >> a[i].ele;
        a[i].id = i;
    }
    sort (a+1, a+n+1);
    int mi = N;
    for (int i=1; i<=n; i++)
    {
        mi = min(mi, a[i].id);
        r[mi] += (a[i].ele - a[i+1].ele) * 1LL * i;
    }
    for (int i=1; i<=n; i++) cout << r[i] << endl;
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int gcd(int &a, int &b) {
	if (b == 0) return a;
	int x = a % b;
	return gcd(b, x);
}

int main() {
	int k; cin >> k;
	int ans = 0;

	vector<int> gab(0);
	for (int a = 1; a <= k; a++) {
		for (int b = 1; b <= k; b++) {
			for (int c = 1; c <= k; c++) {
				int x = gcd(a, b);
				int y = gcd(x, c);
				ans += y;
			}
		}
	}

	dunk(ans);
	return 0;
}


Measured memory_bytes: 3624
k, n = map(int, input().split())
an = list(map(int, input().split()))

s = 0
save = 0
start = 0
for i, a in enumerate(an):
  term = a - start
  if term > save:
    save = term
    s = i
  start = a

term = (k - an[-1]) + an[0]
if term > save:
  save = term
  s = 0

print(k-save)

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

int main() {
    string c;
    cin >> c;
    if(c == "a" || c == "i" || c == "u" || c == "e" || c == "o" ){
    cout << "vowel"<<endl;
    }
    else{
    cout << "consonant" <<endl;
    }

}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def solve(A,B,C,D,E=3**30):
    # 大きさEの穴まで考慮
    if not E:
        return abs(A-C) + abs(B-D)
    a = A//E
    b = B//E
    c = C//E
    d = D//E
    if a != c and b != d:
        return abs(A-C) + abs(B-D)
    if a == c and b == d:
        return solve(A,B,C,D,E//3)
    if b == d and a != c:
        A,B = B,A
        a,b = b,a
        C,D = D,C
        c,d = d,c
    if a == c and b != d:
        if a % 3 != 1:
            return solve(A,B,C,D,E//3)
        if abs(b-d) == 1:
            return solve(A,B,C,D,E//3)
        if B > D:
            A,B,C,D = C,D,A,B
            a,b,c,d = c,d,a,b
        x1 = E * a - 1
        y1 = E * (b+1) - 1
        y2 = E * d
        dist1 = abs(x1-A) + abs(y1-B) + abs(y1-y2) + abs(x1-C) + abs(y2-D)
        x1 = E * (a+1)
        y1 = E * (b+1) - 1
        y2 = E * d
        dist2 = abs(x1-A) + abs(y1-B) + abs(y1-y2) + abs(x1-C) + abs(y2-D)
        return min(dist1, dist2)

solve(2,1,3,1)

N = int(readline())
m = map(int,read().split())
for A,B,C,D in zip(m,m,m,m):
    print(solve(A-1,B-1,C-1,D-1,3**30))



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

int main(){
  int D; cin>>D;
  string r = "Christmas";
  REP(i,25-D){ r += " Eve";}
  cout << r <<"\n";
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MAX 100
#define MIN 1
#define MID

int main(void){
 int a,b,array[MAX],x,y,z;
//double x,y;
char c;

scanf("%d %d %d",&x,&y,&z);
printf("\n");
int tnf=0,trn=0;
tnf=x;
x=y;
y=tnf;
trn=x;
x=z;
z=trn;
printf("%d %d %d",x,y,z);


exit(0);
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int INF=1001001001;
int main() {
    long long N, K;
    cin >> N >> K;
    
    double res = 0.0;
    for (long long n = 1; n <= N; ++n) {
        double tmp = 1.0;
        long long nn = n;
        while (nn < K) nn *= 2, tmp /= 2.0;
        res += tmp;
    }
    res /= N;
    cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 256
S = input()
T = input()
rec = []
for i in range(len(S)):
    flag = True
    Z = S
    for j in range(len(T)):
        if Z[i] == T[j]:
            if len(S)-i < len(T):
                flag = False
                break
            for e in range(i - j):
                if Z[e] == "?":
                    Z = Z.replace("?", "a", 1)
            for k in range(len(T)):
                if Z[i + k - j] == T[k]:
                    continue
                elif Z[i + k - j] == "?":
                    Z = Z.replace("?", T[k], 1)
                else:
                    flag = False
            if flag:
                Z = Z.replace("?", "a")
                rec.append(Z)
        elif Z[i] == "?":
            if len(S)-i < len(T):
                flag = False
                break
            for e in range(i):
                if Z[e] == "?":
                    Z = Z.replace("?", "a", 1)
            for k in range(len(T)):
                if Z[i + k] == T[k]:
                    continue
                elif Z[i + k] == "?":
                    Z = Z.replace("?", T[k], 1)
                else:
                    flag = False
            if flag:
                Z = Z.replace("?", "a")
                rec.append(Z)

if rec == []:
    print("UNRESTORABLE")
else:
    print(rec[-1])

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<set>
#include<map>
//#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long int li;
struct graph{
  int order;
  int comp;
  vector<vector<int>> adj;
  vector<vector<int>> readj;
  vector<int> deg;
  graph(int n,int m,int origin=1);
  void print(string str="");
};

int main(){
  if(df) printf("*debug mode*\n");
  int n,m; cin >>n >>m;
  graph g(n,n+m-1);
  if(df)g.print("graph");
  map<int,int> dict;
  vector<int> que,par(n,-1);
  rep(v,n){
    if(g.deg.at(v)==0)que.push_back(v);
  }
  int i=0;
  if(df){
    for(int x:que)printf("%d ",x);
    printf(":que\n");
  }
  while(not que.empty()){
    auto x=*que.rbegin();
    que.pop_back();
    dict[x]=i++;
    for(int v:g.adj.at(x)){
      if(df)printf("deg%d->",v);
      if(--g.deg.at(v)==0) que.push_back(v);
      if(df)printf("%d\n",g.deg.at(v));
    }
  }
  if(df){
    for(auto x:dict) printf("[%d]%d ",x.first,x.second);
    printf(":dict\n");
  }

  rep(i,n){
    if(g.readj.at(i).size()==0){
      continue;
    }
    int m=g.readj[i].at(0);
    for(int v:g.readj.at(i)){
      if(dict[m]<dict[v])m=v;
    }
    par.at(i)=m;
  }
  rep(i,n) printf("%d\n",par.at(i)+1);
  
}

graph::graph(int n,int m,int origin){
  order=n;
  adj.resize(n);
  readj.resize(n);
  deg.resize(n,0);
  rep(i,m){
    int u,v;cin >>u >>v; u-=origin; v-=origin;
    adj.at(u).push_back(v);
    readj.at(v).push_back(u);
    deg.at(v)++;
    if(df){printf("%d %d",u,v); cout<<endl;}
  }
}
void graph::print(string str){
  if(str!="") cout << str << endl;
  rep(i,order){
    printf("%2d(%d): ",i,deg.at(i));
    for(int v:adj.at(i)) cout << v << " ";
    printf("\n");
  }
}


/// confirm df==0 ///


Measured memory_bytes: 17280
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int h,w,res,book[110][110];
char s[110][110];
struct Node
{
    int x,y,w;
};
const int step[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
signed main()
{
    h=read(), w=read();
    for(ri int i=1;i<=h;i++)
    {
        scanf("%s",s[i]+1);
        for(ri int j=1;j<=w;j++) if(s[i][j]=='.') res++;
    }
    queue<Node> Q;
    Q.push((Node){1,1,0});
    book[1][1]=1;
    while(!Q.empty())
    {
        Node now=Q.front(); Q.pop();
        int x=now.x, y=now.y, t=now.w;
        if(x==h&&y==w) { printf("%lld\n",res-t-1); return 0; }
        for(ri int i=0;i<4;i++)
        {
            int u=x+step[i][0];
            int v=y+step[i][1];
            if(u<1||u>h||v<1||v>w||book[u][v]||s[u][v]=='#') continue;
            book[u][v]=1;
            Q.push((Node){u,v,t+1});
        }
    }
    puts("-1");
    return 0;
}

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

int main(){
  int A,B,K;
  deque<int>q;
  cin>>A>>B>>K;
  if(B-A+1<=2*K){
    for(int t=A;t<=B;t++){
      cout<<t<<"\n";
    }
    return 0;
  }

  for(int t=0;t<K;t++){
    int temp1=A+t;
    cout<<temp1<<"\n";
  }
  for(int t=K-1;0<=t;t--){
    int temp2=B-t;
    cout<<temp2<<"\n";
  }
  return 0;
}


Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    x,y = map(int,ipt().split())
    if x < y:
        ans = y-x
    else:
        ans = x-y+2
    if x*y < 0:
        ans = min(ans,abs(abs(x)-abs(y))+1)
    elif x == 0:
        if y < 0:
            ans = abs(y)+1
    elif y == 0:
        if x > 0:
            ans = x+1
    print(ans)



    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 38380
#include<bits/stdc++.h>
#define ll long long
#define MAX 1e9+7
#define i(a) cin>>a
#define in(a,b) cin>>a>>b
#define o(a) cout<<a
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loop1(i,a,b) for(ll i=a;i<=b;i++)
#define v(a) vector<ll>a
#define mp(a,b) make_pair(a,b)
using namespace std;
int main()
{
    ll a,b,k;
    cin>>a>>b;
    k = (a+b)/2;
    if((a+b)%2==0)
    {
        cout<<k;
    }
    else
    cout<<"IMPOSSIBLE";

}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] line = s.nextLine().split(" ");
		int sum = Integer.parseInt(line[0]);
		int coinC = Integer.parseInt(line[1]);
		line = s.nextLine().split(" ");
		int[] input = new int[coinC];
		for(int i=0 ; i<coinC ; i++) {
			input[i] = Integer.parseInt(line[i]);
		}
		System.out.println(solve(sum, input));
	}

	public static int solve(int sum, int[] input) {
		int[][] result = new int[sum+1][input.length+1];
		for(int j=1 ; j<=sum ; j++)
			result[j][0] = Integer.MAX_VALUE;
		for(int i=1 ; i<=input.length ; i++) {
			for(int j=1 ; j<=sum ; j++) {
				if(j/input[i-1] == 0) {
					result[j][i] = result[j][i-1];
				}else {
					result[j][i] = Math.min(result[j][i-1], result[j-input[i-1]][i] + 1);
				}
			}
		}
		return result[sum][input.length];
	}
}

Measured memory_bytes: 26932
#include<bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N=2e5+5;

int a[N],b[N];
int n;
i64 m;

bool chk(i64 t){
	i64 s=0;
	int i;
	for(i=1;i<=n;i++)
		if(1ll*a[i]*b[n+1-i]>t)
			s+=a[i]-t/b[n+1-i];
	return s<=m;
}

i64 bnsr(i64 l,i64 r){
	i64 mid;
	while(l<=r){
		mid=(l+r)>>1;
		if(chk(mid))r=mid-1;
		else l=mid+1;
	}
	return l;
}

int main()
{
	int i;
	scanf("%d%lld",&n,&m);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<=n;i++)scanf("%d",&b[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	printf("%lld",bnsr(0,1ll*b[n]*a[n]));
	return 0;
}

Measured memory_bytes: 1792
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
a = Counter(A)

ak = list(a.keys())
av = list(a.values())

if N % 3 != 0:
    if a[0] == N:
        print('Yes')
    else:
        print('No')
elif len(ak) == 3:
    if ak[0] ^ ak[1] ^ ak[2] == 0 and av[0] == av[1] == av[2]:
        print('Yes')
    else:
        print('No')
elif len(ak) == 2:
    if 0 in ak:
        if a[0] == N // 3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(ak) == 1:
    if 0 in ak:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	ll x, y; cin >> x >> y;
	ll g = y / x, v = 0;
	
	while (g) {
		g >>= 1, v++;
	}
	cout << v << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define s(n) ((n) * (n + 1) / 2)
using namespace std;
using llong = long long;

const llong mod = (llong)(1e9) + 7;
llong n, k;
llong sum;

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

    llong a = 0;
    llong b = n;
    for (llong i = 0; i < k; i++) {
        a += b;
        b--;
    }
    for (llong i = k; i <= n; i++) {
        sum += a - s(i - 1) + 1;
        sum %= mod;
        a += b;
        b--;
    }
    sum += 1;
    sum %= mod;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3632
n=int(input())
arr=[0]*n
for i in range(n):
  arr[i]=int(input())
tmp=sorted(arr,reverse=True)
arrMax=tmp[0]
for i in range(n):
  if arr[i]==arrMax:
    if tmp[0]==tmp[1]:
      print(tmp[0])
    else:
      print(tmp[1])
  else:
    print(tmp[0])

  


Measured memory_bytes: 18960
#include <bits/stdc++.h>
using namespace std;
#define INF 1001001001
#define MAX_N 200000
typedef pair<int,int> P;

int N;
vector<int> G[MAX_N];
int d[MAX_N];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+N, INF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i=0; i < G[v].size(); ++i) {
            int e = G[v][i];
            if(d[e] > d[v] + 1) {
                d[e] = d[v] + 1;
                que.push(P(d[e], e));
            }
        }
    }
}

int main() {
    int M;
    cin >> N >> M;
    for(int i=0; i<M; ++i) {
        int a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    dijkstra(0);
    if(d[N-1] == 2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

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

#ifdef LOCAL
#include "debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;

const int MAXN = 1e6 + 10;

ll a[MAXN], csum[MAXN] = {};
ll n, m, v, p;

bool valid(ll pos) {
    assert(pos < n - p);
    if(a[pos] + m < a[n - p]) return false;
    if(v <= pos + 1 + p - 1) return true;

    ll v1 = v - (pos + 1 + p - 1);
    ll space = (ll(n - p - pos) * (a[pos] + m)) - (csum[n - p] - csum[pos]);
    ll votes = v1 * m;
    return votes <= space;
}

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;

    cin >> n >> m >> v >> p;
    rep(i, 0, n) cin >> a[i];
    sort(a, a + n);

    csum[0] = a[0];
    rep(i, 1, n) csum[i] = csum[i - 1] + a[i];

    ll lo = 0, hi = n - p, mid;
    while(lo < hi) {
        mid = lo + (hi - lo) / 2;
        if(!valid(mid)) lo = mid + 1;
        else hi = mid;
    }
    cout << n - lo << endl;

    return 0;
}
















Measured memory_bytes: 5120
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
const long long md=1e9+7;
string s;
long long dp[101010][15],n;
int main()
{
	getline(cin,s);
	n=s.size();
	if(s[n-1]=='?')
	{
		for(int i=0;i<10;i++)
		{
			dp[n-1][i]=1;
		}
	}
	else
	{
		dp[n-1][s[n-1]-'0']=1;
	}
	for(int i=n-2;i>=0;i--)
	{
		if(((n-i-1)/3)%2==0)
		{
			if(s[i]=='?')
			{
				if((n-i)%3==1)
				{
					for(int j=0;j<13;j++)
					{
						for(int k=0;k<10;k++)
						{
							dp[i][(j+k)%13]+=dp[i+1][j];
							dp[i][(j+k)%13]%=md;
						}
					}
				}
				else if((n-i)%3==2)
				{
					for(int j=0;j<13;j++)
					{
						for(int k=0;k<10;k++)
						{
							dp[i][(j+k*10)%13]+=dp[i+1][j];
							dp[i][(j+k*10)%13]%=md;
						}
					}
				}
				else
				{
					for(int j=0;j<13;j++)
					{
						for(int k=0;k<10;k++)
						{
							dp[i][(j+k*9)%13]+=dp[i+1][j];
							dp[i][(j+k*9)%13]%=md;
						}
					}
				}
			}
			else
			{
				if((n-i)%3==1)
				{
					for(int j=0;j<13;j++)
					{
						dp[i][(j+(s[i]-'0'))%13]+=dp[i+1][j];
						dp[i][(j+(s[i]-'0'))%13]%=md;
					}
				}
				else if((n-i)%3==2)
				{
					for(int j=0;j<13;j++)
					{
						dp[i][(j+(s[i]-'0')*10)%13]+=dp[i+1][j];
						dp[i][(j+(s[i]-'0')*10)%13]%=md;
					}
				}
				else
				{
					for(int j=0;j<13;j++)
					{
						dp[i][(j+(s[i]-'0')*9)%13]+=dp[i+1][j];
						dp[i][(j+(s[i]-'0')*9)%13]%=md;
					}
				}
			}
		}
		else
		{
			if(s[i]=='?')
			{
				if((n-i)%3==1)
				{
					for(int j=0;j<13;j++)
					{
						for(int k=0;k<10;k++)
						{
							dp[i][(130+j-k)%13]+=dp[i+1][j];
							dp[i][(130+j-k)%13]%=md;
						}
					}
				}
				else if((n-i)%3==2)
				{
					for(int j=0;j<13;j++)
					{
						for(int k=0;k<10;k++)
						{
							dp[i][(130+j-k*10)%13]+=dp[i+1][j];
							dp[i][(130+j-k*10)%13]%=md;
						}
					}
				}
				else
				{
					for(int j=0;j<13;j++)
					{
						for(int k=0;k<10;k++)
						{
							dp[i][(130+j-k*9)%13]+=dp[i+1][j];
							dp[i][(130+j-k*9)%13]%=md;
						}
					}
				}
			}
			else
			{
				if((n-i)%3==1)
				{
					for(int j=0;j<13;j++)
					{
						dp[i][(130+j-(s[i]-'0'))%13]+=dp[i+1][j];
						dp[i][(130+j-(s[i]-'0'))%13]%=md;
					}
				}
				else if((n-i)%3==2)
				{
					for(int j=0;j<13;j++)
					{
						dp[i][(130+j-(s[i]-'0')*10)%13]+=dp[i+1][j];
						dp[i][(130+j-(s[i]-'0')*10)%13]%=md;
					}
				}
				else
				{
					for(int j=0;j<13;j++)
					{
						dp[i][(130+j-(s[i]-'0')*9)%13]+=dp[i+1][j];
						dp[i][(130+j-(s[i]-'0')*9)%13]%=md;
					}
				}
			}
		}
	}/*
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<13;j++)
		{
			cout<<dp[i][j]<<' ';
		}
		cout<<endl;
	}*/
	cout<<dp[0][5]%md<<endl;
	return 0;
}

Measured memory_bytes: 12160
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;

namespace zyt
{
	template<typename T>
	inline bool read(T &x)
	{
		char c;
		bool f = false;
		x = 0;
		do
			c = getchar();
		while (c != EOF && c != '-' && !isdigit(c));
		if (c == EOF)
			return false;
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
		return true;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	typedef long long ll;
	typedef pair<int, int> pii;
	const int N = 1 << 18 | 10, P = 998244353, INV2 = (P + 1) / 2;
	int n, p[N], A[N];
	pii f[N];
	int power(int a, int b)
	{
		int ans = 1;
		while (b)
		{
			if (b & 1)
				ans = (ll)ans * a % P;
			a = (ll)a * a % P;
			b >>= 1;
		}
		return ans;
	}
	int inv(const int a)
	{
		return power(a, P - 2);
	}
	pii operator + (const pii &a, const pii &b)
	{
		return pii((a.first + b.first) % P, (a.second + b.second) % P);
	}
	pii operator - (const pii &a, const pii &b)
	{
		return pii((a.first - b.first + P) % P, (a.second - b.second + P) % P);
	}
	pii operator * (const pii &a, const int &b)
	{
		return pii(int((ll)a.first * b % P), int((ll)a.second * b % P));
	}
	namespace FWT
	{
		void fwt(int *const a, const int n)
		{
			for (int l = 1; l < n; l <<= 1)
				for (int i = 0; i < n; i += (l << 1))
					for (int k = 0; k < l; k++)
					{
						int x = a[i + k], y = a[i + l + k];
						a[i + k] = (x + y) % P;
						a[i + l + k] = (x - y + P) % P;
					}
		}
		void ifwt(pii *const a, const int n)
		{
			for (int l = 1; l < n; l <<= 1)
				for (int i = 0; i < n; i += (l << 1))
					for (int k = 0; k < l; k++)
					{
						pii x = a[i + k], y = a[i + l + k];
						a[i + k] = (x + y) * INV2;
						a[i + l + k] = (x - y) * INV2;
					} 
		}
	}
	int work()
	{
		using namespace FWT;
		read(n);
		int sum = 0;
		for (int i = 0; i < (1 << n); i++)
			read(p[i]), sum += p[i];
		sum = inv(sum);
		for (int i = 0; i < (1 << n); i++)
		{
			p[i] = (ll)p[i] * sum % P;
			A[i] = P - 1;
		}
		A[0] = (1 << n) - 1;
		p[0] = (p[0] - 1 + P) % P;
		fwt(p, 1 << n), fwt(A, 1 << n);
		f[0] = pii(1, 0);
		for (int i = 1; i < (1 << n); i++)
			f[i] = pii(0, (ll)A[i] * inv(p[i]) % P);
		ifwt(f, 1 << n);
		int x = ll(P - f[0].second) * inv(f[0].first) % P;
		for (int i = 0; i < (1 << n); i++)
			write(((ll)f[i].first * x + f[i].second) % P), putchar('\n');
		return 0;
	}
}
int main()
{
	return zyt::work();
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100004
vector<ll> adj[N];
map<pair<ll,ll>,ll> pam;
ll n;
ll c[N];
void dfs(ll s,ll p)
{
	for(ll i=0;i<adj[s].size();i++)
	{
		ll v=adj[s][i];
		if (v!=p)
		{
			ll p=s;
			ll q=v;
			if (p>q)
				swap(p,q);
			if (pam[{p,q}])
				c[v]=c[s]^1;
			else
				c[v]=c[s];

		}
	}
	for(ll i=0;i<adj[s].size();i++)
	{
		ll v=adj[s][i];
		if (v!=p)
		{
			dfs(v,s);
		}
	}
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	ll m=n-1,a,b,w;
	while(m--)
	{
		cin>>a>>b>>w;
		adj[a].push_back(b);
		adj[b].push_back(a);
		if (a>b)
			swap(a,b);
		pam[{a,b}]=(w&1);
	}
	c[1]=0;
	dfs(1,0);
	for(ll i=1;i<=n;i++)
	{
		cout<<c[i]<<"\n";
	}
}

Measured memory_bytes: 17664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    int p[n];
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    sort(p,p+n);
    int x = 0,y = 0,z = 0;
    for(int i = 0; i < n; i++){
        if(p[i] <= a) x++;
        else if(p[i] >= a+1 && p[i] <= b) y++;
        else if(p[i] >= b+1) z++;
    }
    cout << min({x,y,z});
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int P (int a){
  int count = 1;
  for(int i = 0; i < a; i++){
    count *= (i + 1);
  }
  return count;
}
int main () {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for(int i = 0; i < N; i++)cin >> A.at(i);
  for(int i = 0; i < N; i++)cin >> B.at(i);
  int counta = 1, countb = 1, sub = 1;
  for(int i = 0; i < N - 1; i++){
    sub = 0;
    for(int j = i + 1; j < N; j++){
      if(A.at(i) > A.at(j))sub++;
    }
    counta +=P(N - i - 1) * sub;
  }
  for(int i = 0; i < N - 1; i++){
    sub = 0;
    for(int j = i + 1; j < N; j++){
      if(B.at(i) > B.at(j))sub++;
    }
    countb +=P(N - i - 1) * sub;
  }
  cout << abs(counta - countb) << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt, sum int = 0, 0, 0

func main() {
	reader.Split(bufio.ScanWords)
	S := read()
	for i := 0; i < len(S); i++ {
		if i%2 == 0 && string(S[i]) == "L" {
			fmt.Println("No")
			return
		}
		if i%2 == 1 && string(S[i]) == "R" {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	ll s; cin >> s;
	const int M = 1'000'000'000;
	int y0 = 0;
	int y2 = M;
	int x1 = (s + M - 1) / M;
	int x2 = (M - (s % M)) % M;
	int y1 = 1;
	int x0 = 0;
	// x0 (y1 - y2) + x1 (y2 - y0) + x2 (y0 - y1)
	cout << x0 << ' ' << y0 << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

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

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
const ll MOD = 1e9 + 7;

void mainsolve(){

	ll n,c;
	cin >> n >> c;
	vector<vector<ll>> memo(c,vector<ll>(1e5));

	rep(i,n){
		ll s,t,cc;
		cin >> s >> t >> cc;
		--s; --t; --cc;

		memo[cc][s]++;
		memo[cc][t+1]--;
	}

	rep(i,c){
		rep(j,1e5){
			if(j-1 >= 0) memo[i][j] += memo[i][j-1];
		}
	}

	ll res = 0;
	rep(i,1e5){
		ll cnt = 0;
		rep(j,c){
			if(memo[j][i] > 0) cnt++;
		}

		res = max(res, cnt);
	}

	cout << res << endl;

	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}


Measured memory_bytes: 24576
#include<iostream>
#include<queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n,M[N][N];
int d[N];

void bfs(int s){
  queue<int> q;
  q.push(s);
  for(int i = 0; i < n; i++) d[i] = INFTY;
  d[s] = 0;
  int u;
  while(!q.empty()){
    u = q.front();
    q.pop();
    for(int v=0;v<n;v++){
      if(M[u][v] == 0) continue;
      if(d[v]!=INFTY) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for(int i = 0; i<n; i++){
    cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
  }
}

int main(){
  int u,k,v;

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

  for(int i = 0; i < n; i++){
    cin >> u >> k;
    u--;
    for(int j = 0; j<k; j++){
      cin>>v;
      v--;
      M[u][v] = 1;
    }
  }
  bfs(0);

  return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999999;
const ll MOD=128;
const ll MAX_N=100010;
ll a,b,d,e,x,y,z,k,m,n,l,q,h,w,ans=0;
vl v2;
vp v,v1;
char c;
string s1,s2;
ll masu[1001][1001];
ll solve(void){
    while(v.size()>0){
        v1=vp(0);
    rep(i,v.size()){
        ll xx,yy;
        vl x1={1,-1,0,0},y1={0,0,1,-1};
        x=v[i].first;
        y=v[i].second;
        rep(j,4){
            xx=x+x1[j];
            yy=y+y1[j];
            if(xx>-1&&xx<h&&yy>-1&&yy<w){
            if(masu[xx][yy]==0){
                v1.emplace_back(xx,yy);
                masu[xx][yy]=1;
            }
            }
        }
    }
    v=v1;
    //cout<<v.size()<<endl;
    ans++;
    }

    return ans-1;
}
int main(){
    cin>>h>>w;
    rep(i,h){
        rep(j,w){
            cin>>c;
            if(c=='#'){
                masu[i][j]=1;
                v.emplace_back(i,j);
            }
            else masu[i][j]=0;
        }
    }

    cout<<solve()<<endl;
}

Measured memory_bytes: 31716
import bisect
def main():
    N = int(input())
    L = sorted([int(_) for _ in input().split()])

    ret = 0
    for i in range(N):
        for j in range(i+1, N):
            x = bisect.bisect_left(L, L[i] + L[j])
            ret += x - j - 1
    print(ret)

    return

if __name__ == '__main__':
    main()


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

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

#define forn(i, n) for(int i=0; i<n; i++)
#define mp makepair
#define pb push_back

int main(){
    int n;
    int arr[100000 + 7][3];
    cin>>n;
    forn(i,n)scanf("%d %d %d", &arr[i][0], &arr[i][1], &arr[i][2]);
    ll sum[2][3];
    memset(sum, 0, sizeof sum);
    forn(i, n) {
        sum[1][0] = arr[i][0] + max(sum[0][1], sum[0][2]);
        sum[1][1] = arr[i][1] + max(sum[0][0], sum[0][2]);
        sum[1][2] = arr[i][2] + max(sum[0][0], sum[0][1]);

        sum[0][0] = sum[1][0];
        sum[0][1] = sum[1][1];
        sum[0][2] = sum[1][2];
    }

    cout<< max(sum[0][0], max(sum[0][1], sum[0][2])) <<endl;

}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int a[10001];
int main(){
	int n, maxj, minj, s;
	cin >> n;
	maxj = INT_MIN;
	minj = INT_MAX;
	for (int i = 1; i <= n; ++ i)
	{
		cin >> a[i];
	}
	for (int i = 1; i <= n; ++ i)
	{
		if (a[i] > maxj) maxj = a[i];
		if (a[i] < minj) minj = a[i];
	}
	s = maxj - minj;
	cout << s << endl;
	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
 int main()
 {int a,b; char w;
 scanf("%d %c %d",&a,&w,&b);
 if (w=='+')
 {
 printf("%d",a+b);
}
 if (w=='-')
 {
 printf("%d",a-b);
}
 return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        new Solver().solve(new Scanner(System.in));
//        new Solver().solve(new Scanner(ex));
    }

    private static final String ex = "3\n" +
            "0 0 3 0 0 2 3 2\n" +
            "0 0 3 0 1 1 1 4\n" +
            "0 0 3 0 1 1 2 2\n";
}

class Solver {
    private static final double EPS = 1e-10;

    void solve(Scanner scanner) {
        int q = scanner.nextInt();
        for (int i = 0; i < q; i ++) {
            Vector u = new Vector(
                    new Point(scanner.nextInt(), scanner.nextInt()),
                    new Point(scanner.nextInt(), scanner.nextInt())
            );
            Vector v = new Vector(
                    new Point(scanner.nextInt(), scanner.nextInt()),
                    new Point(scanner.nextInt(), scanner.nextInt())
            );

            if (Math.abs(u.innerProduct(v)) < EPS) {
                System.out.println(1);
            } else if (Math.abs(u.outerProduct(v)) < EPS) {
                System.out.println(2);
            } else {
                System.out.println(0);
            }
        }

    }

    private int[] splitInt(String s) {
        String[] split = s.split(" ");
        int[] splitInt = new int[split.length];
        for (int i = 0; i < split.length; i ++) {
            splitInt[i] = Integer.parseInt(split[i]);
        }
        return splitInt;
    }

    private long[] splitLong(String s) {
        String[] split = s.split(" ");
        long[] splitLong = new long[split.length];
        for (int i = 0; i < split.length; i ++) {
            splitLong[i] = Long.parseLong(split[i]);
        }
        return splitLong;
    }
}

class Point {
    double x;
    double y;

    Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
}

class Vector extends Point {
    Vector(double x, double y) {
        super(x, y);
    }

    Vector (Point from, Point to) {
        this(to.x - from.x, to.y - from.y);
    }

    double innerProduct(Vector v) {
        return this.x * v.x + this.y * v.y;
    }

    double outerProduct(Vector v) {
        return this.x * v.y - this.y * v.x;
    }

    double abs() {
        return Math.sqrt(x * x + y * y);
    }
}

Measured memory_bytes: 40092
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,m;
int main(){
	cin>>n>>m;
	if(n<10)cout<<100*(10-n)+m<<endl;
	else cout<<m<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h> 
#include <math.h>
#define PI 3.141592653589793

int main(void)
{	
	double a, b, d, C, S, L, h;

	scanf("%lf %lf %lf",&a, &b, &C);

	C = C * PI / 180;

	h = b * sin(C);

	S = a * h / 2;

	d = sqrt(a * a + b * b - 2 * a * b * cos(C));

	L = a + b + d;

	printf("%f\n%f\n%f\n",S, L, h);


	return 0;
}

Measured memory_bytes: 648
package main

import (
  "fmt"
)

func main() {
  var N int
  fmt.Scan(&N)

  M := (N*(N-2) + (N % 2)) / 2

  fmt.Println(M)
  for i := 1; i <= N-1; i++ {
    for j := i+1; j <= N; j++ {
      if j != N - (i-1) - (N % 2) {
        fmt.Printf("%d %d\n", i, j)
      }
    }
  }
}

Measured memory_bytes: 640
import math

n = int(input())
aL = list(map(int, input().split(" ")))
q = int(input())
bcL = [list(map(int, input().split(" "))) for _ in range(q)]

sums = [0 for i in range(10**5 + 1)]

for a in aL:
    sums[a] += 1

_sum = 0
for i, a in enumerate(sums):
    _sum += i * a

for b, c in bcL:
    _sum += (c - b) * sums[b]

    sums[c] += sums[b]
    sums[b] = 0
    print(_sum)

Measured memory_bytes: 32156
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <stack>
#include <climits>

using namespace std;

int main() {

	//入力
	int n = 0;
	cin >> n;

	vector<int> ans;

	//例外
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}

	//nが0になるまでループ(進数計算は桁を落とし続ける)
	while (n != 0) {
		//nが2で割り切れるなら
		if (n % 2 == 0) {
			//答えに0を追加
			ans.push_back(0);
			//-2進数で今見ている桁の前まで桁をみるために-2でわって一桁減らす
			n = n / -2;
		}
		//割り切れないとき
		else {
			//末尾が奇数⇒末尾以外は-2の倍数で偶数だが、末尾に1が立つと1*-2^0 = 1*1 = 1となるためそれを変換式で加算すると偶数から奇数になる
			ans.push_back(1);
			//nを偶数にしてやるために奇数にするために足している1を引き、それを-2で割ることで桁を落とす
			n = (n - 1) / -2;
		}
	}

	//結果のベクターをリバースする
	reverse(ans.begin(), ans.end());

	for (int i = 0; i < ans.size(); ++i) {
		cout << ans.at(i);
	}
	
	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */

#define MAXN (100000)
#define MOD (1000000007)

char s[MAXN][11];

int acs_c(const void *a, const void *b){return *(char*)a - *(char*)b;} /* 1,2,3,4.. */

int main(void)
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%s",(s[i]));
        qsort(&(s[i]), 10, sizeof(char), acs_c);
    }
    qsort(s, n, sizeof(char)*11, strcmp);

    uint64_t ans = 0;
    int cont = 0;
    for(int i=1;i<n;i++)
    {
        if(strcmp(s[i-1], s[i])==0)
        {
            cont++;
            ans+= cont;
        }else
        {
            cont = 0;
        }
        
    }

    printf("%ld\n",ans);

    return 0;
}





Measured memory_bytes: 2300
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for i in range(A+1):
    for j in range(B+1):
        res = X - 500*i - 100*j
        if res%50 == 0 and res//50 <= C and res >= 0:
            ans += 1
            
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;

map<string, int> hex_table;

void table_init() {
	hex_table.clear();
	string table = "0123456789abcdef";
	for(int i = 0; i < 16; i++)
		for(int j = 0; j < 16; j++)
			hex_table[table.substr(i,1) + table.substr(j,1)] = i * 16 + j;
}

int hex2dec(string H) {
	return hex_table[H];
}

string name[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
string color_code[] = {"000000", "0000ff", "00ff00", "00ffff", "ff0000", "ff00ff", "ffff00", "ffffff"};

int color_value[8][3];

inline double POW(double v) {
	return v * v;
}

void color_value_init() {
	for(int i = 0; i < 8; i++) {
		string R = color_code[i].substr(0, 2);
		string G = color_code[i].substr(2, 2);
		string B = color_code[i].substr(4, 2);
		color_value[i][0] = hex2dec(R);
		color_value[i][1] = hex2dec(G);
		color_value[i][2] = hex2dec(B);
	}
}

int main() {
	table_init();
	color_value_init();
	for(string line; getline(cin, line), line != "0";) {
		int R = hex2dec(line.substr(1, 2));
		int G = hex2dec(line.substr(3, 2));
		int B = hex2dec(line.substr(5, 2));
#if 0
		debug(hex2dec(R));
		debug(hex2dec(G));
		debug(hex2dec(B));
#endif

		int idx = -1;
		double vmin = 1e10;
		for(int i = 0; i < 8; i++) {
			double v = sqrt(POW(R - color_value[i][0]) + POW(G - color_value[i][1]) + POW(B - color_value[i][2]));
			if(v < vmin) {
				idx = i;
				vmin = v;
			}
		}

		cout << name[idx] << endl;
	}
	return 0;
}

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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;

    if((a + b) %2 ==0 ){
        cout << (b-a)/2 << endl;
    }

    else{
        cout << min(a-1,n-b) +1 +(b-a-1)/2 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int takoyakis = 0; // たこ焼きの個数
  int delicious_points_list[50]; // おいしさの値を格納する配列
  int sum_heal_points = 0; // 回復量の総和

  // たこ焼きの個数を設定する
  scanf("%d", &takoyakis);

  // たこ焼き達においしさ値を設定する
  for(int i = 0;i < takoyakis; i++) {
    scanf("%d", &delicious_points_list[i]);
  }

  // 各たこ焼き同士の回復量を総当たり方式で計算する
  for(int i = 0; i < takoyakis * takoyakis; i++) {
    int base = i / takoyakis;
    int material = i % takoyakis;

    // 一度計算した組み合わせ、同じたこ焼きどうしの計算を回避
    if(material >= base) continue;

    sum_heal_points += delicious_points_list[base] * delicious_points_list[material];
  }

  // 出力
  printf("%d\n", sum_heal_points);

  return 0;
}


Measured memory_bytes: 128