akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;
    int cnt = 0;
    rep(i, n) {
        if (a[a[i]] == i) cnt++;
    }
    cnt /= 2;
    cout << cnt << endl;
}

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

long long int N, M, a;

int main(){
    scanf("%lld%lld", &N, &M);
    a = N;
    if(M <= N * 2)return 0 & printf("%lld", M / 2);
    M -= N * 2;
    a += M / 4;
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while (a >= b) k--, b *= 2;
    while (b >= c) k--, c *= 2;
    cout << (k >= 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3644
s = input()
n_a = [0]
n_l = [0]
n_c = [0]
n_r = [0]

mod = 10 ** 9 + 7
n = len(s)

pow3 = [1]
for i in range(n):
    pow3.append(pow3[-1] * 3 % mod)

for i in range(n):
    if s[i] == 'A':
        n_a.append(n_a[-1]+1)
    else:
        n_a.append(n_a[-1])

    if s[i] == '?':
        n_l.append(n_l[-1]+1)
    else:
        n_l.append(n_l[-1])

    if s[-i-1] == 'C':
        n_c.append(n_c[-1]+1)
    else:
        n_c.append(n_c[-1])

    if s[-i-1] == '?':
        n_r.append(n_r[-1]+1)
    else:
        n_r.append(n_r[-1])

ans = 0

for i in range(1, n - 1):
    if s[i] in ['B', '?']:
        # ABC
        ans += n_a[i] * n_c[n -  1 - i] * pow3[n_l[i]] * pow3[n_r[n - 1 - i]] % mod
        ans %= mod
        # ?BC   
        ans += n_l[i] * n_c[n -  1 - i] * pow3[n_l[i] - 1] * pow3[n_r[n - 1 - i]] % mod
        ans %= mod
        # AB?
        ans += n_a[i] * n_r[n -  1 - i] * pow3[n_l[i]] * pow3[n_r[n - 1 - i] - 1] % mod
        ans %= mod
        # ?B?
        ans += n_l[i] * n_r[n -  1 - i] * pow3[n_l[i]-1] * pow3[n_r[n - 1 - i] - 1] % mod
        ans %= mod

print(ans)


Measured memory_bytes: 16808
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;
#define nl endl

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
bool mark[100005];vi prime;
void seive(ll N){for(int i=2;i<=N;i++){if(mark[i]==false){prime.pb(i);for(int j=i+i;j<N;j+=i)mark[j]=true;}}}
//freopen("input.txt", "r", stdin);

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    int res=1,mx=v[0];
    for(int i=1;i<n;i++){
        if(v[i]>=mx) res++;
        mx=max(mx,v[i]);
    }
    cout<<res<<endl;
    End;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

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; }

int main()
{
    int n;
    cin >> n;
    vector <int> c(n), s(n), f(n);
    for (int i = 0; i < n-1; i++) cin >> c[i] >> s[i] >> f[i];

    for (int i = 0; i < n; i++) {
        int t = 0;
        for (int j = i; j < n-1; j++) {
            if (t < s[j]) t = s[j];
            else if (t % f[j] == 0);
            else t += f[j] - (t%f[j]);
            t += c[j];
        }
        cout << t << endl;
    }
	return 0;
}


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


int main() {
  int A,B,K;

  cin >> A >> B >> K;
  set<int> S;

  for(int i=0;i<K;++i){
    if(A+i > B) break;
    cout << A+i << endl;
    S.insert(A+i);
  }

  for(int i=K-1;i>=0;--i){
    if(B-i < A) continue;
    if(!S.count(B-i)){
      cout << B-i << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std;
vector<int>G[1<<18];
double dp[1<<18];
double dp2[1<<18];
double dfs(int u,int p)
{
	int cnt=0;double ans=0;
	for(int i=0;i<G[u].size();i++)
	{
		if(G[u][i]==p)continue;
		ans+=dfs(G[u][i],u)+1;
		cnt++;
	}
	return dp[u]=cnt?ans/cnt:1;
}
void dfs2(int u,int p,double a)
{
	double ans=0;
	for(int i=0;i<G[u].size();i++)
	{
		if(G[u][i]==p)ans+=a;
		else ans+=dp[G[u][i]];
	}
	dp2[u]=ans/G[u].size();
	for(int i=0;i<G[u].size();i++)
	{
		if(G[u][i]==p)continue;
		dfs2(G[u][i],u,1+(ans-dp[G[u][i]])/max(1,(int)G[u].size()-1));
	}
}
main()
{
	int n;cin>>n;int u,v;
	for(int i=1;i<n;i++)
	{
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1,0);
	dfs2(1,0,0);
	for(int i=1;i<=n;i++)
	{
		cout<<fixed<<setprecision(9)<<dp2[i]<<endl;
	}
}

Measured memory_bytes: 21888
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 2e5+10;
inline char get() {
	static char buf[10000], *S = buf, *T = buf;
	if (S == T) {
		T = (S = buf) + fread(buf, 1, 10000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}
inline void read(int &x) {
	static char c; x = 0; int sgn = 0;
	for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
	for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
	if (sgn) x = -x;
}

ll t[N+1];
void upd(int x, ll v) {
  for (; x <= N; x += (x & -x)) t[x] = max(t[x], v);
}
ll query(int x) {
  ll ans = 0;
  for (; x; x -= (x & -x)) ans = max(ans, t[x]);
  return ans;
}

int n;
int h[N];
int a[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read(n);
  for (int i = 0; i < n; i++) {
    read(h[i]);
  }
  for (int i = 0; i < n; i++) {
    read(a[i]);
  }
  ll ans = a[0];
  upd(h[0], a[0]);
  for (int i = 1; i < n; i++) {
    ll dp = query(h[i]) + a[i];
    ans = max(ans, dp);
    upd(h[i], dp);
  }
  cout << ans << nl;
  return 0;
}


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

using namespace std;

int main(){
  int n, m;
  std::cin >> n >> m;

  vector<int> x(m);
  for(int idx = 0; idx < x.size(); idx++){
    std::cin >> x[idx];
  }

  sort(x.begin(), x.end());

  if(x.size() <= n){
    std::cout << "0" << '\n';
    return 0;
  }

  vector<int> diff(m - 1, 0);
  for(int idx = 0; idx < m - 1; idx++){
    diff[idx] = x[idx + 1] - x[idx];
  }

  sort(diff.begin(), diff.end(), greater<int>());
  // for(int idx = 0; idx < diff.size(); idx++) std::cout << diff[idx] << '\n';

  int ans = 0;
  int idx = n - 1;
  for(; idx < diff.size(); idx++){
    ans += diff[idx];
  }

  std::cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 1024
import sys

for s0 in sys.stdin:
  s=s0[:-1]
  d,c=s.split("=")
  a,b=d.split("+")
  f=any([e!=e[0]=="X" for e in [a,b,c]])

  m="NA"
  s=d+"=="+c
  for e in "0123456789"[f:]:
    try:
      if eval(s.replace("X",e)): m=e; break
    except: pass
  print m

Measured memory_bytes: 4272
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

def gcd(a,b):
	while b:
		a,b = b, a%b
	return a

#最小公倍数
def lcm(a,b):
	return a*b // gcd(a,b)

A,B,C,D = inpl()
ans = B-A+1
cn = B//C - ((A-1)//C+1) + 1
dn = B//D - ((A-1)//D+1) + 1
cd = lcm(C,D)
cdn = B//cd - ((A-1)//cd+1) + 1

print(ans-cn-dn+cdn)


Measured memory_bytes: 4328
#include <stdio.h>

int main(void){
    // Your code here!
    int a, b, c, x, i, j, k;
    int count = 0;
    scanf("%d%d%d%d", &a, &b, &c, &x);
    for(i=0; i<=a; i++){
        for(j=0; j<=b; j++){
            for(k=0; k<=c; k++){
                if(x == 500*i+100*j+50*k){
                    count++;
                }
            }
        }
    }
    printf("%d\n", count);
}

Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
b=[0]*8
c=0
for x in a:
  if x<400:
    b[0]=1
  elif x<800:
    b[1]=1
  elif x<1200:
    b[2]=1
  elif x<1600:
    b[3]=1
  elif x<2000:
    b[4]=1
  elif x<2400:
    b[5]=1
  elif x<2800:
    b[6]=1
  elif x<3200:
    b[7]=1
  else:
    c+=1
x=b.count(1)
print(max(x,1),x+c)

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    char c; cin >> c;
    cout << (char)(c+1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int64_t N, M;
    cin >> N >> M;
    int64_t n, m;
    if (N < 3) n = N % 2;
        else n = N - 2;
    if (M < 3) m = M % 2;
        else m  = M - 2;
    cout << n * m << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;

int main() {
	ll N;
	cin >> N;
	vector<ll> n(N);
	map<ll, bool> num;
	ll x = 0;
	for (int i = 0; i < N; i++) {
		cin >> n[i];
		num[n[i]] = false;
	}
	for (int i = 0; i < N; i++) {
		if (num[n[i]] == false)num[n[i]] = true;
		else num[n[i]] = false;
	}
	ll ans = 0;
	for (auto x : num) {
		if (x.second) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 7296
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int[] f = new int[n+1];
		for (int x=1; x<=Math.sqrt(n); x++) {
			for (int y=1; y<=Math.sqrt(n); y++) {
				for (int z=1; z<=Math.sqrt(n); z++) {
					int sum = x*x + y*y + z*z + x*y + x*z + y*z;
					if (sum <= n)
						f[sum]++;
				}
			}
		}
		for (int i=1; i<=n; i++)
			System.out.println(f[i]);
	}
}



Measured memory_bytes: 38828
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder s1 = new StringBuilder(sc.next());
		StringBuilder s2 = new StringBuilder();

		int n = sc.nextInt();
		int rev = 0;

		for (int i = 0; i < n; i++) {
			int q = sc.nextInt();
			if (q == 1) {
				rev = 1 -rev;
			} else {
				int f = sc.nextInt();
				String c = sc.next();
				if (f == 1 && rev == 0 || f == 2 && rev ==1) {
					s2.append(c);
				} else {
					s1.append(c);
				}
			}
		}

		if (rev == 0) {
			System.out.println(s2.reverse().append(s1));
		} else {
			System.out.println(s2.reverse().append(s1).reverse());
		}

	}
}

Measured memory_bytes: 124548
#include<bits/stdc++.h>
using namespace std;
int main(){

    int n;
    cin>>n;
    vector<int >col(9,0);
    int nh = 0;
    vector<int >nos(n,0);
    for(int i=0;i<n;i++)cin>>nos[i];
    for(int i=0;i<n;i++)
    {
        if(nos[i]>=3200){nh++;continue;}
        for(int j=1;j<=8;j++)
            if(nos[i]>=(3200-400*j)){col[j]=1;break;}
    }
    int dist = 0;
    for(int i=0;i<9;i++)dist+=col[i];
    int mini = max(dist,1);
    int maxi = dist+nh;
    cout<<mini<<' '<<maxi;
}

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

int main() {
  int K; cin >> K;
  auto S = [](ll x) {
    ll res = 0;
    while (x) res += x % 10, x /= 10;
    return res;
  };
  auto f = [&](ll n) {
    vector<ll> v;
    for (ll d = 1; d <= n; d *= 10) v.push_back((n / d + 1) * d - 1);
    sort(begin(v), end(v), greater<ll>());
    ll res = v.front();
    for (auto&& x : v) {
      if (S(res) * x > S(x) * res) break;
      res = x;
    }
    return res;
  };
  ll n = 0;
  while (K--) {
    n = f(n + 1);
    cout << n << endl;
  }
  return 0;
}


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

int main(){
  int N;
  long long x;
  cin >> N >> x;
  vector<long long> a(N);
  for(int i=0; i<N; i++) cin >> a.at(i);
  long long ans = 0;
  for(int i=0; i<N-1; i++){
    if(a.at(i)+a.at(i+1)>x){
      long long temp = a.at(i)+a.at(i+1)-x;
      ans+=temp;
      a.at(i+1)-=min(temp,a.at(i+1));
      
    }
  }
  cout << ans << endl;
}

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

int main() {

string s;
cin >> s;
vector<int> vec(s.size()+1);//1-indexed
rep(i,s.size())
{ char c =s.at(i);
  if(c=='A'||c=='C'||c=='G'||c=='T')
  {vec.at(i+1)=vec.at(i)+1;}
  else
  {vec.at(i+1)=0;}
}
int ans=0;
rep(i,s.size())
{
  ans=max(ans,vec.at(i+1));
}


printf("%d\n",ans);
return 0;

}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

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

int main(){
    long long  a,b,k;
    cin >> a >> b >> k ;
  
    long long a_ans,b_ans ;
    b_ans = b ;
    a_ans = a-k ;
   if(a_ans<0) a_ans = 0 ;
   if(k>a) b_ans = b-k+a ;
   if(b_ans<0) b_ans = 0;
 cout << a_ans << " " << b_ans << endl;

  return 0;
}

Measured memory_bytes: 256
import math
 
string = input().split(' ')
 
a = int(string[0])
b = int(string[1])
c = int(string[2])
 

if c< a + b:
  print('No')
  
elif (c - a - b) ** 2 - 4 * a * b > 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
c = float('inf')
N, K = map(int,input().split())
K-=1
t = tuple(sorted(int(input()) for i in range(N)))
for i in range(len(t)-K):
  b = t[i+K]-t[i]
  c = b if b<c else c
  if not c:
    break
print(c)

Measured memory_bytes: 7896
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>
#include <functional>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define PI 3.141592


using namespace std;

long double calc(long double xi, long double xj, long double yi, long double yj)
{
	return sqrtl( pow(xi - xj, 2) + pow(yi - yj, 2) );
}

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

	struct point
	{
	public:
		long double x;
		long double y;
	};
	vector<point> vNum(N);
	vector<int> vIndex(N);
	rep(i, N)
	{
		cin >> vNum[i].x >> vNum[i].y;
		vIndex[i] = i;
	}

	long double totalLength = 0;
	long double counter = 0;
	do {
		long double length = 0;
		for (auto i = vIndex.begin(); i != vIndex.end() - 1; ++i)
		{
			auto next = i + 1;
			length += calc(vNum[(*i)].x, vNum[(*next)].x, vNum[(*i)].y, vNum[(*next)].y);
		}
		totalLength += length;
		++counter;
	} while (next_permutation(vIndex.begin(), vIndex.end()));

	double tmp = totalLength / counter;
	printf("%lf", tmp);
}


Measured memory_bytes: 892
n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
if a[0] > m:
    count+= a[0] - m
    a[0] = m
for i in range(1, n):
  if a[i-1] + a[i] > m:
    count += a[i-1] + a[i] - m
    a[i] = m - a[i-1]
print(count)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int x[6];
    for(int i=1;i<=5;i++)
    {
        cin>>x[i];
    }
    if(x[1]==0)
    cout<<"1";
    else if(x[2]==0)
    cout<<"2";
    else if(x[3]==0)
    cout<<"3";
    else if(x[4]==0)
    cout<<"4";
    else if(x[5]==0)
    cout<<"5";
    return 0;
}

Measured memory_bytes: 3552
package main

import "fmt"

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

	answer := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			g := gcd(a, b)
			for c := 1; c <= k; c++ {
				answer += gcd(g, c)
			}
		}
	}
	fmt.Println(answer)
}

func gcd(n1 int, n2 int) int {
	if n1%n2 > 0 {
		return gcd(n2, n1%n2)
	}
	return n2
}


Measured memory_bytes: 1776
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
int a[200006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	int l = 0, r = 1e7;

	while (r - l > 1) {
		int mi = (l + r) / 2;
		stack<PP>st;
		st.push(PP(1, P(1, a[0])));
	
		for (int i = 1; i < n; i++) {
			PP t = st.top(); st.pop();
			int tn = t.first, tl = t.second.first, tr = t.second.second;

			if (a[i - 1] < a[i]) {
				if (tn == 1) {
					st.push(PP(1, P(tl, a[i])));
				}
				else {
					st.push(t);
					st.push(PP(1, P(tr+1, a[i])));
				}
			}
			else {
				while (tl > a[i]) {
					t = st.top();
					st.pop();
					tn = t.first, tl = t.second.first, tr = t.second.second;
				}
				if (tn != mi) {
					if(tl<=a[i]-1)st.push(PP(tn, P(tl, a[i] - 1)));

					if (st.size()&&st.top().first == tn+1) {
						PP nxt = st.top();
						nxt.second.second = a[i];
						st.pop(); st.push(nxt);
					}
					else st.push(PP(tn + 1, P(a[i],a[i])));
				}
				else {
					if (st.empty()) {
						l = mi; goto Z;
					}
					PP nxt = st.top(); st.pop();
					nxt.second.second--;
					if (nxt.second.first <= nxt.second.second)st.push(nxt);

					if (st.size() && st.top().first == nxt.first + 1) {
						PP nxt2 = st.top();
						nxt2.second.second++;
						st.pop();
						st.push(nxt2);
					}
					else st.push(PP(nxt.first + 1, P(nxt.second.second + 1, nxt.second.second + 1)));
					st.push(PP(1, P(tl, a[i])));
				}
			}
		}
		r = mi;
	Z:;
	}
	cout << r << endl;
}


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

T, A = input().split()

T = float(T)
A = float(A)


H = list(map(float,input().split()))
ans = 0
mini = -1

for i in range(N):

    tem = T - H[i] * 0.006

    if (mini < 0):

        mini = abs(tem - A)

    elif ( mini > abs(tem - A) ):

        #print ("地点", i ,"は ",abs(tem-A),"度で",mini,"より小さい" )
        mini = abs( tem - A )
        ans = i
        

print (ans + 1)

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

typedef long long ll;

const ll MOD = 1000000007;

int l[3005], r[3005];
ll ncr[3005][3005];
ll dp[3005][3005];
char buf[3005];
int cu[3005];
int n, m;

ll slv(int at, int ones)
{
	if (at == m) return 1;
	if (dp[at][ones]) return dp[at][ones];
	if (r[at] >= l[at+1])
	{
		int lim = min(l[at+1]-l[at], ones);
		for (int i = max(0, ones-r[at]+l[at+1]-1);i <= lim;i++)
		{
			dp[at][ones] += slv(at+1, ones-i+cu[r[at+1]]-cu[r[at]])*ncr[l[at+1]-l[at]][i];
			dp[at][ones] %= MOD;
		}
	} else
	{
		dp[at][ones] = ncr[r[at]-l[at]+1][ones] * slv(at+1, cu[r[at+1]]-cu[l[at+1]-1]);
		dp[at][ones] %= MOD;
	}
	return dp[at][ones];
}

int main()
{
	ncr[0][0] = 1;
	for (int i = 1;i < 3005;i++)
	{
		ncr[i][0] = 1;
		for (int j = 1;j <= i;j++) ncr[i][j] = (ncr[i-1][j-1] + ncr[i-1][j]) % MOD;
	}
	scanf("%d%d%s", &n, &m, buf);
	for (int i = 0;i < m;i++) scanf("%d%d", l+i, r+i), --l[i], --r[i];
	for (int i = 1;i < m;i++) r[i] = max(r[i], r[i-1]);
	for (int i = 0;i < n;i++) cu[i] = buf[i]-'0';
	for (int i = 1;i < n;i++) cu[i] += cu[i-1];
	l[m] = r[m] = n;
	printf("%lld\n", slv(0, cu[r[0]]-(l[0]?cu[l[0]-1]:0)));
	return 0;
}


Measured memory_bytes: 59264
#include <bits/stdc++.h>
using namespace std;
#define X ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


long long p = 1e9+7;
typedef pair<int, int> pi;
typedef unordered_map<int, int> UMP;
typedef long long ll;
typedef vector<ll> VI;
#define FOR(i,b) for(i=0;i<b;i++)
#define pb push_back


void printa(VI x,ll n){
    ll i;
    FOR(i, n){
        cout<<x[i]<<" ";
    }
    cout<<endl;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
    #endif
    long double a,b;
    ll c;
    cin>>a>>b;
    b = round(b*100);
    c = a*b;
    ll d = c/100;
    cout<<d<<endl;
}

// 2017634310362021

Measured memory_bytes: 3796
#modの掛け算
 
def modmal(a,b,mod): #a*bをmodを法にして求める
 
    return a * b % mod
 
 
#modの割り算
 
def moddiv(a,b,mod): #a/bをmodを法にして求める
 
    return (a * pow(b,mod-2)) % mod
 
 
#逆元
 
def inverse(a,mod): #aのmodを法にした逆元を返す
    return pow(a,mod-2)
 
 
 
#modのn!と、n!の逆元を格納したリストを返す(拾いもの)
#factorialsには[1, 1!%mod , 2!%mod , 6!%mod… , n!%mod] が入っている
#invsには↑の逆元が入っている
 
def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs
 
 
def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし
 
    return fac[n] * inv[n-r] * inv[r] % mod


H,W,A,B = map(int,input().split())

mod = 10 ** 9 + 7
ans = 0

fac,inv = modfac(H+W,mod)

for i in range(H-A):

    now = modnCr(i + B-1, i,mod,fac,inv)
    now *= modnCr(H+W-i-B-2,W-B-1,mod,fac,inv)

    ans += now
    ans %= mod

print (ans)


Measured memory_bytes: 54128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

ll count(ll left, ll right, ll under, ll up, vector<pair<ll, ll>> &v) {
    if (left > right | under > up) {
        return 0;
    }
    ll ans = 0;
    rep(i, v.size()) {
        if (left <= v[i].first && v[i].first <= right) {
            if (under <= v[i].second && v[i].second <= up) {
                ans++;
            }
        }
    }
    return ans;
}

int main() {
source:
    ll n, k;
    cin >> n >> k;

    vector<pair<ll, ll>> v(n);
    ll x[n], y[n];
    rep(i, n) {
        cin >> x[i] >> y[i];
        v[i] = make_pair(x[i], y[i]);
    }

    sort(x, x + n);
    sort(y, y + n);

    ll ans = -1;

    rep(l0, n) {
        repd(l1, l0, n) {
            rep(l2, n) {
                repd(l3, l2, n) {
                    ll num = count(x[l0], x[l1], y[l2], y[l3], v);
                    ll size = abs(x[l1] - x[l0]) * abs(y[l3] - y[l2]);
                    if (num >= k && (size < ans | ans == -1)) {
                        ans = size;
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}



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

#define all(v)  begin(v), end(v)
#define endl    '\n';
#define int     long long
#define pii     pair<int, int>
#define sz(x)   (int) x.size()

void test_case() {
    string s;
    cin >> s;

    int x = 0;
    for (auto ch : s) {
        int d = ch - '0';
        x += d;
        x %= 9;
    }

    cout << (x ? "No" : "Yes") << endl;
}

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

    int t = 1;
    // cin >> t;

    while (t--) { 
        test_case();
    }
    return 0;
}


Measured memory_bytes: 3728
n=int(input())
h=list(map(int,input().split()))
for i in reversed(range(1,n)):
  if h[i] - h[i-1] >=0:
    continue
  elif h[i] - h[i-1] == -1:
    h[i-1]-=1
  else:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 14396
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInteger

readIntList = map readInt . BS.words

main = do
  n <- readLn
  [as, bs] <- transpose . map readIntList <$> replicateM n BS.getLine
  print $ solve n (sort as) (sort bs)

solve :: Int -> [Integer] -> [Integer] -> Integer
solve n as bs
  | odd n = bs !! div n 2 - as !! div n 2 + 1
  | otherwise = bs !! div n 2 + bs !! div (n - 1) 2 - as !! div n 2 - as !! div (n - 1) 2 + 1

Measured memory_bytes: 115360
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll X;
    cin >> X;
    ll A = 1000ll * 1000ll * 1000ll * 1000ll;
    //cout << A << endl;
    for (ll i = -1000; i <= 1000; ++i) {
        for (int j = -1000; j <= 1000; ++j) {
            ll a = j - i;
            ll b = j * j * j * j
                    + j * j * j * i
                    + j * j * i * i
                    +j * i * i * i
                    + i * i * i * i;
            if(a * b == X){
                cout << j << " " << i << endl;
                return 0;
            }
        }
    }
}


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

using namespace std;

int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); ++i){
        if(i % 2 == 0) {
            if(s[i] == 'L'){ 
             	cout << "No";
            	return 0;
        	}
        }
        else if (s[i] == 'R'){ 
          cout << "No";
          return 0;
        }
    }
    cout << "Yes";
 }







Measured memory_bytes: 256
// Please run with node.js
// $ node p1.js < input.txt
// tested on node version 0.10.36
var fs = require("fs");
var input = fs.readFileSync('/dev/stdin').toString();
var numbers = input.split("\n").map(Number);
numbers = numbers.sort(function(a, b) { return b - a });
for(var i = 0; i < 3; i++) {
    if(i < numbers.length) {
        console.log(numbers[i]);
    }
}

Measured memory_bytes: 15524
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
using namespace std;

int main() {
    int i,j,p,q,temp;
    int k;
    double n;
    int count=0;

    double kakuritsu=0.000000000;
    double pro;
    string s;
    cin>>n>>k;
    double t=n;
    for(i=1; i<=n; ++i){
        temp=i;
        while(temp<k){
            temp=temp*2;
            ++count;
        }
        for(j=0; j<count; ++j){
            t=t*2;
        }
        kakuritsu=kakuritsu+1/t;
        t=n;
        count=0;
    }
    cout<<fixed<<setprecision(12)<<kakuritsu;
    return 0;
}

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

int main(){
    ll a , v , b , w , t;
    cin >> a >> v >> b >> w >> t;
    ll s = abs(a - b);
    ll g = (v - w) * t;
    if(s <= g){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;


int main(){
    int a,b;
    cin >> a >> b;
    if(a<10&&b<10)
        cout << a*b << endl;
    else
        cout << -1 << endl;
	return 0;   
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <algorithm>
#include <vector>
int n, m;
int t[100000];
int s[100000];
int ho[100000];
int ans[100000];
int k[100000];
int e, f;
std::vector<int> g[100000];
std::vector<int> h[100000];
void dfs(int a, int b, int c) {
	if (b > ho[a]) {
		ho[a] = b;
		ans[a] = c;
	}
	s[a]++;
	if (s[a] < h[a].size()) {
		return;
	}
	for (int i = 0; i < g[a].size(); i++) {
		dfs(g[a][i], ho[a] + 1, a);
	}
	return;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n + m - 1; i++) {
		scanf("%d%d", &e, &f);
		e--; f--;
		g[e].push_back(f);
		h[f].push_back(e);
		k[f]++;
	}
	for (int i = 0; i < n; i++) {
		if (k[i] == 0) {
			dfs(i, 0, -1);
			ans[i] = -1;
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d\n", ans[i] + 1);
	}
	return 0;
}

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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if (A+B>C+D) {
    cout<<"Left"<<endl;
  }
  else if (A+B==C+D) {
    cout<<"Balanced"<<endl;
  }
  else {
    cout<<"Right"<<endl;
  }
  
}



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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;

  if(k < u->key) return treeSearch(u->left, k);
  else return treeSearch(u->right, k);
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
    z->parent = y;

    if(y==NIL) root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;
  


}

void inorder(Node u){
  if(u!=NIL){
  inorder(u->left);
  printf(" %d",u->key);  
  inorder(u->right);
  }
  else return;
}
void preorder(Node u){
  if(u!=NIL){
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
  }
  else return;
}


int main(){
  int n,i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19360
using System;
using System.Collections.Generic;
using System.Linq;

namespace Program {
    class Program {
        static void Main(string[] args) {
            var cr = new CR();

            var A = cr.i;
            var B = cr.i;
            var C = cr.i;

            var ans = Math.Min(C, (A + B) + 1) + B;

            Console.WriteLine(ans);
        }

        private class CR {
            System.IO.TextReader _r;
            Queue<string> _d;
            public CR() { _r = Console.In; _d = new Queue<string>(); }
            string Read() {
                while (_d.Count == 0)
                    foreach (var v in _r.ReadLine().Split(' '))
                        if (v != "")_d.Enqueue(v);
                return _d.Dequeue();
            }
            public int i { get { return int.Parse(Read()); } }
            public string s { get { return Read(); } }
        }
    }
}

Measured memory_bytes: 13268
import sys
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

j = 0
Ta = 1e5 + 1
for i in range(N):
    Tm = T - H[i] * 0.006
    Tb = abs(Tm - A)
    if Ta > Tb:
        Ta = Tb
        j = i
print(j + 1)

Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
template <typename CT, typename T> inline void reset_container(CT &c, int sz, T v){c.resize(sz); for(auto &x: c) x=v;}
#define taskname "agc026_e"
string s;
vector <int> pa;
vector <int> pb;
int n;
vector <string> res;
void solve(int i, int j){
    if(pa[i]<pb[i]){
        ///ababababababab
        string r="";
        int nx=0;
        FOR(k, i, j) if(pa[k]>=nx){
            r+="ab";
            nx=pb[k];
        }
        res.pb(r);
    }
    else{
        string r="";
        FOR(k, i, j){
            string t="";
            int a=k;
            int b=k;
            while((a<=j)&&(b<=j)){
                if(pa[a]<pb[b]){
                    t+='a';
                    a++;
                }
                else{
                    t+='b';
                    b++;
                }
            }
            while(a<=j){
                t+='a';
                a++;
            }
            while(b<=j){
                t+='b';
                b++;
            }
            r=max(r, t);
        }
        res.pb(r);
    }
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    cin>>n>>s;
    FFOR(i, 0, s.size()) if(s[i]=='a') pa.pb(i); else pb.pb(i);
    FFOR(i, 0, n){
        int start=min(pa[i], pb[i]);
        int mx=0;
        FFOR(j, i, n){
            mx=max(mx, pa[j]);
            mx=max(mx, pb[j]);
            if((mx-start+1)==(j-i+1)*2){
                solve(i, j);
                i=j;
                break;
            }
        }
    }
    string ans="";
    reverse(res.begin(), res.end());
    for(auto s: res) ans=max(ans, s+ans);
    cout<<ans<<'\n';
}

Measured memory_bytes: 512
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
//#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
vector<set<int> >adj(100005);
int vis[100005];
void init(){
    for(int i=0;i<(adj.size());i++){
        adj[i].clear();
    }
    for(int i=0;i<100005;i++){
        vis[i]=-1;
    }
}
void bfs(int u){
    queue<int>q;
    q.push(u);
    vis[u]=0;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        set<int>st=adj[u];
        for(auto it=st.begin();it!=st.end();it++){
            int v=(*it);

            if(vis[v]==-1){
              //  cout << v << " ";
                vis[v]=u;
                q.push(v);
            }
        }
       // cout << endl;
    }
}
signed main()
{
    IOS
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ac=a*c;
    int ad=a*d;
    int bd=b*d;
    int bc=b*c;
    cout << max(ac,max(ad,max(bd,bc)))<<endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 7792
#include<stdio.h>
#define MAX 1000000
int Partition(int *,int,int);

int A[MAX],key;
main(){
  int n,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
    
  }
  
  key = Partition(A,0,n);
  
  
  for(i = 1; i < key; i++){ 
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[key]);
  for(i = key+1;i<=n;i++){
    if(i == n){
      printf("%d\n",A[n]);
    }else{
      printf("%d ",A[i]);
    }
  }
  
  return 0;
}

int Partition(int *A,int p,int r){  
  int i,j,x,tmp;
  x = A[r];
  i = p-1;
  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[r];
  A[r] = A[i+1];
  A[i+1] = tmp;
  
  
  return i+1;
  
}

Measured memory_bytes: 988
N=int(input())
A=list(map(int, input().split()))
cnt=0
flg=1
while flg:
  flg=0
  for i in range(1,N)[::-1]:
    if A[i] < A[i-1]:
      _=A[i]
      A[i]=A[i-1]
      A[i-1]=_
      flg=1
      cnt+=1
print(*A)
print(cnt)


Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <utility>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef pair<int,int> pii;
int main(){
    int a,b;
    char s;
    cin >> a >> s >> b;
    if(s=='+')cout << a+b << endl;
    else cout << a-b << endl;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  ll n,m; cin>>n>>m;
  
  if(n==m&&n==1){
    cout<<1<<endl;
    return 0;
  }
  
  if(n==1||m==1){
    cout<<max(n,m)-2<<endl;
    return 0;
  }
  
  ll ans=(n-2)*(m-2);
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<unordered_set>
using namespace std;
const int MAX = 100;

int main() {
	int N, K;
	int ans = 0;

	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int y;
		cin >> y;
		ans += min(y, abs(y - K));
	}

	cout << ans * 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(9);
  int n;
  cin>>n;
  int odd;
  odd=n/2;
  if(n%2==1) odd++;
  cout<<(double)odd/n<<endl;

  return 0;
}


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

int main(){
  int N;
  cin>>N;
  char c;
  vector <char> all;
  for(int i=0;i<N;i++){
    cin>>c;
    if(i==0)all.push_back(c);
    else{
      for(int j=0;j<all.size();j++){
        if(all[j]==c)break;
        if(j==all.size()-1)all.push_back(c);
      }
    }
  }

  if(all.size()==3)cout<<"Three";
  else cout<<"Four";
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a,b;
    char op;

    while(1)
    {
     scanf("%d %c %d", &a,&op,&b);
     if(op=='+')printf("%d\n",a+b);
     if(op=='-')printf("%d\n",a-b);
     if(op=='*')printf("%d\n",a*b);
     if(op=='/')printf("%d\n",a/b);
     if(op=='?')break;
    }
    return 0;
}



Measured memory_bytes: 2044
'use strict'
const inputs = require('fs').readFileSync(0, 'utf8').split('\n')
inputs.shift()
const tasks = []
for (const input of inputs) {
  const ab = input.split(' ')
  if (ab.length === 2) tasks.push({a: ab[0], b: parseInt(ab[1], 10)})
}
tasks.sort(function(x, y) {return x.b - y.b})
let time = 0
for (const task of tasks) {
  time += parseInt(task.a, 10)
  if (time > task.b) return console.log('No')
}
return console.log('Yes')

Measured memory_bytes: 70560
#include <stdio.h>

int main(){
    int cnt=0;
    int a,b,c,i;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if(c%i==0){
            cnt++;
        }
    }
    printf("%d\n",cnt);
}

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

// A*B = Nを満たしながら動くとき、A、Bの内、桁数が大きい物の最小値を求めよ。

long long int_len(long long N){
    // int型の桁数を返す関数
    string S = to_string(N);
    return S.size();
}

int main(){
    long long N;
    cin >> N;
    long long i = 1;
    long long ans = 10000;
    while (pow(i,2) <= N){
        // A,B対称なのでO(sqrt(N))の計算
        long long j = N / i;
        long long tmp;
        if (i*j == N){
            tmp = max(int_len(i), int_len(j));
        }
        ans = min(ans, tmp);
        i += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3760
from math import *
n=int(input())
a=[int(x) for x in input().split()]

f=[]
for i in range(n):
	f.append(0)
for i in range(n):
	if a[i]<n and (i+1)>a[i]:
		f[(i+1)-a[i]]+=1

#print(f)
ans=0
for i in range(n):
	#print(a[i]+i+1)
	if a[i]+i+1<n:
		ans+=f[a[i]+(i+1)]
print(ans)

Measured memory_bytes: 33472
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int sl = S.length();
		int[] t = new int[sl];

		for(int i = 0;i<sl;i++) {
			t[i] = Integer.parseInt(S.substring(i,i+1));
		}
		int c = 0;
		for(int i = 0;i<sl;i++) {
			if(i%2==1||i==1) { //奇数なら
				if(t[i]==1) {
					c++;
				}
			}else {
				if(t[i]==0) {
					c++;
				}
			}
		}
		int ans;
		if(c > sl/2) {
			ans = sl-c;
		}else {
			ans = c;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 32032
n=int(input())
a=[0]*(n+1)
ans=1
for i in range(2,n+1):
    x=i
    p=2
    while x>1:
        while x%p==0:
            a[p]+=1
            x//=p
        p+=1
for i in a:
    ans=(ans*(i+1))%(10**9+7)
print(ans)


Measured memory_bytes: 3060