akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repm(i,m,n) for (int i = (m); i < (n); i++)
#define rrep(i,n) for (int i = (n); i >= 0; i--)
using namespace std;
typedef long long ll;

int D, G;
//vector<int> p(D), c(D);
vector<int> p(20), c(20);

int ans = 1e9;

void rec(int sum, int counter, int i, vector<bool> D_bool) {
  if (i == D) {
    if (sum >= G) {
      ans = min(ans, counter);
    }
    else {
      //int j = D - 1;
      rrep(k,D-1) {
        if (D_bool.at(k)) 
          continue;
        else {
          //j = k;

          //for (int l = 0; l < p.at(j)-1 && sum < G; l++) {
          for (int l = 0; l < p.at(k)-1 && sum < G; l++) {
            //sum += 100*(j+1);
            sum += 100*(k+1);
            counter++;
          }

          if (sum >= G) {
            ans = min(ans,counter);
          }
        }
      }
      
    }
  }
  else {
    D_bool.at(i) = false;
    rec(sum, counter, i+1, D_bool);
    
    D_bool.at(i) = true;
    rep(j,p[i]) {
      sum += 100*(i+1);
      counter++;
    }
    sum += c.at(i);
    rec(sum, counter, i+1, D_bool);
  }
}

int main() {
  cin >> D >> G;
  rep(i,D) cin >> p.at(i) >> c.at(i);
  
  vector<bool> vec_bool(D, false);
  
  rec(0,0,0,vec_bool);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())
    if a - 2 * b >= 0:
        print(a - 2 * b)
    else:
        print(0)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

int main(){
  	string s;
  	cin >> s;
  	int ans = 0,aux = 0;
  	for(auto c : s){
      if(c == 'R') aux++;
      else aux = 0;
      ans = max(ans,aux);
    }
  	cout<< ans;
	return 0;
}


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

public static class Permi
{
    public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> items, int? k = null)
    {
        if (k == null) k = items.Count();
        if (k == 0) yield return Enumerable.Empty<T>();
        else
        {
            var i = 0;
            foreach (var x in items)
            {
                var xs = items.Where((_, index) => i != index);
                foreach (var c in Perm(xs, k - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items) yield return i;
    }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var a = new string[n];
            var hb = new int[n];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                a[i] = line[0];
                hb[i] = int.Parse(line[1]) * 10 + int.Parse(line[2]);
            }
            var c = new List<string>();
            var cx = new List<string>();
            foreach (var x in Enumerable.Range(0, 10).Perm(4))
            {
                var s = string.Join("", x);
                cx.Add(s);
                var ok = true;
                for (int i = 0; i < n; i++)
                {
                    var p = check(s, a[i]);
                    if (p != hb[i]) { ok = false; break; }
                }
                if (ok) c.Add(s);
            }
            if (c.Count() == 1) Console.WriteLine(c[0]);
            else getAns(c, cx);
        }
    }
    static void getAns(List<string> c, List<string> cx)
    {
        foreach (var x in cx)
        {
            var hs = new HashSet<int>();
            var ok = true;
            foreach (var y in c)
            {
                var p = check(x, y);
                if (!hs.Add(p)) { ok = false; break; }
            }
            if (ok) { Console.WriteLine(x); return; }
        }
        Console.WriteLine("????");
    }
    static int check(string a, string t)
    {
        var h = 0;
        var b = 0;
        for (int i = 0; i < 4; i++)
        {
            if (a[i] == t[i]) h++;
            else if (t.Contains(a[i])) b++;
        }
        return 10 * h + b;
    }
}



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

ll Ep(int x, int y){
  if(y == 0) return 1;
  if(y == 1) return x;
  ll r = Ep(x,y/2);
  if(y%2 == 1) return r *r *x;
  else return r *r;
}
ll comb(ll m, ll n){
  if(m < n) return 0;
  ll x = 1;
  for(int i=0; i<n; ++i){
    x *= m-i;
    x /= i+1;
  }
  return x;
}

int main(){
  int n, p;
  cin >> n >> p;
  int odd = 0, even = 0;
  for(int i=0; i<n; ++i){
    int x;
    cin >> x;
    if(x%2) ++odd;
    else ++even;
  }
  ll ans = 0;
  for(int i=p; i<=odd; i += 2){
    ans += comb(odd, i);
  }
  ans *= Ep(2,even);
  cout << ans << endl;
}

Measured memory_bytes: 3584
import sys
import math
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
if s == "ABC":
  print("ARC")
else:
  print("ABC")

Measured memory_bytes: 65064
#include<bits/stdc++.h>
using namespace std;
bool a[101][101];
int H,W;
main(){
  cin>>H>>W;
  for(int h=1;h<=H;++h){
    for(int w=1;w<=W;++w){
      char c;
      cin>>c;
      a[h][w]=c=='#';
    }
  }
  for(int h=1;h<=H;++h){
    for(int w=1;w<=W;++w){
      bool exists_col=false;
      bool exists_row=false;
      for(int h2=1;h2<=H;++h2)if(a[h2][w])exists_col=true;
      for(int w2=1;w2<=W;++w2)if(a[h][w2])exists_row=true;
      if(exists_col&&exists_row){
        cout<<(a[h][w]?'#':'.');
      }
    }
    bool exists_row=false;
    for(int w2=1;w2<=W;++w2)if(a[h][w2])exists_row=true;
    if(exists_row)cout<<endl;
  }
}


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

void srch(vector<int> &ans, vector<vector<pair<int, int>>> &cnct, int a){
  if(cnct.at(a).size() == 0){
    return;
  }
  
  pair<int, int> num = cnct.at(a).at(cnct.at(a).size() - 1);
  if(ans.at(num.first) == 2){
    if(num.second % 2 == 1){
      if(ans.at(a) == 0){
        ans.at(num.first) = 1;
      }else{
        ans.at(num.first) = 0;
      }
    }else{
      if(ans.at(a) == 0){
        ans.at(num.first) = 0;
      }else{
        ans.at(num.first) = 1;
      }
    }
  }
  cnct.at(a).pop_back();
  srch(ans, cnct, num.first);
  srch(ans, cnct, a);
}

int main(){
  int N;
  cin >> N;
  
  vector<vector<int>> dot(N, vector<int>(3));
  vector<int> ans(N, 2);
  for(int i = 0; i < N; i++){
    cin >> dot.at(i).at(0) >> dot.at(i).at(1) >> dot.at(i).at(2);
    dot.at(i).at(0)--;
    dot.at(i).at(1)--;
  }
  
  vector<vector<pair<int, int>>> cnct(N);
  for(int i = 0; i < N - 1; i++){
    cnct.at(dot.at(i).at(0)).push_back(make_pair(dot.at(i).at(1), dot.at(i).at(2)));
    cnct.at(dot.at(i).at(1)).push_back(make_pair(dot.at(i).at(0), dot.at(i).at(2)));
  }
  
  ans.at(0) = 0;
  srch(ans, cnct, 0);
  
  for(int i = 0; i < N; i++){
    cout << ans.at(i) << endl;
  }
}


Measured memory_bytes: 19456
N=int(raw_input())
P=[float(x) for x in raw_input().split()]
A=[[0 for i in range(N+1)] for j in range(N+1)]
A[1][0]=1-P[0]
A[1][1]=P[0]
for j in range(2,N+1):
    A[j][0]=A[j-1][0]*(1-P[j-1])
    for k in range(1,j+1):
        A[j][k]=A[j-1][k]*(1-P[j-1]) + A[j-1][k-1]*(P[j-1])
print(sum(A[N][N/2+1:]))


Measured memory_bytes: 170652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  for (int i = 1;i<=10000;i++){
    if ((b * i + c) % a == 0) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

/*　【提出前に確認すること】
・コンパイルできるか
・テストケース試したか
・オーバーフローあるか
*/

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

int min(int a,int b){
  if(a<b) return a;
  return b;
}
int max(int a,int b){
  if(a>b) return a;
  return b;
}

int gcd(Int a, Int b) {
  return b != 0 ? gcd(b, a % b) : a;
}
int lcm(Int a, Int b) {
  return a / gcd(a, b)*b;
}
// a x + b y = gcd(a, b)
int extgcd(Int a, Int b, Int &x, Int &y) {
  Int g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

vector<int> g[100010];
int done[100010];



signed main(){
  char x,y;
  cin>>x>>y;
  if(x>y) cout<<">"<<endl;
  else if(x==y) cout<<"="<<endl;
  else cout<<"<"<<endl;
  return 0;
}
 


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

int main() {
    int64_t A, B, C, D;
    cin >> A >> B >> C >> D;
    // 割り切れる数
    int64_t c = (B / C) - (A-1) / C;
    int64_t d = (B / D) - (A-1) / D;
    int64_t CD = C * D / __gcd(C, D);
    int64_t cd = (B/ CD) - (A-1) / CD;
    cout << (B - A + 1) - c - d + cd << endl;
    //cout << c << " " << d << endl;
    //cout << CD << endl;
    //cout <<  << endl;
    //cout << __gcd(C, D) << endl;
}

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

#include<algorithm>
#define str(a) to_string(a)
#define int long long
#define pb push_back
#define mp make_pair
#define SORT(c) sort(c.begin(),c.end())
#define max_heap priority_queue<int>
#define min_heap priority_queue< int,vector<int>, greater<int> >
#define mod 1000000007
#define setbits(x) __builtin_popcount(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define start(t) int x;cin>>x;while(x--)
#define inf LLONG_MAX
#define sync ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define N 1000001


int ZeroOneKnapsack(vector<int>&weights, vector<int>&profits, int  index, int n, int capacity, vector<vector<int> >&memo) {

	// cout << "(weights,profits, " << index << ", " << n << ", " << capacity << ")" << endl;

	if (index >= n || capacity <= 0) {
		return 0;
	}
	if (memo[index][capacity] != -1)
		return memo[index][capacity];

	// two options...take it or not take it.
	int take = 0;
	if (weights[index] <= capacity )
		take += profits[index] + ZeroOneKnapsack(weights, profits, index + 1, n, capacity - weights[index], memo);
	int leave = ZeroOneKnapsack(weights, profits, index + 1, n, capacity, memo);
	return memo[index][capacity] = max(take, leave);
}



int32_t main()
{

// 	ios_base::sync_with_stdio(0);
// 	cin.tie(0);
// 	cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int n, x, y, c; cin >> n >> c;
	vector<int> weights, profits;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		weights.pb(x); profits.pb(y);
	}
	vector<vector<int> > memo(n, vector<int>(c + 1, -1));
	cout << ZeroOneKnapsack(weights, profits, 0, n, c, memo) << endl;




}








Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

void YN(bool x){
  if(x) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return;
}
int main() {
  bool finish=true;
  int H,W; cin>>H>>W;
  vector<int> S(26,0);
  rep(i,H*W){
    char a; cin>>a;
    int b=a-97;
    S.at(b)++;
  }
  int ki=0,ni=0,yon=0;
  rep(i,26){
    if(S.at(i)%4==0)yon++;
    else if(S.at(i)%2==0)ni++;
    else ki++;
  }
  
  if(ki>1) finish=false;
  else if(ki==1){
    if(H%2==1&&W%2==1){
      if(ki!=1)ni++;
      if(ni>(H-1)/2+(W-1)/2) finish=false;
    }
    else finish=false;
  }
  else{
    if(H%2==1&&W%2==1) finish=false;
    else if(H%2==0&&W%2==0&&ni>0) finish=false;
    else{
      if(H%2==1 && ni>W/2)finish=false;
      if(W%2==1 && ni>H/2)finish=false;
    }
  }
  YN(finish);
}



Measured memory_bytes: 3608
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long ans = 0;
    long sum = 0;
    for(long i = 1; i <= x; i++) {
      sum += i;
      if(sum >= x) {
        ans = i;
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> ans(n);
  int sum = 0;
  rep(i,n) sum ^= a[i];
  rep(i,n){
    ans[i] = sum^a[i];
    cout << ans[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

void Suhaib_Sawalha (){

    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0 ; i < n-2 ; ++i)
        ans += (s.substr(i,3) == "ABC");
    cout << ans;

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

Measured memory_bytes: 3656
import numpy as np

def my_index(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

n = int(input())
h = list(map(int, input().split()))
h = np.array(h)

split_h = []
split_h.append(h)

ans = 0
list_h = []
while len(split_h):
    sph = split_h.pop()

    min_h = sph.min()
    sph -= min_h
    ans += min_h

    if np.all(sph == 0):
        continue

    for elem in sph:
        if elem != 0:
            list_h.append(elem)
        else:
            if list_h:
                split_h.append(np.array(list_h))
                list_h = []
    if list_h:
        split_h.append(np.array(list_h))
        list_h = []

print(ans)


Measured memory_bytes: 12444
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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)*}
    };
}

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)*}
    };
}

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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,
        board: [[usize; n]; 2],
    }
    let mut ans = 0;
    for i in 0..n {
        let acc = &board[0][0..i + 1].iter().sum::<usize>() + &board[1][i..n].iter().sum();
        ans = max(acc, ans);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    string s; cin>>s;
    int n = s.length();
    vector<P> a;
    vector<int> ans(n);
    int l,r;
    l = 0;
    rep(i,n) {
        if (s[i]=='L' && s[i+1]=='R') {
            r = i+1;
            a.emplace_back(l,r);
            l = r;
        }

        if (i==n-1) {
            r = i+1;
            a.emplace_back(l,r);
        }
    }
    
    auto calc = [&] (int x, int y) {
        int m = 0;
        for (int i = x; i < y-1; ++i) {
            if (s[i]=='R' && s[i+1]=='L') {
                m = i;
                break;
            }
        }

        int rcnt = 0, lcnt = 0;
        for (int i = x; i < y; ++i) {
            if (s[i]=='R') rcnt++;
            else lcnt++;
        }

        ans[m] += (lcnt/2); ans[m+1] += ((lcnt+1)/2);
        ans[m] += ((rcnt+1)/2); ans[m+1] += (rcnt/2);
    };

    for (auto &&e: a) {
        ll x,y;
        tie(x,y) = e;
        calc(x,y);
    }

    print(ans);
    return 0;
}

Measured memory_bytes: 1912
H,W=map(int,input().split())
a=[input() for i in range(H)]

dp = [[0]*(W+1) for i in range(H+1)]
dp[1][1]=1
MOD=10**9+7

for i in range(1,H+1):
    for j in range(1,W+1):
        if i==1 and j==1:
            continue
        if a[i-1][j-1] != '#':
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]) % MOD
        else:
            dp[i][j] = 0
            
print(dp[-1][-1])

Measured memory_bytes: 43700
#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 s_size = s.size();
    int t_size = t.size();
    int count = 0;
    int xx = 0;
    rep(i, s_size) {
        if (s[i] == t[i]) {
            count++;
        } 
        else {
            cout << "No" << endl;
            xx++;
            break;
        }
    }
    if (count == s_size){
        if (t_size == s_size + 1) {
            cout << "Yes" << endl;
        }
    }
    else if (count != s_size && xx == 0) {cout << "No" << endl;}
}

Measured memory_bytes: 3624
N, M, X = map(int, input().split())
costs = [0] * N
A = [[0] * M for _ in range(N)]
for i in range(N):
    c, *a = list(map(int, input().split()))
    costs[i] = c
    A[i] = a


INF = 1 << 31
ans = INF
for i in range(1 << N):
    curr_cost = 0
    understanding = [0] * M
    for j in range(N):
        if i >> j & 1:
            curr_cost += costs[j]
            for k in range(M):
                understanding[k] += A[j][k]
    if min(understanding) >= X:
        ans = min(ans, curr_cost)
if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9248
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  string s,t;
  cin >> s >> t;
  int n = s.size(), m = t.size();

  vector<vector<int>> vs(26);
  rep(i,n) vs[s[i]-'a'].push_back(i);
  rep(i,n) vs[s[i]-'a'].push_back(i+n);
  
  ll ans = 0, idx = 0;
  rep(i,m){
    int c = t[i]-'a';
    if(vs[c].size() == 0){
      cout << -1 << endl;
      return 0;
    }
    idx = *lower_bound(vs[c].begin(),vs[c].end(),idx) + 1;
    if(idx>=n){
      idx -= n;
      ans += n;
    }
  }
  ans += idx;
  cout << ans << endl;
}


Measured memory_bytes: 1724
#include <stdio.h>

int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  int x = a * b;
  x = x % 2;
  if(x == 0){
    printf("Even\n");
  }else{
    printf("Odd\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
using namespace std;
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	int sum=n+m;
	if(n%3==0||m%3==0||sum%3==0)
	{
		printf("Possible\n");
	}
	else printf("Impossible\n");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    int a,b;
    char s[11],t[11],sample[11];
    scanf("%s%s",s,t);
    cin>>a>>b;
    scanf("%s",sample);
    int i=0;
    bool r=true;
    while(s[i++]||sample[i++])
    {
        if(s[i]!=sample[i])
        r=0;break;
    }
    if(r)
    a-=1;
    else
    b-=1;
    cout<<a<<" "<<b;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 22
#define maxmask (1ll<<maxbits)
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int  N=1000000 +10, M=(ll)1e9+1 ;
 const int mod =(ll)1e9+7,sz=5 ;

void work(){
    ll n;
    cin >> n;
    vl a(n);
    ll x=0;
    for(ll i=0;i<n;i++){
        cin >> a[i];
        x^=a[i];
    }
    if(!x)
        cout << "Yes";
    else
        cout << "No";
}
int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);
    ll t;
//    cin >> t;
    t=1;
    while(t--){
            work();
    }
   return 0;

}


Measured memory_bytes: 1024
N,K=map(int,input().split());p=[int(i)-1 for i in input().split()];q=[int(i)-1 for i in input().split()]
def I(s):
 r=[0]*N
 for i in range(N):r[s[i]]=i
 return r
def T(s,t):return [s[t[i]] for i in range(N)]
m=[[0 for i in [0]*N] for i in [0]*6]
for i in range(N):m[0][i]=p[i];m[1][i]=q[i]
for i in range(4):m[i+2]=T(m[i+1],I(m[i]))
def E(s,k):
 if k%2==0:
  return E(T(s,s),k//2) if k!=0 else list(range(N))
 else:
  return T(E(T(s,s),k//2),s)
t=E(T(T(T(q,I(p)),I(q)),p),~-K//6);print(" ".join([str(i+1) for i in T(T(t,m[~-K%6]),I(t))]))

Measured memory_bytes: 42684
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int N, M, H[101010];
vector<int> E[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> H[i];
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
 
	int ans = 0;
	rep(cu, 0, N) {
		bool ok = true;
		fore(to, E[cu]) if (H[cu] <= H[to]) ok = false;
		if (ok) ans++;
	}
	cout << ans << endl;
}
 
 
 
 
 


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

#define i64 long long int
#define ran 101101

int n;
pair<int, int> a[ran];
set<int> st;
set<int> ::iterator lit, rit;

int main() {
	scanf("%d", &n);
	for(int i=1;i<=n;i++) {
		scanf("%d", &a[i].first);
		a[i].second = i;
	}
	sort(a+1, a+n+1);
	
	i64 ans = 0;
	st.insert(0);
	st.insert(n+1);
	for(int i=n;i>0;i--) {
		int val = a[i].first;
		int pos = a[i].second;
		
		rit = st.lower_bound(pos);
		lit = rit;
		lit--;
		int lpos = (*lit);
		int rpos = (*rit);
		if (lpos>0) {
			lit--;
			ans += 1LL * (lpos - (*lit)) * (rpos - pos) * val;
		}
		if (rpos<=n) {
			rit++;
			ans += 1LL * ((*rit) - rpos) * (pos - lpos) * val;
		}
		
		st.insert(pos);
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 5760
n,k,s=map(int,input().split())
if k==0:
    if s==10**9:
        for i in range(n):
            print(1,end=" ")
    else:
        for i in range(n):
            print(s+1,end=" ")
else:
    if s==10**9:
        li=[]
        for j in range(k):
            li.append(s)
        for j in range(n-k):
            li.append(1)
        for j in li:
            print(j,end=" ")
    else:
        li=[]
        for j in range(k):
            li.append(s)
        for j in range(n-k):
            li.append(s+1)
        for j in li:
            print(j,end=" ")
        

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

template <typename T1, typename T2>
bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, K;
    cin >> N >> K;
    ll R, S, P;
    cin >> R >> S >> P;
    string T;
    cin >> T;

    vector<bool> win(N, true);

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        if (T[i] == 'r') {
            if (i - K >= 0 && T[i - K] == 'r' && win[i - K]) {
                win[i] = false;
            }
            else {
                ans += P;
            }
        }
        else if (T[i] == 's') {
            if (i - K >= 0 && T[i - K] == 's' && win[i - K]) {
                win[i] = false;
            }
            else {
                ans += R;
            }
        }
        else if (T[i] == 'p') {
            if (i - K >= 0 && T[i - K] == 'p' && win[i - K]) {
                win[i] = false;
            }
            else {
                ans += S;
            }
        }
    }
    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(nullptr), cout.tie(nullptr);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

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

using namespace std;

using LL = long long;
template<typename T> using V = vector<T>; 
template<typename T, typename S> using P = pair<T, S>; 
template<class T> using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
using LD = long double;

#define ALL(v) v.begin(), v.end()
#define endl '\n'
#define SYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL);
#define REP(i, n) for(int i = 0; i < (int)n ;i++)
#define REPN(i, n) for(int i = 1; i <= (int)n ; i++)
#define her 	cerr << "here\n" 
#define pp push_back
#define fi first 
#define se second
#define un(x) x.erase(unique(ALL(x)), x.end())

template<typename T, typename S> void check(T & a, S & b) { if (a >= b) { a %= b; } }
template<typename T>T gcd(T u, T v) { if (u == v)return u; if (u == 0)return v; if (v == 0)return u; if (~u & 1) { if (v & 1) return gcd(u >> 1, v); else return gcd(u >> 1, v >> 1) << 1; }if (~v & 1)return gcd(u, v >> 1); if (u > v)return gcd((u - v) >> 1, v); return gcd((v - u) >> 1, u); }

int bfs(int n) {
	V<int> d(n, (int)1e9);
	min_heap<P<int,int>> q;
	q.push({0, 0});
	int ans = -1;

	while(true) {
		auto v = q.top();
		q.pop();
		int rem = v.se, sum = v.fi;
		if(!rem && sum) return sum;
		REP(i, 10) {
			if(!i && !rem) continue;
			int r = ((rem * 10) + i) % n;
			if(d[r] > sum + i) {
				d[r] = i + sum;
				q.push({d[r], r});
			}
		}
	}

	return ans;
}

int32_t main(){
	SYNC;
	int n;
	cin >> n;
	cout << bfs(n) << endl;
	cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
	return 0; 
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, X;
  cin >> N >> X;
  vector<int> M(N);
  REP(i, N) {
    cin >> M.at(i);
    X -= M.at(i);
  }
  int min_m = *min_element(M.begin(), M.end());
  int ans = N;
  while (X >= min_m) {
    X -= min_m;
    ++ans;
  }

  cout << ans << endl;

  return 0;
}


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

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

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

inline void read() {}

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

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

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

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

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

    int N; read(N);

    vector<i64> a(N);
    rep(i, N) {
        read(a[i]);
    }

    i64 ans = 0;
    rep(i, N - 1) {
        {
            ans += a[i] / 2;
            a[i] &= 1;
        }
        {
            const i64 k = min(a[i], a[i+1]);
            a[i] -= k;
            a[i+1] -= k;
            ans += k;
        }
    }
    ans += a[N-1] / 2;

    print(ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int main() 
{
    ios;
   int ar[3];
   cin>>ar[0]>>ar[1]>>ar[2];
   sort(ar,ar+3); 
   cout<<ar[0]+ar[1];
}


Measured memory_bytes: 256
import collections

S = str(input())
len_S = len(S)
K = int(input())
lst = []

for i in range(len_S):
	j = 1
	while i + j <= len_S:
		if j == 6: break
		lst.append(S[i : i + j])
		j += 1
lst.sort()

if K == 1:
	print(lst[0])
else:
	ctr = 1
	for i in range(1, len(lst)):
		if lst[i] != lst[i - 1]:
			ctr += 1
		if ctr == K:
			print(lst[i])
			break

Measured memory_bytes: 41200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
//#define MOD 1000000007
const int INF = 1LL<<30;

int cnt[1010101];
bool ok[1010101];

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

    rep(i,n) cnt[a[i]]++;
    for(int x=1;x<1010101;x++) ok[x]=true;
    for(int x=1;x<1010101;x++){
        if(0<cnt[x]){
            if(1<cnt[x]) ok[x]=false;
            for(int x2=x*2;x2<1010101;x2+=x) ok[x2]=false;
        }
    }

    int ans=0;
    rep(i,n){
        if(ok[a[i]]) ans++;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 8936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnth[314514],cntw[314514],x[314514],y[314514];
int main(){
	ll h,w,m;
	cin>>h>>w>>m;
	for(int i=0;i<m;i++){
		cin>>y[i]>>x[i];
		cnth[y[i]]++,cntw[x[i]]++;
	}
	ll mah=0,maw=0;
	for(int i=1;i<=h;i++)mah=max(mah,cnth[i]);
	for(int i=1;i<=w;i++)maw=max(maw,cntw[i]);
	ll numh=0,numw=0;
	for(int i=1;i<=h;i++)if(cnth[i]==mah)numh++;
	for(int i=1;i<=w;i++)if(cntw[i]==maw)numw++;
	ll num=0;
	for(int i=0;i<m;i++)if(cnth[y[i]]==mah&&cntw[x[i]]==maw)num++;
	/*cout<<num<<' '<<numh<<' '<<numw<<endl;
	for(int i=1;i<=h;i++)cout<<cnth[i]<<' ';
	cout<<endl;
	for(int i=1;i<=w;i++)cout<<cntw[i]<<' ';
	cout<<endl;*/
	if(num<numh*numw)cout<<mah+maw;
	else cout<<mah+maw-1;
	return 0;
}


Measured memory_bytes: 13000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;

public class Main {

    public static void main(String[] args) throws IOException {

        DecimalFormat df1 = new DecimalFormat("0.00000");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        double r = Double.valueOf(br.readLine());

        double pi = Math.PI;

        String S = df1.format((double)( r * r * pi));
        String L = df1.format((double)( 2 * r * pi));

        System.out.println(S + " " + L);
    }
}

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


int main()
{
 int N,height,height_pre,max_step=0,step=0;
 int k,i;

 cin>>N;
 cin>>height_pre;
 for(i=0;i<N-1;i++)
 {
     cin>>height;
     if(height<=height_pre)
     {
         step++;
     }
     else
     {
         if(step>max_step)
         {
             max_step = step;
         }
         step=0;
     }
     height_pre = height;
 }
 if(step>max_step)
 {
     max_step = step;
 }
 cout<<max_step;
 return 0;
}


Measured memory_bytes: 384
// C++11
#include <iostream>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::swap;

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

  int x[N];
  for (auto i = 0; i < N; i++) {
    cin >> x[i];
  }

  int count = 0;

  for (auto i = 0; i < N; i++) {
    for (auto j = N-1; j > i; j--) {
      if (x[j] < x[j-1]) {
        swap(x[j], x[j-1]);
        count++;
      }
    }
  }

  for (auto i = 0; i < N; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << x[i];
  }
  cout << endl;
  cout << count << endl;

  return 0;
}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

class UnionFind{
public:
  vector<int> p;		// 親
  vector<int> rank;	// サイズ・各集合の根のみ有効
  UnionFind(int n){
    p.resize(n, -1);
    rank.resize(n, 1);
  }
  int root(int x){
    if(p[x] == -1) return x;
    else return p[x] = root(p[x]); // 深さを 1 にしている
  }
  void unite(int x, int y){
    x = root(x); y = root(y);
    if(x == y)return;
    if(rank[x] > rank[y]) swap(x, y); // rankの小さいものを下につける
    rank[y] += rank[x];
    p[x] = y;
  }
  // グループの数
  ll root_num()
  {
    ll num = 0;
    for(ll x : p) if (x < 0) num++;
    return num;
  }
  //xが属すグループのサイズ
  int size(int x){ return rank[root(x)]; }
  bool same(int x, int y){ return (root(x) == root(y)); }
};

void solve()
{
  ll n, m, a, b;
  cin >> n >> m;
  UnionFind uf(n);
  for(int i = 0; i < m; ++i)
  {
    cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
  }
  cout << uf.root_num() - 1;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3952
#include <iostream>
using namespace std;
long long n, m, a, b, c, d[1005][1005];
int main() {
	int i, j, k;
	cin>>n>>m;
	for(i=1; i<=n; i++) {
		for(j=1; j<=n; j++) d[i][j] = -1e18;
		d[i][i] = 0;
	}
	while(m--) cin>>a>>b>>c, d[a][b] = c;
	for(k=1; k<=n; k++) for(i=1; i<=n; i++) {
		if(d[i][k] == -1e18) continue;
		for(j=1; j<=n; j++) if(d[i][k] + d[k][j] > d[i][j]) d[i][j] = d[i][k] + d[k][j];
	}
	d[1][1]>0 ? cout<<"inf" : cout<<d[1][n];
	return 0;
}

Measured memory_bytes: 8064
# -*- coding: utf-8 -*-
import resource
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


g = defaultdict(list)


def f(u):
    d = [f(v) for v in g[u]]
    if not d:
        return 0

    d.sort(reverse=True)
    while len(d) > 1:
        l = d.pop()
        r = d.pop()
        d.append(max((l + 1, r)))
    return d[0] + 1

@mt
def slv(N, A):
    global g
    for i, a in enumerate(A):
        i += 2
        g[a].append(i)

    return f(1)


def main():
    N = read_int()
    A = [read_int() for _ in range(N-1)]
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 239656
#                         author:  kagemeka 
#                         created: 2019-11-08 18:39:24(JST)
### modules
## from standard library
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version)  
# imort numpy as np 

def main():
    s = sys.stdin.readline().rstrip()
    
    if s[0] == 'A':
        s = s[1:]
        if 'C' in s[1:-1] and s.count('C') == 1:
            s = s.replace('C', 'a')
            if s.lower() == s:
                print('AC')
                exit()

    print('WA')
 
if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
N=int(input())
C=[[0]*N for i in range(3)]
S=list(map(int,input().split()))
C[0][0]=S[0]
C[1][0]=S[1]
C[2][0]=S[2]

for i in range(1,N):
    H=list(map(int,input().split()))
    C[0][i]=max(C[1][i-1],C[2][i-1])+H[0]
    C[1][i]=max(C[0][i-1],C[2][i-1])+H[1]
    C[2][i]=max(C[0][i-1],C[1][i-1])+H[2]

ans=C[0][N-1]
if(ans<C[1][N-1]):
    ans=C[1][N-1]
if(ans<C[2][N-1]):
    ans=C[2][N-1]
print(ans)


Measured memory_bytes: 50904
#include <iostream>
using namespace std;
int n;
int A[20];
bool solve(int i,int m){
  if(i >= n && m > 0) return false;
  if(A[i] == m) return true;
  if(m > A[i] && solve(i+1,m-A[i])) return true;
  return solve(i+1,m);
}
int main()
{
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> A[i];
  }
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    int j;
    cin >> j;
    if(solve(0,j)) cout << "yes";
    else cout << "no";
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
S=[0]*53
n=int(input())
for i in range(0,n):
    rank,num = input().split()
    num=int(num)
    if(rank=="S"):
        S[num]=1
    elif(rank=="H"):
        S[num+13]=1
    elif(rank=="C"):
        S[num+26]=1
    elif(rank=="D"):
        S[num+39]=1
for i in range(1,53):
    if(S[i]==0):
        if(1 <= i <= 13):
            print(f"S {i}")
        if(14 <= i <= 26):
            print(f"H {i-13}")
        if(27 <= i <= 39):
            print(f"C {i-26}")
        if(40 <= i <= 52):
            print(f"D {i-39}")


Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
void solve()
{
    int n;
    cin>>n;
    int d=n%10;
    if(d==2||d==4||d==5||d==7||d==9) puts("hon");
    else if(d==0||d==1||d==6||d==8) puts("pon");
    else puts("bon");
}
int main()
{
	//ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//int _;cin>>_;while(_--)
	solve();
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n, t;
struct Data {
    ll time, deli;
    bool operator<(const Data &r) const { return r.time > time; };
};

// dp[何番目の食べ物][今何分か]
ll dp[3030][10100];

int main() {
    cin >> n >> t;
    vector<Data> food(n);
    for(int i = 0; i < n; ++i) {
        cin >> food[i].time >> food[i].deli;
    }
    sort(food.begin(), food.end());
    // cout << food[0].time << endl;
    memset(dp, 0, sizeof(dp));

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < t; ++j) {
            chmax(dp[i+1][j+food[i].time], dp[i][j]+food[i].deli);
            chmax(dp[i+1][j], dp[i][j]);
        }
    }

    ll ans = 0;
    for(int i = 0; i < n; ++i) {
        chmax(ans, dp[i][t-1]+food[i].deli);
    }
    cout << ans << endl;
}

Measured memory_bytes: 242692
#include<iostream>
#include<algorithm>
using namespace std;
int a, b, c, d;
int main(){
  cin >> a >> b >> c >> d;
  if(abs(a - b) <= d && abs(b - c) <= d) cout << "Yes" << endl;
  else if(abs(c - a) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
  }


Measured memory_bytes: 256