akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll r, g, b, n, x;
	ll ans = 0;

	cin >> r >> g >> b >> n;

	REP(i, (n / r) + 1) {
		REP(j, (n / g) + 1) {
			x = n - i * r - j * g;

			if (x >= 0 && x % b == 0) {
				ans++;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a) 
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a) 
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) { 
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll a;
	cin >> a;
	if (a >= 400 && a < 600) {
		cout << 8 << endl;
	}
	else {
		if (a >= 600 && a < 800) {
			cout << 7 << endl;
		}
		else {
			if (a >= 800 && a < 1000) {
				cout << 6 << endl;
			}
			else {
				if (a >= 1000 && a < 1200) {
					cout << 5 << endl;
				}
				else {
					if (a >= 1200 && a < 1400) {
						cout << 4 << endl;
					}
					else {
						if (a >= 1400 && a < 1600) {
							cout << 3 << endl;
						}
						else {
							if (a >= 1600 && a < 1800) {
								cout << 2 << endl;
							}
							else {
								if (a >= 1800 && a < 2000) {
									cout << 1 << endl;
								}
							}
						}
					}
				}
			}
		}
	}
}

Measured memory_bytes: 3680
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var X = Sarray()[0];
            for (var i = -1000; i <= 1000; ++i)
            {
                for (var j = -1000; j <= i; ++j)
                {
                    if ((long)Pow(i, 5) - (long)Pow(j, 5) == X)
                    {
                        WriteLine($"{i} {j}");
                        return;
                    }
                }
            }
        }
    }
}

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

int main(){
  int N;
  cin >> N;
  if(N%2 == 1){
    cout << "No";
    return 0;
  }
  string S;
  cin >> S;
  for(int i = 0;i < N/2;++i)
    if(S[N/2 + i] != S[i]){
      cout << "No";
      return 0;
    }
  cout << "Yes";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main(){
    vector<int> array;
    int i = -1;
    while(cin >> i){
        if(i == 0){
            cout << array[array.size()-1]<< endl;
            array.pop_back();
        }else 
            array.push_back(i);
    }
    return 0;
}

Measured memory_bytes: 1212
#!/usr/bin/env python3
#EDPC E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,W = LI()
wv = [LI() for _ in range(n)]
V = 0
for i in range(n):
    w,v = wv[i]
    V += v
    
dp = [[inf]*(V+1) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
    w,v = wv[i]
    for j in range(V+1):
        if j < v:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j],dp[i][j-v] + w)
res = 0
for i in range(V+1):
    if dp[-1][i] <= W:
        res = i
print(res)


Measured memory_bytes: 308168
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
}
ll fact(int n)
{
	if(n==1)return 1;
	return n*fact(n-1);
}
int main()
{
	//fopen();
	int n;
	cin>>n;
	int a[n],b[n];
	rep(i,n)
	{cin>>a[i];}
	rep(i,n)
	{cin>>b[i];}
	ll g=fact(n);
	ll n1=1,n2=1;
	rep(i,n-1)
	{
			int c=0;
			repA(i+1,j,n)
			{
				if(a[j]<a[i])c++;
			}
			n1+=c*fact(n-i-1);//cout<<n<<i;
			c=0;
			repA(i+1,j,n)
			{
				if(b[j]<b[i])c++;
			}
			n2+=c*fact(n-i-1);
		//cout<<n1<<" "<<n2<<endl;

	}
	cout<<abs(n1-n2);
	//cout<<(k*500>=x?"Yes":"No");

	
}


Measured memory_bytes: 256
P,S=print,sorted
n,k,*t=map(int,open(i:=0).read().split())
l=S([a<1<exit(P(-1)),a-1,i:=i+1]for a in t)[::-1]
*_,b=r=[*zip(*l)][2]
for i in range(k):
 for t in S(l)[::-1]:
  if t[2]-b:t[1]or exit(P(-1));t[1]-=1;r+=t[2],
 b=r[-1]
P(len(r),*r)

Measured memory_bytes: 9360
#include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <sstream>
    #include <algorithm>
    #include <cstdlib>
    #include <map>
    #include <queue>
    #include <utility>
    #include <vector>
    #include <set>
    #include <memory.h>
    #include <iomanip>
    #include <bitset>
    #include <list>
    #include <stack>
     
    using namespace std;
     
    #define mod 1000000007
     
    long long int pow2(long long int n){
        if(n == 0) return 1;
        else {
           long long int tmp = pow2(n / 2);
            if(n % 2 == 0){
                return (tmp * tmp) % mod;
            } else {
                return (((tmp * tmp) % mod) * 2) % mod;
            }
        }
    }
     
    int main()
    {
        int n;
        cin >> n;
        int cnt[100001] = {};
        for(int i = 0; i < n; i++){
            int a;
            cin >> a;
            cnt[a]++;
        }
        bool haveanswer = true;
        if(n % 2 == 1){
            if(cnt[0] != 1){
                haveanswer = false;
            } else {
                for(int i = 1; i <= n - 1; i++){
                    if((i % 2 == 1 && cnt[i] != 0) || ( i % 2 == 0 && cnt[i] != 2)){
                        haveanswer = false;
                        break;
                    }
                }
            }
        } else {
            for(int i = 0; i <= n - 1; i++){
                if((i % 2 == 1 && cnt[i] != 2) || (i % 2 == 0 && cnt[i] != 0)){
                    haveanswer = false;
                    break;
                }
            }
        }
        if(haveanswer){
            cout << pow2(n / 2) << endl;
        } else {
            cout << 0 << endl;
        }
        return 0;
    }

Measured memory_bytes: 640
# うんちーこんぐ

import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

a = list(range(1,N+1))
b = itertools.permutations(a)

ans1 = 1
ans2 = 1

for i in b:
    if i == P:
        break
    ans1 += 1

b = itertools.permutations(a)

for i in b:
    if i == Q:
        break
    ans2 += 1

print(abs(ans1-ans2))

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

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

int main()
{
    char b, c[128];
    c['A'] = 'T';
    c['G'] = 'C';
    c['C'] = 'G';
    c['T'] = 'A';
    cin >> b;
    cout << c[(int)b] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;


int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	string  str,s[200][200];
	//cout << fixed << setprecision(10);
	long long int n, m, a, b, c, k, res = 0,cou=0,memo,ma,mi;

	cin >> str;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == 'o') {
			res++;
		}
	}
	if (res + 15 - str.length() >= 8) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}


Measured memory_bytes: 512
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using lint=long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()
int N;
#define RADIX 2;//0-index;

int shichi(vector<int> &A,int dizit){
    int rad=RADIX;
    vector<int> trinary(dizit);
    REP(i,pow(3,dizit)){
        int K=0;
        REP(i,dizit){
            if(trinary[i]==0){
                K+=3*pow(10,i);
            }else if(trinary[i]==1){
                K+=5*pow(10,i);
            }else{
                K+=7*pow(10,i);
            }
        }
        A.push_back(K);
        int carry=1;
        REPRi(i,dizit-1,-1){
            if(carry==1&&trinary[i]<rad){
                trinary[i]+=1;
                carry=0;
            }else if(carry==1&&trinary[i]==rad){
                trinary[i]=0;
            }
        }
        if(carry==1){
            break;
        }
    }
    return 0;
}


int main(){
    int N;
    cin>>N;
    vector<int> A;
    REPi(i,3,10){
        shichi(A,i);
    }
    int ans;
    REP(i,A.size()){
        string S=to_string(A[i]);
        if(S.find('7')!=SIZE_MAX&&S.find('5')!=SIZE_MAX&&S.find('3')!=SIZE_MAX){
            if(N>=A[i]){
                ans+=1;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto hs = readln.split.to!(int[]);
    auto bs = new bool[](N);
    foreach (_; 0..M) {
        auto ab = readln.split.to!(int[]);
        auto A = ab[0]-1;
        auto B = ab[1]-1;
        if (hs[A] > hs[B]) {
            bs[B] = true;
        } else if (hs[A] < hs[B]) {
            bs[A] = true;
        } else {
            bs[A] = true;
            bs[B] = true;
        }
    }
    int r;
    foreach (b; bs) if (!b) ++r;
    writeln(r);
}

Measured memory_bytes: 6768
#include <stdio.h>

int main() {

  int flag,i,j,A[100],k,N,count=0;



  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }


  flag=1;
  
  while(flag){
    flag=0;
    for(j=N-1;j>=1;j--){
      if(A[j]<A[j-1]){
	k=A[j];
	A[j]=A[j-1];
	A[j-1]=k;
	count++;
	flag=1;
      }
      
      //flag=1;
     
    }
    
  }

    for(i=0;i<N;i++){
      if(i!=0){
	printf(" ");
      }
      printf("%d",A[i]);
    }

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



Measured memory_bytes: 2088
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;

int mat[3005][3005];
int dp[4][3005][3005];
int r, c, K;
 
signed main()
{
    tezz
    
    cin>>r>>c>>K;

    for(int i=0;i<K;i++){
        int x, y, v;
        cin>>x>>y>>v;

        mat[x][y] = v;
    }

    for(int i=1; i<=r; i++){
        for(int j=1; j<=c; j++){
            if(i == 1 && j == 1){
                if(mat[i][j]) dp[1][i][j] = mat[i][j];
                continue;
            }
            //for left
            for(int k=0; k<4; k++){
                if(mat[i][j] && (k < 3)){
                    dp[k + 1][i][j] = max(dp[k][i][j - 1] + mat[i][j], dp[k + 1][i][j]);
                    dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1]);
                }
                else{
                    dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1]);
                }
            }

            //for up
            for(int k=0; k<4; k++){
                if(mat[i][j]){
                    dp[1][i][j] = max(dp[1][i][j], dp[k][i - 1][j] + mat[i][j]);
                    dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j]);
                }
                else{
                    dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j]);
                }
            }
        }
    }

    // cout<<dp[1][1][2]<<endl;

    int mx = 0;
    for(int i=0;i<4;i++) mx = max(mx, dp[i][r][c]);

    cout<<mx;
} 

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

int main(){
    vector<int> a(5),b(5);int ans=0;
    for(int i=0;i<5;i++) {
        cin>>a.at(i);
        b.at(i)=a.at(i)%10;
        if(b.at(i)==0) ans+=a.at(i);
        else ans+=a.at(i)-b.at(i)+10;
    }
    sort(b.begin(),b.end());
    for(int i=0;i<5;i++){
        if(b.at(i)>0) {
            ans+=b.at(i)-10;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
  long N;
  cin>>N;
  long A[200000], B[200000];
  for (long i = 0; i < 200000; i++)
    B[i] = 0;
  for (long i = 1; i < N; i++)
  {
    cin>>A[i];
    B[A[i]-1]++;
  }
  for (long i = 0; i < N; i++)
    cout<<B[i]<<endl;
  return 0;
}

Measured memory_bytes: 6748
#include <cstdio>
#include <iostream>
using namespace std;
bool t[3][5][5] = {
  {{0,0,0,0,0}, {0,0,1,0,0}, {0,1,1,1,0}, {0,0,1,0,0}, {0,0,0,0,0}},
  {{0,0,0,0,0}, {0,1,1,1,0}, {0,1,1,1,0}, {0,1,1,1,0}, {0,0,0,0,0}},
  {{0,0,1,0,0}, {0,1,1,1,0}, {1,1,1,1,1}, {0,1,1,1,0}, {0,0,1,0,0}}
};
int main() {
  int a[10][10] = {}, x, y, s, i, j, m = 0, c = 0;
  while (scanf("%d,%d,%d", &x, &y, &s) != EOF) {
    for (i = 0; i < 5; i++) {
      for (j = 0; j < 5; j++) {
        if ((x + i - 2) < 0 || (x + i - 2) > 9 || (y + j - 2) < 0 || (y + j - 2) > 9)
          continue;
        if (t[s - 1][i][j])
          a[x + i - 2][y + j - 2]++;
      }
    }
  }
  for (x = 0; x < 10; x++) {
    for (y = 0; y < 10; y++) {
      if (!a[x][y])
        c++;
      if (a[x][y] > m)
        m = a[x][y];
    }
  }
  cout << c << endl;
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){

    ll a, b, n;

    cin >> a >> b >> n;


    if(n>=b){
        cout << a* (b-1) / b;
    }
    else cout<< a*n/b;

    return 0;
}

Measured memory_bytes: 3608
# -*- coding:utf-8 -*-

def solve():
    N, K = list(map(int, input().split()))
    D = list(map(int, input().split()))

    n = N
    while True:
        k = str(n)
        ok = True
        for ki in k:
            if int(ki) in D:
                ok = False
        if ok:
            print(n)
            return
        n += 1



if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
s=input()
t=input()


li=[]
for i in range(len(s)-1,len(t)-2,-1):
    if s[i]==t[-1] or s[i]=='?':
        j=-1
        while s[i]==t[j] or s[i]=='?':
            i-=1
            j-=1

            if -j>len(t):
                ss=s[:i+1]+t+s[i+len(t)+1:]
                li.append(ss.replace('?','a'))
                break
li.sort()

print(li[0] if li else 'UNRESTORABLE')

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

int comb(int n) {
    if (n == 0 || n == 1) return 0;
    return n * (n - 1) / 2;
}

int main() {
    int N, M;
    cin >> N >> M;
    cout << comb(N) + comb(M) << endl;
    return 0;
}


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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

const long long MOD = 1000000007;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, std::vector<std::vector<ll>> a) {
  vector<ll> dp((1 << N) + 1, 0);
  dp.at(0) = 1;
  for (int S = 1; S < (1 << N); S++) {
    bitset<3> bs = S;
    int i = __builtin_popcount(S);
    rep(j, N) {
      if ((S >> j) & 1 == 1 && a.at(i - 1).at(j) == 1) {
        int v = S ^ (1 << j);
        dp.at(S) = (dp.at(S) + dp.at(S ^ (1 << j))) % MOD;
      }
    }
  }

  cout << dp.at((1 << N) - 1) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  std::vector<std::vector<ll>> a(N, std::vector<ll>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      scanf("%lld", &a[i][j]);
    }
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 19516
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;



int main(){
  int n,m;
  cin>>n>>m;
  
  cout<< n*(n-1)/2+m*(m-1)/2<<endl;
  
}

Measured memory_bytes: 256
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    double A, B;
    cin >> A >> B;
    double X = 1;
    bool isExist = false;
    for (; X < 20000; X++)
    {
        if (floor(X * 0.08) == A && floor(X * 0.10) == B)
        {
            isExist = true;
            break;
        }
    }

    if (isExist)
    {
        cout << X << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
    return;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {

	int a, b, c;
	cin >> a >> b >> c;
	string s="NO";
	if (a + b >= c && a <= c) {
		s = "YES";
	}
	cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf

const int MAXN = 1050;
const int MP = 100 * 1000 * 1000;

int n;
int x[MAXN], y[MAXN];
int odd = 0, even = 0;
vector<long long> ans;
int evenStart = 0;
long long totalSum;
long long maxSum;

bool ok(long long x, long long y, long long mx) {
  return abs(x) + abs(y) <= mx;
}

int main() { 

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x[i], &y[i]);
    if ((abs(x[i]) + abs(y[i])) % 2 == 0) {
      even++;
    } else {
      odd++;
    }
    maxSum = max(maxSum, 1ll * (abs(x[i]) + abs(y[i])));
  }

  if (even && odd) {
    puts("-1");
    return 0;
  }

  if (even) {
    ans.push_back(1);
    evenStart++;
    totalSum++;
  }

  long long last = 1;
  while (totalSum < maxSum) {
    ans.push_back(last);
    totalSum += last;
    last *= 2;
  }

  printf("%d\n", sz(ans));
  for (long long x : ans) {
    printf("%lld ", x);
  }
  cout << endl;

  for (int i = 0; i < n; i++) {
    string result = "";
    long long sum = totalSum;
    long long xx = x[i], yy = y[i];

    for (int j = sz(ans) - 1; j >= 0; j--) {
      sum -= ans[j];
      if (ok(xx + ans[j], yy, sum)) {
        xx += ans[j];
        result.append(1, 'L');
      } else if (ok(xx - ans[j], yy, sum)) {
        xx -= ans[j];
        result.append(1, 'R');
      } else if (ok(xx, yy + ans[j], sum)) {
        yy += ans[j];
        result.append(1, 'D'); 
      } else {
        yy -= ans[j];
        result.append(1, 'U');
      }
    }

    reverse(all(result));
    cout << result << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include    <bits/stdc++.h>
#define     ll long long
#define     ull unsigned long long
#define     ld long double
#define     prec(k) fixed << setprecision(k)
#define     up(i, k, n) for (int i = k ; i < n ; i ++)
#define     down(i, k, n) for (int i = k ; i >= n ; i --)
#define     ii pair<int, int>
#define     pll pair <ll, ll>
#define     X first
#define     Y second
#define     str basic_string <int>
const int maxN = (int) 1e4 + 7;
const int maxM = (int) 1e5 + 7;
const int maxT = (int) 1e6 + 7;
const int INF = 2e9;

using namespace std;

int n, a[57], maxa = -INF, mina = INF, argmaxa = -1, argmina = -1;

void enter()
{
	cin >> n;
	up(i, 0, n)
	{
		cin >> a[i];
		if (a[i] > maxa)
		{
			maxa = max(maxa, a[i]);
			argmaxa = i;
		}
		if (a[i] < mina)
		{
			mina = min(mina, a[i]);
			argmina = i;
		}
	}
}

void solve()
{
	if (mina >= 0)
	{
		cout << n - 1 << '\n';
		up(i, 0, n - 1) cout << i + 1 << ' ' << i + 2 << '\n';
	}
	else if (maxa <= 0)
	{
		cout << n - 1 << '\n';
		down(i, n, 2) cout << i << ' ' << i - 1 << '\n';
	}
	else if (abs(maxa) >= abs(mina))
	{
		cout << 2 * n - 1 << '\n';
		up(i, 1, n + 1) cout << argmaxa + 1 << ' ' << i << '\n';
		up(i, 0, n - 1) cout << i + 1 << ' ' << i + 2 << '\n';
	}
	else
	{
		cout << 2 * n - 1 << '\n';
		up(i, 1, n + 1) cout << argmina + 1 << ' ' << i << '\n';
		down(i, n, 2) cout << i << ' ' << i - 1 << '\n';
	}
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    enter();
    solve();
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,j,c;
	ll k,a[100100],x,ans=0ll,s=0ll,tmp=0ll;
	cin >> n >> k; ++k;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	for(j=0; j<40; ++j){
		c = 0;
		for(i=0; i<n; ++i){
			if(a[i]&(1ll<<j)){
				++c;
			}
		}
		if(c*2<n){
			s += (1ll<<j);
		}
	}
	for(j=0; j<40; ++j){
		tmp = 0ll;
		if(!(k&(1ll<<j))){
			continue;
		}
		x = (k/(1ll<<(j+1)))*(1ll<<(j+1))+s%(1ll<<j);
		for(i=0; i<n; ++i){
			tmp += (a[i]^x);
		}
		ans = max(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1152
import sys
from operator import itemgetter
read = sys.stdin.read

N, *AB = map(int, read().split())
A = AB[::2]
B = AB[1::2]
ab = [a + b for a, b in zip(A, B)]
ab, A, B = zip(*sorted(zip(ab, A, B), key=itemgetter(0), reverse=True))
print(sum(A[::2]) - sum(B[1::2]))

Measured memory_bytes: 33068
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

const int BL = 5;
const int WH = 6;

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

void dfs(int x, int y, int C){
  REP(i,4){
	int tx = x + dx[i], ty = y + dy[i];
	if(tab[ty][tx] & C) continue;
	tab[ty][tx] |= (C & 3);
	dfs(tx, ty, C);
  }
}

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

  int W, H;
  while(cin >> W >> H, W){
	fill((int*)tab, (int*)tab+52*52, 3);
	REP(y,H){
	  string line; cin >> line;
	  REP(x,W){
		if(line[x] == 'B')
		  tab[y+1][x+1] = BL;
		else if(line[x] == 'W')
		  tab[y+1][x+1] = WH;
		else
		  tab[y+1][x+1] = 0;
	  }
	}
	for(int y=1;y<=H;++y) for(int x=1;x<=W;++x){
	  if(tab[y][x] == BL)
		dfs(x,y,BL);
	  else if(tab[y][x] == WH)
		dfs(x,y,WH);
	}
	/*
	for(int y=1;y<=H;++y){
	  for(int x=1;x<=W;++x)
		cout << tab[y][x] << " ";
	  cout << endl;
	}
	*/
	int cntB = 0, cntW = 0;
	for(int y=1;y<=H;++y) for(int x=1;x<=W;++x){
	  if(tab[y][x] == 1) ++cntB;
	  else if(tab[y][x] == 2) ++cntW;
	}
	cout << cntB << " " << cntW << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1272
using System;
using System.Linq;

namespace BGuidebook
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力Nの取得
            var n = int.Parse(Console.ReadLine());

            // 住所と点数を取得
            var addresses = new string[n];
            var scores = new int[n];
            for (var i = 0; i < n; i++)
            {
                var inputs = Console.ReadLine().Split().ToArray();
                addresses[i] = inputs[0];
                scores[i] = int.Parse(inputs[1]);
            }

            // 住所の辞書順＞点数順で並び替え
            var orders = Enumerable.Range(1, n)
                .OrderBy(i => addresses[i - 1])
                .ThenByDescending(i => scores[i - 1])
                .ToArray();

            // 解答の出力
            for (var i = 0; i < n; i++)
            {
                Console.WriteLine(orders[i]);
            }
        }
    }
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

int dp[200010],mask[200010],mi[1<<26];

int main(){
    string s; cin>>s; int n=s.size();
    rep(i,0,n+1)dp[i]=inf; dp[0]=0;
    rep(i,0,n)mask[i+1]=mask[i]^(1<<(s[i]-'a'));
    rep(i,0,1<<26)mi[i]=inf; mi[0]=0;
    rep(i,0,n){
        chmin(dp[i+1],mi[mask[i+1]]+1);
        rep(j,0,26)chmin(dp[i+1],mi[mask[i+1]^(1<<j)]+1);
        chmin(mi[mask[i+1]],dp[i+1]);
    }
    printf("%d\n",dp[n]);
    return 0;
}

Measured memory_bytes: 264324
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
ll a[5];
int main(){
    ll n;
    cin >> n;
    rep(i, 5) cin >> a[i];
    sort(a, a+5);
    ll mn;
    if(n%a[0]){
        mn = n/a[0];
    }else{
        mn = n/a[0]-1;
    }
    cout << 5 + mn << endl;
}



Measured memory_bytes: 256
N, Y = map(int, input().split())
Y //= 1000

if 10*N < Y or N > Y:
  print('-1 -1 -1')
  exit()
  
for a in range(N+1):
  for b in range(N-a+1):
    if Y - 10*a - 5*b == N - a - b:
      c = N - a - b
      print('{} {} {}'.format(a,b,c))
      exit()
      
print('-1 -1 -1')

Measured memory_bytes: 64796
#include <cstdio>
int main() {
    int H,M,h,m;
    scanf("%d%d%d%d", &H,&M,&h,&m);
    int t = H * M;
    t -= M * h;
    t -= (H - h) * m;
    printf("%d\n", t);
    return 0;
}

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

  ll a = modpow(10, N, MOD);
  ll b = modpow(9, N, MOD);
  ll c = modpow(8, N, MOD);
  ll ans = a - b - b + c;
  ans %= MOD;
  if (ans < 0) ans += MOD;
  cout << ans << endl;
}

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

int main() {
    int N;
    cin >> N;
    int count = 0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) {
        cin >> v[i];
    }
    for(int i = 0; i < N; i+=2) {
        if((v[i] % 2 != 0)) {
            count++;
        }
    }
    cout << count;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll n;
	cin >> n;

	multimap<ll, ll> tasks;
	for (int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		
		tasks.emplace(b, a);
	}

	bool ans = true;
	ll now = 0;
	for (auto task : tasks) {
		now += task.second;

		if (now > task.first) {
			ans = false;
			break;
		}
	}

	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 12800
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 1; i < (n); i++)

int main() {
    int n;
    cin >> n;
    vector<int> ans(n);
    rep(x, 102) {
        rep(y, 102) {
            rep(z, 102) {
                int tmp = x * x + y * y + z * z + x * y + y * z + z * x;
                if (tmp <= n)
                    ans[tmp - 1]++;
                //配列を格納してforを減らす
            }
        }
    }
    for (int i = 0; i < n; i++)cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x

int main(){
  stack<int> S1;
  stack<pair<int, int>> S2;
  char ch;
  string str;
  int sum = 0;

  cin >> str;
  for( int i = 0; i < str.length(); i++ ){
    ch = str[i];
    if( ch == '\\' ) S1.push(i);
    else if( ch == '/' && S1.size() > 0 ) {
      int j = S1.top(); S1.pop();
      sum += i - j;
      int a = i - j;
      while( S2.size() > 0 && S2.top().first  > j){
        a += S2.top().second; S2.pop();
      }
      S2.push(make_pair(j, a));
    } 
  }

  vector<int> ans;
  while( S2.size() > 0 ){
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for(int i = 0; i < ans.size(); i++){
    cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;

}

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

std::string A, B, C;
int main() {
    std::cin >> A >> B >> C;
    std::cout << A[0] << B[0] << C[0] << std::endl;
}

Measured memory_bytes: 256
s=input()
l=len(s)
a=[0 for i in range(l)]

for i in range(l):
  a[i]=int(s[i])
  
ichi=0
zero=0

for i in range(l):
  if a[i]==1:
    ichi+=1
  else:
    zero+=1
    
print(2*min(ichi,zero))

Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 998244353;



///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
const ll MAX_NUM = 1e14;
ll A[112345];
ll num[112345];
bool flag = true;
ll ans = 0;
ll x = 0;

int main(){
    
    cin>>N;
    REP( i, N+1 ) cin>>A[i];
    
    num[0] = 1;
    REP( i, N+1 ){
        num[i+1] = min( MAX_NUM, ( (num[i]-A[i])*2 ) );
        if( num[i+1] < 0 ){
            flag = false;
            break;
        }
    }
    
    if( flag ){
        REP( i, N+1 ){
            x += A[N-i];
            x = min( x, num[N-i] );
            ans += x;
        }
        cout<<ans<<endl;
    }
    else{
        puts("-1");
    }
    
    return 0;
}


Measured memory_bytes: 4728
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, C] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    print A * B /2

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define REEP(i, N) for(ll i = N - 1; i >= 0; --i)
#define FOR(i,m,n) for(ll i = m; i < n; ++i)
#define RFOR(i,m,n) for(ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b // a ??? b ????????°????????§?¢???????
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;} // a / b ??\??????????°???´??°
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
int main(void) {
    while(true) {
        int n, r;
        cin>>n>>r;
        if(n==0&&r==0) return 0;
        vector<int> c(n, 0);
        int hav = 0;
        int pos = 0;
        int winner = -1;
        while(true) {
            if(r > 0) {
                ++c[pos];
                if (c[pos] == 1) ++hav;
                --r;
                if(r == 0 && hav == 1) {
                    winner = pos;
                    break;
                }
            } else {
                if(c[pos] != 0) --hav;
                r = c[pos];
                c[pos] = 0;
            }
            if(pos < n - 1) ++pos;
            else pos = 0;
        }
        cout<<winner<<endl;
    }
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    ll a,b,b2;
    scanf("%lld %lld.%lld",&a,&b,&b2);
    b=b*100+b2;
    printf("%lld",a*b/100);

    return 0;
}


Measured memory_bytes: 3796
import java.util.*;

class Main
{
	public static void main(String args[]) {

		try {

			Scanner sc = new Scanner(System.in);

			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());

			if (a>b) {
				System.out.println("a > b");
			}
			else if (a<b) {
				System.out.println("a < b");
			}
			else {
				System.out.println("a == b");
			}

		}
		catch (Exception e) {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 17284
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;

const int MAX_N = 200, MAX_M = 10000, MAX_R = 1000;
const int INF = 1000000;
int w[MAX_N + 1][MAX_N + 1][2], rs[MAX_R];
int dp[MAX_R][MAX_N + 1];

int main()
{
    int N, M, R;
    while(cin >> N >> M && N && M) {
        for(int i = 1; i <= N; i++) 
            for(int j = 1; j <= N; j++) 
                for(int k = 0; k < 2; k++)
                    w[i][j][k] = (i == j) ? 0 : INF;
            
        int x, y, t;
        char sl;
        for(int i = 0; i < M; i++) {
            cin >> x >> y >> t >> sl;
            if(sl == 'L') 
                w[x][y][0] = w[y][x][0] = t;
            else 
                w[x][y][1] = w[y][x][1] = t;
        }

        cin >> R;
        for(int i = 0; i < R; i++) 
            cin >> rs[i];

        for(int t = 0; t < 2; t++) 
            for(int k = 1; k <= N; k++)
                for(int i = 1; i <= N; i++)
                    for(int j = 1; j <= N; j++)
                        w[i][j][t] = min(w[i][j][t], w[i][k][t] + w[k][j][t]);
        
        for(int i = 0; i < R; i++)
            for(int j = 1; j <= N; j++)
                dp[i][j] = INF;
        
        dp[0][rs[0]] = 0;
        for(int i = 1; i < R; i++) {
            int to = rs[i], from = rs[i - 1];
            for(int j = 1; j <= N; j++) {
                //Land Only
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + w[from][to][0]);
                //With Sea
                for(int k = 1; k <= N; k++) {
                    dp[i][j] = min(dp[i][j], dp[i - 1][k] + w[from][k][0] + w[k][j][1] + w[j][to][0]);
                }
            }
        }
        
        
        int res = INF;
        for(int j = 1; j <= N; j++)
            res = min(res, dp[R - 1][j]);

        cout << res << endl;
    }
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

int main(){
	fast;
	int A,B;
	cin>>A>>B;
	cout<<A * B;
}



Measured memory_bytes: 3652