akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end())
#define rsrt(x) sort((x).rbegin(), (x).rend())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
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; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

const ll commax = 1000100;
vll fact(commax);
vll factinv(commax);
vll inv(commax);
void cominit()
{
    fact[0] = fact[1] = 1;
    factinv[0] = factinv[1] = 1;
    inv[1] = 1;
    rep(i, 2, commax) {
        fact[i] = fact[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        factinv[i] = factinv[i-1] * inv[i] % mod;
    }
}

ll com(ll a, ll b)
{
    if (a < b or a < 0 or b < 0) return 0;
    return fact[a] * (factinv[b] * factinv[a-b] % mod) % mod;
}

ll per(ll a, ll b)
{
    if (a < b or a < 0 or b < 0) return 0;
    return fact[a] * factinv[a-b] % mod;
}

ll route(ll a, ll b)
{
    return fact[a+b] * (factinv[a] * factinv[b] % mod) % mod;
}


bool isint(long double a) {
    double e = 1e-6;
    if (abs(a - floor(a)) < e) return true;
    else return false;
}

int main()
{
    ll X, Y;
    cin >> X >> Y;
    //cout << rem(2*Y-X, 3) << ' ' << rem(2*X-Y, 3) << endl;
    if (rem(2*Y-X, 3) != 0 or rem(2*X-Y, 3) != 0 or (2*Y-X) < 0 or (2*X-Y) < 0) {
        cout << 0 << endl;
        return 0;
    }
    ll a = (2*Y-X)/3;
    ll b = (2*X-Y)/3;
    //cout << a << ' ' << b << endl; 
    cominit();
    cout << route(a, b) << endl;
}




Measured memory_bytes: 23680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] x = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var counts = new int[N];
        counts[0] = 1;
        int p = 0;
        int max = 0;
        for (int i = 0; i < N - 1; ++i)
        {
            int rank = Math.Max(i - (x[i] - 1) / 2, 0);
            if (rank > max)
            {
                max = rank;
                counts[p + 1] = counts[p];
                ++p;
            }
            ++counts[p];
        }
        for (int i = p + 1; i < N; ++i) { counts[i] = counts[i - 1]; }
        long ans = 1;
        for (int i = 0; i < N; ++i)
        {
            ans *= counts[i] - i;
            ans %= 1000000007;
        }
        Console.WriteLine(ans);
    }
}


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

int main()
{
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    char str1[1000];
    char str2[1000];
    string ans = "";
    cin >> str1;
    cin >> str2;
    int m1 = strlen(str1) - 1, m2 = strlen(str2) - 1, pre = 0;
    int m = max(m1, m2);
    for(int j = 0; j <= m; j++){
      int sum = pre;
      sum += (m1 >= 0) ? str1[m1--] - '0' : 0;
      sum += (m2 >= 0) ? str2[m2--] - '0' : 0;
      pre = sum / 10;
      sum -= pre * 10;
      ans += '0' + sum;
    }
    if(pre > 0)
      ans += '0' + pre;
    reverse(ans.begin(), ans.end());
    if(ans.length() > 80)
      cout << "overflow" << endl;
    else
      cout << ans << endl;
  }
}

Measured memory_bytes: 1216
import math
a,b,h,m = map(int, input().split())
'''
最小単位: min
時針: 12h = 12*60 min で一周
分針: 1h  =    60 min で一周
H時M分における時針, 分針の角度を求める

余弦定理:
a = sqrt(b^2 + c^2 - 2bc*cos(th))
'''
pi = math.pi
t_min = h*60 + m
th_h = (t_min / 12 / 60) * 2 * pi
th_m = m/60 * 2 * pi

c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(th_h - th_m))
print(c)

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

const li mod = 1e9 + 7;

vector<li> sort(vector<li>& vs) {
    vector<pair<li, li>> ps;
    for (int i = 0; i < vs.size(); ++i) {
        ps.emplace_back(vs[i], i);
    }
    sort(ps.begin(), ps.end());
    vector<li> ret;
    for (int i = 0; i < vs.size(); ++i) {
        ret.push_back(ps[i].second);
    }
    return ret;
}

li solve(li n, vector<li> ls, vector<li> rs) {
    auto move = [&](li fr, li toi) {
        if (fr < ls[toi]) {
            return ls[toi];
        } else if (fr > rs[toi]) {
            return rs[toi];
        } else {
            return fr;
        }
    };

    vector<li> lord = sort(ls);
    vector<li> rord = sort(rs);
    reverse(lord.begin(), lord.end());

    li lp = 0, rp = 0;
    vector<bool> used(n);

    li ans = 0;
    li pos = 0;
    while (true) {
        {
            while (lp < n && used[lord[lp]]) {
                lp++;
            }
            if (lp == n) {
                break;
            }

            li luse = lord[lp];
            used[luse] = true;

            li dest = move(pos, luse);
            ans += abs(dest - pos);
            pos = dest;
        }

        {
            while (rp < n && used[rord[rp]]) {
                rp++;
            }
            if (rp == n) {
                break;
            }

            li ruse = rord[rp];
            used[ruse] = true;

            li dest = move(pos, ruse);
            ans += abs(dest - pos);
            pos = dest;
        }
    }
    return ans + abs(pos);
}

int main() {
    li n;
    cin >> n;
    vector<li> ls(n), rs(n);
    for (int i = 0; i < n; ++i) {
        cin >> ls[i] >> rs[i];
    }
    li ans = solve(n, ls, rs);
    for (int i = 0; i < n; ++i) {
        li nl = rs[i] * -1;
        li nr = ls[i] * -1;
        rs[i] = nr;
        ls[i] = nl;
    }
    ans = max(ans, solve(n, ls, rs));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
#define rep(i,n) for (ll i = 0; i < (n); ++i)
typedef long long int ll;
using ipair = pair<int,int>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
const int MOD=1000000007;

int main(){  
    int h,w,k;
    cin>>h>>w>>k;
    char c[h][w];
    int kr=0;
    rep(i,h)rep(j,w){cin>>c[i][j];if(c[i][j]=='#')kr++;}
    int ans = 0;
    for(int bit= 0; bit < (1<<h); bit++)
    {     
        for (int bi2 = 0; bi2 < (1<<w); bi2++)
        {
            int cnt=kr;
            rep(i,h){
                if(bit&(1<<i)){
                    rep(j,w){if(c[i][j]=='#')cnt--;}
                }
            }
            rep(j,w){
                if(bi2&(1<<j)){
                    rep(i,h){
                        if(c[i][j]=='#'&&!(bit&(1<<i)))cnt--;
                    }
                }
            }
            if(cnt==k)ans++;
        }
        
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <cctype>

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(n),pt(n);
	int ans = 0;
	int PT = 0;
	for(int i=0;i<n;i++){
		a.at(i) = 0;
		pt.at(i) = 0;
	}
	for(int i=0;i<m;i++){
		int p;
		string s;
		cin >> p >> s;
		if(!a.at(p-1) && s == "AC"){
			a.at(p-1) = 1;
		}
		if(!a.at(p-1) && s == "WA"){
			pt.at(p-1)++;
		}
	}
	for(int i=0;i<n;i++){
		if(a.at(i)){
			ans++;
			PT += pt.at(i);
		}
	}
	cout << ans << " " << PT << endl;
	return 0;
}

Measured memory_bytes: 4056
#include <stdio.h>
#include <string.h>

typedef struct{
	char tango[31];
	int page;
}dictionaly;

int main(void) {
	int i,j,n;
	dictionaly dic[100],tmp;
	
	for(n = 0;~scanf("%s %d",dic[n].tango,&dic[n].page);n++);
	
	for(i = 0;i < n-1;i++){
		for(j = i+1;j < n;j++){
			if((strcmp(dic[i].tango,dic[j].tango)>0) || (!strcmp(dic[i].tango,dic[j].tango) && dic[i].page>dic[j].page)){
				tmp = dic[i];
				dic[i] = dic[j];
				dic[j] = tmp;
			}
		}
	}
	
	j = 0;
	printf("%s\n%d",dic[0].tango,dic[0].page);
	for(i = 1;i < n;i++){
		if(!strcmp(dic[i].tango,dic[j].tango)){
			printf(" %d",dic[i].page);
		}else{
			printf("\n");
			j = i;
			printf("%s\n%d",dic[i].tango,dic[i].page);
		}
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 620
//        ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 
 
 
#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000005
#define MOD 1000000007
                                  //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}

 
 
int main() {
    #ifdef sharma
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);      
    #endif
    fastio;
    ll n;
    cin >> n;
    ll a[n];
    ll m = 0;
    ll idx = -1;
    rep(i, n)
    {
        cin >> a[i];
        m = max(m, a[i]);
        if(m == a[i])
            idx = i;
    }
    ll m2 = 0;
    a[idx] = 0;
    rep(i, n)
    {
        m2 = max(m2, a[i]);
    }
    rep(i, n)
    {
        if(i == idx)
            cout << m2 << endl;
        else
            cout << m << endl;
    }
    return 0; 
}

Measured memory_bytes: 3200
import java.util.Scanner;
public class Main {

    static int n;
    static Node node;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        BinTree tree = new BinTree();
        sc.nextLine();
        String com;
        for(int i = 0; i < n;i++){
            com = sc.next();
            if (com.equals("insert")){
                tree.insert(sc.nextInt());
            }
            else{
                tree.inorder(tree.root);
                System.out.println();
                tree.preorder(tree.root);
                System.out.println();
            }
        }
    }

}

class BinTree{

    Node root=null ;
    void insert(int v){
        Node x = root;
        Node y = null;
        Node z = new Node();
        
        z.key = v;
        while( x != null){
            y = x;
            if(z.key < x.key){
                x = x.l;
            }else{
                x = x.r;
            }
        }
        z.p = y;
        if(y == null){
            root = z;
        }else{
            if(z.key < y.key){
                y.l = z;
            }else{
                y.r = z;
            }
        }
    }
    
    void preorder(Node n){
        if(n == null) return;
        System.out.print(" " + n.key);
        preorder(n.l);
        preorder(n.r);
        return;
    }
    void inorder(Node n){
        if(n == null) return;
        inorder(n.l);
        System.out.print(" " + n.key);
        inorder(n.r);
        return;
    }
    
}
class Node{
    Integer key = null;
    Node r,l,p;
    
}



Measured memory_bytes: 342140
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<double,string> P;
static const int INF=1<<24;

bool Pcomp(const P a,const P b){
	return a.F==b.F?a.S<b.S:a.F>b.F;
}

int main(){
	int n;
	P tmp;
	string st;
	int p,a,b,c,d,e,f,s,m;
	while(cin>>n,n){
		//cout<<n<<endl;
		vector<P> v;
		rep(i,n){
			cin>>tmp.S>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			//cout<<tmp.S<<" "<<p<<" "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" "<<s<<" "<<m;
			tmp.F=(double)(f*s*m-p)/((a+b+c)+(d+e)*m);
			v.PB(tmp);
			//cout<<tmp.S<<endl;
		}
		sort(ALL(v),Pcomp);
		rep(i,v.size()){
			cout<<v[i].S<<endl;
		}
		cout<<"#\n";
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int min(int x, int y) {
	if (x > y) return y;
	return x;
}

int main() {
	int n;
	int b[110] = {0};
	int ans=0;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		cin >> b[i];
	}
	ans = b[0] + b[n-2];
	for (int i = 0; i < n-2; i++) {
		ans += min(b[i], b[i + 1]);
	}
	cout << ans << endl;
	return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


int main(){
    ll N;cin>>N;

    vec_int check_vec(1000);
    int index=0;
    rep(i,1000){
        index = index+i+1;
        check_vec.at(i) = index;
    }

    map<int64_t, int> pf = prime_factor(N);

    int sum_val = 0;
    for(auto iter = pf.begin(); iter!=pf.end();iter++){
//        cout<<"key="<<iter->first<<"\n";
        int num = iter->second;

        for(int i=0;i<999;i++){
            if(num>=check_vec.at(i) && num<check_vec.at(i+1)){
                sum_val += i+1;
                break;
            }
        }
    }
    cout<<sum_val<<endl;




    return 0;
}

Measured memory_bytes: 3636
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  while (true) {
    auto rd = readln.split.map!(to!int);
    auto h = rd[0], w = rd[1];

    if (h == 0 && w == 0) break;

    foreach (_1; 0..h) {
      foreach (_2; 0..w)
        write('#');
      writeln;
    }

    writeln;
  }
}

Measured memory_bytes: 2516
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
s=X()
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
print("".join(s))


Measured memory_bytes: 10372
import 'dart:io';

void main() async {
  int n = int.parse(stdin.readLineSync());
  List a = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();

  int count = 1;
  bool flg = true;
  int trend;

  for (int i = 0; i < n - 1; i++) {
    int diff = a[i] - a[i + 1];
    int curr;

    if (diff == 0) continue;
    if (diff > 0) curr = 0;
    if (diff < 0) curr = 1;
    if (flg) {
      trend = curr;
      flg = false;
      continue;
    }

    if (curr == trend) {
      continue;
    } else {
      flg = true;
      trend = curr;
      count += 1;
    }
  }

  print("$count");
}


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

int main() {
	int n, q;
	cin >> n;
	int S[n + 1];
	for (int i = 0; i < n; i++)
		cin >> S[i];
	cin >> q;
	int T[q];
	for (int i = 0; i < q; i++)
		cin >> T[i];
	int ans = 0;
	for (int i = 0; i < q; i++) {
		S[n] = T[i];
		int j = 0;
		ans++;
		while (S[j] != T[i]) {
			j++;
			if (j == n) {
				ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3112
str = input()
order = 1
symbol = True
for c in str:
    if order % 2 == 1:
        if c not in ['R', 'U', 'D']:
            print('No')
            symbol = False
            break
    else:
        if c not in ['L', 'U', 'D']:
            print('No')
            symbol = False
            break
    order += 1

if symbol:
    print('Yes')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int A,B;cin>>A>>B;
  
  if(A==B){
    cout<<"Draw"<<endl;
  }
  else{
    if(A!=1&&B!=1){
      if(A<B){
        cout<<"Bob"<<endl;
      }
      else{
        cout<<"Alice"<<endl;
      }
    }
    else if(A==1&&B!=1){
      cout<<"Alice"<<endl;
    }
    else{
      cout<<"Bob"<<endl;
    }
  }
}

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

int main() {
    int n , m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a.at(i);

    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a.at(i);
        //cout << sum << endl;
    }

    //bool can;
    int cnt = 0;

    for (int i = 0; i < n; i++) {
        if (a.at(i) * (4 * m) >= sum) cnt++; 
    }

   
   

    if (cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleAppTest
{
    class DivGame
    {
        static void Main(string[] args)
        {

            ulong num = ulong.Parse(Console.ReadLine());
            //ulong num = 24;
            ulong checkNum = (ulong)Math.Sqrt(num);
            int methodNum = 0;


            if (num < 2)
            {
                Console.WriteLine(methodNum);
            }
            else
            {
                for (ulong i = 2; i <= checkNum; i += 2)
                {
                    int powCnt = 0;
                    int popCnt = 1;

                    while (num % i == 0)
                    {
                        powCnt++;
                        num /= i;

                        if (powCnt == popCnt)
                        {
                            methodNum++;
                            popCnt++;
                            powCnt = 0;
                        }
                    }
                    if(i == 2)
                    {
                        i--;
                    }
                }

                if(num > checkNum)
                {
                    methodNum++;
                }
                Console.WriteLine(methodNum);
            }
        }
    }
}

Measured memory_bytes: 27604
#include <bits/stdc++.h>
#define int long long
#define ios std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long MOD=LLONG_MAX; //1e5+7;
int gcd(int x, int y)
{
	if(y==0) return x;
	else return gcd(y,x%y);
}
int power(int x, unsigned int y)  
{  
    int res = 1;
    x = x % MOD;
    if (x == 0) return 0;
  
    while (y > 0)  
    { 
        if (y & 1)  
            res = (res*x) % MOD;
        y = y>>1;
        x = (x*x) % MOD;  
    }  
    return res;  
}
void solve()
{
	int n; cin>>n;
	cout<<(1000-n%1000)%1000<<endl;
	
}

int32_t main()
{	
	ios;
	int t=1; 
	//cin>>t;
	while(t--) solve();
}

Measured memory_bytes: 3644
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e6;
vector<pair<int,int> > vec[N + 5];
map<pair<int,int>,int> ms;
deque<int> dq;
int dist[N + 5], vis[N + 5];
int k = 0;

void hora(int tc) {
	int n,m;
	cin>>n>>m;
	for(int i = 1;i <= n;i++) {
		ms[{i, 0}] = ++k;
		ms[{i, -1}] = ++k;
		vec[k - 1].PB({k, 1});
	}
	for(int i = 0;i < m;i++) {
		int u,v,w;
		cin>>u>>v>>w;
		int from = 0, to = 0;
		if(ms[{u,w}] == 0) ms[{u,w}] = ++k;
		if(ms[{v,w}] == 0) ms[{v,w}] = ++k;
		from = ms[{u,w}];
		to = ms[{v,w}];
		vec[from].PB({to, 0});
		vec[to].PB({from, 0});
		vec[ms[{u, -1}]].PB({from, 0});
		vec[ms[{v, -1}]].PB({to, 0});
		vec[from].PB({ms[{u, 0}], 0});
		vec[to].PB({ms[{v, 0}], 0});
	}
	for(int i = 1;i <= k;i++) dist[i] = 1e9;
	int res = 1e9;
	dist[1] = 0;
	dq.push_back(1);
	while(!dq.empty()) {
		int pos = dq.front();
		dq.pop_front();
		if(vis[pos] == 1) continue;
		vis[pos] = 1;
//		cout<<"POS "<<pos<<endl;
		for(int i = 0;i < vec[pos].size();i++) {
			int nx = vec[pos][i].FI;
			int ct = vec[pos][i].SE;
//			cout<<"TEST "<<nx<<" "<<ct<<" "<<dist[nx]<<" "<<dist[pos]<<endl;
			if(dist[nx] > dist[pos] + ct) {
				dist[nx] = dist[pos] + ct;
				if(ct == 0) {
					dq.push_front(nx);
				} else {
					dq.push_back(nx);
				}
			}
		}
	}
	for(auto x: ms) {
		if(x.FI.FI == n) res = min(res, dist[x.SE]);
	}
	if(res == 1e9) res = -1;
	cout<<res<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




Measured memory_bytes: 90368
a1 = input().split(" ")
a2 = input().split(" ")
a3 = input().split(" ")
A = [a1, a2, a3]
N = int(input())
for i in range(N):
    j = input()
    for k in A:
        for l in k:
            if l == j:
                x = k.index(l)
                k.pop(x)
                k.insert(x, "○")
            else:
                pass
ans = 0
for i in A:
    if len(set(i)) == 1:
        ans += 1
    else:
        pass
if a1[0] =="○":
    if a2[0] == "○":
        if a3[0] == "○":
            ans += 1
if a1[1] == "○":
    if a2[1] == "○":
        if a3[1] == "○":
            ans += 1
if a1[2] == "○":
    if a2[2] == "○":
        if a3[2] == "○":
            ans += 1
if a1[0] == "○":
    if a2[1] == "○":
        if a3[2] == "○":
            ans += 1
if a1[2] == "○":
    if a2[1] == "○":
        if a3[0] == "○":
            ans += 1
if ans >= 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload(_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(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
void in(){}
template<typename F, typename... R>
bool in(F& f, R&... r){
    if(cin >> f){in(r...);return true;}
    else return false;
}
#define out(x) cout << (x)
#define space() cout << " "
#define indent() cout << '\n'
void print(){}
template<typename F, typename... R>
void print(F f, R... r){out(f), indent(), print(r...);}
#define debughead(x) cerr << "Line " << __LINE__ << ": " << #x << ": "
#define debugout(x) cerr << (x) << " "
#define debugindent() cerr << '\n'
#define debug(x) debughead(x), debugout(x), debugindent()
const int INF = 1e18, MOD = 1e9 + 7;
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
struct UF{
    vector<int> t;
    UF(int size): t(size, -1){}
    int root(int x){return t[x] < 0 ? x : t[x] = root(t[x]);}
    int size(int x){return -t[root(x)];}
    bool isSame(int x, int y){return root(x) == root(y);}
    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x != y){
            if(t[y] < t[x]){
                swap(x, y);
            }
            t[x] += t[y], t[y] = x;
        }
        return x != y;
    }
};
main(){
    INCANT;
    int n, m, a, b, c, res = 0;
    in(n, m);
    UF t(n + 1);
    rep(i, m){
        in(a, b, c);
        t.unite(a, b);
    }
    set<int> s;
    rep(i, 1, n + 1){
        s.insert(t.root(i));
    }
    print(s.size());
}


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

using namespace std;
 
int main(void) {
  string s;
  int flag = 1;
  cin >> s;
  for (int i = 0; i < 3; i++) {
    if (s[i] == s[i+1]) {
      flag = 0;
      cout << "Bad" << endl;
      break;
    }
  }
  if (flag == 1) {
    cout << "Good" << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int main(void)
{
  int K, X;
  cin >> K >> X;

  int l = max(X - (K - 1), -1000000);
  int r = min(X + (K - 1), 1000000);
  for (int i = l; i <= r; i++) {
    cout << i << (i == r ? "\n" : " ");
  }

  return 0;
}


Measured memory_bytes: 888
n,C,*H=map(int,open(0).read().split());p=[0];P=[0]
for i in range(1,n):
 h=H[i];g=lambda x,y:(p[P[y]]-p[P[x]])/(H[P[x]]-H[P[y]])-H[P[y]]-H[P[x]]+2*h;
 while len(P)>1and g(1,0)>0:P.pop(0)
 p+=[p[P[0]]+(H[P[0]]-h)**2+C];P+=[i];h=0
 while len(P)>2and g(-1,-2)>g(-2,-3):P.pop(-2)
print(p[-1])

Measured memory_bytes: 27232
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);

		int nx = stdIn.nextInt();
        int [] x = new int[nx];
		int times = 0;
        int work;

        for(int i = 0; i < nx; i++){
        	x[i] = stdIn.nextInt();
        }

		for (int i = 0; i < x.length - 1; i++) {
            for (int j = x.length -1; j >= i+1; j--) {
                    if(x[j] < x[j-1]){
                        work = x[j-1];
                        x[j-1] = x[j];
                        x[j] = work;
            		    times++;
                    }
            }
        }
        out_put(x);
        System.out.println(times);
	}
	private static void out_put(int array[]){

        System.out.printf("%d", array[0]);

        for(int i = 1; i < array.length; i++){
            System.out.printf(" %d", array[i]);
        }
        System.out.printf("\n");
    }

}



Measured memory_bytes: 26440
REGEX = /(.AGC|A.GC|AG.C|.ACG|.GAC)/
DIVISOR = 10**9 + 7

def calc(n)
  return { "A" => 1, "C" => 1, "G" => 1, "T" => 1 } if n == 1
  res = calc(n-1)
  new_res = {}
  res.each do |k, v|
    "AGCT".each_char do |ch|
      cand = k + ch
      cand.slice!(0, 1) if cand.size > 4
      if cand.size < 4
        if cand != "AGC" && cand != "ACG" && cand != "GAC"
          new_res[cand] = 1
        end
      else
        if !REGEX.match(cand)
          new_res[cand] ||= 0
          new_res[cand] += v
        end
      end
    end
  end
  new_res
end

puts((calc gets.to_i).values.inject(&:+) % DIVISOR)


Measured memory_bytes: 2300
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<unordered_map>
#include<stack>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<complex>
#include<bitset>
#include<iostream>
using namespace std;

/**** Type Define ****/

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;

int n,ans;
/**** main function ****/
int main(){
  scanf("%d",&n);
  vector<int> p(n);
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  for(int i=0;i<n-2;i++){
    if(p[i]<p[i+1] && p[i+1] <p[i+2] || (p[i]>p[i+1] && p[i+1] >p[i+2])) ans++;
  }
  printf("%d",ans);
}


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


int main() {
  int N;
  long long int Ans=0;
	cin >> N;
    vector<long long int> vec(N);
  
  	for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
  
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
  
  for (int i = 1; i < N; i++) {
        Ans = Ans + vec.at(i/2);
    }
    
    cout << Ans;

}

Measured memory_bytes: 4836
n,m=map(int,input().split())

listA=[]
for i in range(n):
    listA.append(list(map(int,input().split())))

for i in range(n):
    popped_item1=listA[i].pop(0)

listB=[]
for i in listA:
    for j in i:
        listB.append(j)

cnt=0
for i in range(m+1):
    if listB.count(i)==n:
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    map<int, int> mp;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        B[i] = A[i];
        mp[A[i]] = i;
    }

    sort(B.begin(), B.end());
    int cnt = 0;
    vector<bool> mov(N);
    for (int i = 0; i < N; ++i) {
        if ((mp[B[i]] ^ i) & 1)
            cnt++;
    }

    cout << cnt / 2 << endl;

    return 0;
}


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

int main() {

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

	int h = 0;
	long long ans = 0;

	for (int i = 0; i < n; i++) {
		if (h > a[i]) {
			ans += h - a[i];
		}
		else {
			h = a[i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
int main(){
    long long _,a,b,c,d;
    std::cin>>a>>b>>_>>c>>d>>_>>_;
    std::cout<<b+std::max(2*(a/2+c/2+d/2),(a&&c&&d)*(2*((a-1)/2+(c-1)/2+(d-1)/2)+3))<<std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
using namespace std;
using ll = long long;

bool check_up (int *p,int N){
    bool flag = true; 
    for(int i=0;i<N-1;i++){
        if (p[i+1] < p[i]){
            flag = false;
        }
    }
    return flag;
}

int main(){
    int N;
    cin >> N;
    int p[N],q[N];
    bool flag = true;
    for (int i=0;i<N;i++){
        cin >> p[i];
    }

    for(int i=0;i<N;i++){
        int tmp = p[i];
        for(int j=i;j<N;j++){
            p[i] = p[j];
            p[j] = tmp;         
            if (check_up(p,N)){
                cout << "YES";
                return 0;
            }
            p[j] = p[i];
            p[i] = tmp;
        }
    }
    cout << "NO";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;

class UnionFind {
  public:
    UnionFind(int n): par(n, -1) { }
    int root(int x) {
      if (par[x] < 0) 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 (par[y] < par[x]) swap(x, y);
      par[x] += par[y];
      par[y] = x;
    }
    bool same(int x, int y) {
      return root(x) == root(y);
    }
    int size(int x) {
      return -par[root(x)];
    }

  private:
    vector<int> par;
};

// el[i] = (cost, from, to)
int getMst(int V, vector<pair<ll, pair<int, int>>>& el)
{
  sort(el.begin(), el.end());
  UnionFind uf(V);
  ll ret = 0;
  for (auto e : el) {
    if (!uf.same(e.SE.FI, e.SE.SE)) {
      uf.unite(e.SE.FI, e.SE.SE);
      ret += e.FI; 
    }
  }
  return ret;
}

int main()
{
  int N;
  cin >> N;
  vector<pair<ll, int>> xorder, yorder;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    xorder.PB(MP(x, i));
    yorder.PB(MP(y, i));
  }
  sort(ALL(xorder));
  sort(ALL(yorder));
  
  vector<pair<ll, pair<int, int>>> edge;
  for (int i = 0; i < N - 1; i++) {
    ll cost = abs(xorder[i].FI - xorder[i+1].FI);
    edge.PB(MP(cost, MP(xorder[i].SE, xorder[i+1].SE)));
  }
  for (int i = 0; i < N - 1; i++) {
    ll cost = abs(yorder[i].FI - yorder[i+1].FI);
    edge.PB(MP(cost, MP(yorder[i].SE, yorder[i+1].SE)));
  }
  
  cout << getMst(N, edge) << endl;

  return 0;
}


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

int maxhappiness(vector<int>a,vector<int>b,vector<int>c)
{
    int n=a.size();
    if(n==0)
        return 0;
    int ad=a[0],bd=b[0],cd=c[0];
    for(int i=1;i<n;i++)
    {
        int ta=ad,tb=bd,tc=cd;
        ad=a[i]+max(tb,tc);
        bd=b[i]+max(ta,tc);
        cd=c[i]+max(ta,tb);
    }
    
    return max(ad,max(bd,cd));
}

int main()
{
  int n;
  cin>>n;
  vector<int>a(n);
    vector<int>b(n);
    vector<int>c(n);
  for(int i=0;i<n;i++)
  {
    cin>>a[i]>>b[i]>>c[i];
  } 
  cout<<maxhappiness(a,b,c)<<endl;
  return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#define N 10

main() {
  int hills[N], max, i, j;

  for(i=0 ; i<N ; i++) {
    scanf("%d", &hills[i]);
  }

  for(i=0 ; i<N-1 ; i++) {
    max = hills[i];
    for(j=i ; j<N ; j++) {
      if(hills[i] < hills[j]) {
	max = hills[j];
	hills[j] = hills[i];
	hills[i] = max;
      }
    }
  }
  printf("%d\n%d\n%d\n", hills[0], hills[1], hills[2]);
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main()
{

    int c;
    cin >>c;
     int a[c];
     for(int i=0;i<c;i++){
        cin >>a[i];
     }
     unordered_set<int> s;
    for (int i = 0; i < c; i++) {
        s.insert(a[i]);
    }

    if(s.size() == c){
            cout << "YES"<< endl;
      }else {
              cout << "NO" << endl;
      }
}


Measured memory_bytes: 9288
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
typedef std::pair<int, int> Par;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 200005, mod = 1000000007;
int l[maxn], r[maxn];
int p[maxn];
int tmp[maxn];
Par pr[maxn];
ll f[maxn], s[maxn];

int main() {
	int n = read;

	for(int i = 1; i <= n; i ++)
		read(pr[i].second, pr[i].first);
	std::sort(pr + 1, pr + n + 1);

	for(int i = 1; i <= n; i ++)
		tmp[i] = pr[i].second;
	std::sort(tmp + 1, tmp + n + 1);

	for(int i = 1; i <= n; i ++) {
		pr[i].second = int(std::lower_bound(tmp + 1, tmp + n + 1, pr[i].second) - tmp);
		p[pr[i].second] = i;
	}

	for(int i = 1; i <= n; i ++)
		r[i] = std::max(r[i - 1], p[i]);
	l[n] = p[n];
	for(int i = n - 1; i; i --)
		l[i] = std::min(l[i + 1], p[i]);

	/* for(int i = 1; i <= n; i ++) */
	/* 	debug("%d-%d\n", l[i], r[i]); */

	int L = 0;
	f[0] = s[0] = 1;

	for(int i = 1; i <= n; i ++) {
		while(r[L] < l[i] - 1)
			++ L;
		f[i] = (s[i - 1] - s[L - 1] + mod) % mod;
		s[i] = (s[i - 1] + f[i]) % mod;
		/* debug("%lld\n", f[i]); */
	}

	while(r[L] < n)
		++ L;
	printf("%lld\n", (s[n] - s[L - 1] + mod) % mod);
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
   void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int N;
vec<vec<int>> G;

void dfs(int pos, int par, int cost, vec<int> &dist) {
   dist[pos] = cost;
   for (int to : G[pos]) {
      if (to != par) {
         dfs(to, pos, cost+1, dist);
      }
   }
}

int main() {
   cin >> N;
   G = vec<vec<int>>(N);
   rep (i, N-1) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }
   vec<int> dist1(N), dist2(N);
   dfs(0, -1, 0, dist1);
   dfs(N-1, -1, 0, dist2);

   int b = 0, w = 0;
   rep (i, N) {
      if (dist1[i] <= dist2[i]) {
         b++;
      } else {
         w++;
      }
   }

   if (b > w) {
      puts("Fennec");
   } else {
      puts("Snuke");
   }

   return 0;
}

Measured memory_bytes: 12800
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    let c=read::<i32>();
    println!("{}",if b>=c{"delicious"}else if a+b>=c{"safe"}else{"dangerous"})
}

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

int main() {
    
    int k;
    vector<int> A(3);
    cin >> A[0] >> A[1] >> A[2] >> k;

    int ans = 0;
    vector<int> B = {1, 0, -1};

    for (int i=0; i<3; i++)
    {
        if (A[i] >= k)
        {
            ans += k * B[i];
            break;
        }

        ans += A[i] * B[i];
        k -= A[i];
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3628
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int a[5], k; cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4]>>k;
	string ans = "Yay!";
	rep(i, 0, 5) rep(j, 0, 5) {
		if (abs(a[i] - a[j]) > k) ans = ":(";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int main(){

    double W, H, x, y;
    cin >> W >> H >> x >> y;

    double ans = (W * H) / 2.0;
    cout << ans << " ";

    if(x * 2 == W && y * 2 == H){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

bool solve(const vector<string>& W)
{
    const int n=W.size();
    //condition1
    for(int i=0; i<n-1; i++)
    {
        if(W[i].back()!=W[i+1].front()){ return  false;}
    }
    //condition2
    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            if(W[i]==W[j]) return false;
        }
    }
    return true;
}

vector<string> input()
{
 int n; cin>>n;
 vector<string> W(n);
 REP(i,n) cin>>W[i];
 return W;
}

int main() {
const vector<string>W=input();
if(solve(W)){cout<<"Yes"<<endl;}
else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    int ac=0,wa=0,tle=0,re=0;
    REP(i,N){
        string s;cin>>s;
        if(s=="AC") ac++;
        if(s=="WA") wa++;
        if(s=="TLE") tle++;
        if(s=="RE") re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3628
use std::cmp;

const INF: i64 = 1e17 as i64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let mut graph = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let v = sc.read::<usize>() - 1;
        let u = sc.read::<usize>() - 1;
        graph[v].push(u);
        graph[u].push(v);
    }

    let mut dp1 = vec![vec![]; n];
    let mut dp2 = vec![vec![]; n];
    dfs(0, 0, &graph, &a, &mut dp1, &mut dp2);

    for i in 0..n {
        if dp1[0][i] < INF {
            println!("{}", i);
            return;
        }
        if dp2[0][i] < 0 {
            println!("{}", i);
            return;
        }
    }
}

fn dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<usize>>,
    a: &Vec<i64>,
    dp1: &mut Vec<Vec<i64>>,
    dp2: &mut Vec<Vec<i64>>,
) {
    dp1[v].push(if a[v] > 0 { a[v] } else { INF });
    dp2[v].push(a[v]);
    for &next in graph[v].iter() {
        if next == p { continue; }
        dfs(next, v, graph, a, dp1, dp2);

        dp1[v] = connect(&dp1[v], &dp1[next], &dp2[next], true);
        dp2[v] = connect(&dp2[v], &dp1[next], &dp2[next], false);
    }
}

fn connect(dp: &Vec<i64>, child1: &Vec<i64>, child2: &Vec<i64>, power_only: bool) -> Vec<i64> {
    let mut ans = vec![INF; dp.len() + child1.len() + 1];
    for cuts in 0..dp.len() {
        if dp[cuts] == INF { continue; }
        for child_cuts in 0..child1.len() {
            let total_cuts = cuts + child_cuts + 1;

            if child1[child_cuts] != INF {
                ch_min(&mut ans[total_cuts - 1], dp[cuts] + child1[child_cuts]);
            }
            if child2[child_cuts] != INF && !power_only {
                ch_min(&mut ans[total_cuts - 1], dp[cuts] + child2[child_cuts]);
            }
            if child1[child_cuts] != INF || child2[child_cuts] < 0 {
                ch_min(&mut ans[total_cuts], dp[cuts]);
            }
        }
    }
    ans
}

fn ch_min<T: PartialOrd>(a: &mut T, b: T) {
    if *a > b {
        *a = b;
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 408444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    string s,x="",y="";
    int t,q,a,c=0;
    cin>>s;
    cin>>q;
    while(q--)
    {
        cin>>t;
        if(t==1)
            c++;
        else
        {
            char ch;
            cin>>a>>ch;
            if(a==1)
            {
                if(c&1)
                    y+=ch;
                else
                    x=ch+x;
            }
            else
            {
                if(c&1)
                    x=ch+x;
                else
                    y+=ch;
            }
        }
    }
    s=x+s+y;
    if(c&1)
        reverse(s.begin(),s.end());
    cout<<s<<endl;
}


Measured memory_bytes: 1316
/**
     *      ABC 65 A
     *      author  : kyomukyomupurin
     *      created : 2018-09-04 23:40:46
    **/
     
    #include <bits/stdc++.h>
    using namespace std;
     
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        
        int X, A, B; cin >> X >> A >> B;
        if (A >= B){
            cout << "delicious" << endl;
        }
        else if (B - A <= X){
            cout << "safe" << endl;
        }
        else {
            cout << "dangerous" << endl;
        }
        return 0;
    }

Measured memory_bytes: 256