akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(hoge) hoge.begin(),hoge.end()
const long long INF = 1LL << 60;


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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size() - 1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min + (max - min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n, vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());

}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n) {
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	int flag = 0;
	rep(i, n) {
		cin >> a[i];
		if (a[i] == k) {
			cout << "POSSIBLE";
			return 0;
		}
		else if (a[i] > k) {
			flag = 1;
		}
	}
	if (flag == 0) {
		cout << "IMPOSSIBLE";
		return 0;
	}
	ll g = a[0];
	
	for (int i = 1; i < n; i++) {
		g = gcd(g, a[i]);
	}
	if (k%g == 0) {
		cout << "POSSIBLE";
	}
	else {
		cout << "IMPOSSIBLE";
	}
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int sx,tx,sy,ty;
	scan(sx);scan(sy);scan(tx);scan(ty);
	int yoko=tx-sx,tate=ty-sy;
	rep(i,yoko) printf("R");
	rep(i,tate) printf("U");
	rep(i,yoko) printf("L");
	rep(i,tate) printf("D");
	printf("D");
	rep(i,yoko+1) printf("R");
	rep(i,tate+1) printf("U");
	printf("L");
	printf("U");
	rep(i,yoko+1) printf("L");
	rep(i,tate+1) printf("D");
	printf("R");
	kaigyo;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  int n;
  while(cin>>n,n){
    set<PI> app;
    rep(i,n){
      int x,y;
      cin>>x>>y;
      app.insert(mp(x,y));
    }
    int ans=0;
    FOR(iter,app){
      FOR(jter,app){
	int tx=iter->F-jter->F,ty=iter->S-jter->S;
	if(tx*tx+ty*ty<=ans)continue;
	if(app.count(mp(iter->F-ty,iter->S+tx)) &&
	   app.count(mp(jter->F-ty,jter->S+tx)))ans=tx*tx+ty*ty;
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1000
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
    for j in range(B+1):
        c = (X-500*i-100*j)//50
        if c >= 0 and c <= C:
            ans += 1

print(ans)

Measured memory_bytes: 3060
def solve():
    a, b, c, k = map(int, input().split())
    ans = 0
    if a <= k:
        ans += a
        k -= a
    else:
        ans += k
        k = 0
    if b <= k:
        k -= b
    else:
        k = 0
    if k > 0:
        ans -= k
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t a, b, x;
  int64_t ans = 0;
  cin >> a >> b >> x;
  
  if(a == 0) ans = b / x + 1;
  else ans = b/x - (a-1)/x;
  
  cout << ans << endl;
  return 0;
}

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

int main(){
    int a,b,c,res = 0, cnt = 0;
    vector<int> vec(10);
    string S;
    cin >> a >> b >> c;
    if(a - b >= c) cout << 0 << endl;
    else cout << c - (a-b) << endl;
    return 0;
}

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

int main()
{
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    vector<int> C = {R, G, B};
    sort(C.begin(), C.end(), greater<int>());

    int ans = 0;
    for(int i = N; i >= 0; i--)
    {
        int c1 = C.at(0) * i;
        if(c1 > N)    continue;

        for(int j = N; j >= 0; j--)
        {
            int c2 = C.at(1) * j;
            if(c1 + c2 > N)    continue;

            int c3 = N - c1 - c2;
            if(c3 % C.at(2) == 0)   ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    m: usize,
    ab: [[usize; 2]; m]
    }
    let mut l = vec![Default::default(); n + 1];
    l[1] = 1;
    let mut g = vec![vec![]; n + 1];
    for i in ab {
        g[i[0]].push(i[1]);
        g[i[1]].push(i[0]);
    }
    bfs(1, &g, &mut l);
    if l[1..].contains(&0){
        println!("No");
        return
    }
    println!("Yes");
    for &i in &l[2..]{
        println!("{}", i);
    }
}

// O(n+m)
fn bfs (r: usize, g: &Vec<Vec<usize>>, l: &mut Vec<usize>) {
    let mut que = std::collections::VecDeque::new();
    que.push_back(r);
    while !que.is_empty() {
        let v = que.pop_front().unwrap();
        for &nv in &g[v] {
            if l[nv] != 0 {
                continue;
            }
            l[nv] = v;
            que.push_back(nv);
        }
    }
}



Measured memory_bytes: 19140
n=int(input())
s=list(map(int,input().split()))
q=int(input())
t=list(map(int,input().split()))

def bin(a):
    ok=n-1#okのところは範囲に含める必要がある
    ng=-1#ngは範囲外に置く

    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if s[mid]>=a:
            ok=mid
        else:
            ng=mid
    if s[ok]==a:return 1
    else:return 0

ans=0
for i in t:
    ans+=bin(i)
print(ans)


Measured memory_bytes: 16712
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		System.out.println(((a + b) * h / 2));
	}
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        int n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

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

int dfs(int a,int n,int s) {
    if (n==0) {
        if (s==0)
            return 1;
        return 0;
    }
    if (s<0)
        return 0;
    int cnt=0;
    for (int i=a;i<=9;i++) {
        cnt+=dfs(i+1,n-1,s-i);
    }
    return cnt;
}

int main() {
    while (1) {
        int n,s;
        cin>>n>>s;
        if (n==0&&s==0)
            break;
        cout<<dfs(0,n,s)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>

#define ll long long

using namespace std;

inline int read() {
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}

int a[105];

int main() {
	int n=read();
	int ans=1e9;
	for (int i=1;i<=n;i++) {
		a[i]=read();
	}
	for (int i=1;i<=100;i++) {
		int tot=0;
		for (int j=1;j<=n;j++) {
			tot+=(a[j]-i)*(a[j]-i);
		}
		if (tot<ans) {
			ans=tot;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double db;

const db inf = 1e18;
const db pi = acos(-1);
const db eps = 1e-9;
const int mod = 998244353;

int main () {
	#ifdef ernestico
		freopen ("a.in", "r", stdin );
//		freopen ("a.out", "w", stdout );
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	ll n; cin >> n;
	int cont = 0;
	for ( int i = 2; 1ll*i*i <= n; i ++ ) {
		int e = 0;
		while ( n%i == 0 ) {
			n /= i;
			e ++;
		}
		for ( int j = 1; j <= e; j ++ ) {
			cont ++;
			e -= j;
		}

	}
	cont += ( n > 1 );
	cout << cont << endl;


	return 0;
}


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

vector<int> to[200005];
vector<int> ans;

void dfs (int v, int p=-1) {

    for (int u : to[v]) {
        if (u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main () {

    int N, Q;
    scanf("%d %d", &N, &Q);

    for (int i = 0; i < N-1; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    ans.resize(N);
    for (int i = 0; i < Q; i++) {
        int p, x;
        scanf("%d %d", &p, &x);
        p--;

        ans[p] += x;
    }

    dfs(0);

    for (int i = 0; i < N; i++) {
        printf("%d\n", ans[i]);
    }

    return 0;
}

Measured memory_bytes: 23424
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;
typedef pair<string, string> pss;

struct union_find
{
	vector<int> rnk, par;

	union_find() {}
	union_find(int n) {
		rnk.assign(n, 1);
		par.assign(n, 0);
		for (int i = 0; i < n; i++) par[i] = i;
	}

	int find(int x) {
		if (x == par[x]) return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (rnk[x] > rnk[y]) par[y] = x;
		else {
			par[x] = y;
			if (rnk[x] == rnk[y]) rnk[y]++;
		}
	}
	bool same(int x, int y) {
		x = find(x); y = find(y);
		return x == y;
	}
};


map<string, int> id;
int n, m,x[5010];

int main()
{
	string a, b;
	int y;
	cin >> n;
	rep(i, n) {
		cin >> a >> y;
		x[id[a] = i] = y;
	}
	union_find uf(n);
	cin >> m;
	rep(i, m) {
		cin >> a >> b;
		uf.unite(id[a],id[b]);
	}

	rep(i, n) x[uf.find(i)] = min(x[uf.find(i)], x[i]);
	int ans = 0;
	rep(i, n)ans += x[uf.find(i)];

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

Measured memory_bytes: 3780
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int A[200000];

int main()
{
	int N, K, s, cnt = 1, ans = 0;
	priority_queue<int, vector<int>, greater<int> > PQ;

	cin >> N >> K;
	rep(i, N) cin >> A[i];

	sort(A, A + N);

	rep(i, N - 1) {
		if (A[i + 1] == A[i]) {
			cnt++;
		}
		else {
			PQ.push(cnt);
			cnt = 1;
		}
		if (i + 1 == N - 1) PQ.push(cnt);
	}

	s = PQ.size();
	rep(i, s - K) {
		ans += PQ.top();
		PQ.pop();
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2168
var i,j,n,c:Longint;s,t:String;
begin
	readln(s);
	readln(t);
	n:=length(s);
	for i:=0 to n-1 do begin
		c:=0;
		for j:=1 to n do begin
			if s[j] = t[(i+j-1)mod n+1] then inc(c);
		end;
		if c=n then begin
			writeln('Yes');
			exit;
		end;
	end;
	writeln('No');
end.


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    scanf("%lld", &N);
    vector<ll> L(N);
    REP(int, i, 0, N) scanf("%lld", &L.at(i));
    sort(L.begin(),L.end());
    ans = 0;
    REP(int, i, 0, N-2){
        REP(int, j, i+1, N-1){
            REP(int, k, j+1, N){
                //cout << i << j << k << endl;
                if ( L.at(i) + L.at(j) > L.at(k) ){
                    ans++;
                }
                else{
                    break;
                }
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

queue<ll> que;

void start(){
    rep1eq(i,1,9){
        que.push(i);
    }
}

ll bfs(int m){
    int i=9;
    ll ans;
    while(i<=m){
        ll x = que.front(); que.pop();
        if(x%10 != 0){
            que.push(10*x + (x%10-1));
            i++;
            if(i==m){
                ans = 10*x + (x%10-1);
                break;
            }
        } 
        que.push(10*x + x%10);
        i++;
        if(i==m){
            ans = 10*x + x%10;
            break;
        }
        if(x%10 != 9){
            que.push(10*x + (x%10+1));
            i++;
            if(i==m){
                ans = 10*x + (x%10+1);
                break;
            }
        }  
    }

    return ans;
}


int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int k;
    cin >> k;
    ll a;
    
    if(k<=9){
        cout << k << endl;
        return 0;
    }

    start();
    a = bfs(k);

    cout << a << endl;
    return 0;

}

Measured memory_bytes: 768
use std::io::Read;
use std::collections::HashMap;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr;
}

impl<'a> Parse for std::str::SplitWhitespace<'a> {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn make_map(chars: &Vec<char>) -> HashMap<char, Vec<usize>> {
    let mut map = HashMap::new();
    for a in "abcdefghijklmnopqrstuvwxyz".chars() {
        map.insert(a, Vec::new());
    }

    for (i, c) in chars.iter().enumerate() {
        if let Some(v) = map.get_mut(c) {
            v.push(i);
        }
    }
    map
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let s = iter.to::<String>().chars().collect::<Vec<_>>();
    let t = iter.to::<String>().chars().collect::<Vec<_>>();
    let sm = make_map(&s);
    for indices in sm.values() {
        if indices.is_empty() {
            continue;
        }
        let first = t[indices[0]];
        if indices.iter().any(|&i| t[i] != first) {
            println!("No");
            return;
        }
    }

    let tm = make_map(&t);
    for indices in tm.values() {
        if indices.is_empty() {
            continue;
        }
        let first = s[indices[0]];
        if indices.iter().any(|&i| s[i] != first) {
            println!("No");
            return;
        }
    }

    println!("Yes");
}

Measured memory_bytes: 14588
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
void bubbleSort(vector<int> A, int N)
{
  int flag = 1;
  int times = 0;
  while (flag)
  {
    flag = 0;
    int j = 0;
    for (int i = N - 1; i >= j + 1; i--)
    {
      if (A[i] < A[i - 1])
      {
        swap(A[i], A[i - 1]);
        flag = 1;
        times++;
      }
    }
    j++;
  }

  rep(i, N)
  {
    if (i == N - 1)
    {
      cout << A[i];
    }
    else
    {
      cout << A[i] << " ";
    }
  }
  cout << "\n";
  cout << times << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N)
  {
    cin >> A[i];
  }
  bubbleSort(A, N);
  return 0;
}


Measured memory_bytes: 3160
n = gets.to_i
flag = false

if n > 81
  puts 'No'
else
  9.times do |i|
    i += 1
    s = n / i
    m = n % i
    if m == 0 and s < 10
      flag = true
      break
    end
  end
  if flag
    puts 'Yes'
  else
    puts 'No'
  end
end


Measured memory_bytes: 1788
N=input()
L=[]

for c in N:
    L.append(int(c))

bb=16
b=bin(bb)
for i in range(16):
    b=bin(bb)
    B=str(b)
    n=L[0]
    for p in range(1,4):
        n+=2*(int(B[-1*p])*L[p])
        n-=L[p]
    if n==7:
        break
    bb+=1
    #print(n,B)


def plmi(n):
    if n=="1":
        return "+"
    else:
        return "-"

ans=""

ans+=N[0]
ans+=plmi(B[-1])
ans+=N[1]
ans+=plmi(B[-2])
ans+=N[2]
ans+=plmi(B[-3])
ans+=N[3]
ans+="=7"

print(ans)

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

int main(){
    string s;
    cin >> s;
    string ans = "";
    for(auto c : s){
        if(c == 'B'){
            if(ans.size()) ans.erase(--ans.end());
        } else {
            ans += c;
        }
    }
    cout << ans << endl;
    return 0;
}


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

bool check(string s);

int main() {
    long n, t = 0;
    cin >> n;
    vector<long> num(n);
    rep(i, n) cin >> num.at(i);
    map<long, long> mp;
    rep(i, n) mp[num.at(i)]++;
    for(pair<long, long> p : mp) {
        t += p.second * (p.second - 1) / 2;
    }
    rep(i, n) {
        long temp = mp[num.at(i)];
        temp = t - temp * (temp - 1) / 2 + (temp - 1) * (temp - 2) / 2;
        cout << temp << endl;
    }
}

Measured memory_bytes: 12288
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#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 DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 5e5 + 5;

ll mod = 1e9 + 7, n, m, fact[MAXN], inv[MAXN], ans = 0;

ll power(ll a, ll b)
{
	ll ans = 1;
	while(b > 0)
	{
		if(b & 1ll) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1ll;
	}
	return ans;
}

ll nPr(ll n, ll r)
{
	return (fact[n] * inv[n - r]) % mod;
}

ll nCr(ll n, ll r)
{
	return (nPr(n, r) * inv[r]) % mod;
}

int main()
{
	FAST_IO;

    cin >> n >> m;
    fact[0] = inv[0] = 1;
    for(ll i=1;i<MAXN;i++) 
    {	
    	fact[i] = (fact[i - 1] * i) % mod;
   		inv[i] = power(fact[i], mod - 2);
   	} 
   	for(int i=0;i<=n;i++)
   	{
   		ll temp = (nCr(n, i) * nPr(m, i)) % mod;
   		temp = (temp * nPr(m - i, n - i)) % mod; 
   		temp = (temp * nPr(m - i, n - i)) % mod;
   		if(i % 2 == 1) temp = ((temp * -1) % mod + mod) % mod; 
   		ans = (ans + temp) % mod;
   	}
   	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11456
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int s[999]; s[0] = 1;
  for (int i=1; i<999; i++) s[i] = s[i-1] + i+1;
  printf("%d\n", s[b-a-1] - b);
  return 0;
}


Measured memory_bytes: 128
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a,b,c=map(int,input().split())
if 0<= c-a <=b:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <cstdlib>
#include <cctype>
#include <cstdio>
#include <cstring>

using namespace std;

int str2arr(char s[], string A[]) {
    bool flag = true;
    string t;
    int l = strlen(s);
    int n = 0;
    for (int i = 0; i < l; i++) {
        if (isdigit(s[i]) && flag) {
            t = "";
            int j = 0;
            while (isdigit(s[i+j])) {
                t += s[i+j];
                if (i+j == l-1)
                    break;
                j++;
            }
            A[n++] = t;
            flag = false;
        }
        else if (!isdigit(s[i])) {
            A[n++] = s[i];
            flag = true;
        }
    }
    return n;
}

int Generate_RPN(int n, string A[], string B[]) {
    map<string, int> table;
    table["*"] = 1;
    table["/"] = 1;
    table["+"] = 0;
    table["-"] = 0;
    table["("] = -1;
    table[")"] = -1;
    stack<string> S;
    int j = 0;

    for (int i = 0; i < n; i++) {
        if (isdigit(A[i][0])) {
            B[j++] = A[i];
        }

        else if (A[i] == "(")
            S.push(A[i]);

        else if (A[i] == ")") {
            while (S.top() != "(") {
                B[j++] = S.top();
                S.pop();
            }
            S.pop();
        }
        else {
            while ((!S.empty()) && (table[S.top()] >= table[A[i]])) {
                B[j++] = S.top();
                S.pop();
            }
            S.push(A[i]);
        }
    }
    while (!S.empty()) {
        B[j++] = S.top();
        S.pop();
    }
    return j;
}

int Calculate_RPN(int n, string s[]) {
    stack<double> St;
    double a, b;

    for (int i = 0; i < n; i++) {
        if (s[i] == "+") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a+b);
        }
        else if (s[i] == "-") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a-b);
        }
        else if (s[i] == "*") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a*b);
        }
        else if (s[i] == "/") {
            b = int(St.top()); St.pop();
            a = St.top(); St.pop();
            St.push(a/b);
        }
        else {
            St.push(atoi(s[i].c_str()));
        }
    }
    return int(St.top());
}

int main()
{
    int n, l, t;
    string A[101], B[101];
    char s[101];

    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%s", s);
        s[strlen(s)-1] = '\0';

        l = str2arr(s, A);
        t = Generate_RPN(l, A, B);

        cout << Calculate_RPN(t, B) << endl;
    }

    return 0;
}

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

#define fast ios::sync_with_stdio(false); cin.tie(0)
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define pre(a) cout<<fixed; cout.precision(a);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF = 1e18;
const int inf = 1e9;

int main() {
	fast;

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

	int ans = 0;
	for(int i=0; i<n; i++) {
		int h;
		cin >> h;
		if(h >= k) ans++;
	}	

	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
typedef long long ll;
cs int N = 1e5 + 50;
int n; ll x[N], p[N], S; 
ll work(int l, int r, int tr){
	if(x[l]<S&&S<x[r]){
		if(p[l]>=p[r]) return p[l]+=p[r], work(l,r-1,l)+(tr==r?x[r]-x[l]:0);
		else return p[r]+=p[l], work(l+1,r,r)+(tr==l?x[r]-x[l]:0);
	} return max(S-x[l],x[r]-S);
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d%d",&n,&S);
	for(int i=1; i<=n; i++) 
	scanf("%d%d",&x[i],&p[i]);
	cout<<work(1,n,p[1]<p[n]?1:n); return 0;
}

Measured memory_bytes: 5632
#include<stdio.h>

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

    if(n>2){
    for(i=3;i<=n;i++)
    {
        printf("%d\n",n/i);
        break;
    }
    }
    else
    {
        printf("0\n");
    }

    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long

int main() {
  int n;
  cin>>n;
  int a[n];
  int s1 = 0;
  int s2 = 0;
  for(int i = 0;i<n;i++){
      cin>>a[i];
      s2 += a[i];
  }
  int ans = INT_MAX;
  for(int i = 0;i<n;i++){
      s1 += a[i];
      s2 -= a[i];
      if(abs(s1-s2) < ans){
          ans = abs(s1-s2);
      }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read
MOD = 10**9 + 7

n = int(input())
a = np.array(readline().split(), dtype=np.uint64)
r = np.cumsum(a[::-1])[::-1]
r %= MOD
x = a[:-1] * r[1:]
x %= MOD
ans = np.sum(x) % MOD
print(int(ans))

Measured memory_bytes: 52772
using System;

namespace ITP1_5_D
{
    class Program
    {
        static void Main()
        {
            int x = int.Parse(Console.ReadLine());
            
            for (int i = 3; i <= x; i ++)
            {
                if (i % 3 == 0 || i % 10 == 3 || i % 100 / 10 == 3 || i % 1000 / 100 == 3 || i % 10000 / 1000 == 3)
                {
                    Console.Write(" " + i);
                }
                else continue;
            }
            Console.WriteLine();
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 15940
#include <bits/stdc++.h>
using namespace std;
int main(){
 int X;
 cin>>X;
 double ans=1;
 for(int i=1;i<=X;i++){
   for(int j=2;j<=X;j++){
    // ans*=i;
    if(max(ans,pow(i,j))<=X){ans=max(ans,pow(i,j));}
    else{break;}
   }
 }
 cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
dic = {}
for i in range(N):
    dic[i] = A[i]
dic = sorted(dic.items(), key=lambda x: x[1])
# print(dic)
# print(list(zip(*dic)))
dic = list(zip(*dic))
# dic = list(map(lambda x: x+1, dic))
ans = [dic[0][i] + 1 for i in range(N)]
ans = str(ans).replace(',', '')
ans = ans.replace('[', '')
ans = ans.replace(']', '')
print(ans)

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


int main(){
    int m,n_min,n_max;

    while(cin>>m>>n_min>>n_max,m){
        vector<int> V(m);
        for(int i=0;i<m;i++) cin>>V[i];
        sort(V.begin(), V.end(),greater<int>());
        int ans=-1;
        int gap=0;
        for(int i=n_min-1;i<n_max;i++){
            if(V[i+1]==V[i]) continue;
            if(V[i]-V[i+1]>=gap){
                gap=V[i]-V[i+1];
                ans=i+1;
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 3160
#include<iostream>
#include<cstdlib>
#include<cstdio>

#define N 100001
#define NIL -1
using namespace std;

//array
int parent[N];
int leftc[N];
int rightc[N];

int degree[N];
int depth[N];



int main(){

  int n,i,j,id,child,bef;
  int flag=0;
   //initialize
  for(i=0;i<N;i++){
    parent[i]=NIL;
    leftc[i]=NIL;
    rightc[i]=NIL;
    degree[i]=0;
    depth[i]=0;
  }

  //load n
  scanf("%d",&n);

  //load data set parent, left child and 
  for(i=0;i<n;i++){
    scanf("%d %d",&id,&degree[i]);


    for(j=0;j<degree[i];j++){
      scanf("%d",&child);
  
      parent[child]=id;  
    
      if(j==0){
	leftc[id]=child;
      }
      else{
	rightc[bef]=child;
      }
      //bef is before node
      bef=child;
    }
  }

  //test
  // for(i=0;i<n;i++)printf("%d parent: %d leftchild: %d right child: %d\n",i,parent[i],leftc[i],rightc[i]);

  
  //calc depth

  for(i=0;i<n;i++){
    for(j=parent[i];j!=NIL;j=parent[j]){
      depth[i]++;
    }

  }
  

  
  
  //print
  for(i=0;i<n;i++){



    printf("node %d: parent = %d, depth = %d, ",i,parent[i],depth[i]);

    if(parent[i]==NIL)printf("root, ");
    else if(leftc[i]==NIL) printf("leaf, ");
    else printf("internal node, ");
   
    printf("[");
    for(j=leftc[i];j!=NIL;j=rightc[j]){
      printf("%d",j);
      if(rightc[j]!=NIL)printf(", ");
    }
    printf("]");

    printf("\n");
  }
  
  
  return 0;
}

//problem A is most difficult.

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

int main(void){
    int n; cin >> n;
    ll neg_cnt = 0;
    vector<ll> a;
    for(int i=0;i<n;i++){
        ll tmp; cin >> tmp;
        if(tmp < 0) neg_cnt++;
        a.push_back(abs(tmp));
    }
    sort(a.begin(),a.end());

    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += a[i];
    }

    // ll ans = accumulate(a.begin(),a.end(),0);
    if(int(neg_cnt)%2!=0) ans -= 2*a[0];
    cout << ans << endl;
    return 0;
}

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

int main(){
  int a,b;
  cin >> a>>b;
  long long c=1;
  c*=a;
  c*=b;
  if(c<=0){
    cout << "Zero" << endl;
  }
  else if(a>0&&b>0){
    cout << "Positive" << endl;
  }
  else if((b-a)%2==0){
    cout << "Negative" << endl;
  }
  else{
    cout << "Positive" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(){
  int a;
   int b;
  int c;
 // int d;
 // int e;
 // int f;
  cin>>a>>b>>c ;
   if (a<b&&b<c){ cout<<"Yes"<<endl;
   }
   else  { cout<<"No"<<endl;}
 return 0;
}
 



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL
using namespace std;

lli ar[105][5];
lli dp[100005];


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n,w;
    cin >> n >> w ;

    lli sum=0;
    for(int i=1; i<=n; i++)
    {
        cin >> ar[i][1] >> ar[i][2];
    }

   for(int i=1;i<=n;i++)
   {
       for(int j=w-ar[i][1];j>=0;j--)
       {
           dp[j+ar[i][1]] = max(dp[j+ar[i][1]],ar[i][2]+dp[j]);
       }
   }

   lli ans =0;
   for(int i=0;i<=w;i++)
   {
       ans = max(ans,dp[i]);
   }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int dfs(int now, vector<bool> c, vector<vector<int>> G) {
  c[now] = true;
  int cnt_next = 0;
  int sum = 0;
  for (int next : G[now]) {
    if (c[next])
      continue;
    sum += dfs(next, c, G);
    cnt_next++;
  }
  if (cnt_next == 0) {
    bool ok = true;
    for (bool b : c) {
      if (b == false)
        ok = false;
    }
    if (ok)
      return 1;
    else
      return 0;
  }
  return sum;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  vector<vector<int>> G(N);

  rep(i, M) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    G[a[i]].pb(b[i]);
    G[b[i]].pb(a[i]);
  }

  vector<bool> c(N, false);
  cout << dfs(0, c, G) << endl;
}

Measured memory_bytes: 256
fun abc123c(args: Array<String>) {
    val N = args[0].toLong()
    val min = args.drop(1).map { it.toLong() }.min()!!
    val cnt = Math.ceil(N.toDouble() / min.toDouble()).toLong()
    println(cnt + 4)
}

fun main(args: Array<String>) {
    abc123c(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 37928
#include <iostream>
static void e(int *a) {
    int t = a[1];
    a[1] = a[4];
    a[4] = a[6];
    a[6] = a[3];
    a[3] = t;
}
static void n(int *a) {
    int t = a[1];
    a[1] = a[2];
    a[2] = a[6];
    a[6] = a[5];
    a[5] = t;
}
static void s(int *a) {
    int t = a[1];
    a[1] = a[5];
    a[5] = a[6];
    a[6] = a[2];
    a[2] = t;
}
static void w(int *a) {
    int t = a[1];
    a[1] = a[3];
    a[3] = a[6];
    a[6] = a[4];
    a[4] = t;
}
static bool check(int *a, int *b) {
    bool f = false;
    for (int i = 0; i < 4 && !f; ++i) {
        s(b);
        for (int j = 0; j < 4 && !f; ++j) {
            w(b);
            for (int k = 0; k < 4 && !f; ++k) {
                s(b);
                e(b);
                n(b);
                f = true;
                for (int x = 1; x <= 6; ++x) {
                    if (a[x] != b[x]) {
                        f = false;
                        break;
                    }
                }
            }
        }
    }
    return f;
}
int main() {
    int a[101][7], n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= 6; ++j) {
            std::cin >> a[i][j];
        }
    }
    bool f = false;
    for (int i = 0; i < n && !f; ++i) {
        for (int j = i + 1; j < n && !f; ++j) {
            f = check(a[i], a[j]);
        }
    }
    std::cout << (f ? "No" : "Yes") << std::endl;
}



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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];
  ll ans = 0;
  ll cnt = 0;
  rep(i, 0, N) {
    cnt += A[i];
    if(A[i] == 0 || i == N - 1) {
      ans += cnt / 2;
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define SWAP(a,b) (a+=b,b=a-b,a-=b)
const int MOD = 1000000007;

int main(void){
  int N,tmp=0,arg;

  scanf("%d",&N);

  for(int i=1; i<=N; i++){
    scanf("%d",&arg);
    if(arg!=i){
      tmp++;
    }
  }

  if(tmp<=2){
    printf("YES");
  }else{
    printf("NO");
  }


}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    vector<ll> color(3,0); //[0] [1] [2]
    ll ans=3;
    if(A[0]!=0){
        cout<<0<<endl;
        return 0;
    }
    color[0]++;
    rep1(i,N-1){
        ll cnt=0;
        rep(j,3){
            if(color[j]==A[i]) cnt++;
        }
        rep(j,3){
            if(color[j]==A[i]){
                color[j]++;
                break;
            }
        }
        ans*=cnt;
        ans%=MOD;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4048
import typing


class DSU:
    '''
    Implement (union by size) + (path compression)
    Reference:
    Zvi Galil and Giuseppe F. Italiano,
    Data structures and algorithms for disjoint set union problems
    '''

    def __init__(self, n: int = 0):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        x = self.leader(a)
        y = self.leader(b)

        if x == y:
            return x

        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x

        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x

        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n

        while self.parent_or_size[a] >= 0:
            a = self.parent_or_size[a]

        return a

    def size(self, a: int) -> int:
        assert 0 <= a < self._n

        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> typing.List[typing.List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]

        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)

        return list(filter(lambda r: r, result))


import sys
input = sys.stdin.readline
n, q = map(int, input().split())
uf = DSU(n)
res = []
for i in range(q):
    t, u, v = map(int, input().split())
    if t:
        res.append(int(uf.same(u, v)))
    else:
        uf.merge(u, v)
print("\n".join(map(str, res)))


Measured memory_bytes: 87840
g1 = [4,6,9,11]
g2 = [2]
g3 = [1,3,5,7,8,10,12]

x,y = map(int,input().split())

if x in g1 and y in g1:
    print("Yes")
    exit()

if x == y == 2:
    print("Yes")
    exit()

if x in g3 and y in g3:
    print("Yes")
    exit()

print("No")    

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    vector<int> idx[10];
    REP(i,N){
        idx[S[i]-'0'].push_back(i);
    }

    REP(i,10) REP(j,10) REP(k,10){
        auto itr = lower_bound(idx[i].begin(), idx[i].end(), 0);
        if(itr == idx[i].end()) continue;
        auto itr2 = lower_bound(idx[j].begin(), idx[j].end(), *itr + 1);
        if(itr2 == idx[j].end()) continue;
        auto itr3 = lower_bound(idx[k].begin(), idx[k].end(), *itr2 + 1);
        if(itr3 == idx[k].end()) continue;
        ans++;
    }
    cout << ans << endl;
}


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

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

using namespace std;

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

  int a, b, c; cin >> a >> b >> c;
  cout << c << ' ' << a << ' ' <<b << endl;
}


Measured memory_bytes: 256
/*
 *    author:  Gary Shih
 *    created: 2020-05-03 22:16:20
 */
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(3));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j) cin >> a[i][j];
  vector<vector<int>> dp(n, vector<int>(3));
  dp[0][0] = a[0][0];
  dp[0][1] = a[0][1];
  dp[0][2] = a[0][2];
  for (int i = 1; i < n; ++i) {
    dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
    dp[i][2] = a[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
  }
  cout << *max_element(dp.back().begin(), dp.back().end()) << '\n';
}


Measured memory_bytes: 11264
from queue import deque

k = int(input())
que = deque()
for i in range(1,10):
    que.append(i)

for i in range(k):
    if i == (k-1):
        print(que.popleft())
        exit()
    now = que.popleft()
    if now%10 != 0:
        que.append(now*10+now%10-1)
    que.append(now*10+now%10)
    if now%10 != 9:
        que.append(now*10+now%10+1)

Measured memory_bytes: 18884
import java.util.Scanner;

class Main{
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        System.out.println((int)a * b / 2);
        scanner.close();
    }
}

Measured memory_bytes: 23124
S=gets.chomp
K=gets.to_i

if S.chars.uniq.length == 1
    puts S.length*K/2
    exit 0
end

pc = nil
cnt = 0
a = []
S.each_char do |c|
    if pc == c
        cnt += 1
    else
        a << [pc,cnt]
        pc = c
        cnt = 1
    end
end
a << [pc,cnt]
a.shift

if a[0][0] == a[-1][0]
    ret = 0
    a[1..-2].each do |c,cnt|
        ret += cnt/2 * K
    end
    ret += (a[0][1]+a[-1][1])/2*(K-1)
    ret += a[0][1]/2
    ret += a[-1][1]/2
    puts ret
else
    ret = 0
    a.each do |c,cnt|
        ret += cnt/2 * K
    end
    puts ret
end


Measured memory_bytes: 1788