akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
l = [0]
for i in range(N):
  l.append(l[-1]+A[i])
  
c = Counter(l)
ans = 0
for n in c.values():
  ans += n*(n-1)//2
print(ans)

Measured memory_bytes: 44212
N = int(input())
A = [0] + [int(input()) for _ in range(N)]

x = 1
visited = set([1])
answer = 0

while True:
  x = A[x]
  if x in visited:
    answer = -1
    break
  visited.add(x)
  answer += 1
  if x == 2:
    break
    
print(answer)

Measured memory_bytes: 13724
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;


int main(){
    int N, M;
    cin >> N >> M;
    vector<ll> H(N);
    for(int i=0; i<N; i++){
        cin >> H[i];
    }
    vector<vector<int>> R(N);
    for(int i=0; i<M; i++){
        int A, B;
        cin >> A >> B;
        R[A-1].push_back(B-1);
        R[B-1].push_back(A-1);
    }
//    for(int i=0; i<N; i++){
//        for(int l=0; l<R[i].size(); l++){
//            cout << R[i][l];
//        }
//        cout << endl;
//    }
    int count = 0;
    for(int i=0; i<N; i++){
        bool flag = true;
        for(int l=0; l<R[i].size(); l++){
            if(H[i] <= H[R[i][l]]) flag = false;
        }
        if(flag) count++;
    }
    cout << count;
}

Measured memory_bytes: 9064
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int c[26],d[26];
int main(){
    while(true){
    int n,f,a=114514;
    char z;
    cin>>n;
    if(!n)break;
    f=n;
    rep(i,26)c[i]=0;
    while(true){
        n--;
        cin>>z;
        c[z-'A']++;
        rep(i,26)d[i]=c[i];
        sort(d,d+26);
        if(d[25]>n+d[24])a=min(a,f-n);
        if(!n)break;
    }
    n=0;
    rep(i,26){
        if(c[i]==n)f=114514;
        if(c[i]>n)n=c[i],f=i;
    }
    z=f+'A';
    if(f==114514)cout<<"TIE"<<endl;
    else cout<<z<<" "<<a<<endl;
    }
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int n=s.length();
    for(int i=0;i<n/2+1;i++){
        if(s[i] != s[n-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=0;i<(n-1)/2;i++){
        if(s[i]!=s[(n-1)/2-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=(n+3)/2,j=1;i<n+1;i++,j++){
        if(s[i-1]!=s[n-j]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll mx=0;
    for(ll i=0;i<n;i++)
    {
        ll tmp=a[i];
        ll cnt=0;
   // cout<<"i="<<i<<" ";
        while(i<n&&a[i]>=a[i+1])
        {
            cnt++;
            i++;
        }
       // cout<<i<<" "<<cnt<<endl;
        //cnt--;
        mx=max(mx,cnt);
    }
    if(mx==0)
        cout<<0<<endl;
    else
    cout<<mx<<endl;
}


Measured memory_bytes: 1024
def iin(): return int(input())
def nl(): return list(map(int, input().split()))

n = iin()
ss = [input() for _ in range(n)]
t = input()

i_min = n + 1
i_max = 1
for s in ss:
    if t >= s.replace('?', 'a'):#これとの比較が最後
        i_max += 1
    if t <= s.replace('?', 'z'):#これとの比較が最前
        i_min -= 1
ans = range(i_min, i_max + 1)
print(*ans)

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#define dprintf(...) printf(__VA_ARGS__)
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTI(a,i)
#define dprintf(...)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

template <class T>
vec2<T> vec2_init(int n0, int n1, T x = 0) {
    return vec2<T>(n0, vector<T>(n1, x));
}

template <class T>
vec3<T> vec3_init(int n0, int n1, int n2, T x = 0) {
    return vec3<T>(n0, vec2_init(n1, n2, x));
}

/*
 *           U P
 *           - x
 *            ^
 *            |
 * LEFT -y <--+--> +y RIGHT
 *            |
 *            v
 *           + x
 *         D O W N
 */

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

enum {
    DOWN,
    RIGHT,
    UP,
    LEFT,
};

constexpr double inf = numeric_limits<double>::infinity();

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll result = max({a * c, a * d, b * c, b * d});
    if (result < 0 && (a <= 0 && 0 <= b || c <= 0 && 0 <= d)) {
        amax(result, 0);
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3648
while True:
    m,f,r=map(int,input().split())
    if m==f==r==-1:
        break
    if m==-1 or f==-1 or m+f<30:
        print('F')
    elif m+f>=80:
        print('A')
    elif m+f>=65:
        print('B')
    elif m+f>=50:
        print('C')
    elif m+f>=30 and r>=50:
        print('C')
    else:
        print('D')



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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int a, b, c; cin >> a >> b >> c;
  cout << (1 == ((a == b) + (b == c) + (c == a)) ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>

using namespace std;

int main( void ) {

    int N, L;
    cin >> N >> L;

    vector<string> snake(N);

    for ( int i = 0; i < N; i++ ) {
        cin >> snake.at(i);
    }

    sort(snake.begin(), snake.end());

    for ( int i = 0; i < N; i++ ) {
        cout << snake.at(i);
    }

    cout << endl;

    return 0;
}

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

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

    if (str[2] == str[3] && str[4] == str[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm> 
#include<cstdio>
#include<cctype>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<unordered_map>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int N = 105;
const double pi = acos(-1.0);
const ll mod = 998244353;
void init(){
	ios::sync_with_stdio(false);cin.tie(0);
} 
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
ll a[N];
ll quickpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}

int main()
{
	int n,m;
	cin>>n>>m;
	if(m>=n)cout<<"unsafe";
	else cout<<"safe";
	return 0;
}

Measured memory_bytes: 3624
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N;
	for(int i=N;;i++){
		bool flag=true;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				flag=false;
				break;
			}
		}
		if(flag){
			cout<<i<<endl;
			return 0;
		}
	}
}

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

int main()
{
    int N;
    cin >> N;
    int d10 = N / 10;
    int d1 = N - d10 * 10;
    if (d10 == 9 || d1 == 9)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
    int a,b,x,y,n,max;
    scanf("%d %d",&a,&b);
    n=a+b;
    x=a*b;
    y=a-b;
    max=x>=y?x:y;
    max=max>=n?max:n;
    printf("%d\n",max);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<climits>
#include<algorithm>
using namespace std;
struct mat{
  int w,h;
};
vector<mat> v;
int memo[101][101];

int solve(int l,int r){
  if(memo[l][r] > 0)return memo[l][r];
  //cout << l << ' ' << r << endl;
  if(l == r)return 0;
  int ret = INT_MAX;
  for(int i = l; i < r; i++){
    int ans = solve(l,i) + solve(i+1,r) + v[l].h * v[i].w * v[r].w;
    ret = min(ret,ans);
  }
  return memo[l][r] = ret;
}
int main(){
  fill(*memo,*(memo+101),-1);
  int n;
  cin >> n;
  for(int i = 0;i < n;i++){
    int r,c;
    cin >> r >> c;
    v.push_back({c,r});
  }
  cout << solve(0,n-1) << endl;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	ll n, k;
	cin >> n >> k;
	if(n >= k)
	n %= k;
	cout << min(k - n, n);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define bg begin
namespace IO{
	
cs int RLEN=1<<20|1;
char ibuf[RLEN],*ib,*ob;
inline char gc(){
	(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob)?EOF:*ib++;
}
#define gc getchar
inline int read(){
	char ch=gc();
	int res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
	return f?res:-res;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	return top;
}
inline char readchar(){
	char ch=gc();
	while(isspace(ch))ch=gc();
	return ch;
}

}
using IO::read;
using IO::readstring;
using IO::readchar;
template<typename tp>inline void chemx(tp &a,tp b){a=max(a,b);}
template<typename tp>inline void chemn(tp &a,tp b){a=min(a,b);}
cs int N=128,C=62;
inline bool comp(cs string &a,cs string &b){
	return a.size()<b.size();
}
inline char id(int x){
	if(x<26)return 'a'+x;
	if(x>51)return '0'+(x-52);
	return 'A'+(x-26);
}
inline int query(string x){
	cout<<"? "<<x<<endl;
	return read();
}
int n;
inline bool check(string x){
	return query(x)+x.size()==n;
}
int main(){
	vector<string>tp;
	for(int i=0;i<C;i++){
		string x(N,id(i));
		int vl=N-query(x);
		n+=vl;
		if(vl)tp.pb(string(vl,id(i)));
	}
	while(tp.size()>1){
		sort(tp.bg(),tp.end(),comp);
		string a=tp[0],b=tp[1],res;
		tp.erase(tp.bg(),tp.bg()+2);
		while(a.size()&&b.size()){
			if(check(res+a[0]+b)){
				res+=a[0],a.erase(a.bg());
			}
			else res+=b[0],b.erase(b.bg());
		}
		res+=a,res+=b;
		tp.pb(res);
	}cout<<"! "<<tp[0]<<endl;
}

Measured memory_bytes: 3796
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int N, K;
    cin >> N >> K;
    int i, j;
    long h[100005] = {};
    long dp[100005] = {};
    for(i = 0; i < N; i++){
        cin >> h[i];
    }
    for(i = 1; i <= N; i++){
        dp[i] = 10000000000;
        for(j = 1; j <= K; j++){
            if(i >= j){
                dp[i] = min(dp[i], dp[i - j]+ abs(h[i] - h[i - j]));
            }
        }
    }
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
str1 = input()
str2 = input()
ok = False

if str1.islower() == True and str2.islower() == True:
    if 1 <= len(str1) <= 10:
        if str2[:-1] == str1:
            ok = True

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

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

typedef long long i64;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;

int answer = 1;
int N, M;
int edgeCnt[20][MAXN], dp[MAXN];

inline int loBit(int x)
{
	return x & (-x);
}

inline bool checkContain(int x)
{
	return !(((x & 0x03) != 0) && ((x & 0x03) != 0x03));
}

int main()
{
	cin >> N >> M ;

	for(int i = 1; i <= M; i++)
	{
		int u, v;
		cin >> u >> v, u--, v--;
		edgeCnt[u][1 << v] += 1;
		answer = (2LL * answer) % MOD;
	}

	for(int i = 0; i < N; i++)
		for(int j = 0; j < (1 << N); j++)
			edgeCnt[i][j] = edgeCnt[i][loBit(j)] + edgeCnt[i][j ^ loBit(j)];

	for(int i = 0; i < (1 << N); i++)
	{
		if(!checkContain(i))
			continue;
		dp[i] = 1;

		for(int j = ((i - 1) & i); j > 0; j = ((j - 1) & i))
		{
			if(!checkContain(j))
				continue;

			int tmp = i ^ j;
			i64 val = dp[tmp];

			for(int k = 0; k < N; k++)
			{
				if(tmp & (1 << k))
					val = 1LL * val * ((1 << edgeCnt[k][j]) - 1) % MOD;
				else if(j & (1 << k))
					val = 1LL * val * (1 << edgeCnt[k][tmp]) % MOD;
			}
			dp[i] = (1LL * dp[i] + val) % MOD;
		}
	}
	cout << (answer - dp[(1<<N) - 1] + MOD) % MOD << endl ;
	return 0;
}



Measured memory_bytes: 5120
import sys
n = int(input())
data = []
for i in range(n):
    data.append([ int(i) for i in input().split() ])
for x in range(101):
    for y in range(101):
        h = set()
        le = 1e18
        for pt in data:
            xcx = abs(x-pt[0])
            ycy = abs(y-pt[1])
            if pt[2] > 0:
                h.add(pt[2] + xcx + ycy )
            elif pt[2] == 0:
                le = min( le, xcx + ycy )
        if len(h) == 1:
            for i in h:
                if i <= le:
                    print(x,y,i)
                    sys.exit(0)


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
using ll = long long;
using vi = vector<int>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    ios::sync_with_stdio(false);
    
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int start = max(a, c);
    int end = min(b, d);

    int ans = end - start;
    if(ans <= 0) ans = 0;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{

    int n;
    scanf("%d",&n);
    if(n==25)
        printf("Christmas\n");
    else if(n==24)
        printf("Christmas Eve\n");
    else if(n==23)
        printf("Christmas Eve Eve\n");
    else if(n==22)
        printf("Christmas Eve Eve Eve\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <deque>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int a[6];
	bool flag = true;
	rep(i, 6) cin >> a[i];

	for(int i=0;i<5;i++)
		for (int j = i; j < 5; j++)
			if (a[j] - a[i] > a[5])
				flag = false;

	if (flag) cout << "Yay!" << endl;
	else cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  val c = Math.cos(Math.PI/3)
  val s = Math.sin(Math.PI/3)

  def getPoints(list:Array[(Double,Double)],i:Int):Array[(Double,Double)]  =
    if(i==0) list
    else {
      val b = new ArrayBuffer[(Double,Double)]
      for( k<-0 until list.length-1) {
        val i = list(k); val j = list(k+1)
        val p1 = ((i._1*2+j._1)/3,(i._2*2+j._2)/3)
        val p2 = ((i._1+j._1*2)/3,(i._2+j._2*2)/3)
        val x = (p2._1-p1._1)*c-(p2._2-p1._2)*s+p1._1
        val y = (p2._1-p1._1)*s+(p2._2-p1._2)*c+p1._2
        if(k==0) b+=i
        b+=(p1,(x,y),p2,j)
      }
      getPoints(b.toArray,i-1)
    }

  def main(args:Array[String]) = {
    val n = readInt
    val list = getPoints(Array((0D,0D),(100D,0D)),n)
    for((i,j)<-list) printf("%.8f %.8f\n",i,j)
  }
}

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


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

Measured memory_bytes: 3608
import math

n = int(input())
n -= 1
c = [0 for i in range(n)]
s = [0 for i in range(n)]
f = [0 for i in range(n)]
for i in range(n):
    c[i], s[i], f[i] = [int(i) for i in input().split()]


def nextArriveTime(station, start):
    """
    print("start:{} depart:{} arrive:{}"
          .format(start,
                  s[station] + math.ceil((start - s[station]) / f[station]) * f[station],
                  s[station] + math.ceil((start - s[station]) / f[station]) * f[station] + c[i]))
    """
    # print("kf:{}".format(math.ceil((start - s[station]) / f[station]) * f[station]))
    if start >= s[station]:
        return s[station] \
               + math.ceil((start - s[station]) / f[station]) * f[station] \
               + c[station]
    else:
        return s[station] + c[station]

for i in range(n):
    time = s[i]
    for j in range(i, n):
        time = nextArriveTime(j, time)
        # print("{}->{}:{}".format(j, j+1, nextArriveTime(j, time)))
    print(time)
print(0)


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, M, Q; cin >> N >> M >> Q;
  int m[N][N] = {};
  rep(i, M) { int L, R; cin >> L >> R; L--; R--; m[L][R]++; }
  rep(i, N) for (int j=1; j<N; j++) m[i][j] += m[i][j-1];


  // rep(i, N) { rep(j, N) cout << m[i][j] << " "; cout << endl; }
  rep(i, Q){
    int p, q; cin >> p >> q; p--; q--;
    int result = 0;
    for (int i=p; i<=q; i++) result += m[i][q];
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 1920
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type task struct {
	cost, line int
}
type taskList []task

func (a taskList) Len() int           { return len(a) }
func (a taskList) Less(i, j int) bool { return a[i].line < a[j].line }
func (a taskList) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	L := make(taskList, N)
	for i := 0; i < N; i++ {
		L[i].cost, L[i].line = scanInt(), scanInt()
	}
	sort.Sort(L)

	T := 0
	for _, l := range L {
		T += l.cost
		if T > l.line {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 6272
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M, K;
const int EXPN = 1 << 16;
int d[20], v[110][110];
bool dp[EXPN-1][30];
int dark[110];
int to[EXPN-1][110];
int dist[EXPN-1];
bool visited[EXPN-1];

signed main() {
    memset(dp, false, sizeof(dp));
    memset(dark, -1, sizeof(dark));
    memset(visited, false, sizeof(visited));
    cin >> N >> M >> K;
    rep(i,0,M) {
        cin >> d[i];
        d[i]--;
        // i ???????????????????????????????????? (????????´?????????????????????????????????)
        dark[ d[i] ] = i;
    }
    rep(i,0,N) rep(j,0,K) {
        cin >> v[i][j];
        v[i][j]--;
        // ???????????????????????°??????????????\??????
        if(dark[ v[i][j] ] == -1) v[i][j] = -1;
        else v[i][j] = dark[ v[i][j] ];
    }

    rep(j,0,K) {
        rep(bit,0,1<<M) {
            int nbit = 0;
            rep(i,0,M) {
                if(bit >> i & 1) {
                    if(v[d[i]][j] < 0) continue;
                    int val = 1 << v[d[i]][j];
                    nbit |= val;
                }
            }
            to[bit][j] = nbit;
        }
    }
    
    rep(i,0,1<<M) dist[i] = INF;
    dist[(1<<M)-1] = 0;
    priority_queue< int, vector<int>, greater<int> > q;
    q.push((1<<M)-1);
    while(!q.empty()) {
        int t = q.top(); q.pop();
        rep(i,0,K) {
            int nx = to[t][i];
            if(dist[nx] > dist[t] + 1) {
                dist[nx] = dist[t] + 1;
                q.push(nx);
            }
        }
    }
    cout << dist[0] << endl;
    return 0;
}

Measured memory_bytes: 63744
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int f(int a){
	if(a & 1) return (3 * a + 1);
	else return (a / 2);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int s;
	cin >> s;
	int ind = 1;
	int prev = s;
	map<int, int> mp;
	while(1){
		if(mp.count(prev)){
			cout << ind << endl;
			return 0;
		}
		mp[prev] = 1;
		prev = f(prev);
		ind++;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

typedef int32_t i32;
typedef i32 heap_val;

int cmp_heap_val (const heap_val a, const heap_val b) {
  return a == b ? 0 : a > b ? -1 : 1;
}

typedef struct binaryHeap{
  heap_val *array;
  size_t heap_size;
  size_t max_size;
} heap;

heap* new_binary_heap (void) {
  heap *h = (heap *) calloc (1, sizeof (heap));
  h->array = (heap_val *) malloc (sizeof (heap_val) * (1 + 1));
  h->heap_size = 0;
  h->max_size = 1;
  return h;
}

int32_t get_heap_size (const heap *h) {
  return h->heap_size;
}

int is_empty (const heap *h) {
  return h->heap_size == 0;
}

void free_heap (heap *h) {
  free (h->array);
  free (h);
}

void init_heap (heap *h) {
  h->heap_size = 0;
}

void push (heap *h, const heap_val val) {
  if (h->heap_size == h->max_size) {
    h->max_size = 2 * h->max_size + 1;
    h->array = (heap_val *) realloc (h->array, sizeof (heap_val) * (h->max_size + 1));
  }
  h->heap_size++;
  heap_val *array = h->array;
  size_t k = h->heap_size;
  array[k] = val;
  while(k>1){
    size_t parent = k / 2;
    if (cmp_heap_val (array[parent], array[k]) <= 0) {
      return;
    }
    heap_val swap = array[parent];
    array[parent] = array[k];
    array[k] = swap;
    k = parent;
  }
}

heap_val pop (heap *h) {
  heap_val *array = h->array;
  const heap_val res = array[1];
  array[1] = array[h->heap_size--];
  const size_t n = h->heap_size;
  size_t k = 1;
  while (2 * k  + 1 <= n) {
    int c = cmp_heap_val (array[2 * k], array[2 * k + 1]);
    size_t next = 2 * k + (c <= 0 ? 0 : 1);
    if (cmp_heap_val (array[k], array[next]) <= 0) break;
    heap_val swap = array[k];
    array[k] = array[next];
    array[next] = swap;
    k = next;
  }
  if (2 * k <= n && cmp_heap_val (array[k], array[2 * k]) > 0) {
    heap_val swap = array[2 * k];
    array[2 * k] = array[k];
    array[k] = swap;
  }
  return res;
}

void run (void) {
  heap *h = new_binary_heap ();
  char s[10];
  while (1) {
    scanf ("%s", s);
    if (s[0] == 'i') {
      i32 v;
      scanf ("%" SCNi32, &v);
      push (h, v);
    } else {
      if (s[1] == 'n') break;
      i32 v = pop (h);
      printf ("%" PRIi32 "\n", v);
    }
  }
}

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



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

int main(){
    int N,M;
    cin >> N >> M;
    vector<P> p(M);
    for(int i=0; i<M ; i++){
        cin >> p[i].first >> p[i].second;
    }
    for(int x=0; x<1000 ; x++){
        int keta = 1;
        int nx = x/10;
        vector<int> d(1,x%10);
        while(nx){

            keta++;
            d.push_back(nx%10);
            nx /= 10;
            
        }
        if(keta != N) continue;
        bool ok = true;
        reverse(d.begin(),d.end());
        for(int i=0 ; i < M ; i++){
            if(d[p[i].first -1] != p[i].second) ok = false;
        }
        if(ok) {
            cout << x << endl;
            return 0;
            }
    }

        cout << -1 << endl;
        return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
  
public class Main{
  public static void main(String[] args){
    Scanner stdIn=new Scanner(System.in);
    int W=stdIn.nextInt();
    int H=stdIn.nextInt();
    int x=stdIn.nextInt();
    int y=stdIn.nextInt();
    int r=stdIn.nextInt();
    if (x-r<0||y-r<0||x+r>W||y+r>H){
	System.out.println("No");
    }else{
	System.out.println("Yes");
    }
  }
}



Measured memory_bytes: 26276
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			int x = sc.nextInt();
			if(30<=x) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}




		}catch(Exception e) {
			e.printStackTrace();
		}

	}


}

Measured memory_bytes: 35660
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  string l;
  cin>>l;
  ll n=l.size();
  vector<ll>q;
  ll t=1;
  for(ll i=1;i<n;i++){
    if(l[i]=='0'){
      t++;
    }
    else{
      q.push_back(t);
      t=1;
    }
  }
  q.push_back(t);
  ll ans=1;
  vector<ll>v(q.size()+1,1);//just
  vector<ll>vv(q.size()+1,0);
  for(ll i=0;i<(ll)q.size();i++){
    ll tmp=1;
    for(ll j=1;j<q[i];j++){
      tmp=(tmp*3%MOD);
    }
    v[i+1]=(v[i])*2%MOD;
    vv[i+1]=((v[i]*(tmp)%MOD)+vv[i]*(tmp*3%MOD))%MOD;
  }
  ans=(v[q.size()]+vv[q.size()])%MOD;
  cout<<ans<<endl;
}


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

int main()
{
  int n,sum;
  sum=0;
  cin>>n;
  vector<int> l(n);
  for(int i=0;i<n;i++)
  {
    cin>>l.at(i);
    sum+=l.at(i);
  }
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  if(l.at(0)<sum-l.at(0))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#define FIBO_MAX 1000

int fibonacci(int *F, int n){
  if( n == 0 || n == 1 ) return F[n] = 1;
  if( F[n] != 0 ) return F[n];
  return F[n] = fibonacci(F, n-2) + fibonacci(F, n-1);
}

int main(){
  int n, i, F[FIBO_MAX];
  
  scanf("%d",&n);
  printf("%d\n",fibonacci(F, n) );
  return 0;
}



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

int main() {
	int N;
	string S;
	cin >> N >> S;
	int x = 0, ans = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'I')
			x++;
		else
			x--;
		ans = max(ans, x);
	}
	cout << ans << endl;
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void chmin(int &a, int b){
  if(a > b)
    a = b;
}
void chmax(int &a, int b){
  if(a < b)
    a = b;
}

void llchmin(ll &a, ll b){
  if(a > b)
    a = b;
}
void llchmax(ll &a, ll b){
  if(a < b)
    a = b;
}

int main(){
  int n;
  cin >> n;
  vl a(n);
  ll sum = 0;
  rep(i, 0, n){
    cin >> a[i];
    sum = sum ^ a[i];
  }
  
  rep(i, 0, n){
    cout << (sum^a[i]) << endl;
  }
  
  return 0;
}

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

int main() {
  int H, W, i, j;
//  int sum = 0;
  cin >> H >> W;
  vector<char> table(W);

  for(i = 0; i < W + 1; i++){
    cout << "#";
  }
  cout << "#" << endl;
  
  for(j = 0; j < H; j++){
    cout << "#";
    for(i = 0; i < table.size(); i++){
      cin >> table.at(i);
      cout << table.at(i);
    }
    cout << "#" << endl;
  }
  
  for(i = 0; i < W + 1; i++){
    cout << "#";
  }
  cout << "#" << endl;
}


Measured memory_bytes: 256
program lunlun_number
  implicit none
  integer :: k, l = 9, i, j, m, n = 9, p = 1, q = 2
  integer(8) :: a(2,60000) = 0_8, x, y
  read(*,*) k
  if (k < 10) then
    write(*,'(i0)') k
    stop
  end if
  a(1,1:9) = (/1_8, 2_8, 3_8, 4_8, 5_8, 6_8, 7_8, 8_8, 9_8 /)
  do
    do i = 1, 9
      m = 0
      do j = 1, l
        x = mod(a(p,j),10_8)
        y = a(p,j)*10_8+x
        if (x /= 0_8) then
          m = m+1
          a(q,m) = y-1_8
          n = n+1
          if (n == k) then
            write(*,'(i0)') a(q,m)
            stop
          end if
        end if
        m = m+1
        a(q,m) = y
        n = n+1
        if (n == k) then
          write(*,'(i0)') a(q,m)
          stop
        end if
        if (x /= 9_8) then
          m = m+1
          a(q,m) = y+1_8
          n = n+1
          if (n == k) then
            write(*,'(i0)') a(q,m)
            stop
          end if
        end if
      end do
      p = 3-p
      q = 3-p
      l = m
    end do
  end do
end program lunlun_number

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

int main()
{

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

    int n = 0, w = 0;
    cin >> n >> w;
    
    vector<long long> dp(w + 1, 0);
    long long a = 0, b = 0;

    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        for(int weight_bag = w - a; weight_bag >= 0; weight_bag--) {
            dp[weight_bag + a] = max(dp[weight_bag + a], dp[weight_bag] + b);
        }
    }

    cout << *max_element(dp.begin(), dp.end()) << endl;

    
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
 string S;
 cin>>S;
 if(S=="abc"){
    cout<<"Yes";
 }
 else if(S=="acb"){
    cout<<"Yes";
 }
  else if(S=="bac"){
    cout<<"Yes";
 }
  else if(S=="bca"){
    cout<<"Yes";
 }
  else if(S=="cab"){
    cout<<"Yes";
 }
  else if(S=="cba"){
    cout<<"Yes";
 }
 else cout<<"No";
return 0 ;
}



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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;
    vector<ll> H(N);

    ll maxH = 0;
    REP(i, N){
        cin >> H[i];
        maxH = max(maxH, H[i]);
    }

    ll ans = 0;
    REP(i, maxH){
        bool flag = false;
        REP(j, N){
            if(flag){
                if(H[j] > 0) H[j]--;
                else flag = false;
            }
            else{
                if(H[j] > 0){
                    ans++;
                    H[j]--;
                    flag = true;
                } 
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int dp[100010][13];

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

    dp[0][0] = 1;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '?') {
            rep(k, 10) { // 0 ～ 9 まで試す
                rep(j, 13) {
                    int nextRem = (j * 10 + k) % 13;
                    dp[i + 1][nextRem] += dp[i][j];
                    dp[i + 1][nextRem] %= MOD;
                }
            }
        } else {
            int k = S[i] - '0';
            rep(j, 13) {
                int nextRem = (j * 10 + k) % 13;
                dp[i + 1][nextRem] += dp[i][j];
                dp[i + 1][nextRem] %= MOD;
            }
        }
    }

    cout << dp[S.size()][5] << endl;
}


Measured memory_bytes: 5504
l,r = map(int,input().split())
if r-l >= 2019:
  a = 0
elif l%2019 < r%2019:
  a = 2019 ** 2
  for i in range(l%2019,r%2019):
    for j in range(i+1,r%2019+1):
      a = min(a,i*j%2019)
else:
  a = 0
print(a)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    ll x, y; cin >> x >> y;
    ll ans = 0;
    if(x <= y){
        if(x != y && abs(x) == y) ans = 1;
        else if(x >= 0 && y >= 0){
            ans = y-x;
        }
        else if(x <= 0 && y <= 0){
            ans = y-x;
        }
        else {
            if(abs(x) < y){
                ans = y-abs(x)+1;
            }
            else {
                ans = (-1)*y-x+1;
            }
        }
    } else {
        if(x == 0){
            ans = abs(y)+1;
        }
        else if(y == 0){
            ans = abs(x)+1;
        }
        else if(x > 0 && y > 0){
            ans = y*(-1)-x*(-1)+2;
        }
        else if(x < 0 && y < 0){
            ans = abs(y)-abs(x)+2;
        }
        else {
            if(x <= abs(y)){
                ans = abs(y)-x+1;
            }
            else {
                ans = x-abs(y)+1;
            }
        }
    }
    cout << ans << endl;
}

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

string S;

int main(){
    cin >> S;
    int N = S.size();
    int even = 0,odd = 0;
    for(int i=0;i<N;i++){
        if(i%2==0 && S[i]=='0') even++;
        if(i%2==1 && S[i]=='0') odd++;
    }
    int even_a = (N+1)/2,odd_a = N/2;
    cout << min(even_a-even+odd,odd_a-odd+even) << endl;
}

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

int main()
{
	ios_base::sync_with_stdio(false);	
	cin.tie(NULL);
	long long int a,b,k;
	cin>>a>>b>>k;
	long long int t=k;
	if(a>k)
	a=a-k;
	if(k>=a)
	{
		k=k-a;
		a=0;
		if(b<k)
		{
		b=0;
		}
		else
		b=b-k;
	}
	cout<<a<<" "<<b<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[505][505],n;
void solve(int l,int r,int num){
    if(l==r) return;
    int mid=(l+r)/2;
    for(int i=l;i<=mid;i++){
        for(int j=mid+1;j<=r;j++){
            a[i][j]=num;
        }
    }
    solve(l,mid,num+1);
    solve(mid+1,r,num+1);
}
int main(){
    cin>>n;
    solve(1,n,1);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
#define show(x) cout << #x << " is " << x << "\n";
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

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

	long double x;
	cin>>x;
	int c=0;
	ll ans=100;
	while(ans < x){
		ans*=(1.01);
		c++;
	}
	cout<<c;
	return 0;
}


Measured memory_bytes: 3744
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, a;
vector<int> vec[100010];
int depth[100010];
void dfs(int node, int d) {
	depth[node] = d;
	for (int i : vec[node]) {
		dfs(i, d + 1);
	}
}
int func(int node) {
	if (vec[node].empty())return 0;
	int ma = 0;
	vector<int> memo;
	for (int i : vec[node]) {
		int f = func(i);
		ma = max(ma, f);
		memo.push_back(f);
	}
	sort(memo.begin(), memo.end());
	int q = 0, b = 0;
	rep(i, memo.size()) {
		if (i == 0) {
			b = memo[i];
			q++;
		}
		else if (memo[i] == b)q++;
		else {
			q -= memo[i] - b;
			q = max(q, (ll)0);
			q++;
			b = memo[i];
		}
	}
	return q + ma;
}
signed main() {
	cin >> n;
	for (int i = 2; i <= n; i++) {
		cin >> a;
		vec[a].push_back(i);
	}
	dfs(1, 0);
	cout << func(1) << endl;
	return 0;
}

Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		String[] s = S.split("S");
		int ans = 0;
		for(int i = 0; i < s.length; i ++) {
			ans = Math.max(ans, s[i].length());
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 35628
N,M = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
BC = [0]*M
for i in range(M):
    BC[i] = list(map(int,input().split(" ")))

for i in range(N):
    BC.append([1,A[i]])

BC = sorted(BC,key=lambda x:x[1])
n = N
s = 0
while n != 0:
    B,C = BC.pop()
    bn = min(B,n)
    n -= bn
    s += bn * C

print(s)

Measured memory_bytes: 45008
#include <bits/stdc++.h>
#define Mod 1000000007
#define INF 9999999999
#define INFL 99999999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define N 100005
#define fs first
#define sc second 
using namespace std;
typedef  long long int ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector <ll> vi;

int gcd(int a, int b)
{
    // Everything divides 0 
    if (a == 0 || b == 0)
       return 0;
 
    // base case
    if (a == b)
        return a;
 
    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}

int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
ios::sync_with_stdio(false);
 cin.tie(0);
ll arr[N+5]={0};
ll n,k;
cin>>n;
for(ll i=0;i<n;i++)
{
    cin>>k;
    arr[k]++;
}
ll t=arr[0]+arr[1];
for(ll i=0;i<99999;i++)
{
    if(arr[i]+arr[i+1]+arr[i+2]>t)
        t=arr[i]+arr[i+1]+arr[i+2];

}
cout<<t<<endl;





return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
struct edge{ll to; ll cost;};
typedef pair<ll,ll> P;
const ll INF = 1e17;
ll MAX = 3000;

void dijkstra(int n, int s, vector<vector<edge>>& g, vector<ll>& d){
  priority_queue<P,vector<P>,greater<P>> que;
  rep(i,n) d[i] = INF;
  d[s] = 0;
  que.push(P(0,s));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto e : g[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  ll n, m, s;
  cin >> n >> m >> s;
  ll u[m], v[m], a[m], b[m];
  rep(i,m) {
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--; v[i]--;
  }
  ll c[n], d[n];
  rep(i,n) cin >> c[i] >> d[i];
  vector<vector<edge>> g(n*MAX);
  vector<ll> dist(n*MAX);
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < MAX; j++) {
      g[i*MAX+j].push_back(edge{i*MAX+min(MAX-1,c[i]+j),d[i]});
    }
  }
  rep(i,m) {
    rep(j,MAX) {
      if(j-a[i] >= 0) {
        g[u[i]*MAX+j].push_back(edge{v[i]*MAX+j-a[i],b[i]});
        g[v[i]*MAX+j].push_back(edge{u[i]*MAX+j-a[i],b[i]});
      }
    }
  }
  s = min(MAX-1,s);
  dijkstra(n*MAX,s,g,dist);
  for(int i = 1; i < n; i++) {
    ll ans = INF;
    rep(j,MAX) ans = min(ans,dist[i*MAX+j]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 28016
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        mut v: [f64; n]
    }

    v.sort_by(|a, b| a.partial_cmp(b).unwrap());

    let mut t = v[0];

    for e in &v {
        t = (t + *e) / 2.0;
    }

    println!("{}", t);

}


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

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

    int n, k;
    cin >> n >> k;
    ll h[n];
    rep(i, n) cin >> h[i];
    
    sort(h, h+n);
    
    ll ans = INF;
    
    rep(i, n-k+1){
        ll a = h[i+k-1] - h[i];
        
        if(a < ans) ans = a;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
 
#define rep(i, n) for(int i = 0; (int)(i) < n; i++)
 
using namespace std;
 
int main() {
  int R;
  cin >> R;
  float ans;
  ans = 2 * 3.14 * R;
  cout << ans << endl;
}
  

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

int main() {
  int N;
  cin >> N;
  int res = 0;
  for (int i = 1; i <= N; i += 2) {
    int con = 0;
    for (int j = 1; j <= i; ++j) {
      if (i % j == 0) ++con;
    }
    if (con == 8) ++res;
  }
  cout << res << endl;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <ctime>
using namespace std;

#ifdef __APPLE__
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

const int N = (int)1e6 + 123;
const int MOD = (int)1e9 + 7;
const int inf = (int)5e8;
const long long infll = (long long)1e17;


void solve() {
    int n, x;
    cin >> n >> x;

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

    int ans = 0;
    sort(a.begin(), a.end());
    for (int i = 0; i < n; ++i) {
        if (a[i] <= x) {
            x -= a[i];
            ++ans;
        }
    }

    cout << max(0, ans - (x > 0 ? ans == n : 0)) << endl;
}

int main() {
#ifdef __APPLE__
#endif
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 256