akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a + c <= b + d && a + c <= a + d && a + c <= b + c)
    cout << a + c;
  else if(a + d <= b + c && a + d <= a + c && a + d <= b + d)
    cout << a + d;
  else if(b + c <= a + d && b + c <= b + d && b + c <= a + c)
    cout << b + c;
  else if(b + d <= a + c && b + d <= a + d && b + d <= b + c)
    cout << b + d;
  return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define MAX_N 100000000
#define INF 1000000000

int main(){
  long long n,k;
  cin >> n >> k;
  long long t[n],d[n],f[n+1],s[n+1];
  for(int i=0;i<n;i++){
    cin >> t[i] >> d[i];
    f[i] = 0;
    s[i] = 0;
  }
  f[n] = 0;
  s[n] = 0;
  priority_queue<pair<long long, long long> > uneat;
  priority_queue<pair<long long, long long> , vector<pair<long long, long long> >, greater<pair<long long, long long> > > eat;
  for(int i=0;i<n;i++){
    uneat.push(make_pair(d[i],t[i]));
  }
  long long count = 0;
  pair<long long, long long> sushi;

  for(int i=0;i<k;i++){
    sushi = uneat.top();
    eat.push(sushi);
    uneat.pop();
    count += sushi.first;
    s[sushi.second] += 1;
  }

  long long start = 0;
  for(int i=0;i<n+1;i++){
    if(s[i] > 0) start += 1;
  }
  f[start] = count;
  int end = k+1;

  for(int i=start+1;i<k+1;i++){
    while(!eat.empty() && (s[eat.top().second] < 2) ){
      sushi = eat.top();
      eat.pop();
    }
    if(!eat.empty()){
      sushi = eat.top();
      eat.pop();
      f[i] = f[i-1] - sushi.first;
      s[sushi.second] -= 1;
    }
    else{
      end = i;
      break;
    }

    while(!uneat.empty() && (s[uneat.top().second] != 0)){
      sushi = uneat.top();
      uneat.pop();
    }

    if(!uneat.empty()){
      sushi = uneat.top();
      uneat.pop();
      eat.push(sushi);
      f[i] += sushi.first;
      s[sushi.second] += 1;
    }
    else{
      end = i;
      break;
    }
  }

  long long ans = 0;
  for(long long i=start;i<end;i++){
    if(f[i] > 0) ans = max(ans,f[i]+i*i);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8048
N = int(input())
A_list = []
for _ in range(N):
    A_list.append(int(input()))

A_list_cp = sorted(A_list)
max_1, max_2 = A_list_cp[-1], A_list_cp[-2]

for i in range(N):
    if A_list[i] == max_1:
        print(max_2)
    else:
        print(max_1)


Measured memory_bytes: 14112
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;



int main(){
    int a[10],k;
    rep(i,5) cin>>a[i];
    cin>>k;
    if(a[4]-a[0]>k) cout <<":("<<endl;
    else cout <<"Yay!"<<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;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll x, y;
    cin >> x >> y;
    ll ans = 1;
    ll t = x;
    while (t < y) {
        t *= 2;
        ans++;
    }
    if (t > y)
        ans--;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int maxn = 200005;
int f[maxn];

inline void work() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> f[i];
    }
    sort(f, f + n);
    LL res = f[n - 1];
    int k = 0;
    if (n > 2) {
        for (int i = n - 2; i >= 0; --i) {
            res += f[i];
            k++;
            if (k == n - 2) break;
            res += f[i];
            k++;
            if (k == n - 2) break;
        }
    }
    cout << res << endl;
}

int main() {
    // freopen(".txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 4368
n,a,b,c=gets.split.map &:to_i
s=[]
n.times do |i|
  s[i]=gets.to_i
end
ans=a+b+c
[1,2,3,4].repeated_permutation(n).to_a.each{|j|
  x=a;y=b;z=c
  a1=0;b1=0;c1=0
  kai=0
  n.times do |u|
    if j[u]==1
      kai+=10 if a1==1
      (x-=s[u])
      a1=1
    elsif j[u]==2
      kai+=10 if b1==1
      (y-=s[u])
      b1=1
    elsif j[u]==3
      kai+=10 if c1==1
      (z-=s[u])
      c1=1
    end
  end
  kai+=(x.abs+y.abs+z.abs)
  next if a1+b1+c1 !=3
  ans=[ans,kai].min
}
puts ans


Measured memory_bytes: 21784
/*   __             __  ___        __   ___      ___
	|  \  |  |  |  /   |    |\  | |  \ |    | / |   | \    /
	|   | |  |  |  \   |--- | \ | |--/ |--- |-  |   |  \  /
	|__/  |__|  | __\  |___ |  \| |__/ |___ | \ |___|   \/
	
*/
/*                 
  	 	        / \   \  /   / \   |\  |
  	     	   /---\   \/   /---\  | \ |
  	          /     \  /   /     \ |  \|
*/   
#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back
#define sz(a) (int)(a.size())
#define F first
#define S second
#define mp make_pair
#define ld long double
#define ll long long
#define pii pair<int, int> 
#define forki for(int i = 1; i <= (int)k; i++)
#define forni for(int i = 1; i <= (int)n; i++)
#define fornk for(int k = 1; k <= (int)n; k++)
#define git return 0;
using namespace std;
const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;
int a, b, c;
int main()
{
	cin>>a>>b>>c;
	if(a == b)
		cout<<c;
	else if(c == b)
		cout<<a;
	else if(a == c)
		cout<<b;
	git
}

Measured memory_bytes: 256
# ABC 051 D
INF = 7+10**9
N, M = map(int,input().split())
P = []
D = [[INF for k in range(N)] for l in range(N)]
for k in range(N):
    D[k][k] = 0
for k in range(M):
    a, b, c = map(int,input().split())
    P.append([a-1,b-1,c])
    D[a-1][b-1] = c
    D[b-1][a-1] = c

# Floyd-Warshall
for k in range(N):
    for l in range(N):
        for m in range(N):
            D[l][m] = min(D[l][m], D[l][k]+D[k][m])

ans = M
for p in P:
    a, b, c = p[0], p[1], p[2]
    for k in range(N):
        if D[a][k] + c == D[b][k]:
            ans -= 1
            break 
print(ans)


Measured memory_bytes: 41836
<?php
	$set = 3;
	while (true) {
		$count = 0;

		$result = trim(fgets(STDIN));
		list($n, $x) = explode(" ", $result);

		if ($n == 0 && $x == 0) break;

		pattern($n, $x, array(), 1, $n-$set+1, $count);

		print "$count\n";
	}

	function pattern($n, $x, $sub, $begin, $end, &$count) {
		$arr = array();
		for ($i = $begin; $i <= $end; $i++) {
			$tmp = array_merge($sub, array($i));
	 		if ($end < $n) {
	 			$arr = array_merge($arr, pattern($n, $x, $tmp, $i+1, $end+1, $count));
			} else {
				if (array_sum($tmp) == $x) $count++;
			}
		}

		return $arr;
	}

Measured memory_bytes: 6632
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll h, w; cin >> h >> w;
  if (h == 1 || w == 1){
      say(1)
      return 0;
  }
  
  if((h*w)%2 == 0){
      say(h*w/2)
  }else{
      say((h*w/2) + 1)
  }
}

Measured memory_bytes: 256
def resolve():
    # 隣り合う要素の差を大きくするには、大きい数と小さい数が交互に現れればよい。
    # 数列をsortして両端から交互に要素を取り、並べていく
    # 並べ方のパターン
    # 大きい方から並べるか小さい方から並べるか
    # 最後に並べる数字を左端におくか右端におくか

    # 全パターン試す

    N = int(input())
    A = sorted([int(input()) for _ in range(N)])

    # 左から、大小大小大小に並べる(右に要素を付け足す)
    # 最後に余った要素をどっちの両端に追加するか試す
    res1 = 0
    left = 0
    right = N - 1
    i = 0
    while (right - left) > 1:
        res1 += abs(A[right] - A[left])
        if i % 2 == 0:
            right -= 1
        else:
            left += 1
        i += 1
    if N % 2 == 1:
        # res1 = max(左端、右端)
        res1 += max(abs(A[N - 1] - A[right]), abs(A[left] - A[right]))
    else:
        res1 += max(abs(A[N - 1] - A[left]), abs(A[right] - A[left]))

    # 右から、小大小大小に並べる(左に要素を付け足す)
    # 最後に余った要素をどっちの両端に追加するか試す
    res2 = 0
    left = 0
    right = N - 1
    i = 0
    while (right - left) > 1:
        res2 += abs(A[right] - A[left])
        if i % 2 == 0:
            left += 1
        else:
            right -= 1
        i += 1
    if N % 2 == 1:
        # res2 = max(右端,左端)
        res2 += max(abs(A[0] - A[left]), abs(A[left] - A[right]))
    else:
        res2 += max(abs(A[0] - A[right]), abs(A[right] - A[left]))

    ans = max(res1, res2)
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 14168
#include <iostream>
#include<stdio.h>
using namespace std;
int main() {
	int a, b,i;
	while (cin >> a >> b) {
		if (a < b) {
			for (i = a; i > 0; i--) {
				if (a%i == 0 && b%i == 0)
					break;
			}
		}
		else {
			for (i = b; i > 0; i--) {
				if (a%i == 0 && b%i == 0)
					break;
			}
		}
		cout << i << " ";
		if (a < b) {
			for (i = b; i <= 2000000000; i += b) {
				if (i%a==0)
					break;
			}
		}
		else {
			for (i = a; i <= 2000000000; i += a) {
				if (i%b==0)
					break;
			}
		}
		cout << i << endl;
	}
	return 0;
}


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

int main(){
  double v, time, y, height;

  while(scanf("%lf", &v) != EOF){
    time = v / 9.8;
    y = 4.9 * time * time;
    height = (y + 5) / 5;

    if(height > int(height)){
      height = int(height) + 1;
    }

    printf("%d\n", int(height));
  }

  return 0;
}

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

ll i,j,k;

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

    vector<int> AC(100010,0),WA(100010,0);

    int ac=0,wa=0;
    for(i=0;i<m;i++){
        int number;
        string s;//問題番号　AC or WA
        
        cin>>number>>s;

        if(AC[number]==0 && s=="WA"){
            WA[number]++;//まだACしていないものについてのみwa加算
        }

        if(AC[number]==0 && s=="AC"){
            AC[number]=1;//ACは一問一回
            ac++;
        }
    }

    for(i=0;i<100010;i++){
        if(AC[i]){
            wa+=WA[i];//最終的にacしたものにだけwa加算
        }
    }

    cout<<ac<<" "<<wa<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int flag[9][9];
int array[9][9];

void search(int x, int y)
{
	int i, j;
	
	for (i = 1; x + i < 9; i++){
		if (array[x + i][y] == array[x][y]){
			flag[x + i][y] = 1;
			flag[x][y] = 1;
		}
	}
	
	for (i = 1; y + i < 9; i++){
		if (array[x][y + i] == array[x][y]){
			flag[x][y + i] = 1;
			flag[x][y] = 1;
		}
	}
	
	for (i = 0; i < 3; i++){
		for (j = 0; j < 3; j++){
			if (x / 3 * 3 + i != x && 
			y / 3 * 3 + j != y &&
			array[x / 3 * 3 + i][y / 3 * 3 + j] == array[x][y]){
				flag[x / 3 * 3 + i][y / 3 * 3 + j] = 1;
				flag[x][y] = 1;
			}
		}
	}
}

int main(void)
{
	int t, n, i, j;
	
	scanf("%d", &n);
	for (t = 0; t < n; t++){
		if (t != 0){
			puts("");
		}
		
		for (i = 0; i < 9; i++){
			for (j = 0; j < 9; j++){
				flag[i][j] = 0;
			}
		}
		
		for (i = 0; i < 9; i++){
			for (j = 0; j < 9; j++){
				scanf("%d", &array[i][j]);
			}
		}
		
		for (i = 0; i < 9; i++){
			for (j = 0; j < 9; j++){
				search(i, j);
			}
		}
		
		for (i = 0; i < 9; i++){
			for (j = 0; j < 9; j++){
				if (flag[i][j]){
					printf("*");
				}
				else {
					printf(" ");
				}
				printf("%d", array[i][j]);
			}
			puts("");
		}
	}
	
	return (0);
}

Measured memory_bytes: 612
#include <stdio.h>
 
int main(){
  int n;if(scanf("%d",&n)==1){}
  int i;double sum=0;
  double x[n];
  char u[n][3];
  for(i=0;i<n;i++){
    if(scanf("%lf",&x[i])==1 && scanf("%s",u[i])==1){}
    if(u[i][0]=='J'){
      sum += x[i];
    }else{
      sum += x[i]*380000;
    }
  }
  printf("%lf",sum);
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

// dp[i][j][k]: x[:i] から j 枚選んで k になる組み合わせの個数 
long long dp[51][51][2501] = {};

int main()
{
    int N, A;
    cin >> N >> A;
    vector<int> x(N+1);
    FOR(i, 1, N+1) cin >> x[i];

    dp[0][0][0] = 1;
    REP(i, N){
        REP(j, i+1){
            // x[i+1] を選ばないとき
            REP(k, 2501) dp[i+1][j][k] = dp[i][j][k];
        }
        REP(j, i+1){
            // x[i+1] を選ぶとき
            FOR(k, x[i+1], 2501) dp[i+1][j+1][k] += dp[i][j][k-x[i+1]];
        }
    }

    long long ans = 0;
    FOR(j, 1, N+1){
        REP(k, 2501){
            if(k == A*j) ans += dp[N][j][k];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 49152
from collections import deque

def calculate1(x, y) :
    if   x == 0 : y.appendleft(y.popleft() + y.popleft())
    elif x == 1 : y.appendleft(y.popleft() - y.popleft())
    else : y.appendleft(y.popleft() * y.popleft())
    return y

def calculate2(x, y) :
    if   x == 0 : y.append(y.pop() + y.pop())
    elif x == 1 : y.append(- y.pop() + y.pop())
    else : y.append(y.pop() * y.pop())
    return y

def search1(sample) :
    for first in range(3) :
        for second in range(3) :
            for third in range(3) :
                box = deque(sample)
                calculate1(first, box)
                calculate1(second, box)
                calculate1(third, box)
                if box[0] == 10 :
                    return(first,second,third)
                    break
                
def search2(sample) :
    for first in range(3) :
        for second in range(3) :
            for third in range(3) :
                box = deque(sample)
                calculate1(first, box)
                calculate2(second, box)
                calculate1(third, box)
                if box[0] == 10 :
                    return(first,second,third)
                    break

def attack(sample) :
    test = [[sample[a],sample[b],sample[c],sample[d]] for a in range(4) for b in range(4) for c in range(4) for d in range(4) if a!=b and a!=c and a!=d and b!=c and b!=d and c!=d]
    test = list(set(map(tuple, test)))
    for _ in test : 
        result = search1(_)
        if result != None :
            return result, _, 1
            break
        else :
            result = search2(_)
            if result != None :
                return result, _, 2
                break

ams = ['+', '-', '*']
while True :
    sample = [int(_) for _ in input().split()]
    if sample == [0, 0, 0, 0] : break
    result  = attack(sample)
    if result != None :
        if result[2] == 1 : print('((({} {} {}) {} {}) {} {})'.format(result[1][0], ams[result[0][0]], result[1][1], ams[result[0][1]], result[1][2], ams[result[0][2]], result[1][3]))
        else : print('(({} {} {}) {} ({} {} {}))'.format(result[1][0], ams[result[0][0]], result[1][1], ams[result[0][2]], result[1][2], ams[result[0][1]], result[1][3]))
    else : print(0)

Measured memory_bytes: 8052
#include <iostream>
using namespace std;
 
int main() {
    string s;
    getline(cin, s);

    if ((s[0] == 'H' && s[2] == 'H')||(s[0] == 'D' && s[2] == 'D')){
       cout << 'H' << endl;
    } else {
       cout << 'D' << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int dp[1<<15]={};

int main()
{
    int m,n;
    scanf(" %d %d", &m, &n);
    vector<int> w(m),t(m),W(n),T(n);
    rep(i,m) scanf(" %d %d", &w[i], &t[i]);
    rep(i,n) scanf(" %d %d", &W[i], &T[i]);

    vector<int> sumw(m+1),sumt(m+1);
    rep(i,m)
    {
        sumw[i+1] = sumw[i]+w[i];
        sumt[i+1] = sumt[i]+t[i];
    }

    rep(mask,1<<n)
    {
        // ?¬?????????????????????¶
        rep(i,n)if(!(mask>>i&1))
        {
            int nmask = mask | 1<<i;
            int s=dp[mask];
            int widx = upper_bound(all(sumw),W[i]+sumw[s])-sumw.begin()-1;
            int tidx = upper_bound(all(sumt),T[i]+sumt[s])-sumt.begin()-1;

            dp[nmask] = max(dp[nmask],min(widx,tidx));
        }
    }

    printf("%d\n", dp[(1<<n)-1]);
    return 0;
}

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

using ll = long long;

int main(){
    ll D, P;
    int p[11], c[11];

    cin >> D >> P;
    for(int i = 1; i <= D; ++i){
        cin >> p[i] >> c[i];
    }

    ll ret = 1001;
    for(ll i = 0; i < (1 << D); ++i){
        ll v = i;
        ll cnt = 1;
        ll tmp = P;
        ll g = 0;
        int visited[11] = {};
        while(v){
            if(v & 1){
                tmp -= p[cnt] * cnt * 100 + c[cnt];
                g += p[cnt];
                visited[cnt] = 1;
            }else{
                visited[cnt] = 0;
            }

            cnt++;
            v >>= 1;
        }

        for(int j = D; j > 0; --j){
            if(tmp <= 0){
                break;
            }
            if(visited[j]){
                continue;
            }
            if(tmp > (p[j] - 1) * j * 100){
                tmp -= (p[j] - 1) * j * 100;
                g += p[j];
            }else{
                g += tmp / (j * 100) + (tmp % (j * 100) != 0);
                tmp = -1; 
                break;
            }
        }
        if(tmp > 0) continue;

        ret = min(g, ret);
    }
    
    cout << ret << endl;
}


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

//MACROS
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef long long LL;
typedef pair <int,int> PII;


vector <int> g[1<<20];
int bcomp, ccomp, icomp, col[1<<20], n, m;
bool foo;

void dive(int v, int c) {
    if (col[v]) {
        if (c != col[v]) foo = false;
        return;
    }
    else col[v] = c;
    for (auto u : g[v]) dive(u,3-c);
}

int main() {
	cin >> n >> m;
	rep(i,0,m) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
	}
	rep(i,0,n)
        if (col[i] == 0) {
            if (g[i].empty()) icomp++;
            else {
                foo = true;
                dive(i,1);
                if (foo) bcomp++;
                else ccomp++;
            }
        }
	cout << 1LL*icomp*icomp + 2LL*icomp*(n-icomp) + 2LL*bcomp*ccomp + 2LL*bcomp*bcomp + 1LL*ccomp*ccomp;
}


Measured memory_bytes: 31232
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

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

int main() {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    rep(i, m) {
        int x;
        cin >> x;
        sum += x;
    }
    if (n >= sum) cout << n - sum << endl;
    else cout << -1 << endl;
    return 0;
}



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

list_money = []

while len(list_money) < N:
	list_add = list(input().split())
	list_money.append(list_add)

total_money = 0

for i in range(N):
	list_family_i = list_money[i]
	x_i = float(list_family_i[0])
	u_i = list_family_i[1]
	
	if u_i == 'BTC':
		x_i *= 380000.0
		total_money += x_i
	else:
		total_money += x_i

print(total_money)

Measured memory_bytes: 3060
#include<cstdio>

int n, x[102], ans = 10000000;

int calc(int p) {
  int res = 0;
  for (int i = 0; i < n; i++) {
    res += (x[i] - p) * (x[i] - p);
  }
  return res;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  for (int i = 1; i <= 100; i++) {
    int tmp = calc(i);
    if (tmp < ans) {
      ans = tmp;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 128
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = ((int)(n) - 1); i >= 0; i--)
#define repn(i, n) for(int i = 1; i <= (int)(n); i++)
#define reprn(i, n) for(int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define LARGE_PRIME_NUM 1000000007
typedef long long ll;

#include <iostream>
#include <array>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <numeric>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	s.at(k - 1) += 32;

	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void)
{
	double x1, y1, x2, y2, x, y, s, d;
	scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
	x = (x1 > x2 ? x1-x2 : x2-x1);
	y = (y1 > y2 ? y1-y2 : y2-y1);
	s = x*x + y*y;
	d = sqrt(s);
	printf("%f\n", d);
	return 0;
}

Measured memory_bytes: 652
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    char c = s.charAt(0);
    if (c >= 'a' && c <= 'z') {
    	System.out.println("a");
    } else {
    	System.out.println("A");
    }
    
  }
}

Measured memory_bytes: 35664
package main
 
import (
	"bufio"
	"os"
	//"sort"
	"strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}
 
func scanString() string {
	sc.Scan()
	return sc.Text()
}
 
func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

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

func main() {
	var N, A int
	N = scanInt()
	m := map[int]int {}
    var wr = bufio.NewWriter(os.Stdout)
	for i := 0; i < N; i++ {
		A = scanInt()
		if m[A] == 0 {
			m[A]++
		} else {
			wr.WriteString("NO\n")
	        wr.Flush()
			return
		}
	}
	wr.WriteString("YES\n")
	wr.Flush()
}


Measured memory_bytes: 13480
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e17;
// Int MOD = 998244353;

Int gcd(Int n, Int m) {
    return m == 0 ? n : gcd(m, n % m);
}

int main() {
    ios::sync_with_stdio(false);
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) cin >> a[i];
    Int x = a[0];
    for (Int i = 1; i < n; i++) {
        x = gcd(max(x, a[i]), min(x, a[i]));
    }
    dump(x);
    return 0;  
} 

Measured memory_bytes: 1024
n = int(input())
b =input().split()
ans = []
while len(b) > 0:
    ng = True
    
    for i in range(len(b)-1,-1,-1):
        if b[i] == str(i+1):
            ans.append(i+1)
            b = b[:i]+b[i+1:]
            
            
            ng = False
            break
    if ng:
        print(-1)
        exit(0)
if len(ans) == 0:
    print(-1)
else:
    ans = ans[::-1]
    print(*ans)
    
        

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

int g,l;
double a,b,d;

int main()
	{

	while( cin >> a >> b )
		{
			d = a*b;
			while( a != b)
				{
					if( a>b ){ a = a-b; }
					else if( b>a ){ b = b-a; }
				}
				g = (int)a;
				l =  (int)(d/g);
				cout << g <<" "<< l << endl;
		}
		return 0;
	}

Measured memory_bytes: 1220
import random

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

    c = list(map(int, input().split()))

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

    sche = []
    for i in range(D):
        x = int(input())
        sche.append(x)
    
    last_d = [0 for i in range(26)]
    score = 0
    
    for i in range(D):
        score += s[i][sche[i]-1]
        last_d[sche[i]-1] = i+1
        score = down_score(i+1, c, last_d, score)
        print(score)
        
if __name__ == "__main__":
    main()


Measured memory_bytes: 9580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
const int INF (1<<30);

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

  string ans = (S=="ABC") ? "ARC" : "ABC";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p.at(i);
    int ans;
    for(int i = 1; i < n-1; i++) {
        if(p.at(i-1)<p.at(i)&&p.at(i)<p.at(i+1)) ans++;
        if(p.at(i-1)>p.at(i)&&p.at(i)>p.at(i+1)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
use std::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr;
}

impl<'a> Parse for std::str::SplitWhitespace<'a> {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let a = iter.to();
    let b = iter.to();
    if 1 <= a && a <= 9 && 1 <= b && b <= 9 {
        println!("{}", a * b);
    } else {
        println!("-1");
    }
}

Measured memory_bytes: 4352
def resolve():
    A, B = list(map(int, input().split()))
    if A == B:
        print("Draw")
        return
    if A == 1:
        A = 14
    if B == 1:
        B = 14
    
    if A > B: 
        print("Alice")
    else:
        print("Bob")


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<int> Eratosthenes(const int N)
{
    vector<bool> is_prime(N+1, true);
    vector<int> P;
    for(int i=2; i<=N; i++) {
        if (is_prime[i]) {
            for(int j=2*i; j<=N; j+=i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}
 
int main() {
    int n,k;
    cin >> n >> k;
    int res = 0;
    while(n>0) {
        n /= k;
        res++;
    }
    cout << res << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>
using namespace std;

int main() {

	int N;

	cin >> N;

	vector<int> V(N, 0);
	vector<int> C(N, 0);

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

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

	int total = 0;

	for (int i = 0; i < N; i++) {
		if (V[i] - C[i]>0) {
			total += V[i] - C[i];
		}
	}

	cout << total << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll k,x;
	cin>>k>>x;
	for(ll i=x-k+1;i<k+x;i++)
		cout<<i<<" ";
}

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

int main()
{
    string s;
    int n, k, x, ans = 0;

    cin >> n >> k;

    for(int i = 0; i < n; i++)
    {
        cin >> x;
    }

    ans = ceil((n - 1) / (double)(k - 1));

    cout << ans << endl;


}



Measured memory_bytes: 256
import java.io.*
import java.util.*

const val YES = "Yes"
const val NO = "No"
fun solve(N: Int, t: IntArray, x: IntArray, y: IntArray){
    fun canMove(x1: Int, y1: Int, x2: Int, y2: Int, time: Int): Boolean{
        val step = Math.abs(x2 - x1) + Math.abs(y2 - y1)
        if (step > time) return false
        else if ((time - step) % 2 != 0) return false
        else return true
    }
    for(i in 0 until N){
        if (!canMove(x.getOrElse(i-1){0}, y.getOrElse(i-1){0}, x[i], y[i], t[i]-t.getOrElse(i-1){0})){
            println(NO)
            return
        }
    }
    println(YES)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val t = IntArray(N)
    val x = IntArray(N)
    val y = IntArray(N)
    for (i in 0 until N) {
        t[i] = sc.next().toInt()
        x[i] = sc.next().toInt()
        y[i] = sc.next().toInt()
    }
    solve(N, t, x, y)
}



Measured memory_bytes: 48692
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';


int main() {
	int n, k,r,s,p;
	cin >> n >> k;
	cin >> r >> s >> p;
	string t;
	cin >> t;
	ll ans = 0;
	rep(i, n) {
		if (i + k < n && t[i] == t[i + k]) {
			t[i + k] = 'x';
		}
	}
	rep(i, n) {
		if (t[i] == 'r') ans += p;
		else if (t[i] == 's') ans += r;
		else if (t[i] == 'p') ans += s;
	}
	cout << ans << endl;
	return 0;
	}

	

Measured memory_bytes: 512
import collections
n = int(input())
x = []
def factorization(n):
    d = []
    while n % 2 == 0:
        d.append(2)
        n /= 2
    f = 3
    while f*f <= n:
        if n % f == 0:
            d.append(int(f))
            n /= f
        else:
            f += 2
    if n != 1:
        d.append(n)
    return d

for i in range(n, 1, -1):
    x += factorization(i)

c = collections.Counter(x)
l = list(c.values())
ans = 1

for i in range(len(l)):
    ans *= 1 + l[i]

print(ans % (7+10**9))

Measured memory_bytes: 9336
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x; 
}
#define MN 200000
#define N 262144
struct P{int x,y;}p[MN+5];
bool cmp(const P&a,const P&b){return a.x!=b.x?a.x<b.x:a.y<b.y;} 
int c[MN+5],cn,t[N*2+5];
void rw(int k,int x){for(k+=N;k;k>>=1)t[k]=max(t[k],x);}
int query(int l,int r)
{
	int res=t[0];
	for(l+=N-1,r+=N+1;l^r^1;l>>=1,r>>=1)
	{
		if(~l&1)res=max(res,t[l+1]);
		if( r&1)res=max(res,t[r-1]);
	}
	return res;
}
int main()
{
	int x1,y1,x2,y2,n,i,z=1e8;
	x1=read();y1=read();x2=read();y2=read();
	for(n=read(),i=1;i<=n;++i)p[i].x=read(),p[i].y=read();
	if(x1>x2)swap(x1,x2),swap(y1,y2);
	if(y1>y2)
	{
		y1=z-y1;y2=z-y2;
		for(i=1;i<=n;++i)p[i].y=z-p[i].y;
	}
	p[++n]=(P){x1,y1};p[++n]=(P){x2,y2};
	for(i=1;i<=n;++i)c[i]=p[i].y;
	sort(c+1,c+n+1);cn=unique(c+1,c+n+1)-c-1;
	sort(p+1,p+n+1,cmp);
	memset(t,200,sizeof(t));
	for(i=1;i<=n;++i)
	{
		z=lower_bound(c+1,c+cn+1,p[i].y)-c;
		if(p[i].x==x1&&p[i].y==y1)rw(z,0);
		else if(p[i].x==x2&&p[i].y==y2)break;
		else rw(z,query(1,z)+1);
	}
	z=query(1,z);
	printf("%.12lf",100.*(x2-x1+y2-y1)+z*(5*acos(-1)-20)+(z==min(x2-x1+1,y2-y1+1))*5*acos(-1));
}

Measured memory_bytes: 4608
from collections import deque
N, M = map(int, input().split())
roads = []
for _ in range(N):
    roads.append([])
for _ in range(M):
    a, b = map(int, input().split())
    roads[a - 1].append(b - 1)
    roads[b - 1].append(a - 1)
visited = [float('inf')] * N
q = deque()
q.append(0)
visited[0] = 0
pre = [-1] * N
while q:
    now_room = q.popleft()
    for next_room in roads[now_room]:
        if visited[next_room] != float('inf'):
            continue
        visited[next_room] = visited[now_room] + 1
        if pre[next_room] == -1:
            pre[next_room] = now_room + 1
        q.append(next_room)
# print(*roads)
# print(*pre)

print('Yes')
for i in range(1, N):
    print(pre[i])


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

int main()  {

    int n, step;
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        step = 0;
        while (n != 1) {
            if (!(n & 1)) n /= 2;
            else n = n * 3 + 1;
            step++;
        }
        printf("%d\n", step);
    }
    return 0;
}



Measured memory_bytes: 2684
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    srand(90);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    //for(int i = 0; i<s.size(); i++)
    //{
        if(s[0]!=s[1] && s[1]!=s[2] && s[0]!=s[2])
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    //}
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,x;
int c[101];
int a[101][101];
int sum[101];
int ans=0x7fffffff;
int main()
{
	scanf("%d%d%d",&n,&m,&x);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&c[i]);
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	}
	for(int i=1;i<=(1<<n);i++)
	{
		int sum1=0;
		for(int j=1;j<=m;j++)
			sum[j]=0;
		for(int j=1;j<=n;j++)
			if(i&(1<<(j-1))) {
				sum1+=c[j];
				for(int k=1;k<=m;k++)
					sum[k]+=a[j][k];
			}
		bool f=0;
		for(int j=1;j<=m;j++)
			if(sum[j]<x) f=1;
		if(!f) ans=min(ans,sum1);
	}
	printf("%d",ans==0x7fffffff ? -1 : ans);
	return 0;
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int mo=1000000007;
const int N=100005;
int n,m,k,t[N];
int qq[N],a[N],b[N];
pii q[N];
void change(int x,int v){
	for (;x<=k+1;x+=x&(-x))
		t[x]=(t[x]+v)%mo;
}
int ask(int x){
	int ans=0;
	for (;x;x-=x&(-x))
		ans=(ans+t[x])%mo;
	return ans;
}
bool cmp(pii x,pii y){
	return x.fi==y.fi?x.se>y.se:x.fi<y.fi;
}
int main(){
	scanf("%d%d",&n,&m);
	For(i,1,n) scanf("%d",&a[i]);
	For(i,1,m) scanf("%d",&b[i]);
	int pos=1;
	For(i,1,n){
		for (;pos<=m&&b[pos]<=a[i];++pos);
		if (pos!=1&&pos!=m+1)
			if (b[pos]!=a[i]&&b[pos-1]!=a[i])
				q[++k]=pii(a[i]-b[pos-1],b[pos]-a[i]);
	}
	For(i,1,k) qq[i]=q[i].se;
	sort(qq+1,qq+k+1);
	sort(q+1,q+k+1,cmp);
	change(1,1);
	For(i,1,k){
		q[i].se=lower_bound(qq+1,qq+k+1,q[i].se)-qq;
		if (i==1||q[i]!=q[i-1])
			change(q[i].se+1,ask(q[i].se));
	}
	printf("%d\n",ask(k+1));
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& v : e)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}

struct mint {
ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    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 {mint res(*this);return res+=a;}
    mint operator-(const mint a) const {mint res(*this);return res-=a;}
    mint operator*(const mint a) const {mint res(*this);return res*=a;}
    mint pow(ll t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}
    mint inv() const {return pow(MOD-2);}
    mint& operator/=(const mint a) {return (*this) *= a.inv();}
    mint operator/(const mint a) const {mint res(*this);return res/=a;}
};

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        if (COMBMAX < n){
            mint ret = 1;
            rep1(i,k){
                ret *= (n-i+1);
                ret /= i;
            }
            return ret;
        }
        return fact[n]*ifact[k]*ifact[n-k];
    }
} ;//com(COMBMAX);

int main(){
    string L;cin >> L;
    ll N = L.size();
    mint ans = 0;
    ll rate = 0;
    rep(i,N){
        if(L[i]=='1'){
            ans += (mpow(3,N-1-i)*mpow(2,rate));
            rate += 1;
        }else{

        }        
    }
    ans += mpow(2,rate);
    cout << ans.x << endl;
    return 0;
}

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

int main(){
  long long int n, ans = 0, xx = 0;
  cin >> n;
  vector<long long int> h(n);
  rep(i,n,0) cin >> h[i];
  rep(i,n-1,0){
    if(h[i] >= h[i+1]) xx++;
    else{
      ans = max(ans, xx);
      xx = 0;
    }
  }
  ans = max(ans, xx);
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pib = pair<int, int>;

bool bitget(int a,int b){
    return a&(1<<b);
}

 
int main (){
    int N;
    cin >> N;
    vector<vector<pib>> A(N);
    for(int i=0;i<N;i++){
        int j;
        cin >> j;
        A[i]=vector<pib>(j);
        for(pib &i:A[i])cin >> i.first >> i.second;
    }
    
    
    
    int maxc=0;
    for(int i=0;i<1<<N;i++){
        int count0=0,cc=0;
        vector<bool> S(N,false);
        vector<vector<int>> T(N);
        vector<vector<int>> F(N);
        for(vector<pib> j:A){
            int count1=0;
            for(pib k:j){
                if(bitget(i,k.first-1)!=k.second)break;
                count1++;
            }
            
            if((count1==j.size())&&bitget(i, cc)){
                S[cc]=true;
                for(pib k:j){
                    if(k.second)T[cc].push_back(k.first-1);
                    else F[cc].push_back(k.first-1);
                }
            }else{
                S[cc]=false;
                if(bitget(i, cc))goto skip;
            }
            cc++;
        }
        cc=0;
        for(int j=0;j<N;j++){
            for(int k=0;k<T[j].size();k++){
                if(!S.at(T[j][k])){
                    S[j]=false;
                    break;
                }
            }
            for(int k=0;k<F[j].size();k++){
                if(S.at(F[j][k])){
                    S[j]=false;
                    break;
                }
            }
            count0+=S[j];
        }
        
        
        maxc=max(maxc,count0);
        
    skip:;
        
    }
    
    cout << maxc << endl;
}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
const int INF=0x3f3f3f3f;
//vector<int>v[maxn];
//map<int,string>mp[maxn];
//queue<int>q[maxn];
int	a[5];
int main()
{
	int i,j,k,ans=0;
	for(i=0;i<5;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<5;i++)
	{
		if(a[i]==0)
			cout<<i+1<<" ";
	}
	return 0;
}


Measured memory_bytes: 3152
#include <cstdlib>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <stack>
#include <utility>
#include <unordered_set>
#include <unordered_map>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/multi_array.hpp>

using namespace std;

#if 0
// memo
abs()

start_with(str, "hoge");
ends_with(str, "hoge");

std::sort(d.begin(), d.end());
d.erase(std::unique(d.begin(), d.end()), d.end());
#endif

using namespace boost;
using namespace boost::algorithm;

/**

   @retuen msb pos + 1,
   @retval 0 not found
 */
template<size_t SZ>
size_t msb(const std::bitset<SZ>& s) {
    for (size_t i = SZ; i != 0; --i) {
        if (s[i-1]) {
            return i;
        }
    }
    return 0;
}


static inline bool isOdd(int v)
{
    return v & 0x01;
}

int main()
{
    uint64_t N, Y;
    std::cin >> N >> Y;

    // 10000
    // 5000
    // 1000

    for (size_t i = 0; i <= N; ++i) {
        for (size_t j = 0; j <= N - i; ++j) {
            size_t k = N - (i + j);
            if ((i + j + k) == N && (10000 * i + 5000 * j + 1000 * k == Y)) {
                std::cout << i << " " << j << " " << k << std::endl;
                return 0;
            }
        }
    }
    std::cout << "-1 -1 -1" << std::endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;


signed main(){
  double a, b;
  scanf("%lf%lf", &a, &b);
  printf("%.5lf\n", a/b);
  return 0;
}






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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define f first
#define s second

ll N;
ll x[105],y[105],h[105];

int main(){

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

cin>>N;

rep(i,N) cin>>x[i]>>y[i]>>h[i];

rep(i,101){
	rep(j,101){
		//高さHを特定する
		ll sub1=abs(x[0]-i);;
		ll sub2=abs(y[0]-j);;
		ll H=0;
		rep(k,N){
			if(h[k]>0){
				sub1=abs(x[k]-i);
				sub2=abs(y[k]-j);
				H=h[k]+sub1+sub2;
			}
		}
		//矛盾ないかチェック
		bool flag=1;
		ll hh=0;
		rep(k,N){
			hh=max(H-abs(x[k]-i)-abs(y[k]-j),(ll)0);
			if(hh!=h[k]){
				flag=0; 
				break;
			}
		}
		if(flag){
			cout<<i<<" "<<j<<" "<<H<<endl;
			return 0;
		}
	}
}

}
	


Measured memory_bytes: 384
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val x = inputs(0).toInt

  println(solve(x))

  def solve(x: Int): Int = {
    if (x < 600) {
      8
    } else if (600 <= x && x < 800) {
      7
    } else if (800 <= x && x < 1000) {
      6
    } else if (1000 <= x && x < 1200) {
      5
    } else if (1200 <= x && x < 1400) {
      4
    } else if (1400 <= x && x < 1600) {
      3
    } else if (1600 <= x && x < 1800) {
      2
    } else if (1800 <= x) {
      1
    } else {
      -1
    }
  }
}

Measured memory_bytes: 54760
#include <iostream>

using namespace std;

int main(){
    long long count,res;
    long long n,a,b;
    cin >> n>>a>>b;
    count = n / (a + b);
    res = n % (a + b);
    if (res>a)
        cout << a * count+a << endl;
    else
        cout << a*count+res << endl;
}

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

int main(){
    int N;
    cin >> N;
    int B[N-1], A[N];
    for(int i=0; i<N-1; i++) cin >> B[i];
    A[0] = B[0];

    for(int i=0; i<N-1; i++) {
        A[i+1] = B[i];
        if(A[i] > B[i]) {
            A[i] = B[i];
        }
    }

    ll count = 0;
    for(int i=0; i<N; i++) count += A[i];
    cout <<count << endl;
}

Measured memory_bytes: 3636