akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main (){
    int n;
    cin >> n;
    vector <int> a;
    a.push_back(-1);//社員番号１の社員には上司はいないのでー１とする。
    for(int i = 0; i< n-1; i++){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    vector <int> subordinates(n);
    for(int i = 0; i < a.size(); i++){
        if(a[i]!=-1){
            subordinates[a[i]-1]++;
        }
    }
    for(int i = 0; i< subordinates.size();i++){
        cout << subordinates[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4968
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#define _GLIBCXX_DEBUG
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<long long,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}



int main() {
    int N;cin >> N;
    vector<int> retu(N);
    for(int i = 0;i<N;i++){
        cin >> retu.at(i);
        retu.at(i)--;
    }
    int next = 0;
    for(int i = 1;i<=N;i++){
        next = retu.at(next);
        if(next == 1){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    

    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 640
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST
import Data.Char


main :: IO ()
main = do
  n <- readLn :: IO Int
  vs <- map read . words <$> getLine :: IO [Double]
  print $ solve n (sort vs)

halve x = x / 2.0

solve n (v:vs) = go v vs
  where
    go acc (v0:[]) = halve (acc + v0)
    go acc (v:vs) = go (halve $ acc + v) vs

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

class Program
{
    static List<int> sorce = new List<int>();

    static void Main()
    {
        string[] array = Console.ReadLine().Split(' ');
        int N = int.Parse(array[0]);
        int X = int.Parse(array[1]);

        array = Console.ReadLine().Split(' ');
        List<int> list = new List<int>();
        for (int i = 0; i < array.Length; i++)
            list.Add(int.Parse(array[i]));
        list.Add(X);
        list.Sort();

        List<int> gap = new List<int>();
        for (int i = 1; i < list.Count; i++)
            gap.Add(list[i] - list[i - 1]);

        sorce = gap.Distinct().OrderBy(i => i).ToList();

        if (sorce.Count != 1)
        {
            for (int i = 1; i < sorce.Count; i++)
            {
                Gcd(sorce[i], sorce[i - 1], i);
            }
            Console.WriteLine(sorce[sorce.Count - 1]);
        }
        else Console.WriteLine(sorce[0]);
    }

    static void Gcd(int a, int b, int i)
    {
        while (b != 0)
        {
            int r = a % b;
            a = b;
            b = r;
        }
        sorce[i] = a;
    }
}

Measured memory_bytes: 22496
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}
const int maxn = 5e5 + 7;
int BIT [30][maxn];
ll query(int ro, int x, int n) {
	ll ret = 0;
	while (x > 0) {
		ret += BIT[ro][x];
		x -= (x & -x);
	}
	return ret;
}
void sum(int ro, int x, int n, int k) {
	while (x <= n) {
		BIT[ro][x] += k;
		x += (x & -x);
	}
}
void solve() {
	int n, q;
	cin >> n;
	string s;
	cin >> s;
	s = " " + s;
	cin >> q;
	mem(BIT, 0);
	rep(i, 1, n + 1) {
		int c = (int)(s[i] - 'a');
		sum(c, i, n, 1);
	}
	rep(i, 0, q) {
		int t;
		cin >> t;
		if (t == 1) {
			int u;
			char upd;
			cin >> u >> upd;
			int prev = (int)(s[u] - 'a');
			sum(prev, u, n, -1);
			int now = (int)(upd - 'a');
			sum(now, u, n, 1);
			s[u] = upd;
		}
		else {
			int l, r;
			cin >> l >> r;
			ll lsum = 0, rsum = 0, ans = 0;
			rep(j, 0, 26) {
				lsum = query(j, l - 1, n);
				rsum = query(j, r, n);
				if (rsum > lsum)ans++;
			}
			cout << ans << endl;
		}
	}

}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 59568
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    /* ll t;
    cin>>t;
    while(t--) */
    {
        ll i,j,k,l,m,n,a,b,c,d,cnt=0;
        cin>>a>>b>>n;
        if(b<=n)
            c=b-1;
        else 
            c=n;

        d=(a*(c))/b;
        cout<<d<<endl;

    }

}


Measured memory_bytes: 3600
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    s.sort()
    if s == ["a", "b", "c"]:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    a, b, k = LI()
    ans = []
    for i in range(a, min(a + k, b + 1)):
        ans.append(i)
    for i in range(max(b - k + 1, a + k), b + 1):
        ans.append(i)
    for i in ans:
        print(i)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 38512
N,M = map(int,input().split())

A = ""
B = ""

for i in range(N):
	A += input()



for i in range(M):
	if not i % 2 == 0:
		B += input()[::-1]
	else:
		B += input()

if B in A:
	print("Yes")
else:
	print("No")

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

#define MAX 200001
vector<int> graph[MAX];
long long ans[MAX];

void dfs(int,int,long long);

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

	int a,b;
	for(int i=1;i<N;i++){
		cin>>a>>b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	int start, count;
	for(int i=0;i<Q;i++){
		cin>>start>>count;
		ans[start]+=count;
	}

	dfs(1, -1, 0);

	for(int i=1;i<=N;i++){
		if(i>1)cout<<" ";
		cout<<ans[i];
	}cout<<endl;
		
	return 0;
}


void dfs(int start, int parent, long long count){
	ans[start]+=count;
	for(int next:graph[start]){
		if(next != parent){
			dfs(next, start, ans[start]);
		}
	}
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    ll n;
    while(cin>>n){
        ll ans=0;
        long double res = n*n*n/27.0;
        cout<<fixed<<setprecision(9)<<res<<endl;
    }
  return 0;
}




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

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

  string s, t;
  cin >> s >> t;

  int ans = 0;

  for (int i = 0; i < s.size(); i++)
  {
    if(s.at(i) != t.at(i)) ans++;
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
bool p[1000006];
long long r[1000005],y,o,k[1000006],b,u,a,ans;
int gp()
{
	for(int i=2;i<=1000000;i++)
	{
		if(p[i]==0)
		{
			for(int j=i*2;j<=1000000;j+=i)
			p[j]=1;
		}
	}
	for(int i=2;i<=1000000;i++)
	{
		if(p[i]==0)
		{
			r[y]=i;
			y++;
		}
	}
	return 0;
}
int main()
{
	gp();
	cin>>a;
	for(int i=0;i<a;i++)
	{
		u=1;
		cin>>b;
		for(int j=0;r[j]<=sqrt(b)&&u==1;j++)
		{
			if(b%r[j]==0)
			{
				while(b%r[j]==0)
				b/=r[j];
				k[r[j]]++;
				u=1;
			}
		}
		k[b]++;
	}
	o=1;
	for(int i=2;i<=1000000;i++)
	{
		if(k[i]>=2)
		ans=max(ans,k[i]);
	}
	if(ans<=1)
	cout<<"pairwise coprime"<<endl;
	else if(ans<a)
	cout<<"setwise coprime"<<endl;
	else
	cout<<"not coprime"<<endl;
	return 0;
}

Measured memory_bytes: 13080
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,ans,f[52][52],a[52],b[52],v[52];
ll pd(){
	ll i,j,k;
	for(i=1;i<=n;i++){
		for(k=0;k<=a[i];k++)f[51][k]=0;
		f[51][a[i]]=1;
		for(j=51;j>1;j--){
			for(k=0;k<=a[i];k++)f[j-1][k]=0;
			for(k=0;k<=a[i];k++)if(f[j][k]){
				f[j-1][k]=1;
				if(v[j-1])f[j-1][k%(j-1)]=1;
			}
		}
		if(!f[1][b[i]])return 1;
	}
	return 0;
}
int main(){
	ll i;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(i=1;i<=n;i++)scanf("%lld",&b[i]);
	for(i=1;i<=50;i++)v[i]=1;
	if(pd())return puts("-1"),0;
	for(i=50;i;i--){
		v[i]=0;
		if(pd())v[i]=1;
	}
	for(i=1;i<=50;i++)ans+=(1ll<<i)*v[i];
	printf("%lld",ans);
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int n,cnt=0;
    string s;
    cin>>n>>s;
    for(int i=0; i<=n-3; i++)
    {
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
        {
            cnt++;
            i+=2;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
import collections
import itertools
n = int(input())
s = list(input()[0] for _ in range(n))
s = [i for i in s if i == "M" or i == "A" or i == "R" or i == "C" or i == "H"]

d = dict(collections.Counter(s))
c = list(itertools.combinations(d.values(), 3))

ans = 0
for i, j, k in c:
    ans += i * j * k

print(ans)


Measured memory_bytes: 61912
card = Array.new(3){gets.split.map(&:to_i)}.flatten
gets.to_i.times do
  idx = card.index(gets.to_i)
  card[idx] = '*' if idx
end
bingo = false
3.times do |i|
  l = card[i * 3, 3]
  bingo = true if l == ['*', '*', '*']
end
3.times do |j|
  l = []
  3.times do |i|
    l << card[i * 3 + j]
  end
  bingo = true if l == ['*', '*', '*']
end
l = []
l << card[0]
l << card[4]
l << card[8]
bingo = true if l == ['*', '*', '*']
l = []
l << card[2]
l << card[4]
l << card[6]
bingo = true if l == ['*', '*', '*']
puts bingo ? 'Yes' : 'No'


Measured memory_bytes: 3836
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI = 3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//struct custom_hash {
//    static uint64_t splitmix64(uint64_t x) {
//        // http://xorshift.di.unimi.it/splitmix64.c
//        x += 0x9e3779b97f4a7c15;
//        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//        return x ^ (x >> 31);
//    }
//    size_t operator()(uint64_t x) const {
//        static const uint64_t FIXED_RANDOM =
//            chrono::steady_clock::now().time_since_epoch().count();
//        return splitmix64(x + FIXED_RANDOM);
//    }
//};

#define fi first
#define se second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector< pair<ll, ll> >data;
	for (ll i = 0; i < n; i++)
	{
		ll d1, d2;
		cin >> d1 >> d2;
		data.eb(d1, d2);
	}
	ll fl = 0;
	for (ll i = 0; i < (n - 2); i++)
	{
		if ((data[i].fi == data[i].se) && (data[i + 1].fi == data[i + 1].se) && (data[i + 2].fi == data[i + 2].se))
			fl = 1;
	}
	if (fl)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


//252908XL

/*
comments:-

*/


Measured memory_bytes: 3652
def sosu(n):
    if n<=1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True
def gold(n):
    a=[]
    b=0
    for i in range(n+1):
        if sosu(i):
            a.append(i)
    for j in a:
        for k in a:
            if j>k:
                pass
            elif j+k==n:
                b+=1
            else:
                pass
    print(b)
while True:
    n=int(input())
    if n==0:
        break
    gold(n)


Measured memory_bytes: 5680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 50;
ll a[maxn];
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int k = n % 10;
    if(k == 3) cout << "bon" << endl;
    else if(k == 0 || k == 1 || k == 6 || k == 8 ) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}


Measured memory_bytes: 3640
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element : vec) {
        is >> element;
    }
    return is;
}
template <class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int K, N;
    cin >> K >> N;
    vi a(N);
    cin >> a;

    int diff = 0;
    a.push_back(a[0] + K);
    REP(i, N) {
        chmax(diff, a[i + 1] - a[i]);
    }
    cout << K - diff;
}

#pragma region main
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << std::fixed;
    cout.precision(20);
    Main();
    cout << flush;
}
#pragma endregion


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

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

typedef long long llint;

const int MOD = 1e9 + 7;

int h1, m1, h2, m2, k;

int main(void) {
  scanf("%d%d%d%d%d", &h1, &m1, &h2, &m2, &k);
  m1 += h1 * 60;
  m2 += h2 * 60;
  int sol = 0;
  for (int i = m1; i <= m2; ++i)
    sol += i + k <= m2;
  printf("%d\n", sol - 1);
  return 0;
}


Measured memory_bytes: 3824
line = gets
line = line.split(" ")
moji = line.max_by{|i| i.size}

count = Hash.new(0)
line.each do |elem|
  count[elem] += 1
end
count = count.max{|a,b| a[1]<=>b[1]}
hindo = count[0]
puts [hindo,moji].join(" ")


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

int main(){
    int N;
    char P[100000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> P[i];
    char c = P[0];
    for(int i=1; i<N; i++){
        if(c == 'T' && P[i] == 'F'){
            c = 'F';
        }else{
            c = 'T';
        }
    }
    cout << c << endl;
}



Measured memory_bytes: 3208
H, W = map(int, input().split())
List = [input() for i in range(H)]
queue = [(0,0,1)]
shape = sum(row.count("#") for row in List)
used = {(0,0)}

def check(x,y,c):
    if x > W-1 or y > H-1 or x < 0 or y < 0:
        return
    if List[y][x] == '#':
        return
    if (x,y) in used:
        return
    queue.append((x,y,c))
    used.add((x,y))
    
f = -1
while queue:
    x,y,c = queue.pop(0)
    if x == W-1 and y == H-1:
        f = 1
        break
    check(x+1, y, c+1)
    check(x,y+1,c+1)
    check(x-1,y,c+1)
    check(x,y-1,c+1)
print(f if f == -1 else(H*W - c - shape))
    

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ll x, t;
  ll z = 0;
  cin >> x >> t;
  cout << max(z, x-t) << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from itertools import accumulate

read = sys.stdin.buffer.read


def main():
    N, *L = map(int, read().split())

    L.sort()
    max_L = L[-1]

    C = [0] * (max_L + 1)
    for l in L:
        C[l] += 1
    C = list(accumulate(C))

    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            if L[i] + L[j] > max_L:
                ans += N - j - 1
            else:
                ans += C[L[i] + L[j] - 1] - j - 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 68612
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
using namespace std;
#define REP(i,n) for(int i=0;i < n; i++)
#define RREP(i,n) for(int i=n-1;i >=0; i--)
#define p(a) (a) * (a)
#define p2(a,b) p((a) - (b)) 
 
#define MAX 100002
 
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a*b == c*d) {
		cout << a*b << endl;
	}
	else if (a*b > c*d) {
		cout << a*b << endl;
	}
	else {
		cout << c*d << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll inf = 1LL<<58;

int main(){
    int A, B, Q; cin >> A >> B >> Q;
    vector<ll> s(A+2), t(B+2);
    for(int i=1; i<=A; i++) cin >> s[i];
    for(int i=1; i<=B; i++) cin >> t[i];
    s[0] = t[0] = -inf;
    s[A+1] = t[B+1] = inf;

    vector<ll> ans(Q);
    ll a,b,c,d;
    for(int i=0; i<Q; i++){
        ll x; cin >> x;
        auto itr1 = lower_bound(s.begin(), s.end(), x);
        ll sRight = *itr1;
        itr1--;
        ll sLeft = *itr1;

        auto itr2 = lower_bound(t.begin(), t.end(), x);
        ll tRight = *itr2;
        itr2--;
        ll tLeft = *itr2;

        a = max(sRight, tRight)-x;
        b = x - min(sLeft, tLeft);
        c = min(2*(sRight-x)+x-tLeft, sRight-x+2*(x-tLeft));
        d = min(2*(tRight-x)+x-sLeft, tRight-x+2*(x-sLeft));

        ans[i] = min(min(a,b), min(c,d));
    }

    for(int i=0; i<Q; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 3712
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;

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

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt(); //problems
            int M = in.nextInt(); //subs
            Map<Integer, List<Integer>> subsMap = new HashMap<>();
            while (M-- > 0)
            {
                int problem = in.nextInt();
                String answer = in.next();

                List<Integer> answers = subsMap.getOrDefault(problem, new ArrayList<>());
                answers.add(answer.equals("WA") ? 0 : 1);
                subsMap.put(problem, answers);
            }
            int p = 0;
            int correct = 0;
            for (int problem : subsMap.keySet())
            {
                List<Integer> answers = subsMap.get(problem);
                int i = 0;
                boolean wasSolved = false;
                int localP = 0;
                while (i < answers.size())
                {
                    if (answers.get(i) == 0)
                    {
                        localP++;
                    } else
                    {
                        wasSolved = true;
                        break;
                    }
                    i++;
                }
                if (wasSolved)
                {
                    correct++;
                    p += localP;
                }
            }
            out.print(correct + " " + p);
        }

    }
}



Measured memory_bytes: 74124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
static const int MAX = 100;
int in(){int x; scanf("%d",&x); return x;}

int main(){
  int dish, x = 10, time = 0;

  rep(i, 5){
    dish = in();
    if(dish % 10 > 0) x = min(x, dish % 10);
    time += (dish + 9) / 10 * 10;
  }
  cout << time + x - 10 << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<map>
#define ll long long
using namespace std;
int main(){
        ll n;  cin>>n;
        int a[n];
        for(ll i=0;i<n;i++) cin>>a[i];
       map<ll,ll> m;
       for(ll i=0;i<n;i++){
        m[a[i]]=i+1;
       }
       for(auto it=m.begin();it != m.end();it++){
        cout<<it->second<<" ";
       }
        cout<<endl;
    
}


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

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

    if(S[0] == S[1] && S[2] == S[3] && S[0] != S[2]){
        cout << "Yes" << endl;
    }
    else if(S[0] == S[2] && S[1] == S[3] && S[0] != S[1]){
        cout << "Yes" << endl;
    }
    else if(S[0] == S[3] && S[1] == S[2] && S[0] != S[1]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }    
}

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

#define MAX 26

int main(void)
{
	char c;
	int i, sum;
	int cnt[MAX] = {0};

	while (1) {
		sum = 0;
		while ((c = getchar()) != '\n') {
			sum += (c-'0');
		}
		if (sum == 0) {
			break;
		}
		else {
			printf("%d\n",sum);
		}
	}
	return 0;
}




Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main(){
  char c;
  cin >> c;
  switch (c)
  {
  case 'a':
  case 'i':
  case 'u':
  case 'e':
  case 'o':
    cout << "vowel";
    break;
  
  default:
    cout << "consonant";
    break;
  }
}

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

using namespace std;
using ll = long long;

int main() {
    int K, N;
    cin >> K >> N;
    int fst = 0, prev = 0, m = 0;
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if(i == 0) {
            fst = a;
        } else {
            m = max(m, a - prev);
        }
        prev = a;
        if(i == N - 1) {
            m = max(m, K + fst - a);
        }
    }
    cout << K - m << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int H , W , A , B;
int a[1010][1010];
int main(){
	cin >> H >> W >> A >> B;
	for(int i = 1 ; i <= B ; ++ i){
		for(int j = 1 ; j <= A ; ++ j)
			cout << 0;
		for(int j = A + 1 ; j <= W ; ++ j)
			cout << 1;
		cout << endl;
	}
	for(int i = B + 1 ; i <= H ; ++ i){
		for(int j = 1 ; j <= A ; ++ j)
			cout << 1;
		for(int j = A + 1 ; j <= W ; ++ j)
			cout << 0;
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
def main():
  X = int(input())

  if(X==2):
    print(X)
  elif(X%2>0):
    for i in range(50000):
      if(prime(X+i*2)==1):
        print(X+i*2)
        break
  else:
    for i in range(50000):
      if(prime(X+1+i*2)==1):
        print(X+1+i*2)
        break
        
def prime(A):
  m = int(A**0.5)
  for i in range(1,m,1):
    if(A%(i+1)==0):
      return 0
  return 1
    

if __name__=="__main__":
  main()

Measured memory_bytes: 3064
n, m = gets.split.map(&:to_i)
abs = []
n.times{ abs << gets.split.map(&:to_i) }

abs.sort!{|a, b| a[0] <=> b[0] }

yen = 0
abs.each do |ab|
  yen += ab[0] * [m, ab[1]].min
  m -= ab[1]
  break if m.negative?
end

p yen


Measured memory_bytes: 12536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    vector<vector<int> > vec(3,vector<int>(3));
    rep(i,3){
        rep(j,3){
            cin >> vec[i][j];
        }
    }
    int X = min(vec[0][0], min(vec[0][1], vec[0][2]));
    rep(i,3){
        vec[0][i] -= X;
    }
    bool ans = false;
    rep(i,101){
        rep(j,101){
            if (i + vec[0][0] == vec[1][0] && i + vec[0][1] == vec[1][1] && i + vec[0][2] == vec[1][2] && j + vec[0][0] == vec[2][0] && j + vec[0][1] == vec[2][1] && j + vec[0][2] == vec[2][2]){
                ans = true;
            }
        }
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


#line 1 "lib/modint.hpp"



#include <iostream>

// Modint
struct Mint {
    static const long long mod = (long long)1e9 + 7;
    long long val;

    Mint() { val = 0; }
    Mint(long long a) { val = a; verify_value(); }

    void verify_value() {
        if (val >= mod) val %= mod;
        if (val < 0) val %= mod, val += mod;
    }

    Mint pow(long long p) const {
        Mint cur = Mint(val), ret = 1;
        while (p > 0) {
            if (p & 1) ret *= cur;
            cur *= cur;
            p >>= 1LL;
        }
        return ret;
    }
    Mint inv() const {
        if (val == 0)
            std::cerr << "WARNING: inv() is called with 0." << std::endl;
        return pow(mod - 2);
    }

    Mint operator+() const { return *this; }
    Mint operator-() const { return Mint(mod - val); }

    Mint operator+=(const Mint &a) {
        val += a.val;
        if (val >= mod) val -= mod;
        return Mint(val);
    }
    Mint operator*=(const Mint &a) {
        val *= a.val;
        if (val >= mod) val %= mod;
        return Mint(val);
    }
    Mint operator-=(const Mint &a) { return *this += -a; }
    Mint operator/=(const Mint &a) { return *this *= a.inv(); }

    Mint operator++() { return *this += Mint(1); }
    Mint operator--() { return *this -= Mint(1); }
    Mint operator++(int) {
        Mint ret = *this;
        ++(*this);
        return ret;
    }
    Mint operator--(int) {
        Mint ret = *this;
        --(*this);
        return ret;
    }

    operator long long() const { return val; }
};

Mint operator+(const Mint &a, const Mint &b) {
    long long ret = a.val + b.val;
    if (ret >= Mint::mod) ret -= Mint::mod;
    return Mint(ret);
}
Mint operator*(const Mint &a, const Mint &b) {
    long long ret = a.val * b.val;
    if (ret >= Mint::mod) ret %= Mint::mod;
    return Mint(ret);
}
Mint operator-(const Mint &a, const Mint &b) { return a + (-b); }
Mint operator/(const Mint &a, const Mint &b) { return a * b.inv(); }

std::ostream &operator<<(std::ostream &out, const Mint &a) { return out << a.val; }
std::istream &operator>>(std::istream &in, Mint &a) {
    in >> a.val;
    a.verify_value();
    return in;
}

Mint pow(Mint a, long long b) {
    return a.pow(b);
}


int main() {
    int n, k; std::cin >> n >> k;
    std::vector<std::vector<int>> edg(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; std::cin >> a >> b;
        a--; b--;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    auto func = [&](auto &self, int pos = 0, int prev = -1) -> Mint {
        Mint f = k - 1 - (pos != 0);
        Mint ret = 1;
        for (int v : edg[pos]) {
            if (v == prev) continue;
            ret *= f;
            ret *= self(self, v, pos);
            f--;
        }
        return ret;
    };
    std::cout << func(func)*Mint(k) << std::endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;

pair<int, int> e[1000][1000] = {};
int ein[1000][1000] = {};
int d[1000][1000] = {};

void solve() {
	int n; cin >> n;
	queue<pair<pair<int, int>, int>> q;
	rep(i, n) {
		int a[999]; rep(i, n - 1) { cin >> a[i]; a[i]--; }
		rep(j, n - 1) {
			int b = i, c = a[j]; if (b > c)swap(b, c);
			if (j == 0) {
				q.push({ {b, c}, 1 });
			}
			else {
				e[i][a[j - 1]] = { b, c };
			}
			ein[b][c]++;
		}
	}

	int maxD = 0;
	while (!q.empty()) {
		pair<pair<int, int>, int> P = q.front(); q.pop();
		pair<int, int> p = P.first;
		if (p.first == p.second) continue;

		int &EIN = ein[p.first][p.second];
		int &D = d[p.first][p.second];
		pair<int, int> &E1 = e[p.first][p.second], &E2 = e[p.second][p.first];

		EIN--;
		if (EIN < 0) { cout << -1 << endl; return; }
		D = max(D, P.second);

		if (EIN == 0) {
			q.push({ E1, D + 1 });
			q.push({ E2, D + 1 });
			maxD = max(maxD, D);
		}
	}

	rep(i, n) rep(j, n){
		if (ein[i][j] != 0) {
			cout << -1 << endl;
			return;
		}
	}

	cout << maxD << endl;
}

int main() {

	solve();

	return 0;
}


Measured memory_bytes: 15872
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());
        int C = Integer.parseInt(st.nextToken());
        int counter = 0;
        int[] B = new int[M];
        st = new StringTokenizer(br.readLine());
        for (int i=0; i<M; i++) {
            B[i] = Integer.parseInt(st.nextToken());
        }
        for (int i=0; i<N; i++) {
            st = new StringTokenizer(br.readLine());
            int[] temp = new int[M];
            for (int j=0; j<M; j++) {
                temp[j] = Integer.parseInt(st.nextToken());
            }
            int total = 0;
            for (int j=0; j<M; j++) {
                total += temp[j]*B[j];
            }
            total += C;
            if (total > 0) counter ++;
        }
        System.out.println(counter);
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, 0, n) {
    int a;
    cin >> a;
    mp[a]++;
  }

  int eve = 0;
  for (auto m : mp)
    if (m.second % 2 == 0)
      eve++;

  int subs = 0;
  if (eve & 1)
    subs = 1;

  cout << mp.size() - subs << endl;
}


Measured memory_bytes: 4992
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int N;
bool a[200001];
int ans;

int M = 0;//ボールを入れる箱の個数
bool b[200001];//i番目の箱にボールが入っていればtrue

void solve(){
	int r_N = (int)(sqrt(N));
	for(int i=N;i>=1;i--){
		int sumup = 0;
		for(int j=2;j<=N;j++){ 
			if(i*j>N) break;
			sumup+=b[i*j];
			//cout << i*j << ' ' <<  sumup << ' ' << endl;
		}
		b[i] = (sumup+a[i])%2;
		M+=b[i];
		//cout << "b[" << i << "]:" << b[i] << "  a[" << i << "]:" << a[i] << endl; 
		if((b[i]+sumup)%2!=a[i]){
			M = -1;
			break;
		}
	}
}

void output(){
	if(M<=0){
		cout << M;
		return;
	}else{
		cout << M << endl;
		for(int i=1;i<=N;i++){
			if(b[i]){
				if(M==1){
					cout << i << endl;
				}else{
					cout << i << ' ';
					M--;
				}
			}
		}
	}
}

int main(){
	cin >> N;
	for(int i=1;i<=N;i++) cin >> a[i];

	solve();

	output();
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    int n; cin >> n;
    ll a, b; cin >> a >> b;
    vll x(n);
    rep(i,n) cin >> x[i];
    ll ans = 0;
    rep(i,n-1) {
        if ((x[i+1]-x[i])*a < b) ans += (x[i+1]-x[i])*a;
        else ans += b;
    }
    cout << ans << endl;
}

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

int main(){
	int a, b, c;
	cin>>a>>b>>c;

	int cnt = 0;
	for(int x = a; x <=b; x++){
		if(c % x == 0) cnt++;
	}

	cout<<cnt<<endl;

	return 0;
}


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

int main(void){
    int h, w;
    cin >> h >> w;
    char pic[h][w] = {}, pic2[h][w]={};
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w;j++){
            cin >> pic[i][j];
            pic2[i][j] = pic[i][j];
        }
    }
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cout << pic[i][j];
        }
        cout << endl;
        for (int k = 0; k < w; k++){
            cout << pic2[i][k];
        }
        cout << endl;
    }
        return 0;
}

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

long long cnt=1;

int main()
{
	long long h,ans=0;
	cin>>h;
    while(h>0)
    {
    	ans+=cnt;
		h=h/2;
    	cnt=cnt*2;
    }
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#import<iostream>
#define ll long long
int main() {
	ll N, X, p = 0;
	std::cin >> N >> X;
	for (ll i = (ll)(1 << N / 2) * (1 << (N + 3) / 2);i > 0;i /= 2, --X) {
      	if (X + 1 >= i) {
			p |= i / 2;
			X -= i - 2;
		}
	}
	std::cout << p;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

const INF: i64 = 1 << 50;

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    m: usize,
    l: i64,
    es: [(usize1, usize1, i64); m],
    q: usize,
    qs: [(usize1, usize1); q],
  }
  let mut dist = vec![vec![INF; n]; n];
  for i in 0 .. n {
    dist[i][i] = 0;
  }
  for &(a, b, c) in &es {
    dist[a][b] = c;
    dist[b][a] = c;
  }
  for k in 0 .. n {
    for i in 0 .. n {
      for j in 0 .. n {
        dist[i][j] = cmp::min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  let mut times = vec![vec![INF; n]; n];
  for i in 0 .. n {
    for j in 0 .. n {
      if dist[i][j] <= l {
        times[i][j] = 1;
      }
    }
  }
  for k in 0 .. n {
    for i in 0 .. n {
      for j in 0 .. n {
        times[i][j] = cmp::min(times[i][j], times[i][k] + times[k][j]);
      }
    }
  }
  for &(s, t) in &qs {
    if times[s][t] < INF {
      puts!("{}\n", times[s][t] - 1);
    } else {
      puts!("-1\n");
    }
  }
}


Measured memory_bytes: 10620
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
namespace {

	void chmin(long& x, long y)
	{
		if (x > y || x < 0)
			x = y;
	}

	void chmax(long& x, long y)
	{
		if (x < y)
			x = y;
	}

	void core()
	{
		long N;
		cin >> N;

		std::vector<long> a(N + 1, 0);
		std::vector<long> b(N + 1, 0);
		std::vector<long> c(N + 1, 0);

		for (long i = 1; i <= N; ++i)
		{
			cin >> a[i];
			cin >> b[i];
			cin >> c[i];
		}

		vector<vector<long>> dp(N + 1, vector<long>(3, -1));

		dp[1][0] = a[1];
		dp[1][1] = b[1];
		dp[1][2] = c[1];

		for (long i = 2; i <= N; ++i)
		{
			chmax(dp[i][0], dp[i - 1][1] + a[i]);
			chmax(dp[i][0], dp[i - 1][2] + a[i]);

			chmax(dp[i][1], dp[i - 1][0] + b[i]);
			chmax(dp[i][1], dp[i - 1][2] + b[i]);

			chmax(dp[i][2], dp[i - 1][0] + c[i]);
			chmax(dp[i][2], dp[i - 1][1] + c[i]);
		}

		long ret = -1;
		for (long i = 0; i < 3; ++i)
			ret = max(ret, dp[N][i]);

		cout << ret;
	}
}

int main()
{
	core();
	return 0;
}

Measured memory_bytes: 8064
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	if a >= b {
		fmt.Println(strings.Repeat(strconv.Itoa(b), a))
	} else {
		fmt.Println(strings.Repeat(strconv.Itoa(a), b))
	}
}


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

using namespace std;

const int N = 1000 + 7;
int n, m, d[N], p[N];
vector <int> g[N], inv[N];

vector <int> get(int a)
{
    if (d[a] == 0)
    {
        return {a};
    }
    else
    {
        vector <int> b = get(p[a]);
        b.push_back(a);
        return b;
    }
}

vector <int> sol;

void bfs(int boss)
{
    for (int i = 1; i <= n; i++)
    {
        d[i] = -1;
    }
    d[boss] = 0;
    queue <int> q;
    q.push(boss);
    while (!q.empty())
    {
        int a = q.front();
        q.pop();
        for (auto &b : g[a])
        {
            if (d[b] == -1)
            {
                d[b] = 1 + d[a];
                p[b] = a;
                q.push(b);
            }
        }
    }
    for (auto &a : inv[boss])
    {
        if (d[a] != -1 && (sol.empty() || d[a] + 1 < (int) sol.size()))
        {
            sol = get(a);
        }
    }
}

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

    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        inv[b].push_back(a);
    }

    for (int i = 1; i <= n; i++)
    {
        bfs(i);
    }

    if (sol.empty())
    {
        cout << "-1\n";
    }
    else
    {
        cout << (int) sol.size() << "\n";
        for (auto &a : sol)
        {
            cout << a << "\n";
        }
    }

    return 0;
}


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

int main() {
  int A;
  cin >> A;
  int a;
  int b;
  int c;
  int d;
  a = A / 1000;
  b = A % 1000 / 100;
  c = A % 100 / 10;
  d = A % 10;
  
  if ((a==b && b==c) || (b==c && c==d)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int num1[4]={0,3,5,7};

int makenum(int i);
int hantei(int num);

int pow(int a,int b){
    int num=1;
    for(int i=0;i<b;i++){
        num *= a;
    }
    return num;
}

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

    int i=0;
    int result =0;
    int X=0;
  	if(N>777777753)N=777777753;
    while(X<=N){
        X = makenum(i);
        //cout << X << endl;
        if(hantei(X)==1 && X<=N){result++;if(X>777777753)cout << X <<endl;}
        i++;
    }
    cout << result << endl; 
}

int makenum(int i){
    int num=0;
    int count=0;
    while(i>0){
        int x = i%4;
        i = i/4;
        num += num1[x]*pow(10,count);
        count++;
    }
    return num;

}


int hantei(int num){
    string N = to_string(num);
    int no=0;
    int yes3,yes5,yes7;
    yes3=yes5=yes7=0;
    for(int i=0;i<N.size();i++){
        if(N[i]!=3+'0' && N[i]!=5+'0' &&N[i]!=7+'0'){no++;break;}
        else if(N[i]==3+'0')yes3++;
        else if(N[i]==5+'0')yes5++;
        else if(N[i]==7+'0')yes7++;
    }

    if(no==0 && yes3>0 && yes5>0 && yes7>0){return 1;}
    else return 0;
}

Measured memory_bytes: 256
'use strict';

function Main(input) {
    input = input.split("\n");
    let tmp = input[0].split(" ");

    if (tmp == "A") {
        console.log("T");
        return 0;
    }
    if (tmp == "T") {
        console.log("A");
        return 0;
    }
    if (tmp == "C") {
        console.log("G");
        return 0;
    }
    if (tmp == "G") {
        console.log("C");
        return 0;
    }

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 19912
str = input()
Q = int(input())
left = []
right = []
flag = 1
for _ in range(Q):
    line = input().split()
    op1 = int(line[0])
    if op1 == 1:
        flag = -flag
    else:
        op2 = int(line[1])
        char = line[2]
        if (op2 == 1 and flag == 1) or (op2 == 2 and flag == -1) :
            left.append(char)
        else:
            right.append(char)

if flag == -1:
    right.reverse()
    str = str[::-1]
    str = "".join(right) + str
    str += "".join(left)
else:
    left.reverse()
    str = "".join(left) + str
    str += "".join(right)

print(str)


Measured memory_bytes: 5748
import sys

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


def main():
    N, T, *AB = map(int, read().split())
    D = [(a, b) for a, b in zip(*[iter(AB)] * 2)]

    D.sort()
    A, B = zip(*D)

    dp = [[0] * T for _ in range(N + 1)]
    for i in range(N):
        for t in range(T):
            if 0 <= t - A[i]:
                dp[i + 1][t] = dp[i][t - A[i]] + B[i]
            if dp[i + 1][t] < dp[i][t]:
                dp[i + 1][t] = dp[i][t]

    ans = 0
    for i in range(N):
        tmp = dp[i+1][T - 1] + max(B[i + 1 :], default=0)
        if ans < tmp:
            ans = tmp

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main(){
    int N;
    cin >> N;
    int x,y,z;
    bool c=true;
    int count = 0;
    for(int n=1;n<=N;n++){
        for(int x=1;x<n;x++){
            for(int y=1;y<n;y++){
                double k = n-x*x-y*y-x*y;
                if(k<=0){
                    break;
                }
                double s = x + y;
                double ans = -(s/2)+sqrt((s*s/4)+k);
                //cout << ans  << ((s*s/4)+k) << "ans" << endl;
                int ansche = ans;
                //cout << ans << ansche  << "che" << endl;
                if(ans-ansche == 0){
                    count++;
                }
            }
        }
        cout << count << endl;
        count = 0;
    }
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] h = new int[n];
	for (int i=0; i<n; i++) h[i] = sc.nextInt();
	boolean can = true;
	h[0]--;
	for (int i=1; i<n; i++) {
	    if (h[i] < h[i-1]) {
		can = false;
		break;
	    } else if (h[i] == h[i-1]) {
	    } else {
		h[i]--;
	    }
	}
	if (can) System.out.print("Yes");
	else { System.out.print("No"); }
    }
}


Measured memory_bytes: 59024