akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template<class T> struct rge { T b, e; };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
    ~debug(){cerr<<endl;}
    template<class T> debug& operator<<(T x){cerr<<boolalpha<<x; return *this;}
    template<class B, class C> debug& operator<<(pair<B, C> x){return *this<<"("<<x.first<<", "<<x.second<<")";}
    template<class T> debug& operator<<(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}return *this<<"]";}
    template<class T> debug& operator<<(vector<T> x){ return *this<<range(x.begin(),x.end());}
#else
    template<class T> debug& operator <<(const T&){return *this;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}

const int mod = 1e9+7;

int add(int a, int b) {
    a += b;
    while(a >= mod) a -= mod;
    while(a < 0) a += mod;
    return a;
}
void add_self(int& a, int b) {
    a = add(a, b);
}
int mul(int a, int b) {
    return 1LL * a * b % mod;
}
int mpow(int a, int n) {
    if(n == 0) {
        return 1;
    }
    int x = mpow(a, n/2);
    x = mul(x, x);
    if(n % 2 == 1) {
        x = mul(x, a);
    }
    return x;
}

struct V {
    ll x, y;
    
    V& normalize() {
        if(x < 0) {
            x *= -1, y *= -1;
        }
        if(x == 0 && y) y = 1;
        if(y == 0 && x) x = 1;
        else if(x && y) {
            ll g = gcd(llabs(x), llabs(y));
            x /= g, y /= g;
        }
        return *this;
    }
    
    V perp() const {
        V p{-y, x};
        return p.normalize();
    }
    
    bool operator < (const V& rhs) const {
        return tie(x, y) < tie(rhs.x, rhs.y);
    }
};

ostream& operator <<(ostream& out, V v) {
    return out << "(" << v.x << ", " << v.y << ")";
}

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

    int n;
    cin >> n;
    map<V, int> freq;
    int cnt_zero = 0;
    for(int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        V v{x, y};
        if(x == 0 && y == 0) {
            cnt_zero++;
            continue;
        }
        v.normalize();
        ++freq[v];
    }
    
    int ans = 1;
    for(auto pp : freq) {
        V v = pp.first;
        int cnt1 = pp.second;
        V u = v.perp();
        if(freq.count(u) && !(v < u)) {
            continue;
        }
        int cnt2 = freq.count(u) ? freq[u] : 0;
        debug() nav(v) nav(u) nav(cnt1) nav(cnt2);
        ans = mul(ans, add(mpow(2, cnt1), add(mpow(2, cnt2), -1)));
    }
    debug() nav(cnt_zero);
    add_self(ans, -1);
    add_self(ans, cnt_zero);
    cout << ans << endl;
}













// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie


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


int main()
{
	int index = 0;
	int index_end = 0;
	char s[200001];

	scanf("%s",s);
    index_end = strlen(s) - 1;
	while(s[index] != '\0')
	{
		if(s[index] == 'A')break;
		else ++index;
	}
    
    while(index_end != 0)
    {
        if(s[index_end]=='Z') break;
		else --index_end;
    }
    printf("%d\n",index_end - index + 1);
	return 0;
}

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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r){
    if (l >= r) return;
    int root = pre[pos++];
    int m = distance(in.begin(), find(in.begin(), in.end(), root));
    rec(l, m);//left subtree
    rec(m+1, r);//right subtree

    post.push_back(root);
}

void solve(){
    pos = 0;
    rec(0, pre.size());
    for(int i=0; i<n; i++){
        if (i) cout << " ";
        cout << post[i];
    }
    cout << endl;
}

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

    for (int i=0; i<n; i++){
        cin >> k;
        pre.push_back(k);
    }

    for (int i=0; i<n; i++){
        cin >> k;
        in.push_back(k);
    }

    solve();

    return 0;

}

Measured memory_bytes: 1220
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    a=0
    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                if i+j+k==x and i!=j and j!=k and k!=i and i<j and j<k:
                    a+=1
    print(a)


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

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    sort(s.begin(), s.end());
    int d = 0;
    for (int i = 0; i < n-1; i++) {
        if (s[i] == s[i+1]) d++;
    }

    cout << n-d << endl;
}

Measured memory_bytes: 9600
while True:
    try:
        a = input()
        array = []
        b = str(format(a,'b'))

        for i in range(len(b)):
            if b[i] == '1':
                array.append(2**(len(b)-i-1))

        array.sort()
        for i in range(len(array)):
            array[i] = str(array[i])

        print ' '.join(array)
    except EOFError:
        break

Measured memory_bytes: 4244
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int h,w,m;
  while(1){
    cin >> h >> w;
    if(h==0 && w==0) break;
    int str[w];
    int stri[w];

    for(int i=0;i<w;i++){
      str[i]=0;
      stri[i]=i+1;
    }
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> m;
	if(m==1){
	  str[j]++;
	}
      }
    }
    
    for(int i=0;i<w-1;i++){
      for(int j=0;j<w-1-i;j++){
	if(str[j]<str[j+1]){
	  int temp;
	  temp=str[j];
	  str[j]=str[j+1];
	  str[j+1]=temp;

	  temp=stri[j];
	  stri[j]=stri[j+1];
	  stri[j+1]=temp;
	}
      }
    }

    for(int i=0;i<w;i++){
      cout << stri[i];
      if(i!=w-1){
	cout << " ";
      }
    }
    cout << endl;
  }
  return(0);
}

Measured memory_bytes: 1160
# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion
class union_find:
    def __init__(self, n):
        self.n = n
        self.rank = [0]*n
        self.parent = [int(j) for j in range(n)]
    
    def union(self,i,j):
        i = self.find(i)
        j = self.find(j)
        if self.rank[i] == self.rank[j]:
            self.parent[i] = j
            self.rank[j] += 1

        elif self.rank[i] > self.rank[j]:
            self.parent[j] = i
        else:
            self.parent[i] = j

    def find(self, i):
        temp = i
        if self.parent[temp] != temp:
            self.parent[temp] = self.find(self.parent[temp])
        return self.parent[temp]
def main():
# Enter your code here. Read input from STDIN. Print output to STDOUT
    # l = [int(j) for j in list(input())]
    # if
    s = input()
    if(1<=int(s[:2])<=12 and 1<=int(s[2:])<=12):
        print("AMBIGUOUS")
    elif(1<=int(s[2:])<=12):
        print("YYMM")
    elif(1<=int(s[:2])<=12):
        print("MMYY")
    else:
        print("NA")

    # s[k-1] = s[k-1].lower()
    # print("".join(s))
        





        
                # ls[i+1]=
            # base = f
        # print()


        
        




        # l = [int(j) for j in input().split()]




if __name__ == "__main__":
    main()

Measured memory_bytes: 62980
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	long gcd(long a, long b){return a == 0 ? b : gcd(b % a, a);}
	public void Solve(){
		Console.WriteLine(A / gcd(A,B) * B);
	}
	long A,B;
	public Sol(){
		var d = rla();
		A = d[0]; B = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repush_back(i,a,b) for(ll i=a;i>=b;i--)
#define f(n) for(ll i=0;i<n;i++)
#define r(n) for(ll j=0;j<n;j++)
#define F first
#define S second
#define pi 3.14159265359
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
ll HRX=1e18;
ll INF=1e9+7;

int main()
{
 hs;
 ll n,x;
 cin>>n>>x;
 ll a[n];
 ll sum=1,cnt=0;
 f(n)
 {
  cin>>a[i];
  cnt=cnt+a[i];
  if(cnt<=x)
    sum++;
 }
 cout<<sum<<endl;
 return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += 2 * min(a, k - a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main(){
    int a,b,c,n,tmp;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&a,&b,&c);
        if(b<c){tmp=b;b=c;c=tmp;}
        if(a<b){tmp=a;a=b;b=tmp;}

        if(a*a==(b*b+c*c))printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;

constexpr int INF = 1 << 25;
constexpr int MOD = 1000000007;

int main() {
  int n, q;
  cin >> n;
  vector<int> S(n);
  REP(i, n) cin >> S[i];
  cin >> q;
  vector<int> T(q);
  REP(i, n) cin >> T[i];
  
  auto cnt =
      accumulate(ALL(T), 0, [&S](int acc, int i) { return acc + binary_search(ALL(S), i); });

  cout << cnt << endl;
}



Measured memory_bytes: 3328
for e in iter(input,'0 0'):
 w,h=map(int,e.split())
 M=[[[1,0]*2 for _ in[0]*h]for _ in[0]*w]
 for i in range(1,w):
  for j in range(1,h):
   a,b=M[i-1][j][:2]
   c,d=M[i][j-1][2:]
   M[i][j]=[d,a+b,b,c+d]
 print((sum(M[w-2][h-1][:2])+sum(M[w-1][h-2][2:]))%10**5)


Measured memory_bytes: 7836
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n;
	cin>>n;
	ll ans=0;
	rep(i,n){
		if((i+1)%3!=0&&(i+1)%5!=0){
			ans+=i+1;
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
////////////////////////////////////////
ll n,m;

ll calc(ll x,ll y){
    return (m+y-x)%m;
}


int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    cin>>n>>m;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll sum=0;
    rep(i,0,n-2){
        sum+=calc(a[i],a[i+1]);
    }
    vector<ll>v[m+1];
    rep(i,0,n-2){
        ll x=a[i],y=a[i+1];
        v[y].pb(calc(x,y)-1);
    }
   /* rep(i,1,m){
        cout<<i<<":";
        if(v[i].size()>=1){
            for(auto x:v[i])cout<<x<<" ";
        }cout<<endl;
    }*/
    ll imos[2*m+1];memset(imos,0,sizeof(imos));
    rep(i,0,n-2){
        ll x=a[i],y=a[i+1];
        if(calc(x,y)>=2){
            imos[x+1]++;
            if(y>=x){
                imos[y]--;
            }else{
                imos[m+y]--;
            }
        }
    }
    
    rep(i,1,2*m)imos[i]=imos[i-1]+imos[i];
    rep(i,1,m){
        imos[i]+=imos[i+m];
    }
    /*  rep(i,1,m){
        cout<<imos[i]<<" ";
    }cout<<endl;
    */
    ll ans=0;
    rep(i,0,n-2){
        if(a[i]<=a[i+1]){
            ans+=calc(a[i],a[i+1]);
        }else{
            ans+=a[i+1];
        }
    }
    ll minans=ans;
   // cout<<1<<" "<<ans<<endl;
    rep(i,2,m){
        if(v[i-1].size()>=1){
            for(auto x:v[i-1]){
                ans+=x;
            }
        }
        ans-=imos[i-1];
       // cout<<i<<" "<<ans<<endl;
        minans=min(minans,ans);
    }
    cout<<minans<<endl;
    
    
    return 0;
}

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

int n,k;
int li[105];

int memo[100005][3];
bool vis[100005][3];

int dp(int st, int tu){
//   cout << st << " " << tu << endl;
   int &ret = memo[st][tu];
   if(vis[st][tu]) return ret;
   vis[st][tu] = 1;
   ret = -1;
   for(int i=1;i<=n;i++){
      if(st < li[i]) break;
      ret = max(ret , dp(st-li[i],tu^1) * -1);
   }
   return ret;
}

int main(){
   scanf("%d%d",&n,&k);
   for(int i=1;i<=n;i++) scanf("%d",&li[i]);
   int ans = dp(k,0);
   if(ans == 1) printf("First\n");
   else printf("Second\n");
	return 0;
}


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

size_t f(vector<pair<size_t, size_t>> &x, size_t n)
{
    size_t ret = 0;
    priority_queue<size_t, vector<size_t>, greater<size_t>> candidates;
    priority_queue<pair<size_t, size_t>, vector<pair<size_t, size_t>>, greater<pair<size_t, size_t>>> q;
    for (pair<size_t, size_t> p : x)
    {
        q.push(p);
    }
    size_t current = 0;
    while (!q.empty())
    {
        size_t index = q.top().first;
        if (index >= n)
        {
            q.pop();
            continue;
        }
        if (index > current)
        {
            current++;
            while (current < candidates.size())
            {
                candidates.pop();
            }
        }
        else
        {
            size_t diff = q.top().second;
            q.pop();
            candidates.push(diff);
        }
    }
    current++;
    while (current < candidates.size())
    {
        candidates.pop();
    }
    while (!candidates.empty())
    {
        ret += candidates.top();
        candidates.pop();
    }
    return ret;
}

void solve()
{
    size_t N;
    cin >> N;
    vector<size_t> K(N);
    vector<size_t> R(N);
    vector<size_t> L(N);
    vector<pair<size_t, size_t>> rr;
    vector<pair<size_t, size_t>> ll;
    size_t ans = 0;
    for (size_t n = 0; n < N; n++)
    {
        cin >> K[n] >> R[n] >> L[n];
        if (R[n] >= L[n])
        {
            rr.push_back(make_pair(K[n] - 1, R[n] - L[n]));
        }
        else
        {
            ll.push_back(make_pair((N - 1) - K[n], L[n] - R[n]));
        }
        ans += min(R[n], L[n]);
    }

    ans += f(rr, N);
    ans += f(ll, N);
    cout << ans << endl;
}

int main()
{
    size_t T;
    cin >> T;
    for (size_t t = 0; t < T; t++)
    {
        solve();
    }
}


Measured memory_bytes: 14744
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()

if A > 9 or B > 9:
	print(-1)
else:
	print(A*B)

Measured memory_bytes: 61804
from itertools import chain, product

s = input()
assert all(c in '123456789' for c in s)

betweens = product(('', '+'), repeat=len(s)-1)
strings = (s[0] + ''.join(chain.from_iterable(zip(between, s[1:]))) for between in betweens)
print(sum(map(eval, strings)))

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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
	ll a,b; cin >> a>> b;
	cout << (a * b) / __gcd(a,b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int main() {
  int c[4][4];
  int a[4], b[4];
  for (int i = 1; i < 4; i++)
    for (int k = 1; k < 4; k++)
      cin >> c[i][k];
  
  a[1] = 0;
  for (int i = 1; i < 4; i++) b[i] = c[1][i];
  for (int i = 2; i < 4; i++) a[i] = c[i][1] - b[1];

  for (int i = 1; i < 4; i++) {
    for (int k = 1; k < 4; k++) {
      if (c[i][k] != a[i] + b[k]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    #nCrをmodで割った余りを求める。Nに最大値を入れて使用。
    mod = 10**9+7
    N = 5*10**5
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    for i in range(2,N+1):
        g1.append((g1[-1]*i)%mod)
        inverse.append((-inverse[mod % i]*(mod//i))%mod)
        g2.append((g2[-1]*inverse[-1])%mod)
    n,m = map(int,ipt().split())
    ans = g1[m]*g2[(m-n)]%mod
    dp = [0,m-n,((m-n)*2+1+(m-n)*(m-n-1))%mod]
    for i in range(3,n+1):
        dp.append(((i-1)*dp[-2]%mod+(m-n+i-1)*dp[-1]%mod)%mod)
    print(dp[n]*ans%mod)


    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 164980
#include<bits/stdc++.h>
using namespace std;
long int a;
int main()
{
    cin>>a;
    if(a<2) cout<<1<<endl;
    else if(a<4)  cout<<2<<endl;
    else if(a<8)  cout<<4<<endl;
    else if(a<16) cout<<8<<endl;
    else if(a<32) cout<<16<<endl;
    else if(a<64) cout<<32<<endl;
    else cout<<64<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
	int N, M,a[60],b[60],c[60],d[60],e[60],f[60];
	e[0] = 1000000000;
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= M; i++) {
		cin >> c[i] >> d[i];
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			e[j] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (e[j] < e[j - 1]) {
				f [i]= j;
			}
			else {
				e[j] = e[j - 1];
			}
		}
		cout << f[i] << endl;
	}
    return 0;
}

Measured memory_bytes: 256
n=int(input())
sl=[input() for _ in range(n)]
ans=0
a,b,c=0,0,0
for s in sl:
    ans+=s.count('AB')
    if s[0]=='B' and s[-1]=='A':
        c+=1
    elif s[0]=='B':
        b+=1
    elif s[-1]=='A':
        a+=1
if c==0:
    ans+=min(a,b)
elif a+b>0:
    ans+=c+min(a,b)
else:
    ans+=c-1
print(ans)

Measured memory_bytes: 3700
fun main(args: Array<String>){
    val input = readLine()!!.split(' ')
                            .map { it.toInt() }
                            .toTypedArray()
    val result = D0923A(input).judge()
    println(result)
}

class D0923A(
  val numbers: Array<Int>
){
    fun judge(): Int{
        val max = numbers.max()!!
        return numbers.sum() + (max * 10) - max
    }
}

Measured memory_bytes: 36400
#include <bits/stdc++.h>
template<typename T>
using matrix = std::vector<std::vector<T>>;
const int mod = 1e9 + 9;
template<typename T>
matrix<T> modmul(const matrix<T> &A, const matrix<T> &B) {
  matrix<T> res((int)(A.size()), std::vector<T>((int)(B[0].size())));
  for(int i=0;i<(int)(A.size());++i) {
    for(int j=0;j<(int)(B.size());++j) {
      for(int k=0;k<(int)(B[0].size());++k) {
        res[i][k] += A[i][j] * B[j][k] % mod;
        res[i][k] %= mod;
      }
    }
  }
  return res;
}
template<typename T>
std::vector<T> modmul(const matrix<T> &A, const std::vector<T> &v) {
  std::vector<T> res((int)(A.size()));
  for(int i=0;i<(int)(A.size());++i) {
    for(int j=0;j<(int)(v.size());++j) {
      res[i] += A[i][j] * v[j] % mod;
      res[i] %= mod;
    }
  }
  return res;
}
template<typename T>
matrix<T> E(const int n) {
  matrix<T> res(n, std::vector<T>(n));
  for(int i=0;i<n;++i) {
    res[i][i] = 1;
  }
  return res;
}
template<typename T>
matrix<T> modpow(matrix<T> A, long long k) {
  auto res = E<T>((int)(A.size()));
  while(k) {
    if(k&1) res = modmul(res, A);
    A = modmul(A, A);
    k >>= 1;
  }
  return res;
}
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000009;
const ll INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(ll i=0;i<(ll)(s.size());++i) {
    cout << s[i];
    if(i == (ll)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
bool solve(ll cnt) {
  ll w, h, n; cin >> w >> h >> n;
  if(w == 0) return false;
  map<ll, vector<ll>> mp;
  for(ll i=0;i<n;++i) {
    ll x, y; cin >> x >> y;
    x--; y--;
    mp[y].push_back(x);
  }
  matrix<ll> A(w, vll(w));
  for(ll i=0;i<w;++i) {
    for(ll j=0;j<w;++j) {
      if(abs(i-j) <= 1) A[i][j] = 1;
    }
  }
  vector<ll> v(w);
  v[0] = 1;
  ll prevh = 0;
  for(auto &e: mp) {
    if(e.first == 0) continue;
    matrix<ll> tmp = A;
    tmp = modpow(tmp, e.first - prevh);
    v = modmul(tmp, v);
    for(auto &e2: e.second) {
      v[e2] = 0;
    }
    prevh = e.first;
  }
  if(prevh != h-1) {
    A = modpow(A, h-1 - prevh);
    v = modmul(A, v);
  }
  cout << "Case " << cnt << ": " << v[w-1] << endl;
  return true;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll cnt = 0;
  while(1) {
    cnt++;
    if(!solve(cnt)) break;
  }
}



Measured memory_bytes: 3244
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int a, b, h;
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int aYen = sc.nextInt();// ピザAの値段
        int bYen = sc.nextInt();// ピザBの値段
        int cYen = sc.nextInt();// ピザC(ABピザ)の値段
        int targetACnt = sc.nextInt();
        int targetBCnt = sc.nextInt();

        int cost = Integer.MAX_VALUE;
        int maxCCnt = targetACnt>targetBCnt ? targetACnt*2 : targetBCnt*2;
        for (int i = 0; i <= maxCCnt;i++) {
            int tmpCCnt = i;
            int tmpACnt = Math.max(targetACnt - (tmpCCnt/2), 0);
            int tmpBCnt = Math.max(targetBCnt - (tmpCCnt/2), 0);

            int tmpCost = (aYen*tmpACnt) + (bYen*tmpBCnt) + (cYen*tmpCCnt);
            if (cost > tmpCost) cost = tmpCost;
        }

        System.out.println(cost);
    }
}


Measured memory_bytes: 23892
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <sstream>
#define maxn 200005
#define pb push_back
#define mp make_pair
#define lop(i,k,n) for(int i=(k);i<n;i++)
#define rep(i,k,n) for(int i=(k);i<=n;i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){if (b == 0) return a; return gcd(b , a&b);}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}
map<ll,ll> s;
int a[maxn];
int main(){
    ll n,sum = 0,count = 0;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        sum += a[i];
        s[sum]++;
      // cout << sum << endl;
    }
   // cout << 1 << endl;
    map<ll,ll> ::iterator it;
    for (it = s.begin(); it != s.end(); it++) {
        ll x = it->second;
       // cout << x << endl;
        if (x > 1) {
            //cout <<x*(x-1)/2<<endl;
            count += x*(x-1)/2;
        }
        if (it->first == 0){
            //cout <<x*(x-1)/2<<endl;
            count += it->second;
        }
    }
    cout << count << endl;
    return 0;
}





Measured memory_bytes: 13568
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

void print_ans(int x) {
  printf("%d\n", x);
  exit(0);
}

int min_d(vector<bool> & ex) {
  vector<int> a;
  rep (i, (int)ex.size()) {
    if (ex[i]) {
      a.push_back(i);
    }
  }
  int ret = a.front() + 24 - a.back();
  rep (i, (int)a.size() - 1) {
    ret = min(ret, a[i+1] - a[i]);
  }
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  vi d(n, 0);
  rep (i, n) {
    scanf("%d", &d[i]);
  }

  vi acc(13, 0);
  rep (i, n) {
    acc[d[i]] += 1;
  }

  if (acc[0] >= 1) {
    print_ans(0);
  }
  FOR (i, 1, 12) {
    if (acc[i] >= 3) {
      print_ans(0);
    }
  }
  if (acc[12] >= 2) {
    print_ans(0);
  }

  vector<bool> exist;
  int ans = 0;
  rep (i, (1 << n)) {
    exist.assign(24, false);
    exist[0] = true;

    bool continue_flag = false;
    rep (j, n) {
      int target;
      if (((i >> j) & 1) == 0) {
        target = d[j];
      } else {
        target = 24 - d[j];
      }
      if (exist[target]) {
        continue_flag = true;
        break;
      }
      exist[target] = true;
    }

    if (continue_flag) {
      continue;
    }

    ans = max(ans, min_d(exist));
  }

  print_ans(ans);

  return 0;
}


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

int check(char c[3]){
    int r = 0;
    int g = 0;
    int b = 0;
    for (int i = 0; i < 3; i++)
    {
        if(c[i]=='R'){
            r++;
        }else if(c[i]=='G'){
            g++;
        }else{
            b++;
        }
    }
    return r * g * b;

}

int main(){
    int N;
    string S;
    long long count = 0;
    long long count_not = 0;
    int r = 0, g = 0, b = 0;
    cin >> N;
    cin >> S;



    for (int i = 0; i < N; i++){
        switch(S[i]){
            case 'R':
                r++;
                break;
            case 'G':
                g++;
                break;
            case 'B':
                b++;
                break;
        }
    }

    for (int i = 0; i < N; i++){
        for (int k = 0; k < N; k++){
            if((i<k) && ((i + k)%2)==0){
                int j = (i + k) / 2;
                char c[] = {S[i], S[j], S[k]};
                if(check(c)!=0){
                    count_not++;
                }
            }
        }
    }

    count = r;
    count *= g;
    count *= b;
    count -= count_not;

    cout << count << endl;
}

Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

template <int base>
int digit_sum(int n)
{
	int sum = 0;
	while (n > 0) {
		sum += n % base;
		n /= base;
	}
	return sum;
}

using ivec = vector<int>;

ivec read_int_args()
{
	int N;
	cin >> N;
	ivec v(N);
	for (auto& e : v) {
		cin >> e;
	}
	return v;
}

int compar(const void * b, const void* a)
{
	return (*(int*)a - *(int*)b );
}

int main()
{
	int N, K, Q;
	cin >> N >> K >> Q;

	ivec P(N);
	for (auto& e : P) {
		e = 0;
	}
	
	for (int i = 0; i < Q; i++) {
		int A;
		cin >> A;
		P[A-1]++;
	}

	int th = Q - K;

	for (int i = 0; i < N; i++) {
		if (P[i] > th) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 1024
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v


def shellSort(A, n):
    global cnt
    global m
    global G
    for i in range(m):
        insertionSort(A, n, G[i])


n = int(input())
A = [int(input()) for i in range(n)]

cnt = 0
G = [1]
while G[-1] < n/9:
    G.append(G[-1]*3 + 1)
G.reverse()
m = len(G)

shellSort(A, n)
print(m)
print(" ".join(map(str, G)))
print(cnt)
for i in A:
    print(i)

Measured memory_bytes: 47584
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    string S;
    cin >> N >> K >> S;
    S[K - 1] = tolower(S[K-1]);
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim X As Integer = NextInt()
        Dim ans As Integer = 1

        For b As Integer = 2 To X
            For p As Integer = 2 To X
                If b ^ p > X Then Exit For
                ans = CInt(Math.Max(ans, b ^ p))
            Next
        Next

        WriteLine(ans)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
#include<bits/stdc++.h> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define int long long
#define swap(x,y) (x^=y^=x^=y)

#define debug1(a) cerr<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

using namespace std;
 
#define mod 1000000007
long long modexpo(long long x, long long p){
    int res = 1;x = x%mod;
    while(p){
        if(p%2)res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

struct compare{
    bool operator() (const pair<int,int> a, const pair<int,int> b) const{
        return a.first < b.first;
    }
};

//seen editorial, digit DP

const int nax = 1e5 + 5;

// state
// dp[ith digit of number][rem mod 13]

int dp[nax][13];
string s;

int32_t main(){
    IOS
    int n;
    cin >> s;
    n = s.length();
    
    //base case we say that 0 mod 13 = 1 therefore initial state
    dp[0][0] = 1;

    for(int i = 0; i < n; i++){
        int c = -1;
        if(s[i] != '?'){
            c = (int)(s[i] - '0');
        }
        for(int j = 0; j < 10; j++){
            // s[i] is fixed value we take that else iterate over all possible values
            if(c != -1 && c != j){
                continue;
            }
            // rem can be between 0-12 inclusive
            for(int rem = 0; rem < 13; rem++){
                // transition : IMP
                // if i use j at this i, then whatever num i have till now will be multiplied by 10
                // then add j to it, take mod 13, this newly formed number will only be affected by
                // rem which we already have for particular i,
                // thus rem*10 + j mod 13 forms next rem for current rem.

                dp[i+1][(rem*10 + j)%13] += dp[i][rem];
                
            }
        }
        for(int j = 0; j < 13; j++){
            dp[i+1][j] %= mod;
        }
    }
    int res = dp[n][5];
    res %= mod;
    cout << res << "\n";
}

Measured memory_bytes: 13916
#include <stdio.h>
#include <string.h>
int main(void)
{
 int i;
 char S[7][3];
 S[0][0] = 'M';S[0][1] = 'O';S[0][2] = 'N';
 S[1][0] = 'T';S[1][1] = 'U';S[1][2] = 'E';
 S[2][0] = 'W';S[2][1] = 'E';S[2][2] = 'D';
 S[3][0] = 'T';S[3][1] = 'H';S[3][2] = 'U';
 S[4][0] = 'F';S[4][1] = 'R';S[4][2] = 'I';
 S[5][0] = 'S';S[5][1] = 'A';S[5][2] = 'T';
 S[6][0] = 'S';S[6][1] = 'U';S[6][2] = 'N';

/*
 for(i=0;i<7;i++)
  printf("%c%c%c\n",S[i][0],S[i][1],S[i][2]);
*/

 char Sa[3];
 scanf("%s",Sa);
 if (strcmp(Sa,"SUN")==0) 
  {
  printf("7\n");
  return 0;
  }
 for(i=0;i<7;i++)
  if((S[i][0]==Sa[0])&&(S[i][1]==Sa[1])&&(S[i][2]==Sa[2])) printf("%d\n",(7-i-1)%7);

 return 0;
}



Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

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

    cout << A * B - A - B + 1 << endl;

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define TIME 3


int kurai(int n){
    int a=n;
int dig;
int sum=0;

while(a){
dig=a%10;
sum=sum+dig;
a=a/10;

}

return sum;
}



int main(void){
int a,b;
int n;
scanf("%d",&n);

a=n-1;
b=1;

int min=99999999;
int sum;
for(;;){
sum=kurai(a)+kurai(b);
if(min>=sum){min=sum;}
a--;
b++;
if(a==0||b==n){printf("%d\n",min);break;}
}


}

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

bool primecheck(int);

int main(){

    int x;
    cin>>x;

    while(!primecheck(x)) x++;

    cout<<x<<endl;



    return 0;
}

bool primecheck(int x){
    if(x<=1) return false;
    for(int i=2;i*i<=x;i++){
        if(x%i==0) return false;
    }
    return true;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <utility>

using namespace std;
typedef pair<int, int> P;

int main()
{
	int W, H;
	while (cin >> W >> H, W || H) {
		vector< vector< vector<int> > > kabe(4, vector< vector<int> >(W, vector<int>(H, 1) ) );
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W - 1; j++) {
				cin >> kabe[1][j][i];
				kabe[3][j + 1][i] = kabe[1][j][i];
			}
			if (i < H - 1) {
				for (int j = 0; j < W; j++) {
					cin >> kabe[2][j][i];
					kabe[0][j][i + 1] = kabe[2][j][i];
				}
			}
		}
		vector< vector<int> > maze(W, vector<int>(H, -1));
		queue<P> que;
		maze[0][0] = 1;
		que.push(P(0, 0));
		while (!que.empty()) {
			P temp;
			temp = que.front();
			int f = temp.first, s = temp.second;
			que.pop();
			if (!kabe[0][f][s] && maze[f][s - 1] == -1) {
				maze[f][s - 1] = maze[f][s] + 1;
				que.push(P(f, s - 1));
			}
			if (!kabe[1][f][s] && maze[f + 1][s] == -1) {
				maze[f + 1][s] = maze[f][s] + 1;
				que.push(P(f + 1, s));
			}
			if (!kabe[2][f][s] && maze[f][s + 1] == -1) {
				maze[f][s + 1] = maze[f][s] + 1;
				que.push(P(f, s + 1));
			}
			if (!kabe[3][f][s] && maze[f - 1][s] == -1) {
				maze[f - 1][s] = maze[f][s] + 1;
				que.push(P(f - 1, s));
			}
		}
		if (maze[W - 1][H - 1] == -1)
			cout << 0 << endl;
		else
			cout << maze[W - 1][H - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1260
N = gets.to_i
a = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

ans = 0
(0...N).each do |i|
  b = B[i]
  if a[i] <= b
    ans += a[i]
    b -= a[i]
  else
    ans += b
    next
  end

  if a[i+1] <= b
    ans += a[i+1]
    a[i+1] = 0
  else
    ans += b
    a[i+1] -= b
  end
end
p ans

Measured memory_bytes: 24652
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

#define POS(i, l, r) ((((i) % 3) * (n + 1) + (l)) * (n + 1) + (r))

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  i32 *v = ALLOC (n, i32);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, v + i);
  }
  i32 *dp = ALLOC (3 * (n + 1) * (n + 1), i32);
  for (i32 i = 1; i <= k; ++i) {
    for (i32 l = 0; l < n; ++l) {
      for (i32 r = l; r < n; ++r) {
        i32 max = dp[POS(i - 1, l, r)];
        max = MAX (max, dp[POS(i - 1, l + 1, r)] + v[l]);
        max = MAX (max, dp[POS(i - 1, l, r - 1)] + v[r]);
        if (i >= 2) {
          max = MAX (max, dp[POS(i - 2, l + 1, r)]);
          max = MAX (max, dp[POS(i - 2, l, r - 1)]);
        }
        dp[POS(i, l, r)] = max;
      }
    }
  }
  printf ("%" PRIi32 "\n", dp[POS(k, 0, n - 1)]);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long int a,b,c;
int main(){
	cin>>a>>b>>c;
	if(a%2==0 || b%2==0 || c%2==0){
		cout<<0;
	}
	else{
		long long int ar[3]={a,b,c};
		sort(ar,ar+3);
		cout<<ar[0]*ar[1];
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1e9+7;

ll calc(int a,int b){
    if(b==0)return 1;
    else if(b%2==0){
        ll d=calc(a,b/2);
        return (d*d)%M;
    }else{
        return a*calc(a,b-1)%M;
    }
}

int main(void){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++)cin>>A[i];
    sort(A.begin(),A.end());
    
    bool check=false;
    if(N%2==0){
        int k=1;
        for(int i=0;i<N;i+=2){
            if(A[i]!=k||A[i+1]!=k){check=true;break;}
            k+=2;
        }
    }else{
        if(A[0]!=0)check=true;
        int k=2;
        for(int i=1;i<N;i+=2){
            if(A[i]!=k||A[i+1]!=k){check=true;break;}
            k+=2;
        }
    }
    
    if(check) cout<<0<<endl;
    else{
        ll ans;
        if(N%2==0){
            ans=calc(2,N/2);
        }else{
            ans=calc(2,(N-1)/2);
        }
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define ll long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 210000;
int dp[N], b[N][30], f[30];
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    int n = s.length();
    for (int j = 0; j < 26; j++){
        f[j] = n;
        b[n][j] = n;
    }
    dp[n] = 1;
    for (int i = n - 1; i >= 0; i--){
        f[s[i] - 'a'] = i;
        for (int j = 0; j < 26; j++)
            b[i][j] = f[j];
    }
    for (int i = n - 1; i >= 0; i--){
        int k = 0;
        for (int j = 0; j < 26; j++){
            k = max(k, b[i][j]);
        }
        dp[i] = 1 + dp[k + 1];
    }
    int l = 0;
    string ans;
    while(l < n){
        int t = dp[l];
        for (int j = 0; j < 26; j++){
            int p = b[l][j];
            if (dp[p + 1] + 1 == t){
                ans += ('a' + j);
                l = p + 1;
                break;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 26004
n=int(input())
hlist=[int(i) for i in input().split()]
dp = [0]*n
dp[1] = abs(hlist[1]-hlist[0])
for i in range(2,n):
	dp[i] = min(dp[i-2]+abs(hlist[i]-hlist[i-2]),dp[i-1]+abs(hlist[i]-hlist[i-1]))
print(dp[n-1])

Measured memory_bytes: 13928
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

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

void Main()
{
	int h, w;
  	cin >> h >> w;
  	vector<string> s(h);
  	rep(i,h) cin >> s[i];

  	vvi ans(h, vi(w,0));

  	rep(i,h){
    	rep(j,w){
        	if(s[i][j]=='#'){
            	rep(k,3) {
                  	rep(l,3) {
                  		if(0<=i+dx[k] && i+dx[k]<h && 0<=j+dy[l] && j+dy[l]<w){
							ans[i+dx[k]][j+dy[l]]++;
                    	}
                    }
                }
            }
        }
    }
	
  	rep(i,h){
    	rep(j,w){
        	if(s[i][j]=='#') cout << '#';
          	else cout << ans[i][j];
        }
      	cout << endl;
    }
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int n;
int xs[100005];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &xs[i]);
	//sort(xs + 1, xs + n + 1);

	LL ans = 1;
	int now = 1;
	int cnt = 0;
	LL MOD = 1000000007;
	for (int i = 1; i <= n; i++) {
		cnt++;
		if (now <= xs[i]) {
			xs[i] = now;
			now += 2;
		}
		else if (now > xs[i]) {
			ans = (ans * cnt) % MOD;
			cnt--;
		}
	}
	for (int i = 1; i <= cnt; i++) ans = (ans * i) % MOD;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
const long long OO = 1e18+25;
#define par pair<pair<int,int>, int>
#define f first
#define s second
    
int x,n,a[105],l[105],c;

int main()
{
    scanf("%d%d",&n,&x);
    for(int i=0 ; i<=n ;i++)
    {
        scanf("%d",l+i);
    }for(int i=1; i<=n; i++)
    {
        a[i] = a[i-1]+l[i-1];
        if(a[i] <= x) c++;
    }printf("%d",c+1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[200010], b[200010];
int main() {
	ll n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	ll ans=0;
	for(int i=n;i>=1;i--){
		ll sum=0;
		for(int j=2;j*i<=n;j++){
			ll now=j*i;
			sum+=b[now];
		}
		if(sum%2==a[i]){
			b[i]=0;
		}
		else{
			b[i]=1;
			ans++;
		}
	}
	cout <<ans<<endl;
	for(int i=1;i<=n;i++){
		if(b[i]==1){
			cout << i << " ";
		}
	}
	// your code goes here
	return 0;
}

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

using namespace std;
#define ll long long
#define inf (int)1e5
ll n, W, w[100], v[100];
ll dp[100][inf];

ll knapsack(ll i, ll W){
	//base case
	if(i==n || w==0){return 0;}

	//recursive case
	if(dp[i][W]!=-1){return dp[i][W];}

	if(w[i] <= W){
		dp[i][W]= max(v[i]+knapsack(i+1,W-w[i]), knapsack(i+1, W));
	}
	else{
		dp[i][W]=knapsack(i+1, W);
	}
	return dp[i][W];
}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	memset(dp, -1, sizeof dp);
	cin>>n>>W;
	for(int i=0; i<n; i++){
		cin>>w[i]>>v[i];
	}
	cout<<knapsack(0, W);
}

Measured memory_bytes: 78336
#include<stdio.h>
#define ll long long
ll int func(ll a,ll b,ll c){
     if(a/b==0){return a+c;} 
return func(a/b,10,c+a%b)+func(a,b*10,c);
}
int main(){
  ll int a;
  scanf("%lld",&a);
printf("%lld",func(a,10,0));
  return 0;
}

Measured memory_bytes: 1728