akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000007
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define maxn 200010 

int add(int a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

int mul(int a, int b) {
	return a * 1LL * b % MOD;
}

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}
int func(int a)
{
    int ans=1;
    for(int i=2;i<=a;i++)
        ans=ans*1LL*i%MOD;
    ans=binpow(ans,MOD-2);
    return ans;
}
  

int main()
{
    fastio;
    int n,a,b;
    cin >> n >> a >> b;
    int ans=(binpow(2,n)-1+MOD)%MOD;
    int a1=1;
    for(int i=n-a+1;i<=n;i++)
        a1=(a1*1LL*i)%MOD;
    a1=a1*1LL*func(a)%MOD;
    int b1=1;
    for(int i=n-b+1;i<=n;i++)
        b1=(b1*1LL*i)%MOD;
    b1=b1*1LL*func(b)%MOD;
    ans=(ans-a1+MOD)%MOD;
    ans=(ans-b1+MOD)%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define lli long long int
#include<climits>
#include<unordered_map>
#include<algorithm>
#include<bitset>
#include<map>
#define pb push_back
using namespace std;

int main()
{
   
    int n;
    string s1,s2;
    cin>>n>>s1>>s2;
    string a;
    for(int i=0;i<n;i++)
    {
        a.pb(s1[i]);
        a.pb(s2[i]);
    }
    cout<<a<<endl;
    
}



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

int main(){
    char a, b;
    cin >> a >> b;

    if(a == 'H'){
        if(b == 'H'){
            cout << "H" << endl;
        }else{
            cout << "D" << endl;
        }
    }else{
        if(b == 'H'){
            cout << "D" << endl;
        }else{
            cout << "H" << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char n,m,x,y;
int ans,a,b,c,d;
int main()
{
	cin>>n>>m>>x>>y;
	a=n-48;
	b=m-48;
	c=x-48;
	d=y-48;
	for(char i='+';i<='-';i++)
    	for(char j='+';j<='-';j++)
        	for(char k='+';k<='-';k++)
        	{
            	ans=a;
            	if(i=='+') ans+=b;
            	else if(i=='-') ans-=b;
            	if(j=='+') ans+=c;
            	else if(j=='-') ans-=c;
            	if(k=='+') ans+=d;
            	else if(k=='-') ans-=d;
            	if(ans==7)
            {
                cout<<a<<i<<b<<j<<c<<k<<d<<'='<<ans<<endl;
                return 0;
            }
        }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	int now = 1;
	int cnt = 0;
	rep(i, N*10) {
		now = A[now-1];
		cnt++;
		if (now == 2) {
			cout << cnt << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 640
import heapq
import math
xs, ys, xt, yt = map(int, input().split())
N = int(input())

Coordinate = {-1: (xs, ys, 0), N:(xt, yt, 0)}
minRadiation = {int(i):10**20 for i in range(-1, N+1)}
ToVisit = {int(i) for i in range(-1, N+1)}
for i in range(N):
    x, y, r = map(int, input().split())
    Coordinate[i] = (x, y, r)

Q = [(0, -1)]
heapq.heapify(Q)
while Q:
    nowRadiation, index = heapq.heappop(Q)
    if index == N:
        print(nowRadiation)
        break
    elif index in ToVisit:
      ToVisit.difference_update({index})
      nowx, nowy, nowr = Coordinate[index]
      for nextIndex in ToVisit:
          nextx, nexty, nextr = Coordinate[nextIndex]
          tempTime = max(0, math.sqrt((nextx-nowx)**2 + (nexty-nowy)**2) - nowr - nextr) + nowRadiation
          if minRadiation[nextIndex] > tempTime:
              minRadiation[nextIndex] = tempTime
              heapq.heappush(Q, (tempTime, nextIndex))


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

int main(){
    
    int n,m,i,j;
    cin >> n >> m;//縦横
    
    int A[n][m];
    for(int i=0; i<n; i+=1){
        for(int j=0; j<m; j+=1){
            int x;
            cin >> x;
            A[i][j] = x;
        }
    }
    
    int b[m];
    for(int j=0; j<m; j+=1){
        int y;
        cin >> y;
        b[j] = y;
    }
    
    int c[n];
    for(int i=0; i<n; i+=1){
        c[i] = 0;
        for(int j=0; j<m; j+=1){
            c[i] = (c[i] + A[i][j] * b[j]);
        }
        cout << c[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

static const double pi = 3.14159265358979323846;

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

  map<int,int> honsuu;
  map<int,bool> nihonijou;
  map<int,bool> yonhonijou;
  for(int i=0; i<N; i++){
    int A;
    cin >> A;
    if(honsuu.find(A) != honsuu.end()){
      ++honsuu[A];
      if(honsuu[A]==2) nihonijou[A] = true;
      if(honsuu[A]==4) yonhonijou[A] = true;
    }
    else{
      honsuu[A] = 1;
    }
  }

  long long max_area = 0;
  if(nihonijou.size() > 1){
    auto itr = nihonijou.end();
    long long a = (--itr)->first;
    long long b = (--itr)->first;
    max_area = a*b;
  }
  if(yonhonijou.size() > 0){
    auto itr = yonhonijou.end();
    long long a = (--itr)->first;
    max_area = a*a > max_area ? a*a : max_area;
  }

    cout << max_area << endl;


  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

int main(){
	int N, A, B;
	cin >> N >> A >> B;
	int d2[18];d2[0] = 1;
	for (int i = 0;i < N;i++)d2[i + 1] = d2[i] * 2;

	B = A ^ B;
	vector<pair<int, int>> bit(N);
	int bc = 0;
	for (int i = 0;i < N;i++) {
		bit[i] = { B % 2,i };
		bc += B % 2;
		B /= 2;
	}
	sort(all(bit));
	reverse(all(bit));
	if (bc % 2 == 0) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;

	//ビットが立つ場合
	//正順に入れる 間に最高位を挟みながら
	//最高位-1を入れる
	//逆順に入れる
	//最高位を入れる
	//正順に入れる

	//ビットが立たない場合
	//各数の間に最高位-1,最高位,最高位-1を入れる

	vector<int> X, Y, Z;
	X = Y = { 0 };
	for (int i = 2;i < N;i += 2) {
		X = Z;
		if (bit[i].first) {
			X.push_back(i);
			for (int j : Y) {
				X.push_back(j);
				X.push_back(i);
			}
			X.push_back(i - 1);
			for (int j = Y.size() - 1;j >= 0;j--) {
				X.push_back(Y[j]);
			}
			X.push_back(i);
			for (int j : Y) {
				X.push_back(j);
			}
		}
		else {
			X.push_back(i - 1);
			X.push_back(i);
			X.push_back(i - 1);
			for (int j : Y) {
				X.push_back(j);
				X.push_back(i - 1);
				X.push_back(i);
				X.push_back(i - 1);
			}
		}
		Y = X;
		//for (int i : X)cout << i << " ";
		//cout << endl;
	}
	if (N % 2 == 0) {
		X = Z;
		X.push_back(N - 1);
		for (int j : Y) {
			X.push_back(j);
			X.push_back(N - 1);
		}
	}

	for (int i = 0;i < N;i++)bit[i].first = 0;
	ll ans = 0;
	cout << (ans ^ A) << " ";
	for (int i : X) {
		if (bit[i].first) {
			ans -= d2[bit[i].second];
			bit[i].first = 0;
		}
		else {
			ans += d2[bit[i].second];
			bit[i].first = 1;
		}
		cout << (ans^A) << " ";
	}
	cout << endl;
}

Measured memory_bytes: 2252
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a,b,c,d;
    string s,t;

    cin >> a >> b>> c;// >> d;
    //cin >> s >> t;
    if (abs(a-b) > abs(a-c)) cout << "B";
    else cout << "A"; 


    return 0;
}

Measured memory_bytes: 256
n = gets.to_i - 1
alp = [*?a..?z]
out = [n % 26]
n /= 26
while n > 0
	n -= 1
	out << n % 26
	n /= 26
end
#out[0] += 1
puts out.reverse.map{|i|alp[i]}.join

Measured memory_bytes: 14320
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	string s;
	cin >> s;
	int co = 0;
	for (int i = 0; i < s.size(); i++) {
		co += int(s[i] - '0');
	}
	if (co % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3748
fn main() {
    proconio::input! {
        n: usize,
        s: String,
    }
    let c: Vec<char> = s.chars().collect();
    let mut wl = 0;
    while wl < n && c[wl] != 'W' {
        wl += 1;
    }
    let mut rr = n - 1;
    while rr > 0 && c[rr] != 'R' {
        rr -= 1;
    }

    let mut r = 0;
    while wl < rr {
        r += 1;
        wl += 1;
        while wl < n && c[wl] != 'W' {
            wl += 1;
        }
        rr -= 1;
        while rr > 0 && c[rr] != 'R' {
            rr -= 1;
        }
    }
    println!("{}", r);
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<int ,int> > a(n);

  for(int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }

  int max = -1;
  int min_num = 9999;
  for(int i = 0; i < n; i++) {
    if(max < a[i].second) {
      max = a[i].second;
    }
  }

  for(int i = 0; i < n; i++) {
    if(max == a[i].second && min_num > a[i].first) {
      min_num = a[i].first;
    }
  }

  cout << min_num << " " << max << endl;

  return 0;
}

Measured memory_bytes: 3080
n = int(input())
s = input().split()
s = [int(i) for i in s]
mul = 1
flag = 0

if 0 in s:
    print(0)
else:


    for item in s:
        mul *= item
        if flag == 1:
            break

        if mul >  1e18:
            print(-1)
            flag = 1

    if mul <=  1e18:
        print(mul)



Measured memory_bytes: 21792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;


inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}

template<typename T = int>
inline T nxt(){
    char c=nc();T x=0; int f=1;
    for(;c>'9'||c<'0';c=nc())if(c=='-')f=-1;
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=nc());
    x*=f;
    return x;
}

const int maxn = 200123;
int n;
ll a[maxn];

ll f(ll b){
    ll res = 0;
    rep(i,0,n) res += abs(a[i] - (b + i + 1));
    return res;
}

ll solve(int a, int b){
    while(b - a >= 5){
        int mid = (a + b) / 2;
        if(f(mid) >= f(mid + 1)) a = mid;
        else b = mid + 1;
    }
    rep(i,a+1,b+1) if(f(a) >= f(i)) a = i;
    return a;
}

int main(){
#ifdef LOCAL_DEFINE
    freopen("test.in", "r", stdin);
#else
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
#endif
    n = nxt();
    rep(i,0,n) a[i] = nxt();
    int b = solve(-1e9, 1e9);
    cout << f(b) << '\n';



#ifdef LOCAL_DEFINE
    cout <<"\nTime elapsed: "<<(1000 * clock() / CLOCKS_PER_SEC)<<"ms\n";
 #endif
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int n;
int s;


int f(int b, int x){
	if(x < b) return x;
	return f(b, x/b)+x%b;
}


int solve(){
	if(n < s) return -1;
	if(n == s) return n+1;
	repif(i, 2, i*i <= n)
		if(f(i, n) == s) return i;
	repr(i, CEIL(sqrt(n)), 1)
		if((n-s)%i == 0 && f((n-s)/i+1, n) == s) return (n-s)/i+1;
	return -1;
}


signed main(){
	cin >> n;
	cin >> s;

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  string s; cin >> s;

  int a = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'A') a++;
  }
  int ans = 0;
  if(a == 1) ans = 2;
  if(a == 2) ans = 2;
  if(a == 3) ans = 0;
  cout << (ans == 2 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
//##MohK
// 9/2/2020 ..... 2,00
#include <bits/stdc++.h>
using namespace std ;
using ll = long long ;
using ld = long double;
int main(){
    ll a,b;
    cin>>a;
    set<int>x;
    for(ll i=0;i<a;i++){
        cin>>b;
        x.insert(b);
    }
    if(x.size()==a){
        cout<<"YES"<<endl;
    }
    else
        cout<<"NO"<<endl;


    return 0 ;
}



Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {
	
	public static final double EPS = 0.0000001;
	
	public static void main(String[] args) {

		final Scanner sc = new Scanner(System.in);

		final int t = sc.nextInt();
		
		double[] PROB = new double[t + 1];
		
		for(int i = 0; i <= t; i++){
			final int n = sc.nextInt();
			final int m = sc.nextInt();
			
			double prob_sum = 0;
			double exp = 0;
			
			for(int j = 0; j < m; j++){
				final int v = sc.nextInt();
				final double p = sc.nextDouble();
				
				prob_sum += p;
				exp += v * p;
			}
			
			PROB[i] = exp / prob_sum;
		}
		
		boolean flag = false;
		for(int i = 0; i < t; i++){
			if(PROB[t] + EPS < PROB[i]){
				flag = true;
				break;
			}
		}
		
		System.out.println(flag ? "YES" : "NO");
	}

}

Measured memory_bytes: 28284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const int MOD = 1e9 + 7;
int N;
int a[22][22];
ll dp[1 << 22];
int bitcnt[1 << 22];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			cin >> a[i][j];

	dp[0] = 1;
	for (int mask = 1; mask < (1 << N); mask++) {
		bitcnt[mask] = bitcnt[mask / 2] + mask % 2;
		for (int k = 0; k < N; k++) {
			if ((mask & (1 << k)) == 0) continue;
			dp[mask] += dp[mask - (1 << k)] * a[bitcnt[mask] - 1][k];
			dp[mask] %= MOD;
		}
	}
	cout << dp[(1 << N) - 1] << '\n';
	return 0;
}

Measured memory_bytes: 28928
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');

            int search_index = 1;
            int broken_count = 0;
            int check_count = 0;
            for (int i = 0; i < input.Length; i++)
            {
                if (int.Parse(input[i]) == search_index)
                {
                    search_index++;
                } else
                {
                    broken_count++;
                }
                check_count++;
            }

            if (broken_count == check_count++)
            {
                Console.WriteLine(-1);
            }else if(search_index == check_count++)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(broken_count);
            }
        }
    }
}


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

int main()
{
	int n;
  	cin>>n;
  	vector<int> p(n);
  	int ans=0;
  	for(int i=0 ; i<n ; ++i)
    cin>>p[i];
  	for(int i=1 ; i<n-1 ; ++i)
    {
    	if((p[i]>p[i-1] && p[i]<p[i+1]) || (p[i]>p[i+1] && p[i]<p[i-1]))
    	++ans;
    }
  	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int k,a,b;
  cin >> k >> a >> b;
  int flag = 0;
  for(int i = a; i <= b; i++) {
    if(i % k == 0) {
      flag = 1;
    }
  }
  if(flag == 1) {
    cout << "OK" << endl;
  }else {
    cout << "NG" << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
X = int(input())
Rg = 1000
#print(1000**5)
#print(2**5)
for a in range(Rg):
	A = a**5
	for b in range(Rg): 
		B = b**5
		if A-B==X:
			print(a,b)
			exit()
		if A+B==X:
			print(a,-b)
			exit()

Measured memory_bytes: 9156
def coins(charge, five_hundreds, hundred, fifty):
    count = 0
    for a in range(five_hundreds + 1):
        for b in range(hundred + 1):
            for c in range(fifty + 1):
                if 500 * a + 100 * b + 50 * c == charge:
                    count += 1
    return count

a = int(input())
b = int(input())
c = int(input())
charge = int(input())

print(coins(charge, a, b, c))


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



int main() {
  int N, Y;
  cin >> N >> Y;

  long long diff = Y - N  * 10000;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N-i; ++j) {
      int d = diff + (i+j) * 10000 - (i * 5000) - (j * 1000);
//      cout << d << endl;
      if(d == 0){
        printf("%d %d %d\n",N - (i+j), i, j);
        return 0;
      }
    }
  }

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



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include <algorithm>
#include <vector>

int main(int argc, char* argv[])
{
    long h, w;
    scanf("%ld %ld", &h, &w);

    long a[500][500]={0};
    long i, j;
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            scanf("%ld", &(a[i][j]) );
        }
    }

    std::vector<long> ans;

    long move2 = 0;
    for(i=0; i<h; i++) {
        long move = 0;
        for(j=0; j<w; j++) {
            if ( move ) {
                a[i][j] += 1;
                ans.push_back( i+1 );
                ans.push_back( j );
                ans.push_back( i+1 );
                ans.push_back( j+1 );
            }
            if(j==w-1 && move2) {
                a[i][j] += 1;
                ans.push_back( i );
                ans.push_back( j+1 );
                ans.push_back( i+1 );
                ans.push_back( j+1 );
            }
            move = (a[i][j]%2==0? 0: 1);
            if(j==w-1) {
                move2 = move;
            }
        }
    }
    printf("%d\n", static_cast<long>(ans.size())/4 );
    for(i=0; i<static_cast<long>(ans.size())/4; i++) {
        printf("%d %d %d %d\n", ans[4*i], ans[4*i+1], ans[4*i+2], ans[4*i+3]); 
    }

    return 0;
}





Measured memory_bytes: 8304
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

int main()
{

    int n;
    cin >> n;

    int ac_c = 0;
    int wa_c = 0;
    int tle_c = 0;
    int re_c = 0;
    rep(i,n){
        string s;
        cin >> s;
        if(s == "AC"){ ac_c++; }
        else if(s == "WA"){ wa_c++; }
        else if(s == "TLE"){ tle_c++; }
        else if(s == "RE"){ re_c++; }
    }

    cout << "AC x " << ac_c<< endl;
    cout << "WA x " << wa_c<< endl;
    cout << "TLE x " << tle_c<< endl;
    cout << "RE x " << re_c<< endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

const int N = (int)2e3+5;
int n, lf[N], rt[N], mx[N];
char a[N], b[N];
int ans = (int)1e9+7;

void solve() {
	for (int i = 0; i < n; ++i) {
		lf[i] = rt[i] = 0;
		while (b[(i + rt[i]) % n] == '0') ++rt[i];
		while (b[(i - lf[i] + n) % n] == '0') ++lf[i];
	}
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) mx[i] = 0;
		int cnt = 0;
		for (int i = 0; i < n; ++i) if (a[i] != b[(i + k) % n]) {
			++cnt;
			mx[lf[i]] = max(mx[lf[i]], rt[i] - k);
		}
		int tmp = (int)1e9+7, cur = 0;
		for (int i = n - 1; i >= 0; --i) {
			cur = max(cur, mx[i + 1]);
			tmp = min(tmp, cur + i);
		}
		ans = min(ans, tmp * 2 + cnt + k);
	}
}

int main() {
	scanf("%s%s", a, b);
	n = strlen(a);
	bool all0a = true, all0b = true;
	for (int i = 0; i < n; ++i) {
		all0a &= (a[i] == '0');
		all0b &= (b[i] == '0');
	}
	if (all0b) {
		if (all0a) printf("0");
		else printf("-1");
		return 0;
	}
	solve();
	reverse(a, a + n);
	reverse(b, b + n);
	solve();
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  ll x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;


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

  ll n,m;
  std::cin>>n>>m;

  std::vector<P> a(n);

  rep(i,0,n){
    ll temp;
    std::cin>>temp;
    a[i]={temp,-1};
  }

  std::vector<std::vector<ll>> graph(n);

  rep(i,0,m){
    ll x,y;
    std::cin>>x>>y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }

  if(m==n-1){
    std::cout<<0;
    return 0;
  }

  if(n<2*(n-m-1)){
    std::cout<<"Impossible\n";
    return 0;
  }

  ll groups=0;

  rep(i,0,n){
    if(a[i].second==-1){
      std::queue<ll> que;
      que.push(i);

      while(!que.empty()){
        ll e=que.front();que.pop();

        a[e].second=groups;

        for(ll next:graph[e]){
          if(a[next].second==-1){
            que.push(next);
          }
        }
      }

      groups++;
    }
  }

  std::vector<ll> min(groups,MOD);

  rep(i,0,n){
    chmin(min[a[i].second],a[i].first);
  }

  ll ans=0;
  ll cnt=2*(groups-1);

  rep(i,0,n){
    if(min[a[i].second]==a[i].first){
      ans+=a[i].first;
      min[a[i].second]=MOD;
      a[i].first=MOD;
      cnt--;
    }
  }

  std::sort(all(a));

  rep(i,0,n){
    if(cnt>0){
      ans+=a[i].first;
      cnt--;
    }else{
      break;
    }
  }

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

  return 0;
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
char s[200050];

int main(){
	scanf("%s",s+1);
	int len=strlen(s+1);
	if (s[1]=='0'||s[len]=='1') return puts("-1"),0;
	for (int i=1;i<=len/2;++i)
		if (s[i]!=s[len-i]) return puts("-1"),0;
	int x=1;
	for (int i=1;i<len;++i) {
		printf("%d %d\n",x,i+1);
		if (s[i]=='1') x=i+1;
	}
	
}

Measured memory_bytes: 3828
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)


int main() {
	vc s(3);
	cin >> s[0] >> s[1] >> s[2];
	sort(s.begin(), s.end());
	if (s[0] == s[2])cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
     
                int n;
                n = int.Parse(Console.ReadLine());
                if (n == 25)
                    Console.WriteLine("Christmas");
                if (n == 24)
                    Console.WriteLine("Christmas Eve");
                if (n == 23)
                    Console.WriteLine("Christmas Eve Eve");
                if (n == 22)
                    Console.WriteLine("Christmas Eve Eve Eve");
                Console.ReadKey();

            }
        }
    }


Measured memory_bytes: 11092
n = int(input())
a, b, c = input(), input(), input()
ans = 0
for i in range(n):
    if a[i] == b[i] and b[i] == c[i]:
        continue
    if a[i] == b[i] or b[i] == c[i] or c[i] == a[i]:
        ans += 1
    else:
        ans += 2
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int,int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))

int main() {
     //#ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
     //#endif
     ios;
     int a,b;
     cin>>a>>b;
     if((b-2*a)%2==0&&(4*a-b)%2==0 &&b-2*a>=0 && (4*a-b)>=0){
      cout<<"Yes";
      }
      else
      cout<<"No";


}


Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;

int main() {
	char c;
	cin >> c;
	if (c == 'a'||c == 'e' || c == 'i' || c == 'o' || c == 'u') {
		cout << "vowel" << endl;
	}else {
		cout << "consonant" << endl;
	}
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            
            foreach (var i in Enumerable.Range(1, n))
            {
                if (CheckNum(i) || Include3(i))
                {
                    Console.Write($" {i}");
                }
            }
            Console.WriteLine();
        }

        static bool CheckNum(int n)
        {
            if (n % 3 == 0)
            {
                return true;
            }

            return false;
        }
        static bool Include3(int n)
        {
            var flag = false;
            if (n % 10 == 3)
            {
                return true;
            }
            n /= 10;
            if (n != 0) flag = Include3(n);

            return flag ? true : false;
        }

    }
}



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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N, long long K) {
  double ans = 0;
  for(int i = 1 ; i <= N ; i++){
    int c = 0;
    int v = i;
    while( v < K ){
      c++;
      v *= 2;
    }
    ans += pow(0.5, c);
  }
  printf("%.12lf\n", ans / N);
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  solve(N, K);
  return 0;
}


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

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

    long rmin = numeric_limits<long>::max();
    long max_profit = numeric_limits<long>::min();
    for (int i = 0; i < n; ++i) {
        long r;
        cin >> r;
        if (r - rmin > max_profit) {
            max_profit = r - rmin;
        }
        rmin = min(rmin, r);
    }
    cout << max_profit << endl;

    return 0;
}


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


//      DEEP


using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fwd(i,a,n) for(int i=a;i<=n;i++)
#define bak(i,a,n) for(int i=a;i>=n;i--)
#define all(v) v.begin(),v.end()
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef set<int> si;
const ll mod = 1e9 + 7;
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}
ull gcd(ull x,ull y){
   if(y==0)return x;
   return gcd(y,x%y);
}
int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
      ll a,b;
      cin>>a>>b;
      ll x=b-a+1;
      ll y=b+a-1;
      for(int i=x;i<=y;i++)cout<<i<<" ";
      cout<<endl;
    }
}
/* Be careful about integer ranges;
   Check the corner cases before submitting.
*/




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

int main()
{
    int n, d;
    cin >> n >> d;
    // int型の2次元配列(3×4要素の)の宣言
    vector<vector<int>> data(n, vector<int>(d));

    // 入力 (2重ループを用いる)
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            cin >> data.at(i).at(j);
        }
    }

    // 0の個数を数える
    int count = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i <= j)
                continue;

            float dist = 0;
            rep(k, d)
            {
                dist += (data.at(i).at(k) - data.at(j).at(k)) * (data.at(i).at(k) - data.at(j).at(k));
            }
            dist = sqrt(dist);

            if (ceil(dist) == floor(dist))
                ++count;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String t = sc.next();
		
		int n = s.length();
		int m = t.length();
		
		int[] cnext = new int[26];
		int[][] next = new int[n][26];
		for(int i = 0; i < 26; i++)
			cnext[i]=-1;
		for(int i = 0; i < n; i++)
		{ //what chars exist?
			cnext[s.charAt(i)-'a'] = 0;
		}
		
		for(int i = n-1; i >= 0; i--)
		{
			int cid = s.charAt(i)-'a';
			
//			System.out.println(cid + " " + i);
			for(int j = 0; j < 26; j++)
			{
				next[i][j] = cnext[j];
			}
			cnext[cid] = i;
		}
//		System.out.println("test " + next[0][13]);
		
		long an = 0;
		int ch = 0; //char in s
		for(int i = 0; i < m; i++)
		{
//			System.out.println("i: " + i + ", ch " + ch);
			int tar = t.charAt(i)-'a';
			
			int got = next[ch][tar];
			if(tar == s.charAt(ch)-'a')
			{ //right here!
				an++;
				ch++;
				while(ch>=n)ch-=n;
			}
			else if(got == -1)
			{
//				System.out.println(" No " + i + "tar " + tar);
				System.out.println(-1);
				return;
			}
			else if(got == 0)
			{ //new s!
				an += n - ch;
				i--; //look again from 0!
//				System.out.println("MARK " + ch + " " + (char)('a'+tar) );
				ch = 0;
				
//				if(flag)return; //don't
			}
			else
			{
				an += got+1-ch;
				ch = got+1;
				while(ch>=n)ch-=n;
			}
			
		}
		
		System.out.println(an);

	}

}


Measured memory_bytes: 41036
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
int n,m;
int p[200005];
int t[200005];
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",p+i);
        t[p[i]]=i+1;
    }
    int a=t[1],s=1;
    for(int i=2;i<=n;i++){
        if(a<t[i]){
            s++;
            a=t[i];
        }else{
            m=max(m,s);
            a=t[i];
            s=1;
        }
    }
    m=max(m,s);
    cout<<n-m<<endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
	int a, b, c, num, i, tmp;
	
	scanf("%d", &num);
	for(i = 0; i < num; i++){
		scanf("%d %d %d", &a, &b, &c);
		if(a < b){
			tmp = a;
			a = b;
			b = tmp;
		}
		if(a < c){
			tmp = a;
			a = c;
			c = tmp;
		}
		if(a * a == b * b + c * c){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 580
#include <stdio.h>


int main(int argc, char const *argv[])
{
    int n;
    scanf("%d", &n);

    int a[n];
    for (int i=0; i < n; i++){
        scanf("%d", &a[i]);
    }

    double sum = 0;
    for (int i=0; i < n; i++){
        sum += (double)1/a[i];
    }
    sum = 1.00000/sum;


    printf("%f\n", sum);



    return 0;
}

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

string s;
vector<string> ans;

void solve(int now, string nows, bool ch);

int main() {
  while(1) {
    cin >> s;
    if(s == "#") break;
    solve(24, s, 0);
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    cout << ans.size() << endl;
    if(ans.size() <= 10)
      for(int i = 0; i < ans.size(); ++i)
        cout << ans[i] << endl;
    else {
      for(int i = 0; i < 5; ++i) cout << ans[i] << endl;
      for(int i = 0; i < 5; ++i)
        cout << ans[ans.size() - 5 + i] << endl;
    }
    ans.erase(ans.begin(), ans.end());
  }
  return 0;
}

void solve(int now, string nows, bool ch) {
  if(now == -1) {
    ans.push_back(nows);
    return;
  }
  for(int i = 0; i < nows.size(); ++i)
    if(nows[i] == 'a' + now) {
      string nexts = nows;
      nexts[i] = 'a' + now + 1;
      solve(now - 1, nexts, 0);
    }
    else if(nows[i] == 'a' + now + 1)
      return;
  solve(now - 1, nows, 0);
}


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

int main(){
    int N,K;
    string S;
    cin >> N >> S >> K;

    char chara = S[K-1];
    for(int i=0;i<N;i++){
        if(S[i] != chara){
            S[i] = '*';
        }
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
ll power(int x, unsigned int y) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp =(ll)power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
} 
int main()
{
  fastio;
 // fopen();
  int n;
  cin>>n;
  cout<<(n/500)*1000+((n%500)/5)*5;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	std::string s;
	std::cin >> s;
	rep(i, s.size()) {
		if (s[i] == ',') {
			s[i] = ' ';
		}
	}
	std::cout << s << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min({abs(a+b-c-d), abs(a-b-c+d), abs(a-b+c-d)}) << endl;
}



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

namespace ConsoleApp3
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var hashSet = new HashSet<int>();

            var days = int.Parse(Console.ReadLine());

            var scoreDownCoefficients = Console.ReadLine().Split(" ")
                .Select((x, i) => (score: int.Parse(x), dayNumber: i + 1))
                .OrderByDescending(x => x.score)
                .ToArray();

            foreach (var i in Enumerable.Range(2, days))
            {
                var scoreUpNumber = Console.ReadLine().Split(" ")
                    .Select((x, i) => (score: int.Parse(x), dayNumber: i + 1))
                    .OrderBy(x => hashSet.Contains(x.dayNumber))
                    .OrderByDescending(x => x.score)
                    .First();

                hashSet.Add(scoreUpNumber.dayNumber);

                Console.WriteLine(scoreUpNumber.dayNumber);
            }
        }
    }
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m;

	cin >>n >>m;
	VI a(m);
	rep(i, m) cin >>a[i];
	const VI mt ={0, 2,5,5,4,5,6,3,7,6};
	sort(a.rbegin(), a.rend());
	vector<string> dp(n+5,"");
	dp[0]="";
	rep(j, n+4)  if(sz(dp[j])>0 || j==0) rep(i, m){
		int pp = j+mt[a[i]];
		if(pp > n ) continue;
		if(sz(dp[pp]) < sz(dp[j]) + 1 ||
		  (sz(dp[pp]) == sz(dp[j]) + 1 &&  dp[pp] < dp[j] + to_string(a[i]))){
			dp[pp] = dp[j] +to_string(a[i]);
		}
	}
	
	//for(auto x : dp) cout<<x <<" "; puts("dp");
	
	cout << dp[n] <<"\n";
	return 0;
}



Measured memory_bytes: 33408
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main()
{
    long int n;
    long int c = 0;
    
    cin >> n;
    
    if (n%2 == 1){
        cout << "0" << endl;
    }
    else {
        for (long int i = 10;n >= i;i *= 5){
            c += n/i;
        }
        cout << c << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;

int a, b;

signed main() {
	cin >> a >> b;
	if (a <= b) { cout << a << endl; }
	else { cout << a - 1 << endl; }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N,K;
  cin>>N>>K;
  VL A(N+1);
  rep(i,N) cin>>A[i+1];
  rep(i,N) A[i+1]+=A[i]-K;
  VL B(N+1);
  rep(i,N+1) B[i]=A[i];
  sort(all(B));
  map<ll,int> M;
  ll tmp=1;
  M[B[0]]=tmp;
  rep(i,N){
    if(B[i+1]!=B[i]) tmp++;
    M[B[i+1]]=tmp;
  }
  rep(i,N+1) A[i]=M[A[i]];
  int size=1<<20;
  VL BIT(size);
  ll ans=0;
  rep(i,N+1){
    tmp=A[i];
    ll sum=0;
    do{
      sum+=BIT[tmp];
      tmp-=(tmp&(-tmp));
    }while(tmp>0);
    ans+=sum;
    tmp=A[i];
    do{
      BIT[tmp]++;
      tmp+=(tmp&(-tmp));
    }while(tmp<=size);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 24064
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	string weather[3] = {"Sunny", "Cloudy", "Rainy"};
	string inp;
	cin >> inp;
	int current = 0;
	for (int i = 0; i < 3; i++)
	{
		if (inp == weather[i])
		{
			current = i;
			break;
		}
	}
	current++;
	cout << weather[current % 3] << endl;
}


Measured memory_bytes: 31488
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(9);
    
    int N,M;
    cin >> N >> M;
    vector<int> X;
    for(int i=0; i<M; i++){
        int x;
        cin >> x;
        X.push_back(x);
    }
    sort(X.begin(),X.end());
    //駒は右向きにのみ動かすことができる
    vector<int> dis;
    for(int i=1; i<M; i++){
        dis.push_back(X[i]-X[i-1]);
    }
    sort(dis.begin(),dis.end());

    int ans = 0;
    for(int i=0; i<M-1-(N-1); i++){
        ans += dis[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1400