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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s;
	cin >> s;
	vector<ll>arr(s.size() + 1);
	rep(i, s.size()) {
		if (s[i] == '<')arr[i+1] = arr[i] + 1LL;
	}

	for (ll i = s.size()-1; i >=0;i--) {
		if (s[i] == '>')arr[i] = max(arr[i + 1] + 1LL,arr[i]);
	}
	//if (s[0] == '>')arr[0] = arr[1] + 1LL;

	ll sum = accumulate(all(arr),0LL);
	cout << sum << endl;
}


Measured memory_bytes: 7712
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a * b) << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

struct card{
  int number, id;
  string suit;
};

void swap(card* c[], int i, int j){
  card* tmp;
  tmp = c[i];
  c[i] = c[j];
  c[j] = tmp;
}

int partition(card* c[], int p, int r){
  int x;
  x = c[r]->number;
  int i;
  i = p-1;
  for (int j=p; j<r; j++){
    if (c[j]->number <= x){
      i++;
      swap(c,i,j);
    }
  }
  swap(c,i+1,r);
  return i+1;
}

void quicksort(card* c[], int p, int r){
  if (p<r){
    int q;
    q = partition(c,p,r);
    quicksort(c,p,q-1);
    quicksort(c,q+1,r);
  }
}

void printcards(int n, card* c[]){
  for (int i=0; i<n; i++){
    cout << c[i]->suit << " " << c[i]->number << endl;
  }
}

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

  card* c[n];
  int tmp_number;
  string tmp_suit;
  card* tmp_card;
  for (int i=0; i<n; i++){
    cin >> tmp_suit;
    cin >> tmp_number;
    tmp_card = new card;
    tmp_card->number = tmp_number;
    tmp_card->suit = tmp_suit;
    tmp_card->id = i;
    c[i] = tmp_card;
  }

  quicksort(c,0,n-1);

  bool stableflg = true;
  for (int i=0; i<n-1; i++){
    if (c[i]->number == c[i+1]->number && c[i]->id > c[i+1]->id){
      stableflg = false;
      break;
    }
  }

  if (stableflg){
    cout << "Stable" << endl;
  }
  else{
    cout << "Not stable" << endl;
  }

  printcards(n,c);

  return 0;
}



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

int main (void) {

	while (1) {
		int n, m, p;
		cin >> n >> m >>p;
		if (n == 0 && m ==0 && p == 0) break;
		int x[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> x[i];
			sum += x[i];
		}
		int gold = sum * 100;
		int rest = gold - (gold * p * 0.01);
		if (x[m-1] != 0) 
			cout << rest/x[m-1] <<endl;
		else
			cout << 0 <<endl;
	}
	return 0;
}



Measured memory_bytes: 3092
import string

N = int(input())


def number_to_base(n, b):
    if n == 0:
        return [0]
    digits = []
    while n:
        digits.append(int(n % b))
        n //= b
    return digits[::-1]


def get_dog_name(N):
    N -= 1
    for i in range(1, 14):
        num = 26 ** i
        if N >= num:
            N -= num
            continue
        base26 = number_to_base(N, 26)
        name = "".join([string.ascii_lowercase[i] for i in base26])
        return ("a" * i)[:-len(name)] + name


print(get_dog_name(N))


Measured memory_bytes: 9984
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

string S;

int main() {
	cin >> S;
	if (S == "SUN")cout << 7 << endl;
	if (S == "MON")cout << 6 << endl;
	if (S == "TUE")cout << 5 << endl;
	if (S == "WED")cout << 4 << endl;
	if (S == "THU")cout << 3 << endl;
	if (S == "FRI")cout << 2 << endl;
	if (S == "SAT")cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
// 6/28 バーチャル参加
#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>;
using Graph = vector<vector<int>>;

int main() {
    int N;
    cin >> N;
    cout << (1000 * ((N+1000-1) / 1000)) - N << endl;
    return 0;
}

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

struct LL {
  ll value;

  LL() : value(1e9) {}

  explicit LL(ll value) : value(value) {}

  LL(const LL& a, const LL& b) {
    value = min(a.value, b.value);
  }
};

struct Add {
  ll value;

  Add() : value(0) {}

  explicit Add(ll value) : value(value) {}

  Add(const Add& a, const Add& b) {
    value = a.value + b.value;
  }
};

void apply(LL& e, const Add& m, int l, int r) {
  e.value += m.value;
  (void) l, (void) r;
}

template<typename E, typename M>
struct ST {
  static constexpr int inf = 1e9;
  int base;
  vector<E> t;
  vector<M> upd;

  static int calc_base(int n) {
    int x = 1;
    while (x < n) {
      x *= 2;
    }
    return x;
  }

  ST() : base(0) {}
  ST(int n) : base(calc_base(n)), t(base * 2), upd(base * 2) {}

  void push(int v, int cl, int cr) {
    int cc = (cl + cr) / 2;
    apply(t[v * 2 + 0], upd[v], cl, cc);
    apply(t[v * 2 + 1], upd[v], cc, cr);
    upd[v * 2 + 0] = M(upd[v * 2 + 0], upd[v]);
    upd[v * 2 + 1] = M(upd[v * 2 + 1], upd[v]);
    upd[v] = M();
  }

  E get(int l, int r, int v = 1, int cl = 0, int cr = inf) {
    cr = min(cr, base);
    if (l <= cl && cr <= r) {
      return t[v];
    }
    if (r <= cl || cr <= l) {
      return E();
    }
    push(v, cl, cr);
    int cc = (cl + cr) / 2;
    return E(get(l, r, v * 2, cl, cc), get(l, r, v * 2 + 1, cc, cr));
  }

  void put(int l, int r, const M& x, int v = 1, int cl = 0, int cr = inf) {
    cr = min(cr, base);
    if (l <= cl && cr <= r) {
      apply(t[v], x, cl, cr);
      upd[v] = M(upd[v], x);
      return;
    }
    if (r <= cl || cr <= l) {
      return;
    }
    push(v, cl, cr);
    int cc = (cl + cr) / 2;
    put(l, r, x, v * 2 + 0, cl, cc);
    put(l, r, x, v * 2 + 1, cc, cr);
    t[v] = E(t[v * 2], t[v * 2 + 1]);
  }
};
using Tree = ST<LL, Add>;

const int maxn = 200200;
int b[maxn];
vector<int> qs[maxn];

signed main() {
#ifdef LOCAL
  assert(freopen("f.in", "r", stdin));
#endif
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  Tree t(n + 1);
  t.put(0, 1, Add(-LL().value));
  for (int i = 1; i <= n; ++i) {
    t.put(i, i + 1, Add(-5e8));
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    --l;
    qs[l].push_back(r);
  }
  for (int l = 0; l < n; ++l) {
    for (auto r : qs[l]) {
      ll new_val = t.get(0, r + 1).value;
      ll old_val = t.get(r, r + 1).value;
      t.put(r, r + 1, Add(new_val - old_val));
    }
    
    if (b[l] == 1) {
      t.put(0, l + 1, Add(1));
    } else {
      t.put(l + 1, n + 1, Add(1));
    }
  }
  auto ans = t.get(0, n + 1);
  cout << ans.value << '\n';
}


Measured memory_bytes: 17920
import bisect


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

ans = 0
for b in B:
    idx_a = bisect.bisect_left(A,b)
    idx_c = bisect.bisect_right(C,b)
    ans += idx_a * (N - idx_c)

print(ans)

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

int main(){
    int a;
    
    int b;
    
    int c;
    
    cin >> a >> b >> c;
    
    if (a<b && b<c){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int a; cin >> a;
    string s; cin >> s;
    if(3200 <= a) cout << s << endl;
    else cout << "red" << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>

#define N 100


struct Card{
  char word;
  char num;
};

int judge(struct Card *,struct Card *,int );



int main(){

  struct Card C1[N], C2[N];
  struct Card tmp;
  int i, j;
  int minj;
  int n;
  



  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    scanf(" %c %c", &C1[i].word,&C1[i].num);
  }  


  for(i=0;i<n;i++){
    C2[i]=C1[i];
  }


  
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(C1[j].num < C1[j-1].num){
	tmp=C1[j];
	C1[j]=C1[j-1];
	C1[j-1]=tmp;
      }
    }
  }//bubble sort

   for(i=0;i<=n-1;i++){
    minj=i;
    for(j=i;j<=n-1;j++){
      if(C2[j].num < C2[minj].num){
	minj=j;
      }
    }
      tmp=C2[i];
      C2[i]=C2[minj];
      C2[minj]=tmp;
   }//selection sort


   for ( i = 0; i < n; i++ ){
     if ( i >= 1 ) printf(" ");
     printf("%c%c", C1[i].word,C1[i].num);
   }
   printf("\n");
   
   printf("Stable\n");



   
   for ( i = 0; i < n; i++ ){
     if ( i >= 1 ) printf(" ");
     printf("%c%c", C2[i].word,C2[i].num);
   }
   printf("\n");

   if ( judge(C1, C2, n) == 1 ){
     printf("Stable\n");
   }
   else {
     printf("Not stable\n");
   }
   return 0;   

}
int judge(struct Card C1[] ,struct Card C2[],int n){

  int i;
  
  for(i=0;i<n;i++){
    if(C1[i].word != C2[i].word){
      return 0;
    }
  }
    return 1;
}

Measured memory_bytes: 612
import java.util.*;
public class Main {
	public static void main(String args[]){
		ArrayList[] a;
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				System.out.printf("%dx%d=%d\n",i,j,i*j);
			}
		}
		
	}
}

Measured memory_bytes: 18176
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

char S[10] = {};

int main() {
	cin >> S;
	for (int i = 0; i < 3; i++) {
		if (S[i] == S[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
onazi = False

a.sort()

for i in range(n-1):
    if a[i]==a[i+1]:
        onazi = True
        break

if(onazi):
    print('NO')
else:
    print('YES')


Measured memory_bytes: 25172
//According to all known laws of aviation, there is no way that a bee should be able to fly.
 //Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
 //Because bees don't care what humans think is impossible.
 #include <bits/stdc++.h>
 #define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 #define mod 1000000007
 #define endl "\n"
 using namespace std ;
 using bigint = long long int ;
 using vi = vector<int> ;
 bigint arr[300011] ;
 int main(){
     int N , M ; cin >> N >> M ;
     map<int , int> m ;
     bool flag = true ;
     for( int i = 0 ; i < M ; i++ ){
         int x , y ; cin >> x >> y ;
         x-- ;
         if( m.find(x) == m.end() ){
             m[x] = y ;
         }
         else if( m[x] != y )
             flag = false ;
     }
     if( flag == false ){
         cout << "-1" << endl ;
         return 0 ;
     }
     for( int i = 0 ; i < 10000 ; i++ ){
         int digits = log10(i) + 1 ;
         if( i == 0 )
             digits = 1 ;
         if( digits != N )
             continue ;
         string str = to_string(i) ;
         bool f = true ;
         for( auto x : m ){
             if( str[x.first] - '0' != x.second ){
                 f = false ;
             }
         }
         if( f == true ){
             cout << i << endl ;
             return 0 ;
         }
     }
     cout << "-1" << endl ;
     return 0 ;
 }

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

int main () {
    string str;
    int a[26] = {};
    while(getline(cin, str)) {
        for (int i = 0; i < str.length(); i++) {
            if (str[i] >= 'A' && str[i] <= 'Z') {
                a[str[i] - 'A']++;
            } else if (str[i] >= 'a' && str[i] <= 'z') {
                a[str[i] - 'a']++;
            }
        }
    }
    
    for (int j = 0; j < 26; j++) {
        cout << (char)(j + 'a') << " : " << a[j] << endl;
    }
    
    return 0;
    
}



Measured memory_bytes: 3164
N, M = map(int, input().split())

inf = 1e9+7
dp = [inf] * (1 << N)
dp[0] = 0

for m in range(M):
    a, b = map(int, input().split())

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

    mask = sum(1 << (c-1) for c in hako)

    for i in range(1 << N):
        if dp[i] + a < dp[i | mask]:
            dp[i | mask] = dp[i] + a

if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

template<typename T>
T gcd(T a, T b) {
	if( a < b ) swap(a, b);
	
	T r;
	while( r = a % b ) {
		a = b;
		b = r;
	}
	
	return b;
}

int main(void) {
	int a, b;
	cin >> a >> b;
	
	cout << gcd(a, b) << endl;
	
	return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int N;
  int a[100010];
  cin >> N;
  for (auto i = 0; i < N; ++i) {
    cin >> a[i];
    a[i]--;
  }
  int now = 0;
  int ans = 0;
  while (now != 1 && ans < 200010) {
    now = a[now];
    ans++;
  }
  if (ans > 100010) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[n];
	int sum = 0;
	int ave;
	int dis1 = 0;
	int dis2 = 0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum = sum + a[i];
	}
	
	ave = sum/n;
	for(int i=0;i<n;i++){
		dis1 += (a[i]-ave)*(a[i]-ave);
		dis2 += (a[i]-ave-1)*(a[i]-ave-1);
	}
	cout << min(dis1,dis2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    long long N, A[100000], cnt = 0, ans = 0, min = (int)1e9;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] < 0) cnt++;
        ans += abs(A[i]);
        if (abs(A[i]) < min) min = abs(A[i]);
    }
    if (cnt % 2) ans -= min * 2;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <nmmintrin.h>
#include <chrono>
const double EPS = 1e-8;
#define Scan(a) int a;scanf("%d", &a);
#define ScanS(a) char a[500];scanf("%s", a);
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1LL)
#define bitset(a,b)      ( a |= (1LL << b))
#define bitunset(a,b)    (a &= ~(1LL << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

pii Dir[8] = {
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};


pii operator+(pii obj, pii obj2) {
	return MP(obj.first + obj2.first, obj.second + obj2.second);
}
pii operator-(pii obj, pii obj2) {
	return MP(obj.first - obj2.first, obj.second - obj2.second);
}

struct Edge {
	int from, to, weight;
};

typedef vector<vector<Edge>> Graph;


int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))) % INT_MAX;
}

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

	if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
		cout << "Yes" << endl;
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,a[200005],ans,s=1;
map<ll,ll>p;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        p[a[i]]++;
    }
    sort(a,a+n);
    while(a[n-1]>=s)s*=2;
    for(int i=n-1;i>=0;i--){
        while(a[i]<s/2)s/=2;
        ll x=a[i],y=s-x;
        if(p.find(x)==p.end()||p.find(y)==p.end())continue;
        if(x==y){
            ans+=p[x]/2;
            p[x]=p[x]%2;
        }else{
            ll t=min(p[x],p[y]);
            ans+=t;
            p[x]-=t;
            p[y]-=t;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 14336
#include <iostream>

using namespace std;

int main() {
    int i,a,b,c,ans;
    ans=0;
    cin >> a >> b >> c;
    for(i=a;i<=b;i++)
    {
    if (c%i==0) 
     ans=ans + 1;
    }
     cout << ans << endl;
}


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

int main()
{
	bool flag = true;
	int n, m;
	cin >> n >> m;
	vector<int> num(n + 1, -1);
	for(int i = 1; i <= m; ++i)
	{
		int temp, val; 
		cin >> temp >> val;
		if(num[temp] == -1 || num[temp] == val)
			num[temp] = val;
		else
			flag = false;
	}
	if(flag == false)
	{
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	for(int i = 1; i <= n; ++i)
	{
		if(i == 1)
		{
			if(num[1] == -1)
			{
				if(n == 1)
				{
					cout << 0 << endl;
					return 0;
				}
				else
					ans = 1;
			}
			else if(num[1] == 0)
			{
				if(n == 1)
					cout << 0 << endl;
				else
					cout << -1 << endl;
				return 0;
			}
			else
				ans = num[1];
		}
		else
		{
			ans *= 10;
			if(num[i] == -1)
				continue;
			else
				ans += num[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import math

a,b,h,m = map(int, input().split())

a_speed = 0.5 #degree
b_speed = 6    #degree

a_point = 30*h + a_speed*m
b_point = b_speed*m
if a_point > b_point:
    degree = a_point - b_point
else:
    degree = b_point-a_point
    
degree = min(degree, 360-degree)
feature = (a**2+b**2)-2*b*a*math.cos(math.radians(degree))
print(feature**0.5)

Measured memory_bytes: 9540
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define ma LONG_LONG_MAX
#define fi first
#define sec second
vector<ll> v[100002];
ll in[100005]={0},maxi[100005]={0};
ll dfs(ll x)
{
	if(v[x].size()==0)
	return 0;
	for(ll i=0;i<v[x].size();i++)
	{
		if(maxi[v[x][i]]==0)
		{
			maxi[x]=max(dfs(v[x][i]),maxi[x]);
		}
		else
		{
			maxi[x]=max(maxi[v[x][i]],maxi[x]);
		}
	}
	maxi[x]++;
	return  maxi[x];
}
int main()
{
	ll n,m,x,y;
	cin>>n>>m;
	for(ll i=0;i<m;i++)
	{
		cin>>x>>y;
		v[x].pb(y);
		in[y]=1;
	}
	ll ans=-ma;
	for(ll i=1;i<=n;i++)
	{
		maxi[i]=0;
		if(in[i]==0 && maxi[i]==0)
		{
			ans=max(ans,dfs(i));
		}
	}
	cout<<ans;
}



Measured memory_bytes: 11904
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i = 0; i < (n);++i)
#define repc(i,a,b) for(int i = (a);i <(b);++i)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef vector<int> vi ;
typedef vector<ll> vl ;

const int IMAX = ((1<<30)-1)*2+1 ;
const int INF = 100000000;
double EPS = 1e-10 ;

int main(){
  char c;
  int w,n,a,b,num ;
  bool flag = true;
  cin >> w >> n;
  vi v(w,0),va,vb ;
  rep(i,n){
    cin >> a >> c >> b ;
    va.pb(a),vb.pb(b) ;
  }

  rep(i,w){
    num = i+1 ;
    rep(j,n){
      if(num == va[j]){
        num = vb[j];
      }
      else if(num == vb[j]){
        num = va[j];
      }
    }
    v[num-1] = i+1;
  }
  for(int i = 0;i < v.size();++i){
    cout << v[i] << endl;
  }
  return 0;
}

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

int main(){
  int N,L;cin>>N>>L;
  vector<int>A(N);
  for(int i=0;i<N;i++) cin>>A.at(i);
  
  bool NG=true;
  int check;
  for(int i=0;i<N-1;i++){
    if(A.at(i)+A.at(i+1) >= L){
      NG=false;
      check=i+1;
      
    }
  }
  
  if(NG)
    cout<<"Impossible";
  else{
    cout<<"Possible"<<endl;
    for(int i=1;i<check;i++)
      cout<<i<<endl;
    for(int i=N-1;i>=check;i--)
      cout<<i<<endl;
  }
  
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for(long long a = 2; a * a <= N; ++a) {
        if(N % a != 0)
            continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while(N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if(N != 1)
        res.push_back({N, 1});
    return res;
}
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
    ll A, B;
    cin >> A >> B;
    ll GCD = gcd(A, B);
    const auto &res = prime_factorize(GCD);
    int ans = 1;
    for(auto p : res) {
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define mk make_pair
#define vec vector<int> 
#define finput ifstream cin;cin.open("in.txt")
#define foutput ofstream cout;cout.open("out.txt")
int main(){
	//finput;
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


	int n;
	cin>>n;
	if(n==1){
		cout<<"Hello World";
		return 0;
	}
	else{
		int a,b;
		cin>>a>>b;
		cout<<a+b;
		return 0;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    int N;
    cin >> N;
    int t[100001], x[100001], y[100001];
    for(int i = 1; i <= N; i++) cin >> t[i] >> x[i] >> y[i];
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    bool plan = true;
    for(int i = 1; i <= N; i++){
        if((t[i]-t[i-1])%2 == 1){
            int move = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
            if(move > (t[i]-t[i-1]) || move%2 == 0){
                plan = false;
            }
        }

        else {
            int move = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
            if(move > (t[i]-t[i-1]) || move%2 == 1){
                plan = false;
            }
        }
    }
    if(plan) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 4752
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s1, s2;
    s1 = sc.next();
    s2 = sc.next();
    int n = s1.length();
    int count = 0;
    for(int i = 0; i < n; ++i){
      if(s1.charAt(i) == s2.charAt(n - 1 - i)){
        ++count;
      }
      else break;
    }
    if(count == 3)System.out.println("YES");
    else System.out.println("NO");
  }
}

Measured memory_bytes: 22740
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long n = sc.nextLong();
		long k = sc.nextLong();
		
		ArrayList<Integer> a = new ArrayList<>();
		ArrayList<Integer> x = new ArrayList<>();
		
		for(int i=0;i<n;i++) {
			a.add(sc.nextInt());
		}
		for(int i=0;i<n;i++) {
			x.add(sc.nextInt());
		}
		Collections.sort(a);
		Collections.sort(x);
		
		//String s = sc.next();

		//String[] ss = s.split("");

		//int[] a = new int[n];
		
		long upper  = (long)a.get(a.size()-1)*x.get(x.size()-1);
		long lower = -1;
		
		while(upper>lower+1) {
			long target = lower + (upper-lower)/2;
			long counter = 0;
			
			for(int i=0;i<n;i++) {
				long max = target/x.get((int) (n-1-i));
				if(a.get(i)>max) {
					counter += a.get(i)-max;
				}
			}
			if(counter>k) {
				lower = target;
			}else {
				upper = target;
			}
		}
		
		long ans = lower+1;
		
		System.out.println(ans);

		/*
		TreeMap<Integer,Integer> treeMap = new TreeMap<>();//sorted no duplication
		treeMap.put(b[n], n);
		*/

	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 110924
#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() {
  string N;
  cin >> N;
  int ans = 0;
  
  rep(i, N.size()){
   ans += N.at(i)-'0' ;
   ans %= 9;
  }
  if(ans%9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;


int main(){
	while(1){
		string s; cin >> s;
		if(s=="#")break;
		int n=s.size();
		bool ok=false;
		for(int i=0;i<n;i++){
			if(s[i]=='('){
				i++;
				set<char> a,b;
				while(s[i]!=')'){
					if(s[i]=='~'){
						i++;
						b.insert(s[i]);
						i++;
					}
					else if(s[i]=='&')i++;
					else{
						a.insert(s[i]);
						i++;
					}
				}
				bool che=true;
				for(auto p:a){
					if(b.find(p)!=b.end()){
						che=false;
						break;
					}
				}
				ok=che;
			}
			if(ok)break;
		}
		if(ok){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3172
//By RKO 
//--------------------------------------------------------------------------
//NEVER GIVE UP!! THE BEST IS YET TO COME!! JUST KEEP GOING
//--------------------------------------------------------------------------
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n" 
#define ll long long
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
signed main() {
	// your code goes here
	int t=1; //cin>>t;
	while(t--)
	{
	    int n,k; cin>>n>>k;
	    int wt[n+1]={0},val[n+1]={0};
	    for(int i=0;i<n;i++) {
	    	cin>>wt[i]>>val[i];
	    }
	    int dp[k+1];
	    memset(dp, 0, sizeof(dp));
	    for(int i=0;i<n;i++)
	    {
	    	for(int j=k;j>=wt[i];j--)
	    	{
	    		dp[j]=max(dp[j],val[i]+dp[j-wt[i]]);
	    	}
	    }
	    cout<<dp[k];
	}
	
	return 0;
}

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

main()
{


    int n; cin>>n;
    long long ans=1;
    long long inf=1e18;
    bool flag=false;
    bool flag2=false;
    while(n--)
    {
        long long a;
        cin>>a;
        if(!a) flag=true;
        if(ans and inf/ans<a)
        {
            flag2=true;
        }
        else ans*=a;
    }

    if(!flag2 or flag) cout << ans << "\n";
    else cout << -1 << "\n";
}

Measured memory_bytes: 3636
#include <stdio.h>

main(){
  double x1, y1, x2, y2, x3, y3, x4, y4;
  int i, n;
  double tan1, tan2;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
    tan1=(y1-y2)/(x1-x2);
    tan2=(y3-y4)/(x3-x4);
    if(tan1==tan2) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main
{

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

        int S = scan.nextInt();
        int h = S / 3600;
        S = S - 3600 * h;
        int m = S / 60;
        int s = S - 60 * m;
        System.out.print(h);
        System.out.print(":");
        System.out.print(m);
        System.out.print(":");
        System.out.println(s);
    }
}



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

int main(int argc, char* argv[]) {
  int N, L;
  int tot = 0, minabs;
  cin >> N >> L;
  minabs = abs(L);
  for (int i = 1; i <= N; i++) {
    int taste = (L + i - 1);
    tot += taste;
  }
  if (L > 0)
    cout << (tot - L) << endl;
  else if (L <= 0 && L + N - 1 >= 0)
    cout << tot << endl;
  else  //(L+N-1 < 0)
    cout << (tot - (L + N - 1)) << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%d", $k);

$length = strlen($s);
$memo = [];
$substrs = [];
for ($i = 0; $i < $length; $i++) {
	$string = "";
	for ($len = $i; $len < $i + 5; $len++) {
		$string = $string . $s[$len];
		$substrs[$string] = $string;
	}
	//echo $i, "\n";
}
usort($substrs, function ($strA, $strB) {
	return strnatcmp($strA, $strB);
});
echo $substrs[$k-1], "\n";

Measured memory_bytes: 6648
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int main ()
{
    int N,M;
    cin >> N >> M;
    vector < int > A(N);
    REP(i,N) cin >> A[i];
    vector < pair < int, int > > BC(M);
    REP(i,M) cin >> BC[i].second >> BC[i].first;

    sort(A.begin(), A.end());
    sort(BC.begin(), BC.end());
    reverse(BC.begin(), BC.end());

    int idx = 0;
    REP(i,A.size()) {
        if (BC[idx].second == 0) {
            idx++;
            if (idx == BC.size()) {
                break;
            }
        } 
        if (A[i] < BC[idx].first) {
            A[i] = BC[idx].first;
            BC[idx].second--;
        }
    }

    ll sum = 0;
    REP(i,A.size()) {
        sum += (ll)A[i];
        cerr << A[i] << " ";
    }
    cerr << endl;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1408
N = gets.chomp.to_i
s = []
N.times do
  s << gets.chomp
end

h = {}
s.each do |ss|
  sorted_s = ss.chars.sort.join
  h[sorted_s] ||= 0
  h[sorted_s] += 1
end
  
r = 0
h.each do |_, v|
  if v >= 2
    r += v * (v - 1) / 2
  end
end

p r

Measured memory_bytes: 24700
params0 = list(map(lambda x: int(x), input().split(' ')))
paramN, paramM = params0
paramsH = list(map(lambda x: int(x), input().split(' ')))
ways = []
for i in range(paramM):
    p = list(map(lambda x: int(x), input().split(' ')))
    ways.append([p[0], p[1]])
    ways.append([p[1], p[0]])

spots = [True for i in range(paramN)]

for way in ways:
    if paramsH[way[0] - 1] <= paramsH[way[1] - 1]:
        spots[way[0] - 1] = False

print(len(list(filter(lambda x: x, spots))))

Measured memory_bytes: 37968
#include <stdio.h>
#include <ctype.h>
  
#define MAX 100000
#define _MAX 1500000
 
int par[MAX];
  
void init(int);
int depth(int);
int input(void);
 
char *p;
char in[_MAX];
int tree[MAX][15],idx[MAX];
 
int main(){
  int n,i,j,id,k,c;
 
  fread(in,sizeof(in),1,stdin);  
  p = in;
 
  n = input(); init(n);
  for(i = 0 ; i < n ; i++){
    id = input();
    k = input();
    for(j = 0 ; j < k ; j++){
      c = input();
      par[c] = id;
      tree[id][idx[id]++] = c;
    }
  }
  
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, depth = %d, "
           ,i,par[i],depth(i));
     
    if(par[i] == -1){
      printf("root, [");
    }else if(!idx[i]){
      printf("leaf, [");
    }else{
      printf("internal node, [");
    }
 
    for(j = 0 ; j < idx[i] ; j++){
      printf("%d",tree[i][j]);
      if(j < idx[i]-1) printf(", ");
    }
    puts("]");
  }
  return 0;
}
 
void init(int n){
  int i;
  for(i = 0 ; i < n ; i++){
    par[i] = -1;
  }
}
 
int depth(int x){
  if(par[x] == -1) return 0;
  return depth(par[x]) + 1;
}
 
int input(){
  int v = 0;
  while(!isdigit(*p)) ++p;
  v = *p++&15;
  while(isdigit(*p)){
    v = (v<<3)+(v<<1)+(*p++&15);
  }
  return v;
}



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

typedef long long ll; 
typedef vector<int> veci;

int main()
{
    int n;
    cin>>n;
    vector<bool>e(n+1);
    e.at(1)=true;
    for(int b=2;b<=sqrt(n)+1;b++){
      int t=b*b;
      while(t<=n){
        
        e.at(t)=true;
        t*=b;
        }
        
      }
      for(int i=n;i>0;i--){
       if(e.at(i)){
       cout<<i<<endl;
       break;
       }
       }
return 0;
}


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

using namespace std;

long long M = 1000*1000*1000 + 7;

int main () {
  long long n, m;
  cin >> n >> m;
  if (n - m > 1 || m - n > 1){
    cout << '0';
    return 0;
  }
  long long ans = m == n ? 2 : 1;
  for(int i = 1;i<= n;i++){
    ans *= i;
    ans %= M;
  }
  for(int i = 1;i<= m;i++){
    ans *= i;
    ans %= M;
  }
  cout << ans;
}


Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

int main(){
  startupcpp();
  int i,N;
  ll ans=0;
  cin>>N;
  vector<int> a(N),b(N);
  priority_queue<pair<int,int>> que;
  rep(i,N)cin>>a[i];
  rep(i,N){
    cin>>b[i];
    if(a[i]>b[i]){
      print(-1);
      return 0;
    }
    if(a[i]<b[i])que.push(pair<int,int>(b[i]-a[i],i));
  }
  while(!que.empty()){
    auto x=que.top();que.pop();
    i=b[(x.second+1)%N]+b[(x.second+N-1)%N];
    if(i>x.first){
      print(-1);
      return 0;
    }
    ans+=x.first/i;
    x.first%=i;
    b[x.second]=x.first+a[x.second];
    if(x.first)que.push(x);
  }
  print(ans);
}

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

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

ll fgcd(ll a,ll b, vector<vector<ll>> &dp){
    if(dp[a-1][b-1]==-1){
        dp[a-1][b-1]=gcd(a,b);
    }    
    return dp[a-1][b-1];
}

int main(){
    ll K;
    cin>>K;
    ll ans=0;
    vector<vector<ll>> dp(K, vector<ll> (K, -1));
    for(ll i=1;i<=K;i++){
        for(ll j=1;j<=K;j++){
            for(ll k=1;k<=K;k++){
                ans+=fgcd(fgcd(i,j,dp),k,dp);
            }
        }
    }
    cout<<ans;
}
    

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

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> cnt(3,0);
    for(int i=0; i<N; i++){
        int p;  cin >> p;
        if(p <= A) cnt[0]++;
        else if(p <= B) cnt[1]++;
        else cnt[2]++;
    }

    int ans = 101;
    for(int i=0; i<3; i++) ans = min(ans,cnt[i]);
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        for (int i = 1; i < 10; i++)
        {
            for (int j = 1; j < 10; j++)
            {
                Console.WriteLine(string.Format("{0}x{1}={2}", i, j, i * j));
            }
        }
    }
}

Measured memory_bytes: 9012
#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};

signed main() {
int n,m;
cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
int p[3]={},t,s;long long ans=1;
for(int i=0;i<n;i++){
    t=0;s=3;
   if(p[2]==a[i]){
       t++;
       s=min(s,2);
   }
   if(p[1]==a[i]){
       t++;
       s=min(s,1);
   }
   if(p[0]==a[i]){
       t++;
       s=min(s,0);
   }
   if(s!=3)p[s]++;
   ans=(ans*t)%MOD;
}
cout<<ans;
return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int N,M;
  cin>>N;
  vs s(N);rep(i,N)cin>>s[i];
  cin>>M;
  vs t(M);rep(i,M)cin>>t[i];
  sort(all(s));sort(all(t));
  set<string> se;
  rep(i,N)se.insert(s[i]);
  int ans=0;
  for(auto x:se){
    int cnt=0;
    for(int i=0;i<N;i++){
      if(x==s[i])cnt++;
    }
    for(int i=0;i<M;i++){
      if(x==t[i])cnt--;
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI                \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
//int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

#define ordered_set tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update>

int fun(int x, int d)
{
	if (x <= 0)
		return 0;
	int ans = (x / d);
	return ans;
}
int32_t main()
{
	AB_BHI_NI_DEGI
	//freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	//cout.precision(20);
	//cout << fixed;
	int ans = 0;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		if (x % 2 and i % 2)
			ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3648
// c++ -std=c++14 atcoder.cpp
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
    }
    if (a[n-m] >= sum/4.0/m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N,D;
  cin >> N >> D;
  vector<vector<int>> X(N,vector<int>(D));

  for(int i=0;i<N;++i){
    for(int j=0;j<D;++j) cin >> X.at(i).at(j);
  }

  int ans=0;
  
  for(int i=0;i<N;++i){
    for(int j=i+1;j<N;++j){
      double sum=0;
      for(int d=0;d<D;++d) sum+=pow(X.at(i).at(d)-X.at(j).at(d),2);
      sum=sqrt(sum);
      if(sum==(int)sum) ++ans;
    }  
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()
typedef complex<double> P;
typedef vector<P> VP;

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}
double getarea(const VP &poly){
    double ret = 0;
    for (int i=0; i<(int)poly.size(); i++){ 
        ret += cross(poly[i], poly[(i+1)%poly.size()]);
    }
    return ret*0.5;
}

int main(){
    while(1){
        int n,m,w,h,s;
        cin >> n >> m >> w >> h >> s;
        if(n==0) break;

        vector<double> l(m+1, 0), r(m+1, 0);
        for(int i=1; i<=m; i++){
            cin >> l[i] >> r[i];
        }
        VP p(n);
        for(int i=0; i<n; i++){
            double x,y;
            cin >> x >> y;
            p[i] = P(x, y);
        }

        vector<double> area(m+1, 0);
        for(int i=1; i<=m; i++){
            VP poly = {P(0, l[i-1]), P(w, r[i-1]), P(w, r[i]), P(0, l[i])};
            area[i] = getarea(poly);
            area[i] += area[i-1];
        }
        vector<int> num(m+1, 0);
        for(int i=0; i<n; i++){
            int ub=m, lb=0;
            while(lb +1 < ub){
                int mid = (lb +ub)/2;
                if(ccw(P(0, l[mid]), P(w, r[mid]), p[i]) == 1){
                    lb = mid;
                }else{
                    ub = mid;
                }
            }
            num[ub]++;
        }
        for(int i=0; i<m; i++){
            num[i+1] += num[i];
        }

        int ans = 1e9;
        for(int i=0; i<m; i++){
            if(area[i] +EPS >= s){
                ans = min(ans, num[i]);
                break;
            }
            int lb=i, ub=m;
            while(lb +1 < ub){
                int mid = (lb +ub)/2;
                if(h*w -(area[mid] -area[i]) +EPS > s){
                    lb = mid;
                }else{
                    ub = mid;
                }
            }
            ans = min(ans, n-(num[lb] -num[i]));
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4272
n = int(input())
s = input()
a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = ''

for i in range(len(s)):
    idx = a.index(s[i])
    #print('idx:', idx)
    target = a[(idx + n)%26]
    #print('target:', target)
    ans += target

print(ans)




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

int main(){
	int n;
	cin>>n;
	lp(z,n){
		int a,b=0,count=0;
		cin>>a;
		vector<int> lis;
		while(1){
			if(a/10==0) break;
			int i=1;
			while(1){
				if(a/10==0) break;
				b+=a%10*i;
				a/=10;
				lis.push_back(b*a);
				i*=10;
			}
			b=0;
			sort(lis.begin(),lis.end());
			reverse(lis.begin(),lis.end());
			a=lis[0];
			lis.clear();
			count++;
		}
		cout<<count<<endl;
	}
	return 0;
}


Measured memory_bytes: 3152