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

using namespace std;

unsigned long long int factorial(int a)
{
	if (a == 1)
	{
		return(1);
	}
	return(factorial(a - 1) * a);
}

void solve()
{
	string S;
	cin >> S;
	vector<int> count(26);
	for (int i = 0; i < S.size(); ++i)
	{
		count[S[i] - 'a']++;
	}
	int isOdd = 0;
	int oddPos = 0;
	for (int i = 0; i < count.size(); ++i)
	{
		if (count[i] % 2)
		{
			oddPos = i;
			++isOdd;
			if (isOdd >= 2 || S.size() % 2 == 0)
			{
				cout << 0 << endl;
				return;
			}
		}
	}
	if (oddPos)
	{
		count[oddPos]--;
	}
	unsigned long long int ans = 1;
	int sum = 0;
	unsigned long long int denominator = 1;
	for (int i = 0; i < count.size(); ++i)
	{
		count[i] /= 2;
		sum += count[i];
		if (count[i])
		{
			denominator *= factorial(count[i]);
		}
	}
	for (int i = 1; i <= sum; ++i)
	{
		ans *= i;
	}
	ans /= denominator;
	cout << ans << endl;
}

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

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

// 14:01



using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


int main() {
    int task = 1;
//    cin >> task;
    while (task--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (auto& el : a) {
            cin >> el;
            --el;
        }
        int slow = 0;
        int fast = 0;
        int i = 0;
        do {
            if (a[fast] == 1) {
                cout << i + 1 << "\n";
                exit(0);
            }
            if (a[a[fast]] == 1) {
                cout << i + 2 << "\n";
                exit(0);
            }
            i += 2;
            slow = a[slow];
            fast = a[a[fast]];
        } while (slow != fast);
        cout << -1 << "\n";

    }

    return 0;
}

Measured memory_bytes: 768
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>

int main(int argc, char *argv[]) {
  double a;
  std::cin >> a;
  std::cout << std::fixed;
  std::cout << std::setprecision(9) << (a * a * a / 27) << std::endl;
}


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

typedef long long ll;
const int MAX_N = 100030;    // Change as necessary
const ll  MODD = 1000000009; //

int A[MAX_N];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  string s; cin >> s;
  
  int ctr=0;
  for(int i=0;i<s.length();i++){
    if(i % 2 == 0)
      if(s[i] == 'p') ctr--;
    if(i % 2)
      if(s[i] == 'g') ctr++;
  }
  
  cout << ctr << endl;
  
  return 0;
}


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

int main(){
  int n; cin >> n;
  vector<int> x(n);
  for(int i=0; i<n; ++i) cin >> x[i];
  int p = round((double)accumulate(x.begin(), x.end(), 0) / (double)n);
  int sum = 0;
  for(int i=0; i<n; ++i) sum += pow(x[i]-p , 2);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
vector<T> prime_factor(T N)
{
    vector<T> P;
    for (int i = 2; i * i <= N; i++)
    {
        while (N % i == 0)
        {
            P.push_back(i);
            N /= i;
        }
    }
    if (N != 1)
        P.push_back(N);
    return P;
}

int main()
{
    int N;
    cin >> N;
    printf("%d:", N);
    auto P = prime_factor(N);
    for(auto &p : P){
        printf(" %d", p);
    }
    puts("");
    
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
vector<int> num(0);
for(int i = 0; i<(S.size()-2);i++){
    int K =(S.at(i)-'0')*100+(S.at(i+1)-'0')*10+(S.at(i+2)-'0');
    int L = abs(753-K);
    num.push_back(L);
}
sort(num.begin(),num.end());
cout << num.at(0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  string c;
  
  bool Yellow = false;
  
  int i;
  for( i=0; i < N; i++){
    cin >> c;
    if( c == "Y")	Yellow = true;
  }
  
  if(Yellow)	cout << "Four" << endl;
  else			cout << "Three" << endl;
 
}

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

#define st first
#define nd second
#define mp make_pair
#define space << " " <<
#define END << endl
#define pb push_back
#define fo(i,n) for(int i = 0; i<n; ++i)
#define ff(i,n) for(int i = 1; i<n; ++i)

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pi;
typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> pl;
typedef vector<pil>vil;

const int N = 5000;
const int INF = 10000000;

int s[100500];
vector<int> board[INF], su;
int n,m;
int parent[INF];
int dp[INF][3];
bool ok[INF][3];
int root;


void init()
{
    sort(su.begin(),su.end());
    deque<int> de;
    for(int x=1; x<=n; ++x) de.push_back(x);
    int l = n+1;
    while(de.size()!=1)
    {
        fo(i,3) { int u = de.front(); de.pop_front(); parent[u] = l; }
        de.push_back(l); l++;
    }
    root = de.front();
    for(int x=1; x<root; ++x) board[parent[x]].push_back(x);
}

int dfs(int node , int num,int cost)
{
    if(ok[node][num]) return dp[node][num];
    ok[node][num] = 1;
    if( node <= n)
    {
        if(s[node] && cost <= s[node] && !num ) return dp[node][num] = INF;
        else if(s[node] && cost > s[node] && num ) return dp[node][num] = INF;
        else if(s[node] && cost <= s[node] && num ) return dp[node][num] = num;
        else if(s[node] && cost > s[node] && !num ) return dp[node][num] = num;
        else return dp[node][num] = num;
    }
    else
    {
        int ans = INF;
        for(int x=0; x<3; ++x) ans = min(ans , dfs(board[node][x],1-num,cost) + dfs(board[node][(x+1)%3],num,cost) + dfs(board[node][(x+2)%3],num,cost) );
        ans = min(ans , dfs(board[node][0],num,cost) + dfs(board[node][1],num,cost) + dfs(board[node][2],num,cost) );
        return dp[node][num] = ans;
    }
}

bool check( int u)
{
    int k = 0;
    for(int x=0; x<su.size(); ++x) if(su[x] >= u) k++;
    for(int x=0; x<=root; ++x) for(int y=0; y<2; ++y) dp[x][y] = ok[x][y] = 0;
    int kk = dfs(root,1,u);
    if(kk > k) return 0;
    else return 1;
}

int work()
{
    init();
    int l = 0;
    int r = n-1;
    while(r - l > 1)
    {
        int mid = (r + l)/2;
        if(check(su[mid])) l = mid;
        else r = mid;
    }
    if(check(su[r])) return su[r];
    else return su[l];
}

int main()
{
    //freopen("test.txt","r",stdin);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for(int i=0; i<m; ++i) { int u,v; cin >> u >> v; s[v] = u; su.pb(u); }
    for(int i=0; i<n-m; ++i) { int u; cin >> u; su.pb(u); }
    cout << work() << endl;
}

Measured memory_bytes: 245756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int maxm=125;
const int INF = 0x3f3f3f3f;

int main()
{
    int n,k,ans=0,x;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        if(x>=k) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    scs = [list(map(int, input().split())) for _ in range(m)]
    for i in range(0, 10**n):
        istr = str(i)
        tf = True
        if len(istr) == n:
            for j in range(m):
                if istr[scs[j][0] - 1] != str(scs[j][1]):
                    tf = False
            if tf:
                print(i)
                return
    print('-1')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a,b,c,x,y,ans,ans0,ans1,ans2;
  	cin>>a>>b>>c>>x>>y;
  	map<ll,ll> mp;
  	mp[x]=a;
  	mp[y]=b;
    ans0=a*x+b*y;
    ans1=c*2*min(x,y)+mp[max(x,y)]*abs(x-y);
    ans2=c*2*max(x,y);
    ans=min({ans0,ans1,ans2});
    cout<<ans<<endl;
    return 0;
}	


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

int main() {
	int n;
	while (scanf("%d", &n), n) {
		vector<int>t, h;
		bool used[201]{};
		int b = 0;
		rep(i, n) {
			int a; scanf("%d", &a);
			t.push_back(a);
			used[a] = true;
		}
		for (int i = 1; i <= 2 * n; i++) {
			if (!used[i])h.push_back(i);
		}
		sort(t.begin(), t.end()); sort(h.begin(), h.end());
		bool f = true;
		while (!t.empty() && !h.empty()) {
			if (f) {
				auto it = lower_bound(t.begin(), t.end(), b);
				if (it == t.end())b = 0;
				else { b = *it; t.erase(it); }
			}
			else {
				auto it = lower_bound(h.begin(), h.end(), b);
				if (it == h.end())b = 0;
				else { b = *it; h.erase(it); }
			}
			f = !f;
		}
		printf("%d\n%d\n", h.size(), t.size());
	}
}

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

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

int N,M;
int DP[3005][3005];
string A,B,C;

int main(){
	cin>>A>>B;
	N=A.size();
	M=B.size();
	for(int i=1;i<N+1;i++)
		for(int j=1;j<M+1;j++)
			if(A[i-1]==B[j-1])
				DP[i][j]=DP[i-1][j-1]+1;
			else
				DP[i][j]=max(DP[i][j-1],DP[i-1][j]);

	while(N!=0 and M!=0){
		if(A[N-1]==B[M-1]){
			C+=A[N-1];
			N--;
			M--;
		}
		else if(DP[N-1][M]>DP[N][M-1])
			N--;
		else
			M--;
	}

	reverse(C.begin(),C.end());
	cout<<C;

}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

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

signed main() {
  int n;
  cin >> n;
  ll pw = 1;
  rep(i, 1, n + 1) {
    pw *= i;
    pw %= mod;
  }

  cout << pw << endl;
}


Measured memory_bytes: 256
def main():
    N, X = (int(i) for i in input().split())
    x = [abs(int(i) - X) for i in input().split()]
    from fractions import gcd
    for i in range(1,N):
        x[i] = gcd(x[i-1], x[i])

    print(x[-1])

if __name__ == '__main__':
    main()

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

int main() {
    int N, M, X, Y, temp;
    std::cin >> N >> M >> X >> Y;
    
    std::vector<int> x;
    for (int i=0; i<N; ++i) {
        std::cin >> temp;
        x.push_back(temp);
    }
    std::vector<int> y;
    for (int i=0; i<N; ++i) {
        std::cin >> temp;
        y.push_back(temp);
    }
    
    std::sort(x.begin(), x.end());
    std::sort(y.begin(), y.end());
    
    bool is_war = true;
    
    for (auto Z=x.back()+1; Z<=Y; ++Z) {
        if (Z > X && Z <= Y && Z <= y.front()) {
            is_war = false;
            break;
        }
    }
    
    if (is_war)
        std::cout << "War" << std::endl;
    else
        std::cout << "No War" << std::endl;
        
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#define ll long long
#define out(a) printf("%d",a)
#define ln printf("\n")
const int N=1e5+50;
const int MOD=1e9+7;
const int inf=0x7f7f7f7f;
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	out(3*n*n);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

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

// dp[i][j] :=
// i番目までの商品を、重さがj以下になるように選んだ時の価値の最大値
ll dp[110][100100] = {0};

int main() {
  int n, w_limit;
  cin >> n >> w_limit;

  int w[n + 1];
  int v[n + 1];
  repi(i, 1, n + 1) { cin >> w[i] >> v[i]; }

  repi(i, 1, n + 1) {
    repi(j, 0, w_limit + 1) {
      if (j >= w[i]) {
        // i番目の商品を選ぶ場合
        chmax(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
      }

      // i番目の商品を選ばない場合
      chmax(dp[i][j], dp[i - 1][j]);
    }
  }

  cout << dp[n][w_limit] << endl;
  return 0;
}


Measured memory_bytes: 79360
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

events = []
for i in range(N):
    S, T, X = map(int, input().split())
    events.append([S-X-0.5, 1, X])
    events.append([T-X-0.5, -1, X])

for i in range(Q):
    d = int(input())
    events.append([d, 0, i])

events = sorted(events)

count = defaultdict(int)
Xheap = []
heapq.heapify(Xheap)
ans = [-1 for i in range(Q)]

for e in events:
    if e[1] == 1:
        heapq.heappush(Xheap, e[2])
        count[e[2]] += 1
    elif e[1] == -1:
        count[e[2]] -= 1
    else:
        while Xheap:
            a = Xheap[0]
            if count[a] == 0:
                heapq.heappop(Xheap)
            else:
                ans[e[2]] = a
                break

for i in range(Q):
    print(ans[i])

Measured memory_bytes: 208184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    ll n;cin>>n;
    ll a,b;cin>>a>>b;
    ll A,B;
    ll m=n/6;
    ll l=n-(m*6);
    if(m%2==0){
        A=a;
        B=b;
    }else{
        A=-a;
        B=-b;
    }
    rep(i,1,l){
        if(i%2==1){
            A=A-B;
        }else{
            B=A+B;
        }
    }
    cout<<A<<' '<<B<<endl;
    
    
    
    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; string s;
    cin >> n >> s;
    V<int> a;
    for (int i = 0; i < n - 1; i++) {
        a.emplace_back(abs(s[i] - s[i + 1]));
    }
    n--;

    bool exist1 = false;
    for (int i = 0; i < n; i++) if (a[i] == 1) exist1 = true;
    // 01 だけにする
    for (int i = 0; i < n; i++) {
        if (a[i] == 2) {
            if (exist1) a[i] = 0;
            else a[i] = 1;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) continue;
        int tmp = 1;
        for (int bit = 0; bit < 30; bit++) {
            int nbit = (n - 1) >> bit & 1, rbit = i >> bit & 1;
            if (nbit < rbit) tmp &= 0;
            else tmp &= 1;
        }
        ans ^= tmp;
    }
    if (!exist1) ans *= 2;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 8744
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main() {
  int n;
  string s;
  cin >> n >> s;
  if (n % 2 == 1) {
    cout << "No";
    return 0;
  }
  bool yes = true;
  for (int i = 0, j = n/2; j < s.length(); i++, j++) {
    if (s[i] != s[j]) yes = false;
  }
  if (yes) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
var n,z:int64;
    x,y:longint;
begin
  readln(n);
  for x:=1 to 3500 do
  for y:=1 to 3500 do
  if 4*x*y-(n*(x+y))>0 then
    if (x*y*n) mod (4*x*y-n*(x+y))=0 then
    begin
      z:=(x*y*n) div (4*x*y-n*(x+y));
      writeln(x,' ',y,' ',z);
      exit;
    end;
end.

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

int main() {
  string s;
  string t;

  cin >> s >> t;
  vector<int> a(26);
  vector<int> b(26);

  for(int i=0;i<s.size();i++) {
    int c = s[i] - 'a';
    int d = t[i] - 'a';

    a[c]++;
    b[d]++;
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  if(a == b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 776
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

dp = [[0] * (k + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
    dp[i + 1][0] = dp[i][0]
    for j in range(1, k+1):
        dp[i + 1][j] = (dp[i + 1][j - 1] + dp[i][j]) % mod
    for j in range(k, a[i], -1):
        dp[i + 1][j] = (dp[i + 1][j] - dp[i + 1][j - a[i] - 1]) % mod
print(dp[n][-1])

Measured memory_bytes: 146396
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<int,int> m;
  long n,p,P,d,res=1;
  cin>>n>>P;
  p=P;
  if(n==1){cout<<p;return 0;}
  for(int i=2;i<=pow((double)P,1.0/(double)n);++i){
    d=pow(i,n);
    while(p%d==0){
      m[i]++;
      p/=d;
    }
  }
  for(auto itr=m.begin();itr!=m.end();itr++)res*=pow(itr->first,itr->second);
  cout<<res;
  return 0;
}

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

int main()
{
    unsigned long long a, b, c;
    cin >> a >> b >> c;
    if(a + b > c){
        cout << "No" << endl;
    }else if(a * a + b * b + c * c > 2 * (a * b + b * c + c * a)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
conb::(x,x,x,x,x)->[[x]]
conb (a,b,c,d,e) = [[a,b,c],[a,b,d],[a,b,e],[a,c,d],[a,c,e],[a,d,e],[b,c,d],[b,c,e],[b,d,e],[c,d,e]]

eater::(Integer,Integer,Integer,Integer,Integer)->[String]->(Integer,Integer,Integer,Integer,Integer)
eater (m,a,r,c,h) []         = (m,a,r,c,h)
eater (m,a,r,c,h) ((x:_):xs) = case x of
                              'M' -> eater (m+1,a,r,c,h) xs
                              'A' -> eater (m,a+1,r,c,h) xs
                              'R' -> eater (m,a,r+1,c,h) xs
                              'C' -> eater (m,a,r,c+1,h) xs
                              'H' -> eater (m,a,r,c,h+1) xs
                              otherwise -> eater (m,a,r,c,h) xs

solver::[String]->Integer
solver ss = let vec = eater (0,0,0,0,0) ss in
            sum (map product (conb vec))

main::IO()
main=do
  nc<-getLine
  let n = read nc ::Int
  ss<-forM [1..n] (\_->getLine)
  print (solver ss)

Measured memory_bytes: 48508
#include <stdio.h>
int main(){
	int t;
	char s[50];
	int ac=0,tle=0,wa=0,re=0;
	scanf("%d",&t);
		for(int i=0;i<t;i++){
			scanf("%s",s);
		if(s[0]=='A'){
			ac++;
			}
		else if(s[0]=='W'){
				wa++;
			}
		else if(s[0]=='T'){
				tle++;
			}
		else if(s[0]=='R'){
				re++;
			}
		}	
			printf("AC x %d\n",ac);
			printf("WA x %d\n",wa);
			printf("TLE x %d\n",tle);
			printf("RE x %d\n",re);
     return 0;
}

Measured memory_bytes: 1732
import sys

mod = 1000000007

n, k = map(int, input().split())
nexts = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    nexts[a].append(b)
    nexts[b].append(a)

# [score, defined]
scores = [[0, 0] for _ in range(n+1)]
result = 1
nextList = [1]
while len(nextList) > 0:
    i = nextList.pop()
    defined = 0
    for j in nexts[i]:
        if scores[j][0] != 0:
            defined += scores[j][1]
        else:
            nextList.append(j)
        scores[j][1] += 1
    if k - defined <= 0:
        result = 0
        break
    result = result * (k-defined) % mod
    scores[i][0] = k-defined
    scores[i][1] += 1

print(result)



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

#define NA 1000000000

int n, m, c, s, g;
int p[20];
int q[20][50];
int r[20][50];

int distances[20][100][100];
int fares[20][100][100];
int faresConsideredAllCompany[100][100];

void init()
{
	int company, i, j;
	for (company = 0; company < 20; ++company)
	{
		for (i = 0; i < 100; ++i)
		{
			for (j = 0; j < 100; ++j)
			{
				distances[company][i][j] = faresConsideredAllCompany[i][j] = (i == j ? 0 : NA);
			}
		}
	}
}

int getCost(int company, int distance)
{
	if (distance == NA) { return NA; }
	if (distance == 0) { return 0; }

	int result = 0;
	int i;
	for (i = 0;; ++i)
	{
		if (distance <= q[company][i + 1])
		{
			return result + (distance - q[company][i]) * r[company][i];
		}

		result += (q[company][i + 1] - q[company][i]) * r[company][i];
	}
}

void getMinimumDistances()
{
	int i, j, k, company;
	for (company = 0; company < c; ++company)
	{
		for (k = 0; k < n; ++k)
		{
			for (i = 0; i < n; ++i)
			{
				for (j = 0; j < n; ++j)
				{
					if (distances[company][i][j] > distances[company][i][k] + distances[company][k][j])
					{
						distances[company][i][j] = distances[company][i][k] + distances[company][k][j];
					}
				}
			}
		}
	}
}

void getMinimumFare()
{
	int i, j, company;
	for (i = 0; i < n; ++i)
	{
		for (j = 0; j < n; ++j)
		{
			for (company = 0; company < c; ++company)
			{
				fares[company][i][j] = getCost(company, distances[company][i][j]);
				if (fares[company][i][j] < faresConsideredAllCompany[i][j])
				{
					faresConsideredAllCompany[i][j] = fares[company][i][j];
				}
			}
		}
	}
}

int solve()
{
	getMinimumDistances();
	getMinimumFare();

	int i, j, k;
	for (k = 0; k < n; ++k)
	{
		for (i = 0; i < n; ++i)
		{
			for (j = 0; j < n; ++j)
			{
				if (faresConsideredAllCompany[i][j] > faresConsideredAllCompany[i][k] + faresConsideredAllCompany[k][j])
				{
					faresConsideredAllCompany[i][j] = faresConsideredAllCompany[i][k] + faresConsideredAllCompany[k][j];
				}
			}
		}
	}

	return (faresConsideredAllCompany[s - 1][g - 1] == NA ? -1 : faresConsideredAllCompany[s - 1][g - 1]);
}

int main()
{
	int i, company;
	while (true)
	{
		scanf("%d %d %d %d %d", &n, &m, &c, &s, &g);
		if (n == 0) { break; }

		init();

		for (i = 0; i < m; ++i)
		{
			int x, y, d, company;
			scanf("%d %d %d %d", &x, &y, &d, &company);
			if (distances[company - 1][x - 1][y - 1] > d)
			{
				distances[company - 1][x - 1][y - 1] = distances[company - 1][y - 1][x - 1] = d;
			}
		}

		for (company = 0; company < c; ++company) { scanf("%d", &p[company]); }
		for (company = 0; company < c; ++company)
		{
			for (i = 1; i < p[company]; ++i) { scanf("%d", &q[company][i]); }
			q[company][0] = 0;
			q[company][p[company]] = NA;
			for (i = 0; i < p[company]; ++i) { scanf("%d", &r[company][i]); }
		}

		printf("%d\n", solve());
	}

	return 0;
}


Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int a[3];
	for (int i = 0; i < 3; ++i)
	{
		cin >> a[i];
	}
	sort(a, a+3);
	cout << a[2]-a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
list1=[1,2,4,8,16,32,64,128,256,512,9,27,81,243,729,25,125,625,49,343,100,1000,121]
num=input()
num=int(num)

for i in range(12,32):
    list1.append(i**2)
    i+=1
list2=[]
for j in range(len(list1)):
    if num>=list1[j]:
        list2.append(list1[j])
        j +=1
        
print(max(list2))
    

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAX 100000

// n: #. of luggages.
int n, k;
long long T[MAX];

// given P, k (P: maximum load, k: #. of truck)
// return #. of loaded luggages.
int test(long long P){
    int i = 0;
    for (int j = 0; j < k; j++){
        long long s = 0;
        while(s+T[i] <= P){
            s += T[i];
            i++;
            if(i==n){ return n; }
        }
    }
    return i;
}

int solve() {
    long long left = 0;
    long long right = MAX * 10000;
    long long mid;
    while(left < right){
        mid = (left+right)/2;
        
        // --------------------
        // cout << "check ( " << left << " , " << right << " )." << endl;
        // --------------------
        
        int v = test(mid);
        if(v < n) left = mid+1;
        else right = mid;

    }
    return right;
}

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

    long long ans = solve();
    cout << ans << endl;
    return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;
    for(int i=0; i<10000; i++){
        if( floor(i*0.08)==A && floor(i*0.1) ==B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
main :: IO ()
main = do
  n <- readLn :: IO Int
  print $ length $ filter odd8 [1..n]

factors :: Int -> [Int]
factors n = filter ((==0).(n`mod`)) [1..n]

odd8 :: Int -> Bool
odd8 n
  | even n    = False
  | otherwise = length (factors n) == 8

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for (int i = 0; i < M; ++i)
    cin >> A[i] >> B[i];
  sort(A.begin(), A.end(), greater<int>());
  int ans = 0;
  for (int i = 0; i < M - 1; ++i)
    ans += max(N - A[i], 0);
  cout << ans << endl;
}


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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif



void solve() {
    
	rd1(ll, n);
	vl A(n);
	FOR(i, 0, n)
	    cin >> A[i];
	    
    int DP[100004];
    memset(DP, 0, sizeof(DP));
    DP[0] = 0;
    DP[1] = abs(A[0] - A[1]);
    
    for(int i = 2; i < n; i++) {
        int c1 = abs(A[i - 1] - A[i]) + DP[i - 1];
        int c2 = abs(A[i - 2] - A[i]) + DP[i - 2];
        DP[i] = min(c1, c2);
    }
    
    cout << DP[n - 1] << endl;
	
}

int main() {
	
	fastio;

//  	rd1(ll, t);
	ll t = 1;

    while(t--) {
        solve();
    }
    
	return 0;
}

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

int main() {
	int vetor[5], resp;
	for (int i=0; i<5; i++) {
		cin >> vetor[i];
		if (vetor[i] == 0) {
			resp = i+1;
		}
	}
	cout << resp << endl;
	return 0;
}

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

bool m(std::string& v, size_t i)
{
	if (i != 0 && v.size() == i) {
		return true;
	}

	if (v.compare(i, 5, "dream") == 0) {
		if (m(v, i + 5)) {
			return true;
		}
	}
	if (v.compare(i, 7, "dreamer") == 0) {
		if (m(v, i + 7)) {
			return true;
		}
	}
	if (v.compare(i, 5, "erase") == 0) {
		if (m(v, i + 5)) {
			return true;
		}
	}
	if (v.compare(i, 6, "eraser") == 0) {
		if (m(v, i + 6)) {
			return true;
		}
	}

	return false;
}

int main()
{
	std::string s;
	std::cin >> s;

	std::cout << (m(s, 0) ? "YES" : "NO") << std::endl;

	return 0;
}


Measured memory_bytes: 896
#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<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////


int main() {
    double N; cin >> N;
	if (int(N) % 2 == 0) {
		cout << fixed << setprecision(12) << double(1) / double(2) << endl;
	}
	else {
		cout << fixed << setprecision(12) << (N+1)/(2* N) << endl;
	}
	return 0;
}


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

#define int long long
#define ld long double
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define x first
#define y second

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

	int n,k;
	cin>>n>>k;
	int a[1001];
	for (int i=0; i<n; i++)
		cin>>a[i];
	sort(a,a+n);
	int res=0;
	for (int i=0; i<k; i++)
		res+=a[i];
	cout<<res<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> f(n, 0);
    REP(i, n){
        ll ai;
        cin >> ai;
        f.at(--ai)++;
    }
    sort(f.begin(), f.end());

    vector<ll> cs(n, 0);
    cs.at(0) = f.at(0);
    for(ll i = 1; i < n; ++i){
        cs.at(i) = cs.at(i - 1) + f.at(i);
    }

    vector<ll> ans(n, 0);
    for(ll k = 1; k <= n; ++k){
        ll lo = 0, hi = n / k + 1;
        while(lo < hi){
            const ll x = (lo + hi + 1) / 2;
            const ll idx = upper_bound(f.begin(), f.end(), x) - f.begin();
            ll sum = x * (f.size() - idx);
            if(idx > 0){
                sum += cs.at(idx - 1);
            }
            if(sum >= k * x){
                lo = x;
            }else{
                hi = x - 1;
            }
        }

        cout << lo << endl;
    }
    return 0;
}


Measured memory_bytes: 7936
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a!=b && a!=c)
    printf("%d\n",a);
  else if(b!=a && b!=c)
    printf("%d\n",b);
  else
    printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <queue>
#include <vector>

using namespace std;


int main(){
	int a,b,c;
	char dm[256];
	while(scanf("%d %d",&a,&b) != EOF){
		c = sprintf(dm,"%d",a+b);
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}
 
typedef pair<ll,ll> Pair;
const ll MAX_L=10000;
 

const ll MAX = 100005;
const ll MOD = 1000000007;

ll 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(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll n,k;
ll a[MAX];

void solve(){
    ll ans=0;
    //max
    for(ll i=1;i<=n-k+1;i++){
        ll score=a[n-i]*COM(n-i,n-k-i+1)%MOD;
        ans+=score;
        ans%=MOD;
    }
    //min
    for(ll i=0;i<=n-k;i++){
        ll score=a[i]*COM(n-i-1,n-k-i)%MOD;
        ans-=score;
        ans%=MOD;
    }
    if(ans<0) ans+=MOD;
    kaku(ans);
}

int main(){
    cin >> n >>k;
    rep(i,n) cin >> a[i];
    COMinit();
    sort(a,a+n);
    solve();
  
}




Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;  
using namespace std;



typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
    
    
    
//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;
ll t=1;

void solve()
{
    cin>>n>>k;
    vector<ll>v(n);
    for(ll i=0;i<n;i++)cin>>v[i];
    for(ll i=k;i<n;i++)
    {
        if(v[i]>v[i-k])cout<<"Yes";
        else cout<<"No";
        cout<<"\n";
    }
    
// if(t>0)cout<<"\n";
   
}



int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 4760
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){

  ll N;
  cin >> N;
  vector<ll> h(N+1);

  for(int i = 1; i <N+1;i++){
    cin >> h[i];
  }
  h[0]=INFL;
  vector<ll> dp(N+1, 0);
  dp[0] = 0;
  dp[1] = 0;

  for(int i=2;i<N+1;i++){
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
  }
  cout << dp[N] <<endl;


}


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

int main() {
  int N, a, b, c;
  cin >> N;
  a = N / 100;
  N -= a * 100;
  b = N / 10;
  N -= b * 10;
  c = N;
  if (a == 7 || b == 7 || c == 7) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  int a = N / 100;
  int b = N % 10;
  
  if(a == b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  int n;
  cin >> n;
  vi a(n);
  //rep(i,n) cin >> a[i];
  rep(i,n) scanf("%d",&a[i]);

  vi b(n);
  rep(i,n) {
    int sng;
    if (n%2 == 0) {
      sng = (i%2 == 0 ? 1 : -1);
    }
    else {
      sng = (i%2 == 0 ? -1 : 1);
    }
    b[n/2+sng*((i+1)/2)] = a[i];
  }

  rep(i,n) {
    printf("%d%s",b[i],i!=n-1?" ":"\n");
  }
}

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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n,m;
  cin >> n >> m;
  string s;
  cin >> s;
  reverse(s.begin(), s.end());

  vll step;
  REP(i,n+1){
    if(s[i]=='0')
      step.push_back(i);
  }

  ll cur=0;
  vll ans;
  while(cur!=n){
    auto it = upper_bound(step.begin(), step.end(), cur+m);
    it--;
    if(*it-cur==0){
      cout << -1 << endl;
      return 0;
    }

    ans.push_back(*it-cur);
    cur = *it;
  }

  REP(i, ans.size())
    cout << ans[ans.size()-1-i] << " ";
  cout << endl;

}


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

int main() {
  int n;
  cin >> n;
  int t[n], x[n], y[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  int xc = 0, yc = 0;
  int tc = 0;
  for (int i = 0; i < n; i++) {
    int dist = abs(xc - x[i]) + abs(yc - y[i]);
    int res = (t[i] - tc) - dist;
    if (res < 0 || res % 2) {
      cout << "No" << endl;
      return 0;
    }
    tc = t[i];
    xc = x[i];
    yc = y[i];
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a==1)a=14;
  if(b==1)b=14;
  if(a>b)cout<<"Alice"<<endl;
  else if(a<b)cout<<"Bob"<<endl;
  else cout<<"Draw"<<endl;
  return(0);
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	if n <= k {
		fmt.Println(0)
		return
	}

	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	sort.Sort(sort.IntSlice(h))
	ans := 0
	for j := 0; j < n-k; j++ {
		ans += h[j]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

vector<ll> fact(1e5+1);
vector<ll> inv(1e5+1);
vector<ll> invf(1e5+1);
vector<ll> A(1e5+1, llinf);
int N, K;

int main() {
    cin>>N>>K;
    fact[0] = invf[0] = 1LL;
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
        fact[i] = (i * fact[i-1]) % MOD;
        inv[i] = (i == 1) ? 1 : (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;
        invf[i] = (invf[i-1]*inv[i]) % MOD;
    }
    sort(A.begin(), A.end());
    ll ans = 0LL;
    ll s = (MOD + A[N-1] - A[0]) % MOD;
    int b = 1, e = N - 2;
    if (K-2 < 0) { cout << 0 << endl; return 0; }
    for (int i = N-2; i >= K-2; --i) {
        ans = (ans + (((((fact[i] * invf[K-2]) % MOD) * invf[i-K+2]) % MOD) * s) % MOD) % MOD;
        if (i != K-2) s = (((MOD + s + A[e]) % MOD) - A[b] + MOD) % MOD;
        --e; ++b;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int N, k;
vector<int> h(100010);

vector<int> dp(100010);

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


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

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int a = Integer.parseInt(sc.next());
      if ((i + 1) % 2 == 1 && a % 2 == 1) {
        ans++;
      }
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 35748
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

const big_int: u64 = 1000_000_000 + 7;

fn main() {
    let v: Vec<usize> = read_vec();
    let h = v[0];
    let w = v[1];
    let g = v[2] - 1;
    let mut dp = vec![vec![0; w]; h + 1];
    dp[0][0] = 1;

    for i in 0..h {
        for j in 0..w {
            for k in 0..2u64.pow((w - 1) as u32) {
                let mut k = k;
                let mut line = vec![false; w - 1];
                let mut is_valid = true;
                for l in 0..w - 1 {
                    line[l] = if k % 2 == 1 {true} else {false};
                    k = k >> 1;
                    if l >= 1 {
                        if line[l] && line[l - 1] {
                            is_valid = false;
                            break;
                        }
                    }
                }
                if !is_valid {
                    continue;
                }
                if j >= 1 && line[j - 1] {
                    dp[i + 1][j - 1] += dp[i][j];
                    dp[i + 1][j - 1] %= big_int;
                } else if j < w - 1 && line[j] {
                    dp[i + 1][j + 1] += dp[i][j];
                    dp[i + 1][j + 1] %= big_int;
                } else {
                    dp[i + 1][j] += dp[i][j];
                    dp[i + 1][j] %= big_int;
                }
            }
        }
    }
    println!("{:?}", dp[h][g]);
}


Measured memory_bytes: 4352
MOD = 10**9+7
h, w, k = map(int, input().split())

dp = [[0]*w for _ in range(h+1)]
dp[0][0] = 1

patterns = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

if w == 1:
    print(1)
    exit()

for i in range(1, h+1):
    # most left
    dp[i][0] = (dp[i-1][0]*patterns[1:][w-2]%MOD + dp[i-1][1]*patterns[w-2]%MOD)%MOD
    for j in range(1, w-1):
        npath = dp[i-1][j-1]*(patterns[j-1]*patterns[1:][w-j-2])%MOD\
                + dp[i-1][j]*(patterns[1:][j-1]*patterns[1:][w-j-2])%MOD\
                + dp[i-1][j+1]*(patterns[1:][j-1]*patterns[w-j-2])%MOD
        dp[i][j] = npath%MOD
    dp[i][w-1] = (dp[i-1][w-2]*patterns[w-2]%MOD + dp[i-1][w-1]*patterns[1:][w-2]%MOD)%MOD

# for p in dp: print(p)

print(dp[-1][k-1])
    


Measured memory_bytes: 3064
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n=int(input())
	A=list(map(int,input().split()))
	ans=[0]*(n+1)
	
	for i in range(n,0,-1):
		ans[i]=(sum(ans[::i])%2) ^ A[i-1]
	
	print(sum(ans))
	print(*[i for i,x in enumerate(ans) if x==1])
	
	
if __name__ == '__main__':
	main()


Measured memory_bytes: 13092
#pragma warning disable
using System;


class Program
{
    static void Main(string[] args)

    {
        string line;

        while (true)
        {
            line = Console.ReadLine();
            int judge = int.Parse(line);
            if (judge == 0) break;


            int[] score = new int[judge];
            int sum = 0;

            for (int i = 0; i < judge; i++)
            {
                score[i] = int.Parse(Console.ReadLine());
                sum += score[i];
            }


            int max, min;
            min = max = score[0];
            for(int i = 0; i < judge; i++)
            {
                if (score[i] < min) min = score[i];
                if (score[i] > max) max = score[i];
            }

            int average = (sum - max - min) / (judge - 2);
            Console.WriteLine(average);

          
        }
    }
}

Measured memory_bytes: 9228
n,m = list(map(int,input().split()))
H = list(map(int,input().split()))
h = [0]
h.extend(H)
e = [[] for _ in range(n+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)
ans = 0
for i in range(1,n+1):
    high = True
    for j in range(len(e[i])):
        t = h[e[i][j]]
        if h[i] <=  t:
            high = False
            break
    if high:
        ans += 1
print(ans)

Measured memory_bytes: 30228