akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))

# 矛盾チェック
from collections import Counter
c = Counter(a)

def check():
    if n&1:
        if c[0]!=1:
            return False
        for i in range((n-1)//2):
            if c[2*(i+1)] != 2:
                return False
    else:
        for i in range(n//2):
            if c[2*i+1] != 2:
                return False
    return True

if not check():
    print(0)
    exit()

print(pow(2, n//2, 10**9+7))

Measured memory_bytes: 20420
import Data.List(minimum)
opA :: Int -> Int
opA i = 2 * i


opB :: Int -> Int -> Int
opB i k = i + k

choose :: Int -> Int -> Int
choose i k = minimum [reA, reB]
  where
    reA = opA i
    reB = opB i k

likeFor :: [Int] -> Int -> [Int] -> [Int]
likeFor [] k acc = acc
likeFor src k acc = likeFor (tail src) k acc'
  where
    acc' = (choose (head acc) k) : acc

main = do
  ns <- fmap (fmap (read :: String -> Int) . words) . lines <$> getContents
  let n = head $ head ns
  let k = head $ last ns
  let result = likeFor (replicate n 0) k [1]
  putStrLn $ show $ head result

Measured memory_bytes: 508
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
a,b,k=map(int,input().split())
g=math.gcd(a,b)
d=[]
for i in range(1,int(pow(g,0.5))+1):
  if g%i==0:
    d.append(i)
    if g//i not in d:
      d.append(g//i)
d.sort(reverse=True)
print(d[k-1])

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)

struct sieve { 
  vector<bool> isprime;

  void init(size_t max){
    if(max+1 > isprime.size()){     // resizeで要素数が減らないように
        isprime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    isprime[0] = false; // 0は素数ではない
    isprime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(isprime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                isprime[i*j] = false;      // 素数ではない
  }
};


signed main () {
  int n; cin >> n;
  sieve a;
  a.init(60000);
  vector<int> p;
  FOR(i, 1, 55555) if(a.isprime[i]) p.pb(i);

  vector<int> ans;
  REP(i, p.size() - 1) {
    if(p[i] % 5 == 1) ans.pb(p[i]);
  }

  REP(i, n) cout << ans[i] << " ";
}


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

using namespace std;

using int64 = long long;

struct WeightedEdge {
  int from, to;
  int64 weight;
  WeightedEdge(int from, int to, int64 weight)
      : from(from), to(to), weight(weight) {}
};

vector<vector<WeightedEdge>> ReadUndirectedWeightedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<WeightedEdge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    int64 weight;
    cin >> v1 >> v2 >> weight;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(WeightedEdge(v1, v2, weight));
    graph[v2].push_back(WeightedEdge(v2, v1, weight));
  }
  return graph;
}

int64 DiameterOfTree(const vector<vector<WeightedEdge>>& graph) {
  function<tuple<int, int64>(int, int)> dfs =
      [&](int v, int p) -> tuple<int, int64> {
    auto r = make_tuple(v, 0);
    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      int arg;
      int64 value;
      tie(arg, value) = dfs(e.to, v);
      value += e.weight;
      if (get<1>(r) < value) {
        r = make_tuple(arg, value);
      }
    }
    return r;
  };
  int v;
  tie(v, ignore) = dfs(0, -1);
  int64 d;
  tie(ignore, d) = dfs(v, -1);
  return d;
}

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

  int n;
  cin >> n;
  auto graph = ReadUndirectedWeightedGraph(n, n - 1, false);
  cout << DiameterOfTree(graph) << endl;
}


Measured memory_bytes: 20760
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	int n;
	string s;
	cin >> n >> s;
	int cnt = 0;
	rep(i,n-2) {
		if (s.substr(i,3) == "ABC") cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N;
  string S;
  while (cin >> N >> S) {
    int R = count(S.begin(), S.end(), 'R');
    int B = count(S.begin(), S.end(), 'B');
    bool res = R > B;
    cout << (res ? "Yes" : "No") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;




int main(int argc, char *argv[])
{
	int n;

	//input
	cin >> n;

	vector<int> h;

	for (int i = 0; i < n; i++){
		int hi;
		cin >> hi;
		h.push_back(hi);
	}



	//calc
	string ans = "Yes";
	for (int i = 0; i < n; i++){
		if (i == 0){
			h[i]--;
			continue;
		}

		if (h[i - 1] < h[i]){
			h[i]--;
			continue;
		}

		if (h[i - 1] > h[i]){
			ans = "No";
			break;
		}
	}


	//ans
	cout << ans << endl;




	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  double H,A;
  int n;
cin >> H>>A;
  n=ceil(H/A);
  cout <<n<< endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	s := makeS(h, w)
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			fmt.Print(check(s, i, j, h, w))
		}
		fmt.Println()
	}
}

func makeS(h, w int) [][]string {
	s := make([][]string, h)
	for i := 0; i < h; i++ {
		s[i] = make([]string, w)
		var in string
		fmt.Scan(&in)
		for j := 0; j < w; j++ {
			s[i][j] = string(in[j])
		}
	}
	return s
}

func check(s [][]string, i, j, h, w int) string {
	if s[i][j] == "#" {
		return "#"
	}

	cnt := 0
	for y := -1; y <= 1; y++ {
		for x := -1; x <= 1; x++ {
			if i+y == h || i+y == -1 || j+x == w || j+x == -1 || (x == 0 && y == 0) {
				continue
			}
			if s[i+y][j+x] == "#" {
				cnt++
			}
		}
	}
	return fmt.Sprintf("%d", cnt)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define vi vector<int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

ll n,m,a[105],b[105],ans,dp[105][100005];

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    fort (i,n)
        cin >> a[i] >> b[i];
    fort (i,n)
        for (int j = 0; j <= m; ++j)
        {
            if (j<a[i]) dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j], dp[i-1][j-a[i]]+b[i]);
            ans=max(ans, dp[i][j]);
        }
    cout << ans;
}

Measured memory_bytes: 79360
#include <iostream>
using namespace std;
int main(void){
    int n;
    long long k,a[100000],x=0,f=0;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    if(k==0){
        for(int i=0;i<n;i++){
            f+=a[i];
        }
        cout<<f<<endl;
        return 0;
    }
    
    
    for(long long i=40;i>=0;i--){
        int c=0;
        for(int j=0;j<n;j++){
            if(((a[j]>>i)&1)==1){
                c++;
            }
        }
        if(n-c>=c){
            //cout<<i<<"----"<<c<<endl;
            long long l=1,y;
            y=x;
            y+=(l<<i);
            if(y<=k)x=y;
        }
        //cout<<i<<"--"<<x<<endl;
    }
    
    for(int i=0;i<n;i++){
        f+=(x^a[i]);
    }
    cout<<f<<endl;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    int startZero, startOne;
    startZero = 0, startOne = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (i % 2 == 0) {
            if (s[i] == '0') startOne++;
            else startZero++;
        } else {
            if (s[i] == '1') startOne++;
            else startZero++;
        }
    }
    cout << min(startZero, startOne) << endl;
    return 0;
}


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

using namespace std;

int a, b, c, ans;

int main()
{
	scanf("%d%d%d", &a, &b, &c);
	int max_num;
	if (a >= b && a >= c) max_num = a;
	else if (b >= a && b >= c) max_num = b;
	else if (c >= a && c >= b) max_num = c;
	if ((max_num * 3 - a - b - c) % 2) max_num++;
	while(a < max_num) { a += 2; ans++; }
	if (a > max_num) { a -= 2; ans--; }
	while(b < max_num) { b += 2; ans++; }
	if (b > max_num) { b -= 2; ans--; }
	while(c < max_num) { c += 2; ans++; }
	if (c > max_num) { c -= 2; ans--; }
	int res = max_num * 3 - a - b - c;
	if (res == 2) ans++;
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


ll f(ll a) {
  ll div = 2;
  ll res = 0;
  while (div <= 100000000000000) {
    ll b = a % div;
    if (div == 2) {
      if (a % 4 == 1 || a % 4 == 2) res += 1;
    }
    else {
      if (b >= div / 2 && b % 2 == 0) {
        res += div / 2;
      }
    }
    div *= 2;
  }
  //DEBUG(res);
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll ans;
  if (a == 0) {
    ans = f(b);
  }
  else {
    ans = f(b) ^ f(a - 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from sys import stdin

def solve(N, K):
    if K == 1:
        return 0
    else:
        return N - K


if __name__ == '__main__':
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    print(solve(N, K))
    
    # test
    # print(1 == solve(3,2))
    # print(0 == solve(3,1))
    # print(3 == solve(8,5))

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

#define int long long
#define ll long long
#define vll vector<int>
#define mset(a) memset(a,0,sizeof(a))
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<(int)n; ++i)
#define for1(i,n) for(ll i=1; i<(int)n; ++i)
#define endl '\n'
#define MOD 1000000007
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
using namespace std;

vector<bool> sieve(ll n){
    vector<bool>prime(n+1,true);
    prime[0]=prime[1]=false;
    for(ll i=2; i<=n; ++i){
        if(prime[i]&&(i*i)<=n)
        for(ll j=i*i; j<=n; j+=i)prime[j]=false;
    }
    return prime;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//////////////////////////////////////////////////////////////

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

   

    string s1,s2;
    cin>>s1>>s2;
    int n1 = s1.size();
    int n2 = s2.size();

    int dp[n1+1][n2+1];
    mset(dp);
    for1(i,n1+1) {
        for1(j,n2+1) {
            if(s1[i-1] == s2[j-1]) {
                dp[i][j] = dp[i-1][j-1]+1;
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }    

    string res="";

    int r=n1,c=n2;
    while(r!=0 && c!=0) {
        int val = dp[r][c];
        
        if(dp[r-1][c]!=val && dp[r][c-1]!=val) {
            res.pb(s1[r-1]);
            r-=1;
            c-=1;
            continue;
        }

        if(dp[r-1][c] == val){
            r-=1;
            continue;
        }

        if(dp[r][c-1] == val){
            c-=1;
            continue;
        }
    }

    reverse(range(res));
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    int n;
    cin >> n;
    long long a[n];
    for(int i=0; i<n; i++){
        cin >>a[i];
    }
    
    //even positive
    long long ans_even=0;
    long long sum=0;
    for(int i=0; i<n; i++){
        sum+=a[i];
        if(i%2==0){
            if(sum<=0){
                ans_even+=-sum+1;
                sum=1;
            }
        }else{
            if(sum>=0){
                ans_even+=sum+1;
                sum=-1;
            }
        }
    }
    
    long long ans_odd=0;
    sum=0;
    for(int i=0; i<n; i++){
        sum+=a[i];
        if(i%2==0){
            if(sum>=0){
                ans_odd+=sum+1;
                sum=-1;
            }
        }else{
            if(sum<=0){
                ans_odd+=-sum+1;
                sum=1;
            }
        }
    }
    
    cout<<min(ans_odd,ans_even)<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int n,i;
	long long p;
	scanf("%d",&n);
	p=1;
	for(i=1;i<=n;i++)	{
		p*=i;
		p%=1000000007;
	}
	printf("%lld\n",p);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int qt[200005];
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i = 0; i < n ; i++)
	{
		int a;
		scanf("%d",&a);
		qt[a]++;
	}
	set<pair<int,int> >s;
	for(int i = 1; i <= n; i++)
	{
		s.insert({qt[i],i});
	}
	int ans = 0;
	while(s.size()  > k)
	{
		auto a = *s.begin();
		ans += a.first;
		s.erase(s.begin());
	}
	printf("%d\n",ans);
	return 0;
}


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("fibsubseq.in","r",stdin)
#define write()         freopen("fibsubseq.out","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long int
#define endll           pf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps             1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())

bool Check(unsigned int  N,int pos){return (bool)(N & (1LL<<pos));}
ll  Set(unsigned int N,int pos){    return N=N | (1LL<<pos);}
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod  1000000007
#define mod1 1000000009
#define var    int ii,i,j,n,k,m,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

ll a[100005],dp[100005];

ll fn(ll pos,ll k,ll n)
{
    if(pos==n)
    {
        return 0;
    }
    ll &z=dp[pos];
    if(z!=-1)return z;
    z=inf;
    for(ll i=1;i<=k;i++)
    {
        if(pos+i<=n)
        {
            z=min(z,abs(a[pos]-a[pos+i])+fn(pos+i,k,n));
        }
        else break;
    }
    return z;
}

int main()
{
    SPEED;
    ll var;
    mem(dp,-1);
    sfl(n);sfl(k);
    for(i=1;i<=n;i++)sfl(a[i]);
    z=fn(1,k,n);
    cout<<z<<endl;
}


Measured memory_bytes: 8064
#include <stdio.h>

int main(void) {
	int N, A, B, C, D;
	int i;
	int count1 = 0;
	int count2 = 0;

	scanf("%d%d%d%d%d", &N, &A, &B, &C, &D);

	char masu[200001];

	
	scanf("%s", masu);
	

	if (C < D) {
		for (i = A;i <= C-3;i++) {
			if (masu[i] == '#'&& masu[i+1]=='#'){
				count1++;
			}
		}

		for (i = B;i <= D - 3;i++) {
			if (masu[i] == '#' && masu[i + 1] == '#') {
				count1++;
			}
		}

		if (count1 == 0) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	else {
		for (i = A;i <= C - 3;i++) {
			if (masu[i] == '#' && masu[i + 1] == '#') {
				count1++;
			}
		}
		for (i = B - 2;i <= D - 2;i++) {
			if (masu[i] == '.' && masu[i + 1] == '.' && masu[i + 2] == '.') {
				count2++;
			}
		}
		if (count1==0 && count2 > 0) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}

	return 0;

}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    int a, b, c, d, x, y, z;
    scanf ("%d%d%d%d", &a, &b, &c, &d);
   x = abs (a - b);
   y = abs (b - c);
   z = abs (a - c);
   if (1 <= a && a <= 100 && 1 <= b && b <= 100 && 1 <= c && c <= 100 && 1 <= d && d <= 100){
       if (x <= d && y <= d)
       printf ("Yes\n");
       else if (z <= d)
       printf ("Yes\n");
       else
       printf("No\n");
   }
     return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	int n,b,c;
	cin>>n;
	vector<long long int>a(1000000);
	vector<long long int>d(1000000);
	for(int i=0;i<n;i++){
		cin>>a[i];
		d[i]=a[i];
	}
	sort(a.begin(),a.end(),greater<>());
	b=a[n/2-1];
	c=a[n/2];
	for(int i=0;i<n;i++){
		if(d[i]<=c){
			cout<<b<<endl;
		}
		else{
				cout<<c<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 17792
#include <stdio.h>

int main(void){
  long n, k, x, y;
  scanf("%ld %ld", &n, &k);

  x = n%k;
  y = k-x;

  if(x < y) printf("%ld\n", x);
  else printf("%ld\n", y);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	int N;	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	int max = *max_element(a.begin(), a.end());
	int min = *min_element(a.begin(), a.end());
	cout << max - min << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	int x,y,z,a,b,c;
	char d[256];
	scanf("%s",d);
	if (strlen(d) < 3)
	{
		printf("%s",d);
	} else 
	{
		for (x=strlen(d) - 1;x>=0;x--) printf("%c",d[x]);
	}
	return 0;
}

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

const int MOD = (int)1e9+7;

const int MAX=210000;
long long fac[MAX],finv[MAX],inv[MAX];

//テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

//二項係数の計算
long long COM(int n,int k){
  if(n<k) return 0;
  if(n<0 || k<0)  return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
	int H,W,A,B;
	cin >> H >> W >> A >> B;

	COMinit();
	long long ans=0;
	for(int i=1;i<=H-A;i++){
		long long xx=COM((B-1)+(i-1),(i-1))*COM((H-i)+(W-B-1),(W-B-1))%MOD;
		ans+=xx;
		ans%=MOD;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x1,x2,y1,y2;
  cin >> x1 >> y1 >> x2 >> y2 ;
  int d1,d2;
  d1 = x2-x1;
  d2 = y2-y1;
  int x3,y3,x4,y4;
  x3 = x2 - d2;
  x4 = x1 - d2;
  y3 = y2 + d1;
  y4 = y1 + d1;
  cout << x3 << ' ';
  cout << y3 << ' ';
  cout << x4 << ' ';
  cout << y4 << endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
using namespace std;
using ll = long long;
const int INF = 1e8;
int N;
vector<int>c;
int dp[111111];
int main() {
	cin >> N;
	c.push_back(1);
	for (int i = 6; i <= N; i *= 6) {
		c.push_back(i);
	}
	for (int i = 9; i <= N; i *= 9) {
		c.push_back(i);
	}
	fill(dp, dp + N+1, INF);
	dp[0] = 0;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j < c.size(); ++j) {
			if (i >= c[j]) {
				dp[i] = min(dp[i], dp[i - c[j]] + 1);
			}
		}
	}
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
 
using namespace std;
 
int main()
{
   
   int n,d;
   cin>>n>>d;
   float a,b;
   int num=0;
   rep(i,n){
       cin>>a>>b;
       
       if(sqrt(pow(a,2)+pow(b,2))<=d){
           num++;
       }
   }
   cout<<num<<endl;
   
   
   return 0;
}

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

using namespace std;

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

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

void prework(){

}

void read(){

}

int deg[MAXN], vis[MAXN];
vector<int> E[MAXN];
int fa[MAXN];
int h[MAXN];

int getfather(int x){
	if (fa[x] == x) return x;
	else return fa[x] = getfather(fa[x]);
}

int umi;

void nico(){
	for(int i = 1; i <= n; i++)
		fa[i] = i;
	for(int i = 1; i <= n; i++)
		if (deg[i] == 2){
			int p = getfather(E[i][0]);
			int q = getfather(E[i][1]);
			fa[q] = p;
		}
	for(int i = 1; i <= n; i++)
		getfather(i);
	int cnt = 0;
	map<int, int> mp;
	for(int i = 1; i <= n; i++){
		mp[getfather(i)] = 0;
	}
	for(int i = 1; i <= n; i++){
		if (deg[i] == 1){
			int p = E[i][0];
			auto maki = mp.find(fa[p]);
			maki->second++;
			if (maki->second == 2){
				puts("First");
				umi = 1;
				return ;
			}
		}
	}
	umi = 0;
	puts("Second");
}

int eli = 0;

void dfs(int u, int fa){
	h[u] = -1;
	if (deg[u] == 1 && fa){
		h[u] = -1;
		return ;
	}
	for(int v, i = 0; i < E[u].size(); i++)
		if ((v = E[u][i]) != fa){
			dfs(v, u);
		}
	int p = 0, q = 0, r = 0;
	for(int v, i = 0; i < E[u].size(); i++)
		if ((v = E[u][i]) != fa){
			p += h[v] == 1;
			q += h[v] == -1;
			r += h[v] == 0;
		}
//	cout << u << ' '<<p <<' ' <<q << ' '<< r << endl;
	if (q >= 2){
		eli = 1;
		return ;
	}
	if (q >= 1)
		h[u] = 1;
	
	/*
	if (r == 0 && q == 0){
		h[u] = -1;
		return ;
	}
	if (r == 0 && p == 0){
		h[u] = 1;
		return ;
	}*/
}

void maki(){
	dfs(1, 0);
}

void solve(int casi){
//	cout << "Case #" << casi << ": ";
	cin >> n;
	for(int i = 1; i < n; i++){
		int x, y;
		cin >> x >> y;
		E[x].push_back(y);
		E[y].push_back(x);
		deg[x]++, deg[y]++;
	}
	maki();
	if (eli || h[1] == -1){
		puts("First");
	}
	else
		puts("Second");
	//nico();
	return ;
	for(int i = 1; i <= n; i++)
		vis[i] = 0;
	for(int i = 1; i <= n; i++)
		if (deg[i] == 1){
			int y, x = i, cnt = 1;
			for(y = E[x][0]; deg[y] == 2; cnt++){
				if (cnt & 1){
					vis[y]++;
				}
				int z = E[y][0] + E[y][1] - x;
				x = y;
				y = z;
			}
			if (cnt & 1){
				vis[y]++;
			}
		}
	int flag = 0;
	for(int i = 1; i <= n; i++)
		if (vis[i] >= 2)
			flag = 1;
	assert(flag == umi);
	//cout << (flag ? "First" : "Second") << endl;
}

void printans(){

}

int main(){
	std::ios::sync_with_stdio(false);
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}

Measured memory_bytes: 55168
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if((a+b)%2){
        cout << (a+b+1)/2 << endl;
    }else{
        cout << (a+b)/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from operator import itemgetter

class UnionFindTree:
    def __init__(self,size):
        self.rank=[0]*size
        self.p=[0]*size
        for i in range(size):
            self.makeSet(i)
    
    def makeSet(self,i):
        self.p[i]=i
        self.rank[i]=0
    
    def same(self,x,y):
        return self.findSet(x) == self.findSet(y)
    
    def unite(self, x,y):
        self.link(self.findSet(x), self.findSet(y))
    
    def link(self, x, y):
        if(self.rank[x] > self.rank[y]):
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y]+=1
     
    def findSet(self, x):
        if(x!=self.p[x]):
            self.p[x]=self.findSet(self.p[x])
        return self.p[x]

    def print(self):
        print(self.p)


def readinput():
    nv, ne=list(map(int,input().split()))
    nList=[]
    for _ in range(ne):
        s,t,w=list(map(int,input().split()))
        nList.append((s,t,w))
    return nv,ne,nList

def Kruskal(nv,nList):
    sortedList=sorted(nList, key=itemgetter(2))
    S=UnionFindTree(nv)
    K=[]

    for e in sortedList:
        s=e[0]
        t=e[1]
        if S.same(s,t)==False:
            S.unite(s,t)
            K.append(e)
    
    return K

def main(nv,ne,nList):
    K=Kruskal(nv,nList)
    total=0
    for e in K:
        total+=e[2]
    return total


if __name__=='__main__':
    nv,ne,nList=readinput()
    ans=main(nv,ne,nList)
    print(ans)



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

#define ll long long
#define mk make_pair
#define pb push_back


using namespace std;


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

   int N; cin >> N;
   vector<int> document;
   int even = 0;
   int all = 0;
   while(N--){
      int digit; cin >> digit;

      if(digit % 2 == 0){
         all++;
         if(digit % 5 == 0 || digit % 3 == 0){
            even++;
         }
      }
   }

   if(even == all) cout << "APPROVED";
   else cout << "DENIED"; 
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>v;
ll A[3],n,a[3][1000];
int main(void){
    for(int i=0;i<3;i++)cin>>A[i];
    cin>>n;
    for(int i=0;i<3;i++){
        for(int j=0;j<A[i];j++){
            cin>>a[i][j];
        }
        sort(a[i],a[i]+A[i]);
        reverse(a[i],a[i]+A[i]);
    }
    for(int i=1;i<=A[0];i++){
        for(int j=1;j<=A[1];j++){
            for(int k=1;k<=A[2];k++){
                if(i*j*k>n)break;
                v.push_back(a[0][i-1]+a[1][j-1]+a[2][k-1]);
            }
        }
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i=0;i<n;i++){
        cout<<v[i]<<endl;
    }
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <vector>
#include <map>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> a(N);
  rep(i, N) {
    cin >> a[i];
  }

  std::map<int, int> m;
  rep(i, N) {
    m[a[i] - 1]++;
    m[a[i]]++;
    m[a[i] + 1]++;
  }

  int mx = 0;
  for (const auto& e : m) {
    if (mx < e.second) mx = e.second;
  }

  cout << mx << endl;

  return 0;
}


Measured memory_bytes: 5120
N,D = (int(x) for x in input().split())
grid = []

for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

sum = 0
for i in range(N):
    if grid[i][0] ** 2 + grid[i][1] ** 2 <= D ** 2:
        sum += 1
print (sum)

Measured memory_bytes: 45440
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#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>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
ll solve(){
    int n;
    cin >>n;
    vector< vector<ll> > a(n,vector<ll>(n));
    rep(i,n)rep(j,n) cin >>a[i][j];

    vector< vector<ll> > d(a);
    rep(k,n)rep(i,n)rep(j,n) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

    rep(i,n)rep(j,n)if(d[i][j] != a[i][j]) return -1;

    ll ans = 0;
    rep(i,n)rep(j,i){
        bool ok = false;
        rep(k,n)if(k!=i && k!=j) ok |= (d[i][j] == d[i][k]+d[k][j]);
        if(!ok) ans += d[i][j];
    }

    return ans;
}

int main(){
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s,t;
    cin>>s>>t;
    int n=s.size(),x=t.size();
    int p = 0;
    int res = 2000;
    for(int i=0;i<n-(x-1);i++){
    	//cout<<i<<endl;
    	int curr = 0;
    	for(int j=p;j<x;j++){
    		if(s[i+j]!=t[j])curr++;
    	}
    	res = min(res,curr);
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 3592
def main():
    n = int(input())
    a = []
    b = []
    c = []
    for _ in range(n):
        i, j, k = map(int, input().split())
        a.append(i)
        b.append(j)
        c.append(k)
    dpa = [a[0]]
    dpb = [b[0]]
    dpc = [c[0]]
    for i in range(1, n):
        dpa.append(max(dpb[i-1], dpc[i-1]) + a[i])
        dpb.append(max(dpa[i-1], dpc[i-1]) + b[i])
        dpc.append(max(dpa[i-1], dpb[i-1]) + c[i])
    print(max(dpa[-1], dpb[-1], dpc[-1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 87000
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main() {
	int n;
	char train[52];
	REP(i, 0, 26) train[i] = 'a' + i;
	REP(i, 0, 26) train[i + 26] = 'A' + i;
	
	while (cin >> n, n) {
		int k[101];
		string s;
		REP(i, 0, n) cin >> k[i];
		cin >> s;

		REP(i, 0, s.size()) {
			int key = i%n;
			int cnt = -1;
			REP(j, 0, 52) {
				if (train[j] == s[i]) {
					cnt = j;
					break;
				}
			}

			if (cnt - k[key] < 0) {
				cout << train[52 - (k[key] - cnt)];
			}
			else {
				cout << train[cnt - k[key]];
			}

		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i,n) for(i = 0; i<n; i++)
#define repl(i,n) for(i = 1; i<=n; i++)

#define sz(x)   (int)x.size()
#define pb      push_back
#define all(x)  x.begin(), x.end()
#define uu      first
#define vv  second
#define mem(x,y) memset(x,y,sizeof(x))
#define sdi(x) scanf("%d",&x)
#define sdii(x,y) scanf("%d %d",&x,&y)
#define sdiii(x,y,z)  scanf("%d %d %d",&x,&y,&z)
#define sdl(x) scanf("%lld",&x)
#define sdll(x,y) scanf("%lld %lld",&x,&y)
#define sdlll(x,y,z)  scanf("%lld %lld %lld",&x,&y,&z)
#define sds(x) scanf("%s",s);
#define pfi(x) printf("%d\n",x)
#define pfii(x,y) printf("%d %d\n",x,y)
#define pfiii(x,y,z) printf("%d %d %d\n",x,y,z)
#define pfl(x) printf("%lld\n",x)
#define pfll(x,y) printf("%lld %lld\n",x,y)
#define pflll(x,y,z) printf("%lld %lld %lld\n",x,y,z)

#define eps 1e-9
#define OK  cerr<< "OK" << '\n'
#define DB(x) cerr << #x " = " << x << '\n'

#define FRE(i,a,b) for(i = a; i<=b; i++)
#define FRL(i,a,b) for(i = a; i<b; i++)
#define un(x) x.erase(unique(all(x)),x.end())
#define sf(x) scanf("%d",&x)
#define sff(x,y) scanf("%d %d",&x,&y)
#define sfff(x,y,z)  scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z)  scanf("%lld %lld %lld",&x,&y,&z)
#define D(x)        cerr << #x " = " << x << '\n'
#define DBG         cerr << "Hi" << '\n'
#define PI          acose(-1.00)
#define xx          first
#define yy          second

typedef double db;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

inline int setBit(int N, int pos) { return N=N|(1<<pos);}
inline int resetBit(int N, int pos) {return N=N &~(1<<pos);}
inline bool checkBit(int N, int pos) {return (bool) (N & (1<<pos));}


//int fx[] = {+0, +0, +1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, -1, -1};


const LL  mod[] = { 2078526727, 2117566807 };
const LL base[] = { 1572872831, 1971536491 };

const int MAX = 100005;
int n;
vector <int> graph[MAX];
unordered_map <LL, LL> mapp;

pair <LL, LL> dfs(int u, int par=-1) {
    pair <LL, LL> ret = { 0ll, 0ll };
    for(auto v:graph[u]) {
        if(v == par) continue;
        auto now = dfs(v, u);
        ret.uu += now.uu;
        if(ret.uu >= mod[0]) ret.uu -= mod[0];
        ret.vv += now.vv;
        if(ret.vv >= mod[1]) ret.vv -= mod[1];
    }
    LL here = (ret.uu << 32) ^ ret.vv;
    if(mapp[here] == 0) mapp[here] = 1;
    else mapp[here]++;

    ret.uu *= base[0];
    ret.uu %=  mod[0];
    ret.vv *= base[1];
    ret.vv %=  mod[1];
    ret.uu++;
    if(ret.uu >= mod[0]) ret.uu -= mod[0];
    ret.vv++;
    if(ret.vv >= mod[1]) ret.vv -= mod[1];
    return ret;
}

int main() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);

    int i, u, v;
    LL ans = 0;

    sdi(n);
    rep(i, n-1) {
        sdii(u, v);
        u--, v--;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    dfs(0);
    for(auto x:mapp) {
        LL now = x.vv;
        ans += ((now)*(now-1)) / 2;
    }
    pfl(ans);

    return 0;
}

Measured memory_bytes: 20280
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
s, t = input(), input()
print(sum([1 if s[k] == t[k] else 0 for k in range(3)]))

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

    int cnt[4]={};
    rep(i,N){
        int a;cin>>a;
        cnt[a%4]++;
    }

    int beet=cnt[1]+cnt[3]+(cnt[2]!=0);
    int ei=cnt[0];

    if(ei+1<beet)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))
check = [0] * N
check[0] = A[0]+K - A[-1]

for i in range(N-1):
    check[i+1] = abs(A[i+1] - A[i])

ans = sum(check) - max(check)
print(ans)

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

using namespace std;
#define int long long

signed main(){
	int n;
	cin>>n;
	int a[n+11];
	for(int i=1;i<n;i++)
		scanf("%lld",&a[i]);
	if(n==2){
		printf("%lld\n",2*a[1]);return 0;
	}
	int ans=0;
	for(int i=1;i<n;i++){
		if(i==1){
			ans+=a[1];
		}
		if(a[i]<=a[i+1]){
			ans+=a[i];
		}else{
			ans+=a[i+1];
		}
	}
	cout<<ans;
	return 0;
}

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

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

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

bool check(ll x,ll y, ll n, ll m){
    return x>=0 && y>=0 && x<n && y<m;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin >> n;
    ll p = n * n;
    ll P[p];
    rep(i,0,p)	cin >> P[i];
    ll D[n][n];
    ll vis[n][n];
    rep(i,0,n)	rep(j,0,n){
    	ll a = min(i,n-i-1);
    	ll b = min(j,n-j-1);
    	D[i][j] = min(a,b);
    	vis[i][j] = 1;
    }
    ll ans=0;
    rep(i,0,p){
    	ll r = P[i];
    	ll x = (r-1)/n;
    	ll y = (r-1)%n;
    	queue<pll> q;
    	q.push({x,y});
    	ans += D[x][y];
    	vis[x][y] = 0;
    	while(!q.empty()){
    		pll r = q.front();
    		q.pop();
    		rep(j,0,4){
    			ll nx = r.ft+dx[j];
    			ll ny = r.sd+dy[j];
    			if(check(nx,ny,n,n) and D[nx][ny] > D[r.ft][r.sd] + vis[r.ft][r.sd]){
    				q.push({nx, ny});
    				D[nx][ny] = D[r.ft][r.sd] + vis[r.ft][r.sd];
    			}
    		}	
    	}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9496
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <set>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int mi = min(x, y);
    int cost;

    if(a+b > 2*c){
        cost += 2*c*mi;
    }
    else cost += mi*(a+b);

    int ma = max(x, y);
    int z = ma - mi;

    if(x-y >= 0){
        if(a > 2*c) cost += z*2*c;
        else cost += z*a;
    }

    else{
        if(b > 2*c) cost += z*2*c;
        else cost += z*b;
    }

    cout << cost << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{

    int N,a=0,b=0,c=0;
    cin >> N;
    for(int i=0;i<N;++i)
    {
        int t;
        cin >> t;
        if(t%4==0)
            a++;
        else if(t%2==0)
            b++;
        else c++;
    }

    if(c>a+1||(c==a+1&&b>0))
        cout << "No";
    else
        cout << "Yes";

	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> num = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            num.add(scanner.nextInt());
        }
        num = new ArrayList<Integer>(new LinkedHashSet<Integer>(num));
        System.out.println(num.size());

    }
}

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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)


typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;
const long double PI = (acos(-1));
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];

//////////////////////////////////////////


void COMinit() {
   fac[0] = fac[1] = 1;
   finv[0] = finv[1] = 1;
   inv[1] = 1;
   for (int i = 2; i < MAX; i++){
       fac[i] = fac[i - 1] * i % MOD;
       inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
       finv[i] = finv[i - 1] * inv[i] % MOD;
   }
}

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int b) {

    if(b == 0) return 0;
    return counter(b >> 1) + (b & 1);
}
void Input() {

    cin >> N;
    for(int i = 1; i <= N; i++) {

        cin >> A[i];
        for(int j = 1; j <= A[i]; j++) {

            cin >> x[i][j] >> y[i][j];
        }
    }
}



void Solve() {

    int ans = 0;
    for(int bits = 1; bits < (1 << N); bits++) {

        bool ok = true;
        for(int i = 1; i <= N; i++) {

            if(!(bits  & (1 << (i-1)))) continue;
            for(int j = 1; j <= A[i]; j++) {

                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }

    cout << ans << endl;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}



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

int main() {
  double n,m,x,y;
  cin>>n>>m>>x>>y;
  int ans=0;
  if(n/2==x&&m/2==y)
    ans=1;
  
  
  cout<<n*m/2<<" "<<ans<<endl;
  
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> b(n-1);
  vector<int> a(n);
  for (int i = 0; i < n-1; i++) {
    cin >> b.at(i);
  }
  b.push_back(INT_MAX);
  a.at(0) = b.at(0);
  for (int i = 1; i < n; i++) {
    a.at(i) = min(b.at(i-1), b.at(i));
  }
  cout << accumulate(a.begin(), a.end(), 0) << '\n';
  return 0;
}


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

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

  int con = 1;

  while (S > 4 || S == 3) {
    if (S % 2 == 0) S /= 2;
    else S = S * 3 + 1;
    con++;
  }

  cout << con + 3 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define SIZE 500005
#define EPS 1e-10

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

P st[SIZE];

int main()
{
	int n,L;
	scanf("%d %d",&n,&L);
	int s=0,sz=0;
	double sum=0.0;
	for(int i=0;i<n;i++)
	{
		int t,v;
		scanf("%d %d",&t,&v);
		if(i>0)
		{
			int zan=v;
			while(zan>0)
			{
				if(st[s].second>zan)
				{
					st[s].second-=zan;
					sum-=st[s].first*(double) zan;
					break;
				}
				else
				{
					sum-=st[s].first*(double) st[s].second;
					zan-=st[s].second;
					s++;
				}
			}
		}
		sum+=(double) t*(double) v;
		P p=P(t,v);
		while(sz>s&&st[sz-1].first+EPS>p.first)
		{
			P q=st[--sz];
			P r=P((q.first*(double) q.second+p.first*(double) p.second)/(double) (p.second+q.second),p.second+q.second);
			p=r;
		}
		//printf("%f %d\n",p.first,p.second);
		st[sz++]=p;
		printf("%.10f\n",sum/(double) L);
	}
	return 0;
}


Measured memory_bytes: 18176
N = int(input())
h = list(map(int, input().split()))

MAX_COST = 1001001001

cost_dp = [MAX_COST for _ in range(N)]

cost_dp[0] = 0

for i in range(N):
  if i == 0:
    continue
  elif i == 1:
    cost_dp[1] = cost_dp[0] + abs(h[1] - h[0])
  else:
    cost_dp[i] = min(cost_dp[i-1] + abs(h[i] - h[i-1]), cost_dp[i-2] + abs(h[i] - h[i-2]))

print(cost_dp[N-1])

Measured memory_bytes: 13976
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC134B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ND = Console.ReadLine().Split(' ');
            int N = int.Parse(ND[0]);
            int D = int.Parse(ND[1]);
            if ((N % (2 * D + 1))==0) Console.WriteLine(N / (2 * D + 1));
            else Console.WriteLine((N / (2 * D + 1)) + 1);
        }
    }
}


Measured memory_bytes: 27536
import Foundation
 
let input_line = readLine()!
 
let split = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
let age = Int(split[0])!
let price = Int(split[1])!
var returnPrice = 0

if age > 12 {
	returnPrice = price  
} else if 6 <= age && age <= 12 {
  	returnPrice = price / 2
}
 
print(returnPrice)

Measured memory_bytes: 7776
#include<iostream>

using namespace std;

int main(){
  string S;

  cin >> S;

  int N = S.length();
  int A = (N - 1) / 2;
  int B = (N + 3) / 2 - 1;

  if (S.substr(0, A) == S.substr(B)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256