akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <deque>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <iomanip>
#include <queue>
#include <time.h>
#include <set>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define In insert
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7, maxn = 3e5 + 100;

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    bool equal = 1;
    for (int i = s.size() - 1; i >= 1; i--){
        cnt += 9;
        if (s[i] != '9')
            equal = 0;
    }
    if (equal)
        cnt += s[0] - '0';
    else
        cnt += (s[0] - '0') - 1;
    cout << cnt << endl;
}

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

int main(){
  int n,m; cin>>n>>m;
  vector<int> a(n);
  int sum_a=0;
  for (int i=0; i<n; i++){
    int ta; cin>>ta;
    a[i]=ta;
    sum_a+=ta;
  }
  int cnt=0;
  for (int d : a){
    if (d>=sum_a/(4.0*m)) cnt+=1;
    
  }
  cout<<(cnt>=m ? "Yes" : "No")<<endl;
}

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

int main(){
	int N,K,P[200000],sum=1,minD=0,maxD=0,ren=0,minus=0;
	bool exi[200001];
	priority_queue<int> top;
	priority_queue<int,vector<int>,greater<int>> bot;
	
	cin>>N>>K;
	
	for(int i=0;i<N;i++)cin>>P[i];

	for(int i=0;i<K;i++){
		top.push(P[i]);
		bot.push(P[i]);
	}
	for(int i=1;i<N;i++){
		if(P[i-1]>P[i])ren=0;
		else ren++;
		if(ren==K-1)minus++;
	}
	for(int i=K;i<N;i++){
		while(true){
			minD=bot.top();
			if(exi[minD])bot.pop();
			else break;
		}
		while(true){
			maxD=top.top();
			if(exi[maxD])top.pop();
			else break;
		}
		if(P[i-K]>minD||P[i]<maxD)sum++;
		exi[P[i-K]]=true;
		top.push(P[i]);
		bot.push(P[i]);
	}
	if(minus>=1)sum=sum-minus+1;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3052
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll s,w;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>s>>w;
	if(w>=s)
	cout<<"unsafe";
	else
	cout<<"safe";
	return 0;
}


Measured memory_bytes: 3640
import java.util.*;


public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [] data = new int[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			HashMap<Integer, Integer> map = new HashMap<>();
			ArrayList<Integer> keys = new ArrayList<>();
			for(int i = 0; i < n; i++){
				if(map.containsKey(data[i])){
					map.put(data[i], map.get(data[i]) + 1);
				}
				else{
					map.put(data[i], 1);
					keys.add(data[i]);
				}
			}
			Collections.sort(keys);
			int max = 0;
			int temp = map.get(keys.get(0));
			if(keys.size() > 1 && keys.get(0) + 1 == keys.get(1)){
				temp += map.get(keys.get(1));
			}
			max = Math.max(max, temp);
			max = Math.max(max, map.get(keys.get(keys.size()-1)));
			for(int i = 1; i < keys.size() - 1; i++){
				int prev = keys.get(i-1);
				int now = keys.get(i);
				int next = keys.get(i+1);
				
				int value = map.get(keys.get(i));
				if(now - 1 == prev){
					value += map.get(keys.get(i-1));
				}
				if(now + 1 == next){
					value += map.get(keys.get(i+1));
				}
				max = Math.max(value, max);
			}
			System.out.println(max);
			
			
		}
	}



	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 51060
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    if (n % 2 == 1)
    {
        cout << "0";
        return 0;
    }
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    if (a[n / 2] == a[n / 2 - 1])
    {
        cout << "0";
        return 0;
    }
    cout << a[n / 2] - a[n / 2 - 1];
    return 0;
}


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

int main() {
  int N, M, count=0;
  cin >> N >> M;
  
  double sum=0;
  vector<int> num(N);
  for (int i=0; i<N; i++){
  	cin >> num.at(i);  
    sum += num.at(i);
  }

  double res = sum/(4*M);  
  for (int i=0; i<N; i++){
  	if (num.at(i)>=res){
      count++;
    }
  }
  
  if (count>=M){
  	cout << "Yes" << endl;
  }
  else {
  	cout << "No" << endl;
  }  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N, K; cin >> N >> K;
    vector<ll> X(N), Y(N);
    REP(i, 0, N) cin >> X[i] >> Y[i];

    vector<ll> xx = X, yy = Y;
    sort(ALL(xx)); xx.erase(unique(ALL(xx)), xx.end());
    sort(ALL(yy)); yy.erase(unique(ALL(yy)), yy.end());

    vector<vector<int>> P(N, vector<int>(N, 0));
    REP(i, 0, N) {
        X[i] = lower_bound(ALL(xx), X[i]) - xx.begin();
        Y[i] = lower_bound(ALL(yy), Y[i]) - yy.begin();
        P[X[i]][Y[i]]++;
    }
    
    vector<vector<int>> sum(N + 1, vector<int>(N + 1, 0));
    REP(i, 0, N) {
        REP(j, 0, N) {
            sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + P[i][j];
        }
    }

    ll ans = (1LL << 62);
    REP(i, 0, N) {
        REP(j, 0, N) {
            REP(k, i + 1, N + 1) {
                REP(l, j + 1, N + 1) {
                    if (sum[k][l] - sum[k][j] - sum[i][l] + sum[i][j] >= K) {
                        ans = min(ans, (xx[k - 1] - xx[i]) * (yy[l - 1] - yy[j]));
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define rgi register int
#define pii pair<int,int>
#define mkp make_pair
#define fi first
#define se second
#define pb push_back
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
using namespace std;
const int maxn=3e5+5;
const ll mod=1e9+7;
int n;
ll a[maxn],cnt[60][2],ans;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(rgi i=1;i<=n;++i)
		cin>>a[i];
	for(rgi i=n;i;--i)
	{
		ll tt=a[i];
		for(rgi j=0;j<60;++j)
		{
			ans=(ans+(1ll<<j)%mod*cnt[j][(tt&1)^1]%mod)%mod;
			tt>>=1;
		}
		tt=a[i];
		for(rgi j=0;j<60;++j)
		{
			++cnt[j][tt&1];
			tt>>=1;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include<iostream>

using namespace std;

const long long INF = 1e18;

int main(){
    int n, k; cin >> n; k = 2;
    int a[n+10];
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    long long dp[101000];
    for (int i=0; i<101000; i++){
        dp[i] = INF;
    }
    dp[0] = 0;

    for (int i=0; i<n; i++){
        for (int j=1; j<=k && i+j < n; j++){
            dp[i+j] = min(dp[i+j], dp[i]+abs(a[i]-a[i+j]));
        }
    }

    cout << dp[n-1] << endl;
    
    return 0;
}

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

ll H, W, Ans;

void f(ll a, ll b, ll c) {
	if(a > b) swap(a, b);
	if(a > c) swap(a, c);
	if(b > c) swap(b, c);
	c -= a;
	if(c < Ans) Ans = c;
}

int main() {
	cin >> H >> W;
	Ans = H*W;

	for(int a = H, b = 0; a; a--, b++) {
		if(1 < b) f(W*a, W*(b/2), W*((b+1)/2));
		f(W*a, (W/2)*b, ((W+1)/2)*b);
	}
	for(int a = W, b = 0; a; a--, b++) {
		if(1 < b) f(H*a, H*(b/2), H*((b+1)/2));
		f(H*a, (H/2)*b, ((H+1)/2)*b);
	}

	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 256
import re


password=0
while True:
    try:
        str=input()

        str=re.sub("[^\d]"," ",str)
        str=re.sub("\s+"," ",str)
        for i in str.split(" "):
            try:
                password+=int(i)
            except ValueError:
                pass


    except EOFError:
        break

print(password)



Measured memory_bytes: 6552
N=int(input())
a0,b0,c0=map(int,input().split())
for _ in range(1,N):
    a,b,c=map(int,input().split())
    a0,b0,c0=a+max(b0,c0),b+max(a0,c0),c+max(a0,b0)
print(max(a0,b0,c0))

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<pair<int,int>>;//隣接する点とその点までのコスト

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

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

int main(){
  ll N,M; cin>>N>>M;
  vector<ll> A(N);
  rep(i,N)cin>>A.at(i);
  ll g = A.at(0);
  rep1(i,N)g = gcd(g,A.at(i));
  ll l = 1;
  rep(i,N){
    if((A.at(i)/g)%2==0){
      cout<<0<<endl;
      return 0;
    }
    l = lcm(l,A.at(i));
  }

  ll res = 2*M/l;
  if(res%2!=0)res++;
  cout<<res/2<<endl;
  return 0;
}

Measured memory_bytes: 1024
conv ::	[[String]] -> [(String, Int)]
conv []	= []
conv ([a,b]:xs)	= (a, read b) :	conv xs

solve :: Int -> [(String, Int)] -> [(String, Int)] -> Int -> IO()
solve _ [] [] _ = return ()
solve q [] buf time = solve q (reverse buf) [] time
solve q (all@(a,b):xs) buf time
  | (b - q) <= 0 = do
      putStrLn $ a ++ " " ++ (show . (time +)) b
      solve q xs buf (time + b)
  | otherwise = solve q xs ((a, b - q):buf) (time + q)

main = do
  ([_,qs]:xs) <- fmap (map words . lines) getContents
  solve (read qs) (conv xs) [] 0


Measured memory_bytes: 14264
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		int ans = 0;
		for(int i = 0 ; i < n;) {
			ans++;
			i += k - 1;
			if(i == n - 1) ans--;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 51384
def main():
    import sys
    input = sys.stdin.readline
    from bisect import bisect_right
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))
    b_comb_accum = [0] * (N+1)
    for i in range(N-1, -1, -1):
        c_min_ind = bisect_right(C, B[i])
        b_comb_accum[i] = b_comb_accum[i+1] + N - c_min_ind
    ans = 0
    for a in A:
        b_min_ind = bisect_right(B, a)
        ans += b_comb_accum[b_min_ind]
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 23972
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;
typedef long long ll;
const ll LINF = 1e18;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

double ev[302][302][302]={0};
double pr[302][302][302]={0};
int main(){
  int N,t;
  cin >> N;
  vector<int> cnt(4,0);
  for(int i=0;i<N;i++){
    cin >> t;
    cnt[t]++;
  }
  pr[cnt[1]][cnt[2]][cnt[3]] = 1;
  double dn = (double)N;
  for(int i=N;i>=0;i--){
    for(int j=N;j>=0;j--){
      for(int k=N;k>=0;k--){
        double tev=0,tpr;
        int s = i+j+k;
        
        tpr = pr[k+1][j][i] * (k+1)/(s+1);
        pr[k][j][i] += tpr;
        tev += (ev[k+1][j][i] + dn/(s+1))*tpr;
        
        if (k-1 >= 0){
          tpr = pr[k-1][j+1][i] * (j+1)/s;
          pr[k][j][i] += tpr;
          tev += (ev[k-1][j+1][i] + dn/s)*tpr;
        } 
        if (j-1 >= 0){
          tpr = pr[k][j-1][i+1] * (i+1)/s;
          pr[k][j][i] += tpr;
          tev += (ev[k][j-1][i+1] + dn/s)*tpr;
        }
        if(pr[k][j][i] > 0) ev[k][j][i] = tev/pr[k][j][i];
      }
    }
  }
  cout << fixed << setprecision(10) << ev[0][0][0] << endl;
  return 0;
}



Measured memory_bytes: 430464
N = int(input())
T, A = map(int, input().split())
H = [int(i) for i in input().split()]

d = 10**9
for i, h in enumerate(H):
    tmp = abs(A - (T - h * 0.006))
    if tmp < d:
        d = tmp
        ans = i + 1
print(ans)


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

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

  int A[N];
  for(int i = 0; i < N; i++) {
    A[i] = 0;
  }

  int tmp;
  for(int i = 1; i < N; i++) {
    cin >> tmp;
    A[tmp - 1] += 1;
  }

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

  return 0;
}

Measured memory_bytes: 3888
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int op(int op1, int op2, int operation) {
	if (operation == 0) 
		return op1 + op2;
	else
		return op1 - op2;
}
int main (void) {
	string s; cin >> s;

	for (int i = 0 ; i < 8; i++) {
		//iterate over bits of i
		vector <char> operations;
		int n = s[0]-'0';
		for (int j = 0; j < 3; j++) {
			if ((i & (1<<j)) == 0) {
				n = op(n, s[j+1]-'0', 0);
				operations.push_back('+');
				
			}
			else {
				n = op(n,s[j+1]-'0',1);
				operations.push_back('-');
			}
		}
		if (n == 7) {
			cout << s[0];
			for (int j = 0; j < (int)operations.size(); j++)
				cout  << operations[j] << s[j+1];
			cout << "=7" << endl;
			break;
		}
		
	}


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

constexpr int MOD = 1000000007;
ll modpow(ll n, ll r, ll mod) {
    if(r == 0) return 1;
    if(n == 0) return 0;
    if(r % 2 == 0) {
        ll tmp = modpow(n, r / 2, mod);
        return tmp * tmp % mod;
    }
    else {
        return n * modpow(n, r - 1, mod) % mod;
    }
}

int main(){
    int N, M;
    read(N, M);
    vector<int> L(M);
    vector<int> R(M);
    for(int i = 0; i < M; i++){
        read(L[i], R[i]);
    }
    int ans = max(0, *min_element(R.begin(), R.end()) - *max_element(L.begin(), L.end()) + 1);
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/
 
int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    if(a+b > c+d) cout << "Left" << endl;
    else if(a+b == c+d) cout << "Balanced" << endl;
    else cout << "Right" << endl;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<28

using namespace std;

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

struct edge
{
	int to;
	int cost;

	edge(int to,int cost) : to(to),cost(cost) {}
};

vector<edge> G[10];
ll d[10];

void dijkstra(int s,int n)
{
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+n,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty())
	{
		P p = que.top();
		que.pop();

		int v = p.second;
		if(d[v] < p.first) continue;

		rep(i,G[v].size())
		{
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main()
{
	int n;
	
	while(cin >> n && n)
	{
		vector<int> t;
		rep(i,10)
		{
			G[i].clear();
		}
		rep(i,n)
		{
			int a,b,c;
			cin >> a >> b >> c;

			G[a].push_back(edge(b,c));
			G[b].push_back(edge(a,c));

			vector<int>::iterator ite = find(t.begin(),t.end(),a);
			if(ite == t.end())
			{
				t.push_back(a);
			}

			ite = find(t.begin(),t.end(),b);
			if(ite == t.end())
			{
				t.push_back(b);
			}

		}

		pair<int,ll> ans;
		ans.first = t[0];
		ans.second = INF;
		
		rep(i,t.size())
		{
			dijkstra(t[i],10);

			ll sum = 0;

			rep(j,t.size()) 
			{
				sum += d[t[j]];
			}
			
			if(ans.second == sum)
			{
				if(ans.first > t[i])
				{
					ans.first = t[i];
				}
			}

			if(ans.second > sum)
			{
				ans.first = t[i];
				ans.second = sum;
			}	
		}
		cout << ans.first << " " << ans.second << endl;
	}

	return 0;
	
}

Measured memory_bytes: 1216
#include <stdio.h>

int main(void)
{
    int n;

    while (scanf("%d", &n), n){
        while (n-- > 0){
            int x1, y1, z1, w1;
            int x2, y2, z2, w2;
            int x3, y3, z3, w3;

            scanf("%d %d %d %d", &x1, &y1, &z1, &w1);
            scanf("%d %d %d %d", &x2, &y2, &z2, &w2);
            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;

            printf("%d %d %d %d\n", x3, y3, z3, w3);
        }
    }

    return 0;
}

Measured memory_bytes: 600
n,d =map(int,input().split())
l= [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        a = 0
        for k in range(d):
            a += (l[i][k] - l[j][k])**2
        a **=0.5
        if a.is_integer():
            ans +=1
print(ans)

Measured memory_bytes: 9408
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))

n,m= m()

print(n*m)


Measured memory_bytes: 7328
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

def aa(num):
    if num==1:
        return 300000
    if num==2:
        return 200000
    if num==3:
        return 100000
    else:
        return 0
x,y = MAP()
ans=0
if x==1 and y==1:
    ans += 400000

ans += aa(x) + aa(y)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,x,z;
int main()
{
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x<a||x>=b)z++;
	}
	cout<<z<<endl;
	return 0;
}

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

int main(){

	int n, num[10000];
	int max = -1000000, min = 1000000;
	long long sum = 0;

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> num[i];

		if(min > num[i]) min = num[i];
		if(max < num[i]) max = num[i];
		sum = sum + num[i];
	}

	cout << min << " " << max << " " << sum << endl;

	return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int h, w, p;
    cin >> h >> w >> p;
    vector<string> cake(h);
    vector<vector<int>> ans(h, vector<int>(w, 0));
    int piece = 1;
    for(int i=0;i<h;++i){
        cin >> cake[i];
        int strawberry = -1;
        for(int j=0;j<w;++j) {
            if(cake[i][j] == '#') {
                for(int k=strawberry+1;k<=j;++k) ans[i][k] = piece;
                ++piece;
                strawberry = j;
            }
        }
        if(strawberry != -1) {
            for(int k=strawberry+1;k<w;++k) ans[i][k] = piece-1;
        }
    }

    int ii = (ans[0][0] == 0)?-1:0;
    for(int i=1;i<h;++i) {
        if(ans[i][0] == 0) {
            if(ii == -1) {
                continue;
            } else {
                for(int j=0;j<w;++j) {
                    ans[i][j] = ans[ii][j];
                }
            }
        }
        ii = i;
    }

    for(int i=h-1;i>=0;--i) {
        if(ans[i][0] != 0) {
            ii = i;
        }
    }

    for(int i=0;i<h&&ans[i][0]==0;++i) {
        for(int j=0;j<w;++j) ans[i][j] = ans[ii][j];
    }

    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

}


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

int main() {
	int n, r = 0;
  	cin >> n;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		long long a;
		cin >> a;
		if (a == 0)r = 0;
		ans += (a + r) / 2;
		r = (a + r) % 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000000;

int n, m;
priority_queue<int> pq;

int main(){
  cin >> n >> m;
  rep(i, n){
    int a;
    cin >> a;
    pq.push(a);
  }
  rep(i,m){
    int a = pq.top();
    pq.pop();
    pq.push(a/2);
  }
  ll ans = 0;
  rep(i, n){
    ans = ans + pq.top();
    pq.pop();
  }
  cout << ans <<endl;
}
    

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int N, M, Q;
  int p, q;
  cin >> N >> M >> Q;
  vector<int> L(M), R(M);
  vector<vector<int> > C(N + 1,vector<int>(N + 1, 0));
  for(int i = 0 ; i < M; i++){
    cin >> L[i] >> R[i];
    C[L[i]][R[i]]++;
  }
  for(int i = 0; i <= N; i++){
    for(int j = 1; j <= N; j++)
      C[i][j] += C[i][j - 1];
  }
  for(int i = 0; i <= N; i++){
    for(int j = 1; j <= N; j++)
      C[j][i] += C[j - 1][i];
  }
  
  for(int i = 0; i < Q; i++){
    cin >> p >> q;
    cout << C[q][q] + (C[p - 1][p - 1] - C[p - 1][q] - C[q][p - 1]) << endl; 
  }
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0';
  int d=s[3]-'0';
  for(int i=0;i<8;i++){
    int sum=0;
    sum=sum+a;
    if(i&(1<<0)){    
      sum=sum+b;
    }
    else{
      sum=sum-b;
    }
    if(i&(1<<1)){    
      sum=sum+c;
    }
    else{
      sum=sum-c;
    }
    if(i&(1<<2)){    
      sum=sum+d;
    }
    else{
      sum=sum-d;
    }
    if(sum==7){
      cout << a;
      if(i&(1<<0)){
        cout << '+';
      }
      else{
        cout << '-';
      }
      cout << b;
      if(i&(1<<1)){
        cout << '+';
      }
      else{
        cout << '-';
      }
      cout << c;
      if(i&(1<<2)){
        cout << '+';
      }
      else{
        cout << '-';
      }
      cout << d << "=7" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main(){
  int N,K;cin>>N>>K;
  vector<int> h(N), dp(N, 1000100000);
  rep(i,N) cin>>h[i];
  dp[0] = 0;
  rep(i,N - 1) {
    rep(j, K) {
      if(i + j + 1 <= N - 1) chmin(dp[i + j + 1], dp[i] + abs(h[i + j +1] - h[i]));
    }
  }
  cout << dp[N - 1] << endl;
}

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

int main(){
    ll a,b,c,m,n,x,y,ar[100010];
    scanf("%lld %lld %lld",&a,&b,&c);
    x=(a+b-1)/b;
    printf("%lld\n",x*c);

    return 0;
}


Measured memory_bytes: 3796
def make_bit(n):
    bit = []
    for i in range(2**n):
        bit.append(bin(i)[2::])
    i = 0
    while i < len(bit):
        while len(bit[i]) < len(bin(2**n-1)[2::]):
            bit[i] = "0" + bit[i]
        i += 1

    return bit

n, m, X = map(int, input().split())
c = []
a = []
for i in range(n):
    ca = list(map(int, input().split()))
    c.append(ca[0])
    a.append(ca[1:])

ptarn = make_bit(n)
ans = 10 ** 10
for i in ptarn:
    money = 0
    x = [0 for _ in range(m)]
    for j in range(n):
        if i[j] == "1":
            money += c[j]
            for k in range(m):
                x[k] += a[j][k]

    if min(x) >= X:
        ans = min(ans, money)

if ans == 10 ** 10:
    ans = -1
print(ans)

Measured memory_bytes: 9292
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		for(int i=0;i<N;i++) {
			A[sc.nextInt()-1] = i+1;
		}
		for(int j=0;j<N;j++) {
			System.out.print(A[j]+" ");
		}
	}
}

Measured memory_bytes: 60632
#include <iostream>
#include <algorithm>

#define ll long long

using namespace std;

int main(){

int n;
string s[10001];
cin>>n;
int ab=0,a=0,b=0,ba=0;
for(int i=0;i<n;++i){
  cin>>s[i];
  for(int j=0;j<s[i].length()-1;++j){
     if(s[i][j]=='A'&&s[i][j+1]=='B') ab++;
  }
  if(s[i][0]=='B'&&s[i][s[i].length()-1]=='A'){
    ba++;
  }else if(s[i][0]=='B'){
    b++;
  }else if(s[i][s[i].length()-1]=='A'){
    a++;
  }
}
int ans=0;
if(ba){ 
  if(a&&b){
    ans+=ba+1;
    a--; b--;
  }else if(a||b){
    ans+=ba;
    a=0; b=0;
  }else{
    ans+=ba-1;
  }
}

ans+=min(a,b);
ans+=ab;

cout<<ans<<endl;

return 0;

}


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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0216

int calc(int w) {
	int sum = 1150;
	if (w < 10) return sum;
	sum += min(w - 10, 10) * 125;
	if (w < 20) return sum;
	sum += min(w - 20, 10) * 140;
	if (w < 30) return sum;
	sum += (w - 30) * 160;
	return sum;
}

int main() {
	int w;
	while (cin >> w) {
		if (w == -1) break;
		cout << (4280 - calc(w)) << endl;
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector <int> a(100000, 0);
  for( int i = 0; i < n; i++){
      int ai;
      cin >> ai;
      a.at(ai) += 1;
  }
  int max = a.at(0) + a.at(1);
  for(int i = 1; i < a.size(); i++){
     if(i == a.size() -1){
         if(a.at(i-1) + a.at(i) > max){
             max = a.at(i-1) + a.at(i);
         }
     }else{
         if(a.at(i-1)+ a.at(i)+ a.at(i+1) > max){
             max = a.at(i-1)+ a.at(i)+ a.at(i+1);
         }
     }
  }
  cout << max << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define var(n) int n; scn(n)
#define F first
#define S second 
#define pb(n) push_back(n)
const int N=1e3+5;
const ll M=1e9+7;
const ll inf=1e18+5;

int main()
{
	ll a;
	long double b;
	cin>>a>>b;	
	ll b_dash = (ll)round(b*100);
	ll res = a*b_dash/100;
	cout<<res<<endl;
}

Measured memory_bytes: 3800
N, A, B, C, D = [int(x) for x in input().rsplit()]
S = input()
A = A - 1
B = B - 1
C = C - 1
D = D - 1

sunuke_possible = "##" not in S[A:C + 1]
funuke_possible = "##" not in S[B:D + 1]

if C > D:
    passing = "..." in S[B - 1:D + 2]
    possible = sunuke_possible * funuke_possible * passing
else:
    possible = sunuke_possible * funuke_possible

print("Yes" if possible else "No")


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

using MatrixTy = vector<vector<long>>;
#define UNSOLVE INT_MAX

void solve(MatrixTy &G, MatrixTy &S, long N, long L) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
        if (G[j][k] <= L) {
          S[j][k] = 1;
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        S[j][k] = min(S[j][k], S[j][i] + S[i][k]);
      }
    }
  }
}

int main(int argc, char **argv) {
  long N, M, L;
  cin >> N >> M >> L;

  MatrixTy G = MatrixTy(N, vector<long>(N, UNSOLVE));

  long A, B, C;
  for (int i = 0; i < M; i++) {
    cin >> A >> B >> C;
    --A;
    --B;
    G[A][B] = C;
    G[B][A] = C;
  }

  long Qcnt;
  cin >> Qcnt;

  vector<pair<long, long>> query;
  for (int i = 0; i < Qcnt; i++) {
    long s, t;
    cin >> s >> t;
    query.push_back(make_pair(--s, --t));
  }

  MatrixTy S = MatrixTy(N, vector<long>(N, UNSOLVE));
  solve(G, S, N, L);
  for (auto itr : query) {
    long s, t;
    s = itr.first;
    t = itr.second;
    if (S[s][t] == UNSOLVE) {
      cout << -1 << endl;
    } else {
      cout << S[s][t] - 1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  long long a[n], b[n];
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
  long long c[m], d[m];
  for(int i = 0; i < m; i++) cin >> c[i] >> d[i];
  for(int i = 0; i < n; i++){
    long long dis = abs(a[i] - c[0]) + abs(b[i] - d[0]);
    int p = 0;
    for(int j = 1; j < m; j++){
      if(abs(a[i] - c[j]) + abs(b[i] - d[j]) < dis){
        p = j;
        dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      }
    }
    cout << p+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, adj[105][105];
int main() {
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> u >> m;
        for (int j=0; j<m; j++) {
            cin >> v;
            adj[u][v]=1;
        }
    }
    
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            cout << adj[i][j];
            if (j!=n) cout << " "; 
        }
        cout << "\n";
    }
}


Measured memory_bytes: 3124
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n,c = map(int,input().split())
    d = [list(map(int,input().split())) for i in range(c)]
    cmat = [list(map(int,input().split())) for i in range(n)]
    t = [[0]*c for i in range(3)]
    ans = float("inf")
    for i in range(n):
        for j in range(n):
            t[(i+j)%3][cmat[i][j]-1] += 1
    for i in range(c):
        for j in range(c):
            if i != j:
                for k in range(c):
                    if i != k and j != k:
                        tmpans = 0
                        for l in range(c):
                            tmpans += d[l][i]*t[0][l]+d[l][j]*t[1][l]+d[l][k]*t[2][l]
                        ans = min(tmpans,ans)
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 7856
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
using namespace std;
vector<tuple<int,int,int,int>> vec;

long long  calAns(vector<int>& A){
    long long ans = 0;
    for(auto it : vec){
        int a,b,c,d;
        tie(a,b,c,d) = it;
        if(A[b-1]-A[a-1] == c)
            ans += d;
    }
    return ans;
}

long long sol(vector<int>& A, int cur, int end, int m){
    if(cur == end){
        return calAns(A);
    }
    long long res = 0;
    int s = A.size() ? A[cur-1] : 1;

    for(int i = s; i <= m ; ++i){
        A.push_back(i);
        res = max(res,sol(A,cur+1, end,m));
        A.pop_back();
    }
    return res;
}

int main(){
    int n,m,q;
    cin >> n >> m >> q;
    for(int i = 0,a,b,c,d; i < q ; ++i){
        cin >> a >> b >> c >> d;
        vec.emplace_back(a,b,c,d);
    }
    vector<int> A;
    cout << sol(A,0,n,m);

    return 0;
}

Measured memory_bytes: 3600
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

const int N = 1005;
const int H = 1e4 + 5;
ll arr[N], brr[N];
ll dp[H];

ll solve(ll n, ll h)
{
	if (h <= 0)
		return 0;
	if (dp[h] != -1)
		return dp[h];
	ll ans = MOD;
	for (int j = 0; j < n; j++)
		ans = min(ans, brr[j] + solve(n, h - arr[j]));
	return (dp[h] = ans);
}

void solve()
{
	ll h, n;
	cin >> h >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i] >> brr[i];
	memset(dp, -1, sizeof(dp));
	cout << solve(n, h) << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <algorithm>

typedef long long LL;

int k, c, len, del;
inline int calc(int i) {
	if (del <= k) return i % (k + 1) == 0;
	int num = (del - k) / ((LL)k * k - 1);
	int rem = (del - k) - num * ((LL)k * k - 1);
	if (i > len - num * (k + 1)) return (len - i + 1) % (k + 1) != 0;
	int len2 = len - num * (k + 1);
	int cnt = 1 + rem / k;
	if (i > len2 - cnt) return 1;
	return i % (k + 1) == 0;
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		int A, B, C, D, K;
		scanf("%d%d%d%d", &A, &B, &C, &D);
		K = (A + B) / (std::min(A, B) + 1);
		if (A >= B) {
			k = K, c = B, len = A + B, del = K * (B + 1) - A;
			for (int i = C; i <= D; ++i) putchar('A' + calc(i));
		} else {
			k = K, c = A, len = A + B, del = K * (A + 1) - B;
			for (int i = C; i <= D; ++i) putchar('B' - calc(A + B - i + 1));
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
//N = 4, 5, 6, 12を手で構築すれば大体分かる。
//N = 4を考えると気付くこと：Nが2の累乗だとNとNの間のxorはN未満になるので不可能。
//N = 5をスムーズに構築するには、「100と100の間に101を挟む」「100, 101を3以下の数の間に挟まない場合を考える」
//をするとよく、N = 3のパスを上手く使うことができる。結局、2n xor (2n + 1) = 1が割と大事な性質だったりする。
//N = 6ができれば大体何でもできそうで、できなければNが偶数のときできなさそうだな～と当てをつける。
//(2n + 1) xor (2n + 2)が2^hoge - 1の形になって、これは2n + 2側が2でhoge - 1回割り切れるとかうんたらかんたら。
//つまり、Nを2で何回割り切れるかが大事そうで、するとN = 6, 10, 14…あたりは本質的に同じと見た。
//となると、N = 12あたりで試すのが良さそうで、これはN = 11を構築してから、12 xor 11 = 2^3 - 1を利用してよしなにやるとできる。
#include <iostream>
using namespace std;

int n;
int a[200000], b[200000];
int cor = 0;

void add_edge(int u, int v) {
	a[cor] = u;
	b[cor] = v;
	cor++;
}

void print() {
	int i;
	cout << "Yes" << endl;
	for (i = 0; i < 2 * n - 1; i++) {
		cout << a[i] << " " << b[i] << endl;
	}
}

int main() {
	int i;
	
	cin >> n;
	for (i = 0; (1 << i) <= n; i++) {
		if ((1 << i) == n) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	for (i = 5; i <= n; i += 2) {
		add_edge(i - 1, i);
		add_edge(i, 1);
	}
	
	add_edge(1, 2);
	add_edge(2, 3);
	add_edge(3, n + 1);
	
	for (i = 3; i <= n; i += 2) {
		add_edge(n + 1, n + i - 1);
		add_edge(n + i - 1, n + i);
	}
	
	if (n % 2 == 0) {
		add_edge(n, n - 1);
		int x = n ^ (n - 1);
		add_edge(n + x - 1, 2 * n);
	}
	
	print();
	return 0;
}


Measured memory_bytes: 5184
using System;
  class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        double[] kachi = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);

        Array.Sort(kachi);
        Array.Reverse(kachi);
        double sum = 0;
        for (int i = 0; i < n - 1; i++)
        {
            sum += kachi[i] * Math.Pow(0.5, i + 1);
        }

        Console.WriteLine(sum + kachi[n-1] * Math.Pow(0.5, n-1));
    }
}

Measured memory_bytes: 11604
import itertools

def calc_distance(a, b):
        return (((a[0] - b[0]) ** 2) + ((a[1] - b[1]) ** 2)) ** (1/2)


N = int(input())
point = [list(map(int, input().split()))  for i in range(N)]

base = [i for i in range(N)]

candidate = list(itertools.permutations(base, N))

ans = 0
for i in candidate:
        tmp = 0
        for j in range(len(i) - 1):
                tmp += calc_distance(point[i[j]], point[i[j+1]])
        ans += tmp

print(ans / len(candidate))

Measured memory_bytes: 45552
N = int(input())
S = input()

R_cnt, G_cnt, B_cnt = 0, 0, 0

for i in range(len(S)):
    if S[i] == "R":
        R_cnt += 1
    elif S[i] == "G":
        G_cnt += 1
    else:
        B_cnt += 1

All = R_cnt * G_cnt * B_cnt

for i in range(N-2):
    for j in range(i+1, N-1):
        k = 2 * j - i
        if k >= N:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            All -= 1

print(All)

Measured memory_bytes: 68140
#include<stdio.h>

int main(){
  int N, len, max;
  char S[101];
  
  scanf("%d", &N);
  scanf("%s", &S);
  
  max = 0; N = 0;
  while(S[len]){
    if(S[len] == 'I'){
      N++;
    } else {
      N--;
    }
    if(max < N){
      max = N;
    }
    len++;
  }
  
  printf("%d\n", max);
}

Measured memory_bytes: 128
n,m,x=map(int,input().split())
l=[]

for i in range(n):
    a=list(map(int,input().split()))
    l.append(a)
ans=99999999
for i in range(2 ** n):
    bag = []
    for j in range(n):  #bit全探索
        if ((i >> j) & 1):
            bag.append(l[j])
    skill=[0]*m
    enough=[0]*m #各スキルにつき、xを超えているかどうかを判断
    money=0
    for sub in bag:
        money+=sub[0]
        for kk in range(1,m+1):
            skill[kk-1]+=sub[kk]
            if skill[kk-1]>=x:
                enough[kk-1]+=1
    if 0 not in enough: #全てのスキルがxを超えていたら価格を計算
        if ans>money:
            ans=money#最低価格を下回っていたら更新
if ans==99999999: #初期値からの変更がなければ-1を、そうでなければ最低価格を出力
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9184
#include<iostream>


using namespace std;


int main() {

	int n;

	cin >> n;
	int a;
	int ans[100000];
	for (int i = 1; i <= n; i++) {
		cin >> a;
		ans[a-1] = i;

	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] << " ";
		if (i == n-1)cout << endl;
	}
	
}

Measured memory_bytes: 1152
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N = I()
    a = LI()
    return max(a) - min(a)


print(main())


Measured memory_bytes: 7236
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
//#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
ll pi = acos(-1) ;
ll z =  1000000007 ;
ll inf = 100000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return (2*(i+1)) ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;

void solve()
{
	ll x, y , a , b , c ;
	cin >> x >> y >> a >> b >> c ;
	ll p[a] , q[b] , r[c] ;
	fo(i , a)
	{
		cin >> p[i] ;
	}
	fo(i , b)
	{
		cin >> q[i] ;
	}
	fo(i , c)
	{
		cin >> r[i] ;
	}
	sort(p , p + a) ;
	sort(q , q + b) ;
	sort(r , r + c) ;
	reverse(p , p+a) ;
	reverse(q , q + b) ;
	reverse(r , r+c) ;

	/*fo(i , a)
	{
		cout << p[i] << ' ';
	}
	cout << endl ;*/

	multiset<ll> red , green ;
	fo(i , x)
	{
		red.insert(p[i]) ;
	}
	fo(i , y)
	{
		green.insert(q[i]) ;
	}
	fo(i , c)
	{
		ll curr = r[i] ;
		ll curr_r = (*(red.begin())) ;
		ll curr_g = (*(green.begin())) ;

		if(curr_r < curr_g)
		{
			if(curr_r < curr)
			{
				red.erase(red.begin()) ;
				red.insert(curr) ;
			}
			
		}
		else
		{
			if(curr_g < curr)
			{
				green.erase(green.begin()) ;
				green.insert(curr) ;
			}
		}
	}
	ll ans = 0 ;
	auto itr = red.begin() ;
	for(; itr != red.end() ; itr++)
	{
		ans += (*itr) ;
	}
	for(auto itrg = green.begin() ; itrg != green.end() ; itrg++)
	{
		ans += (*itrg) ;
	}
	cout << ans << endl ;
	return ;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
	freopen("inputf.txt" , "r" , stdin) ;
	freopen("outputf.txt" , "w" , stdout) ;
	freopen("error.txt" , "w" , stderr) ;
	#endif*/
	
	ll t ;
	//cin >> t ;
	t = 1 ;
	while(t--)
	{
		solve() ;
	}
	return 0;
}

Measured memory_bytes: 11008
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)



int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];
	}

	SORT(a);

	int min = a[0];
	int max = a[n - 1];

	int ans = pow(10, 9);

	FOR(i, min, max) {
		int sum = 0;
		REP(j, n) {
			sum += pow((i - a[j]), 2);
		}
		if (sum < ans) {
			ans = sum;
		}
	}

	ANS(ans);

	return 0;
}



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

int main(void) {

  double xa,ya,ra;
  double xb,yb,rb;

  int n;
  
  double d,dr,sr;
  int i;


  scanf("%d",&n);

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

    scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);

    d=(xb-xa)*(xb-xa)+(yb-ya)*(yb-ya);

    dr=(rb-ra)*(rb-ra);

    sr=(ra+rb)*(ra+rb);

    if(d>sr) printf("0\n");

    else if(d<sr && d>dr) printf("1\n");

    else if(dr>d && ra>rb) printf("2\n");

    else if(dr>d && rb>ra) printf("-2\n");

    else printf("1\n");

  }

  return 0;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <class T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
bool chmin(T &a, const T &b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}

// 本体

ll nm[214514] = {};
ll pm[214514] = {};
int main() {
	IOS();
	ll n;
	cin>> n;
	if(n % 1000 == 0){
		dump(0);
	}else {
		dump(1000 - n % 1000);
	}
}


Measured memory_bytes: 3648