akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    for(int i = 0; i < M; i++) {
        cin >> X.at(i);
        // X.at(i).second = -1;
    }
    if(N >= M) {
        cout << 0 << endl;
        return 0;
    }
    sort(X.begin(), X.end());

    vector<int> distance(M - 1);
    for(int i = 0; i < M - 1; i++) {
        distance.at(i) = X.at(i + 1) - X.at(i);
    }

    sort(distance.begin(), distance.end());
    int ans = 0;
    for(int i = 0; i < distance.size() - N + 1; i++) {
        ans += distance.at(i);
    }

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long N;
	cin >> N;
	bool flg=true;
	int i = 0;

	while (flg) {
		i++;
		
		if((i*i)>N) {
			flg = false;
		}
		if (!flg) {
			cout << (i - 1)*(i - 1) << endl;
		}

	}
}

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

int main(){
 int a, b;
 char op;
 
 while(op != '?'){
	 cin >> a >> op >> b;
	 switch(op){
		case '+': 
			cout << a + b << endl;
			break;
		case '-':
			cout << a - b << endl;
			break;
		case '/':
			cout << a / b << endl;
			break;
		case '*':
			cout << a * b << endl;
			break;
	 }
 }
}

Measured memory_bytes: 3048
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

int main() {
	int price;
	int total_price=0;
	int num;
	int total_num = 0;
	double kaisuu=0.0;
	while(scanf("%d,%d",&price,&num)!=EOF){
		total_price = total_price + price*num;
		total_num = total_num + num;
		kaisuu++;
	}
	int x = roundf(total_num / kaisuu);
	cout << total_price << endl << x << endl;
}

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

using T = long long;
constexpr T inf = 1e9;

// 二部グラフ最大重みマッチング
T hungarian(const std::vector<std::vector<T>> &a) {
  int n = a.size(), p, q;
  assert((int)a[0].size() == n);
  std::vector<T> fx(n, inf), fy(n, 0);
  std::vector<int> x(n, -1), y(n, -1);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) fx[i] = std::max(fx[i], a[i][j]);
  for (int i = 0; i < n;) {
    std::vector<int> t(n, -1), s(n + 1, i);
    for (p = q = 0; p <= q && x[i] < 0; ++p)
      for (int k = s[p], j = 0; j < n && x[i] < 0; ++j)
        if (fx[k] + fy[j] == a[k][j] && t[j] < 0) {
          s[++q] = y[j], t[j] = k;
          if (s[q] < 0)
            for (p = j; p >= 0; j = p) y[j] = k = t[j], p = x[k], x[k] = j;
        }
    if (x[i] < 0) {
      T d = inf;
      for (int k = 0; k <= q; ++k)
        for (int j = 0; j < n; ++j)
          if (t[j] < 0) d = std::min(d, fx[s[k]] + fy[j] - a[s[k]][j]);
      for (int j = 0; j < n; ++j) fy[j] += (t[j] < 0 ? 0 : d);
      for (int k = 0; k <= q; ++k) fx[s[k]] -= d;
    } else
      ++i;
  }
  T ret = 0;
  for (int i = 0; i < n; ++i) ret += a[i][x[i]];
  return ret;
}

using namespace std;

using ll = long long;
int main() {
  int n;
  while (cin >> n, n) {
    vector<vector<ll>> v;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
      ll x, y, z;
      cin >> x >> y >> z;
      vector<ll> tmp = {x, y, z};
      sort(tmp.begin(), tmp.end());
      v.push_back(tmp);
      sum += x * y * z;
    }
    vector<vector<ll>> a(n, vector<ll>(n, 0));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (v[i][0] < v[j][0] && v[i][1] < v[j][1] && v[i][2] < v[j][2]) {
          a[i][j] = v[i][0] * v[i][1] * v[i][2];
        }
      }
    }
    cout << sum - hungarian(a) << endl;
  }
}



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

vector<vector<string>> ptn = {
{
  ".###",
  ".#.#",
  ".#.#",
  ".#.#",
  ".###",
},
{
  "..#.",
  ".##.",
  "..#.",
  "..#.",
  ".###",
},
{
  ".###",
  "...#",
  ".###",
  ".#..",
  ".###",
},
{
  ".###",
  "...#",
  ".###",
  "...#",
  ".###",
},
{
  ".#.#",
  ".#.#",
  ".###",
  "...#",
  "...#",
},
{
  ".###",
  ".#..",
  ".###",
  "...#",
  ".###",
},
{
  ".###",
  ".#..",
  ".###",
  ".#.#",
  ".###",
},
{
  ".###",
  "...#",
  "...#",
  "...#",
  "...#",
},
{
  ".###",
  ".#.#",
  ".###",
  ".#.#",
  ".###",
},
{
  ".###",
  ".#.#",
  ".###",
  "...#",
  ".###", 
}
};

int main(){

  int64_t n,m;
  cin>>n>>m;


  vector<int> liked(m,0);
  for(int i=0;i<n;i++){
    int k;
    cin>>k;

    for(int j=0;j<k;j++){
      int a;
      cin>>a;

      liked.at(a-1)++;
    }
  }

  int cnt=0;
  for(int i=0;i<m;i++){
    if(liked.at(i)==n)
      cnt++;
  }

  cout<<cnt<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[200007],sum=0,pref[200007],ans=0;
int check(int start,int fs,long long val){
    int l=start;
    int r=fs;
    int mid=(l+r)/2;
    if(val>sum/3) return 0;
    while(l!=mid && r!=mid){
        if(pref[mid]-pref[start-1]>=val) r=mid;
        else l=mid+1;
        mid=(l+r)/2;
    }
    for(int i=l;i<=r;i++){
        if(pref[i]-pref[start-1]>=val){
            if(sum-val-(pref[i]-pref[start-1])>=val) return 1;
        }
    }
    return 0;
}
long long sol(int pos,int stat){
    int l=pos;
    int r=stat-2;
    int mid=(l+r)/2;
    while(l!=mid && r!=mid){
        if(check(mid+1,stat,pref[mid]-pref[pos-1])==1) l=mid;
        else r=mid-1;
        mid=(l+r)/2;
    }
    for(int i=r;i>=l;i--){
        if(check(i+1,stat,pref[i]-pref[pos-1])==1) return pref[i]-pref[pos-1];
    }
    return -1;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
        pref[i]=pref[i-1]+a[i];
    }
    for(int i=1;i<=n;i++){
        a[i+n]=a[i];
        pref[i+n]=pref[i+n-1]+a[i+n];
    }
    for(int i=n;i<=n+n-1;i++){
        long long ps=sol(i-n+1,i);
        ans=max(ans,ps);
    }
    cout<<ans<<endl;
}

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

int main(){
  int N;
  cin >> N;
  string s=to_string(N);
  int64_t sum=0;
  for(int i=0;i<s.size();i++){
    sum+=s.at(i)-'0';
  }
  if(N%sum==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=100000000;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	char a[110][110];
int s[110][110];
int main(){
	int h,w;
	cin>>h>>w;
	
	rep(i,0,h){
		rep(j,0,w){
			cin>>a[i][j];
			s[i][j]=1;
		}
	}
	rep(i,0,h){
		int x=0;
		rep(j,0,w){
			if(a[i][j]=='.')x++;
		}
		if(x==w){
			rep(k,0,w)s[i][k]=0;
		}
	}
	rep(i,0,w){
		int x=0;
		rep(j,0,h){
			if(a[j][i]=='.')x++;
		}
		if(x==h){
			rep(k,0,h)s[k][i]=0;
		}
	}
	rep(i,0,h){
		int x=0;
		rep(j,0,w){
			if(s[i][j]==1){
				cout<<a[i][j];
				x++;
			}
		}
		if(x!=0)cout<<endl;
	}
}

Measured memory_bytes: 256
package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}



Measured memory_bytes: 2332
#include<iostream>
#include<set>
#include<string>
#include<algorithm>

int main() {

	std::cout.sync_with_stdio(false);

	std::string s;
	int k;

	std::cin >> s;
	//std::cout << s << "\n";
	
	std::cin >> k;

	std::set< std::string > ss;

	auto slen = s.length();
//	std::cout << "slen " << slen << "\n";
	using sltype = decltype(slen);

	for ( sltype i{}; i < slen; ++i) {

		for ( auto j{ i+1 }; j <= slen; ++j) {

			if (j - i > 5)
				continue;

			auto sstr = s.substr(i,j-i);
//				auto sstr = std::string{ "damy" };
				
			/*
			std::cout
				<< i << " " << (j-i)
				<< " " << sstr << "\n";
			*/
			
			if (ss.size() <= 5) {
				ss.emplace( std::move(sstr) );
				continue;
			}

			
			auto end_ = std::begin(ss);
			std::advance(end_, 5);
			auto it = std::upper_bound(std::begin(ss), end_, sstr);

			if (it != end_)
				ss.emplace(std::move(sstr));
			
		}
	}

	/*
	auto it = ss.begin();
	for (int i{}; i < ss.size(); ++i) {
		std::cout << i << ":" << (*it) << "\n";
		++it;
	}*/

	
	auto ans_it = ss.begin();
	
	std::advance(ans_it, k-1);
	std::cout << ans_it->c_str() << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

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

	int n;
	cin >> n;
	

	vector<ll> a(n);
	
	
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] -= i + 1;
	}
	sort(a.begin(), a.end());
	vector<ll> cs(n);
	partial_sum(a.begin(), a.end(), cs.begin());

	ll ans = 1e18;
	for (int i = 0; i < n; ++i) {
		ll res = 0;
		res += a[i] * (i + 1) - cs[i];
		res += (cs.back() - cs[i]) - a[i] * (n - i - 1);
		ans = min(ans, res);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
s = input()
if (int(s[:2]) == 0 or int(s[:2]) > 12)&(0 < int(s[2:]) <= 12):
    print("YYMM")
    
elif (0 < int(s[:2]) <= 12)&(int(s[2:]) == 0 or int(s[2:]) > 12):
    print("MMYY")

elif (0 < int(s[:2]) <= 12)&(0 < int(s[2:]) <= 12):
    print("AMBIGUOUS")

else:
    print("NA")

Measured memory_bytes: 8956
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;



int main() {
	int h, w, n;
	cin >> h >> w >> n;
	int a[n];
	rep (i, n) cin >> a[i];

	vector<vector<int>> ans(h, vector<int>(w));

	vector<int> use;
	rep (i, n) rep (j, a[i]) use.pb(i + 1);

	int id = 0;
	rep (i, h) {
		if (i % 2 == 0) {
			rep (j, w) {
				ans[i][j] = use[id++];
			}
		}
		else {
			for (int j = w - 1; j >= 0; j--) {
				ans[i][j] = use[id++];
			}
		}
	}

	rep (i, h) {
		rep (j, w) cout << ans[i][j] << " ";
		cout << endl;
	}
	return 0;
}

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

int main()
{
    int a;
    long long b,x,y;
    int count = 0;

    cin >> a >> b;
    for (int i=0; i<a; i++){
        cin >> x >> y;
        if(x*x+y*y<=b*b){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    int n, m;
    cin >> n >> m;
    int c[3] = {-1, -1, -1};
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        if (c[a - 1] != -1 && c[a - 1] != b)
        {
            cout << -1 << endl;
            return 0;
        }
        c[a - 1] = b;
    }
    if (c[0] == 0)
    {
        if (n == 1)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << -1 << endl;
        }
    }
    else
    {
        string s = "";
        rep(i, n)
        {
            if (c[i] == -1)
            {
                s.push_back('0');
            }
            else
            {
                s.push_back('0' + c[i]);
            }
        }
        if (n > 1 && s[0] == '0')
        {
            s[0] = '1';
        }
        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
typedef pair<int, int> P;
const int MAX_N = 10000;
const int MAX_L = 100000000;
const int MAX_SQRT_B = 10000;
const int INF = 1000000000;
typedef int64_t ll;
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; }

int N, M;


int main() {
	cin >> N >> M;
	vector<P> AB(N);
	
	rep(i, N) {
		cin >> AB.at(i).first >> AB.at(i).second;
		
	}
	sort(AB.begin(), AB.end());

	
	
	ll ans = 0;
	for (int i = 0; i < N; i++)
	{
		int cnt = min(M, AB.at(i).second);
		ans += (ll)(AB.at(i).first )* cnt;
		M -= cnt;

		if (M ==0 ) {
			cout << ans << endl;
			return 0;
		}
	}
	
	
}

Measured memory_bytes: 4052
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

a,b = NextInts()
print(a*b)

Measured memory_bytes: 9476
import java.util.*;

class Main{
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String ret = "";
        char cleft = line.charAt(0);
        char cright = line.charAt(2);
		if(cleft==cright){
          System.out.println("=");
		}
		else if(cleft<cright){
		  System.out.println("<");
        }
        else{
		  System.out.println(">");
        }
    }
}


Measured memory_bytes: 21844
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


class UnionFindTree:
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n

    def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

    def connect(self, i, j):
        if i==j:
            return
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]
    
n,m = map(int, input().split())
uf = UnionFindTree(n)
ans = [None] * m
val = n * (n-1) // 2
ab = [None] * m
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    ab[i] = (a,b)
i = 0
for a,b in ab[::-1]:
    ans[m-1-i] = val
    i += 1
    ra = uf.root(a)
    rb = uf.root(b)
    if ra==rb:
        pass
    else:
        val -= uf.size[ra] * uf.size[rb]
    uf.connect(a,b)
write("\n".join(map(str, ans)))


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

int main()
{
	int c[30] = {};
	string w;
	cin >> w;
	for (int i = 0; i < w.length(); ++i) {
		++c[w[i] - 'a'];
	}
	for (int i = 0; i < 30; ++i) {
		if (c[i] % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, K;
  cin >> N >> K;
  string S;cin >> S;
  ll cnt = 0;
  char s = 'a';
  rep(i, N){
    if(s!=S[i]){
      s = S[i];
      cnt++;
    }
  }
  cnt = max(1LL, cnt - 2 * K);
  cout << N - cnt;
  return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;
const long long MOD = 1e18;
long long a[100010];


int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0;i < n;i++) scanf("%lld", &a[i]);
    int zero = 0;

        for (int i = 0;i < n;i++)if (a[i] == 0) zero++;
    if (zero > 0) {
        // a[i] contains 0
        printf("0\n");
        return 0;
    }
    long long prod = 1;
    for (int i = 0;i < n;i++) {
        if (a[i] <= 1000000000000000000 / prod) {
            // This condition is equivalent to prod*a[i] <=10ˆ18
            prod *= a[i];
        }
        else {
            printf("-1\n");
            return 0;
        }
    }
    printf("%lld\n", prod);

}

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

int main() {
  int n, x, l, s = 1, p = 0;
  cin >> n >> x;
  rep(i, n) {
    cin >> l;
    if(p + l <= x) {
      s++;
      p += l;
    } else {
      break;
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 3584
#include<stdio.h>
int main(void)
{
	int y[2],m[2],d[2],y1,m1,d1;
	
	scanf("%d %d %d",&y[0],&m[0],&d[0]);
	scanf("%d %d %d",&y[1],&m[1],&d[1]);
	
	if(y[0]>y[1])	y1=y[0],y[0]=y[1],y[1]=y1,
					m1=m[0],m[0]=m[1],m[1]=m1,
					d1=d[0],d[0]=d[1],d[1]=d1;
	//printf("%d %d %d\n",y[0],m[0],d[0]);				
	//printf("%d %d %d\n",y[1],m[1],d[1]);				
	if(y[0]==y[1]&&m[0]==m[1]&&d[0]==d[1]) printf("0\n");
	
	else if(y[0]==y[1]&&m[0]<=m[1]&&d[0]>d[1]||
			y[0]==y[1]&&m[0]>m[1])
		printf("1\n");
		
	else if(y[0]<y[1]&&m[0]<m[1]&&d[0]<d[1])
		printf("%d\n",y[1]);
		
	else if(y[0]<y[1]&&m[0]<m[1])
		printf("%d\n",y[1]-y[0]+1);
		
	else if(y[0]<y[1]&&m[0]>=m[1])
		printf("%d\n",y[1]-y[0]);
}	


Measured memory_bytes: 2764
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
const int MAX = 2000000;
const int MOD = 1000000000 + 7;

long long fac[MAX], finv[MAX], inv[MAX];


void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

    if ((x+y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int m = (2*x-y)/3;
    int n = (2*y-x)/3;

    COMinit();
    cout << COM(m+n, m) << endl;

    return 0;
}


Measured memory_bytes: 47104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastIO fio = new FastIO();
        int n, ans, currans;
        ArrayList<Integer> h = new ArrayList<>();

        n = fio.readInt();
        if(n==1)
        {
            System.out.println("0");
            return;
        }

        for (int i = 0; i < n; i++)
            h.add(fio.readInt());
        int i = 1, j;

        ans = 0;
        currans = 1;
        while (i < n) {
            j = i;
            currans = 1;
            while (j<n && h.get(j)<=h.get(j-1)) {
                ++j;
                ++currans;
            }
            if(currans>ans)
                ans=currans;
            i=j+1;
        }
        System.out.println(ans-1);
    }

    private static class FastIO {
        private StringTokenizer stringTokenizer;
        private BufferedReader bufferedReader;

        public FastIO() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            stringTokenizer = null;
        }

        public String read() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return stringTokenizer.nextToken();
        }

        public int readInt() {
            return Integer.parseInt(read());
        }

        public long readLong() {
            return Long.parseLong(read());
        }
    }
}

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

typedef unsigned uint;
typedef long long INT;
typedef unsigned long long UINT;
const int INF = 1001001001;
const INT INFLL = 1001001001001001001LL;

 int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
INT lin() { INT x; scanf("%lld", &x); return x; }
UINT luin() { UINT x; scanf("%llu", &x); return x;}


int main(){
    int a, b, c;
    double fa, fb, fc;
    char S[128], sa[128], sb[128], sc[128];
    // int N = in();
    // int K = in();
    // scanf("%s", S);

    int N = in();

    // std::vector<INT> vecA;
    // for (INT i = 0; i < N; ++i) {
    //     vecA.push_back(lin());
    // }

    switch ( N % 10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
        printf("hon");
        break;
        case 0:
        case 1:
        case 6:
        case 8:
        printf("pon");
        break;
        case 3:
        printf("bon");
        break;
    }

    return 0;
}







Measured memory_bytes: 3832
/*
Author : N_o_o_B
Created : June 13 2020 17:34:34 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    ll a,v;
    cin >> a >> v;
    ll b,w;
    cin >> b >> w;

    if(v <= w){
        cout << "NO" << endl;
        return 0;
    }

    ll t;
    cin >> t;

    if(a < b and a + (v-w)*t >= b){
        cout << "YES" << endl;
        return 0;
    }

    if(a > b and a - (v-w)*t <= b){
        cout << "YES" << endl;
        return 0;
    }

    cout << "NO" << endl;


    time_taken();
    return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n,k;cin >> n >> k;
  vector<int> a(n);
  rep(i,n){
    int s;cin >> s;
    a[s-1]++;
  }
  int size = 0;
  rep(i,n){
    if(a[i]==0) a[i]=n+2;
    else size++;
  }
  int ans = 0;
  sort(a.begin(),a.end());
  int kae = size-k;
  int i=0;
  if(kae>0){
    while(kae){
      ans+=a[i];
      i++;
      kae--;
    }
  }
  cout << ans << endl;
}


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

#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> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

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

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<pair<string,ll>,ll> &a,pair<pair<string,ll>,ll> &b ){
        if(a.ff.ff != b.ff.ff)return a.ff.ff < b.ff.ff;
        return a.ff.ss > b.ff.ss;
}
ll const N=(ll)1e5+11;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n>>m;
        
        vllv a(m+1);
        
        for(i=1;i<=m;i++){
                cin>>x;
                for(j=0;j<x;j++){
                        cin>>y;
                        y--;
                        a[i].pb(y);
                }
        }
        vll p(m+1);
        for(i=1;i<=m;i++){
                cin>>p[i];
        }
        ll ans=0;
        for(i=0;i<(1<<n);i++){
                
                vll tmp(m+1);
                
                for(j=1;j<=m;j++){
                        
                        for(k=0;k<a[j].sz;k++){
                                if(((1<<a[j][k])&(i))){
                                        tmp[j]++;
                                }
                        }
                }
                ll fl=1;
                for(j=1;j<=m;j++){
                        if(tmp[j]%2!=p[j])fl=0;
                }
                ans+=fl;
        }
        
        cout<<ans<<endl;
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

Measured memory_bytes: 3672
package main

import (
	"fmt"
)

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)

	var ans int
	for i := 1; i <= k; i++ {
		if i <= a {
			ans++
		} else if i > a+b {
			ans--
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define LLMAX (1ll << 60) - 1
#define llMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define vi vector<ll>
#define prll(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define in(x,n)   for(ll e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define vl vector<long long>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define mp make_pair


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 	ll n,m,ans=0;
 	cin>>n>>m;
 	if(m>n)
 	swap(n,m);
 	ans+=n;
 	n--;
 	if(m>n)
 	swap(n,m);
 	ans+=n;
 	cout<<ans;
		
    return 0;
}
 

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

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=200009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int a[M+4];
int cnt[M+4];

 main()

{
    fast
    int n;
    cin>>n;
    f(i,1,n)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
    int sum=0;
    f(i,1,n)
    {
       int yo=(cnt[i]*(cnt[i]-1))/2;
       sum+=yo;
    }
    f(i,1,n)
    {
        int c=a[i];
        int p=cnt[c];
        int tmp=sum;
        tmp=tmp-((p*(p-1))/2);
        p--;
        tmp+=((p*(p-1))/2);
        cout<<tmp<<" ";
    }
    cout<<endl;













    return 0;

}













Measured memory_bytes: 4736
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Tue Mar 31 20:22:40 JST 2020
 **/

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    auto dp = make_vec<Int>(n, 2, 1);
    REP(i, n - 1) {
        dp[i + 1][0] = std::min(dp[i][0] + (a[i] < a[i + 1]), dp[i][1] + 1);
        dp[i + 1][1] = std::min(dp[i][0] + 1, dp[i][1] + (a[i] > a[i + 1]));
    }
    std::cout << std::min(dp[n - 1][0], dp[n - 1][1]) << std::endl;
}


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

int main() {
    set<char> code = {'A', 'C', 'G', 'T'};
    string S; cin >> S;
    int maxlen = 0;
    int len = 0;
    for (int i = 0; i < (int)S.size(); i++) {
        if (0 < code.count(S.at(i))) {
            len++;
            maxlen = max(maxlen, len);
        } else {
            len = 0;
        }
    }
    cout << maxlen << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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

int main(){
  int i, n, m, sum=0;
  scanf("%d%d",&n,&m);
  int a[m];
  rep(i,m) {
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  if(sum>n) {
    puts("-1");
    return 0;
  }
  else printf("%d",n-sum);
}
  
  

Measured memory_bytes: 1760
#include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
        }
        for (int i = 0; i < 10; i++) {
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int min(int, int);
int matrixChainOrder(int p[], int);

int main()
{
  int i, r, c, n, p[101], min_times;   /* r:行列の行数 c:行列の列数 */

  scanf("%d", &n);
  for( i = 0; i<n; i++ )
    {
      scanf("%d%d", &r, &c);

      if( i != 0 )    /* ２つ目以降の行列の場合 */
	p[i+1] = c;
      else            /* １つ目の行列の場合 */
	{
	  p[0] = r;
	  p[1] = c;
	}
    }

  /* 与えられた行列の積を計算するために必要な最小の計算量を求める */
  min_times = matrixChainOrder(p, n);

  printf("%d\n", min_times);
  
  return 0;
}


/* int型整数 a,b について小さい方を求めて返す関数 */
int min(int a, int b)
{
  if( a <= b )
    return a;
  else
    return b;
}


/* 行列の積を計算するために必要な最小の計算量を求めて返す関数 
   引数： num:行列の数 */
int matrixChainOrder(int p[], int num)
{
  int psize = num+1, m[num+1][num+1], q, i, j, k, l, n;

  n = psize -1;

  for( i = 1; i<=n; i++ )
    m[i][i] = 0;

  for( l = 2; l<=n; l++ )
    {
      for( i = 1; i<=n-l+1; i++ )
	{
	  j = i+l-1;
	  m[i][j] = INT_MAX;

	  for( k = i; k<j; k++ )
	    {
	      q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
	      m[i][j] = min(q, m[i][j]);
	    }
	}
    }

  return m[1][num];
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	int n,ans=0;
	cin>>n;
	vector<int>a(2*n);
	for(int i=0;i<n*2;i++)cin>>a[i];
	sort(a.begin(),a.end());
	for(int i=0;i<n*2-1;i+=2)
	ans+=a[i];
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define f(i,p,q) for(int i=p;i<q;i++)
using namespace std;
typedef long long ll;
long long int ar[64];
int main()
{//freopen("in.txt","r",stdin);
 //freopen("out.txt","w",stdout);
  long long  int n,k;cin>>n>>k;
  long long  int t; int l=0;
	long long  int m=n;
	vector<long long int>v;
   for(int i=0;i<n;i++)
   { long long int x;cin>>x;
      v.push_back(x);
     t=x;
  long long int index=0;
   	 while(t!=0)
   	 {   
		if((t&1)==1)
   	      ar[index]++;
   	 	index++;
        t=t>>1;
		}
   }
  long long  int ans=0;
  
  
   for(int i=40;i>=0;i--)
   { long long int u=(1ll<<i);
      if(m-ar[i]>ar[i]&&(ans+u<=k))
          ans=ans+u;
   	  
   	   //cout<<i<<" "<<ar[i]<<"  "<<ans<<"\n";
   }  
  
 
  long long  int res=0;
   for(int i=0;i<m;i++)
     res+=ans^v[i];
      cout<<res;
}


Measured memory_bytes: 1400
#include <stdio.h>

#define BN 10
#define CN 2

static
int balls[ BN ];
static
int commit[ CN ];

int solve (
  int n
  )
{
  int res = 0;
  int i;

  if ( n >= BN )  return ( 1 );

  for ( i = 0; i < CN; ++i )
  {
    if ( balls[ n ] > commit[ i ] )
    {
      int tmp = commit[ i ];
      commit[ i ] = balls[ n ];
      res = solve ( n + 1 );
      commit[ i ] = tmp;
    }

    if ( res )  break ;
  }

  return ( res );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int n;

  scanf ( "%d", &n );
  while ( n-- )
  {
    int i;

    for ( i = 0; i < BN; ++i )
    {
      scanf ( "%d", balls + i );
    }
    for ( i = 0; i < CN; ++i )
    {
      commit[ i ] = -1;
    }

    puts ( solve ( 0 ) ? "YES"
                       : "NO" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <string>
#include <complex>
using namespace std;

#define INT_max 2147483647


typedef long long ll;
typedef long double ld;


int main(){
	int n;
	cin>>n;
	if(n < 4){
		int ans;
		for(int i = 0;i < n;i++){
			int t;
			cin>>t;
			if(i == 0) ans = t;
			else ans = max(ans,t);
		}
		cout<<ans;
		return 0;
	}
	vector<ll> ans1(n,0);//记录的是当前包含i/2个数的最大和 
	vector<ll> ans2(n,0);//记录的是当前包含（i+1）/2个数的最大和
	for(int i = 0;i < n;i++){
		ll t;
		cin>>t;
		if(i < 2){
			ans2[i] = t;
		}
		else{
			if(i%2) ans2[i] = max(ans2[i-2],ans2[i-3]) + t;
			else ans2[i] = ans2[i-2]+t; 
		}
		if(i < 3){
			if(i == 2) ans1[i] = max(ans1[0],t);
			else ans1[i] = t;
		}
		else{
			if(i%2) ans1[i] = max(ans2[i-3],ans1[i-2]) + t;
			else ans1[i] = max(ans1[i-3],ans1[i-2]) + t;
		}
	}
	if(n%2) cout<<max(ans1[n-1],ans1[n-2]);
	else cout<< max(ans2[n-1],ans2[n-2]);
	return 0;
}




Measured memory_bytes: 6428
#include<stdio.h>
#include<algorithm>
using namespace std;
     int selectionSort(int num[],int n){
         int minj,count=0;
         for(int i=0;i<n;i++){
            minj=i;
            for(int j=i;j<n;j++){
                if(num[j]<num[minj])
                    minj=j;
            }
            swap(num[i],num[minj]);
            if(minj!=i)
               count++;
         }
         return count;
     }
     int main(){
     int n;
     while(~scanf("%d",&n) && n>=1 && n<=100){
        int num[100];
        int count;
        for(int i=0;i<n;i++)
           scanf("%d",&num[i]);
        count=selectionSort(num,n);
        for(int i=0;i<n;i++){
           printf("%d",num[i]);
           if(i<n-1)
             printf(" ");
           else
             printf("\n");
        }
        printf("%d\n",count);
     }
   return 0;
}


Measured memory_bytes: 2720
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n;
	int a[101];

	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n-1)cout<<a[i]<<" ";
	cout<<a[n-1]<<endl;

	for(int i=1; i<n; i++){
		int v=a[i];
		int j=i-1;
		while(j>=0&&a[j]>v){
			a[j+1]=a[j];
			j--;
			a[j+1]=v;
		}
		rep(i,n-1)cout<<a[i]<<" ";
		cout<<a[n-1]<<endl;
	}

	return 0;
}



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

#define MAX_L 50000
#define MAX_R 50000
#define MAX_E 150000

using namespace std;

int n1,n2;//（左、右）の頂点数
int edges;//辺の本数
int last[MAX_L];
int preve[MAX_E];
int head[MAX_E];
int match[MAX_R],dist[MAX_L],que[MAX_L];

void init(int _n1, int _n2){
  n1=_n1,n2=_n2,edges=0;
  fill(last,last+n1,-1);
}

void add_edge(int u, int v){
  head[edges]=v;
  preve[edges]=last[u];
  last[u]=edges++;
}

bool used[MAX_L];

void bfs(){
  fill(dist,dist+n1,-1);
  int sz=0;
  for(int u=0;u<n1;u++)
    if(!used[u])que[sz++]=u,dist[u]=0;
 
  for(int i=0;i<sz;i++){
    int u1=que[i];
    for(int e=last[u1];e>=0;e=preve[e]){
      int u2=match[head[e]];
      if(u2>=0 && dist[u2]<0){
	dist[u2]=dist[u1]+1;
	que[sz++]=u2;
      }
    }
  }
}

bool vis[MAX_L];

bool dfs(int u1){
  vis[u1]=true;
  for(int e=last[u1];e>=0;e=preve[e]){
    int v=head[e],u2=match[v];
    if(u2<0 || (!vis[u2] && dist[u2]==dist[u1]+1 && dfs(u2))){
      match[v]=u1;
      return used[u1]=true;
    }
  }
  return false;
}

int bipartite_matching(){
  fill(used,used+n1,false);
  fill(match,match+n2,-1);
  int flow=0;
  for(;;){
    bfs();
    fill(vis,vis+n1,false);
    int f=0;
    for(int u=0;u<n1;u++)
      if(!used[u] && dfs(u))f++;
    
    if(!f)return flow;
    flow+=f;
  }
}

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

int main(void){
  
  int m,n;
  
  while(cin >> m >> n,m|n){
 
    init(m,n);
    
    vector<int>b(m),r(n);
    for(int i=0;i<m;i++)cin >> b[i];
    for(int i=0;i<n;i++)cin >> r[i];
    
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	if(gcd(b[i],r[j])!=1)add_edge(i,j);
      }
    }

    cout << bipartite_matching() << endl;
  }
  
  return 0;
}

Measured memory_bytes: 2148
N, K = map(int, input().split())
mod = 10**9+7

ans = 0
for i in range(K, N+2):
    _min = 0
    _max = 0
    if i % 2 == 0:
        _min = (0+(i-1))*(i//2)
        _max = ((N-i+1)+N)*(i//2)
    else:
        _min = (0+(i-1))*(i//2) + (0+(i-1))//2
        _max = ((N-i+1)+N)*(i//2) + ((N-i+1)+N)//2
    ans = (ans + _max - _min + 1) % mod

print(ans)


Measured memory_bytes: 64792
factor5 :: Integer -> Integer
factor5 0 = 0
factor5 1 = 0
factor5 2 = 0
factor5 3 = 0
factor5 4 = 0
factor5 n = (n `div` (5 :: Integer)) + factor5 (n `div` (5 :: Integer))

solve :: Integer -> Integer
solve n
    | nMod2 == 1  = 0
    | otherwise = factor5 nOver2
    where nOver2 = n `div` 2
          nMod2  = n `mod` 2

main = do
    n <- read <$> getLine
    let ans = solve n
    print ans


Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

struct st{
	int c;
	int s;
	int f;
};

int main(){
	int N; cin>>N;
	vector<st> train(N-1);
	rep(i,N-1)cin>>train[i].c>>train[i].s>>train[i].f;
	rep(i,N-1){
		int e_ans = 0;
		for(int j = i; j<N-1; ++j){
			e_ans = max(train[j].s, (int)ceil((double)e_ans/train[j].f)*train[j].f);
			e_ans += train[j].c;
		}
		cout<<e_ans<<endl;
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
	import scala.math._
	var n = scala.io.StdIn.readLong

	var ans = List[Int]()
	var f = 0L
	var v = 0L

	for(i<-32L to 0L by -1L){
		if(i%2 == 0){
			v = powL(2L, i)
		}else{
			v = powL(-2L, i)
		}

		var sup = v
		var inf = v

		for(j<-i-1L to 0L by -1L){
			if(j%2L == 0L){
				sup += powL(2L, j)
			}else{
				inf += powL(-2L, j)
			}
		}

		if(inf <= n && n <= sup){
			ans = 1 :: ans
			n -= v
			f = 1 
		}else{
			if(f == 1){
				ans = 0 :: ans
			}
		}
	}

	if(ans.size == 0) println(0)
	else println(ans.reverse.mkString)

	def powL(x: Long, y: Long) = pow(x, y).toLong
}


Measured memory_bytes: 27336