akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  
  if (a == 1) { a = 14; }
  if (b == 1) { b = 14; }
  
  if (a == b) {
    cout << "Draw" << endl;
  } else if (a > b) {
    cout << "Alice" << endl;
  } else {
    cout << "Bob" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long int ll;
const ll MOD (1e9+7);
const ll INF (2e9);
const int MAX_N (200001);

int main(void) {
    int n,t;
    cin>>n>>t;
    int end=-1;
    ll ans=t;
    int t1,t2;
    cin>>t1;
    for(int i=1;i<n;i++){
        cin>>t2;
        ans+=min(t2-t1,t);
        t1=t2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=4010,mod=924844033;
int n,k,tot,ans,vis[N][2],fac[N],ed[N],g[N],f[N][N][2];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=fac[0]=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
	for(int i=1;i<=n;i++)for(int j=0;j<2;j++)if(!vis[i][j]){int l=0;for(int x=i,y=j;x<=n;x+=k,y^=1)vis[x][y]=1,l++;ed[tot+=l]=1;}
	f[1][0][0]=1;
	for(int i=1;i<=tot;i++)for(int j=0;j<=n;j++)
	{
		f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%mod;
		if(!ed[i])f[i+1][j+1][1]=f[i][j][0];
	}
	for(int i=0;i<=n;i++)g[i]=(f[tot][i][0]+f[tot][i][1])%mod;
	for(int i=0,j=1;i<=n;i++,j=mod-j)ans=(ans+1ll*j*fac[n-i]%mod*g[i])%mod;
	printf("%d\n",ans);
	return 0;
} 

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

struct edge{
	int to,next;
}e[1000005];
int n,N,cnt,ans,head[1000005],a[1005][1005],q[1000005],pre[1000005],dis[1000005];

void add_edge(int u,int v){
	e[++cnt].next=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}

int main(){
	cin>>n;
	for (int i=1;i<n;i++){
		for (int j=i+1;j<=n;j++){
			a[i][j]=++N;
			dis[N]=-1;
		}
	}
	int be,af,h=1,t=0;
	for (int i=1;i<=n;i++){
		cin>>be;
		for (int j=1;j<n-1;j++){
			cin>>af;
			add_edge(a[min(i,be)][max(i,be)],a[min(i,af)][max(i,af)]);
			pre[a[min(i,af)][max(i,af)]]++;
			be=af;
		}
	}
	
	for (int i=1;i<=N;i++){
		if (!pre[i]){
			q[++t]=i;
			dis[i]=1;
		}
	}
	while (h<=t){
		int u=q[h];
		for (int i=head[u];i;i=e[i].next){
			int v=e[i].to;
			pre[v]--;
			dis[v]=max(dis[v],dis[u]+1);
			if (!pre[v]) q[++t]=v;
		}
		pre[u]=0x7ffffff;
		h++;
	}
	if (t<N) cout<<-1;
	else{
		ans=-1;
		for (int i=1;i<=N;i++){
			ans=max(ans,dis[i]);
		}
		cout<<ans;
	}
	return 0;
}

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

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    ll h, n;
    cin >> h >> n;
    vector<int> a(n);
    ll ans = 0;
    REP(i, n)
    {
        ll x;
        cin >> x;
        ans += x;
    }

    cout << (ans < h ? "No" : "Yes") << endl;

    return 0;
}

Measured memory_bytes: 640
n = int(input()) + 1
a = list(map(int, input().split())) + [2**21-1]

cnt = 0
l = 0
r = 0
s = 0
x = 0
while l < n-1:
    while r < n and s == x:
        s += a[r]
        x ^= a[r]
        r += 1
    cnt += (r-l - 1)
    s -= a[l]
    x ^= a[l]
    l += 1
print(cnt)


Measured memory_bytes: 23560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int N; cin >> N;
    ll cnt = 0;
    vel A(N), B(N); rep(i,N) {cin >> A[i]; B[i] = abs(A[i]); if (A[i] < 0) cnt++;}

    sort(all(A)); sort(all(B));

    int64 ans = 0LL;
    rep(i,N) ans += abs(A[i]);
    if (cnt % 2 == 1) {
        ans -= 2 * B[0];
    }
    cout << ans  << endl;
    return 0;
}

Measured memory_bytes: 1792
/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  // typedef second ss;
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  const ll mod=1e9+7;
  const ll MAX=3e6+10;
  //
  //
  ll solve(){
    cout<<fixed<<setprecision(8);
    double a,b,x,y;
    cin>>a>>b>>x>>y;
    cout<<(a*b/2.0)<<" ";
    if(2*x==a&&2*y==b)
      cout<<"1";
    else
      cout<<"0";
  }
  int main(){ 
        ll t;
        // cin>>t;
        t=1;
        while(t--)
          solve();
    } 

Measured memory_bytes: 256
// 問題URL
// https://atcoder.jp/contests/abc127/tasks/abc127_c

import java.util.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        Integer M = Integer.parseInt(scanner.next());
        int LIMIT = 100000;
        int[] S = new int[LIMIT+1];


        for(int i = 0; i < M; i++) {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        }

        int count = 0;
        for(int i = 1; i <= LIMIT; i++) {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 51012
// g++ -I ~/Documents/programming/cppLib -std=gnu++14 -o test ~/Documents/programming/cppLib/test.cpp && ./test && rm test
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vector2 = vector <vector  <T>>;
template <typename T> using vector3 = vector <vector2 <T>>;
template <typename T> using vector4 = vector <vector3 <T>>;
using lint = long long;
#define FOR( i, a, b ) for( lint i=(a) ; i < (b) ; ++i )
#define REP( i, n )    for( lint i= 0  ; i < (n) ; ++i )
#define ALL( v )       (v).begin(), (v).end()

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

    int count = 0;

    double prob = 0;
    for( int i=1; i<=N; i++ ) {
        double prob_ = 1.0;
        for( int j=i; j<K; j*=2 ) {
            prob_ /= 2;
        }
        prob += prob_;
    }

    cout << setprecision(20) << prob / N << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    an = []
    bn = []
    for i in range(n):
        a, b = map(int, input().split())
        an.append(a)
        bn.append(b)
    su = sum(an)
    assert sum(bn) == su

    if an == bn:
        return 0

    mi_b_smaller = HUGE
    for i in range(n):
        if an[i] > bn[i]:
            mi_b_smaller = min(mi_b_smaller, bn[i])

    return su - mi_b_smaller

print(main())



Measured memory_bytes: 5492
s = gets.chomp
ans = []
i = 0
while i < s.size
  tmp = i
  while s[i] == "R"
    i += 1
  end
  r = i - tmp
  while s[i] == "L"
    i += 1
  end
  l = i - r - tmp
  if (l + r).odd?
    if r > l
      if (r - 1).odd? # 反転
        (r - 1).times do
          ans << 0
        end
        ans << (l + r) / 2
        ans << (l + r) / 2 + 1
        (l - 1).times do
          ans << 0
        end
      else
        (r - 1).times do
          ans << 0
        end
        ans << (l + r) / 2 + 1
        ans << (l + r) / 2
        (l - 1).times do
          ans << 0
        end
      end
    else
      if (l - 1).odd? # 反転
        (r - 1).times do
          ans << 0
        end
        ans << (l + r) / 2 + 1
        ans << (l + r) / 2
        (l - 1).times do
          ans << 0
        end
      else
        (r - 1).times do
          ans << 0
        end
        ans << (l + r) / 2
        ans << (l + r) / 2 + 1
        (l - 1).times do
          ans << 0
        end
      end
    end
  else
    a = (l + r) / 2
    (r - 1).times do
      ans << 0
    end
    ans << a
    ans << a
    (l - 1).times do
      ans << 0
    end
  end
end

puts ans * ' '

Measured memory_bytes: 5372
#include <iostream>
#include <vector>
using namespace std;
vector<int> ans;
int ch;
int solute(int k)
{
	int num=0;
		for(int a=0;a<10;a++)
		for(int b=0;b<10;b++)
			for(int c=0;c<10;c++)
				for(int d=0;d<10;d++)
				{
					if(a+b+c+d==k)
						num++;
				}
		return num;
}
int main()
{
	while(cin>>ch)
	{
		ans.push_back(ch);
	}
	for(int i=0;i<ans.size();i++)
	{
		cout<<solute(ans[i])<<endl;
	}
    
	
	
	return 0;
}

Measured memory_bytes: 3056
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author @MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TripletSum solver = new TripletSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class TripletSum {
        public void solve(int testNumber, FastReader fs, PrintWriter pw) {
            int k = fs.nextInt(), Sum = fs.nextInt();
            int ans = 0;
            for (int i = 0; i <= k; i++) {
                for (int j = 0; j <= k; j++) {
                    int p = Sum - i - j;
                    if (p < 0 || p > k) continue;
                    ans += 1;
                }
            }
            pw.println(ans);
        }

    }

    static class FastReader {
        BufferedReader bf;
        StringTokenizer st;

        public FastReader(InputStream is) {
            bf = new BufferedReader(new InputStreamReader(is));
            st = null;
        }

        public String next() {
            try {
                while (st == null || !st.hasMoreTokens()) {
                    String line = bf.readLine();
                    if (line == null) return null;
                    st = new StringTokenizer(line);
                }
            } catch (Exception e) {
            }

            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 8528
#include "bits/stdc++.h"
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long int;

int C[2001][2001];
const int mod = 1e9+7;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	for (int i = 0; i < 2001; ++i)
		C[i][0] = 1;
	for (int i = 1; i < 2001; ++i)
		for (int j = 1; j <= i; ++j)
			C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;

	int s; cin >> s;
	int ans = 0;
	for (int len = 1; len <= s/3; ++len) {
		int sum = s - 3*len;

		// len variables >= 0, with sum
		ans += C[len+sum-1][sum];
		ans %= mod;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 17424
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    int dif = 0;
    for(int i=0; i<n; i++){
        int p; cin>>p;
        dif += (p != i + 1);
    }

    if(dif == 0 || dif == 2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();

    int result = 0;
    result = Math.max(A + B, A - B);
    result = Math.max(result , A * B);
    System.out.println(result);
  }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    ll a,b,c,d; cin >> a >> b >> c >> d;
    //ll ans = a*c;
    //chmax(ans, b*d);
    //cout << ans << endl;
    ll ans = a*c;
    chmax(ans,a*d);
    chmax(ans,b*c);
    chmax(ans,b*d);
    cout << ans << endl;

}

Measured memory_bytes: 3632
def B_isu(X, Y, Z):
    import math
    # k(Y+Z)+Z<=Xを満たす最大のkが答え。
    ans = math.floor((X - Z) / (Y + Z))
    return ans

X,Y,Z = [int(i) for i in input().split()]
print(B_isu(X, Y, Z))

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
  int cnt;
  int A,B;
  int result;

  cnt = scanf("%d %d", &A, &B);

  if((B%A) == 0) {
    result = A + B;
  } else {
    result = B - A;
  }
  
  printf("%d", result);

  return 0;
} 

Measured memory_bytes: 128
s=gets.chop
k=s.size
while k>0
    if s[k-5, 5]=='dream' or s[k-5, 5]=='erase'
        k-=5
    elsif s[k-6, 6]=='eraser'
        k-=6
    elsif s[k-7, 7]=='dreamer'
        k-=7
    else
        break
    end
end
puts (k>0 ? "NO" : "YES")


Measured memory_bytes: 1916
m[5][5];main(T,i,j,k,r,M,z){
for(scanf("%d",&T);T;printf("%d\n",r),T--){
	for(j=0;j<5;j++)for(r=i=0;i<5;m[j][i]=r,i++)if(scanf("%d",&k),k)r++;else r=0;
	for(r=i=0;i<5;i++)for(j=0;j<5;j++)for(M=9,k=j;k<5;k++){
		if(M>m[k][i])M=m[k][i];
		if(r<M*(z=k-j+1))r=M*z;
	}
}exit(0);}

Measured memory_bytes: 600
#!/usr/bin/env python

def main():
    a, b, c = map(int, input().split())

    if (c - a - b) ** 2 - 4 * a * b > 0 and c - a - b > 0:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


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

int main(){
  int n,A,B,sum=0;
  cin>>n>>A>>B;

  for(int N=1;N<=n;N++){
    int t[5];
    t[0]=(N%10);
    t[1]=(N%100)/10;
    t[2]=(N%1000)/100;
    t[3]=(N%10000)/1000;
    t[4]=(N%100000)/10000;
    int t_sum=t[0]+t[1]+t[2]+t[3]+t[4];

    if(A<=t_sum&&t_sum<=B)sum+=N;
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,diff;
long long arr[100005];
bool solve(long long attack){
	long long min_damage = attack*b;
	long long ret = attack;
	for(int i=0; i<n; i++){
		if(arr[i]<=min_damage) continue;
		else{
			long long left = arr[i]-min_damage;
			long long need_a = left/diff;
			if(left%diff) need_a++;
			ret-=need_a;
		}
	}
	if(ret<0) return false;
	return true;
}
int main(){
	cin>>n>>a>>b;
	diff = a-b;
	for(int i=0; i<n; i++) cin>>arr[i];
	long long start = 1;
	long long fin = numeric_limits<int>::max();
	while(start<=fin){
		long long mid = (start+fin)/2;
		//mid 횟수로 죽일 수 있다면 줄여본다.  
		if(solve(mid)) fin = mid-1;
		else start = mid+1;
		//cout<<mid<<" "<<solve(mid)<<'\n'; 
	}
	
	cout<<start;
}

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

//function to print the array
void print(vector<string> names){

	for(int i=0;i<names.size();i++)
		cout<<names[i];
	printf("\n");
}

bool mycomp(string a, string b){
	//returns 1 if string a is alphabetically
	//less than string b
	//quite similar to strcmp operation
	return a<b;
}

vector<string> alphabaticallySort(vector<string> a){
	int n=a.size();
	//mycomp function is the defined function which
	//sorts the strings in alphabatical order
	sort(a.begin(),a.end(),mycomp);
	return a;
}

int main()
{
	int n,l;

	scanf("%d %d",&n,&l);

	//creating a vector of strings
	//vector to store strings(names)
	vector<string> names;
	string name;

	//taking input
	for(int i=0;i<n;i++){
		cin>>name;
		//insert names into the vector
		names.push_back(name);
	}

	names=alphabaticallySort(names);
	print(names);

	return 0;
}


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

int n, x, l, c, p;

int main(){
	c = 1;
	p = 0;
	cin >> n >> x;
	for (int i = 0; i < n; ++i){
		cin >> l;
		p += l;
		c += (p <= x);
	}
	cout << c;
}

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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;

double sunuke(long long m){
  char ch[32];
  int ii,len;
  int sum = 0;
  double sumd;
  sprintf(ch,"%ld",m);
  //printf("%s",ch);
  len = strlen(ch);
  for(ii=0;ii<len;ii++){
	//cout << sum << endl;
	sum += ch[ii] - '0';
  }
  sumd = sum;
  return m/sumd;
}
bool isSunuke(long long m,long long pls){
  double sunu;
  long long ii;
  sunu = sunuke(m);
  for(ii=pls;ii<=pls*10000;ii=ii+pls){
	if(sunu > sunuke(m+ii)){
	  return false;
	}
  }
  return true;
}

int main(){
  long long k,cnt=0;
  long long first = 1,plus=1,pn,nextLen,firstLen,next,cur;
  char curstr[30],nextstr[30];
  cin >> k;
  
//  while(cnt<=k){
//	cout << first << endl;
//	
//	next = first + plus;
//
//	sprintf(curstr,"%s",first);
//	sprintf(nextstr,"%s",next);
//
//	curLen  = s
//	nextLen = strLen(nextstr);
//	
//  }
//  for(cnt=1;cnt<=1000;cnt++){
//	if(isSunuke(cnt)){
//	  cout << cnt << endl;
//	}
//  }

  cur = 1;
  pn = 0;
  while(cnt < k && cur <= pow(10,15)){
	if(isSunuke(cur,plus)){
	  cout << cur << endl;
	  cnt++;

	}
	if(!isSunuke(cur+plus,plus)){
	  pn++;
	  plus = pow(10,pn);
	}
	//cout << cur << endl;
	cur += plus;
  }
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to; ld cost;};

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

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

//dijkstra
//参考：http://nocotan.github.io/%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0/2017/01/26/dijkstra-copy.html

const long long MXV = 3000;//変更可
vector<edge> G[MXV];
vector<long double> d(MXV, INF);

void dijkstra(int s){
    priority_queue<pair<ld,int>, vector<pair<ld,int>>, greater<pair<ld,int>>> pq;
    d[s] = 0;
    pq.push(pair<ld,int>(0, s));
    while(pq.size()){
        pair<ld,int> p = pq.top();
        pq.pop();
        int V = p.second;
        if(d[V] < p.first){
            continue;
        }
        rep(i,G[V].size()){
            edge e = G[V][i];
            if(d[e.to] > d[V] + e.cost){
                d[e.to] = d[V] + e.cost;
                pq.push(pair<ld,int>(d[e.to], e.to));
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll xs,ys,xt,yt;
    cin >> xs >> ys >> xt >> yt;
    ll N;
    cin >> N;
    vector<pair<P,ll>> p(N);
    rep(i,N){
        cin >> p[i].first.first >> p[i].first.second >> p[i].second;
    }
    rep(i,N){
        rep(j,N){
            G[i].pb({j,max((ld)0,-((ld)p[i].second+p[j].second-(ld)sqrt((p[i].first.first-p[j].first.first)*(p[i].first.first-p[j].first.first)+(p[i].first.second-p[j].first.second)*(p[i].first.second-p[j].first.second))))});
            G[j].pb({i,max((ld)0,-((ld)p[i].second+p[j].second-(ld)sqrt((p[i].first.first-p[j].first.first)*(p[i].first.first-p[j].first.first)+(p[i].first.second-p[j].first.second)*(p[i].first.second-p[j].first.second))))});
        }
    }
    rep(i,N){
        G[N].pb({i,max((ld)0,-((ld)p[i].second-(ld)sqrt((p[i].first.first-xs)*(p[i].first.first-xs)+(p[i].first.second-ys)*(p[i].first.second-ys))))});
    }
    rep(i,N){
        G[i].pb({N+1,max((ld)0,-((ld)p[i].second-(ld)sqrt((p[i].first.first-xt)*(p[i].first.first-xt)+(p[i].first.second-yt)*(p[i].first.second-yt))))});
    }
    G[N].pb({N+1,(ld)sqrt((xs-xt)*(xs-xt)+(ys-yt)*(ys-yt))});
    dijkstra(N);
    cout << fixed << setprecision(20) << d[N+1] << '\n';
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/


Measured memory_bytes: 76336
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <set>
#define ll long long
using namespace std;


bool visited[222];
int pairr[222];

vector<int> edges[222];

bool match(int u)
{
    if(u==-1)
        return 1;
    for(int v : edges[u]) {
        if (visited[v])
            continue;
        visited[v]=1;
        if (match(pairr[v])) {
            pairr[v]=u;
            return 1;
        }
    }
    return 0;
}

int A[111];
int B[111];
int C[111];
int D[111];


int main() {
    int N;
    cin>>N;
    for(int i=0;i<N;i++) {
        cin>>A[i]>>B[i];
    }
    
    for(int i=0;i<N;i++)
        cin>>C[i]>>D[i];
    
    
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++) {
            if (A[i]<C[j] && B[i]<D[j]) {
                edges[i].push_back(N+j);
                edges[N+j].push_back(i);
            }
        }
    
    for(int i=0;i<2*N;i++)
        pairr[i]=-1;
    
    int currmatch=0;
    for(int i=0;i<N;i++) {
        for(int j=0;j<2*N;j++)
            visited[j]=false;
        if (match(i))
            currmatch++;
    }
    
    cout << currmatch << endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int W,H,div_row[4] = {-1,0,0,1},div_col[5] = {0,-1,1,0};

struct Info{
	Info(){
		eat_after = row = col = hp = time = 0;
	}

	void set(int arg_row,int arg_col,int arg_hp,int arg_time,int arg_eat_after){
		row = arg_row;
		col = arg_col;
		hp = arg_hp;
		time = arg_time;
		eat_after = arg_eat_after;
	}

	int row,col,hp,time,eat_after;
	short check[8][8];
};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

void func(){

	int map[H][W];
	int start_row,start_col,goal_row,goal_col;

	for(int i = 0; i < H; i++){
		for(int k = 0; k < W; k++){
			scanf("%d",&map[i][k]);
			if(map[i][k] == 2){
				start_row = i;
				start_col = k;
				map[i][k] = 1;
			}else if(map[i][k] == 3){
				goal_row = i;
				goal_col = k;
			}
		}
	}

	int ans = -1,limit = 2*H*W;
	queue<Info> Q;
	Info current;

	Info first;

	for(int i = 0; i < H; i++){
		for(int k = 0; k < W; k++)first.check[i][k] = 0;
	}

	first.check[start_row][start_col] = 1;
	first.set(start_row,start_col,6,0,3);

	Q.push(first);

	int debug = 0;
	while(!Q.empty()){
		current = Q.front();
		Q.pop();

		debug++;
		if(debug > 250000){
			break;
		}

		if(current.hp == 0)continue;

		if(map[current.row][current.col] == 3){
			ans = current.time;
			break;
		}else if(map[current.row][current.col] == 4){
			current.hp = 6;
			current.eat_after = 0;
		}

		if(current.time + abs(current.row-goal_row)+abs(current.col-goal_col) > limit)continue;

		for(int i = 0; i < 4; i++){
			if(rangeCheck(current.row+div_row[i],current.col+div_col[i]) == true && map[current.row+div_row[i]][current.col+div_col[i]] != 0 &&
					((current.check[current.row+div_row[i]][current.col+div_col[i]] == 0) || (current.check[current.row+div_row[i]][current.col+div_col[i]] == 1 &&	current.eat_after <= 1))){
				Info new_info;
				for(int a = 0; a < H; a++){
					for(int b = 0; b < W; b++){
						new_info.check[a][b] = current.check[a][b];
					}
				}
				new_info.check[current.row+div_row[i]][current.col+div_col[i]]++;
				new_info.set(current.row+div_row[i],current.col+div_col[i],current.hp-1,current.time+1,current.eat_after+1);
				Q.push(new_info);
			}
		}
	}
	printf("%d\n",ans);
}

int main(){

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 58864
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n,k,j;
	vector<int> a;
	cin>>n>>k;
	for (int i = 0; i < n; ++i)
	{
		cin>>j;
		a.push_back(j);

	}
	sort(all(a));
	int cnt=0;
	for (int i = n-1; i >= 0; --i)	{
		if(a[i]>=k){
		 cnt++;	
		}else{
			break;
		}
	}
	cout<<cnt;

   return 0;
}


Measured memory_bytes: 3892
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<unordered_map>
#include<map>
#include<cassert>
#include<deque>
#include<vector>
#include<random>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const long long inf = 1145141919810000;
typedef pair<int, int> P;
vector<P>V;
int nowh[200005];
signed main() {
	int h, w, n; cin >> h >> w >> n;
	rep(i, n) {
		int x, y; cin >> x >> y; V.push_back(P(x, y));
	}
	sort(V.begin(), V.end());
	V.push_back(P(inf, inf));
	nowh[1] = 1;
	int np = 0;
	for (int i = 2; i <= h; i++) {
		while (np < n&&V[np].first <= i) {
			if (V[np] == P(i, nowh[i - 1] + 1)) {
				nowh[i] = nowh[i - 1];
				goto X;
			}
			np++;
		}
		nowh[i] = nowh[i - 1] + 1;
		X:;
	}
	//rep(i, h)cout << nowh[i + 1] << endl;
	rep(i, n) {
		if (V[i].second <= nowh[V[i].first]) {
			cout << V[i].first - 1 << endl;
			return 0;
		}
	}
	cout << h << endl;
}


Measured memory_bytes: 6256
#include<cstdio>

#define gec     getchar
#define FILE(F) freopen(F".in","r",stdin),freopen(F".out","w",stdout)
#define DEBUG   fprintf(stderr,"Passing [%s] in Line (%d)\n",__FUNCTION__,__LINE__)

typedef long long ll;
template<typename T>
inline void read(T &x)
{
	x=0;bool f=0; char c=gec();
	for(;c<'0'||c>'9';c=gec())f=(c=='-');
	for(;c>='0'&&c<='9';c=gec())x=x*10+c-'0';
	x=f?-x:x;
}

const int MAXN(100010),MP(1e9+7);
int n,a[MAXN],col[MAXN];
int last,now,Ans;


int fac[MAXN],inv[MAXN];

void Deal(int n)
{
	fac[0]=inv[1]=inv[0]=1;
	for(int i=1;i<=n;i++)fac[i]=(ll)fac[i-1]*i%MP;
	for(int i=2;i<=n;i++)inv[i]=(MP-MP/i)*(ll)inv[MP%i]%MP;
	for(int i=2;i<=n;i++)inv[i]=(ll)inv[i]*inv[i-1]%MP;
}
void dec(int &x,int y){x-=y;x+=x<0?MP:0;}
int C(int n,int m)
{
	return (n>=m&&(n>0)&&(m>0))?(ll)fac[n]*inv[n-m]%MP*(ll)inv[m]%MP:0;
}

int main()
{
	read(n);Deal(n+1);
	for(int i=1;i<=n+1;i++)
	{
		read(a[i]);
		if(col[a[i]])last=col[a[i]],now=i;
		col[a[i]]=i;
	}
	for(int i=1;i<=n+1;i++)
	{
		Ans=C(n+1,i);if(i==1)dec(Ans,1);
		dec(Ans,C(last-1+n+1-now,i-1));
		printf("%d\n",Ans);
	}
	return 0;
}	

Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
#include <string>
#include <cmath>

using namespace std;

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

int lcm(int a, int b){
    return a * b / gcd(a,b);
}

int main(){
    int N;
    int a[3000];
    int max = 0;

    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    int f = 0;
    for (int j = 0; j < N; j++){
        f += a[j] - 1;
    }
    cout << f << endl;
}


Measured memory_bytes: 256
import heapq


def dijkstra(s, edge):
    # 始点sから各頂点への最短距離
    dist = [10**20] * N
    used = [False] * N
    dist[s] = 0
    used[s] = True
    edgelist = []
    for a, b in edge[s]:
        # a : 距離, b : 頂点番号
        heapq.heappush(edgelist, a * (10**6) + b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        # まだ使われてない頂点の中から最小の距離のものを探す
        if used[minedge % (10**6)]:
            continue
        v = minedge % (10**6)
        dist[v] = minedge//(10**6)
        used[v] = True
        for e in edge[v]:
            if not used[e[1]]:
                heapq.heappush(edgelist, (e[0]+dist[v])*(10**6)+e[1])
    return dist


N, M, r = map(int, input().split())
graph = [list(map(int, input().split())) for _ in range(M)]
edge = [[] for _ in range(N)]
for i in graph:
    edge[i[0]].append([i[2], i[1]])

dist = dijkstra(r, edge)
for i in range(N):
    if dist[i] == 10**20:
        print("INF")
    else:
        print(dist[i])


Measured memory_bytes: 171984
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N =scan.nextInt();
        long[] a = new long[N];
        for(int i=0;i<N;++i)a[i]=scan.nextLong();
        long[] xor = new long[N+1];
        long[] sum = new long[N+1];
        for(int i=0;i<N;++i){
            xor[i+1] = xor[i]^a[i];
            sum[i+1] = sum[i]+a[i];
        }
        long ans = 0;
        for(int i=1;i<=N;++i){
            int left=i,right=N+1;
            while(right-left>1){
                int center=(left+right)/2;
                if((xor[center]^xor[i-1]) == (sum[center]-sum[i-1]))left=center;
                else right=center;
            }
            ans += (long)(right-i);
        }
        System.out.println(ans);
    }
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll mod = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int K, N;
    cin >> K >> N;
    VI V(N);
    REP(i, N) cin >> V[i];
    int mn = INT_MAX;
    REP(i, N) {
    	// int d = V[i] - V[(i + N - 1) % N] + K;
    	int d, p;
    	p = (i + N - 1) % N;
    	if (i > p) {
    		d = V[i] - V[p];
    	} else {
    		d = V[i] + K - V[p];
    	}
    	mn = min(mn, K - d);
    }
    cout << mn << endl;

}

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

using namespace std;

#define MAX 150

int main()
{
    int N, M;
    while (cin >> N >> M, N) {
        double g[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                cin >> g[i][j];
            }
        }
        
        double dp[MAX][MAX];
        for (int i = 0; i < MAX; i++) {            
            for (int j = 0; j < MAX; j++) {
                dp[i][j] = (j == 0 ? 1 : 0);
            }
        }

        for (int i = 0; i < M-1; i++) {
            for (int j = 0; j < N; j++) {                
                for (int k = 0; k < N; k++) {
                    dp[k][i+1] = max(dp[k][i+1],
                                       dp[j][i] * g[j][k]);
                }
            }
        }
        
        double res = 0;
        for (int i = 0; i < N; i++) {
            res = max(res, dp[i][M-1]);
        }
        printf("%.2f\n", res);
    }
    return 0;
}

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

//Compiler version g++ 6.3.0

int main()
{
  int n;
  cin >> n;
  int c[1000000];
  memset(c,0,sizeof(c));
  for(int i = 1; i < n; i++){
    int x; cin >> x;
    c[x]++;
  }
  for(int i = 1; i <= n; i++){
    cout << c[i] << "\n";
  }
  return 0;
}

Measured memory_bytes: 7540
def findTrailingZeros(n): 
      
    if (n%2!=0): 
        return 0

    else: 
        ans = 0
        n //= 2
        while (n): 
            ans += n // 5
            n //= 5
  
        return ans 
  
n = int(input())
  
print(findTrailingZeros(n)) 

Measured memory_bytes: 2940
#include <iostream>
#include <vector>

std::vector<std::vector<int> > table;

int main() {
  std::vector<int> a(3);
  std::vector<int> b(3);
  table.resize(3);
  for (int i = 0; i < 3; i++) table[i].resize(3);

  for (int j = 0; j < 3; j++) {
    for (int i = 0; i < 3; i++) {
      std::cin >> table[j][i];
    }
  }

  a[0] = 0;
  for (int i = 0; i < 3; i++)
    b[i] = table[0][i];
  for (int j = 1; j < 3; j++) {
    a[j] = table[j][0] - b[0];
  }

  bool yes = true;
  for (int j = 0; j < 3; j++) {
    for (int i = 0; i < 3; i++) {
      if (table[j][i] != (a[j] + b[i])) {
        yes = false;
        break;
      }
    }
    if (!yes) break;
  }
  
  std::cout << ((yes) ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  bool success = false;
  for (int i = 9; i >= 1; i--)
  {
    if (n % i == 0)
    {
      if (n / i < 10)
      {
        success = true;
      }
    }
  }

  if (success)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
// Macros for easier access
#define ll long long
#define endl '\n'
#define F first
#define S second
#define umap unordered_map
#define uset unordered_set
#define test ll cases; cin>>cases; for(ll testCase = 1; testCase <= cases; testCase++)   //test cases
#define fill(name, val) memset(name, val, sizeof(name));
#define mop(a, op, b)    (a%mod op b%mod)%mod
#define error(x) fixed<<setprecision(x) //cout<<error(5)<<someDouble    -> example - 3.14159
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define get(a, n)    for(ll i = 0; i < n; i++)    cin>>a[i];
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cerr << #x << " : " << (x) << endl
// Constants
#define MX 100001
#define mod 1000000007LL
#define inf 1000000000000000000LL
void init(){
	boost;
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

int main(){
	init();
	ll d, t, s;	cin>>d>>t>>s;
	cout<<(s*t >= d ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
    int x, y, z, w, u;
    w = 0,u = 0; 
    cin >> x >> y >> z;
    while(true){
        u += 1;
        w += x;
        if(u%7 == 0){
           w += y;
        }
        if (w >= z){
           break;
        }
    }
    cout << u <<endl;
}



Measured memory_bytes: 3084
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x7fffffff
#define N 200005
int n;
long long cnt,a,b,minb=INF;
bool f=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a,&b);
		cnt+=b;
		if(b<a&&minb>b)
		minb=b;
		if(b!=a) f=1; 
	}
	if(f)printf("%lld\n",cnt-minb);
	else printf("0\n");
}

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

int main()
{
    long long int n,k=5,aans=0;cin>>n;
    long long int ans=(n/2);
    long long int s=ans/k;

    if(n%2!=0) cout<<0;
    else {
    while(s>0){
        aans+=(ans/k);
        k*=5;
        s=(ans/k);
    }
    cout<<aans;
    }
	return 0;
}


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

order = [-1 for i in range(N)]
order[0] = 0
path = [1]

cnt = 1
before = 1
roop_start = -1
while True:
	nxt = A[before - 1]
	if order[nxt - 1] >= 0:
		roop_start = order[nxt - 1]
		break
	order[nxt - 1] = cnt
	path.append(nxt)
	cnt += 1
	before = nxt

L = len(path)
T = L - roop_start

if K < L:
	print(path[K])
	exit()

K -= roop_start
print(path[roop_start + K % T])

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

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& vec) {
    out << "[";
    for (int x : vec) out << x << ", ";
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
    #define dbg_var(x) cerr << #x << ": " << x << endl;
#endif

LL A, B, C, D;
map<LL,LL> mem;
LL solve(LL N){
    if(N == 0) return 0;
    if(N == 1) return D;
    if(mem.count(N)) return mem[N];
    LL ans;
    
    if(N % 2 == 0){
        ans = A + solve(N/2);
    }else{
        ans = D + A + min(solve(N/2), solve(N/2+1));
    }
    
    LL k = N%3;
    ans = min(ans, D*k + B + solve(N/3));
    if(k > 0 and N/3 + 1 < N) ans = min(ans, D*(3-k) + B + solve(N/3 + 1));
    
    k = N%5;
    ans = min(ans, D*k + C + solve(N/5));
    if(k > 0 and N/5 + 1 < N) ans = min(ans, D*(5-k) + C + solve(N/5 + 1));
    
    if((double)N * (double)D < 2 * (double)ans) ans = min(ans, N * D);
    
    //~ cerr << N << ' ' << ans << endl;
    
    return mem[N] = ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int T;
    cin >> T;
    for(int tt=1; tt<=T; tt++){
        LL N;
        cin >> N >> A >> B >> C >> D;
        mem.clear();
        LL ans = solve(N);
        cout << ans << '\n';
    }
    
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<ll> a(n);
	int neg = 0;
	for(int i = 0; i < n; i++){
		cin>>a[i];
		if(a[i] < 0)neg++;
		a[i] = abs(a[i]);
	}
	sort(a.begin(), a.end());
	ll sum = accumulate(a.begin(), a.end(), 0LL);
	if(neg&1)cout<<sum - 2*a[0]<<'\n';
	else cout<<sum<<'\n';

	return 0;
}

Measured memory_bytes: 1024
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 10000 + 20 ;
int n , a[N] , b[N] , c[N] , w ;

int32_t main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;

	cin >> n ;
	for (int i = 0 ; i < n ; i ++) cin >> a[i] , c[i] += a[i] ;
	for (int i = 0 ; i < n ; i ++) cin >> b[i] , c[i] -= b[i] ;

	for (int i = 0 ; i < n ; i ++) {
		if (c[i] < 0) w += abs(c[i]) / 2 ;
		else w -= c[i] ;
	}

	cout << (w >= 0 ? "Yes" : "No") << '\n' ;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
const long long INF = 1LL << 60;
using namespace std;
//0:41
int main(int argc, char const *argv[])
{
    int n, z, w;
    cin >> n >> z >> w;
    int a[n];
    rep(i, n) cin >> a[i];
    ll dp[n][2];
    for (int i = n - 1; i >= 0; i--)
    {
        int y = (i == 0) ? w : a[i - 1];
        dp[i][0] = -INF;
        dp[i][0] = max(dp[i][0], llabs(a[n - 1] - y));
        rep(j, i + 1, n)
        {
            dp[i][0] = max(dp[i][0], dp[j][1]);
        }
        y = (i == 0) ? z : a[i - 1];
        dp[i][1] = INF;
        dp[i][1] = min(dp[i][1], llabs(a[n - 1] - y));
        rep(j, i + 1, n)
        {
            dp[i][1] = min(dp[i][1], dp[j][0]);
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
list($n) = ints();
$a = ints();
rsort($a);
$t = [];
for ($i = 0; $i < $n; ++$i) {
    $t[] = $a[$i];
    if (count($t) === $n - 1) break;
    if ($i > 0) $t[] = $a[$i];
    if (count($t) === $n - 1) break;
}
echo array_sum($t);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 39140
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

class UnionFind {
private:
	vector<int> data;
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }

public:
	UnionFind(int size) : data(size, -1) { }
	bool is_same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -data[root(x)]; }

	void unify(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
};

template<class T = lint>
struct Edge {
	int from, to;
	T cost;
	Edge() {}
	Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

int main() {

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

	int N;
	cin >> N;

	struct town { int x, y, idx; };
	vector<town> t(N);
	for (int i = 0; i < N; i++) {
		cin >> t[i].x >> t[i].y;
		t[i].idx = i;
	}

	// 辺の候補をすべてpriority_queに入れる
	priority_queue<Edge<>, vector<Edge<>>, greater<Edge<>>> pq;
	// xが近い同士
	sort(t.begin(), t.end(), [&](town r, town l) {return r.x < l.x; });
	for (int i = 0; i < N - 1; i++) pq.emplace(t[i].idx, t[i + 1].idx, t[i + 1].x - t[i].x);
	// yが近い同士
	sort(t.begin(), t.end(), [&](town r, town l) {return r.y < l.y; });
	for (int i = 0; i < N - 1; i++) pq.emplace(t[i].idx, t[i + 1].idx, t[i + 1].y - t[i].y);

	// kruskal法
	UnionFind uf(N);
	lint ans = 0;
	while (!pq.empty()) {
		
		auto now = pq.top(); pq.pop();

		if (!uf.is_same(now.from, now.to)) {
			uf.unify(now.from, now.to);
			ans += now.cost;
		}
	
	}

	assert(uf.size(0) == N);

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 7664
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a, b;
	cin >> n >> a >> b;
	rep(i,100000){
		if(i%2 == 0){
			if(a+1 < b) ++a;
			else --a;
			if(a < 1){
				cout << "Borys" << endl;
				return 0;
			}
		}
		else{
			if(b-1 > a) --b;
			else ++b;
			if(n < b){
				cout << "Alice" << endl;
				return 0;
			}
		}
	}
	cout << "Draw" << endl;
	return 0;
}

Measured memory_bytes: 3592
//#pragma warning(disable:4996)
#include <stdio.h>

bool equal(char *a, char *b) {
	bool j = true;
	for (int i = 0; i < 12; i++) {
		if (a[i] != b[i]) {
			j = false;
		}
	}
	return j;
}

int main() {
	int n, m;
	char s[100][12] = {};
	char t[100][12] = {};
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", s[i]);
	}
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		scanf("%s", t[i]);
	}

	int max = 0;
	for (int i = 0; i< n; i++) {
		int point = 0;
		for (int j = 0; j < n; j++) {
			if (equal(s[i], s[j])) {
				point++;
			}
		}
		for (int j = 0; j < m; j++) {
			if (equal(s[i], t[j])) {
				point--;
			}
		}
		if (max < point) {
			max = point;
		}
	}
	printf("%d\n", max);
	//while (1);
}

Measured memory_bytes: 128
using System;
 
namespace aizu
{
    class OnlineJudge
    {
        const int Max = 50022;
        static void Main()
        {
            bool[] check = new bool[Max];
            for(int i=2; i < Max; i += 1 + (i & 1)) {
                if(!check[i]) {
                    if(i <= 223) {
                        for(int l=i; i * l < Max; ++l) {
                            check[i * l] = true;
                        }
                    }
                }
            }
            string input;
            while((input = Console.ReadLine()) != null) {
                int val = int.Parse(input);
                int big = 0, small = 0;
                for(int i=1; i < Max >> 1; i = i + 1 + ((val + i) & 1)) {
                    if(big == 0 && !check[val + i]) {
                        big = val + i;
                    }
                    if(small == 0 && !check[val - i]) {
                        small = val - i;
                    }
                    if((big & small) != 0) {
                        break;
                    }
                }
                Console.WriteLine("{0} {1}", small, big);
            }
        }
    }
}

Measured memory_bytes: 5616