akhauriyash/Code-Regression huggingface dataset:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
x, n = M()
if n == 0:
    print(x)
else:
    n_l = LI()
    suchi_list = [i for i in range(-300, 300)] # 1~100までのリスト
    ans = -1
    for i in n_l:
        suchi_list.remove(i)
    if x in suchi_list:
        ans = x
    else:
        for j in range(1, 101):
            if x-j in suchi_list:
                ans = x-j
            elif x+j in suchi_list:
                ans = x+j
            if ans != -1:
                break
    print(ans)

Measured memory_bytes: 68500
#include<iostream>
using namespace std;
#define MAX 100000
int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; };
int right(int i) { return 2 * i + 1; };
int main() {
    int h, i, a[MAX + 1];
    cin >> h;
    for (i = 1; i <= h; i++)cin >> a[i];
    for (i = 1; i <= h; i++) {
        cout << "node " << i << ": key = " << a[i] << ", ";
        if (parent(i) >= 1)cout << "parent key = " << a[parent(i)] << ", ";
        if (left(i) <= h)cout << "left key = " << a[left(i)] << ", ";
        if (right(i) <= h)cout << "right key = " << a[right(i)] << ", ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int mp[N][N],n,m,ans,a[N][N],up[N],l[N],r[N];
char s[N];
int main(){
	scanf("%d%d",&n,&m),ans=max(n,m);
	for (register int i=1;i<=n;++i){
		scanf("%s",s+1);
		for (register int j=1;j<=m;++j)
			mp[i][j]=(s[j]!='.');
	}
	--n,--m;
	for (register int i=1;i<=m;++i) l[i]=1,r[i]=m;
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=m;++j)
			a[i][j]=mp[i][j]^mp[i+1][j]^mp[i][j+1]^mp[i+1][j+1];
	for (register int i=1;i<=n;++i){
		int lmax=0,rmin=m+1;
		for (register int j=1;j<=m;++j)
			if (a[i][j]) up[j]=0,lmax=j,l[j]=1;
			else ++up[j],l[j]=max(l[j],lmax+1);
		for (register int j=m;j;--j)
			if (a[i][j]) rmin=j,r[j]=m;
			else r[j]=min(r[j],rmin-1),ans=max((r[j]-l[j]+2)*(up[j]+1),ans);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35068
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	cout<<(n-1)/2<<"\n";
	return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> p;
 
#define MOD 1000000007
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;

    vector<int> A(N);

    for(int i = 0; i < N; i++) cin >> A[i];

    for(int i = K; i < N; i++) {
        if(A[i] > A[i - K]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3992
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rr(x,y) read(x);read(y)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define pb(x) push_back(x)
#define sss(str) scanf("%s",str+1)
#define ssf(x) scanf("%lf",&x)
#define aLL(x) x.begin(),x.end()
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef double dd;
typedef pair<int,int> pt;
const int N=2e5+5;
const int M=2e3+50;
const int INF=0x7fffffff;
const int mod=1e9+7;
const int sz=18;
const double eps=1e-10;
const double pi=acos(-1);
//***********************
int n,m;
char str[M];
int f[N];
//***********************
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    sss(str);
    bool f1=0,f2=0;
    FOR(i,1,3){
        if(str[i]=='A') f1=1;
        else if(str[i]=='B') f2=1;
    }
    if(f1&&f2) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {

   int n = 0;
   scanf("%d",&n);
   int a[n+1];
   for(int i = 0; i<n; i++) {
     scanf("%d",&a[i]);
   }
   for(int i = n-1; i>=1; i--) {
     printf("%d ",a[i]);
   }  
     printf("%d\n",a[0]);
   return 0;
}


Measured memory_bytes: 2720
import sys
str = list(input())

n = len(str)

for i in range(8):
    edit = str[0:i] + str[n - 7 + i:]
    if edit == ['k', 'e', 'y', 'e', 'n', 'c', 'e']:
        print('YES')
        sys.exit()
print('NO')


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 100005

int main() {

	int n, i, ans = 0;

	cin>>n;

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

		int a;
		cin>>a;

		if(i % 2 == 1 && a % 2 == 1) ans++;
	}

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

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

using namespace std;
using ll = long long;
const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<ll, int> A;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += A[i - a[i]];
        A[a[i] + i]++;
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 26600
N = int(input())
A = list(map(int,input().split()))

from collections import defaultdict
G = defaultdict(list)
D = {}

for i in range(N):
    tmp = A[i]
    G[tmp].append(i)
    
keylist = []

for key in G:
    G[key].sort()
    D[key] = len(G[key])
    keylist.append(key)

keylist.sort()
keylist = keylist[::-1]
keylist.append(0)

D[0] = 0
G[0].append(0)

ans = [0]*N

for i in range(len(keylist)-1):
    key = keylist[i]
    nextkey = keylist[i+1]
    tmpi = G[key][0]
    ans[tmpi] += D[key]*(key-nextkey)
    
    D[nextkey] += D[key]
    G[nextkey][0] = min(G[nextkey][0],tmpi)
    
for i in ans:
    print(i)

Measured memory_bytes: 95852
#include <stdio.h>
#include <string.h>

#define M 1046527
#define L 14
#define NIL -1

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){
  long long key, i, x;
  key = getKey(str);
  for(i = 0; i < M; i++){
    x = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[x], str) == 0) return 1;
    else if(strlen(H[x]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key , i, y;
  key = getKey(str);
  for(i = 0; i < M; i++){
    y = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[y], str) == 0) return 1;
    else if(strlen(H[y]) == 0){
      strcpy(H[y], str);
      return 0;
    }
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 16104
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int A, B;
  cin >> A >> B;
  if(A+B < 10) cout << A+B << endl;
  else cout << "error" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  
    int a=0;
    int b=0;
    int c=0;
    int A[200];
    int d=0;
    int r=0;
    float j=0;

    int w=0;
    float i=0;
    int p=0;
        scanf("%d",&a);
  for(b=0;b<a;b++){
      scanf("%d",&A[b]);
  }
  
  for(b=0;b<a;b++){
     c=c+A[b];
  }
 p=c/a;

 r=2*c/a;
 
  if(r!=p*2){
     w=w+1;
 }
  j=c/a;
  
  for(j=j;j>0;j--){
      w=w+1;
  }
  for(b=0;b<a;b++){
     d=d+(w-A[b])*(w-A[b]);
  }
  
printf("%d",d);
}


    
    
    



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

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            String S = Console.ReadLine();
            String[] line = S.Split(' ');
            int[] A = new int[N];
            bool check = false;

            for(int i=0; i<N; i++)
            {
                A[i] = int.Parse(line[i]);
                if(A[i] % 2 == 0 && (A[i] % 3 != 0　&& A[i] % 5 != 0))
                {
                    check = true;
                }
            }

            if(check == true)
            {
                Console.WriteLine("DENIED");
            }
            else
            {
                Console.WriteLine("APPROVED");
            }

        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	string S; cin>>S;
	// cout<<S<<"\n";//
	int N = S.size();
	S += "R";
	// cout<<S<<"\n";//

	int even = 0, odd = 0;
	int l_pos = -1, r_pos = 0;
	int e = 0, o = 0;
	int r = 0, l = 0;
	rp(i,0,N){
		if(i%2) o++; else e++;

		if(S[i]=='R' && S[i+1]=='L'){
			r_pos = i;
			rp(j,l_pos+1, r_pos) cout<<0<<" ";
			l_pos = i + 1;
			if(r_pos%2){//odd
				r += o;
				l += e;
			}
			else{//even
				r += e;
				l += o;
			}
			o = e = 0;
		}
		else if(S[i]=='L' && S[i+1]=='R'){
			if(r_pos%2){//odd
				r += o;
				l += e;
			}
			else{//even
				r += e;
				l += o;
			}
			o = e = 0;
			cout<<r<<" "<<l<<(i+1<N?" ":"");
			r = l = 0;
		}

	}

	if(l_pos+1==N) cout<<"\n";
	else rp(i, l_pos+1, N) cout<<" "<<0<<(i+1==N?"\n":"");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int a,b;
    cin >> a >> b;
    if(a<=8&&b<=8)print("Yay!");
    else print(":(");
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
    // 1. 入力情報取得.
    string S;
    cin >> S;
    
    // 2. 各方角の出現数をカウント.
    int n = 0, w = 0, s = 0, e = 0;
    for(int i = 0; i < S.size(); i++){
        char c = S[i];
        if(c == 'N') n++;
        if(c == 'W') w++;
        if(c == 'S') s++;
        if(c == 'E') e++;
    }
    
    // 3. 出力.
    string ans = "Yes";
    if(n + s > 0 && n * s == 0) ans = "No";
    if(w + e > 0 && w * e == 0) ans = "No";
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
import math

n, d = map(int, input().split())

X = [list(map(int, input().split())) for i in range(n)]


def Distance(a = [], b = []):
    res = 0.0
    for x, y in zip(a, b):
        res += (x - y) * (x - y)
    return math.sqrt(res)

count = 0
for i in range(int(len(X))):
    for j in range(i + 1, int(len(X))):
        r = Distance(a=X[i], b=X[j])
        if r.is_integer():
            count+=1
        

print(count)


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

int main()
{

	int n;
	int b, f, r, v;
	int home[5][4][11];
	for (int i = 1; i <= 4; i++) {
		for(int j = 1; j <= 3; j++) {
			for(int k = 1; k <= 10;  k++) {
				home[i][j][k] = 0;
			}
		}
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		home[b][f][r] += v;
	}

	for (int b = 1; b <=4; b++) {
		if (b > 1)cout <<"####################"<< endl;
		for (int f = 1; f <= 3; f++){
			for (int r = 1; r <= 10; r++) {
				cout << " " << home[b][f][r];
				if (r == 10)cout << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3056
from collections import deque
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    al = []
    al.append(deque([]))
    for _ in range(n):
        row = list(map(int, input().split()))
        al.append(deque(row))

    # print(al)

    day = 0
    cnt = 0
    max_cnt = n*(n-1)//2
    check_il = [i for i in range(1,n+1)]
    while True:
        next_check_il = check_il[:]
        check_il = []
        day += 1
        already_fights = set()
        update_flag = False
        for i in next_check_il:
            al_i = al[i]
            if not al_i or i in already_fights: continue
            i_next_rival = al_i[0]

            al_rival_i = al[i_next_rival]
            if not al_rival_i or i_next_rival in already_fights: continue
            i_next_rival_rival = al_rival_i[0]

            if i_next_rival_rival == i:
                al[i].popleft()
                al[i_next_rival].popleft()
                already_fights.add(i)
                already_fights.add(i_next_rival)
                check_il.append(i)
                check_il.append(i_next_rival)
                cnt += 1
                update_flag = True
            else:
                continue

        if not update_flag:
            print(-1)
            exit()

        if cnt == max_cnt:
            break

    print(day)


if __name__ == "__main__":
    main()

Measured memory_bytes: 102420
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <vector>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

int calc(int s, int e, int h[]){
  //cout << s << " " << e << endl;
  if(s==e) {
    //cout << h[s] << " " << s << endl;
    return h[s];
  }
  int sum=0;
  int minh=1000;
  for(int i=s; i<=e; i++){
    minh=min(minh,h[i]);
  }
  for(int i=s; i<=e; i++){
    h[i]-=minh;
  }
  sum+=minh;
  int st,en;
  int flag=0;
  for(int i=s; i<=e; i++){
    if(h[i]!=0 && flag==0) st=i,flag=1;
    else if(h[i]==0 && flag==1) en=i-1, flag=0, sum+=calc(st, en, h);
    
    if(i==e && flag==1) sum+=calc(st, e, h);
  }
  return sum;
}

int main(){
  int N;
  cin >> N;
  
  int h[101];
  rep(i, N) cin >> h[i];
  
  cout << calc(0, N-1, h) << endl;
  
}

Measured memory_bytes: 256
#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline


#N=int(input())
N,M=map(int,input().split())
mod=10**9 + 7
maxi=round(M**.5)+2
fac=[1,1]
for i in range(2,N+100):
    fac.append(fac[i-1]*i%mod)
ifac=[pow(i,mod-2,mod) for i in fac]
sosuu={}
i=2
maxi=round(M**.5)+1
while M>1 and maxi>=i:
    if M%i==0:
        sosuu[i]=0
        while M%i==0:
            M//=i
            sosuu[i]+=1
    i+=1
if M>1:
    sosuu[M]=1
count=1

for s in sosuu:
    a=sosuu[s]
    count=(count*fac[a+N-1]*ifac[N-1]*ifac[a])%mod
print(count)


Measured memory_bytes: 70636
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI A(N),W(N);
	bool F = false, FF = false;
	REP(i, N) {
		cin >> A[i];
		if (A[i])F = true;
		if (!A[i])FF = true;
	}
	REP(i, N)cin >> W[i];
	
	VI L, R;
	REP(i, N) {
		if (A[i])L.push_back(W[i]);
		else R.push_back(W[i]);
	}
	SORT(R);
	SORT(L);

	if (F ^ FF) {
		cout << 0 << endl;
	}
	else {
		cout << R[0] + L[0] << endl;
	}


	return 0;
}




Measured memory_bytes: 3224
#include "stdio.h"

int main(void)
{
    int X;
    int ureshisa;
    int gohyaku=0;
    int go=0;

    scanf("%d",&X);
    gohyaku = X/500;
    X = X%500;
    go = X/5;

    ureshisa = gohyaku*1000 + go*5;
    printf("%d",ureshisa);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

int main(void)
{
	int n;
	int a, v;
	vector < pair <int, int> > vi;

	cin >> n;
	while (n--){
		cin >> a >> v;
		vi.push_back(make_pair(v, a));
	}
	sort(vi.rbegin(), vi.rend());

	int ret[2] = {0}, ma = vi[0].first;
	for (int i = 0; i < vi.size(); i++){
		if (ma == vi[i].first){
			ret[0] = vi[i].first;
			ret[1] = vi[i].second;
		}
		else {
			break;
		}
	}


	cout << ret[1] << " " << ret[0] << endl;

	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    double c = double(a);
    double d = double(b);
    int e = a/b;
    int f = a%b;
    double g = c/d;
    printf("%d %d %.81f\n",e,f,g);
}


Measured memory_bytes: 3208
import fractions as fc

A, B = [int(x) for x in input().split()]
C = fc.gcd(A, B)
b = 2
ans =  1
while b * b <= C:
  if C % b == 0:
    ans += 1
    while C % b == 0:
      C //= b
  if C == 1:
    break
  b += 1
if C > 1:
  ans += 1
print(ans)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	

	void solve(){
		

		ini(n);
		ini(n1);
		vi morty(n);
		FOR(i,0,n){
			in(morty[i]);
		}
		int tourist = *max_element(all(morty));
		int l  = 0;
		int r  = tourist;
		auto tmp1 = [&](int x){
			if(x == 0){
				return 0;
			}
			int x1 = 0;
			FOR(i,0,n){
				x1+=(morty[i]+x-1)/x-1;
			}
			if(x1<=n1)return 1;
			else return 0;
		};
		while(l<=r){
			int tmp = l+(r-l)/2;
			if(tmp1(tmp))r = tmp-1;
			else l = tmp+1;
		}
		if(l>tourist)l = n1;
		out(l);
		
			
			
			


				
		


		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 4708
fun main(args: Array<String>) {
    val s = readLine()!!
    var e0 = 0
    var o0 = 0
    for (i in 0 until s.length) {
        val c = s[i]
        if (i and 1 == 0) {
            if (c == '0') o0++
        } else {
            if (c == '0') e0++
        }
    }
    val es = s.length shr 1
    val os = if (s.length and 1 == 0) es else es + 1
    println(Math.min(e0 + os - o0, o0 + es - e0))
}


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

using namespace std;

int main()
{
   int n,k; cin>>n>>k;
   vector<vector <int> >v(n+1);
   vector <int> f(n+1);
   vector<pair<long long,int > > arr;
   for(int i=0;i<n;++i){
       int x; cin>>x;
       f[i+1] = x;
       arr.emplace_back(x,i+1);
   }
   sort(arr.rbegin(),arr.rend());
   for(;k--;){
       int c,d; cin>>c>>d;
       v[c].push_back(d);
       v[d].push_back(c);
   }
   vector<bool>vis(n+1,0);
   int cnt = 0;
   for(auto i: arr){
       if(!vis[i.second]){
           bool flg = 1;
           //cout<<i.second<<" ";
           vis[i.second] = 1;
           for(int j : v[i.second]){
               if(i.first <= f[j]){
                   flg = 0;
                   break;
               }
               vis[j] = 1;
               //cout<<j<<" ";
           }
           //cout<<"\n";
           cnt+=flg;
       }
   }
   cout<<cnt<<"\n";
  
   
   return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int ans = k;
    rep(i, n-1) {
        ans *= k - 1;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int N,K;
  cin>>N;
  char S[N];
  cin>>S>>K;
  for (int i=0;i<N;i++){
    if(S[i]!=S[K-1]){
      S[i]='*';
    }
  }
  cout<<S<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

  int n;
  long p = 1;
  long d = pow(10, 9) + 7;

  cin >> n;

  for (int i = 1; i <= n; i++){
    p = i * (p % d);
  }

  cout << p % d << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
def YesNo(x):print("Yes")if x==True else print("No")
n=N()
n%=10
if n==3:
    print("bon")
elif n in [0,1,6,8]:
    print("pon")
else:
    print("hon")


Measured memory_bytes: 9136
x, n = map(int, input().split())
ps = list(map(int, input().split()))
nums = list(range(-1, 102))
for p in ps:
    nums.remove(p)
min_diff = float("inf")
min_original = float("inf")
for num in nums:
    diff = abs(num - x)
    if diff < min_diff:
        min_diff = diff
        min_original = num
    elif diff == min_diff:
        if num < min_original:
            min_original = num
print(min_original)


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define M 1000000007

int32_t main()
{   fast

    int n;
    cin>>n;
    string s;
    cin>>s;
        char x=s[0];
        int ans=1;
        for(int i=1;i<n;i++)
        {
            if(s[i]!=x)
            {
                ans++;
                x=s[i];
            }
        }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define open(s) freopen( s".in", "r", stdin ), freopen( s".out", "w", stdout )
#define LL long long
#define MAXN 100005
#define MAXM 200005

int N, M;
int hd[MAXN], nxt[MAXM], to[MAXM], tot(1);
int cnt[5], c[MAXN], sum;
bool flg;
LL ans;

void Add( int x, int y ){
	nxt[++tot] = hd[x]; hd[x] = tot; to[tot] = y;
	nxt[++tot] = hd[y]; hd[y] = tot; to[tot] = x;
}

int Get( int x, bool fg ){return fg ? ( x + 2 ) % 3 : ( x + 1 ) % 3;}

void DFS( int x ){
	cnt[c[x] + 1]++;
	for ( int i = hd[x]; i; i = nxt[i] ){
		sum++;
		if ( c[to[i]] >= 0 ){
			if ( Get( c[x], i & 1 ) != c[to[i]] ) flg = 1;
		}else c[to[i]] = Get( c[x], i & 1 ), DFS( to[i] );
	}
}
 
int main(){
	scanf( "%d%d", &N, &M );
	for ( int i = 1; i <= M; ++i ){
		int x, y; scanf( "%d%d", &x, &y ); Add( x, y );
	}
	memset( c, -1, sizeof c );
	for ( int i = 1; i <= N; ++i ){
		if ( c[i] < 0 ){
			flg = 0; c[i] = 0; sum = 0;
			cnt[1] = cnt[2] = cnt[3] = 0;
			DFS( i );
			if ( flg ) ans += 1ll * ( cnt[1] + cnt[2] + cnt[3] ) * ( cnt[1] + cnt[2] + cnt[3] );
			else if ( cnt[1] == 0 || cnt[2] == 0 || cnt[3] == 0 ) ans += sum / 2;
			else ans += (LL)cnt[1] * cnt[2] + (LL)cnt[2] * cnt[3] + (LL)cnt[3] * cnt[1];
		}
	}
	printf( "%lld", ans );
	return 0;
}


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        if (N <= M)
        	System.out.println("unsafe");
        else
        	System.out.println("safe");
        	

	}
}


Measured memory_bytes: 35788
n,k = map(int,input().split())
a = list(map(int,input().split()))

warp = [-1] * (n+1)
warp[1] = 0

now = 1
for i in range(n):
    next_town = a[now-1]
    if warp[next_town] == -1:
        warp[next_town] = i+1
        now = next_town
    else:
        break

loop = (i+1) - warp[next_town]
if warp[next_town] > k:
    count = k
else:
    count = (k-warp[next_town])%loop + warp[next_town]

print(warp.index(count))

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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

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

    map<string, int64_t> mp1, mp2;
    for(int b=0; b<(1<<N); b++){
        string s;
        for(int k=0; k<2; k++){
            for(int i=0; i<N; i++) if(nth_bit(b, i) == k) s.push_back(S[i]);
            s.push_back('!');
        }
        mp1[s]++;
    }
    for(int b=0; b<(1<<N); b++){
        string s;
        for(int k=0; k<2; k++){
            for(int i=0; i<N; i++) if(nth_bit(b, i) == k) s.push_back(S[2*N-1-i]);
            s.push_back('!');
        }
        mp2[s]++;
    }
    int64_t ans = 0;
    for(auto& p : mp1){
        string s = p.first;
        int64_t v = p.second;
        if(mp2.count(s)) ans += v * mp2[s];
    }
    cout << ans << endl;
}

Measured memory_bytes: 73984
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main()
{
	int N, X;

	cin >> N >> X;

	int L = 0;
	int pos = 0;
	int num = 1;
	for (int idx = 0; idx < N; ++idx)
	{
		cin >> L;

		pos += L;
		num++;

		if (X < pos)
		{
			cout << num - 1;
			return 0;
		}

	}

	cout << num;


	return 0;
}


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

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

	if(n < k) {
		long long temp;
		temp = k - n;
		if(n < temp) temp = n;
		cout << temp << '\n';
		return 0;
	}

	long long tmp1, tmp2;
	tmp1 = llabs(n - (k * (n / k)));
	tmp2 = llabs(n - (k * ((n / k) + 1)));

	if(tmp1 <= tmp2) {
		cout << tmp1 << '\n';
	} else {
		cout << tmp2 << '\n';
	}

    return 0;
}


Measured memory_bytes: 256
import math
A, B, N = map(int, input().split())


x = 0

if N >= B - 1:
    x = B - 1
elif N < B -1:
    x = N
    if not N % B == 0:
        pass
    else:
        x -= 1


yoshiki = math.floor((A*x) / B) - A * math.floor(x/B)
print(yoshiki)

Measured memory_bytes: 9176
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [usize;n]
    }
    let mut ans: i32 = 0;
    for i in 0..n {
        if h.get(i).unwrap() >= &k {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int main(){

  int n;
  int a[100][100];
  int i = 1;
  int x,y;

  while(cin >> n, n){

    memset(a,0,sizeof(a));
    i = 1;

    x = n/2+1;
    y = n/2;

    a[x][y] = i;

    x++;
    y++;
    i++;

    while(true){

      int k = 0;

      if(x < n && y < n && x >= 0 && y >= 0 && !a[x][y]){
	  a[x][y] = i;
	  k = 1;
	}

	else if(x >= n) x = 0;
	else if(y >= n) y = 0;
	else if(y < 0) y = n-1; 
	else if(x < n && y < n && a[x][y] != 0){
	  x++;
	  y--;
	}

	if(!k) continue;

	i++;
	x++;
	y++;

	if(i == n*n+1) break;

	}

      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++) printf("%4d",a[i][j]);
	cout << endl; 
      }

    }
  }

Measured memory_bytes: 1236
/**
 * THIS IS CFMASTER'S CODE !
 * HACK IT IF YOU CAN !
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> s(n, -1);
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    if (s[x] != -1 && y != s[x]) {
      ok = false;
      //cout << x << " " << y << " " << s[x] << '\n'; 
    }
    s[x] = y;
  }
  if (!ok || s[0] == 0 && n != 1) {
    cout << -1 << '\n';
    return 0;
  }
  if (n == 1) {
    if (s[0] == -1) {
      cout << 0 << '\n';
      return 0;
    } else {
      cout << s[0] << '\n';
      return 0;
    }
  }
  if (s[0] == -1) {
    s[0] = 1;
  } 
  for (int i = 0; i < n; i++) {
    if (s[i] == -1) {
      s[i] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << s[i];
  }
  cout << '\n';
  return 0;
}

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

int main() {
  int64_t a,b;
  cin >> a >> b;
  if(a==1 || b==1){
  cout << 1 << endl; 
  }  
  else{  
  cout << a*b-(a*b/2) << endl;  
  }  
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 200000
#define SENTINEL 2000000000
typedef long long ll;
int L[MAX / 2 + 2],R[MAX / 2 + 2];
ll merge(int A[], int n,int left,int mid, int right){
	int i,j,k;
	ll cnt = 0;
	int n1 = mid - left;
	int n2 = right-mid;
	for(i = 0; i < n1;i++){
		L[i] = A[left + i];
	}
	for(i = 0; i < n2; i++){
		R[i] = A[mid + i];
	}
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for(k = left;k < right; k++){
		if(L[i] <=R[j]){
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}
ll mergeSort(int A[], int n,int left, int right){
	int mid;
	ll v1,v2,v3;
	if(left + 1<right){
		mid = (left + right) / 2;
		v1 = mergeSort(A,n,left,mid);
		v2 = mergeSort(A,n,mid,right);
		v3 = merge(A,n,left,mid,right);
		return v1+v2+v3;
	}
	else{
		return 0;
	}
}

int main (void){
	
	int A[MAX],n,i;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d",&A[i]);
	}
	ll ans = mergeSort(A,n,0,n);
	printf("%ld\n",ans);
	return 0;
}



Measured memory_bytes: 3360
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int V,E,r;
const int Inf = 10000*100000+100;
ll C[100010];
int main(){
	while(cin >> V >> E >> r && V >0){
		vector< vector< P > > v(V+10);
		for(int i=0;i<E;i++){
			ll s,t,d;
			cin >> s >> t >> d;
			v[s].push_back(make_pair(d,t));
		}
		priority_queue<P> Q;
		Q.push(P(0,r));
		for(int i=0;i<V;i++){
			C[i] = Inf;
		}
		C[r] = 0;
		while(!Q.empty()){
			P t = Q.top();
			ll s = t.second;
			Q.pop();
			if(C[s] < t.first) continue;
			for(int i=0;i<v[s].size();i++){
				P e = v[s][i];
				if(C[e.second] > C[s] + e.first){
					C[e.second] = C[s] + e.first;
					Q.push(make_pair(-C[e.second],e.second));
				}
			}
		}
		for(int i=0;i<V;i++){
			if(C[i] < Inf) cout << C[i] << endl;
			else cout << "INF" << endl;
		}
	}
}
#if 0
所要時間45分程度。ほとんどの部分はテキストを見ながら自力で書いたがうまくいかず，
蟻本(プログラミングコンテストチャレンジブック)(最近友人から譲ってもらった)を見て28行目を追加しAC
「確定しているので無視」ということの意味があまりわかっていなかったらしい。
#endif



Measured memory_bytes: 19400
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int n;
ll a[6000];
vector<int>E[6000];
int siz[6000];
ll dp[2][6000][6000];
bool dp2[2][6000][6000];

void dfs(int v,int p){
	for(int u:E[v]){
		if(u==p)continue;
		dfs(u,v);
	}
	int D=0;
	rep(i,n)dp[0][v][i]=INFL;
	dp[0][v][0]=a[v];
	if(a[v]>0)dp2[0][v][0]=true;
	siz[v]=1;
	for(int u:E[v]){
		if(u==p)continue;
		int a=(E[u].size()-1)%2;
		for(int i=siz[v]+siz[u];i>=0;i--){
			dp[!D][v][i]=INFL;
			dp2[!D][v][i]=false;
		}
		rep(i,siz[v]+1){
			rep(j,siz[u]+1){
				//切断する場合
				if(dp2[a][u][j]||dp[a][u][j]<0){
					dp[!D][v][i+j+1]=min(dp[!D][v][i+j+1],dp[D][v][i]);
					dp2[!D][v][i+j+1]|=dp2[D][v][i];
				}
				//切断しない場合
				dp[!D][v][i+j]=min(dp[!D][v][i+j],dp[D][v][i]+dp[a][u][j]);
				dp2[!D][v][i+j]|=(dp2[D][v][i]&dp2[a][u][j]);
			}
		}
		siz[v]+=siz[u];
		D=!D;
	}
}
int main(){
	scanf("%d",&n);
	rep(i,n)scanf("%lld",&a[i]);
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	dfs(0,-1);
	rep(i,n){
		if(dp[E[0].size()%2][0][i]<0||dp2[E[0].size()%2][0][i]==true){
			cout<<i<<endl;
			return 0;
		}
	}
}

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

const int MOD = (int)1e9+7;

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

	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			if(i*j==N){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

class Info:
    def __init__(self,arg_start,arg_end,arg_S):
        self.start = arg_start
        self.end = arg_end
        self.S = arg_S


LOC = []
POOL = []

line = input()
loc = 0
sum_S = 0

for ch in line:

    if ch == '\\':

        LOC.append(loc)

    elif ch == '/':

        if len(LOC) == 0:
            continue

        tmp_start = int(LOC.pop())
        tmp_end = loc
        tmp_S = tmp_end-tmp_start;
        sum_S += tmp_S;

        #既に突っ込まれている池の断片が、今回の断片の部分区間になるなら統合する
        while len(POOL) > 0:
            if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
                tmp_S += POOL[-1].S
                POOL.pop()
            else:
                break

        POOL.append(Info(tmp_start,tmp_end,tmp_S))

    else:
        pass

    loc += 1

print("%d"%(sum_S))
print("%d"%(len(POOL)),end = "")

while len(POOL) > 0:
    print(" %d"%(POOL[0].S),end = "") #先頭から
    POOL.pop(0)

print()


Measured memory_bytes: 7524
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(2);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 15;
const ll bits = 63;
const ll mod = 1e9+7;
const ld pi = 3.14159265358979323846;



int main(){
    // FASTIO;

    ll a,b;
    cin>>a>>b;

    cout<<(a*b)/__gcd(a,b)<<"\n";

    


    

}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bool ATCG(char p){
  return (p == 'A') or (p == 'T') or (p == 'G') or (p == 'C');
}
bool judge(string &s, int i, int j){
  for(int t = i; t <= j; t++){
    if(not ATCG(s.at(t))) return false;
  }
  return true;
}
int main(void){
  string s; cin >> s;
  int ans = -1;
  for(int i = 0; i < s.size(); i++){
    for(int j = i; j < s.size(); j++){
      if(judge(s, i, j)) chmax(ans, j - i);
    }
  }
  printf("%d\n", ans + 1);
  return 0;
}

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

ll f(ll A){
    if (A % 4 == 1) return 1;
    else if (A % 4 == 2) return (A ^ 1);
    else if (A % 4 == 3) return 0;
    else return A;
}

int main(){
    ll A, B;
    cin >> A >> B;

    cout << (f(max(0LL,A-1)) ^ f(B)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
 
using namespace std;
 

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

	int64_t x , k , d ; cin >> x >> k >> d;

	x = abs(x);

	int64_t dd = min(k , x / d);
	k -= dd;
	x -= dd * d;
	if(k & 1){
		cout << d - x << endl;
	}else cout << x << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
VI findAll(string S,string pattern){VI P;ll pos=(ll)S.find(pattern);
while(pos!=string::npos){P.push_back(pos);pos=(ll)S.find(pattern,pos+1);}return P;}
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
bool is_prime(ll n){if(n<2)return 0;for(int i=2;i*i<n;i++)if(n%i==0)return 0;return 1;}
inline void eratosthenes(VB& p){rep(i,SZ(p))p[i]=1;p[0]=p[1]=0;
rep(i,SZ(p)/2+1){if(p[i])for(ll j=i+i;j<SZ(p);j+=i)p[j]=0;}}
inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}// x^n%mod
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
using Graph=vector<vector<int> >;//int と P

map<ll,ll>prime_factor(ll n){
    map<ll,ll>res;
    for(ll i=2;i*i<=n;++i){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
    }
    if(n!=1)res[n]=1;
    return res;
}
int main(){
    ll a,b;cin>>a>>b;
    ll g=GCD(a,b);
    map<ll,ll>m=prime_factor(g);
    cout<<m.size()+1<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // get a integer
        int D = sc.nextInt();
        // get two integers separated with half-width break
        int T = sc.nextInt();
        int S = sc.nextInt();
        int res = T * S;
        System.out.print(res >= D ? "Yes": "No");
    }
}


Measured memory_bytes: 35636
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string s;
	int ans = 10000;
	cin >> s;
	REP(i, s.size() - 2) {
		string a = s.substr(i,3);
		int tmp = atoi(a.c_str());
		ans = min(ans, abs(753-tmp));
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
// Problem : 
// 			C - Walking Takahashi
// 			
// 		
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	if(d==x)
	{
		if(k%2!=0)
			cout<<0;
		else
			cout<<x;
	}
	else if(d<x)
	{
		ll c=x/d;
		if(k<=c)
			cout<<x-(k*d);
		else
		{
			if((k-c)%2==0)
				cout<<x-(c*d);
			else
				cout<<abs(x-((c+1)*d));
			
		}
	}
	else
	{
		ll z=d-x;
		if(k%2==0)
			cout<<x;
		else
			cout<<z;
	}
	cout<<"\n";
}

Measured memory_bytes: 3568