akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n, m;
int num_visited = 0;
int ans = 0;
vector<int> visited;
vector<vector<int>> G;

void dfs(int now) {
    int next;
    visited.at(now) = 1;
    num_visited++;
    if(num_visited == n) {
        ans++;
    }
    for(int i = 0; i < G.at(now).size(); ++i) {
        next = G.at(now).at(i);
        if(!visited.at(next)) dfs(next);
    }
    visited.at(now) = 0;
    num_visited--;
}

int main() {
    cin >> n >> m;
    G = vector<vector<int>>(n);
    visited = vector<int>(n, 0);
    for(int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G.at(a).push_back(b);
        G.at(b).push_back(a);
    }

    dfs(0);
    cout << ans << endl;
}

Measured memory_bytes: 256
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#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>
using namespace std;
int main()
{
	sync;
	ll n,m,c;
	cin>>n>>m>>c;
	ll b[m];
	input(b,m);
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		ll val=c;
		for(ll j=0;j<m;j++)
		{
			ll a;
			cin>>a;
			val+=b[j]*a;
		}
		if(val>0)
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf (long long)(1e9)
using namespace std;

struct data {
  long long p, c;
};

int n, m, s, t;
vector<int> edge[100005];
vector<vector<long long>> dist;
queue<data> qu;

long long solve();

int main() {
  cin >> n >> m;
  dist.assign(n, vector<long long>(3, inf));
  for(int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    edge[--a].push_back(--b);
  }
  cin >> s >> t;
  --s, --t;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  qu.push({s, 0});
  while(!qu.empty()) {
    data now = qu.front();
    qu.pop();
    if(dist[now.p][now.c % 3] < now.c) continue;
    for(int i = 0; i < edge[now.p].size(); ++i) {
      data nextp = now;
      ++nextp.c;
      nextp.p = edge[now.p][i];
      if(dist[nextp.p][nextp.c % 3] > nextp.c) {
        dist[nextp.p][nextp.c % 3] = nextp.c;
        qu.push(nextp);
      }
    }
  }
  if(dist[t][0] == inf) return -1;
  return dist[t][0] / 3;
}

Measured memory_bytes: 11136
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

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

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, M, X;
  cin >> N >> M >> X;
  vll C(N);
  vector<vll> A(N);
  REP(i, 0, N) {
    cin >> C[i];
    vll a(M);
    REP(j, 0, M) {
      cin >> a[j];
    }
    A[i] = a;
  }

  ll ans = kMod * 100;
  REP(i, 1, (ll) pow(2, N)) {
    ll sum = 0;
    vll now(M, 0);
    vll bought;
    REP(j, 0, N) {
//      cout << (ll) pow(2, j) << "," << i << ":" << ((ll) pow(2, j) & i) << endl;
      if (((ll) pow(2, j) & i) > 0) {
        sum += C[j];
        REP(m, 0, M) {
          now[m] += A[j][m];
        }
      }
    }
    if (count_if(now.begin(), now.end(), [& X](const auto& n) {
      return n >= X;
    }) == M) {
      ans = min(sum, ans);
    }
  }
  if (ans == kMod * 100) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	// m[a] = b: a は b 番目にある(番兵のために 1-indiziert にする)
	int m[n+2];
	for( int i = 1; i <= n; ++i ){
		int tmp; cin >> tmp;
		m[tmp] = i;
	}
	// 左端と右端の番兵
	// 0 は 0 番目，n+1 は n+1 番目にある
	m[0] = 0; m[n+1] = n+1;
	ll ans = 0;
	set<ll> bntzt;
	bntzt.insert(0); bntzt.insert(n+1);
	for( int k = 1; k <= n; ++k ){
		auto itr = bntzt.lower_bound(m[k]);
		ll r = *(itr);
		ll l = *(--itr);
		ans += k*(m[k]-l)*(r-m[k]);
		bntzt.insert(m[k]);
	}
	cout << ans << endl;	
	return 0;
}

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

using namespace std;

int main() {

  int n, a;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> a;
    if((a % 5 != 0 && a % 3 != 0) && a % 2 == 0){
      cout << "DENIED";
      return 0;
    }
  }
  cout << "APPROVED";
  return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main(){
  int a, t, x, y;
  //Input
  scanf("%d %d", &x, &y);
  if( y > x){
    t = x;
    x = y;
    y = t;
  }
  //Algo
  while(x % y != 0){
    a = x % y;
    x = y;
    y = a;
  }
  //Print
  printf("%d\n",y);

  return 0;
}

Measured memory_bytes: 592
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int a, b; cin >> a >> b;
  int n = 0;
  int prev = 0;
  loop(i,1,1000) {
    n += i;
    if (prev >= a and n >= b and (a-prev) == (b-n)) {
      cout << n-b << endl;
      break;
    }
    prev = n;
  }
  return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    set<char> x, y;
    for (int j = 0; j <= i; ++j) {
      x.insert(s[j]);
    }
    for (int j = i+1; j < n; ++j) {
      y.insert(s[j]);
    }
    set<char> v;
    set_intersection(x.begin(), x.end(), y.begin(), y.end(), inserter(v, v.begin()));
    // // v.resize(it-v.begin());
    // cout << v.size() << endl;
    // for (auto it : v) {
    //   cout << it <<  ' ';
    // } cout << endl;
    ans = max(ans, (int)v.size());
  }
  cout << ans << endl;
}


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

int main() {
    int n, m, temp_val;
    int a, b;
    vector<vector<pair<int, int>>> persons;
    vector<pair<int, int>> temp;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> m;
        temp.clear();
        for(int j = 0; j < m; ++j){
            cin >> a >> b;
            temp.push_back(make_pair(b, a));
        }
        persons.push_back(temp);
    }
    
    int limit = pow(2, n), count, max_count = 0;
    vector<bool> truth_vals(n);
    bool found, lied;
    for(int i = 0; i < limit; ++i){
        temp_val = i;
        count = 0;
        found = true;
        for(int j = 0; j < n; ++j){
            if(temp_val % 2 == 1){
                truth_vals[j] = true; 
                ++count;
            }else{
                truth_vals[j] = false;
            }
            temp_val /= 2;
        }
        for(int j = 0; j < n; ++j){
            for(int k = 0; truth_vals[j] && k < persons[j].size(); ++k){
                if(persons[j][k].first == 0 && truth_vals[persons[j][k].second - 1]){
                    found = false;
                    break;
                }else if(persons[j][k].first == 1 && !truth_vals[persons[j][k].second - 1]){
                    found = false;
                    break;
                }
            }   
        }
        
        if(found){
            max_count = max(count, max_count);
        }
    }
    cout << max_count << "\n";
    
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int k;
    cin>>k;
    int a=7%k;
    int count=1;
    rep(i,k){
        if(a==0) break;
        else {
            a=(10*a)%k;
            a=(a+7)%k;
            count++;
        }
    }
    if(count<k+1) cout<<count<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 3596
#include <iostream>

int main() {
    int A, B, C, X;
    std::cin >> A;
    std::cin >> B;
    std::cin >> C;
    std::cin >> X;

    int count = 0;
    for (int a = 0; a <= A; a ++) {
        for (int b = 0; b <= B; b ++) {
            if (500 * a + 100 * b <= X && 500 * a + 100 * b + 50 * C >= X) {
                count ++;
            }
        }
    }
    std::cout << count << std::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++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353a
#define pi acos(-1)
#define all(v) v.begin(),v.end()
 
int main(){
    int N;
    string s;
    cin>>N;
    cin>>s;
    int count=0;
    for(int i=0;i<s.size()-2;i++){
        if (s.at(i)=='A'){
            if (s.at(i+1)=='B'){
                if (s.at(i+2)=='C'){
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
}

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

int64_t n; // 人数
int64_t k; // 修行回数
int64_t maxTime;

int main() {

    //std::cout << "人数\n";
    cin >> n;
    //std::cout << "修行回数\n";
    cin >> k;

    int64_t cost[n];
    int64_t food[n];
    for(int64_t i=0; i < n; i++){
        //std::cout << i+1 << "/" << n << "人目のcost";
        cin >> cost[i];
    }
     for(int64_t i=0; i < n; i++){
        //std::cout << i+1 << "/" << n << "人目の食べにくさ";
        cin >> food[i];
    }   

    sort(food, food+n);
    sort(cost, cost+n, std::greater<>());

    maxTime = 0;
    for(int64_t i=0; i < n; i++){
        if(cost[i]*food[i] > maxTime){
            maxTime = cost[i]*food[i];
            //td::cout << " cost = " << cost[i] << "\n" ;
            //td::cout << " food = " << food[i] << "\n" ;
            //td::cout << " maxTime = " << maxTime << "\n" ;
        }
    }
    
    int64_t minVal = 0;
    int64_t maxVal = maxTime;
    int64_t x = 0;

    int64_t last_min = 0;
    int64_t last_max = 0;
    
    while(1){
        
        x = minVal + (maxVal-minVal)/2;
        
        int64_t k_cnt = 0; 
        for(int64_t i=0; i < n; i++){ 
            int64_t cost_ = x/food[i];
            if(cost_<cost[i]){
                k_cnt = k_cnt + cost[i]-cost_;
            }
        }
        
        last_min = minVal;
        last_max = maxVal;

        if(k_cnt<=k){// OK
            maxVal = x;
        }else{// NG
            minVal = x;
        }
        if(last_max-last_min==1){
            std::cout << maxVal << "\n" ;
            break;
        }       
    }
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
using namespace std;
#define N 20
#define M 33000
#define mod 1000000007
int n,m,f[M],bin[N],a[N][M],b[N][M];
bool ok(int x){return bool(x&1)==bool(x&2);}
void upd(int &x,int y){x+=y;x-=x>=mod?mod:0;}
int main(){
	scanf("%d%d",&n,&m);
	rep (i,1,m){
		int x,y;scanf("%d%d",&x,&y);
		a[x][1<<y-1]++;
	}
	bin[0]=1;rep (i,1,n) bin[i]=2*bin[i-1];
	rep (i,1,n) rep (j,1,(1<<n)-1){
		int k=j&-j;
		b[i][j]=b[i][j^k]+a[i][k];
	}
	f[0]=1;
	rep (i,1,(1<<n)-1) if (ok(i)){
		f[i]=1;
		for (int j=i&(i-1);j;--j&=i) if (ok(j)){//j:sg必须为0
			int k=i^j,now=f[k];//k:sg大于0
			rep (l,1,n){
				if (j>>l-1&1) now=(ll)now*bin[b[l][k]]%mod;
				if (k>>l-1&1) now=(ll)now*(bin[b[l][j]]-1)%mod;
			}
			upd(f[i],now);
		}
	}
	int ans=1;
	rep (i,1,m) ans=2ll*ans%mod;
	upd(ans,mod-f[(1<<n)-1]);
	cout<<ans<<'\n';
	return 0;
}

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

int main(){
  int x,y,a,b,c;cin>>x>>y>>a>>b>>c;
  ll ans=0;
  vector<ll> p(a,0),q(b,0),r(c,0),ttl;
  REP(i,a) cin>>p.at(i);
  sort(p.begin(),p.end(),greater<ll>());
  REP(i,b) cin>>q.at(i);
  sort(q.begin(),q.end(),greater<ll>());
  REP(i,c) cin>>r.at(i);
  sort(r.begin(),r.end(),greater<ll>());
  
  REP(i,x) ttl.push_back(p.at(i));
  REP(i,y) ttl.push_back(q.at(i));
  REP(i,c) ttl.push_back(r.at(i));
  sort(ttl.begin(),ttl.end(),greater<ll>());

  REP(i,x+y) ans+=ttl.at(i); 
  cout<<ans;
}

Measured memory_bytes: 8560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 17;
const ll INF = LLONG_MAX/3;
map<ll,ll> dp[N][N];

int main()
{
    int n,K;
    cin >>n >>K;
    vector<ll> a(n);
    rep(i,n) cin >>a[i];

    dp[0][0][0]=0;
    rep(i,n)rep(j,i+1)
    {
        for(const auto &p:dp[i][j])
        {
            ll k=p.fi, v=p.se;

            if(!dp[i+1][j+1].count(a[i])) dp[i+1][j+1][a[i]]=INF;
            if(!dp[i+1][j].count(k)) dp[i+1][j][k]=INF;
            if(!dp[i+1][j+1].count(k+1)) dp[i+1][j+1][k+1]=INF;

            if(k<a[i])
            {
                dp[i+1][j+1][a[i]] = min(dp[i+1][j+1][a[i]],v);
            }
            else
            {
                dp[i+1][j][k] = min(dp[i+1][j][k],v);
                dp[i+1][j+1][k+1] = min(dp[i+1][j+1][k+1],v+k+1-a[i]);
            }
        }
    }

    ll ans = INF;
    for(int i=K; i<=n; ++i)for(const auto &p:dp[n][i]) ans = min(ans,p.se);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){
    int n;
    cin >> n;
    vector<ll>a(n+1);
    vector<ll>b(n);
    rep(i,n+1)cin >> a[i];
    rep(i,n)cin >> b[i];
    ll ans = 0; 
    rep(i,n){
        int left = min(a[i],b[i]);
        a[i]-=left;
        b[i]-=left;
        ans+= left;

        int right = min(a[i+1],b[i]);
        a[i+1]-=right;
        b[i]-=right;
        ans +=right;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1920
N,W=map(int,input().split())
wv=[]
for i in range(N):
    a,b=map(int,input().split())
    wv.append((a,b))
if wv[0][0]<300:
    dp=[[0]*(30000+1) for i in range(N+1)]
    for i in range(1,N+1):
        wi,vi=wv[i-1]
        for j in range(1,30000+1):
            dp[i][j]=dp[i-1][j]
            if j-wi<0:
                continue
            dp[i][j]=max(dp[i-1][j-wi]+vi,dp[i][j])
    ans=dp[N][W]
    print(ans)
    quit()
dp=[[0]*(301*101) for i in range(N+1)]
d=wv[0][0]
def change(n):
    return 301*(n//d)+min(n%d,300)
#if change(W)>301*101:
#    quit()
for i in range(1,N+1):
    wi,vi=wv[i-1]
    z=301+(wi-d)
    for j in range(1,301*101):
        dp[i][j]=dp[i-1][j]
        if j-z<0:
            continue

        dp[i][j]=max(dp[i-1][j-z]+vi,dp[i][j])
ans=dp[N][change(W)]
print(ans)


Measured memory_bytes: 66028
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    use std::collections::HashMap;

    let n: usize = read();
    let mut s = HashMap::new();

    for i in 0..n {
        let si: String = read();
        let count = s.entry(si).or_insert(0);
        *count += 1;
    }

    let mut ans: usize = 0;
    for (key, value) in &s {
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 18128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  if(max(a,b) <= 8 ){
    cout << "Yay!"<< endl; 
  }else{
    cout << ":(" << endl; 
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
using namespace std;

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

    vector<string> S(N);
    vector<int> P(N);
    vector<pair<pair<string, int>, int>> x(N);
    for(int i = 0; i < N; i++)
    {
        cin >> S[i] >> P[i];
        x[i] = make_pair(make_pair(S[i], -P[i]), i);
    }

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

    for(int i = 0; i < N; i++)
    {
        cout << x[i].second + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))

nums.sort()
mod = 10 ** 9 + 7

# x ** a をmodで割った余りを、O(log(a))時間で求める。
def power(x, a):
	if a == 0:
		return 1
	elif a == 1:
		return x
	elif a % 2 == 0:
		return power(x, a//2) **2 % mod
	else:
		return power(x, a//2) **2 * x % mod

# xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
# https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
def modinv(x):
	return power(x, mod-2)

# 二項係数の左側の数字の最大値を max_len　とする。nとかだと他の変数と被りそうなので。
# factori_table = [1, 1, 2, 6, 24, 120, ...] 要は factori_table[n] = n!
# 計算時間はO(max_len * log(mod))

max_len = n #適宜変更する

factori_table = [1] * (max_len + 1)
factori_inv_table = [1] * (max_len + 1)
for i in range(1, max_len + 1):
	factori_table[i] = factori_table[i-1] * (i) % mod
	factori_inv_table[i] = modinv(factori_table[i])

def binomial_coefficients(n, k):
	# n! / (k! * (n-k)! )
	return (factori_table[n] * factori_inv_table[k] * factori_inv_table[n-k]) % mod

# print(nums)

ans = 0
for i in reversed(range(k-1, n)):
    ans += (nums[i] * binomial_coefficients(i, k-1)) % mod
#    print(nums[i] , binomial_coefficients(i, k-1))


for i in range(n-k+1):
    ans -= (nums[i] * binomial_coefficients(n-i-1, k-1)) % mod
#    print(nums[i] , binomial_coefficients(n-i-1, k-1))

print(ans % mod)


Measured memory_bytes: 14908
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	
	cin >> N;

	//ll a[N];
	ll pair = 0;
	ll remaining = 0;
	rep(i, N)
	{
		ll a;
		cin >> a;
		if (a == 0)
		{
			remaining = 0;
			continue;
		}
		ll tmp = (remaining + a) >> 1; 
		pair += tmp;
		remaining = (a + remaining) - tmp * 2;
	}

	cout << pair << endl;

	
	return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  vsort(a);
  
  ll pre=0;
  ll ans=0;
  rep(i,n){
    if(pre<a[i]){
      ans++;
      pre=a[i];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
n=int(input())
l=list(map(int,input().split()))
flag=0
for i in l:
    if i%2==0:
        if (i%5==0 or i%3==0):
            continue
        else:
            flag=1
            break
if flag==0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#include <tuple>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n, m;
vector<int> e[1010];

int v[1010], last[1010];
vector<int> r(2000, 0);
void bfs(int node) {
	queue<int> q;
	for (int x : e[node])
		q.emplace(x), v[x] = last[x] = node;
	while (!q.empty()) {
		int cur = q.front();
		q.pop();

		for (int x : e[cur])
			if (v[x] != node)
				q.emplace(x), v[x] = node, last[x] = cur;
	}
	if (v[node] != node)
		return;
	int pop = node;
	vector<int> path;
	path.emplace_back(node);
	while (last[pop] != node) {
		path.emplace_back(last[pop]);
		pop = last[pop];
	}
	if (path.size() < r.size())
		r.swap(path);
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		e[a].emplace_back(b);
	}
	for (int i = 1; i <= n; i++)
		bfs(i);
	if (n < r.size())
		printf("-1\n");
	else {
		printf("%d\n", r.size());
		for (int v : r)
			printf("%d\n", v);
	}
}

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

int main() {
    int a, b, c;
    bool ok = false;
    cin >> a >> b >> c;
    for(int i=1;i<=b;i++){
        if(a*i%b == c){
            ok = true;
        }
    }
    if(ok){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}


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

using namespace std;

const int MAXN=1e5+5;
int N,ABC[3];
char buf[4];

int main(){
    scanf("%d%d%d%d",&N,ABC,ABC+1,ABC+2);

    vector<char> ans;
    bool inDanger=false;
    for(int i=0;i<N;i++){
        if (!inDanger)
            scanf("%s",buf);
        else 
            inDanger=false;
        int fst=buf[0]-'A',snd=buf[1]-'A';
        if (ABC[fst]==0&&ABC[snd]==0){
            puts("No");
            return 0;
        } 

        if (ABC[fst]==1&&ABC[snd]==1){
            scanf("%s",buf);
            int nxtFst=buf[0]-'A',nxtSnd=buf[1]-'A';
            if (fst==nxtFst||fst==nxtSnd)
                ans.push_back(fst+'A'),ABC[fst]++,ABC[snd]--;
            else 
                ans.push_back(snd+'A'),ABC[fst]--,ABC[snd]++;

            inDanger=true;
            continue;
        }  

        if (ABC[fst]>ABC[snd])
            ans.push_back(snd+'A'),ABC[fst]--,ABC[snd]++;
        else 
            ans.push_back(fst+'A'),ABC[fst]++,ABC[snd]--;
    }

    puts("Yes");
    for(auto &c:ans) printf("%c\n",c);

    return 0;
}

Measured memory_bytes: 3352
def Main(N, A):
    A.sort()
    for i in range(N):
        if(A[i] == A[i-1]):
            return "NO"
    return "YES"

def main():
    N = int(input())
    A = list(map(int, input().split()))
    print(Main(N, A))

if __name__ == '__main__':
    main()

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

int main(){
    int n;
    cin>>n;
    long long  t1,a1,t2,a2;
    cin>>t1>>a1;
    for(int i=1;i<n;i++){
        cin>>t2>>a2;
        long long tmp1=max(((t1+t2-1)/t2),((a1+a2-1)/a2));
        t1=tmp1*t2;
        a1=tmp1*a2;
    }
    cout<<a1+t1<<endl;
    return 0;
}

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

int main(){
    int d,n;
    cin >> d >> n;
    if(d == 0){
        if(n == 100){
            cout << 101 << endl;
        }else{
            cout << n << endl;
        }
    }else if(d == 1){
        if(n == 100){
            cout << 10100 << endl;
        }else{
            cout << 100 * n << endl;
        }
    }else{
        if(n == 100){
            cout << 1010000 << endl;
        }else{
            cout << 10000 * n << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
	{
		static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			int	x=int.Parse(input[1]);
			int y=int.Parse(input[2]);
			int c=0;
			int n=int.Parse(input[0]);
			int d=0;
			if(x>=y)
			{
				c=y;
				if(n-c-x >0)
				{
					d=0;
				}
				else
				{
					d=(n-c-x)*-1;
				}
			}
			else
			{
				c=x;
				if(n-c-y >0)
				{
					d=0;
				}
				else
				{
					d=(n-c-y)*-1;
				}
			}

			Console.WriteLine(c + " " + d);
			
		}
	}

Measured memory_bytes: 13140
#include <iostream>
#include <cstring>
#include <map>
#define pb push_back
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		map<string,int> m;
		string str, rstr;
		cin >> str;
		m[str] = 1;
		for(int j = 0; j < str.size(); j++) rstr.pb(str[str.size()-1-j]);
		m[rstr] = 1;
		for(int j = 1; j < str.size(); j++){
			string s1, s2, rs1, rs2;
			for(int k = 0; k < j; k++){
				s1.pb(str[k]);
				rs1.pb(str[j-1-k]);
			}
			for(int k = j; k < str.size(); k++){
				s2.pb(str[k]);
				rs2.pb(str[str.size()-1+j-k]);
			}
			//cout << s1 << " " << s2 << " " << rs1 << " " << rs2 << endl;
			m[s1+s2] = 1;
			m[rs1+s2] = 1;
			m[s1+rs2] = 1;
			m[rs1+rs2] = 1;
			m[s2+s1] = 1;
			m[rs2+s1] = 1;
			m[s2+rs1] = 1;
			m[rs2+rs1] = 1;
		}
		cout << m.size() << endl;
	}
}

Measured memory_bytes: 1324
array = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 ]
print(array[int(input())-1])

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

int main(){
  char a[]="Sunny";
  char b[]="Cloudy";
  char c[]="Rainy";
  char d[256];
  cin >> d;
  if(a[1]==d[1]){
    cout << b;
  }
  else if(b[1]==d[1]){
    cout << c;
  }
  else if(c[1]==d[1]){
    cout << a;
  }
  else{
    cout << "A";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin>>a;
  if(a[0]==a[1] && a[1]!=a[2] && a[2]==a[3])cout<<"Yes"<<endl;
  else if(a[0]==a[2] && a[2]!=a[1]&& a[1]==a[3])cout<<"Yes"<<endl;
  else if(a[0]==a[3] && a[3]!=a[1]&&a[1]==a[2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
 

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

  while(T--){
    int n;
    cin >> n;

    int t[n];
    int mn = 0, mx = 0;

    for(int i = 0; i < n; i++){
      cin >> t[i];
      if(i != 0){
        mn = min(mn, t[i] - t[i - 1]);
        mx = max(mx, t[i] - t[i - 1]);
      }
    }

    cout << abs(mx) << " " << abs(mn) << endl;
  }
}

Measured memory_bytes: 1160
N=int(input())
A=list(map(int,input().split()))
flag=0
count=1
for i in range(1,N):
    if A[i-1]<A[i]:
        if flag==-1:
            count+=1
            flag=0
        elif flag==0:
            flag=1
    elif A[i-1]>A[i]:
        if flag==1:
            count+=1
            flag=0
        elif flag==0:
            flag=-1
print(count)

Measured memory_bytes: 14224
N, M, C = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

number = 0
for _ in range(N):
    A = [int(i) for i in input().split()]
    point = sum([i * j for i, j in zip(A, B)]) + C
    if point > 0:
        number += 1

print(number)


Measured memory_bytes: 3060
A,b,c=map(int,input().split())
a=[A,b,c]
if a[0]!=a[1] and a[0]!=a[2]:
    print(a[0])
elif a[1]!=a[0] and a[1]!=a[2]:
    print(a[1])
elif a[2]!=a[0] and a[2]!=a[1]:
    print(a[2])

Measured memory_bytes: 3064
n_vertex, n_edge = gets.split.map(&:to_i)
#puts "#{n_vertex} #{n_edge}"
edges = n_vertex.times.map { Array.new(n_vertex, -1) }
for i in 0...n_edge do
  u, v, d = gets.split.map(&:to_i)
#  puts "#{u} #{v} #{d}"
  edges[u - 1][v - 1] = d
  edges[v - 1][u - 1] = d
end
#for i in 0...n_vertex do
#  puts edges[i].join(" ")
#end

for i in 1...n_vertex do
  if edges[0][i] > 0
    targ_v = i
    targ_d = edges[0][i]
    break
  end
end
#puts "#{targ_v} #{targ_d}"

t_max = gets.to_i
#puts "#{t_max}"
count = 0
for t in 0...t_max do
  n_new = gets.to_i
#  puts "#{n_new}"
  for i in 0...n_new do
    new_id, dst = gets.split.map(&:to_i)
#    puts "#{new_id} #{dst}"
  end
  
  if t < (t_max - targ_d + 1)
    command = -1
  else
    if count < targ_d
      command = targ_v + 1
      count += 1
    else
      command = -1
    end
  end
  puts command
end


Measured memory_bytes: 3324
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int INF = 1e9;

int nokori(int i, int j, int h, int w){
    return min({i, j, h-i-1, w-j-1});
}

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    REP(i,h) cin >> s[i];
    int si, sj;
    REP(i,h) REP(j,w) if (s[i][j] == 'S') si = i, sj = j;

    VVI dist(h, VI(w, INF));
    queue<P> que;
    que.push(P(si,sj));
    dist[si][sj] = 0;
    int di[] = {1,-1,0,0}, dj[] = {0,0,1,-1};
    while (!que.empty()){
        P p = que.front();
        que.pop();
        int i = p.first, j = p.second;
        REP(kk,4){
            int ii = i + di[kk], jj = j + dj[kk];
            if (ii < 0 || ii >= h || jj < 0 || jj >= w || s[ii][jj] == '#') continue;
            if (dist[ii][jj] != INF) continue;
            dist[ii][jj] = dist[i][j] + 1;
            if (dist[ii][jj] == k) continue;
            que.push(P(ii,jj));
        }
    }

    int ans = INF;
    REP(i,h) REP(j,w){
        if (dist[i][j] == INF) continue;
        ans = min(ans, 1 + (nokori(i, j, h, w)+k-1)/k);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <random>
#include <fstream>
#include <string>
#include <tuple>
#include <deque>

#define REP(i, N) for(int i = 0; i< N; i++)
using namespace std;
#define ll long long
const int INF = 1 << 29;
const ll llINF = 1 << 50;

const int MOD = 1000000007;

int main(){
    char S[20];
    int i = 0;
    bool mitasu = true;
    while((S[i] = getchar()) != '\n'){
        i++;
    }
    
    if(S[0] != 'A')mitasu = false;
    bool is_C = false;
    for(int j = 2; j < i - 1; j++){
        if(S[j] == 'C'){
            is_C = true;
            S[j] = 'c';
            break;
        }
    }
    if(!is_C)mitasu = false;
    bool komoji = true;
    for(int j = 1;j < i; j++){
        if(S[j] >= 'a' && S[j] <= 'z'){
        }else{
            komoji = false;
            break;
        }
    }
    if(!komoji)mitasu = false;
    if(mitasu)printf("AC\n");
    else {printf("WA\n");}
}


Measured memory_bytes: 888
s = input()
t = input()

lis_s = list(s)
lis_t = list(t)

lis_s.sort()
lis_t.sort()

lis_t.reverse()

ns = ""
nt = ""

for i in lis_s:
    ns += i

for i in lis_t:
    nt += i

if ns < nt:
    print ("Yes")
else:
    print ("No")


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

using namespace std;

int v[200005];
int vs[200005];

int main()
{

int n;
cin>>n;

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

    int a;
    cin>>a;

    v[i] = a;
    vs[i] = a;

}

sort(vs + 1, vs + n +1);

int x = vs[n/2];
int y = vs[(n/2)+1];

int a = (n/2)+1;
int b = (n/2);

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

    if(v[i] > x && v[i] > y) cout<<x<<endl;
    else if(v[i] == x) cout<<y<<endl;
    else if(v[i] == y) cout<<x<<endl;
    else if(v[i] < x && v[i] < y) cout<<y<<endl;

}




return 0;
}


Measured memory_bytes: 3712
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    N = int(input())
    a = list(map(int,input().split()))
    MOD = 10**9+7
    
    d = defaultdict(int)
    
    for x in a:
        num = x
        count = 0
        while num%2 == 0:
            num //= 2
            count += 1
        d[2] = max(d[2],count)
        for i in range(3,int(x**(1/2))+1,2):
            if num%i == 0:
                count = 0
                while num%i == 0:
                    num //= i
                    count += 1
                d[i] = max(d[i],count)
        if num != 1:
            d[num] = max(d[num],1)

    base = 1
    for x,y in d.items():
        base *= pow(x,y,MOD)
        base %= MOD
        
    s = 0
    for num in a:
        inv_a = pow(num,MOD-2,MOD)
        s += inv_a
        s %= MOD
        
    print((base*s)%MOD)

if __name__ == "__main__":
    main()


Measured memory_bytes: 4792
from collections import defaultdict

n, m = map(int, input().split())
dic = defaultdict(lambda: 0)

for _ in range(m):
  a, b = map(int, input().split())
  dic[a] += 1
  dic[b] += 1

for i in range(1,n+1):
  if i in dic:
	  print(dic[i])
  else:
      print(0)

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

#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int) c.size()
#define DBG1(x) cout<<#x<<" = "<<x<<"\n"
#if USE_CP_REDIR
#define CP \
    freopen("input.txt","r", stdin); \
    freopen("output.txt","w", stdout);
#endif

using ll = long long;
const ll MOD = 1'000'000'007;
const int MN = 200'000;
int DP[MN+1];

ll mod_add(ll a, ll b)
{
    return (((a % MOD) + (b % MOD)) % MOD);
} 

ll go(ll n){
    if(n < 3) return 0;
    if(DP[n] != -1) return DP[n];
    ll ans = 1;
    for(ll i = n-3; i >= 3; i--){
        ans = mod_add(ans, go(i));
    }
    DP[n] = ans;
    return ans;
}

int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    int S;
    cin >> S;
    memset(DP, -1, sizeof DP);
    if(S < 3){
        cout << 0 << endl;
    }else{
        ll ans;
        ans = go(S);
        cout << ans << endl;
    }
}

Measured memory_bytes: 4292
#include <stdio.h>
#include <string.h>

int main()
{
	int i, j;
	for ( i = 1 ; i < 10 ; i++ )
	{
		for ( j = 1 ; j < 10 ; j++ )
		{
			fprintf( stdout, "%dx%d=%d\n", i, j, i*j );
		}
	}

	return 0;
}

Measured memory_bytes: 524
# https://atcoder.jp/contests/abc087/tasks/abc087_b
a, b, c, X = [int(input()) for i in range(4)]
n = 0
for i in range(X//500+1):
    if i > a:
        pass
    else:
        Y = X - 500 * i
        for j in range(Y // 100 + 1):
            if j > b:
                pass
            else:
                Z = Y - 100 * j
                for k in range(Z // 50 + 1):
                    if k > c:
                        pass
                    elif Z - 50 * k == 0:
                        n += 1
                    else:
                        pass

print(n)


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 2010
#define INF   1000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll cnt[MAX_N];

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

    ll N, X, Y;
    cin >> N >> X >> Y;
    
    fill(cnt, cnt + MAX_N, 0);
    
    for(ll i = 1; i < N; i++) {
      for(ll j = i + 1; j <= N; j++) {

	ll d1 = abs(j - i);
	ll d2 = abs(X - i) + 1 + abs(Y - j);
	ll d3 = abs(Y - i) + 1 + abs(X - j);

	ll dist = min(d1, d2);
	dist = min(dist, d3);
	cnt[dist]++;
      }
    }

    for(ll i = 1; i <= N-1; i++) cout << cnt[i] << endl;
    return 0;
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
#define int long long
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
    FASTIO;
    string str;
    cin>>str;
    if(str[0]=='R' && str[1]=='R' && str[2]=='R')
    {
        cout<<3;
        return 0;
    }
    if(str[0]=='R' && str[1]=='R')
    {
        cout<<2;
        return 0;
    }
    if(str[1]=='R' && str[2]=='R')
    {
        cout<<2;
        return 0;
    }
    int cnt=0;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]=='R')
            cnt++;
    }
    if(cnt==0)
    {
        cout<<0;
        return 0;
    }
    cout<<1;
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();

		StringBuffer sb = new StringBuffer();
		for(int i = (x - k + 1);i <= (x + k - 1); i++) {
			sb.append(i).append(" ");
		}
		sb.setLength(sb.length()-1);

		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 22096
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC115
{
    class Program
    {
        static void Main(string[] args)
        {
            int D;

            var word = Console.ReadLine().Split(' ');

            D = int.Parse(word[0]);

            if (D == 22)
            {
                Console.WriteLine("Christmas Eve Eve Eve");
            }

            else if (D == 23)
            {
                Console.WriteLine("Christmas Eve Eve");
            }

            else if (D == 24)
            {
                Console.WriteLine("Christmas Eve");
            }

            else if (D == 25)
            {
                Console.WriteLine("Christmas");
            }

            Console.ReadKey();
        }

    }
}


Measured memory_bytes: 11092
n,m = map(int,input().split())
if n!=1 and m!=1:
    n-=2
    m-=2
    ans=n*m
    if ans < 0:
        ans=0
    print(ans)
elif n*m==2:
    print(0)
elif n*m==1:
    print(1)
else:
    if n==1:
        m-=2
    elif m==1:
        n-=2
    print(n*m)


Measured memory_bytes: 38256
def solve():
    L = input()
    N = len(L)
    mod = 10**9+7
    dp = [[0]*2 for _ in range(N+1)]
    dp[0][1] = 1
    for i in range(1,N+1):
        if L[i-1]=='1':
            dp[i][0] = dp[i-1][0]*3+dp[i-1][1]
            dp[i][1] = dp[i-1][1]*2
        else:
            dp[i][0] = dp[i-1][0]*3
            dp[i][1] = dp[i-1][1]
        dp[i][0]%=mod
        dp[i][1]%=mod
    ans = sum(dp[-1])%mod
    return ans
print(solve())

Measured memory_bytes: 54236
func readIntArray() -> [Int] {
    readLine()!.split(separator: " ").map({Int($0)!})
}

let N = Int(readLine()!)!
var A = readIntArray()
A.sort()

var multiple = Array.init(repeating: false, count: A.last! + 1)
var count = Array.init(repeating: 0, count: A.last! + 1)

A.forEach({ i in
    if count[i] == 0 && !multiple[i] {
        var j = 2
        while i * j <= A.last! {
            multiple[i * j] = true
            j += 1
        }
    }
    count[i] += 1
})

print(A.filter({count[$0] == 1 && !multiple[$0]}).count)


Measured memory_bytes: 22272
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int S = scan.nextInt();
		
		int h = S / 3600;
                int m = (S % 3600) / 60;
                int s = (S % 3600) % 60;
		
		System.out.println(h + ":" + m + ":" + s); 
		
	}
}

Measured memory_bytes: 26204
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

n = int(input())
a = []
for i in range(n):
    s, p = map(str, input().split())
    p = int(p)
    a.append((s,p,i+1))
# 要素[1]を逆ソート
a.sort(key=lambda x:x[1], reverse=True)
# 要素[0]を順ソート
a.sort(key=lambda x:x[0])

for i in range(n):
    print(a[i][2])


Measured memory_bytes: 9124
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

class ModInteger {
	public static long MOD = 1_000_000_007;
	private long x;

	public ModInteger(long n) {
		x = (n % MOD);
	}

	/** 和 */
	public ModInteger add(long augend) {
		return new ModInteger((x + augend) % MOD);
	}

	/** 和 */
	public ModInteger add(ModInteger augend) {
		return add(augend.x);
	}

	/** 逆元 */
	public ModInteger inv() {
		return pow(MOD - 2);
	}

	/** 商 */
	public ModInteger divide(long divisor) {
		return divide(new ModInteger(divisor));
	}

	/** 商 */
	public ModInteger divide(ModInteger divisor) {
		return multiply(divisor.inv());
	}

	/** 積 */
	public ModInteger multiply(long muultiplicand) {
		return new ModInteger((x * muultiplicand) % MOD);
	}

	/** 積 */
	public ModInteger multiply(ModInteger multiplicand) {
		return multiply(multiplicand.x);
	}

	/** 累乗 O(logN) */
	public ModInteger pow(long n) {
		// 繰り返し二乗法
		if (n == 0) {
			return new ModInteger(1);
		}
		ModInteger a = pow(n / 2);
		a = a.multiply(a);
		if (n % 2 == 1) {
			a = a.multiply(x);
		}
		return a;
	}

	/** 差 */
	public ModInteger subtract(long subtrahend) {
		return new ModInteger((x - subtrahend + MOD) % MOD);
	}

	/** 差 */
	public ModInteger subtract(ModInteger subtrahend) {
		return subtract(subtrahend.x);
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof ModInteger) {
			return x == ((ModInteger) o).x;
		}
		return false;
	}

	public boolean equals(long l) {
		return x == (l % MOD);
	}

	@Override
	public int hashCode() {
		return Long.hashCode(x);
	}

	public int compareTo(long val) {
		return Long.compare(x, val);
	}

	public int compareTo(ModInteger val) {
		return compareTo(val.x);
	}

	public long longValue() {
		return x;
	}

	@Override
	public String toString() {
		return Long.toString(x);
	}

	public static ModInteger valueOf(long x) {
		return new ModInteger(x);
	}

}

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	static ModInteger[] f;

	// 初期化 O(N)
	static public void init(int n) {
		f = new ModInteger[100100];
		f[0] = new ModInteger(1);
		for (int i = 1; i < f.length; i++) {
			f[i] = f[i - 1].multiply(i);
		}
	}

	static public ModInteger c(int n, int k) {
		// n! / ((n-k)!*k!)
		return f[n].divide(f[n - k].multiply(f[k]));
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int K = sc.nextInt();

		init(N+2);

		sc.close();

		
		for (int i = 1; i <= K; i++) {
			if(N-K+1 < i) {
				out.println(0);
				continue;
			}
			// 赤(N-K)の間と、左右端の中から、i個の青を入れる場所を選ぶ
			ModInteger a = c(N - K + 1, i);

			// 青(K)をiグループにわける
			ModInteger b = c(K - 1, i - 1);

			out.println(a.multiply(b));
		}
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 26324
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    int N, X;
    cin >> N >> X;
    int position = 0, count = 1;
    for (int i = 0; i < N; i++) {
        int L;
        cin >> L;
        position += L;
        if (position <= X) {
            count++;
        } else {
            break;
        }
    }
    cout << count << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M; 
    cin >> N >> M;
    vector<int> C(M); for(int i = 0; i < M; ++i) cin >> C[i];
    vector<int> dp(N+1, 1e9);
    for(int i = 0; i < M; ++i) dp[C[i]] = 1;
    for(int i = 0; i < N+1; ++i) {
        for(int j = 0;j < M; ++j) {
            if(i - C[j] >= 0) dp[i] = min(dp[i], dp[i-C[j]] + 1);
        }
    }
    cout << dp[N] << '\n';
    return 0;
}


Measured memory_bytes: 3236