akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
using namespace std;
int n;
map<int, int> mp;
int res=0;
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		mp[x]++;
	}
	for (int i=30;i>=0;i--)
	{
		for (map<int, int>::iterator it=mp.begin();it!=mp.end() && 2*it->first<=(1<<i);it++)
		{
			if (it->second==0) continue;
			int t=(1<<i)-it->first;
			if (t==it->first)
			{
				int tt=it->second/2;
				res+=tt;
				it->second-=tt*2;
			}
			else
			{
				map<int, int>::iterator tt=mp.find(t);
				if (tt!=mp.end())
				{
					int tap=min(it->second,tt->second);
					it->second-=tap;
					tt->second-=tap;
					res+=tap;
				}
			}
		}
	}
	printf("%d",res);
	return 0;
}

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

void chmax(int &a,int b){a=max(a,b);}
int n,m,q,v[10],a[50],b[50],c[50],d[50],ans,now;
void check(){
  int res=0;
  for(int i=0;i<q;i++)if(v[b[i]-1]-v[a[i]-1]==c[i])res+=d[i];
  chmax(ans,res);
}

int main(){
  cin>>n>>m>>q;
  for(int i=0;i<q;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
  while(~now){
    now=n-1;
    while(~now&&++v[now]>=m)v[now--]=0;
    for(int i=1;i<n;i++)chmax(v[i],v[i-1]);
    check();
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 100100;
vector<int> g[N];
int a[N];
int n;

void dfs(int v, int par) {
    a[v] = 0;
    for (int u : g[v]) {
        if (u == par) continue;
        dfs(u, v);
        a[v] ^= a[u] + 1;
    }
    return;
}

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

    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int v, u;
        scanf("%d%d", &v, &u);
        v--;u--;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    dfs(0, -1);
    if (a[0] == 0)
        printf("Bob\n");
    else
        printf("Alice\n");

    return 0;
}

Measured memory_bytes: 12416
n = int(input())
a = list(map(int, input().split()))
s = 0
j = 0
ans = 0
for i in range(n):
    while s + a[i] != s ^ a[i]:
        s -= a[j]
        j += 1
    else:
        s += a[i]
        ans += i - j + 1
print(ans)

Measured memory_bytes: 24712
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(len(B)):
  remain = A[i]-B[i]
  if remain >= 0:
    ans += B[i]
  else:
    if i <= N:
      #A[i+1]を超えない分のremainだけ有効
      remain = max(remain,-A[i+1])
      A[i+1] += remain
      ans += (A[i]-remain)
print(ans)

Measured memory_bytes: 18624
# coding: utf-8
# Your code here!
N,M = map(int,input().split())
bulbs = []
for i in range(M):
    l = list(map(int,input().split()))
    bulbs.append(l)
p = list(map(int,input().split()))

ans = 0
for i in range(2 ** N):
    switches = []
    for j in range(N):
        if (i >> j) & 1:
            switches.append(1)
        else:
            switches.append(0)
    
    #print(switches)
    #条件を満たすかどうか調べる
    flag = True
    for x in range(M):
        count = 0
        k = bulbs[x][0]
        for y in range(1, k + 1):
            if switches[bulbs[x][y] - 1] == 1:
                count += 1
        if (count % 2) != p[x]:
            flag = False
            break
    
    if flag == True:
        ans += 1
        
print(ans)        

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

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

    deque<int> deq;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (i % 2 == 0) {
            deq.push_back(x);
        } else {
            deq.push_front(x);
        }
    }

    if(n & 1) {
        reverse(deq.begin(), deq.end());
    }

    for (int x : deq) {
        cout << x << " ";
    }

    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

int main(int argc, char *argv[]){
    int N;
    std::cin >> N;
    std::string S;
    std::cin >> S;
    int sum=1;
    char tmp = S[0];
    for(int i=1; i<N; ++i){
        if(S[i] != tmp){
            ++sum;
            tmp = S[i];
        }
    }
    std::cout << sum << std::endl;

    return 0;
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll H, W;
    cin >> H >> W;
    ll ans;

    if (H % 3 == 0 || W % 3 == 0) {
        ans = 0;
    } else {
        ans = min(W, H);
    }

    for (ll h = 1; h < H; ++h) {
        ll s1 = h * W;
        ll w = W / 2;
        ll s2 = (H - h) * w;
        ll s3 = (H - h) * (W - w);
        ans = min(ans, abs(max({s1, s2, s3}) - min({s1, s2, s3})));
    }

    for (ll w = 1; w < W; ++w) {
        ll s1 = H * w;
        ll h = H / 2;
        ll s2 = (W - w) * h;
        ll s3 = (W - w) * (H - h);
        ans = min(ans, abs(max({s1, s2, s3}) - min({s1, s2, s3})));
    }
    cout << ans << endl;

}

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	long int n,m; scanf("%ld %ld",&n,&m);
	long int ary[n+1];
	for (long int i=0; i<=n; i++) {
		ary[i]=1;
	}
	long int l; 
	for (long int i=0; i<m; i++) {
		scanf("%ld",&l); ary[l]=0;
	}
	for (long int i=2; i<=n; i++) {
		if (ary[i]!=0) ary[i]=(ary[i-2]+ary[i-1])%1000000007;
	}
	printf("%ld\n",ary[n]);
	return 0;
}


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

int main()
{
	int N;
	long long A, B;
	cin >> N >> A >> B;
	long long X[N];
	for(int i = 0; i < N; i++){
		long long x;
		cin >> x;
		X[i] = x;
	}

	long long cost = 0;
	for(int i = 1; i < N; i++){
		if(A * (X[i] - X[i - 1]) < B) cost += A * (X[i] - X[i - 1]);
		else cost += B;
	}
	cout << cost << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    long long a[2],i;
    for(i=0;i<2;i++)
    cin>>a[i];
    sort(a,a+2);
    if(a[0]!=1)
    cout<<1;
    else if(a[1]!=2)
    cout<<2;
    else if(a[1]!=3)
    cout<<3;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def prime_factorization(n):
    factor=[]
    sqrt=int(n**.5) # sqrt=ceil(sqrt(n))
    for d in range(2,sqrt+1):
        while(n%d==0):
            n//=d
            factor.append(d)
    if n!=1: factor.append(n)
    return factor

def resolve():
    a,b=map(int,input().split())
    from fractions import gcd
    g=gcd(a,b)
    factor=prime_factorization(g)
    print(len(set(factor))+1)
resolve()

Measured memory_bytes: 64748
#include <iostream>

#define N_MAX 200000

using namespace std;

typedef unsigned long long ll;

ll x[N_MAX];
ll sum[N_MAX+1];

ll cost(int n){
    if(n == 1) return 5;
    else return n*2+1;
}

int main(){
    ll N, X;
    cin >> N >> X;
    ll ans = __LONG_LONG_MAX__;
    //if(N > 2000) return 0;
    sum[0] = 0;
    for(int i = 0; i < N ; i++){
        cin >> x[i];
        sum[i+1] = sum[i]+x[i];
    }
    for(ll i = 1; i <= N; i++){
        ll m, k;
        if(N%i == 0){
            m = N/i;
            k = i;
        }else{
            m = N/i+1;
            k = N%i;
        }
        ll tmp = X*i + X*N;
        tmp += (sum[k]-sum[0])*cost(m);
        
        for(ll j = 1; j < m; j++){
            tmp += (sum[k+j*i]-sum[k+(j-1)*i])*cost(m-j);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
n = int(input())
a = [int(x) for x in input().split()]
mult = 1
for i in range(n):
    mult *= a[i]
    if mult > 1e+18:
        mult = -1
        break
        
for i in range(n):
    if a[i] == 0:
        mult = 0

print(mult)

Measured memory_bytes: 21576
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,m:usize,
       mut ab:[(usize,usize);n],
    }
    ab.sort();
    let mut hp = BinaryHeap::new();
    let mut ind = 0;
    let mut ans = 0;
    for day in 1..=m {
        while ind < n && ab[ind].0 <= day {
            hp.push(ab[ind].1);
            ind += 1;
        }
        if let Some(x) = hp.pop() {
            ans += x;
        }
    }
    println!("{}", ans);
}


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

#define N 100005

int n, k;
vector <int> A, B, C;

int main() {
	scanf("%d %d", &n, &k);
    if (2*k > n+1) return puts("-1"), 0;
    else {
        for (int i = k; i < k + n; i ++) A.push_back(i), B.push_back(i + n), C.push_back(i + n * 2);
        int d = (n + 1) >> 1;
        for (int i = n-d; i < n; i ++) {
            int x = A[i];
            int y = B[n-1-(i-(n-d))*2];
            int z = C[n-(i-(n-d-1))];
            printf("%d %d %d\n", x, y, z);
        }
        for (int i = 0; i < n-d; i ++) {
            int x = A[i];
            int y = B[n-2-i*2];
            int z = C[n-d-i-1];
            printf("%d %d %d\n", x, y, z);
        }
    }
	return 0;
}


Measured memory_bytes: 4628
def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    cntM = 0
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
            cntM += 1
    if 0 in A or cntM % 2 == 0:
        print(sum(A))
    else:
        print(sum(A) - min(A) * 2)

resolve()


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

int main() {
int n, w;
scanf("%d %d", &n, &w);
vector<int > wt(n), val(n);
for(int i=0; i<n; ++i){
	scanf("%d %d",&wt[i] , &val[i]);
}

vector< vector< long long> > dp(n+1, vector<long long> (w+1,0));

for(int i=1; i<=n; ++i){
	for(int j=1; j<=w; ++j){
		dp[i][j] = dp[i-1][j];
		if(wt[i-1]<=j)
		dp[i][j] = max(val[i-1] + dp[i-1][j-wt[i-1]]  , dp[i][j]);
	}
}

printf("%ld\n", dp[n][w]);
	
	

	return 0;
}


Measured memory_bytes: 83072
package main

import (
	"fmt"
	"math"
)

func round(f float64) float64 {
	return math.Floor(f + .5)
}

func main() {
	var N int
	fmt.Scan(&N)

	X := make([]int, N)
	sum := 0
	for i, _ := range X {
		fmt.Scan(&X[i])
		sum += X[i]
	}

	avg := int(round(float64(sum) / float64(N)))

	result := 0
	for _, x := range X {
		result += (x - avg) * (x - avg)
	}

	fmt.Println(result)
}


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

#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 3002;
int dp[N][N][2];
int a[N];
int n;

int get(int i,int j,int k)
{
    if(i>j) return 0;
    if(dp[i][j][k] != -1) return dp[i][j][k];
    
    int a1 = -get(i+1,j,k^1) + a[i];
    int a2 = -get(i,j-1,k^1) + a[j];
    
    return dp[i][j][k] = max(a1,a2);
}

void solve()
{
   memset(dp,-1,sizeof(dp)); 
    
   cin >> n;
    
   f(i,n) cin >> a[i];
    
   cout << get(0,n-1,0) << '\n'; 
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 141312
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
typedef long long LL;
int pre[maxn], nxt[maxn * 2], w[maxn * 2], to[maxn * 2], cnt = 0;
void addEdge(int x, int y, int v) {
  w[cnt] = v;
  nxt[cnt] = pre[x];
  to[pre[x] = cnt++] = y;
}
LL dep[maxn];
void dfs(int x, int f) {
  for (int i = pre[x]; ~i; i = nxt[i])
    if (to[i] != f) {
      dep[to[i]] = dep[x] + w[i];
      dfs(to[i], x);
    }
}
int main() {
  memset(pre, -1, sizeof pre);
  int n, x, y, v;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d%d", &x, &y, &v);
    addEdge(x, y, v);
    addEdge(y, x, v);
  }
  int q, k;
  scanf("%d%d", &q, &k);
  dep[k] = 0;
  dfs(k, -1);
  while (q--) {
    scanf("%d%d", &x, &y);
    printf("%lld\n", dep[x] + dep[y]);
  }
  return 0;
}


Measured memory_bytes: 9984
using System;

namespace ITP1_6_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int n = int.Parse(N);
            int[,] bill1 = new int[4, 11];
            int[,] bill2 = new int[4, 11];
            int[,] bill3 = new int[4, 11];
            int[,] bill4 = new int[4, 11];

            for (int i = 0; i < n; i++)    //n件の情報
            {
                string Data = Console.ReadLine();
                int b = int.Parse(Data.Split(' ')[0]);
                int f = int.Parse(Data.Split(' ')[1]);
                int r = int.Parse(Data.Split(' ')[2]);
                int v = int.Parse(Data.Split(' ')[3]);
                
                switch(b)
                {
                    case 1:
                        bill1[f, r] += v;
                        break;
                    case 2:
                        bill2[f, r] += v;
                        break;
                    case 3:
                        bill3[f, r] += v;
                        break;
                    case 4:
                        bill4[f, r] += v;
                        break;
                }
            }
            for (int i = 1; i < 4; i++)
            {
                for (int j = 1; j < 11; j++)
                {
                    Console.Write(" {0}", bill1[i, j]);
                }
                Console.Write("\n");
            }
            Console.WriteLine("####################");
            for (int i = 1; i < 4; i++)
            {
                for (int j = 1; j < 11; j++)
                {
                    Console.Write(" {0}", bill2[i, j]);
                }
                Console.Write("\n");
            }
            Console.WriteLine("####################");
            for (int i = 1; i < 4; i++)
            {
                for (int j = 1; j < 11; j++)
                {
                    Console.Write(" {0}", bill3[i, j]);
                }
                Console.Write("\n");
            }
            Console.WriteLine("####################");
            for (int i = 1; i < 4; i++)
            {
                for (int j = 1; j < 11; j++)
                {
                    Console.Write(" {0}", bill4[i, j]);
                }
                Console.Write("\n");
            }
        }
    }
}


Measured memory_bytes: 18012
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

template<typename T>
struct WG{
  using P = pair<int, T>;
  using Q = pair<T, int>;
  int n; T cost;
  vector<vector<P>> graph;
  vector<T> ans;
  WG(int n_){
    n = n_;
    graph.resize(n); ans.resize(n, 1e18);
  }
  void add_edge1(int from, int to, T cost){
    P edge;
    edge.first = to; edge.second = cost;
    graph[from].push_back(edge);
  }
  void add_edge2(int from, int to, T cost){
    P edge1, edge2;
    edge1.first = to; edge1.second = cost;
    edge2.first = from; edge2.second = cost;
    graph[from].push_back(edge1);
    graph[to].push_back(edge2);
  }
  void dijkstra(int start){
    ans[start] = 0; Q s; s.first = 0; s.second = start;
    priority_queue<Q, vector<Q>, greater<Q>> pque;
    pque.push(s);
    vector<bool> seen(n, 1);
    while(!pque.empty()){
      Q tmp = pque.top(); pque.pop();
      int x = tmp.second;
      seen[x] = 0;
      for(auto edge: graph[x]){
        if(!seen[edge.first]) continue;
        if(ans[edge.first] > ans[x] + edge.second){
          ans[edge.first] = ans[x] + edge.second;
          Q next; next.first = ans[edge.first]; next.second = edge.first;
          pque.push(next);
        }
      }
    }
  }
};
struct en{
  ldouble x, y, r;
};

int main(){
  en st, go; cin >> st.x >> st.y >> go.x >> go.y; st.r = 0; go.r = 0;
  int n; cin >> n;
  WG<ldouble> g(n+2);
  vector<en> v(n+2);
  rep(i, n) cin >> v[i].x >> v[i].y >> v[i].r;
  v[n] = st; v[n+1] = go;
  rep(i, n+1){
    rep(j, n+1-i){
      ldouble zero = 0;
      ldouble tmpr = max(zero, sqrtl((v[i].x - v[i+j+1].x)*(v[i].x - v[i+j+1].x)+(v[i].y - v[i+j+1].y)*(v[i].y - v[i+j+1].y))-v[i].r-v[i+j+1].r);
      g.add_edge2(i, i+j+1, tmpr);
    }
  }
  g.dijkstra(n);
  cout << fixed << setprecision(10) << g.ans[n+1] << "\n";
  return 0;
}

Measured memory_bytes: 42764
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int a,p;

int main(){
    INIT;
    cin >> a >> p;
    p += a*3;
    cout << (p/2);
}

Measured memory_bytes: 892
#include <stdio.h>
typedef long long ll;

ll power(ll x, ll y);

int main()
{
    ll m, k;

    scanf("%lld %lld", &m, &k);

    if ((m == 1 && k == 1) ||
        k >= power(2, m)) {
        printf("-1\n");

        return 0;
    }

    if (m == 1 && k == 0) {
        printf("0 0 1 1\n");
        return 0;
    }

    ll max_e = power(2, m);
    printf("%lld", k);
    for (ll i = 0; i < max_e; i++) {
        if (i != k) {
            printf(" %lld", i);
        }
    }
    printf(" %lld", k);
    for (ll i = max_e - 1; i >= 0; i--) {
        if (i != k) {
            printf(" %lld", i);
        }
    }
    putchar('\n');    

    return 0;
}

ll power(ll x, ll y)
{
    ll res = 1;

    for (ll i = 0; i < y; i++) {
        res *= x;
    }

    return res;
}


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

const int maxn = 1e5+5;
int n;
ll m;
ll a[maxn];
ll pre[maxn];

ll cnt(ll x) {
    ll res = 0;
    int pt = 0;
    for (int i = n-1; i >= 0; i--) {
        while (pt < n && a[pt]+a[i] >= x) pt++;
        res += pt;
    }
    //cout << x << ": " << res << endl;
    return res;
}

ll get(ll x) {
    ll res = 0;
    int pt = 0;
    for (int i = n-1; i >= 0; i--) {
        while (pt < n && a[pt]+a[i] >= x) pt++;
        res += pre[pt-1]+pt*a[i];
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a,a+n,greater<ll>());
    for (int i = 0; i < n; i++) {
        pre[i] = i==0?a[i]:a[i]+pre[i-1];
    }
    ll lo = 0, hi = 1e16;
    //find maximum x s.t. cnt(x) >= n
    while (lo + 1 < hi) {
        ll mid = (lo+hi)/2;
        if (cnt(mid) >= m) {
            lo = mid;
        }
        else hi = mid;
    }
    cout << get(lo)-(cnt(lo)-m)*lo << '\n';
}



Measured memory_bytes: 1792
#include <iostream>
using namespace std;
typedef long long ll;
int target = 1;
char c[30];
void cetak(ll num , int cnt){
    if (cnt < target)
        cetak(num / 26 , cnt + 1);
    cout << c[num % 26];
}
int main(){
    for (int i = 'a' ; i <= 'z' ; i++)
        c[i - 'a'] = i;
    ll N;
    cin >> N;
    --N;
    ll penambah = 0 , pengali = 1;
    while(penambah + pengali * 26 <= N){
        pengali *= 26;
        penambah += pengali;
        ++target;
    }
    N -= penambah;
    cetak(N , 1);
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const ll INF=1e9;
const double PI=acos(-1);
const int MAX=200010;

int n;
vector<vector<int>> h(510,vector<int>(510,1)),s(510,vector<int>(510,1));
vector<int> di={-1,0,1,0},dj={0,-1,0,1};

void dfs(int i,int j) {
    int d=h[i][j]+s[i][j];
    rep(k,4) {
        int ni=i+di[k],nj=j+dj[k];
        if (ni>=0 && ni<n && nj>=0 && nj<n) {
            if (h[ni][nj]>d) {
                h[ni][nj]=d;
                dfs(ni,nj);
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);

    cin >> n;
    ll ans=0;
    rep(i,n) {
        rep(j,n) h[i][j]=min(min(i,n-1-i),min(j,n-1-j));
    }
    rep(k,n*n) {
        int p;
        cin >> p;
        --p;
        int i=p/n,j=p%n;
        s[i][j]=0;
        ans+=h[i][j];
        dfs(i,j);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 17072
#include <bits/stdc++.h>
using namespace std;
int main(){
   string s;
   cin>>s;
   string a;
   int kai=0;
   for(int i=0;i<s.size();i++){
     if(s[i]=='0'){
         a[kai]='0';
         kai++;
     }
     else if(s[i]=='1'){
       a[kai]='1';
       kai++;
     }
     else{
         if(kai!=0){
             kai--;
         } 
     }
   }
   for(int i=0;i<kai;i++){
     cout<<a[i]; 
   }
   cout<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
typedef long long ll;
int N;
ll L[87];
int main() {
	scanf("%d", &N);

	L[0] = 2LL; L[1] = 1LL;

	for (int i = 2; i <= N; i++) {
		L[i] = L[i - 1] + L[i - 2];
	}
	printf("%lld\n", L[N]);
}

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

using namespace std ;

#define N 200000
#define LL long long
#define inf 21474836470000000

LL suma , sumb , sum , n , siz , ans ;
LL befa[N] , befb[N] ;

struct node{
    LL a , b , c ;
}A[N] ;

bool cmp(node L , node R ){
    return (L.a - L.b) > (R.a - R.b) ;
}

priority_queue<int> q ;

int main()
{   
    LL x , y , z ;
    scanf("%lld%lld%lld" , &x , &y , &z ) ;
    n = x + y + z ;
    for(int i = 1 ; i <= n ; i++ ){
        LL a , b , c ;
        scanf("%lld%lld%lld" , &a , &b , &c ) ;
        sum += c ;
        A[i].a = a - c ;
        A[i].b = b - c ;
    }
    sort( A + 1 , A + n + 1 , cmp ) ;
    for(int i = 1 ; i <= n ; i++ ) befa[i] = befb[i] = (-inf) ;
    for(int i = 1 ; i <= n ; i++ ){
        q.push( -A[i].a ) ;
        suma += A[i].a ;
        siz++ ;
        if( siz == x ) befa[i] = suma ;
        if( siz > x ){
            siz-- ;
            LL t = q.top() ;
            suma += t ;
            q.pop() ;
            befa[i] = suma ;
        }
    }
    siz = 0 ;
    while( !q.empty() ) q.pop() ;
    for(int i = n ; i >= 1 ; i-- ){
        q.push( -A[i].b ) ;
        sumb += A[i].b ;
        siz++ ;
        if( siz == y ) befb[i] = sumb ;
        if( siz > y ){
            siz-- ;
            LL t = q.top() ;
            sumb += t ;
            q.pop() ;
            befb[i] = sumb ;
        }
    }
    for(int i = x ; i <= n - y ; i++ ) ans = max( ans , befa[i] + befb[i + 1] + sum ) ;
    printf("%lld\n" , ans ) ;
    return 0 ;
}

Measured memory_bytes: 7804
n = int(input())
a = list(map(int,input().split()))
i = 1
j = 0
count = 0
while j < n:
  if a[j] == i:
    i += 1
  else:
    count += 1
  j += 1
if count == n:
  print('-1')
  exit()
print(count)

Measured memory_bytes: 77644
import std.functional,
       std.algorithm,
       std.typecons,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;


void main() {
  int[] NQ = readln.chomp.split.to!(int[]);
  int N = NQ[0],
      Q = NQ[1];
  string s = readln.chomp;
  alias LR = Tuple!(int, "l", int, "r");
  LR[] lrs;
  lrs.length = Q;
  int[] dp;
  dp.length = N;

  foreach (i; 0..Q) {
    int[] lr = readln.chomp.split.to!(int[]);
    lrs[i] = tuple(lr[0], lr[1]);
  }

  for (size_t i = 1; i < s.length; i++) {
    if (s[i] == 'C' && s[i - 1] == 'A') {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = dp[i - 1];
    }
  }

  foreach (lr; lrs) {
    writeln(dp[lr.r - 1] - dp[lr.l - 1]);
  }
}

Measured memory_bytes: 5244
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string str[55];
bool book[55][55];
int nx[]={0,-1,0,1};
int ny[]={1,0,-1,0};
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>str[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(str[i][j]=='#'){
				for(int q=0;q<4;q++){
					int dx=i+nx[q];
					int dy=j+ny[q];
					if(dx<0||dy<0||dx>n||dy>m||str[dx][dy]!='#') continue;
					book[i][j]=book[dx][dy]=true;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(str[i][j]=='#'&&book[i][j]==false) {
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,m,n) for(int i=m;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	int n, m;
	cin>>n>>m;
	int s[m], c[m];
	int max_digit=-1;
	REP(i,m){
		cin>>s[i]>>c[i];
		s[i]=n-s[i]+1;
		max_digit=max(max_digit, s[i]-1);
	}
	int log[n];
	REP(i,n)log[i]=-1;
	REP(i,m){
		if(log[s[i]-1]!=-1 && log[s[i]-1]!=c[i]){
			cout<<-1<<endl;
			return 0;
		}
		log[s[i]-1]=c[i];
	}
	if(n==1){
		if(log[0]==-1 || log[0]==0){
			cout<<0<<endl;
			return 0;
		}
	}
	REP(i,m){
		if(log[s[i]-1]==0 && s[i]-1==n-1){
			cout<<-1<<endl;
			return 0;
		}
	}
	int ans=0;
	REP(i,n){
		if(log[i]!=-1)ans+=log[i]*pow(10,i);
	}
	if(log[n-1]==-1)ans+=1*pow(10,n-1);


	cout<<ans<<endl;
	return 0;
}


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

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

accSA = [0] * (len(S) + 1)
accSB = [0] * (len(S) + 1)

for i, s in enumerate(S):
    accSA[i + 1] += accSA[i]
    accSB[i + 1] += accSB[i]
    if s == 'A':
        accSA[i + 1] += 1
    else:
        accSB[i + 1] += 1

accTA = [0] * (len(T) + 1)
accTB = [0] * (len(T) + 1)

for i, s in enumerate(T):
    accTA[i + 1] += accTA[i]
    accTB[i + 1] += accTB[i]
    if s == 'A':
        accTA[i + 1] += 1
    else:
        accTB[i + 1] += 1

Q = int(input())
ans = []
for _ in range(Q):
    a, b, c, d = map(int, input().split())

    sA = accSA[b] - accSA[a - 1]
    sB = accSB[b] - accSB[a - 1]
    tA = accTA[d] - accTA[c - 1]
    tB = accTB[d] - accTB[c - 1]

    sA = (sA + sB * 2) % 3
    tA = (tA + tB * 2) % 3

    ans.append('YES' if sA == tA else 'NO')
print(*ans, sep='\n')


Measured memory_bytes: 22384
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int G[104];
int main(){
    int n;
    cin >> n;
    vector<int> F[n];
    rep(i,n){
        rep(j,10){
            int f;
            cin >> f;
            F[i].push_back(f);
        }
    }
    int p[n][11];
    rep(i,n){
        rep(j,11){
            cin >> p[i][j];
            //cerr<<p[i][j]<<' ';
        }
        //cerr<<endl;
    }
    ll ans=-INF;
    for(int i=1;i<=pow(2,10)-1;i++){
        rep(j,n){G[j]=0;}
        ll temp=0;
        rep(j,10){
            if((i>>j)&1==1){
                rep(k,n){
                    if(F[k][j]==1){
                        G[k]++;
                    }
                }
            }
        }
        rep(j,n){
            temp+=p[j][G[j]];
            /*
            if(i==32){
                cerr<<G[j]<<' '<<p[j][G[j]]<<' ';
            }
            */
            //cerr<<G[j]<<' ';
        }
        //cerr<<endl;
        if(ans<temp){
            ans=temp;
            //cerr<<temp<<' '<<i<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    int A,B;
    cin>>A>>B;
    if(A<10&&B<10){
        cout<<A*B<<endl;
    }
    else{
        cout<<-1<<endl;
    }
  
   
}




Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double db;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll qsm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n,m,k,rt;

int main(){
    scanf("%d%d",&n,&m);
    if(n>m) swap(n,m);
    while(m) putchar(n+'0'), --m;
    return 0;
}
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n; cin >> n;
    string s; cin >> s;

    map<char, ll> ma;
    ma['R'] = 0;
    ma['G'] = 0;
    ma['B'] = 0;

    for (ll i = 0; i < n; ++i) {
        if (s[i] == 'R') ma['R']++;
        if (s[i] == 'G') ma['G']++;
        if (s[i] == 'B') ma['B']++;
    }

    ll ans = ma['R'] * ma['G'] * ma['B'];

    for (ll t = 1; t < n; ++t) {
        for (ll i = 0; i < n; ++i) {
            set<char> se;
            se.insert(s[i]);

            if (i + t >= n) break;
            se.insert(s[i + t]);

            if (i + t + t >= n) break;
            se.insert(s[i + t + t]);

            if (se.size() == 3) ans--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(){
  char a, b, c, d;
  scanf(" %c", &a);
  scanf(" %c", &b);
  scanf(" %c", &c);
  scanf(" %c", &d);
  if((a == b) || (b == c) || (c == d)){
    printf("Bad\n");
  }else{
    printf("Good\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  long ans = 0, a;
  for(int i = 1; i <= N; i++){
    cin >> a;
    if(i % 2 == 1 && a % 2 == 1)ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
n = gets.to_i

edges = Array.new(n){Array.new}

(n-1).times do |i|
  u, v, w = gets.split.map(&:to_i)
  edges[u-1] << [v-1, w]
  edges[v-1] << [u-1, w]
end

dist = Array.new(n, 0)
visited = Array.new(n,false)
q = [0]

while !q.empty? do
  from = q.shift
  visited[from] = true

  edges[from].each do |(to, wgt)|
    next if visited[to]
    dist[to] = dist[from] + wgt
    q << to
  end
end

n.times do |i|
  if dist[i] %2 == 0
    puts "0"
  else
    puts "1"
  end
end


Measured memory_bytes: 28284
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
  // 回答を記述
  const N = parseInt(inputList[0].split(' ')[0]);
  // [高さ, 隣より高いbool]
  const peaks = inputList[1].split(' ').map(ele => parseInt(ele)).map(ele => [ele, true]);
  // 道のリスト（idx >= 2）から隣以下の高さであればboolをfalseにする
  for (let i = 2; i < inputList.length; i++) {
    const AB = inputList[i].split(' ');
    if (peaks[AB[0] - 1][0] <= peaks[AB[1] - 1][0] ) peaks[AB[0] - 1][1] = false;
    if (peaks[AB[0] - 1][0] >= peaks[AB[1] - 1][0] ) peaks[AB[1] - 1][1] = false;
  }
  // 高いbool == true　の要素数を出力する
  console.log(peaks.filter(ele => ele[1] == true).length)

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 71920
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int T = Integer.parseInt(scanner.next());
        int A = Integer.parseInt(scanner.next());

        double ansDiff = Integer.MAX_VALUE;
        int ansIndex = Integer.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            int h = Integer.parseInt(scanner.next());
            double temperature = T - h * 0.006;

            double diff = Math.abs(temperature - A);
            if (diff < ansDiff) {
                ansDiff = diff;
                ansIndex = i + 1;
            }
        }
        scanner.close();

        System.out.println(ansIndex);
    }
}



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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    const V<int> a = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                      1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    --K;
    cout << a[K] << endl;
    return 0;
}

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

#define int int64_t
#define pr(x) cout << x << endl;
#define vi vector<int>
#define vii vector< vector<int> >
#define mp make_pair
#define ii pair<int,int>
#define fr(i,x,n) for(i = x ; i< n ; i++)
#define f(i,n) for(i = 0 ; i< n ; i++)
#define ff first
#define ss second
#define pb push_back
#define SIZE 200001
#define mod 1000000007
#define int_max 1e12
void solve();
int dp[SIZE]={0};
 
int power(int a, int b)
{
    if(b==0) return 1;
    else if(b&1) return a*power(a*a,b/2);
    else return power(a*a, b/2);
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

int  j=1, n, t, m=0, dot=0, i,  l, r, k, q, x, y, z, n1, m1;

void solve()
{
//    cin >> t;while(t--)
   {
       cin >> n;
       vi a(n), b(n-1);
       f(i, n-1) cin >> b[i];
       a[0]=b[0];
       a[1]= b[0];
       for(i=2;i<n;i++)
       {
           a[i] = b[i-1];
       }

       f(i,n-1)
       {
           if(max(a[i], a[i+1])!= b[i]) {a[i]=b[i];a[i+1]=b[i];}
       }

       cout << accumulate(a.begin(), a.end(), 0);
   }
}

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

using namespace std;
typedef long long ll;
map<long, long> mp;

int main() {
    // freopen("output.txt", "w", stdout);
    ll a, b;
    ll ans = 0;
    cin >> a >> b;
    ll ans1 = 0, ans2 = 0;
    ll i;
    for (i = a - 1; i >= 0; i--) {
        if ((i + 1) % 4 == 0) break;
        ans1 ^= i;
    }
    for (i = b; i >= 0; i--) {
        if ((i + 1) % 4 == 0) break;
        ans1 ^= i;
    }
    cout << (ans1^ans2) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
	owo
	int n;
	cin>>n;
	vector<int>a(n),b(n),c(n);
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		cin>>b[i];
		c[(i+(n/2))%n] = b[i];
	}
	bool ok = 1;
	for(int i=0;i<n;i++){
		if(a[i] == c[i]){ok = 0;break;}
	}
	if(ok){
		cout<<"Yes"<<'\n';
		for(int i=0;i<n;i++)cout<<c[i]<<" ";
		return 0;
	}
	reverse(all(b));
	ok = 1;
	for(int i=0;i<n;i++){
		if(a[i] == b[i]){ok =0;break;}
	}
	if(ok){
		cout<<"Yes"<<'\n';
		for(int i=0;i<n;i++)cout<<b[i]<<" ";
		return 0;
	}	
	cout<<"No";
}	


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

int main(){
  // cout<<"Hello, world!"<<endl;
  // cout<<"こんにちは"<<endl;
  // cout<<"AtCoder"<<endl;
  // cout << "いつも" << 2525 << endl;
  // cout << "AtCoderくん"<< endl;
  int M;

  cin>>M;

  cout<<(24-M)+24<<endl;
}

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

int main() {
	int N,ans = 0;
	cin >> N;
	vector<int> P(N);
	for(int i = 0; i < N; i++){
		cin >> P.at(i);
	}
	sort(P.begin(),P.end());
	for(int i = 0; i < N; i++){
		int now = P.at(i);
		if(i == N - 1){
			now = P.at(i) / 2;
		}
		ans += now;
	}
	cout << ans << endl;
	return 0;
}

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


int main() {
  int n, N, i, t, sum = 0;
  cin >> n;
  N = n;

  for (i = 0; i < 8; i++){
    t = N;
    t %= 10;
    sum += t;
    N /= 10;
  }
  
  if(n % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int s[100]={};
  char a[100];
  scanf("%s",a);
  int i;
  int len=strlen(a);
  for(i=0;i<len;i++){
    s[a[i]-'a']++;
  }
  for(i=0;i<26;i++){
    if(s[i]>1){
      puts("no");
      return 0;
    }
  }
  puts("yes");
  return 0;
}



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

int main()
{
    int64_t n;
    cin >> n;

    int64_t ans = 0;
    for (int64_t i = 2; i * i <= n; i++)
    {
        int64_t ex_cnt = 0;
        while (n % i == 0)
        {
            ex_cnt++;
            n /= i;
        }

        for (int64_t j = 1;; j++)
        {
            if (ex_cnt < (j + 1) * j / 2)//sequence of differences.3,6,10...
            {
                ans += (j - 1);

                break;
            }
        }
    }

    if (n != 1)
    {
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
// ALDS1_4 D Search-Allocaion

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 100000
int n,k;
lli T[MAX]; 



int check(lli P){
	int i=0;
	for(int j=0;j<k;j++){
		lli s=0;
		while(s+T[i]<=P){
			s += T[i];
			i++;
			if(i==n)return n;
		}
	}
	return i;
}


int solve(){
	lli left=0;
	lli right=100000*10000;
	lli mid;
	while(right-left>1){
		mid = (left + right)/2;
		int v = check(mid);
		if(v >= n)right=mid;
		else left = mid;
	}
	return right;
}

 
int main () {
	cin >> n >> k;
	for(int i=0;i<n;i++) cin >> T[i];
	lli ans = solve();
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3852
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    int sum = 0;
    rep(i,n) {
        cin >> s[i];
        sum += s[i];
    }
    sort(all(s));
    int i = 0;
    while (sum % 10 == 0 && i < n) {
        if (s[i] % 10 != 0) {
            sum -= s[i];
        }
        i++;
    }
    if (sum % 10 == 0) {
        cout << 0 << endl;
    } else {
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
#define ll long long int

int main(void)
{
	int r;
	cin >> r;

	cout << r * r << endl;
}

Measured memory_bytes: 256
N = int(input())
tree = {}
ans = [0 for _ in range(N - 1)]

for i in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    tree.setdefault(a, []).append(i)
    tree.setdefault(b, []).append(i)
for k, v in tree.items():
    a = set(range(1, len(v)+1))
    b = set([ans[i] for i in v])
    if 0 in b:
        b.remove(0)
    a = list(a - b)
    c = 0
    for i in v:
        if ans[i] == 0:
            ans[i] = a[c]
            c += 1
print(max(ans))
print(*ans, sep='\n')

Measured memory_bytes: 75296
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	vector<int> v(n);
	for(int i=0;i<n;i++){
		v[i]=i+1;
	}
	int c,d;
	int cnt=0;
	do{
		if(v==a){
			c=cnt;
		}
		if(v==b){
			d=cnt;
		}
		cnt++;
	}while(next_permutation(v.begin(),v.end()));
	cout << abs(c-d) << endl;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
string s;
int a[maxn];

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

  cin>>s;
  n = s.length();

  for (int i=0; i<n; ) {
    int l = i;
    int m = i;
    while (m<n && s[m]=='R') m++;
    m--;
    int r = m+1;
    while (r<n && s[r]=='L') r++;
    r--;
    //cout<<l<<" "<<m<<" "<<r<<endl;

    int len=r-l+1;
    if (len%2==0) {
      a[m]=a[m+1]=(len/2);
    } else {
      a[m]=len/2 + 1;
      a[m+1]=len/2;
      if (m-l+1>r-m) {
	if ((m-l)%2==1) {
	  swap(a[m],a[m+1]);
	}
      } else {
	if ((r-(m+1))%2==0) {
	  swap(a[m],a[m+1]);
	}
      }
    }

    
    i = r+1;
  }


  for (int i=0; i<n; i++) {
    cout<<a[i]<<" ";
  }
  cout<<endl;
  return 0;
}


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

using namespace std;

int main(void) {
  int N, i, ans, tmp;
  vector<int> A, B, C;
  // get input ---------------------------
  cin >> N;
  for(i = 0; i < N; i++) {
    cin >> tmp;
    A.push_back(tmp - 1);
  }
  for(i = 0; i < N; i++) {
    cin >> tmp;
    B.push_back(tmp);
  }
  for(i = 0; i < N - 1; i++) {
    cin >> tmp;
    C.push_back(tmp);
  }
  // calc ---------------------------------
  ans = B[A[0]];
  for(i = 1; i < N; i++) {
    ans += B[A[i]];
    if((A[i-1] + 1) == A[i]) {
      ans += C[A[i-1]];
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;

  if (a > b)
  {
    swap(a, b);
  }

  string out = "";
  for (int i = 0; i < b; i++)
  {
    out += to_string(a);
  }

  cout << out << endl;
}

Measured memory_bytes: 256
N, K=map(int,input().split())
P=list(map(int,input().split()))
Sum=[0]* (N + 1)
for i in range(N):
    Sum[i+1]=Sum[i]+(P[i]+1)/2.0
Ans=0
for i in range(N-K+1):
    Ans=max(Ans,Sum[i+K]-Sum[i])
print(Ans)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend();
#define sz  size()
#define fr(i,a,b) for(int i=a ;i <= b ; i++ )
#define frr(i,a,b) for(int i=a ;i >= b ; i-- )
#define inp ios_base::sync_with_stdio(false);cin.tie(NULL);
#define PQ_INC vector<int>, greater<int>   //priority_queue
using namespace std ;

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

const int N = 3e5 + 9 ,  MOD = 1e9+7 , OO = 0x3f3f3f3f ;
int dX[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dY[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int n , d , c ;
vector < int > v[20] ;
int main(){
   cin >> n >> d ;
    for (int i = 0 ; i < n ; i++ ){
        for (int j = 0 ;j < d ; j++ ){
            int a ; cin >> a ;
            v[i].pb(a) ;
        }
    }
    for (int i = 0 ; i < n ; i++ ){

        for (int j = i+1 ; j < n ; j++) {
            int q = 0 ;
            for (int k = 0 ;k < d ; k++ ) q += abs (v[i][k] - v[j][k] ) * abs (v[i][k] - v[j][k] ) ;
            int w = sqrt(q) ;
            if (w * w == q ) c++ ;
        }

    }
     cout << c ;
}


Measured memory_bytes: 256