akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#define ll long long 
#define ld long double
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define sz(v) sizeof(v)
#define MOD 1000000007
#define MAX (ll)1e12+5


using namespace std;


int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
//////
// prime Seive
/*
bitset<1000005> bt;
//unordered_map<ll,bool> is_prime;
vector<ll> primes;
void pS(ll n){
    ll val = min(n+1,(ll)1000006);
    for(ll i=3;i<=val;i+=2){
        bt[i] =true;
    }
    bt[0] =false;
    bt[1] =false;
    bt[2] =false;
    //is_prime[2] =true;
    primes.pb((ll)2);
    for(ll i=3;i<=val;i+=2){
        if(bt[i])
            for(ll j=i*i;j<=val;j+=2*i)
                bt[j] =false;
    }
    for(ll i=3;i<=val;i+=2){
        if(bt[i]){primes.pb(i);
        //is_prime[i]=true;
        //cout<<i<<" :PRIME\n";
        }
    }
    return;
}
*/          
/////
// Fenwick Tree
/*
BIT[200005] ={0};
//BUILD BIT
// for(int i=1;i<1;i++){ cin>>a[i];update(i,a[i],n);};
 
void update(int i,int val,int n){
    while(i<=n){
    BIT[i]+= inc;
    i+= (i&(-i));
    }
}
ll query(int i){
    ll ans =0;
    while(i>0){
        ans+= BIT[i];
        i-=(i&(-i));
    }
    return ans;
}
 
*/
//__builtin_popcount(4)
ll logPow(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1){
            ans*=a;
        }
        a*=a;
        b= b>>1;
    }
    return ans;
}

ll gcd(ll a,ll b){
    return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return (a*b)/gcd(a,b);
}



/*
// dsu
const int N = 500009;
int p[N],cmp[N];
int getP(int cn){
    return ((cn==p[cn])?cn:(p[cn]=getP(p[cn])));
}

void unite(int a,int b){
    a = getP(a);
    b = getP(b);
    if(a==b) return ;
    if(cmp[a]<cmp[b])
        swap(a,b);
    p[b] = a;
    cmp[a] += cmp[b];
}
*/

/*
//dfs
bool dfs(ll src ,ll dest,unordered_map<ll,bool> &vis,unordered_map<ll,vector<ll>> &g){
    vis[src] =true;
    if(src== dest) return true;
    bool  ans =false;
    for(auto nbr: g[src]){
        if(!vis[nbr])
            ans = ans|dfs(nbr,dest,vis,g);
    }
    return ans;
}

*/
// bfs
/*
ll bfs(ll i,unordered_map<ll,bool> &vis){
    queue<ll> q;q.push(i);vis[i] =true;ll ans =0;
    while(!q.empty()){
        ans++;ll cur = q.front();q.pop();
        for(auto nbr: g[cur]){
            if(!vis[nbr]){
                vis[nbr] =true;q.push(nbr);
    }}}
    return ans;
}
*/

unordered_map<ll,vector<ll>> g;

ll modPow(ll a,ll b){
    ll ans =1;
    while(b>0){
        if(b&1){
            ans*=a;
            ans= (ans+MOD)%MOD;
        }
        a*=a;
        a= (a+MOD)%MOD;
        b = b>>1;
    }
    return  ans;
}


int main(){
    ll t=1; 
    //cin>>t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    while(t--){
        int n; cin>>n;
        if(n>=30){
            cout<<"Yes\n";
        }
        else cout<<"No\n";
        
    }
    return 0;
}

Measured memory_bytes: 3648
#!/usr/bin/env python3
# coding: utf-8

def debug(arg):
    if __debug__:
        pass
    else:
        import sys
        print(arg, file=sys.stderr)
        
def main():
    N, K, C = map(int, input().split())
    S = dict(enumerate(str(input()), 1))

    sr = list(k for k, v in S.items() if v == 'o')
    sl = list(reversed(sr.copy()))

    debug(sr)
    debug(sl)

    l = [sl.pop()]
    r = [sr.pop()]
    
    for x in range(1, K):
        while True:
            ll = sl.pop()
            if ll > l[x - 1] + C:
                l.append(ll)
                break
        while True:
            rr = sr.pop()
            if rr < r[x - 1] - C:
                r.append(rr)
                break

    debug(r)
    debug(l)

    # a = sorted(set(l) & set(r))

    # debug(a)
    # for aa in a:
    #     print(aa)
    
    for ll, rr in zip(l, sorted(r)):
        if ll == rr:
            print(ll)

if __name__ == "__main__":
    main()

Measured memory_bytes: 30736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
//cout<<fixed<<setprecision(11);
const string nl="\n";
const ll MOD=1e9+7;
const ll ARR_MAX = 405;
const ll VAL_MAX = 1e5+1;
const ll INF=1e14;

ll dp[ARR_MAX][ARR_MAX]; //dp[i][j] = minimum cost of construting [i...j]

void solve(){
    int n;cin>>n;
    ll a[n];
    ll s=0;
    ll cum[n+1];
    cum[0]=0;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	s+=a[i];
    	cum[i+1]=s;
    }

    for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
    		dp[i][j]=INF;
    	}
    }
    for(int i=0;i<n;i++){
    	// dp[i][i]=a[i];
    	dp[i][i]=0;
    }
    for(int d=1;d<n;d++){
    	for(int i=0;i+d<n;i++){
    		for(int k=i;k<i+d;k++){
    			dp[i][i+d]=min(dp[i][i+d],dp[i][k] + dp[k+1][i+d] + cum[i+d+1]-cum[i]);
    		}
    	}
    }
    cout<<dp[0][n-1]<<nl;
}

int main(){
    fastio();
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(void)
{
	int W;
	int H;
	int x;
	int y;
	int r;
	
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if (x < 0){
		printf("No\n");
	}
	else if(y < 0){
		printf("No\n");
	}
	else if(x == 0){
		printf("No\n");
	}
	else if(y == 0){
		printf("No\n");
	}
	else if(x == W){
		printf("No\n");
	}
	else if(y == H){
		printf("No\n");
	}
	else if(x > W){
		printf("No\n");
	}
	else if(y > H){
		printf("No\n");
	}
	else if(x < r){
		printf("No\n");
	}
	else if(y < r){
		printf("No\n");
	}
	else if(x > r&&y > r){
		printf("Yes\n");
	}
	else if(x == r&&r==y){
		printf("Yes\n");
	}
	else if("y ==r"){
		printf("Yes\n");
	}
	return (0);
}

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


def main():
    s = input()
    n_count = s.count('N')
    s_count = s.count('S')
    e_count = s.count('E')
    w_count = s.count('W')

    if n_count > 0 and s_count == 0:
        print('No')
    elif s_count > 0 and n_count == 0:
        print('No')
    elif e_count > 0 and w_count == 0:
        print('No')
    elif w_count > 0 and e_count == 0:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
using System;
class Rect{
    public static void Main(){
        String str = Console.ReadLine();
        String[] arr = str.Split(' ');
        int a = int.Parse(arr[0]);
        int b = int.Parse(arr[1]);
        Console.WriteLine("{0} {1}",a*b,2*a+2*b);
    }
}


Measured memory_bytes: 15888
#include <bits/stdc++.h>
#include<string>
using namespace std;
typedef long long ll;
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	int mx,mi;
	if(n>m) mx=n,mi=m;
	else mx=m,mi=n;
	int i=1;
	for(;i<=mi;i++){
		if(i*mx>=k) break;
		}
		cout<<i<<'\n';
	}

Measured memory_bytes: 256
program TOKYO_B
  integer(8)::A,B,T,V,W
  read(*,*)A,V
  read(*,*)B,W
  read(*,*)T
  if((V-W>0 .and. abs(A-B)/real(V-W,8)>T) .or. V-W<=0) then
     write(*,'(a)')'NO'
  else
     write(*,'(a)')'YES'
  end if
end program 

Measured memory_bytes: 2920
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define debug(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define debug(...)
#define end_time()
#endif
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
inline int gcd(int a, int b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); }
inline int power(int x, int n, int m = LLONG_MAX)
    {  int res=1; x = (x%m + m)%m;
       while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
    }
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007
void solve(){
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0; i<n; i++) {
		cin>>a[i];
	}
	sort(a,a+n);
	int sum=0;
	for(int i=0; i<k; i++) {
		sum+=a[i];
	}
	cout<<sum;
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;++i) {
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	end_time();
	return 0;
}

Measured memory_bytes: 3652
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)

	d := map[int]bool{}
	for i := 0; i < k; i++ {
		d[a+i] = true
		d[b-i] = true
	}

	arr := []int{}
	for k := range d {
		if a <= k && k <= b {
			arr = append(arr, k)
		}
	}
	sort.Ints(arr)
	for _, v := range arr {
		fmt.Println(v)
	}
}


Measured memory_bytes: 768
from collections import Counter
MOD = 10 ** 9 + 7
N = int(input())
As = list(map(int, input().split()))

counts = [-1, -1, -1]
ans = 1

for a in As:
    ct = Counter(counts)
    ans *= ct[a-1]
    ans %= MOD
    for i in range(3):
        if counts[i] == a-1:
            counts[i] += 1
            break
print(ans)

Measured memory_bytes: 14312
def sq(a, b, mod):  # aのb乗を剰余,kは初期値#20191116-D-Knight
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=10 ** 9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer

N, M = map(int, input().split())
def c(num):
    if num == 1 or num == 0:
        return 0
    else:
        return (num * (num-1))//2
print(c(N)+c(M))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n;
double d, x, ans;
int main()
{
    cin >> n >> d >> x;
    for (int i = n; i >= 1; -- i)
    {
        ans += d + x * (2 * i - 1) / 2;
        d = d * (i + 1) / i + x * 5 / (2 * i);
        x = x * (i + 2) / i;
    }
    cout << setprecision(30) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

constexpr int s_max = 2600;

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

  vector<vector<ll>> dp(n + 1, vector<ll>(s_max, 0));

  dp[0][0] = 1;

  for (int i = 0; i < n; i++) {
    vector<vector<ll>> ndp(n + 1, vector<ll>(s_max, 0));
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < s_max; k++) {
        ndp[j][k] += dp[j][k]; 
        ndp[j + 1][k + x[i]] += dp[j][k];
      }
    }
    swap(ndp, dp); 
  }

  ll res = 0;

  for (int i = 0; i <= n; i++) {
   res += dp[i][i * a];
  }

  cout << res - 1 << endl;

  return 0;
} 

Measured memory_bytes: 2396
#include <stdio.h>

int main(void) {
    char s[11];
    scanf("%s", s);
    int m = s[6];
    if(s[5] == '1') printf("TBD\n");
    else {
        if(m > '4') printf("TBD\n");
        else printf("Heisei\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{
// }}}


signed main()
{
    i64 S, c;
    cin >> S >> c;

    i64 base = min(S, c/2);
    S -= base;
    c -= base*2;

    cout << (base + c / 4) << endl;

    return 0;
}


Measured memory_bytes: 256
from itertools import product

S = input()
N = len(S)
ans = 0
for opes in product(("", "+"), repeat=N - 1):
    eqn = []
    for s, o in zip(S[:-1], opes):
        eqn += s + o
    ans += eval("".join(eqn) + S[-1])
print(ans)



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

int main(){
    int a[33]={0,1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    int k;
    cin>>k;
    cout<<a[k]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  string t;
  cin>>t;
  for(int i=0;i<(int)t.size();i++){
    //int cnt=0;
    if(t[i]=='?'){
      t[i]='D';
    //   int left=i-1;
    //   while(t[i]=='?'){
    //     cnt++;
    //     i++;  
    //   }
    // int right=i;
    //cout<<left<<" "<<right<<endl;
    //  if(t[left]=='P')t[left+1]='D';
    // if(t[left]=='D')t[left+1]='D';     
    //  if(t[right]=='P')t[right-1]='D';
    //   if(t[right]=='D')t[right-1]='P';
    //   left++,right--;
    //   if(left==right)continue;
  }
}
cout<<t<<endl;
}

Measured memory_bytes: 3752
X = int(input())

items = list(range(100, 106))
MAP = [100000000] * 100001
MAP[0] = 0
PRICE_MAX = 100000

for price in items:
    for i in range(len(MAP)):
        if MAP[i] < PRICE_MAX:
            new_price = min([i + price, PRICE_MAX])
            MAP[new_price] = 1
if MAP[X] < PRICE_MAX:
    print(1)
else:
    print(0)

Measured memory_bytes: 3828
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

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

  std::vector<int> a(n);
  for (auto&& ai : a) std::cin >> ai;

  std::vector<int> order(n);
  std::iota(order.begin(), order.end(), 1);
  std::sort(order.begin(), order.end(),
            [&a](auto i, auto j) { return a[i - 1] < a[j - 1]; });
  for (auto i : order) std::cout << i << ' ';
  std::cout << std::endl;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main() {
    int a, b, c;
    int count = 0;
    cin >> a >> b >> c;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <cstring>
#include <queue>

using namespace std;

#define INF 1e+9

class state{
public:
    float cost;
    unsigned char  used;
    unsigned char  node;

    state(float _c, unsigned char _u, unsigned char _n):cost(_c), used(_u), node(_n){}
    state(){}
    bool operator <(const state &arg) const{
         if(cost != arg.cost){
             return cost > arg.cost;
         }
         return node > arg.node;
     }
 };

int n,m,p,a,b;
int t[9];
float d[31][31];
float dd[513][31];
priority_queue<state> q;

void solve(){
    state st;
    bool visited[513][m];
    
    memset(visited, false, sizeof(visited));
    q.push(state(.0,0,a));

    while(!q.empty()){
        st = q.top();
        q.pop();
        if(st.cost > dd[st.used][st.node]) continue;
        if(st.node == b) break;
        for(int i=0;i<m;i++){
            if(d[st.node][i] != INF){
                for(int j=0;j<n;j++){
                    if((st.used & (1 << j)) == 0 &&  
                       st.cost + (double)d[st.node][i] / t[j] < dd[st.used | (1 << j)][i]){
                        dd[st.used | (1 << j)][i] = st.cost + (double)d[st.node][i] / t[j];
                        q.push(state(st.cost + (double)d[st.node][i] / t[j], st.used | (1 << j), i));
                    }
                }
            }
        }
    }
}

int main(){
    while(cin >> n >> m >> p >> a >> b){
        int src,dst,cost;
        q = priority_queue<state>();
        if((n | m | p | a | b) == 0) break;
        fill((float *)d, (float *)d+31*31, INF);
        fill((float *)dd, (float *)dd+513*31, INF);
        
        a--;
        b--;
        for(int i=0;i<n;i++){
            cin >> t[i];
        }
        for(int i=0;i<p;i++){
            cin >> src >> dst >> cost;
            d[src-1][dst-1] = cost;
            d[dst-1][src-1] = cost;
        }
        solve();
        
        float ret = INF;
        for(int i=0;i<513;i++){
            ret = min(ret, dd[i][b]);
        }
        if(ret == INF){
            cout << "Impossible" << endl;
        }else{
            cout << ret << endl;
        }
    }
}

Measured memory_bytes: 0
import collections
alp = collections.defaultdict(int)
S = input()
for i in S:
    alp[i] += 1
v = alp.values()
if len(alp) <= 2 and len(S) >= 3:
    print('NO')
else:
    if len(S) == 1:
        print('YES')
    elif len(S) == 2:
        if len(alp) == 2:
            print('YES')
        else:
            print('NO')
    elif max(v) - min(v) <= 1:
        print('YES')
    else:
        print('NO')

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

int main()
{
  vector<pair<int, pair<int,int>>> list;
  for(int i = 1; i <= 150; ++i) {
    for(int j = i + 1; j <= 150; ++j) {
      int v = i * i + j * j;
      list.push_back(pair<int, pair<int,int>>(v, pair<int,int>(i, j)));
    }
  }
  sort(list.begin(), list.end());
  int h, w;
  while(cin >> h >> w, (h|w)) {
    int v = h * h + w * w;
    pair<int, pair<int,int>> p(v, pair<int,int>(h, w));

    for( auto v : list ) {
      if( p < v ) {
        cout << v.second.first << " " << v.second.second << endl;
        break;
      }
    }
  }
  return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  vector<PII> xs;
  int K = 0;
  REP(i,N){
	string S;
	cin >> S;
	PII p(0,0);
	REP(i,SZ(S)){
	  p.FF += (S[i] == '('? 1: -1);
	  maxi(p.SS, -p.FF);
	}
	K += p.FF;
	xs.emplace_back(p);
  }
  if(K != 0){
	cout << "No" << endl;
	return 0;
  }
  
  SORT(xs);
  int mid = 0;
  for(;mid<N;++mid) if(xs[mid].FF >= 0) break;

  K = 0;
  vector<bool> used(N);
  bool up = true;
  while(up){
	up = false;
	FOR(i,mid,N){
	  if(used[i]) continue;
	  if(K >= xs[i].SS){
		K += xs[i].FF;
		used[i] = true;
		up = true;
	  }
	}
  }
  FOR(i,mid,N)
	if(!used[i]){
	  cout << "No" << endl;
	  return 0;
	}

  up = true;
  K = 0;
  while(up){
	up = false;
	REP(i,mid){
	  if(used[i]) continue;
	  if(-xs[i].FF + K >= xs[i].SS){
		K += -xs[i].FF;
		used[i] = true;
		up = true;
	  }
	}
  }
  REP(i,N)
	if(!used[i]){
	  cout << "No" << endl;
	  return 0;
	}
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
main(){
  int N,x;
  cin >> N >> x;
  int a[N];
  for(int i=0;i<N;i++) cin >> a[i];
  sort(a,a+N);
  int people=0;
  int stock=x;
  int stop=0;
  for(int i=0;i<N;i++){
    if(a[i]<=stock){
      people++;
      stock-=a[i];
    } else {
      stop=i;
      break;
    }
  }
  if(stock>0&&people>0&&stop==0) people--;
  cout << people <<endl;
}

Measured memory_bytes: 3508
s = input()
zenhan = int(s[0:2])
kouhan = int(s[2:])

if zenhan > 12 or zenhan==0:
    if kouhan > 12 or kouhan==0:
        print("NA")
    else:
        print("YYMM")
else:
    if kouhan > 12 or kouhan==0:
        print("MMYY")
    else:
        print("AMBIGUOUS")

Measured memory_bytes: 3060
import heapq

n = int(input())
a = list(map(int, input().split()))

plus = [0] * (3 * n)
tmp = a[:n]
s = sum(tmp)
heapq.heapify(tmp)
for i in range(n, 2*n):
    plus[i-1] = s
    heapq.heappush(tmp, a[i])
    s += a[i]
    s -= tmp[0]
    heapq.heappop(tmp)
plus[2*n-1] = s

a = [-x for x in a][::-1]
minus = [0] * (3 * n)
tmp = a[:n]
s = sum(tmp)
heapq.heapify(tmp)
for i in range(n, 2*n):
    minus[i-1] = s
    heapq.heappush(tmp, a[i])
    s += a[i]
    s -= tmp[0]
    heapq.heappop(tmp)
minus[2*n-1] = s
minus = minus[::-1]
ans = plus[n-1] + minus[n]
for i in range(n-1, 2*n):
    ans = max(ans, plus[i] + minus[i+1])

print(ans)

Measured memory_bytes: 37212
n = int(input())
a = [0] + list(map(int, input().split())) + [0]

max_ = 0
for i in range(n+1):
    max_ += abs(a[i] - a[i+1])

for i in range(n):
    res = max_ + abs(a[i+2] - a[i]) - ((abs(a[i+1] - a[i]) + abs(a[i+2] - a[i+1])))
    print(res)

Measured memory_bytes: 14048
#define _USE_MATH_DEFINES

#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;
// template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long int
#define ull unsigned long long int
 
#define lp(i,n) 	    for(int i=0;i<(int)(n);i++)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);i++)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);i--)
 
#define all(v)  	 ((v).begin()), ((v).end())
#define sz(v)    	 ((int)((v).size()))
#define clr(v, d)    memset(v, d, sizeof(v))
#define PB           push_back
#define MP           make_pair
#define N 100005
 
#define PI 3.14159265359
 
 
ll nChooseR(int n,int k);
ll gcd(ll a, ll b);
vector<string> split(string target,unsigned char c );


ll n,k,t,m,x,y,a[N*2];

bool isPrime(ll h);
string s;

 

ll ans;

ll mod=1e9 +7;




int main() {
// freopen("pyramid.in","r",stdin); 
  //freopen("output.txt","w",stdout); 
cout.precision(10);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>k;
lp(i,n)cin>>a[i];
sort(a,a+n);
lp(i,n-k)ans+=a[i];

cout<<ans;
}
 
	
ll nChooseR( int n, int k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;
   	ll result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}
 
ll gcd(ll a, ll b){
	return b==0?a:gcd(b,a%b);
	}
 
 
vector<string> split(string target,unsigned char c ){
	string d="";
	vector<string>arr;
	for(auto n:target)
	{
		if(n!=c)
		d+=n;
		else if(d!="")
		arr.push_back(d),d="";
	}
	if (d!="")
	arr.push_back(d),d="";
	return arr;
}
// bool isPrime(ll h){
//      for(ll i=0;primes[i]*primes[i]<= h;i++)
//      if (h%primes[i]==0)
//      	return 0;
//      return h!=1;
//  }
 bool isPrime(ll g){
   if((g%2==0 && g>2) || g==1)return 0;
   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;
   return 1;   
 
 }

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int main(){
	int a,p,ans;
	cin >> a >> p;
	//vector<int>l(m+1);
	//vector<int>r(m+1);
	//bool flag=true;
	ans = (a*3+p)/2;
	cout << ans << endl;
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
vector<string> grid;
vector<vector<int>> d;
queue<P> now_hold;
queue<P> next_look;
int h,w;
void put_adj(int nowx,int nowy, int cost){
	int dy[4] = {0,1,0,-1};
	int dx[4] = {1,0,-1,0};

	for(int i = 0;i < 4;i++){
		int nx = nowx + dx[i];
		int ny = nowy + dy[i];
		if(0 <= nx && nx < w && 0 <= ny && ny < h && grid[ny][nx] != '#' && d[ny][nx] == INF){
			next_look.push(P(nx,ny));
			d[ny][nx] = cost;
			put_adj(nx, ny, cost);
		}
	}
}

int main(){
	cin >> h >> w;
	grid.resize(h);
	d.resize(h,vector<int>(w,INF));
	int sy,sx;
	cin >> sy >> sx;
	int gy,gx;
	cin >> gy >> gx;

	sy--,sx--,gy--,gx--;
	for(int i = 0;i < h;i++)cin >> grid[i];

	//連結しているところをひとまとめにする.

	d[sy][sx] = 0;

	next_look.push(P(sx,sy));
	put_adj(sx, sy, 0);

	while(next_look.size()){
		P p = next_look.front();
		next_look.pop();
		now_hold.push(p);
	}

	while(true){
		while(now_hold.size()){
			P now = now_hold.front();
			now_hold.pop();
			//入れるときに連結しているものをすべてくっつける.
			for(int dx = -2;dx <= 2;dx++){
				for(int dy = -2;dy <= 2;dy++){
					int nx = now.first + dx;
					int ny = now.second + dy;
					if(0 <= nx && nx < w && 0 <= ny && ny < h && grid[ny][nx] != '#' && d[ny][nx] == INF){
						d[ny][nx] = d[now.second][now.first] + 1;
						next_look.push(P(nx,ny));
						put_adj(nx,ny,d[ny][nx]);
					}
				}
			}
		}

		if(next_look.size() == 0)break;

		while(next_look.size()){
			P p = next_look.front();
			next_look.pop();
			now_hold.push(p);
		}
	}

	if(d[gy][gx] == INF)cout << -1 << endl;
	else cout << d[gy][gx] << endl;
}


Measured memory_bytes: 9592
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int N;

int main(){
  cin >> N;
  int H[N];
  rep(i,N){
    cin >> H[i];
  }
  for(int i = N-1; i >0; i--){
    if(H[i]-H[i-1] <= -2){ cout << "No" << endl; return 0;}
    if(H[i]-H[i-1] == -1) H[i-1]--;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void){
	int i,N,now=0,ans=0,a,b=-1;//up=2 down=1
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&a);
		if(now==1&&b<a&&b!=-1){now=0;ans++;b=-1;}
		else if(now==2&&b>a&&b!=-1){now=0;ans++;b=-1;}
		else if(b<a&&b!=-1){now=2;} 
		else if(b>a&&b!=-1){now=1;}
		b=a;
	}
	printf("%d\n",ans+1);
	return 0;
}



Measured memory_bytes: 128
import Control.Applicative
import Control.Monad
import Data.Functor
import Data.List

readInts = map read . words <$> getLine :: IO [Int]

solve xs
  | all ((==0) . (`mod`10)) xs = sum $ map ((*10) . (`div`10) . (+9)) xs
  | otherwise = (sum $ map ((*10) . (`div`10) . (+9)) xs) - 10 + (minimum $ filter (/=0) $ map (`mod`10) xs)

main = replicateM 5 readLn >>= print . solve


Measured memory_bytes: 508
<?php

while ($line = fgets(STDIN)) {
   $tmp[] = trim($line);
}

// 配列の各要素をさらに分解します
foreach ($tmp as $key => $value) {
  $array[] = explode(" ", $value);
}
//命名

$k = $array[0][0];
$x = $array[0][1];

$sum = 500 * $k;

if ($sum >= $x) {
    echo 'Yes';
} else {
    echo 'No';
}


 ?>


Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> inline int Log2(T& x) {int k; for(k=0; (T(1)<<k)<=x; ++k); return k;}


int main() {
  ll N; cin >> N;
  multiset<int> a;
  rep(i, N) {
    int x; cin >> x;
    a.insert(x);
  }

  int ans = 0;
  while (!a.empty()) {
    auto it = a.end();
    it--;
    int x = *it;
    int k = Log2(x);
    int y = (1<<k) - *it;
    a.erase(it);

    it = a.find(y);
    if (it != a.end()) {
      a.erase(it);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9600
h,w = map(int, input().split())
L = [input() for i in range(h)]
dp = [[10**9]*w for i in range(h)]
if L[0][0] == ".":
    dp[0][0] = 0
else:
    dp[0][0] = 1

li = ((1,0),(0,1))
for i in range(h):
    for j in range(w):
        for dy,dx in li:
            ny,nx = i+dy,j+dx
            if ny >= h or nx >= w:
                continue
            plus = 0
            if L[i][j] == "." and L[ny][nx] == "#":
                plus =1
            dp[ny][nx] = min(dp[i][j]+plus,dp[ny][nx])
            
print(dp[h-1][w-1])


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int main() {
	for (int i = 1; i <= 9; i++)
		for (int j = 1; j <= 9; j++)
			cout << i << 'x' << j << '=' << i * j << endl;
}

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

using namespace std;

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

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

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 998244353;

const int MAX = 1e6;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


template<typename T>
T modpower(T a, T n, T mod) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    COMinit();
    int n, m, k;
    cin >> n >> m >> k;
    ll res = 0;
    rep (i, k + 1) {
        ll tmp = 1;
        tmp = m * modpower((ll)m - 1, (ll)n - 1 - i, MOD);
        tmp %= MOD;
        tmp *= COM(n - 1, i);
        tmp %= MOD;
        res += tmp;
        res %= MOD;
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 27112
s = int(input())
a = [s]

while True:
    if a[-1] % 2 == 0:
        num = a[-1] / 2
    else:
        num = a[-1] * 3 + 1

    if num in a:
        print(len(a) + 1)
        break
    else:
        a.append(num)

Measured memory_bytes: 3060
A,B,C,X = map(int,open(0))
ans=0
for i in range(0,A+1):
  for j in range(0,B+1):
    tmp = (X - 500*i - 100*j)/50
    if tmp.is_integer() and tmp >=0 and tmp <=C:
      ans +=1
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
#include <math.h>

int main() {
  int n, ans;
  scanf("%d", &n);
  ans = (int)sqrt((double)n);
  printf("%d\n", ans*ans);
  return 0;
}


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

using namespace std;

int getnum(string s)
{
    int answer = 0;

    int mn = 1;

    for(int i = 1; i < s.size(); ++i)
        mn *= 10;

    for(int i = 0; i < s.size(); ++i)
    {
        answer += (s[i] - '0') * mn;
        mn /= 10;
    }

    return answer;
}

bool issquare(int x)
{
    int k = sqrt(x);

    return ((k * k) == x);
}

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

    string a, b, c = "";
    cin >> a >> b;

    c = a + b;

    int val = getnum(c);

    if(issquare(val))
        cout << "Yes\n";
    else
        cout << "No\n";
}


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

#define ran 101101

int n, st, ed;
vector<int> e[ran];
int p[ran], dist;
int ma;

void dfs2(int cur, int par, int dep) {
	if(cur==ed) return;
	ma = max(ma, dep);
	
	for(int i=0;i<(int)e[cur].size();i++) {
		int nxt = e[cur][i];
		if(nxt==par) continue;
		
		dfs2(nxt, cur, dep+1);
	}
}

void dfs(int cur, int par, int dep) {
	p[dep] = cur;
	if(cur==ed) {
		dist = dep;
		return;
	}
	
	for(int i=0;i<(int)e[cur].size();i++) {
		int nxt = e[cur][i];
		if(nxt==par) continue;
		
		dfs(nxt, cur, dep+1);
		if(dist>=0) return;
	}
}

int main() {
	scanf("%d%d%d", &n, &st, &ed);
	for(int i=1;i<n;i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	
	dist = -1;
	dfs(st, -1, 0);
	ed = p[(dist-1)/2+1];
	
	ma = 0;
	dfs2(p[(dist-1)/2], -1, 0);
	printf("%d\n", ma + dist/2);
	
	return 0;
}

Measured memory_bytes: 11776
import java.util.Scanner;


public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int x = scan.nextInt();
		int t = scan.nextInt();
		int temp = 0;
		if(n % x != 0 ) {
			temp = 1;
		}

		System.out.print(((n / x) + temp) * t);
	}
}

Measured memory_bytes: 35828
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int n;
    cin>>n;
    cout<<(double)(2.0*n*3.1415);
    
}

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

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


int main() {
    long double l; cin >> l;
    cout << fixed << setprecision(6) << pow(l/3,3);
}




Measured memory_bytes: 3832
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <fstream>
#include <stack>
#define LL long long
using namespace std;
LL n,c,d[35][35],lis[3][35],ans[3][35];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>c;
    for(LL i=1;i<=c;i++)
        for(LL j=1;j<=c;j++)
            cin>>d[i][j];
    for(LL i=1;i<=n;i++)
        for(LL j=1;j<=n;j++){
            LL x;
            cin>>x;
            lis[(i+j)%3][x]++;
        }
    for(LL i=0;i<3;i++){
        for(LL j=1;j<=c;j++)
            for(LL k=1;k<=c;k++)
                ans[i][j]+=lis[i][k]*d[k][j];
    }
    LL res=0x7fffffff;
    for(int i=1;i<=c;i++)
        for(int j=1;j<=c;j++)
            for(int k=1;k<=c;k++){
                if(i==j||j==k||i==k) continue;
                res=min(res,ans[0][i]+ans[1][j]+ans[2][k]);
            }
    cout<<res<<endl;
    return 0;
}


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

bool f(const string& s) {
  for (int i = 0; 2 * i < s.size(); i++) {
    if (s[i] != s[s.size() - 1 - i]) return false;
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool r = true;
  r = r && f(s);
  r = r && f(s.substr(0, (n - 1) / 2));
  r = r && f(s.substr((n + 3) / 2 - 1, n - ((n + 3) / 2) + 1));
  cout << (r ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

const int H = 1<<18;
int cou[H];

ll val[3][3][2 * H];
ll le[3][2 * H];
ll ri[3][2 * H];
ll opt[2 * H];

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

	int n;
	cin >> n;

	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> cou[i];
		sum += cou[i];
	}

	// Cover with NONE-EVEN-ODD-EVEN-NONE

	for (int i = 0; i < n; ++i) {
		if (cou[i] == 0) {
			val[0][0][i + H] = -2;
			val[1][1][i + H] = -1;
			val[2][2][i + H] = -2;

			val[0][1][i + H] = -1;
			val[0][2][i + H] = -1;
			val[1][0][i + H] = -1;
			val[1][2][i + H] = -1;
			val[2][0][i + H] = -1;
			val[2][1][i + H] = -1;
		} else {
			int rem = cou[i] & 1;
			val[0][0][i + H] = cou[i] - rem;
			val[1][1][i + H] = cou[i] - (rem ^ 1);
			val[2][2][i + H] = cou[i] - rem;
			val[0][1][i + H] = cou[i];
			val[0][2][i + H] = cou[i];
			val[1][0][i + H] = cou[i];
			val[1][2][i + H] = cou[i];
			val[2][0][i + H] = cou[i];
			val[2][1][i + H] = cou[i];
			
			le[0][i + H] = max(0ll, val[0][0][i + H]);
			ri[0][i + H] = max(0ll, val[0][0][i + H]);

			le[1][i + H] = cou[i];
			ri[1][i + H] = cou[i];

			le[2][i + H] = cou[i];
			ri[2][i + H] = cou[i];

			opt[i + H] = cou[i];
		}
	}
	for (int i = H-1; i > 0; --i) {
		val[0][0][i] = val[0][0][2*i] + val[0][0][2*i+1];
		val[1][1][i] = val[1][1][2*i] + val[1][1][2*i+1];
		val[2][2][i] = val[2][2][2*i] + val[2][2][2*i+1];
		
		val[0][1][i] = max(val[0][0][2*i] + val[0][1][2*i+1], val[0][1][2*i] + val[1][1][2*i+1]);
		val[1][0][i] = max(val[1][0][2*i] + val[0][0][2*i+1], val[1][1][2*i] + val[1][0][2*i+1]);
		val[1][2][i] = max(val[1][2][2*i] + val[2][2][2*i+1], val[1][1][2*i] + val[1][2][2*i+1]);
		val[2][1][i] = max(val[2][1][2*i] + val[1][1][2*i+1], val[2][2][2*i] + val[2][1][2*i+1]);
		
		val[0][2][i] = max(max(val[0][0][2*i] + val[0][2][2*i+1], val[0][1][2*i] + val[1][2][2*i+1]), val[0][2][2*i] + val[2][2][2*i+1]);
		val[2][0][i] = max(max(val[2][0][2*i] + val[0][0][2*i+1], val[2][1][2*i] + val[1][0][2*i+1]), val[2][2][2*i] + val[2][0][2*i+1]);

		le[0][i] = max(le[0][2*i], val[0][0][2*i] + le[0][2*i+1]);
		ri[0][i] = max(ri[0][2*i+1], val[0][0][2*i+1] + ri[0][2*i]);

		le[1][i] = max(le[1][2*i], max(val[1][1][2*i] + le[1][2*i+1], val[1][0][2*i] + le[0][2*i+1]));
		ri[1][i] = max(ri[1][2*i+1], max(val[1][1][2*i+1] + ri[1][2*i], val[0][1][2*i+1] + ri[0][2*i]));
		
		le[2][i] = max(le[2][2*i], max(val[2][2][2*i] + le[2][2*i+1], max(val[2][1][2*i] + le[1][2*i+1], val[2][0][2*i] + le[0][2*i+1])));
		ri[2][i] = max(ri[2][2*i+1], max(val[2][2][2*i+1] + ri[2][2*i], max(val[1][2][2*i+1] + ri[1][2*i], val[0][2][2*i+1] + ri[0][2*i])));

		opt[i] = max(opt[2*i], opt[2*i+1]);
		opt[i] = max(opt[i], ri[0][2*i] + le[2][2*i+1]);
		opt[i] = max(opt[i], ri[1][2*i] + le[1][2*i+1]);
		opt[i] = max(opt[i], ri[2][2*i] + le[0][2*i+1]);
	}
	cout << sum - opt[1] << '\n';
}


Measured memory_bytes: 66688
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int mod = 1e9 + 7;

int main(void)
{
    string s;
    ll k;
    cin >> s >> k;
    bool one = true;
    for (int i = 0; i < k;i++){
        if(s[i]!='1'){
            cout << s[i] << endl;
            one = false;
            break;
        }
    }
    if(one)
        cout << 1 << endl;
    return 0;
}

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

#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()
#define ceiv(a, b) (1 + (int)((a) - 1)/(int)(b))
//#define int long long

signed main(){
    string s;
    cin >> s;
    sort(ALL(s));
    cout << (s=="abc" ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
def dfs(A):
    if len(A)==N:
        temp=0
        for j in range(Q):
            if A[a[j][1]-1]-A[a[j][0]-1]==a[j][2]:
                temp+=a[j][3]
        ans.append(temp)
        return
    else:
        if len(A)>0:
            m=A[-1]
        else:
            m=1
        for i in range(m,M+1):
            A.append(i)
            dfs(A)
            A.pop()
        
N,M,Q=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(Q)]
ans=[]
dfs([])
print(max(ans))

Measured memory_bytes: 12600
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[110][11];
ll dd[110][12];

int main() {
  ll n;
  cin>>n;
  rep(i,0,n){
    rep(j,0,10){
      ll a;
      cin>>a;
      d[i][j] = a;
    }
  }
  rep(i,0,n){
    rep(j,0,11){
      ll a;
      cin>>a;
      dd[i][j] = a;
    }
  }
  ll mx = -1000000000000000000LL;
  rep(i,1,(1<<10)){
    ll c[110];
    clr(c,0);
    rep(j,0,n){
      ll c1 = 0;
      rep(k,0,10){
        if(((i>>k)&1)==1){
          if(d[j][k]==1){
            c1++;
          }
        }
      }
      c[j] = c1;
    }
    ll b = 0;
    rep(j,0,n){
      b += dd[j][c[j]];
    }
    mx = max(mx,b);
  }
  cout << mx << endl;
  return 0;
}

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

string s, wx;
int carry[100001], zero[100001];

bool ispal(string x){
    for(int i = 0 ; i < x.size() ; i++)
        if(x[i] != x[x.size()-i-1]) return 0;
    return 1;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> s;
    for(int i = 0 ; i < s.size() ; i++)
        if(s[i] != 'x') wx += s[i];
    if(!ispal(wx)) return cout << -1 << endl, 0;
    for(int i = 0 ; i < s.size() ; i++)
        if(s[i] == 'x') zero[i] = 1;
    int ans = 0;
    for(int cur = 0 ; cur < s.size() ; cur++){
        if(s[cur] != 'x')
            while(s.size() && s.back() == 'x'){
                ans++;
                s.pop_back();
            }
        if(cur >= s.size()) break;
        if(s[cur] == s.back()){
            s.pop_back();
            continue;
        }
        if(s[cur] == 'x')
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 976
/*     !ya khoda!     */
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define ld long double

#define pp push
#define po pop()
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
#define I insert
#define E erase

#define F first
#define S second

#define mkp make_pair
#define pll pair<ll,ll>
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define all(a) a.begin(),a.end()

#define coutghat(x)      cout<<tolower(x);
#define coutashar(x,d)   cout<<fixed<<setprecision(x)<<(ld)d
#define IOS ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)
//#define poow(a,b,M)   b?(poow((a*a)%M,b/2)%M * (b&1?a))%M:1 ;
/*==========================================================================*/
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll poow(ll x,ll n,ll Mod=1e9+7) { return (n==0?1:poow(x*x%Mod,n/2)*(n&1?x:1)%Mod); }
//#pragma optimize O3
// 107,109, 211,223, 307, 401,409, 503,509, 601,607, 701,709, 809, 907, 1009
/*==========================================================================*/
const int N=1e2+100 , M=1e6+10  , SQ=550 , LG=21 , base=2;
const int mod=1e9+7 , MOD=1e9+9;
const ll  INF=1e9   , inf=1e18 , super_inf=~0ull/4;
ll n,a[N];
/*==========================================================================*/
pll solve(ll l , ll r)
{   ll res=0,t=1,w=1,d=0,e=INF,z=l;
    if(l>r)   return mkp(1,1);
    for(int i=l;i<=r;i++)   e=min(e,a[i]);

    for(int i=l;i<=r;i++)
    {   a[i]-=e;
        if(a[i]==0)
        {   pll f=solve(z,i-1);
            t*=f.S  ,  t%=mod;
            w*=f.F  ,  w%=mod;
            d++     ,  z=i+1;
        }
    }

    pll f=solve(z , r);

    t*=f.S  ,  t%=mod;
    w*=f.F  ,  w%=mod;
    res+=(poow(2,d)*w)%mod   ,   res%=mod;
    res+=(poow(2,e)*t)%mod   ,   res%=mod;
    res+=(t*((poow(2,e)-2+mod)%mod))%mod;
    res%=mod;

    return mkp(res,(poow(2,e)*t)%mod);
}
/*==========================================================================*/
int main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)   cin>>a[i];

    pll res=solve(1,n);

    cout<<(res.F-res.S+mod)%mod;
    return 0;
}


Measured memory_bytes: 256