akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int d,t,s; cin >> d >> t >> s;
  
  if(d<=t*s) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main(){	
	int N,K;
	cin >> N >> K;
	vector<int64_t> A(N);
	vector<int64_t> R(N);
	for (int i=0; i<N; i++){
		cin >> A.at(i);
	}
	for (int i=0; i<N; i++){
		if (i <= K-1){
		}
		else {
			if (A.at(i) > A.at(i-K)){
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}	
	}
}

Measured memory_bytes: 6324
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		List<Double> list = new ArrayList<Double>();
		while (in.hasNext())
			list.add(in.nextDouble());
		Double[] arr = list.toArray(new Double[list.size()]);
		Arrays.sort(arr);
		System.out.println(arr[arr.length - 1] - arr[0]);
	}
}

Measured memory_bytes: 18680
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        if(n>9 && n<100){
            n = n%10;
        }else if(n>99){
            n = n%100;
            n = n%10;
        }
        
        if(n==3){
            System.out.println("bon");
        }else if(n==0 || n==1 || n==6 || n==8){
            System.out.println("pon");
        }else{
            System.out.println("hon");
        }
        
   }
}


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

int main(){
    string S; cin >> S;
    int N = S.size();
    int ans = 0;
    for(int i = 0; i < N;++i){
        if(S[i] != S[N-1-i]) ans++;
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
const ll MOD = (1e+9)+7;
typedef pair<ll, ll> LP;
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1);
}
 
int main()
{
  int a,b;
  cin >> a >> b;
  if(a%b==0)printf("0");
  else printf("1");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

void insertSort(int*, int);
int main() {
    int insertNumber,i;
    int* Array;

    scanf("%d", &insertNumber);
    Array = malloc(sizeof(int) * insertNumber);
    if (Array == NULL) {
    	printf("Array is NULL.");
    }

    for(i = 0 ; i<insertNumber; i++) {
    	scanf("%d",Array + i);
    }
    for(i=0; i<insertNumber; i++) {
      if(i==insertNumber-1){
        printf("%d", *(Array+i));
      }
      else {
        printf("%d ", *(Array+i));
      }
    }
    printf("\n");
    insertSort(Array, insertNumber);
    return 0;
}

void insertSort(int* Array,int insertNumber) {
    int i,j,k,compareNumber;

    for(i = 1; i<insertNumber; i++){
    	compareNumber = *(Array + i);
	    j = i - 1;
	    while(j >= 0 && *(Array + j)>compareNumber ) {
	       *(Array+j+1) = *(Array + j);
	       j--;
	    }
	    *(Array + j +1) = compareNumber;

      for(k=0;k<insertNumber; k++) {
      	if( insertNumber-1==k ) {
  	    printf("%d",*(Array+k));
      	}
  	    else {
  	       printf("%d ", *(Array+k));
  	    }
      }
      printf("\n");
    }
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<a<<endl
#define debug2(a,b) cout<<a<<" "<<b<<endl
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define debug4(a) cout<<"chu "<<a<<endl
#define sz(a) (ll)(a.size())
#define endl "\n"

vector <ll> adj[100005];
ll dp[100005][2];

ll dfs(ll s,ll p){
  dp[s][1]=dp[s][0]=1;
  for(auto it:adj[s]){
    if(it!=p){
      dfs(it,s);
      dp[s][1]=(dp[s][1]*((dp[it][1]+dp[it][0])%mod))%mod;
      dp[s][0]=(dp[s][0]*dp[it][1])%mod;
    }
  }
}

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n,x,y;
  cin>>n;
  forn(i,0,n-1){
    cin>>x>>y;
    adj[x].pb(y);
    adj[y].pb(x);
  }
  dfs(1,-1);
  /*forn(i,1,n+1){
    cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
  }*/
  ll ans=(dp[1][0]+dp[1][1])%mod;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 14208
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, b, ans = 0; cin >> n >> a;
	for (int h = 0; h < n; h++) {
		cin >> b;
		if (b >= a) {
			ans++;
		}
	}
	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
int prime(ll a){
  if(a==2){
    return 1;
  }else if(a%2==0 || a==1){
    return 0;
  }
  for(ll i=3;i*i<=a;i+=2){
    if(a%i==0)
      return 0;
  }
  return 1;
}
int main(){
  ll A,B,ans=1;
  cin>>A>>B;
  ll a=A,b=B;
  ll count=0;
  ll c=-1,d=-1;
  ll sqrtA=sqrt(a);
  ll sqrtB=sqrt(b);
  unordered_map<ll,ll> mp;
  unordered_map<ll,ll> mp2;
  for(ll i=1;i*i<=a;i++){
    while(A%i==0 && A>1 && prime(i)==1){
      A/=i;
      mp[i]++;
      if(A==1){break;}
    }
    if(a%i==0 && prime(a/i)==1 && A%(a/i)==0){
      c=a/i;
      break;
    }
  }
  for(ll i=1;i*i<=b;i++){
    while(B%i==0 && B>1 && prime(i)==1){
      B/=i;
      mp2[i]++;
      if(B==1){break;}
    }
    if(b%i==0 && prime(b/i)==1 && B%(b/i)==0){
      d=b/i;
      break;
    }
  }
  for(ll i=2;i<=(ll)min(sqrtA,sqrtB);i++){
    if(mp[i]>0 && mp2[i]>0){
      ans++;
    }
  }
  if(c>=0 && b%c==0){ans++;cout<<ans<<endl;return 0;}
  if(d>=0 && a%d==0){ans++;cout<<ans<<endl;return 0;}
  cout<<ans<<endl;
}

Measured memory_bytes: 39696
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long a = scan.nextInt();
		long b = scan.nextInt();

		System.out.println((a * b) / gcd(a , b));

	}
	public static long gcd(long a , long b) {
		if(b == 0) {
			return a;
		}

		return gcd(b , a % b);
	}
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#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)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{
    long double n;
    cin >> n;
    lint ans=0;
    lint now = 100;

    while(true){
        ans++;
        now = now * 1.01;
        if(now>=n){
            cout << ans << "\n";
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3728
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

ll N,K;
string S;
int main(){
  cin >>N>>K>> S;
  char x=S[K-1];
  if (x=='A')S[K-1]='a';
  if (x=='B')S[K-1]='b';
  if (x=='C')S[K-1]='c';
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 888
s=input()
ans = 0
if s == "SUN":
  ans = 7
elif s == "MON":
  ans = 6
elif s == "TUE":
  ans = 5
elif s =="WED":
  ans = 4
elif s == "THU":
  ans = 3
elif s == "FRI":
  ans = 2
else:
  ans = 1

print(ans)

Measured memory_bytes: 2940
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int B = scan.nextInt();

		if ((A * B) % 2 == 0){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}

	}
}

Measured memory_bytes: 21204
import java.util.ArrayList;
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		calc();
	}

	public static void calc() {
		Scanner sc;
		sc = new Scanner(System.in);
		while(true) {
			int N = sc.nextInt();
			if(N==0)	break;
			int [][] p = new int[N][N];
			for(int i=0; i<N; i++) {
				int M = sc.nextInt();
				for(int j=0; j<M; j++) {
					p[i][sc.nextInt()-1] = 1;
				}
			}
			
			int K = sc.nextInt();
			int[] L = new int [K];
			for(int i=0; i<K; i++) {
				L[i] = sc.nextInt();
			}
			
			//solve
			int num = 0;
			int index = -1;
			for(int i=0; i<N; i++) {
				int cnt = 0;
				for(int j=0; j<K; j++) {
					if(p[i][L[j]-1] == 1) {
						cnt++;
					}
				}
				if(cnt==K) {
					num++;
					index = i+1;
				}
			}
			System.out.println((num==1)?index:-1);
			
		}
	}
}

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

int main(int argc, char **argv)
{
	ll N, _; cin >> N;
	string str; cin >> str;
	set<string> s;

	ll res{0};
	for (ll i = 0; i <= 999; ++i)
	{
		ll ss[3] = {i/100, (i/10)%10, i%10};
		ll f{0};
		for (ll j = 0; j < N; ++j)
		{
			if ((str[j] - '0') == ss[f]) ++f;
			if (f == 3) break;
		}
		if (f == 3)
		{
			++res;
			// std::cout << "N : " << N << std::endl;
			// std::cout << "str : " << ss.str() << std::endl;
		}
	}
	std::cout << res << std::endl;	
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  ll X[N],Y[N];
  for(int i=0;i<N;i++){
    cin >> X[i];
    Y[i] = X[i];
  }
  sort(X,X+N);

  ll medi_1 = (N+1)/2-1;
  ll medi_2 = (N+1)/2;


  for(int i=0;i<N;i++){
    if(Y[i]<=X[medi_1]){
      cout << X[medi_2] <<endl;
    }else{
      cout << X[medi_1] <<endl;
    }
    
  }

  return 0;
}

Measured memory_bytes: 5376
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
mod = 10**9 + 7
x = y = 0

n.times do |i|
  x += (i + 1).upto(n - 1).count { |j| a[i] > a[j] }
  x %= mod
end

a.each do |e|
  y += a.count { |o| o < e }
  y %= mod
end

puts (x * k + k * (k - 1) / 2 * y) % mod

Measured memory_bytes: 14432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] array = new int[N];
        int count = 0;

        for (int i = 0; i < N; i++) {
        	array[i] = scanner.nextInt();
        }

        calc:
        for (int i = 0; i < 1000000000; i++) {
        	for (int j = 0; j < N; j++) {
        		if (array[j] % 2 == 0) {
        			array[j] /= 2;
        		} else {
        			break calc;
        		}
        	}
        	count++;
        }

        System.out.println(count);
	}

}

Measured memory_bytes: 23892
def solve(k):
    v = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
    v = list(map(int, v.split(",")))
    return v[k-1]

k = int(input())
print(solve(k))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define FOR(i,m,n) for(int i=m;i<(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
using namespace std;

int main(void){
  int N;
  cin >> N;
  vector<int> D(N);
  REP(i, N)
    cin >> D[i];
  int M;
  cin >> M;
  vector<int> T(M);
  REP(i, M)
    cin >> T[i];
  sort(ALL(D));
  sort(ALL(T));
  int n = 0, m = 0;
  while (n < N && m < M) {
    if (T[m] == D[n]) {
      m++;
    }
    n++;
  }
  if (m == M)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
#define pb push_back
#define fastread ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define all(v) v.begin(), v.end()
#define file freopen("in.txt", "r", stdin);
#define pii pair<int, int>
#define pll pair<ll, ll>

const int maxn = 3005;
string s, s1;
int n, n1;
int dp[maxn][maxn];

int call(int i, int j){
	if(i >= n or j >= n1)return 0;
	if(dp[i][j] != -1)return dp[i][j];
	if(s[i] == s1[j]){
		return dp[i][j] = 1 + call(i+1, j+1);
	}
	return dp[i][j] = max(call(i+1, j), call(i, j+1));
}
string ans;

void printlcs(int i, int j){
	if(i >= n or j >= n1){
		cout<<ans<<endl;
		return;
	}
	if(s[i] == s1[j]){
		ans += s[i];
		printlcs(i+1, j+1);
	}
	else{
		if(dp[i+1][j] > dp[i][j+1])printlcs(i+1, j);
		else printlcs(i, j+1);
	}	
}

int main(){
	//file
	fastread
	cin>>s>>s1;
	n = (int)s.size();
	n1 = (int)s1.size();
	memset(dp, -1, sizeof dp);
	call(0, 0);
	printlcs(0, 0);
}

Measured memory_bytes: 35840
N, M = [int(x) for x in input().split()]

S = []
for i in range(N):
    S.append(None)

for i in range(M):
    s, c = [int(x) for x in input().split()]
    
    if S[s - 1] == None:
        S[s - 1] = c
    elif S[s - 1] == c:
        pass
    else:
        S[0] = -1
        break

if S[0] == 0:
    if N == 1:
        print(0)
    else:
        print(-1)
elif S[0] == -1:
    print(-1)
else:
    for i in range(N):
        s = S[i]
        if s == None:
            if i == 0 and N > 1:
                s = '1'
            else:
                s = '0'
        print(s, end="")
    print()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n; cin >> n;
	vpl v(n);
	rep(i,n){
		cin >> v[i].first >> v[i].second;
		if(v[i].first > v[i].second) swap(v[i].first, v[i].second);
	}
	sort(all(v));
	ll mxa = 0, mxb = 0, mna = inf, mnb = inf;
	rep(i,n){
		chmax(mxa, v[i].second);
		chmin(mna, v[i].second);
		chmax(mxb, v[i].first);
		chmin(mnb, v[i].first);
	}
	ll ans = (mxa - mna) * (mxb - mnb);
	ll t = mxa - mnb;
	ll mx = mxb, mn = mnb;
	ll rmn = inf;
	rep(i,n-1){
		chmin(rmn, v[i].second);
		chmax(mn, min(v[i+1].first, rmn));
		chmax(mx, v[i].second);
		chmin(ans, t * (mx - mn));
	}
	cout << ans << "\n";
}

Measured memory_bytes: 6392
#include<iostream>

using namespace std;
typedef pair<int, int> pii;

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

int md(char c){
    if(c=='N') return 0;
    if(c=='E') return 1;
    if(c=='S') return 2;
    else return 3;
}

int main(){

    while(1){
        int N;
        cin>> N;
        if(N==0) break;
        for(int i=0; i<=20; i++){
            for(int j=0; j<=20; j++){
                fld[i][j]=0;
            }
        }
        for(int i=0; i<N; i++){
            int x, y;
            cin>> x>> y;
            fld[y][x]=1;
        }
        int X, Y;
        X=Y=10;
        int cnt=0;
        int M;
        cin>> M;
        for(int i=0; i<M; i++){
            char d; int l;
            cin>> d>> l;
            int j=md(d);
            for(int k=0; k<l; k++){
                X+=dx[j];
                Y+=dy[j];
                if(fld[Y][X]==1) cnt++;
                fld[Y][X]=0;
            }
        }

        cout<< (cnt==N? "Yes": "No")<< endl;
    }

    return 0;
}

Measured memory_bytes: 3004
n, A, B = map(int, input().split())
s = list(input())
a = 0
b = 0
for i in s:
    if i == "a":
        if a + b < A + B:
            a += 1
            print("Yes")
        else:
            print("No")
    elif i == "b":
        if a + b < A + B and b < B:
            b += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")

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

int main() {
    int k, n; cin >> k >> n;

    int old_pos, curr_pos, dist = 0;
    int first_pos; cin >> first_pos;

    old_pos = first_pos;

    for (int i = 1; i < n; i++) {
        cin >> curr_pos;
        dist = max(dist, curr_pos - old_pos);
        old_pos = curr_pos;
    }

    dist = max(dist, k - old_pos + first_pos);
    cout << k - dist << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

class mint {
  private: 
    ll x;

  public:
    constexpr mint(const ll x = 0) noexcept : x((x % MOD + MOD) % MOD) {}
    constexpr ll value() noexcept { return x; }
    constexpr mint operator += (const mint right) noexcept {
      if ((x += right.x) >= MOD) x -= MOD;
      return *this;
    }
    constexpr mint operator -= (const mint right) noexcept {
      if ((x += MOD - right.x) >= MOD) x -= MOD;
      return *this;
    }
    constexpr mint operator *= (const mint right) noexcept {
      x = x * right.x % MOD;
      return *this;
    }
    constexpr mint operator /= (const mint right) noexcept {
      return *this *= right.inv();
    }
    constexpr mint operator + (const mint right) const noexcept {
      return mint(*this) += right;
    }
    constexpr mint operator - (const mint right) const noexcept {
      return mint(*this) -= right;
    }
    constexpr mint operator / (const mint right) const noexcept {
      return mint(*this) /= right;
    }
    constexpr mint operator * (const mint right) const noexcept {
      return mint(*this) *= right;
    }
    constexpr mint inv() const {
      return pow(MOD-2);
    }
    constexpr mint pow(ll n) const {
      if (n == 0) return 1;
      mint a = pow(n>>1);
      a *= a;
      if (n & 1) a *= *this;
      return a;
    }
};

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

  int n; cin >> n;
  int c[3] = {};

  mint ans(1);

  rep(i, n) {
    int cnt = 0;
    int a; cin >> a;

    rep(j, 3) {
      if (c[j] == a) {
        if (cnt == 0) ++c[j];
        ++cnt;
      }
    }

    ans *= cnt;
  }

  cout << ans.value() << endl;

  return (0);
}


Measured memory_bytes: 3656
N = gets.to_i
hash = {}
N.times do |i|
	str = gets.chomp.to_s
	if hash[str]
		hash[str] += 1
	else
		hash[str] = 1
	end
end


best = hash.values.max
bests = hash.select{|k,v| v == best}

ans = bests.sort
ans.map{|k,v| puts k}

Measured memory_bytes: 55344
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>      // sqrt
#include <cstdlib>    // exit
#include <algorithm>  // min,max
using namespace std;
#define forr(i,m,n) for (int i=(m); i<=(n); i++)
#define forv(i,m,n) for (int i=(m); i>=(n); i--)
#define forall(it,p) for (auto it = p.begin(); it != p.end(); ++it)
#define R 1000000007
#define DBG 1
typedef pair<int,int> pii;

#define MAXN 200005
int y[MAXN];
int v[MAXN];
vector< list<int> > dst;

void dfs(int i, int fromup) {
  y[i] = fromup + v[i];
  for (int d : dst[i]) dfs(d,y[i]);
}

int main() {
  int n,q;
  cin >> n >> q;
  dst.resize(n);
  forr(i,0,n-2) {
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    dst[a].push_back(b);
    v[i] = 0;
  }
  forr(i,0,q-1) {
    int p,x;
    cin >> p >> x;
    p--;
    v[p] += x;
  }
  dfs(0,0);
  forr(i,0,n-1)
    cout << (i==0 ? "" : " ") << y[i];
  cout << endl;

}


Measured memory_bytes: 19584
#include <bits/stdc++.h>
#define REP(i,n,s) for (int i = (s); i < (n); i++)
#define MOD 1000000007;
using namespace std;
typedef long long int LL;

int N, K;
LL p[101], l[256][101];

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

	cin >> N >> K;
	p[0] = 1;
	REP(i, N+1, 1) {
		p[i] = p[i-1]*i%MOD;
	}

	int a;
	LL tmp[256][101];
	REP(i, N, 0) {
		cin >> a;
		memset(tmp,0,sizeof(tmp));
		
		REP(j, 256, 0) {
			REP(k, 101, 0) {
				tmp[j][k] = (tmp[j][k]+l[j][k])%MOD;
				tmp[j^a][k+1] = (tmp[j^a][k+1]+l[j][k])%MOD;
			}
		}
		tmp[a][1]++;
		memcpy(l, tmp, sizeof(l));
	}
	LL res = 0;
	REP(i, 101, 1) {
		res = (res+p[i]*l[K][i])%MOD;
	}
	cout << res << endl;
}

Measured memory_bytes: 640
from heapq import *

n, m, s = map(int, input().split())
s = min([s, 50*n])
tree = [[] for _i in range(n+1)]
for _i in range(m):
    u, v, a, b = map(int, input().split())
    tree[u].append([v, a, b])
    tree[v].append([u, a, b])

cd = [[0,0]]
for _i in range(n):
    cd.append(list(map(int, input().split())))

dp = [[float('inf') for _i in range(50*n+1)] for _j in range(n+1)]
hq = [[0, 1, s]]
dp[1][s] = 0
heapify(hq)
while hq:
    t, p, g = heappop(hq)
    if g+cd[p][0] <= 50*n:
        x, y = t+cd[p][1], min([g+cd[p][0], 50*n])
        if dp[p][y] > x:
            dp[p][y] = x
            heappush(hq, [x, p, y])
    for x, y, z in tree[p]:
        if g-y >= 0 and dp[x][g-y] > t+z:
            dp[x][g-y] = t+z
            heappush(hq, [t+z, x, g-y])

for i in dp[2:]:
    print(min(i))

Measured memory_bytes: 29360
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
long long a,b,c,k;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b>>c>>k;
	if(k<=a) cout<<k<<endl;
	else if(k<=(a+b)) cout<<a<<endl;
	else cout<<a-(k-a-b)<<endl;
	return 0;
}


Measured memory_bytes: 3636
#![allow(unused_imports)]pub mod pcl{pub mod stdin{use std::io::prelude::*;use std::io::stdin;use std::str::FromStr;pub fn read_line()->String{let mut s=String::new();stdin().read_line(&mut s).unwrap();s.trim().to_string()}pub fn read<T:FromStr>()->T{read_from(stdin())}pub fn read_token()->String{read_token_from(stdin())}pub fn read_ascii()->char{read_ascii_from(stdin())}pub fn read_from<R:Read,T:FromStr>(read:R)->T{read_token_from(read).parse().unwrap_or_else(|_|panic!("failed to parse a value"))}pub fn read_token_from<R:Read>(read:R)->String{read.bytes().flat_map(|x|x.map(|x|x as char)).skip_while(|x|x.is_whitespace()).take_while(|x|!x.is_whitespace()).collect()}pub fn read_ascii_from<R:Read>(read:R)->char{read.bytes().flat_map(|x|x.map(|x|x as char)).skip_while(|x|x.is_whitespace()).next().expect("failed to get a next character")}}}
use pcl::stdin::*;
use std::collections::VecDeque;
fn main() {
    let s = read_line();
    let q: usize = read();
    let mut reversed = false;
    let mut res: VecDeque<_> = s.chars().collect();
    for _ in 0..q {
        let t: i32 = read();
        if t == 1 {
            reversed = !reversed;
        } else {
            let f: i32 = read();
            let c: char = read_ascii();
            match (reversed, f) {
                (false, 1) => res.push_front(c),
                (false, 2) => res.push_back(c),
                (true, 1) => res.push_back(c),
                (true, 2) => res.push_front(c),
                _ => unreachable!(),
            }
        }
    }
    let iter = res.into_iter();
    let s: String = if !reversed {
        iter.collect()
    } else {
        iter.rev().collect()
    };
    println!("{}", s);
}



Measured memory_bytes: 6396
#!/usr/bin/env python3
import copy
h, w = map(int, input().split())
f = [ list(input()) for _ in range(h) ]
a = copy.deepcopy(f)
b = copy.deepcopy(f)
for y in range(h):
    for x in range(w):
        if y == 0:
            a[y][x] = '#'
        elif y == h - 1:
            b[y][x] = '#'
        else:
            [a, b][x % 2][y][x] = '#'
print(*map(''.join, a), sep='\n')
print()
print(*map(''.join, b), sep='\n')


Measured memory_bytes: 12020
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

lld fac[1000001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=200000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


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

lld p1=1e9 + 7,p2=998244353;
lld l,r,mid,ans=0;
lld n,i,j,k,m;
lld x,y,n1,b=0,a,n2,h,z,c;
vector<vector<lld> > v(200001);
vector<bool > visited(200001,false);
vector<lld> w(200001),pa(200001);

queue<lld> q;
void bfs()
{
    q.pu((lld)1);
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        if(visited[x]==true)
            continue;
        visited[x]=true;
        l=v[x].size();
        for(i=0;i<l;i++)
        {
            if(visited[v[x][i]]==false)
            {
                w[v[x][i]] = w[x]+1;
                pa[v[x][i]] =x;
                q.pu(v[x][i]);
            }
        }
    }
}
void solve()
{
    cin>>n;
    ans=0;
    y=1;
    while(n>=1)
    {
        ans+=y;
        y*=2;
        n=n/2;
    }
    cout<<ans;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    //cin>>t;
    //cout<<t;
     //getfac(p1);
    //check the value by which modulo is to be taken
    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
           solve();
        cout<<"\n";
    }
    return 0;
}

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

int main() {
    int N,K;
    string s;
    cin >> N >> K >> s;
    // cin >> s;
    // cout << a + b + c << " " << s << endl;
    s[K-1] = tolower(s[K-1]);
    cout <<s << endl;

}

Measured memory_bytes: 256
N = int(input())
check = list()
for i in range(N):
    a = int(input())
    tmp = list()
    for j in range(a):
        tmp.append(list(map(int,input().split())))
    check.append(tmp)
lis = ["0"*(N-len(format(i,"b")))+format(i,"b") for i in range(2**N)]

result = 0
for i in lis:
    checker = 1
    for j in range(len(i)):
        if checker == 0:
            break
        if i[j] =="1":
            for k in range(len(check[j])):
                if i[check[j][k][0]-1] != str(check[j][k][1]):
                    checker = 0
                    break
        
    if checker ==1 and result < i.count("1"):
        result = i.count("1")
print(result)
        

        

Measured memory_bytes: 5408
#include <iostream>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll A, ll B) {
  cout << max({A+B,A-B,A*B}) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
b = list(map(int, input().split()))
ans = []

for i in range(n):
    for j in range(n-1-i, -1, -1):
        if b[j] == j+1:
            # print(J+1)
            tmp = b.pop(j)
            ans.append(tmp)
            break
    else:
        print(-1)
        exit()

for a in ans[::-1]:
    print(a)


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

class UnionFind
{
private:
    vector<int> par;
    vector<int> rank;
    vector<int> sz;
    int _count;

public:
    UnionFind(int n) : par(n), rank(n, 0), sz(n, 1), _count(n) {
        iota(par.begin(), par.end(), 0);
    }

    int find(int x) {
        if (par[x] == 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;

        _count--;
        if (rank[x] < rank[y]) {
            par[x] = y; sz[y] += sz[x];
        } else {
            par[y] = x; sz[x] += sz[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sz[find(x)];
    }

    int count(void) {
        return _count;
    }
};

int main()
{
    int n, m; cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int x, y, z; cin >> x >> y >> z;
        x--, y--;
        uf.unite(x, y);
    }
    cout << uf.count() << endl;
    return 0;
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

bigraph = [0] * n


def dfs(v, v_p, depth):
    bigraph[v] = depth % 2
    for v_next in graph[v]:
        if v_next == v_p:
            continue
        dfs(v_next, v, depth + 1)


dfs(0, -1, 1)
m1 = sum(bigraph)
m2 = n - m1

ans = [-1] * n
if m1 > n // 3 and m2 > n // 3:
    c1 = 1
    c2 = 2
    for i in range(n):
        if bigraph[i] == 0 and c1 <= n:
            ans[i] = c1
            c1 += 3
        if bigraph[i] == 1 and c2 <= n:
            ans[i] = c2
            c2 += 3
    c3 = 3
    for i in range(n):
        if ans[i] == -1:
            ans[i] = c3
            c3 += 3
elif m1 > m2:
    # print('A')
    c1 = 1
    c2 = 2
    c3 = 3
    for i in range(n):
        if bigraph[i] == 0:
            # print(i, c1)
            ans[i] = c3
            c3 += 3
    for i in range(n):
        if ans[i] == -1:
            if c1 <= n:
                ans[i] = c1
                c1 += 3
            elif c2 <= n:
                ans[i] = c2
                c2 += 3
            else:
                ans[i] = c3
                c3 += 3
else:  # m1 < m2
    # print('B')
    c1 = 1
    c2 = 2
    c3 = 3
    for i in range(n):
        if bigraph[i] == 1:
            # print(i, c1)
            ans[i] = c3
            c3 += 3
    for i in range(n):
        if ans[i] == -1:
            if c1 <= n:
                ans[i] = c1
                c1 += 3
            elif c2 <= n:
                ans[i] = c2
                c2 += 3
            else:
                ans[i] = c3
                c3 += 3

print(*ans)


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

int main(){
    char s;
    int a,b;
    while(true){
        cin>>a>>s>>b;
        if(s=='?') break;
        if(s=='+'){
            cout<<a+b<<'\n';
        }else if(s=='-'){
            cout<<a-b<<'\n';
        }else if(s=='*'){
            cout<<a*b<<'\n';
        }else if(s=='/'){
            cout<<a/b<<'\n';
        }
    }    
}


Measured memory_bytes: 3092
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

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

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

a = []
for i in range(3):
    a.append(LI())

ll = [[0]*3 for i in range(3)]

n = I()
for i in range(n):
    b = I()
    for j in range(3):
        for k in range(3):
            if a[j][k]==b:
                ll[j][k]=1

for i in range(3):
    if ll[i]==[1,1,1]:
        print("Yes")
        exit()
for i in range(3):
    if ll[0][i]==1 and ll[1][i]==1 and ll[2][i]==1:
        print("Yes")
        exit()

if ll[0][0]==1 and ll[1][1]==1 and ll[2][2]==1:
    print("Yes")
    exit()
if ll[0][2]==1 and ll[1][1]==1 and ll[2][0]==1:
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 5680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pi acos(-1.0)
const int maxn=1e5+5;
int n;
double a,b;
double h,m;
int read() {
	char ch = getchar();
	int x = 0, f = 1;
	while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9') x = x*10 + ch - 48, ch = getchar();
	return x * f;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cout<<setprecision(15)<<fixed;
	cin>>a>>b>>h>>m;
	double da=pi/6*(h+m/60),db=pi/30*m;
	double x1=a*cos(da),y1=a*sin(da);
	double x2=b*cos(db),y2=b*sin(db);
	cout<<sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

	return 0;
}

Measured memory_bytes: 4140
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

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

    int count_even_black = 0;
    int count_odd_black = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (i % 2 == 0) {
            if (s[i] == '1')
                ++count_even_black;
            else
                ++count_odd_black;
        } else {
            if (s[i] == '1')
                ++count_odd_black;
            else
                ++count_even_black;
        }
    }

    cout << min(count_odd_black, count_even_black) << '\n';
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;

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

    int answer = 0;
    for (int i = 0; i < int(s.size()) - 2; i++)
    {
        if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C')
        {
            answer++;
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

const ll p = 1000000007;

int main(){
  ll h, w, k;
  cin >> h >> w >> k;
  ll dp[h+1][w];
  fill(dp[0],dp[h+1],0);
  REP(i,w){
    if(i==0) dp[0][i] = 1;
    else dp[0][i] = 0;
  }
  REP(i,h){
    REP(j,1<<(w-1)){
      bool ignore = false;
      REP(l,w-2){
        if(j>>l&1&&j>>(l+1)&1){
          ignore = true;
        }
      }
      if(!ignore){
        REP(l,w){
          if(l!=0&&j>>(l-1)&1) dp[i+1][l]+=dp[i][l-1];
          else if(l!=w-1&&j>>l&1) dp[i+1][l]+=dp[i][l+1];
          else dp[i+1][l]+=dp[i][l];
          dp[i+1][l] %= p;
        }
      }
    }
  }
  cout << dp[h][k-1] << endl;
  return 0;
}


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

int main(){
  string ans="NO", chk="keyence", s;
    cin >> s;
    if(s!=chk){
    int n = s.size();
      for(int i=0; i<n; i++){
        for(int j=i; j<n; j++){
          string tmp = "";
          for(int k=0; k<n; k++){
            if(i<=k && k<=j) continue;
            else tmp.push_back(s[k]);
          }
          if(tmp==chk) ans = "YES";
        }
      }
    }else ans = "YES";
    cout << ans << endl;
}


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;

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

	ll ans = 0;
	for(int b=1; b<=N; b++){
		int p = N/b;
		int r = N%b;
		int md = max(b-K,0) * p;
		md += max(r-K+1,0);
		ans += md;
	}
	if(K==0)ans -= N;
	cout << ans << endl;

	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/24  Problem: 007_agc_b / Link: https://agc007.contest.atcoder.jp/tasks/agc007_b?lang=en  ----- */
/* ------問題------

集合 {1,2,…,N} の要素を並び替えた順列 p が与えられます。以下の条件をすべて満たす 2 つの正整数列 a1, a2, ..., aN および b1, b2, ..., bN を構成してください。
すべての i に対し、1≤ai,bi≤10^9
a1<a2<…<aN
b1>b2>…>bN
ap1+bp1<ap2+bp2<…<apN+bpN

-----問題ここまで----- */
/* -----解説等-----

全部同じ値になるようにa,bを定義する。
その後p[i]をその位置に足していくとして、均衡関係が崩れないようにするためには値をNよりも大きくすれば良い。

----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VI a(N), b(N);
	FOR(i, 0, N) {
		a[i] = 20000 * i + 1;
		b[i] = 20000 * (N - 1 - i) + 1;
	}
	VI p(N);
	FOR(i, 0, N) {
		cin >> p[i];
		a[p[i] - 1]+=i+1;
	}

	FOR(i, 0, N) {
		cout << a[i] << " ";
	}cout << endl;
	FOR(i, 0, N) {
		cout << b[i] << " ";
	}cout << endl;

	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

class Zahyo
{
public:
	double x, y;
	Zahyo() {}
	Zahyo(double x, double y) : x(x), y(y) {}
};

double inp_x, inp_y;
Zahyo tyouten[20];
char comma;

double calc_area(Zahyo x, Zahyo y, Zahyo z)
{
	double a, b, c;
	double zz, S;
	
	a = sqrt(pow(z.x - y.x, 2) + pow(z.y - y.y, 2));
	b = sqrt(pow(z.x - x.x, 2) + pow(z.y - x.y, 2));
	c = sqrt(pow(x.x - y.x, 2) + pow(x.y - y.y, 2));

	zz = (a + b + c) / 2;
	S = sqrt(zz * (zz - a) * (zz - b) * (zz - c));

	//cout << "S = " << S << endl;

	return S;
}

int main()
{
	int i = 0;
	while (cin >> inp_x >> comma >> inp_y)
	{
		tyouten[i].x = inp_x;
		tyouten[i].y = inp_y;
		i++;
	}

	double area_sum = 0;
	for (int j=2; j<=i-1; j++)
	{
		//	cout << "j = " << j << endl;
		area_sum += calc_area(tyouten[0], tyouten[j-1], tyouten[j]);
	}

	printf("%.6lf\n", area_sum);
	
	return 0;
}

Measured memory_bytes: 1240
#include <iostream>

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

int n, a[55];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0 ; i < n ; ++i){
	cin >> a[i];
}
int sol = 0;
for(int i = 0 ; i < n ; ++i){
	for(int j = 0 ; j < i ; ++j){
		sol += (a[i] * a[j]);
	}
}
cout << sol << endl;

return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
int x[200000];
int n, i, j;
scanf("%d", &n);
for(i=0;i<n;i++){
scanf("%d", &x[i]);
}
int max=-1000000000, min=x[0];
for(j=1;j<n;j++){
if(x[j]-min>max)
max=x[j]-min;
if(min>x[j])
min=x[j];
}
printf("%d\n", max);
return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else{
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){
  Node y;
  if (x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL){
    y=z;
  }
  else{
    y=treeSuccessor(z);
  }

  if(y->left!=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }
  else if(y==y->parent->left){
    y->parent->left=x;
  }
  else {
    y->parent->right=x;
  }
  if(y!=z){
    z->key=y->key;
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
    if(y==NIL){
      root=z;
    }
    else if(z->key<y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }


void inorder(Node u){
  if (u->left != NIL){
    inorder(u->left);
  }
  printf(" %d", u->key);
  if (u->right != NIL){
    inorder(u->right);
  }
}
void preorder(Node u){
  printf(" %d",u->key);
  if (u->left != NIL){
    preorder(u->left);
  }
  if (u->right != NIL){
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

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

int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = (N - 1000 * a) / 100;
  c = (N - 1000 * a - 100 * b) / 10;
  d = N- 1000 * a - 100 * b - 10 * c;
  if (b != c) {
    cout << "No" << endl;
  }
  else if (a == b || c == d) {
    cout << "Yes" << endl;
  }
  else {
     cout << "No" << endl;
  }
}


Measured memory_bytes: 256
require 'matrix'

gets
ARGF.each_line do |line|
  x1, y1, x2, y2, x3, y3 = line.split.map(&:to_r)
  a = Vector[x1, y1]
  b = Vector[x2, y2]
  c = Vector[x3, y3]

  ab = b - a
  bc = c - b
  ca = a - c

  ar = bc.r
  br = ca.r
  cr = ab.r

  as = ar**2
  bs = br**2
  cs = cr**2

  q1 = (as * (bs + cs - as) * a + bs * (as + cs - bs) * b + cs * (as + bs - cs) * c)
  q2 = 2 * (as * bs + bs * cs + cs * as) - (as**2 + bs**2 + cs**2)
  rcc =  q1 / q2

  s1 = ar * br * cr
  s2 = Math.sqrt((ar + br + cr) * (-ar + br + cr) * (ar - br + cr) * (ar + br - cr))
  r = s1 / s2

  puts [*rcc.to_a, r].map{|e| format("%.3f", e) }.join("\s")
end

Measured memory_bytes: 9280
#include<bits/stdc++.h>
//clock_t t=clock();
namespace my_std{
    using namespace std;
    #define pii pair<int,int>
    #define fir first
    #define sec second
    #define MP make_pair
    #define rep(i,x,y) for (int i=(x);i<=(y);i++)
    #define drep(i,x,y) for (int i=(x);i>=(y);i--)
    #define go(x) for (int i=head[x];i;i=edge[i].nxt)
    #define templ template<typename T>
    #define sz 1010
    #define mod 1000000007ll
    typedef long long ll;
    typedef double db;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
    templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
    templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
    templ inline void read(T& t)
    {
        t=0;char f=0,ch=getchar();double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t=(f?-t:t);
    }
    template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
    char sr[1<<21],z[20];int C=-1,Z=0;
    inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
    inline void print(register int x)
    {
    	if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
    	while(z[++Z]=x%10+48,x/=10);
    	while(sr[++C]=z[Z],--Z);sr[++C]='\n';
    }
//    void file()
//    {
//        #ifndef ONLINE_JUDGE
//        freopen("a.in","r",stdin);
//        #endif
//    }
//    inline void chktime()
//    {
//        #ifndef ONLINE_JUDGE
//        cout<<(clock()-t)/1000.0<<'\n';
//        #endif
//    }
//    #ifdef mod
//    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
//    ll inv(ll x){return ksm(x,mod-2);}
//    #else
//    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
//    #endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n,m;
bool visa[sz*sz],visb[sz*sz];

int main()
{
//	file();
	read(n,m);
	int x;
	rep(i,1,n)
	{
		read(x);
		if (visa[x]) return puts("0"),0;
		else visa[x]=1;
	}
	rep(i,1,m)
	{
		read(x);
		if (visb[x]) return puts("0"),0;
		else visb[x]=1;
	}
	ll ans=1;
	ll A=0,B=0;
	drep(i,n*m,1)
	{
		ll AA=A,BB=B;
		if (visa[i]) AA=1,++A;
		if (visb[i]) BB=1,++B;
		if (visa[i]||visb[i]) ans=ans*AA%mod*BB%mod;
		else ans=ans*(1ll*AA*BB-(1ll*n*m-i))%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256