akhauriyash/Code-Regression huggingface dataset:
findThirdRoot :: Integral a => a -> Double
findThirdRoot q = findThirdRoot' q'' $ q'' / 2
    where
        q'' = fromIntegral q
        findThirdRoot' q' xn
            | abs (xn * xn * xn - q') < 0.00001 * q' = xn
            | otherwise                              = findThirdRoot' q' xn2
            where xn2 = xn - (xn * xn * xn - q') / (3 * xn * xn)

main :: IO ()
main = putStr . unlines . map show . map findThirdRoot .
    takeWhile (/= -1) . map read . lines =<< getContents

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

using namespace std;

int st[4];

int main() {
    int N;cin >> N;
    string s;
    int res = 0;
    for (int i = 0; i < N; ++i) {
        cin >> s;
        for (int j = 1; j < s.length(); ++j) {
            if (s[j-1] == 'A' && s[j] == 'B') ++res;
        }
        if (s.front() == 'B' && s.back() == 'A'){ 
            ++st[0];
        } else if (s.front() == 'B') {
            ++st[1];
        } else if (s.back() == 'A') {
            ++st[2];
        }
    }

    if (st[0] != 0 && st[2] != 0) {
        --st[2]; ++res;
    }
    if (st[0] != 0 && st[1] != 0) {
        --st[1]; ++res;
    }
    if (2 <= st[0]) {
        res += (st[0] - 1);
    }
    res += min(st[1], st[2]);

    cout << res << endl;
}

Measured memory_bytes: 256
import math

n = int(input())
for i in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    a1 = x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2
    a2 = y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2
    px = ((y1 - y3) * a1 - (y1 - y2) * a2) / \
        (2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3))
    py = ((x1 - x3) * a1 - (x1 - x2) * a2) / \
        (2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3))
    r = math.hypot(x1 - px, y1 - py)
    print("{0:.3f} {1:.3f} {2:.3f}".format(px, py, r))

Measured memory_bytes: 7680
N,M,X=map(int,input().split())
C=[]
A=[[] for  _  in range(N)]
for i in range(N):
  tmpA=list(map(int,input().split()))
  C+=[tmpA[0]]
  A[i]=tmpA[1:]

costmin=float('inf')
for k in range(2**N):
  tansaku=k
  koubai=[0 for i in range(N)]
  rikaido=[0 for i in range(M)]
  cost=0
  for i in range(N-1):
    koubai[i]=tansaku//(2**(N-i-1))
    tansaku=tansaku%(2**(N-i-1))
  koubai[-1]=tansaku
  for i in range(N):
    if koubai[i]==1:
      cost+=C[i]
      for j in range(M):
        rikaido[j]+=A[i][j]
  for i in range(M):
    if rikaido[i]<X:
      break
  else:
    costmin=min(costmin,cost)
if costmin!=float('inf'):
  print(costmin)
else:
  print(-1)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int main(){

    int a,b,c;
    cin>>a>>b>>c;

    cout<<a*b/2<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 105
using namespace std;
int n;
int a[maxn];
int myabs(int now)
{
	return now>0 ? now : -now;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int maxx=-123456789,minn=1234567890,pos1,pos2;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>maxx)
		{
			pos1=i;
			maxx=a[i];
		}
		if(a[i]<minn)
		{
			pos2=i;
			minn=a[i];
		}
	}

	printf("%d\n",2*n-1);
	if(myabs(maxx)>myabs(minn))
	{
		for(int i=1;i<=n;i++)
			printf("%d %d\n",pos1,i),a[i]+=a[pos1];
		for(int i=2;i<=n;i++)
			printf("%d %d\n",i-1,i),a[i]+=a[i-1];
	}
	else
	{
		for(int i=1;i<=n;i++)
			printf("%d %d\n",pos2,i),a[i]+=a[pos2];
		for(int i=n-1;i>=1;i--)
			printf("%d %d\n",i+1,i),a[i]+=a[i+1];
	}
//	cerr<<"its result"<<endl;
//	for(int i=1;i<=n;i++)
//		cerr<<a[i]<<" ";
//	cerr<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  int N = 0;
  cin >> N;
  int pre = -1;
  int count = 0;
  do{
    int d = N % 10;
    N /= 10;
    
    if(pre == d){ ++count; }
    else{ count = 1; }
    
    if(count >= 3){
      cout << "Yes" << endl;
      return 0;
    }
    
    pre = d;
  }while(N > 0);
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
    int n;
    double med, a;
    while (cin >> n, n != 0) {
        vector<int> s;
        int sum = 0;
        for (int i=0; i<n; ++i) {
            int tmp; cin>>tmp;
            s.push_back(tmp);
            sum += tmp;
        }
        med = (double)sum / n;
        a = 0;
        for (int i=0; i<n; ++i) {
            a += (s[i] - med) * (s[i] - med);
        }
        a = sqrt(a/n);
        cout.precision(8);
        cout << fixed << a << "\n";

        s.clear();
    }
    return 0;
}

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

using namespace std;

typedef long long int ll;

#define mod (int ) (1e9+7)



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


 
 ll ncr(ll x, ll y){
 	ll ans=1;
 	
 	y=(y > x-y? x-y: y);
 	
 	for(ll i=0; i<y; i++){
 		ans=ans*(x-i);
 		ans=ans/(i+1);
 		ans=ans%mod;
 	}
 
 	
 	return ans;
 }

ll power(ll x, ll y){
    ll ans=1;
    while(y){
        if(y&1){
            ans=ans*x;
            ans=ans%mod;
        }
        
        x=x*x;
        x=x%mod;
        y=y>>1;
    }
    
    return ans;
    
}
 
void solve(){
	
  string s; cin>>s;
  
  ll n=0;
  
  for(int i=0; i<s.size(); i++){
  	n=n+s[i]-'0';
  	n=n%9;
  }
  
  cout<<(n%9==0?"Yes":"No")<<"\n";
  
   return ;
	
}

int main(){
    ios_base::sync_with_stdio(0);
    
    cin.tie(0);
    
    int t=1,h=0; //cin>>t;
    
    
    // clock_t begin, end;
    
    // double time_spent;
    
    // begin = clock(); // Time taken till now.
    
    
    while(t--){
    
	  solve();
        
    }
   
   //end= clock(); // Total  Time taken till now.
   
   //time_spent= (end- begin) / CLOCKS_PER_SEC;
   
   //cout<<time_spent<<"\n";
	
	return 0;
}

Measured memory_bytes: 3664
using System;
using System.Linq;

namespace Computation
{
    class A_B_Problem
    {
        static void Main(string[] args)
        {
            var token = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var d = token[0] / token[1];
            var r = token[0] % token[1];
            var f = (double) token[0] / token[1];
            Console.WriteLine("{0} {1} {2:F7}", d, r ,f);
        }
    }
}

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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VC vector<char>
#define FOREACH(x,a) for(auto& (x) : (a) )
using namespace std;

int main() {
	int n;
	cin >> n;
	int a = 0, b = 1000000000;
	REP(i, n) {
		int c;
		cin >> c;
		a = max(a, c);
		b = min(b, c);
	}
	cout << a - b << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
d=[]
for i in range(n):
    ai,bi,ci=map(int,input().split())
    d.append([ai,bi,ci])

if n==1:
    print(max(d[0][0],d[0][1],d[0][2]))
    exit()
    

ap=d[0][0]
bp=d[0][1]
cp=d[0][2]

for i in range(1,n):
    a=max(bp+d[i][0],cp+d[i][0])
    b=max(ap+d[i][1],cp+d[i][1])
    c=max(ap+d[i][2],bp+d[i][2])

    ap=a
    bp=b
    cp=c
    

print(max(a,b,c))






Measured memory_bytes: 22772
using System;
using System.Collections.Generic;
 
public class Test
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int W = int.Parse(str[0]);
        int H = int.Parse(str[1]);
        int x = int.Parse(str[2]);
        int y = int.Parse(str[3]);
        int r = int.Parse(str[4]);
 
        if ( (r * 2 <= H && r * 2 <= W) &&
             (r <= H - y && r <= W - x) &&
             (r <= x && r <= y) )
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 19636
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

# mod = int(1e9+7)
mod = 998244353
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    x = n % 10
    if x==2 or x==4 or x==5 or x==7 or x==9:
        print("hon")
    elif x==0 or x==1 or x==6 or x==8:
        print("pon")
    else:
        print("bon")
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
 
string s, t;
 
int main(){
    cin >> s;
    int n = s.size();
    for(auto &i: s){
        if(t.size() && t.back() == 'S' && i == 'T'){
            t.pop_back();
            n -= 2;
        }
        else
        	t += i;
    }
  
    cout << n << '\n';
	return 0;
}

Measured memory_bytes: 776
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
#include <map>

int main(int argc, char const *argv[]) {

  int NN, MM;
  std::cin >> NN >> MM;

  int b = 1;

  int MM_cop = MM+0;

  std::map<int,int> yakus{};


  while (MM > 1) {
    int no_f = 1;
    for (size_t i = 2; i * i < MM+1; i++) {
      if (MM % i == 0) {
        MM = MM/i;
        yakus[i] += 1;
        no_f = 0;
        break;
      }
    }
    if (no_f == 1) {
      yakus[MM] += 1;
      MM = 1;
    }
  }

  // for (std::map<int,int>::iterator it=yakus.begin(); it!=yakus.end(); ++it){
  //   std::cout << it -> first <<"::" << it -> second << '\n';
  // }

  int num_comb = 1;
  for (std::map<int,int>::iterator it=yakus.begin(); it!=yakus.end(); ++it){
    num_comb *= (it-> second + 1);
  }

  // std::cout << "num_comb::"<<num_comb << '\n';

  for (size_t i = 1; i <= num_comb; i++) {
    int b_cand = 1;
    int i_cop = i + 0;
    for (std::map<int,int>::iterator it=yakus.begin(); it!=yakus.end(); ++it){
      int icc = i_cop % (it-> second + 1);
      // b_cand *= pow(it -> first, icc);
      for (size_t i = 0; i < icc; i++) {
        b_cand *= it -> first;
      }
      i_cop /= (it-> second + 1);
    }
    // std::cout << "i::"<<i << ' ';
    // std::cout << "b_cand::"<<b_cand << ' ';

    int B_cand = MM_cop / b_cand;

    // std::cout << "B_cand" <<B_cand<< '\n';
    if (B_cand >= NN) {
      if (b_cand > b) {
        b = b_cand;
      }
    }

  }



  std::cout << b << '\n';


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
/*bool isPrime(long long n) 
{ long long i;
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false;
  
    return true; 
}

long long factorial(long long n) 
{    if(n==0||n==1)
     return 1;
     else
     return n*factorial(n - 1);  
} 

long long binarySearch(long long arr[], long long l, long long r, long long x) 
{ 
    while (l <= r) { 
        long long  m = l + (r - l) / 2; 
  
        
        if (arr[m] == x) 
            return m; 
  
      
        if (arr[m] < x) 
            l = m + 1; 
  
       
        else
            r = m - 1; 
    } 
    return -1; 
} 
*/

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
   
    long long n,ac=0,wa=0,tle=0,re=0;
    cin>>n;
    while(n--)
    {string s;
     cin>>s;
     if(s=="AC")
      ac++;
     else if(s=="WA")
       wa++;
     else if(s=="TLE")
       tle++;
     else if(s=="RE")
       re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
    
    return 0;
}

Measured memory_bytes: 3656
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<queue>
#include<set>
#define FOR(i,l,r) for(int i=(l),i##R=(r);i<=i##R;i++)
#define DOR(i,r,l) for(int i=(r),i##L=(l);i>=i##L;i--)
#define loop(i,n) for(int i=0,i##R=(n);i<i##R;i++)
#define mms(a,x) memset(a,x,sizeof a)
#define pb push_back
using namespace std;
typedef long long ll;
template<typename A,typename B>inline void chkmax(A &x,const B y){if(x<y)x=y;}
template<typename A,typename B>inline void chkmin(A &x,const B y){if(x>y)x=y;}
const int N=2e5+5;
int n;
int a[N],b[N];
multiset<int>S;
multiset<int>::iterator it;
int h;
int main(){
	scanf("%d",&n);
	FOR(i,1,n)scanf("%d",&a[i]);
	FOR(i,1,n){
		if(S.empty())S.insert(a[i]);
		else {
			it=S.lower_bound(a[i]);
			if(it==S.begin())S.insert(a[i]);
			else {
				it--;
				S.erase(it);
				S.insert(a[i]);
			}
		}
	}
	printf("%d\n",S.size());
	return 0;
}

Measured memory_bytes: 5376
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func get_int(sc *bufio.Scanner) int64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return int64(i)
}

type entry struct {
	team int64
	size int64
}

func get_team(l []entry, i int64) int64 {
	ls := make([]int64, 0)
	for l[i].team != i {
		ls = append(ls, i)
		i = l[i].team
	}
	for _, v := range ls {
		l[v].team = i
	}
	return i
}

func main() {
	var n, m int64
	fmt.Scan(&n, &m)
	sc := wordScanner()
	as := make([]int64, m)
	bs := make([]int64, m)
	for i := range as {
		as[i] = get_int(sc) - 1
		bs[i] = get_int(sc) - 1
	}

	l := make([]entry, n)
	for i := range l {
		l[i].team = int64(i)
		l[i].size = 1
	}

	ans := make([]int64, m)
	ans[len(ans)-1] = n * (n - 1) / 2

	for i := len(ans) - 2; i >= 0; i-- {
		a := as[i+1]
		b := bs[i+1]
		ta := get_team(l, a)
		tb := get_team(l, b)
		if ta == tb {
			ans[i] = ans[i+1]
		} else {
			if ta < tb {
				l[tb].team = ta
				l[b].team = ta
			} else {
				l[ta].team = tb
				l[a].team = tb
			}
			sum := l[ta].size + l[tb].size
			diff := l[ta].size * l[tb].size
			ans[i] = ans[i+1] - diff
			l[a].size = sum
			l[b].size = sum
			l[ta].size = sum
			l[tb].size = sum
		}
	}

	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}


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

template<class T>bool chmin(T &a, const T &b){ return (a>b ? (a=b)||1 : 0); }


int main() {
	
	int n,k; cin >> n>>k;
	vector<int> h(n);
	for(int i=0; i<n; i++) cin >> h.at(i);
	vector<int> dp(n,(int)1e9);
	dp.at(0)=0;
	for(int i=0; i<n-1; i++){
		for(int j=1; j<=k; j++){
			if(i+j<n) chmin(dp.at(i+j), dp.at(i)+abs(h.at(i)-h.at(i+j)));
		}
	}
	cout << dp.at(n-1) << endl;
}


Measured memory_bytes: 1152
void main() {
  problem();
}

void problem() {
  auto S = scan;

  string solve() {
    return S[0..3];
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


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

int main(){
  int H,W,N;
  cin >> H >> W >> N;
  
  if(H>W){
    int i=0;
    while(H*i<N){
      i++;
    }
    cout << i << endl;
  }
  else{
    int i=0;
    while(W*i<N){
      i++;
    }
    cout << i << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  ll n;
  cin >> n;
  vector<P> votes(n);
  rep(i,n) cin >> votes[i].first >> votes[i].second;
  ll tsum, asum;
  tsum = votes[0].first;
  asum = votes[0].second;
  rep(i,n-1) {
    ll T = votes[i+1].first;
    ll A = votes[i+1].second;
    ll cnt = max(tsum/T,asum/A);
    ll t = T*cnt;
    ll a = A*cnt;
    while(t<tsum || a<asum) {
      cnt++;
      t = T*cnt;
      a = A*cnt;
    }
    tsum = t;
    asum = a;
  }
  cout << tsum + asum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

long long int i,j,ans=0;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int INF = 1<<29;
const int mod = 1000000007;

int main(){
	string s,t;
	cin>>s>>t;
	cout <<"A"<<t[0]<<"C"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 

using namespace std;

int digit(int n){
    int k = 1;
    int m = 10;

    while(n >= m){
        m = m * 10;
        k++;
    }

    return k;
}

int digitnum(int n, int k){
    while(k != 1){
        n = n / 10;
        k--;
    }

    return n % 10;
}

int main(){

    int n,k;
    cin >> n >> k;

    vector<int> d;

    rep(i,k){
        int tmp;
        cin >> tmp;
        d.pback(tmp);
    }

    while(true){

        //check
        bool check = true;
        rep(i,digit(n)){
            rep(j,k){
                if(digitnum(n, i + 1) == d[j]){
                    check = false;
                    break;
                }
            }
            if(!check) break;
        }

        if(check) break;

        n++;
    }

    cout << n << endl;



    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.math.BigInteger;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int P = sc.nextInt();
		int nume = 0;
		int numo = 0;
		BigInteger anse = new BigInteger("0");
		BigInteger anso = new BigInteger("0");
		int[] arr = new int[N];
		
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
			if (arr[i]%2 == 0)
				nume++;
			else
				numo++;
		}
		
		int i;
		long even = 1;
		
		for (i = 1; i <= nume; i++)
			even *= 2;
		
		for (i = 0; 2*i <= numo; i++)
			anse = anse.add(C(numo,2*i));
		
		for (i = 0; 2*i + 1<= numo; i++)
			anso = anso.add(C(numo,2*i+1));
		BigInteger numeven = new BigInteger(""+even);
		anse = anse.multiply(numeven);
		anso = anso.multiply(numeven);
		
		if (P == 0)
			System.out.println(anse);
		else
			System.out.println(anso);

	}
	
	
	public static BigInteger C(int N, int k) {
		BigInteger ans = new BigInteger("1");
		BigInteger Nfac = new BigInteger("1");
		BigInteger kfac = new BigInteger("1");
		BigInteger Nminuskfac = new BigInteger("1");
		for (int i = 2; i <= N; i++) {
			BigInteger a = new BigInteger(""+i);
			Nfac = Nfac.multiply(a);
		}
		
		for (int i = 2;i <= k; i++) {
			BigInteger a = new BigInteger(""+i);
			kfac = kfac.multiply(a);
		}
		
		for (int i = 2;i <= N-k; i++) {
			BigInteger a = new BigInteger(""+i);
			Nminuskfac = Nminuskfac.multiply(a);
		}
		BigInteger deno = kfac.multiply(Nminuskfac);
		ans = Nfac.divide(deno);
		return ans;
	}
}

Measured memory_bytes: 22100
def permutations(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutations(data):
                ret.append([i] + j)

        return ret
        

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

bou = [1] * N
ball = [2] * (M-1)

junretsu = permutations(bou + ball)

a, b, c, d = [], [], [], []
for i in range(Q):
    A, B, C, D = map(int, input().split())
    a.append(A)
    b.append(B)
    c.append(C)
    d.append(D)

ans = 0
for i in range(len(junretsu)):
    souwa = 0
    check = 0
    A = []
    for j in range(N+M-1):
        if junretsu[i][j] == 1:
            A.append(j - check + 1)
            check += 1
    for j in range(Q):
        if (A[b[j]-1] - A[a[j]-1]) == c[j]:
            souwa += d[j]
    
    ans = max(ans, souwa)

print(ans)

Measured memory_bytes: 40216
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> s = new List<int>();
    static double result;
static StringBuilder sb = new StringBuilder();
static int N,M,K;
    static void Main()
    {
Read4();
      double[] check=new double[N+1];
      for(int i=1;i<=N;i++){
int count=i;
        check[i]=1;
while(count<K){
  count*=2;
  check[i]/=2;
}
      }
      for(int i=1;i<=N;i++){result+=check[i]/N;}
                    Console.WriteLine(result);

    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }
 
    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
   {
       string[] tmp = Console.ReadLine().Split(' ');
       for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {

 
    }


}

Measured memory_bytes: 11616
import itertools
N = int(input())
Data = [0]*5
for _ in range(N):
    s = input()
    c = s[0]
    if c == 'M':
        Data[0] += 1
    elif c == 'A':
        Data[1] += 1
    elif c == 'R':
        Data[2] += 1
    elif c == 'C':
        Data[3] += 1
    elif c == 'H':
        Data[4] += 1
ans = 0
for data in itertools.combinations(Data,3):
    ans += data[0]*data[1]*data[2]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define N 200005
typedef long long ll;
ll n, a[N], s[N], re = 1e9;
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    s[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
    ll i, j, k, s1, s2, s3, s4, sma, smi, re=1e9;
    i = 1;
    j = 2;
    k = 3;
    s1 = a[1];
    s2 = a[2];
    s3 = a[3];
    s4 = s[n] - s1 - s2 - s3;
    sma = max({s1, s2, s3, s4});
    smi = min({s1, s2, s3, s4});
    re = sma - smi;
    while (j < n - 1) {
        while ( i < j - 1 && s1 + a[i + 1] <= s2 - a[i + 1]) {
            s1 += a[i + 1];
            s2 -= a[i + 1];
            ++i;
        }
        if (s2 - s1 > s1 + 2 * a[i + 1] - s2) {
            ++i;
            s1 += a[i];
            s2 -= a[i];
        }
        while (k < n - 1 && s3 + a[k + 1] <= s4 - a[k + 1]) {
            s3 += a[k + 1];
            s4 -= a[k + 1];
            ++k;
        }
        if (s4 - s3 > s3 + 2 * a[k + 1] - s4) {
            s3 += a[k + 1];
            s4 -= a[k + 1];
            ++k;
        }
        sma = max({s1, s2, s3, s4});
        smi = min({s1, s2, s3, s4});
        re = min(re, sma - smi);
        ++j;
        s2 += a[j];
        s3 -= a[j];
    }
    cout << re;
    return 0;
}


Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const LL MOD = 1000000007LL;
bool b[2000][2000];
bool d[2000][2000];
int L[2000];
int R[2000];
int cnt[2000];
int main() {
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		string l;
		cin >> l;
		for (int j = 0; j < W; j++) {
			if (l[j] == '.') b[i][j] = 1;
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j + 1 < W; j++) {
			d[i][j] = b[i][j] ^ b[i][j + 1];
		}
	}
	int ans = max(H, W);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j + 1 < W; j++) {
			if (i == 0 || d[i][j] == d[i - 1][j]) cnt[j]++;
			else cnt[j] = 1;
		}
		stack<int> S;
		for (int j = 0; j + 1 < W; j++) {
			while (!S.empty() && cnt[S.top()] >= cnt[j]) S.pop();
			if (S.empty()) L[j] = 0;
			else L[j] = S.top() + 1;
			S.push(j);
		}
		while (!S.empty()) S.pop();
		for (int j = W - 2; j >= 0; j--) {
			while (!S.empty() && cnt[S.top()] >= cnt[j]) S.pop();
			if (S.empty()) R[j] = W - 1;
			else R[j] = S.top();
			S.push(j);
		}
		for (int j = 0; j + 1 < W; j++) {
			ans = max(ans, cnt[j] * (R[j] - L[j] + 1));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 8064
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    string S, T;
    cin >> S >> T;
    int N = S.size();
    bool ok = false;
    for(int i = 0; i < N; i++){
        if(S == T){
             ok = true;
             break;
        }
        S = S.back() + S.substr(0, N - 1);
        
    }
    if(ok) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
string s;

int main(){
	cin>>n>>s;
	int t=0,m=0;
	for(int i=0;i<n;i++){
		t+=(s[i]=='('?1:-1);
		m=min(t,m);
	}
	for(int i=0;i<-m;i++) cout<<'(';
	cout<<s;
	for(int i=0;i<t-m;i++) cout<<')';
	cout<<endl;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
a,b,c = readInts()
ma = max(a,b,c)
sa = (ma-a) + (ma-b) + (ma-c)
if sa%2 == 0:
    print(sa//2)
else:
    print(sa//2 + 2)


Measured memory_bytes: 10308
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)

int main(void)
{
    string s;
    cin >> s;
    int c = 0;
    REP(i, 3) {
        if(s[i] == '1') c++;
    }
    cout << c << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var k int
	fmt.Scan(&k)

	q := make([]int64, 0, 100000)
	for i := 1; i < 10; i++ {
		q = append(q, int64(i))
	}

	i := 0
	for i < len(q) {
		if i+1 == k {
			break
		}
		x := q[i]
		i++
		m := x % 10
		n := x * 10
		if m != 0 {
			q = append(q, n+m-1)
		}
		q = append(q, n+m)
		if x%10 != 9 {
			q = append(q, n+m+1)
		}
	}
	fmt.Println(q[i])
}


Measured memory_bytes: 10752
#[allow(unused_imports)]
use std::cmp;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let m: usize = sc.read();
    let k: usize = sc.read();
    let a = sc.read_vec::<usize>(n);
    let b = sc.read_vec::<usize>(m);

    let mut sum_a = 0;
    let mut max_num_a = 0;
    for i in 0..n {
        if sum_a + a[i] > k {
            break;
        } else {
            sum_a += a[i];
            max_num_a += 1;
        }
    }

    let mut ans = max_num_a;
    let mut sum_b = 0;
    let mut num_b = 0;
    for num_a in (0..=max_num_a).rev() {
        while num_b < m && sum_a + sum_b + b[num_b] <= k {
            sum_b += b[num_b];
            num_b += 1;
        }
        ans = cmp::max(ans, num_a + num_b);
        if num_a > 0 {
            sum_a -= a[num_a - 1];
        }
    }
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 3992
#include <stdio.h>
#include <math.h>

int main(){
	int a, b, c[100], i, j, ans[100], d, x, max, k;
	while(scanf("%d %d", &a, &b) != 0){
		if(a == 0 && b == 0) break;
		ans[0] = 0;
		for(i = 0; i < b; i++) c[i] = 0;
		for(i = 0; i < a; i++){
			for(j = 0; j < b; j++){
				scanf("%d", &d);
				if(d == 1) c[j]++;
			}
		}
		for(i = 0; i < b; i++){
			max = 0;
			for(k = 0; k < b; k++){
				if(max < c[k]){
					x = 0;
					for(j = 0; j < i; j++) {
						if(k + 1 == ans[j]){
							x++;
							break;
						}
					}
					if(x == 0){
						max = c[k];
						ans[i] = k + 1;
					}
				}
			}
		}
		for(i = 0; i < b - 1; i++) printf("%d ", ans[i]);
		printf("%d\n", ans[b - 1]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

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; }
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())

int L[100010] = { 0 };
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin >> n >> m;
    m = m + n * 3;
    cout << m/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{
    int H, W;
    while (cin >> H >> W,H||W)
    {
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }

return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s;
        if(!(cin >> s))
            return 0;

        int n = s.size();
        s = '+' + s.substr(0, n-1);

        int i = 0;
        int a = 0;
        bool error = false;
        while(i < n){
            int j = i+1;
            int b = 0;
            while(j < n && isdigit(s[j])){
                b *= 10;
                b += s[j] - '0';
                ++ j;
            }
            if(j - i > 5)
                error = true;

            if(s[i] == '+')
                a += b;
            else if(s[i] == '-')
                a -= b;
            else
                a *= b;
            if(a < 0 || a > 9999)
                error = true;

            i = j;
        }

        if(error)
            cout << "E" << endl;
        else
            cout << a << endl;
    }
}

Measured memory_bytes: 1196
import sys

def chk1(t, x, y):
    return t % 2 == (x + y) % 2
def chk2(t, x, y):
    return t >= abs(x) + abs(y)
def chk(t, x, y):
    return chk1(t, x, y) and chk2(t, x, y)

N = int(input())
T = [0] * (N + 1)
X = [0] * (N + 1)
Y = [0] * (N + 1)
for i in range(1, N + 1):
    T[i], X[i], Y[i] = map(int, input().split())
for i in range(1, N + 1):
    dt, dx, dy = T[i] - T[i - 1], X[i] - X[i - 1], Y[i] - Y[i - 1]
    if not chk(dt, dx, dy):
        print('No')
        sys.exit(0)
print('Yes')


Measured memory_bytes: 11636
x, n = map(int, input().split())
lst = []
if n > 0:
  lst = list(map(int, input().split()))
a = 100
b = 0

for i in range(0, 102):
  if i in lst:
    continue

  if a > abs(x-i):
    a = abs(x-i)
    b = i

print(b)

Measured memory_bytes: 8832
n = int(input())
maps = []
for i in range(n-1):
    maps.append(list(map(int, input().split())))

import math
result = []
for i, item in enumerate(maps):
    cost = item[0] + item[1]
    for j in range(i+1, n-1):
        next_cost = maps[j][1]
        if cost <= next_cost:
            cost = next_cost + maps[j][0]
        else:
            gap = cost - next_cost
            gap = math.ceil(gap/maps[j][2])
            cost = next_cost + maps[j][2]*gap + maps[j][0]
    result.append(cost)

for i in result:
    print(i , flush=True)
print(0 , flush=True)


Measured memory_bytes: 74432
from heapq import heapify, heappop, heappush

heap=[]
while True:
    tmp = input()
    if tmp.startswith("end"):
        break
    elif tmp.startswith("insert"):
        k=int(tmp.split()[1])
        heappush(heap, -k)  # 最大値を取り出すために、初めからマイナスで入れておく
    elif tmp.startswith("extract"):
        print(heappop(heap)*(-1)) # 最大のキー（最大値）を取り出す




Measured memory_bytes: 45308
import java.util.Scanner;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while(true)
		{
			int m, f, r;
			m = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			if(m == -1 && f == -1 && r == -1)
			{
				break;
			}
			if(m == -1 || f == -1)
			{
				System.out.println("F");
			}
			else if(m + f >= 80)
			{
				System.out.println("A");
			}
			else if(m + f >= 65)
			{
				System.out.println("B");
			}
			else if(m + f >= 50)
			{
				System.out.println("C");
			}
			else if(m + f >= 30)
			{
				if(r >= 50)
				{
					System.out.println("C");
				}
				else
				{
					System.out.println("D");
				}
			}
			else
			{
				System.out.println("F");
			}
		}
	}
}


Measured memory_bytes: 26128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

int main() {
    string s; cin >> s;
    int n = s.length();
    ll ans = 0;
    ll b = 0;
    REP(i,n) {
        if(s[i]=='B') b++;
        else ans += b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
Scanf.scanf "%d %d" (fun n k ->
    let arr = Array.init n (fun _ -> Scanf.scanf " %d" (fun p -> p)) in
    let sum =
        let rec loop i acc =
            if i = k then acc else loop (i + 1) (acc + arr.(i))
        in
        loop 0 0
    in
    let rec loop i cur mx =
        if i = n then mx else
            let cur = cur + arr.(i) - arr.(i - k) in
            loop (i + 1) cur (max mx cur)
    in
    let mx = loop k sum sum in
    let ex = float (mx + k) /. 2. in
    Printf.printf "%f\n" ex
)

Measured memory_bytes: 6016
#include<cstdio>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define N 100001
const int mod=1e9+7;
int a[N],inv[N];
int Pow(int p,int q)
{
    int s=1;
    for(;q;q>>=1,p=1LL*p*p%mod)
        if(q&1) s=1LL*s*p%mod;
    return s;
}
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;++i) cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i) inv[i]=Pow(i,mod-2); 
    long long p=1,ans=a[k];
    for(int i=k+1;i<=n;++i)
    {
         p=p*(i-1)%mod;
         p=p*inv[i-k]%mod;
         ans=(ans+a[i]*p%mod)%mod;
    }
    ans-=a[n-k+1];
    p=1;
    for(int i=k+1;i<=n;++i)
    {
         p=p*(i-1)%mod;
         p=p*inv[i-k]%mod;
         ans=(ans-a[n-i+1]*p%mod)%mod;
    }
    if(ans<0) ans+=mod;
    cout<<ans;
}

Measured memory_bytes: 1024
#include<deque>
#include<iostream>
#include<cstdio>
#include<algorithm>
#define F first
#define S second
using namespace std;
 
bool check(deque<int>& deq,int counter)
{
  for(int i=deq.size()-1;i>=0;i--)
        {       
          if(deq[i] != counter)
        return false;
          else     
        counter--;
        }
  return counter == 0;
}
 
int main()
{
  int N;
  while(true)
    {
      cin >> N;
      if(!N)
    break;
      deque<int> deq;
      for(int i=0;i<N;i++)
    {
      int input;
      cin >> input;
      deq.push_back(input);
    }
 
      if(check(deq,N))
    {
      cout << 0 << endl;
      continue;
    }     
 
      bool fin = true;
 
      for(int m = 1;m <= 10000;m++)
    {/*1*/
      //cout << "m = " << m << endl;
      fin = true;
      int counter = 0;
      deque<int> n_deq;
      for(int i=0;i<deq.size();i++)
        {
          if(deq[i] >= 1)
        {
          counter++;
          deq[i]--;
        }
          if(deq[i] >= 1)
        {
          n_deq.push_back(deq[i]);
        }
        }
      
      deq = n_deq;
      deq.push_back(counter);
      if(check(deq,counter))
        {
          cout << m << endl;
          fin = false;
          break;
        } 
    }/*1*/
      if(fin)
    cout << -1 << endl;
      
    }
  return 0;
}

Measured memory_bytes: 1236
def div2(N):
  if(N % 2 != 0):
    return 0
  else:
    i = 0
    while N % 2 == 0:
      N/= 2
      i+= 1
    return i
  
N = int(input())
lista = list(map(int, input().split()))

ans = 0
for x in lista:
  ans+= div2(x)
  
print(ans)  

Measured memory_bytes: 4148
import sys
sys.setrecursionlimit(10**7)

N = int(input())
u = []
v = []
w = []
for _ in range(N-1):
	tu, tv, tw = map(int ,input().split())
	u.append(tu)
	v.append(tv)
	w.append(tw)

inf = float("inf")
E = [[] for _ in range(N+1)]
for i in range(N-1):
	if w[i] % 2 == 0:
		E[u[i]].append(v[i])
		E[v[i]].append(u[i])
	else:
		E[u[i]].append(v[i] * (-1))
		E[v[i]].append(u[i] * (-1))

flg = [inf for _ in range(N+1)]
flg[0] = 0

def dfs(q):
	cp = q.pop()
	next = E[cp]

	for np in next:
		if flg[abs(np)] == inf:
			if np > 0:
				flg[abs(np)] = flg[cp]
			else:
				flg[abs(np)] = flg[cp] * (-1)
			q.append(abs(np))

	if len(q) == 0:
		return

	dfs(q)

flg[1] = 1
dfs([1])

for i in range(1,N+1):
	if flg[i] == 1:
		print(1)
	else:
		print(0)


Measured memory_bytes: 115104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
int main(void)
{
    int N;
    cin>>N;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>> A[i];
        }
int count=0;
int count2=0;
 
    for(int i=0;i<N;i++){
        if(A[i]%2==0){
            count2++;
                if (A[i]%3==0||A[i]%5==0){
                    count++;
                }
            
            
        }
 
    }
  
if(count==count2){
    cout <<"APPROVED"<<endl;
}
else cout<<"DENIED"<<endl;
    return 0;
    return 0;
}
 

Measured memory_bytes: 256
#include <stdio.h>

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

int main(void)
{
    int w, h, c;
    int d;

    scanf("%d %d %d", &w, &h, &c);
    d = gcd(w, h);
    w /= d;
    h /= d;
    printf("%d\n", w * h * c);

    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int n, q, t;
    string name;
    // 標準ライブラリから、queueを使用
    queue<pair<string, int> > Q; // プロセスのキュー

    cin >> n >> q;

    // 全てのプロセスをキューに順番に追加する
    for (int i=0; i<n; i++){
        cin >> name >> t;
        Q.push(make_pair(name, t));
    }
    
    pair<string, int> u;
    int elaps = 0, a;

    // シミュレーション
    while (!Q.empty()){
        u = Q.front(); Q.pop();
        a = min(u.second, q); // qまたは必要な時間u.tだけ処理を行う
        u.second -= a; // 残りの必要時間を計算
        elaps += a; // 経過時間を加算
        if (u.second > 0){
            Q.push(u); // 処理が完了していなければキューに追加
        }
        else {
            cout << u.first << " " << elaps << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 6332
def nishin(n):
  return str(bin(n)[2:])[::-1]
N=int(input())
L=list(map(int,input().split()))
mod=1000000007
ans=sum(L)*(N-1)
c=[0]*61
for i in L:
  i=nishin(i)
  for j in range(len(i)):
    if i[j]=="1":
      c[j]+=1
for i in range(61):
  ans-=(pow(2,i,mod)*c[i]*(c[i]-1))%mod
print(ans%mod)

Measured memory_bytes: 124620
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX_N 100000

int main() {
    int N, A[MAX_N], B[MAX_N], C[MAX_N];
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    for (int i = 0; i < N; i++) cin >> C[i];

    sort(A, A + N);
    sort(B, B + N);
    sort(C, C + N);

    long long num_altar = 0;
    for (int i = 0; i < N; i++) {
        int num_upper = lower_bound(A, A + N, B[i]) - A;
        int num_lower = N - (lower_bound(C, C + N, B[i] + 1) - C);
        num_altar += 1LL * num_upper * num_lower;
    }
    cout << num_altar << endl;
    return 0;
}

Measured memory_bytes: 1408
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextInt() }

  println(abc088b(n, a))
}

private fun abc088b(n: Int, a: List<Int>): Int {
  val sorted = a.sorted().reversed()

  var alice = 0
  var bob = 0
  for (i in 0 until n) {
    if (i % 2 == 0) {
      alice += sorted.get(i)
    } else {
      bob += sorted.get(i)
    }
  }

  return alice - bob
}


Measured memory_bytes: 34004
#include <bits/stdc++.h>
	#define endl "\n"
	#define ll long long int
	#define vi vector<ll>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<ll,ll>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y) 
	#define mem(a,val) memset(a,val,sizeof(a))
	#define pb push_back
	#define f first
	#define s second
	
	using namespace std;
	
	signed main()
	{

	std::ios::sync_with_stdio(false);
	
	

	int r;
	cin>>r;
    ll p = r*r;
	cout<<p;
	return 0;
	}


Measured memory_bytes: 256
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())

adj = [set() for _ in range(N)] #adj[i] = (i_adj, 距離0or1)
for _ in range(N-1):
  u, v, w = mi()
  #0スタートに
  u -= 1
  v -= 1
  adj[u].add((v, w%2))
  adj[v].add((u, w%2))

from collections import deque
q = deque([])

seen = [-1] * N #色を兼ねる。0or1

#とりあえずノード0から探索をスタートすることにする
#0の距離は0としておく
q.append(0)
seen[0] = 0


while q:
  nownode = q.popleft()
  nowcolor = seen[nownode]

  #今のノードから隣接しているものを探索
  for adjidx, w in adj[nownode]:
    if seen[adjidx]==-1:
      q.append(adjidx)
      seen[adjidx]=(nowcolor+w)%2

for color in seen:
  print(color)



Measured memory_bytes: 80668
#include <bits/stdc++.h>
using namespace std;
string S;
int dp[100100];
 
int ask(int x){
	if (x == -1)return 1;
  	if (dp[x] != -1)return dp[x];
  	int as = 0;
  	if (x >= 4){
    	if (S[x] == 'm' && S[x-1] == 'a' && S[x-2] == 'e' && S[x-3] == 'r' && S[x-4] == 'd')as = as|ask(x-5);
      	if (S[x] == 'e' && S[x-1] == 's' && S[x-2] == 'a' && S[x-3] == 'r' && S[x-4] == 'e')as = as|ask(x-5);
    }
  	if (x >= 6){
    	if (S[x] == 'r' && S[x-1] == 'e' && S[x-2] == 'm' && S[x-3] == 'a' && S[x-4] == 'e' && S[x-5] == 'r' && S[x-6] == 'd')as = as|ask(x-7);
    }
    if (x >= 5 && S[x] == 'r' && S[x-1] == 'e' && S[x-2] == 's' && S[x-3] == 'a' && S[x-4] == 'r' && S[x-5] == 'e')as = as|ask(x-6);
	return as;
}
 
int main(){
  	memset(dp,-1,sizeof(dp));
	cin>>S;
 	if (ask(S.size() - 1))cout<<"YES";
 	else cout<<"NO";
}

Measured memory_bytes: 1664