akhauriyash/Code-Regression huggingface dataset:
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.ByteString.Char8 as B
import Data.Char
import Control.Monad

put :: Int -> IO ()
put s = (Prelude.putStr $ show s) >> Prelude.putStr " "

solve vec n 
    | even n = do
        VU.forM_ (VU.reverse $ VU.fromList [1,3..n-1]) $ \i -> VUM.read vec i >>= put
        VU.forM_ (VU.fromList [0,2..n-2]) $ \i -> VUM.read vec i >>= put
        Prelude.putStrLn ""
    | otherwise = do
        VU.forM_ (VU.reverse $ VU.fromList [0,2..n-1]) $ \i -> VUM.read vec i >>= put
        VU.forM_ (VU.fromList [1,3..n-2]) $ \i -> VUM.read vec i >>= put
        Prelude.putStrLn ""

main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    xs' <- VU.unsafeThaw xs
    solve xs' n

Measured memory_bytes: 11516
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);
 
 		String s =fr.next() ,t =fr.next() ;	int i ;
 		if (s.length()+1 == t.length()) {
 			for (i =0 ; i<s.length() ; ++i) {
 				if (s.charAt(i)!=t.charAt(i))	break;
 			}
 			if (i==s.length())	op.println("Yes") ;
 			else 	op.println("No") ;
 		}
 		else 	op.println("No") ;
		op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br =new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st==null || (!st.hasMoreElements())) 
			{
				try
				{
					st =new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}
				
			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}

Measured memory_bytes: 32836
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}
ll mp = 10000, A, B, C, n;
vector<ll> L;
void use_take(ll index, ll a, ll b, ll c, ll mix_num){
  if(index == n && a!=0 && b!=0 && c!=0){
    mp = min(mp, abs(a-A)+abs(b-B)+abs(c-C)+10*mix_num);
  }else if(index < n){
  	use_take(index+1, a, b, c, mix_num);
  	use_take(index+1, a+L[index], b, c, a==0?mix_num:mix_num+1);
  	use_take(index+1, a, b+L[index], c, b==0?mix_num:mix_num+1);
  	use_take(index+1, a, b, c+L[index], c==0?mix_num:mix_num+1);
  }
}
int main(void)
{
  cin >> n >> A >> B >> C;
  L.resize(n);
  RAP(i, n){
    cin >> L[i];
  }
  use_take(0, 0, 0, 0, 0);
  cout << mp << endl;
}


Measured memory_bytes: 256
<?php 
	$s = explode(' ', trim(fgets(STDIN)));
	$ans = "Yes";
	if($s[0]==$s[1] && $s[0]==$s[2]){
    	$ans  = "No";
    }elseif($s[0]!=$s[1] && $s[0]!=$s[2] && $s[1]!=$s[2]){
    	$ans  = "No";
    }
	echo $ans;
?>

Measured memory_bytes: 4604
//要するに周りの数
#include <iostream>
using namespace std;
int main(){
  long long n,m;cin>>n>>m;
  if(n==1||m==1){
    if(n==1&&m==1){
      cout << 1 << endl;
      return 0;
    }
    cout << (long long)n+m-1-2 << endl;
    return 0;
  }else{
	cout << (long long)(n-2)*(m-2) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
        int N,x;
        cin >> N >> x;
        int a[100010];
        int prev;long long int counter=0;
        cin >> a[0];prev=a[0];
        for(int i=1 ; i<=N ; i++ ){
                if(i==N)
                        a[i]=0;
                else
                        cin >> a[i];
                if(prev+a[i]>x){
                        int s=a[i];
                        a[i]=x-prev;
                        if(a[i]<0){
                                counter+=a[i-1]-x;
                                a[i-1]=x;
                                a[i]=0;
                        }
                        counter+=s-a[i];
                }
                prev=a[i];
        }
        cout << counter << endl;
        return 0;
}

Measured memory_bytes: 640
n = int(input())
l = [int(i) for i in input().split()]

flg = True
for i in l:
    if i % 2:
        pass
    elif i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    else:
        flg = False
        break
    
print('APPROVED' if flg else 'DENIED')

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

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

int main(){
  string s;
  cin >> s;

  int n = s.size();
  vector<int> ans(n);
  vector<vector<int>> final(n, vector<int>(2,-1)); //最終到達地 偶奇

  //何回目・誰
  vector<vector<int>> road(n,vector<int>(2,-1));
  
  rep(i,n){
    int step=i; //現在地
    rep(j,n+1){
      int last = road.at(step).at(1);
      if(last!=-1){ //既に来た人がいる
        if(last!=i){ //自分でないならば
          if((abs(j-road.at(step).at(0)))%2){
            final.at(i).at(0) = final.at(last).at(1);
            final.at(i).at(1) = final.at(last).at(0);
          }else{
            final.at(i).at(0) = final.at(last).at(0);
            final.at(i).at(1) = final.at(last).at(1);
          }
        }else{ //自分ならば
          if(j%2){
            if(s.at(step)=='L')final.at(i).at(0) = step-1;
            else final.at(i).at(0) = step+1;
            final.at(i).at(1) = step;
          }else{
            if(s.at(step)=='L')final.at(i).at(1) = step-1;
            else final.at(i).at(1) = step+1;
            final.at(i).at(0) = step;
          }
        }
        break;
      }else{ //まだ誰も来ていない
        road.at(step).at(0)=j; //j回目に
        road.at(step).at(1)=i; //自分が到達
        if(s.at(step)=='R') step++;
        else if(s.at(step)=='L') step--;
      }
      //cout << i << ":" << j << endl;
    }
    //cout << i << "done" << endl;
  }

  //rep(i,n) cout << final.at(i).at(0) << " ";
  rep(i,n) ans.at(final.at(i).at(0))++;
  rep(i,n) cout << ans.at(i) << " ";
  
}

Measured memory_bytes: 14584
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
ll n,a[200005],res[200005],t[800005];
vector<vector<ll>> g(200005);
void update(ll v,ll tl,ll tr,ll pos,ll val){
	if(tl==tr){
		t[v]=val;
		return;
	}
	ll tm=(tl+tr)/2;
	if(pos<=tm)
	update(2*v,tl,tm,pos,val);
	else
	update(2*v+1,tm+1,tr,pos,val);
	t[v]=max(t[2*v],t[2*v+1]);
}
ll query(ll v,ll tl,ll tr,ll l,ll r){
	if(l>r)
	return 0;
	if(l==tl&&r==tr)
	return t[v];
	ll tm=(tl+tr)/2;
	return max(query(2*v,tl,tm,l,min(r,tm)),query(2*v+1,tm+1,tr,max(l,tm+1),r));
}
void dfs(ll i,ll p,vector<vector<ll>> &v){
	res[i]=res[p];
	ll q=0;
	if(a[i]>1)
	q=query(1,1,n,1,a[i]-1);
	res[i]=max(res[i],q+1);
	update(1,1,n,a[i],q+1);
    g[a[i]].push_back(q+1);
	for(ll j=0;j<ll(v[i].size());j++)
	if(v[i][j]!=p)
	dfs(v[i][j],i,v);
	g[a[i]].pop_back();
	ll val=0;
	if(!g[a[i]].empty())
	val=g[a[i]].back();
	update(1,1,n,a[i],val);
}
void solve(){
	cin>>n;
	vector<vector<ll>> v(n+1);
	vector<p2> val;
	for(ll i=1;i<=n;i++){
		ll x;
		cin>>x;
		val.push_back({x,i});
	}
	sort(val.begin(),val.end());
	ll cur=1;
	for(ll i=0;i<n;i++){
		if(i>0&&val[i].first!=val[i-1].first)
		cur++;
		a[val[i].second]=cur;
	}
	for(ll i=0;i<n-1;i++){
		ll x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1,0,v);
	for(ll i=1;i<=n;i++)
	cout<<res[i]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


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

ll N;

int main() {
    cin >> N;

    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    vector<ll> sum_a(N);
    sum_a[0] = a[0];
    for (ll i = 1; i < N; i++) {
        sum_a[i] += sum_a[i - 1] + a[i];
    }

    // for (int i = 0; i < N; i++) {
    //     cout << sum_a[i] << endl;
    // }

    // + - + - のパターン
    ll counter = 0;
    ll ans1 = 0;
    for (ll i = 0; i < N; i++) {
        ll diff = 0;
        if (i % 2 == 0) {
            if (counter + sum_a[i] <= 0) {
                // 足す
                diff = abs(counter + sum_a[i]) + 1;
            }
        } else {
            if (counter + sum_a[i] >= 0) {
                // マイナス
                diff = abs(counter + sum_a[i]) + 1;
            }
        }

        if (i % 2 == 0) {
            counter += diff;
        } else {
            counter -= diff;
        }

        ans1 += diff;
        // printf("i: %d ans1: %d diff %d counter: %d sum: %d\n", i, ans1, diff, counter, sum_a[i]);
    }
    // cout << ans1 << endl; 

    // - + - + のパターン
    ll counter2 = 0;
    ll ans2 = 0;
    for (ll i = 0; i < N; i++) {
        ll diff2 = 0;
        if (i % 2 == 1) {
            if (counter2 + sum_a[i] <= 0) {
                diff2 = abs(counter2 + sum_a[i]) + 1;
            }
        } else {
            if (counter2 + sum_a[i] >= 0) {
                diff2 = abs(counter2 + sum_a[i]) + 1;
            }
        }

        if (i % 2 == 1) {
            counter2 += diff2;
        } else {
            counter2 -= diff2;
        }

        ans2 += diff2;
        // printf("i: %d ans1: %d diff %d counter: %d sum: %d\n", i, ans1, diff, counter, sum_a[i]);
    }
    // cout << ans1 << endl;
    // cout << ans2 << endl;

    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 1792
def sum(i):
  t=0
  while True:
    if i==0:
      return t
    else:
      t +=i%10
      i //=10
      
N,A,B = [int(i) for i in input().split()]
s = 0

for i in range(1, N+1):
  if sum(i) <=B and sum(i) >=A:
    s += i
print(s)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;

void solve() {
	cin >> N;
	cout << 180 * N - 360 << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 384
import std.stdio,std.conv,std.string,std.algorithm,std.array;
void main(){
  auto sn=readln().split();
  auto sa=readln().split();
  int n,a;
  n=to!int(sn[0]);
  a=to!int(sa[0]);
  if(n%500<=a) writeln("Yes");
  else writeln("No");
}

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

def prime_factor(n):
    res = {}
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            res[i] = res.get(i, 0) + 1
            n //= i
    if n != 1:
        res[n] = 1
    return res
            
ans = 1
for k, v in prime_factor(P).items():
    while v >= N:
        ans *= k
        v -= N

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#define N 100000

int partition(int,int);

int A[N];		    

int partition(p,r)
{
  int i,j,x,tmp;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  
  return i+1;
}

int main()
{
  int n,i,h;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  h = partition(0,n-1);
  for(i=0;i<n-1;i++){
    if(i==h) printf("[%d] ",A[i]);
    else printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  return 0;
}




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

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

int main() {
  vector<int> c(3 * 3);
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i * 3 + j);
    }
  }
  vector<bool> flag(3, false);
  bool ans = false;
  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 101; j++) {
      for (int k = 0; k < 101; k++) {
        if (((c.at(0 * 3 + 0) - i == c.at(0 * 3 + 1) - j) &&
             (c.at(0 * 3 + 1) - j == c.at(0 * 3 + 2) - k)) &&
            ((c.at(1 * 3 + 0) - i == c.at(1 * 3 + 1) - j) &&
             (c.at(1 * 3 + 1) - j == c.at(1 * 3 + 2) - k)) &&
            ((c.at(2 * 3 + 0) - i == c.at(2 * 3 + 1) - j) &&
             (c.at(2 * 3 + 1) - j == c.at(2 * 3 + 2) - k))) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
  n, k = map(int, input().split())
  T = [[] for _ in range(n)]
  E = []
  for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))
  d = k//2
  def dfs(vs):
    dist = [-1]*n
    stack = []
    cnt = 0
    for v in vs:
      stack.append(v)
      dist[v] = 0
    while stack:
      v = stack.pop()
      for nv in T[v]:
        if dist[nv] == -1:
          dist[nv] = dist[v] + 1
          if dist[nv] > d:
            cnt += 1
          stack.append(nv)
    return cnt
  ans = n
  if k%2 == 0:
    for i in range(n):
      ans = min(ans, dfs([i]))
  else:
    for l in E:
      ans = min(ans, dfs(l))
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 45020
#include<stdio.h>

#define N 50

int fib(int);
int F[N];

int main(){
  int n;
  scanf("%d",&n);
  printf("%d\n",fib(n));
  return 0;
}
int fib(int n){
  if(n==0 || n==1)
    return 1;
  if(F[n]!=0)
    return F[n];
  return F[n]=fib(n-1)+fib(n-2);
}



Measured memory_bytes: 2052
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;

int main(){
  int w,h,n,x,y,a,i,j,k,s;
  cin >> w >> h >> n;
  s = w*h;
  int t[w][h] = {};
  for(i = 0; i < n; i++){
    cin >> x >> y >> a;
    if(a == 1){
      for(j = 0; j < x; j++){
        for(k = 0; k < h; k++){
          t[j][k] = 1;
        }
      }
    }else if(a == 2){
      for(j = w - 1; j >= x; j--){
        for(k = 0; k < h; k++){
          t[j][k] = 1;
        }
      }
    }else if(a == 3){
      for(j = 0; j < w; j++){
        for(k = 0; k < y; k++){
          t[j][k] = 1;
        }
      }
    }else if(a == 4){
      for(j = 0; j < w; j++){
        for(k = h - 1; k >= y; k--){
          t[j][k] = 1;
        }
      }
    }
  }
    for(j = 0; j < w; j++){
      for(k = 0; k < h; k++){
        if(t[j][k] == 1){
          s = s - 1;
      }
    }
  }
  cout << s;
}


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

template <int64_t N>
class modint {
    int64_t x;
public:
    modint(int64_t x = 0) : x((x % N + N) % N) {}
    modint operator-() const { return modint(-x); }
    modint& operator+=(const modint& a) { if ((x += a.x) >= N) x -= N; return *this; }
    modint& operator-=(const modint& a) { if ((x += N - a.x) >= N) x -= N; return *this; }
    modint& operator*=(const  modint& a) { (x *= a.x) %= N; return *this; }
    modint operator+(const modint& a) const { return modint(*this) += a; }
    modint operator-(const modint& a) const { return modint(*this) -= a; }
    modint operator*(const modint& a) const { return modint(*this) *= a; }
    modint pow(int64_t t) const {
        if (not t) return 1;
        modint a = pow(t >> 1); a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    modint inv() const { return pow(N - 2); }
    modint& operator/=(const modint& a) { return (*this) *= a.inv(); }
    modint operator/(const modint& a) const { return modint(*this) /= a; }
    friend ostream& operator<<(ostream& os, const modint& m){ os << m.x; return os; }
};
const int64_t mod = 998244353;
using mint = modint<mod>;

int main(){
    int n; cin >> n;
    vector<int> d(n); map<int, int> cnt;
    for (auto i = 0; i < n; i++) {
        cin >> d[i]; cnt[d[i]]++;
        if(i == 0 and d[i] != 0) { cout << 0 << endl; return 0; }
        if(i != 0 and d[i] == 0) { cout << 0 << endl; return 0; }
    }
    mint ans = 1; pair<int, int> prev = {0, 0};
    for (auto & elm : cnt) {
        if(elm.first == 0) continue;
        if(prev.first + 1 < elm.first) { cout << 0 << endl; return 0; }
        if(elm.first > 1) ans *= mint(prev.second).pow(elm.second);
        // cout << elm.first << " " << elm.second << " " << prev << " " << ans << endl;
        prev = elm;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8152
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 string s,t ; cin>>s>>t  ; 
  cout<< t<<s <<endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
using Graph = vector< vector<int> >;

int dfs(Graph &G, int cur, int par=-1) {
    int grundy = 0, children = 0;
    for(auto to : G[cur]) {
        if(to == par) continue;
        children++;
        grundy ^= dfs(G, to, cur) + 1;
    }
    // printf("cur = %d, grundy = %d\n", cur + 1, grundy);
    return grundy;
}

int main() {
    int N; scanf("%d", &N);
    Graph G(N);
    for(int i=0; i<N-1; i++) {
        int u, v; scanf("%d%d", &u, &v);
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    printf("%s\n", dfs(G, 0) ? "Alice" : "Bob");
    return 0;
}

Measured memory_bytes: 11904
import sys
from collections import Counter
N=int(input())
S=['']*N
for i in range(N):
    S[i]=input()
counter = Counter(S)
ans=[0]*len(counter)
num=0
for word, cnt in counter.most_common():
    ans[num]=cnt
    num+=1
anker=ans[0]
ankernum=0
for j in range(len(counter)):
    if ans[j]!=anker:
        ankernum=j
        break
    elif j==len(counter)-1:
        ankernum=j+1
word_ans=['']*len(counter)
k=0
for word, cnt in counter.most_common():
    word_ans[k]=word
    k+=1

for l in sorted(word_ans[:ankernum]):
    print(l)

Measured memory_bytes: 48348
#include <iostream>
#include <vector>
// #include <algorithm>
// #include <set>
// #include <cmath>
// #include <string>

using namespace std;
typedef unsigned long long ull;

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

int main(int argc, char const *argv[]) {
    int K;
    cin >> K;

    int ans = 0;
    for (int a = 1; a <= K; a++) {
        for (int b = a+1; b <= K; b++) {
            for (int c = b+1; c <= K; c++) {
                ans += gcd(gcd(a, b), c) * 6;
            }
        }
    }
    for (int a = 1; a <= K; a++) {
        for (int b = a+1; b <= K; b++) {
            ans += gcd(a, b) * 6;
        }
    }
    for (int a = 1; a <= K; a++) {
        ans += a;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>

int main() {
	int a, b, c;
	int flag = 0;

	scanf("%d %d %d", &a, &b, &c);

	if (a == b)flag++;
	if (b == c)flag++;
	if (c == a)flag++;

	if (flag == 3)printf("%d\n", 1);
	else printf("%d\n", 3 - flag);
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int a,b,c;
  c = N % 10;
  b = (N % 100)/10;
  a = N / 100;
  if (a == 7 || b == 7 || c == 7)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
 
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;


int main() {
    int H, W;
    while (cin >> H >> W, H) {
        string field[10];
        for (int i = 0; i < H; i++) {
            cin >> field[i];
        }

        vector<string> cand;
        for (int y = 0; y < H; y++) {
            for (int x = 0; x < W; x++) {
                for (int dx = -1; dx <= 1; dx++) {
                    for (int dy = -1; dy <= +1; dy++) {
                        if (dx == 0 && dy == 0) continue;
                        bool visited[15][25] = { 0 };
                        int nx = x, ny = y;
                        string spell;
                        while (!visited[ny][nx]) {
                            visited[ny][nx] = true;
                            spell += field[ny][nx];
                            cand.push_back(spell);
                            nx = (nx + dx + W) % W;
                            ny = (ny + dy + H) % H;
                        }
                    }
                }
            }
        }
        
        string ans = "";
        sort(cand.begin(), cand.end());
        for (int i = 1; i < (int)cand.size(); ++i) {
            if (cand[i].size() == 1) continue;
            if (cand[i] != cand[i - 1]) continue;
            if (ans.size() < cand[i].size() || ans > cand[i]) {
                ans = cand[i];
            }
        }
        if (ans == "") ans = "0";
        cout << ans << endl;
    }
}

Measured memory_bytes: 30512
#include <stdio.h>

int main(void) {
	int n,a;
	scanf("%d",&n);
  a=n;
	char s[n];
	for(int i=0;i<n;i++){
      scanf("%s",&s[i]);
    }
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
      a--;
    }
  }
    printf("%d",a);
    
  
  
	// your code goes here
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int cnt;
void BubbleSort(int A[], int N){
    bool flag = true;
    while(flag){
        flag = false;
        for(int j = N-1; j >= 1; j--){
            if(A[j] < A[j-1]){
                swap(A[j], A[j-1]);
                cnt++;
                flag = true;
            }
        }
    }
}
 
int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    cnt = 0;
    BubbleSort(A, N);
    for(int i = 0; i < N; i++){
        cout << A[i];
        if(i < N-1)
            cout << " ";
        else
            cout << endl;
    }
    cout<< cnt << endl;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
N = int(input())
B = list(map(int, input().split()))
ans = B[0] + B[-1]
Atmp = 0
for i in range(N - 2):
    Atmp = B[i]

    if Atmp > B[i + 1]:
        ans += B[i + 1]
    else:
        ans += Atmp

print(ans)


Measured memory_bytes: 2940
import itertools

N,M,X=map(int, input().split())
data=[]
ans=999999999
b=[]
b_pairs=[]
for i in range(N):
    b.append(i)
for i in range(N):
    data.append(list(map(int, input().split())))

for i in range(2,N+1):
    b_pairs+=itertools.combinations(b,i)

for i in range(N):
    flag=1
    skill=[0]*M
    for j in range(M):
        skill[j]+=data[i][j+1]
    for j in range(M):
        if skill[j]<X:
            flag=0
    if flag==1:
        ans=min(ans,data[i][0])

for i in range(len(b_pairs)):
    skill=[0]*M
    sum=0
    flag=1
    for k in range(len(b_pairs[i])):
        sum+=data[b_pairs[i][k]][0]
        for j in range(1,M+1):
            skill[j-1]+=data[b_pairs[i][k]][j]
    for h in range(M):
        if skill[h]<X:
            flag=0
    if flag==1:
        ans=min(ans,sum)

if ans==999999999:
    ans=-1
print(ans)


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

int main(){
  string d("abcdefghijklmnopqrstuvwxyz");
  bitset<26> b;
  string s;
  cin >> s;
  
  int n = s.length();
  for(int i=0; i<n;i++){
    for(int j=0; j<26; j++){
      if(s.at(i) == d.at(j)){
        b.set(j);
      }
    }
  }
  
  if(b.all()){
    cout << "None" << endl;
  }else{
    for(int i=0; i<26;i++){
      if(b[i] == 0){
        cout << d.at(i) << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   

    int a,b,c;
    cin >> a >> b >> c;
    if(a == b and b == c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;

#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define M 1000000007
#define MXN 1007
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
ll res[MXN];
ll dp[MXN];
ll t,k,n;
string str;
int main()
{
    fastio;
    ll n,m,x,y,mx=-1e10,mi=1e10;
    cin>>n>>m>>x>>y;
    ll a,b;
    for(int i=0;i<n;++i)
        cin>>a,mx = max(mx,a);
    for(int i=0;i<m;++i)
        cin>>b,mi = min(mi,b);
    if(mx < y && mi >x && x<y && mx<mi)
        cout<<"No War\n";
    else cout<<"War\n";
    return 0;
}   

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset

using namespace std;

typedef long long Lint;
typedef double db;
typedef pair<int,int> ii;
typedef pair<int,char> ic;
typedef pair<db,db> dd;
typedef pair<ii,int> iii;
typedef pair<ii,ii> i4;

const int maxn = 100020;
const int maxm = 1000020;
const int MOd = 998244353;


int main() {

    //freopen("asd.in","r",stdin);
    //freopen("output17.txt","w",stdout);
    int a;
    string s;
    scanf("%d",&a);
    db sum = 0.0;
    for(int i=1,j;i<=a;i++) {
    	scanf("%d",&j);
    	sum += (db)1/j;
    }
    printf("%.12lf\n",1/sum);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    string s;
    cin >> s;
    bool flag = true;
    int c = 0;
    if (s[0] != 'A') flag = false;
    else{
        for (int i = 1; i < (int) s.size(); i++){
            if (s[i] == 'C'){
                c++;
                if (i < 2 || i > (int) s.size()-2 || c > 1){
                    flag = false;
                    break;
                }
            }
            else if (s[i] >= 'A' && s[i] <= 'Z'){
                flag = false;
                break;
            }
        }
    }
    if (!flag || c == 0) cout << "WA\n";
    else cout << "AC\n";
}

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

    //int t; cin >> t; while (t--)
        solve();
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int len = s.length();
    for(int i = 0; i < len; i++){
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
        else{
            s = s.back()+s.substr(0, len-1);
            //cout << s << endl;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N=5e5+20,C=26;
char a[N];
int n,q,type,pos,l,r;
char c;
set <int> s[C];
int main()
{
	scanf("%d %s%d",&n,a+1,&q);
	for(int i=1;i<=n;i++) s[a[i]-'a'].insert(i);

	while(q--)
	{
		scanf("%d",&type);
		if(type==1)
		{
			scanf("%d %c",&pos,&c);
			s[a[pos]-'a'].erase(pos);
			s[c-'a'].insert(pos);
			a[pos]=c;
		}
		else
		{
			scanf("%d%d",&l,&r);

			int ans=0;
			for(int i=0;i<C;i++)
			{
				auto it=s[i].lower_bound(l);
				if(it==s[i].end() or *it>r) continue;
				ans++;
			}
			printf("%d\n",ans);
		}
	}
}

Measured memory_bytes: 24192
n = int(input())
a = []
h = []
for i in range(n):
    arr= list(map(int,input().split()))
    h.append(arr[2])
    a.append(arr)
l = [i for i in a if i[2]>0]
xt = l[0][0]
yt = l[0][1]
ht = l[0][2] 
for i in range(101):
    for j in range(101):
        h_ans = ht+abs(xt-i)+abs(yt-j)    
        if all(max(h_ans-abs(l[0]-i)-abs(l[1]-j),0) == l[2] for l in a):
            print(i,j,h_ans)
            exit()

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
	int N,P,A[100];
	long long even,odd,p;
	int i;

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

	even = 1;
	odd = 0;
	for(i=0;i<N;i++){
		if(A[i]%2 == 0){
			even = 2*even;
			odd = 2*odd;
		}else{
			p = even + odd;
			even = p;
			odd = p;
		}
	}

	if(P == 0){
		printf("%lld\n",even);
	}else{
		printf("%lld\n",odd);
	}

}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;

int main(){
    vector<double> x, y;
    double a, b, c, s;
    while(~scanf("%lf,%lf", &a, &b)){
	x.push_back(a);
	y.push_back(b);
    }
    for(int i = 1;i <= x.size();i++){
	x[i%x.size()] -= x[0];
	y[i%x.size()] -= y[0];
    }
    double res = 0;
    for(int i = 1;i < x.size() - 1;i++){
	res += fabs(x[i] * y[i + 1] - y[i] * x[i + 1]);
    }
    printf("%.9lf\n", res / 2);
    return 0;
}

Measured memory_bytes: 1256
# coding: utf-8
# 整数の入力
#a = int(raw_input())
# スペース区切りの整数の入力
import numpy as np
import itertools

N, T = map(int, raw_input().split())
Timings = map(int, raw_input().split())

TotalTime = 0
beforeTime = 0
for i in range(N):
    if (Timings[i] - beforeTime) > T or i == 0:
        TotalTime += T
    else:
        TotalTime += Timings[i] - beforeTime
    beforeTime = Timings[i]

print TotalTime

Measured memory_bytes: 27524
from sys import stdin
ans = 0
n = int(stdin.readline())
a = []
b = []
for i in xrange(n):
    x,y = map(int,stdin.readline().split())
    a.append(x)
    b.append(y)
add = 0
for i in xrange(n):
    x = a[n-1-i]+add
    y = b[n-1-i]
    c = (y - x%y)%y
    add += c
    ans +=c
print ans    

Measured memory_bytes: 9016
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<int>v(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
		v[i] += v[i - 1];
	}
	L = -1;
	R = 50000;
	while (R - L > 1) {
		int mid = (R + L + 1) / 2;
		vector<vector<int>>dp(N + 1, vector<int>(25001));
		for (int i = 0; i <= 25000; i++) {
			dp[0][i] = 1;
		}
		for (int i = 1; i <= N; i++) {
			for (int j = max(0, i - (int)N + 1); j < i; j++) {
				for (int k = 1; k <= 25000; k++) {
					if (k + mid >= v[i] - v[j]&&k<=v[i]-v[j]) {
						dp[i][k] |= dp[j][k];
					}
				}
			}
		}
		int box = 0;
		for (int i = 1; i <= 25000; i++) {

			box |= dp[N][i];
		}
		if (box) {
			R = mid;
		}
		else {
			L = mid;
		}
	}
	cout << R << endl;
	return 0;
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

int main()
{
    int k;
    string s;
    cin >> k >> s;
    string ss;
    if (s.size() > k)
    {
        ss = s.substr(0, k);
        ss += "...";
    }
    else
    {
        ss = s;
    }

    cout << ss << endl;

    return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;

long long n;

int main()
{
	cin>>n;
	for (int i=sqrt(n);i>=1;i--)
	{
		if (n%i==0) 
		{
			long long ans=(n/i)+i-2;
			cout<<ans;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.TreeMap;
import java.util.Map;

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

		TreeMap<String,Integer> map = new TreeMap<>();

		int n = scan.nextInt();

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

			int query = scan.nextInt();
			String key = scan.next();

			switch(query) {

			case 0:	//insert
				int value = scan.nextInt();
				map.put(key, value);
				break;

			case 1:	//get
				if(map.containsKey(key)) {
					System.out.println(map.get(key));
				}else
				System.out.println("0");
				break;

			case 2:	//delete
				map.remove(key);
				break;

			case 3:	//dump
				String limit = scan.next();
				for(Map.Entry<String, Integer> entry : map.subMap(key,true, limit,true).entrySet()){
					System.out.println(entry.getKey() + " " + entry.getValue());
				}

//				map.subMap(key,true, limit,true).forEach(Map.Entry<String, Integer> entry -> System.out.println(entry.getKey() + " " + entry.getValue()));
				break;
			}
		}
	}
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=1;i<n;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) REP(i,v.size())cout<<#v<<"["<<i<<"]: "<<v[i]<<endl
#define ALL(a) (a).begin(),(a).end()

int main(){
  ll n;
  cin >> n;
  int result = 0;
  while(n){
    n/=2;
    ++result;
  }
  cout << result << endl;
  return 0;
}

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

class UnionFind {
public:
    std::vector<int> data;

    UnionFind( int n ) {
        data.resize( n, -1 );
    }

    int find( int x ) {
        if ( data[x] < 0 ) {
            return x;
        } else {
            int r = find( data[x] );
            data[x] = r;
            return r;
        }
    }

    void unite( int x, int y ) {
        int r = find( x );
        int s = find( y );
        if ( r != s ) {
            data[r] += data[s];
            data[s] = r;
        }
    }
};

int solve() {
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> P[i];
        P[i]--;
    }
    int x, y;
    UnionFind uf(N);
    for ( int i = 0; i < M; i++ ) {
        cin >> x >> y;
        x--, y--;
        uf.unite(x, y);
    }

    unordered_map<int, unordered_map<int, int>> s;
    for ( int i = 0; i < N; i++ ) {
        int k = uf.find(i);
        s[k][i]++;
        s[k][P[i]]++;
    }

    ll ans = 0;
    for ( auto m : s ) {
        for ( auto mm : m.second ) {
            if ( mm.second > 1 ) ans++;
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 20772
#include <iostream>
#include <cmath>
#include <stdio.h>

using namespace std;

typedef long long ll;

int main(){

    ll A,B,V,W,T;

    scanf("%lld %lld",&A,&V);
    scanf("%lld %lld",&B,&W);
    scanf("%lld",&T);
  
    if(abs(A-B)<=(V-W)*T){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        
    }
   
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  in(a),in(b)
#define in3(a,b,c)  in2(a,b),in(c)
#define in4(a,b,c,d)  in2(a,b),in2(c,d)
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
il long long read(){
    char c;long long s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 200010
#define inf 0x7fffffff
#define ll long long
/*------------------------------------------------------------*/
int a[maxn];
int main(){
	int n;
	in(n);
	FOR(i,1,n)in(a[i]);
	sort(a+1,a+n+1);
	int c=inf,ans=0;
	FOR(i,1,n-1)if(abs(a[n]-a[i]-a[i])<c)c=abs(a[n]-a[i]-a[i]),ans=a[i];
	out2(a[n],ans);
}


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

using namespace std;

const int N = 1e5+7;

int n;
long long m;
int a[N];
long long sum[N];

// all >= x
inline long long count(int x)
{
    long long cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int p = lower_bound(a+1, a+n+1, x-a[i])-a;
        cnt += n-p+1;
    }
    return cnt;
}

inline long long calc(int x)
{
    long long res = 0;
    for (int i = 1; i <= n; ++i) {
        int p = lower_bound(a+1, a+n+1, x-a[i])-a;
        res += sum[n]-sum[p-1]+(n-p+1ll)*a[i];
    }
    return res;
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a+1, a+n+1);
    // reverse(a+1, a+n+1);
    for (int i = 1; i <= n+1; ++i) sum[i] = sum[i-1]+a[i];
    // int l = 2*a[n], r = 2*a[1];
    int l = 2*a[1], r = 2*a[n];
    while (l < r) {
        int mid = (l+r+1)>>1;
        if (count(mid) >= m) l = mid;
        else r = mid-1;
    }
    long long cnt = count(l), res = calc(l);
    cout << res-(cnt-m)*l << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    bool f = false;
    while(a>0 && c>0)
    {
        if(!f)
        {
            c -= b;
            f = true;
        }
        else
        {
            a -= d;
            f = false;
        }  
    }
    if(a<=0 && c>0)
    {
        cout<<"No"<<'\n';
    }
    else
    {
        cout<<"Yes"<<'\n';
    }
}
    

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;

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

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


int main() {

    int n; cin >> n;
    ll tmp;
    ll ans;

    rep(i,n){
        cin >> tmp;
        if(i == 0) ans = tmp;
        else ans = lcm(ans,tmp);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3600
#define _USE_MATH_DEFINES

#include <iostream>
#include <math.h> 
#include <vector>
#include <algorithm>
#include <iomanip>      // std::setprecision
#include <map>
#include <unordered_map>
#include <string>
#include <set>
#include <unordered_set>
#include <sstream>

using namespace std;

int main()
{
	int N;
	std::set<int> nums;
	vector<vector<int>> card(3,std::vector<int>(3,0));
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			int input;
			std::cin >> input;
			card[i][j] = input;
		}
	}

	std::cin >> N;
	for (int k = 0; k < N; ++k)
	{
		int num;
		std::cin >> num;
		nums.insert(num);
	}
	//check rows
	for (int i = 0; i < 3; ++i)
	{
		int counter = 0;
		for (int j = 0; j < 3; ++j)
		{
			if (nums.find(card[i][j]) != nums.end())
			{
				counter++;
			}
			else
			{
				break;
			}
		}
		if (counter == 3)
		{
			std::cout << "Yes\n";
			return 0;
		}
	}
	//check columns
	for (int i = 0; i < 3; ++i)
	{
		int counter = 0;
		for (int j = 0; j < 3; ++j)
		{
			if (nums.find(card[j][i]) != nums.end())
			{
				counter++;
			}
			else
			{
				break;
			}
		}
		if (counter == 3)
		{
			std::cout << "Yes\n";
			return 0;
		}
	}

		int counter = 0;
		for (int j = 0; j < 3; ++j)
		{
			if (nums.find(card[j][j]) != nums.end())
			{
				counter++;
			}
			else
			{
				break;
			}
		}
		if (counter == 3)
		{
			std::cout << "Yes\n";
			return 0;
		}
		counter = 0;
		for (int j = 0; j < 3; ++j)
		{
			if (nums.find(card[j][2-j]) != nums.end())
			{
				counter++;
			}
			else
			{
				break;
			}
		}
		if (counter == 3)
		{
			std::cout << "Yes\n";
			return 0;
		}
	std::cout << "No\n";

}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define f(a,b) for(ll i = a; i < b; i++)
#define fr(a,b) for(ll j = a; j >= b; j--)
#define fi(a,b) for(ll j = a; j < b; j++)
#define fii(a,b) for(ll k = a; k < b; k++)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pl pair<ll,ll>
#define vll vector<ll>
#define pll vector< pair<ll,ll> >
#define ld long double


void sieve(int n)
{

    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
              for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
ll modpow(ll a,ll b){
    ll rs=1;
    a%=mod;
    while(b>0){
        if(b&1)rs=(rs*a)%mod;

        b=b>>1;
        a=(a*a)%mod;
    }
    return rs;
}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

int t=1;
//cin>>t;

while(t--){

  ll n,k;
  cin>>n>>k;
  ll lmt=((n-1)*(n-2))/2;
  if(k>lmt)cout<<-1;
  else{
    ll cnt=(n*(n-1))/2;
     cnt=cnt-k;
    cout<<cnt<<endl;
    ll tp=0,di=1,st=1;
    while(tp!=cnt){
        cout<<st<<" "<<st+di<<endl;
        tp++;
        if(st+di==n){
            st++;  di=1;
        }
        else di++;
    }


  }



}

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int n, g, m;

int main(){
    vector<int> v;
    vector<int> c;
    vector<int> d;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> g;
        v.push_back(g);
    }
    for(int i = 0; i < n; i++){
        cin >> g;
        c.push_back(g);
    }
    for(int i = 0; i < n; i++){
        d.push_back(v[i] - c[i]);
    }

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

    auto it = d.end();
    --it;
    while(*it > 0){
        m = m + *it;
        --it;
    }

    cout << m;
}


//g++ -std=c++14 comp.cpp; ./a.exe


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str=sc.nextLine();
        String ans="";
        for(int i=0;i<str.length();i++){
            char a = str.charAt(i);
            if(Character.isUpperCase(a)){
                ans+=String.valueOf(Character.toLowerCase(a));
            }else{
                ans+=String.valueOf(Character.toUpperCase(a));
            }
        }
        System.out.println(ans);
    }
}

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

typedef long long ll;
const int mod = 1e9 + 7;
string S;

int main() {
    cin >> S;
    vector<ll> ans(S.size());

    rep(ri, 2) {
        int cnt = 0;
        rep(i, S.size()) {
            if (S[i] == 'R') cnt++;
            else {
                ans[i] += cnt / 2;
                ans[i - 1] += (cnt + 1) / 2;
                cnt = 0;
            }
        }

        reverse(ans.begin(), ans.end());
        reverse(S.begin(), S.end());
        rep(i, S.size()) {
            if (S[i] == 'R') S[i] = 'L';
            else S[i] = 'R';
        }
    }

    rep(i, S.size()) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1408
#include<iostream>

using namespace std;
  
int main(){
  int N;
  int V[20], C[20]; 
  int x;
  int result = 0;
  
  cin >> N;
  for (int i = 0; i < N; i++){
  	cin >> V[i];
  }
  
  for (int i = 0; i < N; i++){
  	cin >> C[i];
  }
  
  for (int i = 0; i < N; i++){
  	x = V[i] - C[i];
    if (x >= 0){
    	result += x;
    }
  }
  
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 256