akhauriyash/Code-Regression huggingface dataset:
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
  ll ans = 0;
  map<ll,ll> mp;
  rep(i,N) mp[A[i]] += 1;
  rep(i,M){
    mp[C[i]] += B[i]; 
  }
  ll now = 0;
  for(auto itr=mp.rbegin();itr!=mp.rend();itr++){
    ll t = itr->first;
    ll cnt = itr->second;
    ans += t*min(N-now,cnt);
    now += min(N-now,cnt);
    if(now==N) break;
  }
  cout << ans << endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  std::vector<long long> B(M);
  std::vector<long long> C(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&B[i]);
    scanf("%lld",&C[i]);
  }
  solve(N, M, std::move(A), std::move(B), std::move(C));
  return 0;
}


Measured memory_bytes: 17152
# -*- coding: utf-8 -*-

def main():
    dictionary = {}
    input_num = int(raw_input())
    counter = 0
    while counter < input_num:
        command, key = raw_input().split(' ')
        if command[0] == 'i':
            dictionary[key] = True
        else:
            if key in dictionary:
                print 'yes'
            else:
              print 'no'

        counter += 1


if __name__ == '__main__':
    main()

Measured memory_bytes: 32988
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int solve() {
    int n; cin>>n;
    int h[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>h[i];
    }
    vi v; int a=0;
    for (int i = 1; i < n; ++i)
    {
        if(h[i]<=h[i-1]) a++;
        else{
            v.pb(a);
            a=0;
        }
    }
    v.pb(a);
    sort(all(v));
    int t=v.size()-1;
    cout<<v[t];
    return 0;
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 2168
N, M, X = input().split()
N = int(N)
M = int(M)
X = int(X)
A = input().split()
A = [int(A[i]) for i in range(M)]
A.append(X)
A = sorted(A)
if M/2 > A.index(X):
  print(A.index(X))

elif  M/2 < A.index(X):
  print(int(M-A.index(X)))

Measured memory_bytes: 9156
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt() - 1;
    int b = sc.nextInt() - 1;
    String[][] grid = new String[100][100];
    for(int i = 0; i < 50; i++) {
      for(int j = 0; j < 100; j++) {
        grid[i][j] = ".";
      }
    }
    for(int i = 50; i < 100; i++) {
      for(int j = 0; j < 100; j++) {
        grid[i][j] = "#";
      }
    }
    for(int i = 0; i < 50; i += 2) {
      for(int j = 0; j < 100; j += 2) {
        if(b > 0) {
          b--;
          grid[i][j] = "#";
        }
      }
    }
    for(int i = 51; i < 100; i += 2) {
      for(int j = 0; j < 100; j += 2) {
        if(a > 0) {
          a--;
          grid[i][j] = ".";
        }
      }
    }
    System.out.println(100 + " " + 100);
    for(int i = 0; i < 100; i++) {
      String ans = "";
      for(int j = 0; j < 100; j++) {
        ans += grid[i][j];
      }
      System.out.println(ans);
    }
  }
}


Measured memory_bytes: 30420
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using ll = long long;
template <class T>
ostream& operator<<(ostream& output, const vector<T>& v) {
	for (const auto& i : v) output << i << " ";
	return output;
}
int main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> s(H);
	vector<int> num(H);
	vector<vector<int>> ans(H, vector<int>(W, 0));
	int index = 1;
	for (int i = 0; i < H; i++) {
		cin >> s[i];
		num[i] = count(s[i].begin(), s[i].end(), '#');
	}
	vector<int> e;
	for (int i = 0; i < H; i++) {
		if (num[i] == 0) e.push_back(i);
		else {
			int cnt = 0;
			for (int j = 0; j < W; j++) {
				ans[i][j] = index;
				if (num[i] > 1 && s[i][j] == '#') {
					cnt++;
					if (cnt != num[i]) index++;
				}
			}
			index++;
		}
	}
	for (auto i : e) {
		int u = i, d = i;
		while (u >= 0 && num[u] == 0) u--;
		while (d < H && num[d] == 0) d++;
		if (u != i && u >= 0) ans[i] = ans[u];
		else if (d != i && d < H) ans[i] = ans[d];
	}
	for (const auto& v : ans) {
		cout << v << endl;
	}
}


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


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


void dfs(vector<vector<int> > &g,int start,vector<int> &ans,vector<bool> &seen){
seen[start]=true;

for(auto next:g[start]){
  if(seen[next]) continue;
ans[next]+=ans[start];
  dfs(g,next,ans,seen);
}

}


int main(){
int n,q;
cin>>n>>q;
vector<bool> seen;
vector<int> ans;
rep(i,n){
  ans.push_back(0);
  seen.push_back(false);
}
vector<vector<int>> G(n);
rep(i,n-1){
  int a,b;
  cin>>a>>b;
  G[a-1].push_back(b-1);
  G[b-1].push_back(a-1);
}
rep(i,q){
  int A,B;
  cin>>A>>B;
  ans[A-1]+=B;
}
 
dfs(G,0,ans,seen);
rep(i,n){
  cout<<ans[i]<<" ";
}

  return 0;
}


Measured memory_bytes: 29812
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 100000000;

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}

int factrial(int n){
    if(n==0){
        return 1;
    }else{
        return n*factrial(n-1);
    }
}

int main(void){
    int n;
    cin >> n;
    if(n<1000){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }
    return 0;
}

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

using namespace std;

int get (int x) {
	int res = 0;
	while (x) {
		res += x % 10;;
		x /= 10;
	}
	return res;
}

int main () {	
	int n;
	cin >> n;
	int ans = 1e9 + 7;
	for (int i = 1;i < n;i ++) {
		int first = i;
		int second = n - i;
		ans = min (ans, get (first) + get (second));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <vector>

int main() {
  size_t H, W, D;
  scanf("%zu %zu %zu", &H, &W, &D);

  std::vector<int> h(H*W+1), w(H*W+1);
  for (size_t i=1; i<=H; ++i) {
    for (size_t j=1; j<=W; ++j) {
      int a;
      scanf("%d", &a);
      h[a] = i;
      w[a] = j;
    }
  }

  std::vector<std::vector<int>> d(D);
  d[0].emplace_back(0);
  for (size_t i=1; i+D<=H*W; ++i) {
    // x -> x+D
    d[i%D].emplace_back(std::abs(h[i]-h[i+D])+std::abs(w[i]-w[i+D]));
  }

  std::vector<std::vector<int>> dd(D);
  for (size_t i=0; i<D; ++i) {
    dd[i].emplace_back(0);
    for (int d_ij: d[i])
      dd[i].emplace_back(dd[i].back()+d_ij);
  }

  // for (size_t i=0; i<D; ++i) {
  //   for (size_t j=0; j<dd[i].size(); ++j) {
  //     fprintf(stderr, "%d%c", dd[i][j], j+1<dd[i].size()? ' ':'\n');
  //   }
  // }

  int Q;
  scanf("%d", &Q);
  for (int i=0; i<Q; ++i) {
    int L, R;
    scanf("%d %d", &L, &R);

    // fprintf(stderr, "(%zd %zd)\n", R/D, L/D);
    printf("%d\n", dd[R%D][R/D]-dd[L%D][L/D]);
  }
}


Measured memory_bytes: 8192
package main

import "fmt"

func main() {
	var N int
	var S string

	fmt.Scan(&N)
	fmt.Scan(&S)

	vw, ve := make([]int, N+1), make([]int, N+1)

	for i, v := range S {
		vw[i+1] = vw[i]
		ve[i+1] = ve[i]
		if string(v) == "W" {
			vw[i+1]++
		} else {
			ve[i+1]++
		}
	}

	ans := 1 << 32
	for i := 0; i < N; i++ {
		cur := vw[i] + (ve[N] - ve[i+1])
		if cur < ans {
			ans = cur
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7168
#include<stdio.h>
#include<string.h>
main(){
  char str[100];
  int i,j,l,scr=0,by,sum=0;
  while(scanf("%s",str)!=EOF){
  l=strlen(str);
  for(i=l-1;i>=0;i--){
    if(str[i]>='0'&&str[i]<='9'){
      by=1;
      scr+=str[i]-48;
      for(j=i-1;j>=0;j--){
	if(str[j]>='0'&&str[j]<='9'){
	  by*=10;
	  scr+=(str[j]-48)*by;
	}
	else {
	loop:
	  i=j;
	  break;
	}
	if(j==0){
	  goto loop;
	}
      }
    }
    sum+=scr;
    scr=0;
  }
  }
  printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=2e5+100;
const int mod=1e9+7;
bool judge(int x)
{
	if(x<=1)return 0;
	else if(x==2)return 1;
	int up=sqrt(x);
	for(int i=2;i<=up;i++)	
		if(x%i==0)return 0;
	return 1;
}
int prime[N];
int tot=0;
int cal(int n,int x)
{
	//cout<<n<<" "<<x<<endl;
	if(n<x)return 0;
	return (n/x+cal(n/x,x))%mod;
}
int main()
{
	int n;
	while(cin>>n)
	{
		tot=0;
		for(int i=1;i<=n;i++)
			if(judge(i))prime[++tot]=i;
		LL ans=1;
		for(int i=1;i<=tot;i++)
		{
			int x=prime[i];
			ans=(ans*(LL)(cal(n,x)+1))%mod;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
// ITP1_6_B Finding Missing Cards
import java.io.*;

public class Main {
   private static boolean[][] cards = new boolean[4][13];
   private static String[] suit = {"S", "H", "C", "D"};

   public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         int n = Integer.parseInt(br.readLine());
         if (n <= 52 && n >= 0) {
            for (int i = 0; i < n; i++) {
               String str[] = (br.readLine()).split(" ");

               if (str[0].equals(suit[0]))
                  cards[0][Integer.parseInt(str[1]) - 1] = true;
               else if (str[0].equals(suit[1]))
                  cards[1][Integer.parseInt(str[1]) - 1] = true;
               else if (str[0].equals(suit[2]))
                  cards[2][Integer.parseInt(str[1]) - 1] = true;
               else if (str[0].equals(suit[3]))
                  cards[3][Integer.parseInt(str[1]) - 1] = true;
               else
                  System.exit(1);
            }

            for (int i = 0; i < 4; i++) {
               for (int j = 0; j < 13; j++) {
                  if (cards[i][j] == false)
                     System.out.printf("%s %d\n", suit[i], j + 1);
               }
            }
         }
      }
      catch (Exception e) {
         System.out.println(e);
      }
   }
}

Measured memory_bytes: 16968
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a, b, c = sc.nextInt
    var count = 0
    for (i <- a to b){
      if (c%i == 0) count += 1
    }
    println(count)
  }
}

Measured memory_bytes: 45024
def find():
    h,w,m=map(int,input().split())
    idx=[]


    for i in range(m):
      var=list(map(int,input().split()))
      idx.append(var)


    r={}
    c={}
    #maze=[[0 for j in range(w)]for i in range(h)]
    mz={}

    for i in idx:
      mz.setdefault((i[0]-1,i[1]-1),0)
      mz[(i[0]-1,i[1]-1)]=1
      #maze[i[0]-1][i[1]-1]=1
      r.setdefault(i[0]-1,0)
      r[i[0]-1]+=1
      c.setdefault(i[1]-1,0)
      c[i[1]-1]+=1

    ans=0
    maxval=0



    row=[]
    col=[]
    maxr=max(r.values())
    maxc=max(c.values())
    for i in range(h):
      r.setdefault(i,0)
      if r[i]==maxr:
        row.append(i)
      

    for j in range(w):
      c.setdefault(j,0)
      if c[j]==maxc:
        col.append(j)
    
    for i in row:
      for j in col:
        mz.setdefault((i,j),0)
        if(mz[(i,j)]==0):
          return maxc+maxr
         
    return maxc+maxr-1
 
print(find())

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

int main(){
  string S;
  cin >> S;
  int64_t sum=0, size, flag=0, save=0;
  size = S.size();
  
  vector<int> A(size);
  for(int i=0;i<size;i++){
    A.at(i) = (S.at(i) - '0');
  }
  
  for(int tmp=0;tmp < (1 << 10);tmp++){
    bitset<10> p(tmp);
    if(p.test(size-1))
      break;
    for(int i=0;i<size-1;i++){
      if(p.test(i)){
        while(flag > 0){
          save += A.at(i-flag);
          save *= 10;
          flag--;
        }
        save += A.at(i);
        sum += save;
        save = 0;
      }else{
        flag++;
      }
    }
    while(flag > 0){
      save += A.at(size-1-flag);
      save *= 10;
      flag--;
    }
    save += A.at(size-1);
    sum += save;
    save = 0;
  }
  cout << sum << endl;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


#define INFTY 0x7fffffffffffffffLL // -N min(c_i) より大きければよい

void solve(int N,int M,vi& a,vi& b,vi& c) {
    vector<ll> dist(N, INFTY);
    dist[0] = 0;

    // すべての辺を使った更新をN-1回。
    // (ループなしでゴールに届く経路は長さN-1なはず)
    rep(loop, N-1) {
        rep(i, M){
            int u = a[i]-1, v = b[i]-1, d = -c[i];

            if (dist[u] == INFTY) continue;

            if (dist[u] + d < dist[v]) {
                dist[v] = dist[u] + d;
            }
        }
    }
    ll ans = dist[N-1]; // 距離は求まっているはず


    vector<bool> negative(N, false);
    // さらにN回の更新。
    // (ループがあるとしたらその長さは高々Nなはず)
    rep(loop, N) {
        rep(i, M) {
            int u = a[i]-1, v = b[i]-1, d = -c[i];

            if (dist[u] == INFTY) continue;

            // 更新が発生するということは負閉路がある
            // 辺(u,v)は負閉路を構成する辺の1つ
            if (dist[u] + d < dist[v]) {
                dist[v] = dist[u] + d;
                negative[v] = true;
            }
            // そうでなくても負閉路から来てるなら
            else if (negative[u] == true) {
                negative[v] = true;
                // vより前に負閉路ぐるぐるを無限挿入できるってことだよね
            }
        }
    }

    if (negative[N-1])
        cout << "inf" << endl;
    else
        cout << -ans << endl;
}

int main() {
    int N, M; cin >> N >> M;
    vi a(M), b(M), c(M);
    rep(i, M){
        cin >> a[i] >> b[i] >> c[i];
    }
    solve(N,M,a,b,c);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int dp[3001][3001];

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

    for (int i=0; i < s.length(); i++)
        dp[i][0] = 0;
    for (int i=0; i < t.length(); i++)
        dp[0][i] = 0;

    for (int i=1; i <= s.length(); i++)
        for (int j=1; j <= t.length(); j++) {
            if (s[i-1] == t[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    char res[dp[s.length()][t.length()]+1] = {'\0'};
    int cur = dp[s.length()][t.length()];
    cur--;
    if (cur < 0) {
        cout<<endl;
        return 0;
    }
    int i = s.length(), j = t.length();
    while(1) {
        if(s[i-1] == t[j-1]) {
            res[cur--] = s[i-1];
            i--; j--;
            if (cur < 0)
                break;
        }
        else {
            if (dp[i-1][j] > dp[i][j-1])
                i--;
            else
                j--;
        }
    }
    printf("%s\n", res);
    return 0;
}


Measured memory_bytes: 38828
//   __      __       .__           .____________                   __________        __ ________   __                 
//  /  \    /  \ ____ |_________  __| _\______   \__ __  ____  _____\______   \__ ___/  |\_____  \ |  | ______  ___.__.
//  \   \/\/   _/ __ \|  \_  __ \/ __ | |    |  _|  |  \/ ___\/  ___/|    |  _|  |  \   __/   |   \|  |/ \__  \<   |  |
//   \        /\  ___/|  ||  | \/ /_/ | |    |   |  |  / /_/  \___ \ |    |   |  |  /|  |/    |    |    < / __ \\___  |
//    \__/\  /  \___  |__||__|  \____ | |______  |____/\___  /____  >|______  |____/ |__|\_______  |__|_ (____  / ____|
//         \/       \/               \/        \/     /_____/     \/        \/                   \/     \/    \/\/     

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define PI 3.14159265358979323846

using namespace std;

void solve()
{
    ld a, b;
    cin >> a >> b;
    cout << (ll)(a * b) << endl;
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q = 1;
	//cin >> q;
	for(int i = 1; i <= q; i++)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3744
// /Code by : Harry_Singh/
#include<bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define F(i,n) for(int i=1;i<=n;i++)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n" 
#define N 205
// directions
int xx[5]={0,0,1,-1};
int yy[5]={1,-1,0,0};
vector<int > G[N],L[N];
 
 
void we_have_choices()
{

   int n;
   cin>>n;
   int a[n+1];
   F(i,n)cin>>a[i];
int c=0;
sort(a+1,a+n+1);
   for(int i=1;i<=n;i++)
   {
    for(int j=i+1;j<=n;j++)
    {
        for(int k=j+1;k<=n;k++)
        {
          if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i])
          if(a[i]+a[j]>a[k])++c;
        }
    }
   }

   cout<<c;

}



int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int t=1;
    while (t--)we_have_choices();
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>

using namespace std;

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

	int sum = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'o') {
			sum++;
		}
	}
	cout << 700 + sum * 100 << '\n';
	return 0;
}

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

using namespace std;

int main() {
    unsigned long long N; cin >> N;
    unsigned long long res = 0;
    
    for (long long i = 1; i < N; ++i) {
        long long tmp = N / i - 1;
        if (tmp == 0) break;
        if (N % tmp == N / tmp) {
            res += tmp;
        }
        if ((tmp + 1) < (N / tmp)) {
            break;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int k = 0;
    for(;;){
        int w, n;
        cin >> w >> n;
        if(w == 0)
            return 0;

        vector<int> price(w+1, -1);
        price[0] = 0;
        for(int i=0; i<n; ++i){
            int a, b;
            char c;
            cin >> a >> c >> b;
            for(int j=w-b; j>=0; --j){
                if(price[j] != -1)
                    price[j+b] = max(price[j+b], price[j] + a);
            }
        }

        int ret1 = 0, ret2;
        for(int i=0; i<=w; ++i){
            if(price[i] > ret1){
                ret1 = price[i];
                ret2 = i;
            }
        }
        cout << "Case " << (++k) << ':' << endl;
        cout << ret1 << endl << ret2 << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x;
	int ans=0;
	cin>>x;
	for(int iNow=1;iNow<=44722;iNow++)
	{
		ans+=iNow;
		if(ans==x)
		{
			cout<<iNow;
			break;
		}
		if(ans>x&&ans-iNow<x)
		{
			cout<<iNow;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;

class Point{
    int x, y;
    public Point(int x, int y){
        this.x = x;
        this.y = y;
    }
    public boolean equals(Object another){
        if(another instanceof Point){
            return this.x==((Point)another).x && this.y==((Point)another).y;
        }else return false;
    }
}

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int K = sc.nextInt();
        int x1 = sc.nextInt(), y1 = sc.nextInt();
        int x2 = sc.nextInt(), y2 = sc.nextInt();
        char[][] board = new char[H+2][W+2];
        Arrays.fill(board[0], '@');
        Arrays.fill(board[H+1], '@');
        for(int h=1; h<=H; h++){
            
            board[h][0] = '@';
            board[h][W+1] = '@';
            String line = sc.next();
            for(int w=1; w<=W; w++) board[h][w] = line.charAt(w-1);
            
        }

        int[][] shortest = new int[H+2][W+2];
        for(int h=0; h<=H+1; h++) for(int w=0; w<=W+1; w++){
            shortest[h][w] = 1000000000;
            shortest[x1][y1] = 0;
        }

        LinkedList<Point> toCheck = new LinkedList<>();
        toCheck.add(new Point(x1, y1));

        while(!toCheck.isEmpty()){
            Point p = toCheck.pop();
            for(int d=1; d<=K; d++){
                if(board[p.x+d][p.y]=='.'){
                    if(shortest[p.x][p.y]+1 < shortest[p.x+d][p.y]){
                        toCheck.addLast(new Point(p.x+d, p.y));
                        shortest[p.x+d][p.y] = 1+shortest[p.x][p.y];
                    }else if(shortest[p.x][p.y]+1 > shortest[p.x+d][p.y]) break;
                } else break;
            }
            for(int d=1; d<=K; d++){
                if(board[p.x-d][p.y]=='.'){
                    if(shortest[p.x][p.y]+1 < shortest[p.x-d][p.y]){
                        toCheck.addLast(new Point(p.x-d, p.y));
                        shortest[p.x-d][p.y] = 1+shortest[p.x][p.y];
                    }else if(shortest[p.x][p.y]+1 > shortest[p.x-d][p.y]) break;
                } else break;
            }
            for(int d=1; d<=K; d++){
                if(board[p.x][p.y+d]=='.'){
                    if(shortest[p.x][p.y]+1 < shortest[p.x][p.y+d]){
                        toCheck.addLast(new Point(p.x, p.y+d));
                        shortest[p.x][p.y+d] = 1+shortest[p.x][p.y];
                    }else if(shortest[p.x][p.y]+1 > shortest[p.x][p.y+d]) break;
                } else break;
            }
            for(int d=1; d<=K; d++){
                if(board[p.x][p.y-d]=='.'){
                    if(shortest[p.x][p.y]+1 < shortest[p.x][p.y-d]){
                        toCheck.addLast(new Point(p.x, p.y-d));
                        shortest[p.x][p.y-d] = 1+shortest[p.x][p.y];
                    }else if(shortest[p.x][p.y]+1 > shortest[p.x][p.y-d]) break;
                } else break;
            }
        }

        System.out.println(shortest[x2][y2] > 10000000 ? -1 : shortest[x2][y2]);
    }
}


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

static const int INF = 2000000000;

int main() {
    int n, R[210000];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> R[i];
    
    int maxv = -INF;
    int minv = R[0];
    
    for (int i = 1; i < n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    cout << maxv << endl;
    return 0;
}



Measured memory_bytes: 3840
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>


int main(){
    int N;
    long long int A[2000001];
    long long int cnt[2000001];
    long long int tbl[2000001];
    long long int sum=0;

    scanf("%d",&N);
    for(int i = 1 ; i <= N ; i++){
      cnt[i] = 0;
      tbl[i] = 0;
    }
    for(int i = 1 ; i <=  N ; i++){
      scanf("%lld",&A[i]);
      cnt[A[i]]++;
    }
    for(int i = 1 ; i <= N ; i++){
      tbl[i] = cnt[i] * (cnt[i] - 1 ) / 2;
      sum += tbl[i];
    }
    for(int i = 1 ; i <= N ; i++){
      printf("%lld\n", sum - cnt[A[i]] + 1);
    }
    return 0;
}


Measured memory_bytes: 9344
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef unsigned long long ll;
#define endl '\n'

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

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

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

	while (1) {
		int n; cin >> n;
		if (n == 0) { break; }
		vector<int> v(n, 0);
		for (int i = 0; i < n; i++) {
			string str; cin >> str;
			v[i] = str.size();
		}
		set<int> st;
		{
			int temp = 0;
			for (int i = 0; i < n; i++) {
				temp += v[i];
				st.insert(temp);
			}
		}
		int temp = 0;
		for (int i = 0; i < n; i++) {
			if (
				st.find(temp + 5) != st.end() &&
				st.find(temp + 12) != st.end() &&
				st.find(temp + 17) != st.end() &&
				st.find(temp + 24) != st.end() &&
				st.find(temp + 31) != st.end()
				) {
				cout << i + 1 << endl;
				break;
			}
			temp += v[i];
		}
	}

	return 0;
}


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

int main(int argc,char *argv[]){
	int H,W;
	while(1) {
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				cout << "#";
			}
			cout << "\n";
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 3032
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
   map<char,char> m;
   m['A']='T';
   m['T']='A';
   m['C']='G';
   m['G']='C';
   char c;
   cin>>c;
   cout<<m[c]<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e - a > k)
    cout << ":(" << endl;
  else
    cout << "Yay!" << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
mul_list = []
for i in range(1, n+1):
    if i <= n / i:
        if n % i == 0:
            mul = [i, n/i]
            mul_list.append(mul)
    else:
        break
length = 10000000000000
result = 0
for line in mul_list:
    dif = len(str(line[1]))-len(str(line[0]))
    if dif < length:
       result = len(str(int(line[1])))
print(result)    

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

int main(){
  int n,ans=0;
  cin >> n;
  int p[n];
  rep(i,n)
    cin >> p[i];
  for(int i = 1;i<n-1;i++){
    if(min(p[i-1],min(p[i],p[i+1]))!=p[i] && max(p[i-1],max(p[i],p[i+1])) != p[i])
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3556
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vit vector<lint>::iterator
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define mod 1000000007
#define graph_set(n) struct edge{int to,int cost;} vector<edge> G((n))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define range(x,y) ((x) >= 0 && (x) < h && (y) >= 0 && (y) < w)
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
typedef vector<long long> vi;
typedef vector<pair<long long, long long>> vp;
typedef vector<vector<long long>> vvi;
typedef pair<long long, long long> pi;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e14;

//////////////////////////////////////////////////////////////////////

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <cstring>
#include <cmath>
#include <math.h>
#include <algorithm>

using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;

#define EPS (1e-7)
#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()
#define tasu(x, y) (x+y)%MOD
#define kake(x, y) x*y%MOD

long gcd(long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long lcm( long m, long n ){
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	return ((m / gcd(m, n)) * n);
}


int main(){

	int N;
	cin >> N;
	std::vector<pair<int,int>> a;
	std::vector<pair<int,int>> a_abs;

	int sum =0;
	for(int i=0; i<N; i++){
		int a_;
		cin >> a_;
		a.push_back(make_pair(i,a_));
		sum+= a_;
	}

	for(int i=0; i<N; i++){
		int temp = a[i].second * N;
		a_abs.push_back(make_pair(abs(temp-sum), i));
	}

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


	cout << a_abs[0].second << endl;


	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (void)
{
int a[10]={};
int i;
for(i=0;i<10;i++)
scanf("%d",&a[i]);

int k,j;
for(i=0;i<9;i++)
for(k=0;k<9;k++)
if(a[k]<a[k+1]){
j=a[k];
a[k]=a[k+1];
a[k+1]=j;
}

for(i=0;i<3;i++){
printf("%d",a[i]);
putchar('\n');
}
return 0;
}

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

int main()
{
	int n;
	string s;
	cin>>n>>s;
	
	int pos=s.find("ABC",0);
	int sum=0;
	
	while(pos!=string::npos)
	{
		sum++;
		pos=s.find("ABC",pos+3);
	}
	
	cout<<sum<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int int_sort(const void *a, const void *b){
  if(*(int *)a < *(int *)b){
    return -1;
  }else if(*(int *)a == *(int *)b){
    return 0;
  }
  return 1;
}

int main(void){
  int n, *s, i, c=0, m=0, sum=0;
  scanf("%d",&n);
  s = malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&s[i]);
  qsort(s,n,sizeof(int),int_sort);
  for(i=0;i<n;i++){
    if(m!=s[i]){
      if(c>m) sum+=c-m; 
      else if(m>c) sum+=c;
      c=0; m=s[i];
    }
    c++;
  }
  if(c>m) sum+=c-m; 
  else if(m>c) sum+=c;
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 892
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>

#define rep(i,x,y) for (int i=x;i<=y;i++)
#define dep(i,y,x) for (int i=y;i>=x;i--)
#define sz(x) (int)(x.size())

using namespace std;

typedef long long LL; 
typedef unsigned long long uLL;

const int maxn=2000+7;

struct Edge{
 int v,next;
} E[maxn*maxn];

int n,m,Esize,p,q,last[maxn],a[maxn],s[maxn];
vector<int> v[maxn],temp;

bool vis[maxn];

int gcd(int x,int y) {return (y==0)?(x):(gcd(y,x%y));}

void addedge(int x,int y)
{
 E[++Esize]=(Edge){y,last[x]},last[x]=Esize;
 E[++Esize]=(Edge){x,last[y]},last[y]=Esize;
 // M[x][y]=M[y][x]=1;
}

void merge(int x,int y)
{
 temp.resize(sz(v[x]));
 rep(i,0,sz(v[x])-1) temp[i]=v[x][i];
 
 p=0,q=0,m=sz(temp)+sz(v[y]),v[x].resize(m);
 rep(i,0,m-1)
 {
  if (p>=sz(temp)) {v[x][i]=v[y][q],++q;continue;}
  if (q>=sz(v[y])) {v[x][i]=temp[p],++p;continue;}

  if (temp[p]>v[y][q]) v[x][i]=temp[p],++p; else v[x][i]=v[y][q],++q;
 }
}

void DFS(int k)
{
 vis[k]=1;
 for (int i=last[k];i;i=E[i].next)
 {
  int nxt=E[i].v;
  if (vis[nxt]) continue;

  DFS(nxt);
  merge(k,nxt);v[nxt].clear();
 }
 
 m=sz(v[k]);
 rep(i,0,m-1) s[i+1]=v[k][i];
 v[k].resize(m+1);
 v[k][0]=a[k];
 rep(i,1,m) v[k][i]=s[i];
}

int main()
{
 scanf("%d",&n);
 rep(i,1,n) scanf("%d",&a[i]);
 
 sort(a+1,a+n+1);
 rep(i,1,n/2) swap(a[i],a[n-i+1]);
 
 rep(i,1,n-1)
  rep(j,i+1,n)
   if (gcd(a[i],a[j])>1) addedge(i,j);
 
 memset(vis,0,sizeof(vis));
 dep(i,n,1)
  if (!vis[i])
  {
   DFS(i);
   merge(0,i);
  }
 
 rep(i,1,n-1) printf("%d ",v[0][i-1]);
 printf("%d\n",v[0][n-1]);

 // system("pause");
 return 0;
}


Measured memory_bytes: 36608
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inputAB = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int numberOfIncreaseOutletByOnePowerStrip = inputAB[0] - 1;
            int shortageOutlet = inputAB[1] - 1;
            int answer = (int)Math.Ceiling((double)shortageOutlet / (double)numberOfIncreaseOutletByOnePowerStrip);
            Console.WriteLine(answer.ToString());
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  vi P(2);
  rep(i,0,2) cin>>P[i];
  int N=S.size();
  bool flag=0;
  int count=0;
  vii A(2);
  rep(i,0,N){
    if(S[i]=='T'){
      A[flag].pb(count);
      count=0;
      flag=!flag;
    }
    else
      count++;
  }
  A[flag].pb(count);
  vi B(2);
  string ans="Yes";
  rep(i,0,2) B[i]=A[i].size();
  rep(i,0,2){
    vector<set<int>> T(B[i]+1);
    if(i==0){
    T[1].insert(A[i][0]);
    rep(j,1,B[i]){
      for(auto p:T[j]){
        T[j+1].insert(p+A[i][j]);
        T[j+1].insert(p-A[i][j]);
      }
    }
    }
    else{
      T[0].insert(0);
    rep(j,0,B[i]){
      for(auto p:T[j]){
        T[j+1].insert(p+A[i][j]);
        T[j+1].insert(p-A[i][j]);
      }
    }
    }
    if(!T[B[i]].count(P[i])){
      ans="No";
      break;
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 190720
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <string>
#include <utility>
#include <map> 
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>
#define MP make_pair
#define PB push_back
#define SZ size()
#define B begin()
#define E end()
#define ll long long
#define REP(i,a,n) for(ll i=a; i<n; ++i)
#define RED(i,n,a) for(ll i=n; i>=a; --i)
#define m9 1000000007
#define endl "\n"
#define F first
#define S second
#define ld long double
#define eps 0.00000000001
#define MAX 1000000007
#define vll vector <ll> 
#define pll pair <ll,ll> 

using namespace std;

ll gcd(ll a, ll b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}
ll powc(ll a, ll b){
    if(b<0){
        return -1;
    }
    ll res=1;
    while(b>0){
        if(b&1){
            res*=a;
        }
        a*=a;
        //res%=m9, a%=m9;
        b>>=1;
    }
    return res;
}



///target expert

int main(){
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x, k, d;
    cin>>x>>k>>d;
    ll dist =abs(x);
    ll mov= dist/d; ll mov2= (dist+d-1)/d;
    if(x<0){
        if(k<mov){
            cout<<abs(x)-d*k;
        }
        else{
            k-=mov;
            x=x+d*mov;
            if(k%2){
                cout<<x+d;
            }
            else{
                cout<<abs(x);
            }
        }
    }
    else if(x>0){
        if(k<mov){
            cout<<abs(x)-d*k;
        }
        else{
            k-=mov;
            x=x-d*mov;
            if(k%2){
                cout<<d-x;
            }
            else{
                cout<<abs(x);
            }
        }
    }
   else if(x==0){
        if(k%2){
            cout<<d;
        }
        else{
            cout<<0;
        }
    }
    
}

Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,tune=native")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 1000000007;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, cnt[100100];
int main() { //DINIC ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll ans = 1;
	cin >> n;
	vi a;
	a.resize(n);
	ll lft = 3;
	for(auto &i : a) cin >> i;
	for(int i = 0; i < n; i++) {
		cnt[a[i]]++;
		if(a[i]) {
			if(!cnt[a[i]-1]) return cout << 0, 0;
			ans *= cnt[a[i]-1];
			ans%=mod;
			cnt[a[i]-1]--;
		} else
			(ans*=lft--)%=mod;
	}
	cout << ans;
}



Measured memory_bytes: 1024
def ge(n):
    for i in xrange(n):
        yield [(i,j) for j in xrange(n)]
        yield [(j,i) for j in xrange(n)]
        yield [(j,i-j) for j in xrange(i+1)]
        yield [(n-1-i+j,n-1-j) for j in xrange(i+1)]
        yield [(j,n-1-i+j) for j in xrange(i+1)]
        yield [(n-1-i+j,j) for j in xrange(i+1)]

def f(L):
    ret,a = 0,0
    for i in L:
        if i == 0:
            ret = max(ret,a)
            a = 0
        else:
            a += 1
    return max(ret,a)

while True:
    n = input()
    if n == 0:
        break
    A = [map(int,list(raw_input())) for _ in xrange(n)]
    print max(map(f,[map(lambda (i,j): A[i][j], p) for p in ge(n)]))

Measured memory_bytes: 6876
n, k = map(int, input().split())
t = []
for _ in range(n):
    h = int(input())
    t.append(h)
t.sort()
m = 1145141919810
for i in range(0, n - k + 1):
    if m > t[i + k - 1] - t[i]:
        m = t[i + k - 1] - t[i]
print(m)

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

int main(){
  int a,b;
  cin >> a >> b;
  
  bool flag = 0;
  
  if(a%3 == 0) flag = 1;
  if(b%3 == 0) flag = 1;
  if((a+b)%3 == 0) flag = 1;
  
  if(flag) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

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

const int INF = 2e9+5;
const int MAX = 1e5+5;
using ll = long long int;
vector<int> vis(MAX,0), dp(MAX,0), deg(MAX,0);
void dfs(vector<vector<int>>& gr, int node, int par){
  	vis[node]=1;
  	for(auto i:gr[node]){
    	if(i!=par){
          dp[i]=max(dp[i],dp[node]+1);
          deg[i]--;
          if(deg[i]<=0)dfs(gr, i, node);
        }
    }
}
void solve(){
	int n,m;cin>>n>>m;
  	vector<vector<int>> gr(n+1);
  	rep(i,m){
    	int x,y;cin>>x>>y;
      	x,y;
      	gr[x].push_back(y);
      	deg[y]++;
    }
	foi(i,1,n+1){
    	if(!vis[i] && deg[i]==0) dfs(gr,i,0);
    }
  	cout<<*max_element(dp.begin(), dp.end());
}

int main(){
  solve();
  return 0;
}

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

int main(){
    int64_t n;
    cin >> n;
    string s;
    int64_t count[5] = {};
    for(int i=0; i<n; i++){
        cin >> s;
        if(s[0] == 'M'){
            count[0]++;
        }else if(s[0] == 'A'){
            count[1]++;
        }else if(s[0] == 'R'){
            count[2]++;
        }else if(s[0] == 'C'){
            count[3]++;
        }else if(s[0] == 'H'){
            count[4]++;
        }
    }

    int64_t ans = 0;
    ans += (count[0]*count[1]*count[2]);
    ans += (count[0]*count[1]*count[3]);
    ans += (count[0]*count[1]*count[4]);
    ans += (count[0]*count[2]*count[3]);
    ans += (count[0]*count[2]*count[4]);
    ans += (count[0]*count[3]*count[4]);
    ans += (count[1]*count[2]*count[3]);
    ans += (count[1]*count[2]*count[4]);
    ans += (count[1]*count[3]*count[4]);
    ans += (count[2]*count[3]*count[4]);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lb long double
#define eps 1e-10
using namespace std;
struct Po{lb x,y;}p;
struct circ{Po a;lb r;}q;
void get(Po &x){scanf("%Lf %Lf",&x.x,&x.y);}
lb dis(Po x){return sqrtl(x.x*x.x+x.y*x.y);}
Po operator -(Po x,Po y){return (Po){x.x-y.x,x.y-y.y};}
Po operator *(Po x,lb y){return (Po){x.x*y,x.y*y};}
Po operator /(Po x,lb y){return (Po){x.x/y,x.y/y};}
Po operator +(Po x,Po y){return (Po){x.x+y.x,x.y+y.y};}
lb operator ^(Po x,Po y){return x.x*y.x+x.y*y.y;}
Po zhuan(Po x,lb y){return (Po){x.x*cosl(y)-x.y*sinl(y),x.x*sinl(y)+x.y*cosl(y)};}
int main(){
	get(p);get(q.a);scanf("%Lf",&q.r);
	lb di=dis(p-q.a);
	lb a=acosl(q.r/di);
	Po z=(p-q.a)*(q.r/di);
	Po an1=q.a+zhuan(z,a),an2=q.a+zhuan(z,-a);
	if (an1.x>an2.x+eps||(fabs(an1.x-an2.x)<eps&&an1.y>an2.y+eps))swap(an1,an2);
	printf("%.10Lf %.10Lf\n%.10Lf %.10Lf\n",an1.x,an1.y,an2.x,an2.y);
	return 0;
}



Measured memory_bytes: 3532
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int A, B;
  cin >> A >> B;
  vector<int> C({A + B, A - B, A * B});
  sort(C.begin(), C.end());
  cout << C.back() << endl;
  return 0;
}

Measured memory_bytes: 256
def mod_com(n, k, mod):
    def ext_gcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d, x, y = ext_gcd(b, a % b)
            x -= (a // b)*y
        return d, y, x
    p, q = 1, 1
    for i in range(n - k + 1, n + 1):
        p = (p * i) % mod
    for i in range(2, k+1):
        q = (q * i) % mod
    return int(p * (ext_gcd(q, mod)[1] % mod) % mod)


n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
print((pow(2, n, mod) - 1 - mod_com(n, a, mod) - mod_com(n, b, mod)) % mod)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}


void solve(long long a, long long b){
    string ret, as, bs;
    as = to_string(a);
    bs = to_string(b);
    if(a<b) {
        for (ll i = 0; i < b; i++) {
            ret += as;
        }
    }else{
        for (ll i = 0; i < a; i++) {
            ret += bs;
        }
    }
    cout << ret << "\n";
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c < 22) cout << "win\n";
	else cout << "bust\n";
}



Measured memory_bytes: 256