akhauriyash/Code-Regression huggingface dataset:
n,K=map(int,input().split())
S=[[0 for i in range(n+1)] for j in range(n+1)]
p=[list(map(int,input().split())) for i in range(n)]
p.sort(key=lambda x:x[1])
for i in range(n):
    p[i].append(i)
p.sort()
y=[0]*n
for i in range(n):
    y[i]=p[i][2]
for i in range(n):
    S[i+1][y[i]+1]=1
X=[p[i][0] for i in range(n)]
Y=[p[i][1] for i in range(n)]
X.sort();Y.sort()
for i in range(1,n+1):
    for j in range(1,n+1):
        S[i][j]=S[i][j]+S[i][j-1]+S[i-1][j]-S[i-1][j-1]
ans=10**20
for i in range(n):
    for j in range(n):
        for k in range(i+1,n+1):
            for l in range(j+1,n+1):
                if S[k][l]-S[k][j]-S[i][l]+S[i][j]>=K:
                    #print(S[k][l]-S[k][j]-S[i][l]+S[i][j])
                    if ans > (X[k-1]-X[i])*(Y[l-1]-Y[j]):
                        ans = (X[k-1]-X[i])*(Y[l-1]-Y[j])
                #print(ans)
print(ans)

Measured memory_bytes: 42220
s = [i for i in input()]
result = 1
i = 0

while i < len(s)-1:
  if s[i] == s[i+1]:
    i += 3
    result += 2
  else:
    i += 1
    result += 1
    
if i == len(s):
  result -= 1
elif i > len(s):
  result -= 2
  
print(result)

Measured memory_bytes: 5096
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
string a, b;
int main() {
	cin >> a >> b;
	int N = a.length();
	if(N != b.length()) {puts("No"); return 0;}
	//for(int i = 0; i < N; i++) a[i + N] = a[i];
	a = a + a;
	//cout << a << endl << b;
	if(a.find(b) != string::npos) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int timer = 0;
    map<string ,int> mp;
    cin >> N;
    for(int i = 0; i < N; i++) {
        string S;
        cin >> S;
        mp[S]++;
        chmax(timer, mp[S]);
    }
    for(auto tmp : mp) {
        if(tmp.second == timer) cout << tmp.first << endl;
    }
    return 0;
}


Measured memory_bytes: 23808
#!/usr/bin/env python3
#ABC116 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n,k = map(int,input().split())
td = [list(map(int,input().split())) for _ in range(n)]
td.sort(key = itemgetter(1),reverse = True)
f = [0]*n
ans = 0
kind = 0
x = []
for i in range(k):
    t,d = td[i]
    ans += d
    if not f[t-1]:
        kind += 1
    else:
        x.append(d)
    f[t-1] += 1
ans += kind**2
x.sort()
x = deque(x)
y = ans
for i in range(k,n):
    t,d = td[i]
    if not x:
        break
    if f[t-1]:
        continue
    y += d - x.popleft() + 2*kind + 1
    f[t-1] = 1
    kind += 1
    ans = max(ans,y)
print(ans)


Measured memory_bytes: 68096
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	int a=x2-x1;
	int b=y2-y1;
	cout<<(x2-b)<<" "<<(y2+a)<<" "<<(x1-b)<<" "<<(y1+a);
	return 0;
}

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

ll solve() {
    ll N;
    cin >> N;
    vector<vector<int>> G(N, vector<int>());
    string s;
    for ( int i = 0; i < N; i++ ) {
        cin >> s;
        for ( int j = 0; j < N; j++ ) {
            if ( s[j] == '1' ) {
                G[i].push_back(j);
            }
        }
    }

    auto bfs = [&](int ii) -> int {
        vector<int> dep(N,-1);
        queue<int> q;
        q.push(ii);
        dep[ii] = 0;
        while ( !q.empty() ) {
            int v = q.front();
            q.pop();
            for ( int x : G[v] ) {
                if ( dep[x] != -1 ) {
                    if ( dep[x] != dep[v] + 1 && dep[x] != dep[v] - 1 ) return -1;
                    continue;
                }
                dep[x] = dep[v] + 1;
                q.push(x);
            }
        }
        ll a = 0;
        for ( int j = 0; j < N; j++ ) {
            if ( a < dep[j] ) a = dep[j];
        }
        return a + 1;
    };

    ll ans = -1;
    for ( int i = 0; i < N; i++ ) {
        int k = bfs(i);
        if ( ans < k ) ans = k;
    }
    
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 432
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef struct bnode{
    int key;
    struct bnode *parent;
    struct bnode *left;
    struct bnode *right;
}BinNode;
 
typedef struct btree{
    BinNode *bn;
    BinNode *root;
    int size;
}BinTree;
 
BinNode initBinNode(int);
void Insert(BinTree *, BinNode *);
void InorderPrint(BinNode *);
void PreorderPrint(BinNode *);
 
int main(void){
    int m, k;
    char s[10];
    int i;
 
    BinTree t;
    BinTree *T = &t;
    T->root = NULL;
    T->size = 0;
 
    scanf("%d", &m);
    T->bn = calloc(m, sizeof(BinNode));
    for (i = 0; i < m; i++){
        scanf("%s", s);
        if (!strcmp(s, "insert")){
            scanf("%d", &k);
            T->bn[T->size] = initBinNode(k);
            BinNode *z = &(T->bn[T->size]);
            T->size++;
            Insert(T, z);
        }
        else if (!strcmp(s, "print")){
                InorderPrint(T->root);
                printf("\n");
                PreorderPrint(T->root);
                printf("\n");
        }
    }
 
    return 0;
}
 
 
BinNode initBinNode(int v){
    BinNode z;
    z.key = v;
    z.parent = NULL;
    z.left = NULL;
    z.right = NULL;
 
    return z;
}
 
void Insert(BinTree *T, BinNode *z){
    BinNode *x, *y;
 
    y = NULL;
    x = T->root;
    while (x != NULL){
        y = x;
        if (z->key < x->key)
            x = x->left;
        else
            x = x->right;
    }
    z->parent = y;
 
    if (y == NULL)
        T->root = z;
    else if (z->key < y->key)
        y->left = z;
    else
        y->right = z;
}
 
void InorderPrint(BinNode *p){
    if (p != NULL){
        InorderPrint(p->left);
        printf(" %d", p->key);
        InorderPrint(p->right);
    }
}
 
void PreorderPrint(BinNode *p){
    if (p != NULL){
        printf(" %d", p->key);
        PreorderPrint(p->left);
        PreorderPrint(p->right);
    }
}

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

namespace AtCoder_solve
{
    class Program
    {
        static void Main(string[] args)
        {
            var data = Console.ReadLine().Split();
            var n = int.Parse(data[0]);
            var k = int.Parse(data[1]);
            var cnt = 0;
            var ans = 0;

            while (n >= k)
            {
                n /= k;
                cnt++;
            }
            ans = cnt + 1;
            

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    String n=gs();
	    //String y=gs();

        //System.out.println(2*b-a);
        if ((n.charAt(0)==n.charAt(1)&&n.charAt(01)==n.charAt(2)) || (n.charAt(1)==n.charAt(2)&&n.charAt(2)==n.charAt(3))) {
        	System.out.print("Yes");
        }else {
        	System.out.print("No");
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
	
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main(){
	/*input*/
	int n;	cin >> n;
	/*calculation*/
	int s = 0;
	int tmp = n; 
	while(tmp){
		int i = tmp%10;
		tmp = (tmp - i)/10; 
		s += i;
	}
	/*output*/
	if(n%s){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long int h[100005]={0},n,dp[100005]={0},k;
long long int calc(long long int i)
{
	if(dp[i]!=-1)
		return dp[i];
	else
	{
		if(i>=k+1)
		{
			long long int a=LONG_MAX,j,x;
			for(j=i-k;j<i;j++)
			{
				x=calc(j)+fabs(h[i]-h[j]);
				a=x<a?x:a;
			}
			dp[i]=a;
			return dp[i];
		}
		else
		{
			long long int a=LONG_MAX,j,x;
			for(j=1;j<i;j++)
			{
				x=calc(j)+fabs(h[i]-h[j]);
				a=x<a?x:a;
			}
			dp[i]=a;
			return dp[i];
		}
	}
}
int main()
{
	long long int i,ans;
	cin>>n>>k;
	for(i=1;i<=n;i++)
		cin>>h[i];
	for(i=0;i<=n;i++)
		dp[i]=-1;
	dp[1]=0;
	dp[2]=fabs(h[2]-h[1]);
	ans=calc(n);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6528
Spades   = 0
Hearts   = 1
Clovers  = 2
Diamonds = 3
Cards = [[Spades, Hearts, Clovers, Diamonds] for j in range(13)]

for i in range(4):
    for j in range(13):
        Cards[j][i] = True

n = input()

for i in range(n):
    Input = raw_input().split()

    Numb = int(Input[1])
    if Input[0] == 'S':
        Mark = Spades
    if Input[0] == 'H':
        Mark = Hearts
    if Input[0] == 'C':
        Mark = Clovers
    if Input[0] == 'D':
        Mark = Diamonds

    Cards[Numb - 1][Mark] = False

for i in range(4):
    for j in range(13):
        if Cards[j][i]:
            if i == Spades:
                print 'S', j + 1
            if i == Hearts:
                print 'H', j + 1
            if i == Clovers:
                print 'C', j + 1
            if i == Diamonds:
                print 'D', j + 1

Measured memory_bytes: 6488
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

typedef long long ll;

void add_mod(ll& val, ll add_val) {
	val = (val + add_val) % 100000007;
}

int main (int argc, char* argv[]) {
	ll n, m;
	cin >> n >> m;
	priority_queue<ll> q;
	for (ll i = 0; i < n; i++) {
		ll nn;
		cin >> nn;
		q.push(nn);
	}
	for (ll i = 0; i < m; i++) {
		auto current = q.top();
		q.pop();
		current /= 2;
		q.push(current);
	}
	ll res = 0;
	while (!q.empty()) {
		res += q.top();
		q.pop();
	}
	cout << res << endl;
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int used[27];

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	string s;
	cin >> s;

	for(int i=0; i<s.size(); i++){
		used[s[i] - 'a'] = 1;
	}

	for(int i=0; i<26; i++){
		if(used[i] == 0){
			printf("%c\n", 'a'+i);
			return 0;
		}
	}
	puts("None");


	return 0;
}


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

using namespace std;

int main()
{
   string x;
   cin>>x;
   if(x=="xxx")
   {
       cout<<700;
       
   }
   else if(x=="ooo")
   {
       cout<<1000<<endl;
   }
   else if(x=="xox"||x=="oxx"||x=="xxo")
   cout<<800;
   else cout<<900;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;
 
 
public class Main{
     
	public static boolean check(int pos, int[] array, int mod){
		if(pos < 2){
			return true;
		}
		
		int m = 0;
		if(pos >= 2){
			m = (array[0] + array[1] + array[2]) % mod;
		}
		
		if(pos >= 5 && ((array[3] + array[4] + array[5]) % mod != m)){
			return false;
		}
		
		if(pos >= 6 && (((array[0] + array[3] + array[6]) % mod != m) || (array[2] + array[4] + array[6]) % mod != m)){
			return false;
		}
		
		if(pos >= 7 && ((array[1] + array[4] + array[7]) % mod != m)){
			return false;
		}
		
		if(pos >= 8 && (((array[2] + array[5] + array[8]) % mod != m) || (array[0] + array[4] + array[8]) % mod != m)){
			return false;
		}
		
		return true;
	}
	
	public static int dfs(int pos, int[] array, boolean[] used, int mod){
		//System.out.println(pos);
		if(pos < 9){
			if(array[pos] != 0){
				if(used[array[pos]]){
					return 0;
				}else if(!check(pos, array, mod)){
					return 0;
				}else{
					used[array[pos]] = true;
					int ret = dfs(pos + 1, array, used, mod);
					used[array[pos]] = false;
					
					return ret;
				}
			}else{
				int sum = 0;
				
				for(int i = 1; i <= 10; i++){
					//System.out.println(Arrays.toString(used));
					if(used[i]){
						continue;
					}else{
						used[i] = true;
						array[pos] = i;
							
						if(!check(pos, array, mod)){
							array[pos] = 0;
							used[i] = false;
							continue;
						}
						sum += dfs(pos + 1, array, used, mod);
						array[pos] = 0;
						used[i] = false;
					}
				}
				
				return sum;
			}
		}else{
			return 1;
		}
	}
	
    public static void main(String[] args) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	
    	while(true){
    		int[] array = new int[10];
    		
    		for(int i = 0; i < 10; i++){
    			array[i] = sc.nextInt();
    		}
    		
    		boolean flag = true;
    		for(int i = 0; i < 10; i++){
    			if(array[i] != -1){
    				flag = false;
    				break;
    			}
    		}
    		
    		if(flag){
    			break;
    		}
    		
    		if(array[9] != 0){
    			boolean[] used = new boolean[11];
    			used[array[9]] = true;
    			System.out.println(dfs(0, array, used, array[9]));
    		}else{
    			int sum = 0;
    			boolean[] used = new boolean[11];
    			for(int i = 1; i <= 10; i++){
    				used[i] = true;
    				sum += dfs(0, array, used, i);
    				used[i] = false;
    			}
    			System.out.println(sum);
    		}
    	}
    }
     
}

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

int main() {
  int A,B,C,X,Y,plice,ans;
  cin >> A >> B >> C >> X >> Y;
  
  cout << min(A*X + B*Y,min( C*2*X + B*max(Y-X,0), min(C*2*Y + A*max(X-Y,0),C*2*max(X,Y))) ) << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define int long long
//#define _DEBUG
using namespace std;
string sa, sb;
int T[1009][1009];
int solve(){
    int sal = sa.length(), sbl = sb.length();
    for(int a=0; a<=sal; a++){
        for(int b=0; b<=sbl; b++){
            if(a==0 || b==0){
                T[a][b] = 0;
            }else if(sa[a-1] == sb[b-1]){
                T[a][b] = 1 + T[a-1][b-1];
            }else{
                T[a][b] = max(T[a][b-1], T[a-1][b]);
            }
        }
    }
    return T[sal][sbl];
}
signed main(){
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> sa >> sb;
        cout << solve() << endl;
    }
}


Measured memory_bytes: 11112
/*input
200000 0
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
struct segt{
    ll seg[4*maxn];
    int n;
    void resize(int _n){
        n=_n;
    } 
    void mdf(int idx,int l,int r,int p,int x){
        if(r<p or l>p) return;
        if(l==r){
            seg[idx]=x;
            return;
        }
        int mid=(l+r)/2;
        mdf(idx*2,l,mid,p,x);
        mdf(idx*2+1,mid+1,r,p,x);
        seg[idx]=max(seg[idx*2],seg[idx*2+1]);
    }
    int query(int idx,int l,int r,int ql,int qr){
        if(l>qr or r<ql) return 0;
        if(ql<=l and r<=qr) return seg[idx];
        int mid=(l+r)/2;
        return max(query(idx*2,l,mid,ql,qr),query(idx*2+1,mid+1,r,ql,qr));
    }
    int query(int l,int r){
        return query(1,1,n,l,r);
    }
    void mdf(int p,int x){
        mdf(1,1,n,p,x);
    }
}row,col;
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    ll n,q;
    cin>>n>>q;
    row.resize(n+1);
    col.resize(n+1);
    row.mdf(n,INF);
    col.mdf(n,INF);
    while(q--){
        int a,b;
        cin>>a>>b;
        if(a==1){
            int l=1,r=n;
            while(l<r){
                int mid=(l+r)/2;
                if(row.query(1,mid)>=b) r=mid;
                else l=mid+1;
            }
            col.mdf(b,l-1);
        }
        else{
            int l=1,r=n;
            while(l<r){
                int mid=(l+r)/2;
                if(col.query(1,mid)>=b) r=mid;
                else l=mid+1;
            }
            row.mdf(b,l-1);
        }
    }
    ll ans=(n-2)*(n-2);
    REP1(i,n-1){
        ans-=max(col.query(i,i)-1,0);
        ans-=max(row.query(i,i)-1,0);
    }
    cout<<ans<<'\n';
}  


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

int main(){
  ll n,d,m;
  cin >> n;
  for(ll i = sqrt(n); i>0;i--){
    if(n/i*i==n){
      m=n/i;
      while(m/10>0){
        m/=10;
        d++;
      }
      cout << d+1<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
N = int(input())
S = input()

# valid: ..*##*
# base: all black
dist = S.count(".")
min_dist = dist
for i in range(N):
  # .*i + #*(N-i)
  if S[i] == "#":
    dist += 1
  else:
    dist -= 1
    if dist < min_dist:
      min_dist = dist

print(min_dist)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll x;
  cin >> x;
  vector<int> vec(max(x+1, (ll)1e6+1), 0);
  rep(i, 6) {
    vec.at(i+100) = 1;
    rep(j, x+1) {
      if (i+j+100 > x) continue;

      if (vec.at(j)) vec.at(i+j+100) = 1;
    }
  }
  if (vec.at(x)) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 7140
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=3e3+5;
ll inf=1e15;

ll ar[sz][sz],dp[sz][sz][5],n,m,k;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n>>m>>k;
        while(k--)
        {
            ll x,y,val;
            cin>>x>>y>>val;
            ar[x][y]=val;
        }
        // memset(dp,-1,sizeof(dp));
        // cout<<f(0,0,0);

        for(int row=1;row<=n;row++)
        {
            for(int col=1;col<=m;col++)
            {
                for(int cnt=1;cnt<=3;cnt++)
                {
                    dp[row][col][cnt]=max(dp[row][col-1][cnt],dp[row][col-1][cnt-1]+ar[row][col]);
                }
                dp[row][col][0]=max(dp[row][col][0],max(dp[row-1][col][1],max(dp[row-1][col][2],dp[row-1][col][3])));
                dp[row][col][1]=max(dp[row][col][1],max(dp[row-1][col][1],max(dp[row-1][col][2],dp[row-1][col][3]))+ar[row][col]);
                dp[row][col][2]=max(dp[row][col][2],max(dp[row-1][col][1],max(dp[row-1][col][2],dp[row-1][col][3]))+ar[row][col]);
            }
        }

        cout<<max(dp[n][m][3],max(dp[n][m][1],dp[n][m][2]))<<endl;
    }

    return 0;
}

Measured memory_bytes: 426096
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}



// check
// 問題文を復唱する


int main() {
  ll n,k,h,w;
  ll a,b;
  cin >> a >> b ;
  // string s;
  // cin >> s;
  // vector<ll> a(n,0);
  // cin >> a;

  ll ans = 0;
  // for (int i = 0; i < n; i++) {
      
  // }

  if (a >=13)ans = b;
  if (a <13 && a>=6)ans = b/2;



  cout << ans <<endl;

  
  // cout << (true? "Yes":"No");


}




















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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9;
inline int mod(ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit(ll b, ll i) { return b & (1 << i); }
inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; }
// struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while (a >= b && k > 0) {
        b = b * 2;
        k--;
    }
    while (b >= c && k > 0) {
        c = c * 2;
        k--;
    }
    if(a < b && b < c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;

int main(){

	vector<char>a(6);

	for(int i = 0; i < 6 ; i++){
		cin >> a.at(i);
	}

	if(a.at(0) == a.at(5) && a.at(1) == a.at(4) && a.at(2)==a.at(3)){
		cout << "YES" <<endl;
	}

	else{
		cout <<"NO" <<endl;
	}
}

Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int r,g,b;

int main() {
  INCANT;
  cin >> r >> g >> b;
  string ans = (g*10+b)%4==0?"YES":"NO";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<int> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    int n;cin>>n;
    string S;cin>>S;
    int need_left=0,need_right=0;
    rep(i,n){
        if(S[i]=='('){
            need_right++;
        }
        else if(need_right)need_right--;
        else need_left++;
    }
    rep(i,need_left)cout<<'(';
    cout<<S;
    rep(i,need_right)cout<<')';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var S = LnStr();
        var res = "";
        foreach(var i in S)
        {
            res += "x";
        }
        print(res);
    }


public static long SumAtoB(long a,long b){var length = b - a + 1;return (a + b) * (length / 2) + (length % 2 == 1 ? (a + b) / 2 : 0);}
public static long PowLite(long n, long p, int mod = (int)1e9 + 7){long ans = 1;long now = n;for (; p > 0; p >>= 1){if ((p & 1) == 1){ans *= now;ans %= mod;}now *= now;now %= mod;}return ans;}
public static void print(object obj) { Console.WriteLine(obj); }
public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
public static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable{var a = new List<T>(array).ToArray();var res = new List<T[]>();res.Add(new List<T>(a).ToArray());var n = a.Length;var next = true;while (next){next = false;int i;for (i = n - 2; i >= 0; i--){if (a[i].CompareTo(a[i + 1]) < 0) break;}if (i < 0) break;var j = n;do{j--;} while (a[i].CompareTo(a[j]) > 0);if (a[i].CompareTo(a[j]) < 0){var tmp = a[i];a[i] = a[j];a[j] = tmp;Array.Reverse(a, i + 1, n - i - 1);res.Add(new List<T>(a).ToArray());next = true;}}return res;}}


Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

typedef vector<pair<long long, long long>> Intervals;
Intervals mergeIntervals(Intervals a) {
    Intervals res;
    sort(a.begin(), a.end());
    for (const auto & b : a) {
        if (res.size() == 0 || res.back().second < b.first)
            res.push_back(b);
        else
            res.back().second = max(res.back().second, b.second);
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A, B;
    cin >> A >> B;
    if (A == B) {
        cout << 1 << endl;
        return 0;
    }
    int r = 59;
    while ((A >> r & 1) == (B >> r & 1))r--;
    A &= (1ll << (r+1)) - 1;
    B &= (1ll << (r+1)) - 1;

    Intervals U;
    U.push_back({ A,1ll << r });
    U.push_back({ 1ll << r | A,1ll << (r + 1) });

    int k = r - 1;
    while (k >= 0 && (B >> k & 1) == 0)k--;
    U.push_back({ 1ll << r,(1ll << r) + (1ll << (k + 1)) });

    auto V = mergeIntervals(U);
    ll ans = 0;
    each(lr, V)ans += lr.second - lr.first;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=100005,INF=1<<28;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        int cnt=0;
        
        bool ok=true;
        
        for(int i=0;i<N;i++){
            string S;cin>>S;
            if(S[0]=='A') cnt++;
            else cnt--;
            
            if(cnt<0) ok=false;
        }
        
        if(ok&&cnt==0) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        
        break;
    }
}



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

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

    vector<long long> dp(1e6+1, 0);

    long long a = 1, b = 6, c = 9;

    for(long long i = 1; i <= n; i++){
        if(i >= b*6) b = b*6;
        if(i >= c*9) c = c*9;

        if(i <= 5) dp[i] = i;
        else if(i <= 8) dp[i] = min(dp[i-a] + 1, dp[i-b] + 1);
        else{
            dp[i] = min(dp[i-a]+ 1, dp[i-b]+ 1);
            dp[i] = min(dp[i], dp[i-c]+ 1);
        }

    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 11188
x,y = map(int, input().split())

p = 7+pow(10,9)
def cmb(n,r,p):
    numerator = 1
    for i in range(n-r+1, n+1):
        numerator = numerator * i % p
    denominator = 1
    for i in range(1, r+1):
        denominator = denominator * i % p
    return numerator * pow(denominator, p-2, p) % p


if (x+y)% 3 == 1 or (x+y)%3 == 2:
    print(0)
else:
    n = (-x + 2*y)/3 # (+1,+2)の座標の変化の回数
    m = (2*x - y )/3 # (+2, +1)の座標の変化の回数
    if n<0 or m<0:
        print(0)
    else:
        print(cmb(int(n+m), int(n), p))


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

typedef long long lli;
const lli MAXN = 2002;
const lli INF = 1LL<<60;
lli N, A[MAXN];
lli dp[MAXN][MAXN];

int main() {
  while(cin >> N) {
    for(lli i = 0; i < N; ++i) cin >> A[i];
    memset(dp, -1, sizeof(dp));
    for(lli i = 0; i < N; ++i) {
      dp[N-1][(i+1)%N] = A[i];
    }
    for(lli l = N-1; l > 0; --l){
      for(lli i = 0; i < N; ++i) {
        if(dp[l][i] == -1) continue;
        lli j = (i + l - 1) % N;
        if((N-l) % 2) {
          if(A[i] < A[j]) {
            dp[l-1][i] = max(dp[l-1][i], dp[l][i]);
          } else {
            dp[l-1][(i+1)%N] = max(dp[l-1][(i+1)%N], dp[l][i]);
          }
        } else {
          dp[l-1][i] = max(dp[l-1][i], dp[l][i] + A[j]);
          dp[l-1][(i+1)%N] = max(dp[l-1][(i+1)%N], dp[l][i] + A[i]);
        }
      }
    }
    lli res = 0;
    for(lli i = 0; i < N; ++i) {
      res = max(res, dp[0][i]);
    }
    cout << res << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

ll t1, t2, a1, a2, b1, b2;

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

	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	ll A = a1 - b1, B = a2 - b2;
	ll delta1 = A * t1, delta2 = A * t1 + B * t2;
	
	if (delta2 == 0)
		cout << "infinity" << endl;
	else
	{
		if (delta1 > 0 && delta2 > 0)
			cout << 0 << endl;
		else if (delta1 < 0 && delta2 < 0)
			cout << 0 << endl;
		else
		{
			if (abs(delta1) % abs(delta2) == 0)
				cout << 2 * (abs(delta1) / abs(delta2) + 1) - 2 << endl;
			else
				cout << 2 * (abs(delta1) / abs(delta2) + 1) - 1 << endl;
		}
		/*ll delta1 = a1 * t1 - b1 * t1;
		ll delta2 = a1 * t1 + a2 * t2 - b1 * t1 - b2 * t2;
		if (delta1 > 0 && delta2 > 0)
			cout << 0 << endl;
		else if (delta1 < 0 && delta2 < 0)
			cout << 0 << endl;
		else
		{
			ll delta = abs(delta1 + delta2) - abs(delta2);
			cout << (abs(delta1) + abs(delta) - 1) / abs(delta) << endl;
		}*/
	}
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] H = new long[N];
        long rem = 0;
        boolean result = true;
        
        for(int i = 0; i < N; i++){
            H[i] = sc.nextLong();
            if(i == 0)continue;
            if(H[i] < rem - 1){
                result = false;
                break;
            }
            
            if(H[i-1] == H[i] + 1){
                rem = H[i-1];
            }else if(H[i-1] > H[i]){
                result = false;
                break;
            }
            
        }
        if(result){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 50840
#define loop(i,j,k) for(long long i = j;i < k;i++)
#include <iostream>
#include <queue>
#include <array>
#include <utility>
#include <set>

using namespace std;

long mhash(array<array<int,3>,3>& e) {
	long res = 0;
	long cb = 1;
	loop(i,0,9) {
		res += cb * e[i/3][i%3];
		cb = cb * 9;
	}
	return res;
}

bool cp(array<array<int,3>,3>& e) {
	loop(i,0,3)loop(j,0,3)if(e[i][j]!=(1+j+i*3)%9)return false;
	return true;
}


int main() {
	set<long> ald; 
	array<array<int,3>,3> pz;
	queue<pair<array<array<int,3>,3> ,int>> q;
	loop(i,0,3)loop(j,0,3)cin>>pz[i][j];
	q.push(make_pair(pz,0));
	if(cp(pz)) {
		cout << 0 << endl;
		return 0;
	}
	while(!q.empty()) {
		auto cur = q.front().first;
		int dep = q.front().second + 1;
		q.pop();
		int r=-1,c=-1;
		loop(i,0,3)loop(j,0,3)if(cur[i][j] == 0){r=i;c=j;}
		if(r!=2) {
			swap(cur[r][c],cur[r+1][c]);
			if(cp(cur)) {
				cout << dep << endl;
				return 0;
			} else {
				long hs = mhash(cur);
				if(ald.find(hs) == ald.end()){
					q.push(make_pair(cur,dep));
					ald.insert(hs);
				}
			}
			swap(cur[r][c],cur[r+1][c]);
		}
		if(r!=0) {
			swap(cur[r][c],cur[r-1][c]);
			if(cp(cur)) {
				cout << dep << endl;
				return 0;
			} else {
				long hs = mhash(cur);
				if(ald.find(hs) == ald.end()){
					q.push(make_pair(cur,dep));
					ald.insert(hs);
				}
			}
			swap(cur[r][c],cur[r-1][c]);
		}
		if(c!=2) {
			swap(cur[r][c],cur[r][c+1]);
			if(cp(cur)) {
				cout << dep << endl;
				return 0;
			} else {
				long hs = mhash(cur);
				if(ald.find(hs) == ald.end()){
					q.push(make_pair(cur,dep));
					ald.insert(hs);
				}
			}
			swap(cur[r][c],cur[r][c+1]);
		}
		if(c!=0) {
			swap(cur[r][c],cur[r][c-1]);
			if(cp(cur)) {
				cout << dep << endl;
				return 0;
			} else {
				long hs = mhash(cur);
				if(ald.find(hs) == ald.end()){
					q.push(make_pair(cur,dep));
					ald.insert(hs);
				}
			}
			swap(cur[r][c],cur[r][c-1]);
		}
	}
}



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

int main(void){
    int count[4][3][10], n, b, f, r, v;
    cin >> n;

    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 10; k++){
                count[i][j][k] = 0;
            }
        }
    }

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

    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 10; k++){
                cout << ' ' << count[i][j][k];
            }
            cout << endl;
        }
        if(i < 3) cout << "####################" << endl;
    }

    return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(char a,char b){
	return a>b;
}
int main()
{
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),cmp);
	if(s<t)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
//#include    <bits/stdc++.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define N  500005
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f
#define MOD 998244353
#define Mod 1e9 + 7
template<typename T> inline T max(T a,T b,T c){
    return max(a,max(b,c));
}
template<typename T> inline T min(T a,T b,T c){
    return min(a,min(b,c));
}
template<typename T> inline T max(T a,T b,T c,T d){
    return max(a,max(b,c,d));
}
template<typename T> inline T min(T a,T b,T c,T d){
    return min(a,min(b,c,d));
}
const int  dx[]={0,1,0,-1,0,1,-1,1,-1};
const int  dy[]={0,0,1,0,-1,1,-1,-1,1};
typedef long long ll;
using namespace std;
int main(){
   ll n,a,b;
   scanf("%lld",&n);
   for (int i=1;i<=n;i++){
    scanf("%lld%lld",&a,&b);
    ll t1=a*b;
    ll t2=sqrt(t1);
     if (t2*t2==t1){
         if (a==b) printf("%lld\n",t2*2-2);
         else printf("%lld\n",t2*2-3);
     }
     else if (t2*(t2+1)<t1) printf("%lld\n",t2*2-1);
     else printf("%lld\n",t2*2-2);
   }
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int d,t,s;cin>>d>>t>>s;
    if(d<=s*t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  int ans = 0;
  int f = 0;
  int g = 0;

  for (int i = 1; i < n; i++)
  {
    f = f + i;
  }
  for (int i = 1; i < m; i++)
  {
    g = g + i;
  }

  cout << f + g << endl;
}

Measured memory_bytes: 256
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

const int N = 1e5 + 5;

int n;
int a[N];
ll mx[N];

int main()
{
  cin >> n;
  for(int i = 0; i <= n; i++) {
    cin >> a[i];
  }
  if(n == 0) {
    if(a[0] == 1) cout << 1 << endl;
    else cout << -1 << endl;
    return 0;
  }
  if(a[0]) return cout << -1 << endl, 0;
  mx[n] = a[n];
  for(int i = n - 1; i >= 0; i--) {
    mx[i] = a[i] + mx[i + 1];
  }
  for(int i = 0; i <= n; i++) {
    if((1LL << i) > mx[i])  break;
    else mx[i] = (1LL << i);
  }
  ll ans = mx[n];
  for(int i = 0; i < n; i++) {
    mx[i + 1] = min(mx[i + 1], (mx[i] - a[i]) * 2);
  }
  for(int i = 0; i <= n; i++)
    if(mx[i] < a[i]) {
      cout << -1 << endl;
      return 0;
    }
  for(int i = 0; i < n; i++)
    if(mx[i] == a[i]) {
      cout << -1 << endl;
      return 0;
    }
  for(int i = 0; i < n; i++) {
    ans += mx[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4752
//
// Created by yamunaku on 2019/11/05.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

ll b, m;

ll modpow(ll x, ll a){
    ll ans = 1;
    while(a > 0){
        if(a % 2) ans = ans * x % m;
        a /= 2;
        x = x * x % m;
    }
    return ans;
}

void matprod(mtl &ret, mtl &x, mtl &y){
    int n = x.size();
    mtl ans = mtl(n, vl(n, 0));
    rep(i, n){
        rep(j, n){
            rep(k, n){
                ans[i][j] = (ans[i][j] + x[i][k] * y[k][j] % m) % m;
            }
        }
    }
    ret = ans;
}

void matpow(mtl &ret, mtl &x, ll a){
    int n = x.size();
    mtl ans = mtl(n, vl(n, 0));
    rep(i, n) ans[i][i] = 1;
    while(a > 0){
        if(a % 2) matprod(ans, ans, x);
        a /= 2;
        matprod(x, x, x);
    }
    ret = ans;
}

ll solve(ll n, ll c, ll t){
    mtl x = {
            {1, 0, 0},
            {b, 1, 0},
            {0, 1, t}
    };
    matpow(x, x, n);
    return (x[2][0] + x[2][1] * c % m) % m;
}


int main(){
    ll s, a;
    cin >> s >> a >> b >> m;
    ll ans = 0;
    ll now = 0;
    for(ll t = 10, k = 1; now < s && k <= 18; t *= 10, k++){
        if(b * now + a < t){
            ll w = max(0ll, min((t - 1 - (b * now + a)) / b + 1, s - now));
            rep(i,k){
                ans = ans * modpow(10, w) % m;
            }
            ans = (ans + solve(w, (b * now + a) % m, t % m)) % m;
            now += w;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if((a+b)<=(a+c)&&(a+b)<=(b+c)) printf("%d\n",a+b);
else if((a+c)<=(a+b)&&(a+c)<=(b+c)) printf("%d\n",a+c);
else printf("%d\n",b+c);
return 0;
}

Measured memory_bytes: 128
from sys import stdin

N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
for k in reversed(range(1, N + 1)):
    if a[k - 1] == 1:
        ans.append(k)
        tmp = 1
        while tmp * tmp <= k:
            if k % tmp == 0:
                a[tmp - 1] ^= 1
                if tmp != k // tmp:
                    a[k // tmp - 1] ^= 1
            tmp += 1

x = len(ans)
print(x)
if x >= 0:
    print(*ans)


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

using namespace std;

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

int N;
vector<int> v;

int tanka[] = {5, 7, 5, 7, 7};

bool saiki(int pos, int num = 0,int state = 0)
{
	if (pos == (int) v.size()) return false;
	num += v[pos];
	if (tanka[state] < num) return false;
	if (tanka[state] == num) {
		state++;
		num = 0;
	}
	if (state == 5) return true;
	return saiki(pos+1, num, state);
}

int main()
{
	cin >> N;
	while(N) {
		rep(i, N) {
			string s;
			cin >> s;
			v.PB(s.length());
		}
		rep(i, N) {
			if (saiki(i)) {
				cout << i+1 << endl;
				break;
			}
		}
		cin >> N;
		v.clear();
	}
	return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define the_flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define input_output freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)

using namespace std;

int main()
{
	//input_output;
	the_flash;
	ll n, d, x, y;
	cin >> n >> d;
	int count = 0;

	while (n--)
	{
		double cal, res;
		cin >> x >> y;
		cal = pow(x, 2) + pow(y, 2);
		res = sqrt(cal);
		if (ceil(res) <= d)
			count++;
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3692
use std::io;
use std::cmp;


fn main() {
    let (_, _, x, y) = {
        let i = read::<isize>();
        (i[0], i[1], i[2], i[3])
    };

    let xn = read::<isize>();
    let ym = read::<isize>();
    let xmax = xn.iter().max().unwrap();
    let ymin = ym.iter().min().unwrap();

    if cmp::max(x, *xmax) < cmp::min(y, *ymin) { println!("No War"); }
    else { println!("War"); }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;

class Scanner{
  string[] s;
  int i;
 
  char[] cs = new char[] { ' ' };
 
  public Scanner(){
    s = new string[0];
    i = 0;
  }
 
  public string next(){
    if (i < s.Length) return s[i++];
    string st = Console.ReadLine();
    while (st == "") st = Console.ReadLine();
    s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
    if (s.Length == 0) return next();
    i = 0;
    return s[i++];
  }
 
  public int nextInt(){
    return int.Parse(next());
  }
  public int[] ArrayInt(int N, int add = 0){
    int[] Array = new int[N];
    for (int i = 0; i < N; i++){
      Array[i] = nextInt() + add;
    }
    return Array;
  }
 
  public long nextLong(){
    return long.Parse(next());
  }
 
  public long[] ArrayLong(int N, long add = 0){
    long[] Array = new long[N];
    for (int i = 0; i < N; i++){
      Array[i] = nextLong() + add;
    }
    return Array;
  }
 
  public double nextDouble(){
    return double.Parse(next());
  }

  public double[] ArrayDouble(int N, double add = 0){
    double[] Array = new double[N];
    for (int i = 0; i < N; i++){
      Array[i] = nextDouble() + add;
    }
    return Array;
  }
}

public class procon {
  public procon(){}
  
  Scanner cin;
  public static int Main(){
    new procon().calc();
    return 0;
  }
  
  void calc(){
    cin=new Scanner();
    int a=cin.nextInt();
    int b=cin.nextInt();
    int c=cin.nextInt();
    
    int c5=0; int c7=0;
    if(a==5) ++c5;
    else if(a==7) ++c7;
    if(b==5) ++c5;
    else if(b==7) ++c7;
    if(c==5) ++c5;
    else if(c==7) ++c7;
    
    if(c5==2&&c7==1)
      Console.WriteLine("YES");
    else
      Console.WriteLine("NO");
  }
}

Measured memory_bytes: 11092