akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int INF = 5*1e8;

class UnionFind{
  vi p,r;
public:
  UnionFind(int n):p(n,-1),r(n,0){ }
  int find(int x){ return (p[x]<0)?x:(p[x] = find(p[x])); }
  bool same(int x,int y){return find(x)==find(y);}
  void unite(int x,int y){
    x = find(x); y = find(y);
    if(x==y)return;

    if(r[x] < r[y])p[x] = y;
    else p[y] = x;
    if(r[x] == r[y])r[x]++;
  }
};

inline int MSB(int x){ return x>0?31-__builtin_clz(x):-1; }

struct LCA{
  vector<vi> par,w;
  vi depth;
  int ln;
  
  LCA(void){}
  LCA(const vector<vi> &t, const vi weight, int root){
    int n = t.size(); ln = MSB(n)+1;
    depth.resize(n); par.resize(ln,vi(n));
    w.resize(ln,vi(n)); w[0] = weight;

    stack< pair<int,int> > s;
    s.push(make_pair(root,-1));
    while(s.size()){
      int v = s.top().first, p = s.top().second; s.pop();
      par[0][v] = p;
      depth[v] = ((p<0)?0:(depth[p]+1));

      for(int u : t[v]){
	if(u != p)s.push(make_pair(u,v));
      }
    }

    rep(k,ln-1)rep(v,n){
      if(par[k][v]<0){
	par[k+1][v] = -1;
	w[k+1][v] = INF;
      }else{
	par[k+1][v] = par[k][par[k][v]];
	w[k+1][v] = min(w[k][v], w[k][par[k][v]]);
      }
    }
  }

  inline int min_lca(int u, int v){
    int res = INF;
    if(depth[u] > depth[v])swap(u,v);
    rep(k,ln){
      if((depth[v]-depth[u])>>k & 1){
	res = min(res, w[k][v]);
	v = par[k][v];
      }
    }

    if(u==v)return min(res, w[0][u]);
    for(int k = ln-1;k>=0;k--){
      if(par[k][u] != par[k][v]){
	res = min(res, min(w[k][u], w[k][v]));
	u = par[k][u];
	v = par[k][v];
      }
    }
    return min(res, min(w[1][u], w[1][v]));
  }
  inline int dep(int v){ return depth[v]; }
};

int main(){
  int n,m,k,Q;
  scanf("%d%d%d%d",&n,&m,&k,&Q);
  vector< vector<pii> > g(n);
  rep(i,m){
    int a,b,l;
    scanf("%d%d%d",&a,&b,&l); a--; b--;
    g[a].push_back(pii(b,l));
    g[b].push_back(pii(a,l));
  }

  vi dis(n,INF);
  priority_queue<pii> q;
  rep(i,k){
    int f;
    scanf("%d",&f); f--;
    dis[f] = 0;
    q.push(pii(0,f));
  }

  while(q.size()){
    pii p = q.top(); q.pop();
    int d = -p.first, v = p.second;
    if(dis[v] < d)continue;
   
    for(pii nxt : g[v]){
      int u = nxt.first, cost = d+nxt.second;
      if(dis[u] > cost){
	dis[u] = cost;
	q.push(pii(-cost,u));
      }
    }
  }

  vector<pii> order(n);
  rep(i,n)order[i] = pii(dis[i],i);

  sort(all(order)); reverse(all(order));
  UnionFind uf(n);

  vector<vi> tree(n);
  rep(i,n){
    int v = order[i].second;
    vector<pii> nxt;
    for(pii p : g[v]){
      int u = p.first;
      nxt.push_back(pii(dis[u],u));
    }
    sort(all(nxt)); reverse(all(nxt));
    for(pii p : nxt){
      int u = p.second;
      if(dis[u] < dis[v])break;
      if(!uf.same(v,u)){
	tree[u].push_back(v);
	tree[v].push_back(u);
	uf.unite(v,u);
      }
    }
  }
 
  LCA query(tree, dis, 0);
  rep(i,Q){
    int u,v;
    scanf("%d%d",&u,&v); u--; v--;
    cout << query.min_lca(u,v) << endl;
  }
}

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

using namespace std;

int main() {
    int M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;
    if (M1 == M2) {
        cout << 0
             << "\n";
    } else {
        cout << 1
             << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char s[20];
	scanf("%s", s);
	int i;
	for (i = 0; s[i] != '\0'; i++) {
		if (s[i] == ',') {
			s[i] = ' ';
		}
		putchar(s[i]);
	}
	putchar('\n');
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r =sc.nextInt();
        int c =sc.nextInt();
        
        int[][] array = new int[r+1][c+1];
        int[] sum = new int[c+1];
        
        for(int i=0;i<r;i++){
            
            for(int j = 0;j<c;j++){
                
                array[i][j] = sc.nextInt();
            }
        }
         for(int i=0;i<r;i++){
             int k =0;
            for(int j = 0;j<c;j++){
			System.out.print(array[i][j]);
            k += array[i][j];
            sum[j] += array[i][j];
                if(j!=c)System.out.print(" ");
	            }
             sum[c] += k;
             System.out.println(k);
             }
        for(int numb = 0; numb<c+1;numb++){
                 System.out.print(sum[numb]);
                  if(numb!=c)System.out.print(" ");
         }
        System.out.println();
        sc.close();
    }
}


Measured memory_bytes: 42340
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

class UnionFindTree {
public:
    explicit UnionFindTree(size_t size = 0) {
        reset(size);
    }

    void reset(size_t size) {
        group.resize(size);
        rep(i, size) group[i] = i;
    }
 
    int getGroupId(int i) {
        int g = group[i];
        if (i != g) {
            group[i] = getGroupId(g);
        }
        return group[i]; 
    }

    bool inSameGroup(int i, int j) {
        return (getGroupId(i) == getGroupId(j));
    }

    void merge(int i, int j) {
        i = getGroupId(i);
        j = getGroupId(j);
        if (i != j) {
            group[i] = j;
        }
    }

private:
    vector<int> group;
};

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

    int N, M;
    cin >> N >> M;
    UnionFindTree uft(N);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        --A; --B;
        uft.merge(A, B);
    }

    map<int, int> cnt;
    rep(i, N) {
        ++cnt[uft.getGroupId(i)];
    }

    int ans = 0;
    for (auto it: cnt) {
        ans = max(ans, it.second);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13344
n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())
ab=[list(map(int,input().split())) for i in range(q)]

keta=len(format(n+1,"b"))
nxt = [[0 for _ in range(n)] for _ in range(keta)]
# nxt[k][node] == farthest node-num from node in 2**k days

import bisect
for i in range(n):
    num = x[i]+l
    ind = bisect.bisect_right(x,num)
    nxt[0][i] = ind-1

for k in range(1,keta):
    for i in range(n):
        nxt[k][i]=nxt[k-1][nxt[k-1][i]]

def solve(s,g,day):
    bi=format(day,"b")
    keta=len(bi)-1

    for b in bi:
        if b=="1":
            s=nxt[keta][s]
        keta-=1

    return s>=g
for a,b in ab:
    s=min(a,b)
    g=max(a,b)
    l=0
    r=n
    while r-l>1:
        mid=(l+r)//2
        if solve(s-1,g-1,mid):
            r=mid
        else:
            l=mid

    print(r)

Measured memory_bytes: 198932
#include <iostream>
#include <string>

using namespace std;
int main(){
    string n;
    cin >> n;

    //if (n <= 999 || n >= 111){
        for(int i(0); i <= sizeof(n); ++i){
            if(n[i] == '1'){
                cout <<"9";
            }else if(n[i] == '9'){
                cout <<"1";
            }
        }
        //endl;
    //}else{
    //   "111から999で入力してください。" 
    //}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,ans;

int main(){
    cin>>N;
    for(int i=1;i*i<=N;i++){
        ans=i*i;
    }
    out(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};

const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};


ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/

int main(){
  ll N;
  cin >> N;
  map<ll, ll> D;
  rep(i, N){
    ll d; cin >> d;
    D[d]++;
  }
  ll M;
  cin >> M;
  bool l = 1;
  rep(i, M){
    ll t; cin >> t;
    if(D[t] >= 1) D[t]--;
    else l = 0;
  }
  if(l) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 12928
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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

	cout << (3*r*r) << endl;

  return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
g=[input() for _ in range(h)]
from collections import *
d=[[-1]*w for _ in range(h)]
d[0][0]=0
q=deque([(0,0)])
while q:
  tx,ty=q.popleft()
  for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
    nx,ny=tx+dx,ty+dy
    if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]<0:
      d[nx][ny]=d[tx][ty]+1
      q.append((nx,ny))
print((h*w-sum(s.count('#') for s in g)-d[-1][-1])*(d[-1][-1]>0)-1)

Measured memory_bytes: 9472
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,x,*a = map(int,read().split())

ans = 0
for i in range(n-1):
    if a[i] + a[i+1] > x:
        d = a[i]+a[i+1]-x
        ans += d
        if a[i+1] >= d:
            a[i+1] -= d
        else:
            a[i+1] = 0
        
print(ans)      






Measured memory_bytes: 20032
#include <stdio.h>

int main(void)
{
	int A,B;
	scanf("%d %d",&A,&B);
	while(((A<1)||(3<A))||((B<1)||(3<B))){
		scanf("%d %d",&A,&B);
	}
	if((A*B)%2!=0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

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


typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
/*--------------------------------------------*/

int main(){
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N,H;
    cin >> N >> H;

    vector<ll> a(N),b(N);
    rep(i,N) cin >> a[i] >> b[i];

    sort(ALL(a));
    reverse(ALL(a));

    sort(ALL(b));
    reverse(ALL(b));

    ll ans = 0;

    rep(i,N){
        if(b[i] > a[0]){
            H -= b[i];
            ans++;
            if(H <= 0){
                cout << ans << endl;
                return 0;
            }
        }
    }


    cout << ans + (H + a[0] - 1) / a[0] << endl;

}

Measured memory_bytes: 1920
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int ans[] = new int[N+1];
        Arrays.fill(ans, 0);
        for (int x = 1;x<100; x++) {
            for (int y = 1; y<100; y++) {
                for(int z=1;z<100;z++){
                    int s = (int)(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2) + x * y + y * z + z * x);
                    if (s <=N) {
                        ans[s] = ans[s]+1;
                    }
                }
                    // System.out.println(ans);
            }
        }
        for (int i = 1; i <= N; i++) {
            System.out.println(ans[i]);
        }

    }
}

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

int main(){
    int n,m,temp;
    int matrix[100][100]={};
    int vector[100]={};
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>matrix[i][j];
        }
    }
    for(int k=0;k<m;k++){
        cin>>vector[k];
    }
    for(int l=0;l<n;l++){
        temp=0;
        for(int s=0;s<m;s++){
            temp+=matrix[l][s]*vector[s];
        }
        cout<<temp<<endl;
    }
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
 bool a[2000000000];
int main() {
  int N,b;
  cin>>N;
	for(int i=0;i<N;i++){
      cin>>b;
      if(a[b]==false){
        a[b]=true;
      }
      else{
        cout<<"NO";
        return 0;
      }
    }
  cout<<"YES";
}

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

int main() {
  int N;
  cin >>  N;
  int a = 0;
  int b = 10000000000;
  for (int i=0; i<N; i++) {
    int c;
    cin >> c;
    if(a < c) {
      a = c;
    }
    if(c < b) {
      b = c;
    }
  }
  cout << a - b << endl;
}


Measured memory_bytes: 256
#include <cstdio>
int main()
{
	int n;
	char prime[50001];
	for(int i = 0; i <= 50000; i++)
		prime[i] = 1;
	prime[0] = 0; prime[1] = 0;
	for(int i = 2; i <= 50000; i++){
		if(!prime[i]) continue;
		for(int j = i + i; j <= 50000; j += i)
			prime[j] = 0;
	}
	while(scanf("%d\n", &n), n){
		int cnt = 0;
		for(int i = 2; i <= n / 2; i++)
			if(prime[i] && prime[n - i])
				cnt++;
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 812
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=2010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
bool A[MAXN][MAXN], B[MAXN][MAXN];
int U[MAXN], L[MAXN], R[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	for (int i=1; i<=n; i++) for (int j=1; j<=m; j++){
		char ch;
		cin>>ch;
		A[i][j]=(ch=='#');
	}
	ans=max(n, m);
	n--;
	m--;
	for (int i=1; i<=n; i++) for (int j=1; j<=m; j++)
		B[i][j]=A[i][j]^A[i+1][j]^A[i][j+1]^A[i+1][j+1];
	for (int i=1; i<=n; i++){
		for (int j=1; j<=m; j++){
			if (B[i][j]) U[j]=0;
			else U[j]++;
		}
		for (int j=1; j<=m; j++) for (L[j]=j-1; L[j] && U[L[j]]>=U[j]; L[j]=L[L[j]]);
		for (int j=m; j; j--) for (R[j]=j+1; R[j]<=m && U[R[j]]>=U[j]; R[j]=R[R[j]]);
		for (int j=1; j<=m; j++) ans=max(ans, (U[j]+1)*(R[j]-L[j]));
	}
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 8192
K=int(input())
tmp=[1,2,3,4,5,6,7,8,9]
while True:
  k=len(tmp)
  if K<=k:
    print(tmp[K-1])
    break
  else:
    K-=k
    dum=tmp[:]
    tmp=[]
    for a in dum:
      if a%10==0:
        tmp.append(a*10+0)
        tmp.append(a*10+1)
      elif a%10==9:
        tmp.append(a*10+8)
        tmp.append(a*10+9)
      else:
        tmp.append(a*10+a%10-1)
        tmp.append(a*10+a%10)
        tmp.append(a*10+a%10+1)


Measured memory_bytes: 11388
#include<iostream>
using namespace std;
long long A,B,T;
long long dp[100];
int main()
{
    cin>>A>>B>>T;
    dp[1]=A;
    for(int i=2;i<=20;i++) dp[i]=dp[i-1]+A;
    long long sum=0;
    for(int i=1;i<=20;i++){
        if(dp[i]>T+0.5){
            break;
        }
        sum+=B;
    }
    cout<<sum<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    vector<int> a(5);
    for(int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < 5; i++) {
        if(a[i] == 0) {
            cout << i + 1 << endl;
        }
    }
}

Measured memory_bytes: 3608
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
    int minn=100000005;
    int n;
    cin>>n;
    int a[n];
    int sum=0;
    int s=0,s1=0;
    for(int i=0;i<n;i++)
        {cin>>a[i];sum+=a[i];}
        int t;
        t=sum/n;
        for(int i=0;i<n;i++)
        {
            s+=(a[i]-t)*(a[i]-t);
        }
        t+=1;
        for(int i=0;i<n;i++)
        {
            s1+=(a[i]-t)*(a[i]-t);
        }
        if(s>s1)
        cout<<s1<<endl;
        else
            cout<<s<<endl;

}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

ll N, Q;
vector<vector<int>> graph;
vector<ll> num, k;
vector<bool> memo;

void dfs(int n, ll t)
{
    t += num.at(n);
    k.at(n) += t;
    for (auto g : graph.at(n))
    {
        if (memo.at(g))
        {
            continue;
        }
        else
        {
            memo.at(g) = true;
        }
        dfs(g, t);
    }
    return;
}

int main()
{
    cin >> N >> Q;
    graph.resize(N);
    num.resize(N, 0);
    k.resize(N, 0);
    memo.resize(N, false);

    ll a, b;
    rep(1, i, N)
    {
        cin >> a >> b;
        a--;
        b--;
        graph.at(a).push_back(b);
        graph.at(b).push_back(a);
    }

    ll p, x;
    rep(0, i, Q)
    {
        cin >> p >> x;
        p--;
        num.at(p) += x;
    }

    memo.at(0) = true;
    dfs(0, 0);
    rep(0, i, N)
    {
        cout << k.at(i) << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 25856
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	s+=s.substr(0,s.size()-1);
	if(s.find(t)!=string::npos)
	  cout<<"Yes"<<endl;
	else
	  cout<<"No"<<endl; 
   
return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    alphabet = list(set(S))
    flag = False
    if len(alphabet) == 2:
        if S.count(alphabet[0]) == 2 and S.count(alphabet[1]) == 2:
            flag = True
    if flag :
        print("Yes")
    else:
        print("No")
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
from collections import Counter

def read():
    N = int(input().strip())
    S = list()
    for i in range(N):
        s = input().strip()
        S.append(s)
    return N, S

def solve(N, S):
    counter = Counter(S)
    outputs = list()
    max_count = None
    for k, v in counter.most_common():
        if max_count is None:
            max_count = v
        elif max_count > v:
            break
        outputs.append(k)
    return sorted(outputs)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    for output in outputs:
        print(output)


Measured memory_bytes: 45032
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void) {
	int n,a;
	cin >> n;
	vector<int> v,vv;
	for (int i = 0; i < n; i++) {
		cin >> a;
		v.push_back(a);
		vv.push_back(a);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++) {
		if (vv[i] < *(v.end()-1))cout << *(v.end()-1) << endl;
		else {
			cout << *(v.end()-2) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3436
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

int main () {
    
    int n; cin >> n;
    vector<int> v(n);
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    } 
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    } 
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if(v[i] > c[i]) {
            ans = ans + (v[i] - c[i]);
        } 
    } 

    cout << ans << endl;

    return 0;
}




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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  ll X;
  cin>>X;
  repl(n,1,361){
    if((360*n)%X==0){
      cout<<(360*n)/X<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, K;
    cin >> N >> K;
    set<int> st;
    for(int i = 0; i < K; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            st.insert(a);
        }
    }
    cout << N-st.size() << endl;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N = 2e5 + 7;
int dp[N];

int recur(int id, int n, int a[])
{
    if(id >= n - 1)
        return 0;

    if(dp[id] != -1)
        return dp[id];

    int ans = INT_MAX;

    ans = min(ans, abs(a[id + 1] - a[id]) + recur(id + 1, n, a));
    ans = min(ans, abs(a[id + 2] - a[id]) + recur(id + 2, n, a));

    return dp[id] = ans;
}

int32_t main()
{
    int n;
    cin >> n;
    int a[n];

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

    memset(dp, -1, sizeof(dp));
    cout << recur(0, n, a) << "\n";

}

Measured memory_bytes: 10368
import sys
from operator import itemgetter, attrgetter
from itertools import starmap
import cmath
from math import isinf, sqrt, acos, atan2
readline = sys.stdin.readline
EPS = 1e-9
ONLINE_FRONT = -2
CLOCKWISE = -1
ON_SEGMENT = 0
COUNTER_CLOCKWISE = 1
ONLINE_BACK = 2
class Circle(object):
    __slots__ = ('c', 'r')
    def __init__(self, c, r):
        self.c = c
        self.r = r
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
Line = Segment
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
def ccw(p1, p2, p3):
    a = p2 - p1
    b = p3 - p1
    if cross(a, b) > EPS: return 1
    if cross(a, b) < -EPS: return -1
    if dot(a, b) < -EPS: return 2
    if norm(a) < norm(b): return -2
    return 0
def intersect4(p1, p2, p3, p4):
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0)
def intersect2(s1, s2):
    return intersect4(s1.fi, s1.se, s2.fi, s2.se)
def getDistance(a, b):  return abs(a - b)
def getDistanceLP(l, p):
    return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))
def getDistanceSP(s, p):
    if dot(s.se - s.fi, p - s.fi) < 0.0: return abs(p - s.fi)
    if dot(s.fi - s.se, p - s.se) < 0.0: return abs(p - s.se)
    return getDistanceLP(s, p)
def getDistances(s1, s2):
    if intersect2(s1, s2): return 0.0
    return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se),
               getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))
def getCrossPoint(s1, s2):
	base = s2.se - s2.fi
	d1 = abs(cross(base, s1.fi - s2.fi))
	d2 = abs(cross(base, s1.se - s2.fi))
	t = d1 / (d1 + d2)
	return s1.fi + (s1.se - s1.fi) * t
def getCrossPoints(c, l):
    pr = project(l, c.c)
    e = (l.se - l.fi) / abs(l.se - l.fi)
    base = sqrt(c.r * c.r - norm(pr - c.c))
    return Segment(pr + e * base, pr - e * base)
def getCrossPointsCL(c, l):
    pr = project(l, c.c)
    e = (l.se - l.fi) / abs(l.se - l.fi)
    base = sqrt(c.r * c.r - norm(pr - c.c))
    return Segment(pr + e * base, pr - e * base)
def getCrossPointsCC(c1, c2):
    d = abs(c1.c - c2.c)
    a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2.0 * c1.r * d))
    t = cmath.phase(c2.c - c1.c)
    return Segment(*sorted((c1.c + cmath.rect(c1.r, t + a), c1.c + cmath.rect(c1.r, t - a)), key=attrgetter('real', 'imag')))
x, y, r = map(int, readline().split())
c1 = Circle(complex(x, y), r)
x, y, r = map(int, readline().split())
c2 = Circle(complex(x, y), r)
cpc = getCrossPointsCC(c1, c2)
print(*map('{:.10f}'.format, (cpc.fi.real, cpc.fi.imag, cpc.se.real, cpc.se.imag)))

Measured memory_bytes: 8356
/*
  AOJ 0592
  Title:Average Score
  @kankichi573
*/
#include <stdio.h>

main()
{
  int i,p,sum;

  for(i=0,sum=0;i<5;i++)
    {
      scanf("%d",&p);
      sum += ((p>40)?p:40);
    }
  printf("%d\n",sum/5);
  return(0);
}

Measured memory_bytes: 596
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a:String,
        b:String

    };
    if a[..] == b[..b.len() - 1] && a.len() == b.len()-1 {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(){
	int n;
	cin>>n;
	vector<int> x(n), y(n);
	vector<P> xp(n), yp(n);
	rep(i, n){
		cin>>x[i]>>y[i];
		x[i]= -x[i];
		xp[i]=make_pair(x[i], i);
		yp[i]=make_pair(y[i], i);
	}

	sort(xp.begin(), xp.end());
	sort(yp.begin(), yp.end());

	int xi=0, yi=0;
	int xm=xp[0].first, ym=yp[0].first, xv=xp[0].second, yv=yp[0].second;
	int c=0;
	vector<int> g(n, -1);
	while(xi<n){
		xm=xp[xi].first, ym=yp[yi].first;
		xv=xp[xi].second, yv=yp[yi].second;
		g[xv]=g[yv]=c;
		if(xv==yv){//shougai kodoku
			xi++; yi++;
		}
		else{
			xm=max(xm, x[yv]);
			ym=max(ym, y[xv]);
			while(1){
				bool updated=false;
				for(; xp[xi].first<=xm; xi++){
					xv=xp[xi].second;
					if(g[xv]== -1) g[xv]=c;
					ym=max(ym, y[xv]);
					updated=true;
				}
				for(; yp[yi].first<=ym; yi++){
					yv=yp[yi].second;
					if(g[yv]== -1) g[yv]=c;
					xm=max(xm, x[yv]);
					updated=true;
				}
				if(!updated) break;
			}
		}
		c++;
	}

	map<int, int> his;
	rep(i, n) his[g[i]]++;

	rep(i, n) cout<< his[g[i]] <<endl;
	return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int func (int x)
{
    if (x % 100 != 0)
    {
        return 0;
    }

    return func(x * 100) + 1;
}

int main()
{
    int d, n = 0;
    cin >> d >> n;
    if (n == 100)
    {
        n++;
    }
    if (d == 0)
    {
        COUT(n);
        return 0;
    }
    int num = pow(100, d);
    int ans = num * n;
    if (num == 0)
    {
        ans = n;
    }
    COUT(ans);

    return 0;
}

Measured memory_bytes: 512
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 102 B "Maximum Difference"
 */
public class Main {

	public static void main(String[] args) {

		InputScanner in = new InputScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = in.nextInt();
		int[] A = in.nextIntArray(N);

		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			max = Math.max(max, A[i]);
			min = Math.min(min, A[i]);
		}

		int ans = max - min;
		out.println(ans);

		in.close();
		out.close();

	}

	/*
	 * extends java.util.Scanner
	 */
	static class InputScanner{

		Scanner scanner;

		public InputScanner(InputStream inputStream) {
			this.scanner = new Scanner(inputStream);
		}

		public int nextInt() {
			return scanner.nextInt();
		}

		public long nextLong() {
			return scanner.nextLong();
		}

		public double nextDouble() {
			return scanner.nextDouble();
		}
		public String next() {
			return scanner.next();
		}

		public int[] nextIntArray(int n) {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) {
			long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextLong();
			}
			return ret;
		}

		public String[] nextStringArray(int n) {
			String[] ret = new String[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.next();
			}
			return ret;
		}

		public String[] nextStringArray(String splitStr) {
			String[] ret = scanner.next().split(splitStr);
			return ret;
		}

		public void close() {
			scanner.close();
		}
	}

}


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

using namespace std;

const int MAXN = 505;

int n, m;
char a[MAXN][MAXN];

int main () {
    cin >> n >> m;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            cin >> a[i][j];
        }
    }
    for (int i=0; i<n; i++) {
        for (int j=0; j<m-1; j++) {
            if (a[i][j] == '#' || j == 0 || i % 2 == 0) cout << '#'; else cout << '.';
        }
        cout << '.';
        cout << endl;
    }
    cout << endl;
    for (int i=0; i<n; i++) {
        cout << '.';
        for (int j=1; j<m; j++) {
            if (a[i][j] == '#' || j == m-1 || i % 2 == 1) cout << '#'; else cout << '.';
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
//const int INF = INT_MAX  ;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

//< ave , a(time), b(manzoku) >
typedef tuple<double, int, int> A;

int gcd(ll x, ll y) {
    if (x < y) swap(x, y);
    if (y == 0) {
        return x;
    }
    return gcd(y, x % y);
}

int main() {
    int n;
    cin >> n;
    vector<int> mh(n);
    rep (i, n) {
        cin >> mh[i];
    }
    int ans = 0;
    for (int x = 0; x < n; x++) {

        bool b = [&] {
            for (int y = 0; y < x; y++) {
                if (mh[y] > mh[x]) {
                    return false;
                }
            }
            return true;
        }();

        if (b) {
            ans++;
        }

    }
    cout << ans << endl;
}



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

int dx[4] = {0,-1,1,0};
int dy[4] = {-1,0,0,1};
int w,h,c,ans,color_cnt;

void debug(const Panel& a){
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			cout << a[y][x];
		}
		cout << endl;
	}
	cout << endl;
}

int colorConut(const Panel& a){
	int s=0;
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			if( a[y][x] == -1 ) s++;
		}
	}
	return s;
}

void change(Panel& a, int x, int y, int prev_c, int next_c){
	for(int i=0 ; i < 4 ; i++ ){
		int mx = x + dx[i];
		int my = y + dy[i];
		if( mx < 0 || my < 0 || mx >= w || my >= h ) continue;
		if( a[my][mx] == prev_c ){
			a[my][mx] = next_c;
			change( a , mx , my , prev_c , next_c );
		}
	}
}

void solve(const Panel& a, int cnt){
	if( cnt == 6 ){
		Panel b = a;
		b[0][0] = -1;
		change( b , 0 , 0 , c , -1 );
		ans = max( ans , colorConut(b) );
	}else{
		for(int i=1 ; i <= 6 ; i++ ){
			Panel b = a;
			if( a[0][0] == i ) continue;
			b[0][0] = i;
			change( b , 0 , 0 , a[0][0] , i );
			solve( b , cnt+1 );
		}
	}
}

int main(){
	while( cin >> h >> w >> c , h||w||c ){
		Panel a;
		for(int y=0 ; y < h ; y++ ){
			vector<int> v;
			for(int x=0 ; x < w ; x++ ){
				int e;
				cin >> e;
				v.push_back( e );
			}
			a.push_back( v );
		}
		ans = 0;
		solve( a , 1 );
		cout << ans << endl;
	}
}

Measured memory_bytes: 916
import numpy as np
a = []
for _ in range(3):
  a_ = list(map(int, input().split()))
  a=a+a_
c = [0]*9
n = int(input())
for _ in range(n):
  b = int(input())
  if b in a:
    c[a.index(b)]=1
c = np.reshape(c, [3,3])
if 3 in np.sum(c, axis=0):
  print("Yes")
elif 3 in np.sum(c, axis=1):
  print("Yes")
elif c[0][0]+c[1][1]+c[2][2]==3 or c[0][2]+c[1][1]+c[2][0]==3:
  print("Yes")
else:
  print("No")

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

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

  int n;
  cin >> n;

  string s;
  cin >> s;

  if (n & 1) {
  	cout << "No\n";
    return (0);
  }
  if (s.substr(0, n/2) == s.substr(n/2)) cout << "Yes\n";
  else cout << "No\n";

  return (0);
}

Measured memory_bytes: 3612
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := newIo()
	n := io.nextInt()

	seq := []int{}
	for i := 2; i >= 0; i-- {
		for range make([]struct{}, n) {
			k := io.nextInt()
			seq = append(seq, k*10+i)
		}
	}
	sort.Ints(seq)

	var ans, i, j int
	for _, v := range seq {
		switch 'C' - v%10 {
		case 'A':
			i++
		case 'B':
			ans += i * (n - j)
		case 'C':
			j++
		}
	}
	fmt.Println(ans)
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
	}
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextString())
	return i
}


Measured memory_bytes: 20480
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

const INF: usize = 1e18 as usize;

fn main() {
    input!(n: usize, cost: usize, x: [usize; n]);
    let mut sum = vec![0; n + 1];
    for i in 0..n {
        sum[i + 1] = sum[i] + x[i];
    }

    let mut ans = INF;
    for num_robot in 1..(n + 1) {
        let mut sub_sum = cost * num_robot + cost * n;
        for turn in 0..n {
            if n < num_robot * turn {
                break;
            }
            let to = n - num_robot * turn;
            let from = if to >= num_robot { to - num_robot } else { 0 };
            let seg = sum[to] - sum[from];
            let weight = if turn == 0 { 5 } else { 2 * turn + 3 };
            sub_sum += weight * seg;
            if sub_sum > INF {
                break;
            }
        }
        ans = cmp::min(ans, sub_sum);
    }

    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{	
	int n,k,a,sum=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		sum+=min(a,k-a);
	}
	cout<<sum*2<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 444444;
int n,m,a[N],fa[N],tot,idx[N];Vi ch[N];ll sum[N];
struct edge{
	int a,b,c;
}e[N];bool cmp(edge a, edge b){return a.c<b.c;}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
struct qaqq{
	int f[N];ll g[N];
	void init(){
		rep(i,1,n)f[i]=i,g[i]=a[i];
	}
	int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
	void merge(int u, int v){
		u=find(u);v=find(v);
		if(u!=v){f[u]=v;g[v]+=g[u];}
	}
	int query(int u, int v, int c){
		u=find(u);v=find(v);
		if(u==v&&c<=g[u])return 0;return 1;
	}
}qaq;
void dfs1(int u){
	if(u<=n)sum[u]=a[u];rep(i,0,SZ(ch[u])-1)dfs1(ch[u][i]),sum[u]+=sum[ch[u][i]];
}
void dfs(int u, bool flag){
	flag|=u>n&&sum[u]>=e[idx[u]].c;
	if(u>n&&flag)qaq.merge(e[idx[u]].a,e[idx[u]].b);
	rep(i,0,SZ(ch[u])-1)dfs(ch[u][i],flag);
}
int main() {
	read(n);read(m);
	rep(i,1,n)read(a[i]);
	rep(i,1,m)read(e[i].a),read(e[i].b),read(e[i].c);
	sort(e+1,e+m+1,cmp);
	rep(i,1,N-1)fa[i]=i;tot=n;qaq.init();
	rep(i,1,m){
		int u=find(e[i].a),v=find(e[i].b);
		if(u!=v){
			tot++;idx[tot]=i;fa[u]=tot;fa[v]=tot;
			ch[tot].pb(u);ch[tot].pb(v);
		}
	}
	int rt=find(1);dfs1(rt);dfs(rt,0);
	int res=0;
	rep(i,1,m)res+=qaq.query(e[i].a,e[i].b,e[i].c);
	cout<<res;
	return 0;
}


Measured memory_bytes: 41088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 301000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

int main(){
    ll N,W; cin >> N >> W;
    ll w[110],v[110];
    ll dp[101][100100] = {0};
    for(int i = 1; i <= N; i++) cin >> w[i] >> v[i];

    for(int i = 0; i < N; i++){
        for(int j = 1; j <= W; j++){
            dp[i+1][j] = dp[i][j];
            if(j >= w[i+1]){
                dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i+1]] + v[i+1]);
            } else {
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    ll ans = 0;
    for(ll i = W; i >= 0; i--){
        ans = max(ans, dp[N][i]);
    }
    cout << ans << endl;
}


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

namespace TOPSIC2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            int N = int.Parse(NK[0]);
            int K = int.Parse(NK[1]);
            bool[] okashi = new bool[N];

            for (int i = 0; i < K; i++)
            {
                int d = int.Parse(Console.ReadLine());
                string[] A = Console.ReadLine().Split(' ');
                for (int j = 0; j < d; j++)
                {
                    okashi[int.Parse(A[j]) - 1] = true;
                }
            }

            Console.WriteLine(okashi.Count(n => !n));
        }
    }
}


Measured memory_bytes: 19116
n_person = int(input())
infomations_all = [[tuple(map(int, input().split())) for _2 in range(int(input()))] for _1 in range(n_person)]

opinions = [[-1] * n_person for _ in range(n_person)]
for person, infomations_of_each_person in enumerate(infomations_all):
    for infomation in infomations_of_each_person:
        target, isHonest = infomation
        opinions[person][target - 1] = isHonest

BreakOut = type("BreakOut", (Exception, ), {})
ans = 0
for tf_bits in range(2 ** n_person):
    hypothesis = list(map(int, format(tf_bits, "0%db" % n_person)))
    try:
        for person in range(n_person):
            if hypothesis[person]:
                for hyp, opi in zip(hypothesis, opinions[person]):
                    if not (opi == -1 or hyp == opi):
                        raise BreakOut
    except BreakOut:
        pass
    else:
        ans = max(ans, sum(hypothesis))

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    for(int i = 1; i < n; i++)
    {
        ll tmp = ans / (k - 1) + 1;
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	vector<int> ss(N,0);
	int i;
	bool bFlag=false;
	int S=0;
	for (i=0;i<N;i++){
		cin>>ss[i];
		if (ss[i]%10!=0){
			bFlag=true;
		}
		S+=ss[i];
	}
	if (!bFlag){
		cout<<0<<endl;
		return 0;
	}
	if (S%10!=0){
		cout<<S<<endl;
		return 0;
	}
	sort(ss.begin(),ss.end(),std::greater<int>());
	for (i=N-1;i>=0;i--){
		int x=S-ss[i];
		if (x%10!=0){
			cout<<x<<endl;
			return 0;
		}
	}
	cout<<S<<endl;
	return 0;
}

Measured memory_bytes: 256
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

bool isTrue(string in1, string in2)
{
	int a = in2.size();
	int b = in1.size();
	if (a-b != 1)
	{
		return false;
	}

	for (int i = 0; i < in1.length(); i++)
	{
		if (in1[i] != in2[i])
			return false;
	}
	return true;
}

int main()
{
	string input = "";
	string input2 = "";
	cin >> input;
	cin >> input2;

	if (isTrue(input, input2))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,w=0,x=1;
  cin >> n;
  int digit = log10(n)+1;
  for(int i=0;i<digit;i++){
    w+=n/x % 10;
    x*=10;
  }
  if(n%w==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 384
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
A,B,C = [int(x) for x in input().split()]

if A<B:
    if A<C and C<B:
        print("Yes")
    else:
        print("No")
else:
    if B<C and C<A:
        print('Yes')
    else:
        print('No')

        

Measured memory_bytes: 2940
#include <stdio.h>

#define MAX 100
#define INF 100000000


int A[MAX][MAX],n;
int  prim(void);
int main(){

  int i,j,sum=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&A[i][j]);
      if(A[i][j]==-1)A[i][j]=INF;
    }
  }

  sum=prim();

  printf("%d\n",sum);

  return 0;

}

int prim(){

  int i,u,v,min;
  int sum=0;
  int color[MAX],d[MAX],p[MAX];

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

    d[u]=INF;
    p[u]=-1;
    color[u]=1;

  }

  d[0]=0;

  while(1){

    min=INF;

    for(i=0;i<n;i++){
      if(color[i]!=0 && d[i]<min){

	min=d[i];
	u=i;

      }
    }
    if(min==INF) break;
    color[u]=0;

    for(v=0;v<n;v++){
      if(color[v]!=0 && A[u][v]<d[v] && A[u][v]!=-1){

	p[v]=u;
	d[v]=A[u][v];
      }
    }
  }

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

    //printf("keika%d",sum);
    sum+=d[i];
  }

  return sum;
  
}



Measured memory_bytes: 2112