akhauriyash/Code-Regression huggingface dataset:
import sys


def gcd(a, b):
    return gcd(b, a % b) if a % b else b


def lcm(a, b):
    return a * b / gcd(a, b)

for line in sys.stdin:
    data = map(int, line.split())
    a, b, c, d, e, f = data
    if a == 0:
        y = c * 1.0 / b
        x = (f - e * y) * 1.0 / d
        print "%.3f %.3f" % (round(x, 4), round(y, 4))
        continue
    if b == 0:
        x = c * 1.0 / a
        y = (f - d * x) * 1.0 / e
        print "%.3f %.3f" % (round(x, 4), round(y, 4))
        continue
    if d == 0:
        y = f * 1.0 / e
        x = (c - b * y) * 1.0 / a
        print "%.3f %.3f" % (round(x, 4), round(y, 4))
        continue
    if e == 0:
        x = f * 1.0 / d
        y = (c - a * x) * 1.0 / b
        print "%.3f %.3f" % (round(x, 4), round(y, 4))
        continue

    ix = lcm(a, d) / a
    jx = lcm(a, d) / d
    iy = lcm(b, e) / b
    jy = lcm(b, e) / e
    x = (c*1.0*iy - f*jy) / (a*iy - d*jy)
    y = (c*1.0*ix - f*jx) / (b*ix - e*jx)
    print "%.3f %.3f" % (round(x, 4), round(y, 4))

Measured memory_bytes: 4304
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n;
string s;

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

    cin >> n >> s;
    int ans = 1, cnt = 0;
    rep(i, s.size())
    {
        if (s[i] == 'W')
        {
            if (cnt % 2 == 0)
            {
                if (cnt == 0)
                {
                    cout << 0 << endl;
                    return 0;
                }
                (ans *= cnt) %= mod;
                cnt--;
            }
            else
            {
                cnt++;
            }
        }
        else
        {
            if (cnt % 2 == 0)
            {
                cnt++;
            }
            else
            {
                if (cnt == 0)
                {
                    cout << 0 << endl;
                    return 0;
                }
                (ans *= cnt) %= mod;
                cnt--;
            }
        }
    }
    Rep(i, 1, n + 1) ans = (ans * i) % mod;
    cout << (cnt == 0 ? ans : 0) << endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;
        vector<int> v(n);
        for(int i=0;i<n;i++)
            cin >> v[i];
        sort(v.begin(),v.end());
         int sum = 0;
        for(int i=0;i<n-k;i++)
            sum += v[i];
        cout <<sum << '\n';
    }
}


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

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if(s[i] == '.') {
			bool l = true;
			for(int j = i - 1; j >= 0; --j) {
				if(s[j] == 'W') continue;
				if(s[j] == 'B') l = false;
				if(s[j] == '.') break;
			}
			bool r = true;
			for(int j = i + 1; j < n; ++j) {
				if(s[j] == 'W') continue;
				if(s[j] == 'B') r = false;
				if(s[j] == '.') break;
			}
			if(not (l or r)) continue;
			{
				int cnt = 0;
				for(int j = i - 1; j >= 0; --j) {
					if(s[j] == '.') break;
					if(s[j] == 'B') ++cnt;
					if(s[j] == 'W') {
						ans = max(ans, cnt);
						break;
					}
				}
			}
			{
				int cnt = 0;
				for(int j = i + 1; j < n; ++j) {
					if(s[j] == '.') break;
					if(s[j] == 'B') ++cnt;
					if(s[j] == 'W') {
						ans = max(ans, cnt);
						break;
					}
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3212
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N,M,K = map(int,input().split(" "))

tureList = []

for i in range(N+1):
	for j in range(M+1):
		tureList.append((i*M) + (j*N) - 2*(i*j))

if K in tureList:
	print("Yes")

else:
	print("No")

Measured memory_bytes: 42684
import java.util.Scanner;
public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int S [] = new int [m+1]; //S[n] are possible coin choices
        for (int i=1; i<m+1; i++) {
        	S[i] = sc.nextInt();
        }
		int count [] = new int [n+1]; //optimized count
		for (int i=1; i<=n; i++){ //iterate until the goal value n
			int min = 50000;
			for(int j=1; j<=m; j++) { //for every "goal value" i, minimize the coin number
                if(i-S[j] >= 0)
                	if (count[i-S[j]] < min) min = count[i-S[j]];
            }
            count[i] = min + 1;
        }
		System.out.println(count[n]);
	}
}

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

int main() {
  int n, count;
  cin >> n;
  count = 0;
  
  vector<int> p(n);
  vector<int> p_s(n);
  for(int i=0; i<n; i++) {
    cin >> p.at(i);
    p_s.at(i) = p.at(i);
  }
  
  sort(p_s.begin(), p_s.end());
  for (int i=0; i<n; i++) {
  	if (p.at(i)!=p_s.at(i)) {
    	count++;
    }
  }
  
  if (count==2 || count==0) {
  	cout << "YES" << endl;
    return 0;
  }
  
  cout << "NO" << endl;
  return 0;
  
}

Measured memory_bytes: 256
// AtCoder Regular Contest 066
// E - Addition and Subtraction Hard

#include <cstdio>
#include <cmath>
#include <algorithm>
#define MAX_N 100000
#define INF ((ll)1e18)
using namespace std;
typedef long long int ll;


int N;
ll dp[MAX_N][3];
ll ans;

int main() {

  ll a;
  int op;
  char c;

  scanf("%d", &N);
  scanf("%lld", &a);
  dp[0][0] = a;
  dp[0][1] = dp[0][2] = -INF;
  for (int i = 1; i < N; i++) {
    scanf(" %c %lld", &c, &a);
    op = (c == '-') ? 1 : 0;
    for (int j = 0; j <= 2; j++) {
      dp[i][j] = -INF;
      for (int k = j; k <= 2; k++) {
        dp[i][j] = max(dp[i][j], dp[i - 1][k] + (ll)pow(-1, k + op) * a);
      }
      if (op == 1 && j > 0) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + (ll)pow(-1, j) * a);
      }
    }
  }

  ans = 0;
  for (int j = 0; j <= 2; j++) {
    ans = max(ans, dp[N - 1][j]);
  }

  printf("%lld\n", ans);

  return 0;

}




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

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
  int H, i, A[MAX + 1];  // 1-オリジンのため +1 する

  cin >> H;
  for ( i = 1; i <= H; i++ ) cin >> A[i];

  for ( i = 1; i <= H; i++ ) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if ( parent(i) >= 1 ) cout << "parent key = " << A[parent(i)] << ", ";
    if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
    if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>
int main(void)
{
	int n,a[200],b[200],c[200],x,y,z,g,i,j;
	scanf("%d", &n);
	for(i=0; i<n; i++)
	scanf("%d %d %d", &a[i], &b[i], &c[i]);
	for(i=0; i<n; i++)
	{
		x=a[i];
		y=b[i];
		z=c[i];
		for(j=0; j<n; j++)
		{
			if(i!=j)
			{
				if(a[i]==a[j])
				x=0;
				if(b[i]==b[j])
				y=0;
				if(c[i]==c[j])
				z=0;
			}
		}
		g=x+y+z;
		printf("%d\n", g);
	}
	
	return 0;
}


Measured memory_bytes: 2064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0083
{
    public class Program

    {
        public static void Main(string[] args)
        {
            string[] Eras = new string[] { "", "meiji", "taisho", "showa", "heisei" };


            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;

                int[] items = Array.ConvertAll(line.Trim().Split(' '), e => int.Parse(e));

                System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("ja-JP", false);
                ci.DateTimeFormat.Calendar = new System.Globalization.JapaneseCalendar();
                DateTime date = new DateTime(items[0], items[1], items[2]);

                if (date < new DateTime(1868, 9, 8))
                {
                    Console.WriteLine("pre-meiji");
                }
                else
                {
                    Console.WriteLine("{0} {1} {2} {3}",
                        Eras[ci.DateTimeFormat.Calendar.GetEra(date)]
                        , ci.DateTimeFormat.Calendar.GetYear(date)
                        , ci.DateTimeFormat.Calendar.GetMonth(date)
                        , ci.DateTimeFormat.Calendar.GetDayOfMonth(date)
                        );
                }
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



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

int main()
{
    int N,T,ans,i,j,h=0;
    cin>>N>>T;
    int c[N+1],t[N+1];
   for(i=0;i<N;i++)
   {
        cin>>c[i];
        cin>>t[i];
   }
   j=0;
   for(i=0;i<N;i++)
   {
       if(c[i]<=c[j] && t[i]<=T)
       {
           j=i;
           h=1;
       }
   }
   if(h==0) cout<<"TLE"<<endl;
   else cout<<c[j]<<endl;
   return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <map>

using namespace std;

typedef long long LL;
#define maxn 200000


int main()
{
	//freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);

	int N,K;
	scanf("%d %d", &N, &K);

	int u = 1 << (N+1);
	int ans = -1;
	for (int i = 0; i < u; i++) {
		int value = 1;
		int j = i;
		for (int n = 0; n < N; n++) {
			if (j%2)
				value *= 2;
			else
				value += K;

			j /= 2;
		}

		if (ans == -1 || ans > value)
			ans = value;
	}

	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
  int H,W,K,i,j,bit_h,bit_w,count,ans;
  char c[7][7];
  scanf("%d %d %d",&H,&W,&K);
  for(i=0;i<H;i++){
      scanf("%s",c[i]);
  }
  ans = 0;
  for(bit_h=0;bit_h<(1<<H);bit_h++){
    for(bit_w=0;bit_w<(1<<W);bit_w++){
      count = 0;
      for(i=0;i<H;i++){
        for(j=0;j<W;j++){
          if(((bit_h >> i) & 1) && ((bit_w >> j) & 1) == 0 && (c[i][j] == '#')){
            count++;
          }
        }
      }
      if(count == K){
        ans++;
      }
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<algorithm>
#include<climits>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
ll a[200010];
ll s[200010]; //s[i+1]:=a[0]~a[i]までの和
int n;

void acc_sum(){//累積和
  s[0]=0;
  rep1(i,n){
    s[i]=s[i-1]+a[i-1];
  }
}
ll sec_sum(int l,int r){//a[l]~a[r]の区間和
  acc_sum();
  return s[r+1]-s[l];
}
int main(){
  scan(n);
  rep(i,n){
    scan(a[i]);
  }
  acc_sum();
  map<ll,ll> mi;
  rep(i,n+1){
    mi[s[i]]++;
  }
  ll sum=0;
  for(auto ite=mi.begin();ite!=mi.end();ite++){
    ll t=ite->second;
    //   prin2(ite->first,t);
    if(t>=2){
      sum+=t*(t-1)/2;
    }
  }
  prin(sum);
    
  
  return 0;
}


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

#define ff                   first
#define ss                   second
#define ll                   long long int
#define pii                  pair<int,int>
#define pb                   push_back
#define rep(i,a,b)           for(int i=a;i<b;i++)
#define t(x)                 int t; cin>>t; while(t--)
#define vi                   vector<int>
#define mii                  map<int,int>
#define min3(a, b, c)        min(min(a, b), c)
#define min4(a, b, c, d)     min(min(a, b), min(c, d))
#define max3(a, b, c)        max(max(a, b), c)
#define max4(a, b, c, d)     max(max(a, b), max(c, d))
#define ps(x,y)              fixed<<setprecision(y)<<x
#define setbits(x)           __builtin_popcountll(x)
#define zrobits(x)           __builtin_ctzll(x)
#define all(x)               x.begin(),x.end()
#define FIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                      rng(chrono::steady_clock::now().time_since_epoch().count());

ll w, h, n;

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n % 2 == 0 || n % 3 == 0) return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}


int main()
{
    FIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll n;
    cin >> n;
    ll x[n];
    ll y[n];
    ll sum[n];
    ll summ[n];
    rep(i, 0, n)
    {
        cin >> x[i] >> y[i];
        sum[i] = x[i] + y[i];
        summ[i] = x[i] - y[i];
    }
    sort(sum, sum + n);
    sort(summ, summ + n);

    cout << max((sum[n - 1] - sum[0]), (summ[n - 1] - summ[0])) << endl;


}

Measured memory_bytes: 9904
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    c = Counter(S)
    if len(c) != 2:
        return 0
    return min(c.values()) * 2


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5740
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nkq = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            if (nkq[1] > nkq[2])
            {
                for (var i = 0; i < nkq[0]; i++)
                {
                    Console.WriteLine("Yes");
                }
                return;
            }

            var points = new int[nkq[0]];
            for (var i = 0; i < nkq[2]; i++)
            {
                var a = int.Parse(Console.ReadLine());
                points[a - 1]++;
            }

            for (var i = 0; i < points.Length; i++)
            {
                Console.WriteLine(points[i] > nkq[2] - nkq[1] ? "Yes" : "No");
            }
        }
    }
}


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

int main()
{
	int n;
	bool f = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;

		if (a % 2 == 1)
			f = 1;
	}
	
	if (f)
		cout << "first" << endl;
	else
		cout << "second" << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

breakFlg = False
for ans in range(1,32):
    for i,a in enumerate(A):
        if a%2:
            ans -=1
            breakFlg = True
            break
        else:
            A[i] //= 2
    if breakFlg:
        break
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, e, f, h, k, n, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> a >> b >> c >> e >> f;
  vlli d = {a, b, c, e, f};
  rep(i, 0, 5)
  {
    if (d[i] == 0)
    {
      cout << i + 1 << endl;
      return 0;
    }
  }
}

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

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    if (n%x == 0) cout << n/x * t << endl;
    else cout << (n/x + 1) * t << endl;
    return 0;
}


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

namespace yukicode001
{
    class Program
    {
        static void Main()
        {
            string word = Console.ReadLine();

            word = word.Replace(',', ' ');
            Console.WriteLine(word);
        }
    }
}


Measured memory_bytes: 2648
def main():
    from itertools import tee

    S = input()
    it1, it2 = tee(iter(S), 2)
    next(it2)

    ans = 0
    for c1, c2 in zip(it1, it2):
        if c1 != c2: ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
#define MOD 1000000007
using namespace std;
using ll=int64_t;
using pii=pair<int,int>;
using vi=vector<int>;
using VI=vector<ll>;
using vis=vector<string>;
using vvi=vector<vi>;
//最大公約数
int gcd(int a,int b){
    if(a%b==0)
    return b;
    return gcd(b,a%b);
}
//最小公倍数
int lcm(int a,int b){
   return a*b/gcd(a,b);
}
bool prime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0)
        return false;
    }
    return true;
}
int main(){
    string t;
    cin>>t;
    for(int i=0;t.size()>i;++i){
        if(t.at(i)=='?')
        t.at(i)='D';
    }
    cout<<t<<endl;
}

Measured memory_bytes: 3692
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
old = -1
for i in range(N):
  ans += B[A[i]-1]
  if old == A[i]-1:
    ans += C[old-1]
  old = A[i]
print(ans)

Measured memory_bytes: 3064
from heapq import heappush, heappop

T = int(input())

for i in range(T):
    N, A, B, C, D = map(int, input().split())
    h = [(0, N)]
    used = set()
    while h:
        cost, v = heappop(h)

        if v in used:
            continue

        if v == 1:
            print(cost + D)
            break

        used.add(v)

        d, m = divmod(v, 5)
        if d > 0:
            heappush(h, (cost + m * D + C, d))
        if m > 0:
            heappush(h, (cost + (5-m) * D + C, d+1))

        d, m = divmod(v, 3)
        if d > 0:
            heappush(h, (cost + m * D + B, d))
        if m > 0:
            heappush(h, (cost + (3-m) * D + B, d+1))

        d, m = divmod(v, 2)
        if d > 0:
            heappush(h, (cost + m * D + A, d))
        if m > 0:
            heappush(h, (cost + (2-m) * D + A, d+1))

        heappush(h, (cost + (v-1) * D, 1))


Measured memory_bytes: 93668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  	
	ll n;
  	int k;
  	cin >> n >> k ;
  	ll ans=0;
  	if(n==1){cout << 1 <<endl;return 0;}
  	while(n>0){n/=k; ans++;}
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


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

    int n; cin>>n;
    pair<int,int> a[n];
    
    rep(i,n){
        int b; cin>>b;
        a[i] = {b, i};
    }
    sort(a, a+n);

    rep(i,n) cout << a[i].second+1 << " ";
    return 0;
}

Measured memory_bytes: 1664
z=chomp(readline())
n=length(z)
x=ones(Int,n)
s,t=copy(x),copy(x)
x=[parse(Int,y)for y=z]
for i=1:n
s[i]=d=i%2
t[i]=1-d
end
min(sum.(abs.([s-x,t-x]))...)|>print

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

int main(){
  double W,H,x,y;
  cin>>W;
  cin>>H;
  cin>>x;
  cin>>y;
  int kotae=0;
  if(H*x==W*y && H*x+W*y==H*W){
     kotae++;
  }
  cout << fixed << setprecision(6);
  cout<<W*H/2<<" "<<kotae<<endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    long long a, b;

    cin >> a >> b;

    if(a > 0){
        cout << "Positive" << endl;
    }

    else if(a<=0 && 0<=b){
        cout << "Zero" << endl;
    }

    else{
        if((b-a+1)%2==0){
            cout << "Positive" << endl;
        }
        else{
            cout << "Negative" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int main() {
    using namespace std;

    int X, Y, Z;
    cin >> X >> Y >> Z;

    int count = 0;
    X -= Z;
    while (Y + Z <= X) {
        X -= Y + Z;
        count++;
    }

    cout << count << endl;

    return 0;
}

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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

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

    ll ans = 0;
    REP2(i, 1, N-1) {
        ans += i;
    }
    cout << ans << endl;
}


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

int x[51];
int main(){
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    x[a]++; x[b]++;
  }
  for (int i = 1; i <= n; i++) {
    printf("%d\n", x[i]);
  }
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val first = readLine()?.toInt() ?: return
    val second = readLine()?.split(" ")?.map(String::toInt)?.toIntArray() ?: return
    var count = 0;
    (1..first).forEach {
        count += if (second[it - 1] % 2 == 1 && it % 2 == 1) 1 else 0
    }
  	println(count)
}

Measured memory_bytes: 36568
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            String s = reader.readLine();

            s = s.replace(" ", "");

            int x = Integer.parseInt(s);

            System.out.println(
                x % 4 == 0 ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"

const int mod = 1e9+7;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

void work(int n, vector<int> &v) {
    for(int i=2; i*i<=n; i++) {
        if(n % i == 0) {
            v.push_back(i);
            if(n/i != i) v.push_back(n/i);
        }
    }
}

void solve() { 
   int n; cin >> n;
   if(n==2) {
       cout << 1 << endl;
       return;
   }
   vector<int> fac, fac1;
   work(n, fac);
   work(n-1, fac1);
   int ans = fac1.size();
   for(int x : fac) {
       int nn = n;
       while(nn % x == 0) nn /= x;
       if((nn - 1) % x == 0) ans++;
   }
   ans += 2;
   cout << ans << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;

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

Measured memory_bytes: 384
// Link: https://atcoder.jp/contests/abc147/tasks/abc147_b

#include <iostream>
#include <string>

using namespace std;

int main() {
    // INPUT
    string word;                                        // inputting string
    int count;                                          // counting how many letter that are different
    int len;                                            // length of word

    // INPUT
    cin>>word;

    // PROCESS
    count = 0;
    len = word.length();

    if (len % 2 == 0) {
        for (int i = 0; i <= (len/2)-1; i++) {
            if (word[i] != word[len-i-1]) {
                count++;
            }
        }
    } else {
        for (int i = 0; i <= len/2; i++) {
            if (word[i] != word[len-i-1]) {
                count++;
            }
        }
    }

    // OUTPUT
    cout<<count<<endl;

    return 0;
}

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll w,h; cin>>w>>h;
  vector<ll> p(w);
  vector<ll> q(h);
  rep(i, w) cin>>p[i];
  rep(i, h) cin>>q[i];

  vector<pair<ll, ll>> g;
  rep(i, w) g.push_back(make_pair(p[i], 0));
  rep(i, h) g.push_back(make_pair(q[i], 1));
  sort(g.begin(),g.end());

  w++; h++;
  ll ans = 0;
  for (auto x:g) {
    ll v = x.first;
    ll u = x.second;
    if (u == 0) {
      ans += v*h;
      w--;
    } else {
      ans += v*w;
      h--;
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
    int n, l[105], max = 0, idx, sum = 0;
    cin >> n;
    for(int i=0; i<n; ++i){
        cin >> l[i];
        if(l[i]>max){
            max = l[i];
            idx = i;
        }
    }
    for(int j=0; j<n; ++j){
        if(j != idx)
            sum +=l[j];
    }
    if(max<sum)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int dp[1000 + 1][(1 << 12)];

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

  vector<int> a(m), c(m, 0);
  rep(i, m) {
    int b;
    cin >> a[i] >> b;
    rep(j, b) {
      int _c;
      cin >> _c;
      c[i] |= (1 << (_c - 1));
    }
  }

  rep(i, m + 1) rep(j, (1 << n)) dp[i][j] = INF;
  dp[0][0] = 0;

  rep(i, m) rep(j, (1 << n)) if (dp[i][j] != INF) {
    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
  }

  int ans = dp[m][(1 << n) - 1];
  if (ans == INF) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n;
  cin >> n;
  cout << (n-1)/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    bool ans = false;
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            ans = true;
            break;
        }
    }

    cout << (ans ? "OK" : "NG") << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n),b(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }

  ll ope = accumulate(all(b),(ll)0) - accumulate(all(a),(ll)0);
  ll cnt1 = 0,cnt2 = 0;
  for(int i = 0; i < n; i++){
    if(a[i] < b[i]) cnt1 += (ll)((b[i] - a[i]+1)/ 2);
    else cnt2 += a[i] - b[i];
  }

  // cout << "ope =  " << ope << endl;
  // cout << "cnt1 = " << cnt1 << endl;
  // cout << "cnt2 = " << cnt2 << endl;

  cout << ((cnt1 <= ope) && (cnt2 <= ope) ? "Yes": "No") << endl;

  return 0;
}

Measured memory_bytes: 384
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 61)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll sz = 2e5 + 10, mod = 1e9 + 7;
ll ara[sz], suff[sz];

int main()
{
    ll n;
    cin >> n;

    for1(i, n) sl(ara[i]);

    rep1(i, n) suff[i] = (suff[i+1] + ara[i]) % mod;

    ll ans = 0;
    for1(i, n) {
        ans = (ans + ara[i]*suff[i+1]) % mod;
    }

    cout << ans << EL;

    return 0;
}


Measured memory_bytes: 6780
def get_exp(i,m):
    c=0
    while i<m:
        i=i*2
        c+=1
    return c

n,k=map(int,input().split())
r=0
for x in range(1,n+1):
    r+=1/(n*(2**get_exp(x,k)))
    
print(r)

Measured memory_bytes: 9072
// F
#include<bits/stdc++.h>
#define mo 998244353
using namespace std;
int n,m,i,j,k,x,y,book[20005],zhan[20005],flag,f[2005][2005];
int top,nex[20005],to[20005],fir[20005];
int lj(int u,int v){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
}
long long read(){
	long long xx=0,flagg=1;
	char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')
		ch=getchar();
	if(ch=='-'){
		flagg=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx*flagg;
}
void pus(long long xx,int flagg){
	if(xx>=10)
		pus(xx/10,0);
	putchar(xx%10+'0');
	if(flagg==1)
		putchar(' ');
	if(flagg==2)
		putchar('\n');
	return;
}
void ss(int v){
	if(flag!=0)
		return;
	if(book[v]!=0){
		flag=book[v];
		return;
	}
	top++;
	book[v]=top;
	zhan[top]=v;
	for(int top1=fir[v];top1;top1=nex[top1])
		ss(to[top1]);
	if(flag!=0)
		return;
	book[v]=0;
	zhan[top]=0;
	top--;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();m=read();
	for(i=1;i<=m;i++){
		x=read();y=read();
		f[x][y]=1;
		lj(x,y);
	}
	for(i=1;i<=n;i++)
		if(flag==0)
			ss(i);
	if(flag==0){
		printf("-1\n");
		return 0;
	}
	for(i=1;i<=top-flag+1;i++)
		zhan[i]=zhan[i+flag-1];
	top=top-flag+1;
	for(i=1;i<=n;i++)
		book[i]=0;
	for(i=1;i<=top;i++)
		book[zhan[i]]=i;
	while(1){
		flag=0;
		for(i=1;i<=top;i++){
			for(j=1;j<=top;j++)
				if(i+1!=j&&(i!=top||j!=1)){
					if(f[zhan[i]][zhan[j]]==1){
						flag=1;
						if(j<i){
							for(k=1;k<=i-j+1;k++)
								zhan[k]=zhan[j+k-1];
							top=i-j+1;
						}
						else{
							for(k=1;;k++){
								zhan[i+k]=zhan[j+k-1];
								if(j+k-1==top){
									top=i+k;
									break;
								}
							}
						}
					}
					if(flag==1)
						break;
				}
			if(flag==1)
				break;
		}
		if(flag==0)
			break;
	}
	pus(top,2);
	for(i=1;i<=top;i++)
		pus(zhan[i],2);
	return 0;
}

Measured memory_bytes: 7552
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  vector<int>a = {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};
  int p;
  cin >> p;
  
  cout << a[p-1] << endl;
  
  return 0;
}


Measured memory_bytes: 256
-- Multi lines of lists
import Data.Traversable
import Data.List
import Control.Monad
import Data.Maybe

main = do
  (t:a:b:c:xs) <- map read . words <$> getLine
  ps <- for [1..t] $ \x -> do
    read <$> getLine
  putStrLn . show $ solve ps (a,b,c)

solve :: [Int] -> (Int,Int,Int) -> Int
solve ps (a,b,c) =
  let cands = replicateM (length ps) ['a','b','c','n']
  in minimum . catMaybes $ map (calcOne ps (a,b,c)) cands


calcOne ps (a,b,c) s =
  if 'a' `elem` s &&  'b' `elem` s && 'c' `elem` s then
    let ((va,ca),(vb,cb),(vc,cc)) = calc ps (a,b,c) s
    in Just   ((ca + (abs (a - va)))
         + (cb + (abs (b - vb)))
         + (cc + (abs (c - vc))) - 30)
  else
    Nothing

calc [] (a,b,c) [] = ((0,0),(0,0),(0,0))
calc (p:ps) (a,b,c) (s:ss) =
  let ((va,ca),(vb,cb),(vc,cc)) = calc ps (a,b,c) ss
  in case s of
    'a' -> ((va+p,ca+10),(vb,cb),(vc,cc))
    'b' -> ((va,ca),(vb+p,cb+10),(vc,cc))
    'c' -> ((va,ca),(vb,cb),(vc+p,cc+10))
    'n' -> ((va,ca),(vb,cb),(vc,cc))


Measured memory_bytes: 3836
#include <stdio.h>

int min(int a, int b);

int main(void)
{
    int N, A[100], B[100], i, sum=0;

    scanf("%d", &N);

    for(i=1; i<=N-1; i++){
        scanf("%d", &B[i]);
    }

    A[1] = B[1];

    A[N] = B[N-1];

    for(i=2; i<=N-1; i++){
        A[i] = min(B[i-1], B[i]);
    }

    for(i=1; i<=N; i++){
        sum += A[i];
    }

    printf("%d\n", sum);

    return 0;
}

int min(int a, int b)
{
    if(a < b){
        return a;
    }

    else{
        return b;
    }
}

Measured memory_bytes: 128
#include<cstdio>
using namespace std;
int A[200005],last[200005];
long long ans;
int n;
int main(){
	scanf("%d",&n);	
	for(int i=1,cur=0;i<=n;i++){
		last[i]=cur;
		scanf("%d",A+i);
		if(A[i])cur=i;
	}
	for(int i=1;i<=n;i++){
		int oc=0,p=i;
		while(p&&(oc&A[p])==0)oc|=A[p],p=last[p];
		ans+=i-p;	
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1664
# coding: utf-8
import sys
from functools import lru_cache

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
K = ir()

@lru_cache(None)
def solve(N, K):
    assert N >= 0
    if N < 10:
        if K == 0:
            return 1
        elif K == 1:
            return N
        else:
            return 0
    q, r = divmod(N, 10)
    ret = 0
    if K > 0:
        ret += solve(q, K-1) * r
        ret += solve(q-1, K-1) * (9-r)
    ret += solve(q, K)  # 一桁目が0
    return ret

answer = solve(N, K)
print(answer)


Measured memory_bytes: 3940
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
using ll = long long;

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

	int j = 1, count = 0;
	vector<int> a(n);
	for (i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == j) j++;
		else count++;
	}

	if (count != n) cout << count << endl;
	else cout << -1 << endl;

	return 0;
}

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

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d",x)
#define ps printf(" "); 
#define plint(x) printf("%lld",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define bg begin()
#define ed end()
#define Set(a, s) memset(a, s, sizeof (a))
#define mod 1000000007
#define tmod(k) if ((k) >= mod) k %= mod;
#define endl '\n'
#define nl printf("\n");
#define fors(i,n) for(int i=0; i<n; i++)
#define fore(i,n) for(int i=n-1; i>=0; i--)
#define forv(i,a,n) for(int i=a; i<n; i++)
#define fora(i,ele) for(auto i: ele)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

class node{
public:
	int id;
	int prio;
	int prd;
};

class compare{
public:
	bool operator()(node &n1, node &n2){
		if(n1.prio>n2.prio)//ascending
			return true;
		else if(n1.prio==n2.prio){
			return n1.id>n2.id;
		}
		return false;
	}
};
//priority_queue<node, vector<node>, compare> pq;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*#ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #else
    // online submission
    #endif*/
    st str;
    cin>>str;
    bool check = true;
    int a = 97;
    sort(str.bg,str.ed);
    fors(i,str.length()){
        if(str[i]==a){
            a++;
        }
        else if(str[i]>a){
            check = false;
            break;
        }
    }
    if(a=='z'+1){
        printf("None");
    }
    else{
        printf("%c",a);
    }
    
    
    return 0;
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		char c[] = S.toCharArray();
		int ans = 0;
		for (int i = 0; i < S.length(); i++) {
			if (c[i] == '+') {
				ans++;
			} else {
				ans--;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
# coding: utf-8
# Your code here!

L,R = map(int,input().split())
md = 2019
p = []

for i in range(L,R+1):
    p.append(i)
    if i % 2019 == 0:
        print(0)
        exit()
c = 2020
#print(p)
for i in range(L,R+1):
    for j in range(i+1,R+1):
        #print(i,j)
        c = min(c,i*j%2019)
        
print(c)

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

#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)

using namespace std;

class NyaGadgetVector
{
public:
	/**
	@brief 標準入力関数
	@note
	 標準入力から入力されたsize個の値をcollectionに格納する
	**/
	template<typename T> static void InputStream(vector<T>& collection, int size)
	{
		for (int i = 0; i < size; i++)
			cin >> collection[i];
	}
	/**
	@brief 最小値取得関数
	@note
	 collectionの要素の中で最大値を取得する
	**/
	template<typename T> static T Min(const vector<T>& collection)
	{
		T min = collection[0];
		for (const auto& e : collection)
		{
			if (e < min)
				min = e;
		}
		return min;
	}
	/**
	@brief 合計関数
	@note
	 collectionの要素を合計して返す(範囲はstart_index以上end_index未満)
	**/
	template<typename T> static T Sum(const vector<T>& collection, int start_index, int end_index)
	{
		int sum = 0;
		for (int i = start_index; i < end_index; i++)
			sum += collection[i];
		return sum;
	}
};

int main()
{
	int n; cin >> n;	// 木の本数
	int k; cin >> k;	// 飾り個数

	vector<int> tree_collection(n, 0);
	NyaGadgetVector::InputStream(tree_collection, n);
	sort(tree_collection.begin(), tree_collection.end());

	// 木の高さの差を計算する
	vector<int> difference_collection(n - 1, 0);
	loop(i, n - 1)
		difference_collection[i] = tree_collection[i + 1] - tree_collection[i];

	// BF法でパターンの最小値を見つける
	int pattern_length = k - 1;
	int search_times = difference_collection.size() - pattern_length + 1;
	vector<int>pattern_collection(search_times, 0);
	loop(i, search_times)
		pattern_collection[i] = NyaGadgetVector::Sum(difference_collection, i, i + pattern_length);

	std::cout << NyaGadgetVector::Min<int>(pattern_collection);
}


Measured memory_bytes: 1408
def selectionsort(l,n):
    c=0
    for i in range(n):
        minj=i
        for j in range(i,n):
            if int(l[j])<int(l[minj]):
               minj=j
        l[i],l[minj]=l[minj],l[i]
        if i!=minj:
          c+=1
    print(" ".join(l))
    print(c)
n=int(input())
l=list(input().split())
selectionsort(l,n)


Measured memory_bytes: 5600