akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
      
        // flag
        boolean flag = false;

		// argumentの取得
		Scanner sc = new Scanner(System.in);

		Integer x = sc.nextInt();
        String  y = sc.next();
      
        //System.out.println(x);
        //System.out.println(x.length());
      
        if (x % 2 == 0) {
          //System.out.println("yの文字数: " + y.length());
          
          // 判定ロジック
          String firstHalf = y.substring( 0,  y.length()/2);
          String secondHalf = y.substring( y.length()/2,  y.length());
          
          if (firstHalf.equals(secondHalf)) {
            System.out.println("Yes");
          } else {
            System.out.println("No");
          }
          
          //System.out.println("前半分: " + firstHalf);
          //System.out.println("後ろ半分: " + secondHalf);
        } else {
          System.out.println("No");
        }
      
      
	} 
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
 
// Begin Template IO/Utility
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
void dbg_out(){
	cerr<<endl;
}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){
	cerr<<' '<< H;
	dbg_out(T...);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &V){
	os<<'[';
	for(int i=0;i<(int)V.size();i++)
		os<<V[i]<<",]"[i==(int)V.size()-1];
	return os;
}
template<typename T> istream& operator>>(istream &is, vector<T> &V){
	for(T &x:V)
		is>>x;
	return is;
}
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T,U> &p){
	os<<'{'<<p.first<<','<<p.second<<'}';
	return os;
}
template<typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){
	is>>p.first>>p.second;
	return is;
}
template<typename T> void minself(T &a, T b){
	a=min(a,b);
}
template<typename T> void maxself(T &a, T b){
	a=max(a,b);
}
// End Template IO/Utility
 
int main(){
	string s;
	cin>>s;
	if(s[0]=='7' || s[1]=='7' || s[2]=='7')
		cout<<"Yes";
	else cout<<"No";
}

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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<lli, lli>
#define ps pair<double, string>
#define pib pair<pi, bool>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 50
#define MAXL 10001
#define mod 1000000007

signed main()
{
  int k;
  string s;
  cin >> k >> s;
  if (s.size() > k)
    cout << s.substr(0, k) << "...\n";
  else
    cout << s << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

int A,B;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> A >> B;

	if(A>9 || B>9) {
		cout << -1 << endl;
	}
	else {
		cout << A*B << endl;
	}

	return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int a,b,i,x[5],cnt,j,c;
	scanf("%d %d",&a,&b);
	cnt=0;
	for(i=a;i<=b;i++)	{
		c=i;
		for(j=0;j<5;j++)	{
			x[j]=c%10;
			c=c/10;
		}
		if(x[0]==x[4] && x[1]==x[3])	cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}
		

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll H, W, K;
    cin >> H >> W >> K;

    vector<string> s(H);
    REP(i, H) cin >> s[i];

    ll res[303][303];
    REP(i, 303)REP(j, 303) res[i][j] = 0;

    vector<ll> rowsum(303, 0);
    REP(i, H){
    	ll tmp = 0;
    	REP(j, W){
    		if(s[i][j] == '#') tmp++;
    	}
    	rowsum[i] = tmp;
    }

    ll idx = 1;
    REP(i, H){
    	if(rowsum[i]==0) continue;
    	ll cnt = 0;
    	REP(j, W){
    		if(s[i][j] == '#') cnt++;
    		if(s[i][j] == '#' && cnt>1) idx++;
    		res[i][j] = idx;
    	}
    	idx++;
    }

    REP(j, W){
    	ll idx;
    	REP(i, H){
    		if(res[i][j] != 0){
    			idx = i;
    			break;
    		}
    	}
    	REP(i, idx) res[i][j] = res[idx][j];
    	ll now = res[idx][j];
    	ll pos = idx;
    	while(pos<H){
    		if(res[pos][j] == 0) res[pos][j] = now;
    		else now = res[pos][j];
    		pos++;
    	}
    }

    REP(i, H){
    	REP(j, W){
    		cout<< res[i][j] << " ";
    	}
    	cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;
  ll value = n;

  ll ans = value % k;

  if (ans == 0){
    cout << 0 << endl;
    return 0;
  } else {
    while (ans > abs(ans -k)){
      ans = abs(ans - k);
    }
  }

  cout << ans << endl;
}

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

int main()
{

ll n,k;
cin>>n>>k;

ll a=0;
for(ll i=0;i<n;i++) {
	ll x;
	cin>>x;
	if(x>=k)
	a++;
}
cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 3624
N,Y = gets.chomp.split.map(&:to_i)
ret = [0,0,Y/1000]
if ret.inject(:+)>N
	ret[1] = [(ret.inject(:+)-N)/4,ret[2]/5].min
	ret[2] -= ret[1]*5
	if ret.inject(:+)>N
		ret[0] = [(ret.inject(:+)-N),ret[1]/2].min
		ret[1] -= ret[0]*2
	end
end
if ret.inject(:+)==N
	print "#{ret.join(" ")}\n"
else
	print "-1 -1 -1\n"
end

Measured memory_bytes: 1788
#変数でなく定義で、クラス内参照おk
ARRAY = [512, 256 , 128, 64, 32, 16, 8, 4, 2, 1]

while tmp = gets
  break if tmp == nil
  tmp = tmp.to_i
  tmp_hash = Hash.new
  ARRAY.each do |i|
    if  tmp / i  > 0
      tmp_hash[i] =tmp / i
      tmp = tmp - (i * (tmp/i))
    else
      next
    end
  end
  #最終出力
  puts tmp_hash.keys.reverse.join(" ")
end


Measured memory_bytes: 6872
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

C = [0] * N
cnt = 0
for n in range(1, N):
    if S[n - 1:n+1] == "AC":
        cnt += 1
    C[n] = cnt

for q in range(Q):
    l, r = LR[q]
    print(C[r-1] - C[l-1])


Measured memory_bytes: 30640
def hantei(s):
    S=[]
    for i in range(len(s)-2):
        S.append(s[i:i+3])

    for i in range(len(S)):
        w=S[i]
        if w[0]==w[1]==w[2]:
            return True
        

n=list(input())
if hantei(n):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   unik(v)       v.erase(unique(all(v)),v.end())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
void solve()
{
    ll x,y;
    cin>>x>>y;
    for(ll i=0;i<=100;i++){
        for(ll j=0;j<=100;j++){
            ll g=2*i+4*j;
            if(i+j==x && g==y){
                cout << "Yes"<<"\n";
                return;
            }
        }
    }
    cout <<"No"<<"\n";
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	long long int a,b,c,mx=0;
	cin>>a>>b>>c;
	long long int d[a+1], e[b+1];
	vector<long long int> x(a+1,0), y(b+1,0);
	for(int i=1; i<=a; i++)
		cin>>d[i], x[i]=x[i-1]+d[i];
	for(int i=1; i<=b; i++)
		cin>>e[i], y[i]=y[i-1]+e[i];
	long long int ct=0, l=0, k=0;
	for(int i=1; i<=a; i++)
	{
		long long int k=c-x[i], pos=0, l=1, r=b, m=0;
		if(x[i]>c)
			continue;
		while(l<=r)
		{
			m=(l+r)/2;
			if(y[m]>k)
				r=m-1;
			else
				l=m+1;
		}
		r=min(b,r);
		pos=r;
		mx=max(mx, pos+i);
	}
	forr(i,1,b+1)
	{
		long long int k=c-y[i], pos=0, l=1, r=a, m=0;
		if(y[i]>c)
			continue;
		while(l<=r)
		{
			m=(l+r)/2;
			if(x[m]>k)
				r=m-1;
			else
				l=m+1;
		}
		pos=r;
		mx=max(mx, pos+i);
	}	
	cout<<mx;
	
	return 0; 	
}

Measured memory_bytes: 9516
N = int(input())
ss = [input() for _ in range(N)]

BA,A,B = 0,0,0
AB = 0
for s in ss:
    if s[0] == 'B' and s[-1] == 'A':
        BA += 1
    elif s[0] == 'B':
        B += 1
    elif s[-1] == 'A':
        A += 1
        
    for i in range(len(s)-1):
        if s[i] == 'A' and s[i+1] == 'B':
            AB += 1
            
if BA == 0:
    AB += min(A,B)
else:
    AB += BA-1
    if A > 0:
        AB += 1
        A -= 1
    if B > 0:
        AB += 1
        B -= 1
    AB += min(A,B)

print(AB)

Measured memory_bytes: 3700
#include <stdio.h>

int N; long long A[10010], AS, B[10010], BS, AU, BU;

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]); AS += A[i];
	}
	for (int i = 0; i < N; i++) {
		scanf("%lld", &B[i]); BS += B[i];
		if (A[i] > B[i]) BU += A[i] - B[i];
		else {
			if (A[i] % 2 != B[i] % 2) BU++;
			AU += (B[i] + 1 - A[i]) / 2;
		}
	}

	if (AS > BS || BS - AS < AU || BS - AS < BU || (BS - AS - AU) * 2 != (BS - AS - BU)) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 256
while True:
  n = int(input())
  if n == 0:
    break
  for _ in range(n):
    x1, y1, z1, w1, x2, y2, z2, w2 = map(int, input().split())
    x3 = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2
    y3 = x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2
    z3 = x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2
    w3 = x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2
    print(x3, y3, z3, w3)


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

typedef pair<int, int> P;
vector<vector<char>> field;
vector<vector<int>> dist;

int main() {
  int h, w;
  int ng = 0;
  cin >> h >> w;
  field.resize(h, vector<char>(w));
  dist.resize(h, vector<int>(w, -1));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> field[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (field[i][j] == '#') ng++;
    }
  }
  dist[0][0] = 1;

  queue<P> que;
  que.push(P(0, 0));
  
  int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
  while (!que.empty()) {
    P p = que.front(); que.pop();
    int y = p.first, x = p.second;
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny >= 0 && ny < h && nx >= 0 && nx < w && field[ny][nx] == '.' && dist[ny][nx] == -1) {
        dist[ny][nx] = dist[y][x] + 1;
        que.push(P(ny, nx));
      }
    }    
  }
  if (dist[h-1][w-1] == -1) cout << -1 << endl;
  else cout << h * w - ng - dist[h-1][w-1] << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n, m, x;
	cin >> n >> m >> x;

	vector<ll> a(n + 1);
	for (ll i = 0; i < m; i++)
	{
		ll y;
		cin >> y;

		a[y] = 1;
	}

	ll r0 = 0;
	for (ll i = 0; i <= x; i++)
	{
		if (a[i] == 1)
		{
			r0++;
		}
	}

	ll r1 = 0;
	for (ll i = x; i <= n; i++)
	{
		if (a[i] == 1)
		{
			r1++;
		}
	}

	println(min(r0, r1));
}

Measured memory_bytes: 256
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def prime_decomposition(n):
  i = 2
  d = {}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d

def eratosthenes(n):
    if n < 2:
        return []
    prime = []
    limit = n**0.5
    numbers = [i for i in range(2,n+1)]
    while True:
        p = numbers[0]
        if limit <= p:
            return prime + numbers
        prime.append(p)
        numbers = [i for i in numbers if i%p != 0]
    return prime

N = int(input())
A = [int(input()) for i in range(N+1)]
g = abs(A[0])
for a in A:
     g = gcd(g,abs(a))
d = prime_decomposition(g)
ans = [p for p in d]

prime = eratosthenes(N+1)
A.reverse()
for p in prime:
    if A[0]%p != 0:
        continue
    for n in range(1,p):
        s = 0
        for k in range(int((N-n)/(p-1))+1):
            s += A[n+k*(p-1)]
            s %= p
        if s != 0:
            break
    if s == 0:
        ans.append(p)

ans = list(set(ans))
ans.sort()

for p in ans:
    print(p)


Measured memory_bytes: 46808
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()

int n;
ll a[100]={2, 1};
int main(){
    fox1(l, 90){
        a[l+1]=a[l]+a[l-1];
    }
    cin >> n;
    cout << a[n];
    return 0;
}


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

int main()
{
  int r;
  cin >> r;
  
  if(r < 1200){
    cout << "ABC" << endl;
  }else if(r < 2800){
    cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;    
  }
  
  return 0;
}

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

int main() {
  long n;
  cin>>n;
  if(n<4||n==5||n==6||n==9||n==10||n==13||n==17){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 3640
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));
$a[-1] = $a[] = $s = 0;
$d[0] = abs($a[0]);
for ($i = 0; $i < $n; $i++) {
	$d[$i+1] = abs($a[$i+1] - $a[$i]);
	$s += $d[$i];
	$x[$i] = $d[$i] + $d[$i+1] - abs($a[$i+1] - $a[$i-1]);
}
$s += abs($a[$n-1]);
for ($i = 0; $i < $n; $i++) {
	echo $s - $x[$i], "\n";
}

Measured memory_bytes: 21108
import sys
input = sys.stdin.readline
import math


def read():
    N = int(input().strip())
    X = input().strip()
    return N, X


def bitdiv(N:int, X:str, d:int):
    q = 0
    for i in range(N):
        q <<= 1
        q |= int(X[i])
        p, q = divmod(q, d)
    return q


def solve(N, X):
    BP = [0 for i in range(N)]
    BM = [0 for i in range(N)]

    c = X.count("1")
    

    # 2^k mod (c+1) を高速に求める
    qp = int(X, base=2) % (c+1)
    BP[N-1] = 1 % (c+1)
    for i in range(N-2, -1, -1):
        BP[i] = (BP[i+1] * 2) % (c+1)
    
    # 2^k mod (c-1) を高速に求める
    if c > 1:
        qm = int(X, base=2) % (c-1)
        BM[N-1] = 1 % (c-1)
        for i in range(N-2, -1, -1):
            BM[i] = (BM[i+1] * 2) % (c-1)

    for i in range(N):
        q = 0
        ans = 0
        if X[i] == "0":
            # X_i \equiv (X + 2^i)
            q = (qp + BP[i]) % (c+1)
            ans += 1
        elif X[i] == "1" and c > 1:
            # X_i \equiv (X - 2^i)
            q = (qm - BM[i]) % (c-1)
            ans += 1
        else:
            q = 0
            ans = 0
        while q > 0:
            q %= (bin(q).count("1"))
            ans += 1
        print(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 25376
#pragma GCC optimize ("Ofast")
#include"bits/stdc++.h"
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); } } ___;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);
}

#define ll long long
#define pii pair<int,int>
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define endll '\n'
#define rep(i,n) for(int i=0;i++<n;)
#define scl(i) scanf("%lld",&i)
#define int long long int
#define all(n) n.begin(),n.end()
#define mem(n,i) memset(n,i,sizeof n)
#define em(a) emplace_back(a)
#define pb(a) push_back(a)
#define srep(it,vv) for(auto &it : vv)
#define prep(it,vv) for(auto it : vv)
//vector<vector<int>>arr(n + 5, vector<int>(m + 5,0));

typedef vector<int> vii;
typedef vector<string> vss;
/*

*/
signed main()
{

	int n; cin >> n;
	std::vector<int> vv(n + 5);
	std::vector<int> dp(n + 5);

	rep(i, n) cin >> vv[i];

	dp[n] = 0;

	for (int i = n - 1; i >= 1; i--)
	{
		int x1 = dp[i + 1] + abs(vv[i] - vv[i + 1]);
		int x2 = INT_MAX;
		if (i + 2 <= n) x2 = dp[i + 2] + abs(vv[i] - vv[i + 2]);
		dp[i] = min(x1, x2);
	}
	cout << dp[1] << endll;

}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;


int main ()
{

double a,b,ans;
cin >> a >> b ;
ans=a/b;

cout << fixed << setprecision(10) << ans << endl ;

	return 0;
}











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

int main(){
	int a,b,c,d;
	int area1,area2;
	cin >> a >> b>> c >> d;
	area1 = a*b;
	area2 = c*d;
	if(area1 == area2) cout << area1;
	else cout << max(area1,area2) <<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    String[] a = new String[n];

    for (int i = 0; i < n; i++) {
      a[i] = sc.next();
    }

    sc.close();

    Deque<String> deque = new ArrayDeque<>();

    if (n % 2 == 0) {
      for (int i = 0; i < n; i++) {
        if (i % 2 == 0){
          deque.addLast(a[i]);
        } else {
          deque.addFirst(a[i]);
        }
      }
    } else {
      for (int i = 0; i < n; i++) {
        if (i % 2 == 0){
          deque.addFirst(a[i]);
        } else {
          deque.addLast(a[i]);
        }
      }
    }
    
    PrintWriter out = new PrintWriter(System.out);

    int size = deque.size();

    for (int i = 0; i < size; i++) {
      out.print(deque.pollFirst()) ;
      if (i != size - 1) {
        out.print(" ");
      }
    }
    out.println("");

    out.flush();

  }

}


Measured memory_bytes: 74132
from collections import deque
def color_available(unavailable, K):
    idx = 0
    L = len(unavailable)
    unavailable = sorted(unavailable)
    for color in range(K):
        if idx < L and color == unavailable[idx]:
            idx += 1
        else:
            yield color

def bfs(graph, N, K, start):
    colors = [dict() for _ in range(N)]
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        gen = color_available(colors[node].values(), K)
        for n in graph[node]:
            if not visited[n]:
                visited[n] = 1
                colors[node][n] = colors[n][node] = next(gen)
                que.append(n)
    return colors

N = int(input())
graph = [[] for _ in range(N)]
inputs = tuple(tuple(map(lambda n: int(n) - 1, input().split())) for _ in range(N - 1))
counts = [0] * N
for i, j in inputs:
    graph[i].append(j)
    graph[j].append(i)
    counts[i] += 1
    counts[j] += 1
K = max(counts)
colors = bfs(graph, N, K, 0)
print(K)
for i, j in inputs:
    print(colors[i][j] + 1)

Measured memory_bytes: 62132
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

int end_num(int n){
    return n % 10;
}

int top_num(int n){
    if (n < 10) return n;
    else if(n < 100) return n / 10;
    else if(n < 1000) return n / 100;
    else if(n < 10000) return n / 1000;
    else if(n < 100000) return n / 10000;
    else if(n < 1000000) return n / 100000;
    return -1;
}

int N;
ll P[100];
int main(void){
    cin >> N;
    for(int i = 1;i <= N;i++){
        P[top_num(i) * 10 + end_num(i)] += 1;
    }

    ll count = 0;
    for(int i = 1;i <= 9;i++)
        for(int j = 1;j <= 9;j++)
            count += P[10*i+j] * P[10*j+i];
    cout << count << endl;
    return 0;
}



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

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

  int cnt=0;
  for(int i=1;i<=N;i++){
    if(i%2==1) cnt++;
  }

  double res = (double)cnt/(double)N;
  
  printf("%.16f\n", res);
}



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

int main()
{
    int N;
    int K;

    // input
    std::cin >> N >> K;
    std::vector<int> v(N);

    for (int i = 0; i < v.size(); i++)
    {
        int h;
        std::cin >> h;
        v[i] = h;
    }

    // solve
    int cnt = 0;
    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] >= K)
        {
            cnt++;
        }
    }

    // answer
    std::cout << cnt << std::endl;
}


Measured memory_bytes: 764
object Main extends App{
  import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
  val in=new BufferedReader(new InputStreamReader(System.in))
  val out = new PrintWriter(new BufferedOutputStream(System.out))
  val Array(n,m) = in.readLine().split(" ").map(_.toInt)
  val h = in.readLine().split(" ").map(_.toInt)
  var map=scala.collection.mutable.HashMap[Int,Int]()
  for{i <- (0 until m)}{
    val Array(a, b) = in.readLine().split(" ").map(_.toInt)
    if(h(a-1) < h(b-1)){
      map(a) = if(map.contains(a)) map(a) + 1 else 1
    }
    if(h(a-1) > h(b-1)){
      map(b) = if(map.contains(b)) map(b) + 1 else 1
    }
    if(h(a-1) == h(b-1)){
      map(a) = if(map.contains(a)) map(a) + 1 else 1
      map(b) = if(map.contains(b)) map(b) + 1 else 1
    }
  }
  out.println(n - map.toSeq.size)
  out.flush()
}

Measured memory_bytes: 67600
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]

for a,b in ab:
    ans = []
    for c,d in cd:
        ans.append(abs(a-c)+abs(b-d))
    print(ans.index(min(ans))+1)

Measured memory_bytes: 9136
import java.util.*;
 
class Main{
    public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		int[] a = new int[6];
		int[] b = new int[6];
		for(int i=0; i<6; i++){
			a[i] = scan.nextInt();
		}
		for(int i=0; i<6; i++){
			b[i] = scan.nextInt();
		}
		Dice xai1 = new Dice(a);
		Dice xai2 = new Dice(b);
		System.out.println(xai2.cheakSameDice(xai1, xai2));
    }
}

class Dice{
	int[] dice;
	public Dice(int[] a){
		dice = new int[6];
		for(int i=0; i<6; i++){
			dice[i] = a[i];
		}
	}
	public void roll(char c){
		int tmp = 0;
		switch(c){
			case 'N':
				tmp = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = tmp;
				break;
			case 'W':
				tmp = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = tmp;
				break;
			case 'S':
				tmp = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = tmp;
				break;
			case 'E':
				tmp = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = tmp;
				break;
		}
	}
	public void rotation(){ //???????????????????¨???????????????????
		int tmp = dice[1];
		dice[1] = dice[2];
		dice[2] = dice[4];
		dice[4] = dice[3];
		dice[3] = tmp;
	}

	public String cheakSameDice(Dice xai1, Dice xai2){
		for(int i=0; i<6; i++){
			for(int j=0; j<6; j++){
				xai2.roll('N');
				if(checkSurface(xai1, xai2))return "Yes";
				xai2.roll('W');
				if(checkSurface(xai1, xai2))return "Yes";
			}
			xai2.rotation();
			if(checkSurface(xai1, xai2))return "Yes";
		}
		for(int i=0; i<6; i++){
			for(int j=0; j<6; j++){
				xai2.roll('N');
				if(checkSurface(xai1, xai2))return "Yes";
				xai2.roll('E');
				if(checkSurface(xai1, xai2))return "Yes";
			}
			xai2.rotation();
			if(checkSurface(xai1, xai2))return "Yes";
		}
		for(int i=0; i<6; i++){
			for(int j=0; j<6; j++){
				xai2.roll('S');
				if(checkSurface(xai1, xai2))return "Yes";
				xai2.roll('W');
				if(checkSurface(xai1, xai2))return "Yes";
			}
			xai2.rotation();
			if(checkSurface(xai1, xai2))return "Yes";
		}
		for(int i=0; i<6; i++){
			for(int j=0; j<6; j++){
				xai2.roll('S');
				if(checkSurface(xai1, xai2))return "Yes";
				xai2.roll('E');
				if(checkSurface(xai1, xai2))return "Yes";
			}
			xai2.rotation();
			if(checkSurface(xai1, xai2))return "Yes";
		}
		return "No";
	}

	public boolean checkSurface(Dice xai1, Dice xai2){
		if(xai1.dice[0]==xai2.dice[0] && xai1.dice[1]==xai2.dice[1] && xai1.dice[2]==xai2.dice[2] && xai1.dice[3]==xai2.dice[3] && xai1.dice[4]==xai2.dice[4] && xai1.dice[5]==xai2.dice[5]){
			return true;
		}
		return false;
	}

	public int showTop(){
		return dice[0];
	}
}

Measured memory_bytes: 26440
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int N,K,T,U,V,L;
queue<int>C;
int main()
{
	scanf("%d%d%d%d%d%d",&N,&K,&T,&U,&V,&L);
	for(int i=0;i<N;i++)
	{
		int t;
		scanf("%d",&t);
		C.push(t);
	}
	C.push(L);//goal

	int c=0,f=0,p=0;
	double t=0,tmp=0;
	while(!C.empty()||tmp>p)
	{
		if(tmp<=p)
		{
			tmp=C.front();C.pop();
		}
		if(f)
		{
			p+=T*V;
			t+=T;
			while(!C.empty()&&tmp<=p)
			{
				c++;
				if(c>K)
				{
					int nr=T*V-(p-tmp);
					c=K;
					p+=nr;
					t+=1.0*nr/V;
				}
				tmp=C.front();
				C.pop();
				if(tmp>p)break;
			}
			if(c==0)f=0;
			else c--;
		}
		else
		{
			t+=(1.0*tmp-p)/U;
			p=tmp;
			f=1;
		}
	}
	if(p>L)t-=(1.0*p-L)/V;
	printf("%.10f\n",t);
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#define inf ((1<<30)-1)
#define linf ((1<<62)ll-1)
#define LL long long
#define F(i,a,b,c) for(register int i=(a);(b);i=(c))
#define Fu(i,a,b) for(register int i=(a);i<=(b);++i)
#define Fd(i,a,b) for(register int i=(a);i>=(b);--i)
#define COND(c) (isprint(c))
int Fl,Pn,SI=100;char mch=' ',ch,Bf[21];
void chin(char&c){while(!COND(c=getchar()));}
template<typename t>int in(t&a){a=0;ch=getchar();Fl=1;while(((ch<'0')||(ch>'9'))&&ch!=EOF)Fl=(ch=='-')?-Fl:Fl,ch=getchar();if(ch==EOF)return 0;while((ch>='0')&&(ch<='9'))a=a*10+ch-'0',ch=getchar();a*=Fl;return 1;}template<typename t>void out(t a){if(a<0)putchar('-'),a=-a;if(a==0)putchar('0');while(a)Bf[++Pn]=a%10+'0',a/=10;while(Pn)putchar(Bf[Pn]),--Pn;putchar(mch);}
template<typename t,typename ...ARGS>int in(t&a,ARGS&...args){return in(a)+in(args...);}template<typename t,typename ...ARGS>void out(t a,ARGS... args){out(a);out(args...);}
using namespace std;
int n,m,s,ans;
int main()
{
	in(n,m);
	Fu(i,1,n)
	{
		in(s);
		if(s<=m>>1)ans+=s<<1;
		else ans+=(m-s)<<1;
	}
	out(ans);puts("");
	return 0;
}
//BY Segment_Tree_Juruo (2020严誉沣)


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,s;
	cin>>a;
	s=a%10;
	if(s==2 || s==4 || s==5 || s==7 || s==9)
	{
		cout<<"hon"<<endl;
		return 0;
	}
	if(s==0 || s==1 || s==6 || s==8)
	{
		cout<<"pon"<<endl;
		return 0;
	}
	if(s==3)
	{
		cout<<"bon"<<endl;
		return 0;
	}
}


Measured memory_bytes: 3636
Module Program
  Sub Main
    Dim s = GetInts()
    Dim a=s(0),b=s(1),c=s(2)
    Dim ans=a+b+c+Math.Max(a,Math.Max(b,c))*9
    Console.WriteLine(ans)
  End Sub
  
  ' /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 22352
from itertools import groupby
def solve(S):
    N = len(S)
    groups = []
    for k, grp in groupby(S):
        w = len(list(grp))
        groups.append((k, w))

    ans = [0] * N
    ix = 0
    for i in xrange(0, len(groups), 2):
        w1, w2 = groups[i][1], groups[i+1][1]
        ans[ix + w1 - 1] += w1 / 2 + w1 % 2
        ans[ix + w1] += w1 / 2
        ans[ix + w1] += w2 / 2 + w2 % 2
        ans[ix + w1 - 1] += w2 / 2
        ix += w1 + w2
    return ans
    
print ' '.join(map(str, solve(raw_input())))


Measured memory_bytes: 45340
from collections import deque #シーケンスのどちらの端でも要素を追加、削除できるようにしたいときに便利

number_of_execution, rotation_time = map(int, input().split())
queue = deque([])  #順番を作る為、１x複数の行列

for i in range(number_of_execution):
    process_name, execution_time = input().split()
    time = int(execution_time)
    queue.append([process_name, time])

passed_time = 0
while len(queue) > 0:
    running_process = queue.popleft()
    passed_time += min(running_process[1], rotation_time)
    running_process[1] -= rotation_time
    if running_process[1] > 0:
        queue.append(running_process)
    else:
        print('{} {}'.format(running_process[0], passed_time))


Measured memory_bytes: 13304
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

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



Measured memory_bytes: 3592
N = int(input())
a = []
for i in range(N):
    a.append(list(map(str, input().split())))

ss=[]
for i in range(N):
    if a[i][1] == 'JPY':
        ss.append( float(a[i][0]))
    elif a[i][1] == 'BTC':
        ss.append(float(a[i][0])*380000.0)

print(sum(ss))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

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

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    for (int iy = 0; iy < h; iy++) {
        for (int ix = 0; ix < w; ix++) {
            if (s[iy][ix] == '.') {
                continue;
            }
            bool okay = false;
            for (int k = 0; k < 4; k++) {
                int y = iy + dy[k];
                int x = ix + dx[k];
                if (0 <= x && 0 <= y && x < w && y < h && s[y][x] == '#')
                {
                    okay = true;
                    break;
                }
            }
            if (okay == false) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

vector<pair<int, int>> edge[100];
int dist[100][100];

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

  rep (i, N) rep (j, N) dist[i][j] = (i == j) ? 0 : INF;

  rep (i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    edge[a].eb(mp(b, c));
    edge[b].eb(mp(a, c));
    dist[a][b] = dist[b][a] = c;
  }

  rep (k, N) rep (i, N) rep (j, N) {
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  }

  int ans = 0;
  rep (i, N) rep (j, edge[i].size()) {
    int from = i;
    int to = edge[i][j].F;
    int d = edge[i][j].S;

    bool flg = true;
    rep (p, N) rep (q, N) if (dist[p][q] == dist[p][from] + d + dist[to][q]) flg = false;

    if (flg) ans++;
  }

  cout << ans / 2 << endl;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int main(){
    cin.sync_with_stdio(false);
    int n;
    while(cin >> n, n) {
        int key[n];
        rep(i, n) cin >> key[i];
        string s;
        cin >> s;
        int i = 0;
        rep(j, s.size()) {
            if ('a' <= s[j] && s[j] <= 'z') {
                if (key[i] <= 26) {
                    if (s[j] - 'a' >= key[i]) s[j] = (char)(s[j] - key[i]);
                    else s[j] = (char)('Z' - (key[i] - (s[j] - 'a') - 1));
                } else {
                    s[j] = (char)(s[j] + ('A' - 'a'));
                    if (s[j] - 'A' >= key[i] - 26) s[j] = (char)(s[j] - key[i] + 26);
                    else s[j] = (char)('z' - (key[i] - (s[j] - 'A') - 27));
                }
                i = (i + 1) % n;
            } else {
                if (key[i] <= 26) {
                    if (s[j] - 'A' >= key[i]) s[j] = (char)(s[j] - key[i]);
                    else s[j] = (char)('z' - (key[i] - (s[j] - 'A') - 1));
                } else {
                    s[j] = (char)(s[j] - ('A' - 'a'));
                    if (s[j] - 'a' >= key[i] - 26) s[j] = (char)(s[j] - key[i] + 26);
                    else s[j] = (char)('Z' - (key[i] - (s[j] - 'a') - 27));
                }
                i = (i + 1) % n;
            }
        }
        cout << s << endl;
    }

    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b;
  cin >> n;
  vector<ll> ans(1000010);
  ans[0] = 0;
  rep(i,n){
    cin >> a >> b;
    /* if(a) a--; */
    /* if(b) b--; */
    --a;
    ans[a] ++;
    ans[b] --;
  }
  rep(i,100001){
    ans[i+1] += ans[i];
  }
  ll k = 0;
  REP(i,0,n+1){
    if(ans[i] >= i)
      k = max(k,i+ 0LL); 
  }
  cout << k << endl;
  return 0;
}

Measured memory_bytes: 10696
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd

def resolve():
    N = 8

    # すでに配置されたクイーンの効きが及ばない位置であればTrueを返す
    def check(row, FR):
        # まず横の効きで取られないかチェックする
        # すでにクイーンの配置された行だとダメ
        if row in FR:
            return False

        # 次に斜めの効きで取られないかチェックする
        # enumerate関数により、リストFRの添字fc(filled_column)と要素fr(filled_row)を取得
        for fc, fr in enumerate(FR):
            # distだけ離れた列fcが着目されている
            dist = len(FR) - fc
            # 左上あるいは左下にクイーンがあったらアウト
            if (row == fr - dist) or \
                    (row == fr + dist):
                return False
        return True

    # クイーンの可能な配置をすべてprintする関数
    def search(FR):
        # FRはFilled Rowsの略。
        # 第column列のFR[column]行目にすでにクイーンが配置済みであることを意味する。

        # すべての列に配置でき次第出力。クイーンのある位置を黒く塗りつぶす
        if len(FR) == N:
            for i in range(M):
                if FR[X[i]] != Y[i]:
                    break
                elif i==M-1:
                    for k in range(N):
                        for j in range(N):
                            print('Q' if FR[k] == j else '.', end='')
                        print()
                    return

        # クイーンを配置した行数を格納するリストFRを作成
        for row in range(N):
            if check(row, FR):
                FR.append(row)
                # 再帰的に探索する。「以下同様」という意味。
                search(FR)
                # どの行に入れても無理だと判明したら、
                # 最後の行をpopし、もう１回ループを回して別の行でいけないかと模索する
                FR.pop()


    M=int(input())
    X,Y = [0] * M, [0] * M
    for i in range(M):
        X[i], Y[i] = map(int, input().split())

    search([])


resolve()


Measured memory_bytes: 5616
def solve():
    N,M = map(int, input().split())
    A = list(map(int, input().split()))
    sm = sum(A)
    cnt = 0
    for a in A:
        if a >= sm / (4 * M):
            cnt += 1
    
    if cnt >= M:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
#include <iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

int retl(int K,int L){
    int tmp=0;
    while(pow(2,tmp) * L < K){
        tmp++;
    }
    return tmp;
}

struct A{
    string s;
    int p;
    int order;
};


int main(){
    int N,L;

    cin >>N>>L;
    
    int azi[N];
    int azisum=0;
    FOR(i,N){
        int tmp=L+i;
        azi[i]=tmp;
        azisum+=tmp;
        //cout << azi[i];
    }

    int difminpointer=-1;
    int dif=pow(10,5);
    FOR(i,N){
        if(abs(azi[i])<dif){
            dif=abs(azi[i]);
            difminpointer=i;
        }
    }

    cout<<azisum - azi[difminpointer]<< endl;

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;


template <typename T>
using TABLE = vector<vector<T>>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


TABLE<int> buf;
TABLE<int> integral;


int checkMin(vector<int> pattern, int K){
    int cut_num = 0;
    int prev_w = 0;

    int cur_w = 1;

    while(cur_w <= buf[0].size()){
        bool check = true;

        for(int j = 1; j < pattern.size(); ++j){
            int pos = pattern[j];
            int prev_h = pattern[j-1];

            int choco_num = integral[pos][cur_w] - integral[prev_h][cur_w] - integral[pos][prev_w] + integral[prev_h][prev_w];
            if(choco_num > K){
                check = false;
                break;
            }
        }

        if(!check){
            if(cur_w - 1 == prev_w){
                return buf[0].size() * 20;
            }

            prev_w = cur_w - 1;
            ++cut_num;
        }
        else{
            ++cur_w;
        }
    }

    return cut_num + pattern.size() - 2;
}



int main(){
    int H, W, K;
    cin >> H >> W >> K;

    string S;

    buf.resize(H, vector<int>(W, 0));
    integral.resize(H + 1, vector<int>(W + 1, 0));

    for(int i = 0; i < H; ++i){
        cin >> S;
        for(int j = 0; j < W; ++j){
            if(S[j] == '1'){
                buf[i][j] = 1;
            }
        }
    }

    integral[1][1] = buf[0][0];

    for(int i = 1; i < W; ++i){
        integral[1][i + 1] = integral[1][i] + buf[0][i];
    }
    for(int i = 1; i < H; ++i){
        integral[i + 1][1] = integral[i][1] + buf[i][0];
    }

    for(int y = 2; y < H + 1; ++y){
        for(int x = 2; x < W + 1; ++x){
            integral[y][x] = integral[y][x - 1] + integral[y - 1][x] - integral[y - 1][x - 1];
            if(buf[y - 1][x - 1] == 1){
                integral[y][x] += 1;
            }

        }
    }

    int min_try = numeric_limits<int>().max();
    int max_iter = 1 << H - 1;

    for(int i = 0; i < max_iter; ++i){
        vector<int> pattern;
        pattern.push_back(0);
        for(int b = 0; b < H - 1; ++b){
            if(i & (1 << b)){
                pattern.push_back(b + 1);
            }
        }
        pattern.push_back(H);

        min_try = min(checkMin(pattern, K), min_try);
    }

    cout << min_try;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MP make_first
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 2e5 + 5;
char s[N];
int cnt[N], en[N], fi[N];
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n, k; cin >> n >> k;
    cin >> s + 1;
    int num = 0;
    s[0] = '1'; s[n + 1] = '1';
    for(int i = 1; i <= n + 1; i++) {
        if(s[i] == '1') {
            if(s[i - 1] == '0') en[num] = i;
            continue;
        }
        if(s[i - 1] == '1') ++num, fi[num] = i;
        ++cnt[num];
    }
    int ans = 0;
    fi[num + 1] = n + 1; en[0] = 1;
    for(int i = 1; i <= num; i++) {
        int j = min(i + k - 1, num);
        ans = max(ans, fi[j + 1] - en[i - 1]);
    }
    if(num == 0) ans = n;
    cout << ans;
    return 0;
}


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

int main() {
	int N, X;
	cin >> N >> X;
	vector<int> D(N + 1);
	int ans = N + 1, flag = 0;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		D.at(i + 1) = D.at(i) + tmp;
		if (D.at(i + 1) > X && flag == 0) {
			ans = i + 1;
			flag = 1;
		}
	}
	cout << ans << endl;
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

const int N = 10;

int a[N], b[N], d[N];
int n, ans = 2e9;

void check() {
  vector<int> c(4);
  int cal = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] && c[b[i]]) cal += 10;
    c[b[i]] += a[i];
  }
  for (int i = 1; i <= 3; i++) {
    if (c[i] == 0) return;
    cal += abs(c[i] - d[i]);
  }
  ans = min(ans, cal);
}

void brute(int i) {
  for (int j = 0; j <= 3; j++) {
    b[i] = j;
    if (i == n) check();
    else brute(i + 1);
  }
}

void MAIN() {
  cin >> n;
  cin >> d[1] >> d[2] >> d[3];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  brute(1);
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3652