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

int main(){
    int n;
    cin >> n;
    string s[n];
    for(int i=0; i<n; i++) cin >> s[i];
    vector<pair<int,int>> t;
    int right = 0;
    int left = 0;
    for(int i=0; i<n; i++){
        int l=0,r=0;
        for(int j=0; j<s[i].size(); j++){
            if(s[i][j]=='(') l++;
            else if(l>0) l--;
            else r++;
        }
        if(r!=0 && l!=0) t.push_back(make_pair(l,r));
        else if(l==0) right += r;
        else{
            left +=l;
        }
    }
    sort(t.begin(),t.end(),[](pair<int,int> a, pair<int,int> b){
            return (a.first-a.second > b.first-b.second);});
    for(int i=0; i<t.size(); i++){
        left -= t[i].second;
        if(left < 0){
            cout << "No" << endl;
            return 0;
        }
        left += t[i].first;
    }
    if(left == right) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 34712
#include<iostream>
using namespace std;
int main(){
    int h, w;
    while(1){
        cin >> h >> w;
        if(h == 0) break;
        
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(i == 0 || i == h-1){
                    cout << '#';
                }else{
                    if(j == 0 || j == w-1){
                        cout << '#';
                    }else{
                        cout << '.';
                    }
                }
            }
            cout << endl;
            
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3004
#include<stdio.h>
#define N 25

int i;
 
typedef struct{
  int parent;
  int left;
  int right;
}tree;
 
int pre(int), in(int), post(int);
tree T[N];

int main(){
  int n;
  int id, left, right;
 
  scanf("%d\n",&n);
  for(i = 0; i < n; i++){
    T[i].parent = -1;
    T[i].left = -1;
    T[i].right = -1;
  }
 
  for(i = 0 ; i < n ; i++){
    scanf("%d %d %d", &id, &left, &right);
    T[id].left = left;
    T[left].parent = id;
    T[id].right = right;
    T[right].parent = id;
  }
 
  printf("Preorder\n");
  for(i = 0 ; i < n ; i++){
    if(T[i].parent == -1) pre(i);
  }
  printf("\n");
 
  printf("Inorder\n");
  for(i = 0 ; i < n ; i++){
    if(T[i].parent == -1) in(i);
  }
  printf("\n");
 
  printf("Postorder\n");
  for(i = 0 ; i < n ; i++){
    if(T[i].parent == -1) post(i);
  }
  printf("\n");
     
  return 0;
}

int pre(int j){
  if(j == -1) return;
  printf(" %d", j);
  pre(T[j].left);
  pre(T[j].right);
}
 
int in(int j){
  if(j == -1) return;
  in(T[j].left);
  printf(" %d", j);
  in(T[j].right);
}
 
int post(int j){
  if(j == -1) return;
  post(T[j].left);
  post(T[j].right);
  printf(" %d", j);
}

Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    long long a,b;
    cin>>a>>b;
    int mx = max(a,b);
    int mn = min(a,b);
    for(int i=0;i<mx;i++)
        cout<<mn;
}

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

using namespace std;

#define int long long
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back

int mod=1e9+7;

int32_t main() {
    faster;

    int n;
    cin>>n;

    int h[n];
    for(int i=0;i<n;i++) cin>>h[i];

    int dp[n];

    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }

    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int,input().split()))
sums = [a[n-1]]
for i in range(n-2,0,-1):
    sums.append(sums[len(sums)-1]+a[i])
sums = sums[::-1]
mod = 10**9+7
ans = 0
for i in range(n-1):
    ans += a[i]*sums[i]
    ans %= mod
print(ans)

Measured memory_bytes: 31684
while True:
    n, k = map(int, input().split())
    if n == 0 and k == 0:
        break
    s = [0]
    for i in range(n):
        t = int(input())
        s.append(s[-1] + t)
    m = 0
    for i in range(n-k+1):
        m = max(s[i+k] - s[i], m)
    print(m)


Measured memory_bytes: 9656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = INF;

int main()
{
ll n , x ;
cin >> n >> x ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
vector<vector<ll>> v(n, vector<ll>(n,0) );
rep(i,n){
  set<ll> s;
  rep(j,n){
    s.insert(a[(i-j+n)%n]);
    v[i][j]=*s.begin();
  }
}
rep(i,n){
  ll sum=0;
  rep(j,n){
    sum+=v[j][i];
  }
  ans=min(ans,sum+i*x);
}
cout << ans << endl;

return 0;
}

Measured memory_bytes: 31616
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

string shrink(string s, char tar){
    string res;
    ll n = s.length();
    REP(i, n-1){
        if(s[i]==tar || s[i+1]==tar)
            res.push_back(tar);
        else
            res.push_back(s[i]);
    }
    return res;
}

bool check(string s){
    char tar = s[0];
    REP(i, s.length()-1){
        if(s[i+1]!= tar){
            return false;
        }
    }
    return true;
}

void solve(std::string s){
    ll ans = 101;
    for (auto tar: s){
        ll cnt = 0;
        string tmp = s;
        while(!check(tmp)){
            cnt++;
            tmp = shrink(tmp, tar);
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

int main(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

N = int(input())

X = []
L = []

for i in range(N):
    a,b = map(int,input().split())
    X.append(a-b)
    L.append(a+b)

xl = sorted([(X[i],L[i]) for i in range(N)], key = itemgetter(1))

ans = 0
last = -float("inf")

for i in range(N):
    if last <= xl[i][0]:
        ans += 1
        last = xl[i][1]

print(ans)


Measured memory_bytes: 20572
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int m, n, x, t=0;
	cin >> m >> n;
	for (int i=1; i<=n; i++)
	{
		cin >> x;
		t+=x;
	}
	if (t>m) cout << -1 << endl;
	else cout << m-t << endl;
	return 0;
}

Measured memory_bytes: 3624
n, k = map(int, input().split())

ans = 0
buttom = 0
for i in range(k):
    buttom += n - i

top = 0
for i in range(k):
    top += i

_max = 0
for i in range(n+1):
    _max += n - i

_MOD = 10**9+7

for i in range(k, n+1+1):
    ans += buttom - top + 1
    buttom = min(_max, buttom+n-i)
    top += i
    ans = ans % _MOD

print(ans)

Measured memory_bytes: 9148
import sys
from bisect import bisect_right

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B, C, D, E, F = map(int, readline().split())

    sugar = set()
    for i in range(F // C + 1):
        for j in range(F // D + 1):
            s = C * i + D * j
            if s <= F:
                sugar.add(s)
            else:
                break

    sugar = sorted(sugar)

    water = set()
    for i in range(F // (100 * A) + 1):
        for j in range(F // (100 * B) + 1):
            w = 100 * A * i + 100 * B * j
            if w <= F:
                water.add(w)
            else:
                break

    water = sorted(water)

    concentration = 0
    ans_water = ans_sugar = 0
    for w in water[1:]:
        s_max = min(F - w, w // 100 * E)
        s = sugar[bisect_right(sugar, s_max) - 1]
        if concentration < 100 * s / (w + s):
            concentration = 100 * s / (w + s)
            ans_water = w
            ans_sugar = s

    if ans_water == 0:
        ans_water = 100 * A

    print(ans_water + ans_sugar, ans_sugar)
    return


if __name__ == '__main__':
    main()


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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;



int main() {
    int N; cin >> N;
    ll sum =0;
    rep(i,N){
        ll a; cin >> a;
        sum ^= a;
    }

    cout << (sum == 0 ? "Yes" : "No") << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,ans=0;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++)
		for(int j=2;j<=9;j++)
			for(int k=2;k<=9;k++)
				if(i==j*k&&10*j+k<=b)++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = list(input())
c = {}
for i in range(a):
    if b[i] not in c:
        c[b[i]] = 1
    else:
        c[b[i]] += 1
ans = 1
for v in c.values():
    ans *= (v + 1)
print((ans - 1) % (10 ** 9 + 7))


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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }
//
const int N =2e5+5 ; 
ll Counter [N] ; 
vector<int>adj[N]; 
int n , q ; 
void dfs(int u , int p , int val ){
	Counter[u] += val ; 

	for(int v : adj[u] ){
		if( p != v )
			dfs(v,u,Counter[u]); 
	}
}
int main(){
	cin >> n >> q; 
	for(int i = 1 ; i < n ; i++ ){
		int u , v ; 
		cin >> u >> v ; 
		adj[u].pb(v) ; 
		adj[v].pb(u) ; 
	}
	for(int i = 0 ; i < q ; i++ ){
		int val , subtreeof ; 
		cin >> subtreeof >> val; 
		Counter[subtreeof] += val ; 
	}
	dfs(1,-1,0); 
	for(int i =1; i<= n ; i++ )cout << Counter[i] << " " ; 
}


Measured memory_bytes: 24320
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<=ll(b);++i)
#define ALL(f,x,...) ([&](decltype((x)) xxxx) { return (f)(begin(xxxx), end(xxxx), ## __VA_ARGS__); })(x)
#define lim 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define MSG(msg1,msg2,flag) cout<<((flag)? msg1:msg2);

#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}
vector<char> 
string_to_vector_char(const string& input){vector<char> out(input.length());rep(i,input.length()){out[i]=input[i];}return out;}
template <class T> map<T,int> 
count_same_elements(const vector<T>& v){map<T,int>cmap; for_each(v.begin(),v.end(),[&cmap](auto x){cmap[x]++;}); return cmap; }
template<class A,class B> vector<B> 
mapf(const vector<A>& v,const function<B(A)>& func){vector<B> v_(v.size());rep(i,v.size()){ v_[i]=func(v[i]); }return v_;}
template<class A,class B> vector<B> 
adjacent_map(const vector<A>& v,const function<B(A,A)>& func){vector<B> v_(v.size()-1);rep(i,v.size()-1){ v_[i]=func(v[i+1],v[i]); }return v_;}
template<class A> bool
all_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]<1){flag=false;}; }return flag;}
template<class A> bool
any_of(const vector<A>& v){bool flag=false;rep(i,v.size()){ if(v[i]>0){flag=true; break;}; }return flag;}
template<class A> bool
none_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]>0){flag=false;}; }return flag;}
template<class T>
void scan_vector(long long size,vector<T>& vector){
    vector.resize(size);
    for(long long i=0;i<size;++i){
        cin>>vector[i];
    }
}
int n;
vector<int> h;
void input(){
    cin>>n;
    scan_vector(n,h);
}
void src(){
    int ans=0;
    rep(i,n){
        bool f=true;
        rep(j,i){
            if(h[j]>h[i]) f=false;
        }
        ans+=f;
    }
    cout<<ans;
}   

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,q,c,up,low,t,x,y,arr[1000000],a,b;
double ff;
bool f;

int main()
{
    cin >> a >> b;
    arr[0]=0;
    for (ll i=1;i<=a;i++)
        cin >> arr[i];
    sort(arr,arr+(a+1));
    if ( b>=a)
        cout << 0 << endl;
    else
    {
        for (ll i=1;i<=a-b;i++)
            x+=arr[i];
        cout << x << endl;
    }
}


Measured memory_bytes: 1792
"use strict";

const main = arg => {
  const input = arg.trim().split(' ').map(x => parseInt(x));

  const [L, R, d] = input;

  const ans = [];

  for (let i = L; i <= R; i++) {
    if (!(i % d)) {
      ans.push(i);
    }
  }

  console.log(ans.length);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 29620
/**
*    created: 16.07.2020 01:58:06
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

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

    auto ctoi = [&] (char c) {
        if (c >= '0' && c <= '9') return c - '0';
        return -1;
    };

    int n, k; cin >> n >> k;
    set<int> st;
    rep(i,k) {int d; cin >> d; st.insert(d);}
    for (int i = n; i <= 10*n+10; i++) {
        string t = to_string(i);
        bool ok = true;
        rep(j,t.size()) {
            int tmp = ctoi(t[j]);
            if (st.count(tmp)) ok = false;
        }
        if (ok) {cout << i << endl; return 0;}
    }
    return 0;
}

Measured memory_bytes: 3684
import sys
input = sys.stdin.readline
n = int(input().strip())
t = 0
x = 0
y = 0
ans = "Yes"
for _ in range(n):
  tn,xn,yn = map(int,input().split())
  if tn%2 != (xn+yn)%2 or abs(xn-x)+abs(yn-y) > (tn - t):
    ans = "No"
    break
print(ans)

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

using namespace std;

int main(){
	int N; cin >> N;
	int T[N];
	for(int i = 0; i < N; ++i) cin >> T[i];
	int M; cin >> M;
	int P[M], X[M];
	for(int i = 0; i < M; ++i) cin >> P[i] >> X[i];
	
	for(int i = 0; i < M; ++i){
		int buf = T[P[i]-1];
		T[P[i]-1] = X[i];
		cout << accumulate(T, T + N, 0) << endl;
		T[P[i]-1] = buf;
	}
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n,x,m,mn=1000,cnt=0;
  cin >> n >> x;
  for(int i=0;i<n;i++){
    cin >> m;
    x-=m;
    cnt++;
    mn = min(mn, m);
  }
  cnt+=x/mn;
  cout << cnt << endl;
}

Measured memory_bytes: 256
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;

const int N = 2e5 + 100;

int n, p[N];
int mi;
int ans;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> p[i];
	mi = p[0];
	for (int i = 0; i < n; i++) {
		mi = min(mi, p[i]);
		ans += (mi >= p[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
inline = list(map(int,input().split()))
di = {}
key = 0
if N%2 ==1:
    cen = 0
else:
    cen = -1

for l in inline:
    if l in di:
        if l != cen:
            if di[l] >= 2:
                key += 1
                break
            else:
                di[l] += 1
        else:
            if di[l] >= 1:
                key += 1
                break
    else:
        di[l] = 1

if key >= 1:
    print(0)
else:
    print((2**int(N/2)%(10**9+7)))

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  string S;
  cin >> S;
  ll N = S.size();

  for (ll i = 0; i < N; i++)
  {
    if (i % 2 == 0 && S.at(i) == 'L')
      FINALANS("No");
    if (i % 2 == 1 && S.at(i) == 'R')
      FINALANS("No");
  }
  FINALANS("Yes");
}

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

int main(void) {
  int N;
  cin >> N;
  if (N == 1)
    cout << "Hello World" << endl;
  else {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
  return 0;
}

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

typedef long long ll;

ll N[2];
vector<ll> X[2];
const ll MOD = 1e9 + 7;
ll Res = 1;

int main() {
  cin >> N[0] >> N[1];
  for (ll k : {0, 1}) {
    ll n = N[k];
    vector<ll> &x = X[k];
    x.resize(n);
    for (ll i = 0; i < n; ++i) cin >> x[i];
    ll res = 0;
    for (ll i = 1; i < n; ++i)
      (res += (x[i] - x[i - 1]) * i % MOD * (n - i) % MOD) %= MOD;
    (Res *= res) %= MOD;
  }
  cout << Res << endl;
  return 0;
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    ll r=0; ll b=0; ll g=0;
    for(int i=0; i<n; i++){
        if(s[i] == 'R') r++;
        else if(s[i] == 'B') b++;
        else g++;
    }
    ll all = r*g*b;
    ll minus = 0;
    rep(i,n){
        for(int j=i+1; j<n; j++){
            if(s[i] != s[j]){
                if(2*j-i<n){
                if(s[2*j-i] != s[i] && s[2*j-i] != s[j]) minus++;
                }
            }
        }
    }
    cout << all-minus << endl;
}

Measured memory_bytes: 3636
// Kachre ke dher ki bhi jagah badalti hai. Tum toh phir v insaan ho


#include <bits/stdc++.h>

#define ll                   long long int
#define MOD                  1000000007
#define fast()               ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define fd(i,a,b)          for(ll i=(ll)a;i<(ll)b;i++)
#define bk(i,a,b)          for(ll i=(ll)a;i>=(ll)b;i--)
#define pb                   push_back
#define vll                   vector<ll>
#define test()               ll t; cin>>t; while(t--)
#define endl                 "\n"
#define param                greater<ll>()
#define ff                   first
#define ss                   second
#define all(v)               v.begin(),v.end()
#define mk                   make_pair
#define keep_unique(v) sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
#define MAX 1000000000000000000
#define sor(vec) sort(vec.begin(), vec.end());
#define rev(vec) reverse(vec.begin(), vec.end());
#define INF                  (ll)1e18
    // std::cout << std::setprecision(10) << std::fixed;

using namespace std;

const ll N = 1e5+10;

// struct compare {
//     bool operator()(const  pair < ll , ll > &a , const  pair < ll , ll > &b){
//         if(a.ff==b.ff)
//         return a.ss>b.ss;

//         return a.ff>b.ff;
//     }
// };


ll dp[405][405];

ll pre[405];

vector<ll>vec(405);

ll solve(ll i, ll j)
{
    if(i>=j)return 0;
    
    if(dp[i][j]!=-1)
    return dp[i][j];
    
    
    dp[i][j]=INF;
    
    for(ll k=i;k<=j;k++)
    {
        dp[i][j]=min(dp[i][j],solve(i,k)+solve(k+1,j)+pre[j]-pre[i-1]);
    }
    
    return dp[i][j];
    
}



int main()
{
//   #ifndef ONLINE_JUDGE
//   freopen("input.txt","r",stdin);
//   freopen("output.txt","w",stdout);
//   #endif
   fast()
    
  int t;
//   cin>>t; 
 t=1;

   while(t--)
   {
       
    //   string s;
    //   cin>>s;
       
       ll n,x,a,b;
       ll on=0,z=0,i,j,k;
       
       cin>>n;
       
      
      
    //   ll pre[n+1];
      
      pre[0]=0;
    
    // priority_queue < ll, vector < ll > , greater<ll> > pq;
    
    
       
       for(i=1;i<=n;i++)
       {
          cin>>vec[i];
          
         pre[i]=pre[i-1]+vec[i];
           
       }
       
    //   for(i=1;i<=n;i++)
    //   {
    //       cout<<pre[i]<<" ";
           
    //   }
       
       ll sum=0;
       
    //   memset(dp,INF , sizeof dp);
       
          for(i=0;i<=n;i++)
          {
              for(j=0;j<=n;j++)
              {
                  dp[i][j]=-1;
              }
            //   cout<<endl;
          }
       
  
       
       
       ll ans=solve(1,n);
       
       
    //     for(i=0;i<=n;i++)
    //   {
    //       for(j=0;j<=n;j++)
    //       {
    //           cout<<dp[i][j]<<" ";
    //       }
    //       cout<<endl;
    //   }
       
       
       
       
      cout<<dp[1][n];
       
       
    //   cout<<ans<<endl;
       
       
   
       
   }
 
   return 0;
}

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

using namespace std;

typedef long long int lli;

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

    int a, b, ans = 1;
    
    cin >> a >> b;

    if (b == 1) {
        cout << 0 << endl;
        return 0;
    }
    
    while (a*ans-(ans-1) < b) ans++;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
s=int(input())
l=[s]

for i in range(10**6):
    if s%2==0 and s//2 not in l:
        s//=2
        l.append(s)
    elif s%2==1 and s*3+1 not in l:
        s=s*3+1
        l.append(s)
    else:
        break

print(len(l)+1)

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

int main() {
  int K;
  string S;
  cin >> K >> S;
  if(S.size()<=K) cout << S << endl;
  else cout << S.substr(0,K) << "..." << endl;
}

Measured memory_bytes: 3628
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int h, w;
int a[500][500];

int main() {
    fastio();

    cin >> h >> w;
    int total = 0;
    forn(i, h) forn(j, w) {
        cin >> a[i][j];
    }

    vec<pii> from, to;
    forn(i, h) {
        forn(j, w - 1) {
            if (a[i][j] % 2) {
                a[i][j]--;
                from.emplace_back(i, j);
                a[i][j + 1]++;
                to.emplace_back(i, j + 1);
            }
        }
    }

    forn(i, h - 1) {
        if (a[i][w - 1] % 2) {
            a[i][w - 1]--;
            from.emplace_back(i, w - 1);
            a[i + 1][w - 1]++;
            to.emplace_back(i + 1, w - 1);
        }
    }

    assert(from.size() == to.size());

    cout << from.size() << endl;
    forn(i, from.size()) {
        cout << from[i].fst + 1 << " " << from[i].snd + 1 << " " << to[i].fst + 1 << " " << to[i].snd + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5228
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    string N;
    cin >>N;
    REP(i,3){
        if(N[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;    
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int a[2000], b[2000];
bool e[4000000];
int n, m;
int c[4000000];
int f[4000000];
bool d[4000000];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (e[a[i]]) {
			cout << 0 << endl;
			return 0;
		}
		e[a[i]] = 1;
	}
	for (int i = 0; i <= n * m; i++) {
		e[i] = 0;
	}
	for (int j = 0; j < m; j++) {
		cin >> b[j];
		if (e[b[j]]) {
			cout << 0 << endl;
			return 0;
		}
		e[b[j]] = 1;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			c[min(a[i], b[j])]++;
			if (a[i] == b[j]) d[a[i]] = 1;
		}
	}
	for (int i = n * m; i >= 0; i--) {
		f[i] = f[i + 1] + c[i];
	}
	int ans = 1;
	for (int i = n * m; i >= 1; i--) {
		if (d[i]) continue;
		if (c[i] == 0) {
			ans *= (f[i] - (n*m - i));
		}
		else {
			ans *= c[i];
		}
		ans %= Mod;
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;

const int NMax = 2e4 + 5;
const int LIM = 1e9;

int A[NMax];
int B[NMax];
int p[NMax];

int main(){

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

    int n;
    cin >> n;

    for(int i = 1; i <= n; i++) cin >> p[i];

    for(int i = 1; i <= n; i++) {
        A[i] = B[n - i + 1] = ((i - 1) * 30000 + 1);
    }

    int k = 1;
    for(int i = n - 1; i > 0; i--, k++) {
        if(A[p[i]] - k > 0) {
            A[p[i]] -= k;
        } else {
            B[p[i]] -= k;
        }
    }

    for(int i = 1; i <= n; i++) cout << A[i] << " ";
    cout << "\n";
    for(int i = 1; i <= n; i++) cout << B[i] << " ";

    return 0;

}


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

const int N = 200005;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}
template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

struct edge {
	int to, nxt;
} tree[N << 1];
int n, col[N], head[N], perm[N], cnt = 0, cnt0 = 0, cnt1 = 0;
void addedge (int u, int v) {
	edge e = {v, head[u]};
	tree[head[u] = cnt++] = e;
} 

void dfs (int u, int fa) {
	for (int i = head[u]; ~i; i = tree[i].nxt) {
		int v = tree[i].to;
		if (v != fa) {
			col[v] = col[u] ^ 1;
			dfs(v, u);
		}
	}
}

int main () {
	read(n);
	for (int i = 1; i <= n; i++) head[i] = -1;

	for (int i = 1; i < n; i++) {
		int u, v;
		read(u), read(v);
		addedge(u, v), addedge(v, u);
	}
	col[1] = 0, dfs(1, 0);

	for (int i = 1; i <= n; i++) {
		if (col[i] == 0) cnt0++;
		else cnt1++;
	}

	if (cnt0 > cnt1) {
		for (int i = 1; i <= n; i++) col[i] ^= 1;
		swap(cnt0, cnt1);
	}
	int bound0 = n / 3, bound1 = (n + 1) / 3, bound2 = (n + 2) / 3;
	if (cnt0 >= bound1 && cnt1 >= bound2) {
		int tot0 = 0, tot1 = 0, tot2 = 0;
		for (int i = 1; i <= n; i++) {
			if (col[i] == 0) {
				if (tot2 >= bound1) perm[i] = 3 * ++tot0;
				else perm[i] = 3 * ++tot2 - 1;
			}
			else {
				if (tot1 >= bound2) perm[i] = 3 * ++tot0;
				else perm[i] = 3 * ++tot1 - 2;
			}
		}
	}
	else {
		int tot0 = 0, tot1 = 0, tot2 = 0;
		for (int i = 1; i <= n; i++) {
			if (col[i] == 0) perm[i] = 3 * ++tot0;
			else {
				if (tot1 < bound2) perm[i] = 3 * ++tot1 - 2;
				else if (tot2 < bound1) perm[i] = 3 * ++tot2 - 1;
				else perm[i] = 3 * ++tot0;
			}
		}
	}
	for (int i = 1; i <= n; i++) write(perm[i]), putchar(' ');
	putchar('\n');
	return 0;
}

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

int main() {
  int N, M;
  
  cin >> N;
  vector<string> vs(N);
  for (int i = 0; i < N; i++) {
    cin >> vs.at(i);
  }
  
  cin >> M;
  vector<string> vt(M);
  for (int i = 0; i < M; i++) {
    cin >> vt.at(i);
  }
  
  int max = 0;
  for (int i = 0; i < N; i++) {
    string s = vs.at(i);
    int cnt = 0;
    for (int j = 0; j < N; j++) {
      if (s == vs.at(j)) {
        cnt++;
      }
    }
    for (int k = 0; k < M; k++) {
      if (s == vt.at(k)) {
        cnt--;
      }
    }
    
    if (cnt > max) max = cnt;
  }
  
  cout << max << endl;
}

Measured memory_bytes: 256
#include<iostream>
using LL = long long;
int main() {
	LL n, m;
	std::cin >> n >> m;
	LL ans;
	if (n * 2 <= m) {
		ans = n;
		LL plus = (m-n*2) / 4;
		ans += plus;
	}
	else if(n * 2 > m) {
		ans = m/2;
	}
	std::cout << ans << std::endl;
	return 0;
}

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

using namespace std;

int main(){
    long long a,b,k;
    cin >> a >> b >> k;
    long long c=0;
    cout << max(c,a-k);
    if(k>a){
        long long p=k-a;
        if(b>p){
            cout << " " << b-p<< endl;
        }
        else{
            cout << " " << 0 << endl;
        }
    }
    else{
        cout << " "<< b << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
#define x first
#define y second

using namespace std;

typedef long long ll;
template <typename T> using V = vector <T>;
const ll mod = 1e9 + 7;
const int MM = 1e4;

int main() {fio;
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <ll> P(n, 0);
	P[0] = 1;
	for(int i = 1; i < n; i++) {
		bool g = s[i - 1] == '>';
		if(g) {
			reverse(P.begin(), P.begin() + i);
		}
		auto cum = P;
		for(int j = 0; j < n; j++) {
			if(j) cum[j] += cum[j - 1];
			cum[j] %= mod;
			P[j] = 0;
		}
		for(int l = 1; l <= i; l++) {
			P[l] = cum[l - 1];
		}
		if(g) {
			reverse(P.begin(), P.begin() + i + 1);
		}
	}
	ll sm = 0;
	for(auto u : P) sm += u;
	cout << sm % mod;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
#include<set>
using namespace std;
int main() {
	int n; cin >> n;
	set<string> s;

	while (n--) {
		string l;
		cin >> l;
		s.insert(l);
	}
	
	cout << s.size() << endl;
}

Measured memory_bytes: 19060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
#define INF  1<<29

int main(){
    int n; cin >> n;
    vector<vector<ll> > d(n,vector<ll>(n));
    rep(i,n) rep(j,n) cin >> d[i][j];
    ll ans = 0;
    rep(i,n){
        rep(j,n){
            bool flag = true;
            rep(k,n){
                if(i==k || j==k) continue;
                if(d[i][j] == d[i][k]+d[k][j]) flag = false;
                if(d[i][j]>d[i][k]+d[k][j]){
                    cout << -1 << endl;
                    return 0;
                }
            }
            if(flag) ans += d[i][j];
        }
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template<class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    
    int n,m;
    cin>>n>>m;
    vpii v(n);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        v[i]=mp(a,b);
    }
    Sort(v);
    ll ans=0;
    int buy=0;
    for(int i=0;i<n;i++){
        if(buy==m)break;
        if(m-buy>=v[i].se){
            ans+=1LL*v[i].se*v[i].fi;
            buy+=v[i].se;
        } else {
            ans+=(m-buy)*1LL*v[i].fi;
            break;
        }
    }
    fin(ans);
}




Measured memory_bytes: 1024
#include <iostream>

int main()
{
	std::string sn;	getline(std::cin, sn);
	int n = std::stoi(sn);
	for (int i=0; i<n; i++) {
		std::string snake; 
		getline(std::cin, snake);
		int state = 0;
		int equal_count = 0;
		for (int k=0; k<snake.length(); k++) {
			char c = snake[k];
			switch (state) {
			case 0:
				if (c == '>') state = 1;
				else state = 9;
				break;
			case 1:
				if (c == '\'') state = 10;
				else if (c == '^') state = 11;
				else state = 9;
				break;
			case 2:
				if (c == '=') equal_count++;
				else if (c == '#') state = 3;
				else state = 9;
				break;
			case 3:
				if (c == '=') {
					equal_count--;
					if (equal_count < 0) state = 9;
				}
				else if (equal_count == 0 && c == '~') state = 4;
				else state = 9;
				break;
			case 4:
				state = 9;
				break;
			case 5:
				if (c == 'Q') state = 6;
				else if (c == '~') state = 7;
				else state = 9;
				break;
			case 6:
				if (c == '=') state = 5;
				else state = 9;
				break;
			case 7:
				if (c == '~') state = 8;
				else state = 9;
				break;
			case 8:
				state = 9;
				break;
			case 10:
				if (c == '=') {
					equal_count++; state = 2;
				}
				else state = 9;
				break;
			case 11:
				if (c == 'Q') state = 12;
				else state = 9;
				break;
			case 12:
				if (c == '=') state = 5;
				else state = 9;
				break;
			}
		}
		if (state == 4) std::cout << "A" << std::endl;
		else if (state == 8) std::cout << "B" << std::endl;
		else std::cout << "NA" << std::endl;
	}
	
	return 0;
}




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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef vector<unsigned long long> vecull;

int N;
string s, t;

int main(void) {
    cin >> N >> s >> t;

    int ans = 2 * N;
    for(int i = N; i < 2 * N; ++i) {
        string ss = s.substr(i - N, 2 * N - i);
        string tt = t.substr(0, 2 * N - i);

        if (ss == tt) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()
    if S.count("hi") > 0:
        x = S.count("hi")
        if x * 2 == len(S):
            print("Yes")
        else:
            print("No")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define All(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

void bittovec(int n, vector<int> &v){

    rep(i,15){
        int tmp = n % 2;
        v.pback(tmp);
        n = n / 2;
    }
}

int main(){

    int n;
    cin >> n;

    vector<vector<pair<int, int> > > talk;

    rep(i,n){
        int a;
        cin >> a;

        vector<pair<int,int> > tmpv;

        rep(j,a){
            int x,y;
            cin >> x >> y;

            tmpv.pback(mpair(x,y));
        }

        talk.pback(tmpv);
    }

    int ans = 0;


    for(int state = 1; state < (1<<n); state++){

        vector<int> hypov;

        bittovec(state, hypov);
        bool state_result = true;

        rep(j,n){
            if(hypov[j] == 1){

                rep(k, talk[j].size()){

                    if(hypov[talk[j][k].first - 1] == talk[j][k].second){

                    }else{
                        state_result = false;
                        break;
                    }
                }

            }
        }

        if(state_result){
            int tmp = 0;

            rep(i,n){
                if(hypov[i] == 1) tmp++;
            }

            ans = max(ans, tmp);
        }

    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    int a, b, c;
    cin >> a >> b >> c;

    if (a == b+c || b == c+a || c == a+b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n,m,cost[1020],p[1020],f[5020],g[5020];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	n=read();m=read();
	rep(i,1,m)
	{
		cost[i]=read();int len=read();
		rep(j,1,len)
		{
			int tmp=read();
			p[i]|=(1<<(tmp-1));
		}
	}
	memset(f,0x3f,sizeof(f));f[0]=0;
	int lim=(1<<n)-1;
	rep(i,1,m)
	{
		memcpy(g,f,sizeof(g));
		rep(j,0,lim)
			g[j|p[i]]=min(g[j|p[i]],f[j]+cost[i]);
		//rep(j,0,5) cout << g[i] << " ";cout << endl;
		memcpy(f,g,sizeof(f));
		//rep(j,0,5) cout << f[i] << " ";cout << endl;
	}
	if (f[lim]<maxd) printf("%d",f[lim]);
	else puts("-1");
	return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
if a == b and b == c:
  if a%2 == 0:
    print(-1)
  else:
    print(0)
else:
  ans = 0
  while a % 2 == 0 and b % 2 == 0 and c % 2 ==0:
    a1 = a
    b1 = b
    c1 = c
    a = (b1+c1)/2
    b = (a1+c1)/2
    c = (a1+b1)/2
    ans += 1
  print(ans)

Measured memory_bytes: 38256
n = int(input())
s = list(input())
r = [0] * n
g = [0] * n
b = [0] * n
rcnt = 0
gcnt = 0
bcnt = 0
for i in range(n):
    r[i] += r[i-1]
    g[i] += g[i-1]
    b[i] += b[i-1]
    if s[i] == 'R':
        r[i] += 1
        rcnt += 1
    if s[i] == 'G':
        g[i] += 1
        gcnt += 1
    if s[i] == 'B':
        b[i] += 1
        bcnt += 1
#print(r,g,b)
ans = 0
for i in range(n-1):
    for j in range(i+1,n-1):
        if s[i] == 'R':
            if s[j] == 'G':
                ans += b[-1] - b[j]
                if j + (j-i) < n:
                    if s[j + (j-i)] == 'B':
                        ans -= 1
            if s[j] == 'B':
                ans += g[-1] - g[j]
                if j + (j-i) < n:
                    if s[j + (j-i)] == 'G':
                        ans -= 1
        if s[i] == 'G':
            if s[j] == 'R':
                ans += b[-1] - b[j]
                if j + (j - i) < n:
                    if s[j + (j-i)] == 'B':
                        ans -= 1
            if s[j] == 'B':
                ans += r[-1] - r[j]
                if j + (j-i) < n:
                    if s[j + (j-i)] == 'R':
                        ans -= 1
        if s[i] == 'B':
            if s[j] == 'R':
                ans += g[-1] - g[j]
                if j + (j-i) < n:
                    if s[j + (j-i)] == 'G':
                        ans -= 1
            if s[j] == 'G':
                ans += r[-1] - r[j]
                if j + (j-i) < n:
                    if s[j + (j-i)] == 'R':
                        ans -= 1
print(ans)


Measured memory_bytes: 69068
#include <bits/stdc++.h>
using namespace std;
 
struct Node {
    int index = -1;
    int depth = -1;
    int parent = -1;
    int *child;
    int ccnt = 0;
    int type = 0;
};
 
void depth(Node *node, int x, int d) {
    node[x].depth = d;
    for (int i = 0; i < node[x].ccnt; ++i) {
        depth(node, node[x].child[i], d+1);
    }
}
 
int Root(Node *node, int x) {
    if (node[x].parent > -1) {
        Root(node, node[x].parent);
    } else {
        return x;
    }
}
 
int main() {
    int n, x, root;
    string type[] = {"leaf", "internal node", "root"};
    cin >> n;
    Node a[n];
    for (int i = 0; i < n; ++i) {
        cin >> x;
        cin >> a[x].ccnt;
        a[x].index = x;
        a[x].child = new int[a[x].ccnt];
        for (int j = 0; j < a[x].ccnt; ++j) {
            a[x].type = 1;
            cin >> a[x].child[j];
            a[a[x].child[j]].parent = x;
        }
    }
     
    root = Root(a, 0);
    a[root].type = 2;
    depth(a, root, 0);
     
    for (auto& i : a) {
        cout << "node " << i.index << ": ";
        cout << "parent = " << i.parent << ", ";
        cout << "depth = " << i.depth << ", ";
        cout << type[i.type] << ", ";
        cout << "[";
        for (int j = 0; j < i.ccnt-1; ++j) {
            cout << i.child[j] << ", ";
        }
        if (i.ccnt) { 
            cout << i.child[i.ccnt-1] << "]\n";
        } else {
            cout << "]\n";
        }
    }
     
    return 0;
}

Measured memory_bytes: 9796
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		var S = Console.ReadLine();
		string ans = "Yes";
		var count = 0;
		foreach (var c in S) {
			count++;
			if (count % 2 == 0) {
				if (c == 'R') {
					ans = "No";
					break;
				}
			} else {
				if (c == 'L') {
					ans = "No";
					break;
				}
			}
		}
		Console.WriteLine(ans);
	}
}
	

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[100009];
int main()
{
    ll i,j,n,t,m,cnt=1;
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++) {
                cnt+=a[i]*a[j];
        }
      //  cnt=1;
    }
    cout<<cnt-1<<endl;
}


Measured memory_bytes: 256