akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

struct UnionFind{
    vector<int> par,siz;

    UnionFind(int n) : par(n), siz(n, 1){
        iota(par.begin(), par.end(), 0);
    }

    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int size(int x){
        return siz[root(x)];
    }
};

signed main(){
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    int cnt[n] = {};
    int a,b;
    rep(i,m){
        cin >> a >> b;
        a--;
        b--;
        cnt[a]++;
        cnt[b]++;
        uf.unite(a,b);
    }
    int c,d;
    rep(i,k){
        cin >> c >> d;
        c--;
        d--;
        if(uf.same(c,d)){
            cnt[c]++;
            cnt[d]++;
        }
    }
    rep(i,n){
        if(i) cout << " ";
        cout << uf.size(i) - 1 - cnt[i]; 
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 10000000
using namespace std;
typedef long long ll;
const int MAXN=1e9+10;
const int MAX=1e4+10;
const double eps=1e-6;

int N;
struct NODE{
    int x,y;
}r[MAX],b[MAX];
int n;
vector<int>G[MAX];
int vis[MAX];
int link[MAX];

void init(){
    memset(vis,-1,sizeof(vis));
    memset(link,-1,sizeof(link));
}

void addedge(int u,int v){
    G[u].push_back(v);
}

bool DFS(int node){
    for(int i=0;i<G[node].size();i++){
        int v=G[node][i];
        if(!vis[v]){        //找一条交替路
            vis[v]=1;
            if(link[v]==-1||DFS(link[v])){  //找一条增广路
                link[v]=node;       //记录增广路节点 方便更新
                return true;
            }
        }
    }
    return false;
}

int hungary(){
    int res=0;
    for(int i=1;i<=N;i++){
        memset(vis,0,sizeof(vis));
        if(DFS(i))
            res++;
    }
    return res;
}

int main(){


    cin>>n;
    N=2*n;
    init();
    for(int i=1;i<=n;i++)
        scanf("%d%d",&r[i].x,&r[i].y);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&b[i].x,&b[i].y);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(r[i].x<b[j].x&&r[i].y<b[j].y){
                addedge(i,j+n);
            }
        }
    }
    cout<<hungary()<<endl;

    return 0;
}


Measured memory_bytes: 640
n,m=map(int,input().split())
a=[]
for i in range(m):
    x,y,z=map(int,input().split())
    a.append((x-1,y-1))

class union:
    def __init__(self,num):
        self.par=[-1]*num
    def get_par(self,node):
        if self.par[node]==-1:
            return node
        else:
            x=self.get_par(self.par[node])
            return x
    def merge(self,x,y):
        X=self.get_par(x)
        Y=self.get_par(y)
        if X!=Y:
            self.par[Y]=X
    def output(self):
        print(self.par)
    def count(self):
        print(self.par.count(-1))
def get_parent(node):
    if par[node]==-1:
        return node
    else:
        par[node]=get_parent(par[node])
        return par[node]
    
def merge(x,y):
    i=get_parent(x)
    j=get_parent(y)
    if i!=j:
        par[i]=j
    return
par=[-1]*n
for i in range(m):
    merge(a[i][0],a[i][1])
print(par.count(-1))

Measured memory_bytes: 108632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}


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

	ll  d, n, m, k, ans = 0, ret = M;
	bool flag = false, flag2 = false;
	string s, t;
	cin >> n >> m;
	if (-n <= m) ret = min(ret, n + m + 1);
	if (n <= m) ret = min(ret, m - n);
	if (n <= -m)ret = min(ret, -m - n + 1);
	if (-n <= -m)ret = min(ret, -m + n + 2);
	cout << ret << endl;
	return 0;
}


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

    int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r,d,a,ans;
    cin>>r>>d>>a;
    ans=a;
    for(int i=0;i<10;i++){
    ans=r*ans-d;
    cout<<ans<<endl;
    }}


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

using namespace std;
using i64 = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define sqrt(x) sqrt(abs(x))
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define re return
#define prev PREV
#define next NEXT
#define sz(x) ((int)x.size())

template<typename T> T sqr(T a) { re a * a; }
template<typename T> T gcd(T a, T b) { re b ? gcd(b, a % b) : a; }
template<typename T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }
template<typename T> T abs(T a) { re a > 0 ? a : -a; }

const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int K = 1000;
const int NMAX = 1000;
#define FILENAME ""   

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
//	freopen("symposium.in", "r", stdin);
//	freopen("symposium.out", "w", stdout);
   	int a, b;
   	cin >> a >> b;
   	if (a*b % 2 == 0) cout << "No";
   	else cout << "Yes";
   	re 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<long long> a(N);
  long long sum = 0;
  for(int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long ave = sum / N;
  long long ave2;
  /*if(ave >= 0)*/ ave2 = ave +1;
  //else ave2 = ave - 1;
  long long res = 0, res2 = 0;
  for(int i = 0; i < N; i++){
    res += (a[i] - ave) * (a[i] - ave);
    res2 += (a[i] - ave2) *(a[i] - ave2);
  }
  cout << min(res, res2) << endl;
}


Measured memory_bytes: 256
from math import gcd
import random
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1


def is_prime3(q, k=50):
    q = abs(q)
    # 計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q & 1 == 0: return False

    # n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    # 判定をk回繰り返す
    for i in range(k):
        a = random.randint(1, q - 1)
        t = d
        y = pow(a, t, q)
        # [0,s-1]の範囲すべてをチェック
        while t != q - 1 and y != 1 and y != q - 1:
            y = pow(y, 2, q)
            t <<= 1
        if y != q - 1 and t & 1 == 0:
            return False
    return True

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


A, B = map(int, input().split())
l = make_divisors(gcd(A, B))
_l = factorization(gcd(A, B))
ans = 0
#print(gcd(A, B))
#print(l)
#print(_l)
for num in l:
    if is_prime3(num):
        #print(num)
        ans += 1
print(ans + 1)



Measured memory_bytes: 83528
#include<iostream>
typedef long long ll ;
using namespace std ;
int main()
{
    ll a,b,k,x;
    cin >> a >> b >> k ;
    if(a>=k)
    {
        a-=k;
    }
    else
    {
        k-=a;
        a=0;
        ll ans = min(b,k);
        b-=ans;
    }
    cout << a << " " << b << endl;
    return 0;
}

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

int main(void){
    int K;
    cin >> K;
    if((K % 2 == 0)||(K % 5 == 0)){
        cout << -1 << endl;
    }else{
        if(K % 7 == 0)K/=7;
        int repunit = 1;
        int res = 1;
        while(repunit % K != 0){
            repunit = repunit * 10 + 1;
            repunit %= K;
            res++;
        }
        cout << res << endl;
    }
    return 0;
}

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int M, m;
    M = min(a, b);
    if(n-(a+b)>0) m=0;
    else m = (a+b)-n;
    cout << M << ' ' << m << endl;
}

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

A = [int(_) for _ in input().split()]


def f(x, y):
    return (x - y) ** 2


tmp = sum(A) // N
print(min(
    sum(map(lambda x: f(x, tmp), A)),
    sum(map(lambda x: f(x, tmp + 1), A))
)
)


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;


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

	char c; cin >> c;

	cout << (char) (c+1) << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;


int main(int argc, char **argv)
{
	ll res{0};
	ll N, K; cin >> N >> K;
	vector<bool> has(N+1, false);
	for (ll i = 0; i < K; ++i)
	{
		ll d; cin >> d;
		for (ll j = 0;j < d; ++j)
		{
			ll a; cin >> a;
			has[a] = true;
		}
	}
	
	for (ll i = 1; i <= N; ++i)
		res += !has[i];
	std::cout << res << std::endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        long Y = Long.parseLong(sc.next());

        for (int i = 0; i <= N; i++) {
            for (int j = 0; (i+j) <= N; j++) {
                for (int k = 0; i+j+k <= N; k++) {
                    if ((i+j+k == N) && 1000*i + 5000*j + 10000*k == Y) {
                        System.out.println(k + " " + j + " " + i);
                        System.exit(0);
                    }
                }
            }
        }

        System.out.println("-1 -1 -1");
    }
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    if(n==m)
    cout<<"Yes";
    else
    {
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cctype>
#include <iomanip>
#include <limits>
#include <bitset>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef unsigned long long int ull;
const ll mod = 1000000007;
const ll linf = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = (m); i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<>()
#define SUM(a) accumulate((a).begin(), (a).end(), 0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
template <typename T>
int len(T tmp)
{
	int res = 0;
	while (tmp > 0)
	{
		res++;
		tmp /= 10;
	}
	return res;
}
template <typename T>
T gcd(T a, T b)
{
	T t;
	while (b != 0)
	{
		t = a % b;
		a = b;
		b = t;
	}
	return a;
}
template <typename T>
T recfact(T start, T n)
{
	T i;
	if (n <= 16)
	{
		T r = start;
		for (i = start + 1; i < start + n; i++)
			r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
template <typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
template <typename T>
T fct(T n)
{
	return recfact<T>(1, n);
}
template <typename T>
T ncm(T n, T m)
{
	if (n < m)
		return 0;
	T x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr)
{
	if (firstItr < 0 || secondItr > int(str.size() - 1))
		return str;
	while (firstItr < secondItr)
	{
		swap(str[firstItr], str[secondItr]);
		firstItr++;
		secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str)
{
	int itr = 0;
	std::string res;
	while (itr < int(str.size()))
	{
		char tmp = str[itr++];
		int length = 1;
		while (itr < int(str.size()) && str[itr] == tmp)
		{
			++itr;
			++length;
		}
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
str split(str str, size_t first_itr, size_t second_itr)
{
	string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++)
	{
		tmp.push_back(str.at(i));
	}
	return tmp;
}

int main(void)
{
	int k, n;
	cin >> k >> n;
	vec v(n);
	vec d(n);
	cin >> v[0];
	REP(i,1,n){
		cin >> v[i];
		d[i] = v[i] - v[i - 1];
	}
	d[0] = abs(k + v[0] - v[n - 1]);
	cout << k - *max_element(all(d)) << endl;

	return 0;
}

Measured memory_bytes: 1792
# D - Pairs

import numpy as np

N, K = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))), np.int64)

n_zero = len(A[A == 0])
A_posi = A[A > 0]
A_nega = A[A < 0]

def n_pairs_less_than_or_equal_to_border(product_border):
    n_pairs = -np.sum(A*A <= product_border) # i==jかつ条件を満たすペアの個数を先に引き、以降重複を許して数える
    n_pairs += n_zero * N * (product_border >= 0)

    n_pairs += np.searchsorted(A, product_border//A_posi, side="right").sum()
    n_pairs += (N - np.searchsorted(A, -(-product_border//A_nega), side="left")).sum()

    # 上記2行は下記と同様の処理だが下記の実装だとTLE
    # for i in range(N):
    #     if A[i] > 0:
    #         n_pairs += np.searchsorted(A, product_border//A[i], side="right")
    #     elif A[i] < 0:
    #         n_pairs += N - np.searchsorted(A, -(-product_border//A[i]), side="left")

    n_pairs //= 2
    return n_pairs


lower = -(10**18)
upper = 10**18

while lower <= upper:
    x = (lower + upper) // 2
    if n_pairs_less_than_or_equal_to_border(x) >= K:
        ans = x
        upper = x - 1
    else:
        lower = x + 1

print(ans)

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

using namespace std;
typedef pair<int,int> edge;
typedef pair<int,int> dist_node;

#define maxsize 100005
const long long INF = 1000000000000000l;

vector <edge> g[maxsize];
long long d[maxsize];
int p[maxsize]; // p is used to verify if there is a route to the desired node

void dijkstra(int s, int n){
    for(int i =0;i<=n;++i){d[i]=INF;p[i]=-1;}
    priority_queue <dist_node, vector<dist_node>, greater<dist_node> > q;
    d[s]=0;
    q.push(dist_node(0,s));
    while(!q.empty()){
        int dist = q.top().first;
        int cur = q.top().second;
        q.pop();
        if(dist>d[cur]) continue;
        for(int i=0;i<g[cur].size();++i){
            int next = g[cur][i].first;
            int w = g[cur][i].second;
            if(d[cur]+w <   d[next]){
                d[next] = d[cur] + w;
                p[next] = cur;
                q.push(dist_node(d[next],next));
            }
        }
    }
}

main(){
  int n;
  scanf("%d",&n);
  int a,b,c;
  for(int i=0;i<n-1;++i){
    cin >> a >> b >> c;
    g[a].push_back(edge(b,c));
    g[b].push_back(edge(a,c));
  }
  int q , k;
  scanf("%d %d",&q,&k);
  dijkstra(k,n);
  int x, y;
  for(int i=0;i<q;++i){
    scanf("%d %d",&x,&y);
    cout << d[x] + d[y] << endl;
  }
}

Measured memory_bytes: 9204
//Author- VMAX


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*
/*
ll prf(ll n)
{
    ll c=0,i;
    while(n%2==0)
    {
        n=n/2;
        c++;
    }
    for(i=3;i*i<=n;i++)
    {
        while(n%i==0)
    }
    
    
    
}
*/

int main()
{
      fast
       
       
       char c;
       cin>>c;
       
       if(c>=97&&c<=122)
       {
           o("a")
       }
       else
       {
           o("A")
       }
       
       
       
       
       
       
       
       
     
   
    re
}

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
//------------------------------------------------------------------------------------------------------------------------------

int N;
int C;
vector<vector<P>> V(N);
void func(int par, int chi, int color) {
    if (par != -1){
        V[par][chi].second = color;
        V[chi][par].second = color;
    }
    int c = color;
    for (int i = 0; i < V[chi].size(); i++) {
        if(V[chi][i].first != par){
            c++;
            func(chi, V[chi][i].first, c % C);
        }
    }
    return;
}

int main(void) { 
    int N, Y; 
    cin >> N >> Y;
    for(int i = 0; i <= 2000; i++) {
        for(int j = 0; j <= 2000; j++) {
            if(i+j <=N && 10000*i+5000*j+1000*(N-i-j) == Y){
                cout << i << ' ' << j << ' ' << N - i - j << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

min_abs = abs(a[0])  # a[0], ..., a[n-1]中の絶対値の最小値
sum = 0   # b[0] +  ... + b[n-1]
p_neg = 0  # a[0], ..., a[n-1]中の負の数の数が偶数なら0、奇数なら1
zero_exists = False  # a[0], ..., a[n-1]の中に0があるかどうか

for i in range(n):
    min_abs = min( min_abs, abs(a[i]))
    if a[i] < 0:
        p_neg = 1 - p_neg
        sum += -a[i]
    elif a[i] == 0:
        zero_exists = True
    else:
        sum += a[i]

if zero_exists or p_neg == 0:
    pass
else:
    sum -= 2 * min_abs

print(sum)


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


void solve(long long N, std::vector<std::string> S){
    map<string,int> mp;
    int mx = 0;
    for(int i=0;i<N;i++){
        
        mp[S[i]]++;
        mx=max(mx,mp[S[i]]);
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if(itr->second == mx){
            cout << itr->first << endl; 
        }
    }


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 26880
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int A,B,C;
	cin >> A >> B >> C;
	
	int sum = A+B+C;
	int SUM = max(A,max(B,C))*3;
	SUM -= sum;
	if(SUM%2 == 1)SUM += 3;
	cout << SUM/2 << endl;
}



Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
int n,m;
bool judge(int i,vector<int> const& s,vector<int> const& c){
  bool flag=true;
  int keta=0;
  int buf=i;
  vector<int> kakuketa;
  while(buf>0){
    kakuketa.push_back(buf%10);
    keta++;
    buf/=10;
  }
  if(i==0)keta++;
  kakuketa.push_back(0);
  reverse(ALL(kakuketa));
  if(keta!=n)flag=false;
  rep(j,m){
    if(kakuketa[s[j]]!=c[j]){
      flag=false;
    }
  }
  return flag;
}
signed main(){
  cin>>n>>m;
  vector<int> s(m);
  vector<int> c(m);
  rep(i,m)cin>>s[i]>>c[i];
  int sup=1000;
  if(n==2)sup=100;
  if(n==1)sup=10;
  rep(i,sup){
    if(judge(i,s,c)){
      cout<<i<<endl;
      break;
    }
    if(i==sup-1){
      cout<<-1<<endl;
    }
  }
  return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define MAX_N 100000

class Checker
{
  public:
    ll x;
    ll y;
    char c;
};

ll a[1001][2001];

int main(){
  ll n, k;
  cin >> n >> k;
  
  Checker xyc[MAX_N];
  REP(i, n){
    cin >> xyc[i].x >> xyc[i].y >> xyc[i].c;
    int flag = 0;
    if((xyc[i].x / k) % 2 == 1){
      flag += 1;
    }
    xyc[i].x %= k;
    if((xyc[i].y / k) % 2 == 1){
      flag += 1;
    }
    xyc[i].y %= k;
    if((flag % 2 == 0 && xyc[i].c == 'B') || (flag % 2 == 1 && xyc[i].c == 'W')){
      xyc[i].y += k;
    }
  }

  REP(i,n){
    a[xyc[i].x + 1][xyc[i].y + 1] += 1;
  }

  REP(i,k+1){
    FOR(j,1,k*2+1){
      a[i][j] += a[i][j-1];
    }
  }
  REP(i,k*2+1){
    FOR(j,1,k+1){
      a[j][i] += a[j-1][i];
    }
  }

  ll ans = 0;
  ll temp;
  REP(i,k){
    REP(j,k){
      temp = a[k][k*2] - (a[i][k*2]+a[k][k+j]) + 2*a[i][k+j] + a[k][j] - 2*a[i][j];
      ans = max({ans, temp, n-temp});
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 18176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

struct DINIC{
#define MAX_V 5050
    typedef long long ll;
    typedef ll CapType;
    struct edge {
        int to; // 行き先
        CapType cap; // 容量
        int rev; // 逆辺
        edge() {}
        edge(int to, CapType cap, int rev) :to(to), cap(cap), rev(rev) {}
    };
    vector<edge> G[MAX_V]; // グラフの隣接リスト表現
    ll level[MAX_V]; // sからの距離
    ll iter[MAX_V]; // どこまで調べ終わったか
    
    // fromからtoへ向かう容量capの辺をグラフに追加する
    void add_directed_edge(int from, int to, CapType cap) {
        G[from].push_back(edge(to, cap, (int)G[to].size()));
        G[to].push_back(edge(from, 0, (int)G[from].size() - 1));
    }
    void add_undirected_edge(int from, int to, CapType cap) {
        G[from].push_back(edge(to, cap, (int)G[to].size()));
        G[to].push_back(edge(from, cap, (int)G[from].size() - 1));
    }
    
    // sからの最短距離をBFSで計算する
    void bfs(int s){
        fill(level,level+MAX_V,-1);
        queue<int> q;
        level[s] = 0;
        q.push(s);
        while(!q.empty()){
            int v = q.front(); q.pop();
            for(int i = 0; i < (int)G[v].size();i++){
                edge& e = G[v][i];
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }
    
    // 増加パスをDFSで探す
    CapType dfs(int v, int t,CapType f){
        if(v == t) return f;
        for(ll &i = iter[v]; i < G[v].size();i++){
            edge &e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.to]){
                CapType d = dfs(e.to,t,min(f,e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    
    CapType max_flow(int s,int t){
        CapType flow = 0;
        for(;;){
            bfs(s);
            if(level[t] < 0) return flow;
            fill(iter,iter+MAX_V,0);
            CapType f;
            while((f = dfs(s,t,LINF)) > 0){
                flow += f;
            }
        }
    }
};

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int V,E; cin >> V >> E;
    DINIC Flow;
    for(int i = 0; i < E;i++){
        int u,v; ll cap; cin >> u >> v >> cap;
        Flow.add_directed_edge(u,v,cap);
    }
    cout << Flow.max_flow(0, V-1) << endl;
	return 0;
}



Measured memory_bytes: 3436
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

int main() {
    int n;
    std::cin >> n;

    std::vector<int> p(n + 2);
    p[0] = -1;
    for (int i = 1; i < n + 1; i++)
    {
        std::cin >> p[i];
    }

    p[n + 1] = -1;

    int ans = 0;
    for (int i = 1; i < n + 1; i++)
    {
        if(p[i] == i) {
            ans++;
            std::swap(p[i], p[i + 1]);
        }
    }

    std::cout << ans << "\n";
}

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

int main () {
  int D;
  cin >> D;
  if (D == 25) cout << "Christmas" << endl;
  else if (D == 24) cout << "Christmas Eve" << endl;
  else if (D == 23) cout << "Christmas Eve Eve" << endl;
  else cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = (1 << 29);
const long long INFL = (1LL<<60);
const double eps = (1e-9);

bool secdesc(const pair<int, int>& a, const pair<int, int>& b)
{
  return a.second > b.second;
}

int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  vector<pair<int, int>> red(n);
  vector<pair<int, int>> blue(n);

  rep(i, n) {
    int x, y;
    cin >> x >> y;
    red[i] = make_pair(x, y);
  }
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    blue[i] = make_pair(x, y);
  }

  sort(ALL(red), secdesc);   // y 座標の大きい順
  sort(ALL(blue));           // x 座標の小さい順

  set<int> used;
  int ans = 0;
  rep(i, n) {
    int bx = blue[i].first;
    int by = blue[i].second;
    rep(j, n) {
      if (used.count(j) != 0) {
        continue;
      }
      int rx = red[j].first;
      int ry = red[j].second;
      if (rx < bx && ry < by) {
        used.insert(j);
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    print(eval(input().replace(' ','')))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include "iostream"
using namespace std;
 
int main(){
 int M1,D1,M2,D2; 
  
  cin >> M1 >> D1;
  cin >> M2 >> D2;
   
  if(M1 == M2) cout << 0;
  else cout << 1;
  
return 0;
  
}

Measured memory_bytes: 256
from networkx import*
H,*S=open(0)
H,W=map(int,H.split())
g=Graph()
a=g.add_edges_from
for i in range(m:=H*W):a([[M:=m*2,h:=i//W],[M,w:=i%W+m]]*((c:=S[h][w-m])=='S')+[[h,I:=m*3],[w,I]]*(c=='T'),capacity=I),a([[h,w],[w,h]]*(c>'T'),capacity=1)
f,_=minimum_cut(g,M,I)
print(-(f>M)or f)

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

int main(){
    long int N,M;
    cin >> N >> M;

    vector<long int> A(M);

    rep(i,M) {
        cin >> A.at(i);
    }

    long int total = 0;
    rep(i,M) {
        total += A.at(i);
    }

    if(N>=total) {
        cout << N - total << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void) {
	ll x, t; cin >> x >> t;
	printf("%lld\n", max(0ll, x - t));
	return 0;
}

Measured memory_bytes: 256
import Data.Array
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

readString = map BS.unpack . BS.words

getIntList = readIntList <$> BS.getLine

getString = readString <$> BS.getLine

checkRock :: Array Int Char -> Int -> Int -> Char -> Bool
checkRock ss i n c
  | i > n = True
  | c == '#' && c' == '#' = False
  | otherwise = checkRock ss (i + 1) n c'
  where
    c' = ss ! i

checkTriplet :: Array Int Char -> Int -> Int -> Char -> Char -> Bool
checkTriplet ss i n c1 c2
  | i > n = False
  | c2 == '#' && c' == '#' = False
  | c1 == '.' && c2 == '.' && c' == '.' = True
  | otherwise = checkTriplet ss (i + 1) n c2 c'
  where
    c' = ss ! i

main = do
  [n, a, b, c, d] <- getIntList
  [ss] <- getString
  let ss' = listArray (1, n) ss
  if b > c
    then if checkRock ss' a b '.' && checkRock ss' c d '.' then putStrLn "Yes" else putStrLn "No"
    else do
      if d > c
        then if checkRock ss' a d '.' == False then putStrLn "No" else do putStrLn "Yes"
        else if checkRock ss' a c '.' && checkTriplet ss' (b + 1) (d + 1) (ss' ! (b -1)) (ss' ! b) then putStrLn "Yes" else do putStrLn "No"


Measured memory_bytes: 6776
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;



int main()
{
    ll n, m;
    cin >> n >> m;
    vector<pll> need(m);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        need[i] = mp(b,a);
    }
    sort(all(need));
    ll ans = 0;
    ll bef = 0;
    rep(i,m){
        if (need[i].S<=bef){
            continue;
        }
        else{
            bef = need[i].F - 1;
            ans++;
        }
    }
    cout << ans << endl;
}


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

typedef long long ll;
int sharp[1000000] = {0};
int dot[1000000] = {0};
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    int sums = 0;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == '#'){
            sums++;
        }
        sharp[i] = sums;
    }    
    int sumd = 0;
    for(int i = n - 1; i >= 0; i--)
    {
        if(s[i] == '.'){
            sumd++;
        }
        dot[i] = sumd;
    }

    int ans = 10000000;
    for(int i = 0; i < n -1; i++)
    {
        int tmp = sharp[i] + dot[i + 1];
        //printf("%d %d %d %d\n", i, sharp[i], dot[i], sharp[i] + dot[i + 1]);
        ans = min(ans, tmp);
    }
    ans = min(ans, dot[0]);
    ans = min(ans, sharp[n - 1]);
    cout << ans << endl;
 
}



Measured memory_bytes: 5508
#include<bits/stdc++.h>
using namespace std;
queue<int>q;
const int N=100005;
int visit[2][N];
vector<int>v[N];
int n;
inline void BFS(int o,int k)
{
	q.push(k);
	q.push(1);
	while(!q.empty())
	{
		int x=q.front();q.pop();
		int t=q.front();q.pop();
		visit[o][x]=t;
		for(int i=0;i<v[x].size();i++)
		{
			int y=v[x][i];
			if(!visit[o][y])
			{
				q.push(y);
				q.push(t+1);
			}
		}
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	BFS(0,1);
	BFS(1,n);
	int x=0,y=0;
	for(int i=1;i<=n;i++){
		if(visit[0][i]<=visit[1][i])x++;
		else y++;
	}
	if(x>y)cout<<"Fennec\n";
	else cout<<"Snuke\n";
}

Measured memory_bytes: 6784
#include <stdio.h>

int main(void){
   int W, H, x, y, r;
   scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
   
   if(x-r < 0 || x+r > W || y-r < 0 || y+r > H) printf("No\n"); 
   else printf("Yes\n");
   
   return 0;
}



Measured memory_bytes: 2104
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n){
        cin >> d[i];
    }
    d.push_back(0);
    SORT(d);
    int sign = 1;
    rep(i, n+1){
        d[i] *= sign;
        sign = -sign;
    }
    vector<int> a;
    for(int i = 0 ; i < n ; i++){
        for(int j = i + 1 ; j < n + 1 ; j++){
            a.push_back(min(abs(d[i] - d[j]), 24 - abs(d[i]) - abs(d[j])));
        }
    }
    SORT(a);
    cout << a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(N);
  GVI(A, N);
  sort(ALL(A));
  vector<P> ans;
  int min_root = A[0], max_root = A[N - 1];
  int sum = -A[0];
  FORIN(i, 1, N - 1) {
    if (A[i] < 0) {
      sum -= A[i];
      ans.push_back(P(max_root, A[i]));
      max_root -= A[i];
    } else {
      sum += A[i];
      ans.push_back(P(min_root, A[i]));
      min_root -= A[i];
    }
  }
  sum += A[N - 1];
  ans.push_back(P(max_root, min_root));
  print(sum);
  for (P p : ans) {
    cout << p.first << " " << p.second << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    ll a, b, c, k; cin >> a >> b >> c >> k;
    if (k <= a) {
        cout << k;
    } else if (k <= a + b) {
        cout << a;
    } else {
        cout << a - (k - a - b);
    }
    return 0;
}


Measured memory_bytes: 3608
import java.util.*;

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


	class State implements Comparable<State>{
		int now,cost, tick;

		public State(int now, int cost, int tick) {
			this.now = now;
			this.cost = cost;
			this.tick = tick;
		}

		@Override
		public int compareTo(State arg0) {
			return this.cost - arg0.cost;
		}
		
	}

	private void doit(){
		while(true){
			int c = sc.nextInt();
			int n = sc.nextInt();
			int m = sc.nextInt();
			int s = sc.nextInt();
			int d = sc.nextInt();
			if((c|n|m|s|d) == 0) break;
			s--;
			d--;
			int [][] pass = new int[n][n];
			int INF = 1 << 24;
			for(int i = 0; i < n; i++){
				Arrays.fill(pass[i], INF);
				pass[i][i] = 0;
			}
			for(int i = 0; i < m; i++){
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				int cost = sc.nextInt();
				pass[a][b] = cost;
				pass[b][a] = cost;
			}
			PriorityQueue<State> open = new PriorityQueue<Main.State>();
			open.add(new State(s, 0,c));
			int [][] close = new int[n][c+1];
			for(int i = 0; i < n; i++){
				Arrays.fill(close[i], INF);
			}
			close[s][c] = 0;
			int ans = -1;
			while(! open.isEmpty()){
				State now = open.poll();
				if(now.now == d){
					ans = now.cost;
					break;
				}
				for(int i = 0; i < n; i++){
					if(pass[now.now][i] == INF) continue;
					int nextcost = now.cost + pass[now.now][i];
					if(close[i][now.tick] > nextcost){
						open.add(new State(i, nextcost, now.tick));
						close[i][now.tick] = nextcost;
					}
					if(now.tick != 0){
						nextcost = now.cost + pass[now.now][i] / 2;
						if(close[i][now.tick - 1] > nextcost){
							open.add(new State(i, nextcost, now.tick - 1));
							close[i][now.tick-1] = nextcost;
						}
					}
				}
			}
			System.out.println(ans);
		}
	}
	
	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

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

Measured memory_bytes: 55800
import java.util.Scanner;


// 147_b
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        out((int) Math.pow(sc.nextInt(), 3));
    }

    /*
     * 以下メソッド集
     */

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

}


Measured memory_bytes: 21844
import Data.List
import Data.Maybe

main :: IO()
main = getContents >>= putStr.form.f.(++[1000]).map read.words.last.lines

form :: [Int] -> String
form xs = unlines [(unwords.map show.init) xs, show $last xs -1000]

f :: [Int] -> [Int]
f xs = let n = minimum xs in g n xs
    where g _ [] = []
          g m ys@(z:zs) | m == z = (z:) $f zs
                        | otherwise = let s = fromJust $elemIndex m ys in f  $((++ [last ys +1]).(m:).tail.init) $take s ys ++ [z] ++ drop (s+1) ys

Measured memory_bytes: 4104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 998244353;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];
ll beki(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    const int MAX = 10000002;
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}
ll N, X;
ll ans;

int main() {
    //cout.precision(10);
    cin >> N >> X;
    init_combination();
    for(ll sum = 0; sum <= 2 * N; sum++) {
        if(sum >= X and sum % 2 == X % 2) continue;
        if(sum < X) {
            for(ll num = 0; num <= sum; num++) {
                ll two = sum - num;
                ll one = num - two;
                ll zero = N - two - one;
                if(two < 0 or one < 0 or zero < 0) continue;
                ll tmp = combination(N, one) * combination(N - one, two) % mod;
                ans += tmp;
                ans %= mod;
            }
        }
        if(sum >= X) {
            ll sidetwo = (sum - X + 1);
            for(ll mid = 0; mid <= sum; mid++) {
                ll two = (sum - 2 * sidetwo) - mid;
                ll one = mid - two;
                ll zero = N - sidetwo - two - one;
                //cerr << sum << " " << sidetwo << " " << two << " " << one << " " << zero << endl;
                if(sidetwo < 0 or two < 0 or one < 0 or zero < 0) continue;
                ll tmp = combination(N, zero) * combination(one + two, one) % mod;
                ans += tmp;
                ans %= mod;
            }
            if(sidetwo * 2 > sum and X % 2 == 1) {
                ll tmp = combination(N, sum / 2);
                //cerr << sum << " " << sidetwo << endl;
                ans += tmp;
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

sunuke = [0]*(n+1)

for j in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for i in range(d):
        sunuke[a[i]] += 1

cnt = 0

for k in range(1, n+1):
    if sunuke[k] == 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n,m=M,c=0,d=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];c+=a[i];
  }
  for(int i=0;i<n-1;i++){
    c-=a[i];d+=a[i];
    m=min(abs(c-d),m);
  }
  cout<<m;
}

Measured memory_bytes: 256