akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            int N = Integer.parseInt(s);

            System.out.println(checkHarshad(s, N) ? "Yes" : "No");
        }
    }
    static boolean checkHarshad(String s, int n) {
        int x = 0;
        for (int i = 0; i < s.length(); i++)
            x += Character.getNumericValue(s.charAt(i));

        return n % x == 0;
    }
}


Measured memory_bytes: 23124
import java.util.Arrays; 
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			final int m = sc.nextInt();
			
			if(n == 0 && m == 0){
				break;
			}
			
			boolean[] is_legal = new boolean[n];
			String[] source_pattern = new String[n];
			String[] destination_pattern = new String[n];
			
			for(int i = 0; i < n; i++){
				final String act = sc.next();
				final String so = sc.next();
				final String de = sc.next();
				
				is_legal[i] = "permit".equals(act);
				source_pattern[i] = so.replaceAll("\\?", ".");
				destination_pattern[i] = de.replaceAll("\\?", ".");
				
				//System.out.println(is_legal[i] + " => " + source_pattern[i] + " : " + destination_pattern[i]);
			}
			
			LinkedList<String> list = new LinkedList<String>();
			
			for(int i = 0; i < m; i++){
				boolean ok = false;
				
				String from = sc.next();
				String to = sc.next();
				String mes = sc.next();
				
				for(int j = n - 1; j >= 0; j--){
					if(from.matches(source_pattern[j]) && to.matches(destination_pattern[j])){
						if(is_legal[j]){
							ok = true;
						}else{
							ok = false;
						}
						
						break;
					}
				}
				
				if(!ok){
					continue;
				}
				
				list.add(from + " " + to + " " + mes);
			}
			
			System.out.println(list.size());
			
			for(String str : list){
				System.out.println(str);
			}
			
		}
		
		sc.close();
	}
}

Measured memory_bytes: 13000
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

struct Info {
	int val;
	int dif;

	Info(int a, int b) {
		val = a;
		dif = b;
	}
};

bool cmp(const Info& a, const Info& b) {
	if (a.dif == b.dif) {
		return a.val < b.val;
	}
	else {
		return a.dif < b.dif;
	}
}

int main() {

	int X;
	int N;
	cin >> X >> N;

	vector<int> p(N, 0);
//	int p;
//	vector<Info> ans;

	for (int i = 0; i < N; i++) {
		cin >> p[i];
//		ans.push_back(Info(p, abs(X - p)));
	}
	
	bool jdg = false;
	int cnt = 0;
	int ans = 0;

	while (jdg == false) {
		if (p.end() == find(p.begin(), p.end(), X - cnt)) {
			jdg = true;
			ans = X - cnt;
		}
		else if (p.end() == find(p.begin(), p.end(), X + cnt)) {
			jdg = true;
			ans = X + cnt;
		}
		cnt += 1;
	}

//	sort(ans.begin(), ans.end(), cmp);

	cout << ans << endl;
//	cout << ans[0].val << endl;

	return 0;
}



Measured memory_bytes: 3628
S = input()
if S == 'SAT':
    print(1)
elif S == 'FRI':
    print(2)
elif S == 'THU':
    print(3)
elif S == 'WED':
    print(4)
elif S == 'TUE':
    print(5)
elif S == 'MON':
    print(6)
elif S == 'SUN':
    print(7)

Measured memory_bytes: 8980
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main(){
ll n,a;
cin>>n>>a;
cout<<n*n-a<<endl;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    int sol = 1;
    for (int i = 2; i < x; ++i)
    {
        int j = i * i;
        while (j <= x)
        {
            sol = max(sol, j);
            j *= i;
        }
    }
    cout << sol;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N+1);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> dist(N+1, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[1] = 0;
    que.push(1); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    if(dist[N]==2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 13168
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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 T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

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

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int a, b;
    cin >> a >> b;
    repr(i, 1, 100000) {
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

int main()
{
	int A = 0, B = 0;
	scanf("%d %d", &A, &B);
	printf("%d\n", (A*B));
	//yesno(ans);
	//okng(ans);
	return 0;
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e9 + 5;
double PI = 3.14159265358979323846;

void solve() {

    string a, b;
    cin >> a >> b;
    int na = a.length();
    int nb = b.length();

    vector<vector<ar<int, 3>>> dp(na + 1, vector<ar<int, 3>>(nb + 1, {0, 0, 0}));

    // so dp[i][j][0] = LCS till ith char of string a and jth char of string b;
    // dp[i][j][1] and dp[i][j][2] contains movement info i,e from where we came to pos (i,j)
    

    for (int i = 1; i <= na; i++) {
        for (int j = 1; j <= nb; j++) {
            if (a[i - 1] == b[j - 1]) {
                dp[i][j][0] = 1 + dp[i - 1][j - 1][0];
                dp[i][j][1] = i - 1;
                dp[i][j][2] = j - 1;
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                if (dp[i - 1][j][0] > dp[i][j - 1][0]) {
                    dp[i][j][0] = dp[i - 1][j][0];
                    dp[i][j][1] = i - 1;
                    dp[i][j][2] = j;
                } else {
                    dp[i][j][0] = dp[i][j - 1][0];
                    dp[i][j][1] = i;
                    dp[i][j][2] = j - 1;
                }
            }
        }
    }

    int x, y;
    x = na; y = nb;
    string s;
    while(x!=0 and y!=0){
        int tempx = dp[x][y][1];
        int tempy = dp[x][y][2];
        if(tempx == x-1 and tempy == y-1){
            assert(a[x-1] == b[y-1]);
            s+=a[x-1];
        }
        x = tempx;
        y = tempy;
    }

    reverse(all(s));
    cout << s << endl;

}

int32_t main()
{
    IOS
    // int T; cin >> T; while (T--)
    solve();
    return 0;
}


Measured memory_bytes: 108944
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;
    ll n=s.size();
    vector<int> t(n+1);
    rep(i,n) {
        if (s[i]=='<') t[i+1]=t[i]+1;
    }
    invrep(i,n) {
        if (s[i]=='>') t[i]=max(t[i],t[i+1]+1); 
    }
    ll ans=0;
    rep(i,n+1) ans+=t[i];
    cout << ans << endl;
    

   
    return 0;   
}

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

namespace AtTest.ABC_131
{
    class E
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];

            int max = (n - 1) * (n - 2) / 2;
            if (k > max)
            {
                WriteLine(-1);
                return;
            }

            int delta = max - k;
            int m = delta + n - 1;
            WriteLine(m);
            for (int i = 1; i < n ; i++)
            {
                WriteLine(1 + " " + (i + 1));
            }
            if (delta == 0) return;
            for(int i = 1; i < n; i++)
            {
                for(int j = i + 1; j < n; j++)
                {
                    WriteLine((i + 1) + " " + (j + 1));
                    delta--;
                    if (delta == 0) return;
                }
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

class Program {
    static string ReadLine() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    static void Main() {
        var xs = ReadInts();
        int x5 = 0, x7 = 0;
        foreach (var x in xs) {
            if (x == 5) x5++;
            if (x == 7) x7++;
        }
        if (x5 == 2 && x7 == 1) {
            Console.WriteLine("YES");
        }
        else {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 2776
#include<bits/stdc++.h>
#define ll long long
#define db double
#define lowbit(p) (p&(-p))
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define A first
#define B second
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
/*
一次操作可以选择一对相邻的且不同的,然后这样
ab->cc
ac->bb
bc->aa
*/

#define mo 998244353
#define M 200005
int a[M],n,sum;
char s[M];
void add(ll &a,ll b){
	a=(a+b)%mo;
}
struct P1{
	int res;
	map< string ,int >mark; 
	void dfs(string s){
		if (mark[s])return ;
		res++; mark[s]=1;
		int i;
		for (i=0;i<n-1;i++)if (s[i]!=s[i+1]){
			string ns=s;
//			cout<<s<<endl;
//			printf("%c %c\n",s[i],s[i+1]);
			if (s[i]=='a'){
				if (s[i+1]=='b')ns[i]=ns[i+1]='c';
				else ns[i]=ns[i+1]='b';
			}
			if (s[i]=='b'){	
				if (s[i+1]=='a')ns[i]=ns[i+1]='c';
				else ns[i]=ns[i+1]='a';
			}
			if (s[i]=='c'){
				if (s[i+1]=='a')ns[i]=ns[i+1]='b';
				else ns[i]=ns[i+1]='a';
			}
//			cout<<ns<<endl;
			dfs(ns);
		}
	}
	void solve(){
		string S="";
		int i;
		for (i=1;i<=n;i++)S+=s[i];	
		dfs(S);
		printf("%d\n",res);	
	}
}p1;
struct P2{
	ll dp[M][3][3][2];
	bool chk(){
		int i;
		for (i=1;i<n;i++)if (a[i]==a[i+1])return 0;
		return 1;
	}
	// i   lastc  sum  havesam  
	void cal(int x){
		for (int c=0;c<3;c++){
			for (int s=0;s<3;s++){
				for (int op=0;op<2;op++){
					for (int nc=0;nc<3;nc++){
						add(dp[x+1][nc][(s+nc)%3][(nc==c)||op],dp[x][c][s][op]);
					}
				}
			}
		}
	}
	void solve(){
		int i;
		ll res=0;
		for (i=0;i<3;i++)dp[1][i][i][0]=1;
		for (i=2;i<=n;i++){
			cal(i-1);
		}
		if (chk())res++;
		for (i=0;i<3;i++)res+=dp[n][i][sum][1];
		res=(res+mo)%mo;
		printf("%lld\n",res);
	}
}p2;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	freopen("1.in","r",stdin);
	scanf("%s",s+1);
	n=strlen(s+1);
	int i,flag=1;
	for (i=1;i<=n;i++){
		a[i]=s[i]-'a';
		sum+=a[i];
	}
	for (i=1;i<n;i++){
		if (a[i]!=a[i+1])flag=0;
	}
	if (flag){
		printf("1\n");
		return 0;
	}
	sum%=3;
	if (n<=3){
		p1.solve();
		return 0;
	}
	p2.solve();
	return 0;
}

Measured memory_bytes: 29312
#include<iostream>
#include<map>
#include <vector>
using namespace std;

int main(){
    int n,i;
    while(cin>>n,n){
        map<int,long long>m;
        vector<int>vec;
        long long p,q,s=0;
        while(n--){
            cin>>i>>p>>q;
            if(!m[i])vec.push_back(i);
            m[i]+=p*q;
        }
//        for (map<int,long long>::iterator it=m.begin(); it!=m.end(); ++it){
//            if(it->second>=1000000){
//                s=1;
//                cout<<it->first<<endl;
//            }
//        }
        for (int i=0;i<vec.size();i++){
            if(m[vec[i]]>=1000000){
                s=1;
                cout<<vec[i]<<endl;
            }
        }
        if(!s)cout<<"NA"<<endl;
    }
}

Measured memory_bytes: 1288
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e10;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 100;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,v,p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    cins(all(a));
    SORT(a);
    v--;
    ll l = -1,r = n-1;
    while(r-l > 1){
        vector<ll> b = a;
        ll mid = (l+r)/2;
        b[mid] += m;
        ll cnt = 0,same = 0,big = 0;
        vector<ll> mod;
        rep(i,n){
            if (i == mid) continue;
            if (b[mid] > b[i]){
                if (b[mid]-b[i] >= m) cnt += m;
                else{
                    cnt += b[mid]-b[i];
                    mod.push_back(m-(b[mid]-b[i]));
                }
            }
            else if (b[mid] == b[i]){
                same++;
            }
            else{
                big++;
                cnt += m;
            }
        }
        RSORT(mod);
        if (cnt >= v*m){
            //NONE
        }
        else if (cnt+same*m >= v*m){
            ll s = v*m-cnt;
            big += (s%m ? s/m+1 : s/m);
        }
        else{
            ll s = v*m-(cnt+same*m);
            big += same;
            ll i = 0;
            while(s > 0){
                s -= mod[i];
                big++;
                i++;
            }
        }
        if (big < p) r = mid;
        else l = mid;
        //PRINT(a[mid] << " " << cnt << " " << same << " " << big);
    }
    //PRINT(a[r]);
    PRINT(a.end()-lower_bound(all(a),a[r]));
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int sum = 0;
    set<int> st;
    for(int i = 1;sum < N;i++){
        sum += i;
        st.insert(i);
    }
    for(int i = 1;i*(i+1)/2 <= N;i++){
        if(sum - i == N){
            st.erase(i);
            break;
        }
    }
    for(auto i:st)cout << i << endl;
}

Measured memory_bytes: 512
using System;

namespace testes
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] strA = Console.ReadLine().Split(' ');
            int[] A = new int[N];
            for (int i = 0; i < N; i++) A[i] = int.Parse(strA[i]);
            string[] strB = Console.ReadLine().Split(' ');
            int[] B = new int[N];
            for (int i = 0; i < N; i++) B[i] = int.Parse(strB[i]);
            string[] strC = Console.ReadLine().Split(' ');
            int[] C = new int[N];
            for (int i = 0; i < N - 1; i++) C[i] = int.Parse(strC[i]);
            int ans = 0;
            for (int i = 0; i < N; i++)
            {
                ans += B[i];
            }
            for (int i = 0; i < N-1; i++)
            {
                if (A[i + 1] - A[i] == 1) ans += C[A[i] - 1];
            }

            Console.WriteLine(ans);
        }
    }

}

/*
int a, b, c;
a = int.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = int.Parse(str[1]);
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力

string[] str = Console.ReadLine().Split(' ');
int[] a = new int[N];
for(int i = 0; i < N; i++) a[i] = int.Parse(str[i]);
 */
 

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

int main(){
  int n;
  cin >> n;
  vector<long long>a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  long long r=n-2,l=1,sum=-a.at(0),sum2=a.at(0),ans;
  for(int i=0;i<n;i++)
    sum+=a.at(i);
  ans=abs(sum-sum2);
  for(int i=1;i<n-1;i++){
    sum-=a.at(i);
    sum2+=a.at(i);
    ans=min(ans,abs(sum-sum2));
  }
  cout << ans << endl;
  return 0;
}
    

Measured memory_bytes: 4796
/*
 * Created by Dipta Das on 09-06-2019
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;

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

    int arr[3];
    for(int i = 0; i < 3; i++){
                cin >> arr[i];
                    
    }

    sort(arr, arr + 3);

    cout << arr[0] + arr[1] << endl;
    


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

ll dd[] = {1, 0, -1};
set<PLL> se;
ll H, W, N;

int main() {
    init_io();
    cin >> H >> W >> N;
    for(ll i = 0; i < N; i++) {
        PLL p;
        cin >> p.first >> p.second;
        se.insert(p);
    }
    set<PLL> searched;
    V<ll> cnt(10);
    for(const auto &p : se) {
        ll oh, ow;
        tie(oh, ow) = p;
        for(ll i = 0; i < 3; i++) for(ll j = 0; j < 3; j++) {
            ll tmp = 0;
            ll h = oh + dd[i], w = ow + dd[j];
            if(searched.find(PLL(h, w)) != searched.end()) continue;
            if(!(1 <= h - 1 && h + 1 <= H && 1 <= w - 1 && w + 1 <= W)) continue;
            searched.insert(PLL(h, w));
            for(ll ii = 0; ii < 3; ii++) for(ll jj = 0; jj < 3; jj++) {
                ll nh = h + dd[ii], nw = w + dd[jj];
                tmp += (se.find(PLL(nh, nw)) != se.end());
            }
            DEBUG(tmp);
            cnt[tmp]++;
        }
    }
    ll sum = accumulate(ALL(cnt), 0ll);
    cnt[0] = (H - 2) * (W - 2) - sum;
    for(ll e : cnt) cout << e << endl;
    return 0;
}


Measured memory_bytes: 62720
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll a, t, w, r;
int main() {
    ll n;
    cin >> n;
    vector<string> s(n);
    REP(i, n)
        cin >> s[i];
    REP(i,n){
        if (s[i] == "AC") a++;
        if (s[i] == "WA") w++;
        if (s[i] == "TLE") t++;
        if (s[i] == "RE") r++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;
}


Measured memory_bytes: 6424
main :: IO ()                                                                                                                                         
main = do                                                                                                                                             
  getLine                                                                                                                                             
  as <- map read . words <$> getLine                                                                                                                  
  print $ minimum $ map (\x -> sum . map (\y -> (x - y)^2) $ as) [-100..100]

Measured memory_bytes: 892
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	string s;
	cin>>s;
	if(s.at(0)==s.at(2)){
		ce("Yes")
	}else{
		ce("No")
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int com (const void * a, const void * b) {
   return ( *(int*)a - *(int*)b );
}
int main(){
  int N,K;
  scanf("%d %d",&N,&K);
  int V[N];
  for (int i=0;i<N;i++){
    scanf("%d",&V[i]);
  }
  int R = K;
  if (N<K){
  	R = N;
  }
  int ans = 0;
  for (int i=0;i<=R;i++){
    for (int j=0;j<=i;j++){
      int A = j;
      int B = i-j;
      int D = K-(A+B);
      int arr[A+B];
      int k = 0;
      for (k=0;k<A;k++){
        arr[k] = V[k];
      }
      int a = 0;
      int vl = N-1;
      while(a<B){
        arr[k++] = V[vl--];
        a++;
      }

      qsort(arr,i, sizeof(int), com);
      int count = 0;
      for (int l=0;l<D;l++){
        if (l<i && arr[l]<0){
          count -=arr[l];
        }
      }
      for (int l=0;l<i;l++){
        count += arr[l];
      }
      if (count>ans){
        ans = count;
      }
    }
  }
  printf("%d",ans);
  return 0;
}


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

const int INF = 1145141919;
const long long INFL = 1LL<<60;

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;
}

int memo[110000];
int N, M;
vector<int> V[110000];

int rec(int x)
{
	if(memo[x] != 0)
	{
		return memo[x];
	}
	int fans = 0;
	for (auto v : V[x])
	{
		fans = max(fans, rec(v) + 1);
	}
	return memo[x] = fans;
}

int main()
{
	cin >> N >> M;
	int x, y;
	for (int i = 0; i < M; ++i)
	{
		cin >> x >> y;
		V[x].push_back(y);
	}
	int ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		ans = max(ans, rec(i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int H, W; cin >> H >> W;
	vector<vector<int>> bia(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> bia[i][j];
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int b; cin >> b;
			bia[i][j] = abs(bia[i][j] - b);
		}
	}

	int M = 6400;
	vector<vector<vector<bool>>> dp(H, vector<vector<bool>>(W, vector<bool>(M + 1)));
	dp[0][0][bia[0][0]] = true;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			for (int k = 0; k <= M; k++) {
				if (dp[i][j][k]) {
					if (i + 1 < H) {
						dp[i + 1][j][abs(bia[i + 1][j] - k)] = true;
						if (bia[i + 1][j] + k <= M) dp[i + 1][j][bia[i + 1][j] + k] = true;
					}
					if (j + 1 < W) {
						dp[i][j + 1][abs(bia[i][j + 1] - k)] = true;
						if (bia[i][j + 1] + k <= M) dp[i][j + 1][bia[i][j + 1] + k] = true;
					}
				}

			}
		}
	}

	for (int k = 0; k <= M; k++) {
		if (dp[H-1][W-1][k]) {
			cout << k << endl;
			break;
		}
	}

}



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

using namespace std;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int n;
	cin >> n;
	int xr = 0;
	int a;
	for(int i = 0; i < n; i++) {
		cin >> a;
		xr = xr ^ a;
	}
	if(xr == 0) cout << "Yes";
	else cout << "No";

	return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

    lint a, b, n;
    cin >> a >> b >> n;

    lint ans, tmp;
    lint x = min(n, b - 1);
    ans = (a * x) / b;

    cout << ans <<"\n";

    return 0;
}

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

int main() {
    int wh, bk; cin >> wh >> bk;
    int h = 100 / 2, w = 100;
    cout << h * 2 << " " << w << endl;
    auto func = [&](char c0, char c1, int cnt) {
        vector<string> s(h, string(w, c0));
        for (int i = 1; i < h - 1; i += 2) for (int j = 0; j < w; j += 2) {
            if (cnt) s[i][j] = c1, cnt--;
        }
        for (auto &si: s) cout << si << endl;
    };
    func('.', '#', bk - 1);
    func('#', '.', wh - 1);
    return 0;
}


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var ns = Console.ReadLine().Split(' ').Select(num => long.Parse(num))
                .OrderByDescending(num => num)
                .ToArray();

            var result = ns[0];
            var nCnt = n - 2;
            for (var i = 1; i < n; i++)
            {
                if (nCnt >= 2) { result += ns[i] * 2; nCnt -= 2; continue; }
                else if (nCnt == 1) { result += ns[i]; nCnt--; break; }
                else break;
            }

            Console.WriteLine(result);
        }
    }
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    cout << (n-1)*(m-1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int n,a[10],sum = 1,ans;
	cin >> n; ans = pow(3, n);
	rep(i, n) {
		cin >> a[i];
		if (a[i] % 2 == 0) sum *= 2;
	}
	cout << ans - sum << endl;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対グラフ

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

int main(){
    int H,W,h,w;
    cin >>H>>W>>h>>w;
    cout << W*H-h*W-w*H+h*w<<endl;
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL x, y, z, n, a[100000][3], ans[100000];
typedef pair<LL, int> PP;
PQ<PP> pq[3][3];

PP get(int f, int t) {
	PP p = pq[f][t].top();
	while(ans[p.SE] != f) { pq[f][t].pop(); p = pq[f][t].top(); }
	return p;
}

void add(int i, int v) {
	ans[i] = v;
	inc(j, 3) {
		if(j == v) { continue; }
		pq[v][j].emplace(a[i][j] - a[i][v], i);
	}
}

bool RT(int r) { // r: 1 or 2
	PP e[3];
	inc(j, 3) { e[j] = get(j, (j + r) % 3); }
	
	if(e[0].FI + e[1].FI + e[2].FI <= 0) { return false; }
	inc(j, 3) { add(e[j].SE, (j + r) % 3); }
	return true;
}

bool SW(int f, int t) {
	PP ft = get(f, t);
	PP tf = get(t, f);
	
	if(ft.FI + tf.FI <= 0) { return false; }
	add(ft.SE, t);
	add(tf.SE, f);
	return true;
}

LL calc() {
	LL sum = 0;
	inc(i, n) {
		sum += a[i][ans[i]];
	}
	return sum;
}

int main() {
	cin >> x >> y >> z;
	n = x + y + z;
	inc(i, n) {
	inc(j, 3) {
		cin >> a[i][j];
	}
	}
	
	inc(i, n) {
		int v;
		if(inID(i, 0,     x)) { v = 0; }
		if(inID(i, x, x + y)) { v = 1; }
		if(inID(i, x + y, n)) { v = 2; }
		add(i, v);
	}
	
	// 適当
	inc(x, 8) {
		inc(j, 3) {
			while(SW(j, (j + 1) % 3)) { }
		}
		while(RT(1)) { }
		while(RT(2)) { }
		while(RT(1)) { }
	}
	
	cout << calc() << endl;
	
	return 0;
}


Measured memory_bytes: 9836
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  lint k,n;
  cin>>k>>n;
  vector<lint> a(n);

  for(int i=0;i<n;i++){
    int v;
    cin>>v;
    a[i]=v;

  }
  lint result=a[n-1]-a[0];
  for(int start=1;start<n;start++){
    lint tmp_result=a[n-1]-a[start]+k-a[n-1]+a[start-1];
    UpdateMin(result,tmp_result);
  }
  cout<<result<<endl;

  return 0;
}




Measured memory_bytes: 1792
n = gets.to_i
a = gets.split(" ").map(&:to_i)
b = [0]
n.times do |i|
  b[i+1] = b[i] + a[i]
end

ans = Float::INFINITY

(n-1).times do |i|
  x = b[i+1]
  y = b[n] - b[i+1]
  tmp = (x-y).abs
  ans = tmp if ans > tmp
end

puts ans


Measured memory_bytes: 16972
#include <bits/stdc++.h>
#define MAX_N 100000
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n; lnt P, f[MAX_N+5], g[MAX_N+5]; vector <int> G[MAX_N+5];
void DFS(int u, int fa) {
	f[u] = 1;
	for (int v : G[u]) if (v ^ fa)
		DFS(v, u), (f[u] *= f[v]+1) %= P;
}
void DP(int u, int fa, lnt pr) {
	g[u] = f[u]*(pr+1)%P;
	vector <lnt> lf, rf; lnt cur = 1; int c = 0;
	for (int v : G[u]) if (v ^ fa)
		lf.push_back(cur), (cur *= f[v]+1) %= P;
	reverse(G[u].begin(), G[u].end()), cur = 1;
	for (int v : G[u]) if (v ^ fa)
		rf.push_back(cur), (cur *= f[v]+1) %= P;
	reverse(G[u].begin(), G[u].end());
	reverse(rf.begin(), rf.end());
	for (int v : G[u]) if (v ^ fa)
		DP(v, u, lf[c]*rf[c]%P*(pr+1)%P), c++;
}
int main() {
	read(n), read(P);
	for (int i = 1, u, v; i < n; i++)
		read(u), read(v), G[u].push_back(v), G[v].push_back(u);
	DFS(1, 0), DP(1, 0, 0);
	for (int i = 1; i <= n; i++)
		printf("%lld\n", g[i]);
	return 0;
}


Measured memory_bytes: 24064
#include <algorithm>
#include<bits/stdc++.h>
#include <ios>
#include <iterator>
using namespace std;
#define ll long long
#define f(n)  for(int i=0;i<n;i++) 
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define all(v)   v.begin(),v.end()  
void speed (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main() {
    speed();
  ll int n;
  cin>>n;
  ll int q=n/500;
  ll int r=n%500;
  ll int ans=q*1000;
  int v=r/5;
  ans+=(v*5);
  cout<<ans;
  
   
    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int n,m,k;
int cc[100010];
int co[100010];
bool vis[100010];
vector<pii> d;
vector<int> g[100010];
map<pii,int> bl;//(i,j) i's enemy with col j
void dfs(int v,int col){
	vis[v]=1;
	co[v]=col;
	cc[col]++;
	rep(i,g[v].size()){
		int to=g[v][i];
		if(!vis[to]){
			dfs(to,col);
		}
	}
}
int main(int argc,char** argv){
	cin>>n>>m>>k;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	int cnt=0;
	rep(i,n){
		if(!vis[i]){
			dfs(i,cnt);
			cnt++;
		}
	}
	rep(i,k){
		int x,y;
		cin>>x>>y;
		x--;y--;
		bl[mp(x,co[y])]++;
		bl[mp(y,co[x])]++;
	}
	/*
	rep(i,n){
		cout<<i<<" "<<co[i]<<" "<<cc[co[i]]<<" "<<bl[mp(i,co[i])]<<endl;
	}
	*/
	rep(i,n){
		int x=co[i];
		int ans=cc[x]-g[i].size()-bl[mp(i,x)]-1;
		cout<<ans<<" ";
	}
	return 0;
}

Measured memory_bytes: 17536