akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7,N=1e6+10;
ll n,f[N],po[N];
ll ksm(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
ll c(int n,int m)
{
	return po[n]*ksm(po[m],mod-2)%mod*ksm(po[n-m],mod-2)%mod;
}
int main()
{
	cin>>n;
	if(n==1) 
	{
		cout<<0;
		return 0;
	}
	ll ans=0;
	po[0]=1;
	for(int i=1;i<=n;i++) po[i]=po[i-1]*i%mod;
	ll x=4,y=ksm(8,n-2),p=ksm(8,mod-2);
	for(int i=2;i<=n;i++)
	{
		ans=(ans+c(n,i)*(((x-2)%mod+mod)%mod)%mod*y%mod)%mod;
		x=x*2%mod;
		y=y*p%mod;
	}
	cout<<ans;
	
	return 0;
} 

Measured memory_bytes: 11392
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
bool isMM(int mm){
  if(mm >= 1 && mm <= 12){
    return true;
  }
  else{
    return false;
  }
}
int main(){
  string s;
  string sMae,sAto;
  cin >> s;
  int mae,ato;
  sMae = s.substr(0,2);
  sAto = s.substr(2,2);
  //cout << sMae << endl;
  //cout << sAto <<endl;
  mae = atoi(sMae.c_str());
  ato = atoi(sAto.c_str());
  if(isMM(mae) && isMM(ato)){
    cout << "AMBIGUOUS" << endl;
  }
  else if(isMM(mae) && !isMM(ato)){
    cout << "MMYY" << endl;
  }
  else if(!isMM(mae) && isMM(ato)){
    cout << "YYMM" << endl;
  }
  else{
    cout << "NA" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// モジュール
constexpr ll pdiv = 1000000007LL;

// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    ll rs = 0;
    ll gs = 0;
    ll bs = 0;
    ll ans = 1;
    REP(i, n) {
        ll term = (a[i] == rs) + (a[i] == gs) + (a[i] == bs);
        if (a[i] == rs) {
            rs++;
            (ans *= term) %= pdiv;
        } else if (a[i] == gs) {
            gs++;
            (ans *= term) %= pdiv;
        } else if (a[i] == bs) {
            bs++;
            (ans *= term) %= pdiv;
        } else {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#define ll long long
ll power(ll a){
  if(a==0) return 1;
  return 2*power(a-1);}
int main(){
  ll h,ans=0;
  scanf("%lld",&h);
  long double p;
  p=log2l(h);
  ll q=p/1;
  if(h==1)
    ans=1;
  else
    ans=power(q+1)-1;
  printf("%lld\n",ans);
  return 0;}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main()
{
  char s[100];
  char b='x';
  scanf("%s",s);
  int a,i;
  a=strlen(s);
  for(i=0;i<s[i]!='\0';i++)
  {
    printf("%c",b);

  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main() {
    int K; cin >> K;
    long double sum = 0;
    for (int i = 0; i < K; ++i) {
        long double input; string s;
        cin >> input >> s;
        if (s == "BTC") {
            input *= 380000.0;
        }
        sum += input;
    }

    cout << sum << endl;   
}

Measured memory_bytes: 256
while true
    judges = gets.to_i
    break if judges == 0
    b = []
    for i in 0..judges-1
        b << gets.to_i
    end
    b.delete_at(b.index(b.max))
    b.delete_at(b.index(b.min))
    sum = 0
    for i in 0..judges-3
        sum = sum + b[i]
    end
    puts sum / (judges-2)
end

Measured memory_bytes: 8652
s = input()
N = len(s)

i = N-1
ret = 0
BC_count = 0
while i >= 0:
    prev = i-1
    if prev < 0:
        if s[i] == 'A':
            ret += BC_count
            
        break
        
    
    if s[i] == 'A':
        ret += BC_count
        if s[prev] == 'B':
            BC_count = 0
    elif s[i]=='C':
        if s[prev]=='B':
            BC_count += 1
        else:
            BC_count = 0
    elif s[i]=='B':
        if s[prev]=='B':
            BC_count = 0

    i-= 1


print(ret)


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

int main() {
	//入力
	string S;
	cin >> S;

	//処理
	// A <-> T C <-> G
	char ans = 'A';

	if (S[0] == 'A') ans = 'T';
	else if (S[0] == 'T') ans = 'A';
	else if (S[0] == 'C') ans = 'G';
	else if (S[0] == 'G') ans = 'C';

	//出力
	cout << ans << endl;
}



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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;
    //cin>>testcase;
    for(int p=0;p<testcase;p++){
     ll n=0,k=0;
     cin>>n>>k;
     n=n%k;
     cout<<min(n,abs(n-k));
    }

    return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int IINF = INT_MAX;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    ll a, v, b, w, t; cin >> a >> v >> b >> w >> t;
    if(v <= w){
        cout << "NO" << endl;
        return 0;
    }

    if(abs(a - b) <= (v - w) * t){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 3644
#!/usr/bin/env ruby

STDIN.gets.chomp.to_i
array = STDIN.gets.chomp.split(' ').map(&:to_i)

def get_answer(first, array)
  ans = 0
  sum = first
  array.each do |a|
    if sum >= 0
      if sum + a < 0
        sum += a
      else
        ans += (-1 - (sum + a)).abs
        sum = -1
      end
    else # sumがマイナス
      if sum + a > 0
        sum += a
      else
        ans += (1 - (sum + a)).abs
        sum = 1
      end
    end
  end

  return ans
end

first = array.shift

if first == 0
  ans = [get_answer(1, array), get_answer(-1, array)].min + 1
else
  ans1 = get_answer(first, array)
  ans2 = get_answer((-1 * first/first.abs), array) + first.abs + 1
  ans = [ans1, ans2].min
end

puts ans


Measured memory_bytes: 9612
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)



signed main(){
  string s;
  cin>>s;
  if(s=="ani"){
    cout<<"square1001"<<endl;
  }
  else{
    cout<<"e869120"<<endl;
  }
  return 0;
}




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

int main(){
    int n, i, ans = 0;
    cin >> n;
    int a[n+1];
    for(i = 0; i < n; i++){
        cin >> a[i];
    }

    while(1){
        for(i = 0; i < n; i++){
            if(a[i] % 2 == 0){
                a[i] /= 2;
            }else{
                cout << ans << endl;
                return 0;
            }
        }
        ans++;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	REP(i,s.size()-1) {
		if(s[i]=='A'&&s[i+1]=='C') {
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]

use procon::*;
use std::cmp::{max, min};
use std::collections::*;
use std::ops::*;
use std::*;

pub fn main() {
    let words = read_words::<i32>();
    let (A, B, C, X, Y) = (
        words[0],
        words[1],
        words[2],
        words[3] as i32,
        words[4] as i32,
    );

    let total = (0..max(X, Y) + 1)
        .map(|N| {
            // ABピザを 2N 枚買う
            C * (2 * N) + A * max(0, X - N) + B * max(0, Y - N)
        })
        .min()
        .unwrap();

    println!("{}", total);
    return;
}

pub mod procon {
    use std;
    use std::collections::*;
    use std::io;
    use std::mem;
    use std::str::FromStr;

    pub fn read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim_right().to_owned()
    }

    pub fn read_words<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace()
            .map(|word| T::from_str(word).unwrap())
            .collect()
    }

    pub fn read_vec(len: usize) -> Vec<String> {
        let mut vec = Vec::new();
        while vec.len() < len {
            let line = read_line();
            for word in line.split_whitespace() {
                vec.push(word.to_owned());
            }
        }
        assert!(vec.len() == len);
        vec
    }

    pub trait IteratorExt: Iterator {
        fn vec(self) -> Vec<Self::Item>
        where
            Self: Sized,
        {
            self.collect()
        }
    }

    impl<T: Iterator> IteratorExt for T {}
}


Measured memory_bytes: 4352
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int d,g,a[55],c[55];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  cin >> d >> g;
  int sum = 0;
  for(int i=0;i<d;i++){
    cin >> a[i] >> c[i];
    sum+=a[i];
  }
  int ans = sum;
  for(int i=0;i<(1<<d);i++){
    int cur = 0;
    int score = 0;
    priority_queue<int> q;
    for(int j=0;j<d;j++){
        if(i&(1<<j)){
            score+=c[j];
            score+=100*(j+1)*a[j];
            cur+=a[j];
        }
        else {
            for(int k=1;k<=a[j];k++){
                q.push(100*(j+1));
            }
        }
    }
    while(score<g){
        cur++;
        score+=q.top();q.pop();
    }
    ans = min(ans,cur);
  }
  cout << ans << endl;

return 0;
}
///....


Measured memory_bytes: 256
/*
sonu_verma1
*/
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set;*/
 
#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout <<val <<ch
#define FOR(i, st, en, ch) for(register int i = (st); i <= (en) ; i += (ch))
#define RFOR(i, st, en, ch) for(register int i = (st); i >= (en) ; i -= (ch))
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
 
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
int fun(vector<int>&dp,vector<int>&h,int n)
{
    if(n==0)
        return 0;
    if(n==1)
        return abs(h[1]-h[0]);
    if(dp[n]!=-1)
        return dp[n];
    dp[n]=min(abs(h[n]-h[n-1])+fun(dp,h,n-1),abs(h[n]-h[n-2])+fun(dp,h,n-2));
    return dp[n];
}
/*********************************************************************/
void test(int r)
{
    int n;
    cin>>n;
    vector<int>dp(n,-1),h(n);
    int i;
    for(i=0;i<n;i++)
    {
        cin>>h[i];
    }
    int ans=fun(dp,h,n-1);
    cout<<ans<<endl;
    

}
/***********************************************************************/
int main()
{
    fast();
    int t=1,r;
    // cin>>t;
    for(r=1;r<=t;r++)
        test(r);
    return 0;
}

Measured memory_bytes: 7940
#include <iostream>
#include <vector>

using namespace std;

int h, w;

void f(vector<vector<bool>>& board, vector<vector<bool>>& visited,int& num_black, int& num_white, int hi, int wi){
    if(visited[hi][wi]) return;
    bool color=board[hi][wi];
    if(color) ++num_black;
    else ++num_white;
    visited[hi][wi]=true;
    if(hi>0 && board[hi-1][wi]!=color) f(board, visited, num_black, num_white, hi-1, wi);
    if(hi+1<h && board[hi+1][wi]!=color) f(board, visited, num_black, num_white, hi+1, wi);
    if(wi>0 && board[hi][wi-1]!=color) f(board, visited, num_black, num_white, hi, wi-1);
    if(wi+1<w && board[hi][wi+1]!=color) f(board, visited, num_black, num_white, hi, wi+1);
}

int main(){
    cin >> h >> w;
    auto board=vector<vector<bool>>(h, vector<bool>(w));
    auto visited=vector<vector<bool>>(h, vector<bool>(w, false));
    for(int hi=0; hi<h; ++hi){
        string s;
        cin >> s;
        for(int wi=0; wi<w; ++wi){
            board[hi][wi]= s[wi]=='#';
        }
    }
    long long result=0;
    for(int hi=0; hi<h; ++hi){
        for(int wi=0; wi<w; ++wi){
            int num_black=0, num_white=0;
            f(board, visited, num_black, num_white, hi, wi);
            result+=(long long)num_black*(long long)num_white;
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 20224
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define N 10000

int keisan(int);
int main(){
  int i,j,num;
  int S[N];
  int count = 0;
  while(1){
    scanf("%d",&num);
    if(num >= 1 && num <= N)break;
  }
  for(i = 0;i<num;i++){
    scanf("%d", &S[i]);
  }
  for(i = 0;i<num;i++){
    if(keisan(S[i]) == 1)count++;
       }
    printf("%d\n",count);

    return 0;

  }
int keisan(int a){
  int i;
  if(a==2)return 1;
  if(a < 2 || a%2 == 0)return 0;
  i = 3;
  while(i <= sqrt(a)){
    if(a%i == 0)return 0;
    i = i+2;
  }
  return 1;
}

Measured memory_bytes: 628
#include <iostream>
#include <cstring>
using namespace std;
int main(){
  char str[100+1];
  cin >> str;
  int cnt=0,len=strlen(str);
  for(int i=0;i<len;i++){
    if(str[i]!=str[len-i-1])cnt++;
  }
  cout << cnt/2 << endl;
  return 0;
}

Measured memory_bytes: 256
import collections
h,w = map(int,input().split())
q = collections.deque()
A = []
for i in range(h):
    s = input()
    L = []
    for j in range(w):
        if s[j] == '.':
            L.append(s[j])
        else:
            L.append(0)
            q.append([i,j])
    A.append(L)
dy_dx = [[1,0],[0,1],[-1,0],[0,-1]]
while len(q) > 0:
    cur = q.popleft()
    for i in range(4):
        y = cur[0]+dy_dx[i][0]
        x = cur[1]+dy_dx[i][1]
        if 0 <= y < h and 0 <= x < w:
            if A[y][x] == '.':
                A[y][x] = A[cur[0]][cur[1]]+1
                q.append([y,x])
ans = 0
for i in range(h):
    for j in range(w):
        if ans < A[i][j]:
            ans = A[i][j]
print(ans)

Measured memory_bytes: 139740
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    cout << (ll)pow(2, m) * (1900 * m + 100 * (n - m)) << endl;
    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << endl
using namespace std;
int n, a[1234], k, ans;
vector<int>v;
bool b[1234 * 1234];
signed main() {
	cin >> n >> k;
	for1(i, n) {
		cin >> a[i]; a[i] += a[i - 1];
		for0(j, i)v.push_back(a[i] - a[j]);
	}
	int p = 1099511627776;
	while (p > 0) {
		int cnt = 0;
		for0(i, v.size())if ((v[i] / p) % 2 && !b[i])cnt++;
		if (cnt >= k) {
			for0(i, v.size())if ((v[i] / p) % 2 == 0)b[i] = 1;
			ans += p;
		}
		p /= 2;
	}
	puts(ans);
}

Measured memory_bytes: 6128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string S;
    cin >> S;

    vector<int> ans(S.size());
    int r = 0, l = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'R') r++; else l++;
        if (i + 1 == S.size() || (S[i] == 'L' && S[i + 1] == 'R')) {
            ans[i - l] = (r + 1) / 2 + l / 2;
            ans[i - l + 1] = r + l - ans[i - l];
            r = 0, l = 0;
        }
    }

    for(auto a : ans) {
        cout << a << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	   static long gcd(long a, long b) 
	    { 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
	    } 
	      
	    // method to return LCM of two numbers 
	    static long lcm(long a, long b) 
	    { 
	        return (a*b)/gcd(a, b); 
	    } 
	static long find(long x,long c,long d)
	{
		long ans=0;
		ans=x/d;
		ans+=x/c;
		ans-=x/lcm(c,d);
		return ans;
	}
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		long a=scan.nextLong();
		long b=scan.nextLong();
		long c=scan.nextLong();
		long d=scan.nextLong();
		
		long ans=(b-find(b,c,d))-((a-1)-find(a-1,c,d));
		System.out.println(ans);
	}
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  vector<int>a(n);
  int p=0;
  for(int i=0;i<m;++i){
    int k;
    cin >> k;
    for(int j=0;j<k;++j){
      int s;
      cin >> s;
      s--;
      a[s] |= 1 << i;
    }
  }
  for(int i=0;i<m;++i){
    int x;
    cin >> x;
    p |= x << i;
  }
  int ans=0;
  for(int s=0;s<(1<<n);s++){
    int t=0;
    for(int i=0;i<n;i++){
      if(s>>i&1){
        t^=a[i];
      }
    }
    if(t==p){
      ans++;
    }
  }
  cout << ans << endl;
}
    


Measured memory_bytes: 3624
def resolve():
    N = int(input())
    S = input()
    left, right, cnt = 0,0,0

    for s in S:
        if s == "(":
            cnt += 1
        else:
            cnt -= 1
        if cnt < 0:
            right += 1
            cnt = 0

    if cnt>0:
        left = cnt

    ans = "("*right + S + ")"*left
    print(ans)

if __name__ == "__main__":
    resolve()

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



int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif


    int n, m;
    while (scanf("%d%d", &n, &m) == 2) {
        vector<vector<int> > e(n);
        for (int i = 0; i < m; i++) {
            int u, v;
            scanf("%d%d", &u, &v);
            --u; --v;
            e[u].push_back(v);
            e[v].push_back(u);
        }

        vector<int> ans;
        vector<int> used(n);
        vector<int> pref, suf;
        pref.push_back(0);
        suf.push_back(e[0][0]);
        for (int x : pref) used[x] = 1;
        for (int x : suf) used[x] = 1;

        while (!e[pref.back()].empty()) {
            int to = e[pref.back()].back();
            e[pref.back()].pop_back();
            if (used[to]) continue;
            used[to] = 1;
            pref.push_back(to);
        }
        while (!e[suf.back()].empty()) {
            int to = e[suf.back()].back();
            e[suf.back()].pop_back();
            if (used[to]) continue;
            used[to] = 1;
            suf.push_back(to);
        }
        reverse(pref.begin(), pref.end());
        for (int x : suf) pref.push_back(x);

        printf("%d\n", (int)pref.size());
        for (int i = 0; i < (int)pref.size(); i++) printf("%d%c", pref[i] + 1, " \n"[i + 1 == (int)pref.size()]);
    }


#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 7416
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
//~ int const MOD = 1e9 + 7;
int const MOD = 998244353;
long long const INF = 1e18 + 42;
/*************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, m;
  cin >> n >> m;
  string s; cin >> s;
  set<pair<int,int>> st;
  vector<int> dp(n + 1, MOD), to(n + 1, -1);
  dp[n] = 0;
  to[n] = n;
  st.emplace(0, n);
  for (int i = n - 1; i >= 0; --i) {
    if (i + m + 1 <= n) {
      st.erase({dp[i + m + 1], i + m + 1});
    }
    if (s[i] == '0') {
      auto x = *st.begin();
      if (x.first >= MOD) kek(-1);
      dp[i] = 1 + x.first;
      to[i] = x.second;
    }
    st.emplace(dp[i], i);
  }
  int p = 0;
  while (p < n) {
    cout << to[p] - p << ' ';
    p = to[p];
  }
  
  return 0;
}


Measured memory_bytes: 5632
N,H,W=map(int,input().split())
A=[]
B=[]
for n in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
count=0
for n in range(N):
    if H<=A[n] and W<=B[n]:
        count+=1
print(count)

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

int main() 
{
    int a, b;
    cin >> a >> b;
    int sum = 0;
    if (a > b) {
        for (int i = 0; i < a; i++) {
            sum += b * pow(10,i);
        }
    }else{
        for (int i = 0; i < b; i++) {
            sum += a * pow(10,i);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N);
    vector<int> a(N);
    read(a);
    rep(i, 0, N) a[i]--;

    int len = 0;
    int ans = 0;
    rep(i, 0, N) {
        if (a[i] == i) {
            ++len;
        } else {
            ans += (len + 1) / 2;
            len = 0;
        }
    }
    ans += (len + 1) / 2;

    print(ans);

    return 0;
}


Measured memory_bytes: 640
from collections import deque
n = int(input())
ad_ls = [[] for _ in range(n)]
for _ in range(n-1):
    a,b,w = map(int,input().split())
    ad_ls[a-1].append([b-1,w])
    ad_ls[b-1].append([a-1,w])

cost_ls = [0] * n
done_ls = [0] * n
done_ls[0] = 1
q = deque()
q.append(0)

while q:
    now = q.pop()
    for new in ad_ls[now]:
        nex,cost = new[0],new[1]
        if not done_ls[nex]:
            cost_ls[nex] = cost + cost_ls[now]
            done_ls[nex] = 1
            q.append(nex)

color_ls = [0] * n
for i in range(n):
    color_ls[i] = cost_ls[i] % 2

for color in color_ls:
    print(color)



Measured memory_bytes: 52428
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    n = max(0, n - 1);
    n = (n * n + n) / 2;
    m = max(0, m - 1);
    m = (m * m + m) / 2;
    cout << (n + m);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main (){
int a,b,c,d,f=0,s=0;
cin>>a>>b>>c>>d;
if (a<d&&b>c){
     
    if (a<c)
        f=c;
        else
        f=a;

    if(b<d)
        s=b;
    else
        s=d;

        cout<<abs(s-f)<<endl;


     }

else
    cout<<0<<endl;

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int h, n;
	cin >> h >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	sort(a.begin(), a.end(), greater<int>());
	
	bool yes = false;
	for(int i = 0; i < n; ++i) {
		h -= a[i];
		
		if( h <= 0 ) {
			yes = true;
			break;
		}
	}
	
	if( yes ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
#define pb push_back

typedef long long ll;
using namespace std;
int MOD = 1000000007;

ll calc(ll n, ll d){
  ll sum = 0;
  while(n){
    sum += n % d;
    n /= d;
  }
  return sum;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, s, i = 2;
  cin >> n >> s;
  if(n == s){cout << n + 1 << endl;return 0;}
  for(; i * i <= n; i++){
    if(s == calc(n, i)){cout << i << endl; return 0;}
  }
  FORR(j, min(i-1, s), 0){
    ll p = n - s + j;
    if((p % j == 0) && (p / j > s - j) && (p / j > j)){
      cout << p / j << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = 1000000;
		boolean[] p = new boolean[N + 1];
		int[] map = new int[N + 1];
		for (int i = 2; i <= N; i++) {
			map[i] = map[i - 1];
			if (!p[i]) {
				map[i]++;
				for (int j = i * 2; j <= N; j += i) {
					p[j] = true;
				}
			}
		}

		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int sum = 0;
			for (int i = 0; i < n; i++) {
				int a = scanner.nextInt();
				int b = scanner.nextInt();
				int c = Math.max(a - b, 2);
				int d = Math.min(a + b, 1000000);
				sum += map[d] - map[c - 1];
			}
			System.out.println(sum - n);
		}
	}
}

Measured memory_bytes: 33108
N, Y = map(int, input().split())

a, b, c = -1, -1, -1
flag = False
for i in range(N+1):
    if flag:
        break

    for j in range(N+1-i):
        if i * 10000 + j * 5000 + (N-i-j) * 1000 == Y:
            a = i
            b = j
            c = N-i-j
            flag = True
            break

print("{} {} {}".format(a,b,c))

Measured memory_bytes: 40684
#include<bits/stdc++.h>
using namespace std;
int c[4][4];
int main()
{
	std::ios::sync_with_stdio(false);
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			cin>>c[i][j];
		}
	}
	for(int i=1;i<3;i++)
	{
		if(c[i][1] - c[i+1][1] != c[i][2] - c[i+1][2]) 
		{
			cout<<"No"<<endl;
			return 0;
		}
		if(c[i][1] - c[i+1][1] != c[i][3] - c[i+1][3])
		{
			cout<<"No"<<endl;
			return 0;
		}
	} 
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
loop do
  w, q = gets.split.map(&:to_i)
  break if w==0 and q==0
  field = Array.new(w, nil)
  findSpace = ->d{
    space = 0
    pos = nil
    (0...w).each{|i|
      if field[i]==nil
        pos = i if pos==nil
        space += 1
        return pos if space>=d
      else
        space = 0
        pos = nil
      end
    }
    return nil
  }
  fill = ->id, pos, d{
    (pos...pos+d).each{|i| field[i] = id}
  }
  delete = ->id{
    (0...w).each{|i| field[i] = nil if field[i]==id}
  }
  
  q.times{
    type, *args = gets.split
    args.map!(&:to_i)
    
    if type=="s"
      id, d = args
      pos = findSpace[d]
      if pos
        puts pos
        fill[id, pos, d]
      else
        puts "impossible"
      end
    elsif type=="w"
      id = args[0]
      delete[id]
    end
    
  }
  puts "END"
end


Measured memory_bytes: 6876
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int Combination(int n, int r){
    if (n/2<r)r=n-r;
    vector<vector<long long> > dp(n+1,vector<long long>(r+1));
    for (int i=0;i<=n;i++){
        dp[i][0] = 1;
    }
    for (int i=0;i<=r;i++){
        dp[i][i] = 1;
    }
    for (int i=1;i<=n;i++)
        for (int j=1;j<i && j<=r;j++)
            dp[i][j] = (dp[i-1][j] + dp[i-1][j-1])%MOD;
    return dp[n][r];
}
map<long long, int> PrimeFactor(int n){
    map<long long, int> ret;
    for (int i=2;i*i<=n;i++){
        while(n%i==0){
            ret[i]++;
            n/=i;
        }
    }
    if (n!=1){
        ret[n] = 1;
    }
    return ret;
}

int main() {
  int n, m;
  cin >> n >> m;
  long long ans = 1;
  for(auto p : PrimeFactor(m)) {
    //cout << p.first << " " << p.second << endl;
    ans *=  Combination(n+p.second-1,p.second);
    ans = ans % MOD;
  }
  cout << ans << endl;
}

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

int main() {
 long long N;
  
  cin >> N;
  
  vector<long long>A(N);
  
  for(int i = 0 ; i < N ; i++){
  	cin >> A.at(i);
  }
    
  long long X = 1;
  long long Y = 1;
  
  sort(A.begin(), A.end());
  
  if(A.at(0) == 0){
  		cout << 0 << endl;
        exit(0);
  }
  
  for(int i = 0 ; i < 18 ; i++){
  	Y = Y*10;
  }
  
  for(int i = 0 ; i<N ; i++){
   long long emer = Y/X + 1;
    X *= A.at(i);
  	if(X > Y||A.at(i)>emer){
  		cout << -1 << endl;
        exit(0);
  	}
  }
   
  cout << X << endl;
  
}



Measured memory_bytes: 4384
package main
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func kuriage(i int) int {
    amari := i % 10
    if amari == 0 {
        return i
    } else {
        return i - i % 10 + 10
    }
}

func main(){
    var waitTime [5]int
    var minIdx int
    min := 10
    for i := range waitTime {
        if sc.Scan() {
            t, _ := strconv.Atoi(sc.Text())
            if amari := t % 10; 0 < amari && amari < min {
                minIdx = i
                min = amari
            }
            waitTime[i] = t
            // fmt.Println(waitTime[i])
        }
    }
    // fmt.Println(min)
    
    var minTotal int
    for i, v := range waitTime {
        if i == minIdx {
            minTotal += v
        } else {
            minTotal += kuriage(v)
        }
    }
    fmt.Println(minTotal)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <math.h>

int main(){

  int N, K;
  scanf("%d %d",&N, &K);
  char S[N+5];
  scanf("%s",S);

  int happy = 0;
  for (int i=0; i<N-1; i++){
    if (S[i]==S[i+1]){
      happy++;
    }
  }
  //printf("%d\n",happy);
  int edge_alone = 0;
  if (S[0]=='L'){
    edge_alone++;
  }
  if (S[N-1]=='R'){
    edge_alone++;
  }
  while(K>0 && happy<N-2){
    happy+=2;
    K--;
  }
  while(K>0 && happy<N-1){
    happy++;
    K--;
    //edge_alone--;
  }
  printf("%d\n",happy);
  return 0;
}

Measured memory_bytes: 384
import itertools

N, M, Q = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(Q)]

Mls = list(range(1,M+1))
Mls = [str(n) for n in Mls]
l = list(itertools.combinations_with_replacement(Mls,N))

ans = 0
for A in l:
    pnt = 0
    for l in ls:
        if int(A[l[1]-1])-int(A[l[0]-1]) == l[2]:
            pnt += l[3]
    ans = max(ans,pnt)
print(ans)

Measured memory_bytes: 84820
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            
            string a = "";
            for(int i = 0; i < S.Length; i++)
            {
                string tmp = S.Substring(S.Length - 1, 1);
                a = S.Substring(0, S.Length - 1);
                tmp += a;
                if(tmp == T)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                S = tmp;
            }
            Console.WriteLine("No");
        }
    }
}
//int[] N = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

Measured memory_bytes: 25860
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <string>
#include <sstream>
int fix()
{
    //example to format floating point numbers.
    double pi = 3.141592653589793;
    double r = 3.141592653589793 * 128;
    std::ios_base::fmtflags f(std::cout.flags()); //[1]
    std::cout << "default:\n  " << pi << " " << r << "\n";
    std::cout << std::setprecision(4) << "setprecision(4):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout << std::setiosflags(std::ios::fixed) << "setiosflags(std::ios::fixed):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout << std::setprecision(5) << "setprecision(5):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout.flags(f);
    std::cout << "reset:\n  " << pi << " " << r << "\n";
    //[1] https://stackoverflow.com/questions/2273330/restore-the-state-of-stdcout-after-manipulating-it
    //[2] https://stackoverflow.com/questions/4217510/how-to-cout-the-correct-number-of-decimal-places-of-a-double-value
    return 0;
}
void multipleLines()
{
    //example to parse multiple lines input.
    std::istringstream isin("1 2 3\n3 2 4\n0 0 0");

    for (std::string str; std::getline(isin, str);)
    {
        std::istringstream tisin(str);
        int a, b, c;
        tisin >> a >> b >> c;
        std::cout << a << " " << b << " " << c << "\n";
    }
    //[1]  https://stackoverflow.com/questions/19767644/c-parsing-input-string-to-variables
}
#include <vector>
#include <set>
#include <map>

int main()
{
    int n, m;
    std::vector<double> vM;
    std::vector<double> vV;
    std::cin >> n >> m;
    vM.resize(n * m);
    vV.resize(m);
    for (int i = 0; i < n * m; i++)
    {
        std::cin >> vM[i];
    }
    for (int i = 0; i < m; i++)
    {
        std::cin >> vV[i];
    }

    for (int i = 0; i < n; i++)
    {
        double s=0;
        for (int j = 0; j < m; j++)
        {
            s += vM[i*m + j]*vV[j];
        }
        std::cout << std::setprecision(16) << s << "\n";
    }

    return 0;
}


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

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

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

const long long INF = 1LL << 60;

int N;
long long h[100010];
long long dp[100010];


void solve(long long N, std::vector<long long> h){
    // 初期化
    for(int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // 貰うDP
    /*
    for(int i = 1; i < N; ++i){
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }
    */

    // 配るDP
    for(int i = 0; i < N; ++i){
        chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        chmin(dp[i+2], dp[i] + abs(h[i]-h[i+2]));
    }


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

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, std::move(h));
    return 0;
}


Measured memory_bytes: 1792
import sys
import queue
input = sys.stdin.readline
n = int(input())
g = [[] for _ in range(n+1)]
d = [-1 for _ in range(n+1)]
for _ in range(n):
    c = list(map(int,input().split()))
    g[c[0]] = c[2:]

depth = 0
q = queue.Queue()
p = queue.Queue()
q.put(1)
while not q.empty():
    while not q.empty():
        s = q.get()
        if d[s] < 0:
            d[s] = depth
            for i in g[s]:
                p.put(i)
    p, q = q, p
    depth += 1

for i in range(1,n+1):
    print (i,d[i])


Measured memory_bytes: 7008
#include<bits/stdc++.h>
using namespace std;
const int MN = 1e6+2;
char s[MN],t[MN];
int main () {
	int n;
	scanf ("%d %s %s",&n,s,t);
	for (int i = 0; i < n; i++) printf("%c%c",s[i],t[i]);
	putchar(10);
	return 0;
}


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

#define sz(a) ((int)a.size())
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define forse(i,s,e) for(int i=(int)s;i<(int)e;i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using dbl=double;
using ll=long long;
using pii=pair<int, int>;
using pll=pair<ll, ll>;

dbl PI=3.141592653589793;

//Modular arithmetic
template<int P>
class Modular{
	public:
		static int init_siz;
		static vector<Modular> inverse,factorial;
		int n=0;
		static Modular exp(Modular a, long long e) {
			Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
			return res;
		}
		static void init(int n){
			init_siz=n;
			inverse.resize(n+1);factorial.resize(n+1);
			factorial[0] = 1;
			for (int i = 1; i <= n; i++) factorial[i] = factorial[i - 1] * i;
			inverse[n]=exp(factorial[n],P-2);
			for (int i = n-1; i>=0; i--) inverse[i] = inverse[i+1] * (i+1);
		}
		static Modular inv(Modular const& a){
			assert(a.n!=0);
			return (init_siz>=a.n? inverse[a.n]*fac(a-1):exp(a,P-2));
		}
		static Modular cinv(Modular const& a){
			return (init_siz>=a.n? inverse[a.n]:exp(fac(a),P-2));
		}
		static Modular fac(Modular const& a){
			if(init_siz>=a.n) return factorial[a.n];
			else{
				Modular out=1;
				for(int i=0;i<a.n;i++) out*=(i+1);
				return out;
			}
		}
		Modular(long long val = 0) {n=val%P;if(n<0) n+=P;}
		Modular& operator+=(Modular const& b) {n += b.n; if (n >= P) n -= P; return *this;}
		Modular& operator-=(Modular const& b) {n -= b.n; if (n < 0) n += P;return *this;}
		Modular& operator*=(Modular const& b) {n = (long long)n * b.n % P;return *this;}
		Modular exp(long long e) {return exp(*this,e);}
		Modular inv(){return inv(*this);}
		Modular& operator/=(Modular const& b){ return *this *=inv(b);}	
		friend std::ostream& operator<<(std::ostream& os,Modular const& a){return os<<a.n;}
		friend Modular operator+(Modular a, Modular const b) { return a += b; }
		friend Modular operator-(Modular a, Modular const b) { return a -= b; }
		friend Modular operator-(Modular const a) { return 0 - a; }
		friend Modular operator*(Modular a, Modular const b) { return a *= b; }
		friend Modular operator/(Modular a, Modular const b) { return a /= b; }
		friend bool operator==(Modular const& a, Modular const& b) {return a.n == b.n;}
		friend bool operator!=(Modular const& a, Modular const& b) {return a.n != b.n;}
};
template<int P> int Modular<P>::init_siz=-1;
template<int P> vector<Modular<P>> Modular<P>::factorial;
template<int P> vector<Modular<P>> Modular<P>::inverse;
template<int P> string to_string(Modular<P> b) { return to_string(b.n);}
const int P=1e9+7;
typedef Modular<P> mint;


void solve(){
	ll n;
	cin >> n;
	ll out=0;
	forn(i,n){
		out+=((n-i)*(n-i+1))/2;
	}
	forn(i,n-1){
		ll u,v;
		cin >> u >> v;
		if(u>v) swap(u,v);
		out-=u*(n+1-v);
	}
	cout << out;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	for(int c=1;c<=T;c++){
		solve();
	}
}


Measured memory_bytes: 3648
#include <vector> // vectorを使うためにインクルードする
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
	vector<int> vc; // <T>でT型のvector
	int n;
	cin >> n;
	while(n--) {
		int x;
		cin >> x;
		vc.push_back(x);
	}
	int ans=10000;
	for(int i=0; i<vc.size(); i++){
		int sum1 = 0, sum2 = 0;
		for(int j=0; j<i; j++) sum1 = sum1+vc[j];
		for(int j=i; j<vc.size(); j++) sum2 = sum2+vc[j];
		int diff = sum1-sum2;
		if(diff<0) diff = -diff;
		ans = min(diff, ans);


	}

	cout << ans << '\n';
}


Measured memory_bytes: 256
s = input()
ans = "Yes"
if len(s) & 1:
    ans = "No"
else:
    for i in range(0, len(s), 2):
        if s[i] != "h":
            ans = "No"
            break
    for i in range(1, len(s), 2):
        if s[i] != "i":
            ans = "No"
            break
print(ans)

Measured memory_bytes: 3060