akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

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

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int n, m;
string s;
const int MAX = 200000;
vector<vector<int>> edges(MAX);
vector<int> numA(MAX), numB(MAX);
vector<bool> deleted(MAX);

void del(int i) {
	if (deleted[i]) {
		return;
	}

	deleted[i] = true;
	for (auto j : edges[i]) {
		if (deleted[j]) {
			continue;
		}

		(s[i] == 'A' ? numA[j] : numB[j])--;

		if (numA[j] == 0 || numB[j] == 0) {
			del(j);
		}
	}
}

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

	cin >> n >> m >> s;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;

		edges[a].emplace_back(b);
		edges[b].emplace_back(a);
		(s[b] == 'A' ? numA[a] : numB[a])++;
		(s[a] == 'A' ? numA[b] : numB[b])++;
	}

	for (int i = 0; i < n; i++) {
		if (numA[i] == 0 || numB[i] == 0) {
			del(i);
		}
	}

	for (int i = 0; i < n; i++) {
		if (!deleted[i]) {
			cout << "Yes" << endl;
			return 0;
		}
	}

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


Measured memory_bytes: 17232
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;

int main(void){
    string S,T;
    cin >> S >> T;
    vector<char> P(26, 'A');
    vector<int> cntS(26, 0);
    vector<int> cntT(26, 0);
    bool l = true;
    
    for(int i = 0; i < S.size(); i++){
        cntS.at(S.at(i) - 'a')++;
        cntT.at(T.at(i) - 'a')++;
    }
    sort(cntS.begin(), cntS.end());
    sort(cntT.begin(), cntT.end());
    for(int i = 0; i < 26; i++){
        if(cntS.at(i) != cntT.at(i)){
            l = false;
        }
    }
    
    
    
    for(int i = 0; i < S.size(); i++){
        int a = S.at(i) - 'a';
        if(P.at(a) == 'A'){
            P.at(a) = T.at(i);
        }else{
            if(P.at(a) != T.at(i)){
                l = false;
            }
        }
    }
    
    
    
    if(l){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    int a;
    set<int> st;
    rep(i,3) cin >> a, st.insert(a);
    pr(sz(st));
}

Measured memory_bytes: 256
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	n, d := readInt(), readInt()

	ans := 0
	i := 0
	for i < n {
		i += 2*d + 1
		ans++
	}
	fmt.Println(ans)
}


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

int main(void){
    int N, K;
    cin >> N;
    cin >> K;
    int ball[N];
    int sum = 0;

    for(int i = 0; i < N; i++)
        cin >> ball[i];

    for(int i = 0; i < N; i++){
        if(ball[i] <= abs(K-ball[i]))
            sum += ball[i]*2;
        else
            sum += abs(K-ball[i])*2;
    }

    cout << sum << endl;
    return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long N,K,i,ans=0,count=0,cmp=0;
    cin >> N >> K;
    long long A[N],tmp[200000]={};
    for(i = 0; i < N; i++) {
        cin >> A[i];
        tmp[A[i]-1]++;
    }
    
    for(i = 0; i < N; i++) {
        if(tmp[i] != 0) {
            cmp++;
        }
    }
    if(cmp <= K) {
        cout << 0 << endl;
        return 0;
    }
    sort(tmp,tmp+200000);
    for(i = 0; i < 200000; i++) {
        if(tmp[i] != 0) {
            ans += tmp[i];
            count ++;
        }
        if(count == cmp - K) {
            cout << ans << endl;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3328
def cro(a,b):
    return a.real * b.imag - a.imag * b.real

"""class Point:
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def __repr__(self):
        return repr((self.x, self.y))
"""

n = int(input())
p = []
po = []
for i in range(n):
    x,y=list(int(x) for x in input().split()) 
    p.append(complex(x,y))

po=sorted(p, key=lambda x:(x.imag, x.real))
ps,j = [0]*(n+1),0


for i in range(n):
    while j > 1 and cro(ps[j-1]-ps[j-2],po[i]-ps[j-1]) < 0:
        j-=1
    ps[j] = po[i]
    j+=1

l = j

for i in reversed(range(n-1)):    
    while j > l and cro(ps[j-1]-ps[j-2],po[i]-ps[j-1]) < 0:
        j-=1
    ps[j] = po[i]
    j+=1
 
k = ps[0:j-1]

print(len(k))

for i in k:
    print(int(i.real),int(i.imag))




Measured memory_bytes: 22948
public class Main {
  public static void main(String[] args) {
	java.util.Scanner scanner = new java.util.Scanner(System.in);
	int n = scanner.nextInt();
	long[] a = new long[n];
	for (int i = 0; i < n; i++) {
		a[i] = scanner.nextLong();
	}
	
	int count = 0; // 2で割った回数
	while(true) {
		boolean hasOdd = false;
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 != 0) {
				hasOdd = true;
				break;
			}
		}
		if (hasOdd) {
			break;
		}
		for (int i = 0; i < n; i++) {
			a[i] = a[i] / 2;
		}
		count++;
	}
	System.out.println(count);
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  
  sort(a.begin(), a.end());
  
  cout << a[n/2] - a[n/2 - 1];
  
  return 0;
}

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

S, P = [], []
t = []
for i in range(N):
    s, p = input().split()
    S.append(s), P.append(int(p))
    t.append((s, int(p)))

ss = list(set(S))
ss.sort()

a = []
b = []
for i in ss:
    for s, p in t:
        if i == s:
            a.append(p)
    b.extend(sorted(a, reverse=True))
    a = []

for i in range(len(b)):
    for j in range(len(P)):
        if b[i] == P[j]:
            print(j+1)
            break

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 100010;

inline int in() {int x; scanf("%d",&x); return x;}
inline ll lin() {ll x; scanf("%lld",&x); return x;}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

ll inp[5];

int main(){
    for(int i = 1; i <= 3; i++) inp[i] = lin();
    sort(inp + 1, inp + 4);
    int k = in();
    for(int i = 1; i <= k; i++) inp[3] *= 2ll;
    cout << inp[1] + inp[2] + inp[3] << '\n';
}


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

vector<int> change(const vector<int>& a, const vector<int>& b) {
	int n = a.size();
	vector<int> res(n);
	for (int i = 0; i < n; i++) {
		res[i] = a[b[i]];
	}
	return res;
}

vector<int> Pow(vector<int> a, int x) {
	int n = a.size();
	vector<int> res(n);
	for (int i = 0; i < n; i++) {
		res[i] = i;
	}
	while (x) {
		if (x & 1) {
			res = change(res, a);
		}
		a = change(a, a);
		x >>= 1;
	}
	return res;
}

int it, len;
int N, L;
string S;

vector<int> sequence();
vector<int> repetition();
vector<int> operation();
int number();

vector<int> sequence() {
	vector<int> res(N * N);
	for (int i = 0; i < N * N; i++) {
		res[i] = i;
	}
	while (it < len && S[it] != ')') {
		if (S[it] == '(') {
			res = change(res, repetition());
		}
		else {
			res = change(res, operation());
		}
	}
	return res;
}

vector<int> repetition() {
	assert(S[it++] == '(');
	auto res = sequence();
	assert(S[it++] == ')');
	return Pow(res, number());
}

vector<int> operation() {
	vector<int> res(N * N);
	for (int i = 0; i < N * N; i++) {
		res[i] = i;
	}
	auto tmp = res;
	char c = S[it++];
	int cnt = number() - 1;
	switch (c) {
	case 'L':
		for (int i = 0; i < N; i++) {
			res[cnt * N + i] = tmp[cnt * N + (i + 1) % N];
		}
		break;
	case 'R':
		for (int i = 0; i < N; i++) {
			res[cnt * N + i] = tmp[cnt * N + (i + N - 1) % N];
		}
		break;
	case 'U':
		for (int i = 0; i < N; i++) {
			res[i * N + cnt] = tmp[(i + 1) % N * N + cnt];
		}
		break;
	case 'D':
		for (int i = 0; i < N; i++) {
			res[i * N + cnt] = tmp[(i + N - 1) % N * N + cnt];
		}
		break;
	}
	return res;
}

int number() {
	int res = 0;
	while (it < len && isdigit(S[it])) {
		res = res * 10 + S[it++] - '0';
	}
	return res;
}

int main()
{
	cin >> N >> L >> S;
	len = S.size();
	vector<int> tmp = sequence();
	vector<int> res(N * N);
	for (int i = 0; i < N * N; i++) {
		res[i] = i + 1;
	}
	res = change(res, tmp);
	for (int i = 0; i < N * N; i++) {
		cout << res[i] << " \n"[(i + 1) % N == 0];
	}
	return 0;
}

Measured memory_bytes: 16120
#include <bits/stdc++.h>
using namespace std;
#define For(I,A,B) for(int I=(A); I < (B); ++I)
int c[1005][1005];
int main()
{
int t;
string p;
cin>>t;
getline(cin,p);
while(t--){

int x,y,z,k=0,l,i,j;
string a,b,q="o",r="o";

 For(i,0,1005)
 For(j,0,1005)
 c[i][j]=0;

 getline(cin,a);
 getline(cin,b);
 x=a.length();
 y=b.length();

  For(i,0,x) q=q+a[i];

  For(i,0,y) r=r+b[i];
 For(i,1,x+1)
 For(j,1,y+1)
 {
     if(q[i]==r[j]) c[i][j]=c[i-1][j-1]+1;
     else  c[i][j]=max(c[i-1][j],c[i][j-1]);
 }
    cout<<c[x][y]<<endl;

}

    return 0;
}

Measured memory_bytes: 7092
N=int(input())
X=[[] for _ in range(N)]

for a in range(N):
  for _ in range(int(input())):
    x,y=map(int,input().split())
    X[a].append([x-1,y])

ans=[]
for i in range(2**N):
  judge=True
  count=0
  total=format(i,"b").count("1")
  for j in range(N):
    if (i>>j)&1==1:
      for k in X[j]:
        a,b=k[0],k[1]
        if (i>>a)&1==1 and b==0:
          judge=False
        elif (i>>a)&1!=1 and b==1:
          judge=False
  else:
    if judge:
      ans.append(total)

print(max(ans))

Measured memory_bytes: 3444
// Create by JJL
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <set>
#include <queue>
#define fi first
#define se second
#define ll long long
#define maxn 4005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int c1[maxn],c2[maxn],B[maxn][maxn],W[maxn][maxn],n,x[maxn];
int x1[maxn],x2[maxn],cnt1,cnt2,dp[maxn][maxn];
char s[maxn],q;

inline void a1(int x,int val){for(int i=x;i<=n;i+=i&-i) c1[i]+=val;}
inline void a2(int x,int val){for(int i=x;i<=n;i+=i&-i) c2[i]+=val;}
inline int q1(int x){int res=0; for(int i=x;i;i-=i&-i) res+=c1[i]; return res;}
inline int q2(int x){int res=0; for(int i=x;i;i-=i&-i) res+=c2[i]; return res;}

int main()
{
	n=read(); rep(i,1,2*n) cin>>s[i],x[i]=read();
	rep(i,1,2*n)
	{
		if(s[i]=='B')
		{
			a1(x[i],1);
			rep(j,0,n) B[x[i]][j]=i-q1(x[i])-q2(j);
		}
		else
		{
			a2(x[i],1);
			rep(j,0,n) W[j][x[i]]=i-q1(j)-q2(x[i]);
		}
	}
	rep(i,0,n) rep(j,0,n) dp[i][j]=inf; dp[0][0]=0;
	rep(i,0,n) rep(j,0,n)
	{
		if(i!=0) dp[i][j]=min(dp[i][j],dp[i-1][j]+B[i][j]);
		if(j!=0) dp[i][j]=min(dp[i][j],dp[i][j-1]+W[i][j]);
	}
	cout<<dp[n][n]<<endl;
	return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  
  cout<<vec.at(n-1)-vec.at(0)<<endl;
}


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

int main()
{
    int cnt = 0;
    string S;
    // 
    cin >> S;
    //
    for(int i = 0;i<4;i++)
    {
        if(S[i] == '+') cnt++;
        else cnt--;
    }
    cout << cnt << endl;
}

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

class E
{
	static void Main()
	{
		var M = 1000000007;
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var k = h[1];

		var map = new int[h[0] + 1].Select(_ => new List<int>()).ToArray();
		foreach (var r in new int[h[0] - 1].Select(_ => read()))
		{
			map[r[0]].Add(r[1]);
			map[r[1]].Add(r[0]);
		}

		var u = new bool[h[0] + 1];
		var q = new Stack<int>();
		u[1] = true;
		q.Push(1);

		long c = k;
		while (q.Any())
		{
			var p = q.Pop();
			c = c * ModNpr(k - (p == 1 ? 1 : 2), map[p].Count - (p == 1 ? 0 : 1), M) % M;

			foreach (var np in map[p])
			{
				if (u[np]) continue;
				u[np] = true;
				q.Push(np);
			}
		}
		Console.WriteLine(c);
	}

	static long ModNpr(int n, int r, int mod)
	{
		if (n < r) return 0;
		for (long x = 1, i = n - r; ; x = x * ++i % mod) if (i >= n) return x;
	}
}


Measured memory_bytes: 33020
S = input()
N = len(S)
for i in range(len(S)):
    S = S[0:-1]
    if len(S)%2 == 0:
        if S[0:len(S)//2] == S[len(S)//2:len(S)]:
            ans = i+1
            break
    else:
        pass
print(N - ans)

Measured memory_bytes: 9052
#include<bits/stdc++.h>
using namespace std;
bool chiahet(string s){
	int sol=0;
	for (char x:s) sol+=x-'0';
	return sol%9==0;
}
int main (){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	if (chiahet(s)) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3744
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;
void solve()
{
	int n;
	string s;
	cin>>n;
	cin>>s;
	int cnt = 0;
	int abc = 0;
	int i = 2;
	while(i < n){

		if(s[i] == 'C' && s[i-1] == 'B' && s[i-2] =='A'){
			cnt++;
		}
		i++;
	}
	cout<<cnt<<endl;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;

}
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    int a, b; cin >> a >> b;
    if(a < b){
        cout << "a < b" << endl;
    }else if(a > b){
        cout << "a > b" << endl;
    }else{
        cout << "a == b" << endl;
    }
	return 0;
}



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


typedef  long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;


#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=2e5+5;
ll mod=1e9+7;

ll mul (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll add (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a+b+mod)%mod;
}
ll fastpow(ll b, ll p)
{
    if(p==0)
        return 1;
    ll ans=fastpow(b,p/2);
    ans=mul(ans,ans);
    if(p%2)ans=mul(ans,b);
    return ans;
}
pair<int,int>arr[N];
int main()
{
    FIO
    priority_queue<int,vector<int>,greater<int>> q;
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        q.push(x);
    }
    for(int i=0;i<m;i++)
        cin>>arr[i].second>>arr[i].first;
    sort(arr,arr+m);
   for(int i=m-1;i>=0;i--)
   {
       if(q.top()>=arr[i].first)
        break;
       while(q.top()<arr[i].first&&arr[i].second>0)
       {
           q.pop();
           q.push(arr[i].first);
           arr[i].second--;
       }
   }
   ll ans=0;
   while(q.size())
    ans+=q.top(),q.pop();
   cout<<ans;






    return 0;
}



Measured memory_bytes: 4448
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    int x;
    int a;
    int b;
    cin >> x >> a >> b ;
    
    if(a>=b){
        cout << "delicious" << endl;
    }else if(a+x<b){
        cout << "dangerous" << endl;
    }else{
        cout << "safe" << endl;
    };
    
    return 0;
}

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

//1:昇順	0:降順
int sort(char *num, int kind);
void swap(char *a, char *b);
void itostr(int n, char *str);

int main(void)
{
	char num[5];
	int L, S;
	int count;
	
	while (scanf("%s", num)){
		
		if (strcmp(num, "0000") == 0){
			break;
		}
		else if (num[0] == num[1] && num[1] == num[2] && num[2] == num[3] && num[3] == num[0]){
			puts("NA");
			continue;
		}
		
		count = 0;
		
		while (1){
			
			if (strcmp(num, "6174") == 0){
				break;
			}
			
			L = sort(num, 0);
			S = sort(num, 1);
			itostr(L - S, num);
			count++;
		}
		
		printf("%d\n", count);
	}
	
	return (0);
}

int sort(char *num, int kind)
{
	int i, j;
	char *nptr;
	
	for (i = 0; i < 3; i++){
		for (j = 3; j > i; j--){
			if (kind == 1 && *(num + j - 1) > *(num + j)){
				swap(&num[j - 1], &num[j]);
			}
			else if (kind == 0 && *(num + j - 1) < *(num + j)){
				swap(&num[j - 1], &num[j]);
			}
		}
	}
	
	return (atoi(num));
}

void swap(char *a, char *b)
{
	char tmp;
	
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void itostr(int n, char *str)
{
	int i;
	
	for (i = 3, str[4] = '\0'; i >= 0; i--){
		str[i] = '0' + (n % 10);
		n /= 10;
	}
}



Measured memory_bytes: 2112
numq = int(input())
lis = [1]*100001
lis[0] = 0
lis[1] = 0
i = 2
while(i < 318):
  if lis[i] == 1:
    k = 2
    while(i*k < 100001):
      lis[i*k] = 0
      k += 1
  i += 1
lis2 = [0]*100001

for i in range(1,100001):
  if i % 2 == 1 and lis[i] == lis[(i+1)//2] == 1:
    lis2[i] = lis2[i-1] + 1
  else:
    lis2[i] = lis2[i-1]

for _ in range(numq):
  a,b = map(int,input().split())
  print(lis2[b] - lis2[a-1])


Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define init(x,y) memset(x,y,sizeof(x))

signed main() 
{
   // haha
    int n;
    cin>>n;
    string s;
    cin>>s;
    int prer[n+1];
    int preg[n+1];
    int preb[n+1];
    prer[0]=0;
    preg[0]=0;
    preb[0]=0;
    init(preg,0);
    init(prer,0);
    init(preb,0);
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R')
        prer[i+1]=1;
         if(s[i]=='G')
        preg[i+1]=1;
         if(s[i]=='B')
        preb[i+1]=1;
        prer[i+1]+=prer[i];
        preg[i+1]+=preg[i];
        preb[i+1]+=preb[i];
    }
   
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(s[i]==s[j])
            continue;
            if(s[i]=='R' && s[j]=='B')
            {
                ans+=(preg[n]-preg[j]);
                int in=j-i;
                if(j+in<n && s[j+in]=='G')
                ans--;
            }
            if(s[i]=='R' && s[j]=='G')
            {
                ans+=(preb[n]-preb[j]);
                int in=j-i;
                if(j+in<n && s[j+in]=='B')
                ans--;
            }
            if(s[i]=='G' && s[j]=='B')
            {
                ans+=(prer[n]-prer[j]);
                int in=j-i;
                if(j+in<n && s[j+in]=='R')
                ans--;
            }
            if(s[i]=='G' && s[j]=='R')
            {
                ans+=(preb[n]-preb[j]);
                int in=j-i;
                if(j+in<n && s[j+in]=='B')
                ans--;
            }
            if(s[i]=='B' && s[j]=='G')
            {
                ans+=(prer[n]-prer[j]);
                int in=j-i;
                if(j+in<n && s[j+in]=='R')
                ans--;
            }
            if(s[i]=='B' && s[j]=='R')
            {
                ans+=(preg[n]-preg[j]);
                int in=j-i;
                if(j+in<n && s[j+in]=='G')
                ans--;
            }
        }
    }
    cout<<ans;
    
    
    
   
}
    
    

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
#define NUM 6
int main(){
    int n;
    cin >> n;
    int high[] = {165,170,175,180,185,200};
    int a[6] = {};
    for(int i = 0; i < n; i++){
        double h;
        cin >> h;
        for(int j = 0; j < NUM; j++)if(h < high[j]){
            a[j]++;
            break;
        }
    }
    for(int i = 0; i < NUM; i++){
        cout << i+1 << ":";
        for(int j = 0; j < a[i]; j++)cout << "*";
        cout << endl;
    }
}



Measured memory_bytes: 3164
#include <iostream>
#include <string>

using namespace std;

int main(void){
    // Your code here!
    while(true){
        int N;
        cin >> N;
        if(N == 0){
            break;
        }
        int sumA = 0;
        int sumB = 0;
        for(int i=0;i<N;i++){
            int A,B;
            cin >> A >> B;
            if(A > B){
                sumA += A + B;
            }else if(A < B){
                sumB += A + B;
            }else{
                sumA += A;
                sumB += B;
            }
        }
        cout << sumA << " " << sumB << endl;
    }
    return 0;
}



Measured memory_bytes: 2980
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
//#include <boost/range/algorithm.hpp>

using namespace std;
using boost::irange;

// 定義
typedef long long     ll;
typedef pair<ll, ll>  P;
#define ALL(x)        (x).begin(),(x).end()
#define REP(i, n)     for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n) for (ll i = m ; i < (ll)n ; ++i)
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

// ライブラリ
namespace {
	ll Ceil(ll val, ll div)   { return (val + div - 1) / div; };
	ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; };
	ll FloorN(ll x, ll n) { return (x - x % n); };
	bool IsOdd(ll x)      { return ((x & 1) == 1); };
	bool IsEven(ll x)     { return ((x & 1) == 0); };
};

// 処理
void Solve()
{
	ll N = M_PI;
	cin >> N;
	string ans = "second";
	REP(i, N) {
		int a;
		cin >> a;
		if (IsOdd(a)) {
			ans = "first";
		}
	}
	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 256
fun main(ar: Array<String>?) {
    val i = System.`in`!!.reader(Charsets.US_ASCII).readLines()

    val il = i.flatMap { it.split(" ") }.let { IntArray(it.size) { id -> it[id].toInt() } }
    val m = il[2]
    val b = il[1]
    val a = il[0]
    var min = Int.MAX_VALUE
    for (xi in (0 until m).reversed()) {
        var xxa = 3 + a + b + xi * 3 + 2
        val p1 = -il[xxa] + il[3 + a + il[--xxa] - 1] + il[3 + il[--xxa] - 1]
        if (p1 < min) {
            min = p1
        }
    }
    var ma = Int.MAX_VALUE
    for (aai in (3 until 3 + a).reversed()) {
        val ai = il[aai]
        if (ai < ma) {
            ma = ai
        }
    }
    if (ma < min) {
        var mb = Int.MAX_VALUE
        for (bbi in (3 + a until 3 + a + b).reversed()) {
            val bi = il[bbi]
            if (bi < mb) {
                mb = bi
            }
        }
        val mr = ma + mb
        if (mr < min) {
            print(mr)
            return
        }
    }
    print(min)
}

Measured memory_bytes: 118956
fun main(args: Array<String>) {
    val mod = 1000000007L
    
    val N = readInputLine().toInt()
    val A = readInputLine().split(" ").map { it.toInt() }.sorted()

    var now = 0
    var cnt = 0

    if (N % 2 == 1) {
        now = 0
        cnt = 1
    } else {
        now = 1
        cnt = 0
    }
    
    for (a in A) {
        if (a != now) {
            if (cnt != 2) {
                println(0)
                return
            }
            now = a
            cnt = 1
        } else {
            cnt++
        }
    }
    
    if (cnt != 2) {
        println(0)
        return
    }
    
    var ans = 1L
    
    for (i in 1..N / 2) {
        ans *= 2L
        ans %= mod
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}



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

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

int main(){
    int h, w; cin >> h >> w;
    vector<string> maze(h);
    rep(i,h) cin >> maze[i];
    rep(i,h)rep(j,w){
        if(maze[i][j]=='#') continue;
        int count = 0;
        rep(dir,8){
            int ni = i + dx[dir];
            int nj = j + dy[dir];
            if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if(maze[ni][nj]=='#') count++;
        }
        maze[i][j] = char(count+'0');//??
    }
    rep(i,h)cout << maze[i] << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{
	public static void main(String[] args){
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
			try{

				//シャッフルした単語のリストを用意する。
				List<String> strList = new ArrayList<String>();

				while(true){

					//文字を読み取る。
					String strLine = insBR.readLine();
					if("-".equals(strLine)){
						break;
					}

					//シャッフル回数をリストにつめる。
					String strTime = insBR.readLine();
					int intTime = Integer.parseInt(strTime);
					List<Integer> intList = new ArrayList<Integer>();
					for(int i = 0; i < intTime; i++){
						String strShuffle = insBR.readLine();
						int intShuffle = Integer.parseInt(strShuffle);
						intList.add(intShuffle);
					}

					//仮の箱を用意する。
					List<String> actList = new ArrayList<String>();

					//単語を1文字ずつ区切る。
					String[] strWord = strLine.split("");

					//シャッフルした単語を初期化する。
					String strResult = "";

					//シャッフルする。
					for(int i = 0; i < intList.size(); i++){

						//シャッフル回数。
						int intTime2 = intList.get(i);

						//strResultを初期化する。
						strResult = "";

						//仮の箱のリストにつめる。
						int intNext = strLine.length() - intTime2;
						for(int j = 0; j < intTime2; j++){
							actList.add(strWord[j]);
						}

						//最初の文字をstrResultに足しこむ。
						for(int j = 0; j < intNext; j++){
							int intChange = j + intTime2;
							strResult += strWord[intChange];
						}

						//残りの文字をstrResultに足しこむ。
						for(int j = 0; j < actList.size(); j++){
							strResult += actList.get(j);
						}

						//strWord を strResult で初期化する。
						strWord = strResult.split("");

						//仮の箱のリストを空っぽにする。
						actList.clear();

					}

					//シャッフル回数のリストを空っぽにする。
					intList.clear();

					//シャッフルした単語をリストにつめる。
					strList.add(strResult);

				}

				//出力。
				for(int i = 0; i < strList.size(); i++){
					System.out.println(strList.get(i));
				}

			}catch(IOException e){
				e.printStackTrace();
			}catch(NumberFormatException e){
				e.printStackTrace();
			}

	}

}



Measured memory_bytes: 46056
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

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

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

    int a, b;
    cin >> a >> b;

    FOR(i, 1, 10000) {

        int ta = floor(i * 0.08);
        int tb = floor(i * 0.10);

        if (ta == a and tb == b) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}


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

using ll = long long;
const ll MOD = 1e9 + 7;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int N;
    cin >> N;
    vector<ll> x(N), f(N + 1, 1), v(N);
    rep(i, N) {
        cin >> x[i];
        f[i + 1] = (f[i] * (i + 1)) % MOD;
    }
    v[0] = f[N - 1];
    rep(i, N - 2) {
        v[i + 1] = (v[0] * mod_pow(i + 2, MOD - 2, MOD) + v[i]) % MOD;
        //cout << v[i + 1] << " ";
    }
    //cout << endl;
    /*
    vector<vector<ll>> v(N, vector<ll>(N, 0)), s(N, vector<ll>(N + 1, 0));
    v[0][0] = 1;
    s[0][1] = 1;
    rep(i, N - 1) {
        rep(j, i + 2) {
            v[i + 1][j] = (v[i][j] * (i + 1 - j)) % MOD;
            v[i + 1][j] += s[i][j];
            v[i + 1][j] %= MOD;
            v[i + 1][j] += (f[i + 1] * (j + 1)) % MOD;
            v[i + 1][j] %= MOD;
            s[i + 1][j + 1] = (s[i + 1][j] + v[i + 1][j]) % MOD;
            //cout << v[i + 1][j] << " ";
        }
        //cout << endl;
    }
    */
    ll ans = 0;
    rep(i, N - 1) {
        ans += (x[i + 1] - x[i]) * v[i];
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
#define ln(a) cout << (a) << endl
#define debug(a, n) rep(hoge, n) printf("%lld%c", a[hoge], hoge == (n) - 1? '\n' : ' ');
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define EPS 0.00000001

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using ILP = pair<int, ll>;

signed main() {
    int n;
    ll d, a;
    cin >> n >> d >> a;
    LP* b = new LP[n];
    rep(i, n) {
        ll x, h;
        cin >> x >> h;
        b[i] = LP(x, h % a == 0? h / a : h / a + 1);
    }
    sort(b, b + n);
    queue<ILP> v;
    ll num = 0;
    ll ans = 0;
    rep(i, n) {
        while(!v.empty() && v.front().first == i) {
            num -= v.front().second;
            v.pop();
        }
        if(b[i].second <= num) continue;
        ll tmp = -1;
        tmp = b[i].second - num;
        ans += tmp;
        num += tmp;
        v.push(LP(upper_bound(b, b + n, LP(b[i].first + d * 2, LINF)) - b, tmp));
    }

    ln(ans);
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
 
using namespace std;
 
void load(void);
void calc(void);
void output(void);

long long N, D, res = 0;

int main(){
	load();
	output();
	return 0;
}
 
void load(void){
	long long i, X, Y;
	cin >> N >> D;
	for(i = 0;i < N;i++){
		cin >> X >> Y;
		if(X * X + Y * Y <= D * D){
			res++;
		}
	}
}
 
void output(void){
	cout << res << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#define ll long long
using namespace std;
int main(void){
    ll n;
    cin>>n;
    ll ans = 0;
    for(ll i=1;i<=n;++i){
        if(i%3 != 0 && i%5 != 0){
            ans += i;
        }
    }cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return


ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////


int main(){

    ll x;
    cin >> x;

    rep(i,-200,200){
	rep(j,-200,200){
	    if(pow(i,5) - pow(j,5) == x){
		PS(i);P(j);
		ret 0;
	    }
	}
    }
    return  0;
}


Measured memory_bytes: 4064
#include <iostream>
#include <cmath>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    char alpha;
    cin >> alpha;
    if (alpha >= 'A' && alpha <= 'Z'){
        cout << 'A' << endl;
    }
    if (alpha >= 'a' && alpha <= 'z') {
        cout << 'a' << endl;
    }
    return 0;
}



Measured memory_bytes: 3588
using System;

namespace AtCoder
{
    class C_Otoshidama_085
    {
        public static void Main()
        {
            var inputs = Console.ReadLine().Split(' ');
            var num = int.Parse(inputs[0]);
            var price = int.Parse(inputs[1]);
            
            for (var yukichiNum = 0; yukichiNum <= num; ++yukichiNum)
            {
                for (var higuchiNum = 0; higuchiNum <= num; ++higuchiNum)
                {
                    var noguchiNum = num - yukichiNum - higuchiNum;
                    if (noguchiNum < 0) { break; }
                    if (yukichiNum * 10000 +
                        higuchiNum * 5000 +
                        noguchiNum * 1000 == price)
                    {
                        Console.WriteLine(yukichiNum + " " + higuchiNum + " " + noguchiNum);
                        return;
                    }
                }
            }

            Console.WriteLine("-1 -1 -1");
        }
    }
}


Measured memory_bytes: 13140
# -*- coding: utf-8 -*-
n = int(input())
w = list(map(int, input().split()))

w1 = [0 for _ in range(n)]
w2 = [0 for _ in range(n)]
w_ = w[::-1]

w1[0] = w[0]
w2[0] = w_[0]

for i in range(1, n):
    w1[i] = w[i] + w1[i-1]
    w2[i] = w_[i] + w2[i-1]

w2 = w2[::-1]

m = 1000000
for i in range(n-1):
    sub = abs(w1[i] - w2[i+1])
    m = min(m, sub)

print(m)


Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 3000;
int r, c;
LL memo[N+1][N+1][3+1];
LL v[N+1][N+1];
LL dp(int i, int j, int ct)
{
    if(!(1 <= i && i <= r && 1 <= j && j <= c))
        return 0;
    if(memo[i][j][ct]!=-1)
        return memo[i][j][ct];
    else
    {
        LL if_I_take = 0;
        if(ct > 0)
            if_I_take = max(dp(i+1,j,3),dp(i,j+1,ct-1))+v[i][j];
        return memo[i][j][ct] = max(if_I_take,max(dp(i+1,j,3),dp(i,j+1,ct)));
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    memset(v,0,sizeof v);
    int k; cin >> r >> c >> k;
    for(int i = 0; i < k; i++)
    {
        int x, y, val; cin >> x >> y >> val;
        v[x][y] = val;
    }
    memset(memo,-1,sizeof memo);
    cout<<dp(1,1,3)<<endl;

    cout<<flush;
    return 0;
}

Measured memory_bytes: 355988
def main():
    N, M = map(int, input().split())
    road = [0] * N
    for _ in range(M):
        a, b = map(lambda x: int(x) - 1, input().split())
        road[a] += 1
        road[b] += 1
    print('\n'.join(map(str, road)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38416
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N, K;
	cin >> N >> K;
	if (N % K == 0)cout << 0 << endl;
	else cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            while(n!=0){
                int max=0, min=1000;
                int average=0;
                for (int i = 0; i < n; i++) {
                    int scores = sc.nextInt();
                    average += scores;
                    if(scores >= max){
                        max=scores;
                    }
                    if(scores <= min){
                        min=scores;
                    }
                }
                average=average-max-min;
                average /= (n-2);
                System.out.println(average);
                n = sc.nextInt();
            }
        }
    }
}



Measured memory_bytes: 28684
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



#define roll_swap(x, a, b, c, d) swap(x.a, x.b), swap(x.b, x.c), swap(x.c, x.d);
template<class T> struct Dice {
    T top, front, right, left, back, bottom;
    
    Dice(T to = 1, T fr = 2, T ri = 3, T le = 4, T ba = 5, T bo = 6) 
        : top(to), front(fr), right(ri), left(le), back(ba), bottom(bo) { }
    void roll_right() { roll_swap((*this), top, left, bottom, right); }
    void roll_left() { roll_swap((*this), top, right, bottom, left); }
    void roll_front() { roll_swap((*this), top, back, bottom, front); }
    void roll_back() { roll_swap((*this), top, front, bottom, back); }
    void roll_cw() { roll_swap((*this), back, left, front, right); }
    void roll_ccw() { roll_swap((*this), back, right, front, left); }
    
    vector<Dice<T> > all_rotate() {
        vector<Dice> res(24);
        Dice<T> d;
        for (int i = 0; i < 6; ++i) {
            for (int j = 0; j < 4; j++) {
                res[i * 4 + j] = d;
                d.roll_cw();
            }
            if (i & 1) d.roll_front();
            else d.roll_right();
        }
        return res;    
    }
};
    

int n;
string str;

int main() {
    while (cin >> n) {
        if (n == 0) break;
    
        int res = 1;
        Dice<int> d;
        
        for (int i = 0; i < n; ++i) {
            cin >> str;
            if (str == "North") d.roll_back();
            else if (str == "East") d.roll_right();
            else if (str == "South") d.roll_front();
            else if (str == "West") d.roll_left();
            else if (str == "Right") d.roll_cw();
            else d.roll_ccw();
            
            res += d.top;
        }
        
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main(){
    int d,m;
    scanf("%d%d",&m,&d);
    int cnt=0;
    for(int i=1;i<=m;i++){
        for(int j=2;j<10;j++){
            for(int k=2;k<10;k++){
                if(j*k==i&&j*10+k<=d)
                    cnt++;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define NIL -2000000001
#define MAX 2000000

int main() {
  int n = 0;
  scanf("%d", &n);
  char str[n];
  scanf("%s", str);

  int sum = 0;
  for (int i = 1; i < n; i++) {
    if (str[i] == 'E') sum++;
  }

  int min = sum;
  for (int i = 1; i < n; i++) {
    if (str[i] == 'E') sum--;
    if (str[i-1] == 'W') sum++;
    if (sum < min) min = sum;
  }

  printf("%d\n", min);

  return 0;
}


Measured memory_bytes: 512
while (n=gets.chomp)!="0"
  id,d = 0,0
  n.to_i.times do
    p,d1,d2 = gets.split.map!(&:to_i)
    if d<d1+d2
      d=d1+d2
      id=p
    end
  end
  puts [id,d].join(' ')
end

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

int main(){
  string n;
  cin >> n;
  ll x=0,a=0;
  rep(i,n.size()){
      x+=n[i]-'0';
  }
  rep(i,n.size()){
      a+=(n[i]-'0')*pow(10,n.size()-i-1);
  }
  if(a%x==0) cout << "Yes" << endl;
  else cout << "No" <<endl;
}

Measured memory_bytes: 4008
import java.util.Scanner;

public class Main {
    
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
        long luca[]=new long [87];
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        luca[0]=2;
        luca[1]=1;
        for (int i = 2; i < luca.length; i++) {
		    luca[i]=luca[i-1]+luca[i-2];
		}
        System.out.println(luca[n]);
	}

}

Measured memory_bytes: 23892