akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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



int main() {
	
	ll N[4];
	rep(i, 4) cin >> N[i];

	sort(N, N + 4);

	if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9) { cout << "YES"; }
	else { cout << "NO"; }
	system("PAUSE");
}


Measured memory_bytes: 504
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int R;cin>>R;
    if(R<1200)cout<<"ABC"<<endl;
    else if(R<2800)cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
    return 0;
}

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



int main() {
    int n;
    cin >> n;
    
    int cnt = 0;
    bool tf = false;
    rep(i,n) {
        int x, y;
        cin >> x >> y;
        
        if(x == y)
            cnt++;
        else
            cnt = 0;
        
        if(cnt == 3) {
            tf = true;
        }
    }
    
    if(tf)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    
    return 0;
}




Measured memory_bytes: 3592
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	char c; cin >> c;
	cout << (char)(c + 1);

	return 0;
}

Measured memory_bytes: 3012
<?php
    while(true){
        list($height, $width) = explode(" ",trim(fgets(STDIN)));

        if($height == 0 && $width == 0) exit;
    
        $bar = str_repeat("#",$width)."\n";

        for($j = 0; $j < $height; $j++){
            print $bar;
        }

        print "\n";
    }    

Measured memory_bytes: 15400
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

ll memo[201][201];

ll gcd(ll a, ll b)
{
    if (memo[a][b] != -1)
    {
        return memo[a][b];
    }
    else if (memo[b][a] != -1)
    {
        return memo[b][a];
    }

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

int main()
{
    ll k;
    cin >> k;

    for (auto i = 0; i <= 200; i++)
    {
        for (auto j = 0; j <= 200; j++)
        {
            memo[i][j] = -1;
        }
    }

    ll ans = 0;

    for (auto a = 1; a <= k; a++)
    {
        for (auto b = 1; b <= k; b++)
        {
            for (auto c = 1; c <= k; c++)
            {
                ll z = gcd(a, b);
                ans += gcd(z, c);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3952
x=int(input())

for _ in range(x):
    a,b,c=map(int,input().split())
    if a**2 + b**2 == c**2:
        print('YES')
    elif b**2 + c**2 == a**2:
        print('YES')
    elif c**2 + a**2 == b**2:
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    string a = "AAA";
    string b = "BBB";
    if(s == a || s == b){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3604
from itertools import accumulate

N  = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]

# earliest deadline first
AB.sort(key=lambda x: x[1])

# 累積時刻とデッドライン
tB = accumulate(AB, lambda x, y: (x[0] + y[0], y[1]))

yes = all(t <= b for t, b in tB)
print('Yes' if yes else 'No')


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

int mini(const int* array, size_t size)
{
    assert(array != NULL);
    assert(size >= 1);

    int min = array[0];
    for (size_t i = 1; i < size; ++i) {
        if (min > array[i]) {
            min = array[i];
        }
    }

    return min;
}

int main() {
    int k, l, m;
    cin >> k >> l >> m;
    int a[k], b[l], aa[m], bb[m], c[m];
    for(int i=0; i<k; i++) cin >> a[i];    
    for(int i=0; i<l; i++) cin >> b[i];    
    for(int i=0; i<m; i++){
        cin >> aa[i] >> bb[i] >> c[i];
    }
    int ans = mini(a,k) + mini(b,l);
    for(int i=0; i<m; i++){
        ans = std::min(ans, a[aa[i]-1]+b[bb[i]-1]-c[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, k;
llong h[200005];

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    sort(h, h + n);

    llong ans = 0;
    for (int i = 0; i < n - k; i++) {
        ans += h[i];
    }

    cout << ans << endl;

    return 0;
}


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

struct edge{int to,cost;};
typedef pair<int,int> P;

int V;
vector<edge> g[100010];
int d[100010];
int inf = 2000000007;
int pre[100010];
int fen = 0,snu = 0;
vector<int> keiro;
bool used[100010];

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P>> que;
  for(int i = 0;i <= V;i++){
    d[i] = inf;
  }
  d[s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i = 0;i < g[v].size();i++){
      edge e = g[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to],e.to));
        pre[e.to] = v;
        //cout << 'v' << v << endl;
      }
    }
  }
}

vector<int> get_path(int t){
  vector<int> path;
  for(;t != 1;t = pre[t]){
    path.push_back(t);
    //cout << 't' << t << endl;
  }
  path.push_back(1);
  reverse(path.begin(),path.end());
  return path;
}

void dfs(int s,string player,int j){
  used[s] = true;
  //cout << s << endl;
  if(player == "Fennec"){
    fen++;
  }
  else if(player == "Snuke"){
    snu++;
  }
  for(int i = 0;i < g[s].size();i++){
    edge e = g[s].at(i);
    if(used[e.to] != true){
      if(j != keiro.size() - 1 && e.to != keiro.at(j+1)){
        dfs(e.to,player,j);
      }
      else if(j == keiro.size() - 1){
        dfs(e.to,player,j);
      }
    }
  }
}

int main() {
  cin >> V;
  vector<int> a(V-1);
  vector<int> b(V-1);
  for(int i = 0;i < V-1;i++){
    edge e;
    edge f;
    cin >> a.at(i) >> b.at(i);
    e.to = b.at(i);
    f.to = a.at(i);
    e.cost = 1;
    f.cost = e.cost;
    g[a.at(i)].push_back(e);
    g[b.at(i)].push_back(f);
  }
  for(int i = 0;i <= V;i++){
    used[i] = false;
  }
  dijkstra(1);
  keiro = get_path(V);
  for(int i = 0;i < keiro.size();i++){
    //cout << 'i' << ' ' <<  i << endl;
    if(i <= (keiro.size() - 1) / 2){
      dfs(keiro.at(i),"Fennec",i);
    }
    else{
      dfs(keiro.at(i),"Snuke",i);
    }
  }
  //cout << fen << ' ' << snu << endl;
  if(fen > snu){
    cout << "Fennec" << endl;
  }
  else{
    cout << "Snuke" << endl;
  }
}

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

typedef long long ll;

int main(void) {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> L(n), R(n);
    for (int i = 0; i < n; ++ i) {
        L[i] = R[i] = i;
        cin >> a[i];
    }


    vector<int> st;
    for (int i = 0; i < n; ++ i) {
        while (!st.empty() && a[i] < a[st.back()]) {
            L[i] = L[st.back()];
            st.pop_back();
        }
        st.push_back(i);
    }

    st.clear();
    for (int i = n - 1; i >= 0; -- i) {
        while (!st.empty() && a[i] < a[st.back()]) {
            R[i] = R[st.back()];
            st.pop_back();
        }
        st.push_back(i);
    }

    ll ans = 0;
    for (int i = 0; i < n; ++ i) {
        //cerr << L[i] << ' ' << R[i] << endl;
        ans += (ll)a[i] * (R[i] - i + 1) * (i - L[i] + 1);
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N, 0), B(N, 0);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  int count = 0;
  for(int i = 0; i < N; i++){
    while(A.at(i) % 2 == 0 && A.at(i) != 0){
      count++;
      A.at(i) /= 2;
    }
    B.at(i) = count;
    count = 0;
  }
  sort(B.begin(), B.end());
  cout << B.at(0)  << endl;
}
  

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
template<class T>bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    ll A, B, C, K; IN(A,B,C,K);
    if(K&1) cout << B - A << endl;
    else cout << A - B << endl;
    return 0;
}

Measured memory_bytes: 256
s = str(input())
S = s[::-1]

if s==S:
    t = s[0:int((len(s)-1)/2)]
    T = t[::-1]
    #print(t)
    if t ==T:
        p = s[int((len(s)+3)/2)-1:]
        P = p[::-1]
        #print(p)
        if p == P:
            print("Yes")
            quit()

print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 998244353;

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

    int n;
    cin >> n;

    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    if (d[0] != 0) {
        cout << 0 << endl;
        exit(0);
    }

    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        c[d[i]]++;
    }
    if (c[0] != 1) {
        cout << 0 << endl;
        exit(0);
    }

    ll r = 1, t = 1;
    int s = 1;
    for (int j = 1; j < n; j++) {
        for (int h = 0; h < c[j]; h++) {
            r = r * t % P;
        }
        s += c[j];
        if (s == n) break;
        t = c[j];
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
int W,H,x,y,r;
scanf ("%d%d%d%d%d",&W,&H,&x,&y,&r);
if( x>=r && (W-x)>=r && y>=r && (H-y)>=r )
printf ("Yes\n");
else printf ("No\n");
return 0;
}



Measured memory_bytes: 2104
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>

struct edge
{
  int to;
  int cap;
  int rev;
};

class dinic
{
private:
  int INF;
  std::vector<edge> G[100000];
  int level[100000];
  int iter[100000];
  
public:
  dinic();
  void add_edge(int from,int to,int cap);
  void bfs(int s);
  int dfs(int v,int t,int f);
  int maximum_flow(int s,int t);
};

dinic::dinic()
{
  INF=0x7fffffff;
  std::fill(level,level+100000,0);
  std::fill(iter,iter+100000,0);  
}

void dinic::add_edge(int from,int to,int cap)
{
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

void dinic::bfs(int s)
{
  std::memset(level,-1,sizeof(level));
  std::queue<int> que;
  level[s]=0;
  que.push(s);
  while(!que.empty())
    {
      int v=que.front();
      que.pop();
      for(int i=0;i<(int)G[v].size();i++)
	{
	  edge &e=G[v][i];
	  if(e.cap>0&&level[e.to]<0)
	    {
	      level[e.to]=level[v]+1;
	      que.push(e.to);
	    }
	}
    }
}

int dinic::dfs(int v,int t,int f)
{
  if(v==t) return f;
  for(int &i=iter[v];i<(int)G[v].size();i++)
    {
      edge &e=G[v][i];
      if(e.cap>0&&level[v]<level[e.to])
	{
	  int d=dfs(e.to,t,std::min(f,e.cap));
	  if(d>0)
	    {
	      e.cap-=d;
	      G[e.to][e.rev].cap+=d;
	      return d;
	    }
	}
    }
  return 0;
}

int dinic::maximum_flow(int s,int t)
{
  int flow=0;
  for(;;)
    {
      bfs(s);
      if(level[t]<0)
	return flow;
      std::memset(iter,0,sizeof(iter));
      int f;
      while((f=dfs(s,t,INF))>0)
	flow+=f;
    }
}

int main()
{
  int V,E;
  int u,v,c;
  int i;
  dinic g;
  std::cin>>V>>E;
  for(i=0;i<E;i++)
    {
      std::cin>>u>>v>>c;
      g.add_edge(u,v,c);
    }
  std::cout<<g.maximum_flow(0,V-1)<<std::endl;
  return 0;
}

Measured memory_bytes: 6288
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, K = na()
mod = 1000000007

a = [0]
for d in range(1, K+1):
    a.append(pow(K//d, n, mod))
for i in range(K, 0, -1):
    j = 2*i
    while j <= K:
        a[i] -= a[j]
        j += i
    if a[i] < 0:
        a[i] %= mod
        if a[i] < 0: a[i] += mod

ans = 0
for i in range(1, K+1):
    ans += i*a[i]
print(ans%mod)


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

typedef long long ll;

const int N = 1e6 + 10;

ll a[N];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll sum = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	ll ans = 0;
	for (int i = 0; i < n; i++)
		ans += a[i] * (sum - a[i]);
	cout << ans / 2 << endl;
}

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

int main(int argc, char const *argv[])
{
    string A;
    string B;
    string C;
    cin >> A >> B >> C;
    int la = A.length();
    int lb = B.length();
    if (A[la-1]==B[0]&&B[lb-1]==C[0]) {
        cout << "YES";
    }    
    else
    {
        cout << "NO";
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    i64 h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;
    return 0;
}


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

int main()
{
    int w,a,b;
    while(scanf("%d%d%d",&w,&a,&b)==3)
    {   int t;
        if(b<a){
            t=a;
            a=b;
            b=t;
        }
        if(a+w>=b)
            printf("0\n");
        else
           printf("%d\n",b-a-w);
    }
    return 0;
}


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

int main(){
  int K,N;
  cin >> K >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  
  int ans = A[N-1] - A[0];
  for(int i=1;i<N;i++) ans = min(ans,K - (A[i]-A[i-1]));
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

int dfs(int dfs_i, const std::vector<int>& ds, std::vector<int>& xs) {
    if (dfs_i == ds.size()) {
        int res = 24,
            l = 0;
        for (int i = 1; i < 24; i++) {
            if (xs[i]) {
                res = std::min({res, 24 - i, i - l});
                l = i;
            }
        }
        return res;
    }

    int d = ds[dfs_i],
        res = 0;

    for (int i = 0; i < 2; i++) {
        if (xs[d] == 0) {
            xs[d]++;
            res = std::max(res, dfs(dfs_i + 1, ds, xs));
            xs[d]--;
        }
        d = (24 - d) % 24;
    }
    return res;
}

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

    int n;
    std::cin >> n;

    std::vector<int> ds(n);
    for (int i = 0; i < n; i++) {
        std::cin >> ds[i];
    }

    std::vector<int> xs(24, 0);
    xs[0] = 1;

    std::cout << dfs(0, ds, xs) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n;
int a[100010];
ll s[100010];
int main(void){
	cin >> n;
	rep(i, n) cin >> a[i];
	sort(a, a + n);

	s[0] = a[0];
	reps(i, 1, n) s[i] = s[i - 1] + a[i];
	int i = n - 1;
	while(i > 0 and a[i] <= s[i - 1] * 2)i--;
	printf("%d\n", n - i);
	return 0;
}

Measured memory_bytes: 1408
using System;

namespace ABC061_B_Counting_Roads
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			int n = int.Parse(input[0]);
			int m = int.Parse(input[1]);
			
			int[] count = new int[n + 1]; //都市番号が1から始まるため+1
			for (int i = 1; i <= n; i++)
				count[i] = 0;
			
			for (int i = 0; i < m; i++)
			{
				input = Console.ReadLine().Split(' ');
				count[int.Parse(input[0])]++;
				count[int.Parse(input[1])]++;
			}
			
			for(int i = 1; i <= n; i++)
				Console.WriteLine(count[i]);
		}
	}
}

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

int main(){
  int N,A,B,C,D;
  
  cin >> N >> A >> B;
  C = 0;
  for(int i=1;i<(N+1);i++){
  int ii = i;
  int a[5];
  a[0] = (ii%10);
  ii /=10;
  a[1] = (ii%10);
  ii /=10;
  a[2] = (ii%10);
  ii /=10;
  a[3] = (ii%10);
  ii /=10;
  a[4] = (ii%10);
  ii /=10;

//  std::cout << a[0] << a[1] << a[2] << a[3] << std::endl;
  int sum = a[0] + a[1] + a[2] +a[3] + a[4];
  if(sum >= A && sum <= B){
  C += i;
  }
  }
  std::cout << C << std::endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
const int N=1e5+10;
const int mod=1000000007;
vector<int>f[N];
int n,m,x,y;
long long ans=1;
void dfs(int u,int last)
{
	int sum;
	if(!last)sum=m-1;
	else sum=m-2;
	for(int v=0;v<f[u].size();v++)
		if(f[u][v]!=last)
		{
			dfs(f[u][v],u);
			ans=ans*1ll*sum%mod;
			sum--;
		}
	return;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		f[x].push_back(y);
		f[y].push_back(x);
	}
	dfs(1,0);
	printf("%lld",ans*1ll*m%mod);
	return 0;
}


Measured memory_bytes: 10368
using System;

namespace AtCoder.ABC097
{
    class a
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var spl = line.Split(' ');
            var a = int.Parse(spl[0]);
            var b = int.Parse(spl[1]);
            var c = int.Parse(spl[2]);
            var d = int.Parse(spl[3]);
            Console.WriteLine(Math.Abs(a - c) <= d || Math.Abs(a - b) <= d && Math.Abs(b - c) <= d ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11220
// O O O O O O O O O O O O O O O OO O OO O OO O O O TTCH O TTTCH O TTTCH O O O O
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("no-stack-protector")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
#include <cassert>

using namespace std;

// #define int long long
#define double long double
#define less less228
#define left left228
#define right right228

template<typename T> void uin(T &a, T b) {
    if (b < a) a = b;
}
template<typename T> void uax(T &a, T b) {
    if (b > a) a = b;
}


random_device rnd;

template<typename T> void shuffle(vector< T > &v) {
    for (int i = 1; i < (int)v.size(); ++i) {
        swap(v[rnd() % i], v[i]);
    }
    for (int i = (int)v.size() - 1; i; --i) {
        swap(v[rnd() % i], v[i]);
    } 
}




signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0) {
        cout << "Zero\n";
        return 0;
    }
    if (a >= 0) {
        cout << "Positive\n";
        return 0;
    }
    if ((b - a + 1) & 1) {
        cout << "Negative\n";
    } else {
        cout << "Positive\n";
    }
    return 0;
}
// RU_023

/*
6 5 2
5 1 3 6 2 4
1 3
1 6
3 5
4 5
2 2

3 3 5
1 12 6
1 3
2 3
1 2

shironury

boootgslkfjdaojfdopsjfopjso
pgjq]pogjopsjg\qrwjopg
j
pogjqwrjgp]oqwjjqw]pjljfojpjowjow4jgopja    ohbip]aeo'rogpoaj0
[bkrw
pР С‘Р С—РЎС“РЎРѓРЎвЂљРЎРЉР В±РЎС“Р Т‘Р ВµРЎвЂљРЎР‚РЎС“Р С”Р В°РЎвЂљР Р†Р С•РЎРЏРЎвЂљР Р†Р ВµРЎР‚Р Т‘Р В°ojgqwjp\\j\;sync_with_stdiojp
ojeofmpworuc[owejgoprwig
[sdkz
pgj
p[gjes
p0ghjqsp[

jg
prsjgopjg]prwjgoprejgopjrepogjrepog]jgoprejgrgjporeqjgoperjgoprejgopeqrjgopeqrjgoprqwjgpoqjrwsopt4ng\ojsbjsoprnbfqsn\bvhqerpogjorwo
pwewh\rwh \wjiowe orw jop jgr\p jpj o jopj gr\pj p gjop j\pj\pe jp'oj [
 k
 p[eq   fj\pjfdwj\ejopjojopjopjf;'djpfsj, ipojs\p gpsdigsj gorkgjgjrogjdojgiao'fsdvopdshpdfidopcnweojccodj [cjd;ofjd[jdspmcojc"ajno[:Afvoq[w0shbprs`nm/jP{Vadmn;'fnc[Ajojsfpfjcffor 9int i= ; 1 < nfor (int i =1; for (int i =1 ; i <= n: ++i) frfor (int j = 1; j <= ml; ++'}]]]]]]]]]
5
1 5
1 2
2 3
2 
4
*/

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

int main()
{
  i64 h, w, a, b;
  cin >> h >> w >> a >> b;
  for (i64 i = 0; i < h; i++)
  {
    for (i64 j = 0; j < w; j++)
      cout << (((i < b) ^ (j < a)) ? 0 : 1);
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
	bool is_visited;
} edge;
int main( void ){
	edge E;
	int N, Q;
	cin >> N >> Q;
	vector <edge> array( N );
	rep( i, 0, N - 1 ){
		int a, b;
		cin >> a  >> b;
		a--;
		b--;
		array[ a ].to.push_back( b );
		array[ b ].to.push_back( a );
		array[ a ].cost = 0;
	}
	rep( i, 0, Q ){
		int e, cost;
		cin >> e >> cost;
		array[ e - 1 ].cost += cost;
	}
	rep(i, 1, N){
		array[i].is_visited = false;
	}
	array[0].is_visited = false;
	stack <int> st;
	st.push( 0 );
	while(!st.empty()){
		int e = st.top(); st.pop();
		array[ e ].is_visited = true;
		for(auto to: array[ e ].to){
			// if (array[e].dist > array[to].dist)
			// 	continue;
			if (array[to].is_visited)
				continue;
			st.push(to);
			array[to].cost += array[e].cost;
		}
	}
	rep(i,0,N){
		cout << array[i].cost << " ";
	}
	cout << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 16372
#include <iostream>
using namespace std;
int main()
{
	int A, B;
	cin >> A >> B;

	if (A == B)
	{
		cout << "Draw";
	}
	else
	{
		if (A == 1) {
			cout << "Alice";
		}
		else if (B == 1) {
			cout << "Bob";
		}
		else {
			if (A < B) {
				cout << "Bob";
			}
			else
			{
				cout << "Alice";
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
// Traveling Plan

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n+2, 0);

    int sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += abs(a[i-1] - a[i]);
    }
    sum += abs(a[n] - a[n+1]);

    int res = 0;
    for (int i = 1; i < n+1; i++) {
        cout << sum - abs(a[i+1] - a[i]) - abs(a[i] - a[i-1]) + abs(a[i+1] - a[i-1]) << endl;
    }

    return 0;
}


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

int main(){
    long long int x;
    cin >> x;
    for(long long int i = -5000; i < 5000; i++){
        for(long long int j = -5000; j < 5000; j++){
            if(i*i*i*i*i - j*j*j*j*j == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int main(){
	int a, b,n;
	while(cin >> a>>b){
		n=a+b;
		int ans = 1;
		while(n>=10){
			n/=10;
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int a = scanner.nextInt();
      if (a < 0) {
        break;
      }
      if (a == 0) {
        System.out.println(0);
        continue;
      }
      System.out.println(aaa(a));
    }
  }
  public static String aaa (int a) {
    if (a == 0) {
      return "";
    }
    return aaa(a / 4) + a % 4;
  }
}

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<vector<int>> v(n);
	while(m--){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		v[a].emplace_back(b);
		v[b].emplace_back(a);
	}
	deque<int> dq;
	dq.emplace_back(0);
	bool done[n]{};
	done[0] = true;
	while(true){
		bool f = true;
		int x = *dq.begin(), y = *dq.rbegin();
		for(int i:v[x]) if(!done[i]){
			dq.emplace_front(i);
			done[i] = true;
			f = false;
			break;
		}
		for(int i:v[y]) if(!done[i]){
			dq.emplace_back(i);
			done[i] = true;
			f = false;
			break;
		}
		if(f) break;
	}
	cout << dq.size() << endl;
	for_each(dq.begin(), dq.end(), [](int i){cout << i + 1 << ' ';});
	cout << endl;
	return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
ll mod=1e9+7;
ll dp[2001][2001];
const int M=2000*2000;
ll f[M+1],g[M+1],inv[M+1];
void precalc(){
	f[0]=1;
	rep1(i,M) f[i]=f[i-1]*i%mod;
	inv[1]=1;
	for(int i=2;i<=M;i++) inv[i]=mod-mod/i*inv[mod%i]%mod;
	g[0]=1;
	rep1(i,M) g[i]=g[i-1]*inv[i]%mod;
}
ll C(int x,int y){
	return f[x]*g[y]%mod*g[x-y]%mod;
}
void add(ll &x,ll y){
	x+=y;
	x%=mod;
}
int main(){
	precalc();
	int N,K;
	cin>>N>>K;
	if(K==1){
		puts("1");
		return 0;
	}
	dp[1][0]=1;
	rep1(i,N) rep(j,i+1){
//		printf("dp[%d][%d]=%lld\n",i,j,dp[i][j]);
		if(i!=N) add(dp[i+1][j],dp[i][j]);
		if(j!=i){
			int left=N*K-i-j*(K-1)-1;
			add(dp[i][j+1],dp[i][j]*C(left,K-2));
		}
	}
	ll ans=dp[N][N];
	rep1(i,N) ans=ans*i%mod;
	cout<<ans<<endl;
}


Measured memory_bytes: 116608
#include <algorithm>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <iostream>
#include <set>

typedef long long ll;

using namespace std;

ll memo[64][64];
ll cmb(int n, int k){
  if(memo[n][k] != 0) return memo[n][k];
  ll ret = 1;
  REP(i,k) ret = ret * (n - i) / (i + 1);
  return memo[n][k] = ret;
}

ll bc[50];
ll its[50];

int main(){
  ll n; cin >> n;
  const ll nn = n;

  REP(i,50){
    if(i < 2){
      bc[i] = 0;
      its[i] = 0;
    }else{
      bc[i] = (1ll << (i - 1)) - 1;
      its[i] = 0;
      REP(j,i/2+1) its[i] += cmb(i/2,j) * cmb(i-i/2,j);
      its[i]--;
    }
  }

  vector<pair<ll, vector<int> > > memo;

  for(int i = 2; i < 50; i++){
    vector<int> v(1, i);
    memo.push_back(make_pair(bc[i], v));
    for(int j = 2; j <= i; j++){
      v.push_back(j);
      memo.push_back(make_pair(bc[i] + bc[j] + its[i] * its[j], v));
      for(int k = 2; k <= j; k++){
        v.push_back(k);
        ll t = 0;
        t += bc[i] + bc[j] + bc[k];
        t += its[i] * its[j] + its[j] * its[k] + its[k] * its[i];
        t += its[i] * its[j] * its[k];

        memo.push_back(make_pair(t, v));
        v.pop_back();
      }
      v.pop_back();
    }
  }

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

  vector<vector<int> > ans;
  while(n){
    auto it = lower_bound(memo.begin(), memo.end(), make_pair(n, vector<int>()));
    if(it->first > n) --it;
    ans.push_back(it->second);
    n -= it->first;
  }

  int t = 0;
  for(const auto p : ans)
    for(const auto v : p)
      t += v;
  printf("%d\n", t);

  int a = 1;
  vector<int> res;
  for(const auto p : ans){
    REP(i,p.size()) REP(j,p[i]-p[i]/2)
      res.push_back(a + i);
    REP(i,p.size()) REP(j,p[i]/2)
      res.push_back(a + i);
    a += p.size();
  }

  for(const int p : res) printf("%d ", p);
  puts("");
  /*
  ll c = 0;
  REP(i,1<<t) if(i && __builtin_popcount(i) % 2 == 0){
    vector<int> a;
    REP(j,t) if(i & (1 << j)) a.push_back(res[j]);
    bool ok = true;
    REP(j,a.size()/2) ok &= a[j] == a[a.size()/2+j];
    if(ok) c++;
  }

  puts(c == nn ? "OK" : "NG");
  if(c != nn) printf("%lld %lld\n", nn, c);
  */
  return 0;
}


Measured memory_bytes: 1784
S=input();T=input();p=0;e=1
for s in T:
  q=p%len(S)
  if not s in S:e=0;break
  if s in S[q:]:p+=S[q:].index(s)+1
  else:p+=S.index(s)+len(S[q:])+1
print((p+1)*e-1)

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


int main(void){
	string str; cin >> str;
	if(str <= "2019/04/30") cout << "Heisei";
	else cout << "TBD";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
int a[200005];
double x[10];
double y[10];
double ans;
double k[10][10];
int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>x[i]>>y[i];
	}
	rep(i,n)rep(j,n)
	{
		double t=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
		ans+=sqrt(t);
	}
	//cout<<ans/(double)n<<endl;
	printf("%.7f\n",ans/(double)n);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
	if(a==0) return b;
	else return gcd(b%a,a);
}
int main(){
	ll n;
	ll clock[110];
	cin>>n;
	for(int i=0;i<n;i++) cin>>clock[i];
	ll temp=clock[0];
	for(int i=1;i<n;i++){
		ll flag=gcd(temp,clock[i]);
		temp*=(clock[i]/flag);
	}
	cout<<temp<<endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, A, B; scanf("%d %d %d", &N, &A, &B);
  vector<ll> V(N + 1, 0);
  for (int i = 1; i <= N; ++i) {
    scanf("%lld", &V[i]);
  }
  sort(V.begin() + 1, V.end(), greater<ll>());

  ll sum = accumulate(V.begin() + 1, V.begin() + 1 + A, 0LL);
  double ans_avg = 1.0 * sum / A;

  vector<vector<ll> > combi(55, vector<ll>(55, 0));
  for (int i = 0; i < 55 - 1; ++i) {
    combi[i][0] = 1;
    for (int j = 0; j <= i; ++j) {
      combi[i + 1][j] += combi[i][j];
      combi[i + 1][j + 1] += combi[i][j];
    }
  }

  ll ans = 0;
  if (V[1] == V[A]) {
    int n = A;
    while (n + 1 <= N and V[1] == V[n + 1]) { ++n; }
    for (int r = A; r <= min(B, n); ++r) {
      ans += combi[n][r];
    }
  }
  else {
    int total = 0, cnt = 0;
    for (int i = 1; i <= N; ++i) {
      if (V[A] == V[i]) {
        ++total;
        if (i <= A) { ++cnt; }
      }
    }
    ans = combi[total][cnt];
  }
  printf("%lf\n", ans_avg);
  printf("%lld\n", ans);
  return 0;
}


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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

int main(){
    int x,y,z;
    cin >> x;
    cin >> y;
    cin >> z;

    x-=z;
    int count=-1;
    do{
        x-=y;
        x-=z;
        count++;
    }while(x>=0);

    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i,j,s;
		for(i=1;i<=9;i++){
			for(j=1;j<=9;j++){
			s=i * j;
			printf("%dx%d=%d\n",i,j,s);
		}
	}
	 return 0;
}

Measured memory_bytes: 924
using System;

namespace A____Therefore_
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());


            if ((n - 1) % 10 == 0)
            {
                Console.WriteLine("pon");
            }
            else if ((n - 1) % 10 == 0)
            {
                Console.WriteLine("pon");
            }
            else if ((n - 2) % 10 == 0)
            {
                Console.WriteLine("hon");
            }
            else if ((n - 3) % 10 == 0)
            {
                Console.WriteLine("bon");
            }
            else if ((n - 4) % 10 == 0)
            {
                Console.WriteLine("hon");
            }
            else if ((n - 5) % 10 == 0)
            {
                Console.WriteLine("hon");
            }
            else if ((n - 6) % 10 == 0)
            {
                Console.WriteLine("pon");
            }
            else if ((n - 7) % 10 == 0)
            {
                Console.WriteLine("hon");
            }
            else if ((n - 8) % 10 == 0)
            {
                Console.WriteLine("pon");
            }
            else if ((n - 9) % 10 == 0)
            {
                Console.WriteLine("hon");
            }
            else
            {
                Console.WriteLine("pon");
            }
        }
    }
}

Measured memory_bytes: 27480
/* AOJ0002 Digit Number */

#include <stdio.h>

int sum_digits(int n, int base)
{
    int count = 0;

    while(n) {
        count++;
        n /= base;
    }

    return count;
}

int main(void)
{
    int a, b;

    while(~scanf("%d%d", &a, &b))
        printf("%d\n", sum_digits(a + b, 10));

    return 0;
}


Measured memory_bytes: 2760
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]

ans = 100*11
for i in range(2**d):
    sum = 0
    cnt = 0
    a = []
    for j in range(d):
        if (i >> j) & 1 == 1:
            sum += (j+1)*100*pc[j][0] + pc[j][1]
            cnt += pc[j][0]
            a.append(j)
    if sum < g:
        for j in range(d):
            if d-j-1 not in a:
                for k in range(pc[d-j-1][0]):
                    if sum >= g:
                        break
                    sum += (d-j)*100
                    cnt += 1
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 9148
#include<bits/stdc++.h>
#define N 300005
using namespace std;
vector<int> G[N];
int n,m,l[N],r[N],now,ans,tr[N];
void M(int x,int d){ while(x<=m) tr[x]+=d,x+=(x&(-x));}
int Q(int x){ int s=0; while(x) s+=tr[x],x-=(x&(-x)); return s;}
int main()
{
	int i,j;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%d %d",&l[i],&r[i]);
		G[r[i]-l[i]+1].push_back(l[i]);
	  }
	now=n;
	for(i=1;i<=m;i++){
		now-=G[i-1].size(),ans=now;
		for(j=0;j<G[i-1].size();j++)
			M(G[i-1][j],1),M(G[i-1][j]+i-1,-1);
		for(j=i;j<=m;j+=i) ans+=Q(j);
		printf("%d\n",ans);
	  }
	return 0;
}


Measured memory_bytes: 13824
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#if defined(_MSC_VER)
#pragma warning(disable : 4996)  // VSでscanfを使う．
#endif

struct Task {
  int a, b;
  int start_time;

  bool operator<(const Task& task) {
    if (this->b == task.b) {
      return this->start_time < task.start_time;
    }

    return this->b < task.b;
  }
};

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

  vector<Task> tasks(n);

  for (int i = 0; i < n; i++) {
    cin >> tasks[i].a >> tasks[i].b;
    tasks[i].start_time = tasks[i].b - tasks[i].a;
  }

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

  int t = 0;
 
  for (int i = 0; i < n; i++) {
    if (t > tasks[i].start_time) {
      cout << "No" << endl;
      return 0;
    }

    t += tasks[i].a;
  }

  cout << "Yes" << endl;
  
  return 0;
}


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

int main(void){

    int A, B, K;

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

    if(A + K - 1 >= B - K + 1){
        for(int i = A; i <= B; i++){
            printf("%d\n", i);
        }
    }else{
        for(int i = A; i <= A + K - 1; i++){
            printf("%d\n", i);
        }
        for(int i = B - K + 1; i <= B; i++){
            printf("%d\n", i);
        }
    }

    return 0;
}

Measured memory_bytes: 1696
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 6001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
   ll H,W;
   cin >> H >> W;
   if(H == 1 || W == 1){
       cout << 1 << endl;
       return 0;
   }
   if(H % 2 == 0 || W % 2 == 0){
       cout << H * W / 2 << endl;
   }else{
       cout << (H * W + 1) / 2 << endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
  int z;
  if(b==0){
    z=1;
    z%=c;
    return z;
  }
  if(b==1){
    z=a;
    z%=c;
    return z;
  }
  else{
    return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
  }
}
bool IsPrime(int num){
  if(num<2) return false;
  else if(num==2) return true;
  else if(num%2==0) return false;
  double sqrtNum=sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
  return true;
}

int main(){
  int n;
  cin>>n;
  int vec[25];
  int vecb[25];
  int p=0;
  for(int i=1;i<101;i++){
    if(IsPrime(i)==true){
      vec[p]=i;
      p++;
    }
  }
  for(int i=0;i<25;i++){
    p=n;
    vecb[i]=0;
    while(p>=vec[i]){
      vecb[i]+=p/vec[i];
      p/=vec[i];
    }
  }
  int ans=0;
  for(int i=0;i<25;i++){
    if(vecb[i]>=74){
      ans++;
    }
  }
  for(int i=0;i<25;i++){
    for(int j=0;j<25;j++){
      if(i==j){
        continue;
      }
      if(vecb[j]>=2&&vecb[i]>=24){
        ans++;
      }
      if(vecb[j]>=4&&vecb[i]>=14){
        ans++;
      }
    }
  }
  for(int i=0;i<25;i++){
    for(int j=0;j<24;j++){
      for(int k=j+1;k<25;k++){
        if(i==j||j==k||k==i){
          continue;
        }
        if(vecb[i]>=2&&vecb[j]>=4&&vecb[k]>=4){
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())
table = [[i for i in input()] for _ in range(H)]
ans = 0

for h in range(1 << H):
    for w in range(1 << W):
        black = 0
        for i in range(H):
            if (h >> i) % 2 == 1:
                continue
            for j in range(W):
                if (w >> j) % 2 == 1:
                    continue
                if table[i][j] == '#':
                    black += 1
        if black == K:
            ans += 1

print(ans)


Measured memory_bytes: 9016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    int x[6], ans;
    rep(i, 1, 6)
    {
        cin >> x[i];
        if (x[i] == 0)
            ans = i;
    }
    cout << ans << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 3632
from itertools import combinations_with_replacement as comp_rplc

n, m, q = list(map(int, input().split()))

req = [list(map(int, input().split())) for _ in range(q)]

ans = 0

for seq in comp_rplc(range(1, m + 1), n):
  score = 0
  for a, b, c, d in req:
    if seq[b - 1] - seq[a - 1] == c:
      score += d
    
  ans = max(ans, score)

print(ans)

Measured memory_bytes: 9136