akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

using namespace std;


bool dfs(bool state[], bool p1[], bool p2[], bool nowp1);

int main() {
  int N;
  cin >> N;
  for(int game = 0; game < N; game++) {
    int f[6];
    for(int i = 0; i < 6; i++) {
      cin >> f[i];
    }
    bool state[13];
    bool p1[13];
    bool p2[13];
    for(int i = 0; i < 13; i++) {
      state[i] = false;
      p1[i]    = false;
      p2[i]    = true;
    }
    state[6] = true;
    p2[6]    = false;
    for(int i = 0; i < 6; i++) {
      p1[f[i]-1] = true;
      p2[f[i]-1] = false;
    }

    bool ans = dfs(state,p1,p2,true);

    if(ans) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }

  }
}

bool dfs(bool state[], bool p1[], bool p2[], bool nowp1) {

  bool p1noc = true;
  bool p2noc = true;
  for(int i = 0; i < 13; i++) {
    if(p1[i]) p1noc = false;
    if(p2[i]) p2noc = false;
  }
  if(p1noc) return true;
  if(p2noc) return false;


  if(nowp1) {
    bool put = false;
    for(int i = 0; i < 13; i++) {
      if(i != 12) {
        if(state[i] && !state[i+1] && p1[i+1]) {
          state[i+1] = true;
          p1[i+1] = false;
          bool ans = dfs(state,p1,p2,false);
          state[i+1] = false;
          p1[i+1] = true;
          put = true;
          if(ans) return true;
        }
      }
      if(i != 0) {
        if(state[i] && !state[i-1] && p1[i-1]) {
          state[i-1] = true;
          p1[i-1] = false;
          bool ans = dfs(state,p1,p2,false);
          state[i-1] = false;
          p1[i-1] = true;
          put = true;
          if(ans) return true;
        }
      }
    }
    if(!put) {
      bool ans = dfs(state,p1,p2,false);
      if(ans) return true;
    }

    return false;
  } else {
    bool put = false;
    for(int i = 0; i < 13; i++) {
      if(i != 12) {
        if(state[i] && !state[i+1] && p2[i+1]) {
          state[i+1] = true;
          p2[i+1] = false;
          bool ans = dfs(state,p1,p2,true);
          state[i+1] = false;
          p2[i+1] = true;
          put = true;
          if(!ans) return false;
        }
      }
      if(i != 0) {
        if(state[i] && !state[i-1] && p2[i-1]) {
          state[i-1] = true;
          p2[i-1] = false;
          bool ans = dfs(state,p1,p2,true);
          state[i-1] = false;
          p2[i-1] = true;
          put = true;
          if(!ans) return false;
        }
      }
    }
    if(!put) {
      bool ans = dfs(state,p1,p2,true);
      if(!ans) return false;
    }
    return true;
  }
}

Measured memory_bytes: 3080
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<int>TopologicalSort(int n,vector<int>in,vector<int>e[]) {
	stack<int>st;
	for (int i = 0; i < n; i++)if (!in[i])st.push(i);
	vector<int>ret;
	while (st.size()) {
		int i = st.top();
		st.pop();
		ret.pb(i);
		fore(x, e[i]) {
			in[x]--;
			if (!in[x])st.push(x);
		}
	}
	return ret;
}

int A[10101010];
vector<int>beg(10101010);
void preKmp(string x) {
	A[0] = -1;
	int j = -1;
	for (int i = 0; i < x.size(); i++) {
		while (j >= 0 && x[i] != x[j])j = A[j];
		j++;
		if (x[i + 1] == x[j])A[i + 1] = A[j];
		else A[i + 1] = j;
	}
}
void Kmp(string x, string y) {
	preKmp(x);
	int xind = 0;
	for (int yind = 0; yind < y.size(); yind++) {
		while (xind >= 0 && x[xind] != y[yind])xind = A[xind];
		xind++;
		if (xind == x.size()) {
			beg[yind - x.size() + 1]++;
			xind = A[xind];
		}
	}
}

int dp[10101010];

int main() {
	string s, t;
	cin >> s >> t;
	string T = t;
	string S;
	while (S.size() <= T.size())S += s;
	Kmp(T,S+S);

	vector<int>edge[10101010];
	vector<int>in(S.size());
	for (int i = 0; i < S.size(); i++) {
		if (beg[i]){
			int to = (i + T.size()) % S.size();
			edge[i].pb(to);
			in[to]++;
		}
	}


	vector<int>ord = TopologicalSort(S.size(),in,edge);
	if (ord.size() != S.size()) {
		puts(-1);
		return 0;
	}

	int ans = 0;
	for (int i = 0; i < S.size()-1; i++) {
		int cur = ord[i];
		fore(to, edge[cur]) {
			dp[to] = max(dp[to], dp[cur] + 1);
			ans = max(ans, dp[to]);
		}
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 321528
n = int(input())
a = [int(i)%4 for i in input().split()]

cnt_4 = a.count(0)
cnt_2 = a.count(2)
cnt_0 = n - cnt_4 - cnt_2

if cnt_2 == 0:
  if cnt_4 >= cnt_0-1:
    print('Yes')
  else:
    print('No')
else:
  if cnt_4 >= cnt_0:
    print('Yes')
  else:
    print('No')
    

Measured memory_bytes: 11100
import sys
import collections

n = int(sys.stdin.readline())
a_list = [int(x) for x in sys.stdin.readlines()]
a_list_counter = collections.Counter(a_list)
count = 0
for i in a_list_counter:
    if a_list_counter[i] % 2 != 0:
        count += 1
    else:
        continue
print(count)


Measured memory_bytes: 18660
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long

int main(){

    int n;
    cin >> n;
    vector<ll int> a;
    ll int now;
    for(int i=0;i<n;i++){
        cin >> now;
        a.push_back(now);
    }
    sort(a.begin(),a.end());
    ll int back = -1;
    now = -1;
    int cnt = 0,ans = 0;
    for(int i=0;i<n;i++){
        now = a[i];
        if(back == now){
            cnt ++;
        }
        else{
            if(cnt%2 == 1){
                ans ++;
            }
            cnt = 1;
            back = now;
        }
    }
    if(cnt%2 == 1){
        ans ++;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main(void)
{
    int a, b, c, i;
    
    while(1){
        scanf("%d %d", &a, &b);
        if(a == 0 && b == 0) break;
        
        if(a < b){
            c = b;
            b = a;
            a = c;
        }
        for(i = 0;; i++){
            a = a % b;
            c = a;
            a = b;
            b = c;
            if(b == 0) break;
        }
        printf("%d %d\n", a, i+1);
    }
    return 0;
}


Measured memory_bytes: 2044
include Math

a,b,h,m =  gets.split.map(&:to_i)

m_degree = 360.0 / 60 * m
h_degree = 360.0 / 12 * h + 360.0 / 12 / 60 * m

mh_degree = (m_degree - h_degree).abs
if (mh_degree > 180)
  mh_degree = 360 - mh_degree
end

cosC = cos(mh_degree * PI / 180.0)
c2 = a*a + b*b - 2 * a * b * cosC
printf("%.12f\n", sqrt(c2));


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int a[252521];

int main(){
    scanf("%d",&n);
    REP(i,n)scanf("%d",a+i);
    int id = max_element(a,a+n)-a;
    int ans = a[id];
    a[id] = -252521;
    REP(i,n){
        if(i==id){
            printf("%d\n",*max_element(a,a+n));
        }else{
            printf("%d\n",ans);
        }
    }
    return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)

void solve() {
    vector<int> v;
    for (int i = 0; i < 3; i++) {
        int a;
        cin >> a;
        v.push_back(a);
    }
    sort(bn(v));
    cout << (v[1] == 5 ? "YES" : "NO");
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3632
s = gets.chomp

answers = [(0..s.size - 1).map { |i| i % 2 }, (0..s.size - 1).map { |i| (i + 1) % 2 }]

min = Float::INFINITY
answers.each do |ans|
  count = 0
  s.chars.to_a.map(&:to_i).each_with_index do |char, index|
    count += 1 if ans[index] == char
  end
  min = [count, min].min
end

puts min


Measured memory_bytes: 15100
/**
 * @author      : Luis Miguel Baez <es.luismiguelbaez@gmail.com>
 * @created     : Thursday August 13, 2020
 */

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(arr, value) memset(arr, value, sizeof arr)
#define ll    int64_t

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

// add template here

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template<class T>
void println(const T &data) {
#ifndef ONLINE_JUDGE
    cout << to_string((T)data) << endl;
#endif
}


const int oo  = (int)(1e9);
const ll lloo  = (ll)(1e18);

const int N = 1e5 + 10;

class Task {
public:
    int n;
    vector<int> A;

    ll dp[N];

    ll go(int index) {
        if(index > n) return 0LL;
        if(index == n) {
            return 0LL;
        }

        ll &ans = dp[index];
        if(ans != -1) return ans;

        ll x = oo;
        ll y = oo;

        if(index+1 <= n) {
            x = abs(A[index]-A[index+1]) + go(index + 1);
        }
        
        if(index+2 <= n) {
            y = abs(A[index]-A[index+2]) + go(index + 2);
        }
        ll mn = min(x, y);
        if(mn == oo) {
            ans = 0;
            return ans;
        }
        ans = min(x, y);
        return ans;
    }

    ll solveOne(istream &in, ostream &out) {
        in >> n;
        A.resize(n+1);
        for(int i = 1; i <= n; ++i){
            in >> A[i];
        }
        memset(dp, -1, sizeof dp);
        ll ans = go(1);
        return ans;  
    }
    
    void solve(istream &in, ostream &out) {
        int t = 1;
        while(t--) {
            out << solveOne(in, out) << endl;
        }
    }
};

auto main() -> int {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    Task solver;
    istream &in(cin);
    ostream &out(cout);
    solver.solve(in, out);
    return 0;
}



Measured memory_bytes: 12184
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int n, k;
vector<int> h;
ll memo[100100];

ll dp(int i){
    if(i == 0) return 0;
    if(memo[i] != INF) return memo[i];

    ll res = INF; 
    for(int j = 1; j <= k; j++){
        if(i - j >= 0){
            res = min(res, dp(i - j) + abs(h[i] - h[i - j]));
        }
    }

    return memo[i] = res;
}

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

    for(int i = 0; i <= n; i++){
        memo[i] = INF;
    }

    cout << dp(n - 1) << endl;
}

Measured memory_bytes: 7680
h,w = gets.chomp.split(" ").map(&:to_i)
a = h.times.map{gets.chomp}
x = Array.new(w,true)
y = Array.new(h,true)
for i in 0..h-1
  y[i] = false if !a[i].index("#")
end
for i in 0..w-1
  f = true
  for j in 0..h-1
    f = false if a[j][i] == "#"
  end
  x[i] = false if f
end
for i in 0..h-1
  next if y[i] == false
  for j in 0..w-1
    print a[i][j] if x[j]
  end
  puts ""
end

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <iomanip>

using namespace std;


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

	int count = 0;
	int score = 0;
	double p = 0.;
	for (int i = 1; i < N + 1; i++) {
		score = i;
		count = 0;

		while (score < K) {
			score = score * 2;
			count++;
		}

		p = p + 1. / double(N) * pow(0.5, double(count));
//		cout << 1. / double(N) * pow(0.5, count) << endl;
	}

	cout << std::setprecision(16) << p;
}

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


void solve(long long N, std::vector<long long> a){
    int ans = 0;
    int cnt = 0;
    for(int i = 0;i < N;i++){
        if(cnt + 1 == a[i]){
            cnt++;
        }
    }
    ans = max(ans, cnt);
    if(ans == 0){
        cout<<-1<<endl;
        return;
    }
    cout<<N-ans<<endl;
}

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


Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
int N, A[100001];
int main() {
  scanf("%d", &N);
  ll sumA = 0LL;
  for(int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    sumA += A[i];
  }
  A[0] = A[N], A[N+1] = A[1];
  ll ans[100001] = {0LL};
  for(int i = 1; i <= N; ++i) {
    ans[1] += pow(-1, i%2+1)*A[i];
  }
  printf("%ld", ans[1]);
  for(int i = 2; i <= N; ++i) {
    ans[i] = 2*A[i-1]-ans[i-1];
    printf(" %ld", ans[i]);
  }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//const ll MOD=(ll)1e9+7;
const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

struct Stat{
    ll d;
    ll x;
    ll y;
    int dir;
};
bool operator> (const Stat &student1, const Stat &student2){
    return student1.d > student2.d;
};

void solve(int ca){
    ll h,w,K,x1,x2,y1,y2; cin>>h>>w>>K>>x1>>y1>>x2>>y2;
    const int H=h, W=w;
    --x1; --x2; --y1; --y2;
    vector<string> c(H);
    for (int i = 0; i < H; ++i) {
        cin>>c[i];
    }
    ll dist[H][W][4];
    ll det[H][W][4];
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            for (int k = 0; k < 4; ++k) {
                dist[i][j][k]=INF;
                det[i][j][k]=false;
            }
        }
    }

    dist[x1][y1][0]=0;
    //dist[x1][y1][1]=K;
    //dist[x1][y1][2]=K;
    //dist[x1][y1][3]=K;

    priority_queue<Stat,vector<Stat>,greater<>> pq;

    pq.push({0ll,x1,y1,0});

    while(!pq.empty()){
        auto stat=pq.top();
        pq.pop();
        ll d=stat.d,x=stat.x,y=stat.y,dir=stat.dir;
        if(x==x2&&y==y2){
            cout<<d/K<<endl;
            //break;
            return;
        }
        if(det[x][y][dir]) continue;
        //cout<<d<<" "<<x<<" "<<y<<" "<<dir<<endl;
        det[x][y][dir]=true;
        for (int i = 0; i < 4; ++i) {
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<0||nx>=H||ny<0||ny>=W||c[nx][ny]=='@'||det[nx][ny][i]) continue;
            if((x==x1&&y==y1)||i!=dir){
                if(chmin(dist[nx][ny][i],d/K*K+K)) pq.push({dist[nx][ny][i],nx,ny,i});
            }else{
                //cout<<"called"<<endl;
                if(chmin(dist[nx][ny][i],d+1)) pq.push({dist[nx][ny][i],nx,ny,i});
            }
        }
    }
    cout<<-1<<endl;

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(1);
#endif
    return 0;
}


Measured memory_bytes: 75436
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

int parent[10005];

void init()
{
	for(int i = 0; i < 10005; i++) parent[i] = i;
}

int root(int n)
{
	if(parent[n] == n) return n;
	else return parent[n] = root( parent[n] );
}

bool same(int a, int b)
{
	return root(a) == root(b);
}

void unite(int a, int b)
{
	int root_a = root(a);
	int root_b = root(b);
	parent[root_a] = root_b;
}

struct edge{
	int s;
	int e;
	double cost;
	edge(int s, int e, double cost){
		this->s = s, this->e = e, this->cost = cost;
	}
	bool operator<(const edge &obj){
		return this->cost < obj.cost;
	}
};

int N, M;
long long posX[10005], posY[10005];
vector<edge> G;

int main(void)
{
	cin >> N >> M;
	for(int i = 1; i <= N; i++){
		cin >> posX[i] >> posY[i];
	}
	int s, e;
	double dist, sum = 0;
	for(int i = 0; i < M; i++){
		cin >> s >> e;
		dist = (posX[s] - posX[e]) * (posX[s] - posX[e]) + (posY[s] - posY[e]) * (posY[s] - posY[e]);
		dist = sqrt(dist);
		sum += dist;
		G.push_back( edge(s, e, dist) );
	}
	
	sort(G.begin(), G.end());
	reverse(G.begin(), G.end());
	
	init();
	
	for(int i = 0; i < M; i++){
		if(!same(G[i].s, G[i].e)){
			sum -= G[i].cost;
			unite(G[i].s, G[i].e);
		}
	}
	
	printf("%.8f\n", sum);
	return 0;
}

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

const int MOD = 998244353;

void solve_test() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22) {
		cout << "bust\n";
		return;
	}
	cout << "win\n";
}

int main() {
	int T;
	T = 1;
	for (int t = 1; t <= T; t++)
		solve_test();

	return 0;
}


Measured memory_bytes: 3636
#%%
n, k = map(int, input().split())
k = ['0'] * (42 - len(list(bin(k)[2:]))) + list(bin(k)[2:])
a = list(map(int, input().split()))

b = [[0] for _ in range(n)]
for i in range(n):
    b[i] = ['0'] * (42 - len(list(bin(a[i])[2:]))) + list(bin(a[i])[2:])

count = [[0, 0] for _ in range(42)]
for j in range(42):
    c_0, c_1 = 0, 0
    for i in range(n):
        if b[i][j] == '0':
            c_0 += 1
        else:
            c_1 += 1
    count[j] = c_0, c_1
        
ans = []
for i in range(42):
    if count[i][1] >= count[i][0]:
        ans.append('0')
    else:
        ans.append('1')

flag = False
for i in range(42):
    if ans[i] == '1' and k[i] == '0':
        ans[i] = '0'
    elif ans[i] == '0' and k[i] == '1':
        flag = True
    
    if flag:
        break

tmp = 0
ans = ans[::-1]
for i in range(42):
    if ans[i] == '1':
        tmp += 2**i

ans = 0
for i in range(n):
    ans += a[i] ^ tmp
print(ans)



Measured memory_bytes: 50592
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N,M;

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

    int div=1;
    int ans=1;
    while(div*div<=M){
        if(M%div==0){
            if(div>=N) ans=max(ans,M/div);
            if(M/div>=N) ans=max(ans,div);
        }
        div++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
c0 = 0
c1 = 0
c2 = 0
c3 = 0

for i in range(n):
    s = input()
    if  s == "AC":
        c0 += 1
    elif s == "WA":
        c1 += 1
    elif s == "TLE":
        c2 += 1
    else:
        c3 += 1

print("AC x " + str(c0))
print("WA x " + str(c1))
print("TLE x " + str(c2))
print("RE x " + str(c3))


Measured memory_bytes: 9196
using System;
using System.Linq;
using System.Collections.Generic;

class Mondai
{
    static void Main()
    {
        var S = Console.ReadLine().ToCharArray();
        var k = 15-S.Length;
        var kachi = 0;
        for (int i=0;i<S.Length;++i)
        {
            if (S[i] == 'o') kachi++;
        }
        var ans = 7 < kachi + k ? "YES" : "NO";
        Console.WriteLine(ans);
    }
}   

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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N, L =map(int, input().split())

arr = [None] * N

for i in range(N):
    arr[i] = L + i

minV = 1e20

for i in range(N):
    if abs(arr[i]) < abs(minV):
        minV = abs(arr[i])
        d = arr[i]

print(sum(arr) - d)


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

int main() {
	char	c;

	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int p[105];
main()
{
	int n;
    scanf("%d",&n);
    for(int i = 0;i < n;i++)
    {
        scanf("%d",&p[i]);
    }
    int cal=0,mn=1e9;
    for(int i = -200;i <= 200;i++)
    {
        cal=0;
        for(int j = 0;j < n;j++)
        {
            cal+=(i-p[j])*(i-p[j]);
        }
        mn=min(mn,cal);
    }
    printf("%d",mn);
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
  constexpr long double PI=3.1415926535897932384626433832795028841971693993751L;
  
  long double a,b,h,m;
  std::cin>>a>>b>>h>>m;
  
  long double angleH=h/12*2*PI+m/12/60*2*PI;
  long double angleM=m/60*2*PI;
  long double angleAOB=angleH-angleM;
  
  long double result=std::sqrt(a*a+b*b-2*a*b*std::cos(angleAOB));
  
  std::cout<<std::setprecision(30)<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 4168
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
//#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 100100;
int good[N];

int32_t main(){
 fastio;
 int n,m;
 cin>>n>>m;
 priority_queue<ll> pq;
 vector<int> a(n+1);
 for(int i=1;i<=n;i++){
  cin>>a[i];
  pq.push(a[i]);
 }
 while(!pq.empty()){
    if(m==0)break;
    m--;
    int cur = pq.top();
    pq.pop();
    pq.push(cur/2);
 }
 ll res=0;
 while(!pq.empty()){
  res+=pq.top();
  pq.pop();
 }
 cout << res << endl;

  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 2296
#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int N;
	cin >> N;
	vector<long> as(3), ls(N);
	for (int i = 0; i < 3; i++) cin >> as[2-i];
	for (int i = 0; i < N; i++) cin >> ls[i];
	vector<tuple<long, long, int>> ps;
	for (int s = 1; s < 1<<N; s++)
	{
		int k = __builtin_popcount(s);
		long res = 0;
		for (int i = 0; i < N; i++)
		{
			if (s >> i & 1)
			{
				res += ls[i];
			}
		}
		ps.emplace_back(res, 10*(k-1), s);
	}
	N = ps.size();
	long ans = 1L << 50;
	for (int i = 0; i < N; i++)
		for (int j = i+1; j < N; j++)
			for (int k = j+1; k < N; k++)
	{
		auto p = ps[i], q = ps[j], r = ps[k];
		if (get<2>(p) & get<2>(q) || get<2>(q) & get<2>(r) || get<2>(p) & get<2>(r) || __builtin_popcount(get<2>(p) ^ get<2>(q) ^ get<2>(r)) < 3)
			continue;
		long res = 0;
		res += get<1>(p);
		res += get<1>(q);
		res += get<1>(r);
		long t[] = {get<0>(p), get<0>(q), get<0>(r)};
		sort(t, t + 3);
		for (int l = 0; l < 3; l++) res += abs(t[l]-as[l]);
		ans = min(ans, res);
	}
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

void func148b() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  for (int i = 0; i < n; i++) cout << s[i] << t[i];
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  bool result = false;
  char in1, in2;
  char prev1, prev2;
  char preprev1, preprev2;

  cin >> prev1 >> prev2;
  cin >> in1 >> in2;

  for(int i=2; i<N; i++) {
    preprev1 = prev1;
    preprev2 = prev2;
    prev1 = in1;
    prev2 = in2;
    cin >> in1 >> in2;
    if(preprev1 == preprev2 && prev1 == prev2 && in1 == in2) {
      result = true;
    }
  }

  if(result == true) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
    int a,b,c,d,mt,mb;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a>b)
    {
        mt=b;
    }
    else
    {
        mt=a;
    }
    if(c>d)
    {
        mb=d;
    }
    else
    {
        mb=c;
    }
    printf("%d",(mt+mb));
    return 0;
}

Measured memory_bytes: 1736
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 23 14:06:18 2019

@author: Enya
"""

S = input()
N1 = S[0]
N2 = S[1]
N3 = S[2]
N4 = S[3]

if N1==N2 or N2==N3 or N3==N4:
    print('Bad')
    
else:
    print('Good')

Measured memory_bytes: 3060
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in); 
      int a = input.nextInt();
      int b =input.nextInt();
      for(int i =0; i<b; i++){
        	int c = input.nextInt();
      		a = a-c;
      }
      if(a<0){
        System.out.println ("-1");
      }
      else{
        System.out.println(a);
      }
    }
}

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

int h[112345];
int dp[112345];
int INF = 1000000007;

int N;
int main () {
    cin >> N;
    for(int i=0; i<N; i++) dp[i] = INF;
    for(int i=0; i<N; i++) cin >> h[i];
    dp[0] = 0;
    for(int i=0; i<N; i++) {
        if(i+1<N) dp[i+1] = min(dp[i+1],dp[i] + abs(h[i+1] - h[i]));
        if(i+2<N) dp[i+2] = min(dp[i+2],dp[i] + abs(h[i+2] - h[i]));
    }
    cout << dp[N-1] << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int len_init = 0, len_tail = 0, len = 1, d = 0;
  for (int i = 1; i < s.size(); i++) {
    if (s.at(i) == s.at(i - 1)) {
      len++;
    } else {
      if (len == i) {
        len_init = i;
        len = 1;
      } else {
        d += len / 2;
        len = 1;
      }
    }
  }
  len_tail = len;
  if (len_init == 0) {
    cout << s.size() * k / 2 << endl;
    return 0;
  }
  if (s.at(0) != s.at(s.size() - 1)) {
    d += len_init / 2 + len_tail / 2;
    len_init = 0;
    len_tail = 0;
  }
  cout << (long long) d * k
    + (long long) (len_init + len_tail) / 2 * (k - 1)
    + len_init / 2 + len_tail / 2 << endl;
}

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

int main() {
  int n, maxh; cin >> n >> maxh;
  int h, c = 1;
  for (int i = 1; i < n; i++) {
    cin >> h;
    if (h >= maxh) c++, maxh = h;
  }
  cout << c << endl;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}



void solve(std::istream &in, std::ostream &out) {
  int s, w;
  in >> s >> w;
  out << ((w >= s) ? "unsafe" : "safe");
}


Measured memory_bytes: 3652
import math
import fractions
import collections
import itertools
N=int(input())
L=list(map(int,input().split()))
cnt=0
for i in range(N):
    x=L[i]
    for j in range(i+1,N):
        y=L[j]
        for k in range(j+1,N):
            z=L[k]
            if ((x+y>z)and(y+z>x)and(x+z>y))and(x!=y)and(y!=z)and(z!=x):
                cnt=cnt+1
            #print(cnt,i,j,k)
print(cnt)


Measured memory_bytes: 73504
s = input()
k = int(input())
n = len(s)

# print('s',s,'k',k)
c = set()
for i in range(n):
    # print(s[i:i+5])
    t = s[i:i+5]
    for j in range(1,5+1):
        # print(t[:j])
        c.add(t[:j])

c = list(c)
c.sort()
# print(*c,sep='\n')
print(c[k-1])


Measured memory_bytes: 4464
// 20
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forr(_, x, n) for (int _ = x; _ > n; _--)
#define fos(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fos(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
// typedef long long int li;
typedef int li;
typedef long double ld;

li binPow(li a, li p) {
  li ans = 1LL;
  while (p) {
    if (p & 1LL) ans *= a;
    a *= a, p >>= 1LL;
  }
  return ans;
}

// 12
void _main(int tc) {
  int n, k;
  cin >> n >> k;
  int ans = k * binPow(k - 1, n - 1);
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0); return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 256
s = input()

a = 0
b = 0
c = 0

for i in range(3):
    if s[i] == 'a':
        a = 1
    elif s[i] == 'b':
        b = 1
    elif s[i] == 'c':
        c = 1
        
if a*b*c==1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){

  int a[7], b[7], i;

  for(i = 0; i < 7; i++){
    scanf("%d%d", &a[i], &b[i]);
  }

  for(i = 0; i < 7; i++){
    printf("%d\n", a[i] - b[i]);
  }

  return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		string[] str2 = Console.ReadLine().Split();
		int ans = 0;
		for(var i=0;i<N;i++){
			int a = int.Parse(str[i]);
			int b = int.Parse(str2[i]);
			ans += Math.Max(0,a-b);
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int a,b,c,k;
    scanf("%d %d %d %d", &a, &b, &c, &k);
    if(k < a){
        printf("%d", k);
    } else if (k < a + b){
        printf("%d", a);
    } else {
        printf("%d", 2 * a + b - k);    
    }
    
    return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
using namespace std;
using ll = long long;

ll calc(vector<ll>& v, ll k){
  for(int b=40; b>=0; b--){
    ll cnt = 0, ans = (1LL << 41) - 1;
    vector<ll> n;
    for(int i=0; i<v.size(); i++){
      if((1LL << b) & v[i]){
        cnt++;
        n.emplace_back(v[i] - (1LL << b));
      }
    }

    if(cnt >= k){
      return (1LL << b) + calc(n, k);
    }
  }
  
  return 0;
}

int main(){
  ll n, k; cin >> n >> k;
  ll a[n+1], s[n+1];

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

  vector<ll> sum;
  for(int l=0; l<n; l++){
    for(int r=l+1; r<=n; r++){
      sum.emplace_back(s[r]-s[l]);
    }
  }

  cout << calc(sum, k) << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N, M; cin >> N >> M;
  ll A[N]; rep(i,N) { cin >> A[i]; A[i]--; }
  ll count[N] = {}; rep(i,N) count[A[i]]++;
  ll cover[N*2] = {};
  rep(i,N) rep(j,count[i]) cover[N+i-j]++;
  // debug(cover+N,cover+N*2);
  ll result = 0; rep(i,N) result += cover[N+i]==0;

  rep(i,M) {
    ll X, Y; cin >> X >> Y; X--; Y--;
    if (A[X]-(count[A[X]]-1)>=0&&cover[N+A[X]-(count[A[X]]-1)]==1) result++;
    cover[N+A[X]-(count[A[X]]-1)]--; 
    count[A[X]]--; count[Y]++; A[X] = Y;
    cover[N+Y-(count[Y]-1)]++;
    if (Y-(count[Y]-1)>=0&&cover[N+Y-(count[Y]-1)]==1) result--;
    // debug(cover+N,cover+N*2);
    cout << result << endl; 
  }
  return 0;
}

Measured memory_bytes: 7808
void main()
{
    string s = readln.chomp;

    long n = s.length.to!int - 1;

    long total;
    foreach (i; 0 .. (1 << n))
    {
        string eq = s[0].to!string;
        foreach (j; 0 .. n)
        {
            if (i & (1 << j))
            {
                eq ~= '+';
            }
            eq ~= s[j+1];
        }
        string[] tarms = eq.split('+');
        total += tarms.to!(long[]).sum;
    }

    total.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if(c=='a'){
    cout << "vowel" << endl;
  }else if(c=='i'){
    cout << "vowel" << endl;
  }else if(c=='u'){
    cout << "vowel" << endl;
  }else if(c=='e'){
    cout << "vowel" << endl;
  }else if(c=='o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    long long n,m;
    cin>>n>>m;
    if(n>m)swap(n,m);
    long long ans;
    if(n==1&&m==1)ans=1;
    if(n==1&&m>1)ans=m-2;
    if(n>1&&m>1)ans=(n-2)*(m-2);
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
    int N, W;
    cin>>N>>W;
    long long DP[N][W+1], w[N], v[N];
    memset( DP,-1,sizeof(DP) );
    for(int i=0; i<N; i++) cin>>w[i]>>v[i];
    DP[0][0] = 0, DP[0][w[0]] = v[0];
    for(int i=0; i<N-1; i++)
    {
        for(int j=0; j<=W; j++)
        {
            DP[i+1][j] = max( DP[i][j],DP[i+1][j] );
            if( j+w[i+1]<=W ) DP[i+1][j+w[i+1]] = max( DP[i+1][j+w[i+1]],DP[i][j]+v[i+1] );
        }
    }
    long long mxSUM = 0;
    for(int i=0; i<=W; i++) mxSUM = max( mxSUM,DP[N-1][i] );
    cout<<mxSUM<<"\n";
}

Measured memory_bytes: 78336
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 20:45:37 2020

@author: liang
"""

def gcc(a,b):
    if b == 0:
        return a
    return gcc(b, a%b)

A, B = map(int, input().split())
if A < B:
    A ,B = B, A
print(A*B//gcc(A,B))


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

int main() {
  int s,ans=0;
  cin >> s;
  
  if(s/100>0){
  	ans +=1;
    s = s - 100;
  }
  if(s/10>0){
  	ans +=1;
    s = s - 10;
  }
  if(s/1>0){
  	ans +=1;
    s = s - 1;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
n = int(input())
list_info = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for _ in range(n):
    info = input()
    info_list = info.split(" ")
    b = int(info_list[0])
    f = int(info_list[1])
    r = int(info_list[2])
    v = int(info_list[3])
    list_info[b - 1][f - 1][r - 1] += v 
for l in range(4):
    for m in range(3):
        num = ""
        for n in range(10):
            num += " "
            num += str(list_info[l][m][n])
        print(num)
    if not(l == 3):
        print("#" * 20)


Measured memory_bytes: 5612
S = input()

n = 0
o = 0
for s in S:
    if o == 0:
        if s == '0':
            pass
        else:
            n = n + 1
    else:
        if s == '0':
            n = n + 1
        else:
            pass

    o = 1 - o
n = min(n, len(S) - n)
print(n)


Measured memory_bytes: 3188
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def get_factorials(max, mod=None):
    """
    階乗 0!, 1!, 2!, ..., max!
    :param int max:
    :param int mod:
    :return:
    """
    ret = [1]
    n = 1
    if mod:
        for i in range(1, max + 1):
            n *= i
            n %= mod
            ret.append(n)
    else:
        for i in range(1, max + 1):
            n *= i
            ret.append(n)
    return ret


def mod_invs(max, mod):
    """
    逆元のリスト 0 から max まで
    :param int max:
    :param int mod:
    """
    invs = [1] * (max + 1)
    for x in range(2, max + 1):
        invs[x] = (-(mod // x) * invs[mod % x]) % mod
    return invs


def factorial_invs(max, mod):
    """
    階乗 0!, 1!, 2!, ..., max! の逆元
    :param int max:
    :param int mod:
    """
    ret = []
    r = 1
    for inv in mod_invs(max, mod):
        r = r * inv % mod
        ret.append(r)
    return ret


class Combination:
    def __init__(self, max, mod):
        """
        :param int max:
        :param int mod: 3 以上の素数であること
        """
        self._factorials = get_factorials(max, mod)
        self._finvs = factorial_invs(max, mod)
        self._mod = mod

    def ncr(self, n, r):
        """
        :param int n:
        :param int r:
        :rtype: int
        """
        if n < r:
            return 0
        return self._factorials[n] * self._finvs[r] % self._mod * self._finvs[n - r] % self._mod


N, K = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))

if K == 1:
    print(0)
    exit()

comb = Combination(max=N + 10, mod=MOD)
A.sort()
# それぞれ何回 max と min になるか？
max_counts = [0] * N
min_counts = [0] * N
for i in range(N):
    max_counts[i] += comb.ncr(i, K - 1)
    min_counts[i] += comb.ncr(N - i - 1, K - 1)

ans = 0
for a, ma, mi in zip(A, max_counts, min_counts):
    ans += a * ma - a * mi
    ans %= MOD
print(ans)


Measured memory_bytes: 58096
#include<bits/stdc++.h>
using namespace std;
vector<long int > w(101),v(101);
long int dp[101][100001];
long int max_val(int n,int W)
{
    if(dp[n][W]!=-1)
    return dp[n][W];
    if(n==0)
    return dp[n][W]=0;
    if(W<=0)
    return dp[n][W]=0;
    if(w[n]>W)
    return dp[n][W]=max_val(n-1,W);
    
    return dp[n][W]=max(max_val(n-1,W-w[n])+v[n],max_val(n-1,W));
    
    
}
int main()
{
    int n,W,i;
    cin>>n>>W;
    for(i=0;i<=n;i++)
    for(int j=0;j<=W;j++)
    dp[i][j]=-1;
    
    for(i=1;i<=n;i++)
    cin>>w[i]>>v[i];
    cout<<max_val(n,W)<<endl;
    
    return 0;
    
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 1e5 + 5;

const int mod = 1e9 + 7;

vector<vi> AdjList;

ll dp[maxn][2];

void mul(ll &a, ll b){
	a *= b;
	a %= mod;	
}

void add(ll &a, ll b){
	a += b;
	if(a >= mod){
		a -= mod;
	}
}

ll solve(int idx, int warna, int p){
	int i,j;
	// printf("idx: %d warna: %d\n",idx, warna);
	bool isTraversed = false;
	if(dp[idx][warna] != -1){
		// printf("direturn %d\n",dp[idx][warna]);
		return dp[idx][warna];
	}
	ll ans = 1;
	for(i=0;i<AdjList[idx].size();i++) {
		int v = AdjList[idx][i];
		if(v != p){
			isTraversed = true;
			if(warna == 0) {
				ll jawab = solve(v, 0, idx) + solve(v, 1, idx);
				mul(ans, jawab);
				// add(ans, solve(v, 0, idx));
				// add(ans, solve(v, 1, idx));

			}else{

				mul(ans, solve(v, 0, idx));
			}
		}
	}
	
	return dp[idx][warna] = ans;
}


int main(){
	int n,i,j;
	scanf("%d",&n);
	AdjList.assign(maxn, vi());
	for(i=0;i<(n-1);i++){
		int a,b;
		scanf("%d %d",&a,&b);
		AdjList[a].pb(b); AdjList[b].pb(a);
	}

	memset(dp, -1, sizeof dp);
	int ans = solve(1, 0, -1) + solve(1,1,-1);
	for(i=1;i<=n;i++){
		for(j=0;j<2;j++){
			// printf("dp[%d][%d]: %d\n",i,j,dp[i][j]);
		}
	}
	if(ans >= mod){ans -= mod;}
	printf("%d\n",ans);

	return 0;
};

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C

int main() {
	int n;
	cin >> n;
	int dist[n];
	vector<int> map[n];
	for (int i = 0; i < n; i++) {
		dist[i] = -1;
		int a, b, c;
		cin >> a >> c;
		for (int j = 0; j < c; j++) {
			cin >> b;
			map[a - 1].push_back(b - 1);
		}
	}
	
	queue<int> q;
	q.push(0);
	dist[0] = 0;
	while (q.size() > 0) {
		int c = q.front(); q.pop();
		for (int i = 0; i < map[c].size(); i++) {
			if (dist[map[c][i]] != -1) continue;
			dist[map[c][i]] = dist[c] + 1;
			q.push(map[c][i]);
		}
	}
	
	for (int i = 0; i < n; i++)
		cout << (i + 1) << " " << dist[i] << endl;
	return 0;
}

Measured memory_bytes: 1224
h, w, m = map(int, input().split())
a_list = []
b_list = []
h_list = [0 for _ in range(h)]
w_list = [0 for _ in range(w)]
for i in range(m):
    a, b = map(int, input().split())
    a_list.append([a,b])
    h_list[a - 1] += 1
    w_list[b - 1] += 1
h_max = max(h_list)
w_max = max(w_list)
w_flag = [0 for _ in range(w)]
for i in range(w):
    if w_list[i] == w_max:
        w_flag[i] = 1
h_flag = [0 for _ in range(h)]
for i in range(h):
    if h_list[i] == h_max:
        h_flag[i] = 1
flag = 0   
for i in range(m):
    if h_flag[a_list[i][0] - 1] == 1 and w_flag[a_list[i][1] - 1] == 1:
        flag += 1
s = sum(h_flag) * sum(w_flag)
print(h_max + w_max - 1 if flag == s else h_max + w_max)        


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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;
typedef vector<string> vecst;

int main(){
    ll P, Q, R;
    cin >> P >> Q >> R;
    ll maxx = max(P, Q);
    maxx = max(maxx, R);
    cout << P + Q + R - maxx <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

class Point {
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) { return Point(x-p.x, y-p.y); }
    Point operator * (double a) { return Point(a*x, a*y); }
    Point operator / (double a) { return Point(x/a, y/a); }

    double abs() {return sqrt(norm()); }
    double norm() {return x*x + y*y; }
};

typedef Point Vector;

double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x*b.y - a.y*b.x;
}

class Circle {
    public:
    double r;
    Point c;

    Circle(double r = 0, Point c = Point()): r(r) {}
};

//ポイントpがベクトルp1-p0からみて反時計回りにいるかどうか
//CCW: 1, CW: -1, ON:0
int isCCW(Point p, Point p0, Point p1){
    Vector v01 = p1 - p0;
    Vector v02 = p - p0;

    double Cross = cross(v01, v02);
    
    int out = 2;
    if (Cross>0){out = 1;}
    else if(Cross<0){out = -1;}
    else{out = 0;}

    return out;
}

Point projection(Point p1, Point p2, Point p) {
    Vector v = p2 - p1;
    Vector u = p - p1;
    Point t = p1 + v*dot(u,v)/v.norm();
    return t;
}

void print(Point p0, Point p1);

int main(){
    #if 0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    #endif

    Circle K;
    cin >> K.c.x >> K.c.y >> K.r;

    int q;
    cin >> q;

    for (int i=0; i<q; i++) {
        Point p0, p1, proj, cross0, cross1;
        cin >> p0.x >> p0.y >> p1.x >> p1.y;

        if ( isCCW(K.c, p0, p1) == 0 ) {
            Vector v1 = p1 - p0;
            v1 = v1 * K.r / v1.abs();
            cross0 = K.c + v1;
            cross1 = K.c - v1;
            print(cross0, cross1);
            continue;
        }

        proj = projection(p0, p1, K.c);
        double d = ( proj - K.c ).abs();
        if ( d > K.r ) {
            cout << "Invalid Input" << endl;
            continue;
        }
        if ( d == K.r ) {
            print(proj, proj);
            continue;
        }
        
        Vector v0 = proj - K.c;
        Vector v1;
        v1.x = v0.y;
        v1.y = - v0.x;
        v1 =  v1 * sqrt( K.r*K.r - d*d ) / v1.abs();
        cross0 = proj + v1;
        cross1 = proj - v1;
        print(cross0, cross1);
    }

    return 0;
}

void print(Point p0, Point p1) {
    double x0, y0, x1, y1;
    if ( p0.x < p1.x ) {
        x0 = p0.x;
        y0 = p0.y;
        x1 = p1.x;
        y1 = p1.y;
    }
    else if ( p0.x > p1.x ) {
        x0 = p1.x;
        y0 = p1.y;
        x1 = p0.x;
        y1 = p0.y;
    }
    else {
        if ( p0.y < p1.y ){
            x0 = p0.x;
            y0 = p0.y;
            x1 = p1.x;
            y1 = p1.y;
        }
        else{
            x0 = p1.x;
            y0 = p1.y;
            x1 = p0.x;
            y1 = p0.y;
        }
    }
    cout << fixed << setprecision(11) << x0 << " " << y0 << " " << x1 << " " << y1 << endl;
}


Measured memory_bytes: 3280
A,B,C,X,Y = map(int,input().split())
a,b,c = 0,0,0
ans = 0
for c in range (0,2*max(X,Y)+1,2):
    a = max(0,X - c//2)
    b = max(0,Y - c//2)
    if(c==0):
        ans = A*a + B*b + C*c
    else:
        if(ans > A*a + B*b + C*c):
            ans = A*a + B*b + C*c
print(ans)


Measured memory_bytes: 3064
import Data.List
import Data.Char

main = interact $ show' . solve [] . read'
  where
    show' = unlines . reverse
    solve acc [] = acc
    solve acc (s:n:xs) = solve ((solveOne init' s):acc) tail'
      where
        (init', tail') = splitAt (readInt n) xs
        solveOne [] s = s
        solveOne (y:ys) s = solveOne ys (st ++ sh)
          where (sh, st) = splitAt (readInt y) s
    read' = takeWhile (/= "-") . lines
    readInt = read :: String -> Int



Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef pair<int,int> pi;

void debug_out(){cerr << ' ';}
template<typename t1,typename... t2>
void debug_out(t1 A, t2... B){cerr << " " << A;debug_out(B...);}
#define debug(...)cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)

#define cerr if(0) cout

const ll INF = 1e18+7;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n,a,b;
	cin >> n >> a >> b;
	vector<ll> x(n);
	for (int i = 0; i < n; ++i) cin >> x[i];
	vector<ll> dp(n,INF);
	dp[0] = 0;
	for (int i = 1; i < n; ++i) dp[i] = min(dp[i-1]+(x[i]-x[i-1])*a,dp[i-1]+b);
	cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 1792