akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
#include <iomanip>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define ld long double
 
#define mp make_pair
#define pb push_back

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define ft first
#define sd second
#define endl "\n"
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
const long double pi=asin(1)*2;
 
const ll M=1000000007;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll pow1(ll a,ll b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=(res*a)%M;
		}
        a=(a*a)%M;
        b>>=1;
    }
    return res%M;
}
const ll N =100001;



int main()
{
	fast;
	int t;
	t=1;
//	cin>>t;
	while(t--)
	{
		ll h,w,m;
		cin>>h>>w>>m;
		ll x[h+1]={0};
		ll y[w+1]={0};
		ll e[m],f[m];
		rep(i,0,m){
			ll a,b;
			cin>>a>>b;
			e[i]=a;f[i]=b;
			x[a]++;
			y[b]++;
		}
		ll mxh=0;
		ll mxw=0;
		rep(i,0,h+1){
			mxh=max(mxh,x[i]);
		}
		rep(i,0,w+1){
			mxw=max(mxw,y[i]);
		}
		set<ll> v1;
		set<ll> v2;
		rep(i,1,h+1){
			if(x[i]==mxh){
				v1.insert(i);
			}
		}
		rep(i,1,w+1){
			if(y[i]==mxw){
				v2.insert(i);
			}
		}
		ll cnt1=v1.size();
		ll cnt2=v2.size();
		if(cnt1*cnt2>m){
			cout<<mxh+mxw<<endl;
		}
		else{
			set<pll> v3;
			for(auto i:v1){
				for(auto j:v2){
					v3.insert(mp(i,j));
				}
			}
			rep(i,0,m){
				if(v3.find(mp(e[i],f[i]))!=v3.end()){
					v3.erase(mp(e[i],f[i]));
				}
			}
			ll cnt3=v3.size();
			if(cnt3>0){
				cout<<mxh+mxw<<endl;
			}
			else{
				cout<<mxh+mxw-1<<endl;
			}
		}
	}
	return 0;
}

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

#define ll long long int

using namespace std;

int main() {
    ll h, w;
    cin >> h >> w;
    string grid[h + 1];
    for (ll i = 1 ; i <= h ; i++) {
        cin >> grid[i];
    }
    ll dp[h + 1][w + 1];
    if (grid[h - 1].at(w - 1) == '.') dp[h - 1][w] = 1;
    else dp[h - 1][w] = 0;
    if (grid[h].at(w - 2) == '.') dp[h][w - 1] = 1;
    else dp[h][w - 1] = 0;
    for (ll i = w - 2 ; i >= 1 ; i--) {
        if (grid[h].at(i - 1) != '#') {
            dp[h][i] = dp[h][i + 1];
        }
        else
        {
            dp[h][i] = 0;
        }
    }
    for (ll i = h - 2 ; i >= 1 ; i--) {
        if (grid[i].at(w - 1) != '#') {
            dp[i][w] = dp[i + 1][w];
        }
        else
        {
            dp[i][w] = 0;
        }
    }

    for (ll i = h - 1 ; i >= 1 ; i--) {
        for (ll j = w - 1 ; j >= 1 ; j--) {
            if (grid[i].at(j - 1) == '#') {
                dp[i][j] = 0;
            } else {
                ll moves = dp[i + 1][j] + dp[i][j + 1];
                moves = moves % 1000000007;
                dp[i][j] = moves;
            }
        }
    }
    cout << dp[1][1];
    return 0;
}

Measured memory_bytes: 9088
#include <stdio.h>

int main(void)
{
	int x, y;
	int t;
	int i;
	int s1;
	int s2;
	
	s1 = 0; s2 = 0;
	while (scanf("%d,%d,%d", &x, &y, &t) != EOF){
		if (x * x + y * y == t * t){
			s1++;
		}
		if (x == y){
			s2++;
		}
	}
	
	printf("%d\n%d\n", s1, s2);
	
	return (0);
}

Measured memory_bytes: 596
# AOJ 0087 Strange Mathematical Expression

def calc(s)
  data = s.split
  stack = []

  data.each do |d|
    case d
    when /\d+/
      stack.push d.to_f
    when "+"
      x, y = stack.pop(2)
      stack.push(x + y)
    when "-"
      x, y = stack.pop(2)
      stack.push(x - y)
    when "*"
      x, y = stack.pop(2)
      stack.push(x * y)
    when "/"
      x, y = stack.pop(2)
      stack.push(x / y)
    end
  end

  stack.pop
end

while line = gets
  line.chomp!
  puts calc(line)
end

Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> v;
    int n;
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        v.push_back(a);
    sum+=a;
    
    }


int sum1=0;
int sum2=sum;
    int min=INT_MAX;
for(int i=0;i<n;i++)
{
    sum1+=v[i];
    sum2-=v[i];
    if(abs(sum1-sum2)<min)
    min=abs(sum1-sum2);

}


    cout<<min;
    
    
    return 0;
}

Measured memory_bytes: 256
import sys
A = int(input())
B = int(input())

if A < 0 or A > 10 ** 100 or B < 0 or B > 10 ** 100:
    sys.exit()

if A - B > 0:
    print("GREATER")
if A - B == 0:
    print("EQUAL")
if A - B < 0:
    print("LESS")

Measured memory_bytes: 9088
from collections import defaultdict

def solve(n, S):
    counts = defaultdict(lambda: 0)
    for s in S:
        counts[''.join(sorted(list(s)))] +=  1
    total = 0
    for v in counts.values():
        if v > 1:
            total += int(v * (v - 1) / 2)
    return total

_n = int(input())
_S = [input() for _ in range(_n)]
print(solve(_n, _S))


Measured memory_bytes: 25316
import sys
input = sys.stdin.readline

def ppp(n,m,h,ab):
    g = [1] * n
    for l,r in ab:
        if h[l-1] >= h[r-1]:
            g[r-1] = 0
        if h[l-1] <= h[r-1]:
            g[l-1] = 0
    print(sum(g))
if __name__ == "__main__":
    n,m = map(int,input().split())
    h = list(map(int,input().split()))
    ab = [list(map(int,input().split())) for _ in range(m)]
    ppp(n,m,h,ab)


Measured memory_bytes: 31944
#include <bits/stdtr1c++.h>
// typedef __int128 int128;
// typedef __float128 float128;

using namespace std;
using namespace rel_ops;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ld> vd;
typedef vector<vd> vvd;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
#define pb push_back


int main(){

  // freopen("B.in", "r", stdin);

  ll L, R;
  cin >> L >> R;

  bool nf = true;
  for (ll i = L; i <= R; ++i) {
    if(i % 2019 == 0){
      cout << 0 << endl;
      nf = false;
      return 0;
    }
  }

  ll res = ((L % 2019) * ((L + 1) % 2019)) % 2019;
  for (ll i = L; i < R; ++i) {
    for (ll j = i + 1; j <= R; ++j) {
      ll ij = ((i % 2019) * (j % 2019)) % 2019;
      res = min(ij, res);
    }

  }

  cout << res << endl;

}


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

  int n;
  string in,temp;

  while(1){
    
    cin >>n;
    if(n == 0)break;

    int cnt=0;
    temp="ld";
    
    for(int i=0 ; i < n ; i++){

      cin >>in;
      
      if((temp == "ld" && in == "rd")||
	 (temp == "rd" && in == "ld")||
	 (temp == "lu" && in == "ru")||
	 (temp == "ru" && in == "lu")
	 )cnt++;
      
      temp=in;
    }
    
    cout <<cnt<<endl;
    
  }
  
  return 0;
}

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

int main() {
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0, d = 0;
    for (const auto &e : s) {
        a += (e == 'N');
        b += (e == 'W');
        c += (e == 'S');
        d += (e == 'E');
    }
    
    bool ss = ((a == 0 and c == 0) or (a and c));
    bool t = ((b == 0 and d == 0) or (b and d));
    cout << (ss and t ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
  ll a,b,c,d;cin>>a>>b>>c>>d;
  if((a+d-1)/d>=(c+b-1)/b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100000+5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(ll &f){
	f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
ll n,m;
ll a[DMAX];
ll p=1;
ll q;
ll LCM(ll x,ll y){
	return x*y/__gcd(x,y);
}
int main(){
	read(n),read(m);
	for(ll i=1;i<=n;i++){
		read(a[i]);
		p=LCM(p,a[i]);
	}
	q=p/2;
	if(q>m){
		cout<<0<<endl;
		return 0;
	}
	for(ll i=1;i<=n;i++){
		if((p/a[i])%2==0){
			cout<<0<<endl;
			return 0;
		}
	}
	cout<<(m-q)/p+1<<endl;
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC target ("avx2")
#pragma GCC optimize "trapv"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define input(a,n) for(ll i1=0;i1<n;i1++)cin>>a[i1]
#define ll long long
#define pi 2 * acos(0.0)
#define usll unordered_set<ll>
#define sll set<ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define umll unordered_map<ll,ll>
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define Y cout<< "YES"<< "\n"
#define N cout<< "NO"<< "\n"
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    string s="";
    while(n)
    {
       ll v=(n-1)%26;
       s+=(char)(v+97);
       n=(n-1)/26;
    }
    reverse(all(s));
    cout<<s;
    return 0;
}


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

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

  if (100 <= N) {
    N %= 100;
    N %= 10;
  } else if (10 <= N && N < 100) {
    N %= 10;
  }

  if (N == 3) {
    cout << "bon" << endl;
  } else if (N == 0 || N == 1 || N == 6 || N == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 1000000007
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin >> n;
	cout << n + (n * n) + (n * n * n) << endl;
}

Measured memory_bytes: 3648
K = []
S = []
N,M = map(int,input().split())
for i in range(M):
    tmp = [int(i) for i in input().split()]
    K.append(tmp[0])
    tmp.pop(0)
    S.append(tmp)
P = [int(i) for i in input().split()]
List = []
for i in range(2**N):
    tmp = []
    for j in range(N):
        if ((i>>j) & 1):
            tmp.append('1')
        else:
            tmp.append('0')
    List.append(tmp)

for i in range(M):
    kouho = []
    for j in range(len(List)):
        cnt = 0
        for k in range(len(List[j])):
            if List[j][k] == '1':
                if k+1 in S[i]:
                    cnt += 1
        if cnt % 2 != P[i] and not List[j] in kouho:
            kouho.append(List[j])
    for x in kouho:
        List.remove(x)
print(len(List))  




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

int main(){
        int n,i,idx,cnt;
        cin >> n;
        vector<int> a(n);
        vector<int> ans(n);
        for(i=0;i<n;++i){
                cin >> a.at(i);
                if(i>=n/2) ans.at(i) = a.at(i);
        }
        for(i=n/2-1;i>=0;--i){
                cnt = 0;
                idx = 2*i + 1;
                while(idx<n){
                        cnt += ans.at(idx);
                        idx += i+1;
                }
                if(cnt%2==0) ans.at(i) = a.at(i);
                else ans.at(i) = (a.at(i)+1)%2;
        }
        cout << cnt+ans.at(0) << endl;
        for(i=0;i<n;++i) if(ans.at(i)==1) cout << i+1 << " ";
        cout << endl;
        return 0;
}

Measured memory_bytes: 4812
//15
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>

using namespace std;

int x,y;

struct S{
  int t;
  vector<char> g;
};

void ff(vector<char> &g,int xx,int yy,char c,char sc){
  if(xx<0||x<=xx||yy<0||y<=yy||sc!=g[yy*x+xx])return;
  g[yy*x+xx]=c;
  for(int i=0;i<4;i++){
    int d[]={0,1,0,-1,0};
    ff(g,xx+d[i],yy+d[i+1],c,sc);
  }
}

int main(){
  while(cin>>x>>y,x|y){
    vector<char> g(y*x);
    for(int i=0;i<y*x;i++){
      cin>>g[i];
    }
    queue<S> que;
    S is={0,g};
    que.push(is);
    for(;;){
      S cs=que.front();
      char l='Z',h='A';
      for(int i=0;i<y*x;i++){
	l=min(l,cs.g[i]);
	h=max(h,cs.g[i]);
      }
      if(l==h)break;
      que.pop();
      for(int i=0;i<3;i++){
	const char *c="RGB";
	if(c[i]==cs.g[0])continue;
	S ns={cs.t+1,cs.g};
	ff(ns.g,0,0,c[i],ns.g[0]);
	que.push(ns);
      }
    }
    cout<<que.front().t<<endl;
  }
  return 0;
}

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

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

const int N = 500000;

int n, k, x, a[N];
vector<pii> cnt;

signed main()
{
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
    cin >> n >> k;
    forn(i, n) cin >> x, a[x]++;
    sort(a, a + n + 1);
    int si = 0;
    forn(i, n - k + 1) si += a[i];
    cout << si;
}


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

int main() {
  int n;
  cin >> n;
  int w[n];
  for ( int i = 0; i < n; i++ ) {
    cin >> w[i];
  }
  int min = 100000, s1, s2;
  for ( int i = 0; i < n; i++ ) {
    int j;
    s1 = 0;
    s2 = 0;
    for ( j = 0; j <= i; j++ ) {
      s1 += w[j];
    }
    for ( ; j < n; j++ ) {
      s2 += w[j];
    }
    min = ( min > abs(s1-s2) ) ? abs(s1-s2) : min;
  }

  cout << min << endl;
  return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

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

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, W;
    cin >> H >> W;
    int N; cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    int ans[H][W]; rep(i, H) rep(j, W) ans[i][j] = -1;
    int dir = 0;
    int paint = 0;
    int x = 0, y = 0;
    if(W > 1){
        rep(i, H*W){
            ans[x][y] = paint+1;
            A[paint]--;
            if(A[paint] == 0) paint++;
            if(y == W-1 && dir == 0) dir = 3;
            else if(y == W-1 && dir == 3) dir = 2;
            else if(y == 0 && dir == 2) dir = 3;
            else if(y == 0 && dir == 3) dir = 0;
            x += dx[dir]; y += dy[dir];
        }
        rep(i, H){
            rep(j, W) cout << ans[i][j] << " "; cout << endl;
        }
    }
    else{
        rep(i, H){
            cout << paint+1 << endl;
            A[paint]--;
            if(A[paint] == 0) paint++;
        }
    }
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int MAX_N = 1e5 + 10;
struct edge { int to, cost; };
vector<edge> G[MAX_N];
int solve(int n)
{
    int res = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, 0));
    bool used[n + 1] = {};
    while(not que.empty())
    {
        int w = que.top().first;
        int v = que.top().second;
        que.pop();
        if(used[v]) continue;
        used[v] = true;
        res += w;
        for(int u = 0; u < G[v].size(); u++)
        {
            edge e = G[v][u];
            if(not used[e.to]) que.push(P(e.cost, e.to));
        }
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<P> px, py;
    for(int i = 0; i < n; i++)
    {
        int x, y; cin >> x >> y;
        px.push_back(P(x, i));
        py.push_back(P(y, i));
    }
    sort(px.begin(), px.end());
    sort(py.begin(), py.end());
    for(int i = 0; i < n - 1; i++)
    {
        int cost1 = px[i + 1].first - px[i].first;
        G[px[i].second].push_back({px[i + 1].second, cost1});
        G[px[i + 1].second].push_back({px[i].second, cost1});
        int cost2 = py[i + 1].first - py[i].first;
        G[py[i].second].push_back({py[i + 1].second, cost2});
        G[py[i + 1].second].push_back({py[i].second, cost2});
    }
    cout << solve(n) << endl;
    return 0;
}

Measured memory_bytes: 11116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
int main(){
    int n;
    list<int> arr;
    cin >> n;
    for(int i = 0; i < n; ++i){
        int a;
        scanf("%d",&a);
        if(i%2 == 0)
            arr.push_back(a);
        else
            arr.push_front(a);
    }
    if(n%2 == 1)
        reverse(arr.begin(),arr.end());
    for(int x : arr)
        printf("%d ",x);
    cout << '\n';
}


Measured memory_bytes: 8448
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    if (n % 2) {
        if (s[0] != s[n-1]) cout << "First" << endl;
        else cout << "Second" << endl;
    } else {
        if (s[0] == s[n-1]) cout << "First" << endl;
        else cout << "Second" << endl;
    }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 512
s = str(input())
# 1|2|3|4| Each vertical bar corresponds bit flag
all = []
for b in range(1 << len(s)-1):
    sub = []
    l = 0
    b |= 1 << len(s)-1
    for r in range(len(s)):
        if b & (1 << r):
            sub.append(int(s[l: r+1]))
            l = r+1
    all.append(sum(sub))

print(sum(all))


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

int main(){
  char fg,fd;
  string sen;
  getline(cin,sen);
  cin >> sen;
  for(int i = 0;i<sen.size();i++){
    fg = sen.at(i);
    if(isalpha(fg)){
      if(islower(fg))fd = toupper(fg);
      else if(isupper(fg))fd = tolower(fg);
      cout << fd;
      continue;
    }
    cout << fg;
  }
  cout << endl;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

vector<int> a;
int n,m;
vector<bool> d(300);

void saiki(vector<int> a,vector<bool> &u,int p){
    if(u[p]) return ;
    u[p] = true;
    for(int i=1;i<=m;i++){
	int temp = min(n+1,p+i);
	temp = max(min(temp+a[temp],n+1),0);
	saiki(a,u,temp);
    }
}

int main(){
    while(true){
	fill(ALL(d),true);
	a = vector<int>(0);
	cin >> m;
	if(m == 0) break;
	cin >> n;
	a.PB(-300);
	REP(i,n){
	    int temp;
	    cin >> temp;
	    a.PB(temp);
	}
	a.PB(300);
	vector<bool> u(a.size(),false);
	saiki(a,u,0);
	bool ans = true;
	if(!u[u.size()-1]) cout << "NG"<< endl;
	else{
	    u[u.size()-1] = false;
	    RREP(i,n+2){
		if(u[i]){
		    vector<bool> used(u.size(),false);
		    queue<int> q;
		    q.push(i);
		    while(!q.empty()){
			int x = q.front();
			q.pop();
			if(x == a.size()-1) {
			    u[x] = true;
			    break;
			}
			for(int i=1;i<=m;i++){
			    int nx = x + i;
			    if(a.size()<=nx) nx = a.size()-1;
			    nx = min((int)(a.size()-1),a[nx] + nx);
			    nx = max(nx,0);
			    if(!used[nx]){
				used[nx] = true;
				q.push(nx);
			    }
			}
		    }
		    if(!used.back()){
			ans = false;
			break;
		    }
		}
	    }
	    if(ans) cout << "OK"<<endl;
	    else cout << "NG" << endl;
	}
    }
    return 0;
}

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

using namespace std;

const int N = 1e4+5;
const int A = 1e9+5;
int a, n;

int main() {
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		while ((a & 1) == 0) {
			a >>= 1;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

arr=Set{Int}()
function dfs(s)
    push!(arr,parseInt(s))
    if length(s)>10
        return 0
    else
        for i in max(s[end]-1,'0'):min(s[end]+1,'9')
            dfs(s*string(i))
        end
    end
end

function main()
    k=parseInt(readline())
    for i in '1':'9'
        dfs(string(i))
    end
    println(sort(collect(arr))[k])
end
main()

Measured memory_bytes: 198876
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "abc161_d.cpp"

// cur: 今見てる数字 res: 残りの桁数, num: 何番目か
pair<int, pair<ll, bool>> dfs(ll cur, int res, int num, int k) {
  if (res == 0) {
    num++;
    if (num == k) {
      return {num, {cur, true}};
    } else {
      return {num, {cur, false}};
    }
  }

  REP(i, 3) {
    ll nCur = cur + i - 1;
    if (nCur < 0 || nCur > 9)
      continue;
    auto val = dfs(nCur, res - 1, num, k);
    if (val.second.second) {
      ll tmp = cur;
      REP(i, res) { tmp *= 10; }
      return {num, {val.second.first + tmp, true}};
    } else {
      num = val.first;
    }
  }
  return {num, {cur, false}};
}

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

  int num = 0;
  FOR(i, 1, 11) {
    FOR(l, 1, 10) {
      ll cur = l;
      auto val = dfs(cur, i - 1, num, k);
      if (val.second.second) {
        cout << val.second.first << endl;
        return 0;
      } else {
        num = val.first;
      }
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int main(){
    vector<PL> a(4);
    ll n;
    REP(i,4) cin >> a[i].first;
    cin >> n;
    n *= 4;
    a[0].second = 1;
    a[1].second = 2;
    a[2].second = 4;
    a[3].second = 8;
    REP(i,4) a[i].first *= 8 / a[i].second;
    sort(ALL(a));
    REP(i,4) a[i].first /= 8 / a[i].second;
 
    ll ans = 0;
    REP(i,n){
        ll x = n / a[i].second;
        n -= x * a[i].second;
        ans += x * a[i].first;
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


class Ruiseki_lr:
    """左右からの畳み込みをそれぞれ計算する"""
    def __init__(self, array, op, e):
        self.op = op
        self.e = e

        n = len(array)
        self.left = [e] * (n + 1)
        self.right = [e] * (n + 1)
        for i in range(n):
            self.left[i + 1] = self.op(self.left[i], array[i])
        for i in reversed(range(n)):
            self.right[i] = self.op(self.right[i + 1], array[i])

    def get_left(self, p):
        """区間[0, p)の畳み込み結果を返す"""
        return self.left[p]

    def get_right(self, p):
        """区間[p, n)の畳み込み結果を返す"""
        return self.right[p]

    def fold(self, p):
        """p番目を除いた区間[0, n)の畳み込み結果を返す"""
        return self.op(self.left[p], self.right[p + 1])


n = int(input())
a = list(map(int, input().split()))
ru = Ruiseki_lr(a, gcd, 0)

ans = 0
for i in range(n):
    ans = max(gcd(ru.get_left(i), ru.get_right(i + 1)), ans)
print(ans)

Measured memory_bytes: 63984
n=int(input())
a=list(map(int,input().split()))
a.sort()
t=0
for i in range(n):
  ans=0
  while True:
    if t==n-1:
      print(ans)
      break
    if a[t]==i+1:
      t=t+1
      ans=ans+1
    else:
      print(ans)
      break
    

Measured memory_bytes: 32360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,m,cap;
  while(cin>>n>>m>>cap,n||m||cap){
    map<string,int> ms;
    string src,dst;
    cin>>src>>dst;
    ms[src]=0;ms[dst]=1;
    vector<P> G[10000];
    for(int i=0;i<n;i++){
      string a,b;
      int c;
      cin>>a>>b>>c;
      if(!ms.count(a)){int k=ms.size();ms[a]=k;}
      if(!ms.count(b)){int k=ms.size();ms[b]=k;}
      G[ms[a]].push_back(P(ms[b],c));
      G[ms[b]].push_back(P(ms[a],c));
    }
    
    int v=ms.size(),inf=1<<25;
    int dp[m+2][v];
    vector<string> vs(m+2);
    for(int i=0;i<m+2;i++){
      for(int j=0;j<v;j++) dp[i][j]=inf;
      if(i<m) cin>>vs[i];
      else if(i==m) vs[i]=src;
      else vs[i]=dst;
      int u=ms[vs[i]];
      priority_queue<P> q;
      dp[i][u]=0;
      q.push(P(0,u));
      while(!q.empty()){
	P p=q.top();q.pop();
	int x=p.second;
	if(dp[i][x]<-p.first) continue;
	for(P y:G[x]){
	  if(dp[i][x]+y.second<dp[i][y.first]){
	    dp[i][y.first]=dp[i][x]+y.second;
	    q.push(P(-dp[i][y.first],y.first));
	  }
	}
      }
    }

    int e[m+2][m+2];
    for(int i=0;i<m+2;i++)
      for(int j=0;j<m+2;j++)
	e[i][j]=inf*(i!=j);

    for(int i=0;i<m+2;i++)
      for(int j=0;j<m+2;j++)
	if(dp[i][ms[vs[j]]]<=cap*10)
	  e[i][j]=dp[i][ms[vs[j]]];
    
    for(int k=0;k<m+2;k++)
      for(int i=0;i<m+2;i++)
	for(int j=0;j<m+2;j++)
	  e[i][j]=min(e[i][j],e[i][k]+e[k][j]);

    cout<<(e[m][m+1]<inf?e[m][m+1]:-1)<<endl;
    
  }
  return 0;
}

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

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

    int a=0, u=0;
    rep(i, n) {
        string t;
        cin >> t;

        if (t == "A") a++;
        if (t == "Un") u++;

        if (a < u) {
            cout << "NO" << endl;
            return 0;
        }

    }

    cout << (a == u ? "YES" : "NO") << endl;

}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int N; cin >> N;
  cout << (N-2)*180 << endl;  
  return 0;
}

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

int main()
{
    std::string str;
    std::cin >> str;
    const int n = str.size() - 1;

    int64_t sum = 0;
    // 右端は常に1桁目
    // 右から2番目は50%ずつで1桁と2桁
    // 右から3番目は50%は1桁、25%ずつで2桁と3桁
    // 右から4番目は50%は1桁、25%は2桁、12.5%ずつで3桁と4桁
    for (int i = 0; i < str.size(); ++i)
    {
        int64_t scale = 1;
        for (int j = 0; j < i; ++j)
        {
            sum += scale * (str[str.size() - 1 - i] - '0') * (1 << (n - j - 1));
            scale *= 10;
        }
        sum += scale * (str[str.size() - 1 - i] - '0') * (1 << (n - (i - 1) - 1));
    }
    std::cout << sum << std::endl;
    return 0;
}


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


void solve(long long X){
    ll X0 = X;
    if(X == 1) {
        cout << 1 << endl;
        return;
    }
    ll i=1;
    for(; ; i++){
        X -= i;
        if(X <=0) break;
    }
    cout << i << endl;
    //* X is one solution;
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use itertools::Itertools;

#[fastout]
fn main() {
  input! {
    k: i64,
  }
  let mut sum = 0;
  for a in 1 ..= k {
    for b in 1 ..= k {
      let g = a.gcd(&b);
      for c in 1 ..= k {
        sum += g.gcd(&c);
      }
    }
  }

  println!("{}", sum);
}


Measured memory_bytes: 2164
import java.util.Scanner;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		int x[] = new int[n];
		int sum[] = new int[n+1];
		for(int i=0; i<n; i++) {
			x[i]=sc.nextInt();
			sum[i+1]=sum[i]+x[i];
		}
		long ans = Long.MAX_VALUE;
		for(int i=0; i<n-k+1; i++) {
			int r = Math.abs(x[i+k-1]-x[i]);
			int cnt = Math.min(Math.abs(x[i])+r, Math.abs(x[i+k-1])+r);
			ans = Math.min(ans, cnt);
		}
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 50268
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, A, B, C):
    d = defaultdict(lambda : sys.maxsize)
    # @lru_cache(maxsize=None)
    def f(t, v):
        if v >= d[t]:
            return sys.maxsize
        else:
            d[t] = v
        n = None
        for i in range(N):
            if  (1 << i) & t == 0:
                n = i + 1
                break
        else:
            return v

        ret = sys.maxsize
        for i, c in enumerate(C):
            if n in c:
                t_  = t
                for j in c:
                    t_ |= 1 << (j-1)
                ret = min(ret, f(t_, v + A[i]))
        return ret
    ans = f(0, 0)
    return  ans if ans != sys.maxsize else -1


def main():
    N, M = read_int_n()
    A = []
    B = []
    C = []
    for _ in range(M):
        a, b = read_int_n()
        A.append(a)
        B.append(b)
        C.append(set(read_int_n()))

    print(slv(N, M, A, B, C))

    # N = 12
    # M = 10**3
    # A = [random.randint(1, 10**5) for _ in range(M)]
    # B = [random.randint(1, N) for _ in range(M)]
    # C = [set([random.randint(1, N)]) for _ in range(M)]
    # print(slv(N, M, A, B, C))


if __name__ == '__main__':
    main()


Measured memory_bytes: 66136
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#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>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    ll k;
    cin >> s >> k;
    for (int i = 0; i < min((ll)s.size(), k); ++i) {
      if (s[i] >= '2') {
        cout << s[i] << '\n';
        return 0;
      }
    }
    cout << '1' << '\n';
    return 0;
}


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

public class Program{
    public static void Main(){
        int N=int.Parse(Console.ReadLine());
        int[] d=Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        int ans=0;
        Array.Sort(d);
        ans=d[N/2]-d[N/2-1];
        Console.WriteLine(ans);
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));
  rep(i, 2) {
    rep(j, n) cin >> a[i][j];
  }

  vector<int> A(n), B(n);
  int asum = 0;
  int bsum = 0;
  rep(i, n) {
    asum += a[0][i];
    bsum += a[1][i];
    A[i] = asum;
    B[i] = bsum;
  }
  int ans = A[0] + B[n-1];
  rep(i, n-1) ans = max(ans, A[i+1] + B[n-1] - B[i]);
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    L = [int(x) for x in input().split()]

    L.sort()
    ans = 0
    for i in range(0, N * 2, 2):
        ans += L[i]

    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll i,j,ans=0,H,W,K;cin>>H>>W>>K;
  char C[H][W];
  REP(i,H)REP(j,W)cin>>C[i][j];
  REP(i,1<<H)REP(j,1<<W){
    ll p,q,res=0;
    REP(p,H)REP(q,W)if(C[p][q]=='#'&&!(i&(1<<p))&&!(j&(1<<q)))res++;
    if(res==K)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <algorithm>
#include <stack>
using namespace std; 
int main(){
	int N, Q; cin >> N >> Q; 
	string S;
	cin >> S; 
	char T[200010] = {}; 
	char D[200010] = {}; 
	for(int i = 0; i < Q; i++){
		cin >> T[i] >> D[i]; 
	}
	int left = 0; int right = N; //左右から落ちる境界
	for(int i = Q - 1; i >= 0; i--){
		if(D[i] == 'L' && left <= N-1 && T[i] == S.at(left)){
			left ++; 
		} 
      	else if(D[i] == 'R' && left >= 1 && T[i] == S.at(left-1)){
			left --; 
		} 
		if(D[i] == 'R' && right >= 1 && T[i] == S.at(right-1)){
			right --; 
		} 
      	else if(D[i] == 'L' && right <= N-1 && T[i] == S.at(right)){
			right ++; 
		} 
      //cout << left << " " << right << endl; 
	} 
	cout << right - left << endl; 
}

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

int x,y,t;

while(1){

scanf("%d %d",&x,&y);

if(x==0&&y==0)break;


if(x>y){
t=x;
x=y;
y=t;
}

printf("%d %d\n",x,y);

}
return 0;
}


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) if (a[i] == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    rep(i, n) {
        if (ans > (ll)1e18 / a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t solve(int64_t left,int64_t right,int64_t n,vector<int64_t> &a,vector<int64_t> &b,int64_t k){
  int64_t mid=(left+right)/2;
  if(mid==left){
    int64_t cnt=0;
    rep(i,n){
      if(a[i]*b[n-i-1]>mid)cnt+=b[n-1-i]-(mid/a[i]);
    }
    if(cnt<=k)return mid;
    else return right;
  }
  int64_t cnt=0;
  rep(i,n){
    if(a[i]*b[n-i-1]>mid)cnt+=b[n-1-i]-(mid/a[i]);
  }
  if(cnt<=k)return solve(left,mid,n,a,b,k);
  else return solve(mid,right,n,a,b,k);
}

int main(){
  int64_t n,k;
  cin >> n >> k;
  vector<int64_t> b(n,0);
  vector<int64_t> a(n,0);
  vector<int> c(n,0);
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> a[i];
  int64_t t=0;
  rep(i,n)t+=b[i];
  if(t<=k){
    cout << 0 << endl;
    return 0;
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  /*rep(i,n){
    c[i]=a[i]*b[n-i-1];
  }*/
  cout << solve(0,1100000000001,n,a,b,k) << endl;
}


Measured memory_bytes: 4096
digit, m = map(int, input().split())

rules = []
for _ in range(m):
    rules.append(list(map(int, input().split())))

numlst = [ -1 for _ in range(digit) ]

for rule in rules:
    numindex = rule[0] - 1
    # ルールの重複
    if numlst[numindex] != -1 and numlst[numindex] != rule[1]:
        print(-1)
        exit()
    numlst[numindex] = rule[1]

# 先頭が０の場合
if digit > 1 and numlst[0] == 0:
    print(-1)
    exit()


# 先頭がマイナス１かつ２ケタ以上の場合、０ではなく１にする
if digit > 1 and numlst[0] == -1:
    numlst[0] = 1

# 文字列の組み立ておよび出力
for n in numlst:
    if n == -1:
        n = 0
    print(n, end="")
print()

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
  char A, B;
  scanf("%c %c\n", &A, &B);
  A = (int)A;
  B = (int)B;
  if (A - B > 0) printf(">\n");
  else if(A - B < 0) printf("<\n");
  else printf("=\n");
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void) {
    int kind[10],i,j,temp,num;
    while (1) {
        scanf("%d",&num);
        if (num==0) break;
        for (i=0; i<10; i++) kind[i]=0;
        for (i=0; i<num; i++) {
            scanf("%d",&temp);
            kind[temp]++;
        }
        for (i=0; i<10; i++) {
            if (kind[i]==0) {
                printf("-\n");
            } else {
                for (j=0; j<kind[i]; j++) printf("*");
                printf("\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 572
use proconio::input;
use std::collections::HashMap;

fn get_count_map(arr: &Vec<i64>) -> HashMap<i64, i64> {
    let mut hm: HashMap<i64, i64> = HashMap::new();

    for val_ref in arr.iter() {
        let val = *val_ref;
        match hm.get(val_ref) {
            Some(cnt_ref) => {
                let cnt: i64 = *cnt_ref + 1;
                hm.insert(val, cnt);
            }
            None => {
                hm.insert(val, 1);
            }
        }
    }

    hm
}

#[allow(non_snake_case)]
fn main() {
    input! {
        N: i64,
        Ds: [i64; N],
    }

    let MOD: i64 = 998244353;
    let hm = get_count_map(&Ds);

    if Ds[0] != 0 {
        println!("0");
        return;
    }

    if *hm.get(&0).unwrap() != 1 {
        println!("0");
        return;
    }

    // 距離0は自動的に決まるから除外
    let mut distances: Vec<i64> = Vec::new();

    for disntace_ref in hm.keys() {
        let distance = *disntace_ref;
        if distance != 0 {
            distances.push(distance);
        }
    }
    distances.sort();

    // 1から順に見ていこう
    let mut ans = 1;
    for distance_ref in distances.iter() {
        let distance = *distance_ref;

        match (hm.get(&distance), hm.get(&(distance-1))){
            (None, _) | (_, None) => {
                println!("0");
                return;
            }

            (Some(current), Some(last)) => {
                // eprintln!("{} {} {} {}", distance, last, current, ans);
                let mut po = 1;
                for _ in 0..*current {
                    po = (po * last) % MOD;
                }

                ans = (ans * po) % MOD;
            }
        }
    }

    println!("{}", ans);
}


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

int main(){
    bool nonprime[120000] = {};
    vector<int> prime;
    for(int i = 2; i < 120000; i++){
        if(!nonprime[i]){
            prime.push_back(i);
            for(int j = i+i; j < 120000; j += i)    nonprime[j] = true;
        }
    }

    int n, p;

    while(cin >> n >> p, n+p != -2){
        vector<int> use;
        auto it = upper_bound(prime.begin(), prime.end(), n);
        for(int i = 0; i < 100; i++) use.push_back(*it), it++;

        vector<int> sum;
        for(int i = 0; i < 100; i++) for(int j = i; j < 100; j++) sum.push_back(use[i]+use[j]);
        sort(sum.begin(), sum.end());

        cout << sum[p-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int c = b - a - 1;
    cout << (1 + c) * c / 2 - a << endl;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(){
  long long n,a,b;
  cin >>n>>a>>b;
  if(a==0){cout <<0; return 0;}
  long long number=(n/(a+b))*a;
  if (n%(a+b) !=0){if(n%(a+b)>=a){number=number+a;}else{number=number+n%(a+b);}}
  cout <<number;}

Measured memory_bytes: 256
# tenka1-2018-beginnerB - Exchange
def main():
    A, B, K = tuple(map(int, input().split()))
    for i in range(K):
        if i & 1 == 0:
            if A & 1:
                A -= 1
            A //= 2
            B += A
        else:
            if B & 1:
                B -= 1
            B //= 2
            A += B
    print(A, B)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int main(){
    long double a;
    cin >> a;
    long double r = (a/3);
    long double ans = r*r*r;
    cout << fixed;
    cout << setprecision(12) << ans << "\n";
}

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

int main()
{
    int n[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << n[k - 1] << endl;
}

Measured memory_bytes: 256
// D - Sum of Divisors

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;


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

	ll ans = 0;

	for (int j=1; j<=N; j++) {
		/*
		cout << "j=" << j;
		for (int i=1; i<=N; i++) {
			if (i % j == 0) {
				ans += i;
				cout << " " << i;
			}
		}
		cout << endl;
		*/

		// 等差数列の和
		ll n = N / j;
		ll a = j;
		ll l = a + j * (n-1);

		ans += n * (a + l) / 2;
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3672
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = input.trim().split(" ").map(a=>~~a);
  
  var a = input[0];
  var b = input[1];
  
  var c = -1000000;
  
  c = Math.max(c,a+b);
  c = Math.max(c,a-b);
  c = Math.max(c,a*b);
  
  return parseInt(c,10);
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
-1000 1000
`);

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

ans = 0
for i in range(N):
    # i番目の街のモンスターを倒す
    ans += min(A[i], B[i])
    nb = B[i] - min(A[i], B[i])
    # i+1番目の街のモンスターを倒す
    ans += min(A[i+1], nb)
    A[i+1] -= min(A[i+1], nb)
print(ans)

Measured memory_bytes: 18624