akhauriyash/Code-Regression huggingface dataset:
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

ll N;
vector<ll> num;

int main() {
    cin >> N;

    ll ans = 0;
    REP(i, (N-1)){
        ans += (i+1);
    }    

    print(ans);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const ll LINF = 1000000000000000000;

int main(){
    int A, B, C;
    ll K;
    cin >> A >> B >> C >> K;
    
    if(K % 2 == 0){
        cout << A - B << endl;
    }
    else{
        cout << B - A << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int n, i, b;
    long max,min,sum=0;
    scanf("%d", &n);
    for(i=0;i<n;i++) {
        scanf("%d", &b);
        if(i==0){
            max = min = b;
        }
        if(b>max) max = b;
        if(b<min) min = b;
        sum+=b;
    }
    cout <<min<<" "<<max<<" "<<sum<<endl;
    return 0;
}


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

int main()
{
    int a[3] = {};
    for (int i = 0; i<2; i++)
    {
        int x; cin>>x;
        a[x-1]++;
    }
    for (int i = 0; i<3; i++)
    {
        if (!a[i])
        {
            cout<<i+1;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main()
{
  int n,w;
  cin >> n >> w;
  vector<pair<int,int> >l;
  vector<vector<long> >dp(n+1,vector<long>(w+1));
  for(int i=0;i<n;i++){
    int w,v;
    cin >> w >> v;
    l.push_back(make_pair(w,v));
  }

  for(int i=0;i<=n;i++){
    for(int j=0;j<=w;j++){
      if(i==0){
        dp[i][j]=0;
      }
      else{
        if(j-l[i-1].first<0)
          dp[i][j]=dp[i-1][j];
        else
          dp[i][j]=max(dp[i-1][j],dp[i-1][j-l[i-1].first]+l[i-1].second);
      }
    }
  }

  cout << *max_element(dp[n].cbegin(),dp[n].cend()) << endl;


  return 0;
}

Measured memory_bytes: 80256
lis = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input())

print (lis[K-1])


Measured memory_bytes: 38384
N = int(input())
a = [0]*10050
for i in range(1,105):
    for j in range(1,105):
        for k in range(1,105):
            v = i*i+j*j+k*k+i*j+i*k+j*k
            if v < 10050:
                a[v-1] += 1
 
for i in range(N):
    print(a[i])

Measured memory_bytes: 92080
import scala.collection.mutable
import scala.io.StdIn._
object Main extends App {
  val Array(n, r) = readLine.trim.split(' ').map(_.toInt)
  val towns = Array.fill(n){Nil: List[(Int, Int)]}
  for (_ ← 0 until r){
    val Array(s, t, d) = readLine.trim.split(' ').map(_.toInt)
    towns(s - 1) ::= (t - 1, d)
    towns(t - 1) ::= (s - 1, d)
  }
  val heap = mutable.PriorityQueue()(Ordering.by[(Int, Int), Int](_._2).reverse)
  val maxDistanceFrom = Array.fill(n){0}
  val useWhenStartFrom = Array.fill(n){Array.fill(n){false}}
  var maxDistance = 0
  for (start ← 0 until n){
    val minDistance = Array.fill(n){Int.MaxValue}
    minDistance(start) = 0
    heap.enqueue((start, 0))
    var far = start
    while (heap.nonEmpty) {
      val (current, cost) = heap.dequeue()
      if (minDistance(current) == cost) {
        far = current
        for ((next, length) ← towns(current)) {
          if (minDistance(next) > cost + length) {
            minDistance(next) = cost + length
            heap.enqueue((next, cost + length))
          }
        }
      }
    }
    maxDistanceFrom(start) = minDistance(far)
    if (maxDistance <= minDistance(far)) {
      maxDistance = minDistance(far)
      val fars = (0 until n).filter(t ⇒ minDistance(t) == maxDistance)
      val queue = mutable.Queue[Int](fars:_*)
      fars.foreach(i ⇒ useWhenStartFrom(start)(i) = true)
      while (queue.nonEmpty) {
        val current = queue.dequeue()
        for ((next, length) ← towns(current) if minDistance(next) + length == minDistance(current) && !useWhenStartFrom(start)(next)) {
          useWhenStartFrom(start)(next) = true
          queue.enqueue(next)
        }
      }
    }
  }
  val buzzer = (0 until n).filter(t ⇒ maxDistanceFrom(t) == maxDistance)
  val quiet = (0 until n).filterNot(t ⇒ buzzer.exists(b ⇒ useWhenStartFrom(b)(t)))
  println(quiet.length)
  if (quiet.nonEmpty) println(quiet.map{_ + 1}.mkString("\n"))
}


Measured memory_bytes: 570280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  if((N-1)%(K-1)==0){
    cout<<(N-1)/(K-1)<<endl;
    return 0;
  }
    cout<<(N-1)/(K-1)+1<<endl;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n,i,count=0,q=0;float t;
    cin>>n>>m;
    int a[n];
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<n;i++){q=q+a[i];};t=((1.0/(4*m))*q);
    for(i=0;i<n;i++)
    {if(a[i]>=t)
          {
          count++;}}
    if(count>=m)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;

const double eps=(1e-8);

int n;

bool check(int x,int y)
{
   if (x<=y) 
   {
      return (y-x<=8);
   }
   return (y+60-x<=8);
}

int calc(int a, int b)
{
     return b*100/a;
}

int main()
{
   int sum[5][2];
   while(scanf("%d",&n)!=EOF)
   {
	  if(n==0) break;
	  memset(sum,0,sizeof(sum));
	  for (int i=1;i<=n;i++)
	  {
		  int h,t1,t2;
		  scanf("%d%*c%d%d",&h,&t1,&t2);
		  if (h>=11&&h<=14)
		  {
		     sum[1][0]++;
			 if (check(t1,t2)) sum[1][1]++;
		  }
		  if (h>=18&&h<=20)
		  {
			 sum[2][0]++;
			 if (check(t1,t2)) sum[2][1]++;
		  }
		  if ((h>=0&&h<=1)||(h>=21&&h<=23))
		  { 
			 sum[3][0]++;
			 if (check(t1,t2)) sum[3][1]++;
		  }
	  }  
	  if (sum[1][0]==0)
	  printf("lunch no guest\n");
	  else
	   {
		  printf("lunch %d\n", calc(sum[1][0], sum[1][1]));
	   }
	  
	  if (sum[2][0]==0)
	  printf("dinner no guest\n");
	  else
	   {
		  printf("dinner %d\n", calc(sum[2][0], sum[2][1]));
	   }
	  
	  if (sum[3][0]==0)
	  printf("midnight no guest\n");
	  else
	   {
		  printf("midnight %d\n", calc(sum[3][0], sum[3][1]));
	   }
   }
   return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int n, k, a[107];
bool dp[100007], vis[100007];

bool solve(int rem){
	if(vis[rem]) return dp[rem];
	vis[rem] = true;
	bool ret = false;
	for(int i = 1; i <= n; i++){
		if(a[i] > rem) continue;
		ret = max((int)ret, solve(rem - a[i]) ^ 1);
	}
	dp[rem] = ret;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	cout << (solve(k) ? "First" : "Second");
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a, b, c, d;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    ll ans1 = a * c;
    ll ans2 = a * d;
    if (ans1 > ans2)
        swap(ans1, ans2);
    ll ans3 = b * c;
    ll ans4 = b * d;
    if (ans2 > ans3)
        swap(ans2, ans3);
    if (ans3 > ans4)
        swap(ans3, ans4);
    printf("%lld\n", ans4);
}

Measured memory_bytes: 3832
#include <stdio.h>

int main(){
	
	int c1,c5,c10,c50,c100,c500;
	scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
	if(c1+c5*5+c10*10+c50*50+c100*100+c500*500>=1000)printf("1\n");
	else printf("0\n");
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

signed main()
{
#ifdef POSPELOV
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector <ll> arr(n);
    for (ll &i : arr)
        cin >> i;
    reverse(arr.begin(), arr.end());
    ll l = 2, r = 2;
    for (int i = 0; i < n; i++)
    {
        l = l + ((arr[i] - l % arr[i]) % arr[i]);
        r = (r - r % arr[i]) + arr[i] - 1;
        if (l > r)
            return cout << "-1", 0;
    }
    cout << l << " " << r;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    unsigned long int a[n], b[n-1];
    for(int i=0; i<n-1; i++){
        scanf("%lu", &b[i]);
    }
    a[0] = b[0];
    a[1] = b[0];
    for(int i=1; i<n-1; i++){
        if(a[i] > b[i]){
            a[i] = b[i];
        }
        a[i+1] = b[i];
    }
    unsigned long int ans = 0;
    for(int i=0; i<n; i++){
        ans += a[i];
        //printf("%lu ", a[i]);
    }
    //printf("\n");
    printf("%lu", ans);

    return 0;
}

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

vector<vector<int>> g;
deque<int> c;
int v[1111];
int f(int u) {
	v[u] = 1;
	for (int w : g[u]) {
		int r = v[w] ? v[w] > 0 ? w : 0 : f(w);
		if (!r) continue;
		if (r > 0)
			c.push_front(u);
		if (r == u) r = -1;
		return r;
	}
	v[u] = -1;
	return 0;
}
int main() {
	int n, m;
	cin >> n >> m;
	g.resize(n + 1);
	set<pair<int, int>> e;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		e.emplace(a, b);
	}
	for (int i = 1; i <= n; i++)
		if (!v[i] && f(i))
			goto pn;
	cout << -1 << endl;
	return 0;
pn:
	for (;;) {
		int i, j;
		for (i = 0; i < c.size(); i++) {
			for (j = 0; j < c.size(); j++) {
				if (i == j) continue;
				if (i + 1 == j) continue;
				if (i == c.size() - 1 && !j) continue;
				if (e.find({ c[i],c[j] }) != e.end())
					goto pf;
			}
		}
		break;
	pf:
		if (i < j) c.erase(c.begin() + i + 1, c.begin() + j);
		else c.erase(c.begin() + i + 1, c.end()), c.erase(c.begin(), c.begin() + j);
	}
	cout << c.size() << '\n';
	for (int v : c) cout << v << '\n';
	cout << flush;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

main()
{
	int n,k;
	int p[1001];
	
	scanf("%d",&n);
	scanf("%d",&k);
	
	int i;
	int j;
	int sum=0;
	int temp;
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&p[i]);
	}
	
	for(j=1;j<n+1;j++)
	{
		for(i=0;i<n-1;i++)
		{
			if(p[i]>=p[i+1])
			{
				temp=p[i];
				p[i]=p[i+1];
				p[i+1]=temp;
			}
		}
	}
	
	for(i=0;i<k;i++)
	{
		sum+=p[i];
	}
	
	printf("%d",sum);
}
	
	

Measured memory_bytes: 1688
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	a := map[int]int{}

	for i := 0; i < n; i++ {
		num := nextInt()
		_, ok := a[num]
		if ok {
			delete(a, num)
		} else {
			a[num] = num
		}
	}

	fmt.Println(len(a))

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 8636
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

readInt :: B.ByteString -> Maybe (Int,B.ByteString)
readInt xs = do
    (x,ys) <- B.readInt xs
    return (x,B.tail ys)

main :: IO ()
main = do
    (n,m) <- (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
    print $ (n*(n-1) `div` 2) + (m*(m-1) `div` 2)

Measured memory_bytes: 380
mod = 10**9+7
fact = [1]*(10**6+1)
for i in range(10**6):
    fact[i+1] = ((i+1)*fact[i])%mod

def comb(n,k):
    return (fact[n]*pow(fact[k],mod-2,mod)*pow(fact[n-k],mod-2,mod))%mod

X,Y = map(int,input().split())
a = 2*Y-X
b = 2*X-Y
ans = 0
if a%3==0 and b%3==0 and a>=0 and b>=0:
    ans = comb((a+b)//3,a//3)
print(ans)

Measured memory_bytes: 48464
import math
def myop1(e):
    return e[1]

def myop2(e):
    return e[0]

t=int(input())
l=[]
d={}
for _ in range(t):
    s,n=input().split(' ')
    n=int(n)
    l.append((s,n))
k=[i for i in l]
l.sort(reverse=True,key=myop1)
l.sort(key=myop2)
for i in range(len(l)):
    d[k[i]]=i
for i in l:
    print(str(d[i]+1))

Measured memory_bytes: 3064
import sys
from collections import deque
import copy
def main():
    a, b, c, K = map(int, input().split())
    ans = 0
    ans += min(K, a)
    K -= a
    if K > 0:
        K -= b
    if K > 0:
        ans -= K
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9568
function main(input){
  const lines = input.split('\n')
  const W = lines[0].split(' ').map(x => parseInt(x))[0];
  const H = lines[0].split(' ').map(x => parseInt(x))[1];
  const x = lines[0].split(' ').map(x => parseInt(x))[2];
  const y = lines[0].split(' ').map(x => parseInt(x))[3];

  var result = W*H/2;
  var flag = 0;

  if(x==W/2 && y==H/2){
    flag=1;
  }

  console.log('%s %s',result, flag);

}

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

Measured memory_bytes: 21064
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;
using PAIR = pair<string, int>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
    }
    a.push_back(1001001001);
    vector<mint> dp(n + 10, 0);
    dp[0] = 1;
    int index = 0; //今aベクトルのどこまで見たのか
    for (int i = 1; i <= n; i++)
    { //iは段数
        if (a[index] > i)
        {
            if (i != 1)
            {
                dp[i] = dp[i - 1] + dp[i - 2];
            }
            else
            {
                dp[i] = dp[i - 1];
            }
        }
        else if (a[index] == i)
        {
            index++;
            continue;
        }
    }
    // debug_vec(dp);
    cout << dp[n] << endl;

    return 0;
}

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

int main()
{
  int n;
  string s;
  string t;
  
  cin >> n >> s >> t;
  
  for(int i = 0; i < s.size(); i++){
    cout << s.at(i) << t.at(i);
  }
  
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
N=input()
n=int(N)
if len(N)==1:
  print(n)
elif len(N)==2:
  print(9)
elif len(N)==3:
  print(9+(n-99))
elif len(N)==4:
  print(909)
elif len(N)==5:
  print(909+(n-9999))
else:
  print(90909)

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

using namespace std;

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

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

template <class T>
class SegmentTree{
private:
	int n;
	vector<T> data;
	T def;
	function<T(T,T)> operation;
	function<T(T,T)> update;

	T _query(int a, int b, int k, int l, int r){
		if(r <= a or b <= l) return def;

		if(a <= l and r <= b) return data[k];
		else{
			T c1 = _query(a, b, 2*k+1, l, (l+r)/2);
			T c2 = _query(a, b, 2*k+2, (l+r)/2, r);
			return operation(c1, c2);
		}
	}

public:
	SegmentTree(size_t n_, T _def, function<T(T,T)> _operation, function<T(T,T)> _update)
	: def(_def), operation(_operation), update(_update){
		n = 1; while(n < n_) n *= 2;
		data = vector<T>(2*n-1, def);
	}

	void change(int i, int val){
		i += n-1;
		data[i] = update(data[i], val);
		while(i > 0){
			i = (i-1)/2;
			data[i] = operation(data[2*i+1], data[2*i+2]);
		}
	}

	T query(int a, int b){
		return _query(a, b, 0, 0, n);
	}

	T operator[](int i){
		return data[i+n-1];
	}

};

int main(){

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

    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    SegmentTree<ll> st(n, 0LL, [](ll a, ll b){return gcd(a, b);}, [](ll a, ll b){return b;});

    ll mx = 0LL;

    rep(i, n) st.change(i, a[i]);
    rep(i, n) mx = max(mx, gcd(st.query(0, i), st.query(i+1, n)));
    ppp(mx);
    return 0;
}


Measured memory_bytes: 2688
#include<stdio.h>
#include<stdlib.h>
int kaijou(int);
int main(void){
  int N,i,j,p[1000],s[1000],a=0,b=0,pc=0,sc=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&p[i]);
  }
   for(i=0;i<N;i++){
    scanf("%d",&s[i]);
  }
  
  
  for(i=0;i<N-2;i++){
    for(j=i+1;j<N;j++){
      if(p[i]>p[j])pc++;
    }
    if(pc>0){
  a+=pc*kaijou(N-i-1);
    }
    pc=0;
  }

  if(p[N-2]<p[N-1])a++;
  else a+=2;
  
   
  for(i=0;i<N-2;i++){
    for(j=i+1;j<N;j++){
      if(s[i]>s[j])sc++;
    }
    if(sc>0){
  b+=sc*kaijou(N-i-1);}
    sc=0;
  }
  if(s[N-2]<s[N-1])b++;
  else b+=2;
 printf("%d",abs(a-b));
  return 0;
}

int kaijou(int M){
if(M>1)return M*kaijou(M-1);
  else return 1;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int h, w;
	cin >> h >> w;

	vector<vector<char>> a(h, vector<char>(w));
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
		}
	}

	vector<int> gyo;
	rep(i, h) {
		bool f = true;
		rep(j, w) {
			if (a[i][j] != '.') {
				f = false;
				break;
			}
		}
		if (f) {
			gyo.push_back(i);
		}
	}

	vector<int> retsu;
	rep(j, w) {
		bool f = true;
		rep(i, h) {
			if (a[i][j] != '.') {
				f = false;
				break;
			}
		}
		if (f) {
			retsu.push_back(j);
		}
	}

	rep(i, h) {
		if (find(all(gyo), i) == gyo.end()) {
			rep(j, w) {
				if (find(all(retsu), j) == retsu.end()) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

int main()
{
	int a,b,c,na,nb,nc,x,y,ans=0;
	scanf("%d%d%d%d%d",&na,&nb,&nc,&x,&y);
	if(nc<=((na+nb)>>1))
	{
		if(x>y)
		{
			swap(x,y);
			swap(na,nb);
		}
		ans+=nc*x*2;
		y-=x;x=0;
		if(2*nc<nb)
			ans+=y*nc*2;
		else
			ans+=y*nb;
		printf("%d\n",ans);
	}
	else
		printf("%d\n",x*na+y*nb);
	return 0;
}

Measured memory_bytes: 128
kind = int(input())
atLIST=[list(map(int,input().split())) for i in range(3)]

happy = 0
tmp = atLIST[0][0]
c=0
for i in range(kind):
		happy = happy + atLIST[1][i-1]
		if tmp == atLIST[0][i]-1:
				happy = happy + atLIST[2][tmp-1]
				c = c + 1
		tmp = atLIST[0][i]
print(happy)





Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,m;cin >> n >> m;
  vector<int> s(m),c(m);
  rep(i,m) {cin >> s[i] >> c[i];s[i]--;}
  vector<int> res(n,-1);
  rep(i,m){
    if(res[s[i]]>=0){
      if(res[s[i]]!=c[i]){
	cout << -1 << "\n";
	return 0;
      }
    }
    else{
      res[s[i]]=c[i];
    }
  }

  if(n>=2){
    if(res[0]==0){
      cout << -1 << "\n";
      return 0;      
    }
    else if(res[0]==-1){
      res[0]=1;
    }
  }
  rep(i,n){
    if(res[i]==-1) res[i]=0;
  }
  rep(i,n) cout << res[i];
  cout  << "\n";
  return 0;
}


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

int main()
{
  int N, K;
  int a[210000];
  int b[210000];
  int res=0;
  cin >> N >> K;

  rep(i,N) cin >> a[i];
  rep(i,N+1) b[i]=0;

  rep(i,N){
    b[a[i]]++;
  }

  sort(b,b+N, greater<int>());

  rep(i,N+1){
    if(i<K) continue;
    res += b[i];
  }

  cout << res << endl;
}


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

    int a,b;
    
    cin >> a >> b;
    
    if(a < b){
        cout << "a < b" << endl;
    }else if(a > b)
    {
        cout << "a > b" << endl;
    }else
    {
        cout << "a == b" << endl;
    }
    
}


Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;



int main() {
    int H, W;
    queue<pii> q;
    char c;
    int dx[] = {1, 0, -1, 0},
        dy[] = {0, 1, 0, -1};
    static int m[1001][1001];
    
    cin >> H >> W;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> c;
            if (c == '#') {
                q.push(pii(i,j));
                m[i][j] = 1;
            }
        }
    }
    
    while(!q.empty()) {
        pii t = q.front();
        q.pop();
        for (int i = 0; i < 4; ++i) {
            int x = t.x + dx[i],
                y = t.y + dy[i];
            if (x >= 0 && y >= 0 && x < H && y < W && !m[x][y]) {
                m[x][y] = m[t.x][t.y] + 1;
                q.push(pii(x, y));
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < H; ++i)
        for (int j = 0; j < W; ++j) {
            if (m[i][j] > ans) ans = m[i][j];
        }
    cout << ans - 1;
    return 0;
}

Measured memory_bytes: 12304
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
char g[102][102];
bool tag[102][102];
int n,m;
void dfs(int ,int);
int main(){
	while(cin>>n>>m&&n&&m){
		cin.get();
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				cin>>g[i][j];
		memset(tag,0,sizeof(tag));
		int cnt=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if(!tag[i][j]){
					cnt++;
					dfs(i,j);
				}
		cout<<cnt<<endl;
	}
	return 0;
}
void dfs(int y,int x){
	tag[y][x]=1;
	for(int i=-1;i<=1;i++)
		for(int j=-1;j<=1;j++)
			if(abs(i)+abs(j)==1&&g[y][x]==g[y+i][x+j]&&y+i>=1&&y+i<=n&&x+j>=1&&x+j<=m&&tag[y+i][x+j]==0)
				dfs(y+i,x+j);
}



Measured memory_bytes: 4172
N = int(input())

A = []
for i in range((N//4)+1) :
    for j in range((N//7)+1) :
        if N == 4*i + 7*j :
            A.append("Yes")
        else :
            A.append("No")

if "Yes" in A :
    print("Yes")
else :
    print("No")


Measured memory_bytes: 2940
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	S := ReadString()
	Q := ReadInt()
	reverse := false
	head := ""
	tail := ""
	for i := 0; i < Q; i++ {
		q := ReadInt()
		if q == 1 {
			reverse = !reverse
		} else {
			f, c := ReadInt(), ReadString()
			if reverse {
				if f == 1 {
					f = 2
				} else {
					f = 1
				}
			}
			if f == 1 {
				head += c
			} else {
				tail += c
			}
		}
	}
	head = toReverse(head)
	S = head + S + tail
	if reverse {
		S = toReverse(S)
	}
	fmt.Println(string(S))
}

func toReverse(s string) string {
	out := []byte(s)
	i := 0
	j := len(s) - 1
	for i < j {
		out[i], out[j] = out[j], out[i]
		i++
		j--
	}
	return string(out)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 8340
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define     int                 ll
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

int pwr(int b,int e){
	int ret = 1;
	while(e){
		if(e&1){
			ret = (ret*b)%MOD;
		}
		b = (b*b)%MOD;
		e /= 2;
	}
	return ret;
}

void solve(){
    int n, ans;
    cin >> n;
    if(n==1){
    	cout << "0\n";
    	return;
    }
    ans = pwr(10,n);
    ans -= 2*pwr(9,n);
    ans += pwr(8,n);
    cout << (ans%MOD+MOD)%MOD << '\n';
}

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

Measured memory_bytes: 3696
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B&lang=jp
// hos?????????????????????????????????
// lowlink????¨??????????????????§??????
// lowlink????¨??????????????????§????????????????????¢?????¨?????????????????????????????§
// http://kagamiz.hatenablog.com/entry/2013/10/05/005213??????????????????
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
vector<int> G[100000];
vector<P> bridge;
vector<int> articulation;
int ord[100000], low[100000];
bool vis[100000];
int v, e, s, t, k;
void dfs(int v, int p, int &k) {
    vis[v] = true;
    ord[v] = k++; low[v] = ord[v];
    bool isArticulation = false;
    int ct = 0;
    for (int i=0; i<G[v].size(); i++) {
        if (!vis[G[v][i]]) {
            ct++;
            dfs(G[v][i], v, k);
            low[v] = min(low[v], low[G[v][i]]);
            if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
            if (ord[v] < low[G[v][i]]) bridge.push_back(P(min(v, G[v][i]), max(v, G[v][i])));
        } else if (G[v][i] != p) {
            low[v] = min(low[v], ord[G[v][i]]);
        }
    }
    if (p == -1 && ct > 1) isArticulation = true;
    if (isArticulation) articulation.push_back(v);
}
int main() {
    scanf("%d%d",&v,&e);
    for (int i=0; i<e; i++) {
        scanf("%d%d",&s,&t);
        G[s].push_back(t); G[t].push_back(s);
    }
    if (v == 1) {
    } else {
        k = 0;
        for (int i=0; i<v; i++) {
            if (!vis[i]) dfs(i, -1, k);
        }
        sort(articulation.begin(), articulation.end());
        for (int i=0; i<articulation.size(); i++)
            printf("%d\n", articulation[i]);
    }
}

Measured memory_bytes: 5188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200010;
map<int,int> mp;
ll n,s[N],sum[N],k;
int main()
{
	cin>>n>>k;
	ll mx=0,l;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		sum[i]=sum[i-1]+s[i];
	}
	for(int i=k;i<=n;i++)
	{
		if(sum[i]-sum[i-k]>mx) mx=sum[i]-sum[i-k],l=i; 
	}
	double ans=0;
	for(int i=l-k+1;i<=l;i++)
		ans+=(((s[i]+1)*s[i])/(2.0*s[i]));
	printf("%.10lf",ans);
	return 0;
 }

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(c >= a && c <= b)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = str(input())
n_list = list(n)
r = ''
for i in n_list:
  r += '1'

def make_math(numbers, b_str):
  b_str_list = list(b_str)
  r = ''
  for index, n in enumerate(b_str_list):
    r += numbers[index]
    if n == '1' and index < len(b_str_list) - 1:
      r += '+'
  return r

math_list = []
f = '0' + str(len(r)) + 'b'
bi = int(r, 2)
for i in range(bi):
  bb = format(i+1, f)
  math_list.append(make_math(n, bb))

total = 0
m = list(set(math_list))
for mm in m:
  mm_split = map(int, mm.split('+'))
  total += sum(mm_split)

print(total)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
	int n,i,j;
	int debt=100000;
	cin>>n;
	for(i=0;i<n;i++){
		debt=(double)debt*1.05;
		if((int)debt/1000*1000!=(int)debt){
			debt=(int)debt/1000*1000+1000;
		}
	}
	cout<<debt<<endl;
	return 0;
}

Measured memory_bytes: 1160
A,B,C,D = map(int,input().split())

def gcd(x,y):

    if(y>x):
        x,y = y,x
    if(x%y==0):
        return y
    else:return gcd(y,x%y)


def lcm(x,y):
    return x*y//gcd(x,y)

Bika = B - B//C -B//D + B//lcm(C,D)
Aika = A-1 - (A-1)//C -(A-1)//D + (A-1)//lcm(C,D)

print(Bika-Aika)


Measured memory_bytes: 38256
import sys
s=p=0
for l in sys.stdin:
	if l.strip()=="":
		s=p=0
		continue
	if s==5:continue
	t=int(l)
	c=l.count("1")
	if c==4:
		s=5
		print"C"
	if s==1:
		if c==1:print"B"
		elif t/p==1:print"F"
		else: print"D"
		s=5
	elif s==2:
		if p>t:print"E"
		elif p==t:print"A"
		else: print"G"
		s=5
	else:
		p=t
		s=c

Measured memory_bytes: 4224
# Reference: https://qiita.com/dn6049949/items/afa12d5d079f518de368

# self.data: 1-indexed
#    __1__
#  _2_   _3_
# 4   5 6   7

# f(f(a, b), c) == f(a, f(b, c))

class SegmentTree:
    # a = [default] * n
    # O(n)
    def __init__(self, n, f=max, default=-2**30):
        self.num_leaf = 2 ** (n-1).bit_length()
        self.data = [default] * (2*self.num_leaf)
        self.f = f

    # a[i] = x
    # O(log(n))
    def update(self, i, x):
        i += self.num_leaf
        self.data[i] = x
        i >>= 1
        while i > 0:
            self.data[i] = self.f(self.data[2*i], self.data[2*i+1])
            i >>= 1

    # return f(a[l:r])
    # O(log(n))
    def query(self, l, r):
        l += self.num_leaf
        r += self.num_leaf - 1
        lres, rres = self.data[0], self.data[0] # self.data[0] == default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.data[l])
                l += 1
            if not r & 1:
                rres = self.f(self.data[r], rres)
                r -= 1
            l >>= 1
            r >>= 1
        if l == r:
            res = self.f(self.f(lres, self.data[l]), rres)
        else:
            res = self.f(lres, rres)
        return res

    # You can use min_index only if f == max.
    # return min({i | x <= i and v <= a[i]}, self.num_leaf)
    # O(log(n))
    def min_index(self, x, v):
        x += self.num_leaf
        while self.data[x] < v:
            if x & 1:
                if x.bit_length() == (x+1).bit_length():
                    x += 1
                else:
                    return self.num_leaf
            else:
                x >>= 1
        while x < self.num_leaf:
            if self.data[2*x] >= v:
                x = 2*x
            else:
                x = 2*x + 1
        return x - self.num_leaf

from sys import stdin
input = stdin.buffer.readline

def main():
    n, k = map(int, input().split())

    # その値で終わる最長部分列の長さを格納
    st = SegmentTree(n=300001, default=0)

    for _ in range(n):
        a = int(input())
        st.update(a, st.query(max(0, a - k), min(300001, a + k + 1)) + 1)

    print(st.data[1])

main()

Measured memory_bytes: 83884
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> abc(3); int k;
  for(int i=0; i<3; i++) cin>>abc.at(i);
  cin>>k;
  sort(abc.begin(), abc.end());
  for(int i=0; i<k; i++)
    abc.at(2) *= 2;
  cout<<abc.at(0)+abc.at(1)+abc.at(2)<<endl;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = LLONG_MAX;
 
using vc = vector<char>;
using vi = vector<int>;

int H, W, N;
int SR, SC; 
string S, T;

bool solveLR() {
    int lo = 0; int hi = W - 1;
    R0F(i, N) {
        if (T[i] == 'L')             
            hi = min(hi+1, W-1);
        if (T[i] == 'R')
            lo = max(lo-1, 0);

        if (S[i] == 'L') ++lo;
        if (S[i] == 'R') --hi;

        if (lo > hi || lo > W - 1 || hi < 0) return false;
    }
    return lo <= SC && SC <= hi;
}

bool solveUD() {
    int lo = 0; int hi = H - 1;
    R0F(i, N) {
        if (T[i] == 'U')             
            hi = min(hi+1, H-1);
        if (T[i] == 'D')
            lo = max(lo-1, 0);

        if (S[i] == 'U') ++lo;
        if (S[i] == 'D') --hi;

        if (lo > hi || lo > H - 1 || hi < 0) return false;
    }
    return lo <= SR && SR <= hi;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> H >> W >> N;
    cin >> SR >> SC; --SR; --SC;
    cin >> S >> T;
    if (solveLR() && solveUD()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 920
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

typedef long long LL;
typedef vector<LL> VL;
typedef vector<vector<LL>> VVL;
typedef vector<string> VS;

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

LL llRead(){
  LL a;
  cin >> a;
  return a;
};

string stringRead(){
  string a;
  cin >> a;
  return a;
};

vector<LL> vlRead(LL a){
  vector<LL> rv;
  REP(i, a){
    LL input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}

vector<string> vsRead(LL a){
  vector<string> rv;
  REP(i, a){
    string input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}
vector<vector<LL>> vvlRead(LL a, LL b){
  vector<vector<LL>> rv;
  REP(i, a){
    rv.push_back(vector<LL>());
    REP(j, b) {
      LL input;
      cin >> input;
      rv.at(i).push_back(input);
    }
  }
  return rv;
}

#if 1
#define debug(d) debug1(__LINE__,#d, d)
void debug1(LL line, const char* name, VL& v) {
  cout << line << ":" << name << ":vector<LL>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, LL i) {
  cout << line << ":" << name << ":LL " << i << endl;;
}
void debug1(LL line, const char* name, VS& v) {
  cout << line << ":" << name << ":vector<string>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, VVL& v) {
  cout << line << ":" << name << ":vector<vector<LL>>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    REP(j, (LL)v.at(i).size()) {
      cout << v.at(i).at(j) << " ";
    }
    cout << ", ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, char* s) {
  cout << line << ":" << name << ":char* " << s << endl;;
}
void debug1(LL line, const char* name, vector<const char*>& v) {
  cout << line << ":" << name << ":vector<const char*>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, priority_queue<LL>& p) {
  cout << line << ":" << name << ":priority_queue<LL>(" << p.size() << ") ";
  priority_queue<LL> copy = p;
  while(!copy.empty()) {
    cout << copy.top() << " ";
    copy.pop();
  }
  cout << endl;
}
#else
#define debug(n)
#endif

int main(int argc, const char * argv[]) {
	cout.precision(16);
  // source code

  auto a = llRead();
  auto b = llRead();
  auto c = a - b -b;
  if (c > 0) cout << c << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]
n, m=map(int, input().split())
U=WeightedUnionFind(n)
def C(U):
    for i in range(m):
        l, r, d = map(int, input().split())
        if U.same(l-1, r-1):
            if U.diff(l-1, r-1)!=d:
                return False
        else:
            U.union(l-1, r-1, d)
    return True
if C(U):
    print('Yes')
else:
    print('No')
        

Measured memory_bytes: 100896
formula = gets.split

# formula = %w(1 2 + 3 4 - *)
opes = ['+','-','*']
stack = []
ans = nil
formula.each do |char|
  # binding.pry
  if opes.include?(char)
    first = stack.pop
    second = stack.pop
    str = "#{second}"+"#{char}"+"#{first}"
    stack.push(eval(str))
  else
    stack.push(char)
  end
end
puts stack[0]



Measured memory_bytes: 6920
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;

int main(){
    int n,x,c=0;
    vector<int>v,t ;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>x;
        v.push_back(x);
        t.push_back(x);
    }
    
    sort(t.begin(),t.end());
    
    for(int i=0;i<n;++i)
        if(v[i]!=t[i])
          c++;

    if(c>2)puts("NO");
    else puts("YES");
}

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

int main(){
  int n,tem,p[51], ans=0;
  bool flg=true;
  cin>>n;
  for (int i = 0; i < n; i++) {
    cin>>p[i];
  }

  for(int k=0; k<n; k++){
    // cout<<p[k]<<" ";
    if(p[k]!=k+1) flg=false;
  }
  if(flg){
    ans=1;
    // cout<<"YES"<<endl;
  }


  for(int i=0; i<n; i++) {
    for(int j=i+1; j<n; j++) {
      tem=p[j];
      p[j]=p[i];
      p[i] =tem;
      flg=true;
      for(int k=0; k<n; k++){
        // cout<<p[k]<<" ";
        if(p[k]!=k+1) flg=false;
      }
      if(flg){
        ans=1;
        // cout<<"YES"<<endl;
      }
      // else cout<<"NO"<<endl;
      tem=p[j];
      p[j]=p[i];
      p[i] =tem;
    }
  }
cout<<((ans==1)?"YES":"NO")<<endl;;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n);
    rep(i, 0, n + 1) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    
    ll cnt = 0;
    rep(i, 0, n)
    {
        int c;
        c = min(a[i], b[i]);
        cnt += c;
        b[i] -= c;
        a[i] -= c;

        c = min(a[i + 1], b[i]);
        cnt += c;
        b[i] -= c;
        a[i + 1] -= c;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
            vars
            (mapcar (constantly '(read))
                vars)))
       ,@body)))

(defsolver solution-c (w h x y)
  (let ((gx (/ w 2))
	(gy (/ h 2)))
    (format t "~,6F ~:[0~;1~]"
	    (/ (* w h) 2)
	    (and (= gx x) (= gy y)))))

(solution-c)

Measured memory_bytes: 12900
#include<bits/stdc++.h>
using namespace std;
long int c[100001];
long int cost(int a[],int i){
    if(i==0)return 0;
    if(i==1)return abs(a[1]-a[0]);
    if(c[i]!=-1)return c[i];
    return c[i]= min(cost(a,i-1)+abs(a[i]-a[i-1]),cost(a,i-2)+abs(a[i]-a[i-2]));
 }
int main(){
    int n;
    cin >>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        c[i]=-1;
    }
    cout << cost(a,n-1)<<endl;
    
    // for(int i=0;i<n;i++){
    //     cout<<c[i]<<endl;
    // }
    return 0;
}

Measured memory_bytes: 4480
def fctr1(n): 
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append((i,c))
            c=0
    if n!=1:
        f.append((n,1))        
    f.sort(reverse=True,key=lambda x:x[1])
    return (f)

def main():

  n,p=map(int,input().split())
  li=fctr1(p)
  ans=1
  for i,j in li:
    ans*=(i**(j//n)) 

  print(ans)
  
main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int A,B,C,D;cin>>A>>B>>C>>D;
  int i=0;
  while(A>0 && C>0){
    if(i%2==0) C-=B;
    else A-=D;  
    ++i;
  }
  if(A<=0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cmath>

#define N_MAX 100
#define H_MAX 100000001

int x[N_MAX];
int y[N_MAX];
int h[N_MAX];
int h_diff[N_MAX];

using namespace std;

int main(){
    int N;
    int h_min = H_MAX;
    int h_max = -1;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> h[i];
    }

    int H_tmp;
    int sum_min;

    for(int i = 0; i <= N_MAX; i++){
        for(int j = 0; j <= N_MAX; j++){
            sum_min = H_MAX;
            if(h[0] == 0){
                H_tmp = -1;
                sum_min = abs(x[0]- i) + abs(y[0] - j);
            }else{
                H_tmp = h[0] + abs(x[0]- i) + abs(y[0] - j);
            }
            for(int k = 1; k < N; k++){
                if(H_tmp == -1){
                    if(h[k] != 0){
                        H_tmp = (h[k] + abs(x[k]- i) + abs(y[k] - j));
                    }else{
                        if(abs(x[k]- i) + abs(y[k] - j) < sum_min){
                            sum_min = abs(x[k]- i) + abs(y[k] - j);
                        }
                    }
                }else{
                    if(h[k] == 0){
                        if(abs(x[k]- i) + abs(y[k] - j) < sum_min){
                            sum_min = abs(x[k]- i) + abs(y[k] - j);
                        }
                    }else{
                        if(H_tmp != (h[k] + abs(x[k]- i) + abs(y[k] - j))) break;
                    }
                }
                if(k == N-1 && H_tmp <= sum_min && sum_min != H_MAX){
                    cout << i << ' ' << j << ' ' << H_tmp << '\n';
                }else if(k == N-1 && sum_min == H_MAX){
                    cout << i << ' ' << j << ' ' << H_tmp << '\n';
                }
            }
        }
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  string s;
  cin >> s;
  int n=s.length()-1;
  ll ans=0;

  for(int bit=0; bit< (1<<n); bit++){
    ll plusbefore=s[0]-'0';
    rep(i, n){
      if(bit&(1<<i)){
        ans+=plusbefore;
        plusbefore=s[i+1]-'0';
      } else {
        plusbefore=plusbefore*10+s[i+1]-'0';
      }
    }
    ans+=plusbefore;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
  int i;//カウンタ
  int n;//景品の種類の数
  int k;//各景品がいくつ残っているか
  
  //最初の景品の種類数を入力
  scanf("%d", &n);
  do{
    int one = 0;//景品が１個以下の景品を格納する
    int zero = 0;//景品が０個の種類数を格納する
    for(i=0;i<n;i++){
      //景品の種類数を格納する
      scanf("%d", &k);
      
      //判定
      if (k <= 1){
	++one;//景品が１以下だったらカウントする
      }
      if (k == 0){
	++zero;//残りの景品が０個のものをカウントする
      }
      
    }
    if(n==one){//全ての種類の景品が１個以下だったらおそろいの景品は獲得できない
      printf("NA\n");
    }else{
      printf("%d\n", n -zero + 1);//ｎ種類の景品のうち、０個の物を除き、１を足してやる
    }
    //景品の種類数を入力
    scanf("%d",&n);
  }while(n>0);
  
  return(0);  
}



Measured memory_bytes: 2748
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i){ return i/2;}

int left(int i){ return 2*i;}

int right(int i){ return 2*i+1;}

int main(){
  int H,i,A[MAX+1];//1をはじめに考える

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

  for(int i=1;i<=H;i++){
    cout<<"node "<<i<<": key = "<<A[i]<<", ";
    if(parent(i)>=1) cout<<"parent key = "<< A[parent(i)]<<", ";
    if(left(i)<=H) cout<<"left key = "<< A[left(i)]<<", ";
    if(right(i)<=H) cout<<"right key = "<< A[right(i)]<<", ";
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3072