akhauriyash/Code-Regression huggingface dataset:
N = int(input())
_L = list(map(int,input().split()))

L =[(v,i) for i,v in enumerate(_L)]
L = sorted(L,key = lambda x:(-x[0],x[1]))

dp = [[0]*(N+1) for _ in range(N+1)]

for i in range(N):#i番目の数字まで見た
    for k in range(N):#k回(i-pi)のパターン
        if k>i:
            continue
        val,ind = L[i]
        dp[i+1][k+1] = max(dp[i+1][k+1],dp[i][k] + val * abs(ind-k))#先頭からk番目に動かす
        dp[i+1][k] = max(dp[i+1][k],dp[i][k]+val * abs(N-1-(i-k)-ind))#すでに後ろからi-k個は使ってる=>後ろからN- (i-k)+1番目に動かす
print(max(dp[-1]))




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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
using mint = Fp<MOD>;

int main() {
  int S; cin >> S;
  vector<mint> dp(S + 1); dp[0] = 1;
  for(int i = 1; i <= S; ++i) {
    for(int k = 0; k <= i - 3; ++k) {
      dp[i] += dp[k];
    }
  }
  cout << dp[S] << endl;
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  ll h,w;cin>>h>>w;
  ll ans=min(h,w);
  if(h%3==0||w%3==0){
    cout<<0<<endl;return 0;
  }
  rep(i,1,h/2+1){
    ll tate=max(h-i,i),yoko=w/2;
    ll s1=tate*yoko,s2=tate*(w-yoko),s3=(h-tate)*w;
    ll smax=max(s1,max(s2,s3)),smin=min(s1,min(s2,s3));
    ans=min(ans,smax-smin);
    
  }
  rep(i,1,w/2+1){
    ll tate=h/2,yoko=max(w-i,i);
    ll s1=tate*yoko,s2=(h-tate)*yoko,s3=h*(w-yoko);
    ll smax=max(s1,max(s2,s3)),smin=min(s1,min(s2,s3));
    ans=min(ans,smax-smin);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3620
/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n; cin>>n;
    vector<ll> a(n);
    for(ll &i : a)
        cin>>i;
    vector<vector<int>> table(63, vector<int> (n));
    for(int bit = 0; bit < 63; bit++){
        for(int i = 0 ; i < n; i++){
            table[bit][i] = ((a[i]&(1LL<<bit)) > 0);
        }
    }
    auto add = [&](ll &a, ll b){
        a = (a + b)%mod1;
    };
    ll ans = 0;
    for(int bit = 0; bit < 63; bit++){
        ll x = count(table[bit].begin(), table[bit].end(),0);
        ll y = n - x;
        add(ans, (1LL<<bit)%mod1*y%mod1*x%mod1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 80528
// Problem : D - Friends
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 	
int mod=1e9+7;
int po(int x,int y,int m)  { if (y==0) return 1; int t=po(x,y/2,m)%m; t=(t*t)%m; if (y&1) return (t*x)%m;	return t%m; }

vector<vector<int>> v(1000001);
vector<int> vis(1000001);

void dfs(int src,int count){
	vis[src]=count;
	for (auto it:v[src]){
		if (vis[it]==0)
			dfs(it,count);
	}
}

signed main() {

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	int n,m;
   	cin>>n>>m;
   	for (int i=0;i<m;++i){
   		int x,y;
   		cin>>x>>y;
   		v[x].push_back(y);
   		v[y].push_back(x);
   	}
   	int count=1;
   	for (int i=1;i<=n;++i){
   		if (vis[i]==0){
   			dfs(i,count);
   			count++;
   		}
   	}
   	map<int,int> ma;
   	for (int i=1;i<=n;++i)
   		ma[vis[i]]++;
   	int ans=0;
   	for (auto it:ma)
   	{
   		if (it.first==0)
   			continue;
   		ans=max(ans,it.second);
   	 }
   cout<<ans<<endl;
   	return 0;
}

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

bool chk(string s){
    if(s.size()<=1) return true;
    int l=s.size()/2;

    for(int i=0;i<l;i++){
        if(s[i]!=s[s.size()-1-i]) return false;
    }
    return true;
}

int abs(int a){
    return a>0?a:(-a);
}

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

    int ans=0;
    int l=0,r=s.size()-1;
    while(l<r){
        if(s[l]==s[r]){
            l++;
            r--;
        }else{
            if(s[l]=='x'){
                l++;
                ans++;
            }else if(s[r]=='x'){
                r--;
                ans++;
            }else{
                cout << "-1" << endl;
                return 0;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
//周♂雨扬是最强的！！！
//大佬祝您AK
//沈哲♂贝是最强的！！！
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<fstream>
using namespace std;
int n,tong[100003];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int num;
		cin>>num;
		tong[num]++,tong[num-1]++,tong[num+1]++;
	}
	int ans=0;
	for(int i=1;i<=100000;i++){
		ans=max(ans,tong[i]);
	}
	cout<<ans<<endl;
	return 0;
}
/*

in:
7
3 1 4 1 5 9 2

out:
4

*/
//沈♂哲贝是最强的！！！
//大佬祝您AK
//周♂雨扬是最强的！！！

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

int main() {
	int n=0,dup=0;
    cin >> n;
	vector<int> d(n);
    for(int i=0; i<n; i++)cin >> d.at(i);
    for(int i=0; i<n; i++){
     	for(int j=i+1; j<n; j++){
          if(d.at(i)==d.at(j)) d.at(j)=0;
        }
    }
  	for(int i=0; i<n; i++){
      if(d.at(i) == 0)dup++;
    }
	cout << n-dup << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {
	int n;
	int a[101] = { 0 };
	int i, j, v, k;

	scanf("%d", &n);

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

	for (i = 0; i < n; i++) {
		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
			a[j + 1] = v;
		}
		for (k = 0; k < n; k++) {
			printf("%d", a[k]);
			if (k < n - 1) {
				printf(" ");
			}
		}
		printf("\n");
	}


	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
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; }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<30;
const int MOD = 1000000007;

void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

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

using Edge = pair<int, ll>;
using Graph = vector<vector<Edge> >;

void rec(const Graph &G, int v, int p, ll sum, vector<ll> &dist){
  dist[v] = sum;
  for(auto e : G[v]){
    if(e.first == p) continue;
    rec(G, e.first, v, sum+e.second, dist);
  }
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
  	int N;
    cin >> N;
    Graph G(N);
    rep(i,N-1){
      int a,b; ll c; cin >> a >> b >> c;
      --a,--b;
      G[a].push_back({b,c});
      G[b].push_back({a,c});
    }
    int Q, K; cin >> Q >> K; --K;
    vector<ll> dist(N, 0);
    rec(G,K,-1,0,dist);

    rep(q,Q){
      int x,y;
      cin >> x >> y;
      --x,--y;
      cout << dist[x] + dist[y] << endl;
    }
}


Measured memory_bytes: 17408
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0101&lang=jp
"""
import sys


def solve(data):
    result = data.replace('Hoshino', 'Hoshina')
    return result


def main(args):
    num = int(input())
    for _ in range(num):
        data = input()
        result = solve(data)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7600
if __name__ == '__main__':

    n,k = map(int,input().split())
    A = [0]
    AA= list(map(int,input().split()))
    A = A + AA

    B = set()
    cnt = 0
    ind = 1
    startind = 0
    D = []
    while True:
        if A[ind] not in B:
            B.add(ind)
            D.append(ind)
            cnt += 1
            ind = A[ind]
        else:
            B.add(ind)
            D.append(ind)
            cnt += 1
            startind = A[ind]
            break

    C = set()
    ind = startind
    ANS = []
    while True:
        if A[ind] not in C:
            C.add(ind)
            ind = A[ind]
            ANS.append(ind)
        else:
            C.add(ind)
            ANS.append(A[ind])
            break

    if k >= cnt:
        tmp = k - cnt
        tmp = tmp % (len(C))
        print(ANS[tmp-1])
    else:
        print(D[k])
    

Measured memory_bytes: 44908
/* 
 * Project: AtCoder Beginners Contest 156 B - Digits
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/20
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <vector>
using namespace std;

int n;
int k;

void solve() {

    vector<char> t;
    int q;
    // int rem;
    int cnt = 0;
    while (n) {
        q = n / k;
        // rem = n % k;
        // t.push_back((char)(rem + '0'));
        n = q;
        cnt++;
    }
    printf("%d\n", cnt);
    return;
}

int main() {

    scanf("%d", &n);
    scanf("%d", &k);

    solve();

}

Measured memory_bytes: 3108
def solve(N, K, Hs):
    Hs.sort()
    return min([b - a for (a, b) in zip(Hs[:], Hs[K - 1:])])


if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    Hs = [int(input()) for _ in range(N)]
    print(solve(N, K, Hs))


Measured memory_bytes: 12748
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn count_divisor(n: i32) -> i32 {
    let mut count = 0;
    for i in 1..n {
        if i * i > n {
            break;
        }
        if n % i == 0 {
            count += 1;
            if i != n / i {
                count += 1;
            }
        }
    }
    count
}

fn main() {
    let n: i32 = read();
    let mut cnt = 0;
    for i in 1..n+1 {
        if i % 2 == 1 && count_divisor(i) == 8 {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 128
char s[N];
ll dp[N][2][4] = {};

int main(){
	int kk; scanf("%s%d", s, &kk); int n = strlen(s);
	dp[0][0][0] = 1;
	REP(i, n){
		REP(j, 2){
			REP(k, 4){
				DEBUG("dp[%d][%d][%d] = %lld\n", i, j, k, dp[i][j][k]);
				// use 0
				int jj = j;
				if(s[i] > '0') jj = 1;
				dp[i+1][jj][k] += dp[i][j][k];
				DEBUG(" [%d][%d][%d] => [%d][%d][%d]\n", i, j, k, i+1, jj, k);
				if(k + 1 < 4){
					if(j){
						dp[i+1][1][k+1] += 9 * dp[i][j][k];
						DEBUG(" [%d][%d][%d] * 9 => [%d][%d][%d]\n", i, j, k, i+1, 1, k+1);
					}else if(s[i] > '0'){
						// use non-zero, less
						dp[i+1][1][k+1] += (s[i] - '0' - 1) * dp[i][j][k];
						DEBUG(" [%d][%d][%d] * %d => [%d][%d][%d]\n", i, j, k, (s[i] - '0' - 1), i+1, 1, k+1);
						// use non-zero, equal
						dp[i+1][j][k+1] += dp[i][j][k];
						DEBUG(" [%d][%d][%d] => [%d][%d][%d]\n", i, j, k, i+1, j, k+1);
					} 
				}
			}
		}
	}
	printf("%lld\n", dp[n][0][kk] + dp[n][1][kk]);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
signed main() {
	int p = 1, n, m; cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int l, r; cin >> l >> r;
		p = max(p, l);
		n = min(r, n);
	}
	cout << max(n - p + 1, 0) << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    int i,flag=0;
    for(i=0;i<s.size();i++) {
        if(i & 1) {
            if(s[i]!='L' && s[i]!='U' && s[i]!='D') {
                flag=1;
                break;
            }
        }
        else {
            if(s[i]!='R' && s[i]!='U' && s[i]!='D') {
                flag=1;
                break;
            }
        }
    }
    if(flag==0) {
        cout<<"Yes\n";
    }
    else {
        cout<<"No\n";
    }
    return 0;
}


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

using namespace std;
using ll = long long;

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

ll choose(ll n) {
  if (n <= 0) return 0;
  return n * (n - 1) / 2;
}

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

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

  ll mx = 0;
  for (auto p : mp) mx += choose(p.second);

  rep(i, n) {
    int k = mp[b[i]];
    ll ans = mx;
    ans -= choose(k) - choose(k - 1);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 8320
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll a[N],b[N],x;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>x,a[i]=x-i-1+N;
    sort(a,a+n);
    b[0]=a[0];
    for(int i=1;i<n;i++)
        b[i]=b[i-1]+a[i];
    ll ans=b[n-1]-a[0]*n;
    for(int i=1;i<n;i++)
        ans=min(ans,a[i]*(i-1)-b[i-1]+b[n-1]-b[i-1]-a[i]*(n-i-1));
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3328
#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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, A[6010];
int dp[2010][2010];
using tiii = tuple<int, int, int>;
int ma_row[2020];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N * 3) cin >> A[i];

	rep(i, 1, N + 1) rep(j, 1, N + 1) dp[i][j] = -inf;
	dp[A[0]][A[1]] = dp[A[1]][A[0]] = 0;
	rep(i, 1, N + 1) ma_row[i] = -inf;
	ma_row[A[0]] = ma_row[A[1]] = 0;

	int additionalPoint = 0;
	int ma = 0;

	rep(i, 0, N - 1) {
		int idx = i * 3 + 2;

		vector<int> nxt;
		rep(j, 0, 3) nxt.push_back(A[idx + j]);
		sort(all(nxt));

		if (nxt[0] == nxt[1] && nxt[1] == nxt[2]) {
			additionalPoint++;
			continue;
		}

		vector<tiii> changeQueue;
		rep(_a, 0, 3) rep(_b, 0, 3) if(_a != _b) {
			int a = nxt[_a], b = nxt[_b], c = (nxt[0] + nxt[1] + nxt[2] - a - b);

			// dp[i][x][y] -> dp[i + 1][x][a]
			rep(x, 1, N + 1) {
				int opt = -inf;
				//rep(y, 1, N + 1) chmax(opt, dp[x][y]);
				opt = ma_row[x];
				if (b == c) chmax(opt, dp[x][b] + 1);
				changeQueue.push_back(tiii(x, a, opt));
			}

			// dp[i][any][any] -> dp[i + 1][a][b]
			int ma2 = ma;
			chmax(ma2, dp[c][c] + 1);
			changeQueue.push_back(tiii(a, b, ma2));
		}

		fore(t, changeQueue) {
			int x, y, val;
			tie(x, y, val) = t;

			chmax(dp[x][y], val);
			chmax(dp[y][x], val);
			chmax(ma_row[x], val);
			chmax(ma_row[y], val);
			chmax(ma, val);
		}
	}

	int ans = 0;
	rep(x, 1, N + 1) rep(y, 1, N + 1) chmax(ans, dp[x][y] + ((x == y && x == A[N * 3 - 1]) ? 1 : 0));
	ans += additionalPoint;
	cout << ans << endl;
}







Measured memory_bytes: 19456
//Keep Working Hard
  // I__Like__Food  
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int mod = 1e9 + 7;
  const int mod2 = 998244353;
  const int N = 20005;
  const int INF = 1e16;
  const double PI = acos(-1);



int32_t main()
{
       

    IOS


    int n;
    cin >> n;

    int b[n];

    for(int i = 1; i <= n-1; i++)
    {
      cin >> b[i];
    }

    int ans = b[1] + b[n-1];

    for(int i = n-1; i >=2; i--)
    {
      ans += min(b[i],b[i-1]);
    }


    cout << ans;
    
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define allr(v) v.rbegin(),v.rend() 
//#define endl '\n'  
typedef  long long ll; 
typedef  unsigned long long ull; 
typedef vector< ll > edge; 
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
const ll mod=1e9+7;
const ll inf=1e15+10;
const ll N=1e6+10;

int main()
{
	boost;
	ll n,m;
	cin>>n>>m;
	std::vector<ll> a(m),dp(n+1);
	std::vector<bool> ok(n+1,1);
	for(auto &i:a) cin>>i;
	for(auto i:a) ok[i]=0;
	dp[0]=1;	
	for(ll i=1;i<=n;i++)
	{
		dp[i]=0;
		if(ok[i])
		{
			if((i-1)>=0 and ok[i-1]) dp[i]+=dp[i-1],dp[i]%=mod;
			if((i-2)>=0 and ok[i-2]) dp[i]+=dp[i-2],dp[i]%=mod;
		}

	}	
	cout<<dp[n];
  	return 0;
}  

Measured memory_bytes: 1792
#include <iostream>
#include<stack>
#include<vector>
using namespace std;
int main(void){
    int n ,i,DP[1001][1001],num,p,k,f[101][3],ptr=1,v;
    stack<int> s;
        cin>>n;
    for(i=1;i<=n;i++){
        cin>>p>>k;
        for(int j=1;j<=k;j++){
            cin>> num;
            DP[i][num]=1;
        }
    }
    for(i=1;i<=n;i++){
        DP[0][i]=1;
    }
    s.push(0);
    while(!s.empty()){
        v=s.top();
        for(int i=1;i<=n;i++){
            if(DP[v][i]==1&&f[i][0]==0){
                    s.push(i);
                    f[i][0]=1;
                    f[i][1]=ptr;
                    goto Exit;
            }
        }
        s.pop();
        f[v][2]=ptr;
        Exit:;
        ptr++;
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<f[i+1][1]<<" "<<f[i+1][2]<<endl;
    }
}




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

int main() {
  string S;
  cin >> S;
  
  if ( S == "AAA" ) {
    cout << "No" << endl;
  }
  
  else if ( S == "BBB" ) {
    cout << "No" << endl;
  }
  
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int i,j,x,y,n,m,a;
 
int main(void){
  int x_max = -100;
  int y_min = 100;
  scanf("%d %d %d %d",&n,&m,&x,&y);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if( x_max < a ) x_max = a;
  }
  for(i=0;i<m;i++){
    scanf("%d",&a);
    if( a < y_min  ) y_min = a;
  }
  
  if( x_max <  y_min && 
          x <  y_min &&
      x_max <  y      )printf("No War");
  else                 printf("War");
    
  return 0;
}

Measured memory_bytes: 128
# ALDS_10_A - フィボナッチ数

n = int(input())

dp = [0] * (n + 1)

for i in range(n + 1):
    if (i == 0) or (i == 1):
        dp[i] = 1
    else:
        dp[i] = dp[i - 1] + dp[i - 2]

print(dp[-1])
# print(dp)



Measured memory_bytes: 5600
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
using namespace std;
int main()
{
    int n, x;
    long long a[maxn] = {0};
    cin >> n >> x;
    long long  count = 0;
    for (int i = 0; i < n; i++)
        scanf("%lld", &a[i]);
    for (int i = 0; i < n - 1; i++)
    {
        if (a[i] > x)
        {
            count += (a[i] - x);
            a[i] = x;
        }
        if (a[i] + a[i+1] > x)
        {
            count += (a[i+1] + a[i] - x);
            a[i+1] = a[i+1] - (a[i+1] + a[i] - x);
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict

def solve():
    N, K = map(int, input().split())
    d = defaultdict(int)
    for _ in range(N):
        a, b = map(int, input().split())
        d[a] += b
        
    for k in sorted(d.keys()):
        K -= d[k]
        if K <= 0:
            return k
        
print(solve())

Measured memory_bytes: 10852
// mp.second を li に
#include<iostream>
#include<map>
using namespace std;
#define nC2(n) ((n)*((n)-1)/2)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
typedef long int li;

int main(){
  int n,m; cin >>n >>m;
  li s=0;
  li ans=0;
  map<int,li> mp; mp[0]=1;
  rep(i,n){
    int a; cin >>a;
    (s+=a)%=m;
    mp[s]++;
  }
  for(auto x: mp){
    ans+=nC2(x.second);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 4224
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        for(int i = 0; i < 100; i++){
            if(a <= i && i < b && c <= i && i < d){
                count++;
            }
        }
        System.out.print(count);
    }
}

Measured memory_bytes: 23124
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))
ans = -float('inf')
for s in range(N):
    scores = [0] * (N+1)
    i = P[s]
    v = scores[i] = C[i]
    l = 1
    while i != s:
        i = P[i]
        v += C[i]
        scores[i] = v
        l += 1
    i = P[s]
    c = 1
    ans = max(ans, scores[i], scores[i] + (K - c) // l * v)
    while i != s and c < K:
        i = P[i]
        c += 1
        ans = max(ans, scores[i], scores[i] + (K - c) // l * v)
print(ans)

Measured memory_bytes: 69872
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;

int main(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<int> x(N);
    vector<int> y(M);
    int tmp;

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

    int x_max = *max_element(x.begin(), x.end());
    int y_min = *min_element(y.begin(), y.end());

    if(x_max >= Y || y_min <= X){
        cout << "War" << endl;
        return 0;
    }

    if(x_max < y_min){
        cout << "No War" << endl;
        return 0;
    }else{
        cout << "War" << endl;
        return 0; 
    }
}

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

using namespace std;

using ll = long long;

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

    int maxA = *max_element(A.begin(),A.end());

    int maxcount = 0;

    for(int i=0;i<N;i++)
    {
        if(A.at(i) == maxA)
        {
            maxcount++;
        }
    }
    
    for(int i=0;i<N;i++)
    {
        if(maxcount < 2)
        {
            if(maxA == A.at(i))
            {
                vector<int> B = A;
                sort(B.begin(),B.end(),greater<int>());
                B.erase(B.begin());
                cout << B.at(0) << endl;
            }
            else
            {
                cout << maxA << endl;
            }
        }
        else
        {
            cout << maxA << endl;
        }
        
    }
    return 0;
}

Measured memory_bytes: 3200
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    int l = 1, r = n - 1;
    int cnt = 0;
    while( l < r ) {
        ++cnt;
        ++l; --r;

    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 892
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}




int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    map<ll, ll> mp;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
        mp[a[i]]++;
    }
    ll ans = 0;
    for(auto a : mp){
        ans += a.sc * (a.sc - 1) / 2;
    }
    rep(i, n){
        print(ans - (mp[a[i]] - 1));
    }

    

}


Measured memory_bytes: 12652
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    string S;
    cin >> S;
    if(S == "ARC"){
        fin("ABC");
    }else{
        fin("ARC");
    }
    return 0;
}

Measured memory_bytes: 3020
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
pii a[maxn];

int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		a[i].fi = x+y;
		a[i].se = x-y;
//		cout<<"->"<<x-y<<" "<<x+y<<endl;
	}
	sort(a+1,a+1+n);
	int ans = 0,cur = -1e9;
	for(int i=1;i<=n;i++){
		if(a[i].se>=cur){
			ans++;
			cur = a[i].fi;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"unicode/utf8"
)
var input = bufio.NewScanner(os.Stdin)

func get() int {
	input.Scan()
	s := input.Text()
	return utf8.RuneCountInString(s)
}

func main () {
	count := get()
	fmt.Printf("%s\n",strings.Repeat("x",count))
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> hoge(n);
    for (int i = 0; i < n; i++) cin >> hoge[i];
    vector<int> foo(n);
    for (int i = 0; i < n; i++){
        for (int j = 0;;){
            if (hoge[i] % 2 == 0){
                hoge[i] = hoge[i] / 2;
                j++;
                if (hoge[i] == 1){
                    foo[i] = j;
                    break;
                }
                
            }else{
                foo[i]=j;
                break;
            }
        }
    }
    sort(foo.begin(), foo.end());
    cout << foo[0] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
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 main(){
  ll a,b,c; cin >> a >> b >> c;
  if(4*a*b < (c-a-b)*(c-a-b) && 0 < c-a-b) cout << "Yes";
  else cout << "No";
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3636
using System;
using System.Linq;

class F
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

		if (n % 2 == 0)
		{
			var dp = new long[n + 5, 2];
			for (int i = 0; i <= n; i++)
				for (int j = 0; j < 2; j++)
					dp[i, j] = long.MinValue;
			dp[1, 1] = a[0];
			dp[2, 0] = a[1];

			for (int i = 0; i < n; i++)
				for (int j = 0; j < 2; j++)
				{
					if (dp[i, j] == long.MinValue) continue;
					if (i + 1 < n)
						dp[i + 2, j] = Math.Max(dp[i + 2, j], dp[i, j] + a[i + 1]);
					if (j > 0 && i + 2 < n)
						dp[i + 3, j - 1] = Math.Max(dp[i + 3, j - 1], dp[i, j] + a[i + 2]);
				}
			Console.WriteLine(Math.Max(dp[n - 1, 1], dp[n, 0]));
		}
		else
		{
			var dp = new long[n + 5, 3];
			for (int i = 0; i <= n; i++)
				for (int j = 0; j < 3; j++)
					dp[i, j] = long.MinValue;
			dp[1, 2] = a[0];
			dp[2, 1] = a[1];
			dp[3, 0] = a[2];

			for (int i = 0; i < n; i++)
				for (int j = 0; j < 3; j++)
				{
					if (dp[i, j] == long.MinValue) continue;
					if (i + 1 < n)
						dp[i + 2, j] = Math.Max(dp[i + 2, j], dp[i, j] + a[i + 1]);
					if (j > 0 && i + 2 < n)
						dp[i + 3, j - 1] = Math.Max(dp[i + 3, j - 1], dp[i, j] + a[i + 2]);
					if (j > 1 && i + 3 < n)
						dp[i + 4, j - 2] = Math.Max(dp[i + 4, j - 2], dp[i, j] + a[i + 3]);
				}
			Console.WriteLine(Math.Max(dp[n - 2, 2], Math.Max(dp[n - 1, 1], dp[n, 0])));
		}
	}
}


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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

const int MOD1=1000000007;
const int MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const int dx[]={0,1,0,-1,1,-1,1,-1};
const int dy[]={1,0,-1,0,1,1,-1,-1};

#define unless(a) if(!(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(n);i++)
#define bitrep(i,s,n) for(int i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}
long long cutup(long long a,long long b){return (a+b-1)/b;}
long long popcnt(long long a){return __builtin_popcountll(a);}
template<class T,class U> inline bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template<class T,class U> inline bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

struct edge{long long to,cost;};
struct edge2{long long from,to,cost;};

template<typename t>
constexpr t nCr(t n,int r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    if(r>n-r)r=n-r;
    t x=1;
    for(int i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vl C(5,0);
    rep(i,n){
        string s;
        cin>>s;
        if(s[0]=='M'){
            C[0]++;
        }
        if(s[0]=='A'){
            C[1]++;
        }
        if(s[0]=='R'){
            C[2]++;
        }
        if(s[0]=='C'){
            C[3]++;
        }
        if(s[0]=='H'){
            C[4]++;
        }
    }
    ll res=0;
    rep(i,3){
        rep2(j,i+1,4){
            rep2(l,j+1,5){
                res+=C[i]*C[j]*C[l];
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


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

	int kkt = 1;
	while (kkt--) {
		ll n; scanf("%lld", &n);
		map<string, multiset<ll>> mp;
		for (int i = 0; i < n; i++) {
			string s;
			ll d;
			cin >> s >> d;
			mp[s].emplace(d);
		}
		ll now = -INF;
		ll jupi; scanf("%lld", &jupi);
		while (jupi--) {
			string s; cin >> s;
			if (mp.find(s) == mp.end()) {
				puts("No");
				return 0;
			}
			auto& ms = mp[s];
			auto itr = ms.upper_bound(now);
			if (itr == ms.end()) {
				puts("No");
				return 0;
			}
			now = *itr;
			ms.erase(itr);
			if (ms.size() == 0) {
				mp.erase(s);
			}
		}
		puts("Yes");
	}
	return 0;

}



Measured memory_bytes: 25192
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }

    val n4 = a.filter { it % 4 == 0 }.count()
    val n2 = (a.filter { it % 2 == 0 }.count() - n4) / 2

    println(if (n4 + n2 >= n / 2) "Yes" else "No")
}


Measured memory_bytes: 53900
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

int INF=1e4;
int dist[15][15];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  while(cin>>n,n){
    fill(dist[0],dist[0]+15*15,INF);
    int m=0,a,b,d;
    rep(i,n){
      cin>>a>>b>>d;
      dist[a][b]=dist[b][a]=min(dist[a][b],d);
      m=max({m,a,b});
    }
    ++m;
    rep(i,m) dist[i][i]=0;
    rep(k,m) rep(i,m) rep(j,m)
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

    pii re=pii(INF,-1);
    rep(i,m){
      int sum=0;
      rep(j,m) sum+=dist[i][j];
      re=min(re,pii(sum,i));
    }
    //rep(i,m){rep(j,m)cout<<dist[i][j]<<",";cout<<endl;}
    cout<<re.Y<<" "<<re.X<<endl;
  }
  return 0;
}

Measured memory_bytes: 3160
import java.util.*;

public class Main {
  Scanner sc;
  
  static int M, T, P, R;
  void run() {
    while(true){
      M = ni();
      T = ni();
      P = ni();
      R = ni();
      if(M==0&&T==0&&P==0&&R==0)break;
      Team[] team = new Team[T];
      for(int i=0;i<T;i++){
        team[i] = new Team(i);
      }
      for(int i=0;i<R;i++){
        int m = ni();
        int t = ni();
        int p = ni();
        int j = ni();
        if(j==0){
          team[t-1].ans++;
          int tt = (team[t-1].submits[p-1])*20;
          team[t-1].time += (tt + m);
        }else{
          team[t-1].submits[p-1]++;
        }
      }
      Arrays.sort( team, new Comparator<Team>(){
        public int compare(Team t1, Team t2){
          if(t1.ans == t2.ans){
            if(t1.time == t2.time){
              return t2.number - t1.number;
            }else{
              return t1.time - t2.time;
            }
          }else{
            return t2.ans - t1.ans;
          }
        }
      });
//      for(Team tm : team)System.out.println(tm);
      System.out.print(team[0].number+1);
      for(int i=1;i<T;i++){
        if(team[i-1].ans == team[i].ans && team[i-1].time == team[i].time){
          System.out.printf("=%d", team[i].number+1);
        }else{
          System.out.printf(",%d", team[i].number+1);
        }
      }
      System.out.println();
    }
  }
  
  Main() {
    sc = new Scanner(System.in);
  }
  
  int ni() {
    return sc.nextInt();
  }
  
  public static void main(String[] args) {
    new Main().run();
  }
  
  void debug(Object... os) {
    System.err.println(Arrays.deepToString( os ));
  }
}
class Team{
  public int number;
  public int time;
  public int ans;
  public int[] submits;
  public Team(int number){
    this.number = number;
    submits = new int[Main.P];
    
  }
  public String toString(){
    return String.format("%2d, %4d, %2d, %s", number, time, ans, Arrays.toString(submits));
  }
}

Measured memory_bytes: 61836
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    K=input()
    D=I()
    N=len(str(K))
    
    #dp[i][j]はi桁目まで見て，総和のmodがj，tight&lose
    dpt=[[0]*D for _ in range(N+1)]
    dpl=[[0]*D for _ in range(N+1)]
    
    start=int(K[0])
    
    #初期化
    dpt[0][0]=1
            
    #推移
    now=0#tが0ではない位置
    
    for i in range(N):
        num=(int(K[i]))
        #t
        dpt[i+1][(now+num)%D]=1
        for k in range(num):
            dpl[i+1][(now+k)%D]+=1
        now=(now+num)%D
                    
        
        #l，尺取り
        S=0
        for j in range(10):#初期化，0~9までの和
            S+=dpl[i][j%D]
            
        for j in range(D):#あまりが10~D-1,0~9の順に配る
            dpl[i+1][(j+9)%D]+=S
            dpl[i+1][(j+9)%D]%=mod
            S+=dpl[i][(j+10)%D]-dpl[i][j%D]
        
                
    #0もカウントしているmので1ひく
    print((dpt[-1][0]+dpl[-1][0]-1)%mod)
    
    
            
    
    

main()


Measured memory_bytes: 58480
function f(N,A)
	dp=zeros(Int,N+1)
	dp[1]=1
	for a=A
		for i=1:N+1-a
			dp[i+a]+=dp[i]
		end
	end
	dp[N+1]
end
R,G,B,N=map(x->parse(Int,x),split(readline()))
println(f(N,[R,G,B]))

Measured memory_bytes: 109716
/*AOJ 0021*/

#include<iostream>
using namespace std;

class point_obj{
public:
	double x,y;
};

int main(){

	int n;
	point_obj p[4];


	cin>>n;

	for(int i=0;i<n;i++){

		for(int j=0;j<4;j++){
			cin>>p[j].x;
			cin>>p[j].y;
		}

		if( p[1].x - p[0].x == 0){
			if(p[3].x-p[2].x == 0){
				cout<<"YES"<<endl;
			}

			else{
				cout<<"NO"<<endl;
			}

		}

		else{
			double tmp0 = (p[1].y - p[0].y)/(p[1].x - p[0].x);
			if(p[3].x-p[2].x == 0){
				cout<<"NO"<<endl;
			}
			else{
				double tmp1 = (p[3].y - p[2].y)/(p[3].x-p[2].x);
				if(tmp0 == tmp1){
					cout<<"YES"<<endl;
				}
				else{
					cout<<"NO"<<endl;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0