akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

int a,b;
char grid[100][100];

void func(){
  for(int i=0;i<49;i+=2){
      for(int j=0;j<100;j+=2){
        grid[i][j]='#';
        b--;
        if(b==0)return;
      }
    }
}

void func2(){
  for(int i=50;i<100;i+=2){
      for(int j=0;j<100;j+=2){
        grid[i][j]='.';
        a--;
        if(a==0)return;
      }
    }
}

void solve(){
    cin>>a>>b;
    a--;b--;
    rep(i,49){
      rep(j,100){
        grid[i][j]='.';
      }
    }
    rep(i,51){
      rep(j,100){
        grid[i+49][j]='#';
      }
    }
    if(b)func();
    if(a)func2();
    cout<<100<<" "<<100<<"\n";
    rep(i,100){
      rep(j,100)cout<<grid[i][j];
      cout<<"\n";
    }
}
 
int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


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

int main(void) {
    constexpr long mod = 1e9+7;
    int n;
    cin >> n;

    vector<string> domino(2);
    cin >> domino[0];
    cin >> domino[1];

    vector<long> dp(n);
    if(domino[0][0] == domino[1][0])
        dp[0] = 3;
    else
        dp[0] = 6;
    for(int i=0; i<n-1; i++) {
        bool b0 = domino[0][i] == domino[0][i+1];
        bool b1 = domino[0][i] == domino[1][i];
        bool b2 = domino[0][i+1] == domino[1][i+1];

        if(b0) {
            dp[i+1] = dp[i];
            continue;
        }

        if(b1) {
            if(b2)
                dp[i+1] = dp[i] * 2 % mod;
            else
                dp[i+1] = dp[i] * 2 % mod;
        } else {
            if(b2)
                dp[i+1] = dp[i] * 1 % mod;
            else
                dp[i+1] = dp[i] * 3 % mod;
        }
    }

    cout << dp[n-1] << endl;
}


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

int main(){
  vector<int> p;
  vector<int> j;
  int tmp;
  while(cin >> tmp){
    p.push_back(tmp);
    for(int i=0; i<2; ++i){
      cin >> tmp;
      p.push_back(tmp);
    }

    for(int i=0; i<2; ++i){
      cin >> tmp;
      j.push_back(tmp);
    }
    sort(p.begin(),p.end());
    sort(j.begin(),j.end());
    int ans = p[0] + j[0]-50;
    cout << ans  << endl;
  }
}



Measured memory_bytes: 3152
#include <stdio.h>
int main(){

  int n,m,now,ud[1000],sai[1000],i,j;

  while(1){
  scanf("%d %d",&n,&m);
  if(n == 0) break;

  now=0;
  for(i = 0; i < n; i++) scanf("%d",&ud[i]);
  for(i = 0; i < m; i++) scanf("%d",&sai[i]);

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

    now += sai[i];

    if(now >= n-1) break;

    now += ud[now];

    if(now >= n-1) break;

  }

  printf("%d\n",i+1);

  }

  return 0;

}

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

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout << setprecision(20) << 3.14159 * n * 2 << endl;
    return 0;
}


Measured memory_bytes: 3796
#include<bits/stdc++.h>
#include<climits>
using namespace std;
int main()
{
     long long int n,i,flag=0;
    cin>>n;
   long long int ar[n];
    for(i=0;i<n;i++)
        cin>>ar[i];
        long long int mi=0;
    for(i=0;i<n-1;i++)
    {
        if(ar[i]>=ar[i+1])
            {
            flag++;
            }
        else if(ar[i]<ar[i+1])
        {
            flag=0;
        }
        if(mi<flag)
        {
            mi=flag;
        }
    }
    cout<<mi<<endl;
}

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

using namespace std;

long long MOD = 1e9 + 7;

int main() {
    long long n, k;
    cin >> n >> k;

    long long ans = 1;
    for (long long i = k; i > k - n; --i) {
        ans = (ans * i + MOD) % MOD;
    }

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


Measured memory_bytes: 3120
#include <stdio.h>
int main(void)
{
	int S, h, m, s, a, b;
	scanf("%d",&S);
	h = S / 3600;
	a = S - (h * 3600);
	m = a / 60;
	s = a - (m * 60);
	printf("%d:%d:%d\n",h, m, s);
	return 0;
}

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

int main() {
	long long n,i,j,q,query,r,t,f,ans1,ans2;
	string s;
	char c;
	cin >> s >> query;
	n=s.size()+400000;
	vector<char> ans(n);
	for(i=0; i<s.size(); i++){
		ans[i+200000]=s[i];
	}
	
	ans1=200000; ans2=200000+s.size()-1;
	r=0;
	for(q=0; q<query; q++){
		cin >> t;
		if(t==1){
			r=(r+1)%2;
		}else{
			cin >> f >> c;
			if((f+r)%2){
				ans1--; ans[ans1]=c;
			}else{
				ans2++; ans[ans2]=c;
			}
		}
	}
	if(r==0){
		for(i=ans1; i<=ans2; i++){
			cout << ans[i];
		}
	}else{
		for(i=ans2; i>=ans1; i--){
			cout << ans[i];
		}
	}
}

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





int main() {
  int n,k;
  cin>>n>>k;
  
  int answer=1;
  for (int i=0;i<n;i++){
    if (answer>k){
      answer+=k;
    }
    else {
      answer*=2;
    }
  }

  cout<<answer<<endl;
  

}

  













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

int main() {
    int n;
    int a[110];  // 最大 100 個ですが余裕をもたせます
    int A = 0;
    int B = 0;
    cin >> n;
    rep(i,n){
      cin >> a[i];
    }
    sort(a, a + n, greater<int>());  // a[0:N] を大きい順にソート
    rep(i,n){
        if (i % 2 == 0) A += a[i];
        else B += a[i];
    }
    cout << A - B << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n; scanf("%d",&n);
	int ary[n+1]; for (int i=1; i<=n; i++) { scanf("%d",&ary[i]); }
	
	int bry[n+1];
	int s = 0;
	for (int i=n; i>0; i--) {
		int k = 2;
		int sum = 0;
		while ((k*i) <= n) {
			sum += bry[k*i];
			k++;
		}
		if ((sum % 2) == ary[i]) {
			bry[i] = 0;
		} else {
			bry[i] = 1;
			s++;
		}
	}
	printf("%d\n",s);
	for (int i=1; i<=n; i++) {
		if (bry[i] == 1) {
			printf("%d ",i);
		}
	}
	
    return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>

using namespace std;

const int MAX_N = 50;

int N;

double v[MAX_N+1];

void solve() {
    sort(v, v+N);
    double ans = (double)v[0];
    for (int i=1; i<N; i++) {
        ans = (double)((ans + v[i])/2.0);
    }
    cout << ans << endl;
}

int main() {
    cin >> N;
    for(int i=0; i < N; i++) {
        cin >> v[i];
    }
    solve();
}

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

bool isPrime(int n)
{
    for (int i = 2; i <= n / 2; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    while (!isPrime(n))
    {
        n++;
    }
    cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3+5;
int x,y,n,mid,k,d,ans[maxn];

int main(){
	cin >> n >> x >> y;
	mid = (x+y) >> 1;
	for (int i=1;i<n;i++){
		for (int j=i+1;j<=n;j++){
			d = min(j-i,abs(i-x)+1+abs(j-y));
			ans[d] ++;
		}
	}
	for (int i=1;i<=n-1;i++){
		cout << ans[i] << endl;	
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}

int n,k;
vi a,f;

bool g(int m){
  int s=k;
  rep(i,n){
    int t=a[i]*f[n-i-1];
   
    if(t>m){
      t=t-m;
      s-=((t+f[n-i-1]-1)/f[n-i-1]);
    }
    //cout<<s<<endl;
  }

  //cout<<m<<' '<<s<<endl;

  return s>=0;
}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  
  cin>>n>>k;
  a = vi(n);
  f = vi(n);
  rep(i,n){
    cin>>a[i];
  }
  rep(i,n){
    cin>>f[i];
  }
  sort(all(a));
  sort(all(f));
  
  int l=-1,r=-1;

  rep(i,n){
    r=max(r,a[i]*f[n-i-1]);
  }
  

  while(r-l>1){
    int m=(r+l)/2;
    if(g(m)) r=m;
    else l=m;
  }

  cout<<r<<endl;
}

Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            int[] v = new int[N];
            for (int i = 0; i < N; i++)
            {
                v[i] = int.Parse(s[i]);
            }

            int[] a = new int[N];

            int ind = N / 2;
            a[ind] = v[0];

            int dir;
            if (0 == N % 2)
            {
                dir = -1;
            }
            else
            {
                dir = 1;
            }


            for (int i = 1; i < N; i++)
            {
                a[ind + dir] = v[i];

                dir *= -1;
                if (i != 1 && 0 == (i % 2))
                {
                    dir = Math.Sign(dir) * (Math.Abs(dir) + 1);
                }
            }

            for (int i = 0; i < N; i++)
            {
                Console.Write("{0} ", a[i]);
            }

            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 36652
#include <iostream>

using namespace std;

int main(void) {
  int A, B, plus, minus, multiple;
  cin >> A >> B;
  
  plus = A + B;
  minus = A - B;
  multiple = A*B;
  
  if(plus >= minus && plus >= multiple) {
    cout << plus << endl;
  } else if(minus >= plus && minus >= multiple) {
    cout << minus << endl;
  } else if(multiple >= plus && multiple >= minus) {
    cout << multiple << endl;
  }
  
  return 0;
}


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

using namespace std;
using ll = long long;
const int maxn = 3005;
ll dp[maxn][maxn][4];
int good[maxn][maxn];
int main() {
#ifdef LOCAL
    freopen("in1.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif

    ll r, c, k;
    cin >> r >> c >> k;
    for(int i = 0; i < k; i++){
        ll x, y, z;
        cin >> x >> y >> z;
        good[x][y] = z;
    }
    for(int j = r; j >= 1; j--){
        for(int q = c; q >= 1; q--){
            for(int i = 3; i >= 0; i--){
                if(i > 0 and good[j][q] > 0){
                    dp[j][q][i] = max(dp[j+1][q][3] , dp[j][q+1][i-1]) + good[j][q];
                    dp[j][q][i] = max(dp[j][q][i] , dp[j+1][q][3]);
                    dp[j][q][i] = max(dp[j][q][i] , dp[j][q+1][i]);
                }
                else {
                    dp[j][q][i] = max(dp[j+1][q][3] , dp[j][q+1][i]);
                }
            }
        }
    }
    ll ans = dp[1][1][3];
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 320428
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
  int a, b, c, d, e;
  scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
  printf("%d\n",(d-min(d,e))*min(a,c+c)+(e-min(d,e))*min(b,c+c)+min(d,e)*min(a+b,c+c));
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void solve(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	int sum=0,sua=0;
	sort(a,a+n);
	reverse(a,a+n);
	rep(i,n){
		if(i%2==0)sum+=a[i];
		else sum-=a[i];
	}
	cout<<sum;
}

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

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    char c;
    cin>>c;
    if (islower(c)){
        cout<<'a';
    }
    else cout<<'A';
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 3448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;

int N, M;
vector<int> G[1010];
vector<int> X[1010];

int calc(int a){
	vector<int> d(N);
	fill(d.begin(), d.end(), INF);
	queue<int> que;
	d[a] = 0;
	que.push(a);
	while(que.size()){
		int x = que.front(); que.pop();
		for(int i=0; i<G[x].size(); i++){
			int next = G[x][i];
			if(next == a) return d[x] + 1;
			if(d[next] == INF){
				d[next] = d[x] + 1;
				que.push(next);
			}
		}
	}
	return -1;
}

int main(){
	cin >> N >> M;
	int ans[N+1];
	for(int i=1; i<=N; i++) ans[i] = INF;
	for(int i=0; i<M; i++){
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		X[b].push_back(a);
	}
	int mi = INF, mi_index = -1;
	for(int i=0; i<N; i++){
		int len = calc(i);
		if(len != -1 && len < mi){
			mi = len;
			mi_index = i;
		}
	}
	if(mi == INF) cout << -1 << endl;
	else{
		vector<int> d(N);
		fill(d.begin(), d.end(), INF);
		queue<int> que;
		d[mi_index] = 0;
		que.push(mi_index);
		int f = 0;
		while(que.size()){
			int x = que.front(); que.pop();
			for(int i=0; i<G[x].size(); i++){
				int next = G[x][i];
				if(next == mi_index){
					f = 1;
					break;
				}
				if(d[next] == INF){
					d[next] = d[x] + 1;
					que.push(next);
				}
			}
			if(f) break;
		}
		int now = mi_index;
		cout << mi << endl;
		for(int i=0; i<mi; i++){
			for(int j=0; j<X[now].size(); j++){
				if(mi == d[X[now][j]] + i + 1){
					now = X[now][j];
					cout << now + 1 << endl;
					break;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func Min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M := nextInt(), nextInt()
	H := make([]int, N)
	maxs := make([]int, N)
	for i := 0; i < N; i++ {
		H[i] = nextInt()
	}
	for i := 0; i < M; i++ {
		a := nextInt() - 1
		b := nextInt() - 1
		maxs[a] = Max(maxs[a], H[b])
		maxs[b] = Max(H[a], maxs[b])
	}

	ans := 0

	//fmt.Println(maxs, H)
	for i := 0; i < N; i++ {
		if maxs[i] == 0 {
			ans++
			continue
		} else {
			if maxs[i] < H[i] {
				ans++
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5832
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<random>
#include<stdio.h>
using namespace std;

typedef long long ll;

long long Mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    for (ll i=0;i<N;i++){
        cin>>A[i];
    }

    ll mod=998244353;

    vector<ll> inverse={0,1};
    for (long int i=2;i<1000000+1;i++){
        inverse.push_back(Mod(-inverse[mod%i]*(mod/i),mod));
    }

    vector<ll> data(1000001);
    vector<ll> data2(1000001);
    for (long int i=0;i<N;i++){
        data[A[i]]=Mod(data[A[i]]+A[i],mod);
        data2[A[i]]=Mod(data2[A[i]]+A[i]*A[i],mod);
    }

    for (ll i=1;i<1000000+1;i++){
        for (ll j=2;j<1000000/i+1;j++){
            data[i]=Mod(data[i]+data[i*j],mod);
            data2[i]=Mod(data2[i]+data2[i*j],mod);
        }
    }


    vector<ll> ans(1000001);
    for (ll i=1000000;i>0;i--){
        for (ll j=1;j<1000000/i+1;j++){
            ans[i]=Mod(ans[i]-ans[i*j],mod);
        }
        ll plus=Mod((data[i]*data[i]-data2[i]),mod);
        plus=Mod(plus*inverse[2],mod);
        ans[i]=Mod(ans[i]+plus,mod);
    }

    ll res=0;
    for (ll i=1;i<1000001;i++){
        res=Mod(res+inverse[i]*ans[i],mod);
    }
    cout<<res<<endl;

}

Measured memory_bytes: 35304
program main
implicit none
integer :: a, b, c

read(*,*) a, b, c
if( a==5 ) then
   if( b== 5 ) then
      if( c == 7 ) then
         write(*,*) 'YES'
         stop
      end if
   else if( b == 7 ) then
      if ( c== 5 ) then
         write(*,*) 'YES'
         stop
      end if
   end if
else if( a== 7 ) then
   if( b==5.and.c==5 ) then
      write(*,*) 'YES'
      stop
   end if
end if
write(*,*) 'NO'


end program main


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
//26

int a[1000][1000], f[1000];
vector<int> G[1000];
signed main(){
	int n, m;
	scanf("%lld%lld", &n, &m);
	rep(i,n)a[i][i] = 1;
	rep(i,m){
		int x, y;
		scanf("%lld%lld", &x, &y);x--;y--;
		a[x][y] = a[y][x] = 1;
	}
	rep(i,n)rep(j,n)if(a[i][j] == 0)G[i].pb(j);
	
	int flag = 0;
	queue<P> q;
	vector<P> S;
	fill(f, f+1000, -1);
	rep(i,n){
		if(f[i] >= 0)continue;
		int color[2] = {0};
		q.push(P(i, 0));
		while(!q.empty()){
			P p = q.front();q.pop();
			int v = p.fi, c = p.se;
			if(f[v] >= 0){
				if(f[v] != c){flag = 1;break;}
				else continue;
			}
			f[v] = c;color[c]++;
			for(int to: G[v]){
				q.push(P(to, !c));
			}
		}
		S.push_back(P(color[0], color[1]));
	}
	if(flag == 1){printf("-1\n");return 0;}
	
	int size = S.size();
	vector<int> dp(1000), nxt(1000);
	dp[0] = 1;
	rep(i,size){
		nxt = vector<int>(1000, 0);
		drep(j,999,1){
			//if(S[i].fi and S[i].se)dp[j] = 0;
			int x = j-S[i].fi, y = j-S[i].se;
			if(x >= 0 and dp[x])nxt[j] = 1;
			if(y >= 0 and dp[y])nxt[j] = 1;
		}
		swap(dp, nxt);
	}
	
	int ans = INF;
	rep(i,998)if(dp[i]){
		int x = i, y = n-i;
		chmin(ans, (x-1)*x/2+(y-1)*y/2);
	}
	printf("%lld\n", ans);
	return 0;
}





Measured memory_bytes: 18960
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str = Console.ReadLine ().Split (' ');
            var N = long.Parse (str[0]);
            var Y = long.Parse (str[1]);

            for (int i = 0; i < (N + 1); i++)
            {
                for (int j = (i + 1); j < (N + 2); j++)
                {
                    var total = 10000 * i + 5000 * (j - i - 1) + 1000 * (N + 1 - j);
                    if (total == Y)
                    {
                        Console.WriteLine (i + " " + (j - i - 1) + " " + (N + 1 - j));
                        return;
                    }
                }
            }
            Console.WriteLine (-1 + " " + -1 + " " + -1);
        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
 
void solve()
{
  int n;
    cin>>n;
  double dp[n+1][n+1];
  double prob[n];
    for(int i=0;i<n;i++)
        cin>>prob[i];
  
  dp[0][0]=1;
  for(int i=1;i<=n;i++)
  {
    dp[i][0]=(1-prob[i-1])*dp[i-1][0];
    dp[0][i]=0;
  }
  
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
       dp[i][j]=prob[i-1]*(dp[i-1][j-1]);
       dp[i][j]+=(1-prob[i-1])*(dp[i-1][j]);
       
    }
  double ans=0;
  for(int i=n/2+1;i<=n;i++)
    ans+=dp[n][i];
    
    //ans=ceil(ans*1000000000.0)/1000000000.0;
    cout<<setprecision(9)<<fixed;
    cout<<ans<<endl;
    
// printf("%.9f\n", ans);
 
 
 
}
 
int32_t main()
{
    
    int t;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 74056
function main(input) {
    const args = input.split(' ');
    const Stones = args[0].toString();

    var count_B = 0;
    var ans = 0;

    for(var i = 0; i < Stones.length - 1; i++) {
        if (Stones.charAt(i) === 'B') {
            count_B++;
        }
        else {
            ans += count_B;
        }
    }

    console.log(ans);

}

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


Measured memory_bytes: 22332
#include <bits/stdc++.h>
using namespace std;
int main (){
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=0;i<100000;i++){
		if(((b*i)+c)%a==0){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

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

#define y1 dmytxdy
#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
int x[1005],y[1005];

ll dist(ll x1,ll y1,ll x2,ll y2){return fabs(x2-x1)+fabs(y2-y1);}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) x[i]=readint(),y[i]=readint();
	int fl=-1;
	for(int i=1;i<=n;i++){
		if(fl<0) fl=(x[i]+y[i])&1;
		else if(fl!=((x[i]+y[i])&1)) return printf("-1\n"),0;
	}
	if(fl==0){
		printf("32\n");
		printf("1 ");
		for(int i=0;i<31;i++) printf("%lld ",1ll<<i);
		printf("\n");
		for(int i=1;i<=n;i++){
			printf("U");
			ll nx=0,ny=1;
			vector<char> ans(0);
			for(int j=30;j>=0;j--){
				ll mina=1ll<<60;
				char opt;
				if(chkmin(mina,dist(nx+(1<<j),ny,x[i],y[i]))) opt='R';
				if(chkmin(mina,dist(nx,ny+(1<<j),x[i],y[i]))) opt='U';
				if(chkmin(mina,dist(nx-(1<<j),ny,x[i],y[i]))) opt='L';
				if(chkmin(mina,dist(nx,ny-(1<<j),x[i],y[i]))) opt='D';
				ans.pb(opt);
				if(opt=='R') nx+=1<<j;
				if(opt=='U') ny+=1<<j;
				if(opt=='L') nx-=1<<j;
				if(opt=='D') ny-=1<<j;
			}
			reverse(ans.begin(),ans.end());
			for(auto r:ans) printf("%c",r);
			assert(nx==x[i]&&ny==y[i]);
			printf("\n");
		}
	}
	else{
		printf("31\n");
		for(int i=0;i<31;i++) printf("%lld ",1ll<<i);
		printf("\n");
		for(int i=1;i<=n;i++){
			ll nx=0,ny=0;
			vector<char> ans(0);
			for(int j=30;j>=0;j--){
				ll mina=1ll<<60;
				char opt;
				if(chkmin(mina,dist(nx+(1<<j),ny,x[i],y[i]))) opt='R';
				if(chkmin(mina,dist(nx,ny+(1<<j),x[i],y[i]))) opt='U';
				if(chkmin(mina,dist(nx-(1<<j),ny,x[i],y[i]))) opt='L';
				if(chkmin(mina,dist(nx,ny-(1<<j),x[i],y[i]))) opt='D';
				ans.pb(opt);
				if(opt=='R') nx+=1<<j;
				if(opt=='U') ny+=1<<j;
				if(opt=='L') nx-=1<<j;
				if(opt=='D') ny-=1<<j;
			}
			reverse(ans.begin(),ans.end());
			for(auto r:ans) printf("%c",r);
			assert(nx==x[i]&&ny==y[i]);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll x;std::cin >> x;
  ll t = (x/11)*2;
  x = x%11;
  std::cout << t + (x==0?0:x>6?2:1) << '\n';
  return 0;
}


Measured memory_bytes: 384
S = list(input())

res = 0
for i in range(2 ** (len(S) - 1)):
    s = S[0]
    for j in range(len(S) - 1):
        if i >> j & 1 == 1:
            s += "+"
        s += S[j + 1]
    res += eval(s)

print(res)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    int nr,time,i,j;
    cin >>nr >> time;
    int ans = INT_MAX;
    for(i = 0; i != nr; i++){
        int cost,t;
        cin >> cost>>t;
        if(t > time)continue;
        else{
          ans = min (ans,cost);
        }
    }
    if(ans == INT_MAX)
        cout <<"TLE"<<endl;
    else cout <<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
const int N=100100;
int a[N],l[N],r[N],h[N];
int n,m,tot,x,y,flag,root;
struct edge{int y,next;}g[N*2];

void adp(int x,int y){
	g[++tot].y=y;
	g[tot].next=h[x];
	h[x]=tot;
}

void dfs(int x,int fa,int d){
	if (a[x]!=-1){
		if ((a[x]%2==a[root]%2)==d)
			flag=1;
	}
	for (int i=h[x];i;i=g[i].next)
	if (g[i].y!=fa){
		dfs(g[i].y,x,1-d);	
		l[x]=max(l[x],l[g[i].y]-1);
		r[x]=min(r[x],r[g[i].y]+1);	
	}
	if (a[x]!=-1 && (l[x]>a[x] || a[x]>r[x]))
		flag=1;
}

void dfs(int x,int fa){
	if (a[x]==-1){
		if (l[x]<=a[fa]-1 && a[fa]-1<=r[x])
			a[x]=a[fa]-1; else a[x]=a[fa]+1;
	}
	for (int i=h[x];i;i=g[i].next)
		if (g[i].y!=fa) dfs(g[i].y,x);
}

int main(){
	 
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		adp(x,y);adp(y,x);
	}
	scanf("%d",&m);
	memset(a,-1,sizeof(a));
	memset(l,128,sizeof(l));
	memset(r,127,sizeof(r));
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		a[x]=l[x]=r[x]=y;root=x;
	}
	dfs(root,0,0);
	if (flag){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	dfs(root,0);
	for (int i=1;i<=n;i++)
		printf("%d\n",a[i]);
}

Measured memory_bytes: 8704
#include <cstdio>
using namespace std;
#define LL long long
int a[200005];
int main()
{
	int n;scanf("%d",&n);LL ans=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if (i==1 && a[i]!=0) {printf("-1");return 0;}
		if (i!=1 && a[i]-a[i-1]>1) {printf("-1");return 0;}
		if (a[i]-a[i-1]==1) ans++;
		else ans+=(LL)a[i]; 
	}
	printf("%lld",ans);
}

Measured memory_bytes: 896
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))


def search(target, st, en):
    h_len = (en + st) // 2
    if st > en:
        return False
    if S[h_len] == target:
        return True
    if S[h_len] > target:
        return search(target, st, h_len-1)
    if S[h_len] < target:
        return search(target, h_len+1, en)


def main():
    num = 0
    for i in T:
        st = 0
        en = n - 1
        if search(i, st, en):
            num += 1
    print(num)


if __name__ == '__main__':
    main()



Measured memory_bytes: 16712
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int main()
{
	int n,arr[15];
	LL a=1,b=1;
	scan(n);
	for(int i=1;i<=n;i++)
	{
		scan(arr[i]);
		a*=3;
		if(arr[i]&1)
			;
		else
			b*=2;
	}
	cout<<a-b<<endl;
}

Measured memory_bytes: 256
from collections import deque


class Graph:
    def __init__(self, n):
        self.n = n
        self.edge = [[] for _ in range(n)]
        self.color = [-1] * n

    def add_edge(self, node1, node2):
        self.edge[node1].append(node2)
        self.edge[node2].append(node1)

    def is_bipartite_graph(self):
        self.color = [-1] * self.n

        for i in range(self.n):
            if self.color[i] == -1:
                self.color[i] = 0
                d = deque([(i, 0)])

                while d:
                    node, c = d.pop()
                    for j in self.edge[node]:
                        if self.color[j] == -1:
                            self.color[j] = c ^ 1
                            d.append((j, self.color[j]))
                        elif self.color[j] == c:
                            return False

        return True


N, M = map(int, input().split())

g = Graph(N)

for i in range(M):
    A, B = map(int, input().split())
    g.add_edge(A-1, B-1)

if g.is_bipartite_graph():
    zero = g.color.count(0)
    print(zero * (N - zero) - M)
else:
    print(N * (N - 1) // 2 - M)


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

//For DP
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//Union-Find tree
struct UnionFind{
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
    vector<int> tsize;  // treeの大きさ

    UnionFind(int N) : par(N),tsize(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N;  i++) par[i] = i;
        for(int i = 0; i < N;  i++) tsize[i] = 1;
    }  


    int root(int x) { // データxが属する木の根を再帰で得る : root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { //xとyの木を併合
        int rx = root(x); //xの木の根をrx
        int ry = root(y); //yの木の根をyx
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)ときはそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時 : xの根rxをyの根ryにつける
        tsize[ry] += tsize[rx]; //根をつけた場合はもう一つのtree size分増加
        tsize[rx] = -1; // 同じ木になったため、xの根は-1
        //tree_size[x] = -1;  //子になった木はtree_sizeを持たない
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(){
    ll N,K;
    cin >> N >> K;
    ll A[N];
    rep(i,N) {
        cin >> A[i];
        A[i]--;
    }
    bool seen[N];
    rep(i,N) seen[i] = false;
    UnionFind tree(N);
    ll cnt = 0;
    ll goal = 0;
    seen[0] = true;
    ll roop[N] = {0};
    ll s_step;
    rep(i,N+10){
        goal = A[goal];
        cnt += 1;
        if(seen[goal] == true) {
            cnt = cnt - roop[goal];
            s_step = roop[goal];
            break;
        }
        roop[goal] = cnt;
        seen[goal] = true;
    }
    ll r_step;
    if (K>s_step) r_step = (K-s_step) % cnt;
    goal = 0;
    ll step = 0;
    rep(i,s_step){
        step += 1;
        goal = A[goal];
        if(step==K){
            cout << goal + 1 << endl;
            return 0;
        }
    }
    rep(i,r_step){
        goal = A[goal];
    }
    cout << goal + 1 << endl;
    return 0;
}


Measured memory_bytes: 8264
"use strict";
    
const main = arg => {
    const A = arg.split("\n")[0].split(" ")[0];
    const B = arg.split("\n")[0].split(" ")[1];
    const S = arg.split("\n")[1];
    
    if(S.split("-")[0].length == A && S.split("")[A] == "-" && S.split("-")[1].length == B) {
        console.log("Yes");
    } else {
        console.log("No");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;

int const maxn = 105, maxt = 205, maxv = 105;
double inf = 1000.0 * 1000.0 * 1000.0;
int t[maxn], v[maxn];
int V[2 * maxn * maxt];
int dp[2 * maxn * maxt][2 * maxv];

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, N = 1;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> t[i];
    for (int i = 1; i <= n; ++i) cin >> v[i];
    for (int i = 1; i <= n; ++i) {
        while (t[i]--) {
            V[N++] = v[i];
            V[N++] = v[i];
        }
    }
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j < 2 * maxv; ++j) dp[i][j] = -inf;
    }
    dp[0][0] = 0;
    for (int i = 1; i < N; ++i) {
        for (int j = 0; j <= 2 * V[i]; ++j) {
            for (int lst = max(0, j - 1); lst <= j + 1; ++lst) {
                if (j == 2 * V[i] && lst > j) continue;
                dp[i][j] = max(dp[i][j], dp[i - 1][lst] + j + lst);
            }
        }
    }
    cout << fixed << setprecision(9) << dp[N - 1][0] / 8.0 << '\n';
    return 0;
}


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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

ll modexp(ll x, ll n) {
    ll ans = 1;
    while (n) {
        if (n & 1) ans = ans * x % mod;
        x = x * x % mod;
        n /= 2;
    }
    return ans;
}

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

    ll n;
    cin >> n;

    ll ans = modexp(10, n);
    ans = (ans - 2 * modexp(9, n) % mod + mod) % mod;
    ans = (ans + modexp(8, n)) % mod;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3644
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C

#D
def root(x):
    if x == par[x]:
        return x
    par[x] = root(par[x])
    return par[x]

def same(x,y):
    return root(x) == root(y)

def unite(x,y):
    x = root(x)
    y = root(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
n = I()
v = LIR(n)
l = []
for i in range(n):
    v[i].append(i)
par = [i for i in range(n)]
rank = [0 for i in range(n)]
v.sort(key = lambda x:x[0])
for i in range(n-1):
    l.append([v[i][2],v[i+1][2],v[i+1][0]-v[i][0]])
v.sort(key = lambda x:x[1])
for i in range(n-1):
    l.append([v[i][2],v[i+1][2],v[i+1][1]-v[i][1]])
l.sort(key = lambda x:x[2])
k = 0
ans = 0
for i in range(len(l)):
    x,y,c = l[i]
    if not same(x,y):
        k += 1
        ans += c
        unite(x,y)
    if k == n-1:break
print(ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 126336
#include<iostream>

#include<vector>

using namespace std;

int main()
{
	for(;;)
	{
		int N;
		cin >> N;
		if(N == 0)
		{
			break;
		}

		vector<int> vobj;
		for(;;)
		{
			if(N <= 7)
			{
				vobj.push_back(N);
				break;
			}
			vobj.push_back(N % 8);
		
			N = N / 8;


		}

		for(int i = vobj.size() -1; i >= 0; i--)
		{
			int outputNo;
			outputNo = vobj[i];
			if(outputNo == 4)
			{
				outputNo = 5;
			}
			else if(outputNo == 5)
			{
				outputNo = 7;
			}
			else if(outputNo == 6)
			{
				outputNo = 8;
			}
			else if(outputNo == 7)
			{
				outputNo = 9;
			}
			cout << outputNo;

		}
		cout << endl;

	}



}

Measured memory_bytes: 3120
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")

#include <bits/stdc++.h>
using namespace std;

int c[26];
int64_t csum;
int64_t s[366][26];

constexpr int width = 475;
constexpr int dw = (width - 50) / 365;

int64_t eval(const vector<int> &state, int d){
    int last[26] = {0};
    int64_t decl = -csum;
    int64_t score = 0;

    for(int i=1;i<=d;++i){
        score += s[i][state[i]];
        decl += (i - last[state[i]])*c[state[i]];
        last[state[i]] = i;
        score += decl;
        decl -= csum;
    }
    return score;
}

vector<int> beam(int D, int w){
    map<int64_t, vector<int>, greater<int64_t>> mp;
    for(int i=0;i<26;++i){
        mp[s[1][i] + c[i] - csum] = vector<int>{2, i};
    }
    for(int d=2;d<=D;++d){
        w -= dw;
        int cnt = 0;
        vector<vector<int>> states;
        for(auto p: mp){
            states.push_back(p.second);
            ++cnt;
            if(cnt >= w) break;
        }
        mp.clear();
        for(auto v: states){
            for(int i=0;i<26;++i){
                vector<int> state{v};
                state.emplace_back(i);
                mp[eval(state, d)] = state;
            }
        }
    }
    return mp.begin()->second;
}

int main(){
    int d;
    scanf("%d", &d);
    for(int i=0;i<26;++i) scanf("%d", &c[i]);
    for(int i=0;i<26;++i) csum += c[i];

    for(int i=1;i<=d;++i){
        for(int j=0;j<26;++j) scanf("%" SCNd64, &s[i][j]);
    }

    auto ans = beam(d, width);
    for(int i=1;i<=d;++i) printf("%d\n", ans[i] + 1);

    return 0;
}

Measured memory_bytes: 10408
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, c, ans = 0;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, 0, m) cin >> b[i];
    rep(i, 0, n){
        vector<int> a(m);
        rep(j, 0, m){
            cin >> a[j];
        }
        int tmp = c;
        rep(j, 0, m){
            tmp += a[j] * b[j];
        }
        if(tmp > 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x,ans,k=100;
	cin>>x;
	for(int i=0;;i++){
		if(k>=x){
			ans=i;
			break;
		}
		k+=k*0.01;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3636
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

    vector<ll> l(N), r(N);
    for (ll i = 0; i < N; i++) {
        cin >> l[i] >> r[i];
    }

    multiset<ll> le, ri;
    le.insert(l[0]);
    ri.insert(r[0]);

    ll ls = l[0], rs = l[0];
    ll ans = 0;
    for (ll i = 1; i < N; i++) {
        ls -= r[i] - l[i];
        rs += r[i - 1] - l[i - 1];

        ll a = *le.rbegin();
        ll b = *ri.begin();
        if (ls <= l[i] && l[i] <= rs) {
            le.insert(l[i] - (ls - a));
            ri.insert(l[i] - (rs - b));
            ls = rs = l[i];
        } else if (l[i] < ls) {
            ans += abs(l[i] - ls);
            le.insert(l[i] - (ls - a));
            le.insert(l[i] - (ls - a));
            ll left = *le.rbegin() + (ls - a);
            le.erase(--le.end());
            ri.insert(left - (rs - b));
            ls = *le.rbegin() + (ls - a);
            rs = left;
        } else {
            ans += abs(l[i] - rs);
            ri.insert(l[i] - (rs - b));
            ri.insert(l[i] - (rs - b));
            ll right = *ri.begin() + (rs - b);
            ri.erase(ri.begin());
            le.insert(right - (ls - a));
            ls = right;
            rs = *ri.begin() + (rs - b);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

typedef struct {
	int b;
	int c;
}pair_t;

int cmp(const void* p, const void* q) {
	return *(int*)p - *(int*)q;
}

int cmp2(const void* p, const void* q) {
	return ((pair_t*)q)->c - ((pair_t*)p)->c;
}

int main(void) {
	int n, m;
	int a[100000] = { 0 };
	pair_t pair[100000] = { 0 };
	int flag = 0;

	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	for (int i = 0; i < m; i++)scanf("%d %d", &pair[i].b, &pair[i].c);

	qsort(a, n, sizeof(int), cmp);
	qsort(pair, m, sizeof(pair_t), cmp2);
	int left = 0;
	for (int i = 0; i < m; i++) {
		for (int j = left; j - left < pair[i].b; j++) {	

			if(pair[i].c <= a[j]){
				flag = 1;
				break;
			}
			else {
				a[j] = pair[i].c;
				if (j >= n - 1) {
					flag = 1;
					break;
				}
			}
			if (j - left >= pair[i].b - 1) {
				left = j + 1;
				break;
			}
		}
		if (flag)break;
	}
	long long total = 0;
	for (int i = 0; i < n; i++)total += a[i];
	printf("%lld", total);
	return 0;
}

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

int main(void){
    string s[3];
    
    cin >> s[0];
    cin >> s[1];
    cin >> s[2];
    int index = 0;
    char c;
    
    while(true){
        if( s[index].size() == 0 )break;
        
        c = s[index][0];
        s[index] = s[index].substr(1,s[index].size()-1);
        
        switch(c){
            case 'a':
                index = 0;
                break;
            case 'b':
                index = 1;
                break;
            case 'c':
                index = 2;
                break;
        }
    }
    
    printf("%c\n", index == 0 ? 'A' : (index==1?'B':'C'));
    
    return 0;
}


Measured memory_bytes: 256
import re

N = int(input())

cnt = 0
tail_A = 0
head_B = 0
both = 0

for i in range(N):
    s = input()
    if s[0] == 'B':
        head_B += 1
    if s[-1] == 'A':
        tail_A += 1
    if s[0] == 'B' and s[-1] == 'A':
        both += 1
    matchedList = re.findall(r"AB", s)
    cnt += len(matchedList)

if tail_A == 0 and head_B == 0 and both == 0:
    cnt = cnt
elif tail_A == both and head_B == both:
    cnt += min(tail_A, head_B) - 1
else:
    cnt += min(tail_A, head_B)


print(cnt)

Measured memory_bytes: 3188
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

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

int f(int n){
  if(n % 2 == 0){
    return n / 2;
  }
  else{
    return 3 * n + 1;
  }
}

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

  int s;
  cin >> s;

  int m = 1;
  set< int > b;
  int a = s;
  b.insert(a);
  while(true){
    ++m;
    a = f(a);
    if(b.find(a) != b.end()) break;
    b.insert(a);
  }

  cout << m << endl;

  return 0;
}


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

using namespace std;

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

	int h, m, s;

	h = S / 3600;
	m = (S % 3600) / 60;
	s = S % 60;

	cout << h << ":" << m << ":" << s << endl;

}



Measured memory_bytes: 3104
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstdlib>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
int N;
ll K;
int ans = 0;
vector<int> parent;
vector<vector<int> > G;


//木の高さを調べながらansをプラスしていけ
int dfs(int n) {
    int max_child = 0;
    for (auto child : G[n]) {
        chmax(max_child, dfs(child));
    }

    int ret = max_child + 1;
    if(ret > K){
        exit(-1);
    }
    if (ret == K) {
        if (parent[n] != 0) ans++;
        ret = 0;
    }
    return ret;
}

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

    cin >> N >> K;
    G.resize(N);

    rep(i, 0, N) {
        int p;
        cin >> p;
        p--;
        if (i == 0) {
            if (p != 0)
                ans++;
            parent.push_back(0);
            continue;
        }
        parent.push_back(p);
        G[p].push_back(i);
    }

    dfs(0);
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 10744
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)

long long a,b,n;

int main() {
    cin>>a>>b>>n;
    long long x;
    long long ans;
    if(n<b){
        x=n;
        ans=(a*x)/b - a*(x/b);
    }else{
        x=b-1;
        ans=(a*x)/b - a*(x/b);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    s[5] = s[13] = ' ';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
def insertion_sort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j -= g
            cnt += 1
        A[j + g] = v


def shell_sort(A, n):
    G = []
    i = 1
    while i <= n:
        G.append(i)
        i = i * 3 + 1
    G_inv = G[::-1]
    for g in G_inv:
        insertion_sort(A, n, g)
    return len(G), G_inv, A

N = int(input())
a = [int(input()) for i in range(N)]
cnt = 0
m, Gl, A = shell_sort(a, N)
print(m)
print(' '.join(str(g) for g in Gl))
print(cnt)
print('\n'.join(str(e) for e in A))

Measured memory_bytes: 127880