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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  cout << "Christmas";
  rep(i, 25 - n) {
    cout << " Eve";
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
   char str1[50] , str2[50] ,str3[50] ;
   scanf("%s%s%s",str1,str2,str3);
   int count1=0 , count2  = 0  , i;

   char a = str1[0] - 32 ;
   char b = str2[0] -32 ;
   char c = str3[0] - 32 ;

   //char *sd[] =  strcat(a,b,c);

    printf("%c%c%c",a,b,c);
}


Measured memory_bytes: 128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=II()
  a=b=0

  for i in range(n):
    _a,_b=LI()
    if _a>a:
      a=_a
      b=_b

  return a+b

print(main())


Measured memory_bytes: 6296
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
 
int main()
{
    int N,M,X; cin >> N >> M >> X;
    int c1,c2; c1 = c2 = 0;
    for (int i = 0; i < M; i++)
    {
        int a; cin >> a;
        if(a < X) c1++;
        else c2++;
    }
    cout << min(c1,c2) << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define print(x) cout<<x<<endl;
typedef long long ll;

int main() {
	int n, m;
	int a[1002], b[1002],c[1002];
	int dp[102][102];
	const int inf = 100000000;
	cin >> n >> m;
	rep(i, 0, m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
	}
	rep(i, 0, n) {
		rep(j, 0, n) {
			if (i == j) { dp[i][j] = 0; }
			else { dp[i][j] = inf; }
		}
	}

	rep(i, 0, m) {
		dp[a[i]][b[i]] = min(c[i], dp[a[i]][b[i]]);
		dp[b[i]][a[i]] = min(c[i], dp[b[i]][a[i]]);
	}

	rep(k, 0, n) {
		rep(i, 0, n) {
			rep(j, 0, n) {
				dp[i][j]=min(dp[i][j], dp[i][k]+dp[k][j]);
			}
		}
	}

	int ans = m;
	rep(i, 0, m) {
		bool flag = false;
		rep(j, 0, n) {
			if (dp[j][a[i]] + c[i] == dp[j][b[i]]) { flag = true; }
		}
		if (flag)ans--;
	}
	print(ans);
	return 0;
}

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

typedef long long ll;

int n,m,a,b,c;
string s,t,u;

int main(){
  cin>>n>>s;
  vector<string> v;
  t=s;
  v.push_back(s);
  for(int i=1;i<n;i++){
    cin>>s;
    for(int j=0;j<i;j++){
      if(v[j]==s){cout<<"No"<<endl;return 0;}
    }
    if(s[0]==t[t.size()-1]){
      v.push_back(s);
      t=s;
    }else{
      cout<<"No"<<endl;return 0;
    }
  }
  cout<<"Yes"<<endl;return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

vector<int> a(200000, 0); 

int main(){

    int n, k;
    cin >> n >> k;
    rep(i, n){
        int x;
        cin >> x;
        a[x]++;
    }
    sort(a.rbegin(), a.rend());
    int y = 0;
    rep(i, k) y += a[i];
    cout << n-y << endl;
    

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, count=0;
  cin >>N;
  for(int i=0; i<N; i++){
    int a;
    cin >>a;
    if(a%2==1) count++;
  }
  string ans="YES";
  if(count%2==1) ans="NO";
  cout <<ans <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
#include <math.h>
#include<algorithm>
#include <map>
using namespace std;


int main(int argc,char** argv)
{

	string s;

	int k,tmp;
	cin >> s >> k;
	for(int i = 0; i < s.size(); i++){
		if(s.rfind("1", i) != i){
			tmp = i;
			break;
		}
	}
	if(tmp < k){
		cout <<  s[tmp] <<endl;
	}
	else{
		cout << "1" <<endl;
	}


	return 0;
}


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

string X;
int L;

int main() {
  cin >> X; L = X.size();
  int cur = 0, bottom = 0;
  for(int i = 0; i < L; ++i) {
    cur += X[i] == 'S' ? 1 : -1;
    bottom = min(bottom, cur);
  }
  cout << (-bottom) * 2 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl

using namespace std;
using lli = long long int;

lli mod197 = 1000000007LL;

int main(void) {

	int N;
	cin >> N;

	lli sum = 0;

	for (int i = 0; i < N; i++) {
		lli a;
		cin >> a;
		sum += a;
	}

	COUT(sum - N);

	return 0;
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    int n;
    cin>>n;
    map<string, int> mp;
    ll ans=0;
    rep(i,0,n){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        ans+=mp[s];
        mp[s]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
// AOJ 1611: Daruma Otoshi
// 2018.1.30 bal4u

#include <stdio.h>
#include <string.h>

int w[301];
int dp[301][301];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, i, j, k, m, t;

	while (n = in()) {
		for (i = 0; i < n; i++) w[i] = in();
		memset(dp, 0, sizeof(dp));

		for (k = 2; k <= n; k++) for (i = 0; i <= n - k; i++) {
			j = i+k-1;
			if (dp[i+1][j-1] == k-2 && -1 <= w[i]-w[j] && w[i]-w[j] <= 1) dp[i][j] = k;
			for (m = i; m < j; m++) {
				t = dp[i][m] + dp[m+1][j];
				if (t > dp[i][j]) dp[i][j] = t;
			}
		}
		printf("%d\n", dp[0][n-1]);
	}
	return 0;
}


Measured memory_bytes: 2052
///Nahid Hasan Raju
#include <bits/stdc++.h>

#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define Fin freopen("input.txt","r",stdin)
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Fout freopen("output.txt","w",stdout)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define EPS 0.00000001
#define INF INT_MAX
#define PI 2*acos(0.0)
#define P1(XX) cout<<"db1: "<<XX<<endl
#define P2(XX,YY) cout<<"db2: "<<XX<<" "<<YY<<endl
#define P3(XX,YY,ZZ) cout<<"db3: "<<XX<<" "<<YY<<" "<<ZZ<<endl
#define set(XX,POS) XX|=(1<<POS)
#define reset(XX,POS) XX&=(~(1<<POS))
#define check(XX,POS) (bool)(XX&(1<<POS))
#define toggle(XX,POS) (XX^(1<<POS))
#define SORT(v) sort(v.begin(),v.end())
#define REVERSE(V) reverse(v.begin(),v.end())
#define VALID(X,Y,R,C) X>=0 && X<R && Y>=0 && Y<C
#define SIZE(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
#define RT printf("Run Time : %0.3lf seconds\n", clock()/(CLOCKS_PER_SEC*1.0))
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>


using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree< pair<int,int> , null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;

#define MOD 1000000007LL
#define MX 200005


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

ll m, n;
ll a[MX];
map<ll,int>mp;
int main()
{
    int test, tc=0, i, j;
    ll q,b,c,ans=0,s=0;
    //scanf("%d", &test);
    test=1;
    while(test--)
    {
       cin>>n;
       for(i=0;i<n;i++){
            scanf("%lld", &a[i]);
            s^=a[i];
            //cout<<s<<endl;
       }
       //cout<<endl;
       for(i=0;i<n-1;i++){
            ans=s^a[i];
            cout<<ans<<" ";
       }
       ans=s^a[n-1];
       cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 5184
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n;
    int ans=0;
    rep(i,n+1)ans+=i;
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define out(x) cerr << #x << " = " << x << "\n"
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
	x = 0;char c = getchar();bool f = 0;
	for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
	for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
	if(f) x = -x;
}
const int N = 2e5 + 10, mo = 1e9  + 7;
int a[N], b[N], c[N], ans = 1, n;
inline int Pow(int a, int k) {
	int ans = 1;
	for(; k; k >>= 1, a = (a * a) % mo) if(k & 1) ans = (ans * a) % mo;return ans;
}

main() {
	read(n);
	for(int i = 1; i <= n; i ++) read(a[i]);
	for(int i = 1; i <= n; i ++) read(b[i]);
	for(int i = 1; i <= n; i ++) {
		if(a[i] != a[i - 1]) {
			c[i] = a[i];
			if(a[i] != min(a[i], b[i])) return cout <<"0\n", 0;
		}
	}
	for(int i = 1; i <= n; i ++) {
		if(b[i] != b[i + 1]) {
			if(c[i] && c[i] != b[i]) return cout <<"0\n", 0;
			c[i] = b[i];	
			if(b[i] != min(a[i], b[i])) return cout <<"0\n", 0;
		}
	}
//	for(int i = 1; i <= n; i ++) cout << c[i] << ' '; putchar('\n');
	int pre = n + 1;
	for(int i = n; i >= 1; i --) {
		if(c[i]) {
			(ans *= Pow(min(c[i], c[pre]), pre - i - 1)) %= mo;
//			cout << i << ' ' << ans << ' ' << min(c[i], c[pre]) << ' ' << pre - i - 1 <<  "\n";
			pre = i;
		}
	}
	cout << ans << "\n";
	return 0; 
}

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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

int N, Q;

ll a[100005];

ll t, x, l, r, c;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N>>Q;
	
	rep(i, N) {
		cin>>a[i];
	}
	
	rep(i, Q) {
		cin>>x;
		
		l = 0;
		r = 0;
		t = 0;
		c = 0;
		
		while(l<N) {
			if(l>0)t -= a[l-1];
			l++;
			while(r<=N) {
				if(x<t)break;
				if(r<N)t += a[r];
				r++;
			}
			c += r-l;
		}
		
		cout<<c<<endl;
		
	}
	
	return 0;
}



Measured memory_bytes: 3960
#from math import abs
x,k,d=input().split()
x=int(x)
k=int(k)
d=int(d)
if(x<=0):
    if(x+k*d<=0):print(abs(x+k*d))
    else:
        res=x%d
        k-=abs(res-x)//d
        if(k%2):
            ans1=res+d
            ans2=res-d
            if(abs(ans1)>abs(ans2)):print(abs(ans2))
            else:print(abs(ans1))
        else:print(abs(res))
else:
    if(x-k*d>0):print(abs(x-k*d))
    else:
        res=x%d
        k-=abs(res-x)//d
        if(k%2):
            ans1=res+d
            ans2=res-d
            if(abs(ans1)>abs(ans2)):print(abs(ans2))
            else:print(abs(ans1))
        else:print(abs(res))
        


Measured memory_bytes: 9236
n,a,b = map(int,input().split())
s = input()
count_a = 0
count_b = 0
for i in range(n):
  s1 = s[i]
  if s1 == "c":
    print("No")
  elif s1 == "b":
    if count_a + count_b < a+b and count_b < b:
      count_b += 1
      print("Yes")
    else:
      print("No")
  else:
    if count_a + count_b < a+b:
      count_a += 1
      print("Yes")
    else:
      print("No")
      

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


int main()
{
    double a, b, x;
    cin >> a >> b >> x;
    double ans;
    if(x >= a * a * b / 2){
        ans = atan((2 / a) * (b - (x / (a * a))));
    }else{
        ans = asin((a * b * b) / sqrt(a * a * pow(b, 4) + 4 * x * x));
    }
    ans = 180 * ans / PI;
    printf("%.10f\n", ans);
}

Measured memory_bytes: 384
#include <cstdio>
#include <vector>
using namespace std;
#define ll long long

#define mx 200005

int main(){
    int N;
    scanf("%d", &N);

    ll ans=(ll)N*(N+1)*(N+2);
    ans/=6;

    for(int i=0;i<N-1;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        if(x>y) swap(x,y);
        ans-=(ll)x*(N+1-y);
    }

    printf("%lld\n",ans);
}


Measured memory_bytes: 1732
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	var k int
	fmt.Scan(&k)

	var s string
	fmt.Scan(&s)

	ss := make([]string, 0, n)
	ss = strings.Split(s, "")

	for idx, item := range ss {
		if idx == k-1 {
			ss[idx] = strings.ToLower(item)
		}
	}

	fmt.Println(strings.Join(ss, ""))
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
int a[100100], b[100100];

int solve() {
    vector<P> vec(m);
    for (int i = 0; i < m; i++) {
        vec[i] = make_pair(a[i], -b[i]);
    }
    sort(ALL(vec));

    int res = 1;
    int lb = 0, ub = 100010;
    for (int i = 0; i < m; i++) {
        int l = vec[i].first, r = -vec[i].second;
        if (ub <= l) {
            res++;
            lb = l;
            ub = r;
        } else {
            lb = l;
            ub = min(ub, r);
        }
    }
    return res;
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> a[i] >> b[i];
}

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

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


Measured memory_bytes: 1792
pub fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let s = read1::<String>().chars().collect::<Vec<char>>();
    let t = read1::<String>().chars().collect::<Vec<char>>();
    let s_len = s.len();
    let t_len = t.len();
    if s_len < t_len {
        println!("UNRESTORABLE");
        return;
    }
    let mut pos = s_len;
    for i in 0..(s_len - t_len + 1) {
        let mut flg = true;
        for j in 0..t_len {
            if s[i+j] != t[j] && s[i+j] != '?' {
                flg = false;
                break;
            }
        }
        if flg {
            pos = i;
        }
    }
    if pos != s_len {
        let ans = s.iter().enumerate().map(|(i, &c)| {
            if i >= pos && i < pos + t_len {
                t[i - pos]
            } else {
                if c == '?' {
                    'a'
                } else {
                    s[i]
                }
            }
        }).collect::<Vec<char>>();
        println!("{}", ans.into_iter().collect::<String>());
    } else {
        println!("UNRESTORABLE");
    }
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll, int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

void solve(){
	int n;
	cin >> n;
	cout << (n>=30?"Yes":"No") << endl;
}

int main(){
	fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 3628
N  = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

suma = sum(A)
sumb = sum(B)

if all( A[i] == B[i] for i in range(N)):
    print("Yes")
    exit()
if all( A[i] <= B[i] for i in range(N)):
    print("Yes")
    exit()    
if suma >= sumb:
    print("No")
    exit()
margin = 0
ato = 0
for i in range(N):
    if A[i] < B[i]:
        margin += (B[i] - A[i])//2 * 2
    if A[i] > B[i]:
        ato += A[i] - B[i]

if margin >= 2 * ato:
    print("Yes")
    exit()
print("No")



Measured memory_bytes: 40560
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

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

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int n;

ll dp[2010][2010];
vpll v;
ll solve(int l, int r) {
    if(l == r) {
        return abs(l-v.back().S) * v.back().F;
    }
    if(dp[l][r] != -1) return dp[l][r];
    int id = l+(n-1-r);
    return dp[l][r] = max(abs(l-v[id].S) * v[id].F + solve(l+1, r), abs(r-v[id].S) * v[id].F + solve(l, r-1));
}

int main() {
    ios_base::sync_with_stdio(false);
    memset(dp, -1, sizeof dp);

    cin >> n;

    for(int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        v.PB(MP(x, i));
    }
    sort(v.rbegin(), v.rend());
    cout << solve(0, n-1) << "\n";
}


Measured memory_bytes: 35424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  string S;
  cin >> S;
  ll N = S.size();

  ll ans = N;
  ll l = 1;
  for (ll i = 1; i < N; i++)
  {
    if (l == 1 && S.at(i) == S.at(i - 1))
    {
      ans--;
      l = 2;
      i++;
    }
    else
      l = 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 644
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        Map<Integer, List<Arbeit>> queue = new HashMap<>();
        for(int i=0; i<n; i++) {
            Arbeit ar = new Arbeit();
            ar.a = in.nextInt();
            ar.b = in.nextInt();
            List<Arbeit> array = null;
            if(queue.containsKey(ar.a)) {
                array = queue.get(ar.a);
            }
            else {
                array = new ArrayList<>();
            }
            array.add(ar);
            queue.put(ar.a, array);
        }
        SortedMap<Integer, List<Arbeit>> pool = new TreeMap<>();
        long result = 0;
        for(int i=1; i<=m; i++) {
            List<Arbeit> array = queue.get(i);
            if(array != null) {
                for(int j=0; j<array.size(); j++) {
                    Arbeit ar = array.get(j);
                    if(pool.containsKey(ar.b)) {
                        List<Arbeit> list = pool.get(ar.b);
                        list.add(ar);
                    }
                    else {
                        List<Arbeit> list = new ArrayList<>();
                        list.add(ar);
                        pool.put(ar.b, list);
                    }
                }
            }
            if(!pool.isEmpty()) {
                int lastKey = pool.lastKey();
                List<Arbeit> list = pool.get(lastKey);
                result += list.get(0).b;
                list.remove(0);
                if(list.isEmpty()) {
                    pool.remove(lastKey);
                }
            }
        }
        System.out.println(result);
    }
}
class Arbeit implements Comparable<Arbeit> {
    int a;
    int b;
    public static Arbeit getDummy() {
        Arbeit a = new Arbeit();
        a.a = Integer.MAX_VALUE;
        a.b = -100;
        return a;
    }
    public boolean isDummy() {
        return (this.a == Integer.MAX_VALUE && this.b == -100);
    }
    public void turnIntoDummy() {
        this.a = Integer.MAX_VALUE;
        this.b = -100;
    }

    @Override
    public int compareTo(Arbeit o) {
        return o.b - this.b;
    }
}


Measured memory_bytes: 107900
#include <cstdio>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int n;
int k;
int nQuery;
int vs[2000+10];
// int ms[2000+10][2010];
// int is[2000+10][2010];

struct K {
  vector<int> sorted;
  int used;
};
bool operator>(const K& k1, const K& k2) {
  return k1.sorted[k1.used] > k2.sorted[k2.used];
}

int main(void) {
  scanf("%d%d%d", &n, &k, &nQuery);
  set<int> ss;
  ss.insert(0);
  REP(i, n) {
    scanf("%d", &vs[i]);
    ss.insert(vs[i]);
  }

  int res = 2000000000;
  for(int v : ss) {
    priority_queue<K, vector<K>, greater<K> > q;
    { // init
      int lastOmit = -1;
      vector<int> sorted;
      REP(i, n) {
        if(vs[i] <= v) {
          if((int)sorted.size() >= k) {
            K r;
            r.used = 0;
            sort(sorted.begin(), sorted.end());
            r.sorted = sorted;
            q.push(r);
          }
          lastOmit = i;
          sorted.clear();
        } else {
          sorted.push_back(vs[i]);
        }
      }
      K r;
      r.used = 0;
      if((int)sorted.size() >= k) {
        sort(sorted.begin(), sorted.end());
        r.sorted = sorted;
        q.push(r);
      }
    }

    int maxi = -1;
    int mini = 2000000000;
    int cnt = 0;
    // cerr << endl;
    while(cnt < nQuery && !q.empty()) {
      K cur = q.top(); q.pop();
      int curV = cur.sorted[cur.used];
      // cerr << ">" << curV << endl;
      maxi = max(maxi, curV);
      mini = min(mini, curV);
      cur.used++;
      if((int)cur.sorted.size() - cur.used >= k) {
        q.push(cur);
      }
      ++cnt;
    }
    // cerr << v << " " << mini << " " << maxi << " " << cnt << endl;
    if(cnt == nQuery) {
      int cur = maxi - mini;
      res = min(res, cur);
    } else {
      break;
    }
  }

  printf("%d\n", res);
  
  return 0;
}


Measured memory_bytes: 384
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


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



int n, arr[100005], cnt[100005], depth[100005];


int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    for(int i=2;i<=n;i++){
        cin>>arr[i];
        cnt[arr[i]]++;
    }

    priority_queue<ii> pq;
    for(int i=1;i<=n;i++)
        if(cnt[i] == 0)
            pq.push({-depth[i], i});

    while(!pq.empty()){

        int d = -pq.top().ff;
        int idx = pq.top().ss;
        pq.pop();

        if(d != depth[idx]){
            pq.push({-depth[idx], idx});
            continue;
        }

        int par = arr[idx];
        depth[par] = max(depth[par]+1, depth[idx]+1);
// cout<<"set depth of "<<par<<" to "<<depth[par]<<" after playing "<<idx<<endl;

        cnt[par]--;
        if(cnt[par] == 0)
            pq.push({-depth[par], par});
    }


// cout<<"depth: ";for(int i=1;i<=n;i++)   cout<<depth[i]<<" ";cout<<endl;

    cout<<depth[1];
    return 0;
}



Measured memory_bytes: 1912
/*Author: Gautam*/
 
 
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#define MOD 1000000007
#define ull unsigned long long int
#define newline cout<<endl
 
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<ll,ll>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
 
  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 
void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    forn(i,ln(s))s[i]=(char)(s[i]-'A'+n)%26 +'A';
    cout<<s<<endl;

}

int main()
{
    FastIO;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 256
(let* ((lst (loop :repeat (read) :collect (read))))
  (defun x2 (a n)
    (if (= 0 (mod n (expt 2 (1+ a))))
        (x2 (1+ a) n)
        a))
  (defun x2a (n)
    (x2 0 n))
  (princ (reduce #'+ (mapcar #'x2a lst))))

Measured memory_bytes: 28516
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
typedef long long ll;
using namespace std;

const int N = 1000001;

bool cmp(const pair<int,int>&a, const pair<int,int>&b){
    return a.S > b.S;
}

int n;
vector<pair<int,int>>v1, v2;

int main(){
    IOS

    int n;
    cin >> n;
    FOR(i,1,n){
        string s;
        cin >> s;
        int m = s.length();
        int open = 0, closed = 0;
        FOR(j,0,m-1){
            if(s[j] == '(')
                open++;
            else{
                if(open > 0)
                    open--;
                else
                    closed++;
            }
        }
        if(open > closed)
            v1.pb(mp(open, closed));
        else
            v2.pb(mp(open, closed));
    }
    int remmatch = 0;

    sort(all(v1), cmp);
    sort(all(v2));

    for(auto p:v2){
        if(p.F > remmatch){
            cout << "No";
            return 0;
        }
        remmatch -= p.F;
        remmatch += p.S;
    }
    for(auto p:v1){
        if(p.F > remmatch){
            cout << "No";
            return 0;
        }
        remmatch -= p.F;
        remmatch += p.S;
    }

    if(remmatch != 0)
        cout << "No";
    else
        cout << "Yes";


    return 0;
}

Measured memory_bytes: 11220
/*
	Powered by C++11.
	Author : Alex_Wei.
*/

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

//#pragma GCC optimize(3)
//#define int long long

#define ll long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define mem(x,v) memset(x,v,sizeof(x))

// Templates start.

namespace IO{
	char buf[1<<21],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
	#ifdef __WIN64
		#define gc getchar()
	#else
		#define gc (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
	#endif
	#define pc(x) (*O++=x)
	#define flush() fwrite(obuf,O-obuf,1,stdout)

	inline int read(){
		int x=0,sign=0; char s=getchar();
		while(!isdigit(s))sign|=s=='-',s=getchar();
		while(isdigit(s))x=(x<<1)+(x<<3)+(s-'0'),s=getchar();
		return sign?-x:x;
	}
	void print(int x) {if(x>9)print(x/10); pc(x%10+'0');}
}

namespace math{
	const int mod=998244353;
	const int maxn=1e6+5;

	ll ksm(ll a,ll b){ll s=1,m=a; while(b){if(b&1)s=s*m%mod; m=m*m%mod,b>>=1;} return s;}
	ll inv(ll x){return ksm(x,mod-2);}

	ll fc[maxn],ifc[maxn];
	void init_m(int n){
		fc[0]=1; for(int i=1;i<=n;i++)fc[i]=fc[i-1]*i%mod;
		ifc[n]=inv(fc[n]); for(int i=n-1;i>=0;i--)ifc[i]=ifc[i+1]*(i+1)%mod;
	}
	ll C(ll n,ll m){return fc[n]*ifc[m]%mod*ifc[n-m]%mod;}
}

// Templates end. Please give me more points.

using namespace IO;
//using namespace math;


ll x;

int main(){
	cin>>x;
	for(ll i=1;i<=3e3+5;i++){
		ll tmp=i*i*i*i*i-x;
		ll l=-i,r=i;
		while(l<r){
			ll m=(l+r>>1)+1;
			if(m*m*m*m*m<=tmp)l=m;
			else r=m-1;
		}
		if(l*l*l*l*l==tmp)cout<<i<<" "<<l<<endl,exit(0);
	}
	return 0;
}

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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >

const int N=1;

int main()
{
    string s,t;
    cin>>s>>t;
    int n=s.size();
    int k=t.size();
    int ans=1e9;
    for(int i=0;i<n-k+1;i++){
            int cnt=0;
        for(int j=i;j<i+k;j++){
            if(s[j]!=t[j-i])
            cnt++;
        }
    ans=min(ans,cnt);
    }

    cout<<ans;
}


Measured memory_bytes: 3636
from itertools import product

N, M, X = [int(x) for x in input().strip().split(" ")]
C = []
A = []

for _ in range(N):
    v = [int(x) for x in input().strip().split(" ")]
    c = v.pop(0)
    C.append(c)
    A.append(v)

sums = []
patterns = product(*[(0, 1) for _ in range(N)])
for pattern in patterns:
    price = 0
    status = [0 for _ in range(M)]
    for i, p in enumerate(pattern):
        price += C[i] * p
        for j in range(M):
            status[j] += A[i][j] * p
    if min(status) >= X:
        sums.append(price)

if len(sums) > 0:
    print(min(sums))
else:
    print(-1)

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

const int NORMAL_END = 0;	/* Nomal End */
const int ERROR_END  = 1;	/* Error End */

using namespace std;

class Dice
{
public:
	/* Constructor */
	Dice() :
	TopNum   (1),
	southNum (2),
	eastNum  (3),
	westNum  (4),
	northNum (5),
	bottomNum(6)
	{
	}
	
	/* Destructor */
	~Dice()
    {
    }
	
	/** 
	 *  Get Top Number
	 *  @return TopNum Top Number
	 */
	int getTopNum( void )
	{
		return TopNum;
	}
	
	/** 
	 *  Roll to North
	 */
	void roll2North( void )
	{
		int tempNum = TopNum;
		
		TopNum    = southNum;
		southNum  = bottomNum;
		bottomNum = northNum;
		northNum  = tempNum;
		return;
	}
	
	/** 
	 *  Roll to East
	 */
	void roll2East( void )
	{
		int tempNum = TopNum;
		
		TopNum    = westNum;
		westNum   = bottomNum;
		bottomNum = eastNum;
		eastNum   = tempNum;
		return;
	}
	
	/** 
	 *  Roll to West
	 */
	void roll2West( void )
	{
		int tempNum = TopNum;
		
		TopNum    = eastNum;
		eastNum   = bottomNum;
		bottomNum = westNum;
		westNum   = tempNum;
		return;
	}
	
	/** 
	 *  Roll to South
	 */
	void roll2South( void )
	{
		int tempNum = TopNum;
		
		TopNum    = northNum;
		northNum  = bottomNum;
		bottomNum = southNum;
		southNum  = tempNum;
		return;
	}
	
	/** 
	 *  Roll to Right
	 */
	void roll2Right( void )
	{
		int tempNum = southNum;
		
		southNum = eastNum;
		eastNum  = northNum;
		northNum = westNum;
		westNum  = tempNum;
		return;
	}
	
	/** 
	 *  Roll to Left
	 */
	void roll2Left( void )
	{
		int tempNum = southNum;
		
		southNum = westNum;
		westNum  = northNum;
		northNum = eastNum;
		eastNum  = tempNum;
		return;
	}
	
private:
	int TopNum;		/* Numbers on the top of the dice    */
	int southNum;	/* Numbers on the south of the dice  */
	int eastNum;	/* Numbers on the east of the dice   */
	int westNum;	/* Numbers on the west of the dice   */
	int northNum;	/* Numbers on the north of the dice  */
	int bottomNum;	/* Numbers on the bottom of the dice */
};

/** 
 *  Roll to Right
 *  @return NORMAL_END Success
 *  @return ERROR_END  Failure
 */
int main(void)
{
	int dataSetCnt = 0;
	int dataSet;
	string roll;
	
	while( cin >> dataSet )
	{
		/* End Case */
		if( dataSet == 0 )
		{
			break;
		}
		
		/* Abnorml Case */
		if( dataSetCnt > 5 )
		{
			return ERROR_END;
		}
		if( dataSet > 10000 )
		{
			return ERROR_END;
		}
		
		Dice dice;
		int topSum = dice.getTopNum();
		
		/* Roll Dice */
		for( int i = 0; i < dataSet; i++ )
		{
			cin >> roll;
			if ( roll.compare("North") == 0 )
			{
				dice.roll2North();
			}
			else if ( roll.compare("East") == 0 )
			{
				dice.roll2East();
			}
			else if ( roll.compare("South") == 0 )
			{
				dice.roll2South();
			}
			else if ( roll.compare("West") == 0 )
			{
				dice.roll2West();
			}
			else if ( roll.compare("Right") == 0 )
			{
				dice.roll2Right();
			}
			else if ( roll.compare("Left") == 0 )
			{
				dice.roll2Left();
			}
			else
			{
				return ERROR_END;
			}
			topSum += dice.getTopNum();
		}
		
		/* Output */
		cout << topSum << endl;
		
		/* DataSetCnt CountUp */
		++dataSetCnt;
	}
	
	return NORMAL_END;
}

Measured memory_bytes: 3152
import sys
input = sys.stdin.readline

N,M,X = map(int,input().rstrip().split())
C = []
A = []
for i in range(N):
    c, *a = [int(i) for i in input().rstrip().split()]
    C.append(c)
    A.append(a)

ans = 10**18
for i in range(2**N):
    d = [0]*M
    cst = 0
    for j in range(N):
        if (i>>j&1):
            cst += C[j]
            for s in range(M):
                d[s] += A[j][s]
    ok = True
    for j in d:
        if j < X:
            ok = False

    if(ok):
        ans = min(ans,cst)

if(ans == 10**18):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9048
#include<iostream>
using namespace std;
int main(){
	const int MAX=46;
	long long f[MAX]={1,1};
	for(int i=2;i<MAX;i++)f[i]=f[i-1]+f[i-2];
	int n;
	cin>>n;
	cout<<f[n]<<endl;
	return 0;
}


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

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int A, B, C; cin >> A >> B >> C;
    END( max(0, C - (A-B)) );
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#include <map>
#include <set>
#include <array>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N, C;
	cin >> N >> C;
	vector<vector<int>> D(C + 1, vector<int>(C + 1));
	for (int i = 1; i < C + 1; i++)for (int j = 1; j < C + 1; j++)cin >> D[i][j];
	vector <vector<int> > grid(N, vector<int>(N));
	vector<vector<int> > colors(3, vector<int>(C+1,0));
	for (int i = 0; i < N; i++)for (int j = 0; j < N; j++) {
		cin >> grid[i][j];
		colors[(i + j) % 3][grid[i][j]]++;
	}
	int ans = INF;
	for (int i = 1; i <= C; i++)for (int j = 1; j <= C; j++)for (int k = 1; k <= C; k++) {
		//3で割ったときのあまりが0のグリッドをiに、1のグリッドをj,2のグリッドをkに塗り替える
		if (i == j || j == k || k == i)continue;
		int tmp = 0;
		for (int s = 1; s <= C; s++) tmp += D[s][i] * colors[0][s];
		for (int s = 1; s <= C; s++) tmp += D[s][j] * colors[1][s];
		for (int s = 1; s <= C; s++) tmp += D[s][k] * colors[2][s];
		ans = min(ans, tmp);

	}
	cout << ans << endl;
	return 0;
}

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

char s[15];

int main(){
    scanf("%s", s);
    bool ac = false;
    for(int i=1; i<strlen(s); i++){ 
        if(s[i]=='C' && i<strlen(s)-1 && i>=2 && !ac) ac = true;
        else if(s[i]< 'a' || s[i]> 'z'){
            ac = false;
            break;
        }
    }
    if(s[0] != 'A') ac = false;  
    if(ac) printf("AC");
    else printf("WA");
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
rbg = [-1, -1, -1]
ans = 1
mod = 10 ** 9 + 7

for A in a:
    ans *= rbg.count(A - 1)
    ans %= mod
    for i in range(3):
        if rbg[i] == A - 1:
            rbg[i] = A
            break

print(ans)


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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			D();
		}

		public static void D()
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int m = cin.Int();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = cin.Int();
			}

			int[] b = new int[m];
			int[] c = new int[m];
			for (int i = 0; i < m; i++) {
				b[i] = cin.Int();
				c[i] = cin.Int();
			}

			Hoge[] values = new Hoge[n + m];
			for (int i = 0; i < n; i++) {
				values[i] = new Hoge { Value = a[i], Count = 1 };
			}

			for (int i = 0; i < m; i++) {
				values[i + n] = new Hoge { Value = c[i], Count = b[i] };
			}

			Hoge[] values2 = values.OrderByDescending(x => x.Value).ToArray();
			long ans = 0;
			long count = 0;
			for (int i = 0; i < n + m; i++) {
				long num = count + values2[i].Count <= n
					? values2[i].Count
					: n - count;
				ans += values2[i].Value * num;
				count += num;
				if (count >= n) {
					break;
				}
			}

			Console.WriteLine(ans);
		}
	}

	public struct Hoge
	{
		public int Value;
		public int Count;
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 35268
#include<stdio.h>
int main(void)
{
	int a,s,d[11],f,g,i,j;
	scanf("%d",&a);
	while(a!=0){
	for(i=0;i<10;i++) d[i]=0;
		for(i=0;i<a;i++){
			scanf("%d",&s);
			d[s]++;
		}
		for(i=0;i<10;i++){
			if(d[i]>0){
				for(j=0;j<d[i];j++){
					printf("*");
				}
			}
			else if(d[i]==0){
				printf("-");
			}
			printf("\n");
		}
		scanf("%d",&a);
	}
	return 0;
}

Measured memory_bytes: 1000
//   PIGMEISTER™   //

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

#define ll long long
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define MAX 100005

ll n, m, x;
ll c[12], a[12][12], p[12];
ll ans = LLONG_MAX;

bool check(ll *che) {
    bool flag = true;
    sidha (i, 0, m) {
        //cout << che[i]<<' ';
        if (che[i] < x) {
            flag = false;
            break;
        }
    }
    return flag;
}

void mincost(ll io = 0) {
    if (io == n) {
        ll che[m] = {0};
        sidha (i, 0, n) {
            if (p[i] == 0) continue;
            sidha (j, 0, m) che[j] += a[i][j];
        }
        if (check(che)) {
            ll cos = 0;
            sidha (i, 0, n) {
                if (p[i]) cos += c[i];
            }
            ans = min(ans, cos);
        }
        return;
    }
    mincost(io+1);
    p[io] = 1;
    mincost(io+1);
    p[io] = 0;
}

int main()
{
    jaldi;
    
    cin >> n >> m >> x;
    ll che[m] = {0};
    sidha (i, 0, n) {
        cin >> c[i];
        sidha (j, 0, m) cin >> a[i][j], che[j] += a[i][j];
    }
    
    if (!check(che)) {
        cout << -1;
        return 0;
    }

    mincost();
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
 
int main () {
    int N;
    cin >> N;
    long int power = 1;
    int a = 1000000007;
    
    for (int i=1; i <= N; i++) {
        power = power * i % a;
    }
    
    cout << power << endl;
    
    
}

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

int main(void) {
  char s[6];
  
  cin >> s;
  
  if (s[2] == s[3] && s[4] == s[5]) {
    printf("Yes\n");
  }
  else printf("No\n");
  
  return 0;
}


Measured memory_bytes: 256
M[501],l;
D[999][501];
n,m,a,b,d,t;
i,j,k;
I(s,r){
	for(r=l;--r&&strcmp(s,M[r]););
	!r?M[r=l++]=strdup(s):0;
	return r;
}
main(){
	char S[100],P[100],G[100],A[100],B[100];
	for(;scanf("%d%d",&n,&m)*n;){
		memset(D,l=1,2e6);
		scanf("%s%s%s",S,P,G);
		for(;m--;){
			scanf("%s%s%d%d",A,B,&d,&t);
			a=I(A);
			b=I(B);
			D[a][b]=D[b][a]=d/40+t;
		}
		for(k=l;--k;)
			for(i=j=n;!j?j=n,--i:1;j--)
				t=D[i][k]+D[k][j],D[i][j]=D[i][j]<t?D[i][j]:t;
				//D[i][j]=fmin(D[i][j],D[i][k]+D[k][j]);
		printf("%d\n",D[I(S)][I(P)]+D[I(P)][I(G)]);
	}
}

Measured memory_bytes: 0
N = int(input())
A = [int(a) for a in input().split()]
d = [0] * (N - 1)

for i in range(N - 1):
    d[i] = 1 if A[i + 1] - A[i] > 0 else -1 if A[i + 1] - A[i] < 0 else 0

money = 1000
stock = 0
state = 0
for i in range(N - 1):
    if d[i] == 1 and state == 0:
        stock += money // A[i]
        money %= A[i]
        state = 1
    elif d[i] == -1 and state == 1:
        money += A[i] * stock
        stock = 0
        state = 0

money += A[-1] * stock
print(money)


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

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

  vector<int> D(N);
  for(int i = 0; i < D.size(); i++)
  {
    cin >> D.at(i);
  }
  
  sort(D.begin(), D.end());
  
  int numDevidingK = 0;
  int medIdx = N/2;
  
  if(D.at(medIdx - 1) >= D.at(medIdx)) numDevidingK = 0;
  else numDevidingK = D.at(medIdx) - D.at(medIdx - 1);
  
  cout << numDevidingK << endl; 
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

ll judge(ll a) {
  if (a % 4 == 0) return a;
  if (a % 4 == 1) return 1;
  if (a % 4 == 2) return a + 1;
  return 0;
}

int main() {
  ll a,b;
  cin >> a >> b;

  cout << (judge(b) ^ judge(a-1)) << endl;
}


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

int main(){
    int n,co=0,ce=0;
    cin >> n;
    for(int i = 0;i < n;i ++){
        ll a;
        cin >> a;
        if(a%2) co ++;
        else ce ++;
    }
    if(co%2&&n>1) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long int N,M,sum=0;
  cin >> N >> M;
  if(N>1)
    sum += N*(N-1)/2;
  if(M>1)
    sum += M*(M-1)/2;

  cout << sum <<endl;
}


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

 using namespace std;

 int main() {
   int x1, y1, x2, y2, x3, y3, x4, y4;

   cin >> x1 >> y1 >> x2 >> y2;

   x3 = x2 + y1 - y2;
   y3 = y2 - x1 + x2;
   x4 = x1 + y1 - y2;
   y4 = -x1 + x2 + y1;

   cout << x3 << " " << y3 << " " << x4 << " " << y4 << " ";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int num, i, ans;
	double n, a;
	cin >> n;
	a = n;
	a /= 1.08;
	ans = (int)a;
	if (a - ans > 0.0) {
		ans++;
	}
	if (ans * 108 / 100 == n)
		cout << ans << "\n";
	else
		printf(":(\n");
	return 0;
}

Measured memory_bytes: 256