akhauriyash/Code-Regression huggingface dataset:
/*
    Take me to church
    I'll worship like a dog at the shrine of your lies
    I'll tell you my sins and you can sharpen your knife
    Offer me that deathless death
    Good God, let me give you my life
*/
#include<bits/stdc++.h>
using namespace std;
const int LG = 19, N = 1 << LG, Mod = 924844033;
inline int Power(int a, int b)
{
    int ret = 1;
    for (; b; b >>= 1, a = 1LL * a * a % Mod)
        if (b & 1) ret = 1LL * ret * a % Mod;
    return (ret);
}
inline int Rev(int a, int k)
{
    int ra = 0;
    for (; k; k --)
        ra = ra << 1 | (a & 1), a >>= 1;
    return (ra);
}
inline void NTT(int * F, int n, int inv)
{
    int k = __builtin_ctz(n);
    for (int i = 0; i < n; i ++)
        if (i < Rev(i, k))
            swap(F[i], F[Rev(i, k)]);
    for (int len = 1; len < n; len <<= 1)
    {
        int wn = Power(5, (Mod - 1) / (len << 1));
        if (inv) wn = Power(wn, Mod - 2);
        for (int i = 0; i < n; i += (len << 1))
            for (int j = i, w = 1; j < i + len; j ++)
            {
                int a = F[j + len] * 1LL * w % Mod;
                F[j + len] = F[j] - a; F[j] += a;
                if (F[j + len] < 0)
                    F[j + len] += Mod;
                if (F[j] >= Mod)
                    F[j] -= Mod;
                w = 1LL * w * wn % Mod;
            }
    }
    if (inv)
        for (int i = 0, rn = Power(n, Mod - 2); i < n; i ++)
            F[i] = 1LL * F[i] * rn % Mod;
}
int n, A[N], C[N], F[N], I[N];
vector < int > Adj[N];
int DFS(int v, int p)
{
    int sz = 1;
    for (int u : Adj[v])
        if (u != p)
            sz += DFS(u, v);
    if (sz < n)
        C[sz] --, C[n - sz] --;
    return (sz);
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i < n; i ++)
    {
        int v, u;
        scanf("%d%d", &v, &u);
        Adj[v].push_back(u);
        Adj[u].push_back(v);
    }
    DFS(1, 0); C[n] = n;
    for (int i = 1; i < n; i ++)
        if (C[i] < 0)
            C[i] += Mod;
    for (int i = F[0] = 1; i < N; i ++)
        F[i] = 1LL * F[i - 1] * i % Mod;
    I[N - 1] = Power(F[N - 1], Mod - 2);
    for (int i = N - 2; ~ i; i --)
        I[i] = 1LL * I[i + 1] * (i + 1) % Mod;
    int m = 1;
    while (m <= n + n)
        m <<= 1;
    for (int i = 0; i <= n; i ++)
        A[n - i] = I[i], C[i] = 1LL * C[i] * F[i] % Mod;
    NTT(C, m, 0);
    NTT(A, m, 0);
    for (int i = 0; i < m; i ++)
        A[i] = 1LL * A[i] * C[i] % Mod;
    NTT(A, m, 1);
    for (int i = 1; i <= n; i ++)
        printf("%lld\n", A[i + n] * 1LL * I[i] % Mod);
    return 0;
}

Measured memory_bytes: 36864
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define mod 1000000007
int main()
{
	ll n; cin>>n;
	ll v=10LL;
	for(int i=1;i<n;i++)
	{
		v=(v*10LL)%mod;
	}
	ll r=9LL;
	for(int i=1;i<n;i++)
	{
		r=(r*9LL)%mod;
	}
	r=(r*2)%mod;
	ll k=8LL;
	for(int i=1;i<n;i++)
	{
		k=(k*8LL)%mod;
	}
	cout<<((v%mod-r%mod+k%mod)+mod)%mod;
}

Measured memory_bytes: 3600
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        char[] c = sc.next().toCharArray();
        for (int i = 1; i < c.length; i++) {
            if ((c.length - i) % 2 != 0) {
                continue;
            }
            int mid = (c.length - i) / 2;
            String first = Arrays.toString(Arrays.copyOfRange(c, 0, mid));
            String second = Arrays.toString(Arrays.copyOfRange(c, mid, c.length - i));
            if (first.equals(second)) {
                System.out.println(c.length - i);
                return;
            }
        }
    }
}


Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#define MN 40002
#define MM 5000001
#define ll long long
#define ld long double
#define inf 0x7fffffff
#define clz 1000000007
#define ers(arr,val) memset(arr,val,sizeof(arr));
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repd(i,b,a) for(int i=(b);i>=(a);i--)
#define repe(i,u) for(int i=h[u];i;i=e[i].nx)
using namespace std;
int n,m,k,d=0;
int x[200001],y[200001],o[200001],Ans;
bool cmp(int p,int q){return x[p]==x[q]?y[p]<y[q]:x[p]<x[q];}
int main(){
	scanf("%d%d%d",&n,&m,&k);Ans=n+1;
	rep(i,1,k) scanf("%d%d",&x[i],&y[i]);
	rep(i,1,k) o[i]=i;
	sort(o+1,o+k+1,cmp);
	rep(i,1,k){
		if(x[o[i]]>y[o[i]]+d) {Ans=x[o[i]];break;}
		if(x[o[i]]==y[o[i]]+d) d++;
	}
	printf("%d",Ans-1);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 40;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

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


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int X; cin >> X;
	vector<bool> a(1001);
	a[1]=1;
	for(int i=2;i<=X;i++){
		int n=i*i;
		while(n<=X){
			a[n]=1;
			n *= i;
		}
	}
	for(int j=X;j>=1;j--){
		if(a[j]){
			cout << j << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = ll(1e18)+1;

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    ll l = -INF, r = INF;

    while(l+1 < r) {
        ll x = (l+r) / 2;
        bool ok = [&]{
            ll tot = 0;
            for(int i=0; i<n; i++) {
                if (a[i] < 0) {
                    int l = -1, r = n;
                    while(l+1<r) {
                        int c = (l+r) / 2;
                        if (a[c]*a[i] < x) r = c; else l = c;
                    }
                    tot += n-r;
                } else {
                    int l = -1, r = n;
                    while(l+1<r) {
                        int c = (l+r)/2;
                        if (a[c]*a[i] < x) l = c; else r = c;
                    }
                    tot += r;
                }
                if (a[i]*a[i] < x) tot--;
            }
            tot /= 2;
            return tot < k;
        }();
        if (ok) l = x; else r = x;
    }

    cout << l << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    int a, b, c, tmp;
    
    cin >> a >> b >> c;
    
    if(a > b){
        tmp = a;
        a = b;
        b = tmp;
    }
    if(b > c){
        tmp = b;
        b = c;
        c = tmp;
    }
    if(a > b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    cout << a << " " << b << " " << c << endl;
    
    return 0;
}



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

int main(){
  string S,T;
  cin >> S >> T;
  const int LenS= int(S.size());
  const int LenT= int(T.size());

  int ans= LenT;
  for(int offset=0; offset+ LenT <= LenS; offset++){
    int cnt= 0;
    for(int i=0; i<LenT; i++){
      if(S.at(offset+i) != T.at(i)){ cnt++; }
    }
    ans= min(ans, cnt);
  }
  
  cout << ans << endl;
}

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

using Graph=vector<vector<int>>;
Graph g;
vector<int> used;

void First(){
    cout<<"Taro"<<endl;
    exit(0);
}
void Second(){
    cout<<"Hanako"<<endl;
    exit(0);
}
int dfs(int v){
    if(used[v]) return 0;
    used[v]=true;
    int res=1;
    for(auto to:g[v]) res+=dfs(to);
    return res;
}
int main(){
    int n;
    cin>>n;
    g.resize(n);
    int e=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        for(int j=0;j<n;j++){
            if(s[j]=='Y'){
                g[i].push_back(j);
                e++;
            }
        }
    }
    e/=2;
    int ec=0,oc=0;
    used.assign(n,0);
    for(int i=0;i<n;i++){
        if(!used[i]){
            int c=dfs(i);
            if(c%2==0) ec++;
            else oc++;
        }
    }

    int x=n*(n-1)/2-e;
    // cerr<<"#"<<x<<endl;
    if(x%2==0){
        if(ec>=2){
            // cerr<<"EC>=2"<<endl;
            Second();
        }
        else if(oc>=3){
            // cerr<<"OC>=3"<<" "<<oc<<" "<<ec<<endl;
            Second();
        }
        else if(ec==1 && oc==1) Second();
        else First();
    }
    else{
        if(ec>=1) First();
        else if(oc==2) Second();
        else if(oc!=4) First();
        else if(e%2==1) First();
        else Second();
    }
    

    return 0;
}


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

int main(){
  int K,A,B,c=0;
  cin >> K >> A >> B;
  for(int i=A;i<=B;i++){
    if(i%K==0){
      c=1;
      break;
    }
  }
  if(c==0)
    cout << "NG" <<endl;
  else
    cout << "OK" <<endl;

}


Measured memory_bytes: 3644
# -*- coding: utf-8 -*-
# 標準入力を取得
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

# メイン処理
ans_list = ["no" for i in range(q)]
for bit in range(1 << n):
    s = 0
    for i in range(n):
        if bit & (1 << i):
            s += A[i]
    L = [i for i, x in enumerate(m) if x == s]
    for l in L:
        ans_list[l] = "yes"

# 結果出力
for ans in ans_list:
    print(ans)


Measured memory_bytes: 5628
N = int(input())
ans = 0
renzoku = 0
for _ in range(N):
    D1,D2 = map(int,input().split( ))
    if D1 == D2:
        renzoku += 1
    else:
        renzoku = 0
    if renzoku == 3:
        ans += 1
if ans > 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9176
#include <cstdio>
int n, l, r, p[222];
int main() {
	while (scanf("%d%d%d", &n, &l, &r), n | l | r) {
		for (int i = 0; i < n; i++) scanf("%d", &p[i]);
		int ret = 0, gap = -1;
		for (int i = l; i <= r; i++) {
			if (p[i - 1] - p[i] >= gap) ret = i, gap = p[i - 1] - p[i];
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 2660
#include <bits/stdc++.h>
#define mp make_pair 
#define pb push_back 
#define fi first
#define se second
#define MOD 1000007
#define DOMOD(d) if ((d) >= MOD) d %= MOD;
#define DONEGMOD(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
 
#define inp(a) scanf("%d", &a)
#define inp2(a,b) scanf("%d %d", &a, &b)
#define inp3(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define inp4(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
 
#define inpl(a) scanf("%lld", &a)
#define inpl2(a,b) scanf("%lld %lld", &a, &b)
#define inpl3(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define inpl4(a,b,c,d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i=a;i<b;i++)
#define mset(a,val) memset(a,val,sizeof(a))
#define printv(v) for (int i=0;i<(int) v.size(); i++) cout<<v[i]<<" " 
#define MAX 1000005
using namespace std ;
typedef long long int ll ;
typedef pair<int,int> pii ;
typedef pair<long long , long long > pll ;
typedef pair<int,pii> pipi ;
typedef pair<ll,pll> plpl ;
typedef pair<long long, int> pli ;
typedef pair<int,pair<int,string>> piis ;
typedef pair<ll,string> pls ;

int count(ll x)
{
	int c = 0 ;
	while (x > 0)
	{
		c++ ; x /= 10 ;
	}
	return c ;	
} 
 
int main()
{
   ll n ; inpl(n) ;
   int ans = 100 ;
   for (ll i=1;i<=100000;i++)
   {
	   if (i > n) break ;
	   if (n % i == 0)
	   {
		   ans = min(ans,max(count(i),count(n/i))) ;
	   }
   }
   cout<<ans<<endl ;
   return 0 ;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d) {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")

	}
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}


Measured memory_bytes: 512
import re

S=input().replace('?','.')
T=input()

if len(S)<len(T):
  print('UNRESTORABLE')
  exit()

for i in range(len(S)-len(T)+1): #8-5: 0,1,2,3
  l = len(S)-len(T)-i
  r = len(S)-i
  if re.match(S[l:r], T):
    s = S[:l] + T + S[r:]
    print(s.replace('.','a'))
    exit()

print('UNRESTORABLE')
  

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  ll x;
  cin >> x;
  int ans_a,ans_b;
  for(ll a=-200;a<200;a++){
    for(ll b = -200;b<200;b++){
      ll m = pow(a,5);
      ll n = pow(b,5);
      if((m-n)==x) {
	cout << a << " " << b << endl;
	return 0;
      }
    }
  }
}


Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int N,M;
  cin >> N >> M ;
  int a[N][M];
  int b[M];
  int tmp = 0;
  for(int i = 0; i < N; i++ ){
    for(int j = 0; j < M; j++){
          cin >> a[i][j]; 
    }
  }
  for(int i = 0; i < M; i++){
    cin >> b[i] ;
  }
  for(int i  = 0 ; i < N; i++){
      for(int j = 0; j < M; j++){
        tmp += a[i][j] * b[j];
      } 
      cout << tmp << "\n";
      tmp = 0;
  }
  
  return 0;
}


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

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

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

	int n;
	cin>>n;
	if(n%10==9 || n/10==9){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,i,j,num,c,in,k=0;
  int a[101][101]={};

  
  scanf("%d",&n);
  //入力
  for(i=0;i<n;i++){
      scanf("%d%d",&num,&c);
    for(j=0;j<c;j++){
      scanf("%d",&in);
      a[num-1][in-1]++;
      
    }
  }
  //出力
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",a[i][j]);
      if(j!=n-1)printf(" ");
    }
    puts("");
  }

  return 0;
}



Measured memory_bytes: 2048
#include<stdio.h>

int la[100][7], lt[7], s=1, c;

void dice(int num){
    lt[0] = lt[1];
    lt[1] = lt[num];
    lt[num] = lt[6];
    lt[6] = lt[7-num];
    lt[7-num] = lt[0];
}

int same(int a){
    s = (la[a][1]==lt[1]&&la[a][3]==lt[3]&&la[a][4]==lt[4]&&la[a][5]==lt[5]&&la[a][6]==lt[6])?0:1;
    return s;
}

void reset(int a){
    for(int i=0; i<6; i++) lt[i+1] = la[a][i+1];
    c = 0;
}

int main(void){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++) for(int j=0; j<6; j++) scanf("%d", &la[i][j+1]);
    for(int i=0; i<n&&s; i++){
        for(int j=i+1; j<n&&s; j++){
            if(s){
                reset(j);
                dice(5);
                if(la[i][2]==lt[2]) while(same(i) && c++<4) dice(4);
            } // 1
            if(s){
                reset(j);
                if(la[i][2]==lt[2]) while(same(i) && c++<4) dice(4);
            } // 2
            if(s){
                reset(j);
                dice(3);
                dice(5);
                if(la[i][2]==lt[2]) while(same(i) && c++<4) dice(4);
            } // 3
            if(s){
                reset(j);
                dice(4);
                dice(5);
                if(la[i][2]==lt[2]) while(same(i) && c++<4) dice(4);
            } // 4
            if(s){
                reset(j);
                dice(5);
                dice(5);
                if(la[i][2]==lt[2]) while(same(i) && c++<4) dice(4);
            } // 5
            if(s){
                reset(j);
                dice(2);
                if(la[i][2]==lt[2]) while(same(i) && c++<4) dice(4);
            } // 6
        }
    }
    if(s) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

typedef long long ll;
typedef long double ld;

using namespace std;

void INeedIt() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int a[1001];
int main() {
	INeedIt();
	ll n, sum=0;
	cin>>n;
	for (int i=0;i<n-1;i++) cin>>a[i];
	sum+=(a[0]+a[n-2]);
	for (int i=0;i<n-2;i++) sum+=min(a[i], a[i+1]);
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  ll x;
  cin>>x;
  ll n = x/500;
  ll r  = x%500;
  ll k = r/5;
  ll ans = n*1000 + k*5;
  cout<<ans;
  
    return  0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;

char str[100005];

int main(int argc, char* argv[])
{
    scanf("%s", str);
    int n=strlen(str);

    vector<int> save;
    vector<char> z;
    int i;
    int cnt=0;
    for(i=0; i<n; i++) {
        if(str[i]=='x') {
            cnt++;
        }
        else {
            save.push_back(cnt);
            cnt=0;
            z.push_back(str[i]);
        }
    }
    save.push_back(cnt);

    for(i=0; i<(int)z.size()/2; i++) {
        if(z[i]!=z[(int)z.size()-1-i]) {
            printf("-1\n"); return 0;
        }
    }
    ll ans=0;
    for(i=0; i<(int)(z.size()+1)/2; i++) {
        ans+=abs(save[i]-save[(int)z.size()-i]);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

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

   int n;
   cin >> n;
   vector<int> a(n), b(n);
   rep(i, 0, n) cin >> a[i] >> b[i];
   sort(all(a));
   sort(all(b));
   int mida, midb;
   if (n % 2) {
      mida = a[n / 2];
      midb = b[n / 2];
   } else {
      mida = (a[n / 2] + a[n / 2 - 1]);
      midb = (b[n / 2] + b[n / 2 - 1]);
   }
   int ans = midb - mida + 1;
   cout << ans << endl;
   return 0;
}

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

int main()
{
    int X;
    cin >> X;
    int ans = 0;
    ans += (X / 500) * 1000;
    X = X % 500;
    ans += (X / 5) * 5;
    cout << ans << endl;
}


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

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

    vector<int> r, g, b;
    vector<int> cntr(N), cntg(N), cntb(N);
    REP(i, 0, N) {
        if (S[i] == 'R') r.push_back(i);
        if (S[i] == 'G') g.push_back(i);
        if (S[i] == 'B') b.push_back(i);
        cntr[i] = r.size();
        cntg[i] = g.size();
        cntb[i] = b.size();
    }

    ll ans = 0;
    REP(i, 0, N) {
        if (S[i] == 'R') {
            auto itrg = upper_bound(ALL(g), i);
            if (itrg != g.end()) {
                for (auto itr = itrg; itr != g.end(); itr++) {
                    ans += b.size() - cntb[*itr] - binary_search(ALL(b), *itr + (*itr - i));
                }
            }
            auto itrb = upper_bound(ALL(b), i);
            if (itrb != b.end()) {
                for (auto itr = itrb; itr != b.end(); itr++) {
                    ans += g.size() - cntg[*itr] - binary_search(ALL(g), *itr + (*itr - i));
                }
            }
        }
        if (S[i] == 'G') {
            auto itrr = upper_bound(ALL(r), i);
            if (itrr != r.end()) {
                for (auto itr = itrr; itr != r.end(); itr++) {
                    ans += b.size() - cntb[*itr] - binary_search(ALL(b), *itr + (*itr - i));
                }
            }
            auto itrb = upper_bound(ALL(b), i);
            if (itrb != b.end()) {
                for (auto itr = itrb; itr != b.end(); itr++) {
                    ans += r.size() - cntr[*itr] - binary_search(ALL(r), *itr + (*itr - i));
                }
            }
        }
        if (S[i] == 'B') {
            auto itrr = upper_bound(ALL(r), i);
            if (itrr != r.end()) {
                for (auto itr = itrr; itr != r.end(); itr++) {
                    ans += g.size() - cntg[*itr] - binary_search(ALL(g), *itr + (*itr - i));
                }
            }
            auto itrg = upper_bound(ALL(g), i);
            if (itrg != g.end()) {
                for (auto itr = itrg; itr != g.end(); itr++) {
                    ans += r.size() - cntr[*itr] - binary_search(ALL(r), *itr + (*itr - i));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2010;
int n,m,ans,map1[N][N],map2[N][N],map3[N][N],top,sta[N],pos[N],h[N];
char str1[N];
int main(){
	scanf("%d%d",&n,&m);
	ans=max(n,m);
	for(int i=1;i<=n;i++){
		scanf("%s",str1+1);
		for(int j=1;j<=m;j++){
			if(str1[j]=='.')map1[i][j]=0;
			else map1[i][j]=1;
			//printf("%d %d %d\n",i,j,map1[i][j]);
		}
	}
	for(int i=2;i<=n;i++)
	for(int j=2;j<=m;j++){
		map2[i][j]=map1[i-1][j-1]^map1[i-1][j]^map1[i][j-1]^map1[i][j];
	//	printf("%d %d %d %d %d %d\n",i,j,map1[i-1][j-1],map1[i-1][j],map1[i][j-1],map1[i][j]);
	}
	for(int i=2;i<=n;i++)
	for(int j=m;j>1;j--)
	if(map2[i][j]==0)map3[i][j]=map3[i][j+1]+1;
	else map3[i][j]=0;
//	for(int i=2;i<=n;i++){
//		for(int j=2;j<=m;j++)printf("%d ",map3[i][j]);
//		printf("\n");
//	}
	for(int i=2;i<=m;i++){
		top=0;
		for(int j=2;j<=n;j++){
			h[j]=j;
			while(top>0&&map3[j][i]<=sta[top]){
				ans=max(ans,(sta[top]+1)*(j-h[pos[top]]+1));
				h[j]=h[pos[top]];
				top--;
			}
			if(map3[j][i]){sta[++top]=map3[j][i];pos[top]=j;}
		}
		while(top>0){
			ans=max(ans,(sta[top]+1)*(n+2-h[pos[top]]));
			top--;
		//printf("%d %d\n",i,ans);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 47488
def main():
    A, B, C, K = list(map(int, input().split()))

    rest = K
    total = 0

    if(rest - A >= 0):
        rest = max(0, rest - A) 
        total += 1 * A
    else:
        total += 1 * rest

    rest = max(0, rest - B) 

    
    total += -1 * rest

    print(total)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9068
#include<iostream>
using namespace std;
int main(){
    int n;
    long  a;
    long  s=0;
    long  m=-1000000;
    long  l=1000000;
    cin >> n;
    for(int b=0; b<n; b++){
        cin >> a;
        s+=a;
        if(m<a){
            m=a;
        }if(l>a){
            l=a;
        }
    }
    cout << l << " " << m << " " << s <<endl;
    return 0;
    
    
}


Measured memory_bytes: 3088
import java.util.Scanner;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int cnt[] = new int[n+1];
		ModInt ans = new ModInt(1);
		for(int i=2; i<=n; i++) {
			int k=i;
			for(int j=2; j<=i; j++) {
				while(k%j==0) {
					cnt[j]++;
					k /= j;
				}
			}
		}
		for(int i=2; i<=n; i++) {
				ans = ans.mul(new ModInt(cnt[i]+1));
		}
		System.out.println(ans.x);
		sc.close();
	}

}
class ModInt {

	 final static int MOD = 1000000007;
	 public long x;
	 ModInt(long x){
		 this.x = (x % MOD + MOD) % MOD;
	 }
	 public ModInt plus(final ModInt a) {
		 ModInt res = new ModInt(this.x);
		 if((res.x += a.x) >= MOD) {
			 res.x -= MOD;
		 }
		 return res;
	 }
	 public ModInt minus(final ModInt a) {
		 ModInt res = new ModInt(this.x);
		 if((res.x += MOD-a.x) >= MOD) {
			 res.x -= MOD;
		 }
		 return res;
	 }
	 public ModInt mul(final ModInt a) {
		 ModInt res = new ModInt(this.x);
		 res.x *= a.x;
		 res.x %= MOD;
		 return res;
	 }
	 public ModInt pow(long t) {
		 if(t == 0) {
			 return new ModInt(1);
		 }
		 ModInt a = pow(t>>1);
		 a = a.mul(a);
		 if((t&1)==1) {
			 a = a.mul(this);
		 }
		 return a;
	 }
	 public ModInt inv() {
		 ModInt res = pow(MOD-2);
		 return res;
	 }
	 public ModInt div(ModInt a) {
		 ModInt inv = a.inv();
		 return mul(inv);
	 }

}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main(){
	vector<int> h(5);
	rep(i,5) cin >> h[i];
	
	int res = INF;
	
	do{
		int tmp = 0;
		rep(i,4){
			tmp += ceil((double)h[i]/10) * 10;
		}
		tmp += h[4];
		res = min(res,tmp);
	}while(next_permutation(h.begin(), h.end()));
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
from math import *
N=int(input())
K=sqrt(N)
F=11
for a in range(1,int(K)+1):
  if N%a==0:
    b=N//a
    al=len(str(a))
    bl=len(str(b))
    G=max(al,bl)
    F=min(F,G)
print(F)

Measured memory_bytes: 80264
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

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

  vector<int> s(N);

  int sum = 0;
  REP(i, N){
    cin >> s[i];
    sum += s[i];
  }

  if(sum%10 != 0){
    cout << sum << endl;
    return 0;
  }

  sort(ALL(s));

  REP(i, N){
    if(s[i]%10 != 0){
      cout << sum - s[i] << endl;
      return 0;
    }
  }

  cout << 0 << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int gcd(int a,int b){
  int m= min(a,b);
  int n= max(a,b);
  
  if(n%m==0) 
    return m;
  else 
    return gcd(m,n%m);}
  

int main(){
  
  int N;
  cin >> N;
  
  int a[N];
  
  for(int i=0;i<N;i++){
    cin >> a[i];}
  
  int now = gcd(a[0],a[1]);
  
  for(int i=1;i<N-1;i++){
    now = gcd(now,a[i+1]);}
  
  cout <<   now;
  
}

Measured memory_bytes: 640
/*
Created on Thu Aug 27 21:32:39 2020

@author: roastedcoder

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
const int mod = 1e9+7;
#define endl "\n"
#define append push_back
#define roastedcoder ios_base::sync_with_stdio(false); cin.tie(NULL);
//__________________________________________________________________

int a[100001];

int weird(int n, int k) {
	vector <int> dp(n, INT_MAX);
	dp[0] = 0;
	for(int i = 0; i<n; i++) {
		for(int j = i+1; j<=i+k; j++) {
			if(j<n) {
				dp[j] = min(dp[j], dp[i] + abs(a[i]-a[j]));
			}
		}
	}
	return dp[n-1];
}

int main() {
	roastedcoder
	int n, k; cin>>n>>k;
	for(int i = 0; i<n; i++) cin>>a[i];
	cout<<weird(n, k);
}

//__________________________________________________________________
/*
Sample Input:
3 1
10 20 10

Sample Output:
20

*/

Measured memory_bytes: 4012
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) System.out.println("Hello World");
        if (n == 2) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a + b);
        }
    }
}

Measured memory_bytes: 35664
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<vector>
using namespace std;

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

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

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

int main(){
	int n; cin >> n;
	int N = n + 2;
	long long c; cin >> c;
	long long x[N], v[N];
	long long lx[N], lc[N], rx[N], rc[N];
	long long ml[N], mr[N];
	FOR(i, 1, N - 1) cin >> x[i] >> v[i];
	x[0] = v[0] = lx[0] = lc[0] = rx[0] = rc[0] = ml[0] = mr[0] = 0;
	x[N-1] = v[N-1] = lx[N-1] = lc[N-1] = rx[N-1] = rc[N-1] = ml[N-1] = mr[N-1] = 0;
 
	long long ans = 0;
	FOR(i, 1, N - 1){
		lx[i] = x[i]; lc[i] = lc[i-1] + v[i];
		long long t = lc[i] - lx[i];
		ans = max(ans, t);
		ml[i] = max(ml[i-1], t);
	}
 
	for(int i = N-2; i > 0; i--){
		rx[i] = c - x[i]; rc[i] = rc[i+1] + v[i];
		long long t = rc[i] - rx[i];
		ans = max(ans, t);
		mr[i] = max(mr[i+1], t);
	}
 
	FOR(i, 1, N - 1){
		long long l = lc[i] - 2 * lx[i];
		long long r = mr[i+1];
		ans = max(ans, l + r);
	}

	for(int i = N-2; i > 0; i--){
		long long l = ml[i-1];
		long long r = rc[i] - 2 * rx[i];
		ans = max(ans, l + r);
	}

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



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

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

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

  cout << (a * b % 2 == 1 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
/*input
8 6
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
string s[]={"Even","Odd"};
int main()
{
	IOS;
	int x,y;
	cin>>x>>y;
	if(x%y==0) cout<<"-1";
	else cout<<x;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#include <bitset>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    int N;
    cin >> N;
    int A[N],count=0;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        if(A[i]==i+1){
            swap(A[i],A[i+1]);
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long  n,ans=0;
    cin >>n;
    vector<long long>dp(n+1,1);
    
    
    for(int i=2;i<=n+1;i++){
        for(int j=1;i*j<=n;j++){
            dp[i*j]++;
        }
    }
    
    
    
    for(int i=1;i<=n;i++){
        ans+=i*dp.at(i);
    }
    
    cout<<ans;
}

Measured memory_bytes: 81404
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long N,T,A,t,a;
	cin>>N;
	t=a=1;
	for(long long n=0;n<N;n++)
	{
		cin>>T>>A;
		long long k=max((t+T-1)/T, (a+A-1)/A);
		t=k*T;
		a=k*A;
	}
	cout<<t+a<<endl;
	return 0;
}



Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
A = LIST()
print(len(set(A)))

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

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int n = sc.nextInt();
			if(n == 0 )break;
			else calc(n);
			
		}
	}
	public void calc(int n){
		int[] noT = new int[n];
		int[][] t = new int[n][n];
		for(int i = 0; i < n; i ++){
			for(int j = 0; j < n+1; j++){
				if(j == 0) noT[i] = sc.nextInt();
				else t[i][j-1] = sc.nextInt();
			}
		}
		int[] ans = new int[1 << n];
		Arrays.fill(ans, Integer.MAX_VALUE);
		ans[0] = 0;
		for(int bit = 0; bit < (1 << n); bit++){
			for(int i = 0; i < n; i++){
				if(((bit >> i) & 1) == 0){
					int min = noT[i];
					for(int j = 0; j < n; j++){
						if(((bit >> j) & 1) > 0){
							min = Math.min(min, t[i][j]);
						}
					}
					ans[bit|(1 << i)] = Math.min(ans[bit|(1<< i)], min + ans[bit]);
				}
			}
		}
		System.out.println(ans[(1<<n) - 1]);
	}


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

Measured memory_bytes: 35552
#include <stdio.h>
int main(void){
	int i,detaset,sankaku[3000];
	scanf("%d",&detaset);//????????????????????°?????\???
	for(i=1;i<=detaset*3;i++){//????§???¢?????????????????\???
		scanf("%d",&sankaku[i-1]);
	}
	for(i=1;i<=detaset*3-1;i=i+3){
		if(sankaku[i-1]<=sankaku[i]&&sankaku[i+1]<=sankaku[i]){//i??????????????§
			if(sankaku[i]*sankaku[i]==sankaku[i-1]*sankaku[i-1]+sankaku[i+1]*sankaku[i+1]){
				printf("YES\n");
			}else{
				printf("NO\n");
			}
		}else if(sankaku[i]<=sankaku[i-1]&&sankaku[i+1]<=sankaku[i-1]){//i-1??????????????§
			if(sankaku[i-1]*sankaku[i-1]==sankaku[i]*sankaku[i]+sankaku[i+1]*sankaku[i+1]){
				printf("YES\n");
			}else{
				printf("NO\n");
			}
		}else if(sankaku[i]<=sankaku[i+1]&&sankaku[i-1]<=sankaku[i+1]){//i+1??????????????§
			if(sankaku[i+1]*sankaku[i+1]==sankaku[i-1]*sankaku[i-1]+sankaku[i]*sankaku[i]){
				printf("YES\n");
			}else{
				printf("NO\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int howmanytimes=0;
vector<int> selectionSort(vector<int> A,int N) {
	
	rep(i, N) {
		int minj = i;
		for (int j = i; j < N; j++) {
			if (A[j] < A[minj])
			{
				minj = j;
			}
		}
		if (A[i] != A[minj]) { howmanytimes++; }
		int swap = A[minj];
		A[minj] = A[i];
		A[i] = swap;

	}
	return A;
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int>a;
	for (int i = 0; i < n; i++) {
		int u;
		cin >> u;
		a.pb(u);
	}
	a = selectionSort(a,n);
	for (int i = 0; i < a.size();i++)
	{
		if (i != 0) { cout << " "; }
		cout << a[i];
	}
	
	cout << endl<<howmanytimes << endl;
	return 0;
}


Measured memory_bytes: 3156
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/03/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,c; cin>>n>>c;
  int D[c][c];
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      cin>>D[i][j];
    }
  }

  array<map<int, int>, 3> table;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int v; cin>>v; v--;
      table[(i+j)%3][v]++;
    }
  }

  ll ans = numeric_limits<ll>::max();
  for (int s = 0; s < c; s++) {
    for (int t = 0; t < c; t++) {
      if (s == t) continue;
      for (int u = 0; u < c; u++) {
        if (u == s or u == t) continue;
        ll sum = 0;
        for (auto p : table[0]) {
          sum += D[p.first][s]*p.second;
        }
        for (auto p : table[1]) {
          sum += D[p.first][t]*p.second;
        }
        for (auto p : table[2]) {
          sum += D[p.first][u]*p.second;
        }
        ans = min(ans, sum);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n;
string s;

void input(){
    cin >> n >> s;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int cntr = 0;
    int cntb = 0;
    for(int i=0;i<n;i++){
        if(s[i] == 'R') cntr++;
        else cntb++;
    }
    if(cntr > cntb) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    L=-INF; R=INF
    for _ in range(m):
        l,r=map(int,input().split())
        L=max(L,l)
        R=min(R,r)
    print(max(R-L+1,0))
resolve()

Measured memory_bytes: 40684
def func(N):
    loop = int(N ** 0.5)

    ans = float("inf")
    for i in range(1, loop + 1):
        if N % i:
            continue
        j = N // i
        tmp = i + j - 2
        ans = min(ans, tmp)
    
    return ans


if __name__ == "__main__":
    N = int(input())
    
    print(func(N))

Measured memory_bytes: 3064
import bisect
n,c,k = map(int,input().split())

t = [0 for _ in range(n)]

for i in range(n):
    t[i] = int(input())

t.sort()
cnt = 0
st = 0
while st < n:
    fire_time = t[st] + k
    wait_num = bisect.bisect_right(t,fire_time) - st

    if(wait_num <= c):
        st = wait_num + st
    else:
        st = st + c
    cnt += 1

print(cnt)


Measured memory_bytes: 13256
#include <stdio.h>
int main(){
  int a,b,c,k;
  scanf("%d %d %d",&a,&b,&c);
  scanf("%d",&k);
  for(int i=0;i<k;i++){
	if (c <= a) c *= 2;
	else if(b <= a) b *= 2;
	else if(c <= b) c *= 2;
	else continue;
  }
  if(a<b && b<c) printf("Yes");
  else printf("No");
  return 0;
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;

int main(){
    ll n,ans1=0,ans2=0,sum1=0,sum2=0;
    cin >> n;
    vl a(n),s(n);
    lrp(i,n){
        cin >> a.at(i);
    }
    s.at(0)=a.at(0);
    lrep(i,1,n-1){
        s.at(i)=a.at(i)+s.at(i-1);
    }
    lrp(i,n){
        if(i%2==0&&s.at(i)+sum1<=0){
            sum2 += 1-s.at(i)-sum1;
            ans1 += abs(1-s.at(i)-sum1);
        }elif(i%2==1&&s.at(i)+sum1>=0){
            sum2 -= s.at(i)+sum1+1;
            ans1 += abs(s.at(i)+sum1+1);
        }
        sum1=sum2;
    }
    sum1=0;
    sum2=0;
    lrp(i,n){
        if(i%2==1&&s.at(i)+sum1<=0){
            sum2 += 1-s.at(i)-sum1;
            ans2 += abs(1-s.at(i)-sum1);
        }elif(i%2==0&&s.at(i)+sum1>=0){
            sum2 -= s.at(i)+sum1+1;
            ans2 += abs(s.at(i)+sum1+1);
        }
        sum1=sum2;
    }
    cout << min(ans1,ans2) << endl;
    return 0;
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ll flag[310][310][310];
double dp[310][310][310];
ll n;
double f(ll c1,ll c2,ll c3){
  if(flag[c1][c2][c3])return dp[c1][c2][c3];
  flag[c1][c2][c3]=1;
  if(c1==0&&c2==0&&c3==0){
    dp[0][0][0]=0.0;
    return 0;
  }
  double d=c1+c2+c3;
  double fans=n/d;
  if(c1>0)fans+=f(c1-1,c2,c3)*c1/d;
  if(c2>0)fans+=f(c1+1,c2-1,c3)*c2/d;
  if(c3>0)fans+=f(c1,c2+1,c3-1)*c3/d;
  dp[c1][c2][c3]=fans;
  return fans;
}
int main(){
  cin>>n;
  rep(i,n+1){
    rep(j,n+1){
      rep(k,n+1){
        dp[i][j][k]=0;
        flag[i][j][k]=0;
      }
    }
  }
  map<ll,ll>M;
  rep(i,n){
    ll k;cin>>k;
    M[k]++;
  }
  double ans=f(M[1],M[2],M[3]);
  cout<<fixed<<setprecision(15)<<ans<<endl;
}

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

using namespace std;

using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<array<ll, 3>> vp;
  int idx;
  for (int i = 0; i < n; ++i) {
    int x, y, h;
    cin >> x >> y >> h;
    vp.push_back({x, y, h});
    if (h > 0) {
      idx = i;
    }
  }

  for (int i = 0; i <= 100; ++i) {
    for (int j = 0; j <= 100; ++j) {
      bool ok = true;
      ll ch = abs(i - vp[idx][0]) + abs(j - vp[idx][1]) + vp[idx][2];
      for (int k = 0; k < vp.size(); ++k) {
        auto &p = vp[k];
        ll h = max(0ll, ch - abs(p[0] - i) - abs(p[1] - j));
        if (h != p[2]) {
          ok = false;
          break;
        }
      }

      if (ok) {
        cout << i << ' ' << j << ' ' << ch << '\n';
        return 0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

	int main(){
		int n;
		char c[10002];
		scanf("%d %s",&n, c);
		
		for(int i=0; c[i] != '\0'; i++){
			c[i] = 'A' + (c[i]-'A'+n) % 26;
		}
		printf("%s\n",c);
		return 0;
	}

Measured memory_bytes: 1632
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
int main(){
	char c;
	int b[26]={};
	while(cin >> c){
		int a = c-'A';
		if(a>26) a = c-'a';
		b[a]++;
	}
	char d[26];
	for(int i=0;i<26;i++){
		int e = 'a' + i;
		d[i] = e;
	}
	for(int i=0;i<26;i++) cout << d[i] << " : " << b[i] << endl;
}

Measured memory_bytes: 1140
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline ll ri()
{
	register ll x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(ll x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=1e5+7;
ll a[N],ps[N],ss[N];
int main()
{
	ll n=ri(),i;
	for(i=1;i<=n;i++)	a[i]=ri();
	for(i=2;i<=n;i++)	ps[i]=ps[i-1]+abs(a[i]-a[i-1]);
	for(i=n-1;i>=1;i--)	ss[i]=ss[i+1]+abs(a[i]-a[i+1]);
	wi(ss[2]+abs(a[n])+abs(a[2]));putchar('\n');
	for(i=2;i<n;i++)
	{
		wi(ps[i-1]+ss[i+1]+abs(a[1])+abs(a[n])+abs(a[i-1]-a[i+1]));
		putchar('\n');
	}
	wi(ps[n-1]+abs(a[1])+abs(a[n-1]));putchar('\n');
	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
	#include <string>
	#include <stdio.h>
	#include <queue>
	#include <stack>
	#include <string.h>
	#include <algorithm>
	#include <math.h>
	//#include <bits/stdc++.h>
	#define ll long long
	#define wtcl return
	using namespace std;
	
	inline int read()
	{
	    ll s = 0, f = 1;
	    char ch = getchar();
	    for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = - 1;
	    for(; ch >= '0' && ch <= '9'; ch = getchar()) s = ((s << 3ll) + (s << 1ll) + (ch ^ 48ll));
	    return s * f ;
	}
	
	int main()
	{
	    int n;
	    while(cin>>n)
	    {
	    	int num[200005];
	    	int a[200005];
	    	for(int i=0;i<n;i++)
	    	{
	    		num[i] = read();
	    		a[i] = num[i];
			}
			sort(a,a+n);
			for(int i=0;i<n;i++)
			{
				int pos = upper_bound(a,a+n,num[i])-a;
				//cout<<pos<<" ";
				if(pos<=(n/2))
					cout<<a[n/2]<<endl;
				else cout<<a[n/2-1]<<endl;
			}
	    		
		}
	    wtcl 0;
	}

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

int main(){
	std::vector<int> line;
	std::vector<int> out;
	int a;

	while(std::cin >> a){
		if(a != 0){
			line.push_back(a);
		}else if(a == 0){
			out.push_back(line.back());
			line.pop_back();
		}
	}

	for(int i=0; i<(int)out.size(); ++i){
		std::cout << out.at(i) << std::endl;
	}
}

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

int main(){
    string o,e;
    cin >> o;
    cin >> e;
    string ans = "";
    for(int i = 0; i < o.length()+e.length(); i++){
        if(i % 2 == 0 && i/2 < o.length()) ans += o[i/2];
        else if((i-1)/2 < e.length()) ans += e[(i-1)/2];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604