akhauriyash/Code-Regression huggingface dataset:
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n%2!=0)
    {
        cout<<"0"<<endl;
        return 0;
    }
    sort(a,a+n);
    ll x=n/2;
    ll y=a[x];
    ll z=a[x-1];
    ll ans=y-z;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 1024
using System;

namespace AtCoderBeginnerContest118_3
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] A = new int[N];

            string[] s = Console.ReadLine().Split(' ');

            for (int i = 0; i < N; i++)
                A[i] = int.Parse(s[i]);

            Array.Sort(A);
        
            while(A.Length > 1)
            {
                for(int i=1;i<A.Length;i++)
                {
                    A[i] = A[i] % A[0];
                }

                Array.Sort(A);

                for(int i=0;i<A.Length;i++)
                {
                    if(A[i] > 0)
                    {
                        int[] B = new int[A.Length -i];
                        Array.Copy(A, i, B, 0, A.Length - i);
                        A = B;
                        break;
                    }
                }

            }

            Console.WriteLine(A[0].ToString());
        }
    }
}


Measured memory_bytes: 20448
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
using namespace std;

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

    string com;
    int n, c;
    cin>>n;
    string s;
    cin>>s;
    int mb = 0;

    for(int i = 0; i < n-1; i++){
        if((s[i] == 'O' && s[i+1] == 'X') || (s[i] == 'X' && s[i+1] == 'O')){
            mb += 1;
            i++;
        }
    }
    cout<<mb<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
vector<ii> g[100010];

ll dist[100010];
void dfs(int u, int p)
{
	for(auto next : g[u]) {
		int v = next.first;
		int w = next.second;

		if(v == p)
			continue;
		dist[v] = dist[u] + w;
		dfs(v, u);
	}
}

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

	for(int i = 0; i < n - 1; i++) {
		int u, v, w;
		scanf("%d %d %d\n", &u, &v, &w);

		g[u].push_back(ii(v, w));
		g[v].push_back(ii(u, w));
	}

	int q, k;
	scanf("%d %d", &q, &k);
	
	dist[k] = 0;
	dfs(k, -1);

	for(int i = 0; i < q; i++) {
		int u, v;
		scanf("%d %d", &u, &v);

		printf("%lld\n", dist[u] + dist[v]);
	}

	return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> B;
    B.push_back(1e9);
    for (int i = 0; i < N - 1; i++) {
        int b;
        cin >> b;
        B.push_back(b);
    }
    B.push_back(1e9);

    ll sum = 0;
    for (int i = 0; i < B.size() - 1; i++) {
        sum += min(B[i], B[i + 1]);
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

if N == 1:
    print(1)
    exit()
ans = 1
pm = 1

i = 0
tmp = []
while i < N:

    if i == 0:
        if A[i] <= A[i+1]:
            pm = 1
        else:
            pm = -1

        i += 1
    else:
        if pm*(A[i] - A[i-1]) >= 0:
            i += 1
            if pm == 0 and A[i] != A[i-1]:
                if A[i-1] < A[i]:
                    pm = 1
                else:
                    pm = -1
        else:
            i += 1
            if N <= i:
                ans += 1
                break

            if A[i-1] == A[i]:
                pm = 0
            elif A[i-1] < A[i]:
                pm = 1
            else:
                pm = -1

            ans += 1


print(ans)


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

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = new List<int>();
        for (int i = 0; i < N; ++i)
            A.Add(int.Parse(Console.ReadLine()));
        var B = new List<int>(A);
        B.Remove(B.Max());
        var max = A.Max();
        var secondmax = B.Max();

        if (max == secondmax)
            for (int i = 0; i < N; ++i)
                Console.WriteLine(max);
        else
        {
            var indx = A.IndexOf(A.Max());
            if (indx == 0)
            {
                Console.WriteLine(secondmax);
                for (int i = indx + 1; i < N; ++i)
                {
                    Console.WriteLine(max);
                }
            }
            else if (indx == N - 1)
            {
                for (int i = 0; i < indx ; ++i)
                {
                    Console.WriteLine(max);
                }
                Console.WriteLine(secondmax);
            }
            else
            {
                for (int i = 0; i < indx; ++i)
                {
                    Console.WriteLine(max);
                }
                Console.WriteLine(secondmax);
                for (int i = indx + 1; i < N; ++i)
                {
                    Console.WriteLine(max);
                }
            }
        }
    }
}



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

using namespace std;

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

typedef long long ll;

int beki(int x)
{
	int s=0, tmp=1;
	while(tmp<=x)
	{
		s++;
		tmp*=2;
	}
	return tmp;
}

int main()
{
	int n;
	int a[200010];
	cin >> n;
	rep(i, n) cin >> a[i];
	sort(a, a+n);
	map<int, int> T;
	rep(i, n) T[a[i]]++;
	int ans=0;
	for(int i=n-1; i>0; i--)
	{
      	T[a[i]]--;
		int tmp=beki(a[i])-a[i];
		if(T[a[i]]>=0 && T[tmp]>0)
		{
			ans++;
			T[tmp]--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

void Main() {
    // input
    u_int32_t N;
    cin >> N;
    u_int32_t nums[N];

    for (u_int32_t i = 0; i < N; i++) {
        cin >> nums[i];
    }

    u_int32_t count = 0;
    u_int32_t min = 200000 + 1;
    // process
    for (u_int32_t i = 0; i < N; i++) {
        if (nums[i] < min) {
            count++;
            min = nums[i];
        }
    }

    // output
    cout << count << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 4416
import sys
import collections

n = int(sys.stdin.readline().rstrip("\n"))
l = []
for a in range(1,100):
    for b in range(1,100):
        for c in range(1,100):
            l.append(a**2+b**2+c**2+a*b+b*c+c*a)
c = collections.Counter(l)
for i in range(1,n+1):
    print(c[i])

Measured memory_bytes: 131772
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = []
for i in range(N - K + 1):
    t = abs(x[i] - x[i + K - 1])
    ans.append(min(abs(x[i]) + t, abs(x[i + K - 1]) + t))
print(min(ans))


Measured memory_bytes: 14392
def BC132_E():
    n, m = list(map(int, input().split(' ')))
    e = [[] for _ in range(n)]
    for _ in range(m):
        u, v = list(map(int, input().split(' ')))
        e[u - 1].append(v - 1)
    s, t = list(map(int, input().split(' ')))
    s, t = s - 1, t - 1
    stack, visited = [(s, 0)], set()
    a, b = set(), set()
    while stack:
        i, d = stack.pop(0)
        if i == t: return d
        if i in visited:
            continue
        visited.add(i)
        v = set()
        for j in e[i]:
            if j in a: continue
            a.add(j)
            for k in e[j]:
                if k in b: continue
                b.add(k)
                v.update(e[k])
        if t in v:
            return d + 1
        else:
            stack += [(x, d + 1) for x in list(v)]
    return -1


print(BC132_E())

Measured memory_bytes: 38672
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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 MOD=1e9+7;
const ll INF=1e18;
const ll inf=1e9;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

ll dp[100010][13];


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  string s;
  cin >> s;
  int n = s.size();
  
  memset(dp, 0, sizeof(dp));
  
  dp[0][0] = 1;
  rep(i,n){
    rep(j,13){
      if(s[i] == '?'){
        rep(k,10){
          dp[i+1][(j*10+k)%13] += dp[i][j];
          dp[i+1][(j*10+k)%13] %= MOD;
        }
      }
      else{
        int k = s[i] -'0';
        dp[i+1][(j*10+k)%13] += dp[i][j];
        dp[i+1][(j*10+k)%13] %= MOD;
      }
    }
  }
  cout << dp[n][5] << endl;
  return 0;
}


Measured memory_bytes: 13944
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define answer(formula) formula ? cout << "Yes" << endl : cout << "No" << endl
#define ANSWER(formula) formula ? cout << "YES" << endl : cout << "NO" << endl

#define PI 3.14159265358979323846
#define INF 1050000000
#define MOD 1000000007
#define EPS (1e-10)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int, int>> vp;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvll;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<pair<int, int>>> vvp;

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

/*<ここから>***********************************************************/

int main()
{
	int N;
	ll sum = 0;
	cin >> N;
	vll a(N);
	rep(i, N) {
		cin >> a[i];
		sum += a[i];
	}

	vll as(N + 1, 0);
	rep(i, N) as[i + 1] = a[i];
	rep(i, N) as[i + 1] += as[i];

	ll mi = 2e+9 + 1;
	repr(i, 1, N) {
		mi = min(mi, abs(as[i] - sum + as[i]));
	}

	cout << mi << endl;

	return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int data[12]={31,29,31,30,31,30,31,31,30,31,30,31};
	string out[7]={
	"Wednesday",
	"Thursday",
	"Friday",
	"Saturday",
	"Sunday",
	"Monday",
	"Tuesday"
	};
	int a,b;
	while(cin>>a>>b,a+b){
		int sum=b;
		rep(i,a-1)sum+=data[i];
		cout<<out[sum%7]<<endl;
	}
}

Measured memory_bytes: 1196
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
string s,t;
int N;
ll K;
vector<ll> A;
vector<ll> factors;
int main(){
	cin>>N>>K;
	int sum=0;
	rep(i,N){
		ll x;
		cin>>x;
		A.pb(x);
		sum+=x;
	}
	for(int i=1;i*i<=sum;i++){
		if(sum%i==0){
			factors.pb(i);
			factors.pb(sum/i);
		}
	}
	ll ans=1;
	rep(i,factors.size()){
		ll num=factors[i];
		bool flag=false;
		ll hoge[505];
		ll sumres=0,nowres=0;
		rep(j,N){
			hoge[j]=A[j]%num;
			sumres+=hoge[j];
		}
		sort(hoge,hoge+N);
		rep(j,N){
			nowres+=hoge[j];
			if(nowres>=((ll)(N-j-1)*num-(sumres-nowres))){
				if(nowres<=K)flag=true;
			}
		}
	

		if(flag)ans=max(ans,num);
	}
	cout<<ans<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
            #define ll long long
            #define MOD 1000000007
            #define maxx ((ll)1e6+5)
            #define zuciso ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define test ll t; cin>>t; while(t--)
            #define int long long
            #define INF 1000000000000000005
            #define pb push_back
            #define pi 3.1415926
            #define MAX 300006
            #define MAX_N 1000000
            #define N 15000005
            #define fori(i,a,b) for(int i=a;i<b;i++)
            ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
            ll fact[1000007]={0};
            void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
            ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[r],MOD-2)))%MOD; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
            ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
            ll modmul(ll x, ll y){return (x*y)%MOD;}
            ll modadd(ll x, ll y){return (x+y)%MOD;}
            ll modsub(ll x, ll y){return (x-y+MOD)%MOD;}
            ll xx[4]={1,0,-1,0};
            ll yy[4]={0,1,0,-1};
           using namespace std;


            signed main(){
                zuciso;
                int n,k;
                cin>>n>>k;
                int a[n];
                fori(i,0,n){
                    cin>>a[i];

                }
                int b[n];

                while(k--){
                    fori(i,0,n)b[i]=0;
                    fori(i,0,n){

                        b[max(0LL,i-a[i])]+=1;

                        if(i+a[i]+1<n)
                        b[i+a[i]+1]-=1;
                    }

                    fori(i,1,n){

                        b[i]+=b[i-1];

                    }
                    int f=0;
                    fori(i,0,n){
                       // cout<<b[i]<<" ";
                        if(b[i]!=n){

                            f=1;
                        }

                    }
                    fori(i,0,n){
                        a[i]=b[i];
                    }

                    if(f==0){
                        break;
                    }

            }

            fori(i,0,n){
                cout<<a[i]<<" ";
            }
            }


Measured memory_bytes: 6776
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
first_max = b[-1]
second_max = b[-2]
if first_max == second_max:
    for i in range(n):
        print(first_max)
else:
    for i in range(n):
        if a[i] == first_max:
            print(second_max)
        else:
            print(first_max)
            

Measured memory_bytes: 14112
import java.util.Scanner;
import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException {

        Scanner sc = new Scanner(System.in);
        int s = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        sc.close();
        String result = "safe";
        if (w >= s) {
            result = "unsafe";
        }
        System.out.println(result);
    }
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    int A,B,C;
    cin >> A >> B >> C;

    cout << max( C-(A-B), 0 ) << endl;
}


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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

const int MOD1=1000000007;
const int MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const int dx[]={0,1,0,-1,1,-1,1,-1};
const int dy[]={1,0,-1,0,1,1,-1,-1};

#define unless(a) if(!(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(n);i++)
#define bitrep(i,s,n) for(int i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}
long long cutup(long long a,long long b){return (a+b-1)/b;}
long long popcnt(long long a){return __builtin_popcountll(a);}
template<class T,class U> inline bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template<class T,class U> inline bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

struct edge{long long to,cost;};
struct edge2{long long from,to,cost;};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vl A(n);
    rep(i,n)cin>>A[i];
    int a=0;
    ll res=1;
    rep(i,n-1){
        if(!a&&A[i+1]>A[i]){
            a=1;
        }else if(!a&&A[i+1]<A[i]){
            a=2;
        }else if(a==1&&A[i+1]<A[i]){
            a=0;
            res++;
        }else if(a==2&&A[i+1]>A[i]){
            a=0;
            res++;
        }
    }
    cout<<res<<endl;
}

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  int ans = 0;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  
  for (int i=0; i<N; i++) {
    cin >> C.at(i);
    for (int j=0; j<M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  vector<int> f;
  for (int s=0; s<(1<<N); s++) {
    int cost = 0;
    vector<int> d(M);//i番めの本の組み合わせでのj番めのアルゴリズムの理解度
    for (int i=0; i<N; i++) {
      if (s>>i&1) {
        cost += C.at(i);
        for (int j=0; j<M; j++) {
          d.at(j) += A.at(i).at(j);
        }
      }
    }
    bool e = true;
    for (int j=0; j<M; j++) {
      if (d.at(j) < X) {
        e = false;
        break;
      }
    }
    if (e) {
      f.push_back(cost);
    }
  }
  if (f.empty()) {
    ans = -1;
  }
  else {
    sort(f.begin(), f.end());
    ans = f.at(0);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int left = a + b;
    int right = c + d;
    if (left > right)
        cout << "Left\n";
    else if (left < right)
        cout << "Right\n";
    else
        cout << "Balanced\n";
}


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

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var l = new int[N + 1];
            var r = new int[N + 1];

            l[0] = 0;
            for (int i = 0; i < N; i++)
            {
                l[i + 1] = Gcd(l[i], A[i]);
            }

            r[N] = 0;
            for (int i = N - 1; i > 0; i--)
            {
                r[i] = Gcd(r[i + 1], A[i]);
            }

            var m = new int[N + 1];
            for (int i = 0; i < N; i++)
            {
                m[i] = Gcd(l[i], r[i + 1]);
            }

            Console.WriteLine(m.Max());
        }

        private static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}

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

int main()
{
	int a, b;
	int keta;

	while( cin >> a >> b )
	{
		keta = 0;
		a += b;
		while( 1 )
		{
			a /= 10;
			if( a != 0 )
			{
				keta++;	
			}else{
				break;
			}
		}
		cout << ( keta + 1 ) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include "stdio.h"
#include <algorithm>

using namespace std;

int N;

#define USED -1
//#define _DEBUG_


int main(int argc, char* argv[])
{
	int ans = 0;
	int i, j;
	pair<int, int> red[100];
	pair<int, int> blue[100];

#if 0
	N = 5;

	red[0].first = 0;
	red[0].second = 0;
	red[1].first = 7;
	red[1].second = 3;
	red[2].first = 2;
	red[2].second = 2;
	red[3].first = 4;
	red[3].second = 8;
	red[4].first = 1;
	red[4].second = 6;
	blue[0].first = 8;
	blue[0].second = 5;
	blue[1].first = 6;
	blue[1].second = 9;
	blue[2].first = 5;
	blue[2].second = 4;
	blue[3].first = 9;
	blue[3].second = 1;
	blue[4].first = 3;
	blue[4].second = 7;
#else
	scanf("%d", &N);

	for(i=0; i<N; i++){
		scanf("%d%d", &red[i].first, &red[i].second);
	}
	for(i=0; i<N; i++){
		scanf("%d%d", &blue[i].first, &blue[i].second);
	}
#endif

	//blue point sort by x (ascending order)
	{
		pair<int, int> tmp_pair;

		for(i=0; i<N-1; i++){
			for(j=0; j<N-i-1; j++){
				if(blue[j].first>blue[j+1].first){
					tmp_pair = blue[j];
					blue[j] = blue[j+1];
					blue[j+1] = tmp_pair;
				}
			}
		}
	}

	//red point sort by y (descending order)
	{
		pair<int, int> tmp_pair;

		for(i=0; i<N-1; i++){
			for(j=0; j<N-i-1; j++){
				if(red[j].second<red[j+1].second){
					tmp_pair = red[j];
					red[j] = red[j+1];
					red[j+1] = tmp_pair;
				}
			}
		}
	}

	for(i=0; i<N; i++){  //blue
		if(blue[i].first==USED) continue;
		for(j=0; j<N; j++){  //red
			if(red[j].first==USED) continue;
			if(blue[i].first>red[j].first && blue[i].second>red[j].second){
#ifdef _DEBUG_
				printf("blue=%d %d pair with red=%d %d\r\n", blue[i].first, blue[i].second, red[i].first, red[i].second);
#endif
				ans++;
				blue[i].first=USED;
				red[j].first=USED;
			}
		}
	}


	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 128
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	s := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		s[i], _ = strconv.Atoi(sc.Text())
	}

	cnt := mergeSort(&s, 0, len(s), 0)
	fmt.Println(strings.Trim(fmt.Sprint(s), "[]"))
	fmt.Println(cnt)
}

func mergeSort(a *[]int, l int, r int, cnt int) int {
	if l + 1 < r {
		m := (l + r) / 2
		cnt = mergeSort(a, l, m, cnt)
		cnt = mergeSort(a, m, r, cnt)
		cnt = merge(a, l, m, r, cnt)
	}
	return cnt
}

func merge(a *[]int, l int, m int, r int, cnt int) int {
	ll := append([]int{}, (*a)[l:m]...)
	ll = append(ll, 1 << 30)
	rr := append([]int{}, (*a)[m:r]...)
	rr = append(rr, 1 << 30)

	i := 0
	j := 0
	for k := l; k < r; k++ {
		if ll[i] <= rr[j] {
			(*a)[k] = ll[i]
			i++
		} else {
			(*a)[k] = rr[j]
			j++
		}
		cnt++
	}
	return cnt
}



Measured memory_bytes: 32004
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int n,z,w;
vector<int> a(2010,0);
vector<int> dp(2010,-1);		//dp[i] x ga i get   score

int dfs(int k){
  if(dp[k]!=-1){ return dp[k]; }
  int ret=abs(a[k]-a[n-1]);
  
  if(k==n-1){ ret=abs(a[k]-w); return dp[k]=ret; }
  if(k==n-2){ ret=abs(a[k]-a[k+1]); return dp[k]=ret; }
  for(int i=k+1; i<n; i++){
    ret = min(ret,dfs(i));
  }  
  return dp[k]=ret;
}

int main(){
  cin >> n >> z >> w;
  rep(i,n){ cin >> a[i]; }
  int ans = dfs(0);
  rep(i,n){ ans = max(ans,dp[i]); }  
  cout << ans << endl;
  return 0;
}


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

const int N = 500005;

int n, f[N][2], g[N][2];
char str[N], ans[N];

int main () {
	scanf("%s", str);
	n = strlen(str);

	f[0][0] = -N, f[0][1] = 0;
	for (int i = 1; i <= n + 1; i++) {
		for (int j = 0; j <= 1; j++) {
			f[i][j] = -N;
			if (str[i - 1] == 'P' && j == 1) continue;
			if (str[i - 1] == 'D' && j == 0) continue;
			for (int k = 0; k <= 1; k++) {
				int num = j;
				if (k == 0 && j == 1) num++;
				if (f[i][j] < f[i - 1][k] + num) {
					f[i][j] = f[i - 1][k] + num;
					g[i][j] = k;
				}
			}
		}
	}

	int now = 0;
	for (int i = n; i >= 1; i--) {
		if (g[i + 1][now]) ans[i] = 'D';
		else ans[i] = 'P';
		now = g[i + 1][now];
	}
	for (int i = 1; i <= n; i++) printf("%c", ans[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 7180
#include<stdio.h>
int main(){
  int i=0,t,j;
  int h[10];
  for(i=0;i<10;i++){
    scanf("%d",&h[i]);
  }
  for(i=0;i<10;i++){
    for(j=0;j<10-i-1;j++){
      if(h[j]<h[j+1]){
	t=h[j];
	h[j]=h[j+1];
	h[j+1]=t;
      }
    }
  }
  for(i=0;i<3;i++){
    printf("%d\n",h[i]);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 2e5 + 10;
pll a[MAXN];
void solve() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i].f >> a[i].s;
    ll mn1 = 1e18, mn2 = 1e18, mn3 = 1e18, mn4 = 1e18;
    for(int i = 1; i <= n; ++i) {
        mn1 = min(mn1, a[i].f + a[i].s);
        mn2 = min(mn2, a[i].f - a[i].s);
        mn3 = min(mn3, a[i].s - a[i].f);
        mn4 = min(mn4, -a[i].f - a[i].s);
    }
    ll ans = -1e18;
    for(int i = 1; i <= n; ++i)
        ans = max(ans,max(max(a[i].f + a[i].s - mn1, a[i].f - a[i].s - mn2), max(a[i].s - a[i].f - mn3, -1 * (a[i].f + a[i].s + mn4))));
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


Measured memory_bytes: 6728
///Bismillahir Rahmanir Rahim
///ALLAH HU AKBAR
#include<bits/stdc++.h>
using namespace std;
int main()
{
   map<string,int>mp;
   string a="AC";
   string b="WA";
   string c="TLE";
   string d="RE";
   int n;
   cin>>n;
   while(n--)
   {
       string A;
       cin>>A;
       mp[A]++;
   }
   cout<<a<<" x "<<mp[a]<<endl;
   cout<<b<<" x "<<mp[b]<<endl;
   cout<<c<<" x "<<mp[c]<<endl;
   cout<<d<<" x "<<mp[d]<<endl;

}


Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <vector>

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

    std::vector<int> vec_a{};
    for (int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        vec_a.push_back(a);
    }

    int m;
    std::cin >> m;

    std::vector<int> vec_b{};
    for (int i = 0; i < m; ++i) {
        int b;
        std::cin >> b;
        vec_b.push_back(b);
    }

    std::vector<int> difference{};
    std::set_difference(vec_a.begin(), vec_a.end(), vec_b.begin(), vec_b.end(),
                        std::inserter(difference, difference.end()));

    for (auto member : difference) std::cout << member << std::endl;
}


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

int main() {
  int n,x; cin >>n >>x;
  int d = 0;
  int ans = 1;
  int l;
  for (int i=0; i<n; i++){
    cin >>l; d += l;
    if (d<=x) ans++;
  }
  
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[101],b[101],s=0;
	cin>>n;
	for(int i=1;i<=n-1;i++) scanf("%d",&b[i]);
	for(int i=n-1;i>=1;i--)
	{
		if(i==n-1)
		{
			a[i+1]=b[i];
			a[i]=b[i];
		}
		else if(b[i]<a[i+1])
		{
			a[i+1]=b[i];
			a[i]=b[i];
		}
		else a[i]=b[i];
	}
	for(int i=1;i<=n;i++) s+=a[i];
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
static const ll MOD = 1000000007;

int main(){
	int n, k;
	cin >> n >> k;
	vector<vector<ll> > memo(k + 1, vector<ll>(n + 1, 0));
	for(int i = 0; i <= k; i++){
		for(int j = 0; j <= n; j++){
			if(i == 0 && j == 0) memo[i][j] = 1;
			else if(i == 0) continue;
			else{
				if(j - i < 0) memo[i][j] = memo[i - 1][j];
				else memo[i][j] = memo[i][j - i] + memo[i - 1][j];
				memo[i][j] %= MOD;
			}
		}
	}
	cout << memo[k][n] << endl;
	return 0;
}



Measured memory_bytes: 10736
#include <iostream>

int main(){
    long long n, a, b;
    std::cin >> n >> a >> b;

    long long ans = a * (n / (a + b)), val = n % (a + b);
    if(val <= a){
        ans += val;
    }else{
        ans += a;
    }

    std::cout << ans << std::endl;

    return 0;
}
    

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    int N;
    cin >> N;
    ll all = 0;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        all ^= A[i];
    }
    for (int i = 0; i < N; i++) {
        cout << (A[i]^all);
        if (i < N-1) cout << " ";
        else cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4760
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <queue>
#include <algorithm>

using namespace std;




int main(){
	int n, m;
	int INF = 9999999;

	cin >> n >> m;
	int c[m];
	int dp[m+1][n+1];
	for(int i=0 ; i<m ; i++){
		cin >> c[i];
	}

	for(int i=0 ; i<=m ; i++){
		for(int j=0 ; j<=n ; j++){
			dp[i][j] = 0;
		}
	}
	for(int j = 0 ; j<=n ; j++){
		dp[0][j] = INF;
	}


	for(int i=1 ; i<=m ; i++){
		for(int j=1 ; j<=n ; j++){

			if(c[i-1] > j){
				dp[i][j] = dp[i-1][j];
			}else{
				dp[i][j] = min(dp[i-1][j], dp[i][j - c[i-1]] + 1);	
			}
			
		}
	}
	cout << dp[m][n] << endl;

	return 0;
}

Measured memory_bytes: 5260
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const ll mod = 1e9+7;

ll sz[(ll)2e5+10], parent[(ll)2e5+10];

ll find_set(ll x) {
	if(x == parent[x])
		return x;
	return parent[x] = find_set(parent[x]);
}

void union_set(ll x, ll y) {
	if(sz[x] < sz[y])
		swap(x,y);
	parent[y] = x;
	sz[x] += sz[y];
}

int main() {
	ll n,m;
	cin>>n>>m;
	ll x,y,i;
	for(i=1;i<=n;i++) {
		parent[i] = i;
		sz[i] = 1;
	}
	for(i=0;i<m;i++) {
		cin>>x>>y;
		x = find_set(x);
		y = find_set(y);
		if(x != y) {
			union_set(x,y);
		}
	}
	ll mx=0;
	for(i=1;i<=n;i++)
		mx = max(mx, sz[i]);
	cout<<mx;
	return 0;
}

Measured memory_bytes: 6724
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int[][] A=new int[3][3];
	    boolean[][] F=new boolean[3][3];
	    for (int i=0; i<3;i++) {
	    	for (int j=0; j<3;j++) {
		    	A[i][j]=gi();
		    }
	    }
	    int N=gi();
	    int[] B=new int[N];

	    for (int i=0; i<N;i++) {
	    	B[i]=gi();
	    	for (int j=0; j<3;j++) {
		    	for (int k=0; k<3;k++) {
			    	if(A[j][k]==B[i])F[j][k]=true;
			    }
		    }
	    }
	    
	    boolean bz=false;
	    
	    for (int i=0; i<3;i++) {
            boolean b=true;
		    for (int j=0; j<3;j++) {
		    	if(F[i][j]==false)b=false;
		    }
	    	if(b)bz=true;
	    }
	    
	    for (int i=0; i<3;i++) {
            boolean b=true;
		    for (int j=0; j<3;j++) {
		    	if(F[j][i]==false)b=false;
		    }
	    	if(b)bz=true;
	    }
	    

       //System.out.print((int)Math.floor(Math.sqrt(n)));

        if (bz || (F[0][0]==true && F[1][1]==true && F[2][2]==true) || (F[0][2]==true && F[1][1]==true && F[2][0]==true)) {
    	    System.out.print("Yes");
        }else {
        	System.out.print("No");
        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35812
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main(){
int x=0,y=0,z=0,w=0,a=0,b=0;
std::vector<int> v(4);
rep(i,4){
  std::cin >> x>>y;
  if(x==1)v[i]=6000*y;
  else if(x==2)v[i]=4000*y;
  else if(x==3)v[i]=3000*y;
  else if(x==4)v[i]=2000*y;
}
rep(i,4)
std::cout << v[i] << '\n';
}




Measured memory_bytes: 3084
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException{
        int[] arr;
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            arr = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        }
        int a = arr[0];
        int b = arr[1];

        System.out.printf("%d %d %f", a / b, a % b, (double) a / b);
    }
}



Measured memory_bytes: 31180
from itertools import zip_longest
from heapq import heappush, heappop

# 入力
Q = int(input())

q, a, b = (
    zip_longest(*(map(int, input().split()) for _ in range(Q))) if Q else
    ((), ())
)

INF = 10**18
L = []
R = []
heappush(L, INF)
heappush(R, INF)
S = 0
res = []

for i, A, B in zip(q, a, b):
    if i == 1:
        S += B
        if len(L) == len(R):
            if A < -L[0]:
                S += -L[0] - A
                heappush(L, -A)
            elif A <= R[0]:
                heappush(L, -A)
            else:
                S += A - R[0]
                t = heappop(R)
                heappush(L, -t)
                heappush(R, A)
        else:
            if A < -L[0]:
                S += -L[0] - A
                t = -heappop(L)
                heappush(R, t)
                heappush(L, -A)
            else:
                S += A - (-L[0])
                heappush(R, A)
    else:
        res.append((-L[0], S))

ans = '\n'.join(
    ' '.join(map(str, r))
    for r in res
)

# 出力
print(ans)


Measured memory_bytes: 116972
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    string s, t;

    cin >> n >> s >> t;

    s = s;
    t = t;

    ll res = 1;

    int i = 1;
    bool b = true; //縦

    if (s[0] == t[0])
        res = 3, b = true;
    else
        res = 6, b = false, i++;

    while (i < n)
    {
        if (b)
        {
            if (s[i] == t[i])
                res *= 2, b = true, i++;
            else
                res *= 2, b = false, i += 2;
        }
        else
        {
            if (s[i] == t[i])
                res *= 1, b = true, i++;
            else
                res *= 3, b = false, i += 2;
        }

        res %= MOD;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
 
int n, mn, x, v[30], d[200005], ju[200005], u[200005];
string a, ans;
int main()
{
	int i, j, t;
	cin >> a;
	n = a.size();
	a = '.' + a;
	for (i = 0; i < 26; i++) v[i] = n + 1;
	for (i = n; i >= 0; i--) {
		mn = 2e9;
		for (j = 0; j < 26; j++) {
//			if (a[i] - 'a' == j) t = d[v[j]] + 1;
			t = d[v[j]];
			if (t < mn) {
				mn = t;
				x = j;
			}
		}
		ju[i] = v[x];
		d[i] = mn + 1;
		if (i > 0) v[a[i] - 'a'] = i;
		u[i] = x;
	}
	i = 0;
	do {
		ans += (char)(u[i] + 'a');
		i = ju[i];
	} while (i <= n);
	cout << ans;
return 0;
}

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

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

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;

  if ( A == B ) {
    cout << "YES" << endl;
    return 0;
  }

  if ( A > B ) {
    if ( A - V*T <= B - W*T ) cout << "YES" << endl;
    else cout << "NO" << endl;
  } else {
    if ( A + V*T >= B + W*T ) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3652
object Main {

  import scala.collection.mutable.ArrayBuffer

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, K = sc.nextInt
    val mod = 1000000007L

    val res = new ArrayBuffer[Long]()

    val max = 1000000
    var fac = new Array[Long](max)
    var inv = new Array[Long](max)
    var finv = new Array[Long](max)

    comInit()

    def comInit() = {
      fac(0) = 1
      fac(1) = 1
      finv(0) = 1
      finv(1) = 1
      inv(1) = 1
      for (i <- 2 until max) {
        fac(i) = fac(i - 1) * i % mod
        inv(i) = mod - inv((mod % i).toInt) * (mod / i) % mod
        finv(i) = finv(i - 1) * inv(i) % mod
      }
    }

    def comb(n: Int, k: Int): Long = {
      if (n < k) return 0
      if (n < 0 || k < 0) return 0
      fac(n) * (finv(k) * finv(n - k) % mod) % mod
    }

    def hcomb(n: Int, r: Int): Long = {
      comb(n + r - 1, r)
    }

    for (i <- 0 until K) {
      if (i == 0) {
        res += N - K + 1
      } else {
        val insert = comb(K - 1, i) % mod
        res += insert * hcomb(i + 2, N - K - i) % mod
      }
    }

    res.foreach(println)
  }
}

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

int main(){
	int n;	cin>>n;
	vector<int> l(n);
	for(int i=0;i<n;i++)cin>>l[i];
	sort(l.begin(),l.end());
	long long ans=0;

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
				int a=l[i], b=l[j];
			/*
				これより、
				1. a<b+c	: いかなるcでも成立
				2. b<c+a	: b-a<c
				3. c<a+b	: まんま

				よって、b-a < c < a+b となるcの個数を数える
			*/

			// a+b未満の要素数
			int R=lower_bound(l.begin(),l.end(),a+b)-l.begin();

			int count=R-(j+1);

			ans+=count;
		}
	}

	cout<<ans<<endl;

	return 0;
}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ws(x) cerr << #x << " is " << x << endl;
#define pb(x) push_back(x)
#define ats(x) cout << x << "\n";

typedef long long ll;
typedef vector<int> vi;
typedef pair <int, int> pii;
typedef vector<pii> vii;

const int INF = INT_MAX;

map <string, ll> as;

int main()
{
    FAST_IO;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        as[s]++;
    }
    ll ans = 0;
    for (auto a:as){
        ll sk = a.second;
        if (sk >= 2){
            ans += ((sk-1)*sk) / 2;
        }
    }
    ats(ans);
    return 0;
}


Measured memory_bytes: 11264
use proconio::{input, fastout};

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

#[fastout]
fn main() {
  input!{
    n: usize,
    xl: [(i64, i64);n]
  };

  let mut xl = xl;
  xl.sort_by_cached_key(|t| t.0 + t.1);
  let mut idx = std::i64::MIN;
  let mut ans = 0;
  for (x, l) in xl {
    if idx <= x - l {
      idx = x+l;
      ans += 1;
    }
  }
  echo!(ans);
}


Measured memory_bytes: 6992
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

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

long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

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

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

typedef long long ll;
ll mod = 1000000007;
const double PI = 3.141592653589793238460;
const int INF = 1e9+5;

vector<int> a;

bool flag=false;

void backTrack(vector<int> a, int start, int k){

    if(a[0]<a[1] && a[1]<a[2]){
        flag=true;
        return;
    }

    for(int i = start; i<3; i++){

        for(int j=1; j<=k; j++){
            a[i] *= j*2;
            backTrack(a,start+1,k-j);
            if(flag) break;
            a[i] /= j*2;
        }
        if(flag) break;
    }

    return;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    int k;
    for(int i=0; i<3; i++){
        cin >> k;
        a.push_back(k);
    };
    cin >> k;
    backTrack(a,0,k);
    if(flag) cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main(){
    int n,l[4]={0};
    //ac=wc=tc=rc=0;
    char a[4];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s",a);
        if(a[0]=='A'&&a[1]=='C')l[0]++;
        if(a[0]=='W'&&a[1]=='A')l[1]++;
        if(a[0]=='T'&&a[1]=='L'&&a[2]=='E')l[2]++;
        if(a[0]=='R'&&a[1]=='E')l[3]++;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",l[0],l[1],l[2],l[3]);
    return 0;
}

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

int main(){
    string a, b;
    cin >> a >> b;
    queue<char> q1, q2;
    for(char c : a) q1.push(c);
    for(char c : b) q2.push(c);
    string ans;
    for(int i = 0; ; i++){
        if(q1.size() == 0 && q2.size() == 0) break;
        if(i % 2 == 0) ans += q1.front(), q1.pop();
        else ans += q2.front(), q2.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, M = map(int,input().split())
    A = [0 for k in range(N)]
    P = [0 for k in range(N)]
    b = 0
    for _ in range(M):
        p, S = input().split()
        if S == "AC":
            if A[int(p)-1] == 0:
                A[int(p)-1] = 1
                b += P[int(p)-1]
        else:
            if A[int(p)-1] == 0:
                P[int(p)-1] += 1
    print(sum(A),b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 47536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n,d;
    cin >> n >> d;
    if(n % (d+d+1) == 0){
        cout << n / (d+d+1) << endl;
    }else{
        cout << n / (d+d+1) + 1 << endl;
    }
}

Measured memory_bytes: 256