akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#include <fstream>

#include <cstdio>

#include <cmath>

#include <vector>

#include <cstring>

#include <string>

#include <set>

#include <map>

#include <stack>

#include <queue>

#include <algorithm>

using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)

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

#define FORR(i,a,b) for (int i=a; i>=b; --i)

#define ALL(c) (c).begin(), (c).end()

typedef long long ll;

typedef vector<int> VI;

typedef vector<ll> VL;



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

  ll a = 2;
  ll b = 1;

  if(N==1){
    cout << b <<"\n";

  }else{
    ll c;
    for(int i = 1;i<N;i++){
      c = a + b;
      a = b;
      b = c;
    };
    cout << c <<"\n";
  }
    return 0;
  }


Measured memory_bytes: 764
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const pi = math.Pi

var A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z int
var mod int = pow(10, 9) + 7
var Umod uint64 = 2019
var ans int = 1e9

func main() {
	var L, R int
	fmt.Scan(&L, &R)

	// i*j = k...p (mod 2019)
	// (i*j+p) = k*2019
	if 2019 <= R-L {
		fmt.Println(0)
	} else {
		for i := L; i <= R-1; i++ {
			for j := L + 1; j <= R; j++ {
				cnt := i * j % 2019
				ans = min(ans, cnt)
			}
		}
		fmt.Println(ans)
	}
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] > a[j] }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskH {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();
            char[][] a = new char[h + 1][w + 1];
            for (int i = 1; i <= h; i++) {
                String s = in.next();
                for (int j = 1; j <= w; j++) {
                    a[i][j] = s.charAt(j - 1);
                }
            }
            int[][] dp = new int[h + 1][w + 1];
            for (int i = 1; i <= h; i++) {
                for (int j = 1; j <= w; j++) {
                    if (i == 1 && j == 1) {
                        dp[i][j] = 1;
                        continue;
                    }
                    if (a[i][j] == '.') {
                        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
                    }
                }
            }
            out.println(dp[h][w]);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 34328
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int towerDiff = a - b;
		System.out.println(towerDiff + (towerDiff - 1) * (towerDiff) / 2 - a);
	}
}


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

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

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;

#define int long long

signed main(){
    int one=INT_MAX;
    int two=0;
    int n=0;
    double size[3]={0.25,0.5,1};
    for(int i=0;i<3;i++){
        int temp=0;
        cin >> temp;
        one=min(one,(int)(temp*(1/size[i])));
    }
    cin >> two;
    cin >> n;
    if(one*2<two){
        cout << one*n << endl;
    }else{
        cout << two*(int)(n/2)+one*(n%2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		char ch[]=s.toCharArray();
		int c=0;
		for(int i=1;i<s.length();i++){
		int	j=i-1;
			if(ch[j]==ch[i]){
				if(ch[j]=='1'){
			      ch[i]='0';
				c++;
				}
				else{
				ch[i]='1';
					c++;
				}
			}
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 27988
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int N, M;
vector<int> G[100000];
vector<int> vc;
vector<int> ans;
vector<bool> visit(100000, false);

void dfs(int p) {
  visit[p] = true;
  REP(i, G[p].size()) {
    int q = G[p][i];
    if (!visit[q]) {
      vc.push_back(q);
      dfs(q);
      break;
    }
  }
}

int main() {
  cin >> N >> M;
  REP(i, M) {
    int A, B;
    cin >> A >> B;
    A--, B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  dfs(0);
  reverse(ALL(vc));
  REP(i, vc.size()) ans.push_back(vc[i]);
  ans.push_back(0);
  vc.clear();
  dfs(0);
  REP(i, vc.size()) ans.push_back(vc[i]);
  cout << ans.size() << endl;
  REP(i, ans.size()) {
    if (i != 0) cout << " ";
    cout << ans[i] + 1;
  }
  cout << "\n";
  return 0;
}

Measured memory_bytes: 9976
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

const int bound = 200010;
ll dp[bound];
int vorh[bound];

void init(){
	dp[0] = 1;
	for( int i = 0; i < bound; ++i ) vorh[i] = -1;
}

int main(){
	int n; cin >> n;
	vector<int> tmp(n);
	for( auto &k : tmp ) cin >> k;
	tmp.push_back(-1);
	vector<int> farbe;
	for( int i = 0; i < n; ++i ){
		if( tmp[i] != tmp[i+1] ){
			farbe.push_back(tmp[i]);
		}
	}
	n = farbe.size();
	init();
	for( int i = 0; i < n; ++i ){
		dp[i+1] = dp[i];
		if( vorh[farbe[i]] == -1 ){
			vorh[farbe[i]] = i;
		} else {
			dp[i+1] += dp[vorh[farbe[i]]];
			dp[i+1] %= mod;
			vorh[farbe[i]] = i+1;
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 5232
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i+100*j+50*k == X: ans += 1
        
print(ans)

Measured memory_bytes: 9180
# -*- coding: utf-8 -*-

a, b = [int(x) for x in input().split()]
flag, count = 0, 0
for i in range(a,b+1):
    flag = 0
    si = str(i)
    for j in range(int(len(si)/2)):
        if si[j] == si[-(j+1)]:
            pass
        else:
            flag = 1
    if flag == 0:
        count += 1
print(count)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int mxN = 1e5 + 5;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int deg[mxN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	vi a(m), b(m);
	rep(i, m){
		cin >> a[i] >> b[i];
		deg[a[i]]++;
		deg[b[i]]++;
	}
	rep(i, m){
		if(deg[a[i]] % 2 != 0 || deg[b[i]] % 2 != 0){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main() {
    int A,B;
    cin >> A >> B;
    int i = 1;
    if(B == 1) {
        cout << 0 << endl;
        return 0;
    }
    while(A * i - (i - 1) < B) {
        i++;
    }
    cout << i << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> s(n, 1);
	vector<bool> t(n);
	t[0] = true;
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		
		if (t[a - 1]) {
			t[b - 1] = true;
		}

		s[a - 1]--;
		if (s[a - 1] == 0) {
			t[a - 1] = false;
		}
		s[b - 1]++;
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (t[i]) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

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



int main(){
    int A, B;

    cin >> A >> B;
    if(A > 12){
        cout << B << endl;
        return 0;
    }else if(A < 6){
        cout << 0 << endl;
        return 0;
    }else{
        cout << B/2 << endl;
        return 0;
    }
    


}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            string[] st = ReadLine().Split(' ');
            string s = st[0];
            string t = st[1];
            var sb = new StringBuilder();
            for (int i = 0; i < n; i++)
            {
                sb.Append(s[i]);
                sb.Append(t[i]);
            }
            WriteLine(sb.ToString());
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll bj=1,pp=0;
ll n;
cin>>n;
ll a[n+1];
for(int i=1;i<=n;i++)cin>>a[i];
for (int i = 1; i <= n; i++)
	{
		if (a[i] == bj) 
		{
			++bj;
			++pp;
		}
	}
	if (pp == 0) puts("-1");
	else printf("%d\n", n - pp);
}


Measured memory_bytes: 1920
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

s = 0
for a in A:
	s ^= a
ans = []
for a in A:
	ans.append(s^a)
print(*ans)

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

int main(){
    int n , k , c ;
    cin >> n >> k >> c ;
    if(n + k >= c ) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

const int maxn = 500010,inf = 0x7fffffff;
int n,k,p[maxn],q[maxn],minn[maxn << 2],du[maxn],ans[maxn],cnt;
vector<int> V[maxn];

void pushup(int o)
{
    minn[o] = min(minn[o * 2],minn[o * 2 + 1]);
}

void build(int o,int l,int r)
{
    if (l == r)
    {
        minn[o] = inf;
        return;
    }
    int mid = (l + r) >> 1;
    build(o * 2,l,mid);
    build(o * 2 + 1,mid + 1,r);
    pushup(o);
}

int query(int o,int l,int r,int x,int y)
{
    if (x > y)
        return inf;
    if (x <= l && r <= y)
        return minn[o];
    int mid = (l + r) >> 1,res = inf;
    if (x <= mid)
        res = min(res,query(o * 2,l,mid,x,y));
    if (y > mid)
        res = min(res,query(o * 2 + 1,mid + 1,r,x,y));
    return res;
}

void update(int o,int l,int r,int pos,int v)
{
    if (l == r)
    {
        minn[o] = v;
        return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
        update(o * 2,l,mid,pos,v);
    else
        update(o * 2 + 1,mid + 1,r,pos,v);
    pushup(o);
}

void topo()
{
    priority_queue<int,vector<int>,greater<int> >q;
    for (int i = 1; i <= n; i++)
        if (!du[i])
            q.push(i);
    while (!q.empty())
    {
        int u = q.top();
        q.pop();
        ans[u] = ++cnt;
        for (int i = 0; i < V[u].size(); i++)
        {
            int v = V[u][i];
            if (--du[v] == 0)
                q.push(v);
        }
    }
}

int main()
{
    scanf("%d%d",&n,&k);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d",&p[i]);
        q[p[i]] = i;
    }
    build(1,1,n);
    for (int i = n; i >= 1; i--)
    {
        int pos = query(1,1,n,max(q[i] - k + 1,1),q[i]);
        //cout << "输出!!! " << i << endl;
        if (pos != inf)
        {
            //cout << i << " " << pos << endl;
            V[q[i]].push_back(q[pos]);
            //cout << pos << " " << i << endl;
            //V[pos].push_back(i);
            du[q[pos]]++;
        }
        pos = query(1,1,n,q[i],min(n,q[i] + k - 1));
        if (pos != inf)
        {
            //cout << i << " " << pos << endl;
            V[q[i]].push_back(q[pos]);
            //cout << i << " " << pos << endl;
            //V[i].push_back(pos);
            du[q[pos]]++;
        }
        update(1,1,n,q[i],i);
    }
    for (int i = 1; i <= n; i++)
        sort(V[i].begin(),V[i].end());
    topo();
    for (int i = 1; i <= n; i++)
        printf("%d\n",ans[i]);

    return 0;
}


Measured memory_bytes: 44416
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2 == 0) {
        cout << "Even" << endl;
    }
    else {
        cout << "Odd" << endl;
    }
} 

Measured memory_bytes: 256
x,y=map(int,input().split())
x=3 if x==1 else 2 if x==2 else 1 if x==3 else 0
y=3 if y==1 else 2 if y==2 else 1 if y==3 else 0
print(1000000 if x==3 and y==3 else(x+y)*100000)

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

int main(){
	
	long long n;
	cin >> n;
	long long mx = n;
	
	if(n == 1){
		cout << 0 << endl;
		return 0;
	}
	
	long long ans = 0;
	for(long long i = 2; i * i <= n; i++){
		long long cnt = 0;
		if(n % i == 0){
			while(n % i == 0){
				n /= i;
				cnt++;
			}
			for(int j = 1; j <= cnt; j++){
				cnt -= j;
				ans++;
			}
		}
	}
	if(n > 1)ans++;
	cout << ans << endl;
	return 0;
}
 


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"
#include <set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
 

vector <int > H;
int A,B; 

int main()
{
  cin >> A >> B;
    cout << max(A - B*2,0) << " ";

}


Measured memory_bytes: 256
import math
N = int(input())
ans = ''

if N == 0:
    ans += '0'
else:
    while N != 1:
        if N % 2 == 0:
            ans += '0'
        else:
            ans += '1'
        N = math.ceil(N / -2)
    ans += '1'
ans = ans[::-1]
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define debug(x) cerr<<"\tDEBUG: "<<#x<<" = "<<(x)<<endl
#define debug2(a,x) cerr<<#a<<"\tDEBUG: "<<#x<<" = "<<(x)<<endl
using namespace std;
const int maxn=2100;
int l,r;
int main(){
	cin>>l>>r;
	if(r-l>3000){
		cout<<0<<endl;
	}else {
		long long ans=2e9;
		for(int i=l;i<r;i++)
			for(int j=i+1;j<=r;j++)
				ans=min(ans,1LL*i*j%2019);
		cout<<ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int  x, y;
  int  g[13] = {0,1,2,1,3,1,3,1,1,3,1,3,1};

  scanf("%d %d", &x, &y);

  if(g[x] == g[y]){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
def solve(n, ga, sa, ba, gb, sb, bb):
    gd, sd, bd = gb - ga, sb - sa, bb - ba

    if bd <= 0:
        if sd <= 0:
            if gd <= 0:
                return n
            return n + n // ga * gd
        if gd <= 0:
            return n + n // sa * sd
        return max(n + g * gd + (n - g * ga) // sa * sd for g in range(n // ga + 1))
    if sd <= 0:
        if gd <= 0:
            return n + n // ba * bd
        return max(n + g * gd + (n - g * ga) // ba * bd for g in range(n // ga + 1))
    if gd <= 0:
        return max(n + s * sd + (n - s * sa) // ba * bd for s in range(n // sa + 1))
    (_, ga, gd), (_, sa, sd), (_, ba, bd) = \
        sorted([(gb / ga, -ga, gd), (sb / sa, -sa, sd), (bb / ba, -ba, bd)], reverse=True)
    ga, sa, ba = -ga, -sa, -ba
    sga = 0 if n // ga < 1000 else n // ga // 2
    return max(n + g * gd + s * sd + (n - g * ga - s * sa) // ba * bd
               for g in range(sga, n // ga + 1)
               for s in range((n - g * ga) // sa + 1))


n = int(input())
ga, sa, ba = list(map(int, input().split()))
gb, sb, bb = list(map(int, input().split()))
n2 = solve(n, ga, sa, ba, gb, sb, bb)
n3 = solve(n2, gb, sb, bb, ga, sa, ba)
print(n3)


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



int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    string s; cin >> s;
    int i = 0;
    while (i < s.size()) {
        if (s.substr(i, 11) == "dreameraser") {
            i += 11;
        } else if (s.substr(i, 10) == "dreamerase") {
            i += 10;
        } else if (s.substr(i, 7) == "dreamer") {
            i += 7;
        } else if (s.substr(i, 6) == "eraser") {
            i += 6;
        } else if (s.substr(i, 5) == "dream") {
            i += 5;
        } else if (s.substr(i, 5) == "erase") {
            i += 5;
        } else {
            cout << "NO\n";
            return 0;
        }

        // cout << i << ' ';
    }

    cout << "YES\n";

    return 0;
}


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

#define sz 100005
int arr[sz][4],dp[sz][4];

int main(){

    int n, i, j, a, b, c ;
    cin>>n;
    for(i=1; i<=n; i++){
        for(j=1; j<=3; j++){
            cin>>arr[i][j];
        }
    }
    for(i=1; i<=n; i++){
        for(j=1; j<=3; j++){
            if(j==1){
                dp[i][j]=max(dp[i-1][2],dp[i-1][3])+arr[i][j];
            }
            else if(j==2){
                dp[i][j]=max(dp[i-1][1],dp[i-1][3])+arr[i][j];
            }
            else if(j==3){
                dp[i][j]=max(dp[i-1][2],dp[i-1][1])+arr[i][j];
            }
        }
    }
    cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));



    return 0;
}


Measured memory_bytes: 3328
n, y = (int(x) for x in input().split())

_10000, _5000, _1000 = 0, 0, 0

exist = False

for i in range(n + 1):

    # print("10000円札 : {0}枚".format(i))
    
    for j in range(n + 1 - i):

        # print("5000円札 : {0}枚".format(j))

        # print("1000円札 : {0}枚".format(k))

        if (i * 10000) + (j * 5000) + ((n - i - j) * 1000) == y :
                # print("答えを発見!")
                _10000, _5000, _1000 = i, j, n - i - j
                exist = True

        # if i + j + (n - i - j) == n :

        #     # print("合計枚数がN枚")
        #     # print("合計金額 : {0}円".format((i * 10000) + (j * 5000) + (k * 1000)))

        #     if (i * 10000) + (j * 5000) + ((n - i - j) * 1000) == y :
        #         # print("答えを発見!")
        #         _10000, _5000, _1000 = i, j, n - i - j
        #         exist = True

    if exist == True :
        break

if exist == True :
    print("{0} {1} {2}".format(_10000, _5000, _1000))
else :
    print('-1 -1 -1')





                



Measured memory_bytes: 9132
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
 

int main() {
    int n,k;
    cin >> n >> k;
    int  i = 0;
    while(pow(k,i)<=n){
        i++;
    }
    cout << i << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
#include <queue>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

//input
int main(void)
{
    int N;
    cin >> N;
    vector<int> a;
    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        a.push_back(tmp);
    }
    map<int, int> x;
    //int maxvalue = 0;
    int maxnum = 0;
    for (int i = 0; i < N; i++)
    {
        x[a[i]]++;
    }
    for (int i = 0; i < N; i++)
    {
        maxnum = max(maxnum, x[a[i] - 1] + x[a[i]] + x[a[i] + 1]);
    }

    cout << maxnum << endl;
    /*
    for (int i = 0; i < N; i++)
    {
        if (x[a[i]] == maxnum)
        {
            cout << x[a[i] - 1] + maxnum + x[a[i] + 1] << endl;
            return 0;
        }
    }*/
    return 0;
}


Measured memory_bytes: 8016
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        Long N = Long.parseLong(in.readLine());
        System.out.println(favoriteSum(N));
    }

    long favoriteSum(long N){
        long sum = 0L;
        for (int r = 1, bound = (int) Math.sqrt(N); r <= bound; r++) {
            if (N % r == 0) {
                long m =  (N / r) - 1;
                if (m > r) {
                    sum += m;
                }
            }
        }
        return sum;
    }

    long simple(long N) {
        long sum = 0;
        for (int m = 1; m < N; m++) {
            long s = N / m;
            long r = N % m;
            if (s == r) {
                sum += m;
            }
        }
        return sum;
    }


    static class CustomReader extends BufferedReader {

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

    }
}

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

int main(){
  int n, count = 0;
  bool f = true;
  cin >> n;
  vector<p> work(n);
  ll time=0;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    work[i] = make_pair(b, a);
  }
  sort(work.begin(), work.end());
  //rep(i, n) cout << work[i].first << endl;
  while(f&& count < n){
    time += work[count].second;
    if(time>work[count].first){
      f = false;
    }
    count++;
    //cout << time << endl;
  }
  if(f) cout << "Yes";
  else cout << "No";
  

  }


Measured memory_bytes: 4772
s_a = list(x for x in input())
s_b = list(x for x in input())
s_c = list(x for x in input())

def turn_a():
  try:
    temp = s_a.pop(0)
    if temp == 'a':
      turn_a()
    elif temp == 'b':
      turn_b()
    elif temp == 'c':
      turn_c()
  except:
    print('A')
  return
 
def turn_b():
  try:
    temp = s_b.pop(0)
    if temp == 'a':
      turn_a()
    elif temp == 'b':
      turn_b()
    elif temp == 'c':
      turn_c()
  except:
    print('B')
  return

def turn_c():
  try:
    temp = s_c.pop(0)
    if temp == 'a':
      turn_a()
    elif temp == 'b':
      turn_b()
    elif temp == 'c':
      turn_c()
  except:
    print('C')
  return

turn_a()
  


Measured memory_bytes: 3188
from itertools import*
s=input();k=int(input());x=0
g=[len(list(v))for k,v in groupby(s)]
for c in g:x+=c//2
x*=k
if s[-1]==s[0] and g[0]%2>0<g[-1]%2:
	if len(s)==g[0]:
		x+=k//2
	else:
		x+=k-1
print(x)

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    long double a, b;
    cin >> a >> b;

    // 処理
    // 出力
    if (a > b) {
        cout << "GREATER" << endl;
    } else if (a < b) {
        cout << "LESS" << endl;
    } else {
        cout << "EQUAL" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
	boolean flag = false;
        int k = 2;
        for(int i = 2; i * (i - 1) <= n * 2; i++){
            if(i * (i-1) == n * 2){
                k = i;
                flag = true;
                break;
            }
        }
        if(!flag){
            System.out.println("No");
            return;
        }
        else{
            System.out.println("Yes");
            System.out.println(k);
            int[][] s = new int[k][k-1];
            int cnt = 0;
            for(int i = 0; i < k-1; i++){
                for(int j = 0; j < k - 1 - i; j++){
                    s[i][j] = ++cnt;
                    s[k - 1 - j][k-2-i] = cnt;
                }
            }
            for(int i = 0; i < k; i++){
                System.out.print(k-1);
                for(int j= 0; j < k-1; j++){
                    System.out.print(" " + s[i][j]);
                }
                System.out.println("");
            }
        }
    }
}

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

int n, a, x[50];
long long dp[60][60][2510];

int main(void) {
    cin >> n >> a;
    for (int i = 0; i < n; i++)
        cin >> x[i];
    dp[0][0][0] = 1;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k <= 50 * n; k++) {
                if (i >= 1 && k < x[i - 1]) dp[i][j][k] = dp[i - 1][j][k];
                if (i >= 1 && j >= 1 && k >= x[i - 1]) dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
            }
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++)
        ans += dp[n][i][a * i];
    cout << ans << endl;
}

Measured memory_bytes: 60544
#include <bits/stdc++.h>
#define INF 1e9
#define MOD 1000000007
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    for (int i = 0; i < M; i++)
    {
        cin >> B[i];
    }
    
    for (int i = 0; i <= N-M; i++)
    {
        for (int j = 0; j <= N-M; j++)
        {
            bool match = true;
            for (int k = 0; k < M; k++)
            {    
                if(A[i+k].substr(j, M) != B[k]){
                    match =false;
                    break;
                }
            }
            
            if(match){
                cout << "Yes" <<endl;
                return 0;
            }
        }
    }
    
    cout << "No"<< endl;

    return 0;
}


Measured memory_bytes: 3600
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll arr[10000];
ll brr[10000];
ll n ;
ll solve(ll x,ll y , ll j){
	ll idx1=j+1,idx2=j+1;
	ll cnt1=0 , cnt2=0;
	while(idx1<n && arr[idx1]>x && arr[idx1++]<y)cnt1++;
	// cerr<<cnt1<<" "<<cnt2<<endl;
	return cnt1;
}
int main(){
	//mahakal(),
    fast;
	cin>> n ;
	ll cnt=0;
	for(ll i=0;i< n ; i++)cin>>arr[i];
	sort(arr,arr+n);
	for(ll i=n-1;i>=0;i--)brr[(n-1-i)]=arr[i];
	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			ll a=arr[i],b=arr[j];
			ll x=abs(a-b);
			ll y=a+b;
			cnt+=solve( x, y,j);
		}
	}
	cout<<cnt<<endl;

	return 0;
}

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

#define ll long long
#define ld long double
#define ull unsigned long long

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

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

    const int MOD = 2019;

    string s;
    cin >> s;
    int n = s.size();
    int suf = 0; // suffix num
    int pot = 1; // power of t0
    ll ans = 0;
    vector<int> cnt_suf(MOD);
    ++cnt_suf[suf]; // empty sufix

    for (int i = n - 1; i >= 0; --i)
    {
        int digit = s[i] - '0';
        suf = (suf + digit * pot) % MOD;
        pot = 10 * pot % MOD;
        ans += cnt_suf[suf];
        ++cnt_suf[suf];
        // db3(digit, suf, ans);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3772
//"I'll live the focused life, because it's the best kind there is" - Winifred Gallagher
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl
const int nax = 1002;
char a[nax][nax];
const int mod = 1e9 + 7;
void add_self(int& a, int b){
	a += b;
	if(a >= mod){
		a -= mod;
	}
}
int main(){
	//freopen("input.txt", "r",stdin);
	int h, w; cin>>h>>w;
	for(int row = 0; row < h; row++){
		string s; cin>>s;
		for(int i = 0; i<int(s.size()); i++)
			a[row][i] = s[i];
	}
	vector<vector<int>> dp(h, vector<int>(w));
	dp[0][0] = 1;
	for(int row = 0; row < h; row++){
		for(int col = 0; col < w; col++){
			for(int r2: {row, row + 1}){
				int c2 = col;
				if(r2 == row){
					c2 = col + 1;
				}
				if(r2 < h && c2 < w && a[r2][c2] == '.'){
					add_self(dp[r2][c2], dp[row][col]);
				}
			}
		}
	}
	cout<<dp[h-1][w-1]<<endl;
	return 0;
}
	


Measured memory_bytes: 5248
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();

	//日付が4月30以降の時1になる→.compareTo("2019/04/30")
			if (S.compareTo("2019/04/30") > 0) {

				System.out.println("TBD");
			}else {
				System.out.println("Heisei");
			}

	}
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,a=0,b;
    scanf("%d",&n);
    while(n--)
    {
    	scanf("%d",&x);
    	if(x%2==1)a++;
	}
	if(a%2==0)printf("YES");
	else printf("NO");
}


Measured memory_bytes: 256
<?php
//error_reporting(0);
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$M) = array_map('intval',explode(" ",trim(fgets(STDIN))));
$a = array_map('intval',explode(" ",trim(fgets(STDIN))));
$sum = array_sum($a);

$choice = 0;
foreach($a as $v) {
  if ($v*4*$M>=$sum) {
    $choice++;
  }
}
if ($choice >= $M) {
  printf("Yes\n");
}
else {
  printf("No\n");
}


Measured memory_bytes: 4728
n = int(input())
mod = 10**9 + 7

n_bit = []
x = n
while(x>0):
    n_bit.append(x%2)
    x //= 2
n_bit = n_bit[::-1]

n_len = len(n_bit)

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

for i,bi in enumerate(n_bit):
    if(bi == 0):
        dp[i+1][0] += dp[i][0] + dp[i][1]
        dp[i+1][1] += dp[i][1]
        dp[i+1][2] += dp[i][1] + dp[i][2]*3
    else:
        dp[i+1][0] += dp[i][0]
        dp[i+1][1] += dp[i][0] + dp[i][1]
        dp[i+1][2] += dp[i][1]*2 + dp[i][2]*3
    dp[i+1][0] %= mod
    dp[i+1][1] %= mod
    dp[i+1][2] %= mod

ans = sum(dp[-1]) % mod
print(ans)

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int sum = 0;
    if (a < b) swap(a, b);
    sum += a;
    a--;
    if (a < b) swap(a, b);
    sum += a;
    a--;
    print(sum);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, k, l[50], res = 0;
int main(void){
    // Your code here!
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> l[i];
    
    sort(l, l + n, greater<int>());
    for (int i = 0; i < k; i++)
        res += l[i];
    
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define rall(i) (i).begin(),(i).end(),greater<int>()
using namespace std;
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T> void print(T x) { std::cout << x << '\n'; }

typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100001
// #define TENFIVE 11

// #define int long long



signed main(){
    

    //以下エラトステネスの篩
    bool sieve[TENFIVE];
    rep(i,TENFIVE)sieve[i] = true;
    // rep(i,TENFIVE)cout<<i<<" "<<sieve[i]<<endl;
    
    sieve[0] = false;
    sieve[1] = false;

    
    int MAX = int(floor(sqrt(TENFIVE)));
    
    FOR(i,2,MAX+1){
        if(sieve[i]){
            // cout<<"hoge"<<endl;
            for(int j = i*2; j<=TENFIVE;j += i){
                sieve[j] = false;
            }

        }
    }
    // rep(i,TENFIVE)cout<<i<<" "<<sieve[i]<<endl;;
    //以上エラトステネスの篩
    int count[TENFIVE] = {0};
    rep1(i,TENFIVE){
        
        if(i%2 == 1 && sieve[i] && sieve[(i+1)/2])count[i]= count[i-1]+1;
        else count[i] = count[i-1];
    }
    // rep(i,7)cout<<count[i]<<endl;
    // cout<<"hoge"<<endl;

    int Q;
    cin>>Q;
    rep(i,Q){
        int l,r;
        cin>>l>>r;
        cout<< count[r] - count[l-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    ll ans = 1;
    vector<ll> c(3,0);
    rep(i,n){
        ll cnt = 0,ind = 0;
        rep(j,3){
            if (a[i] == c[j]){
                cnt++;
                ind = j;
            }
        }
        (ans *= cnt)%=MOD;
        c[ind]++;
    }
    PRINT(ans);
}


Measured memory_bytes: 3952
using System;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split(' ');
			int n = int.Parse(input[0]);
			int l = int.Parse(input[1]);

			int sumAll = 0;

			int minAbs = int.MaxValue;
			int eat = 0;
			for (int i = 0; i < n; i++)
			{
				int t = l + (i + 1) - 1;
				sumAll += t;
				int abs = Math.Abs(t);
				if (abs < minAbs)
				{
					eat = t;
					minAbs = abs;
				}
			}
			Console.WriteLine(sumAll - eat);
		}
	}
}


Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp111 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int sx = st[0];
            int sy = st[1];
            int tx = st[2];
            int ty = st[3];

            int H = tx - sx;
            int W = ty - sy;

            StringBuilder ans = new StringBuilder("");
            //1
            for (int i = 0; i < H; i++) {
                ans.Append("R");
            }
            for (int i = 0; i < W; i++) {
                ans.Append("U");
            }
            //2
            for (int i = 0; i < H; i++) {
                ans.Append("L");
            }
            for (int i = 0; i < W; i++) {
                ans.Append("D");
            }
            //3
            ans.Append("D");
            for (int i = 0; i < H + 1; i++) {
                ans.Append("R");
            }
            for (int i = 0; i < W + 1; i++) {
                ans.Append("U");
            }
            ans.Append("L");
            //4
            ans.Append("U");
            for (int i = 0; i < H + 1; i++) {
                ans.Append("L");
            } 
            for (int i = 0; i < W + 1; i++) {
                ans.Append("D");
            }
            ans.Append("R");

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  int x,t;
  cin>>x>>t;
  cout<<max(0,x-t)<<endl;
  
  return 0;
}


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

int ans[365],c[26],s[365][26],last[26],csum,nowscore,newscore;
const int INF=1e9,d=365,starttemp=12000,endtemp=100;
double temperature,prob;

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

void FIN(bool a){
  if(a){
    ofstream fout("output.txt");
    REP(i,d)fout<<ans[i]+1<<"\n";
    fout.close();
    return;
  }
  REP(i,d)cout<<ans[i]+1<<"\n";
  return;
}
/*
int score(){
  int res=0;
  memset(last,-1,sizeof(last));
  REP(day,d){
    res+=s[day][ans[day]];
    last[ans[day]]=day;
    REP(i,26)res-=c[i]*(day-last[i]);
  }
  return res;
}
*/
int score(){//上のがO(26*365)、こっちがO(365)のスコア計算
  int res=0,minus=csum;
  memset(last,-1,sizeof(last));
  REP(day,d){
    res+=s[day][ans[day]];
    minus-=c[ans[day]]*(day-last[ans[day]]);
    last[ans[day]]=day;
    res-=minus;
    minus+=csum;
  }
  return res;
}
void swap(){
  int RAND=rand();
  int day=RAND%(d-8),diff=((RAND^newscore)&7)+1;
  swap(ans[day],ans[day+diff]);
  newscore=score();
  prob=exp((newscore-nowscore)/temperature);
  if(prob>(rand()%INF)/(double)INF)nowscore=newscore;
  else swap(ans[day],ans[day+diff]);
}
void onechange(){
  int day=rand()%365;
  REP(i,26){
    int tmp=ans[day];
    ans[day]=i;
    newscore=score();
    prob=exp((newscore-nowscore)/temperature);
    if(prob>(rand()%INF)/(double)INF)nowscore=newscore;
    else ans[day]=tmp;
  }
}

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  clock_t start=clock();
  memset(last,-1,sizeof(last));
  cin>>c[0];
  REP(i,26){cin>>c[i];csum+=c[i];}
  REP(i,d)REP(j,26)cin>>s[i][j];
  REP(day,d){
    int idx,mx=-INF;
    REP(i,26){
      int A=c[i]*(day-last[i])+s[day][i];
      if(mx<A)mx=A,idx=i;
    }
    ans[day]=idx,last[idx]=day;
  }
  nowscore=score();
  while(true){
    clock_t nowt=clock();
    const double Time=static_cast<double>(nowt-start)/CLOCKS_PER_SEC;
    if(Time>1.95)break;
    temperature=starttemp+(double)(endtemp-starttemp)*(nowt-start)/(CLOCKS_PER_SEC*1.95);
    REP(_,50)
      if((_^newscore)&1)swap();
      else onechange();
  }
  FIN(0);
}


Measured memory_bytes: 4280