akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
int a[25][25];

int count(int i,int j,int H,int W){
  int dis=0;
  for(int k=0;k<H;k++){
    for(int n=0;n<W;n++){
      dis+=min(abs(i-k),abs(j-n))*a[k][n];
    }
  }

  return dis;
}

int main(){
  int H,W,sum=1000000001;

  cin>>H>>W;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++)
      cin>>a[i][j];
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      sum=min(sum, count(i,j,H,W));
    }
  }

  cout<<sum<<endl;
  return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>

int main(void){
  int n;
  int r;
  int i;
  int min, max;
  int min_sub;
  
  //input
  scanf("%d", &n);

  //main
  for(i = 0; i < n; i++){
    scanf("%d", &r);
    if(i == 0){
      min = r;
      min_sub = r;
    }else if(i == 1){
      max = r;
      if(min > r){
        min_sub = r;
      }
    }else{
      if(r > max){
        max = r;
        if(max - min < r - min_sub){
          max = r;
          min = min_sub;
        }
      }else if(r < min_sub){
        min_sub = r;
      }else{
        if(max - min < r - min_sub){
          max = r;
          min = min_sub;
        }
      }
    }
  }
  
  //output
  printf("%d\n", max - min);
  return 0;
}

Measured memory_bytes: 1840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int x[n];
    for(int i=0;i<n;++i){
        cin>>x[i];
    }
    ll ans=0;
    for(int i=0;i<n-1;++i){
        ll d=x[i+1]-x[i];
        if(d*a<b)ans+=d*a;
        else ans+=b;
    }
    cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;

int main() {
    int P, Q, R;
    cin >> P >> Q >> R;

    cout << min(P + Q, min(Q + R, R + P)) << endl;
    return 0;
}

Measured memory_bytes: 888
/* Atcoder 157*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3][3];
    for (int i=0;i<3;i++)
    {
        for (int j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    long long int n;
    cin>>n;
    int f[3][3]={0};
    for (int k=0;k<n;k++)
    {
        long int temp;
        cin>>temp;
        for (int i=0;i<3;i++)
        {
            for (int j=0;j<3;j++)
            {
                if(a[i][j]==temp) f[i][j]=1;
            }
        }
    }
    int flag=0,ans=0;
    for (int i=0;i<3;i++)
    {
        flag=0;
        for (int j=0;j<3;j++)
        {
            if(f[i][j]==1) flag=1;
            else 
            {
                flag=0;
                break;
            }
        }
        if(flag) {
            ans=1;
            break;
        }
    }
    for (int j=0;j<3;j++)
    {
        flag=0;
        for (int i=0;i<3;i++)
        {
            if(f[i][j]==1) flag=1;
            else 
            {
                flag=0;
                break;
            }
        }
        if(flag) {
            ans=1;
            break;
        }
    }
    /*for (int i=0;i<3;i++)
    {
        for (int j=0;j<3;j++)
        {
            cout<<f[i][j]<<" ";
        }
        cout<<endl;
    }*/
    if(f[0][0]==f[1][1] && f[1][1]==f[2][2] && f[2][2]==1 ) ans=1;
    else if(f[0][2]==f[1][1] && f[1][1]==f[2][0] && f[2][0]==1 ) ans=1;
    if(ans) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;

int main(){
	int n;
	cin >> n;
	vi t(n);
	rep(i, n) cin >> t[i];
	int m;
	cin >> m;
	vi sub(m);
	rep(i, m){
		int p, x;
		cin >> p >> x;
		sub[i] = x - t[p-1];
	}

	rep(i, m){
		int ans = 0;
		rep(j, n){
			ans += t[j];
		}
		ans += sub[i];
		cout << ans << endl;
	}
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var array = Console.ReadLine().Split(' ');

        var s = int.Parse(array[0]);
        var w = int.Parse(array[1]);

        if(w >= s)
        {
            Console.WriteLine("unsafe");
        }
        else
        {
            Console.WriteLine("safe");
        }
        Console.Read();


    }
}


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

int minn = (int)1e9 + 7, n, x, ans = 0;

int main() {
	cin >> n;
	while(n--) {
		cin >> x;
		if(x < minn) ++ans;
		minn = min(minn, x);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt() // <= 4000
    val s = sc.next()
    var ans = 0L
    val m = mapOf('R' to 0, 'G' to 1, 'B' to 2)

    val acc = IntArray(3){0}
    val counts = Array(3){IntArray(n+1)}

    for(i in s.indices) {
        val idx = m[s[i]]!!
        acc[idx]++
        counts[idx][i] = acc[idx]
    }

    for(i in 0 until 3) {
        var j = 0
        val count = counts[i]
        while (j < n) {
            if(count[j] != 0) {
                val d = count[j]
                ++j
                while (j < n && count[j] == 0) {
                    count[j++] = d
                }
            } else {
                ++j
            }
        }
    }
    // R G B
    for(i in 0 until n) {
        for(j in i + 1 until n) {
            if(s[i] == s[j]) continue
            // 남은 인덱스
            val remain = 3 - (m[s[i]]!! + m[s[j]]!!)
            val diff = j - i

            var v = counts[remain][n - 1] - counts[remain][j]
            if(j + diff < n && counts[remain][j + diff] != counts[remain][j + diff - 1]) {
                --v
            }

            ans += v 

            // k > j && k - j > d
            // total remain size - [k <=d + j

            // k > j && k - j < d
            // lower bound (j + d) - lower bound(j)

            // k - j > d
            // k - j < d
        }
    }
    println(ans)


}

Measured memory_bytes: 39956
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    string s,t;
    cin>>a;
    cout<<(a+1)/2<<endl;
}


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

int main()
{
  int a, b, k;
  cin >> a >> b >> k;
  if (b - a < k * 2) {
    for (int i = a; i <= b; i++) {
      cout << i << endl;
    }
  } else {
    for (int i = 0; i < k; i++) {
      cout << a + i << endl;
    }
    for (int i = -k + 1; i <= 0; i++) {
      cout << b + i << endl;
    }
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
//言語は「C++14(GCC 5.4.1)」
//AtCoder Beginner Contest 45-A

int main(void)
{
	int A, Aafter, B, Bafter;
	scanf("%d", &A);
	scanf("%d", &B);
	Aafter = A;
	Bafter = B;
	if (A == 1)
		Aafter = 14;
	if (B == 1)
		Bafter = 14;
	if (Aafter == Bafter)
		printf("Draw");
	else if (Aafter > Bafter)
		printf("Alice");
	else if (Aafter < Bafter)
		printf("Bob");
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	if(s[a]=='-')
	{
		int i,flag = 0;
		for(i = 0; i<s.length(); i++)
		{
			if(i==a) continue;
			if(s[i]>'9' || s[i]<'0') flag = 1;
		}
		if(flag) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int  Q = 1;
  for(int i = 0;i < 3;i++){
    if(S.at(i) == S.at(i + 1))
      Q = 0;
  }
  if(Q == 1)
    cout << "Good" << endl;
  if(Q == 0)
   cout << "Bad" << endl;
}
    

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    ll d,t,s;
    cin>>d>>t>>s;
    if (d <= t*s) {
	cout<<"Yes\n";
    } else {
	cout<<"No\n";
    }
    
    
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
ll f[20000001];
ll invf[20000001];
ll calc(int x, int y){
	return f[x+y]*invf[x]%MOD*invf[y]%MOD;
}
int main()
{
	int h, w, k; cin>>h>>w>>k;
	f[0]=1;
	for(ll i=1; i<=h+w; i++) f[i]=f[i-1]*i%MOD;
	invf[h+w]=inv(f[h+w]);
	for(ll i=h+w-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
	ll ans=0;
	for(ll i=1; i<=k; i++){
		ans+=(calc(w, h)+i*calc(w-1, h)+i*calc(w, h-1)+i*(i-1)%MOD*calc(w-1, h-1));
		ans%=MOD;
	}
	ans*=(f[w]*f[h]%MOD*invf[h+w-k]%MOD);
	ans%=MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 312704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    string w;cin>>w;
    map<string,int> m;
    m[w]++;
    bool flag = true;
    rep(i,n-1){
        string x;cin>>x;
        m[x]++;
        if(m[x]==2||w[w.size()-1]!=x[0]){flag=false;}
        w=x;
    }
    cout<<(flag?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;

const int maxn = 100100;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int t = 1; // cin >> t;
    while(t--){
       int n,k; cin >> n >> k;
       k--;
       string s; cin >> s;
       s[k] = s[k] - 'A' + 'a';
       cout << s << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,m,h,w,a,b,c,d;
string str;

signed main(){

  string gl;
  cin >> gl >> str;
  cout <<"A"<<str[0]<<"C\n";
  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main( String[] args )
    {
        Scanner scanner = new Scanner(System.in);
        int H = scanner.nextInt();
        int A = scanner.nextInt();
        int i= 0;

        while (true) {

            H = H - A;
            i++;
            if(H <= 0)break;

        }

        System.out.println(i);

    }
}

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

typedef long long ll;

bool judge(ll* ar, ll N) {
  for (int i = 0; i < N; i++) {
    if (*ar == i + 1) {
      return false;
    }
    ++ar;
  }
  return true;
}

void solve() {
  ll N;
  cin >> N;
  ll p[100001];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  ll res = 0;
  for (int i = 0; i < N; i++) {
    if (p[i] == i + 1) {
      res++;
      if (i == N - 1) {
        swap(p[i], p[i-1]);
      }
      else {
        swap(p[i], p[i+1]);
      }
    }
  }
  cout << res << endl;
}

int main() {
  solve();
}


Measured memory_bytes: 1024
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
 
const int NMAX = 300000;
const int LOGN = 20;
int V[LOGN];
int Lmost[NMAX][LOGN], Rmost[NMAX][LOGN];
 
int dpL[1<<LOGN], dpR[1<<LOGN];
int arr[NMAX+1];
int dp[NMAX+2];
 
int main(){
    int N; scanf("%d%d",&N,&V[0]);
    for(int i=1;i<=N;i++) scanf("%d",arr+i);
 
    int M = 1;
    while(V[M-1]){
        V[M] = V[M-1]/2;
        M++;
    }
 
    for(int i=0;i<M;i++){
        int v = V[i];
        int j = 1;
        while(j<=N){
            int k = j+1;
            while(k<=N && arr[k]-arr[k-1] <= v) k++;
            for(int x=j;x<k;x++) Rmost[x][i] = k-1;
            j = k;
        }
        j = N;
        while(j>=1){
            int k = j-1;
            while(k>=1 && arr[k+1]-arr[k] <= v) k--;
            for(int x=j;x>k;x--) Lmost[x][i] = k+1;
            j = k;
        }
    }
 
    for(int i=0;i<(1<<M);i++) dpR[i] = N+1;
    for(int i=1;i<(1<<M);i++){
        for(int j=0;j<M;j++) if(i&(1<<j)){
            // use V[j]
            int L = dpL[i^(1<<j)];
            dpL[i] = max(dpL[i], Rmost[L+1][j]);
 
            int R = dpR[i^(1<<j)];
            dpR[i] = min(dpR[i], Lmost[R-1][j]);
        }
    }
 
    for(int i=0;i<=N+1;i++) dp[i] = -0x3fFFffFF;
 
    for(int i=0;i<(1<<M);i+=2){
        int j = ((1<<M)-1)^i^1;
        dp[dpR[j]] = max(dp[dpR[j]], dpL[i]);
    }
 
    for(int i=1;i<=N+1;i++)
        dp[i] = max(dp[i], dp[i-1]);
 
    for(int i=1;i<=N;i++){
        int L = Lmost[i][0], R = Rmost[i][0];
        int det = dp[R+1];
        if(det>=L-1) printf("Possible\n");
        else printf("Impossible\n");
    }
}

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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define VI(v,n) vector<int> v(n);REP(i,n){assert(0<scanf("%d",&v[i]));}
#define MSET(arr,val)  memset(arr,val,sizeof(arr))

class union_find {
public:
  vector<unsigned int> par, rank;
  union_find(unsigned int n) {
    for(unsigned int i = 0; i < n; i++){
      par.push_back(i);
      rank.push_back(0);
    }
  }
  unsigned int root(unsigned int x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }
  bool same(unsigned int x, unsigned int y){
    return root(x) == root(y);
  }
  void unite(unsigned int x, unsigned int y){
    x = root(x);
    y = root(y);
    if (x == y){return;}
    if (rank[x] < rank[y]){
      par[x] = y;
    }
    else {
      par[y] = x;
      if (rank[x] < rank[y]){
        rank[x]++;
      }
    }
  }
};

int main(){
  ll ans = 0; int cnt = -1;
  INT(n); INT(m); VI(as, n);
  union_find uni(n);
  REP(m){
    INT(x); INT(y);
    uni.unite(x, y);
  }
  vector<vector<pair<int, int>>> vvp(n);
  REP(i, n){
    vvp[uni.root(i)].EB(as[i], i);
  }
  vector<pair<int, int>> vp;
  REP(i, n){
    if (vvp[i].empty()){continue;}
    sort(vvp[i].begin(), vvp[i].end());
    vp.EB(SZ(vvp[i]), i);
    cnt++;
  }
  sort(vp.rbegin(), vp.rend());
  set<pair<int, int>> sp;
  for(auto p0: vp){
    for(auto p: vvp[p0.second]){
      if (sp.empty()){
        sp.insert(p);
        continue;
      }
      int u = (*sp.begin()).second, v = p.second;
      if (uni.same(u, v)){
        sp.insert(p);
      } else {
        uni.unite(u, v);
        ans += as[u] + as[v];
        sp.erase(sp.begin());
      }
    }
  }
  REP(i, 1, n){
    if (!uni.same(0, i)){
      ans = -1;
      break;
    }
  }
  if (ans < 0){
    printf("Impossible\n");
  } else{
    printf("%lld\n", ans);
  }
  return 0;
}

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

int main() {
    int n,count=0;
    cin>>n;
    vector<int> d(n);
    rep(i,n) cin>>d.at(i);

    sort(d.begin(),d.end());

    if (n%2==0) {
        count=d.at(d.size()/2)-d.at(d.size()/2-1);
    }

    cout<<count<<endl;
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> X(N), A(M), B(M), C(M);
	for (int i = 0; i < N; ++i) {
		cin >> X[i];
	}
	for (int i = 0; i < M; ++i) {
		cin >> A[i] >> B[i] >> C[i]; --A[i], --B[i];
	}
	vector<int> perm(M);
	for (int i = 0; i < M; ++i) {
		perm[i] = i;
	}
	sort(perm.begin(), perm.end(), [&](int i, int j) { return C[i] < C[j]; });
	vector<int> fA(M), fB(M), fC(M);
	for (int i = 0; i < M; ++i) {
		fA[i] = A[perm[i]];
		fB[i] = B[perm[i]];
		fC[i] = C[perm[i]];
	}
	A = fA; B = fB; C = fC;
	vector<vector<int> > g(N), cg(N), sg(N);
	vector<int> root(N), croot(N);
	vector<long long> cost(N), ccost(N);
	for (int i = 0; i < N; ++i) {
		g[i].push_back(i);
		cg[i].push_back(i);
		sg[i].push_back(i);
		root[i] = i;
		croot[i] = i;
		cost[i] = X[i];
		ccost[i] = X[i];
	}
	for (int i = 0; i < M; ++i) {
		int a = root[A[i]], b = root[B[i]];
		if (a == b) continue;
		if (g[a].size() < g[b].size()) {
			swap(a, b);
		}
		for (int j : g[b]) {
			root[j] = a;
		}
		cost[a] += cost[b];
		g[a].insert(g[a].end(), g[b].begin(), g[b].end());
		g[b].clear();
		cg[a].insert(cg[a].end(), cg[b].begin(), cg[b].end());
		cg[b].clear();
		if (cost[a] >= C[i]) {
			for (int j : cg[a]) {
				if (j == a) continue;
				for (int k : sg[j]) croot[k] = a;
				sg[a].insert(sg[a].end(), sg[j].begin(), sg[j].end());
				ccost[a] += ccost[j];
				sg[j].clear();
			}
			cg[a] = vector<int>({ a });
		}
	}
	int ans = 0;
	for (int i = 0; i < M; ++i) {
		if (croot[A[i]] == croot[B[i]] && ccost[croot[A[i]]] >= C[i]) {
			++ans;
		}
	}
	cout << M - ans << endl;
	return 0;
}


Measured memory_bytes: 27160
// ABC 151-F
// 2020.1.12 bal4u

#include <stdio.h>
//#include <stdlib.h>
#include <math.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

#define EPS 1e-10

typedef struct { double x, y; } PP;
PP p[55];

double dist(PP a, PP b)
{
	double x = a.x - b.x;
	double y = a.y - b.y;
	return sqrt(x*x + y*y);
}

double solve_by_movement(int n)
{
	int  k, i, t;
	PP a;
	double move, max, d;

    a.x = a.y = 500;
	move = 0.5;
	while (move > EPS) {
		for (t = 0; t < 100; t++) {
			max = 0;
			for (i = 0; i < n; i++) {
				if ((d = dist(a, p[i])) > max) max = d, k = i;
			}
			a.x += (p[k].x - a.x)*move;
			a.y += (p[k].y - a.y)*move;
		}
		move /= 2;
	}
	return max;
}

int main()
{
	int i, x, y, N;

	N = in();
	for (i = 0; i < N; ++i) {
		p[i].x = in(), p[i].y = in();
	}
	printf("%.10lf\n", solve_by_movement(N));
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn=510;
int h[maxn][maxn],a[maxn][maxn],p[maxn*maxn];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int n;
void dfs(int x,int y)
{
    int cost,nx,ny;
    cost=h[x][y]+a[x][y];
    for (int d=0;d<4;d++) {
        nx=dx[d]+x; ny=dy[d]+y;
        if (nx<=0||nx>=n||ny<=0||ny>=n) continue ;
        if (cost<h[nx][ny]) {
            h[nx][ny]=cost;
            dfs(nx,ny);
        }
    }
}
int main()
{
  //  freopen("text.in","r",stdin);
    int ans,x,y;
    scanf("%d",&n);
    for (int i=1;i<=n*n;i++) {
        scanf("%d",&p[i]);
    }
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=n;j++) {
            h[i][j]=min(i-1,min(j-1,min(n-i,n-j)));
            a[i][j]=1;
        }
    }
    ans=0;
    for (int i=1;i<=n*n;i++) {
        x=(p[i]-1)/n; y=p[i]-x*n; x++;
        a[x][y]=0;
        dfs(x,y);
        ans+=h[x][y];
    }
    printf("%d\n",ans);
    return 0;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

int main() {
    int n,p;
    ll ans = 0;
    cin >> n >> p;
    string s;cin >> s;
    if (p == 2 || p == 5) {
        for (int i = 0;i < n;++i) if ((s[i]-'0')%p == 0) ans += i+1;
    } else {
        reverse(s.begin(),s.end());
        int a = 1;
        int t = 0;
        vector<ll> cnt(p,0);
        cnt[0] = 1;
        for (int i = 0;i < n;++i) {
            t = (t+(s[i]-'0')*a)%p;
            ans += cnt[t]++;
            (a *= 10) %= p;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int n;
    cin>>n;
    int a[3*n+4];
    f(i,1,3*n)cin>>a[i];
    sort(a+1,a+3*n+1);
    int ses=0;
    for(int i=n+1;i<=3*n;i=i+2)
    {
        ses+=a[i];
    }
    cout<<ses<<endl;
    return 0;

}





































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

int main(){
    
    
    while(true){
        
        
        int a,b;
        cin>>a>>b;
        if(a==0&&b==0)break;
        for(int i=0;i<a;i++){
            for(int j=0;j<b;j++){
                if(i==0||i==a-1||j==0||j==b-1)cout<<'#';
                else cout<<'.';
            }
            cout<<endl;
        }
        
        cout<<endl;
        
    }
    
    
    
    
}


Measured memory_bytes: 3080
#include <iostream>
#include <sstream>

int main() {
  int A, B;
  std::cin >> A >> B;

  std::stringstream ss;

  ss << A << B;

  int n = std::stoi(ss.str());

  bool yes = false;

  for (int i = 0; !yes && i * i <= n; i++) {
    yes = (i * i == n);
  }

  std::cout << (yes ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int min_distance(int i, int j, int x, int y){
    int min = j - i;
    if (min > abs(x-i) + 1 + abs(y-j)){
        min = abs(x-i) + 1 + abs(y-j);
    }
    if (min > abs(y-i) + 1 + abs(x-j)){
        min = abs(y-i) + 1 + abs(x-j);
    }
    return min;
}

int main(){
    int n,x,y;
    cin >> n >> x >> y;
    int count[n] = {};
    for (int i = 1; i < n + 1; i++){
        for (int j = i; j < n + 1; j++){
            count[min_distance(i,j,x,y)]++;
        }
    }
    for (int i = 1; i < n; i++){
        cout << count[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pi pair <string, int>
using namespace std;

struct comp
{
	string a;
	int b;
	int c;
	bool operator()(auto x, auto y)
	{
		if (x.a < y.a) return true;
		else if (x.a == y.a)
			if (x.b < y.b) return false;
			else return true;
		else return false;
	} 
} obj;

int main() 
{
	int n;
	cin >> n; 
	comp p[n];
	for (int i = 0; i < n; i++)
	{
		cin >> p[i].a;
		cin >> p[i].b;
		p[i].c = i + 1;
	}
	sort(p, p + n, obj);
	
	for (int i = 0; i < n; i++) cout << p[i].c << endl;
}

Measured memory_bytes: 256
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o A.exe A.cpp 
Execute: ./A
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	int a; 
	cin >> a; 
	
	cout << a + a*a + a*a*a << endl; 
	
	return 0; 
} 


Measured memory_bytes: 3568
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int main()
{
    int n,k;
    vi l;
    cin >> n >> k;
    l.resize(n);
    rep(i,n) cin >> l[i];
    sort(all(l), greater<int>());
    int ans = 0;
    rep(i,k) ans += l[i];
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long aa = sc.nextLong();
      long a = Math.abs(aa);
		// スペース区切りの整数の入力
		long b = sc.nextLong();
		long c = sc.nextLong();
		// 文字列の入力
		long d = a / c;
		if(d > b){
			System.out.println(a - b * c);
         // System.out.println(0);
		}else{
			if((b- d) % 2 == 0){
				System.out.println(a % c);
              // System.out.println(1);
			}
			else{
				System.out.println(- (a % c) + c);
              // System.out.println(2);
			}
		}
		
		
	}
}

Measured memory_bytes: 35772
three_int = list(map(int, input().split()))
k = int(input())

for _ in range(k):
    three_int = sorted(three_int, reverse=True)
    # 0th element is the max value in the list (A, B, C)
    three_int[0] = three_int[0] * 2
print(sum(three_int))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N, x; cin >> N >> x;
    vec a(N); readvec(a);
    SORT(a);

    int ans = 0;
    REP(i, N - 1){
        if(x >= a[i]){
            x -= a[i];
            ans++;
        }
    }
    if(x == a[N - 1]) ans++;
    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

void ioinit() { ios::sync_with_stdio(0); cin.tie(0); }

int main() {
  ioinit();
  int a,b;
  cin >> a >> b;
  string ret = "Even";
  if((a*b) % 2 == 1) ret = "Odd";
  cout << ret << endl;
}


Measured memory_bytes: 256
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
if A + B + C + D == 7:
    op1 = op2 = op3 = "+"
elif A + B + C - D == 7:
    op1 = op2 = "+"
    op3 = "-"
elif A + B - C + D == 7:
    op1 = op3 = "+"
    op2 = "-"
elif A + B - C - D == 7:
    op1 = "+"
    op2 = op3 = "-"
elif A - B + C + D == 7:
    op1 = "-"
    op2 = op3 = "+"
elif A - B + C - D == 7:
    op1 = op3 = "-"
    op2 = "+"
elif A - B - C + D == 7:
    op1 = op2 = "-"
    op3 = "+"
elif A - B - C - D == 7:
    op1 = op2 = op3 = "-"
print(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3] + "=7")

Measured memory_bytes: 61728
s = input()
x,y = map(int,input().split())

XY = [[],[]]
i = 0
xy = 0
for c in s+"T":
    if c == "T":
        XY[xy].append(i)
        i = 0
        xy = 1-xy
    else:
        i+=1

xset = set((XY[0][0],))
yset = set((0,))
for X in XY[0][1:]:
    xset = set(i + X for i in xset) | set(i - X for i in xset)
for Y in XY[1]:
    yset = set(i + Y for i in yset) | set(i - Y for i in yset)
if x in xset and y in yset:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4928
//#pragma GCC optimize(2)


#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#include<ext/rope>*/
//using namespace __gnu_cxx;
//using namespace __gnu_pbds;
//void err(istream_iterator<string> it){cerr<<endl;}
//template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args){cerr << *it << " = " << a << " , ";err(++it, args...);}
//#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mem(a,b) memset((a),b,sizeof((a)))
#define fpre(x) cout<<fixed<<setprecision(x)
#define clr(v) (v).clear()
#define pii pair<int,int>
#define pdd pair<double,double>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp make_pair
#define eb emplace_back
#define pb emplace_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define uint unsigned int
#define ushort unsigned short
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define lowbit(i) (i&(-i))
#define lson rt<<1
#define rson lson|1
#define fi first
#define se second
const double eps=1e-7;
const double pi=acos(-1);
inline int dcmp(double x)
{
    if(x<-eps)
        return -1;
    if(x>eps)
        return 1;
    return 0;
}
//-----------------------------------------------head

bool v[10];
bool ok(int n)
{
    while(n)
    {
        if(v[n%10])
            return 0;
        n/=10;
    }
    return 1;
}
int a[4];
int main()
{
    while(cin>>a[0]>>a[1]>>a[2])
    {
        sort(a,a+3);
        if(a[0]!=5||a[1]!=5||a[2]!=7)
            cout<<"NO\n";
        else
            cout<<"YES\n";
    }
}

/*
6
0 0 -1 3
-2 -1
2 3
3 -1
-1 2
-3 2
-4 0
6
3 10 3 2
2 1
4 1
0 3
6 3
4 4
2 4
6
3 2 3 10
2 1
4 1
0 3
6 3
4 4
2 4
*/









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ll n, k, ans = 0;
  cin >> n >> k;
  vector<ll> a(n), bcnt(n, 0), acnt(n, 0);
  REP(i, n) { cin >> a[i]; }

  REP(i, n) {
    for (ll j = i + 1; j < n; j++) {
      if (a[i] > a[j]) acnt[i]++;
    }
  }

  REP(i, n) {
    for (ll j = i - 1; j >= 0; j--) {
      if (a[i] > a[j]) bcnt[i]++;
    }
  }
  REP(i, n) {
    ans += acnt[i] * (k * (k + 1) / 2 % MOD)%MOD;
    ans += bcnt[i] * (k * (k - 1) / 2 % MOD)%MOD;
    ans %= MOD;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 2000;
int N, Z, W, c[MAX_N];

int main() {
  cin >> N >> Z >> W;
  for (int i=0; i<N; i++) {
    cin >> c[i];
  }
  int ans = abs(W - c[N-1]);
  if (2 <= N) ans = max(ans, abs(c[N-2] - c[N-1]));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int r, c;
    while(cin >> r >> c && (r || c))
    {
        if( r % 2 && c % 2) cout << "no" << endl;
        else cout << "yes" << endl;

    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

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;
  }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  //fact 階乗　iface 階乗の逆数
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    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];
  }
};

int main(){
  int r1,c1,r2,c2;
  cin >> r1 >> c1 >> r2 >> c2;
  mint ans = 0;
  combination c(2000005);
  ans += c(r2+c2+2,c2+1)-1;
  ans -= c(r1+c2+1,r1)-1;
  ans -= c(r2+c1+1,c1)-1;
  ans += c(r1+c1,c1)-1;
  cout << ans << endl;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  
  ll ans = 0;
  ll x1 = 0, x2 = 0;
  rep(i,n-1) {
    if (a[i] == a[i+1]) {
      if (x1 == 0) x1 = a[i++];
      else {
        x2 = a[i];
        break;
      }
    }
  }
   
  ans = x1*x2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  int n; read(n);
  int t=0;
  for(int i=1;i<=n;++i) {
    int a; read(a);
    t+=a&1;
  }
  puts(t%2?"NO":"YES");
  return 0;
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;


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

	string s;
	cin >> s;
	if(sz(s) >= 4 && s.substr(0, 4).find("YAKI") != string::npos){
		dier("Yes");
	}else{
		dier("No");
	}

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)


def main():
    N, K = map(int, input().split())

    num = 0
    min_sum = sum(range(0, K))
    max_sum = sum(range(N + 1 - K ,N + 1))

    for i in range(N + 2 - K):
        num += max_sum - min_sum + 1
        max_sum += N - K - i
        min_sum += K + i

    D = 10 ** 9 + 7
    print(num % D)



if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
import math

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

cnt = 0
for i in range(min(a, math.floor(x / 500)) + 1):
  for j in range(min(b, math.floor(x / 100)) + 1):
    for k in range(min(c, math.floor(x / 50)) + 1):
      if x - i * 500 - j * 100 - k * 50 == 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))

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

template<class T> void dump(const vector<T> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

template<class T> void dump(int w, int h, const vector<T> &v)
{
	REP(j, h){
		REP(i, w-1){ cout << v[j * w + i] << " "; }
		cout << v[j * w + w-1] << endl;
	}
}

template<class T> struct Matrix
{
	T w, h;
	vector<T> A;
	Matrix(T w_, T h_) : w(w_), h(h_), A(w * h) {}
	T get(T x, T y) const { return A[y * w + x]; }
};

template<class T> void input(Matrix<T> &m)
{
	REP(j, m.h){
		REP(i, m.w){
			cin >> m.A[j * m.w + i];
		}
	}
}

template<class T> Matrix<T> prod(const Matrix<T> &a, const Matrix<T> &b)
{
	Matrix<T> m(b.w, a.h);

	REP(j, m.h){
		REP(i, m.w){
			ll c = 0;
			REP(k, a.w){
				c += a.A[j * a.w + k] * b.A[k * b.w + i];
			}
			m.A[j * m.w + i] = c;
		}
	}

	return m;
}

void dump(const Matrix<ll> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%lld ", m.A[j * m.w + i]); }
		printf("%lld\n", m.A[j * m.w + m.w-1]);
	}
}

void dump(const Matrix<double> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%f ", m.A[j * m.w + i]); }
		printf("%f\n", m.A[j * m.w + m.w-1]);
	}
}

int main()
{
	int cnt[256];

	ZERO(cnt);
	
	for(;;){
		string s;
		if(!getline(cin, s))
			break;

		REP(i, s.length()){
			cnt[(int)(s[i])]++;
		}
	}

	REP(i, 26){
		printf("%c : %d\n", (char)('a' + i), cnt['A' + i] + cnt['a' + i]);
	}

	return 0;
}



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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (int i=1; i<=n; i++)
#define rep0(i,n) for (int i=0; i<n; i++)
#define chmin(a,b) if ((a)>(b)) { a=(b); }
#define chmax(a,b) if ((a)<(b)) { a=(b); }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%d "; return r + "\n"; }
#define debug(...) printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__);
#else
#define debug(...) 
#endif

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

    cout << n + n*n + n*n*n << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

bool f(int x)
{
	int a = 0;
	for (int i = 2; i * i <= x; i++)
	{
		if (x % i == 0)
		{
			a = 1;
			break;
		}
	}
	if (a == 1) return false;
	else return true;
}

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

	int y = 0;
	while (y == 0)
	{
		if (f(x))
		{
			y = x;
		}
		x++;
	}
	
	cout << y << "\n";
	return 0;
}

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


int main(){
	int A,B;
	cin >> A >> B;
	
	if(A==B){
		cout << "Draw" << endl;
	}else if(A==1){
		cout << "Alice" << endl;
	}else if(B==1){
		cout << "Bob" << endl;
	}else{
		if(A>B){
			cout << "Alice" << endl;
		}else{
			cout << "Bob" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
# デバッグ用
GBN_DEBUG = False
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')
def puts(s): print(s)

#本体ここから

#S = input()
N = int(input())
#S, T = input().split()
#A, B, C = map(int, input().split())
#W = [input() for _ in range(N)]
#A = list(map(int, input().split()))

#GBN_DEBUG = True

if N < 10:
    print(N)
elif N < 100:
    print(9)
elif N < 1000:
    print(9 + N - 99)
elif N < 10000:
    print(909)
elif N < 100000:
    print(909 + N - 9999)
else:
    print(90909)


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

int Col(int x){
  if(x%2==0){
    return x/2;
  }
  else{
    return 3*x+1;
  }
}

int main(){
  int s;
  cin >> s;
  vector<int> N(1000005, 0);
  N.at(s)++;
  for(int i=1; i<1000005; i++){
    s=Col(s);
    if(N.at(s)==1){
      cout << i+1 << endl;
      break;
    }
    else{
      N.at(s)++;
    }
  }
}

Measured memory_bytes: 4096