akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define  st first
#define  nd second
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define MAXN  1<<17
#define MOD   1000000007
#define int long long
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef gp_hash_table<int, int, hash<int > > ht;
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  string s,t;
  cin>>s>>t;
  int c=0;
  for(int i=0;i<3;i++)
    if(s[i]==t[i])
      c++;
  cout<<c;



  return 0;
}


Measured memory_bytes: 256
n, m, x = gets.split.map(&:to_i)
a = Array.new(n).map{Array.new(m+1, 0)}
c = []
for i in 0...n
    a[i] = gets.split.map(&:to_i)
    c[i] = a[i].shift
end

MAX = 10**9
ans = MAX
N = 1<<n
for b in 1...N
    ok = true
    for j in 0...m
        sumx = 0
        for i in 0...n
            if (b & (1<<i)) != 0
                sumx += a[i][j]
            end
        end
        if sumx < x
            ok = false
            break
        end
    end

    if ok
        sumc = 0
        for i in 0...n
            if (b & (1<<i)) != 0
                sumc += c[i]
            end
        end
        ans = sumc if ans > sumc
    end
end

ans = -1 if ans == MAX
puts ans

Measured memory_bytes: 14380
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

int my[4]={0, 1, 0, -1}, mx[4]={1, 0, -1, 0};

signed main() {
    int h, w;
    cin >> h >> w;
    V(V(char)) A(h, V(char)(w));
    int sum = 0;
    queue<P> q;
    P la = P(0, 0);
    rep(i, h) rep(j, w) {
        cin >> A[i][j];
        if(A[i][j]=='#') {
            q.push(P(i, j));
            la = P(i, j);
        }
    }

    int res = 0;
    while(!q.empty()) {
        P n = q.front();
        q.pop();
        rep(i, 4) {
            int ny=n.fi+my[i], nx=n.se+mx[i];
            if(ny>=0 && ny<h && nx>=0 && nx<w) {
                if(A[ny][nx]=='.') {
                    A[ny][nx]='#';
                    q.push(P(ny, nx));
                }
            }
        }
        if(n==la) {
            res++;
            la=q.back();
        }
    }
    

    cout << res-1 << endl;
    
    return 0;
}

Measured memory_bytes: 17588
#include <iostream>
#include <map>
#include <vector>
#include <math.h>
#include <cstring>
#include <algorithm>
#include<iterator>
using namespace std;

#define booster           std::ios::sync_with_stdio(false); cin.tie(0);
typedef long long int ll;
typedef long int li;
typedef double dl;
#define prec(n) fixed << setprecision(n)


int main() {
    
    #ifndef ONLINE_JUDGE
    freopen("i.txt", "r", stdin);
    freopen("o.txt", "w", stdout);
#endif
    ll n;
    cin>>n;

    ll helper=ceil(n/1000);
  
     ll rem=0;
   if(n%1000!=0)  rem=(helper+1)*1000-n;
   
    cout<<rem<<"\n";
    return 0;
}

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
from collections import *

def bfs():
    color = [0]*N
    color[0] = 1
    q = deque([0])
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if color[nv]==0:
                color[nv] = -color[v]
                q.append(nv)
            else:
                if color[nv]==color[v]:
                    return False
    
    return True
    
def warshall_floyd():
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
            
N = int(input())
S = [input()[:-1] for _ in range(N)]
G = [[] for _ in range(N)]

for i in range(N):
    for j in range(i+1, N):
        if S[i][j]=='1':
            G[i].append(j)
            G[j].append(i)

if not bfs():
    print(-1)
    exit()

d = [[10**18]*N for _ in range(N)]

for i in range(N):
    d[i][i] = 0
    
for i in range(N):
    for j in range(i+1, N):
        if S[i][j]=='1':
            d[i][j] = 1
            d[j][i] = 1

warshall_floyd()
ans = 0

for i in range(N):
    for j in range(N):
        ans = max(ans, d[i][j])

print(ans+1)

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;
typedef vector<string> vecst;

int main(){
    ll N, x;
    cin >> N >> x;
    vecll a(N);
    for(auto& i: a) cin >> i;
    sort(a.begin(), a.end());
    ll ans = 0;
    while(ans < N){
        x -= a.at(ans);
        if(x < 0 || (ans == N - 1 && x > 0)) break;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// listに書き直す
#include <iostream>

struct Node {
	int key;
	Node* next;
	Node* prev;
};

class Splice {
public:
	Node* first;
	Node* end;
	int size;
	Splice() {
		size = 0;
		first = new Node;
		end = new Node;
		first->next = end;
		first->prev = nullptr;
		end->next = nullptr;
		end->prev = first;
	}
	void insert(int x) {
		size++;
		Node* n = new Node;
		n->key = x;
		n->next = end;
		n->prev = end->prev;
		end->prev->next = n;
		end->prev = n;
	}
	void dump() {
		Node* tmp = first;
		for (int i = 0; i < size; i++) {
			tmp = tmp->next;
			std::cout << tmp->key;
			if (i < size - 1) {
				std::cout << " ";
			}
		}
		std::cout << std::endl;
	}
	void splice(Splice& s) {
		end->prev->next = s.first->next;
		end->prev->next->prev = end->prev;
		end = s.end;
		size += s.size;

		s.size = 0;
		s.first = new Node;
		s.end = new Node;
		s.first->next = s.end;
		s.end->prev = s.first;
	}
};

int main() {
	int n, q;
	std::cin >> n >> q;
	Splice* s = new Splice[n];
	while (q--) {
		int com, t;
		std::cin >> com >> t;
		if (com == 0) {
			int x;
			std::cin >> x;
			s[t].insert(x);
		}
		if (com == 1) {
			s[t].dump();
		}
		if (com == 2) {
			int t1;
			std::cin >> t1;
			s[t1].splice(s[t]);
			//s[t1].dump();
		}
	}
}




Measured memory_bytes: 28120
#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
string s;
int main()
{
	cin>>s;
	if(s[0]==s[s.length()-1])puts(s.length()&1?"Second":"First");
	else puts(s.length()&1?"First":"Second");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;

vector<int> edg[200005];
bool used[200005];

int main() {
	int n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	
	int ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (used[i]) continue;
		
		for (ll t = 1; t <= 30; t++) {
			ll tg = (1LL << t) - a[i];
			if (tg <= 0) continue;
			if (tg > a[i]) continue;

			int lo = -1, hi = i;
			while (hi - lo > 1) {
				int mid = lo + (hi - lo) / 2;
				if (a[mid] > tg) hi = mid;
				else lo = mid;
			}
			int ub = hi;
			lo = -1, hi = i;
			while (hi - lo > 1) {
				int mid = lo + (hi - lo) / 2;
				if (a[mid] >= tg) hi = mid;
				else lo = mid;
			}
			int lb = hi;
			for (int j = ub - 1; j >= lb; j--) {
				if (used[j]) continue;
				used[i] = used[j] = true;
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

const ll mod = 1000000007;
const int INF = 101234567;

int main() {
    string s;
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    map<char, int>m;
    for (int i = 25; i >= 0; i--) {
        m[alphabet[i]] = 26 - i;
    }
    ll K;
    cin >> s;
    cin >> K;

    int i = 0;
    while (K > 0) {
        if (i == s.size()-1) {
            break;
        }
        if (s[i] == 'a') {
            i++;
            continue;
        } else {
            if (m[s[i]] <= K) {
                K -= m[s[i]];
                s[i] = 'a';
            }
        }
        i++;
    } 
    K %= 26;
    int loc = 26 - m[s[i]];
    loc += K;
    loc %= 26;
    s[i] = alphabet[loc];
    cout << s << endl;
}



Measured memory_bytes: 512
using System;
using System.IO;
using System.Text;

namespace Contest
{
    class Program
    {
        private Scanner sc;
        private string S, T;
        public void Solve()
        {
            sc = new Scanner();
            long N = sc.NextLong();
            long M = sc.NextLong();
            long cnt = 0;
            cnt += Math.Min(N, M / 2);

            N -= cnt;
            M -= cnt * 2;

            cnt += M / 4;
            Console.WriteLine(cnt);
        }

        static void Main() => new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
        _separator = ' ';
    }
    private readonly char _separator;
    private readonly StreamReader _stream;
    private int _pos;
    private string[] _line;
    #region get a element
    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(_separator);
            _pos = 0;
        }
        return _line[_pos++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    #endregion
    #region convert array
    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }
    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }
    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }
    #endregion
    #region get array
    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(_separator);
        _pos = _line.Length;
        return _line;
    }
    public int[] IntArray()
    {
        return ToIntArray(Array());
    }
    public long[] LongArray()
    {
        return ToLongArray(Array());
    }
    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }
    #endregion
}

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

int main() {
    string b;
    cin >> b;
    for (int i = 0; i < b.size(); i++) {
        if(b[i]=='A'){
            b[i] = 'T';
        }else if(b[i]=='C'){
            b[i] = 'G';
        }else if(b[i]=='T'){
            b[i] = 'A';
        }else{
            b[i] = 'C';
        }
    }

    cout << b << endl;
}

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

using namespace std;

int main(){
  int x, n;
  cin >> x >> n;
  cin.ignore();

  vector<int> p;
  int tmp;
  for(int i = 0; i < n; i++){
    cin >> tmp;
    p.push_back(tmp);
  }
  if(n != 0){
    cin.ignore();
  }
  sort(p.begin(), p.end());

  int p_ptr = 0;
  int min = INT_MAX;
  int ans = -1;
  for(int i = 0; i <= 101; i++){
    if(p_ptr < p.size() && i == p[p_ptr]){
      ++p_ptr;
      continue;
    }
    int ab = abs(x - i);
    if(ab < min){
      ans = i;
      min = ab;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	int ans = 700;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'o') {
			ans += 100;
		}
	}
	cout << ans << endl;
	return 0;
}	

Measured memory_bytes: 256
n = int(input())
a = {}
for i in range(n):
    s = input()
    if s in a:
        a[s] += 1
    else:
        a[s] = 1
a = sorted(a.items(), key=lambda x: x[1], reverse=True)
max_a = a[0][1]
w = []
for i in range(len(a)):
    if a[i][1] == max_a:
        w.append(a[i][0])
    else:
        break
w = sorted(w)
for i in range(len(w)):
    print(w[i])

Measured memory_bytes: 47476
n = int(input())
a = list(map(int,input().split()))

ans = []
x = a[0]
y = a[0]

flg = False
for i in range(n-1):
   if flg:
     x += a[i+1]
     y -= a[i+1]
     flg = False
   else:
     x -= a[i+1]
     y += a[i+1]
     flg = True

ans.append(x)
ans.append(y)

p = 0

for i in range(n-2):
  ans.append(ans[p] -2*a[p] + 2*a[p+1] )
  p += 1

ans_str = " ".join(list(map(str,ans)))
print(ans_str)

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

int main(){
  int N,M,C;
  cin>>N>>M>>C;
  int B[M],A[N][M];
  for(int i=0; i<M; ++i) cin>>B[i];
  for(int i=0; i<N; ++i){
    for(int j=0; j<M; ++j){
      cin>>A[i][j];
    }
  }
  int ans=0;
  for(int i=0; i<N; ++i){
    int count=0;
    for(int j=0; j<M; ++j){
      count += A[i][j]*B[j];
    }
    if(count+C>0) ans+=1;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<set>
#include<string>

using namespace std;

int n;
string s;
int main(){
  string cmd;
  typedef set<string> set_t;
  set_t A;
  cin >> n;
  while (cin >> cmd && n >= 1){
    n--;
    if (cmd == "insert"){
      cin >> s;
      A.insert(s);
    }
    else if(cmd == "find"){
      cin >> s;
      if(A.count(s) == 1){
        cout << "yes" << endl;
      }else{
        cout << "no" << endl;
      }
    }
  }
}


Measured memory_bytes: 32620
// Problem : C - Tsundoku
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_c?lang=en
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)
#define int long long

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
    int f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

inline LL gl()
{
    LL f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;

int n, m, k;
int a[N], b[N];
int sa[N], sb[N];
int ta, tb;

signed main()
{
    //File("");
    n = gi(), m = gi(), k = gi();
    int ans = 0;
    for (int i = 1; i <= n; i+=1) a[i] = gi(), sa[i] = sa[i - 1] + a[i];
    for (int i = 1; i <= m; i+=1) b[i] = gi(), sb[i] = sb[i - 1] + b[i];
    ta = 1, tb = m;
    for (int i = 0; i <= n; i+=1)
    {
    	if (sa[i] > k) break;
    	while (tb > 0 && sb[tb] + sa[i] > k) --tb;
    	ans = max(ans, i + tb);
    }
    cout << ans << endl;
    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end

template<unsigned mod=998244353>struct mint {
   unsigned val;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=val,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0)x+=mod; return x;
   }
   mint():val(0){}
   mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
   mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
   mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
   mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
   mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;}
   mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;}
   mint operator+(const mint& x)const{return mint(*this)+=x;}
   mint operator-(const mint& x)const{return mint(*this)-=x;}
   mint operator*(const mint& x)const{return mint(*this)*=x;}
   mint operator/(const mint& x)const{return mint(*this)/=x;}
   bool operator==(const mint& x)const{return val==x.val;}
   bool operator!=(const mint& x)const{return val!=x.val;}
};
template<unsigned mod=998244353>struct factorial {
   using Mint=mint<mod>;
   vector<Mint> Fact, Finv;
public:
   factorial(int maxx){
      Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
      Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
   }
   Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
   Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};
using Mint=mint<>;
factorial<> fact(4020);

int main(){
   int n,k; scanf("%d%d",&k,&n);
   vector<Mint> res(k+2);
   rep(rot,2,k+2){
      int r2=rot/2;
      rep(i,0,r2+1){
         Mint add=fact.nCr(r2,i)*fact.nCr(k+n-i*2-1,n-i*2);
         if(i&1)res[rot]-=add; else res[rot]+=add;
      }
   }
   auto sub=res; sub.pop_back(); reverse(ALL(sub));
   res.insert(res.end(),ALL(sub));
   rep(i,2,2*k+1)printf("%d\n",res[i].val);
   return 0;
}

Measured memory_bytes: 384
def solve():
    N,K=map(int,input().split())
    S=input()
    s2=[]
    cp='1'
    cn=0
    count={'0':0, '1':0}
    for c in S:
        if cp != c:
            s2.append(cn)
            count[cp]+=1
            cp = c
            cn = 0
        cn += 1
    s2.append(cn)
    count[cp]+=1
    if cp=='0':
        s2.append(0)

    csum = [0]
    csumval = 0
    for v in s2:
        csumval += v
        csum.append(csumval)

    s2_len = len(s2)
    csum_len = len(csum)

    if count['0'] <= K:
        return csum[-1]

    #print('csumlen =',csumlen)
    ans=0
    for i in range(1,s2_len,2):
        ans1 = csum[min(i+K*2,s2_len)]-csum[i-1]
        #print(ans1,i,i+K*2)
        ans = max(ans,ans1)
    return ans

print(solve())


Measured memory_bytes: 47412
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<map> 
#include<string>
#include<queue>
#include<stack> 
#include<bitset>
#include<list>
#include<set>
#include<utility>
#define IO ios::sync_with_stdio(false)
#define int long long
using namespace std;
int n,a[200005],pos=1,ans;
bool cmp(int x,int y)
{
	return x>y;
}
signed main()
{
	IO;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1,cmp);
	/*for(int i=1;i<=n;i++)
	{
		cout<<a[i]<<" ";
	}
	cout<<endl;*/
	ans+=a[pos];
	//cout<<ans<<endl;
	//pos++;
	for(int i=3;i<=n;i++)
	{
		if(i%2!=0)pos++;
		ans+=a[pos];
	}
	cout<<ans;
}


Measured memory_bytes: 5272
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

ll gcd(ll a,ll b){
  ll r = a%b;
  while(r!=0){
    a = b;
    b = r;
    r = a%b;
  }

  return b;
}

int main(){
  ll n; cin >> n;
  vector<ll> t(n);
  rep(i,n){
    cin >> t.at(i);
  }

 sort(all(t));

 rep(i,n-1){
   if(t.at(i)>t.at(i+1)) swap(t.at(i),t.at(i+1));
   if(t.at(i+1)%t.at(i)==0) continue;
   else t.at(i+1)=t.at(i)/gcd(t.at(i+1),t.at(i))*t.at(i+1);
 }

 cout << t.at(n-1) << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define endl "\n"
	#define space " "
	#define ll long long int
	#define vl vector<ll>
	#define vvl vector < vll >
	#define pii pair<int,int>
	#define pll pair<ll,ll>
	#define vpl vector < pll >
	#define mod 1000000007
	#define pi 3.1415926535897932384626433
	#define inf 1000000000000000001;
	#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y) 
	#define mem(a,val) memset(a,val,sizeof(a))
	#define pb push_back
	#define f first
	#define s second
	
	void solve()
	{
		ll n,k; cin>>n>>k;
		vector<ll>v(n);
		ll a=k-1,sum=0,l=0,m=0;
		for (int i = 0; i < n; ++i)
		{
			/* code */
			cin>>v[i];
		}
		for(int i=0;i<=a;i++){
			sum+=v[i];
		}
		m=sum;
		for(int i=a+1;i<n;i++){
			sum=sum+v[i]-v[l];
			if(sum>m){
				cout<<"Yes"<<endl;
			}
			else cout<<"No"<<endl;
			l++; m=sum;
		}
	}

	signed main()
	{

	fast;
	#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
     #endif

	ll T=1;
	// cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
	}


Measured memory_bytes: 4780
#include<iostream>
#include<math.h>
//#include<map>                                                                                                        
using namespace std;

int main()
{
  // 入力                                                                                                              
  int A, B;
  cin >> A >> B;

  int mult, add, sub;

  add = A + B;
  sub = A - B;
  mult = A * B;

  // 出力                                                                                                              
  cout << max(max(add, sub), mult) << endl;

  return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int x, y; cin >> x >> y;
    if (x == 1 && y == 1) {
        cout << 1000000 << '\n';
    }
    else {
        int ans = 0;
        if (x <= 3) ans += 100000*(4-x);
        if (y <= 3) ans += 100000*(4-y);
        cout << ans << '\n';
    }
}



Measured memory_bytes: 256
'use strict'

const main = arg => {
 const input = arg.trim().split("\n")[0].split(" ").map(num => parseInt(num, 10));
 const A = input[0];
 const B = input[1];

 const integer = Math.floor(A / B);
 const remainder = A % B;
 var realNumber = (A/B).toFixed(5);

 console.log(`${integer} ${remainder} ${realNumber}`);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 15380
#include "bits/stdc++.h"
using namespace std;
int main(void){
    int N,T[100],M,P[100],X[100],SUM=0;
    cin >> N;
    for (int i=0;i<N;i++){
        cin >> T[i];
        SUM += T[i];
    }

    cin >> M;

    for (int g=0;g<M;g++){
        cin >> P[g] >> X[g];
        cout << SUM - T[P[g] - 1] + X[g] << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18+2;
const int MX=300503;
int N, M, k;
ll arr[MX];
int main()
{
    int i;
    cin>>N>>i;int an=0;
    while(N)
    {
        an++;
        if(N == i) break;
        N--;
    }
    cout<<an;
    return 0;
}



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

int main() {
  long long s, c, x;
  cin >> s >> c;

  if (s >= c / 2) x = c / 2;
  else {
    x = s;
    c -= s * 2;
    x += c / 4;
  }

    
  cout << x << endl;
  
  return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;

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

    int n; cin >> n;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n; i++) cin >> q[i];

    vector<int> ref(n);
    iota(ref.begin(), ref.end(), 1);
    int cnt = 0, a, b;
    do {
        if (p == ref) a = cnt;
        if (q == ref) b = cnt;
        cnt++;
    } while (next_permutation(ref.begin(), ref.end()));
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
def pows(n, K):
    count = 0
    while True:
        if n >= K:
            return count
        n = n * 2
        count += 1


def main():
    N, K = list(map(int, input().split()))
    # re = max(N - K, 0) / N
    re = 0
    # print(re)
    for i in range(1, N + 1):
        if i >= K :
            re = re + 1 / N
            continue
        p = pows(i, K)
        # print(p)
        re = re +  pow(0.5, p) / N
    print(re)
    # print(re / N)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    std::deque<int> deq_a;
    std::deque<int> deq_b;
    std::deque<int> result;
    int n,a,m,b;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        deq_a.emplace_back(a);
    }
    cin >> m;
    for (int j=0;j<m;j++) {
        cin >> b;
        deq_b.emplace_back(b);
    }
    set_difference(deq_a.begin(),deq_a.end(),deq_b.begin(),deq_b.end(),inserter(result,result.end()));
    for (int k=0;k<result.size();k++) {
        cout << result[k] << endl;
    }
}



Measured memory_bytes: 5244
<?php
while (fscanf(STDIN, "%d %d", $n, $q) && ($n | $q)) {
  
  $day = array();
  for ($i = 0; $i < 100; $i++) {
    $day[] = 0;
  }

  while ($n--) {
    $tmp = explode(' ', trim(fgets(STDIN)));
    
    for ($i = 1; $i < count($tmp); $i++) {
      $day[$tmp[$i]]++;
    }
  }
  
  $ans = 0;
  $maxm = $q - 1;
  
  for ($i = 0; $i < 100; $i++) {
    if ($day[$i] > $maxm) {
      $ans = $i;
      $maxm = $day[$i];
    }
  }

  print $ans . "\n";
}

Measured memory_bytes: 6672
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

int n, k, a[N];

bool tmam(ll x){
    ll c = 0;
    for(int i = 0; i < n; i++){
        c += ((a[i]- 1) / x);
        if(c > k) return 0;
    }
    return 1;

}


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> a[i];
    ll low = 1, high = mod - 7, mid, ans = mod;
    while(high >= low){
        mid = low + high >> 1;
        if(tmam(mid)){
            ans = mid;
            high = mid - 1;
        }
        else low = mid + 1;
    }
    cout << ans;

   return 0;
}


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

int main(void)
{
        int i,j,l,c=0;
        char s[200];

        scanf("%s",s);
        l=strlen(s);
        for(i=l-3;i>0;i-=2){
                c=0;
                for(j=0;j<(i+1)/2;j++){
                        if(s[j]==s[(i+1)/2+j])c++;
                }
                if(c==(i+1)/2){
                        printf("%d\n",i+1);
                        return 0;
                }
        }
        printf("0\n");
        return 0;
}



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

template <class T = int>
class SegTree {
    int orig_n;

    // k番目のノードの[l, r)について[a, b)を求める
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return UNIT;
        }
        if (a <= l && r <= b) {
            return dat[k];
        }
        T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return f(vl, vr);
    }

public:
    int N;
    vector<T> dat;
    function<T(T, T)> f;
    T UNIT;

    SegTree() {}

    SegTree(int n, function<T(T, T)> f_, const T unit) : orig_n(n), f(f_), UNIT(unit) {
        for (N = 1; N < n; N *= 2)
            ;
        dat = vector<T>(2 * N - 1, UNIT);
    }

    SegTree(const vector<T> &a, function<T(T, T)> f_ = [](int a, int b) { return max(a, b); }, T unit = 0)
        : orig_n(a.size()), f(f_), UNIT(unit) {
        for (N = 1; N < orig_n; N *= 2)
            ;
        dat = vector<T>(2 * N - 1);
        for (int i = 0; i < a.size(); i++) {
            dat[N - 1 + i] = a[i];
        }
        for (int k = N - 2; k >= 0; k--) {
            dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    // k番目をaに
    void update(int k, T a) {
        k += N - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    // [a, b)でのクエリ
    T query(int a, int b) {
        assert(0 <= a && a < b && b <= orig_n);
        return query(a, b, 0, 0, N);
    }

    T query(int a) { return query(a, a + 1); }
};

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

    int n, k;
    cin >> n >> k;
    vector<int> as(n);
    for (int i = 0; i < n; i++) cin >> as[i];

    int ans = 1;
    SegTree<int> nin(as, [](int a, int b) { return min(a, b); }, 1e9);
    SegTree<int> nax(as, [](int a, int b) { return max(a, b); }, -1e9);

    vector<bool> sorted(n);
    int cnt = 1;
    for (int i = 1; i < n; i++) {
        if (as[i] > as[i - 1]) {
            cnt++;
        } else {
            cnt = 1;
        }
        if (cnt >= k) sorted[i] = true;
    }
    bool add_sorted = sorted[k - 1];
    for (int i = 0; i < n - k; i++) {
        if (as[i] == nin.query(i, i + k + 1) && as[i + k] == nax.query(i, i + k + 1)) {
            // same
        } else {
            if (sorted[i + k]) {
                if (!add_sorted) ans++;
                add_sorted = true;
            } else {
                ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 5120
n = int( input() )
a = list( map( int, input().split() ) )
b = list( map( int, input().split() ) )
 
kill = 0
for i in range(n):
    if a[i] >= b[i]:
        a[i] -= b[i]
        kill += b[i]
        b[i] = 0
    else:
        b[i] -= a[i]
        kill += a[i]
        a[i] = 0
        if a[i+1] >= b[i]:
            a[i+1] -= b[i]
            kill += b[i]
            b[i] = 0
        else:
            b[i] -= a[i+1]
            kill += a[i+1]
            a[i+1] = 0
 
print(kill)

Measured memory_bytes: 82020
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>


using namespace std;

string s,ans="";
int p=0;
string c,d;
int cou;


int string_num(string str) {
	stringstream sstream;
	int n;
	sstream << str;
	sstream >> n;
	return n;
}


int main(){
	while(cin >> s){
		ans = "";
		p=0;

		while(s[p] != '\0'){
			if(s[p] != '@'){
				ans += s[p];
			}else{
				c = s[++p];
				cou = string_num(c);
				p++;
				for(int i=0;i<cou;i++){
					ans += s[p];
				}

			}
			p++;
		}
		cout << ans << endl;


	}

}

Measured memory_bytes: 2992
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {
    
    int N, M; cin >> N >> M;
    map<int,vector<int>> mp;
    rep(i,M) {
        int a, b; cin >> a >> b;
        mp[a].push_back(b);
        mp[b].push_back(a);
    }

    bool seen[N+1]; rep(i,N+1) seen[i] = false;
    int ans[N+1];

    queue<int> que;
    que.push(1);
    seen[1] = true;
    while (!que.empty()) {
        int now = que.front(); que.pop();
        rep(i,mp[now].size()) {
            int next = mp[now][i];
            if (seen[next] == false) {
                que.push(next);
                seen[next] = true;
                ans[next] = now;
            }
        }
    }

    bool flag = true;
    for (int i = 1; i <= N; ++i) {
        if (!seen[i]) flag = false;
    }
    if (flag) {
        cout << "Yes" << endl;
        for (int i = 2; i <= N; ++i) {
            cout << ans[i] << endl;
        }
    }
    else {
        cout << "No" << endl;
    }
    

    
    return 0;
}






Measured memory_bytes: 16080
exception InvalidInput
let () =
  let line = read_line () in
  let a, b = line |>
             Str.split (Str.regexp " ") |>
             List.map int_of_string |>
             (function | [a; b] -> a, b
                       | _ -> raise InvalidInput) in
  let d = a / b
  and m = a mod b
  and fd = ((float_of_int a) /. (float_of_int b)) in
  Printf.printf "%d %d %.6f" d m fd

Measured memory_bytes: 2356
#include <bits/stdc++.h>
#define ll long long
#define pb(x) push_back((x))
#define line() cerr << "DEBUG @" << __LINE__ << endl;
#define debug(x) \
    cerr << "DEBUG @" << __LINE__ << " -> " << #x << " = " << x << endl;
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int best = 0;
    for (int i = 0; (i + m - 1) < n; i++) {
        int cur = 0;
        for (int j = i; j < i + m; j++) {
            cur += s[j] == t[j - i];
        }
        best = max(best, cur);
    }
    cout << (m - best) << endl;
}


Measured memory_bytes: 3612
debug = False

if debug:import time
if debug:start = time.time()

n = int(input())
R = [0]*n
R_min = 10**9

for i in range(n):
    R[i] = int(input())

maximum_profit = -10**9
for i in range(1, n):
    R_min = R[i-1] if R[i-1] < R_min else R_min
    profit = R[i] - R_min
    maximum_profit = profit if profit > maximum_profit else maximum_profit
print(maximum_profit)

if debug:print(time.time() - start)

Measured memory_bytes: 15324
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e10;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 100;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    ll cnt = 0,x,y,ind = n-1;
    SORT(a);
    while(ind > 0){
        if (a[ind] == a[ind-1]){
            if (cnt == 0){
                x = a[ind];
                cnt++;
                ind -= 2;
            }
            else{
                y = a[ind];
                cnt++;
                break;
            }
        }
        else{
            ind--;
        }
    }
    if (cnt < 2) PRINT(0);
    else PRINT(x*y);
}


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

bool nine(long long N) {
    string S = to_string(N);
    bool Flag = true;
    for (int i = 1; i < S.length(); i++) {
        if (S[i] != '9') Flag = false;
    }
    return Flag;
}

int tn(long long N) {
    string S = to_string(N);
    return (S[0]-'0');
}

int main() {
    long long N;
    cin >> N;
    int K = to_string(N).length();
    int c = tn(N);
    int mx = c + 9 * (K-1);
    if (nine(N)) { cout << mx << endl; return 0; }
    cout << mx-1 << endl;
    return 0;
}
    

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

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> C(6, vector<char>(6));
    vector<vector<char>> D(6, vector<char>(6));
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            cin >> C[i][j];
            D[i][j] = C[i][j];
        }
    }
    int ans = 0;
    for (int tmpi=0; tmpi<(1<<H); tmpi++) {
        bitset<6> si(tmpi);
        for (int tmpj=0; tmpj<(1<<W); tmpj++) {
            bitset<6> sj(tmpj);
            for (int i=0; i<H; i++) {
                for (int j=0; j<W; j++) {
                    D[i][j] = C[i][j];
                }
            }
            for (int i=0; i<H; i++) {
                if (si.test(i)) {
                    for (int j=0; j<W; j++) {
                      	D[i][j] = '.';
                    }
                }
            }
            for (int j=0; j<W; j++) {
                if (sj.test(j)) {
                    for (int i=0; i<H; i++) {
                      	D[i][j] = '.';
                    }
                }
            }
            int cnt = 0;
        	for (int i=0; i<H; i++) {
            	for (int j=0; j<W; j++) {
                	if (D[i][j] == '#') {
                    	cnt ++;
                    }
                }
            }
        	if (cnt == K) {
            	ans ++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    long long int a, b;
    cin >> a >> b;
    cout << 6 - a - b << 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++)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define MAX 500005

template<typename T>
struct SegTree {
  int n;
  vector<T> dat, lazy;
  SegTree(int _n) : n(), dat(_n*4,0), lazy(_n*4,0) {
    int x = 1;
    while (x < _n) x <<= 1;
    n = x;
  }

  void eval(int k, int p) {
    if (lazy[k] == 0) return;
    if (k < n-1) {
      lazy[k*2+1] += lazy[k];
      lazy[k*2+2] += lazy[k];
    }
    dat[k] += lazy[k] * p;
    lazy[k] = 0;
  }
  void update(int a, int b, int x, int k, int l, int r) {
    eval(k, r-l);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      lazy[k] += x;
      eval(k, r-l);
    } else {
      int mid = (l+r)>>1;
      update(a,b,x,k*2+1,l,mid);
      update(a,b,x,k*2+2,mid,r);
      dat[k] = dat[k*2+1] + dat[k*2+2];
    }
  }
  void update(int a, int b, int x) { update(a,b,x,0,0,n); }

  T query(int a, int b, int k, int l, int r) {
    eval(k, r-l);
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return dat[k];
    int mid = (l+r)>>1;
    T vl = query(a,b,k*2+1,l,mid);
    T vr = query(a,b,k*2+2,mid,r);
    return vl + vr;
  }
  T query(int a, int b) { return query(a,b,0,0,n); }
  inline T operator[](int a) { return query(a,a+1); }
};

int main(int, char**)
{
  int n, q;
  cin >> n >> q;

  SegTree<ll> seg(n);

  vector<ll> ans;
  rep(i,q) {
    int command; cin >> command;
    if (command == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      seg.update(s-1,t,x);
    } else if (command == 1) {
      int s, t; cin >> s >> t;
      ans.push_back(seg.query(s-1,t));
    }
  }
  for (auto a : ans) cout << a << endl;

  return 0;
}



Measured memory_bytes: 10008
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    vector<int> num(N);
    num[0] = 3;
    lint ans = 1;
    REP(i, N) {
        ans = (ans * num[A[i]]) % MOD;
        num[A[i]]--;
        num[A[i]+1]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#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) // ROF(i,n,0)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define SUM(a) accumulate(all(a), int(0))
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }

signed main() {
  string s;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] == '?')
      cout << 'D';
    else
      cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll sum = 0;
    for(ll i =1;i<=n;i++)
    {
        if(i%3 != 0 && i%5!=0)
            sum = sum + i;
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 3572
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
bool cmp(const P &a, const P &b)
{
	if (a.second < b.second) {
		return true;
	} else if (a.second == b.second) {
		return (a.first < b.first);
	} else {
		return false;
	}
}

// メイン
int main()
{
	// 入力
	int N, M;
	cin >> N >> M;
	vector<P> ab;
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		ab.push_back({a, b});
	}

	// 昇順
	sort(ab.begin(), ab.end(), cmp);

	// 区間スケジューリング
	int ans = 1;
	int pos = ab[0].second;
	REPN(i, 1, ab.size()) {
		if (pos <= ab[i].first) {
			pos = ab[i].second;
			ans++;
		}
	}

	// 結果
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2420
n = int(input())
last = [-1]*n
mod = 10**9 + 7
l = 10**6
fac = [1]*l
facr = [1]*l

for i in range(l-1):
    fac[i+1] = fac[i]*(i+1)%mod
facr[l-1] = pow(fac[l-1],mod - 2,mod)
for i in range(1,l)[::-1]:
    facr[i-1] = facr[i]*i%mod

def combi(N,K):
    if N < K:
        return 0
    return fac[N]*facr[N-K]%mod*facr[K]%mod



A = list(map(int,input().split()))

for i,a in enumerate(A):
    if last[a-1] == -1: last[a-1] = i
    else:
        dup = [last[a-1],i]
        m = last[a-1] + n - i
        break

pow2 = [1]*(n+2)
for i in range(n+1):
    pow2[i+1] = pow2[i]%mod

ans = [0]*(n+1)
for i in range(n+1):
    ans[i] = (combi(n+1,i+1) - combi(m,i))%mod
print("\n".join(str(i) for i in ans))


Measured memory_bytes: 108560
#include <iostream>
#include <vector>

int main(){
    int N, ans = 1;
    std::cin >> N;
    std::vector<int> H(N);
    for(auto i = 0; i < N; i++){
        std::cin >> H.at(i);
    }

    int max = H.at(0);
    for(auto i = 1; i < N; i++){
        if(max <= H.at(i)){
            ans++;
            max = H.at(i);
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256