akhauriyash/Code-Regression huggingface dataset:
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

#define INF 100000000


string board[60];
int dx[] = { 1,1,0,-1,-1,-1,0,1 };
int dy[] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	int X, Y;
	cin >> X >> Y;
	rep(i, X) cin >> board[i];

	rep(i, X) {
		rep(j, Y) {
			if (board[i][j] == '.') {
				int cnt = 0;
				rep(k, 8) {
					int x = i + dx[k];
					int y = j + dy[k];

					if (x >= 0 && x < X && y >= 0 && y < Y && board[x][y] == '#')
						cnt++;
				}
				board[i][j] = '0' + cnt;
			}
		}
	}

	rep(i, X) cout << board[i] << endl;
	return 0;
}

Measured memory_bytes: 384
n = int(input())
b = list(map(int, input().split()))
rev_b = b[::-1]
rev_a = [None for _ in range(n)]
rev_a[0] = rev_b[0]
for i in range(1, n-1):
  rev_a[i] = min([rev_b[i], rev_b[i-1]])
rev_a[n-1] = rev_b[n-2]
print(sum(rev_a))

Measured memory_bytes: 3064
#include<stdio.h>
char getScore(int,int,int);
int main(void)
{
  int m,f,r;
  for(;;)
    {
      scanf("%d%d%d",&m,&f,&r);
      if(m==-1&&f==-1&&r==-1) break;
      printf("%c\n",getScore(m,f,r));
    }
  return 0;
}
char getScore(int m,int f,int r)
{
  if(m==-1||f==-1) return 'F';
  else if(m+f>=80) return 'A';
  else if(m+f>=65) return 'B';
  else if(m+f>=50) return 'C';
  else if(m+f>=30)
    {
      if(r>=50) return 'C';
      else return 'D';
    }
  else return 'F';
}


Measured memory_bytes: 2108
N=int(input())
P=10**9+7
A=[int(i) for i in input().split()]
B=[-1 for i in range(N)]
s=(-1,-1)
for i in range(N+1):
    if B[A[i]-1]==-1:
        B[A[i]-1]=i
    else:
        s=(B[A[i]-1],i)
        break
M=N-s[1]+s[0]+1
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,P)[0]
Fact=[0 for i in range(N+2)]
Finv=[0 for i in range(N+2)]
Fact[0]=1
Finv[0]=1
for i in range(1,N+2):
    Fact[i]=(i*Fact[i-1])%P
    Finv[i]=inv(Fact[i])%P
def C(n,k):
    return (((Fact[n]*Finv[k])%P)*Finv[n-k])%P
ans=[0 for i in range(N+1)]
for i in range(1,N+2):
    if i<=M:
        ans[i-1]=(C(N+1,i)-C(M-1,i-1))%P
    else:
        ans[i-1]=C(N+1,i)%P
for i in ans:
    print(i)


Measured memory_bytes: 64236
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

int main() {
  int N, M; cin >> N >> M;
  vi X(M); rep(i,M) cin >> X.at(i);
  
  if(N>=M) {
    cout << 0 << endl;
    return 0;
  }
  
  SORT(X);
  
  vi d(M-1);
  rep(i,M-1) {
    d.at(i) = X.at(i+1)-X.at(i);
  }
  
  SORT(d);
  
  rep(i,N-1) {
    d.pop_back();
  }
  
  cout << accumulate(all(d),0) << endl;
}

Measured memory_bytes: 1024
def dfs(i, f, s, n):
    if i == n-1:
        return sum(list(map(int, f.split("+"))))

    return dfs(i + 1, f + s[i + 1], s, n) + dfs(i + 1, f + "+" + s[i + 1], s, n)

def main2():
    s = input()
    n = len(s)
    print(dfs(0, s[0], s, n))

if __name__ == '__main__':
    main2()

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359;
#define inf (1 << 21);
#define mod 1000000007;

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> Graph(N); //隣接行列
    for (int i = 0; i < M; i++) {
        int A, B; cin >> A >> B;
        A--;
        B--;
        Graph.at(A).push_back(B);
        Graph.at(B).push_back(A);
    }
    queue<int> q;
    vector<int> parent(N, -1);
    q.push(0);
    parent.at(0) = 0;
    while (!q.empty()) {
        int v;
        v = q.front();
        q.pop();
        for (int n : Graph.at(v)) {
            if (parent.at(n) != -1) {
                continue;
            }
            q.push(n);
            parent.at(n) = v;
        }
    }
    bool J = true;
    for (int i = 0; i < N; i++) {
        if (parent.at(i) == -1) {
            J = false;
        }
    }
    if (J) {
        cout << "Yes" << endl;
        for (int i = 1; i < N; i++) {
            cout << parent.at(i) + 1<< endl;
        }
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 10232
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,aa[220000],cnt=0,a,b;
pair<int,int> p[220000];
string s,t,u;
char c;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>aa[i];
    }
    sort(aa,aa+n);
    rep(i,n-1){
        if(aa[i]==aa[i+1]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
}

Measured memory_bytes: 3200
// B - Crane and Turtle
#include <bits/stdc++.h>
using namespace std;

int main(){
	int x,y; cin>>x>>y;
	for(int turu=0; turu<=x; ++turu){
		int kame = x - turu;
		if(turu*2 + kame*4 == y){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}


Measured memory_bytes: 3588
public class Rectangle {
  static void Main(string[] args) {
    var line = System.Console.ReadLine().Trim().Split(' ');
    int a = int.Parse(line[0]);
    int b = int.Parse(line[1]);

    System.Console.WriteLine("{0} {1}", a * b, 2 * (a + b));
  }
}

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 100111, inf = 1000111222;

int main()
{
    //freopen("input.txt", "r", stdin);
    int m[3];
    cin >> m[0] >> m[1] >> m[2];
    sort(m, m + 3);
    cout << m[0] + m[1] << endl;


    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define ppll pair<ll, pll>
#define pii pair<int, int> 
#define mod 998244353
#define pb push_back
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro%mod);
}
vector<int> prime;
void seive(){
    vector<bool > isprime(1000001,true);
    for(int i=2;i*i<=1000000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
bool cmp(pll a,pll b){
    return a.se<b.se;
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll ans=n*n;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
S = [input() for _ in range(N)] + ["AC", "WA", "TLE", "RE"]

S = Counter(S)

print("AC x "+ str(S["AC"]-1) )
print("WA x "+ str(S["WA"]-1) )
print("TLE x "+ str(S["TLE"]-1) )
print("RE x "+ str(S["RE"]-1) )

    



Measured memory_bytes: 17068
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

ll a[100000];
ll rui[100001];
ll ruieven[100001];
int main()
{
	int n,q;
	int ans=0;
	cin>>n>>q;
	for(int i=0;i<n;i++)
		cin>>a[i];
	rui[0]=0;ruieven[0]=0;
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		rui[i+1]=rui[i]+a[i];
		ruieven[i+1]=ruieven[i];
		if(i&1)
			ruieven[i+1]+=a[i];
	}
	ll x,tak;
	for(int i=0;i<q;i++)
	{
		cin>>x;
		//連続で取るゾーンの合計の長さは？
		int ok=0;
		int ng=n+1;
		while(ng-ok>1)
		{
			int mid=(ok+ng)/2;//青木くんと高橋くんが取る枚数
			int rs=mid/2+(mid&1);//高橋くんが取る枚数
			int r=n-rs;//高橋くんが取る先頭
			int l=n-mid;//青木くんが取る先頭
			if((!(mid&1) && abs(a[l+1]-x)>abs(a[r]-x)) || ((mid&1) && abs(a[l]-x)>abs(a[r]-x)))
				ng=mid;
			else
				ok=mid;
		}
		//cerr<<" "<<ok<<endl;
		int rs=ok/2+(ok&1);
		int r=n-rs;
		int l=n-ok;
		tak=rui[n]-rui[r];
		if((n-ok)&1)
			tak+=rui[l]-ruieven[l];
		else
			tak+=ruieven[l];
		cout<<tak<<endl;
	}
	return 0;
}

Measured memory_bytes: 4096
// https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0521?year=2008

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;

    while (cin >> n, n) {
        n = 1000 - n;

        int a = n / 500;
        n %= 500;

        int b = n / 100;
        n %= 100;

        int c = n / 50;
        n %= 50;

        int d = n / 10;
        n %= 10;

        int e = n / 5;
        int f = n % 5;

        int ans = a + b + c + d + e + f;
        cout << ans << endl;
    }
    return 0;
}

/*
 * 
 */


Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
deque <int> Q;
int n;
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i)
    {
        int a;
        scanf("%d", &a);
        if ((n - i) & 1) Q.push_back(a); else Q.push_front(a);
    }
    while (!Q.empty()) printf("%d ", Q.front()), Q.pop_front();
}


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


int main() {

    int t, x;
    cin >> t >> x;
    double ans = double(t) / x;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>


#define ll long long
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define line cout << "\n" ;
using namespace std ;



int main(){
      int t;
      cin>>t;
// AC x 10
// WA x 0
// TLE x 0
// RE x 0
      vector<int> a(4,0);
      string x;
      while(t--){
            cin>>x;
            if(x=="AC") a[0]+=1;
            else if(x=="WA")     a[1]+=1;
            else if(x=="TLE") a[2]+=1;
            else  a[3]+=1;
      }
      cout<<"AC"<<" x "<<a[0]<<endl;
      cout<<"WA"<<" x "<<a[1]<<endl;
      cout<<"TLE"<<" x "<<a[2]<<endl;
      cout<<"RE"<<" x "<<a[3]<<endl;
}


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

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;

ll mod = 1e9+7;

string solve() {
    int H, N, a; cin >> H >> N;
    rep(i, N) {
        cin >> a;
        H -= a;
    }
    if (H <= 0) {
        return "Yes";
    } else {
        return "No";
    }
}

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

	cout << solve() << endl;
}


Measured memory_bytes: 3604
#!/usr/bin/env python
# coding: utf-8

import sys


def main():
    line = sys.stdin.readline()
    t = line.rstrip().split(' ')
    a, b = map(lambda x: int(x), t)
    print(a*b)

    for line in sys.stdin:
        print(line)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	ll x;
	cin>>x;

	ll a=100,res=0;
	while (a<x) {
		res++;
		a+=a/100;
	}
	cout<<res<<'\n';
}


Measured memory_bytes: 3652
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

#define max 1000000

int main(){
	bool is_prime[max] = {};
	for (int i = 2; i < max; ++i) {
		is_prime[i] = 1;
	}
	for (int i = 0; i < max; ++i) {
		if (is_prime[i]) {
			for (int j = i + i; j < max; j += i) {
				is_prime[j] = 0;
			}
		}
	}
	int num_prime[max] = {};
	for (int i = 1; i < max; ++i) {
		num_prime[i] = num_prime[i-1] + is_prime[i];
	}
	int n;
	while (cin >> n) {
		cout << num_prime[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 6048
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 1e5 + 5;
vector <int> adj[MAX];
int deg[MAX], dist[MAX];

int main()
{
	boost;
	int n, m, i, a, b;
	cin >> n >> m;
	fo(i, 0, m) {
		cin >> a >> b;
		++deg[b];
		adj[a].pb(b);
	}
	
	queue <int> q;
	foe(i, 1, n) {
		if(!deg[i]) 
		q.push(i);
	}
	
	while(!q.empty()) {
		int p = q.front();
		q.pop();
		
		for(int v : adj[p]) {
			--deg[v];
			dist[v] = max(dist[v], dist[p] + 1);
			if(!deg[v])
			q.push(v);
		}
	}
	cout << *max_element(dist + 1, dist + n + 1);
}


Measured memory_bytes: 9828
mod = 10 ** 9 + 7

N = int(input())
S1 = input()
S2 = input()
cnt = 0
if S1[0] == S2[0]:
    cnt += 3
    i = 1
    x = True
else:
    cnt += 6
    i = 2
    x = False

while i < N:
    if S1[i] == S2[i]:
        if x:
            cnt *= 2
        else:
            pass
        x = True
        i += 1
    else:
        if x:
            cnt *= 2
        else:
            cnt *= 3
        x = False
        i += 2
print(cnt % mod)


Measured memory_bytes: 3064
import sys

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


def com_once(n, r, MOD):
    if n < r or n < 0 or r < 0:
        return 0
    r = min(r, n - r)
    numer = denom = 1
    for i in range(r):
        numer = numer * (n - i) % MOD
        denom = denom * (i + 1) % MOD
    return numer * pow(denom, MOD - 2, MOD) % MOD


def main():
    n, a, b = map(int, read().split())

    ans = (pow(2, n, MOD) - com_once(n, a, MOD) - com_once(n, b, MOD) - 1) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 63300
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll power(ll n)
{ ll x=2;
    ll r=1;
    while(n>0)
    {
    if(n%2==1)
    r=r*x;
    x=x*x;
    n/=2;
    }
    return r;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll i,j,k,n,m;
  cin>>n;
  ll c=0;
  int f=0;
  if((n&(n-1))==0)
  {
      f=1;
  }
  else
  f=0;
  while(n>0)
  {
      if(n==1)
      {
          c++;break;
      }
      if(n%2==0)
      n/=2;
      else
      n=(n/2)+1;
      c++;
  }
  
  if(f==1)
  cout<<(power(c)-1);
  else
  cout<<(power(c)/2-1);
}

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

using namespace std;

int main() {
    int n, l;
    string s;
    vector<string> v;

    cin >> n >> l;
    for (int i = 0; i < n; i ++) {
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(), v.end());

    for (int i = 0; i < n; i ++) {
        cout << v[i];
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
#define MAX 100000
vector<vector<int>>edge;
bool visited[MAX];
int prenum[MAX],parent[MAX],lowest[MAX],timer;
int N;
void dfs(int current,int prev){
    prenum[current]=lowest[current]=timer;
    timer++;
    visited[current]=true;
    int  next;
    for(int i=0;i<edge[current].size();i++){
        next=edge[current][i];
        if(!visited[next]){
            parent[next]=current;
            dfs(next,current);
            lowest[current]=min(lowest[current],lowest[next]);
        }else if(next != prev){
            lowest[current] = min(lowest[current],prenum[next]);
        }
    }
}
void art_point(){
    timer=1;  //?¨???????????¨????
    dfs(0,-1);
    map<int,int>Mp;
    int np=0;
    //?????¶????????????????????¢???
    for(int i=1;i<N;i++){
        int p=parent[i];
        if(p==0)np++;
        else if(prenum[p]<=lowest[i])Mp[p]++;
        if(np>1)Mp[0]++;
    }
        for(auto itr:Mp)
            cout<<itr.first<<endl;
    
}
signed main(){
    int m;
    cin>>N>>m;
    edge.resize(N);
    rep(i,N)visited[i]=false;
    for(int i=0;i<m;i++){
        int s,t;
        cin>>s>>t;
        edge[s].push_back(t);
        edge[t].push_back(s);
    }
    art_point();
}

Measured memory_bytes: 4476
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_HW 1000

using namespace std;
typedef pair<int, int> ipair;

int H, W;
bool cells[MAX_HW][MAX_HW];
int d[MAX_HW][MAX_HW];

class Point {
    public:
    int x, y;
    Point() {}
    Point(int x, int y) {this->x = x; this->y = y; }
};

int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main(int argc, char **argv) {
    queue<Point> que;

    cin >> H >> W;
    for(int i = 0; i < H; ++i)
        for(int j = 0; j < W; ++j) {
            char ch;
            cin >> ch;

            cells[i][j] = ch == '#';
            d[i][j] = ch == '#' ? 0 : INF;
            if(ch == '#')
                que.push(Point(i, j));
        }

    while(!que.empty()) {
        Point cur = que.front();    que.pop();
        for(int i = 0; i < 4; ++i) {
            Point next = Point(cur.x + dir[i][0], cur.y + dir[i][1]);
            if(next.x >= 0 && next.x < H && next.y >= 0 && next.y < W) {
                    if(d[next.x][next.y] > d[cur.x][cur.y] + 1) {
                        d[next.x][next.y] = d[cur.x][cur.y] + 1;
                        que.push(Point(next.x, next.y));
                    }
                }
        }
    }
    
    int res = -INF;
    for(int i = 0; i < H; ++i)
        for(int j = 0; j < W; ++j)
            res = max(res, d[i][j]);
    
    cout << res << endl;
}

Measured memory_bytes: 13328
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int x,y,z;
	int e;
	int min;

	while(1){
		cin>>e;
		if(e==0) break;

		min=e;
		for(z=0;z*z*z<=e;z++){
			for(y=0;z*z*z+y*y<=e;y++){
				x=e-z*z*z-y*y;

				if(min>(x+y+z)) min=x+y+z;
			}
		}
		cout<<min<<endl;
	}
	return 0;
}

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

class MyComparator implements Comparator{
	public int compare(Object arg0, Object arg1){
		Point x = (Point)arg0;
		Point y = (Point)arg1;

		if(x.x > y.x){
			return 1;
		}
		else if(x.x < y.x){
			return -1;
		}
		else{
			return 0;
		}
	}
}

class Point{
	int x;
	int y;
	Point(int x, int y){
		this.x = x;
		this.y = y;
	}
}

class Main{
	public static final Comparator Comp = new MyComparator();
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i=0;i<n;i++){
        	a[i] = sc.nextInt();
        	b[i] = sc.nextInt();
        }
        long ans = 0;

        PriorityQueue pq = new PriorityQueue(n, Comp);
        for(int i=0;i<n;i++){
        	Point p = new Point(a[i], b[i]);
        	pq.add(p);
        }

        while(m>0){
        	Point p = (Point)pq.poll();
        	int x = (int)p.x;
        	int y = (int)p.y;
        	if(y<=m){
        		ans += (long)x * (long)y;
        		m -= y;
        	}
        	else{
        		ans += (long)x * (long)m;
        		m = 0;
        	}
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 87188
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int nums[n];
  map<int,int> mp;
  REP(i,n) {
    cin >> nums[i];
    ++mp[nums[i]];
  }
  if(mp.size() == n) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

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

  char a, b;
  cin >> a >> b;

  if (a == b) cout << "H\n";
  else cout << "D\n";

  return (0);
}


Measured memory_bytes: 3544
n = int(input())
xl = [list(map(int,input().split())) for i in range(n)]
move =[[xl[i][0] - xl[i][1],xl[i][0] + xl[i][1]]for i in range(n)]
move.sort(key=lambda x: x[1])

cnt = 0
for i in range(n):
    if(i==0):
        last=move[i][1]
        cnt+=1
        continue
    if(move[i][0]<last):
        continue
    last = move[i][1]
    cnt += 1
print(cnt)

Measured memory_bytes: 42792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N, K;
  long double ans = 0;
  cin >> N >> K;
  REP(i, N) {
    long double kakuritu = 1;
    ll now = i + 1;
    while (now < K) {
      now *= 2;
      kakuritu *= 0.5;
    }
    ans += kakuritu;
  }
  cout << setprecision(100) << fixed << ans / N << endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    s += "R";
    int rs,re,ls,le;
    rs = 0;
    le = n-1;
    vector<int> ans(n,0);
    for(int i = 1;i <= n;i++){
        if(s[i] == 'L' && s[i-1] == 'R'){
            re = i-1;
            ls = i;
        }else if(s[i] == 'R' && s[i-1] == 'L'){
            le = i-1;
            ans[re] = (le-ls+1)/2 + (re-rs+2)/2;
            ans[re+1] = (le-ls+2)/2 + (re-rs+1)/2;
            rs = i;
        }
    }
    for(int i = 0;i < n;i++){
        cout << ans[i] << " ";
    }
}

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

using namespace std;

typedef long long  ll;

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

    int n, q;

    // Input
    cin >> n;
    vector<int> s(n + 1);
    for (int i = 0; i < n; ++i)
        cin >> s[i];
    cin >> q;

    int ans = 0, idx, t;
    for (int i = 0; i < q; ++i) {
        cin >> t;
        s[n] = t;
        idx = 0;
        while (s[idx] != t)
            ++idx;
        if (idx != n)
            ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1232
import sys

data = sys.stdin.readlines()
_data = data[0].split()
kakaku = data[1].split()
ans = 0

kazu = int(_data[1])
list_int = [int(n) for n in kakaku]
list_int.sort()
for i in range(kazu):
  ans += list_int[i]
  
print(ans)

Measured memory_bytes: 62440
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}


signed main(void) {
    int n;
    vector<vector<string>> s(10, vector<string>(1));
    cin >> n;
    s[0][0] = "";
    repi(i, 1, 10) {
        rfor(x, s[i - 1]) {
            s[i].push_back(x + "3");
            s[i].push_back(x + "5");
            s[i].push_back(x + "7");
        }
    }
    set<string> ans;
    rfor(v, s) {
        rfor(str, v) {
            if(str.find("3") == string::npos) continue;
            if(str.find("5") == string::npos) continue;
            if(str.find("7") == string::npos) continue;
            if(stoi(str) > n) continue;
            ans.insert(str);
        }
    }
    print(ans.size());


    return 0;
}


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

namespace ABC140C
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadInt;
            var B = cin.ReadIntArray(N - 1);


            var A = new int[N];
            A[0] = B[0];
            // A[1] = Min(B[0], B[1]);
            for(int i = 1; i < N - 1; i++)
            {
                A[i] = Min(B[i - 1], B[i]);
            }
            A[N - 1] = B[N - 2];

            Console.WriteLine(A.Sum());
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main(){
int H,W;
cin>>H>>W;
char a[H][W];
for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
        cin>>a[i][j];
    }
}
int cnt=0;
string x;
for(int i=0;i<H;i++){
   for(int j=0;j<W;j++){
        if(a[i][j]=='.'||a[i][j]=='*')cnt++;
    }
    if(cnt==W){
       for(int j=0;j<W;j++){
        a[i][j]='*';
    }

    }
    cnt=0;
}
cnt=0;
for(int i=0;i<W;i++){
   for(int j=0;j<H;j++){
        if(a[j][i]=='.'||a[j][i]=='*')cnt++;
    }
    if(cnt==H){
       for(int j=0;j<H;j++){
        a[j][i]='*';
    }

    }
    cnt=0;
}
bool b=false;
for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
        if(a[i][j]!='*'){
        cout<<a[i][j];
        b=true;
        }
        if(j==W-1&&b)cout<<endl;
    }
    b=false;

}

return 0;
}

Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	mod = 1000000007
	t = readline() |> chomp
	s = Array{Int,1}(length(t))
	for i in 1:length(t)
		if t[i] == '?'
			s[i] = 99
		else
			s[i] = parseInt(t[i])
		end
	end
	g = zeros(Int,13,13)
	for i in 0:12
		for j in 0:12
			g[i+1,j+1] = (10*i+j)%13
		end
	end
	dp = zeros(Int,length(s),13)
	if s[1] == 99
		for i in 1:10
			dp[1,i] = 1
		end
	else
		dp[1,s[1]+1] = 1
	end
	for i in 2:length(s)
		if s[i] == 99
			for j in 1:13
				for k in 1:10
					x = g[j,k]+1
					dp[i,x] = (dp[i,x]+dp[i-1,j])%mod
				end
			end
		else
			for j in 1:13
				x = g[j,s[i]+1]+1
				dp[i,x] = (dp[i,x]+dp[i-1,j])%mod
			end
		end
	end
	println(dp[length(s),6])
end

main()

Measured memory_bytes: 138936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h[200010],n,k;
bool cmp(ll a,ll b)
{
  return a>b;
}
int main()
{
  cin>>n>>k;
  for(int i=1;i<=n;i++)
    cin>>h[i];
  sort(h,h+n+1,cmp);
  ll ans=0;
  for(int i=k;i<=n;i++)
    ans+=h[i];
  cout<<ans;
  return 0;
}


Measured memory_bytes: 5140
#include<iostream>
     
    using namespace std;
     
    long long int dp[112345];
     
    int N,W;
    int w[110],v[110];
    int main () {
        cin >> N >> W;
        for(int i=0; i<N; i++) cin >> w[i] >> v[i];
        for(int i=0; i<N; i++) {
            for(int j=W; j >= w[i]; j--) {
                dp[j] = max( dp[j], dp[ j - w[i] ] + v[i]);
            }
        }
        cout << dp[W] << endl;
        return 0;
    }

Measured memory_bytes: 1024
n,a,b = map(int,input().split())
s = input()
ans = ["0"]*n
acnt = 0
bcnt = 0
for i in range(n):
  if s[i] == "a":
    if acnt < a+b:
      acnt += 1
      ans[i] = "Yes"
    else:
      ans[i] = "No"
  elif s[i] == "b":
    bcnt += 1
    if acnt < a+b and bcnt <= b:
      acnt += 1
      ans[i] = "Yes"
    else:
      ans[i] = "No"
  else:
    ans[i] = "No"
print(*ans,sep='\n')

Measured memory_bytes: 6344
#include <bits/stdc++.h>
#include <iostream>
// #include <unordered_map>
#define vi vector <ull>
#define ii pair<ull,ull>
#define vii vector<ii>

#define seti set<ull>
#define mii map<ull,ull>
#define um unordered_map
#define ll long long
#define ull  long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MAX 100100
#define _ << " " <<

using namespace std;




void solve(){


	int n, m;
	cin >> n >> m;

	ull w[n+1], c[n+1];
	for(int i = 1 ; i <= n; i++){
		cin >> w[i] >> c[i];
	}

	ull dp[n+1][m+1];

	for(int i = 0; i <= n; i++){
		dp[i][0] = 0;
	}
	for(int i = 0; i <= m; i++){
		dp[0][i] = 0;
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(j-w[i] >= 0){
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+c[i]);			
			}else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}

	cout << dp[n][m];

}


int main(){
	// freopen("data.in", "r", stdin);
	// freopen("data.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ull q;
	// cin >> q;
	q = 1;
	for(ull i = 0; i < q; i++){
		// cout << "Case #" << i+1 << ":" << endl;

		solve();
		// cout << endl;
	}

	

	return 0;
}


Measured memory_bytes: 79232
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort(reverse=True)
    Alice = 0
    Bob = 0
    for i in range(len(A)):
        if i % 2 == 0:
            Alice += A[i]
        else:
            Bob += A[i]
    print(Alice - Bob)
main()

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

int main(){
  int n, a = -2000000000, b;
  int A[200000];
  
  cin>>n;
  for(int i = 0; i < n; i++)cin >> A[i];
  
  b = A[0];

  for(int i = 1;i < n; i++){
      a = max(a,A[i] - b);
      b = min(b,A[i]);



  }
  cout<<a<<endl;
}


Measured memory_bytes: 3852
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

LL f(LL  n, LL b) {
	LL ret = 0;
	while (n) {
		ret += n % b;
		n /= b;
	}
	return ret;
}

int main() {
	LL n, s;
	cin >> n >> s;
	if (n == s) {
		cout << n + 1 << endl;
		return 0;
	}
	for (LL b = 2; b*b <= n; b++) {
		if (f(n, b) == s) {
			cout << b << endl;
			return 0;
		}
	}
	LL ret = 1e18;
	for (LL p = 1; p*p < n; p++) {
		LL b = (n - s) / p + 1;
		LL q = n - p * b;
		if (p + q == s && q < b && 0<= q) {
			ret = min(ret, b);
		}
	}
	if (ret == 1e18) ret = -1;
	cout << ret << endl;
	return 0;
}

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

int top, S[1000];

void push(int x) {
  S[++top]=x;
}
int pop() {
  top--;
  return S[top+1];
}
int main() {
  char s[100];
  int a, b;
  top=0;
  while (scanf("%s",s)!=EOF) {
    if (s[0]=='+') {
      a=pop();
      b=pop();
      push(a+b);
    } else if (s[0]=='-') {
      b=pop();
      a=pop();
      push(a-b);
    } else if (s[0]=='*') {
      a=pop();
      b=pop();
      push(a*b);
    } else {
      push(atoi(s));
    }
  }
  cout<<pop()<<endl;
  return 0;
}



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

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

  int count = 0;

  rep(i, s.length()) {
    if (s[i] != t[i]) {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3916
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
ab.sort(key=lambda x:x[0])
br=set([])
ans=0
now=[0,n+1]
for a,b in ab:
  #print('now',now)
  if now[1]<=a:
    ans+=1
    now=[a,b]
  else:
    now[0]=a
    now[1]=min(now[1],b)
print(ans+1)

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

int main() {
    int n;
    cin>>n;
    char a[n];
    cin>>a;
    vector<int> b;
    for(int i=0;i<n;i++) {
        if(a[i] == 'R')
            b.push_back(i);
    }
    int y = b.size()-1;
    int i=0;
    int c=0;
    while(i < n && y >= 0) {
        if(a[i] == 'W') {
            if( i < b[y]) {
                a[b[y]] = 'W';
                y--;
                c++;
            } else {
                break;
            }
        }
        i++;
    }
    cout<<c<<"\n";

}

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

int N,K;
int p[1007];
int main(){
    cin >> N >> K;
    for(int i = 0;i < N;i++){
        cin >> p[i];
    }
    long long int num = 0;
    sort(p,p + N);
    for(int i = 0;i < K;i++){
        num += p[i];
    }
    cout << num << endl;
}

Measured memory_bytes: 3632
#include <iostream>                           
using namespace std;                          
                                              
int main()                                    
{                                             
  int N;                                      
  cin >> N;                                   
  int h[N];                                   
  for (int i = 0; i < N; i++ ){               
    cin >> h[i];                              
  }                                           
  h[0]--;                                     
  bool flag = true;                           
  for (int i = 1; i < N && flag ; i++){       
    if (h[i] - h[i-1] < 0) flag = false;      
    else if (h[i] - h[i-1] == 0) h[i]++;      
    h[i]--;                                   
  }                                           
  if (flag) cout << "Yes" << endl;            
  else cout << "No" << endl;                  
}                                             

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int inf=1000000005;
int v[5005];
int w[5005];
int k[5005];
int dp[10005];
int cnt;
int main(){
	int n,W;cin>>n>>W;
	fill(dp,dp+10002,0);
	dp[0]=0;
	for(int i=1;i<=n;i++)cin>>v[i]>>w[i]>>k[i];
	for(int i=n;i>=1;i--){
		while(k[i]>1){
			int cnt=1;
			while(k[i]>cnt){
				k[i]-=cnt;
				n++;
				v[n]=v[i]*cnt;
				w[n]=w[i]*cnt;
				cnt*=2;
			}
		}
	}
	for(int i=1;i<=n;i++)
		for(int j=W;j>=w[i];j--)
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
	cout<<dp[W]<<endl;
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  bool chk;
  for (int i=0;i<s.size();i++){
    if (i>0 && s[i] == s[i-1]){
      cout << "Bad"  << endl;
      chk = false;
      break;
    }
    chk = true;
  }
  if (chk){
    cout << "Good"  << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int num[]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
    for(int i=0,x,y;i<n;i++){
        cin>>x>>y;
        if(x<6&&y<6){
            int sum=y-x;
            if(sum>0){
                cout<<num[x];
                for(int j=x+1;j<=y;j++)cout<<" "<<num[j];
                cout<<endl;
            }
            else {
                cout<<num[15-x];
                for(int j=16-x;j<16-y;j++)cout<<" "<<num[j];
                cout<<endl;
            }
        }
        else{
            cout<<num[x];
            for(int j=x+1;num[j-1]!=y;j++){
                if(j==16)j=1;
                cout<<" "<<num[j];
            }
            cout<<endl;
        }
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,mod=1e9+7;
int aa[N+2],cnt[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n;cin>>n;
  for(int i=1;i<=n;i++)cin>>aa[i],aa[i]++;

  int ans=1;cnt[0]=3;
  for(int i=1;i<=n;i++)
  {
    ans=(1LL*ans*(cnt[aa[i]-1]-cnt[aa[i]]))%mod;
    cnt[aa[i]]++;
  }
  cout<<ans<<endl;
  return 0;
}

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

#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	vector<ll> v;
	v.pb(a * c);
	v.pb(a * d);
	v.pb(b * c);
	v.pb(b * d);
	if (b >= 0 and a <= 0) {
		v.pb(0 * c);
		v.pb(0 * d);
	} if (c <= 0 and d >= 0) {
		v.pb(a * 0);
		v.pb(b * 0);
	}
	cout << *max_element(v.begin(), v.end()) << endl;	
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

bool check(const vl& L,const ll& N){
	FOR(i,0,N-1)if(L[i+1] < L[i])return 0;
	return 1;
}

vl Sort(vl L,ll N){
	random_device rnd;
	while(!check(L,N)){
		ll a = rnd()%N;
		ll b = rnd()%N;
		if(L[a] > L[b])swap(L[a],L[b]);
	}
	return L;
}

signed main(){
	ll N;
	cin >> N;
	vl L(N);
	FOR(i,0,N)cin >> L[i];
	vl ans = Sort(L,N);
	ll SUM = 0;
	FOR(i,0,N)SUM += ans[i];
	Yes(SUM-ans[N-1] > ans[N-1]);
}

Measured memory_bytes: 256
#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 k,x;
  cin >> k >> x;
  if(k*500 >= x) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = n; i >= 0; i--)
#define For(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
template <class T = int> T in(){T x; cin >> x; return (x);}

int main(void){
    string S;
    cin >> S;
    int N[S.length()];
    transform(ALL(S), N, [](char c) {return c - '0'; });

    ll result = 0;
    
    ll temp = 0;
    rep(i, S.length()){
        if(N[i] != temp){
            result ++;
        }
        
        if(temp == 0){
            temp = 1;
        }else{
            temp = 0;
        }
    }
    
    if(S.length() - result < result){
        result = S.length() - result;
    }
    
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 848
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL s;

int main(){
    cin >> s;
    if(s == 1000000000000000000){
        cout << "0 0 1000000000 1000000000 1000000000 0" << endl;
        return 0;
    }
    LL sqs = (sqrt(s));
    if(sqs*sqs != s)sqs++;
    cout << "0 0 " << sqs << " 1 " << sqs * sqs - s << " " << sqs << endl;
}

Measured memory_bytes: 256