akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

typedef long long LL;
typedef long double LD;

struct DATA{
  LL b;
  LL c;
  bool operator< (const DATA& bc2) const{
    return c < bc2.c;
  }
  bool operator> (const DATA& bc2) const{
    return c > bc2.c;
  }
};


int main()
{
  LL N;
  cin >> N;
  LL M;
  cin >> M;
  priority_queue<LL, vector<LL>, greater<LL>> A;
  for (LL n = 1; n <= N; ++n) {
    LL a;
    cin >> a;
    A.push(a);
  }

  priority_queue<DATA, vector<DATA>, less<DATA>> BC;

  for (LL m = 1; m <= M; ++m) {
    LL B;
    LL C;
    cin >> B >> C;
    DATA data;
    data.b = B;
    data.c = C;
    BC.push(data);
  }

  while (!BC.empty()) {
    LL B = BC.top().b;
    LL C = BC.top().c;
    //cerr << BC.top().b << " : " << BC.top().c << endl;
    BC.pop();
    for (LL b = 0; b < B; ++b) {
      if (A.top() < C) {
        //cerr << A.top() << " : " << C << endl;
        A.pop();
        A.push(C);
      }
      else {
        break;
      }
    }
  }
  LL total = 0;
  while (!A.empty()) {
    total += A.top();
    A.pop();
  }
  cout << total;
  
  
  return 0;
}



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

int main() {

	int K,X;
	cin >> K >> X;
	
  	int M = K * 500;
  
  	if(M >= X){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
  	

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

def main():
    N, K = map(int, input().split())

    p = 0
    for i in range(1, N + 1):
        a = K / i
        b = 1
        while b < a:
            b *= 2
        p += (1 / N) * (1 / b)
    print(p)


if __name__ == '__main__':
    main()


Measured memory_bytes: 77296
#include <iostream>
#include <math.h>

using namespace std;
typedef long long ll;

int main()
{

	ll A, B, C;
	cin >> A >> B >> C;

	if(A+B-C>0||abs(A+B-C)<=1){
		cout <<B+C;
	}
	else{
		cout <<(A+B+1)+B;
	}
	/*if(A==0&&B==0&&C>=1){
		cout << 1;
	}
	else if (A + B +1<= C)
	{
		cout << A + B + (C - A - B) + 1;
	}
	else
	{
		cout << B + C;
	}*/

	return 0;
}


Measured memory_bytes: 256
n = int(input())
H = list(map(int,input().split()))
ans = 0
count = 0
for i in range(n):
  if i == n-1:pass
  elif H[i] >= H[i+1]:
    count += 1
    ans = max(ans,count)
  else:
    count = 0
print(ans)

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc127_d.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M;
  cin >> N >> M;

  vector<int> a(N);
  rep(i, N) { cin >> a[i]; }
  sort(a.begin(), a.end());

  priority_queue<pl, vector<pl>> que;
  rep(i, M) {
    int b, c;
    cin >> b >> c;
    que.push(make_pair(c, b));
  }

  ll ans = 0;
  int r = 0;
  bool ok = true;
  while (!que.empty() && ok) {
    auto top = que.top();
    que.pop();
    ll tgt = top.first;
    ll cnt = top.second;

    int replace = 0;
    repi(i, r, r + cnt) {
      if (a[i] <= tgt) {
        a[i] = tgt;
        replace++;
      } else {
        ok = false;
        break;
      }
    }
    r += replace;
  }

  rep(i, N) { ans += a[i]; }

  cout << ans << endl;
}

Measured memory_bytes: 3700
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() { // 日本語文字列のテスト
    int w = readint;
    int n = readint;

    auto xs = new int[w + 1];
    for (int i = 0; i < xs.length; i++)
        xs[i] = i;

    for (int i = 0; i < n; i++) {
        auto ab = readln.chomp.split(",").to!(int[]);
        int a = ab[0], b = ab[1];
        swap(xs[a], xs[b]);
    }

    foreach (x; xs[1 .. $])
        writeln(x);
}

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

using namespace std;

const int N = 100010;

int a[N];

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n);
	int ans = 0, nowm = 1e9;
	for(int i = 1; i < n; i++)
	{
		if(a[n] % 2 == 0)
		{
			if(abs(a[i] - a[n] / 2) < nowm)
			{
				nowm = abs(a[i] - a[n] / 2);
				ans = a[i];
			}
		}
		else
		{
			if(abs(a[i] - a[n] / 2) < nowm)
			{
				nowm = abs(a[i] - a[n] / 2);
				ans = a[i];
			}
			if(abs(a[i] - (a[n] / 2 + 1)) < nowm)
			{
				nowm = abs(a[i] - (a[n] / 2 + 1));
				ans = a[i];
			}
		}
	}
	printf("%d %d\n", a[n], ans);
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var H = int.Parse(ss[0]);
            var W = int.Parse(ss[1]);

            var a = new char[H, W];
            for (int i = 0; i < H; i++)
            {
                var s = Console.ReadLine();
                for (int j = 0; j < W; j++)
                {
                    a[i, j] = s[j];
                }
            }

            var row = new bool[H];
            var col = new bool[W];
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (a[i, j] == '#')
                    {
                        row[i] = true;
                        break;
                    }
                }
            }

            for (int i = 0; i < W; i++)
            {
                for (int j = 0; j < H; j++)
                {
                    if (a[j, i] == '#')
                    {
                        col[i] = true;
                        break;
                    }
                }
            }

            for (int i = 0; i < H; i++)
            {
                if (!row[i]) continue;
                for (int j = 0; j < W; j++)
                {
                    if (col[j])
                        Console.Write(a[i, j]);
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 11092
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]

ans = sum(A)

DP = [0] * (10**5 + 1)

for i in range(N):
    DP[A[i]] += 1

for i in range(Q):
    DP[C[i]] += DP[B[i]]
    ans += DP[B[i]] * (C[i]-B[i])
    DP[B[i]] = 0
    print(ans)

Measured memory_bytes: 67004
using System;
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main()
    {
        var N = NextInt();
        var L = NextInt();
        var S = new string[] { };

        for (var i = 0; i < N; i++)
        {
            Array.Resize(ref S, S.Length + 1);
            S[S.Length - 1] = ReadLine();
        }
        Array.Sort(S);
        WriteLine(string.Join("", S));
    }

    static int NextInt()
    {
        return int.Parse(NextString());
    }

    static string NextString()
    {
        var result = new List<char>();
        while (true)
        {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}


Measured memory_bytes: 13268
A=[[0 for ia in range(10)]for iaa in range(3)]
B=[[0 for ib in range(10)]for ibb in range(3)]
C=[[0 for ic in range(10)]for icc in range(3)]
D=[[0 for id in range(10)]for idd in range(3)]
num=int(input())
for i in range(num):
	a=input().split()
	if int(a[0])==1:
		A[int(a[1])-1][int(a[2])-1]+=int(a[3])
	elif int(a[0])==2:
		B[int(a[1])-1][int(a[2])-1]+=int(a[3])
	elif int(a[0])==3:
		C[int(a[1])-1][int(a[2])-1]+=int(a[3])
	elif int(a[0])==4:
		D[int(a[1])-1][int(a[2])-1]+=int(a[3])
	else:
		pass
for ja in range(3):
	for ka in range(10):
		print(' ',end='')
		print((A[ja][ka]),end='')
	print() 
print('####################')
for jb in range(3):
	for kb in range(10):
		print(' ',end='')
		print((B[jb][kb]),end='')
	print()
print('####################')
for jc in range(3):
	for kc in range(10):
		print(' ',end='')
		print((C[jc][kc]),end='')
	print()
print('####################')
for jd in range(3):
	for kd in range(10):
		print(' ',end='')
		print((D[jd][kd]),end='')
	print()


Measured memory_bytes: 5640
def main():
    from sys import stdin
    n = int(stdin.readline().rstrip())
    s = list(map(int,list(stdin.readline().rstrip())))
    ans=0
    g = set(list(range(10))) - set(s)
    for i in range(1000):
        tap = (i//100,(i//10)%10,i%10)
        if set(tap) & g == set({}):
            flag = 0
            for p in s:
                if flag == 0:
                    if p==tap[0]:
                        flag = 1
                elif flag == 1:
                    if p==tap[1]:
                        flag = 2
                elif flag == 2:
                    if p==tap[2]:
                        flag = 0
                        ans+=1
                        break
        else:
            continue

    
    print(ans)
main()

Measured memory_bytes: 3572
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
#define rep(i, a, b) for (long long(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug LINE:" <<__LINE__<<"  "<< #i <<":"<< i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

using ll = long long;
using P = std::pair<ll, ll>;
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

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

  ll n,m;
  std::cin>>n>>m;

  std::vector<std::vector<ll>> graph(n),graph_inv(n);
  rep(i,0,m){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    graph[a].push_back(b);
    graph_inv[b].push_back(a);
  }

  ll min=MOD;
  ll itr=-1;

  rep(i,0,n){
    std::vector<ll> d(n,MOD);
    std::queue<ll> que;
    for(ll to:graph[i]){
      d[to]=1;
      que.push(to);
    }

    while(!que.empty()){
      ll now=que.front();que.pop();

      if(now==i)break;

      for(ll to:graph[now]){
        if(chmin(d[to],d[now]+1)){
          que.push(to);
        }
      }
    }

    if(chmin(min,d[i]))itr=i;
  }

  if(min==MOD){
    std::cout<<-1<<"\n";
    return 0;
  }

  std::cout<<min<<"\n";

  std::vector<ll> d(n,MOD);
  std::queue<ll> que;

  for(ll to:graph[itr]){
    d[to]=1;
    que.push(to);
  }

  while(!que.empty()){
    ll now=que.front();que.pop();

    if(now==itr)break;

    for(ll to:graph[now]){
      if(chmin(d[to],d[now]+1)){
        que.push(to);
      }
    }
  }

  std::cout<<itr+1<<"\n";

  ll now=itr;min--;
  while(min>0){
    for(ll from:graph_inv[now]){
      if(d[from]==min){
        std::cout<<from+1<<"\n";
        min--;
        now=from;
        break;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 384
N,K = map(int, input().split())

"""
ノード１にノード２からNまでをつなぐ時が、距離２の組を最大にできるつなぎ方（のはず）で、nCk(N-1, 2)組できる。
あとはKがひとつ減るごとに、２～Nの間に辺を追加位していけばよいか

"""
if (N-1)*(N-2)//2 < K:
    print(-1)
    exit()


print(N-1 + ((N-1)*(N-2)//2 - K))
for i in range(2, N+1):
    print(1, i)

cnt = N-1
for i in range(2, N+1):
    for j in range(i+1, N+1):
        if cnt >= N-1 + ((N-1)*(N-2)//2 - K):
            exit()
        print(i,j)
        cnt += 1

Measured memory_bytes: 42864
/*author : Yashvardhan
Saturday, May 02, 2020
5:43 PM
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

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

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int x;
	cin >> x;

	double p = 100;
	for(int i = 1; i <= 3760; i++){
		double nxt = floor(0.01 * p);
		p += nxt;
		if(p >= x){
			cout << i << endl;
			return 0;
		}
	}
	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 3652
#include<stdio.h>

int calc(int N){
    int ret;
    if(N<100){
        ret = N;
    }else{
        ret = 101;
    }
    return ret;
}

int main(void){
    int D,N;
    scanf("%d %d",&D,&N);
    N = calc(N);
    if(D==0){
        printf("%d",N);
    }else if(D==1){
        printf("%d",N*100);
    }else if(D==2){
        printf("%d",N*10000);
    }else{
        printf("ERROR");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int>so;
  vector<bool>un(N + 1, true);
  const long long mo = 1e9 + 7;
  for (int i = 2; i <= N; i ++) {
    if (un[i]) {
      so.push_back(i);
      for (int j = 0; j <= N / i; j ++) {
        un[i * j] = false;
      }
    }
  }
  long long ans = 1;
  int si = (int)so.size();
  for (int i = 0; i < si; i ++) {
    int n = N;
    long long kj = 0;
    while (n) {
      kj += (long long) n / so[i];
      n /= so[i];
      kj %= mo;
    }
    ans *= kj + 1;
    ans %= mo;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;

void solve()
{   
    ll h,n,sum =0;
    cin>>h>>n;
    vl a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    if(h > sum)
        cout<<"No";
    else cout<<"Yes";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define YES cout<<"YES"<<endl
#define all(v) v.begin(),v.end()
#define NO cout<<"NO"<<endl
#define pb(x) emplace_back(x)
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define mi map<ll,ll>
#define pi pair<ll,ll>
#define what(x) cout<<#x<<" ="<<x<<endl;
using namespace std;
using ll =long long;

ll dp[100005][2];
vi w(100005),val(100005);
ll n,cnt=0;



int main()
{
    fastio;
        memset(dp,0,sizeof dp);
        ll W;
        cin>>n>>W;


        fr(i,0,n)cin>>w[i]>>val[i];



       fr(i,0,n)
       {
           fr(j,0,W+1)
           {
               if(i%2==0)
               {
                   if(j-w[i]>=0)  dp[j][1]=max(dp[j][0],val[i]+dp[j-w[i]][0]);
                   else dp[j][1]=dp[j][0];
               }
               else
               {
                   if(j-w[i]>=0) dp[j][0]=max(dp[j][1],val[i]+dp[j-w[i]][1]);
                   else dp[j][0]=dp[j][1];
               }
           }
       }


       ll ans=max(dp[W][0],dp[W][1]);

       cout<<ans<<endl;








}




























Measured memory_bytes: 6316
class Dice():

    patterns = {"N":[1,5,2,3,0,4],"S":[4,0,2,3,5,1],"W":[2,1,5,0,4,3],"E":[3,1,0,5,4,2]}

    def __init__(self):
        self.number = [i for i in range(6)]

    #0->上、1->正面、2->右面、3->左面、4->裏面、5->下面
    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5

    def roll(self,command,int):
        for i in command:
            self.number = [self.number[j] for j in self.patterns[i]]
        return self.number[int]


dice = Dice()

###d1を基準として、d2の目を合わせる
d1 = list(map(int,input().split()))
d2 = list(map(int,input().split()))

dice.setNumber(d2[0],d2[1],d2[2],d2[3],d2[4],d2[5])

command1 = ["S","S","S","S","E","E","E"] #topを一致させるための回転
command2 = ["S","E","N","S","E","N","S","E","N","S","E","N"] #frontを一致させるための回転

chk = False
for i in command1:
    if d1[0] == dice.roll(i,0):
        for j in command2:
            if d1[1] == dice.roll(j,1):
                if d1[2] == dice.number[2] and d1[3] == dice.number[3] and d1[4] == dice.number[4] and d1[5] == dice.number[5]:
                    chk = True
                else:chk = False
            else:continue
    else:continue

if chk == True:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5620
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long llint;

llint n;
llint a[10005];



void solve(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	llint ans=0;
	for(int i=0;i<n;i++){
		while(a[i]%2==0){
			a[i]/=2;
			ans++;
		}
	}
	cout << ans << endl;

}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

int main() {
  string s, t; cin >> s >> t;
  int sn = s.size(), tn = t.size();
  vector<vector<int>> dp(sn + 1, vector<int>(tn + 1));

  rep(i, sn) rep(j, tn) {
    if (s[i] == t[j]) {
      dp[i + 1][j + 1] = dp[i][j] + 1;
    }
    else {
      dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
    }
  }

  string ans;

  int i = sn, j = tn, now = dp[sn][tn];
  while (i * j > 0)
  {
    if (dp[i - 1][j] == now) i--;
    else if (dp[i][j - 1] == now) j--;
    else {
      i--; j--; now--;
      ans.push_back(s[i]);
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}

Measured memory_bytes: 35584
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <map>
#include <set>
#include <queue>

#define LL long long

using namespace std;

const int MOD = 1000000007, N = 100000+10;

int n, a[N];
LL sum[N];

void gg()
{
	puts("No");
	exit(0);
}

int main()
{
	//freopen("test_in.txt", "r", stdin);
	//freopen("test_out.txt", "w", stdout);
	int a, b; scanf("%d%d\n", &a, &b);
	while(a--)
	{
		char x = getchar();
		if(x > '9' || x < '0')
			gg(); 
	}
	if(getchar()!='-')	gg();
	while(b--)
	{
		char x = getchar();
		if(x > '9' || x < '0')
			gg(); 
	}
	if(getchar()!='\n')
		gg();
	puts("Yes");
}


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

#define ll long long int 
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i)) 
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'



#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main()
{
	_fastio
	db a,b,h,m,x,c;
	cin>>a>>b>>h>>m;
	x=(abs((60.0*h)-(11.0*m)))/2.0;
	c=(a*a)+(b*b)-(2.0*a*b*cos((x*pi)/180.0));
	c=sqrt(c);

	cout<<setprecision(20)<<fixed<<c<<en;
}

Measured memory_bytes: 4208
#include <iostream>
#include <map>
#include <vector>

const int64_t INF = 5e18;

int32_t a, b, c, d;
std::map< int64_t, int64_t > dp;

int64_t calc_dp(int64_t x) {
	if(x == 1) {
		return d;
	}
	else if(dp.count(x) != 0) {
		return dp[x];
	}

	dp[x] = INF;

	if(x < INF / d) {
		dp[x] = x * d;	
	}

	std::vector< int32_t > mults = { 2, 3, 5 };
	std::vector< int32_t > costs = { a, b, c };

	for(int32_t i = 0; i < 3; i++) {
		int32_t mult = mults[i];
		int32_t cost = costs[i];

		if(x % mult == 0) {
			dp[x] = std::min(dp[x], calc_dp(x / mult) + cost);
		}
		else {
			int64_t down = x / mult * mult;
			dp[x] = std::min(dp[x], calc_dp(down / mult) + cost + (x - down) * d);
			int64_t up = down + mult;
			dp[x] = std::min(dp[x], calc_dp(up / mult) + cost + (up - x) * d);
		}
	}

	return dp[x];
}

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

	int32_t t;
	std::cin >> t;

	while(t--) {
		int64_t n;
		std::cin >> n >> a >> b >> c >> d;

		std::cout << calc_dp(n) << '\n';

		dp.clear();
	}
}


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

using namespace std;

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

  char a, b;
  cin >> a >> b;
  if (a == b) {
    cout << "H\n";
  } else {
    cout << "D\n";
  }
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	for i := 0; i < 5; i++ {
		if intScanner() == 0 {
			fmt.Println(i + 1)
		}
	}
}


Measured memory_bytes: 1756
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)
using namespace std;

class point{
	public:
		int x;
		int y;
		point(int x = 0, int y = 0):x(x), y(y){}
		void setPos(int dir){
			switch(dir){
			case 0:
				x -= 1;
				break;
			case 1:
				y -= 1;
				break;
			case 2:
				x += 1;
				break;
			case 3:
				y += 1;
				break;
			default:
				break;
			}
		}

};


int main(){
	int n = 0;
	while(cin >> n && n != 0){
		if(n == 1){
			cout << 1 << " " << 1 << endl;
			continue;
		}
		
		vector<point> box;
		int m = 0, dir = 0;
		
		for(int i = 0; i < n; i++){
			if(!i){
				point a;
				box.push_back(a);
				continue;
			}
			cin >> m >> dir;
			point a(box[m].x, box[m].y);
			a.setPos(dir);
			box.push_back(a);
		}

		int maxX = 0, minX = 0, maxY = 0, minY = 0;
		for(int i = 0; i < box.size(); i++){
			if(maxX < box[i].x) maxX = box[i].x;
			if(minX > box[i].x) minX = box[i].x;
			if(maxY < box[i].y) maxY = box[i].y;
			if(minY > box[i].y) minY = box[i].y;
		}

		cout << maxX - minX + 1 << " " << maxY - minY + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
import java.util.Scanner;

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

		int n = sc.nextInt();

		if (n <= 0 || n > 100) {
			System.out.print("数値の有効範囲は0 <= n <= 100です");
			System.exit(0);
		}
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] < 0 || a[i] >= 1000) {
				System.out.print("数値の有効範囲は0 <= a[i] < 1000です");
				System.exit(0);
			}
		}

		for (int i = n - 1; i >= 0; i--) {
			if (i == 0) {
				System.out.println(a[i]);
			} else {
				System.out.print(a[i] + " ");
			}
		}
	}

}



Measured memory_bytes: 26376
import math
n, d = list(map(int,input().split()))
x = []
y = []
for i in range(n):
    xi, yi = list(map(int,input().split()))
    x.append(xi)
    y.append(yi)

cnt = 0
for xi, yi in zip(x, y):
    di = math.sqrt(xi ** 2 + yi ** 2)
    if di <= d: cnt += 1
  
print(cnt)

Measured memory_bytes: 24936
#include<iostream>
#include<string>
using namespace std;
int main(){
 string s;
 cin>>s;

 for(int i=0;i<s.size();i+=2){
  cout<<s[i];
 // if(i==s.size()-1||i==s.size()-2){
   //cout<<s[i]<<endl;
  //}
 }
}

Measured memory_bytes: 512
N, X = map(int, input().split())
a, p = [1], [1]
for i in range(N):
    a.append(a[i]*2 + 3)
    p.append(p[i]*2 + 1)
def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])
print(f(N, X))

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

vector<int> G[200005];
int ans[200005];


void dfs(int v, int p=-1){
    for(auto s:G[v]){
        if(s==p) continue;
        ans[s]+=ans[v];
        dfs(s,v);
    }
}

int main(){
    int n,q;
    cin >> n >> q;
    
    rep(i,n-1){
        int aa,bb;
        cin >> aa >> bb;
        aa--;
        bb--;
        G[aa].push_back(bb);
        G[bb].push_back(aa);
    }
    
    memset(ans,0,sizeof(ans));

    rep(i,q){
        int p,x;
        cin >> p >> x;
        p--;
        ans[p]+=x;
    }
    dfs(0);

    

    rep(i,n){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 23424
#! /usr/bin/python
# -*- coding: utf-8 -*-

(n, m) = map(int, raw_input().split())
while n!=0:
    Sum = 0
    pd = []
    for i in range(n):
        (d, p) = (map(int, raw_input().split()))
        Sum += d*p
        pd.append([p, d])
    pd.sort(reverse=True)
    red = 0
    for i in range(n):
        if m >= pd[i][1]:
            m -= pd[i][1]
            red += pd[i][0]*pd[i][1]
        else:
            red += m*pd[i][0]
            break
    print Sum-red

    (n, m) = map(int, raw_input().split())

Measured memory_bytes: 5952
x= []
for i in range(5):
    x.append(int(input()))

k = int(input())

ans = 0
for i in range(4):
    for j in range(i+1,5):
        if abs(x[i] - x[j]) > k:
            ans = 1

if ans == 0:
    print("Yay!")
else:
    print(":(")

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

int main() {
	int a,b,c,x;
	cin >> a;
	cin >> b;
	cin >> c;
	if (a > b){
		x = a;
		a = b;
		b = x;
	}
	if (b > c){
		x = b;
		b = c;
		c = x;
	}
	if (a > b){
		x = a;
		a = b;
		b = x;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}


Measured memory_bytes: 3076
N, K = map(int, input().split())

if K == 0:
    print(N**2)
    quit()
    
ans = 0
for b in range(1, N+1):
    p = N // b
    r = N % b
    ans += p * max(0, b-K) + max(0, r-K+1)

print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

int N;
int a[101010];

int main() {
  cin >> N;
  repe(i, 1, N) { cin >> a[i]; }

  int cnt = 0;
  int cur = 1;
  while (cur != 2) {
    cur = a[cur];
    ++cnt;

    if (cnt > N) {
      cout << -1;
      return 0;
    }
  }

  cout << cnt << endl;
}


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

int main(){
  int n,i;
  cin>>n;
  if(n<=9){
    cout<<n;
  }else if(n<=99){
    cout<<9;
  }else if(n<=999){
    cout<<9+n-99;
  }else if(n<=9999){
    cout<<909;
  }else if(n<=99999){
    cout<<909+n-9999;
  }else{
    cout<<90909;
  }
}
  

Measured memory_bytes: 256
while True:
    x = input()
    list = x.split()
    [m, f, r] = list
    m = int(m)
    f = int(f)
    r = int(r)
    mf = m + f
    mfr = m + f + r
    
    #終了条件を記載
    if mfr ==  -3:
        break
    
    ####ここから成績ごとの区分け。
    
    #まずどんなに点が良くても欠席したらF判定
    if m == -1 or f == -1:
        ans = "F"
    
    ##ここからは両方受けた人
    #80以上でA
    elif mf >= 80:
        ans = "A"
    
    #65以上でB
    elif mf >= 65:
        ans = "B"
    
    #50以上でC
    elif mf >= 50:
        ans = "C"
    
    #30未満でF
    elif mf < 30:
        ans = "F"
    
    #30以上で追試50以上でC
    elif mf >= 30 and r >= 50:
        ans = "C"
    
    #30以上で追試50未満でD
    elif mf >=30 and r < 50:
        ans = "D"
    
    #成績表示
    print(ans)


Measured memory_bytes: 5592
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

//先行順巡回
void preParase(int u){
    if (u == NIL) return;
    printf(" %d", u);
    preParase(T[u].l);
    preParase(T[u].r);
}

//中間順巡回
void inParase(int u){
    if (u == NIL) return;
    inParase(T[u].l);
    printf(" %d", u);
    inParase(T[u].r);
}

//後行順巡回
void postParase(int u){
    if (u == NIL) return;
    postParase(T[u].l);
    postParase(T[u].r);
    printf(" %d", u);
}

int main(){
    int i, v, l, r, root;

    scanf("%d", &n);
    for(i=0; i<n; i++){
        T[i].p = NIL;
    }

    for(i=0; i<n; i++){
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if(l != NIL) T[l].p = v;
        if(r != NIL) T[r].p = v;
    }

    for(i=0; i<n; i++) if(T[i].p == NIL) root = i;

    printf("Preorder\n");
    preParase(root);
    printf("\n");
    printf("Inorder\n");
    inParase(root);
    printf("\n");
    printf("Postorder\n");
    postParase(root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int n;
    cin>>n;
    vc<pair<string,int> > ans;
    ans.push_back(make_pair("a",0));
    for(int i=1;i<n;i++)
    {
        vc<pair<string,int> > nxt;
        for(auto u:ans)
        {
            int mx=u.second;
            for(int j=0;j<=mx+1;j++)
            {
                string cur=u.first+char(j+'a');
                nxt.push_back(make_pair(cur,max(j,mx)));
            }
        }
        ans=nxt;
    }
    //sort(ans.begin(),ans.end());
    for(auto u:ans) cout<<u.first<<'\n';

}

Measured memory_bytes: 10984
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	for (const auto& e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& st) {
	for (const auto& e : st) os << e << " ";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const map<T1, T2>& mp) {
	for (const auto& e : mp) os << e << " ";
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T&& h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head&& h, Tail&&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	Int N, u, v;
	cin >> N >> u >> v;

	u--;
	v--;
	vector<vector<Int>> G(N);

	Int a, b;
	for (Int i = 0; i < N-1; i++) {
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	vector<Int> distu(N, -1);
	vector<Int> distv(N, -1);
	queue<Int> queu;
	queue<Int> quev;

	distu[u] = 0;
	queu.push(u);
	while (!queu.empty()) {
		Int temp = queu.front();
		queu.pop();


		for (const auto& nv : G[temp]) {
			if (distu[nv]!=-1) {
				continue;
			}

			distu[nv] = distu[temp] + 1;
			queu.push(nv);
		}
	}
	

	distv[v] = 0;
	quev.push(v);
	while (!quev.empty()) {
		Int temp = quev.front();
		quev.pop();


		for (const auto& nv : G[temp]) {
			if (distv[nv] != -1) {
				continue;
			}

			distv[nv] = distv[temp] + 1;
			quev.push(nv);
		}
	}

	DMP(distu, distv);

	Int ans = 0;
	for (Int i = 0; i < N; i++) {
		if (distu[i]>=distv[i]) {
			continue;
		}
		if (G[i].size()!=1) {//端じゃない
			continue;
		}

		ans = max(ans, distu[i] + (distv[i] - distu[i] - 1));
	}
	cout << ans << "\n";
}


Measured memory_bytes: 8064
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())

int n;
string s;
int toE[300010];
int toW[300010];

void init() {

}

void input() {
	cin >> n >> s;
}

void solve() {
	int cnt = 0;
	REP(i, n) {
		toE[i] = cnt;
		if (s[i] == 'W'){
			cnt++;
		}
	}
	cnt = 0;
	for (int i = n-1; i >= 0; i--) {
		toW[i] = cnt;
		if (s[i] == 'E') {
			cnt++;
		}
	}
	int res = 1<<29;
	REP(i, n) {
		chmin(res, toE[i]+toW[i]);
	}
	cout << res << endl;
}

int main() {
	init();
	input();
	solve();
	return 0;
}


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

bool even(int n){
  return (n%2 == 0);
}

int main() {
  int a, b;
  cin >> a >> b;
  if (even(a)||even(b)){
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}


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

int main(){
	int x1, y1, x2, y2, x3, y3, x4, y4;
	cin >> x1 >> y1 >> x2 >> y2;
	x3 = x2 - (y2-y1);
	y3 = y2 + (x2-x1);
	x4 = x3 - (y3-y2);
	y4 = y3 + (x3-x2);
	printf("%d %d %d %d\n", x3, y3, x4, y4);
}

Measured memory_bytes: 256
while True:
  H,W = map(int, input().split())
  if H == 0 and W == 0:
    break
  for i in range(H):
    for j in range(W):
      if(i+j)%2 == 0:
        print('#',end="")
      else:
        print('.',end="")
    print()
  print()


Measured memory_bytes: 7008
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
typedef pair<int,int> P;
typedef pair<int,P> PP;

signed main(){
  int n;
  cin>>n;
  int c[22],v[22];
  for(int i=0;i<n;i++)cin>>c[i];
  for(int i=0;i<n;i++)cin>>v[i];
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=max(0LL,c[i]-v[i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;

int main() {
    int n; cin >> n;
    int a[n]; rep(i, n) cin >> a[i];
    ll sum = 0, befsum = 0;
    ll ans = 0;
    rep(i, n) {
        sum += a[i];
        if (sum == 0) {
            ans += 1;
            if (befsum > 0) sum = -1;
            else sum = 1;
        } else if (sum * befsum > 0) {
            if (sum > 0) {ans += sum + 1; sum = -1;}
            else {ans += -sum + 1; sum = 1;}
        }
        befsum = sum;
        
    }
    ll tmp = abs(a[0]) + 1;
    if (a[0] >= 0) {sum = -1; befsum = -1;}
    else {sum = 1; befsum = 1;}
    rrep(i, 1, n) {
        sum += a[i];
        if (sum == 0) {
            tmp += 1;
            if (befsum > 0) sum = -1;
            else sum = 1;
        } else if (sum * befsum > 0) {
            if (sum > 0) {tmp += sum + 1; sum = -1;}
            else if (sum < 0) {tmp += -sum + 1; sum = 1;}
        }
        befsum = sum;
    }
    ans = min(ans, tmp);
    cout << ans << endl;
}




Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] f = new int[m + 1];
            for (int i = 0; i < n; i++) {
                int k = in.nextInt();
                for (int j = 0; j < k; j++) {
                    f[in.nextInt()]++;
                }
            }
            int count = 0;
            for (int i = 1; i <= m; i++)
                if (f[i] == n)
                    count++;
            out.println(count);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            int n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



Measured memory_bytes: 23380
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc161
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = int.Parse(Console.ReadLine());
            var ans = r * 2 * 3.14;
            Console.WriteLine(ans);
           

        }
    }
}


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

#define pi 3.1416
int main()
{

    int a,b ,c, d;
    double r,p;
    cin>>r;

    p=pi*r*2;

    cout<<fixed<<setprecision(5) <<p << '\n';
     return 0;
}


Measured memory_bytes: 3728
#![allow(dead_code)]
#![allow(unused)]
use proconio::input;

mod union_find {
    pub struct UnionFind { pub(self) list: Vec<i32> }
    impl UnionFind {
        pub fn new(size: usize) -> UnionFind { UnionFind{ list: vec![-1; size] } }
        pub fn root(&self, n: usize) -> usize { if self.list[n] < 0 { n } else { self.root(self.list[n] as usize) } }
        pub fn size_at(&self, n: usize) -> i32 { std::cmp::max(0, -self.list[n]) }
        pub fn unite(&mut self, x: usize, y: usize) {
             let (mut x_root, mut y_root) = (self.root(x), self.root(y));
              if(x_root == y_root) { return; } 
              if(self.list[x_root] > self.list[y_root]) { std::mem::swap(&mut x_root, &mut y_root); } 
              self.list[x_root] += self.list[y_root]; 
              self.list[y_root] = x_root as i32; }
        pub fn are_in_same_tree(self, x: usize, y: usize) -> bool { self.root(x) == self.root(y) }  
    }
}

fn main() {
    input!{n: usize, m: usize, ab: [[usize; 2]; m]}
    let mut uf = union_find::UnionFind::new(n);
    for item in ab {
        uf.unite(item[0] - 1, item[1] - 1);
    }
    let mut max = 0;
    for i in 0..n {
        max = std::cmp::max(max, uf.size_at(i));
    }
    println!("{}", max);
}

Measured memory_bytes: 16308
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


int N;
string s;
int main() {
	cin >> N >> s;
	int ans = 0;
	for (int i = 0; i < N-1; i++) {
		if ((s[i] == 'O' && s[i + 1] == 'X') || (s[i] == 'X' && s[i + 1] == 'O')) {
			ans++;
			i++;
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3328
N,M,K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

asum = A.inject([0]){|a,i| a << a.last + i; a}
bsum = B.inject([0]){|a,i| a << a.last + i; a}
maxacount = asum.find_index{|x| x > K} - 1 rescue N
ans = 0
bcount = 0

maxacount.downto(0).each do |acount|
  loop do
    break if bcount > M || asum[acount] + bsum[bcount] > K
    bcount += 1
  end
  bcount -= 1
  ans = [ans, acount + bcount].max
end

puts ans

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

int main(){
  int l;
  cin >> l;
  double const e = 1E-6;
  //  cout << e << endl;
  
  double a,b,c;
  a = ((double) l)/3.0;
  b = ((double) l)/3.0;
  c = ((double) l)/3.0;
  printf("%16.10lf\n",a*b*c);
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[5][4][11]={0};
int b,f,r,v;
for(int i=0;i<n;i++)
{
cin>>b>>f>>r>>v;
a[b][f][r]+=v;
}
for(int i=1;i<=4;i++)
{
for(int j=1;j<=3;j++)
{
for(int k=1;k<=10;k++)
{
cout<<" "<<a[i][j][k];
}
cout<<endl;
}
if(i!=4)cout<<"####################"<<endl;
}
return 0;
}

Measured memory_bytes: 3064