akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = (0 until n).map { sc.next() }
    println(problem089b(n, s))
}

fun problem089b(n: Int, s: List<String>): String {
    val colorSet = hashSetOf<String>()
    for (i in 0 until n) {
        colorSet.add(s[i])
        if (colorSet.size == 4) return "Four"
    }
    return "Three"
}

Measured memory_bytes: 34116
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        int[] c = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
            c[i] = scanner.nextInt();
        }
        int res = vacation(N, a, b, c);
        System.out.println(res);
    }

    private static int vacation(int n, int[] a, int[] b, int[] c) {
        // subproblem:
        // s1(k) = max points of first k days ending with a
        // s2(k) = max points of first k days ending with b
        // s3(k) = max points of first k days ending with c
        // max{ s1(n), s2(n), s3(n) }

        // s*(0) = 0
        // s*(1) = a/b/c[0]
        // s1(k) = max{ s2(k-1), s3(k-1) } + a[k-1]
        // s2(k) = max{ s1(k-1), s3(k-1) } + b[k-1]
        // s3(k) = max{ s1(k-1), s2(k-1) } + c[k-1]
        int s1 = 0;
        int s2 = 0;
        int s3 = 0;
        for (int i = 0; i < n; i++) {
            int t1 = a[i] + Math.max(s2, s3);
            int t2 = b[i] + Math.max(s1, s3);
            int t3 = c[i] + Math.max(s1, s2);
            s1 = t1;
            s2 = t2;
            s3 = t3;
        }
        return Math.max(s1, Math.max(s2, s3));
    }
}


Measured memory_bytes: 92084
T_MAX = 10**5
n, nc = list(map(int, input().split()))
stc = [list(map(int, input().split())) for _ in range(n)]

recs = [[0]*(T_MAX+1) for c in range(nc+1)]
for s, t, c in stc:
    recs[c][s-1:t] = [1]*(t-s+1)

ans = max(map(sum, zip(*recs)))
print(ans)


Measured memory_bytes: 51704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int x, n;
    cin >> x >> n;
    set<int> s;
    for (int i=0; i<n; i++) {
        int y; cin >> y;
        s.insert(y);
    }

    int duh = 0;
    while (1) {
        if (!s.count(x-duh)) {
            cout << x-duh << "\n";
            break;
        } else if (!s.count(x+duh)) {
            cout << x+duh << "\n";
            break;
        }
        duh++;
    }
}


Measured memory_bytes: 3648
/*
    NO 
        TIME 
            TO 
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=1e9+7;
#define OS //single input use oeis
lli INF=1e17;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,z,k,x,m,d,y,q,b,c;
const double pi=3.14159265358979323846;
lli add(lli a, lli b) {
 	lli res = a + b;
 
 	while (res >= mod) res -= mod;
 
 	while (res < 0) res += mod;
 
 	return res;
}
 lli me(lli a,lli b)
{
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}
lli ans;
lli odd,eve;
void solve(lli n,lli k)
{
    if(k==0)
    {
        ans=n;
        return;
    }
    if(n&1)
    solve(n-1,k-1),odd++;
    else
    {
        solve(n/2ll,k-1);
        eve++;
    }
}
 
// double dp[100005];
lli dp[105][105];
int main()
{
 IO;
 OS;
 lli h,w;
 cin>>h>>w;
 char a[h+1][w+1];
 for(int i=1;i<=h;i++)
 {
     for(int j=1;j<=w;j++)
     cin>>a[i][j];
 }
 mem2(dp,1e15);
 if(a[1][1]=='.')
 dp[1][1]=0;
 else
 dp[1][1]=1;
 for(int i=1;i<=h;i++)
 {
     for(int j=1;j<=w;j++)
     {
         if(a[i][j]=='#')
         {
             if(i>1&&a[i-1][j]=='#')
             dp[i][j]=min(dp[i][j],dp[i-1][j]);
             else if(i>1)
             dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
             
             if(j>1&&a[i][j-1]=='#')
             dp[i][j]=min(dp[i][j],dp[i][j-1]);
             else if(j>1)
             dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
         }
         else
         {
             if(i>1)
             dp[i][j]=min(dp[i][j],dp[i-1][j]);
             
             
             if(j>1)
             dp[i][j]=min(dp[i][j],dp[i][j-1]);
             
         }
     }
 }
 
 cout<<dp[h][w];
 
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n,k;
  cin >> n >> k;
  int ans = 0;
  for(int i = k+1;i <= n;i++){
    int syou = n/i;
    int amari = n%i;
    if((i-1) >= k) ans += ((i-1) - k+1)*syou;
    if(amari >= k) ans += amari - k+1;
  }
  if(k != 0) cout << ans << endl;
  else{
    ans = pow(n,2);
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b;scanf("%d%d",&a,&b);
	int d=0;
	for(int i=0;i<b;i++){
		int c;scanf("%d",&c);
		d=max(d,c);
	}
	printf("%d\n",max(0,d-(a-d)-1));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int mi = a[0],now;
    while(1){
        now = mi;
        for(int i = 0; i < n; i++){
            if(a[i]%mi != 0){
                mi = min(mi,a[i]%mi);
            }
        }
        if(now == mi) break;     

    }
    /*
    for(int i = n-2; i >= 0; i--){
        int b = a[i+1]%mi;
        if(b != 0) mi = min(mi,b);
    }*/
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    char ch[2] = {'-', '+'};
    string s;
    cin >> s;
    int a[4];
    for (int i = 0; i < 4; i++) {
        a[i] = s[i] - '0';
    }

    for (int i = 0; i < 8; i++) {
        int tmp = i;
        int res = a[0];
        string ss = "";
        ss += s[0];
        for (int j = 1; j <= 3; j++) {
            if (tmp % 2 == 0) {
                res += a[j];
                ss += '+';
                ss += s[j];
            } else {
                res -= a[j];
                ss += '-';
                ss += s[j];
            }
            tmp /= 2;
        }

        if (res == 7) {
            cout << ss << "=7" << endl;
            return 0;
        }
    }

    return 0;
}


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

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

const double EPS = 1e-10;

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



int main(){
    int N,K; cin >> N >> K;
    vector<int> H(N);
    rep(i,N) cin >> H[i];
    sort(H.rbegin(),H.rend());
    rep(i,min(N,K)){
        H[i] = 0;
    }
    ll ans = 0;
    repr(i,min(N,K),N) ans += H[i];
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
	int x[6];
	for (int i = 1; i <= 5; ++i) cin >> x[i];
	for (int i = 1; i <= 5; ++i) {
		if (!x[i]) cout << i << '\n';
	}
	return 0;
}

Measured memory_bytes: 3592
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
int A,B;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>A>>B;
	cout<<((A<=9&&B<=9)?A*B:-1)<<endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {
    let a: i32 = read();
    if a%2==0 {
	println!("{}",a/2-1);
    }else {
	println!("{}",a/2);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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 ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   double p = N / 2 + N % 2 * 1;
   cout << p / (double)N << endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for((int) (i)=0;(i)<(int)(n);(i)++)
#define mp make_pair
#define pb push_back
using namespace std;
int k,x;
int main(){
	cin>>k>>x;
	for(int i=x-k+1;i<=x+k-1;i++)
	cout<<i<<" ";
	return 0;
}


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

#define INF (1e+18)

int main() {

    long long a, b, c;
    long long k;

    cin >> a >> b >> c >> k;

    long long sub = a - b;
    if(llabs(sub) >= INF) cout << "Unfair" << endl;
    if(k % 2) cout << -sub << endl;
    else cout << sub << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int z = gcd(sc.nextInt(), sc.nextInt());
        System.out.println(z);
        sc.close();
    }

    private static int gcd(int x, int y) {
        if (x == 0) return y;
        return gcd(y % x, x);
    }
}



Measured memory_bytes: 26344
#include <bits/stdc++.h>
#define int long long
#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++)
using namespace std;
signed main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int mn = a[0];
    int mv = -1000000000;
    rep2(i,1,n){
        mv = max(mv, a[i]-mn);
        mn = min(mn, a[i]);
    }
    cout << mv << endl;
    return 0;
}


Measured memory_bytes: 4432
#include<bits/stdc++.h>
using namespace std;
main()
{
    int a,b,i,j,k,l;
    cin>>l>>a>>b;
    for(i=a;i<=b;i++)
    {
        if(i%l==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }
       // cout<<i<<endl;
    }
    cout<<"NG"<<endl;
    return 0;
}


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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

signed main()
{
  int n = in();
  vi p(n);

  rep(i, n * (n - 1) / 2) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c > d) p[a - 1] += 3;
    else if (c < d) p[b - 1] += 3;
    else p[a - 1]++, p[b - 1]++;
  }
  int log = 0, rank = 0, cnt = 0;
  vector<pair<int, int>> vp;
  rep(i, n) vp.pb(mp(p[i], i + 1));
  sort(all(vp));
  reverse(all(vp));
  vector<pair<int, int>> rankv;
  rep(i, n) {
    if (vp[i].fst == log) {
      rankv.pb(mp(vp[i].sec, rank));
      cnt++;
    }
    else {
      rank += cnt;
      rankv.pb(mp(vp[i].sec, ++rank));
      log = vp[i].fst;
      cnt = 0;
    }
  }
  sort(all(rankv));
  rep(i, n) print(rankv[i].sec);

  return (0);
}

Measured memory_bytes: 3204
#【ABC 085-C】解答例コード・解説コメント

N, Y = map(int, input().split())

a = 0

#【註】全体の枚数が N 枚の時、それぞれのお札がとる可能性のある枚数は 0 枚～ N 枚のいずれかです。
# そのため、for 文は range(N+1)で回すようにし、i や ii が 0 枚～N 枚のいずれかを取るように
# しなければなりません（range(N) だと、0 枚～N-1 枚になってしまいます）。
for i in range(N+1):

    #【註：★１】ここで、10000 円札が i 枚のとき、5000 円札の枚数は N-i 枚以下となりますから、
    # i と ii の合計だけで N を超えてしまうことが無いよう、予め N+1 - i 枚分だけループを回すように
    # しておくことで、実行時間の節約やバグの抑止につなげることが可能です。
    # なお、この ★１ と後述する ★２ は、いずれかの付記を行えば問題ありません。
    for ii in range(N+1 - i):

        #【註】最高 N 回 ^3 の三重ループは、実行時間制限（2秒）の中に収めることは難しいです。
        # そのため、「お札の合計枚数が N 枚」であり、10000 円札が i 枚、5000 円札が ii 枚となったとき、
        # 条件を満たす 1000 円札の枚数は (N - i - ii) 枚のただ一通りに限られることを利用して
        # そのケースが条件を満たすかどうかを検証します。
        iii = N - i - ii

        #【註：★２】もし ★１ の修正を行わない場合でも、このように「計算した iii ：1000 円札の枚数」が
        # 負の枚数にならないかどうかを確認し、負になったら break を挟んで次の　i を見るようにするだけで、
        # ★1 の処理と同等の処理を行うことが可能です。
        # この ★１、もしくは ★２ の処理は、最終的なそれぞれのお札の枚数が負にならず、また i + ii + iii の合計
        # 枚数が N を超えないことを保証するために設けているものとなります。
        if iii < 0:
            break

        #【註】これ以降の計算、および最終的にループを抜ける処理の形については、
        # お送りいただいたコードをそのまま利用しております。
        ans = 10000 * i + 5000 * ii + 1000 * iii
        if ans == Y:
                print(i,ii,iii)
                a += 1
                break

    if a != 0:
        break

if a == 0:
    print(-1,-1,-1)


Measured memory_bytes: 3060
n = list(input())
inf = 10**9
dp = [[inf for i in range(2)] for j in range(len(n) + 2)]
#dp[i][j] := 下からi桁目まで決めたときの、繰り下がりがjである。(true, false)
#ときの、最小紙幣数
n.reverse()
n += ['0']
#繰り下がりがない
dp[0][0] = 0
#配るDP
for i in range(len(n)):
    for j in range(2):
        x = int(n[i])
        #さっきの桁に繰り下がりをしている場合は、今回の数字が一つ減る。
        #んだけど、実際に払う数字は後で決めるから、今回は、引く側の数字を1大きく
        #することで、同じ操作を実現している
        x += j
        for a in range(10):
            #今回払う数字を決める
            if a >= x:
                #繰り下がりなし
                dp[i+1][0] = min(dp[i+1][0], dp[i][j] + 2 * a - x)
            else:
                #繰り下がりあり
                dp[i+1][1] = min(dp[i+1][1], dp[i][j] + 2 * a - x + 10)
print(min(dp[len(n)][0], dp[len(n)][1]))



Measured memory_bytes: 204784
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n;
	cin >> n;
	
	vector<string> v;
	map<string, int> mp;
	
	int mx = 0;
	
	while(n--){
		string s;
		cin >> s;
		mp[s]++;
		
		mx = max(mx, mp[s]);
	}
	
	for(auto &el : mp){
		if(el.second == mx)
			v.push_back(el.first);
	}
	
	sort(v.begin(), v.end());
	for(auto &el : v)
		cout << el << endl;

	return 0;
}


Measured memory_bytes: 25584
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=1;i<=n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
using namespace std;
ll int tr[1000000];
ll int n,h[N],v[N];
void init(int i,int l,int r){
	if(l==r)tr[i]=v[l];
	else{
		init(2*i,l,(l+r)/2);
		init(2*i+1,(l+r)/2+1,r);
		tr[i]=max(tr[2*i],tr[2*i+1]);
	}
}
void upd(int i,int ht,int l,int r,ll int vv){
	if(l==r)tr[i]=vv;
	else if(ht<l||r<ht)return ;
	else{
		upd(2*i,ht,l,(l+r)/2,vv);
		upd(2*i+1,ht,(l+r)/2+1,r,vv);
		tr[i]=max(tr[i],vv);
	}
}
ll int qry(int i,int l,int r,int l1,int r1){
	if(r1<l||r<l1)return 0;
	if(l1<=l&&r<=r1)return tr[i];
	ll int x=qry(2*i,l,(l+r)/2,l1,r1);
	ll int y=qry(2*i+1,(l+r)/2+1,r,l1,r1);
	return max(x,y);
}
void solve(){
	cin>>n;
	rep(i,n)cin>>h[i];
	rep(i,n)cin>>v[h[i]];
	ll int ans=0;
	for(int i=1;i<=n;i++){
		ll int vv=qry(1,1,n,1,h[i]-1);
		upd(1,h[i],1,n,v[h[i]]+vv);
		ans=max(ans,vv+v[h[i]]);
	}
	cout<<ans;
}
int main()
{
	waste;
	int t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 12032
M,D = list(map(int,input().split()))
count = 0
for i in range(1,M+1):
    for j in range(1,D+1):
        if len(str(j)) == 1:
            continue
        d10 = int(str(j)[0])
        d1 = int(str(j)[1])
        if d10 >= 2 and d1 >= 2 and d10*d1 == i:
            count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
#define int long long
#define All(v) (v.begin(),v.end())
int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
int lcm(int a, int b) {
	return a / gcd(a, b)*b;
}
int modpow(int a,int b){
    if(!b)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int fac(int a){
    int Ans=1;
    for(int i=1;i<=a;i++){
        Ans*=i;
        Ans%=MOD;
    }
    return Ans;
}//kaijo
int comb(int a,int b){
    return fac(a)*modpow(fac(a-b),MOD-2)%MOD*modpow(fac(b),MOD-2)%MOD;
}
signed main(){
	int n,m;
	ll a[100001],b[100001];
	cin>>n>>m;
	ll bsum=0;
	ll asum=0;
	rep(i,n){
		cin>>a[i];
		asum+=a[i];
	}
	rep(i,m){
		cin>>b[i];
		bsum+=b[i];
	}
	cout<<asum*bsum<<endl;
	return 0;
}




Measured memory_bytes: 4668
#include<iostream>
#include<algorithm>

using namespace std;

int gcd(int a ,int b);
int lcm(int a,int b);

int main(){
	int a,b;
	while(cin >> a >> b){
		cout << gcd(a,b) << " ";
		cout << lcm(a,b) << endl;
	}
	return 0; 
}

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

int lcm(int a,int b){
	return a/gcd(a,b)*b;
}

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

int main(void){
    int n = 0, mai = 0; 

    scanf("%d", &n);

    if(n % 1000 == 0){
        printf("0\n");
    }else{
        mai = n / 1000 + 1;
        printf("%d\n", 1000 * mai - n);
    }

    return 0;

} 


Measured memory_bytes: 3828
#include <iostream>
#include <string>

int main()
{
	int x, a, b;
	std::cin >> x >> a >> b;

	std::string ans = "";
	int d = b - a;
	if( d <= 0 ) {
		ans = "delicious";
	}
	else if( 0 < d and d <= x ) {
		ans = "safe";
	}
	else {
		ans = "dangerous";
	}
	
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.12 21:14:07
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int MOD = 1e9 + 7;
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((MOD+x)%MOD) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= MOD;
        }
        this->x = z;
    }
    mint& operator+=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint& operator/=(const mint &a) {
        long long n = MOD - 2;
        mint u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};

template<typename T, typename U>
T pow(T k, U n, T unity = 1) {
    while (n > 0) {
        if (n & 1) {
            unity *= k;
        }
        k *= k;
        n >>= 1;
    }
    return unity;
}
int main() {
    int n,c;cin >> n >> c;
    vector<vector<mint>> pow_sum(c+1,vector<mint>(401,0));
    vector<vector<mint>> dp(n+1,vector<mint>(c+1));
    dp[0][0] = 1;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i <= c; i++) {
        for (int j = 0; j < 400; j++) {
            pow_sum[i][j + 1] = pow_sum[i][j] + pow(mint(j + 1),i);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= c; j++) {
            for (int k = 0; k <= j; k++) {
                dp[i + 1][j] += dp[i][j - k] * (pow_sum[k][b[i]] - pow_sum[k][a[i]-1]);
            }
        }
    }
    cout << dp[n][c] << endl;
    return 0;
}


Measured memory_bytes: 6136
from itertools import combinations_with_replacement as cr
n,m,q=map(int,input().split())
s=[list(map(int,input().split()))for i in range(q)]
f=0
for i in cr([i for i in range(1,m+1)],n):
    e=0
    for a,b,c,d in s:
        if i[b-1]-i[a-1]==c:
            e+=d
    if f<e:f=e
print(f)       

Measured memory_bytes: 9148
#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>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define debug(x) #x << "=" << (x)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0521

int main() {

    int price;
    while(true) {
        cin >> price;
        if (price == 0) break;

        int change = 1000 - price;
        int coins[] = {500, 100, 50, 10, 5, 1};
        int ans = 0;
        for (int c : coins) {
            int num = change / c;
            ans += num;
            change -= c * num;
        }

        cout << ans << "\n";
    }

    return 0;
}



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

int main(){
    int n,arr[51][6],ans = 0;
    vector<int>v;
    cin >> n;
    
    for(int i = 0;i < n;++i){
        for(int j = 0;j < 6;++j){
            int h,m;
            cin >> h >> m;
            arr[i][j] = h * 60 + m;
            if(j % 2 == 0){
                v.push_back(arr[i][j]);   
            }
        }
    }
    sort(v.begin(),v.end());
    
    for(int i = 0;i < v.size();++i){
        for(int j = i + 1;j < v.size();++j){
            for(int k= j + 1;k < v.size();++k){
                int cnt = 0;
                for(int l = 0;l < n;++l){
                    if(arr[l][0] <= v[i] && v[i] <= arr[l][1] && arr[l][2] <= v[j] && v[j] <= arr[l][3] && arr[l][4] <= v[k] && v[k] <= arr[l][5]){
                        cnt++;        
                    }
                }
                ans = max(ans,cnt);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3164
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i<n;i++)
#define cint(a) int a; cin >> a;
#define cstr(str) string str; cin >> str;
#define vv(Type, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c; cin >> a >> b >> c;
	if (a == b && c == b) cout << "No" << endl;
	else if (a != b && c != b && a != c) cout << "No" << endl;
	else cout << "Yes" << endl;


	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
int dp[2][333][333];
signed main(){
  int n,m,mod=1000000007;
  cin>>n>>m;
  dp[0][1][n-1]=1;
  for(int i=0;i<m;i++){
    int ii=i%2;
    int ni=(i+1)%2;
    fill_n(*dp[ni],333*333,0);
    for(int j=0;j<=n;j++){
	 for(int k=0;k<n;k++){
	   if(dp[ii][j][k]==0)continue;
	   dp[ni][n-k][k]+=dp[ii][j][k]*j%mod;
	   dp[ni][n-k][k]%=mod;
	   dp[ni][j][k]+=dp[ii][j][k]*(n-k-j)%mod;
	   dp[ni][j][k]%=mod;
	   if(k>0){
		dp[ni][j][k-1]+=dp[ii][j][k]*k%mod;
		dp[ni][j][k-1]%=mod;
	   }
	 }
    }
  }
  cout<<dp[m%2][n][0]<<endl;
  return 0;
}



Measured memory_bytes: 1920
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
vector<int>pat[303030];
bool flag[303030];
int dep[303030];
int maxd, rmd;
int dat[303030];
int m1[303030], m2[303030], r1[303030];
typedef long long ll;
void dfs(int node, int d)
{
	if (flag[node])return;
	flag[node] = true;
	dep[node] = d;
	if (maxd < d)maxd = d, rmd = node;
	dat[d] = max(dat[d], int(pat[node].size()) - 1);
	for (int i = 0; i < pat[node].size(); i++)dfs(pat[node][i], d + 1);
}
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	fill(flag, flag + num, false);
	maxd = -1;
	dfs(0, 0);
	int s = rmd;
	fill(flag, flag + num, false);
	maxd = -1;
	dfs(s, 0);
	int t = rmd;
	int now = t;
	for (int i = 0; i < maxd / 2; i++)
	{
		for (int j = 0; j < pat[now].size(); j++)
		{
			if (dep[now] - 1 == dep[pat[now][j]])
			{
				now = pat[now][j];
				break;
			}
		}
	}
	if (maxd % 2 == 1)
	{
		int len = (maxd + 1) / 2;
		int a = now, b;
		for (int j = 0; j < pat[now].size(); j++)
		{
			if (dep[now] - 1 == dep[pat[now][j]])
			{
				b = pat[now][j];
				break;
			}
		}
		fill(flag, flag + num, false);
		fill(dat, dat + num, 0);
		flag[a] = true;
		dfs(b, 0);
		flag[a] = false;
		dfs(a, 0);
		ll ans = 2;
		for (int i = 0; i < len - 1; i++)ans *= dat[i];
		printf("%d %lld\n", len, ans);
	}
	else
	{
		int c = now;
		int len = maxd / 2 + 1;
		fill(flag, flag + num, false);
		fill(dat, dat + num, 0);
		flag[c] = true;
		fill(r1, r1 + num, -1);
		for (int i = 0; i < pat[c].size(); i++)
		{
			maxd = -1;
			dfs(pat[c][i], 0);
			for (int j = 0; j <= maxd; j++)
			{
				if (dat[j] > m1[j])m2[j] = m1[j], m1[j] = dat[j], r1[j] = i;
				else if (dat[j] > m2[j])m2[j] = dat[j];
				//printf("%d %d %d\n", pat[c][i] + 1, j, dat[j]);
			}
			fill(dat, dat + maxd + 1, 0);
		}
		ll sum = 1;
		for (int i = 0; i < len - 2; i++)sum *= m1[i];
		//printf("%lf\n", exp(sum + log(pat[c].size())));
		ll mini = sum * pat[c].size();
		fill(flag, flag + num, false);
		flag[c] = true;
		for (int i = 0; i < pat[c].size(); i++)
		{
			maxd = -1;
			dfs(pat[c][i], 0);
			ll x = sum * 2 * max(int(pat[c].size()) - 1, int(pat[pat[c][i]].size()) - 1);
			for (int j = 0; j < maxd; j++)
			{
				if (r1[j] == i)x = x / m1[j] * max(m2[j], dat[j + 1]);
				else x = x / m1[j] * max(m1[j], dat[j + 1]);
			}
			mini = min(mini, x);
			fill(dat, dat + maxd + 1, 0);
		}
		printf("%d %lld\n", len, mini);
	}
}


Measured memory_bytes: 11520
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

  ll h,w,a,b;
  std::cin>>h>>w>>a>>b;

  if(h%a==0&&w%b==0){
    std::cout<<"No\n";
    return 0;
  }

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

  bool flip=false;

  ll n=w,m=b;

  if(w%b==0){
    flip=true;
    n=h;
    m=a;
  }

  std::vector<ll> sum(n+1);

  for(ll i=n;i>0;i--){
    if(i==n)sum[i]=1;
    else if(i+m>n)sum[i]=-1;
    else sum[i]=sum[i+m]+1;
  }

  for(ll i=0;i<=n;i+=m){
    sum[i]=-1*(i/m);
  }

  std::vector<ll> ans(n);
  rep(i,0,n)ans[i]=sum[i+1]-sum[i];

  if(flip){
    rep(i,0,h){
      rep(j,0,w){
        std::cout<<ans[i]<<" ";
      }
      std::cout<<"\n";
    }
  }else{
    rep(i,0,h){
      std::cout<<ans<<"\n";
    }
  }

  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> adp(n + 1, 0), bdp(n + 1, 0);
    rep(i, n) {
        ll p;
        cin >> p;
        p--;
        adp[p] += i;
        bdp[p + 1] -= i;
    }
    rep(i, n - 1) {
        adp[i + 1] += adp[i];
        bdp[i + 1] += bdp[i];
    }
    rep(i, n) {
        adp[i] += i + 1;
        bdp[i] += n - i + abs(bdp[n - 1]);
    }
    rep(i, n) printf("%lld%s", adp[i], (i == (n - 1)) ? "\n" : " ");
    rep(i, n) printf("%lld%s", bdp[i], (i == (n - 1)) ? "\n" : " ");
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
signed main(){
  string a;
  cin>>a;
  if(a=="SUN")
    cout<<7;
 if(a=="MON")
    cout<<6;
 if(a=="TUE")
    cout<<5;
 if(a=="WED")
    cout<<4;
 if(a=="THU")
    cout<<3;
 if(a=="FRI")
    cout<<2;
 if(a=="SAT")
    cout<<1;
}

Measured memory_bytes: 256
//
//  main.cpp
//  C - Alchemist
//
//  Created by Hashizo on 2019/08/18.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

using namespace std;

#undef LONG_MAX
#undef LONG_MIN

#define LONG_MAX	9223372036854775807
#define LONG_MIN	(-LONG_MAX  -1)

#define ll long long

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char * argv[]) {
	ll n;
	cin >> n;

	vector<double> v(n);
	REP(i, n) {
		cin >> v[i];
	}

	SORT(v);
	
	
	FOR(i, 0, (n-2)) {
		double value = (v[0] + v[1]) / 2;
		v.erase(v.begin());
		v.erase(v.begin());
		v.emplace_back(value);
		SORT(v);
	}
	
	
	cout << (v[0] + v[1]) / 2 << endl;
	return 0;
}


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

#define ll long long

const int Nmax = 2e5 + 10;
int A[Nmax];

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

  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    if (i >= k) {
      cout << ((A[i] > A[i - k]) ? "Yes" : "No") << "\n";
    }
  }
  
  
  return 0;
}


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

int main() {
	int N;
	string S;
	cin >> N >> S;
	int ans=0;
	for(int dist=1; dist<N; ++dist){
		int now=0;
		for(int i=0; i+dist<N; ++i){
			if(S[i]==S[i+dist]) ++now;
			else{
				ans=max(ans, min(now, dist));
				now=0;
			}
		}
		ans=max(ans, min(now, dist));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

// https://atcoder.jp/contests/abc141/submissions/7542028がjavaだとTLEせず通るのかテスト
// StringBufferだとどうなるか
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        long K = Long.parseLong(sc.next());
        int Q = Integer.parseInt(sc.next());

        int[] A = new int[Q];
        for (int i = 0; i < Q; i++) {
            A[i] = Integer.parseInt(sc.next());
        }

        String ans = solve(N, Q, K, A);
        System.out.println(ans);
    }

    public static String solve(int n, int q, long k, int[] a) {
        long[] dp = new long[n];
        for (int i = 0; i < q; i++) {
            int winner = a[i];
            dp[winner - 1] = dp[winner - 1] + 1;
        }

        StringBuffer sb = new StringBuffer();
        for (long element : dp) {
            sb.append(q - k >= element ? "No\n" : "Yes\n");
        }
        return sb.toString();
    }
}



Measured memory_bytes: 48808
def main():
    n = int(input())
    a = list(map(int, input().split()))
    colors = [[0 for _ in range(3)] for _ in range(n + 1)]
    # color 1, 2, 3
    ans = 1
    mod = 10 ** 9 + 7
    for i in range(n):
        for j in range(3):
            colors[i + 1][j] = colors[i][j]
        for j in range(3):
            if a[i] == colors[i + 1][j]:
                colors[i + 1][j] += 1
                break
    for i in range(n):
        ans *= colors[i].count(a[i])
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 26892
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}


void solve(LL N, LL D){
    cout << ceil((double)N / (2 * D + 1)) << endl;
}

int main(){
    LL N;
    scanf("%lld",&N);
    LL D;
    scanf("%lld",&D);
    solve(N, D);
    return 0;
}


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

int main(){
  vector<char> al(26);
  al.at(0) = 'A';
  al.at(1) = 'B';
  al.at(2) = 'C';
  al.at(3) = 'D';
  al.at(4) = 'E';
  al.at(5) = 'F';
  al.at(6) = 'G';
  al.at(7) = 'H';
  al.at(8) = 'I';
  al.at(9) = 'J';
  al.at(10) = 'K';
  al.at(11) = 'L';
  al.at(12) = 'M';
  al.at(13) = 'N';
  al.at(14) = 'O';
  al.at(15) = 'P';
  al.at(16) = 'Q';
  al.at(17) = 'R';
  al.at(18) = 'S';
  al.at(19) = 'T';
  al.at(20) = 'U';
  al.at(21) = 'V';
  al.at(22) = 'W';
  al.at(23) = 'X';
  al.at(24) = 'Y';
  al.at(25) = 'Z';
  
  
  int di;
  cin >> di;
  string s;
  cin >> s;
  int N = s.size();
  string ans = s;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 26; j++){
      if(s.at(i) == al.at(j)){
        int a = (j + di) % 26;
        ans.at(i) = al.at(a);
      }
    }
  }
  
  cout << ans << endl;
}

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

int l[2004][2004], r[2004][2004], u[2004][2004], d[2004][2004];
int mx;
int main(){
    int h,w;
    cin >> h >> w;

    string s[h+1];

    for(int i = 0;i<h;i++){
        cin >> s[i];
    }  
    for(int i = 0; i<=h+3;i++){
        for(int j= 0;j<=w+3;j++){
            l[i][j] = 0;
            r[i][j] = 0;
            u[i][j] = 0;
            d[i][j] = 0;
        }
    }
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            if(s[i][j]!='#'){
                l[i+1][j+1] = l[i+1][j] + 1;
            }

        }
    }

    for(int i = 0;i<w;i++){
        for(int j = 0;j<h;j++){
            if(s[j][i]!='#'){
                u[j+1][i+1] = u[j][i+1] + 1;
            }
        }
    }

    for(int i = 0;i<h;i++){
        for(int j = w-1;j>=0;j--){
            if(s[i][j]!='#'){
                r[i+1][j+1] = r[i+1][j+2] + 1;
            }
        }
    }

    for(int i = 0;i<w;i++){
        for(int j = h-1;j>=0;j--){
            if(s[j][i]!='#'){
                d[j+1][i+1] = d[j+2][i+1] + 1;
            }
        }
    }

    for(int i = 1;i<=h;i++){
        for(int j = 1;j<=w;j++){
            //cout << i << " " << j << " " << l[i][j]+r[i][j]+u[i][j]+d[i][j]-3 << endl;
            mx = max(mx, l[i][j]+r[i][j]+u[i][j]+d[i][j]-3);
        }
    }

    cout << mx << endl;

    return 0;
}

Measured memory_bytes: 67072
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

int ncr[55][55];

int power(int x, int n) {
	int res = 1LL;
	while (n > 0) {
		if (n & 1) (res *= x);
		(x *= x);
		n >>= 1;
	}
	return res;
}

int f(int n, int r){
	if(r==0 || r==n) return 1;
	if(ncr[n][r]>0) return ncr[n][r];
	return ncr[n][r] = f(n-1, r-1) + f(n-1, r);
}

signed main() {
  INIT;
	VAR(int,n,p);
	VEC(int,a,n);
	int zero, one=0;
	REP(i,n){
		if(a[i]%2==1) ++one;
	}
	zero = n-one;

	int ans=0;
	REP(i,one+1){
		if(p==i%2){
			ans += f(one,i);
		}
	}
	ans *= power(2,zero);
	OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    long long money=1000;
    int buy=1;
    long long stock=0;
    for(int i=0; i<n; i++){
        if(i==n-1){
            money+=stock*a[i];
            break;
        }
        if(buy){
            if(a[i]<a[i+1]){
                stock+=money/a[i];
                money-=stock*a[i];
                buy=0;
            }
        }else {
            if(a[i]>a[i+1]){
                money+=stock*a[i];
                stock=0;
                buy=1;
            }
        }
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstring>
using namespace std;
#define REP(i,n)  for(int i=0;i<n;++i)
int n,a[5000],b[5000];
int main() {
	cin>>n;
	REP(i,n)cin>>b[i];
	int ans = 1e6;
	REP(i,b[0]+1){
		memcpy(a,b,sizeof(b));
		a[0]-=i;
		int t=i;
		REP(j,n-1){
			if(a[j]<1)continue;
			t+=a[j]*2;
			a[j+1]-=a[j];
		}
		t += max(0, a[n-1]);
		ans = min(ans, t);
	}
	cout << ans << endl;
	return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

ll dp[100005][10];

int main() {
  ll N, K;
  scanf("%lld %lld", &N, &K);

  ll ans = 0;
  for (ll num = K; num <= N + 1; num++) {
    ll start = (0 + num - 1) * num / 2;
    ll end = (N + N - (num - 1)) * num / 2;

    ll plus = (end - start) + 1;

    ans = (ans + plus) % MOD;
  }
  cout << ans << endl;
}


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

int main() {
  int n = 0;
	string s;
	cin >> s;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+') {
			n++;
		}
		else {
			n--;
		}
	}
	cout << n;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val t = sc.next()
    val tmp_t = t.substring(0,s.length)
    if (s == tmp_t) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 36324
#encoding:utf-8 No.0014 2014.10.1
ary = []
while gets
  ary.push $_.chomp.to_i
end

def func(n)
  return n **2
end

ary.length.times do |i|
  width = ary[i]
  area = 0
  x = ary[i]
  while x < 600
    length = func(x)
    area += length * width
    x += ary[i]
  end
  puts area
end

Measured memory_bytes: 6100