akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


void solve(long long N, long long A, long long B){
    if(A==0){
        cout << 0 << endl;
        return;
    }
    if(N < A){
        cout << N << endl;
        return;
    }
    if(N <= A+B){
        cout << A << endl;
        return;
    }
    long long sum = A+B;
    long long devider = N/sum;
    long long countA = sum * devider - B * devider;
    long long remain = (N - sum * devider) > A ? A : (N - sum * devider);


    cout << countA + remain << endl;


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int N; cin >> N;
	int* x = new int[N];
	int* y = new int[N];

	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}

	int cost = N;
	for (int X = 0; X < N; X++) {
		for (int Y = 0; Y < N; Y++) {
			if (X == Y) { continue; }
			int p = x[Y] - x[X];
			int q = y[Y] - y[X];

			int count = 0;
			for (int i = 0; i < N; i++) {
				bool flag = true;
				for (int j = 0; j < N; j++) {
					int dx = x[i] - x[j];
					int dy = y[i] - y[j];
					if (dx == p && dy == q) {
						flag = false;
						break;
					}
				}
				if (flag == true) {
					count++;
				}
			}
			cost = min(cost, count);
		}
	}

	cout << cost << endl;
	return 0;
}


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

int main () {
  string S;
  cin >> S;
  vector<string> divide = {"dream", "dreamer", "erase", "eraser"};
  reverse(S.begin(), S.end());
  for (int i = 0; i < 4; i++) reverse(divide.at(i).begin(), divide.at(i).end());
  
  bool can = true;
  for (int i = 0; i < S.size();) {
    bool can2 = false;
    for (int j = 0; j < 4; j++) {
      string d = divide.at(j);
      if (S.substr(i, d.size()) == d) {
        can2 = true;
        i += d.size();
      }
    }
    if (!can2) {
      can = false;
      break;
    }
  }
  if (can) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 512
n = int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
p = prime_factorize(n)

import collections
cnt = collections.Counter(p)

ans = 0
for pi, ci in cnt.items():
    num = 1
    for i in range(1, 10000):
        if (i * (i+1))//2 <= ci:
            num = i
        if (i * (i+1))//2 > ci:
            break
    ans += num

print(ans)

Measured memory_bytes: 65944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

struct edge {int from, to; ll cost;};
vector<edge> es(2005);
vector<ll> d(1005);
int V, E;

bool negativeloop(int s){
    FOR(i,0,V) d[i]=INF;
    d[s]=0;
    FOR(i,0,V){
        FOR(j,0,E){
            edge e=es[j];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i==V-1)return true;
            }
        }
    }
    return false;
}

void ford(int s){
    FOR(i,0,V) d[i]=INF;
    d[s]=0;
    while(1){
        bool update=false;
        FOR(i,0,E){
            edge e=es[i];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                update=true;
            }
        }
        if(!update) break;
    }
} 

int main(){
    cin >> V >> E;
    int st; cin >>st;
    int x,y; ll co;
    edge ed;
    FOR(i,0,E){
        cin >> x >> y >> co;
        ed.from=x;
        ed.to=y;
        ed.cost=co;
        es[i]=ed;
    }
    bool f = negativeloop(st);
    if(f) cout << "NEGATIVE CYCLE" << endl;
    else{
        ford(st);
        FOR(i,0,V){
            if(d[i]==INF) cout<<"INF"<<endl;
            else cout << d[i] << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3128
import bisect
S=input()
R=[]
L=[]
count=[0]*len(S)
for i in range(len(S)-1):
    if(S[i]=='R' and S[i+1]=='L'):
        R.append(i)
        L.append(i+1)
for i in range(len(S)):
    if(S[i]=='R'):
        b=bisect.bisect_left(R,i)
        if(abs(R[b]-i)%2==0):
            count[R[b]]+=1
        else:
            count[R[b]+1]+=1
    elif(S[i]=='L'):
        b=bisect.bisect_left(L,i)
        if(b<len(L) and L[b]==i):
            count[L[b]]+=1
        else:
            b-=1
            if(abs(i-L[b])%2==0):
                count[L[b]]+=1
            else:
                count[L[b]-1]+=1
                
print(*count)

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


int main() {
  int n, l;
  cin >> n >> l;
  vector<int> vec(n);
  rep(i,n){
    vec[i] = l + i;
  }
  int a,c;
  c = vec[0];
  if(c < 0){
    c = -c;
  }
  a = c;
  int d = 0;
  rep(i,n){
    int b;
    b = vec[i];
    if(b < 0){
      b = 0 - b;
    }
    if(a > b){
      d = i;
    }
    a = min(a,b);
    
  }
  
  int ans = 0;
  rep(i,n){
    ans += vec[i];
  }
  
  cout << ans - vec[d];
 
  return 0;
}

Measured memory_bytes: 3612
import itertools
h, w, d = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
p = [0] * (h * w)
for i, j in itertools.product(range(h), range(w)):
  p[a[i][j] - 1] = (i, j)
s = [0] * d
for i in range(h * w - d):
  s.append(s[-d] + abs(p[i][0] - p[i+d][0]) + abs(p[i][1] - p[i+d][1]))
q = int(input())
for i in range(q):
  l, r = map(int, input().split())
  l -= 1
  r -= 1
  print(s[r] - s[l])


Measured memory_bytes: 17660
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int p[N], n, m, ans;  
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a, b;
    cin >> a >> b;
    if(a > 12){
        cout << b << endl;
    }else{
        if(a > 5){
            cout << b / 2 << endl;
        }else{
            cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <cstdio>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}


int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<int> >money(100001);
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a<=m)money[a].push_back(b);
    }
    int ans=0;
    priority_queue<int>q;
    for (int i=1;i<=m;i++)
    {
        for(int j=0;j<money[i].size();j++)
            q.push(money[i][j]);
        if(!q.empty())
        {
            ans+=q.top();
            q.pop();
        }
    }
    cout<<ans<<endl;

    return 0;
}


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

int n, q, m, a[21];
bool dp[21][2001] = { false };

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	dp[0][0] = true;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= 2000; j++) {
			if (dp[i-1][j] || (j- a[i] >= 0 && dp[i-1][j - a[i]])) {
				dp[i][j] = true;
			}
		}
	}

	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m;
		cout << (dp[n][m] ? "yes" : "no") << endl;
	}

	return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (a == b) cout << c << endl;
  else if (b == c) cout << a << endl;
  else cout << b << endl;

  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc076/tasks/abc076_c
# C - Dubious Document 2

blank_s = input().split()[0]
t = input().split()[0]

matched_index_list = []

for i in range(len(blank_s) - len(t) + 1):
    is_match = True
    for s_char, t_char in zip(blank_s[i:i+len(t)], t):
        if s_char != '?' and s_char != t_char:
            is_match = False
            break

    if is_match:
        matched_index_list.append(i)

if not matched_index_list:
    answer = 'UNRESTORABLE'
else:
    replaced_s_list = []
    for index in matched_index_list:
        replaced_s = list(blank_s)
        replaced_s[index:index+len(t)] = t
        replaced_s = ''.join(replaced_s)
        replaced_s = replaced_s.replace('?', 'a')
        replaced_s_list.append(replaced_s)

    answer = min(replaced_s_list)

print(answer)

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(5e3) + 17;

int n, k;
int a[MAXN];
bool dp_l[MAXN][MAXN], dp_r[MAXN][MAXN];

bool read() {
    if (!(cin >> n >> k))
        return false;

    forn (i, n)
        cin >> a[i + 1];
    
    return true;
}

void solve() {
    dp_l[0][0] = 1;

    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= k + 1; ++j) {
            dp_l[i + 1][j] |= dp_l[i][j];
            dp_l[i + 1][min(k + 1, j + a[i + 1])] |= dp_l[i][j];
        }

    dp_r[n + 1][0] = 1;

    for (int i = n + 1; i > 1; --i)
        for (int j = 0; j <= k + 1; ++j) {
            dp_r[i - 1][j] |= dp_r[i][j];
            dp_r[i - 1][min(k + 1, j + a[i - 1])] |= dp_r[i][j];
        }

    int ans = 0;

    for (int i = 1; i <= n; ++i) {
        int sum = 0;

        for (int j = max(0, k - a[i]); j < k; ++j)
            sum += dp_r[i + 1][j];

        bool nec = false;

        for (int s_l = 0, l = k - a[i], r = k - 1; s_l <= k; ++s_l, --l, --r) {
            if (dp_l[i - 1][s_l] && sum > 0) {
                nec = true;
                break;
            }

            if (l - 1 >= 0)
                sum += dp_r[i + 1][l - 1];

            if (r >= 0)
                sum -= dp_r[i + 1][r];
        }

        ans += !nec;
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 49408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    string f,g;
   // char k[16]={'0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15'};
    cin>>f>>g;
    if(f=="0")
    {
        n=0;
    }
    if(f=="1")
    {
        n=1;
    }
    if(f=="2")
    {
        n=2;
    }
    if(f=="3")
    {
        n=3;
    }
    if(f=="4")
    {
        n=4;
    }
    if(f=="5")
    {
        n=5;
    }
    if(f=="6")
    {
        n=7;
    }
    if(f=="8")
    {
        n=8;
    }
    if(f=="9")
    {
        n=9;
    }
    if(f=="A")
    {
        n=10;
    }

    if(f=="B")
    {
        n=11;
    }
    if(f=="C")
    {
        n=12;
    }
     if(f=="D")
    {
        n=13;
    }
     if(f=="E")
    {
        n=14;
    }
     if(f=="F")
    {
        n=15;
    }
    if(g=="1")
    {
        m=1;
    }
    if(g=="2")
    {
        m=2;
    }
    if(g=="3")
    {
        m=3;
    }
    if(g=="4")
    {
        m=4;
    }
    if(g=="5")
    {
        m=5;
    }
    if(g=="6")
    {
        m=6;
    }
    if(g=="7")
    {
        m=7;
    }
    if(g=="8")
    {
        m=8;
    }
    if(g=="9")
    {
        m=9;
    }
    if(g=="A")
    {
        m=10;
    }
    if(g=="B")
    {
        m=11;
    }
    if(g=="C")
    {
        m=12;
    }
    if(g=="D")
    {
        m=13;
    }
    if(g=="E")
    {
        m=14;
    }
    if(g=="F")
    {
        m=15;
    }
    if(g=="0")
    {
        m=0;
    }
        if(n>m)
        {
            cout<<">"<<endl;
           // cout<<n<<" > "<<m<<endl;
        }
        if(n<m)
        {
            cout<<"<"<<endl;
           // cout<<n<<" < "<<m<<endl;
        }
         if(n==m)
        {
            cout<<"="<<endl;
           // cout<<n<<" = "<<m<<endl;
        }


}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORL(i,a,b) for(ll i=(a);i<(b);++i)
#define REPL(i,n) FORL(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   RFOR(i,n,0)
#define MAX 200001
using namespace std;



int main(){
	int tmp;
	int N, P[200002] = { 0 };
	scanf("%d", &N);
	FOR(i, 1, N + 1){
		scanf("%d", &tmp);
		P[tmp] = i;
	}

	
	int p = 0, q = 0;
	FOR(i, 1, N + 1){
		p++;
		if (P[i + 1] < P[i]){
			if (p>q){
				q = p;
			}
			p = 0;
		}
	}

	printf("%d\n", N - q);

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

int MP(std::string &S, std::vector<long long int> &A);
int KMP(std::string &S, std::string &word, std::vector<long long int> &match_table);

long long int euclid_gcd(long long int x, long long int y);

int main(){
  
  // read problem
  std::string s, t;
  std::cin >> s;
  std::cin >> t;
  long long int slen = s.length(), tlen = t.length();
  //std::cerr << "s: " << s << std::endl << "t: " << t << std::endl;
  
  // solve problem
  std::string s_extend = s;
  for(int i = 0; s_extend.length() < slen+tlen; i++){
    s_extend = s_extend + s_extend;
  }
  s_extend = s_extend.substr(0, slen+tlen);
  
  // KMP
  std::vector<long long int> match_table;
  KMP(s_extend, t, match_table);
  
  // change format of result
  std::vector<long long int> match_index(slen);
  for(long long int i = 0; i < match_table.size(); i++){
    if(match_table[i] < slen){
      match_index[match_table[i]] = 1;
    }
    else{
      break;
    }
  }
  
  // calculate answer
  long long int gcd_st = euclid_gcd(slen, tlen);
  long long int tmp, ntmp, ntmp_max=0, start, nstart, eternity_flg;
  
  for(long long int i = 0; i < gcd_st; i++){
    tmp = i;
    eternity_flg = 1;
    ntmp = 0;
    nstart = 0;
    for(int j = 0; j < slen/gcd_st; j++){
      tmp = (tmp+tlen)%slen;
      if(match_index[tmp] == 0){
        eternity_flg = 0;
        ntmp_max = std::max(ntmp, ntmp_max);
        ntmp = 0;
      }
      else{
        if(eternity_flg == 1){
          nstart++;
        }
        ntmp++;
      }

    }
    
    if(eternity_flg == 1){
      break;
    }
    ntmp_max = std::max(ntmp_max, nstart+ntmp);
  }
  
  std::cerr << "Answer:" << std::endl;
  if(eternity_flg == 1){
    std::cout << -1 << std::endl;
  }
  else{
    std::cout << ntmp_max << std::endl;
  }
  
  return 0;
  
}

int MP(std::string &S, std::vector<long long int> &A){
  
  A[0] = -1;
  long long int L = S.length();
  long long int j = -1;
  
  for(long long int i = 0; i < L; i++){
    while(j >= 0 && S[i]!=S[j]) j=A[j];
    j++;
    A[i+1] = j;
  }
  
  return 0;
}

int KMP(std::string &S, std::string &word, std::vector<long long int> &match_table){
  
  // preparation: MP calculation
  std::vector<long long int> MP_table(word.length()+1);
  MP(word, MP_table);
  match_table.clear();
  
  // make match_table
  long long int m  = 0, i = 0, ls = S.length(), lword = word.length();
  
  while(m+i < ls){
    if(word[i] == S[m+i]){
      i++;
      if(i == lword){
        match_table.push_back(m);
        m = m+i - MP_table[i];
        i = MP_table[i];
      }
    }
    else{
      m = m+i - MP_table[i];
      if(i > 0){
        i = MP_table[i];
      }
    }
  }
  
  return 0;
}

long long int euclid_gcd(long long int x, long long int y){
  if(y == 0){
    return x;
  }
  /*else if(x == 0){
    return y;
  }*/
  else{
    return euclid_gcd(y, x%y);
  }
}


Measured memory_bytes: 13200
s = int(input())
 
ans = 0
 
if (s == 1 or s == 2 or s == 4):
  print(4)
else:
  while (s != 4):
    if (s % 2 == 0):
      s  =  int(s/2)
    else:
      s = 3*s + 1
    ans += 1
  
 
  print(ans+4)


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

using namespace std;

int main(){
    double ans = 0;

    int N, K; cin >> N >> K;

    for(int i = 1; i<=N; i++){
        long long aux = i;
        int flip = 0;
        while(aux < K){
            aux = aux*2;
            flip++;
        }
        double daux = (1.0/N)*(pow(0.5, flip));
        ans+=daux;
    }

    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[int(j) for j in input().split()]
mod=10**9+7
l=[-1]*(n+1)
ind=[]
for i in range(n+1):
    if l[a[i]]!=-1:
        ind=[l[a[i]],i]
        break
    l[a[i]]=i
U = 2*10**5
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
  fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U],MOD-2,MOD)
 
for i in range(U,0,-1):
	fact_inv[i-1] = (fact_inv[i]*i)%MOD
 
def comb(n,k):
  if k < 0 or k > n:
    return 0
  x = fact[n]
  x *= fact_inv[k]
  x %= MOD
  x *= fact_inv[n-k]
  x %= MOD
  return x

i,j=ind
for k in range(1,n+2):
    if k==1:
        print(n)
    else:
        print((comb(n+1,k)-comb(i+n-j,k-1))%mod)









Measured memory_bytes: 27944
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=5e3+5;
int n,R,L,a[N];ll ans=1e18,dp[N];

int main() {
	scanf("%d%d%d",&n,&R,&L);
	memset(dp,64,sizeof(dp)),dp[0]=0;
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i) {
		for(int j=0;j<a[i];++j) dp[a[i]]=min(dp[a[i]],dp[j]);
		for(int j=0;j<a[i];++j) dp[j]+=R;
		for(int j=a[i];j<n;++j) dp[j+1]+=L;
	}
	for(int i=0;i<=n;++i) ans=min(ans,dp[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) 
{
	char cards[52] = { 0 }, s;
	char suits['S' + 1] = { ['S'] = 13 * 0,['H'] = 13 * 1,['C'] = 13 * 2,['D'] = 13 * 3 };
	int i, n;

	scanf("%d ", &n);
	while (n--) 
	{
		scanf("%c %d ", &s, &i);
		cards[suits[(int)s] + i - 1] = 1;
	}
	for (i = 0; i < 52; i++) 
	{
		if (!cards[i]) 
		{
			printf("%c %d\n", "SHCD"[i / 13], i % 13 + 1);
		}
	}
	return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N;
    cin >> N;
    set<int> st;
    rep(i, N) {
        int x;
        cin >> x;
        st.insert(x);
    }
    puts(st.size() == N ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 9600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

int main(){   

    ll K;
    cin >> K;
    ll sum = 0;
    rep1(a, K)rep1(b, K)rep1(c, K){
        sum += gcd(a, gcd(b, c));
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<cctype>
#include<stdlib.h>
#define N 200
#define ll long long
using namespace std;

int main()
{
    ll n, m;
    ll s;
    s = 0;
    scanf("%lld%lld", &n, &m);
    if(m >= 2*n)
    {
        s += n;
        m = m-2*n;
        s += m/4;
    }
    else
        s += m/2;
    printf("%lld", s);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void pk()
{
   ll n,x,t;
   cin>>n>>x>>t;
   cout<<(fixed)<<setprecision(0)<<ceil((double)n/x)*t;
}
int main() 
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    //a #ifndef ONLINE_JUDGE 
    // freopen("/home/priyanshu/Hackercup/input.txt", "r", stdin); 
    // freopen("/home/priyanshu/Hackercup/output.txt", "w", stdout); 
    // #endif 
	ll t=1;
    //cin>>t;
    while(t--)
    {
        pk();
    }
} 

Measured memory_bytes: 3800
#!/usr/bin/ruby
M=10**9+7
def d(x,y) x.zip(y).reduce(0){|s,(a,b)|s+a*b} end
def mul(x,y)
	y=y.transpose
	[[d(x[0],y[0])%M,d(x[0],y[1])%M],[d(x[1],y[0])%M,d(x[1],y[1])%M]]
end
def pow(x,y)
	z=1
	while y>0
		z=z*x%M if y%2>0
		x=x*x%M
		y/=2
	end
	z
end
h,w,k=gets.split.map(&:to_i)
k-=1
m=$<.map{|e|e.chomp.chars};mt=m.transpose
c=m.count{|s|s[0]=='#'&&s[-1]=='#'}
d=mt.count{|s|s[0]=='#'&&s[-1]=='#'}
if d>0
	(p 1;exit) if c>0
	c,d=d,c
	m,mt=mt,m
	h,w=w,h
end
a=b=0
m.each{|s|w.times{|i|
	a+=1 if s[i]=='#'
	b+=1 if i<w-1&&s[i]=='#'&&s[i+1]=='#'
}}
b=0 if c==0&&d==0
 
e=[[1,0],[0,1]]
m=[[a,-b],[0,c]]
while k>0
	e=mul(e,m) if k%2>0
	m=mul(m,m)
	k/=2
end
p (e[0][0]+e[0][1])%M

Measured memory_bytes: 89212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int diff=0;
  diff = A%500;
  //cout << diff << endl;
  if(diff<=B){
    cout << "Yes"<< endl;
  }else{
    cout << "No" << endl;
  } 
  
}

Measured memory_bytes: 256
from itertools import*
s=input()
k=int(input())
x=y=0
g=[len(list(v))for k,v in groupby(s)]
for c in g:
	x += c//2
if s[-1]==s[0]:
	if g[-1]%2==0 or g[0]%2==0:
		pass
	elif len(s)==1:
		y=k//2
	elif len(s)==g[0]:
		y=k//2
	else:
		y=k-1
print(x*k+y)

Measured memory_bytes: 3064
-- https://atcoder.jp/contests/abc175/submissions/15989458 の改変
import           Control.Monad
import           Data.Array
import           Data.List
getIntLine = map read . words <$> getLine
main = do
  [n,k] <- getIntLine
  p <- listArray (1,n) <$> getIntLine
  c <- listArray (1,n) <$> getIntLine
  let acc i= tail $ scanl' (+) 0 $ map ((c !).(p !)) $ takeWhile (/= i) (tail $ iterate (p !) i) ++ [i]
      ans i =
        if val > 0
          then
            if rem /= 0
              then num * val + maximum (take rem list)
              else (num-1) * val + maximum list
          else maximum list
        where list = acc i
              val = last list
              len = length list
              num = k `div` len
              rem = k `mod` len
  print $ maximum $ map ans [1..n]


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

int main(void){
  int n, k;
  vector<double> p(100000);
  cin >> n >> k;

  for(int i = 1; i <= n; i ++){
    int point = i;

    int j = 0;
    while(point < k){
      point *= 2;
      j ++;
    }

    p.at(i-1) = (1.0/n) * pow(0.5, j);
  }
  
  double sum = 0;
  for(int i = 0; i < n; i ++)
    sum += p.at(i);

  cout << setprecision(13) << sum << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int N;

int main() {
	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		ans += (b - a) + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#define FOR(i,l,r) for (i=l;i<=r;i++)
#define INF 0x3f3f3f3f

using namespace std;

int i,j,k,l,m,n;
static int c[5][6],t[30],z[6];
const int w[24][6]={2,3,0,5,4,1, 3,2,0,5,1,4, 4,1,0,5,3,2, 1,4,0,5,2,3,
	2,3,1,4,0,5, 3,2,1,4,5,0, 0,5,1,4,3,2, 5,0,1,4,2,3, 
	5,0,2,3,4,1, 0,5,2,3,1,4, 4,1,2,3,0,5, 1,4,2,3,5,0,
	5,0,3,2,1,4, 0,5,3,2,4,1, 1,4,3,2,0,5, 4,1,3,2,5,0,
	2,3,4,1,5,0, 3,2,4,1,0,5, 5,0,4,1,3,2, 0,5,4,1,2,3,
	2,3,5,0,1,4, 3,2,5,0,4,1, 1,4,5,0,3,2, 4,1,5,0,2,3};
string st;
int dfs(int o)
{
	int ans=INF,i,j,k;
	if (o>n)
	{
		ans=0;
		FOR(i,0,5)
		{
			memset(t,0,sizeof(t));
			int ma=0;
			FOR(j,0,n)
				ma=max(ma,++t[c[j][w[z[j]][i]]]);
			ans+=(n-ma);
		}
		return ans;
	}
	FOR(i,0,23)
	{
		z[o]=i;
		ans=min(ans,dfs(o+1));
	}
	return ans;   
}
int main() {
	map <string,int> a;
	while (scanf("%d",&n)!=EOF && n)
	{
		FOR(i,1,n) FOR(j,0,5) {
		cin>>st;if (!a[st]) a[st]=++m;
		c[i][j]=a[st];} 
		z[1]=0;
		printf("%d\n",dfs(2));
		map<string,int>::iterator o=a.begin();
		for (;o!=a.end();o++)
			o->second=0;
		m=0;
	}
	return 0;
}

Measured memory_bytes: 1256
/* 
 * Project: AtCoder Beginners Contest 148 C - Snack
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/01
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <numeric>
using namespace std;

long a, b;

void solve() {

    long long number = lcm(a, b);
    printf("%lld\n", number);
}

int main() {

    scanf("%ld", &a);
    scanf("%ld", &b);

    solve();

}


Measured memory_bytes: 3200
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def C(n,r):
    return fact[n]*pow(fact[n-r],mod-2,mod)*pow(fact[r],mod-2,mod)%mod

n,a,b = LI()
fact = [1]*(min(n+1,2*10**5+1))
for i in range(1,min(n+1,2*10**5+1)):
    fact[i] = i*fact[i-1]
    fact[i] %= mod

ans = pow(2,n,mod)-1
tmp = 1
for i in range(a):
    tmp *= (n-i)
    tmp %= mod

tmp *= pow(fact[a],mod-2,mod)
ans -= tmp
ans %= mod
tmp = 1
for i in range(b):
    tmp *= (n-i)
    tmp %= mod
tmp *= pow(fact[b],mod-2,mod)
ans -= tmp
ans %= mod
print(ans)

Measured memory_bytes: 40560
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <utility>
#include <tuple>

class language {
  size_t sigma;
  size_t length = 0;
  std::vector<std::pair<size_t, size_t>> s;  // {alpha, run}

  void truncate_to(size_t next_len) {
    assert(!s.empty());
    size_t last = s.back().first;
    while (length > next_len) {
      size_t run;
      std::tie(last, run) = s.back();
      s.pop_back();
      length -= run;
    }
    if (length == next_len) return;
    s.emplace_back(last, next_len-length);
    length = next_len;
  }

  bool increment() {
    assert(!s.empty());
    size_t& alpha = s.back().first;
    size_t& run = s.back().second;
    if (run == 1) {
      ++alpha;
      size_t slen = s.size();
      if (slen >= 2 && s[slen-2].first == alpha) {
        s.pop_back();
        ++s.back().second;
      }
    } else {
      --run;
      s.emplace_back(alpha+1, 1);  // OK?
    }
    if (s.back().first < sigma) return true;
    return resolve_carry();
  }

  bool resolve_carry() {
    assert(s.back().first == sigma);
    assert(s.back().second == 1);
    
    s.pop_back();
    if (s.empty()) return false;
    size_t run = 1;
    if (s.back().first+1 == sigma) {
      run += s.back().second;
      s.pop_back();
    }
    if (s.empty()) return false;
    increment();
    s.emplace_back(0, run);
    return true;
  }

public:
  language(size_t sigma): sigma(sigma) {}

  bool next_string(size_t next_len) {
    if (sigma == 0) return false;
    if (length == 0) {
      s.emplace_back(0, next_len);
      length = next_len;
      return true;
    }
    if (length < next_len) {
      if (s.back().first == 0) {
        s.back().second += next_len-length;
      } else {
        s.emplace_back(0, next_len-length);
      }
      length = next_len;
      return true;
    }

    truncate_to(next_len);
    return increment();
  }

  void show() const {
    fprintf(stderr, "%zu:", length);
    for (const auto& p: s)
      for (size_t i = 0; i < p.second; ++i)
        fprintf(stderr, " %s%zu%s",
                ((i > 0)? "":"("), p.first,
                ((i+1 < p.second)? "":")"));

    fprintf(stderr, "\n");
  }
};

bool valid(const std::vector<size_t>& A, size_t k) {
  language la(k);
  for (size_t ai: A)
    if (!la.next_string(ai)) return false;

  return true;
}

void debug() {
  size_t N;
  scanf("%zu", &N);

  size_t i = 0;
  language la(N);
  while (true) {
    size_t k;
    scanf("%zu", &k);
    if (!la.next_string(k)) break;
    la.show();
    ++i;
  }
  printf("%zu\n", i);
}

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<size_t> A(N);
  for (size_t i = 0; i < N; ++i)
    scanf("%zu", &A[i]);

  size_t lb = 0;
  size_t ub = N+1;
  while (ub-lb > 1) {
    size_t mid = (lb+ub) >> 1;
    (valid(A, mid)? ub:lb) = mid;
  }

  printf("%zu\n", ub);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long i=0;i<(n);i++)
#define FOR(i,a,b) for(long i=(a);i<(b);i++)
#define dfor(i,a,b) for(long i=(a);i>=(b);i--)
#define ll long long
#define ull unsigned long long

int main() {
	long n;
	cin>>n;
	long a[n],b[n],c[n]={0};
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n) cin>>b[i];
	FOR(i,1,n) cin>>c[i];

	long sum = 0;
	sum = b[a[0]-1];
	FOR(i,1,n){
		if(a[i-1] == a[i]-1){
			sum += c[a[i]-1]; 
		}
		sum += b[a[i]-1];
	}
	cout<<sum;
	
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,ans=0;
  vector<ll> v(30);
  cin >> n;
  v[0]=1;
  for(int i=1; i<=26; i++) {
    v[i]=v[i-1]*5;
  }
  
  if(n%2) {
    cout << 0 << endl;
  }
  else {
    for(int i=1; i<=26; i++) {
      ans+=n/v[i]/2;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(0, i, N)
    {
        cin >> A.at(i);
    }
    int num = 0;
    int count = 1;
    rep(0, i, N)
    {
        if (A.at(num) == 2)
        {
            cout << count << endl;
            return 0;
        }
        else
        {
            num = A.at(num) - 1;
            count++;
        }
    }

    cout << -1 << endl;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a = 0, b = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'R')
      a++;
    else
      b++;
  }
  if (a > b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
     
    int n;
    vector<int> cnt(4);
    //vector<vector<vector<double>>> dp;
    const int N = 305;
	double dp[N][N][N];

    int main(){
        cin>>n;
        for(int i = 0; i < n; i++){
            int tmp; cin>>tmp;
            cnt[tmp]++;
        }
        dp[0][0][0] = 0.0;
        for(int k = 0; k <= n; k++){
            for(int j = 0; j <= n; j++){
                for(int i = 0; i <= n; i++){
                    double kk = i + j + k;
                    if(kk == 0 || n < kk) continue;
                    dp[i][j][k] = (n/kk) + (1/kk) * ((i ? i*dp[i-1][j][k] : 0) + (j ? j*dp[i+1][j-1][k] : 0) + (k ? k*dp[i][j+1][k-1] : 0));
                }
            }
        }
        auto res = dp[cnt[1]][cnt[2]][cnt[3]];
        cout<<setprecision(20)<<res<<endl;
        return 0;
    }

Measured memory_bytes: 112576
import java.util.Scanner;

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

	int H = scan.nextInt();
	int W = scan.nextInt();

	String[] a = new String[H];
	for(int i = 0; i < H; i++){
	    a[i] = scan.next();
	}
    
	/*
	String[][] a = new String[H][W];
	for(int i = 0; i < H; i++){
	    for(int j = 0; j < W; j++){
		a[i][j] = scan.next();
	    }
	}
	*/

	int[] h = new int[H];
	int[] w = new int[W];
	
	for(int i = 0; i < H; i++){
	    for(int j = 0; j < W; j++){
		if(a[i].charAt(j) == '#'){
		    h[i] = 1;
		    break;
		}
	    }
	}
       
	for(int j = 0; j < W; j++){
	    for(int i = 0; i < H; i++){
		if(a[i].charAt(j) == '#'){
		    w[j] = 1;
		    break;
		}
	    }
	}

	/*
	for(int i = 0; i < H; i++){
	    System.out.println(h[i]);
	}
	for(int i = 0; i < W; i++){
	    System.out.println(w[i]);
	}
	*/
	for(int i = 0; i < H; i++){
	    if(h[i] == 1){
		for(int j = 0; j < W; j++){
		    if(w[j] == 1){
			System.out.print(a[i].charAt(j));
		    }
		}
		System.out.println();
	    }
	}
	
    }
}


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

int main(){
  string S ; 
  cin >> S ; 
  int N = S.size() ; 
  
  if(S.at(0) != S.at(1) && S.at(1) != S.at(2) && S.at(0) != S.at(2)){
    cout << "Yes" << endl ; 
  }
  else{
    cout << "No" <<endl ; 
  }

}

Measured memory_bytes: 3564
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      	long pow = 1;
      
      for(int i=1 ; i <= n;i++){
      pow = pow*i%1000000007;
      }
      System.out.print(pow);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	register short f=1;x=0;char c=getchar();
	while(!isdigit(c)){ if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
template<typename T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
template<typename T>inline void writeln(T x){
	write(x),putchar('\n');
}
int main(){
	int a[100010],n,s1=-1,s2=-1;
    long long ans;read(n);
    for(int i=1;i<=n;i++)read(a[i]);
    sort(a+1,a+n+1);
    for(int i=n;i>=2;i--)
		if(a[i]==a[i-1]){s1=a[i],a[i]=a[i-1]=0;break;}
    for(int i=n;i>=2;i--)
		if(a[i]==a[i-1]&&a[i]!=0){s2=a[i];break;}
    if(s1!=-1&&s2!=-1)writeln((long long)s1*s2);
	else writeln(0);
	return 0;
}


Measured memory_bytes: 640
N,i = map(int,input().split())
i -= 1
N -= 1

if i == 0 or i == 2*N:
    print('No')
    exit()

res = list(range(2*N+1))
if i > N:
    res = res[i-N:]+res[:i-N]
else:
    res = res[i+N+1:]+res[:i+N+1]

res[N+1],res[N-1] = res[N-1],res[N+1]

print('Yes')
print(*(a+1 for a in res), sep='\n')

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

int main(void){

    int A, B, C;

    scanf("%d%d%d", &A, &B, &C);

    if((A == 5 && B == 5 && C == 7) || (A == 5 && B == 7 && C == 5) || (A == 7 && B == 5 && C == 5)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 1616
#include<bits/stdc++.h>
 
/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace std;
 
#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const LL MOD = 1000000000 + 7;
const LD EPS = 0.0000001 ;
#define MPP(a, b, c) MP(MP(a, b), c)
#define PII pair<pair<LL,LL>, LL>
 
LL pows(LL a, LL b)
{
	if (b == 0) return 1LL;
	LL temp = pows(a, b / 2);
	temp = (temp * temp) % MOD;
	if (b % 2) temp = (temp * a) % MOD;
	return temp;
}

const int N = 100000 + 5000;

vector<int> graph[N];
bool vis[N];
int ans = 0;
int dp[N];

void dfs(int node)
{
	dp[node] = 1;
	vis[node] = 1;
	for (auto it : graph[node]){
		if (vis[it] == 0) dfs(it);
		dp[node] = max(dp[node], 1 + dp[it]);
	}
	ans = max(ans, dp[node]);
}

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

    int n, m; cin >> n >> m;

    for (int i = 0; i < m; i++){
    	int u, v; cin >> u >> v;
    	graph[u].PB(v);
    }

    for (int i = 1; i <= n; i++){
    	if (vis[i]) continue;
    	dfs(i);
    }

    cout << ans - 1 << endl;

	return 0;
}

Measured memory_bytes: 8448
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  (int)(1e9+7)
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){ 
    int n; cin>>n; 
    vi a(n+1),dp(n,0); 
    dp[0] = 3;
    int ans = 1 ; 
    for (int i=1;i<=n;i++) cin >> a[i] ; 
    for (int  i=1 ; i<=n ; i++) { 
        ans = (ans*(dp[a[i]]))%mod;
        dp[a[i]]--; dp[a[i]+1]++;
    } 
    cout << ans << endl; 
} 

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}
/*

0 0 0 1 1 1 


*/


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

template <class T>
using lim = numeric_limits<T>;

const int maxn = 500;


struct train{
	int l, r;
	train(){l=r=0;}
	train(int a, int b){
		l = a;
		r = b;
	}
};

vector<train> arr[maxn+1];
int prefix[maxn+2];
int starts[maxn+2][maxn+2];
int main() {
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);

	memset(prefix, 0, sizeof prefix);
	memset(starts, 0, sizeof starts);
	
	int n, m, Q;
	cin >> n >> m >> Q;
	for (int i = 0; i < m; i++){
		int l, r;
		cin >> l >> r;
		arr[l].push_back(train(l,r));
	}
	
	for (int i = 1; i <= n; i++){
		for (train t : arr[i]){
			starts[i][t.r]++;
			prefix[t.r]++;
		}
	}
		
	for (int i = 1; i <= n; i++){
		// how many trains 0 to i inclusive
		prefix[i] = prefix[i-1]+prefix[i];
		// how many trains starts below i inclusive but ends before j
		for (int j = 1; j <= n; j++){
			starts[i][j] = starts[i][j-1] + starts[i][j];
		}
	}
	
	for (int j = 1; j <= n; j++){
		for (int i = 2; i <= n; i++){
			starts[i][j] = starts[i][j] + starts[i-1][j];
		}
	}
	
	
	while(Q--){
		int p, q;
		cin >> p >> q;
		
		cout << prefix[q]-starts[p-1][q] << endl;
	}
}



Measured memory_bytes: 4480
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

func Solve(){
  var N int
  NextInt(&N)
  K := 0
  for K * K <= N { K++ }
  cnt := 1
  if N == 2 {
    Write(1)
    return
  }
  for k := 2; k < K; k++ {
    n := N
    for n % k == 0 { n /= k }
    if n % k == 1 { cnt++ }
  }
  for k := 1; k < K; k++ {
    if (N - 1) % k == 0 && K <= (N - 1) / k { cnt++ }
  }
  Write(cnt)
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

#define MAX 10

int main() {
  int N, array[MAX], maxLength = 0, sum = 0;
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> array[i];
    sum += array[i];
    maxLength = max(array[i], maxLength);
  }
  sum -= maxLength;
  if(sum <= maxLength){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

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

int main() {
  ll X,fh,f,sum=0;
  cin>>X;
  fh=X/500;
  f=X%500/5;
  sum+=fh*1000+f*5;
  cout<<sum<<endl;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
S = [input() for _ in range(N)]

x = [A, B, C]
d = {"A": 0, "B": 1, "C": 2}
if sum(x) == 0:
    print("No")
else:
    flag = True
    ans = []
    for i, s in enumerate(S):
        n, m = list(s)

        if x[d[n]] == x[d[m]] == 0:
            flag = False
            break

        if x[d[n]] > x[d[m]]:
            x[d[n]] -= 1
            x[d[m]] += 1
            ans.append(m)
        elif x[d[n]] < x[d[m]]:
            x[d[n]] += 1
            x[d[m]] -= 1
            ans.append(n)
        elif i < N - 1 and S[i] != S[i + 1]:
            # x[d[n]] == x[d[m]]
            if n in S[i + 1]:
                x[d[n]] += 1
                x[d[m]] -= 1
                ans.append(n)
            else:
                x[d[m]] += 1
                x[d[n]] -= 1
                ans.append(m)
        else:
            # x[d[n]] == x[d[m]] at last
            x[d[n]] += 1
            x[d[m]] -= 1
            ans.append(n)

    if flag:
        print("Yes")
        print(*ans, sep="\n")
    else:
        print("No")


Measured memory_bytes: 91152
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    if N%2==0:
        c=N//10
        tmp=c
        ans=0
        z=0
        while tmp > 0:
            ans+=tmp
            tmp=tmp//5
    else:
        ans=0
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <stdio.h>
 
int main(){
 int p, q, r;
 int min;
 
 scanf("%d%d%d", &p, &q, &r);
 
 min=p+q;
 
 if(min > p+r){
  min = p+r;
 }
if(min > q+r){
  min = q+r;
 }
 
 printf("%d", min);
 return 0;
}


Measured memory_bytes: 128
// Created by the_solver...
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];

void fastio()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

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

int min(int a, int b)
{
	return a<b?a:b;
}
// int dp[100001];
// int  rec(int a[], int n, int cost)
// {
// 	if(n==1)return cost;
// 	if(n<1)return 10000000000;
// 	int cost1,cost2;
// 	if(n-2>=0){
// 		if(dp[n-2] == -1)
// 		{
// 	cost1 = cost + abs(a[n-1] - a[n-2]);
// 	dp[n-2]  = cost1;
// 	}
// 	}
//  	// else cost1 = 10000000000;
// 	if(n-3>=0){
// 		if(dp[n-3] == -1){
// 	cost2 = cost + abs(a[n-1] - a[n-3]);
// 	dp[n-3]= cost2;
// 	}
// 	}
//  	// else dp[n] = 10000000000;
// 	return dp[n-1] = min(rec(a,n-1,dp[n-2]),rec(a,n-2,dp[n-3])); 
// }



void solve()
{
	
	int n;cin>>n;
	int a[n],dp[n+1];
	for(int i=0;i<n;i++)cin>>a[i];
	dp[0] = 0;
	dp[1] = abs(a[1]-a[0]);
	dp[2] = min((dp[1]+abs(a[2]-a[1])),abs(a[2]-a[0]));
	for(int i=3;i<n;i++)
	{
		dp[i] = min((dp[i-1]+abs(a[i-1]-a[i])),(dp[i-2]+abs(a[i-2]-a[i])));
	}
	cout<<dp[n-1]<<endl;
}


int32_t main()
{
    
    // fastio();
    // int t;cin>>t;
    // while(t--)
    solve();
    return 0;
}

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

typedef long long ll; 
ll m=1e9+7;
ll dp[2002][1002];


ll dfs(ll a,ll b){
  if(a==b)return 1;
  if(dp[a][b])return dp[a][b];
  ll res=0;
  if(a)res+=dfs(a-1,b);
  if(a&&b)res+=dfs(a-1,b-1);
  res%=m;
  return dp[a][b]=res;
}

int main(){
  ll n,k;
  cin>>n>>k;
  dp[0][0]=1;
  cout<<dfs(n+k-1,k-1)<<endl;
  return 0;
}


  



Measured memory_bytes: 16888