akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int sum = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }

    vector<int> div;
    for(int i = 1; i * i <= sum; ++i) {
        if(sum % i == 0) {
            int j = sum / i;
            div.push_back(i);
            div.push_back(j);
        }
    }
    sort(div.rbegin(), div.rend());
    for(int d : div) {
        vector<int> v(n);
        int t = 0;
        for(int i = 0; i < n; ++i) {
            v[i] = a[i] % d;
            t += d - v[i];
        }
        t /= d;
        sort(begin(v), end(v));
        int mov = 0;
        for(int i = 0; i < t; ++i) {
            mov += v[i];
        }
        if(mov <= k) {
            cout << d << '\n';
            return 0;
        }
    }
    assert(0 == 1);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    long N = sc.nextLong();
    long M = sc.nextLong();
    long D = sc.nextLong();
    double c = D == 0 ? N : (N - D) * 2;
    c /= N;
    c *= (M - 1);
    c /= N;
    System.out.printf("%.8f\n", c);
  }

}

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

#define ll long long
#define ar array
#define vi vector<int>
#define INF 1000000000

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	ll sum = 0;
	for(int i=1; i <= N; i++){
		if(i % 5 != 0 && i % 3 != 0) sum += i;
	}	
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 3560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] w = new int[n];
		for(int i = 0 ; i < n ; i++) {
			w[i] = sc.nextInt();
		}
		int ans = Integer.MAX_VALUE;
		for(int i = 1 ; i < n ; i++) {
			int s1 = 0;
			int s2 = 0;
			for(int j = 0 ; j < i ; j++) {
				s1 += w[j];
			}
			for(int j = i ; j < n ; j++) {
				s2 += w[j];
			}
			ans = Math.min(ans, Math.abs(s2 - s1));
		}
		System.out.println(ans);
		sc.close();

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b; cin >> a >> b;
	cout <<(a-1)*(b-1);

	cout << endl;
	return 0;
}

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

int main(void) {
	vector<int> height;
	for (int i=0; i<10; i++)
	{
		int a;
		cin >> a;
		height.push_back(a);
	}
	sort(height.begin(),height.end(),greater<int>());
	for (int i=0; i<3; i++)
	{
		cout << height[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdlib>
#include <iostream>

using namespace std;

constexpr size_t d = 1000000000 + 7;

size_t fact(int n) {
  if (n == 1)
    return 1;
  return n * fact(n - 1) % d;
}

int main() {
  int N;
  cin >> N;
  cout << fact(N) << endl;
  return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			String buffer = sc.next();

			if (buffer.equals("#")) {
				break;
			}

			int n = buffer.length();

			int dpl[][] = new int[n + 1][4];
			int dpr[][] = new int[n + 1][4];

			for (int i = 0; i < n + 1; i++) {
				Arrays.fill(dpl[i], Integer.MAX_VALUE >> 2);
				Arrays.fill(dpr[i], Integer.MAX_VALUE >> 2);
			}
			dpl[0][3] = 0;
			dpr[0][3] = 0;

			for (int i = 0; i < n; i++) {
				char ch = buffer.charAt(i);
				int v = (ch - '1') % 3;
				for (int prev = 0; prev < 3; prev++) {
					if (prev >= v) {
						dpl[i + 1][v] = Math.min(dpl[i + 1][v], dpr[i][prev]);
					}
					if (prev <= v) {
						dpr[i + 1][v] = Math.min(dpr[i + 1][v], dpl[i][prev]);
					}
					dpl[i + 1][v] = Math.min(dpl[i + 1][v], dpl[i][prev]+1);
					dpr[i + 1][v] = Math.min(dpr[i + 1][v], dpr[i][prev]+1);
				}
				dpl[i + 1][v] = Math.min(dpl[i + 1][v], dpr[i][3]);
				dpr[i + 1][v] = Math.min(dpr[i + 1][v], dpl[i][3]);
			}
			
			int ans = Integer.MAX_VALUE;
			for(int i =0 ; i < 4;i++){
				ans = Math.min(dpl[n][i],ans);
				ans = Math.min(dpr[n][i],ans);
			}
			System.out.println(ans);
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 0
l, r = map(int, input().split())
if r - l >= 2019:
    print(0)
    exit()
ans1 = []
for i in range(l, r + 1):
    ans1.append(i % 2019)
ans2 = []
for i in range(len(ans1) - 1):
    for j in range(i + 1, len(ans1)):
        ans2.append((ans1[i]* ans1[j]) % 2019)
print(min(ans2))

Measured memory_bytes: 75436
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define INF 10000000; 


int partition(int A[],int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
		swap(A[i + 1], A[r]);
		return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[],int n,int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >=0  ) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n,int v[],int ww[]) {
	int W[101][10001];
		for (int j = 0;j <= w;j++) {
			W[0][j] = 0;
		}
	for (int i = 0;i < n;i++) {
		for (int j = 0;j <= w;j++) {
			if (j - ww[i] < 0) {
				W[i+1][j] = W[i][j];
			}
			if (j - ww[i] >= 0) {
				W[i+1][j] = max(W[i][j], W[i][j - ww[i]] + v[i]);

			}
		}
	}
	return W[n][w];
}
int main() {
		int N,W;
		cin >> N>>W;
		int v[100];
		int w[100];
		for (int i = 0;i < N;i++) {
			cin >> v[i] >> w[i];
		}
		cout << knapsack(W, N, v, w)<<endl;
}

Measured memory_bytes: 5104
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n; 
int main(){
	n=read();
	cout<<n*n*n<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args : Array<String>) {
  val s = readLine()!!
  val s1 = s.substring(0, 2)
  val s2 = s.substring(2)
  val t1 = s1 == "00" || s1 > "12"
  val t2 = s2 == "00" || s2 > "12"
  val ans = when {
    t1 && t2 -> "NA"
    t1 -> "YYMM"
    t2 -> "MMYY"
    else -> "AMBIGUOUS"
  }
  println(ans)
}


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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long
#define pii pair<int, int>
#define ld long double

const int INF = 2e9 + 1;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> p(n);
    for (auto &c : p) cin >> c;
    if (is_sorted(all(p))) {
        cout << "YES";
        return 0;
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            vector<int> a = p;
            swap(a[i], a[j]);
            if (is_sorted(all(a))) {
                cout << "YES";
                return 0;
            }
        }
    }
    cout << "NO";
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
using namespace std;
inline void put(int a[], int n) {
	cout << a[0];
	for (int i = 1; i < n; i++) {
		cout << ' ' << a[i];
	}
	cout << endl;
}
inline void sort(int a[], int n) {
	for (int i = 1; i < n; i++) {
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j+1] = a[j];
			j--;
		}
		a[j + 1] = v;
		put(a, n);
	}
}
int main() {
	const int num = 1000;
	int ar[num];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
	}
	put(ar, n); 
	sort(ar, n);
	return 0;

}

Measured memory_bytes: 3088
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

//  B - Card Game for Two

public class Main {
  public static void main(String[] args ) throws Exception {

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    List<Integer> list = new ArrayList();

    for(int i = 0; i < n ; i++) {
    	list.add(Integer.parseInt(sc.next()));
    }

    int alice = 0;
    int bob = 0;

    boolean flg = true;
    Collections.sort(list);
    Collections.reverse(list);
    for(Integer a : list) {
    	if(flg) {
    		alice += a;
    		flg = false;
    	} else {
    		bob += a;
    		flg = true;
    	}
    }

    	System.out.println(alice-bob);
  }
}



Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    ll n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>a>>b;

    if(a*b<=0)cout<<"Zero\n";
    else {
        if(a>0)cout<<"Positive\n";
        else if((b-a)&1)cout<<"Positive\n";
        else cout<<"Negative\n";
    }

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
vector<T> Dijkstra(const weighted_graph<T>& G,int s){
	const T INF=numeric_limits<T>::max();
	int n=G.size();
	vector<T> d(n,INF); d[s]=0;
	priority_queue<pair<T,int>> Q; Q.emplace(0,s);
	while(!Q.empty()){
		T d0=-Q.top().first;
		int u=Q.top().second; Q.pop();
		if(d0>d[u]) continue;
		for(const auto& e:G[u]){
			int v=e.to;
			if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, Q.emplace(-d[v],v);
		}
	}
	return d;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);

	int k=n;
	vector<map<int,int>> f(n); // f[u][color] := (vertex id)

	vector<tuple<int,int,int>> E(m);
	rep(i,m){
		int u,v,c; scanf("%d%d%d",&u,&v,&c); u--; v--; c--;
		E[i]=make_tuple(u,v,c);
		if(f[u].count(c)==0) f[u][c]=k++;
		if(f[v].count(c)==0) f[v][c]=k++;
	}

	weighted_graph<int> G(k);
	rep(u,n) for(auto p:f[u]) {
		int i=p.second;
		G[u].emplace_back(i,1);
		G[i].emplace_back(u,1);
	}
	for(auto e:E){
		int u,v,c; tie(u,v,c)=e;
		int i=f[u][c],j=f[v][c];
		G[i].emplace_back(j,0);
		G[j].emplace_back(i,0);
	}

	int res=Dijkstra(G,0)[n-1];
	printf("%d\n",res<1e8?res/2:-1);

	return 0;
}


Measured memory_bytes: 58872
#include <stdio.h>

typedef long long ll;

int main() {

	ll a, b, x;

	scanf("%lld %lld %lld",&a,&b,&x);

	if(a==0ll||b==0ll){
		if (b == 0ll) { printf("1\n"); }
		else {
			printf("%lld\n", (b / x) + 1);
		}
	}
	else {
		printf("%lld\n", (b / x) - ((a - 1) / x));
	}

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  int n;
  n=32;
  vi a(n);
  a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout<<a[k-1]<<endl;
    


} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


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

int main() {

        int abc[3];

        cin >> abc[0] >> abc[1] >> abc[2];

        int ope = 0;
        while (1) {

                if (abc[0] == abc[1] && abc[1] == abc[2]) {
                        break;
                }

                for (int i = 0; i < 2; ++i) {
                        for (int j = 0; j < 2; ++j) {
                                if (abc[j] > abc[j+1]) {
                                        int tmp = abc[j];
                                        abc[j] = abc[j+1];
                                        abc[j+1] = tmp;
                                }
                        }
                }

                if (abc[1] == abc[2]) {
                        abc[0] += 2;
                        ope++;
                        continue;
                }

                abc[0] += 1;
                abc[1] += 1;
                ope++;
        }
        cout << ope << endl;




}


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

int main() {
    string s;
    cin >> s;
    if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
        cout << "Bad" << '\n';
    } else {
        cout << "Good" << '\n';
    }
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long h=sc.nextLong();
		long ans=0;
		long t=1;
		while(h>=t){
			ans+=t;
			t*=2;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,t[103],tsum=0,m,p,x;
  
  cin >> n;
  for (i=0;i<n;i++){
    cin >> t[i];
    tsum+=t[i];
  }
  
  cin >> m;
  for (i=0;i<m;i++){
    cin >> p >> x;
    cout << tsum-t[p-1]+x << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }

bool is_prime(int x) {
    for (int i=2; i*i<=x; i++) if(x % i == 0) return false;
    return x != 1;
}

int[] make_primes() {
    int[] a;
    foreach(i; 5..55555+1) if(is_prime(i)) a ~= i;
    return a;
}

void main() {
    int n = readint();
    int[] primes = make_primes();
    int[] ans;
    foreach (int p ; primes) {
        if (p % 5 == 1) ans ~= p;
        if (ans.length == n) break;
    }
    writefln("%(%s %)", ans);
    string _ = readln;
}

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

int main() {
  int n,r;
  cin >> n>>r;
  if (n<10) {
  cout << r+100*(10-n)<<endl;
  }
  if  (n>=10) {
  cout << r<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
var
	s:String;
	i,j,k:Longint;
	a,b,c,d,e:String[5];
begin
	readln(s);
	read(k);
	a:='zzzzz';
	b:=a;
	c:=b;
	d:=c;
	e:=d;
	for i:=1 to length(s)do begin
		for j:=1 to k do begin
			if i+j-1>length(s)then break;
			if a>copy(s,i,j)then begin
				e:=d;
				d:=c;
				c:=b;
				b:=a;
				a:=copy(s,i,j);
			end else if a<>copy(s,i,j)then begin
				if b>copy(s,i,j)then begin
					e:=d;
					d:=c;
					c:=b;
					b:=copy(s,i,j);
				end else if b<>copy(s,i,j)then begin
					if c>copy(s,i,j)then begin
						e:=d;
						d:=c;
						c:=copy(s,i,j);
					end else if c<>copy(s,i,j)then begin
						if d>copy(s,i,j)then begin
							e:=d;
							d:=copy(s,i,j);
						end else if d<>copy(s,i,j)then begin
							if e>copy(s,i,j)then begin
								e:=copy(s,i,j);
							end;
						end;
					end;
				end;
			end;
		end;
	end;
	if k=1 then writeln(a)else if k=2 then writeln(b)else if k=3 then writeln(c)else if k=4 then writeln(d)else writeln(e);
end.

Measured memory_bytes: 128
#include <stdio.h>

int main(void){

	int a,b,c;
	int min1,min2;
	int ans;

	scanf("%d %d %d",&a,&b,&c);

	if(a > b){
		min1 = b;
		min2 = a;
	}
	else {
		min1 = a;
		min2 = b;
	}

	if(min1 > c){
		min2 = min1;
		min1 = c;
	}
	else if(min2 > c)
		min2 = c;
	
	ans = min1 + min2;

	printf("%d",ans);

	return 0;
}



Measured memory_bytes: 128
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.container; // SList, DList, BinaryHeap

void main()
{
  auto n = readln.chomp.to!size_t;

  auto g = new size_t[][](n);
  auto c = new int[][](n);
  foreach (_; 0..n-1) {
    auto rd1 = readln.splitter;
    auto ai = rd1.front.to!size_t-1; rd1.popFront;
    auto bi = rd1.front.to!size_t-1; rd1.popFront;
    auto ci = rd1.front.to!int;
    g[ai] ~= bi; c[ai] ~= ci;
    g[bi] ~= ai; c[bi] ~= ci;
  }

  auto rd2 = readln.split.to!(size_t[]), q = rd2[0], k = rd2[1]-1;

  auto p = new size_t[](n), d = new long[](n);
  p[k] = n;

  auto queue = DList!size_t([k]);
  while (!queue.empty) {
    auto u = queue.front; queue.removeFront();
    foreach (v, ci; lockstep(g[u], c[u])) {
      if (p[u] != v) {
        p[v] = u;
        d[v] = d[u] + ci;
        queue.insertBack(v);
      }
    }
  }

  foreach (_; 0..q) {
    auto rd3 = readln.splitter;
    auto x = rd3.front.to!size_t-1; rd3.popFront();
    auto y = rd3.front.to!size_t-1;
    writeln(d[x] + d[y]);
  }
}


Measured memory_bytes: 19708
#include <bits/stdc++.h>
#define N 2010
using namespace std;
const int INF = 1e9;
int K,C[N][N],NG[N][N];
vector<int> G[N];
int Max(int &a,int b){return a=max(a,b);}

int visited[N];
vector<int> g;
void dfs(int pos,int pre){
  g.push_back(pos);
  if(visited[pos]++) return;
  for(int nx:G[pos])if(nx!=pre){dfs(nx,pos);break;}
}

int dp1[2][2][N][N]; //flg,used,pos,cnt
void update(int flg,int i,int cnt){
  int pos = g[i];
  int pre = g[i-1];

  //pos???????????????
  if(!(pos==g[0] && flg == 1)){ //??????????????§????????????????????¨??????????????????????????£?????\???
    Max(dp1[flg][0][i][cnt],dp1[flg][0][i-1][cnt]); //??????????????£????????? 
    Max(dp1[flg][0][i][cnt],dp1[flg][1][i-1][cnt]); //??????????????£???
  }

  if(flg==0 && pos==g[0])return; //start??§?????????start????????£??????????????????????????¨?????????????????????
  int f = !(pos==g[0] && flg == 1); // ??????????????§???????????????????????§????????´???(flg==1)???cost???0?????????

  //pos????????????
  Max(dp1[flg][1][i][cnt+f],dp1[flg][0][i-1][cnt]); //??????????????£????????? 
  if(NG[pre][pos]==0)Max(dp1[flg][1][i][cnt+f],dp1[flg][1][i-1][cnt]+C[pre][pos]);//???????????£???
}

vector<vector<int> >D;
void DP1(){

  int n = g.size();
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++)
      for(int k=0;k<=n;k++)
	for(int l=0;l<=n;l++)dp1[i][j][k][l] = -INF;

  
  dp1[0][0][0][0] = 0;
  dp1[1][1][0][1] = 0;
  
  for(int i=1;i<n;i++)
    for(int j=0;j<=n;j++)update(0,i,j),update(1,i,j);
  
  vector<int> tmp;
  for(int i=0;i<=n;i++){
    int a = max(dp1[0][0][n-1][i],dp1[0][1][n-1][i]);
    int b = max(dp1[1][0][n-1][i],dp1[1][1][n-1][i]);
    tmp.push_back(max(a,b));
  }
  D.push_back(tmp);
}

int DP2(){
  int dp2[N]; //1??????????????§????????????????????????
  for(int i=0;i<=K;i++)dp2[i] = -INF; //?????????
  
  int n = D.size();
  dp2[0] = 0;
  for(int i=0;i<n;i++) //??£??????????????????????????§?????????
    for(int k=K,m=D[i].size();k>=0;k--) //???????????????????????????
      for(int j=0;j<m && k+j<=K;j++) //?¬?????????????????????????
	Max(dp2[k+j],dp2[k]+D[i][j]);

  return dp2[K];
}

int main(){
  int n,m;
  cin>>n>>m>>K;

  for(int i=0,a,b,c;i<m;i++){
    cin>>a>>b>>c;a--,b--;
    C[a][b] = C[b][a] = c;
    if(c==0)NG[a][b] = NG[b][a] = 1;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  //?¬???°????????\???????????????????????????
  for(int i=0;i<n;i++)
    if(G[i].size()<=1 && visited[i]==0) g.clear(),dfs(i,-1),DP1(); 

  //?¬???°????????????????????????
  for(int i=0;i<n;i++)
    if(visited[i] == 0) g.clear(),dfs(i,-1),DP1();

  int ans = DP2();
  if(ans<-1e8) cout<<"Impossible"<<endl;
  else cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 79308
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void) {
    ll n, m, ans = 0;
    cin >> n >> m;
    ll h[n];
    bool isGood[n];
    rep(i, n){
        cin >> h[i];
        isGood[i] = true;
    }
    rep(i, m){
        ll a, b;
        cin >> a >> b;
        if(h[a-1] > h[b-1]){
            isGood[b-1] = false;
        }else if(h[a-1] == h[b-1]){
            isGood[a-1] = false;
            isGood[b-1] = false;
        }else{
            isGood[a-1] = false;
        }
    }
    rep(i, n){
       if(isGood[i]){
           ans++;
       }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4500
#include <stdio.h>

int main(){
    int hours, minites, seconds;
    int time;

    scanf("%d", &time);

    hours = time/(60*60);
    time = time - hours*60*60;

    minites = time/60;
    time = time - minites*60;

    seconds = time;

    printf("%d:%d:%d\n", hours, minites, seconds);    

    return 0;
}

Measured memory_bytes: 592
package main

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

func main() {
	defer writer.Flush()
	N, K, Q := ReadInt(), ReadInt(), ReadInt()
	m := make(map[int]int)
	for i := 0; i < Q; i++ {
		a := ReadInt() - 1
		m[a]++
	}
	for i := 0; i < N; i++ {
		if K-Q+m[i] > 0 {
			Println("Yes")
		} else {
			Println("No")
		}
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }

var writer = bufio.NewWriter(os.Stdout)

func Println(a ...interface{}) { fmt.Fprintln(writer, a...) }


Measured memory_bytes: 8596
#include <stdio.h>

int daysans(int page, int max)
{
    int ans;

    if (page % max == 0){
        ans = page / max;
    }
    else {
        ans = (page / max) + 1;
    }

    return (ans);
}
int main(void)
{
    int days, pageM, pageJ, maxM, maxJ;

    scanf("%d", &days);
    scanf("%d", &pageJ);
    scanf("%d", &pageM);
    scanf("%d", &maxJ);
    scanf("%d", &maxM);

    if (daysans(pageJ, maxJ) >= daysans(pageM, maxM)){
        printf("%d\n", days - daysans(pageJ, maxJ));
    }
    else {
        printf("%d\n", days - daysans(pageM, maxM));
    }
    return (0);
}

Measured memory_bytes: 596
#include <iostream>
#define llint long long

using namespace std;

llint n, W;
llint w[105], v[105];
llint dp[105][100005];

int main(void)
{
	cin >> n >> W;
	for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= W; j++){
			dp[i][j] = -1e18;
		}
	}
	dp[0][0] = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= W; j++){
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(j+w[i+1] <= W) dp[i+1][j+w[i+1]] = max(dp[i+1][j+w[i+1]], dp[i][j] + v[i+1]);
		}
	}
	llint ans = 0;
	for(int i = 0; i <= W; i++) ans = max(ans, dp[n][i]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	int i,n,ans=0;
	string s;
	cin>>s;
	for(i=0;i<4;++i){
		if(s[i]=='+')ans++;
		else ans--;
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  if(n==1){
    cout<<"Yes"<<endl;
    return 0;
  } 
  vector<int> vec(n);
  rep(i,n) cin>>vec[i];
  vec[0]-=1;
  rep(i,n-1){
    if(vec[i]<vec[i+1]){
      vec[i+1]-=1;
    }
  }
  rep(i,n-1){
    if(vec[i]>vec[i+1]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
int main(void){
    char a[1001],c[101],f[1001],m[1001];
    int b,d,e,i,j;
    scanf("%s",&a);
    scanf("%d",&b);
    for(i=0;i<b;i++){
        scanf("%s %d %d",&c,&d,&e);
        if(strcmp(&c,"print")==0){
            for(j=d;j<=e;j++)
                printf("%c",a[j]);
            printf("\n");}
        if(strcmp(&c,"replace")==0){
            scanf("%s",&f);
            for(j=d;j<=e;j++)
                a[j] = f[j-d];}
        if(strcmp(&c,"reverse")==0){
            for(j=d;j<=e;j++)
                m[j] = a[j];
            for(j=d;j<=e;j++)
                a[j] = m[d+e-j];}
    }
    return 0;
}


Measured memory_bytes: 2096
result = []
loop do
    input = gets.chomp!.to_i
    ary = []
    break unless input != 0

    input.times do
        ary << gets.chomp!.to_i
    end

    ary.sort!{|a, b| a<=>b}
    ary.delete_at(0)
    ary.delete_at(ary.length-1)
    
    sum = 0
    ary.each do |i|
        sum += i
    end
    
    result << sum / ary.length
end

result.each do |r|
    p r
end

Measured memory_bytes: 8628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[][] d = new int[n][2];

        for (int i = 0; i < n; i++) {
            d[i][0] = sc.nextInt();
            d[i][1] = sc.nextInt();
        }

        boolean isAns = false;
        for (int i = 0; i < n-2; i++) {
            boolean isTmp = true;

            for (int j = 0; j < 3; j++) {
                if (d[i+j][0] != d[i+j][1])
                    isTmp = false;
            }

            if (isTmp == true)
                isAns = true;
        }

        System.out.println(isAns ? "Yes" : "No");
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 32972
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		//int N = in.nextInt();
		//int K = in.nextInt();
		String c = in.nextLine();
		String d = in.nextLine();
		d = new StringBuilder(d).reverse().toString();
		/*for(int i=0; i<N; i++) {
			int x = in.nextInt();
			int d = Math.abs(x-K);
			if(Math.abs(x) < d) {
				sum += 2*x;
			}else {
				sum += 2*d;
			}
		}*/
		if(c.equals(d)) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		
		in.close();
	}
}

Measured memory_bytes: 22612
#include <cstdio>
#include <algorithm>

const int MAXN = 100000 + 10;

int n;
int pre[MAXN << 1], to[MAXN << 1], wcol[MAXN << 1], head[MAXN], wcnt;
int fa[MAXN], col[MAXN];

inline void addedge(int u, int v) {
	wcnt++;
	pre[wcnt] = head[u];
	head[u] = wcnt;
	to[wcnt] = v;
} 
inline void add2edge(int u, int v) {
	addedge(u, v);
	addedge(v, u);
}

#define v to[i]
void dfs(int u) {
	static int colcnt[MAXN];
	int i;
	
	for(i=head[u]; i; i=pre[i]) {
		if(fa[u] ^ v) {
			colcnt[u]++;
			if(colcnt[u] == col[u])
				colcnt[u]++;
			col[v] = wcol[i] = colcnt[u];
			fa[v] = u;
			dfs(v);
		}
	}
}
#undef v

int main() {
	int i, u, v, maxcol = 0;
	
	scanf("%d", &n);
	for(i=1; i<n; i++) {
		scanf("%d %d", &u, &v);
		add2edge(u, v);
	}
	
	dfs(1);
	for(i=1; i<=wcnt; i++)
		maxcol = std::max(maxcol, wcol[i]);

	printf("%d\n", maxcol);
	for(i=1; i<=wcnt; i++) 
		if(wcol[i]) 
			printf("%d\n", wcol[i]);
	return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int toInt(char c)
{
	//cout << c << endl;
	return (int)(c - '0');
}
int main()
{
	int n;
	while (cin >> n && n != 0)
	{
		vector<pair<int, int> > input;
		for (int i = 0; i < n; i++)
		{
			char line[15];
			pair<int, int> newRange;
			cin >> line;
			int hour = toInt(line[0]) * 10 + toInt(line[1]);
			int minute = toInt(line[3]) * 10 + toInt(line[4]);
			int second = toInt(line[6]) * 10 + toInt(line[7]);
			newRange.first = hour * 60 * 60 + minute * 60 + second;
			char line2[15];
			cin >> line2;
			hour = toInt(line2[0]) * 10 + toInt(line2[1]);
			minute = toInt(line2[3]) * 10 + toInt(line2[4]);
			second = toInt(line2[6]) * 10 + toInt(line2[7]);
			newRange.second = hour * 60 * 60 + minute * 60 + second;
			input.push_back(newRange);
		}

		sort(input.begin(),input.end());

		vector<pair<int, int> > out[10000 + 1];
		int vectorIndex = 0;
		for (int i = 0; i < n; i++)
		{
			bool flag = false;
			for (int j = 0; j < vectorIndex; j++)
			{
				bool f = false;
				for (int k = 0; k < out[j].size(); k++)
				{
					if (input.at(i).first >= out[j].at(k).first && input.at(i).first < out[j].at(k).second ||
						input.at(i).second > out[j].at(k).first && input.at(i).second <= out[j].at(k).second)
					{
						f = true;
						break;
					}
				}

				if (!f)
				{
					out[j].push_back(input.at(i));
					flag = true;
					break;
				}
			}

			if (!flag)
			{
				out[vectorIndex++].push_back(input.at(i));
			}
		}
		cout << vectorIndex << endl;
	}
	return 0;
}

Measured memory_bytes: 1640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var LR = ReadLine().Split().Select(int.Parse).ToArray();
        var L = LR[0];
        var R = LR[1];
        var l = L % 2019;
        var r = R % 2019;
        var ans = R - L >= 2018 ? 0 : l > r ? 0 : 2018;
        for (var i = l; i <= r; i++)
        {
            for (var j = i + 1; j <= r; j++)
            {
                ans = Min(ans, i * j % 2019);
            }
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 13268
package main

import (
	"fmt"
)

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

	as := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}

	for i := range as {
		if as[i] == 0 {
			fmt.Println(0)
			return
		}
	}

	ret := 1
	for i := 0; i < n; i++ {
		if as[i] <= 1000000000000000000/ret {
			ret *= as[i]
		} else {
			fmt.Println(-1)
			return
		}

	}

	fmt.Println(ret)
}

Measured memory_bytes: 6320
k, n = map(int, input().split())
a = list(map(int, input().split()))

max_kyori = 0
a.append(k + a[0])

for i in range(1, n+1):
    kyori = a[i] - a[i-1]
    if(kyori > max_kyori):
        max_kyori = kyori

print(k - max_kyori)


Measured memory_bytes: 99988
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    ll n;
    set<ll> key;
    map<ll, ll>  cnt;
        cin >> n;
    for(int i=0; i<n; i++){
        ll x; cin >> x;
        key.insert(x);
        cnt[x] += 1;
    }
    ll ans=0;
    for(auto x: key){
        if(cnt[x] == x) continue;
        if(x<cnt[x]){
            ans += cnt[x]-x;
        }else{
            ans += cnt[x];
        }
    }
    cout << ans << endl;
}
    

Measured memory_bytes: 10752
private class ModInt(x: Long) {

    companion object {
        const val MOD = 1e9.toLong() + 7
    }

    val x = (x % MOD + MOD) % MOD

    operator fun plus(other: ModInt): ModInt {
        return ModInt(x + other.x)
    }

    operator fun minus(other: ModInt): ModInt {
        return ModInt(x - other.x)
    }

    operator fun times(other: ModInt): ModInt {
        return ModInt(x * other.x)
    }

    operator fun div(other: ModInt): ModInt {
        return this * other.inv()
    }

    fun pow(exp: Long): ModInt {
        if (exp == 0L) return ModInt(1L)
        var a = pow(exp shr 1)
        a *= a
        if (exp and 1L == 0L) return a
        return this * a
    }

    fun inv(): ModInt {
        return this.pow(MOD - 2)
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as ModInt

        if (x != other.x) return false

        return true
    }

    override fun hashCode(): Int {
        return x.hashCode()
    }

    override fun toString(): String {
        return "$x"
    }

}

fun main(args: Array<String>) {
    val (n, a, b) = readLine()!!.split(' ').map { it.toLong() }
    val comb = Array(200001) { ModInt(1) }
    for (i in 1 until comb.size) {
        comb[i] = ModInt(n - i + 1) / ModInt(i.toLong()) * comb[i - 1]
    }
    println(ModInt(2).pow(n) - comb[a.toInt()] - comb[b.toInt()] - ModInt(1))
}


Measured memory_bytes: 122516
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>A(N);
    rep(i, N)cin >> A[i];
    sort(A.begin(), A.end());
    cout << A[N - 1] - A[0] << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  int n; std::cin >> n;
  std::vector<int> l(n); REP(i,n) std::cin >> l[i];
  sort(ALL(l));
  int ans = 0;
  REP(i,n-1) FOR(j,i+1,n-1) {
    if (i == n-1 || j == n-1) continue;
    int a = l[i],b = l[j]; // 問題分でのa,b a < b

    // c < a + bを二分探索
    int left = j+1, right = n;
    while (left+1 < right) {
      int center = (left+right)/2, sum = a + b;
      if (l[center] < sum) left=center;
      else right = center;
    }
    // c > b - cを二分探索
    int LEFT = j,RIGHT = left;
    while (LEFT+1 < RIGHT) {
      int CENTER = (LEFT+RIGHT)/2, sub = b - a;
      if (l[CENTER] <= sub) LEFT = CENTER;
      else RIGHT = CENTER;
    }
    // std::cout << "a " << a << "\tb " << b << "\tleft " << l[RIGHT] << "\tright " << l[left] << '\n';
    // std::cout << a+b << '\n';
    // std::cout << "left " << left << "\tRIGHT" << RIGHT << '\n';
    if (left == j+1) {
      int c = l[left];
      if (c >= a + b) continue;
    }
    if (RIGHT == n-1){
      int c = l[RIGHT];
      if (c <= b - a) continue;
    }
    ans+=left-RIGHT+1;
    // std::cout << "ans " << ans << '\n';
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

vector<string> split(const string &str, char delim){
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos){
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}


int main()
{
	string s;
	int a[4];
	memset(a,0,sizeof(a));
	while(cin >> s)
	{
		vector<string> _s = split(s,',');
		if(_s[1] == "A") a[0]++;
		if(_s[1] == "B") a[1]++;
		if(_s[1] == "AB") a[2]++;
		if(_s[1] == "O") a[3]++;
	}

	rep(i,4) cout << a[i] << endl;

	return 0;
}

Measured memory_bytes: 1196
N = int(input())

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

list.sort(key=lambda x:x[1])
  
result='Yes'
time=0
for i in range(len(list)):
  time+=list[i][0]
  if(time>list[i][1]):
    result='No'
    
print(result)

Measured memory_bytes: 53600
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }

  if(b==0){
    return a;
  }

  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }

  return b;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  long int n;
  scanf("%ld",&n);

  long int ans=0;
  long int m=0;
  
  for(long int i=0;i<n;i++){
    long int now;
    scanf("%ld",&now);

    if(m<=now){
      m=now;
    }
    else{
      ans+=(m-now);
    }
  }

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

  return 0;
}

Measured memory_bytes: 1704
s=input()
t=input()
S=[]
T=[]
for i in range(len(s)):
    S.append(s[i])
for i in range(len(t)):
    T.append(t[i])
S.sort()
T.sort(reverse=True)
ST=[]
ST.append(''.join(S))
ST.append(''.join(T))
ss=ST[0]
tt=ST[1]
ST.sort()
if ST[0]==ss and ST[1]==tt and s!=t:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int N=305;
const ll mod=1e9+7;
ll dp[N][N][N];
bool is0[N][N][N];
int n;

void make_zeros(int l,int r,int x){
	vector<int>vec;
	FER(i,1,r)FER(j,i+1,r){
		vec.clear();
		vec.pb(i);vec.pb(j);vec.pb(r);
		do{
			int cnt=0;
			for(int val:vec)if(val>=l)cnt++;
			if(cnt!=x)is0[vec[0]][vec[1]][vec[2]]=true;
		}while(next_permutation(all(vec)));
	}
	FER(i,1,r){
		vec.clear();
		vec.pb(0);vec.pb(i);vec.pb(r);
		do{
			int cnt=0;
			for(int val: vec)if(val>=l)cnt++;
			if(cnt!=x)is0[vec[0]][vec[1]][vec[2]]=true;
		}while(next_permutation(all(vec)));
	}
	vec.clear();
	vec.pb(0);vec.pb(0);vec.pb(r);
	do{
		int cnt=0;
		for(int val: vec)if(val>=l)cnt++;
		if(cnt!=x)is0[vec[0]][vec[1]][vec[2]]=true;
	}while(next_permutation(all(vec)));
}

void MOD(ll &a){
	if(a>=mod)a-=mod;
}



int main(){	
	fastio;
	int q;cin>>n>>q;
	memset(dp,0,sizeof(dp));
	memset(is0,false,sizeof(is0));
	dp[0][0][0]=1;
	while(q--){
		int l,r,x;cin>>l>>r>>x;
		make_zeros(l,r,x);
	}
	FER(i,1,n+1)FER(j,1,n+1)FER(k,1,n+1)
		if(i==j||j==k||i==k)is0[i][j][k]=true;

	ll ans=0;
	
	FER(i,0,n+1)FER(j,0,i+1)FER(k,0,j+1){
		vector<int>vec;
		vec.pb(k);vec.pb(j);vec.pb(i);
		int nx=i+1;
		do{
			if(!is0[nx][vec[1]][vec[2]]){
				dp[nx][vec[1]][vec[2]]+=dp[vec[0]][vec[1]][vec[2]];
				//dp[nx][vec[1]][vec[2]]%=mod;
				MOD(dp[nx][vec[1]][vec[2]]);
			}
			if(!is0[vec[0]][nx][vec[2]]){
				dp[vec[0]][nx][vec[2]]+=dp[vec[0]][vec[1]][vec[2]];
				//dp[vec[0]][nx][vec[2]]%=mod;
				MOD(dp[vec[0]][nx][vec[2]]);
			}
			if(!is0[vec[0]][vec[1]][nx]){
				dp[vec[0]][vec[1]][nx]+=dp[vec[0]][vec[1]][vec[2]];
				//dp[vec[0]][vec[1]][nx]%=mod;
				MOD(dp[vec[0]][vec[1]][nx]);
			}
		}while(next_permutation(all(vec)));
	}

	//FER(r,0,n+1){
	//	FER(g,0,n+1){
	//		FER(b,0,n+1)cout<<dp[r][g][b]<<" ";
	//		cout<<endl;
	//	}
	//	cout<<endl;
	//}


	FER(r,0,n+1)FER(g,0,n+1)FER(b,0,n+1){
		int mx=max(r,max(g,b));
		if(mx==n){
			ans+=dp[r][g][b];
			MOD(ans);
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 249728
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{
    while (true) {
        string s;
        int m;
        
        cin >> s;
        if (s == "-") {
            break;
        }
        
        cin >> m;
        
        for (int i = 0; i < m; i++) {
            int h;
            cin >> h;
            s = s.substr(h, s.size()) + s.substr(0, h);
        }
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
  string s;
  
  cin>>s;
  string front="";
  string back=s;


  int q;
  cin>>q;

  int t;
  int f;
  bool revflag=false;
  string c;
  for(int i=0;i<q;i++){
    cin>>t;
    switch(t){
      case 1:
        revflag=!revflag;
        break;
      case 2:
        cin>>f>>c;
        switch (f) {
          case 1:
            if(revflag){
              back+=c;
            }
            else{
              front+=c;
            }
            break;
          case 2:
            if(revflag){
              front+=c;
            }
            else{
              back+=c;
            }
            break;
        }
        break;
    }
  }
  if(revflag){
    reverse(back.begin(), back.end());
    cout<<back+front;
  }
  else{
    reverse(front.begin(), front.end());
    cout<<front+back;
  }  
}

Measured memory_bytes: 1500
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    ll count[1000][1000]={};
    REP(i,0,n+1){
	int cp=i;
	int ma,mi;
	mi=i%10;
	while(cp>=10){
	    cp/=10;
	}
	ma=cp%10;
	count[ma][mi]++;
    }
    ll ans=0;
    REP(i,0,n+1){
	int cp=i;
	int ma,mi;
	if(i%10!=0){
	    mi=i%10;
	    while(cp>=10){
		cp/=10;
	    }
	    ma=cp%10;
	    ans+=count[mi][ma];
	}
    }
    cout<<ans<<'\n';
    return(0);
}


Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  if (s == "SUN"){
    cout << "7\n";
  }
    if (s == "MON"){
    cout << "6\n";
  }
    if (s == "TUE"){
    cout << "5\n";
  }
    if (s == "WED"){
    cout << "4\n";
  }
    if (s == "THU"){
    cout << "3\n";
  }
    if (s == "FRI"){
    cout << "2\n";
  }
      if (s == "SAT"){
    cout << "1\n";
  }
  return 0;   
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s, s2;
    cin >> s >> s2;
    reverse(s2.begin(), s2.end());
    if (s2 == s) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <set>
#include <utility>

using namespace std;

constexpr static int MAXN = 1e6;

int n;
int a[MAXN];
int64_t cnt[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);

    set <pair <int, int>> s;
    for (int i = 0; i < n; i++)
        s.insert({a[i], i});

    int prv = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] <= prv)
            continue;

        auto it = s.begin();
        while (it != s.end() && it->first <= a[i]) {
            cnt[i] += it->first - prv;
            s.erase(it);
            it = s.begin();
        }
        cnt[i] += 1LL * s.size() * (a[i] - prv);
        prv = a[i];
    }
    for (int i = 0; i < n; i++)
        printf("%lld\n", cnt[i]);
}


Measured memory_bytes: 10624