akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

struct mypair{
    int i;
    int a;
};

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

    int h,w;
    int n;

    cin >> h >> w;
    cin >> n;
    vector<mypair> a(n);
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        a[i] = mypair{i+1,t};
    }

    vector<vector<int>> c(h,vector<int>(w));

    bool frag = true;

    for(int i = 0; i < h; i++){
        if(frag){
            for(int j = 0; j < w; j++){
                c[i][j] = a[0].i;
                a[0].a--;
                if(a[0].a == 0){
                    a.erase(a.begin());
                }
            }
            frag = false;
        }else{
            for(int j = w-1; j >= 0; j--){
                c[i][j] = a[0].i;
                a[0].a--;
                if(a[0].a == 0){
                    a.erase(a.begin());
                }
            }
            frag = true;
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(j > 0) cout << " ";
            cout << c[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 384
/**
*    author:  souzai32
*    created: 08.08.2020 00:36:14
**/

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

int main() {

    string s;
    cin >> s;
    int n=s.size();

    int num1=-1,num2=-1;

    rep(i,n-1){
        if(s.at(i)==s.at(i+1)){
            num1=i+1;
            num2=i+2;
        }
    }
    rep(i,n-2){
        if(s.at(i)==s.at(i+2)){
            num1=i+1;
            num2=i+3;
        }
    }

    cout << num1 << ' ' << num2 << endl;
}

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

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

    int v = s.size() / 2;
    //cout << s << v << endl;

    string s2 = s.substr(v + 1);
    //cout << s2 << endl;
    //reverse(s2.begin(), s2.end());
    //cout << s2 << endl;

    if(s.substr(0,v) == s2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec t(N+1,0), x(N+1,0), y(N+1,0);
    REP(i,1,N+1) cin >> t[i] >> x[i] >> y[i];

    bool f = true;
    REP(i,1,N+1) {
        ll dt = t[i] - t[i-1];
        ll d = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]);
        if(dt - d >= 0 && (dt - d) % 2 == 0) continue;
        else {
            f = false;
            break;
        } 
    }
    if(f) PR("Yes");
    else PR("No");

    return 0;
}

/*



*/

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

namespace abc140_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var a = CIn.ReadIntArray(n);
      var b = CIn.ReadIntArray(n);
      var c = CIn.ReadIntArray(n - 1);

      var sum = b.Sum();

      for (var i = 0; i < n - 1; i++)
      {
        if (a[i] + 1 == a[i + 1])
        {
          sum += c[a[i] - 1];
        }
      }

      Console.WriteLine(sum);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ll A,B;
  cin >>A;
  ll i,count,d;
  B=A-1;
  count=0;
  if(B==1){B=2;}
  else{
  for(i=0;count==0;i++){
    B=B+1;
    for(d=2;d<B;d++){
    if(d==B-1){count=1;break;}
      if(B%d==0){break;}
      }
  }}
  
  
   cout << B << endl;
}


Measured memory_bytes: 256
# -*- coding=utf-8 -*-
import itertools

count = int(input())
_list = list(map(int, input().split(" ")))

count2 = int(input())
_answers = list(map(int, input().split(" ")))

desc = []
checked = False

# answersの数だけloopして取ってくる
for answer in _answers:
    checked = False
    tmp = [i for i in _list if answer >= i]

    # そもそもtmpの中身をsumしてanswer未満ならば強制的にno
    if answer > sum(tmp):
        desc.append("no")

    # itertoolsのコンビネーションを使用して解く
    else:
        for i in range(len(tmp) + 1):
            if checked == True:
                break

            tmp2 = list(itertools.combinations(tmp, i))
            for tmp3 in tmp2:
                if sum(tmp3) == answer:
                    desc.append("yes")
                    checked = True
                    break

        if checked != True:
            desc.append("no")

for i in desc:
    print(i)



Measured memory_bytes: 58496
#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>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long
#define ff first
#define ss second

ll n, a[300009], ans[64], mod = 1000000007;
ll freq[64];

void func(ll x)
{
    for(ll i = 0; x; i++)
    {
        freq[i] += (x&1);
        x = x >> 1;
    }
}

ll po(ll a, ll b)
{
    if(b == 0)
        return 1;
    ll x = 1;
    if(b&1)
        x = a%mod;
    ll y = po(a, b/2);
    return (((y*y)%mod)*x)%mod;
}

int main()
{
    ll i, j;
    cin >> n;

    for(i = 0; i < n; i++)
    {
        cin >> a[i];
        func(a[i]);
    }

//    for(auto u : freq)
//        cout << u.ff << " " << u.ss << endl;

    for(i = 0; i <= 62; i++)
    {
        for(j = 0; j < n; j++)
        {
            if(a[j] & (1LL << i))
            {
                ans[i] += (n-j) - freq[i];
                freq[i]--;
            }
            else
                ans[i] += freq[i];
        }
    }

    ll x = 0;
    for(i = 0; i <= 62; i++)
        x = (x + (ans[i]%mod)*po(2LL, i))%mod;
    cout << x;
}

Measured memory_bytes: 2560
let z=List.fold_left2 and k=[0;1;2;3]and h()=Scanf.scanf"%d %d %d %d "(fun a b c d->[a;b;c;d]);;
let rec f()=
  let a,b=h(),h()in
  let m,n=z(fun(m,n)s i->z(fun(p,q)x j->if x=s&&i=j then(p+1,q)else if x<>s then(p,q)else(p,q+1))(m,n)a k)(0,0)b k in
  f(Printf.printf "%d %d\n"m n);;
try f()with _->()

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

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (a > b) a = b; }

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

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, k; cin >> n >> k;

  cout << (n % k != 0) << endl;

  return (0);
}


Measured memory_bytes: 3604
#include <stdio.h>

int dfs(int n, int s, int x){
  int sum=0;
  if(n==0 && s==0)    return 1;
  if(n>0){
      for(int i=x; i<10; i++){
          if(s-i>=0)  sum+=dfs(n-1, s-i, i+1);
      }
  }
  return sum;
}

int main(void){
  int n, s;
  while(scanf("%d %d",&n,&s)!= EOF){
      if(n==0 && s==0)    break;
      printf("%d\n",dfs(n, s, 0));
  }
  return 0;
}



Measured memory_bytes: 2024
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N, A, B, C, D;
	static double EPS = 1e-8;

	public static void main(String[] args) {
		N = sc.nextInt();
		for (int i = 0; i < N; ++i) {
			A = sc.nextInt();
			B = sc.nextInt();
			C = sc.nextInt();
			D = sc.nextInt();
			if (A < 0) {
				A *= -1;
				B *= -1;
				C *= -1;
				D *= -1;
			}
			int[] ans = solve();
			System.out.println(ans[0] + " " + ans[1]);
		}
	}

	static int[] solve() {
		int[] ret = new int[2];
		int QA = 3 * A;
		int QB = 2 * B;
		int QC = C;
		int Q = QB * QB - 4 * QA * QC;
		if (Q < 0) {
			double f = f(0);
			if (f == 0) {
				return new int[] { 0, 0 };
			} else if (f > 0) {
				return new int[] { 0, 1 };
			} else {
				return new int[] { 1, 0 };
			}
		} else if (Q == 0) {
			double axis = -QB / 2.0 / QA;
			double f = f(axis);
			if (Math.abs(f) < EPS) {
				if (axis == 0) {
					return new int[] { 0, 0 };
				} else if (axis > 0) {
					return new int[] { 3, 0 };
				} else {
					return new int[] { 0, 3 };
				}
			} else {
				double f0 = f(0);
				if (f0 > 0) {
					return new int[] { 0, 1 };
				} else {
					return new int[] { 1, 0 };
				}
			}
		} else {
			double x1 = (-QB - Math.sqrt(Q)) / 2.0 / QA;
			double x2 = (-QB + Math.sqrt(Q)) / 2.0 / QA;
			double v1 = f(x1);
			double v2 = f(x2);
			if (Math.abs(v1) < EPS) {
				if (x1 < -EPS) {
					ret[1] += 2;
				} else if (x1 > EPS) {
					ret[0] += 2;
				}
			} else if (v1 > EPS) {
				double r = findRoot(-1000, x1, 1);
				if (r < -EPS) {
					ret[1]++;
				} else if (r > EPS) {
					ret[0]++;
				}
			}
			if (Math.abs(v2) < EPS) {
				if (x2 < -EPS) {
					ret[1] += 2;
				} else if (x2 > EPS) {
					ret[0] += 2;
				}
			} else if (v2 < EPS) {
				double r = findRoot(x2, 1000, 1);
				if (r < -EPS) {
					ret[1]++;
				} else if (r > EPS) {
					ret[0]++;
				}
			}
			if (v1 > EPS && v2 < EPS) {
				double r = findRoot(x1, x2, -1);
				if (r < -EPS) {
					ret[1]++;
				} else if (r > EPS) {
					ret[0]++;
				}
			}
			return ret;
		}
	}

	static double findRoot(double l, double r, int sign) {
		for (int i = 0; i < 1000; ++i) {
			double m = (l + r) / 2;
			double v = f(m) * sign;
			if (v < 0) {
				l = m;
			} else {
				r = m;
			}
		}
		return r;
	}

	static double f(double x) {
		return A * x * x * x + B * x * x + C * x + D;
	}

}

Measured memory_bytes: 25816
N = int(input())
ans = 0
for i in range(1,N+1):
    if i % 2 == 0:
        continue
    tmp = 0
    for k in range(1,i+1):
        if i % k == 0:
            tmp += 1
    if tmp == 8:
        ans += 1
print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
#define int ll
#define INF LLONG_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

// factorize
vector<pair<ll, ll> > prime_factorize(ll n) {
  vector<pair<ll, ll> > res;
  for (ll p = 2; p * p <= n; p++) {
    if (n %p != 0) continue;
    int num = 0;
    while (n % p == 0) {
      num++;
      n /= p;
    }
    res.push_back(make_pair(p,num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}

// enumerate divisors
vector<pair<int, int>> enum_div(int n) {
  vector<pair<int, int>> res;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(make_pair(n/i, i));
    } 
  }
  return res;
}

signed main() {
  int N; cin >> N;
  vector<pair<int, int>> T = enum_div(N);
  int m = INF;
  for (auto x: T) {
    m = min(m, x.first+x.second-2);
  }

  cout <<m << endl;
}


Measured memory_bytes: 384
#include<iostream>
 
using namespace std;
 
int n;
long long a[100005];
long long ans1, ans2, sum;
 
void solver(){
  sum = 0;
  for(int i = 1, s = 1; i <= n; ++i, s *= -1){
    sum += a[i];
    if(sum * s <= 0)ans1+=abs(sum-s),sum=s;
  }
  sum = 0;
  for(int i = 1, s = -1; i <= n; ++i, s *= -1){
    sum += a[i];
    if(sum * s <= 0)ans2+=abs(sum-s),sum=s;
  }
  cout << min(ans1, ans2) << endl;
}
 
int main(){
  cin >> n;
  for(int i = 1; i <= n; ++i){
    cin >> a[i];
  }
  solver();
}


Measured memory_bytes: 1024
// #include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
const int MOD = 1e9 + 7; // 10^9 + 7
using namespace std;

// ------------------ コンビネーション関数 ------------------ //
// ---------------- 使用前「COMinit();」必須 ---------------- //
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// ------------------ 最大公約数関数 ------------------ //
int GCD(int x, int y) {
	if (x == 0) return y;
	else GCD(y % x, x);
}

// ------------------ ベクター表示 ------------------ //
void printVec(vector<int>& vec) {
	cout << "";
	for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
	cout << endl;
}

// ------------------ ベクター合計 ------------------ //
int sumVec(vector<int> v) {
	int sum = 0;
	for (size_t i = 0; i < v.size(); i++) sum += v[i];
	return sum;
}


// ------------------------------------------------ //
// ------------------ ここから下 ------------------ //
// ------------------------------------------------ //

int main(void) {

	int A, B, C, D;
	cin >> A >> B >> C >> D;

	while (true) {

		C = C - B;
		if (C <= 0) {
			cout << "Yes" << endl;
			break;
		}
		A = A - D;
		if (A <= 0) {
			cout << "No" << endl;
			break;
		}

	}

	return 0;
}

Measured memory_bytes: 3596
n=parse(Int,readline())
println((BigInt[1 1 0 1 -2;1 0 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 0 0 1]^n*[2*n*n-n;n*n;n;1;1])[4]%(10^9+7))

Measured memory_bytes: 236860
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.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 < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll MOD = (ll)pow(10.0, 9.0) + 7;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll min(ll a, ll b)
{

	return (a < b) ? a : b;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }






char A[1005][1005];
ll dp[1005][1005];
int main() {
	ll H, W;

	cin >> H >> W;



	auto in = [&](int a, int b) { return a >= 0 && b >= 0 && a < H && b < W; };


	rep(i, H) {
		rep(j, W) {
			dp[i][j] = inf;

		}
	}

	queue<pint> q;
	rep(i, H) {
		rep(j, W) {
			cin >> A[i][j];
			if (A[i][j] == '#') {
				dp[i][j] = 0;
				q.push({ i, j });
			}
		}
	}



	ll cx, cy;
	while (!q.empty()) {

		cx = q.front().first;
		cy = q.front().second;

		rep(i, 4) {
			ll nx = cx + dx[i].first, ny = cy + dx[i].second;
			if (in(nx, ny) && dp[nx][ny] == inf) { dp[nx][ny] = min(dp[nx][ny], dp[cx][cy] + 1); q.push({ nx, ny }); }

		}

		q.pop();
	}

	ll m = 0;
	rep(i, H) {
		rep(j, W) {


			m = max(dp[i][j], m);
		}
	}


	cout << m << endl;
	return 0;
}

Measured memory_bytes: 25524
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char c[] = str.toCharArray();
        int n = str.length();
        int p = 2019;
        
        // ans: i桁目～j桁目の部分列が2019の倍数であるパターン数
        // ex. 1817181712114
        //         ^^^^^
        long ans = 0;
        
        // 2019の倍数になる桁i, jの組み合わせ全探索はO(N^2)
        // -> 各桁の「2019の余り」をO(N)で計算する。
        
        // d'[i]: 右からi桁目の値 * 10^i (mod 2019)
        // ex. 1817181712114
        // d'[0]: 4 % 2019 -> 4
        // d'[1]: 10 % 2019 -> 10
        // d'[5]: 700000 (mod 2019) -> ?
        // ≡ 7 * 10 * 10^4
        // ≡ 7 * 19240
        // ≡ 7 * 1069 = 7483 % 2019 = 1426
        
        // d[i]: d'[i]の累積和
        // d = {4,14,114,95}
        int[] d = new int[n+1];
        // ten: 10^i (mod 2019)
        int ten = 1;
        
        // d[i]を計算する
        // (右の桁(c[n-1])から順に見る)
        for (int i = n - 1; i >= 0; i--) {
            // 1000000 % 2019は計算しんどいので、
            int a = ((c[i] - '0') * ten) % p;
            d[i] = (d[i+1] + a) % p;
            ten = (ten * 10) % p;
        }
        
        // 「d[i] = d[j]となる」とは、
        // 「ex. 181712114 % 2019 = 2114 % 2019」。
        // -> 181710000 ≡ 0 (mod 2019)
        // -> (合同式で割り算はmod pと互いに素でないと不能)
        // -> (gcd(2019, 10) = 1)
        // -> 18171 ≡ 0 (mod 2019)
        // -> 18171 % 2019 = 0
        // -> 18171は2019の倍数
        
        // map: d[]の値の頻度
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = n; i >= 0; i--) {
            int key = d[i];
            if (!map.containsKey(key)) {
                map.put(key, 1);
            } else {
                int val = map.get(key);
                map.put(key, val + 1);
            }
        }
        // 同じ値の個数nから2つ選ぶパターン数 = nC2
        for (Integer key : map.keySet()) {
            int val = map.get(key);
            ans += (long)val * (val-1) / 2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 53416
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < 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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    REP(i,s.size()){
        if(s[i]==',') cout<<" ";
        else cout<<s[i];
    }
    cout<<endl;
}

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

char s[10001];
int n,count=0,i;

int dfs();
int cmp(const void *p1,const void *p2){
  return *(int*)p1-*(int*)p2;
}

int main(void){
  int a,ans=0;
  scanf("%d",&n);
  scanf("%c",&s[0]);
  for(a=0;a<n;a++){
    i=0;
    count=0;
    while(1){
      scanf("%c",&s[count]);
      if(s[count]=='\n')break;
      count++;
    }
    i=0;
    ans = dfs();
    printf("%d\n",ans);
  }
  return 0;
}

int dfs(){
  int ca=0,j,ans=0;
  int ab[4000];
  i++;
  if(s[i]>='0'&&s[i]<='9'){
    int x=0;
    while(s[i]>='0'&&s[i]<='9'){
      x = x*10+s[i]-'0';
      i++;
    }
    i++;
    return (x/2)+1;
  }

  else  while(s[i]=='['){
      ab[ca]=dfs();
      ca++;
    }
  qsort(ab,ca,sizeof(int),cmp);
  for(j=0;j<(ca/2)+1;j++)ans+=ab[j];
  i++;
  return ans;
}



Measured memory_bytes: 2052
program sample
	character(len=6) :: x
    
    read(*,*) x
    
    if (x(3:3)==x(4:4) .and. x(5:5)==x(6:6)) then
    	write(*,*) 'Yes'
    else
    	write(*,*) 'No'
    end if
    stop
end program sample



Measured memory_bytes: 2856
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize, x: usize,
        l: [usize; n],
    }
    let mut bound = vec![0];
    let mut acc = 0;

    for i in 0..n {
        acc += l[i];
        bound.push(acc);
    }
    let mut ans = bound.iter().filter(|&v| v <= &x).count();

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> input = Arrays.asList(br.readLine().split(" "));

            List<Integer> numbers = new ArrayList<>();
            for (String s : input) {
                numbers.add(Integer.parseInt(s));
            }

            int rating = numbers.get(1);

            if (numbers.get(0) < 10) {
                int internalRationg = (10 - numbers.get(0)) * 100;
                rating += internalRationg;
            }

            System.out.println(rating);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 21204
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    map<int, int> cnt, f;
    vector<int> xs;
    string buf;
    int t = 1;
    while (getline(cin, buf)) {
        if (buf.size() == 0) { t++; continue; }
        int id, _;
        sscanf(buf.c_str(), "%d,%d", &id, &_);
        cnt[id]++;
        f[id] |= t;
        xs.push_back(id);
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    rep (i, xs.size()) if (f[xs[i]] == 3) {
        printf("%d %d\n", xs[i], cnt[xs[i]]);
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(vector<int>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}

//CODE
std::vector<int> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<int> P;
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            if(i%5 == 1)
            P.emplace_back( i );
        }
    }
    return P;
}

void solve(void)
{
  int N;
  cin>>N;
  vector<int> PRIME = Eratosthenes(55555);
  for (int i = 0; i < N; i++)
  {
    if(i != 0) cout<<" ";
    cout<<PRIME[i];
  }
  cout<<endl;
  
  
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
//
//  main.swift
//  TestSpace for AtCoder
//
//  Created by Koichi Okai on 2020/06/25.
//  Copyright © 2020 Koichi Okai. All rights reserved.
//

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let lrd = readInts()
    
    let L = lrd[0]
    let R = lrd[1]
    let d = lrd[2]
    
    let a = (L...R).filter { $0 % d == 0 }.count
    
    print(a)
}

main()


Measured memory_bytes: 8260
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
long long gcd(long long a, long long b) { return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b) { return a/gcd(a,b)*b;}

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

int main() {
  int n;
  cin >> n;
  vector<int> v;
  int tmp;
  rep (i, n) {
    cin >> tmp;
    if (tmp != 0) v.push_back(tmp);
  }
  long sum = 0;
  rep (i, v.size()) {
    for (int j = i + 1; j < v.size(); ++j)
    {
      sum += v[i] * v[j];
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int a,b,c,k; cin >> a >> b >> c >> k;
    int ans = 0;
    if (k==a+b+c) ans = a-c;
    else if (k>a+b && k<a+b+c) {
        ans = a-(k-a-b);
    } else if (k>a && k<=a+b) {
        ans = a;
    } else {
        ans = k;
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    string stone;
    cin >> stone;
    int nr = count(stone.begin(),stone.end(),'R');
    string bubun = stone.substr(0,nr);
    int r = count(bubun.begin(),bubun.end(),'R');
    cout << nr - r << endl;
}


Measured memory_bytes: 3756
using System;

namespace AOJ
{
	class ReverseSequence
	{
		public static void Main(string[] args)
		{
			string input = Console.ReadLine();
			int len = input.Length;
			string output = "";
			for(int i = len - 1; i >= 0; i--){ output += input[i]; }
			Console.WriteLine(output);
		}
	}
}

Measured memory_bytes: 5228
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

vector<vector<int>> G;
vector<ll> sum(202020);

void dfs(int v){
    for(auto nv : G[v]){
        sum[nv] += sum[v];
        dfs(nv);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    G.resize(N);
    REP(i,N-1){
        int a,b;
        cin >> a >> b;
        --a,--b;
        G[a].push_back(b);
    }

    REP(i,Q){
        int p,x;
        cin >> p >> x;
        --p;
        sum[p] += x;
    }
    
    dfs(0);
    REP(i,N) cout << sum[i] << " ";
    cout << endl;
}


Measured memory_bytes: 21120
# 初期入力
from bisect import bisect_left
import sys
#input = sys.stdin.readline  #文字列では使わない
N = int(input())
c =input().strip()
ans =0
w =[i for i, x in enumerate(c) if x == 'W']
r =[i for i, x in enumerate(c) if x == 'R']
w_num =len(w) #全体でWの数
r_num =len(r) #全体でRの数

ans =bisect_left(r,r_num)
print(r_num -ans)

Measured memory_bytes: 17256
from collections import Counter
N=int(input())
D=list(map(int,input().split()))
d=Counter(D)
M=int(input())
T=list(map(int,input().split()))
t=Counter(T)
ans="YES"
for k in list(t.keys()):
  if d[k]<t[k]:
    ans="NO"
    break
print(ans)

Measured memory_bytes: 57056
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)

struct CumulativeSum2D {
  vector<vector<long long>> csum;
  template<typename T>
  CumulativeSum2D(vector<vector<T>> input) : csum(input.size() + 1, vector<long long>(input[0].size() + 1, 0)) {
    for(int i = 0; i < input.size(); i++) for(int j = 0; j < input[i].size(); j++)
      csum[i+1][j+1] += csum[i+1][j] + csum[i][j+1] - csum[i][j] + input[i][j];
  }
  CumulativeSum2D(vector<string> input, char target) : csum(input.size() + 1, vector<long long>(input[0].size() + 1, 0)) {
    for(int i = 0; i < input.size(); i++) for(int j = 0; j < input[i].size(); j++)
      csum[i+1][j+1] += csum[i+1][j] + csum[i][j+1] - csum[i][j] + (input[i][j]==target);
  }
  long long query(int x_left, int y_top, int x_right, int y_bottom) { /* 0-indexed, inclusive */
    return csum[x_right+1][y_bottom+1] - csum[x_right+1][y_top] - csum[x_left][y_bottom+1] + csum[x_left][y_top];
  }
};

signed main() {
  int n,m,Q; cin >> n >> m >> Q;
  vector<vector<int>> grid(n, vector<int>(n, 0));
  rep(i,m) {
    int l,r; cin >> l >> r;
    grid[l-1][r-1]++;
  }
  CumulativeSum2D cs(grid);
  rep(i,Q) {
    int p,q; cin >> p >> q; --p,--q;
    cout << cs.query(p,p, q,q) << endl;
  }
}


Measured memory_bytes: 7196
#include <bits/stdc++.h>    //C++の標準ライブラリのヘッダを全て読み込む
 
int main() {
    using std::cout;
    using std::endl;
    using std::cin;
    using std::string;

    int A, N;
    cin >> N >> A;


    if ((N % 500) <= A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

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

int main () {
    int N, K;
    cin >> N >> K;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        if (x * 2 < (K - x) * 2) {
            sum += x * 2;
        }
        else {
            sum += (K - x) * 2;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main() {
  long long a, b, k;
  cin>>a>>b>>k;
  if(a>=k){
    cout<<a-k<<" "<<b<<endl;
  }
  else if(a<k&a+b>=k){
    cout<<0<<" "<<a+b-k<<endl;
  }
  else{
    cout<<0<<" "<<0<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	ll N, D;
	cin >> N >> D;
	int A[200001];
	ll C[200001];
	C[0] = 1e18;
	ll motomoto = (N - 1) * D;
	rep1(i, N) {
		cin >> A[i];
		motomoto += A[i];
		C[i] = min(C[i - 1], A[i] - i * D);
	}
	ll saishou = 1e18;
	ll setuyaku = 0;
	for (int i = N - 1; i > 1; i--) {
		saishou = min(saishou, A[i + 1] + (i + 1) * D);
		motomoto += A[i];
		ll kari = min(saishou - i * D, C[i - 1] + i * D);
		if (A[i] > kari) setuyaku += A[i] - kari;
	}
	co(motomoto - setuyaku);

	Would you please return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,b,c,i,j,arr[100],sum=0;
    cin>>n;
    for(i=1;i<=n;i++){
            cin >>b;
        arr[i]=b;
    }
    for(j=1;j<=n-1;j++){
        for(i=j+1;i<=n;i++){
            c=arr[j]*arr[i];
            sum+=c;
        }
    }
    cout << sum<<endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
d=a+b+c
m=max(a,b,c)
if d%2==0:
  if m%2==0:
    m=m
  else:
    m=m+1
else:
  if m%2==0:
    m=m+1
  else:
    m=m
s=3*m
ans=s-d
ans//=2
print(ans)

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;


    
int main(){
    string S;
    cin >> S;
    ll blackp = 0;
    ll black = 0;
    ll finish = 0;
    REP(i,S.size()){
        if(S[i]=='B'){
            blackp += i;
            black ++;
        }
    }
    
    finish = black*(2*S.size()-1-black)/2;
    cout << finish - blackp << endl;
}


Measured memory_bytes: 640
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int N=105;
int n,a[N],b[N],c[N],d[N],g[N][N];
int match[N],vis[N];
bool Match(int x){
	for (int i=1;i<=n;i++)
		if (g[x][i]&&!vis[i]){
			vis[i]=1;
			if (!match[i]||Match(match[i])){
				match[i]=x;
				return 1;
			}
		}
	return 0;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d%d",&a[i],&b[i]);
	for (int i=1;i<=n;i++)
		scanf("%d%d",&c[i],&d[i]);
	memset(g,0,sizeof g);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (a[i]<c[j]&&b[i]<d[j])
				g[i][j]=1;
	int ans=0;
	memset(match,0,sizeof match);
	for (int i=1;i<=n;i++){
		memset(vis,0,sizeof vis);
		if (Match(i))
			ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    a=list(map(int,input().split()))
    a.sort(reverse=1)
    dp0=[1]*N
    dp1=[1]*N
    mask=(1<<K)-1
    for i in range(N-1):
        if a[i]<K:
            dp0[i+1]=(dp0[i]|(dp0[i]<<a[i]))&mask
        else:
            dp0[i+1]=dp0[i]
        if a[N-i-1]<K:
            dp1[N-i-2]=(dp1[N-i-1]|(dp1[N-i-1]<<a[N-i-1]))&mask
        else:
            dp1[N-i-2]=dp1[N-i-1]
    ans=0
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(i):
        if a[i]<K:
            mask2=((1<<a[i])-1)<<(K-a[i])
            for j in range(dp0[i].bit_length()):
                if j>mask2.bit_length():
                    return True
                if (dp0[i]>>j)&1:
                    if dp1[i]&(mask2>>j):
                        return True
        else:
            return True
        return False
    
    res=nibutan(-1,N)
    print(N-1-res)
    


if __name__ == '__main__':
    main()


Measured memory_bytes: 47964
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
counter=[0 for i in range(n+1)]
counter[0]=3
ans=1
for i in range(n):
    ans=(ans*(counter[lis[i]]-counter[lis[i]+1]))%mod
    counter[lis[i]+1]+=1
print(ans%mod)





Measured memory_bytes: 83408
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> >v;
void dfs(int i,int vis[])
{
    vis[i]=1;
    for(auto j:v[i])
    {
        if(vis[j]==0)
            dfs(j,vis);
    }
}

int main()
{
    int n,m;
    cin>>n>>m;
    v.resize(n);
    int vis[n]={0};
    int x,y,z;
    for (int i = 0; i <m ; ++i) {
        cin>>x>>y>>z;
        x--;
        y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    int count=0;
    for (int i = 0; i < n; ++i) {
        if(vis[i]==0)
        {
            dfs(i,vis);
            count++;
        }
    }
    cout<<count;
}

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

int main() {
  ll A, B, V, W, T;
  cin >> A >> V >> B >> W >> T;
  if (V <= W) {
    cout << "NO" << endl;
  }
  else {
    ll distance;
    if (A > B) distance = A-B;
    else distance = B-A;
    ll shorten = V-W;
    if (distance > shorten*T) cout << "NO" << endl;
    else cout << "YES" << endl;
  }
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <cmath>

using namespace std;

using ull = unsigned long long;

template <typename T>
T Abs(const T t) {
    return t >= 0 ? t : -t;
}

int main() {
    constexpr int modu = 1000000007;
    
    int n, m;

    cin >> n >> m;

    if(Abs(n - m) > 1) {
        cout << 0 << endl;
    }
    else {
        int min = n < m ? n : m;

        ull ans {1};

        for(ull i = min; i >= 1; --i) {
            ans = (ans * i) % modu;
        }

        if(n != m) {
            ans = (ans * ((ans * (min + 1)) % modu)) % modu;
        }
        else {
            ans = (((ans * ans) % modu) * 2) % modu;
        }

        cout << ans << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
ll const MOD=1000000007;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    vector<ll>AA;
    ll count=0;
    AA.pb(0);
    for(int i=1;i<=2*N;i++){
        if(i%2==1)count+=A[(i-1)%N];
        else{count-=A[(i-1)%N];}
        AA.pb(count);
    }
    for(int i=0;i<N;i++){
        cout<<abs(AA[i+N]-AA[i])<<endl;
    }
}

Measured memory_bytes: 3440
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int dp[105][4][2];

int main () {
  string s;
  cin >> s;
  int n = s.size();
  int K;
  cin >> K;
  dp[0][0][0] = 1;
  rep(i,n)rep(j,4)rep(k,2) {
    int nd = s[i]-'0';
    rep(d,10) {
      int ni = i+1, nj = j, nk = k;
      if (d != 0) nj++;
      if (nj > K) continue;
      if (k == 0) {
        if (d > nd) continue;
        if (d < nd) nk = 1;
      }
      dp[ni][nj][nk] += dp[i][j][k];
    }
  }
  int ans = dp[n][K][0] + dp[n][K][1];
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main()
{
    int N,A,B; cin >>N>>A>>B;
    vector<int> X(N); cin >> X;
    ll ans = 0;
    rep1(i, N) {
        ll walk_cost = (X[i]-X[i-1])*(ll)A;
        if (walk_cost <= (ll)B) {
            ans += walk_cost;
        } else {
            ans += B;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

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


Measured memory_bytes: 256