akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber , InputReader in , PrintWriter out){
            int n = in.nextInt();
            int[] arr = new int[n];
            int sum2 = 0;
            for (int i = 0; i <n ; i++) {
                arr[i] = in.nextInt();
                sum2+=arr[i];
            }
            int min = Integer.MAX_VALUE;
            int sum1 = 0;
            for (int i = 0; i <n ; i++) {
                sum1+=arr[i];
                sum2-=arr[i];
                if (min > Math.abs(sum1-sum2) ) min = Math.abs(sum1-sum2);
            }
            out.println(min);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }

}

Measured memory_bytes: 21460
import sys
import scipy.sparse.csgraph as s
f=s.floyd_warshall
def main():
  n,m,l,*t=map(int,sys.stdin.buffer.read().split())
  d=[[0]*(n+1)for _ in range(n+1)]
  for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c
  d=f(f(d,0)<=l)-1
  d[d>n]=-1
  print('\n'.join(map(str,map(int,[d[i]for i in zip(*[iter(t[m*3+1:])]*2)]))))
main()

Measured memory_bytes: 36304
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
using namespace std;
//作者：中国江苏南京朱泽齐
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	int a,b;
	cin>>a>>b;
	if(a==1 && b==1){
		cout<<"Draw"<<endl;
		return 0;
	}
	if(a==1 && b!=1){
		cout<<"Alice"<<endl;
		return 0;
	}
	if(b==1 && a!=1){
		cout<<"Bob"<<endl;
		return 0;
	}
	if(a>b){
		cout<<"Alice"<<endl;
	}
	else if(a<b){
		cout<<"Bob"<<endl; 
	}
	else{
		cout<<"Draw"<<endl;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll vv[11], old[11], n, ans;

int main(void)
{
	ll i, j, x; cin>>n;
	for(i=1 ; i<=n ; i++)
	{
		cin>>x;
		for(j=0 ; j<=9 ; j++) old[j]=vv[j];
		for(j=0 ; j<=9 ; j++)
			if(old[j]%10==j) vv[(j+x)%10]=max(vv[(j+x)%10],old[j]+x);
	}
	for(i=1 ; i<=9 ; i++) ans=max(ans,vv[i]);
	cout<<ans; return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

vector<ll> ans,cnt;
vector<vector<ll>> edge;
void dfs(ll pa, ll cv){
  if(pa != -1) ans[cv] = ans[pa] + cnt[cv];
  FOREACH(x, edge[cv]){
    if(x==pa) continue;
    dfs(cv,x);
  }
  return;
}

int main(){
  ll n,q; cin >> n >> q;
  edge = vector<vector<ll>>(n, vector<ll>());
  cnt = vector<ll>(n,0);
  REP(i,n-1){
    ll a,b; cin >> a >> b;
    a--; b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  REP(i,q){
    ll p,x; cin >> p >> x;
    p--;
    cnt[p] += x;
  }
  ans = vector<ll>(n,0);
  ans[0] = cnt[0];
  dfs(-1,0);
  REP(i,n){
    cout << ans[i];
    if(i==n-1) cout << endl;
    else cout << " ";
  }
}



Measured memory_bytes: 25856
import java.util.Scanner;

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

    while (in.hasNext()) {
      int N = in.nextInt();
      int K = in.nextInt();
      int Q = in.nextInt();
      int[] point = new int[N];
 
      for (int i = 0; i < Q; ++i) {
        ++point[in.nextInt() - 1];       
      }

      for (int i = 0; i < point.length; ++i) {
        if (point[i] + K - Q > 0) {
          System.out.println("Yes");
        } else {
          System.out.println("No");
        }
      }
    }
  }
}

Measured memory_bytes: 70036
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int h, w;
string s[410];

bool used[410][410];
const int dy[4] = {1, 0, -1, 0};
const int dx[4] = {0, 1, 0, -1};

P calc(int y, int x) {
    used[y][x] = true;
    ll a = 0, b = 0;
    if (s[y][x] == '.') a++;
    else b++;
    for (int i = 0; i < 4; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        if (0 <= ny && ny < h && 0 <= nx && nx < w &&
            !used[ny][nx] && s[y][x] != s[ny][nx]) {
            P p = calc(ny, nx);
            a += p.first;
            b += p.second;
        }
    }
    return make_pair(a, b);
}

ll solve() {
    ll res = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (!used[i][j]) {
                P p = calc(i, j);
                res += p.first * p.second;
            }
        }
    }
    return res;
}

void input() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> s[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 16064
import Data.Char
import Data.List

main = interact $ unlines . show' . itp1_8_c
 where show' = zipWith (++) [[a]++" : " | a<-['a'..'z']] . map show

itp1_8_c = map ((subtract 1) . length) . group . sort . (++ ['a'..'z']) . map toLower . filter isAlpha

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

int main(){
  int N;
  vector <int> V(21);
  vector <int> C(21);
  int P = 0;

  cin >> N;

  //N個の宝石の価値を代入する
  for (int i=0; i<N; i++){
    cin >> V.at(i);
  }
  //N個の宝石のコストを代入する
  for (int i=0; i<N; i++){
    cin >> C.at(i);
  }

  //宝石の価値とコストを比較する
  //0以上であれば利益が出るので、Pに代入する
  for (int i=0; i<N; i++){
    if (V.at(i)-C.at(i) > 0) {
      P += V.at(i)-C.at(i);
    }
  }

  cout << P;




}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define N 100005

using namespace std;
typedef pair<int,int> Pair;
typedef long long ll;

const int mod = 1e9 + 7;
inline int add(int x, int y) { return (x += y) - (x >= mod ? mod : 0); }
inline void inc(int &x, int y) { (x += y) -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = mul(res, x);
		x = mul(x, x), y >>= 1;
	} return res;
}

template <class T> inline T	input() {
	T x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

template <class T> inline void chkmin(T &x, T &y) { x = x < y ? x : y; }
template <class T> inline void chkmax(T &x, T &y) { x = x > y ? x : y; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

int n, L, T, pos;
int x[N], d[N], ans[N];

int main() {
	read(n, L, T);
	for (int i = 1; i <= n; ++i) read(x[i], d[i]), d[i] = d[i] == 2 ? -1 : 1;
	for (int i = 1; i <= n; ++i) {
		x[i] = x[i] + T * d[i], pos += x[i] / L;
		if (x[i] % L < 0) --pos;
		x[i] = (x[i] % L + L) % L;
	}

	pos = (pos % n + n) % n + 1;
	sort(x + 1, x + n + 1);
	for (int i = pos; i <= n; ++i) printf("%d\n", x[i]);
	for (int i = 1; i < pos; ++i) printf("%d\n", x[i]);
	return 0;
}


Measured memory_bytes: 2048
# include <iostream>
# include <math.h>

using namespace std;

int main()
{
    int N, D;

    cin >> N >> D;

    int* X, * Y;
    X = new int[N];
    Y = new int[N];

    for (int i = 0; i < N; i++)
    {
        cin >> X[i] >> Y[i];
    }

    int close = 0;

    sqrt(double(N));

    for (int i = 0; i < N; i++)
    {
        if (sqrt(pow(double(X[i]),2) + pow(double(Y[i]),2)) <= D)
        {
            close++;
        }
    }
    cout << close;


    return 0;
}

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

const int N = 1e5 + 10;
typedef long long ll;
ll n, m, v, p, ans;
ll a[N], b[N];

bool cmp(ll a, ll b) {
    return a > b;
}

bool chk(ll lim) {
    rep(i, 1, n) a[i] = b[i];
    ll vv = v, pos;
    pos = lim;
    while (pos <= n && vv) {
        a[pos] += m; --vv, ++pos;
    }
    pos = 1;
    while (pos <= p - 1 && vv) {
        a[pos] += m; --vv, ++pos;
    }
    if (!vv) {
        return a[lim] >= a[p];
    }
    ll rest = 1ll * vv * m;
    rep(i, p, lim - 1) {
        ll t = a[lim] - a[i];
        if (t < 0) return 0;
        t = min(t, rest);
        rest -= t;
        if (!rest) return 1;
    } return 0;
}

int main() {
    cin >> n >> m >> v >> p;
    rep(i, 1, n) scanf("%lld", &a[i]), b[i] = a[i];
    sort(b + 1, b + n + 1, cmp);
    ll l = p, r = n;
    while (l <= r) {
        ll mid = (l + r) >> 1;
        if (chk(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5276
n = gets.chomp.to_i
v = gets.chomp.split.map(&:to_i)

v1 = []
v2 = []
n.times do |i|
  if i.even?
    v1.push(v[i])
  else
    v2.push(v[i])
  end
end

v11 = v1.group_by(&:to_i).sort_by{|_,v|-v.size}.map(&:first).first
v22 = v2.group_by(&:to_i).sort_by{|_,v|-v.size}.map(&:first).first

if v11 != v22
  p v1.count{|a| a != v11} + v2.count{|a| a != v22}
else
  v222 = v2.group_by(&:to_i).sort_by{|_,v|-v.size}.map(&:first)[1]
  tmp1 = v1.count{|a| a != v11} + v2.count{|a| a != v222}
  v111 = v1.group_by(&:to_i).sort_by{|_,v|-v.size}.map(&:first)[1]
  tmp2 = v1.count{|a| a != v111} + v2.count{|a| a != v22}
  p [tmp1, tmp2].min
end


Measured memory_bytes: 26356
import bisect
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.sort()
B.sort()
C.sort()
ans = 0

for i in range(N):
    count_A = bisect.bisect_left(A,B[i])
    count_C = bisect.bisect_right(C,B[i])
    ans += count_A * (N-count_C)
print(ans)


Measured memory_bytes: 23292
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define rall(a)		(a).rbegin(), (a).rend()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 1e9;

int m10, m50, m100, m500;
int u10, u50, u100, u500;
int t10, t50, t100, t500;
int Min;
int N;
int sum;

void dfs(int n){

	if (n == 4){
		int v = 0;
		int tsum = sum;
		int al = t10 * 10 + t50 * 50 + t100 * 100 + t500 * 500;
		if (al < N)return;
		tsum -= t10 + t50 + t100 + t500;
		int r = al - N;

		if (r / 500 && t500)return;
		tsum += r / 500; r = r % 500;
		if (r / 100 && t100)return;
		tsum += r / 100; r = r % 100;
		if (r / 50 && t50)return;
		tsum += r / 50; r = r % 50;
		if (r / 10 && t10)return;
		tsum += r / 10; r = r % 10;

		if (tsum < Min){
			Min = tsum;
			u10 = t10; u50 = t50; u100 = t100; u500 = t500;
		}

	}

	if (n == 0){
		rep(i, m10 + 1){
			t10 = i;
			dfs(1);
		}
	}
	if (n == 1){
		rep(i, m50 + 1){
			t50 = i;
			dfs(2);
		}
	}
	if (n == 2){
		rep(i, m100 + 1){
			t100 = i;
			dfs(3);
		}
	}
	if (n == 3){
		rep(i, m500 + 1){
			t500 = i;
			dfs(4);
		}
	}

}

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

		cin >> m10 >> m50 >> m100 >> m500;
		sum = m10 + m50 + m100 + m500;
		t10 = t50 = t100 = t500 = 0;
		Min = INF;
		dfs(0);

		if (u10)cout << 10 << " " << u10 << endl;
		if (u50)cout << 50 << " " << u50 << endl;
		if (u100)cout << 100 << " " << u100 << endl;
		if (u500)cout << 500 << " " << u500 << endl;
		cin >> N;
		if (!N)break;
		else cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int ans=N;
  for(int i=0;i<=N;i++){
    int X=i,a=0;
    while(X>0){
      a+=X%6;
      X/=6;
    }
    X=N-i;
    while(X>0){
      a+=X%9;
      X/=9;
    }
    if(ans>a) ans=a;
  }
  cout<<ans<<endl;
}

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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  bool ans = true;
  for (int i = 0; i < (N-1)/2; i++){
    if (S.at(i) != S.at((N-3)/2-i)){
      ans = false;
      break;
    }
    if (S.at(i+(N+1)/2) != S.at(N-1-i)){
      ans = false;
      break;
    }
    if (S.at(i) != S.at(N-1-i)){
      ans = false;
      break;
    }
  }
  if(ans) cout <<"Yes"<<endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
def actual(n, l):
    apples = [l + i - 1 for i in range(1, n + 1)]
    yotei = sum(apples)

    if 0 in apples:
        return yotei

    if apples[0] >= 0:
        return yotei - apples[0]

    if apples[-1] <= 0:
        return yotei - apples[-1]

n, l = map(int, input().split())
print(actual(n, l))

Measured memory_bytes: 3060
#include<stdio.h> 

main(){  

int a=0;  

int W,H,x,y,r=0;  

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);  

if(x-r>=0&&x+r<=W){    

if(y-r>=0&&y+r<=H){      

a=1;    }  

}   

else{    

a=0;  

}  

if(a==1){    

printf("Yes\n");  

} 

else if(a==0){    

printf("No\n");  

}  

return 0; 

}

Measured memory_bytes: 584
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	int n, m, q, t, x;
	ll score, M = 0;
	cin >> n >> m >> q;
	vector<int> a(q), b(q), c(q), d(q), C(n+m);
	rep(i, 0, q)cin >> a[i] >> b[i] >> c[i] >> d[i];
	m--;
	rep(i, 0, 1 << (n + m)) {
		t = x = 0;
		rep(i2, 0, n + m) {
			if (i >> i2 & 1)t++;
			else C[x++] = t + 1;
		}
		if (t != m)continue;
		for (; x < n + m; x++)C[x] = t + 1;
		score = 0;
		rep(i2, 0, q) {
			if (C[b[i2] - 1] - C[a[i2] - 1] == c[i2])score += (ll)d[i2];
		}
		M = max(M, score);
	}
	printf("%lld\n", M);
	return 0;
}

Measured memory_bytes: 3636
N = int(input())
A = sorted(list(map(int,input().split())))[::-1]
if N%2 == 1:
    print(sum(A[0:N//2])+sum(A[1:N//2 + 1]))
else:
    print(sum(A[0:N//2-1])+sum(A[1:N//2])+ A[N//2 - 1])

Measured memory_bytes: 31560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int ans;
int main(void){
    int a,b,c,d; cin>>a>>b>>c>>d;
    for(int i=0;i<=100;i++){
        if(a<=i&&i<=b&&c<=i&&i<=d){
            ans++;
        }
    }
    cout<<max(0,ans-1)<<endl;
    
}


Measured memory_bytes: 3636
import sys

def stackBall(ball):
	sB, sC = [0], [0]
	for b in ball:
		if max(sB[-1], sC[-1]) < b:
			if sB[-1] >= sC[-1]:
				sB.append(b)
			else:
				sC.append(b)
		elif min(sB[-1], sC[-1]) < b:
			if sB[-1] >= sC[-1]:
				sC.append(b)
			else:
				sB.append(b)
		else:
			return False
	return True


n = int(input())

for _ in range(n):
	ball = list(map(int, input().split()))
	if stackBall(ball):
		print("YES")
	else:
		print("NO")

Measured memory_bytes: 6724
#AKIHABARA
S = input()
T = ["AKIHABARA",
     "AKIHABAR",
     "AKIHABRA",
     "AKIHBARA",
     "KIHABARA",
     "AKIHABR",
     "AKIHBAR",
     "KIHABAR",
     "AKIHBRA",
     "KIHABRA",
     "KIHBARA",
     "AKIHBR",
     "KIHABR",
     "KIHBAR",
     "KIHBRA",
     "KIHBR"]
for t in T:
    if t == S:
        print("YES")
        exit()
print("NO")

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17

n, x, y = map(int, input().split())
A=[0]*n
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        distance1 = abs(i - j)
        distance2 = abs(i - x) + abs(j - y) + 1
        distance3 = abs(i - y) + abs(j - x) + 1
        distance = min(distance1, distance2)
        distance = min(distance, distance3)
        A[distance] += 1
for i in range(1, n):
    print(A[i])


Measured memory_bytes: 49244
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007
using namespace std;
int main(){
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin>>x1>>y1>>x2>>y2;
    int dx=x2-x1;
    int dy=y2-y1;
    y3=y2+dx;
    x3=x2-dy;
    y4=y3-dy;
    x4=x3-dx;
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100005
using namespace std;
int n,k,x[N],ans=1000000001;
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>x[i];
	sort(x,x+n);
	for(int i=k-1;i<n;i++)ans=min(ans,x[i]-x[i-k+1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;
vector<int>p[100010];
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int main()
{
    int n=read(),k=ceil(sqrt(2*n));
    if(k*(k-1)!=2*n)printf("No\n");
    else
    {
    	printf("Yes\n");
    	printf("%d\n",k);
    	int now=0;
    	for(int i=1;i<k;i++)
    	{
    		for(int j=i+1;j<=k;j++){now++;p[i].push_back(now),p[j].push_back(now);}
    	}
    	for(int i=1;i<=k;i++)
		{
			printf("%d ",k-1);
			for(int j=0;j<k-1;j++)printf("%d ",p[i][j]);
			printf("\n");
		}
    }
	return 0;
}

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

int main() {
	// your code goes here
	vector<int> vec;
	int n;
	cin>>n;
	for(int i=0;i<2*n;i++){
		int a;
		cin>>a;
		vec.push_back(a);
	}
	std::sort(vec.begin(),vec.end());
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=vec[i*2];
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	int i,n;
	long long a[100]={2,1};
	for(i=2;i<=86;i++)
	a[i]=a[i-1]+a[i-2];
	while(scanf("%d",&n)!=EOF)
	printf("%lld\n",a[n]);
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from itertools import *
INF = 10**10

CHRtoINT = defaultdict(int)
atoz = [chr(i) for i in range(97,97+26)]
for i, c in enumerate(atoz):
    CHRtoINT[c] = i

N, S = int(input()), input()
b = 26
m = 67280421310721
l, r = 0, N//2+1
while l+1 < r:
    x = (l+r)//2
    OK = 0
    dic = defaultdict(int)
    B, hash, b_inv = pow(b, x-1, m), 0, pow(b, m-2, m)
    t = B
    for c in S[:x]:
        hash = (hash + CHRtoINT[c] * t) % m
        t = t * b_inv % m
    dic[hash] = 0
    B *= b
    for i, c in enumerate(S[:-x]):
        hash = (hash * b - CHRtoINT[c] * B + CHRtoINT[S[i+x]]) % m
        if hash in dic:
            if i+1-dic[hash] >= x:
                OK = 1
                break
        else:
            dic[hash] = i+1
    if OK:
        l = x
    else:
        r = x
print(l)


Measured memory_bytes: 45676
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>
using namespace std;
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define int long long

const int maxn = 120000;
int ff[maxn*2];
int a[maxn];
/*
int add(int x){
	x++;
	for(;x < maxn*2;x+=x&(-x))ff[x]+=1;
}

int get(int x){
	x++;
	int ans = 0;
	for(;x > 0; x-=x&(-x))ans+=ff[x];
	return ans;
}*/

void add(int x) {
	for (; x < maxn * 2; x |= (x + 1))
		ff[x] += 1;
}
 
int get(int x) {
	int ans = 0;
	for (; x >= 0; x = (x & (x + 1)) - 1)
		ans += ff[x];
	return ans;
}

signed main(){
	
	int n;cin>>n;
	FOR(i,0,n-1)cin>>a[i];

	int l=0,r=1e9+2;
	
	int all = n*(n+1)/2;
	
	while(r-l > 1)
	{
		int mid = (l+r)/2;
		memset(ff,0,sizeof(ff));
		int cur = n;
		add(cur);
		int now = 0;
		FOR(i,0,n-1)
		{
			if(a[i]>=mid)cur++;
			else cur--;
			
			now += get(cur);
			add(cur);
		}
		
		if(now*2 >= all) l = mid;
		else r = mid;
	}
	
	cout << l << endl;
}


Measured memory_bytes: 2944
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#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;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const long double INF = 1e100;
const ll MOD = 1000000007LL;

const int MAXH = 500;
long double dp[160][MAXH + 10];
signed main() {
    int N; cin >> N;
    vector<int> h(N);
    for(int i=0; i<N; i++) {
        cin >> h[i];
    }

    fill(dp[0], dp[N+1], INF);
    dp[0][1] = 0;
    for(int i=0; i<N; i++) {
        int H = h[i];
        for(int j=1; j<MAXH; j++) {
            if(dp[i][j] == INF) continue;
            for(int k=1; k<MAXH; k++) {
                long double cost = -1;
                // (x_{i-1}, j), (x_{i}, k)
                if(j <= H and k <= H) {
                    long double A = H;
                    long double B = 1.0 * (j + k) / 2;
                    cost = A - B;
                }
                else if(j <= H and k > H) {
                    long double x = 1.0 * (H - j) / (k - j);
                    /*
                    if(j < 10 and k < 10) {
                        fprintf(stderr, "i = %lld, j = %lld, k = %lld, x = %.12Lf\n", i, j, k, x);
                    }
                    */

                    cost = ((H - j) * x + (k - H) * (1 - x)) / 2.0;
                }
                else if(j > H and k <= H) {
                    long double x = 1.0 * (j - H) / (j - k);
                    cost = ((j - H) * x + (H - k) * (1 - x)) / 2.0;
                }
                else {
                    long double h1 = j - H;
                    long double h2 = k - H;
                    cost = (h1 + h2) / 2.0;
                }

                chmin(dp[i+1][k], dp[i][j] + cost);
            }
        }
    }

    /*
    for(int i=0; i<=N; i++) {
        for(int j=0; j<MAXH; j++) {
            if(j >= 10 or dp[i][j] == INF) continue;
            fprintf(stderr, "dp[%lld][%lld] = %.12Lf\n", i, j, dp[i][j]);
        }
    }
    */

    long double res = *min_element(dp[N], dp[N] + MAXH + 5);
    cout << fixed << setprecision(15) << res << endl;
    return 0;
}



Measured memory_bytes: 4456
//                                  _                 ______   ______   ______   ______
//                                 | |               |  __  | |  __  | |  __  | |____  |
//    __ _   ____    _____    _  _ | |____           | |__| | | |__| | | |__| |      | |
//  / _` | |  __| /  __  |  / _` | |  __  |          |____  | |____  | |____  |      | |
// | (_| | | |    | |  | | | (_| | | |__| |  ______   ____| |  ____| |  ____| |      | |
//  \__,_| |_|    |_|  |_|  \__,_| |______| |______| |______| |______| |______|      |_|

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define endl '\n'
#define REP(i, n) for(int i=0; i<n; i++)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9+7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();
  //Code goes past here:

  int a, b, x;
  cin>>a>>b;
  for(x=1; x <= 2501; x++){
    if(x*8/100==a && x*10/100==b){
      cout<<x<<endl;
      exit(0);
    }
  }

  cout<<-1<<endl;

  return 0;
}


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

std::vector<std::pair<int, int>> mins(const std::vector<int>& v) {
  std::vector<std::pair<int, int>> v_p;
  for (int i = 0; i < v.size(); ++i) {
    v_p.push_back({i, v[i]});
  }
  std::sort(
            v_p.begin(),
            v_p.end(),
            [](const std::pair<int, int>& x, const std::pair<int, int>& y){return x.second < y.second;}
    );
  return v_p;
}

int main () {
  int N, C;
  std::cin >> N >> C;
  std::vector<std::vector<int>> D(C, std::vector<int>(C));
  for (int i = 0; i < C; ++i) {
    for (int j = 0; j < C; ++j) {
      std::cin >> D[i][j];
    }
  }

  std::vector<std::vector<int>> c(N, std::vector<int>(N));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      std::cin >> c[i][j];
      --c[i][j];
    }
  }
  std::vector<std::vector<int>> color(3, std::vector<int>(C, 0));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < C; ++k) {
        color[(i + j) % 3][k] += D[c[i][j]][k];
      }
    }
  }
  auto c0 = mins(color[0]);
  auto c1 = mins(color[1]);
  auto c2 = mins(color[2]);
  int min = INT32_MAX;
  int i0, i1, i2;
  for (i0 = 0; i0 < 3; ++i0) {
      for (i1 = 0; i1 < 3; ++i1) {
          for (i2 = 0; i2 < 3; ++i2) {
            if (c0[i0].first != c1[i1].first && c0[i0].first != c2[i2].first && c2[i2].first != c1[i1].first) {
              if (c0[i0].second + c1[i1].second + c2[i2].second < min)
                min = c0[i0].second + c1[i1].second + c2[i2].second;
            }
          }
      }
  }
  std::cout << min << std::endl;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

int len;
string a,b;

int rec(const string& s,int idx){
    if(idx==len) return 0;
    const int d=(b[idx]-s[idx]+10)%10;
    if(d==0) return rec(s,idx+1);
    int res=inf;
    rep(i,1,len-idx+1){
        string tmp=s;
        rep(j,idx,idx+i){
            tmp[j]='0'+(tmp[j]-'0'+d)%10;
        }
        res=min(res,rec(tmp,idx+1)+1);
    }
    return res;
}

void solve(){
    while(true){
        cin >> len; if(!len) break;
        cin >> a >> b;
        cout << rec(a,0) << endl;
    }
}

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

Measured memory_bytes: 3144
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 2000
#define INF 1000000000000000000LL
using namespace std;
typedef long long LL;
int N;
LL b[MAXN+5],a[MAXN+5],x;
int main()
{
//	freopen("slime.in","r",stdin);
//	freopen("slime.out","w",stdout);
	scanf("%d %lld",&N,&x);
	for(int i=0;i<N;i++)
		scanf("%lld",&a[i]);
	fill(b,b+N,INF);
	LL ans=INF;
	for(int mv=0;mv<N;mv++)
	{
		LL ansn=0;
		for(int i=0;i<N;i++)
			b[i]=min(b[i],a[(i-mv+N)%N]);
		for(int i=0;i<N;i++)
			ansn+=b[i];
		ansn+=mv*x;
		ans=min(ans,ansn);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
N, monster = map(int,input().split())
sword = [list(map(int,input().split())) for _ in range(N)]
power = 0
attack = 0
sword = sorted(sword, key=lambda x:x[1], reverse=True)

for i in range(N):
    power = max(sword[i][0], power)

for j in range(N):
    if sword[j][1] >= power:
        monster -= sword[j][1]
        attack += 1
        if monster <= 0:
            break
if monster > 0:
    attack += monster // power
    if monster % power != 0:
        attack += 1

print(attack)

Measured memory_bytes: 29680
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    int a,b,c,d,e,k;
    std::cin >> a>>b>>c>>d>>e>>k;
    if ((e - a) > k) {
        std::cout << ":(" << std::endl;
    } else {
        std::cout << "Yay!" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
 #define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=1000002;

void solve(){
	ll n,a,b;
	cin>>n>>a>>b;
	if((b-a)%2==0){
		cout<<(b-a)/2;
		return;
	}
	if(a!=1&&b!=n){
		cout<<(b-a)/2ll+min((a-1),(n-b))+1;
	}
	else{
		cout<<min((b-a)/2ll+((b-a)%2),b-a);
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 256
n,a,b = map(int,input().split())
mod = 10**9+7
sum_comb = pow(2,n,mod) - 1


def comb(n, r, mod):
    x=y=1
    for i in range(r):
        x *= n; y *= r
        x %= mod; y %= mod
        n -= 1; r -= 1
    return x * pow(y, mod - 2, mod) % mod

comb_a = comb(n,a,mod)
comb_b = comb(n,b,mod)

print((sum_comb - comb_a - comb_b)%mod)


Measured memory_bytes: 38640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {
  int D;
  scanf("%d", &D);
  int c[27];
  for(int i=1;i<=26;i++){
    scanf("%d", &c[i]);
  }
  int s[366][27];
  int smax[366];
  int smax_idx[366];

  for(int i=1;i<=365;i++){
    smax_idx[i]=1;
    smax[i]=0;
    for(int j=1;j<=26;j++){
      scanf("%d", &s[i][j]);
      if(smax[i]<s[i][j]){
        smax[i]=s[i][j];
        smax_idx[i]=j;
      }
    }
  }
  for(int i=1;i<=365;i++){
    printf("%d\n", smax_idx[i]);
  }
  return 0; 
}

Measured memory_bytes: 2192
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector< vector<int> > as(n,vector<int>(n-1));
  for(int i=0;i<n;i++)
    for(int j=0;j+1<n;j++)
      cin>>as[i][j],as[i][j]--;

  vector<int> day(n,0),pos(n,0);
  queue<int> que;
  for(int i=0;i<n;i++){
    if(as[as[i][0]][0]==i){
      que.emplace(i);
      day[i]=1;
      pos[i]++;
    }
  }

  while(!que.empty()){
    int v=que.front();que.pop();
    if(pos[v]==n-1) continue;
    int u=as[v][pos[v]];
    if(as[u][pos[u]]!=v) continue;
    int d=max(day[u],day[v])+1;
    day[u]=day[v]=d;
    pos[u]++;
    pos[v]++;
    que.emplace(u);
    que.emplace(v);
  }

  for(int i=0;i<n;i++)
    if(pos[i]!=n-1) drop(-1);

  cout<<*max_element(day.begin(),day.end())<<endl;
  return 0;
}


Measured memory_bytes: 4224
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(double &x){
  scanf("%lf",&x);
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned x){
  int s=0;
  char f[10];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned long long x){
  int s=0;
  char f[21];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(double x){
  printf("%.15f",x);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    putchar_unlocked(x[i]);
  }
}
template<class T> inline T pow2_L(T a){
  return a*a;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
double X[50];
double Y[50];
double dist[50];
int main(){
  int e98WHCEY;
  int i;
  int j;
  int k;
  double cx = 0;
  double cy = 0;
  double mv = 1;
  double r = 0.999;
  double res = 1e150;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(X[Lj4PdHRW]);
      rd(Y[Lj4PdHRW]);
    }
  }
  for(e98WHCEY=(0);e98WHCEY<(100000);e98WHCEY++){
    for(i=(0);i<(N);i++){
      dist[i] =pow2_L((X[i]-cx))+pow2_L((Y[i]-cy));
    }
    {
      int WYIGIcGE;
      double t_ynMSdg;
      if(N==0){
        t_ynMSdg = 0;
      }
      else{
        t_ynMSdg = dist[0];
        for(WYIGIcGE=(1);WYIGIcGE<(N);WYIGIcGE++){
          t_ynMSdg = max_L(t_ynMSdg, dist[WYIGIcGE]);
        }
      }
      chmin(res, t_ynMSdg);
    }
    {
      int a2conNHc;
      int hCmBdyQB = 0;
      double V9aVTaxx;
      double APIVbQlN;
      int YREPHmFM;
      for(a2conNHc=(0);a2conNHc<(((N)-1)+1);a2conNHc++){
        APIVbQlN = dist[a2conNHc];
        if(hCmBdyQB==0 || V9aVTaxx<APIVbQlN){
          V9aVTaxx = APIVbQlN;
          hCmBdyQB = 1;
          YREPHmFM = a2conNHc;
        }
      }
      k =YREPHmFM;
    }
    cx += mv * (X[k] - cx);
    cy += mv * (Y[k] - cy);
    mv *= r;
  }
  wt_L(sqrt(res));
  wt_L('\n');
  return 0;
}
// F

Measured memory_bytes: 256
n, m = map(int, input().split())
root_map = dict()
root_map[1] = set()
root_map[n] = set()

for i in range(m):
    a, b = map(int, input().split())
    if a == 1 or a == n:
        root_map[a].add(b)
    if b == 1 or b == n:
        root_map[b].add(a)

for i in root_map[1]:
    if i in root_map[n]:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")


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

int main(){
    int A,N,i = 0;
    cin >> N >> A;
    if(N % 500 == 0){
        cout << "Yes";
    }else if(N <= A){
        cout << "Yes";
    }else if(N % 500 <= A){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int ans;
  if(S == "SUN")ans = 7;
  else if(S == "MON")ans = 6;
  else if(S == "TUE")ans = 5;
  else if(S == "WED")ans = 4;
  else if(S == "THU")ans = 3;
  else if(S == "FRI")ans = 2;
  else if(S == "SAT")ans = 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())

int main(){
    long long int N,A,B,C=0,D,E;
    cin>>N>>A>>B;
    C=A+B;
    D=N/C;
    E=N-D*C;
    if(E>A)cout<<A*D+A<<endl;
    else cout<<A*D+E<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;
int main() {
	unsigned long long x, y;
	cin >> x >> y;

	int count = 1;
	while (x<=y)
	{
		x *= 2;
		count++;
	}
	cout << count-1 << endl;
	return 0;
}

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

es = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j,(a,b) in enumerate(es):
        if i == j: continue
        if uf.is_same(a,b): continue
        uf.unite(a,b)
    u,v = es[i]
    if not uf.is_same(u,v):
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    LL n,k;
    cin>>n>>k;
    int ans=1;
    int cnt=1;
    while(n>=cnt*k){ans++;cnt=cnt*k;}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
c = input()

count = 0
rui_red = [0 for _ in range(N)]
rui_white = [0 for _ in range(N)]
now_red = 0
now_white = 0
for i in range(N):
    if c[i] == "W":
        now_white += 1
        rui_white[i] = now_white
    if c[-1-i] == "R":
        now_red += 1
        rui_red[-1-i] = now_red


left = 0
right = N-1
for i in range(N+1):
    pre_left = left
    pre_right = right
    
    while rui_white[left] < i:
        left += 1
        if  left >= N:
             break
    while rui_red[right] < i:
        right -= 1
        if right < 0:
            break
    if left>=right:
        break
answer = i-1
count = 0
for i in range(pre_left+1, pre_right):
    if c[i] == "W":
        count+=1
    else:
        count-=1

print(answer)

Measured memory_bytes: 100672
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
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; }
using namespace std;

int N;
ll A[500100];
const ll SENTINEL = numeric_limits<ll>::max();
int cnt = 0;

void merge(ll A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    ll L[n1+1], R[n2+1];
    rep(i, n1) L[i] = A[left + i];
    rep(i, n2) R[i] = A[mid + i];
    L[n1] = SENTINEL;
    R[n2] = SENTINEL;

    int i = 0, j = 0;
    for(int k=left; k<right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
        cnt++;
    }
}

void merge_sort(ll A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        merge_sort(A, left, mid);
        merge_sort(A, mid, right);
        merge(A, left, mid, right);
    }
}

void print_array(ll A[]) {
    rep(i, N) {
        cout << A[i];
        if (i != N-1) cout << " ";
    }
    cout << endl;
}

int main() {
    cin >> N;
    rep(i, N) cin >> A[i];
    merge_sort(A, 0, N);
    print_array(A);
    cout << cnt << endl;
}



Measured memory_bytes: 10896