akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define print(a,n)  for(lli i=0;i<n;i++)cout<<a[i]<<' ';br
#define br          cout<<endl;
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define upar        1000000007
#define fr(i,a,b)  for(int i=a;i<=b;i++)
using namespace std;

int ans=0;
using namespace std;
void solve()
{
    int n;
    cin>>n;

 cout<<(n*(n-1))/2;

}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;

    //cin>>t;

    while(t--){
        solve();

    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

void output(vector<int> s){
    int n=s.size();
    for(int i=0;i<n;i++){
        //if(i!=0) cout<<" ";
        cout<<s[i]<<endl;
    }
    //cout<<endl;
}


int D,score;
vector<int> c(27);
vector<int> last_day(27);
vector<vector<int>> s(D,vector<int>(27));

int unpresure(int d,int i){
    return c[i]*(d-last_day[i]);
}

void day(int d,int i){
    score+=s[d][i];
    last_day[i]=d;
    for(int j=1;j<=26;j++){
        score-=unpresure(d,j);
    }
}

signed main(){ 
   cin>>D; score=0;
   last_day.assign(27,0);
   s.assign(D+1,vector<int>(27));


   for(int i=1;i<=26;i++) cin>>c[i];

   for(int i=1;i<=D;i++){
       for(int j=1;j<=26;j++){
           cin>>s[i][j];
       }
   }

   vector<int> t;

   int ma=distance(c.begin(),max_element(c.begin()+1,c.end()));
   for(int i=0;i<D;i++) t.push_back(ma);

   output(t);

}  

Measured memory_bytes: 3708
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int popcount(i64 x) {
	int ret = 0;
	for(int i = 0; i < 64; i++) ret += x >> i & 1;
	return ret;
}

int main() {
	int n; cin >> n;
	std::vector<std::vector<i64>> li(3, std::vector<i64>(3000, 0));
	std::vector<std::vector<int>> A(3);
	for(int i = 0; i < n; i++) {
		for(int k = 0; k < 3; k++) {
			int a, b, c, d; cin >> a >> b >> c >> d;
			
			A[k].push_back(a * 60 + b);
			A[k].push_back(c * 60 + d);
			for(int j = a * 60 + b; j <= c * 60 + d; j++) {
				li[k][j] |= 1LL << i;
			}
		}
	}
	
	int ma = 0;
	for(auto x : A[0]) {
		for(auto y : A[1]) {
			for(auto z : A[2]) {
				for(int i = 0; i < n; i++) {
					ma = std::max(ma, popcount(li[0][x] & li[1][y] & li[2][z]));
				}
			}
		}
	}
	cout << ma << endl;
	return 0;
}



Measured memory_bytes: 3260
#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() {
  int n, k;
  cin >> n >> k;
  
  int ans = 0;
  
  while(true) {
    n = n / k;
    if (n == 0) {
      ans++;
      break;
    } else {
     ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;




void main() {
    int N;
    scan(N);

    auto cnt = new int[](26);
    cnt[] = inf;

    foreach (i ; 0 .. N) {
        string s;
        scan(s);
        auto c = new int[](26);
        foreach (ch ; s) {
            c[ch - 'a']++;
        }
        foreach (j ; 0 .. 26) {
            chmin(cnt[j], c[j]);
        }
    }

    string ans;
    foreach (i ; 0 .. 26) {
        foreach (j ; 0 .. cnt[i]) {
            ans ~= (i + 'a').to!char;
        }
    }
    writeln(ans);
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
    
		// 出力
		System.out.println(Math.max(a, b) < 9 ? "Yay!" : ":(");
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
double dp[150001];
int stones(int *a,int n,int k){
    if(k<0) return 1;
    if(k==0) return 0;
    if(dp[k]>-1) return dp[k];
    int ans=-1;
    for(int i=0;i<n;i++){
        ans=max(ans,(stones(a,n,k-a[i]))^1);
    }
    return dp[k]=ans;
}
int main() {
    int n,k;
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    int *a=new int[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=stones(a,n,k);
    if(ans==1) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}


Measured memory_bytes: 9216
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
//use proconio::marker::*;
use std::collections::*;
// use std::cmp::*;
//use std::collections::VecDeque;

fn main() {
    input! {
       N:usize, S:[String;N]
    }
    let mut nums = HashMap::new();
    for s in S {
        *nums.entry(s).or_insert(0) += 1;
    }

    println!("AC x {}", nums.get(&"AC".to_string()).unwrap_or(&0));
    println!("WA x {}", nums.get(&"WA".to_string()).unwrap_or(&0));
    println!("TLE x {}", nums.get(&"TLE".to_string()).unwrap_or(&0));
    println!("RE x {}", nums.get(&"RE".to_string()).unwrap_or(&0));
}


Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

ll C[51][51]; // C[n][k] = nCk


void combination_table(int N) {
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= i; j++) {
			if (j == 0 || j == i) C[i][j] = 1LL;
			else C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
		}
	}
}


int main() {
	int N, A, B; cin >> N >> A >> B;
	ll v[N];
	for (int i = 0; i < N; i++) cin >> v[i];
	sort(v, v + N, greater<ll>());

	ll sum = 0;
	for (int i = 0; i < A; i++) sum += v[i];
	double ans = sum / double(A);

	ll num = v[A - 1]; // こいつが何個あるか
	ll ans2 = 1;
	
	combination_table(N);

	if (v[0] != v[A - 1]) {
		int count1 = 0;
		int count2 = 0;
		for (int i = 0; i < N; i++) count1 += (v[i] == num); // 全体で何個あるか
		for (int i = 0; i < A; i++) count2 += (v[i] == num); // 先頭N個以内に何個あるか

		// nCmの計算
		// n = count1, m = count2
		ans2 = C[count1][count2];
		/*
		for (int i = count1 - count2 + 1 ; i <= count1; i++) ans2 *= i;
		for (int i = 1; i <= count2; i++) ans2 /= i;
		*/
	}
	else {// v[0] == v[A-1]
		int count1 = 0;
		int count2 = 0;
		for (int i = 0; i < N; i++) count1 += (v[i] == num);
		count2 = min(count1, B);

		ans2 = 0;
		for (int m = A; m <= count2; m++) {
			// nCmの計算
			// n = count1, m = m
			ll tmp = C[count1][m];
			/*
			for (int i = count1 - m + 1; i <= count1; i++) tmp *= i;
			for (int i = 1; i <= m; i++) tmp /= i;
			*/
			ans2 += tmp;
		}
	}

	printf("%.7f\n", ans);
	cout << ans2 << endl;

	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn switch_number(n1: &mut i32, n2: &mut i32) {
    let tmp = *n1;
    *n1 = *n2;
    *n2 = tmp;
}

fn main() {
    let mut A: i32 = read();
    let mut B: i32 = read();
    let mut C: i32 = read();
    switch_number(&mut A, &mut B);
    switch_number(&mut A, &mut C);
    println!("{} {} {}", A, B, C);
}


Measured memory_bytes: 2124
#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
	char in;
	while (in = getchar(),in!='\n') {
		if ('a' <= in && in <= 'z')
			cout << (char)(in - 0x20);
		else
			cout << in;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
int main(void){
   char a, b;
   cin >> a >> b;
   
   int A, B;
   A = a - '0';
   B = b - '0';
   
   if (A >= B) {
       for (int i=0; i<A; i++) {
           cout << b;
       }
   } else {
       for (int i=0; i<B; i++) {
           cout << a;
       }
   }
   cout << endl;
 }


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int n,m;
string s;
int a[11];
int dp[111111][11];
int solve(int k,int t){
  t %= 10;
  if(k == n) return (t?0:1);
  if(dp[k][t] >= 0) return dp[k][t];

  int res = 0;
  if(s[k] == '*'){
    for(int i = 0; i < m; i++){
      int p = a[i];
      if((n-k)%2 == 0) p*=2;
      p = p/10+p%10;
      res += solve(k+1,t+p);
    }
  }else{
    int p = s[k]-'0';
    if((n-k)%2 == 0) p*=2;
    p = p/10+p%10;
    res = solve(k+1,t+p);
  }
  return dp[k][t] = res;
}
int main(void){
  cin >> n >> s >> m;
  for(int i = 0; i < m; i++) cin >> a[i];
  memset(dp,-1,sizeof(dp));
  cout << solve(0,0) << endl;
}

Measured memory_bytes: 13920
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {

  int a;
  cin >> a;
  
if(a%10==2||a%10==4||a%10==5||a%10==7||a%10==9) cout << "hon" << endl;
else if (a%10==3) cout << "bon" << endl;
else cout << "pon" << endl;


  
}

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

typedef pair<int,int> P;

const int N=2e5+5;
const int INF=numeric_limits<int>::max();
int n,x[N],y[N],mn[N],mx[N];
set<P> Smin,Smax;
P Rx,Rn,Bx,Bn;

void del(int id){
	Smin.erase({mn[id],id});
	Smax.erase({mx[id],id});
}

void add(int id){
	Smin.emplace(mn[id],id);
	Smax.emplace(mx[id],id);
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>x[i]>>y[i];
		mn[i]=min(x[i],y[i]);
		mx[i]=max(x[i],y[i]);
		Smin.emplace(mn[i],i);
		Smax.emplace(mx[i],i);
	}
	ll res=numeric_limits<ll>::max();
	//choose Rmin->Rmax->Bmin->Bmax
	Rn=*Smin.begin();
	auto it=Smax.rbegin();
	if(it->second==Rn.second) it--;
	Rx=*it;
	if(mx[Rn.second]<mn[Rx.second]) 
		Bn={mx[Rn.second],Rn.second},		
		Bx={mn[Rx.second],Rx.second};
	else
		Bn={mn[Rx.second],Rx.second},
		Bx={mx[Rn.second],Rn.second};
	//choose Bmin first
	P oldBn=Bn,oldBx=Bx;
	if(Smax.begin()->first<Bn.first) Bn=*Smax.begin();
	for(int i=0;i<n;++i)
		if(i!=Rn.second&&i!=Rx.second&&i!=Bn.second){
			if(mn[i]<Bn.first) Bx.first=max(Bx.first,mx[i]);
			else Bx.first=max(Bx.first,mn[i]);
		}
	res=min(res,1LL*(Rx.first-Rn.first)*(Bx.first-Bn.first));
	//choose Bmax first
	Bn=oldBn,Bx=oldBx;
	if(Smin.rbegin()->first>Bx.first) Bx=*Smin.rbegin();
	for(int i=0;i<n;++i)
		if(i!=Rn.second&&i!=Rx.second&&i!=Bx.second){
			if(mx[i]>Bx.first) Bn.first=min(Bn.first,mn[i]);
			else Bn.first=min(Bn.first,mx[i]);
		}
	res=min(res,1LL*(Rx.first-Rn.first)*(Bx.first-Bn.first));
	//choose Bmin->Rmax->Bmax->Rmin
	Bn=Rn;
	Rn={mx[Bn.second],Bn.second};
	Bx={mn[Rx.second],Rx.second};
	P oldRn=Rn;
	oldBx=Bx;
	//choose Rmin first
	if(Smax.begin()->first<Rn.first) Rn=*Smax.begin();
	for(int i=0;i<n;++i)
		if(i!=Rn.second&&i!=Rx.second&&i!=Bn.second){
			if(mx[i]>=Rn.first) Bx.first=max(Bx.first,mn[i]);
			else Bx.first=max(Bx.first,mx[i]);
		}
	res=min(res,1LL*(Rx.first-Rn.first)*(Bx.first-Bn.first));
	//choose Bmax first
	Rn=oldRn;
	Bx=oldBx;
	if(Smin.rbegin()->first>Bx.first) Bx=*Smin.rbegin();
	for(int i=0;i<n;++i)
		if(i!=Rx.second&&i!=Bn.second&&i!=Bx.second){
			if(mn[i]<=Bx.first) Rn.first=min(Rn.first,mx[i]);
			else Rn.first=min(Rn.first,mn[i]);
		}
	res=min(res,1LL*(Rx.first-Rn.first)*(Bx.first-Bn.first));
//	cerr<<Rx.first<<' '<<Rn.first<<' '<<Bx.first<<' '<<Bn.first<<'\n';
	cout<<res<<'\n';
}




Measured memory_bytes: 25544
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

string s;

ll dp[13][100005],m=1e9+7;

int main()
{ios_base::sync_with_stdio(false);
cin>>s;
int n=s.length();
reverse(all(s));
dp[0][0]=1;
ll p=1;
rep(i,1,n)
{
	char c=s[i-1];
	if(c=='?')
	{
		rep(j,0,12)
		{
			rep(k,0,9)
			{
				dp[(j+(p*k))%13][i]=(dp[(j+(p*k))%13][i]+dp[j][i-1])%m;
			}
		}
	}
	else
	{
		int x=c-'0';
		rep(j,0,12)
		{
			dp[(j+p*x)%13][i]=(dp[(j+p*x)%13][i]+dp[j][i-1])%m;
		}
	}
	p=(p*10)%13;
}
ol(dp[5][n]);
return 0;
}



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

int main(){
    long long N;
    double ans=0;
    cin>>N;
    vector<pair<double,string>> vec(N);

    for(auto &x:vec){
        cin>>x.first>>x.second;

        if(x.second=="JPY"){
            ans+=x.first;
        }else{
            ans+=x.first*380000.0;
        }
    }


    printf("%.5f\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  string S; cin >> S;
  cout << (S[2] == S[3] && S[4] == S[5] ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,i,A;
	cin>>a>>b>>c;
	for(i=1;i<=1000;i++)
	{
		A=a*i;
		if(A%b==c)
		{
			cout<<"YES";
			return 0;	
		}	
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	m := make(map[int]int, 0)
	for i := 0; i < n; i++ {
		m[nextInt(sc)]++
	}
	ans := 0
	for x := 1; x < 100000; x++ {
		ans = max(ans, m[x-1]+m[x]+m[x+1])
	}
	fmt.Println(ans)
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}


Measured memory_bytes: 6784
#include <iostream>

int main(){
	int x = 0, y = 0;//数値代入
	std::cin >> x;
	std::cin >> y;

	if (x == y){//同値なら即座に終了
		std::cout << y << std::endl;
		return 0;
	}

	if (x < y){//常にx>yとなるよう調整
		int a = x;
		x = y;
		y = a;
	}

	int r = 0;//ユークリッドの互除法(GCD(x,y)= GCD(y,r))
	while (1){
		r = x % y;
		if (r == 0){
			std::cout << y << std::endl;
			break;
		}
		x = y;
		y = r;
	}

	return 0;
}

Measured memory_bytes: 1164
s = gets.chomp.split(//)
if (x = ('a'..'z').to_a - s) != []
  s << x[0]
  puts s.join('')
elsif s == ('a'..'z').to_a.reverse
  puts -1
else
  a = ('a'..'z').to_a
  (1..26).each do |i|
    if a.index(s[-i]) > a.index(s[-(i+1)])
      c = s[-(i+1)]
      s = s.take(25-i)
      x = a - s
      s << x[x.index(c)+1]
      puts s.join('')
      break
    end
  end
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
long long x,y,n,p;
char c;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
x=n*800;
p=n/15;
y=p*200;
cout<<x-y;



return 0;}



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


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

int main()
{
	string i,j;
	cin>>i;
	cin>>j;
	int len = i.length() + j.length();
	int idx = 0;
	while(idx!=len)
	{
		if(idx%2==0) printf("%c",i[idx/2]);
		else printf("%c",j[idx/2]);
		idx++;
	}
	printf("\n");
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
 
def main():
    n,k = inpm()
    p = inpl()
    for i in range(n):
        p[i] = (1+p[i])/2
    cnt = 0
    for i in range(k):
        cnt += p[i]
    ans = cnt
    for i in range(n-k):
        cnt -= p[i]
        cnt += p[i+k]
        ans = max(ans,cnt)
    print(ans)
    
if __name__ == "__main__":
    main()

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

int main() {
    ll H, N;
    ll A[100000] = {};
    cin >> H >> N;
    rep(i,N) cin >> A[i];
    ll sum = 0;
    rep(i,N) sum += A[i];
    if(H<=sum) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int k, a, b; cin >> k >> a >> b;
	if(a+1>=b || k<=a){
		cout << k+1 << endl;
		return 0;
	}
	long long int x = k-(a-1);
	if(x%2==0){
		cout << a+(b-a)*(x/2) << endl;
	}else{
		cout << a+(b-a)*(x/2)+1 << endl;
	}
	return 0;
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("7 3");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("100 10");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("1 1");
            //0
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();

        int N = wkArr[0];
        int K = wkArr[1];

        if (N % K == 0) Console.WriteLine(0);
        else Console.WriteLine(1);
    }
}


Measured memory_bytes: 13268
A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[]
y=[]
c=[]
rei=[[]for i in range(A)]
for i in range(m):
    x1,y1,c1=map(int,input().split())
    x.append(x1-1)
    y.append(y1-1)
    c.append(c1)
    #rei[x1-1].append((y1-1,c1))
    rei[x1-1].append(b[y1-1]-c1)


saisho=min(a)+min(b)

for i in range(m):
    gen=a[x[i]]+b[y[i]]-c[i]
    if(gen<saisho):
        saisho=gen

print(saisho)

Measured memory_bytes: 94828
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var HW = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (H, W) = (HW[0], HW[1]);
            var A = new string[H].Select(x => x = Console.ReadLine()).ToArray();
            var wall = string.Join("", Enumerable.Repeat("#", W + 2));
            Console.WriteLine(wall);
            for (var i = 0; i < H; i++)
            {
                Console.WriteLine($"#{A[i]}#");
            }
            Console.WriteLine(wall);
        }
    }
}


Measured memory_bytes: 28156
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=0,c=0;
        do{
            a=sc.nextInt();
            c++;
            if(a!=0){
                System.out.printf("Case %d: %d\n",c,a);
            }
        }
        while(a!=0);
        sc.close();
    }
}


Measured memory_bytes: 67160
n = gets.to_i

m = n / 3
b = n % 3

sum = 0
m.times do |i|
  mm = m - i
  bb = b + 3 * i
  ci = bb + mm - 1
  cj = [bb, ci - bb].min
  add = 1
  if cj > 0
    cc = ((ci-cj+1)..ci).reduce(&:*)
    cp = ((1..cj).reduce(&:*))
    add = cc / cp
  end

  sum += add
  sum %= 10 ** 9 + 7
end

puts sum

Measured memory_bytes: 15244
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

vector<int> xs;
vector<int> ys;

int table[8005][16005];

bool canMake(vector<int>& arr, int idx, int num)
{
    if (idx == arr.size())
    {
        if (num == 0)
            return true;
        else
            return false;
    }

    if (table[idx][num + 8001] != -1)
        return table[idx][num + 8001];

    int& res = table[idx][num + 8001];

    res = 0;

    //현재 위치를 +로 가냐 -로 가냐
    if (canMake(arr, idx + 1, num + arr[idx]))
        res = 1;
    else if (canMake(arr, idx + 1, num - arr[idx]))
        res = 1;

    return res == 1;
}

int main()
{
    string s;
    int x, y;

    cin >> s >> x >> y;
    s.push_back('T');

    bool xphase = true;

    int comp = 0;

    for (auto& c : s)
    {
        if (c == 'F')
            comp++;
        else
        {
            if (xphase)
                xs.push_back(comp);
            else
                ys.push_back(comp);

            xphase = !xphase;
            comp = 0;
        }
    }

    //이 조각들로 답 확인
    bool ans = false;
    memset(table, -1, sizeof(table));

    if (xs.empty())
        ans = (x == 0);
    else
        ans = canMake(xs, 1, x - xs[0]);

    memset(table, -1, sizeof(table));

    if (ys.empty())
        ans &= (y == 0);
    else
        ans &= canMake(ys, 1, y - ys[0]) || canMake(ys, 1, y + ys[0]);

    if (ans)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

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

string to_string(string s) {
    return '"' + s + '"';
}
string to_string(char ch) {
    string s(1, ch);
    return '\'' + s + '\'';
}
string to_string(const char *s) {
    return to_string((string)s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
 
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long int ll;
#define int ll
#define pb          push_back
#define pll         pair<int,int>
#define mll	        map<int,int>
#define F           first
#define S           second
#define lbnd(v,val) lower_bound(v.begin(),v.end(),val)
#define ubnd(v,val) upper_bound(v.begin(),v.end(),val)
#define bs(v,val)   binary_search(v.begin(),v.end(),val)
#define mp          make_pair
#define f(i,x,n)    for(int i=x;i<n;i++)
#define isup		isupper
#define islow 		islower
#define max3(a,b,c)	max(a,max(b,c))
#define endl        "\n"
#define countbits(n)	 __builtin_popcountll(n)
#define all(ar) ar.begin(), ar.end()
#define rall(ar) (ar).rbegin(), (ar).rend()
const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 2e5 + 10;

typedef vector<vector<ll>> matrix;
typedef vector<ll> vll;


void solve(){
	int n,k;
	cin>>n>>k;
	vll v(n);
	f(i,0,n){
		cin>>v[i];
	}
	vector<bool> dp(k+1);
	f(stones,0,k+1){
		for(int x: v){
			if(stones>=x and !dp[stones-x]){
				dp[stones] = true;
			}
		}
	}
	if(dp[k] ? (cout<<"First\n"): (cout<<"Second\n"));
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    

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


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

int main() {
  // your code here...
  char s[100000];
  scanf("%s", s);

  unsigned int allbit = 0;
  unsigned int bit = 0;
  for (unsigned int i = 0; s[i] != '\0'; i++) {
    bit = 1;
    bit = bit << (s[i] - 0x61);
    allbit = allbit | bit;
  }

  unsigned int expected_all = 0;
  for (unsigned int i = 0; i < 26; i++) {
    bit = 1;
    bit = bit << i;
    expected_all = expected_all | bit;
  }

  if (allbit == expected_all) {
    printf("None\n");
    return 0;
  }

  for (int i = 0; i < 26; i++) {
    if ((~allbit >> i) & 0x1) {
      printf("%c\n", i + 0x61);
      break;
    }
  }

  return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define all(v) (v).begin(), (v).end()
#define MP make_pair

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> P;
typedef vector<P> vp;

void pp(vi v){
	rep(i, v.size()){
		cout << v[i] << ' ';
	}
	cout << endl;
}

void pp(vector<string> v){
	rep(i, v.size()){
		cout << v[i] << endl;
	}
}

void pp(int (*v)[1000], int size = 10){
	rep(i, size){
		rep(j, size){
			cout << v[i][j] << ' ';
		}
		cout << endl;
	}
}

bool prime[1000000];

int main(){
	rep(i, 1000000) prime[i] = true;
	prime[0] = prime[1] = false;
	FOR(i, 2, 1000000){
		if(prime[i]){
			for(int j = i*2; j < 1000000; j+=i){
				prime[j] = false;
			}
		}
	}

	int a, d, n;
	while(cin >> a >> d >> n){
		if(!a&!d&!n)break;

		int cnt = 0;
		while(true){
			if(prime[a]) cnt++;
			if(cnt == n) break;
			a += d;
		}
		cout << a << endl;
	}

	return 0;
}

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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define pb push_back
using ll  = long long;
using vi  = vector<int>;

int k;
vi small;

bool solve(int mid){ // small[mid]を使わない
  vector<bool> dp(k,false);
  dp[0] = true;
  rep(i,small.size())
    if(i != mid)
      ROF(j,k-small[i],0)
	dp[j+small[i]] = dp[j+small[i]] or dp[j];

  bool res = false;
  FOR(i,k-small[mid],k) res |= dp[i];
  return res;
}

int bs(int _ok, int _ng){
  int ok = _ok;
  int ng = _ng;

  while(abs(ok - ng) > 1){
    int mid = (ok + ng) / 2;
    if(solve(mid)){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  return ok;
}

main(){
  int n; cin >> n >> k;
  vi a(n); rep(i,n) cin >> a[i];

  // k以上の数は全て必要
  // a[i] < kが必要 <=> a[i]を使って[k,k+a[i])が作れる
  rep(i,n) if(a[i] < k) small.pb(a[i]);
  sort(all(small));

  cout << bs(small.size(),-1) << endl;
}


Measured memory_bytes: 384
import java.util.*;
import java.util.Collections;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int X = sc.nextInt();
        if (500 * K >= X) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

 int main()
{
int n,k,arr[1000],c=0,i;
cin>>n>>k;
for(i=0;i<n;i++)
{
    cin>>arr[i];
}
sort(arr,arr+n);
for(i=0;i<k;i++)
{
    c+=arr[i];
}
cout<<c<<endl;
return 0;
}


Measured memory_bytes: 3616
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

char board[15][1010];
ll sum[15][1010], dp[1010], K;

ll get_sum(int h1, int h2, int w1, int w2) {
    return sum[h2][w2] - sum[h1][w2] - sum[h2][w1] + sum[h1][w1];
}

int main() {
    int H, W; cin >> H >> W >> K;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            cin >> board[i][j];
            sum[i+1][j+1] += (board[i][j] - '0');
        }
    }

    for(int i=0; i<=H; i++) {
        for(int j=1; j<=W; j++) {
            sum[i][j] += sum[i][j-1];
        }
    }
    for(int j=0; j<=W; j++) {
        for(int i=1; i<=H; i++) {
            sum[i][j] += sum[i-1][j];
        }
    }

    ll ans = LONGINF;
    for(int bit=0; bit<(1<<(H-1)); bit++) {
        fill(dp, dp + W + 1, -LONGINF);
        dp[0] = __builtin_popcount(bit);

        vector<ll> h1, h2;
        h1.emplace_back(0);
        for(int i=0; i<(H-1); i++) {
            // i と i+1 の間に境界がある
            if(bit >> i & 1) {
                h2.emplace_back(i+1);
                h1.emplace_back(i+1);
            }
        }
        h2.emplace_back(H);
        vector<ll> s(h1.size());

        auto check = [&](int w1, int w2) {
            bool ok = true;
            for(size_t i=0; i<h1.size(); i++) {
                ll res = get_sum(h1[i], h2[i], w1, w2);
                ok &= (res <= K);
            }
            return ok;
        };

        set< pair<ll, ll> > S;
        S.emplace(dp[0], 0LL);
        
        int ptr = 0;
        for(int i=0; i<W; i++) {
            while(ptr <= i and !check(ptr, i+1)) {
                S.erase(make_pair(dp[ptr], ptr));
                ptr++;
            }
            if(ptr > i) {
                dp[W] = LONGINF;
                break;
            }
            
            // fprintf(stderr, "bit = %d, i = %d, ptr = %d\n", bit, i, ptr);
            dp[i+1] = S.begin()->first + 1;
            S.emplace(dp[i+1], i+1);
        }

        // for(int i=0; i<=W; i++) cerr << dp[i] << " ";
        // cerr << endl;
        // fprintf(stderr, "bit = %d, cand = %lld\n", bit, dp[W] - 1);
        chmin(ans, dp[W] - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.math;

void main()
{
    int n = readln.chomp.to!int;
    long[] a = readln.split.to!(long[]);

    for (int i = 0; i < n; i++)
        a[i] -= i + 1;
    sort(a);

    long b = a[n / 2];

    long ans = 0;
    for (int i = 0; i < n; i++)
        ans += abs(a[i] - b);

    writeln(ans);
}

Measured memory_bytes: 11120
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
#include <numeric>
#include <stack>
using namespace std;

const long INF = 1000000000;
const int N_MAX = 8;
int N;
int mp = 0;
int A, B, C;
int l[N_MAX];


int dfs(int cur, int a, int b, int c) {
	int ret0, ret1, ret2, ret3;
	if (cur == N) {
		if (min({ a, b, c }) > 0) return abs(a - A) + abs(b - B) + abs(c - C) - 30; //A,B,Cが1本以上で、初期の+10*3を最後に引く
		else return INF;
	}
	ret0 = dfs(cur + 1, a, b, c);
	ret1 = dfs(cur + 1, a + l[cur], b, c)+10;
	ret2 = dfs(cur + 1, a, b + l[cur], c)+10;
	ret3 = dfs(cur + 1, a, b, c + l[cur])+10;
	return min({ ret0, ret1, ret2, ret3 });
}

int main() {
	cin >> N >> A >> B >> C;
	for (int i = 0; i < N; i++) cin >> l[i];
	cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
//#include "debug.cpp"

int32_t main()
{
	boost;

    int n,m;
    cin>>n>>m;
    if(n>m)
    	swap(n,m);
    string s="";
    while(m--){
    	s+=char(n+'0');
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  char b;
cin >> b;
if(b == 'A') cout << 'T' << endl;
if(b == 'T') cout << 'A' << endl;
if(b == 'G') cout << 'C' << endl;
if(b == 'C') cout << 'G' << endl;
}

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

int s(int n){
  int ans = 0;
  while(n > 0){
    ans += n % 10;
    n /= 10;
  }
  return ans;
}

int main(void){
  int n, m;
  cin >> n;
  m = s(n);
  if(n % m == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

score = sum(A[:K])
tmp = score
for i in range(K, N):
    tmp -= A[i-K]
    tmp += A[i]
    if score < tmp:
        print('Yes')
    else:
        print('No')
    score = tmp



Measured memory_bytes: 94168
def main():
    """
    1 <= N <= 100
    -100 <= ai <= 100
    """
    N = int(input())
    *A, = map(int, input().split())

    ans = float("inf")
    for to in range(-100, 100 + 1):
        cost = 0
        for a in A:
            cost += (a - to) ** 2
        ans = min(ans, cost)

    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  string s;
  cin>>s;

  int tho=0;
  int otho=0;

  for(int i=0;i<n;i++){
    if(s[i]=='a'&&tho<a+b){
      cout<<"Yes"<<endl;
      tho++;
    }else if(s[i]=='b'&&tho<a+b&&otho<b){
      cout<<"Yes"<<endl;
      tho++;
      otho++;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 896
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    main(input)
});

function main(input){
    var args = input.trim().split('\n');

    for(var i = 0; i < args.length; i+=1){
        var set = args[i].split(' ').map(Number);
        var n = set[0], s = set[1];
        if(!n && !s){
            return;
        }
        console.log( solve(n, s) );
    }
}

function solve(n, s){
    return countRecursively(s, -1, n);
}

function countRecursively(nowS, numPos, step){
    if(step === 0){
        var success = nowS === 0;
        return success ? 1 : 0;
    }

    var total = 0;
    for(var i = numPos + 1; i <= 9; i+=1){
        if(nowS >= i){
            total += countRecursively(nowS - i, i, step - 1);
        }
    }
    return total;
}

Measured memory_bytes: 15952
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll n;
cin>>n;
vector<ll>v;
for(ll i=0;i<n;i++)
{
    ll a;
    cin>>a;
    v.pb(a);
}
ll ans=1;
ll r=0,b=0,g=0;
for(ll i=0;i<n;i++)
{
    ll cnt=0;
    if(r==v[i])
    {
        cnt++;
    }
    if(b==v[i])
    {
        cnt++;
    }
    if(g==v[i])
    {
        cnt++;
    }
    if(r==v[i])
    {
        r++;
    }else if(b==v[i])
    {
        b++;
    }else if(g==v[i])
    {
        g++;
    }
    ans=(ans*cnt)%mod;
}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output14.txt", "w", stdout);
#endif
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s, t;
	cin >> s >> t;
	int n1, n2;
	n1 = s.length();
	n2 = t.length();
	vector<vector<int>> dp(n1 + 1, vector<int>(n2 + 1, 0));
	for (int i = 1; i <= n1; i++)
	{
		for (int j = 1; j <= n2; j++)
		{
			if (s[i - 1] == t[j - 1])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	// for (int i = 1; i <= n1; i++)
	// {
	// 	for (int j = 1; j <= n2; j++)
	// 	{
	// 		cout << dp[i][j] << "     ";
	// 	}
	// 	cout << "\n";
	// }
	string ans;
	int m = n1, n = n2;
	while (m > 0 && n > 0)
	{
		if (dp[m][n] == dp[m - 1][n])
			m--;
		else if ((dp[m][n] == dp[m][n - 1]))
			n--;
		else
		{

			ans = s[m - 1] + ans;
			n--;
			m--;
		}
	}
	cout << ans << "\n";
//cout << "\n";
}

Measured memory_bytes: 38972
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int ctoi(char c){return c - '0';}

bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v;
  for (ll i = 2; i*i <= n; ++i) {
    while(n%i==0){
      n/=i;
      v.pb(i);
    }
  }
  if(n != 1)v.pb(n);
  return v;
}

bool dfs(int n,int tmp,vector<vector<int>> a){
  if(n >= a.size())return tmp;
  bool isOk = true;
  rep(i,a[0].size()){
    isOk &= dfs(n+1,(tmp == 0)?a[n][i]:a[n][i]^tmp,a);
  }
  return isOk;
}

int main() {
  //cin.tie(0); ios::sync_with_stdio(0);
  char c;cin>>c;
  print((char)(c+1));
  return 0;
}

Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

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

	int x, y, z, k;

	cin >> x >> y >> z >> k;

	vector<long long> a(x), b(y), c(z);

	for(int i = 0; i < x; i++) cin >> a[i];

	for(int i = 0; i < y; i++) cin >> b[i];

	for(int i = 0; i < z; i++) cin >> c[i];

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	
	vector<long long> s;

	for(int i = 0; i < x; i++) {
		for(int j = 0; j < y; j++) {
			s.push_back(a[i] + b[j]);
		}
	}

	sort(s.begin(), s.end());

	vector<long long> s2;

	for(int i = 0; i < z; i++) {
		for(int j = (int)s.size() - 1; j >= max(0, (int)s.size() - k); j--) {
			s2.push_back(c[i] + s[j]);
		}
	}

	sort(s2.begin(), s2.end());
	
	for(int i = 0; i < k ; i++) {
		cout << s2[(int)s2.size() - i - 1] << "\n";
	}


	return 0;
}


Measured memory_bytes: 43368
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
using P = pair<int, int>;



int dp[1000010][2];
//1->上位紙幣使用,0->上位紙幣未使用

int main()
{
	string N;
	cin >> N;
	int ans = 0;
	dp[0][0] = (int)N[0] - '0';
	dp[0][1] = 11 - ((int)N[0] - '0');
	for (int i = 1; i < N.size(); i++) {
		int d = (int)N[i] - '0';
		dp[i][0] = min(dp[i - 1][0] + d, dp[i - 1][1] + d);
		dp[i][1] = min(dp[i - 1][0] + (11 - d), dp[i - 1][1] + (9 - d));
	}
	cout << min(dp[N.size()-1][0], dp[N.size() - 1][1]) << endl;
}

Measured memory_bytes: 9220
n=int(input())
s=input()
Rs,Gs,Bs=[],[],[]

for i in range(n):
    if s[i]=='R':
        Rs.append(i)
    elif s[i]=='G':
        Gs.append(i)
    else:
        Bs.append(i)

ans=len(Rs)*len(Gs)*len(Bs)
for i in Rs:
    for j in Gs:
        dis=abs(i-j)
        a=min(i,j)-dis
        b=max(i,j)+dis
        c=min(i,j)+dis//2
        if a>=0:
            if s[a]=='B':
                ans-=1
        if b<n:
            if s[b]=='B':
                ans-=1
        if dis%2==0:
            if s[c]=='B':
                ans-=1

print(ans)

Measured memory_bytes: 9252
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    s=input()
    q=int(input())
    even=1
    right=[]
    left=[]
    for i in range(q):
        temp=list(input().split())
        temp[0]=int(temp[0])
        if temp[0]==2:
            a=int(temp[1])
            b=temp[2]
            if a==1:
                left.append(b)
            else:
                right.append(b)
        else:
            even=-(even-1)
            left,right=right,left
#    print(left,s,right,even)
    if even==0:
        s=s[::-1]
 #       right=right[::-1]
    left=left[::-1]
    ans="".join(left)+s+"".join(right)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 72024
def calculAngle(h,m):          
    if (h == 12): 
        h = 0
    if (m == 60): 
        m = 0
    h_angle = 0.5 * (h * 60 + m) 
    m_angle = 6 * m 
    angle = abs(h_angle - m_angle) 
    angle = min(360 - angle, angle) 
    return angle 
import math
A,B,H,M = map(int,input().split())
ans = math.sqrt(A**2 + B ** 2 - 2 * A * B * math.cos(math.radians(calculAngle(H,M))))
print(ans)

Measured memory_bytes: 9464