akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int SIZE = 100 + 10;

ll n[SIZE] = {1};

void init()
{
    for (int i = 1; i < SIZE; i++)
        n[i] = 2 * n[i - 1];
}

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

    init();

    int a, b;
    cin >> a >> b;
    cout << (1900 * b + (a - b) * 100) * n[b] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<30;
const int mod = 1e9+7;
const int MAX_V = 100010;
struct edge { int to, cost; };
vector<edge> tree[MAX_V];
ll depth[MAX_V];

void dfs(int v, int p, ll d) {
  depth[v] = d;
  for(auto &e: tree[v]) {
    if(e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}

int main() {
  int N; cin >> N;
  for(int i = 0; i < N-1; i++) {
    int a, b, c; cin >> a >> b >> c;
    a--, b--;
    tree[a].push_back({b, c});
    tree[b].push_back({a, c});
  }
  int Q, K; cin >> Q >> K; K--;
  dfs(K, -1, 0);

  for(int i = 0; i < Q; i++) {
    int x, y; cin >> x >> y; x--, y--;
    cout << depth[x] + depth[y] << endl;
  }
  return 0;
}


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

using namespace std;


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

  for(int i = 0; i < s.length(); i++){
    int dist_a = ('z' - s[i] + 1) % 26;
    if(i == s.length() - 1){
      s[i] = (s[i] + k - 'a') % 26 + 'a';
      break;
    }
    if(k - dist_a >= 0){
      s[i] = 'a';
      k -= dist_a;
    }else{
      continue;
    }
  }

  cout << s << endl;

  return 0;
}


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

int main(void){
  
  int i;
  int a=-1, b=-1;
  int len;
  char str[100000];
  scanf("%s", str);

  len = strlen(str);
  for(i = 0; i + 1 < len; i++){
    if(str[i] == str[i+1]){
      a = i+1;
      b = i+2;
      break;
    }
    else if(i+2!=len && str[i]==str[i+2]){
      a = i+1;
      b = i+3;
      break;
    }
  }

  printf("%d %d\n", a, b);

  return 0;
}


Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val A = new Array[Int](N+1)
  for (i <- 1 to N) {
    A(i) = in.next().toInt
  }

  val iA = new Array[Int](N+1)
  val jA = new Array[Int](N+1)
  for (i <- 1 to N) {
    iA(i) = i + A(i)
    jA(i) = i - A(i)
  }

  val hash = Map[Int, Int]()
  for (i <- 1 to N) {
    val now = jA(i)
    if (hash.contains(now))
      hash(now) += 1
    else
      hash += (now->1)
  }


  var ans = 0L
  for (i <- 1 to N) {
    val now = iA(i)
    hash(jA(i)) -= 1

    if (hash.contains(now))
      ans += hash(now)
  }

  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 75984
#include<algorithm>
#include<cstdio>
#include<functional>
#include<iostream>
#include<cfloat>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<time.h>
#include<vector>
using namespace std;
int main(){
 	vector<int> a(3);
 	for (int i = 0; i < 3; ++i) {
     	scanf("%d", &a[i]);
 	}
 	int k;
 	scanf("%d", &k);
  	sort(a.begin(), a.end());
  	int ret = a[0] + a[1] + (a[2] << k);
  	printf("%d\n", ret);
  	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long long A[100][100] = {0};
long long B[100][100] = {0};
long long C[100][100] = {0};

int main(void) {
	int n, m, l;
	int i, j, k;
	scanf(" %d %d %d", &n, &m, &l);

	for (i = 0; i < n; ++i) {
		for (j = 0; j < m; ++j) {
			scanf(" %lld", &A[i][j]);
		}
	}

	for (i = 0; i < m; ++i) {
		for (j = 0; j < l; ++j) {
			scanf(" %lld", &B[i][j]);
		}
	}

	for (i = 0; i < n; ++i) {
		for (j = 0; j < m; ++j) {
			for (k = 0; k < l; ++k) {
				C[i][k] += A[i][j] * B[j][k];
			}
		}
	}

	for (i = 0; i < n; ++i) {
		for (j = 0; j < l; ++j) {
			printf("%lld%c", C[i][j], (j == l - 1)?'\n':' ');
		}
	}
	
	return 0;
}

Measured memory_bytes: 832
#include<iostream>
	using namespace std;
int main(){
	int a[100];
	int N;
	cin>>N;
	int k;//kはソート済みの添え字
	for(int i=0;i<N;i++)cin>>a[i];
	
	k=0;
	
	for(int i=0;i<N;i++){
		int v=a[i];
		int j=i-1;
			while(v<a[j]&&j>=0){
				a[j+1]=a[j];
				
				/*for(int k=0;k<N-1;k++)cout<<a[k]<<"  ";
			cout<<a[N-1]<<endl<<endl;*/
				
				j--;
		}
		a[j+1]=v;
			for(int k=0;k<N-1;k++)cout<<a[k]<<" ";
			cout<<a[N-1]<<endl;
	}

	return 0;
}

Measured memory_bytes: 1164
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;
  v(vi) as(H, vi(W));
  F0R(r, H) {
    F0R(c, W) {
      cin >> as[r][c];
    }
  }

  vector<tuple<int, int, int, int>> rs;

  F0R(r, H) {
    if (r & 1) {
      RF0(c, W) {
        if (as[r][c] & 1) {
          int nr, nc;
          if (c > 0) { nr = r; nc = c - 1; }
          else {
            if (r < H - 1) {
              nr = r + 1;
              nc = c;
            }
            else break;
          }
          as[r][c]--;
          as[nr][nc]++;
          rs.emplace_back(r, c, nr, nc);
        }
      }
    }
    else {
      F0R(c, W) {
        if (as[r][c] & 1) {
          int nr, nc;
          if (c < W - 1) { nr = r; nc = c + 1; }
          else {
            if (r < H - 1) {
              nr = r + 1;
              nc = c;
            }
            else break;
          }
          as[r][c]--;
          as[nr][nc]++;
          rs.emplace_back(r, c, nr, nc);
        }
      }
    }
  }
  cout << rs.size() << newl;
  F0R(i, sz(rs)) {
    cout << (get<0>(rs[i])+1) << ' ' << (get<1>(rs[i])+1) << ' '
      << (get<2>(rs[i])+1) << ' ' << (get<3>(rs[i])+1) << newl;
  }
}
#endif


Measured memory_bytes: 6324
Sp = input()
T = input()
n = len(Sp)+1-len(T)
flag = 1
suc = 0
S = ['']*len(Sp)

for i in range(n):
    flag = 1
    for j in range(len(T)):
        if T[j] != Sp[i+j] and Sp[i+j] != '?':
            flag = 0
    
    if flag == 1:
        for l in range(len(Sp)):
            S[l] = Sp[l]
        for k in range(len(T)):
            S[i+k] = T[k]
        for l in range(len(Sp)):
            if S[l] == '?':
                S[l] = 'a'
        suc = 1

if suc == 1:
    print("".join(S))
else:
    print("UNRESTORABLE")

Measured memory_bytes: 38640
//BISMILLAH
#include<bits/stdc++.h>
using namespace std;
#define ll long long
pair<long long,long long>p;

int main()
{
    int n;
    long long d;
    //d=d*d;
    //int countt=0;
    scanf("%d %lld",&n,&d);
    d=d*d;
    int countt=0;

    while(n--)
    {
        scanf("%lld %lld",&p.first,&p.second);
        if(p.first*p.first+p.second*p.second<=d) countt++;
    }
    printf("%d\n",countt);

    return 0;
 }

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
int main() {
     int n;
     cin >> n;
     int ans = 0;
     for(int i = 1; i < n + 1; i++){
          int count =0;
          for(int j = 1; j < i + 1; j++){
               if(i % 2 != 0 && i % j == 0) count++;
          }
          if(count == 8) ans++;
     }
     cout << ans << endl;
}

Measured memory_bytes: 384
let () =
  let n = Scanf.scanf "%d\n" (fun x -> x) in
  let s = Array.make 13 false in
  let h = Array.make 13 false in
  let c = Array.make 13 false in
  let d = Array.make 13 false in

  for i = 1 to n do
    let a, b = Scanf.scanf "%c %d\n" (fun x y -> x, y) in
    match a with
      | 'S' -> s.(b-1) <- true
      | 'H' -> h.(b-1) <- true
      | 'C' -> c.(b-1) <- true
      | 'D' -> d.(b-1) <- true
      | _   -> ()
  done;

  Array.iteri (fun i x -> if not x then Printf.printf "S %d\n" (i+1) else ()) s;
  Array.iteri (fun i x -> if not x then Printf.printf "H %d\n" (i+1) else ()) h;
  Array.iteri (fun i x -> if not x then Printf.printf "C %d\n" (i+1) else ()) c;
  Array.iteri (fun i x -> if not x then Printf.printf "D %d\n" (i+1) else ()) d;

Measured memory_bytes: 2380
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
struct node{
    int index;
    char c[100];
    int val;
}a[Max];
bool cmp(node a,node b){
    if(strcmp(a.c,b.c)==0){
        return a.val>b.val;
    }
    return strcmp(a.c,b.c)<0;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s%d",a[i].c,&a[i].val);
        a[i].index=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
       // printf("%s\n",a[i].c);
        printf("%d\n",a[i].index);
    }

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

# Sの数が初期のcの必要数より少ない場合はcの数で総数が決まる
if m - (n*2) < 0:
    ans = m // 2
else:
    # 初期段階で作れるSccの数
    tmp_Scc = n

    # 初期のSのみでSccを作ったときのcのあまり
    tmp_amari = m - (n*2)

    # 余りを用いるとc 4つでSccが一つ作れる
    tmp_Scc_2 = tmp_amari // 4

    ans = tmp_Scc + tmp_Scc_2

print(ans)
    
    



Measured memory_bytes: 2940
//   /$$$$           /$$                 /$$$$  /$$$$$$            /$$
//  | $$_/          | $$                |_  $$ /$$__  $$          | $$
//  | $$    /$$$$$$$| $$$$$$$   /$$$$$$   | $$|__/  \ $$ /$$$$$$$ | $$   /$$
//  | $$   /$$_____/| $$__  $$ |____  $$  | $$  /$$$$$$/| $$__  $$| $$  /$$/
//  | $$  |  $$$$$$ | $$  \ $$  /$$$$$$$  | $$ /$$____/ | $$  \ $$| $$$$$$/
//  | $$   \____  $$| $$  | $$ /$$__  $$  | $$| $$      | $$  | $$| $$_  $$
//  | $$$$ /$$$$$$$/| $$  | $$|  $$$$$$$ /$$$$| $$$$$$$$| $$  | $$| $$ \  $$
//  |____/|_______/ |__/  |__/ \_______/|____/|________/|__/  |__/|__/  \__/
//
//
//






#include <bits/stdc++.h>
using namespace std;


#define ll long long int
#define ull unsigned long long int
#define po2(z) 1<<(ll)z
#define fr(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define rf(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define modinv(x) powah(x,mod-2)
#define ncr(n,r) (((fact[n]*modinv(fact[n-r]))%mod*modinv(fact[r]))%mod)
#define factorial fact.pb(1);sidha(i,1,MAX)fact.pb((fact[i-1]*i)%mod)
#define tej ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod (ll)1000000007
#define MAX 100005
#define Vii  vector<ll>
#define pb  push_back
#define pii pair<ll,ll>
#define ff  first
#define ss second
#define vpii vector<pii >
#define endl '\n'


//--------------------------------------------------//
void solve(){
	ll  n,k;
	cin>>n>>k;
	vector<ll>h(n);

for(ll i=0;i<n;i++){
	cin>>h[i];
}
ll dp[n];

for(ll i=0;i<n;i++) dp[i]=1e10;

dp[0]=0;

for(ll i=0;i<n;i++){
	for(ll j=1;j<=k;j++){
		if(i+j<n){	
		dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
		}
	}
}
cout<<dp[n-1];
}

//--------------------------------------------------//


int main(){
  ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
    int tc=1;
//	cin >> tc;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }


}


Measured memory_bytes: 4784
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	

	int a, b, c;
	cin >> a >> b >> c;
	if (a == c && b == a &&  c == b) {

		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;


	return 0;
}



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

int main() {
  string s;
  cin >> s;
  string S = "";

  for (int i = 0; i < s.size(); i++) {
    if (i == 0) {
      S += s[i];
    } else {
      if (s[i - 1] != s[i]) { S += s[i]; }
    }
  }
  cout << S.size() - 1 << endl;
}

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

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

ll power(ll x, ll y)
{
    ll res = 1;

    while (y > 0) {

        if (y & 1)
            res = res * x;


        y = y >> 1;
        x = x * x;
    }
    return res;
}

int main()
{
    int n;
    cin>>n;
    //vector<int> a;
    double d  = 0;
    for(int i=0;i<n;i++){
        int val;
        cin>>val;
        //a.push_back(val);
        d += (1.0/val);
    }
    d = 1/d;
    cout<<d<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define mm memset
#define PI 3.14159265358979323846264338327950288419716939937510
#define MAXI (ll)2e5+3
#define M 998244353 
void solve(){
  ll n;
  cin>>n;
  cout<<(n+n*n+n*n*n)<<endl;
}
int main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t=1;
  //cin>>t;
  for(ll i=0;i<t;i++){
    solve();
  }
  return 0;
} 

Measured memory_bytes: 3600
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const int N=200005;

int n,cnt;
char str[N];

int main()
{
    scanf("%d\n%s",&n,str);
    int i=-1,j=n;
    while(i<j)
    {
        while(++i<n&&str[i]=='R');
        while(--j&&str[j]=='W');
        if(i<j)cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 3952
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
inline int read(int x){
	int f=1,n=0;char c=getchar();
	while(!isdigit(c)){if(c=='-') f=0;c=getchar();}
	while(isdigit(c)){n=n*10+int(c-'0');c=getchar();}
	return f*n;
}
signed main(void){
	int n,ans=0;
	n=read(n);
	for(int i=1;i<n;++i){
		int ab=n-i;
		for(int j=1;j<=int(sqrt(ab));++j){
			if(ab%j==0){
				if(j==sqrt(ab)) ++ans;
				else ans+=2;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3676
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;

int main() {
    int a,b,c;cin>>a>>b>>c;
    if (a<b && b<c) {
        ct("Yes");
        return 0;
    }
    ct("No");
}



Measured memory_bytes: 3096
def main():
    n, m = map(int, input().split())
    a = set([int(input()) for _ in range(m)])

    ansls = [0]*(n+1)
    big = 10**9 + 7

    if 0 not in a:
        ansls[0] = 1
    if 1 not in a:
        ansls[1] = 1

    for i in range(2, n+1):
        if i not in a:
            ansls[i] = (ansls[i-2] + ansls[i-1])%(10**9 + 7)
    
    print(ansls[-1])
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 56664
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(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;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  int n;
    scanf("%d%",&n);
  int Sum=0;
  int Min=1000000;
  for(int i=0;i<n;++i){
    int a;
      scanf("%d",&a);
    if(a%10!=0){
      chmin(Min,a);
    }
      Sum+=a;
  }

  if(Sum%10==0){
    Sum-=Min;
  }
  int ans=max(0,Sum);
  printf("%d\n",ans);
}

Measured memory_bytes: 256
n,k,q=gets.chomp.split(" ").map(&:to_i)
score=Array.new(n){k}
q.times do|i|
  score[gets.to_i-1]+=1
end
max=score.max
n.times do|i|
  if(score[i]-q >0)
    puts "Yes"
  else
    puts "No"
  end
end

Measured memory_bytes: 3196
import java.util.*;
class Main{
    Main(){
	Scanner sc =new Scanner(System.in);
	int a,b,c,d;
	String x="YES";
	a=sc.nextInt();

	while(a>0){
	    a--;
	    c=0;d=0;
	    for(int i=0;i<10;i++){
		b=sc.nextInt();
		if(c<b)c=b;
		else if(d<b)d=b;
		else x="NO";
	    }
	    System.out.println(x);
	}
    }
    public static void main (String[]arg){
	new Main();
    }
}

Measured memory_bytes: 18156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;


ll i;


int main(){
    ll N,M;
    cin>>N>>M;
    priority_queue<ll> A;
    V c(N);
    rep(i,N)cin>>c.at(i);
    rep(i,N)A.push(c.at(i));
    rep(i,M){
        ll f=A.top();
        A.pop();
        A.push(f/2);
    }
    ll ans=0;
    rep(i,N){
        ll f=A.top();
        ans+=f;
        A.pop();
    }

    cout<<ans<<endl;
    

    
    
}


Measured memory_bytes: 2168
#include<stdio.h>

int main(void)
{
	char str;
	
	while(1){
		scanf("%c", &str);
		if(str == '\n'){
			break;
		}
		else if(str >= 'a' && str <= 'z'){
			str -= 0x20;
		}
		else if(str >= 'A' && str <= 'Z'){
			str += 0x20;
		}
		printf("%c", str);
	}
	printf("\n");
	
	return (0);
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n+1];
    int dp[n+1];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    memset(dp,0,sizeof dp);
    dp[0]=0;
        for(int i=1;i<n;i++){
        if(i>=2)dp[i]=min(abs(arr[i-1]-arr[i])+dp[i-1],abs(arr[i-2]-arr[i])+dp[i-2]);
        else dp[i]=abs(arr[i-1]-arr[i]);
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = [int(i) for i in input().split()]
a.insert(0, 0)
a.append(0)
t = 0
for i in range(n + 1):
    t += abs(a[i] - a[i + 1])
for i in range(1, n + 1):
    print(t - abs(a[i + 1] - a[i]) - abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i - 1]))


Measured memory_bytes: 13792
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
inline int read()
{
	int res=0,f=0;
	char c;c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){res=res*10+c-48;c=gc();}
	if(f)return -res;
	return res;
}
int main()
{
	int n=read(),m=read();
	if(n<6){puts("0");return 0;}
	if(n<=12)cout<<m/2;
	else cout<<m;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <iostream>
//#include <iomanip>
//#include <vector>
//#include <cmath>
//#include <algorithm>
using namespace std;


#define F first
#define PB push_back
#define MP make_pair

typedef long long ll;

ll p = pow(10, 9) + 7;




int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    cout << (n * (n + 1)) / 2 <<endl;
    


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  vector<pair<int, int>> A;
  int i = 0;
  while (i < N) {
    int j = i;
    while (i < N && S[i] == S[j]) i++;
    A.push_back({S[j] - '0', i - j});
  }
  vector<int> T(A.size() + 1);
  REP(i, A.size()) T[i + 1] = T[i] + A[i].second;
  int ans = 0;
  REP(i, A.size()) {
    if (A[i].first == 0) {
      int j = min<int>(A.size(), i + 2*K);
      ans = max(ans, T[j] - T[i]);
    } else {
      int j = min<int>(A.size(), i + 2*K+1);
      ans = max(ans, T[j] - T[i]);
    }
  }
  cout << ans << '\n';
}



Measured memory_bytes: 1652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <functional>
using namespace std;
#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++)
using ll = unsigned long long;
const ll mod = 1000000007;
string al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//bool less_sec(const pair<int, int>&a, const pair<int, int>&b) {
//	return a.second > b.second;
//}
int a, b, c, k;
vector<string> field;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> a >> b >> c >> k;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(), v.end());
    for(int i=1; i<=k; ++i){
        v[2]*=2;
    }
    cout << v[0]+v[1]+v[2] << endl;
    return 0;
}

Measured memory_bytes: 256
program One_Card_Poker;

uses crt;

var
A,B:integer;

begin
clrscr;
read(A);
readln(B);
if (A>=0) and (A<=13) and (B>=0) and (B<=13) then
  if (A=13) and (B=1) then
    writeln('Bob')
  else if (A=1) and (B=13) then
    writeln('Alice')
  else if (A>B) then
    writeln('Alice')
  else if (A<B) then
    writeln('Bob')
  else if (A=B) then
    writeln('Draw')   
end.

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N;
    cin >> N;

    vector<vector<int>> tree(N);
    vector<int> a(N-1),b(N-1);
    rep(i,0,N-1){
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
        tree[a[i]].push_back(b[i]);
        tree[b[i]].push_back(a[i]);
    }

    static i64 height[128][128];
    static i64 depth[100][100][101];
    fill_n((i64*)height,128*128,-1);
    fill_n((i64*)depth,100*100*101,0);

    function<i64(int,int)> calc_height=[&](int u,int p){
        i64& res=height[u][p];
        if(res!=-1) return res;
        res=1;
        rep(i,0,tree[u].size()){
            if(tree[u][i]==p) continue;
            res=max(res,calc_height(tree[u][i],u)+1);
        }
        return res;
    };

    function<void(int,int)> calc_depth=[&](int u,int p){
        if(depth[u][p][0]!=0) return;
        depth[u][p][0]=tree[u].size()-1;
        for(int v:tree[u]){
            if(v==p) continue;
            calc_depth(v,u);
            rep(i,0,101){
                if(depth[v][u][i]==0) break;
                depth[u][p][i+1]=max(depth[u][p][i+1],depth[v][u][i]);
            }
        }
    };

    pair<i64,i64> ans(inf64,inf64);
    rep(i,0,N-1){
        int x=a[i],y=b[i];
        i64 max_height=max(calc_height(x,y),calc_height(y,x));
        calc_depth(x,y);
        calc_depth(y,x);

        i64 r=1;
        rep(j,0,101){
            if(depth[x][y][j]==0 and depth[y][x][j]==0) break;
            r*=max(depth[x][y][j],depth[y][x][j]);
        }
        pair<i64,i64> tmp(max_height,r*2);
        ans=min(ans,tmp);
    }

    rep(x,0,N){
        i64 max_height=0;
        vector<i64> depthx(101);
        rep(j,0,tree[x].size()){
            max_height=max(max_height,calc_height(tree[x][j],x)+1);
            calc_depth(tree[x][j],x);
            rep(k,0,100) depthx[k+1]=max(depthx[k+1],depth[tree[x][j]][x][k]);
        }
        i64 r=1;
        rep(k,0,101){
            if(depthx[k]==0) continue;
            r*=depthx[k];
        }
        pair<i64,i64> tmp(max_height,r*tree[x].size());
        ans=min(ans,tmp);
    }

    cout << ans.first << " " << ans.second << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 8320
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,t,c;
    int i=0,j=0,m=0x3f3f3f3f;
    scanf(" %d %d",&n,&t);
    int ar1[n],ar2[n];
    c=n;
    while(n--)
    {
      scanf(" %d %d",&ar1[i],&ar2[i]);
      if(ar2[i]>t)
        ar1[i]=0x3f3f3f3f;
      i++;
    }
        for (i=0; i<c; i++)
    {
        if(m>ar1[i])
            m=ar1[i];
    }

    if(m==0x3f3f3f3f)
        printf("TLE");
    else
        printf("%d",m);
    return 0;
}


Measured memory_bytes: 128
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文

/*各位の和　
int sum = 0;
for(int i = 0; i <= 5; i++){
   sum += n%10;
   n /= 10;  
}
*/

//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  ll n;
  cin>>n;
  vs w(n);
  rep(i,n)
  {
  cin>>w[i];
  if(i!=0){
    if(w[i][0]!=w[i-1][w[i-1].size()-1])
    p=1;
  }
  }
  rep(i,n-1){for(int j=i+1;j<n;j++){if(w[i]==w[j])p=1;}}
  if(p==0)print("Yes")else print("No")
}


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

int main()
{
	int ans, n;
	int cnt[2];
	string a;
	cnt[0] = 0;
	cnt[1] = 0;
	getline(cin,a);
	n = a.length();
	for (int i = 0; i < n; i++) {
		if (a[i] == '0') cnt[i%2]++;
		else cnt[(i + 1 )% 2]++;
	}
	if (cnt[0] < cnt[1]) ans = cnt[0];
	else ans = cnt[1];
	cout << ans;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

func snack(a, b int) int {
	return (a * b) / gcd(a, b)
}

func gcd(a, b int) int {
	var tmp int
	for a%b != 0 {
		tmp = b
		b = a % b
		a = tmp
	}
	return b

}

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	fmt.Println(snack(a, b))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> m(N);
	for (ll i = 0; i < N; ++i)
	{
		cin >> m[i], --m[i];
	}

	ll res{0};
	for (ll i = 0; i < N-1; ++i)
	{
		if (i == m[i])
		{
			swap(m[i], m[i+1]);
			++res;
		}
	}

	if (N-1 == m[N-1]) ++res;

	std::cout << res << std::endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,m;
ll a[200010];
int main(){
	scanf("%lld",&n);
	ll s=0;
	rep(i,0,n){
		scanf("%lld",a+i);
		s+=a[i];
	}
	ll ans=INF;
	ll t=0;
	rep(i,0,n){
		ans=min(ans,llabs(s-t-t));
		t+=a[i];
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1664
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
res = 1
for i in range(n):
    if i == 0:
        res *= k
    else:
        res *= k-1
print(res)


Measured memory_bytes: 38636
N = int(input())
S = [x == '1' for x in input()]
S.append(0)
ans = 0
now = 0

def dp(arr):
    L = len(arr)
    if L == 1:
        return 0
    dp = [[0] * 4 for _ in range(L)]
    dp[0] = [-1, arr[0], -1, 0]
    ret = max(dp[0])
    for i in range(L - 1):
        dp[i + 1][0] = dp[i][3] + arr[i + 1]
        if dp[i][0] != -1 and arr[i] > 1:
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + arr[i + 1] - 1)
        if dp[i][2] != -1 and arr[i] > 1:
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][2] + arr[i + 1])
        dp[i + 1][1] = dp[i][3] + arr[i + 1]
        if dp[i][0] != -1 and i != L - 2:
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + arr[i + 1])
        if dp[i][1] != -1 and arr[i + 1] > 1 and i != L - 2:
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + arr[i + 1] - 1)
        if dp[i][2] != -1 and i != L - 2:
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][2] + arr[i + 1])
        dp[i + 1][2] = dp[i][1]
        dp[i + 1][3] = max([dp[i][0], dp[i][3], dp[i][2]])
        ret = max(ret, max(dp[i + 1]))
    #print(*dp, sep='\n')
    return ret


while now < N:
    if S[now] == 1:
        left = now
        cnt_1 = 1
        prev = 1
        now += 1
        arr = []
        while now < N and (prev != 0 or S[now] != 0):
            if S[now] == 0:
                arr.append(cnt_1)
                cnt_1 = 0
            else:
                cnt_1 += 1
            prev = S[now]
            now += 1
        if cnt_1:
            arr.append(cnt_1)
        if now == N:
            if prev == 0:
                right = N - 2
            else:
                right = N - 1
        else:
            right = now - 2
        #print('#', arr)
        ans += dp(arr)
        while now < N and S[now] == 0:
            now += 1
    else:
        now += 1
print(ans)


Measured memory_bytes: 8468
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

int main() {
    
    #define N 50
    
    long long A[N];
    long long K;
    cin >> K;
    
    for ( int i = 0; i < N; i++ ) {
        A[i] = i;
    }
    
    for ( int i = 0; i < N; i++ ) {
        A[i] += K / N;
    }
    
    for ( int i = 0; i < (K%N); i++ ) {
        for ( int j = 0; j < N; j++ ) {
            A[j]--;
        }
        A[i] += N+1;
    }
    
    cout << N << endl;
    for ( int i = 0; i < N-1; i++ ) {
        cout << A[i] << " ";
    }
    cout << A[N-1] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int i, l;
    cin>>s;
    for(i=1; i<s.size(); i++)
        if(s[i]==s[i-1])
        {
            cout<<"Bad"<<endl;
            return 0;
        }
    cout<<"Good"<<endl;
    return 0;
}


Measured memory_bytes: 256
n, q = gets.chomp.split(' ').map(&:to_i)
ab = (1..(n - 1)).map { gets.chomp.split(' ').map(&:to_i) }
px = (1..q).map { gets.chomp.split(' ').map(&:to_i) }

@tree = Array.new(n) { [] }
@answer = Array.new(n, 0)
@is_added = Array.new(n, false)

ab.each do |a, b|
  @tree[a - 1] << b - 1
  @tree[b - 1] << a - 1
end
px.each { |p, x| @answer[p - 1] += x }

queue = [0]

until queue.empty?
  p = queue.shift
  @is_added[p] = true
  @tree[p].each do |i|
    next if @is_added[i]
    @answer[i] += @answer[p]
    @is_added[i] = true
    queue << i
  end
end

puts @answer.join(' ')


Measured memory_bytes: 50616
N = int(input())
A = list(map(int, input().split()))
D = {}

ans = 0
for i in range(N):
    s = i-A[i]
    if s in D: ans+=D[s]

    t = i+A[i]
    if t not in D: D[t]=0
    D[t]+=1

print(ans)

Measured memory_bytes: 40352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  ll d[N];
  ll ans=-1;
  d[0]=7%N;
  rep(i,N){
    if(N%2==0) break;
    if(d[i]==0){
      ans=i+1;
      break;
    }
    else{
      d[i+1]=(d[i]*10+7)%N;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 11384
N, Y = [int(_) for _ in input().split()]

for x in range(0, Y//10000 + 1, 1):
    for y in range(0, Y//5000 + 1, 1):
        
        z = N - x - y
        
        if z < 0:
            continue
        
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()
    
print("-1 -1 -1")

Measured memory_bytes: 67092
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9+7;
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<bool> vb;
long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
long long int min(long long int a,long long int b){
  if(a<b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
    }
  return res;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}

lli mul(lli a,lli b){
  return (a%mod * b%mod)%mod;
}

lli add(lli a,lli b){
  return (a%mod + b%mod)%mod;
}

lli sub(lli a,lli b){
  return (a%mod-b%mod+mod)%mod;
}
 
//############################ENDOFTEMPLATE############################



void solve(){
  int n;
  cin>>n;

  vi a(n+1);

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

  vector<vi> dp(n+1,vi(3));
  int ans = 1;

  for(int i = 1;i<=n;i++){
    int t = 0;
    for(int j = 0;j<3;j++){
      if(dp[i-1][j]==a[i])
        t++;

      dp[i][j] = dp[i-1][j];
      
    }
    for(int j = 0;j<3;j++){
      if(dp[i][j]==a[i]){
        dp[i][j]+=1;
        break;
      }
    }

    ans = (ans%mod*t%mod)%mod;
  }


  cout<<ans;




}

 
 
 
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 9000
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int N, R, I;

int divisible(int v, int n){
	if(v % 2 == 0) return divisible(v / 2, n + 1);
	else return n + 1;
}

int main(void){
	//IO("test.in", "test.out");
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		int d = divisible(i, 0);
		if(d > R) R = d, I = i;
	}
	printf("%d\n", I);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    boolean check = true;
    boolean check2 = true;
    for (int i = 0; i < s.length(); i+=2) {
      if (!"RUD".contains(s.substring(i, i+1))) {
        check = false;
        break;
      }
    }
    for (int i = 1; i < s.length(); i+=2) {
      if (!"LUD".contains(s.substring(i, i+1))) {
        check2 = false;
        break;
      }
    }
    if (check && check2) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 27008
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

long long N;

int main()
{
	scanf("%lld", &N);
	
	if (N % 2 == 1) {
		printf("0\n");
		return 0;
	}
	
	//偶数，只需要计算10的倍数即可
	long long count = 0;
	long long tempN = N;
	long long base = 10;
	while (tempN >= base)  {
		long long section = tempN / base;
		count = count + section;
		base = base * 5;
	}
	long long count5 = count;
	
	count = 0;
	tempN = N;
	base = 2;
	while (tempN >= base)  {
		long long section = tempN / base;
		count = count + section;
		base = base * 2;
	}
	long long count2 = count;
	
	if (count5 > count2)
		printf("%lld\n", count2);
	else
		printf("%lld\n", count5);

	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#include <functional>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const ll mod = 1000000000 + 7; //10^9


int main() {
    int N, L;
    cin >> N >> L;
    vector<int> abs_taste(N);
    int eat = 300;
    int c;
    for (int i = 0; i < N; i++)
    {
        abs_taste[i] = abs(L + i);
        if(abs_taste[i] < eat){
            eat = abs_taste[i];
            c = i;
        }
    }
    int sum = N * (L - 1) + (1 + N) * N / 2;
    int ans = sum - (L + c );
    cout << ans << endl;
    
}

Measured memory_bytes: 3628
void main()
{
    long n = readln.chomp.to!long;

    long[] a = new long[n], b = new long[n];
    foreach (i; 0 .. n)
    {
        long[] tmp = readln.split.to!(long[]);
        a[i] = tmp[0], b[i] = tmp[1];
    }

    long buttons;
    foreach_reverse (i; 0 .. n)
    {
        long r = (a[i] + buttons) % b[i];
        if (r)
        {
            buttons += b[i] - r;
        }
    }

    buttons.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4860
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt(), A = cin.getIntArray(N);
    A.sort((a, b) => b - a);
    A.push(0);
    let a = A[0], h = Math.floor(a / 2);
    let max = 0, b1 = 0, b2 = 0;
    for (let n = 1; n < N; n++) {
        if (h <= A[n]) {
            b1 = A[n];
            b2 = A[n+1];
        }
    }
    console.log(`${a} ${(Math.abs(h - b1) <= Math.abs(h - b2)) ? b1 : b2}`);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 31536
#include <iostream>
using namespace std;
typedef long long ll;
ll h, w, a, b, s, ans, M=1e9+7, fac[200005]={1}, inv[200005];
ll pow(ll p, ll q) {
	ll ret = 1;
	for(; q>>=1; p = p*p%M) if(q&1) ret = ret*p%M;
	return ret;
}

int main() {
	ll i, j, x, y;
	cin>>h>>w>>a>>b;
	for(i=1; i<=h+w; i++) fac[i] = i * fac[i-1] % M;
	inv[h+w] = pow(fac[h+w], M-2);
	for(i=h+w-1; i>=0; i--) inv[i] = (i+1) * inv[i+1] % M;
	i = h-a-1; x = a-1;
	for(j=b; j<w; j++) {
		s = fac[i+j] * inv[i]%M * inv[j]%M;
		y = w-1-j;
		s *= fac[x+y] * inv[x]%M * inv[y]%M;
		ans = (ans+s) % M;
	}
	cout<<ans;
	return 0;
}

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

int main(){
	long long N,x,ans=999999999999999999;
	cin >> N >> x;
	vector<long long> a(N);
	for(auto &i:a)cin >> i;
	
	long long m[N][N];
	for(int i=0;i<N;i++)m[i][0]=a[i];
	for(int k=1;k<N;k++){
		for(int i=0;i<N;i++){
			m[i][k]=min(m[i][k-1],a[(i+N-k)%N]);
		}
	}
	
	for(int k=0;k<N;k++){
		long long tmp=x*k;
		for(int i=0;i<N;i++)tmp+=m[i][k];
		ans=min(ans,tmp);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 31488
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

void Main(){
  int N, L;
  cin >> N >> L;
  vector<string> vec(N);
  for(auto& v : vec){
    cin >> v;
  }
  sort(vec.begin(), vec.end());

  string ans;
  for(auto& v : vec){
    ans += v;
  }
  cout << ans << endl;
}

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
	int m=0;
	char a[4];
	scanf("%s",a);
	for(int i=0;i<3;i++)
	{
		if(a[i]==a[i+1])
		{
			m++;
			break;
		}
	}
	if(m==0)
		printf("Good\n");
	else
		printf("Bad\n");
	return 0;

	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--) 
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    ll N,sum=0;
    cin >> N;
    vector<int> A(N),B(N,0);
    rep(i,0,N){
        cin >> A[i];
    }
    sum= accumulate(A.begin(),A.end(),0);
    sum/=2;

    for(ll j=0;j<N;j+=2){
        if(j>=N){
            continue;
        }
        B[0]+=A[j];
    }
    for(ll j=0-1;j>=0;j-=2){
        if(j<0){
            continue;
        }
        B[0]+=A[j];
    }
    B[0]=2*(B[0]-sum);

    rep(i,0,N-2){
        B[i+1]=(2*A[i]-B[i]);
    }
    B[N-1]=(2*A[N-2]-B[N-2]);

    rep(i,0,N){
        cout << B[i] << ' ';
    }
    cout << ' ' << endl;


    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 300 + 10;

int n, m, ans;
int a[MAXN][MAXN];
bool exist[MAXN];
int num[MAXN];

void calc()
{
	for(int i = 1; i <= m; i++)
		num[i] = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			if(exist[a[i][j]])
			{
				num[a[i][j]]++;
				break;
			}
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	ans = n;
	memset(exist, true, sizeof(exist));
	for(int i = 1; i <= m; i++)
	{
		calc();
		int p = -1;
		for(int j = 1; j <= m; j++)
			if(exist[j] && (p == -1 || num[p] < num[j]))
				p = j;
		ans = min(ans, num[p]);
		exist[p] = false;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
/*
AizuOnline A0086
Title Patrol
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
#define NO_OF_CROSS 100
int hist[NO_OF_CROSS];
//
main()
{
  int c1,c2,i,ans;

  memset(hist,0,sizeof(hist));
  while(1)
    {
      if(EOF==scanf("%d %d ",&c1,&c2))
	break;
#ifdef DEBUG
      printf("%d %d\n",c1,c2);
#endif
      if(c1 || c2)
	{
	  hist[c1]++;
	  hist[c2]++;
	}
      else
	{
	  ans=0;
	  if((hist[1] & 1)==0)
	    ans=1;
	  else if((hist[2] & 1)==0)
	    ans=1;
	  else
	    for(i=3;i<NO_OF_CROSS;i++)
	      if(hist[i] & 1)
		ans=1;
#ifdef DEBUG
	  printf("h1234:%d %d %d %d\n",hist[1],hist[2],hist[3],hist[4]);
#endif
	  printf("%s\n",ans?"NG":"OK");
	  memset(hist,0,sizeof(hist));
	}
    }
  return(0);
}

Measured memory_bytes: 588
#include <stdio.h>

int main(void)
{
    int a,b;

    scanf("%d%d",&a,&b);

    if(a<b){
     printf("a < b\n");

    }else if(a>b){
     printf("a > b\n");

    }else{
     printf("a == b\n");
    }

    return 0;
}


Measured memory_bytes: 2052