akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

import sys


# 再帰深度の制限
REC_LIMIT = 100000

# 頂点の色
UNDEF = 0
WHITE = 1
BLACK = -WHITE


# 所与のグラフが二部グラフならば，(True, color[])を返す
# さもなければ，(False, None)を返す
# 参考：『プログラミングコンテストチャレンジブック』（第2版）p.94
def is_bipartite_graph(adj_list):
    n = len(adj_list)  # 頂点数
    color = [UNDEF] * n

    # 頂点をWHITEとBLACKで塗っていく
    def dfs(v, c):
        color[v] = c
        for u in adj_list[v]:
            if color[u] == c:
                # 隣接頂点が同色で塗られていたら不可
                return False
            if color[u] == UNDEF and not dfs(u, -c):
                # 隣接頂点が未彩色なら，反対の色で塗れるか
                return False
        return True  # すべて色を塗れた
    for i in range(n):
        if color[i] == 0:
            # 未彩色なら，WHITEで塗ってみる
            if not dfs(i, WHITE):
                return (False, None)
    return (True, color)


def compute_max_additional_edges(n, m, adj_list):
    is_bi, color = is_bipartite_graph(adj_list)
    if not is_bi:
        # 二部グラフではない場合
        return n * (n - 1) // 2 - m
    else:
        # 二部グラフである場合
        w = sum(c == WHITE for c in color)
        b = sum(c == BLACK for c in color)
        return w * b - m


def main():
    # 最大再帰深度の再設定
    sys.setrecursionlimit(REC_LIMIT)
    # 入力の読み込み
    n, m = (int(x) for x in input().split())
    adj_list = [set() for _ in range(n)]
    for _ in range(m):
        a, b = (int(x) - 1 for x in input().split())
        adj_list[a].add(b)
        adj_list[b].add(a)
    res = compute_max_additional_edges(n, m, adj_list)
    print(res)


if __name__ == '__main__':
    main()


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

struct Node{
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil)break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t){
    if(t==nil)return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for(i = 0; i < n; i++){
        scanf("%s%d", com, &key);
        if(com[0] == 'i'){
            insert(key);
            np++;
            size++;
        }else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F')deleteFirst();
                else if(com[6] == 'L')deleteLast();
            } else {
                deleteKey(key);
                nd++;
            }
            size--;
        }
    }
    printList();
    return 0;
}



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

const long long mod = pow(10, 9) + 7;

const long long INF = 1LL << 60;

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

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

// A...0  G...1  C...2  T...3
bool ok(int c0, int c1, int c2, int c3)
{
  if (c0 == 0 && c1 == 1 && c2 == 2) return false;
  if (c1 == 0 && c2 == 1 && c3 == 2) return false;
  if (c0 == 0 && c1 == 2 && c2 == 1) return false;
  if (c1 == 0 && c2 == 2 && c3 == 1) return false;
  if (c0 == 1 && c1 == 0 && c2 == 2) return false;
  if (c1 == 1 && c2 == 0 && c3 == 2) return false;
  if (c0 == 0 && c1 == 1 && c3 == 2) return false;
  if (c0 == 0 && c2 == 1 && c3 == 2) return false;
  return true;
}

int main() 
{
  int N;
  cin >> N;
  
  long long dp[N + 10][4][4][4];
  dp[0][3][3][3] = 1;
  
  for (int i = 0; i < N; i++)
  {
    for (int c0 = 0; c0 < 4; c0++)
    {
      for (int c1 = 0; c1 < 4; c1++)
      {
        for (int c2 = 0; c2 < 4; c2++)
        {
          if (dp[i][c0][c1][c2] != 0)
          {
            for (int c3 = 0; c3 < 4; c3++)
            {
              if (ok(c0, c1, c2, c3))
              {
                dp[i + 1][c1][c2][c3] += dp[i][c0][c1][c2];
                dp[i + 1][c1][c2][c3] %= mod;
              }
            }
          }
        }
      }
    }
  }
  
  long long ans = 0;
  for (int c0 = 0; c0 < 4; c0++)
  {
    for (int c1 = 0; c1 < 4; c1++)
    {
      for (int c2 = 0; c2 < 4; c2++)
      {
        ans += dp[N][c0][c1][c2];
        ans %= mod;
      }
    }
  }
  
  cout << ans << endl;
}

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

using namespace std;

void solve()
{
	int N, W;
	cin >> N >> W;
	vector<int> v(N);
	vector<int> w(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> v[i] >> w[i];
	}
	vector<vector<int> > dp(N + 1, vector<int>(W + 1));
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j <= W; ++j)
		{
			if (j < w[i])
			{
				dp[i + 1][j] = dp[i][j];
			}
			else
			{
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			}
		}
	}
	cout << dp[N][W] << endl;
}

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

Measured memory_bytes: 4964
N  = int(input())
using = [0 for _ in range(9)]
def color(i):
    i = int(i)
    if i < 400:
        return 0
    elif i< 800:
        return 1
    elif i<1200:
        return 2
    elif i<1600:
        return 3
    elif i<2000:
        return 4
    elif i<2400:
        return 5
    elif i<2800:
        return 6
    elif i<3200:
        return 7
    else:
        return 8
L = list(map(color, input().split()))
for x in L:
    using[x] += 1
val = using.pop(-1)
if list(filter(lambda x:x!=0,using)) == []:
    print(1,val)
else:
    minimum = len(list(filter(lambda x:x!=0,using)))
    maximum =  minimum + val
    print(minimum,maximum)


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

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;

  std::vector<int> L;

  for (size_t i = 0; i < N; i++) {
    int tmp;
    std::cin >> tmp;
    L.push_back(tmp);
  }

  sort(L.begin(), L.end(), greater<int>());

  const int maximum = L.at(0);
  int sum = 0;
  
  for (size_t i = 1; i < L.size(); i++) {
    sum += L.at(i);
  }

  sum > maximum ? std::cout << "Yes" << '\n' : std::cout << "No" << '\n';
  
  return 0;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    int cnt = 0, cnt2=0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A') cnt++;
        else cnt2++;
    }
        
    if(cnt and cnt2)
        cout << "Yes";
    else    cout<<"No";


}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var NM = ReadSplitInt();
            var Rmin = int.MaxValue;
            var Lmax = 0;
            for (int i = 0; i < NM[1]; i++)
            {
                var lr = ReadSplitInt();
                Lmax = Max(Lmax, lr[0]);
                Rmin = Min(Rmin, lr[1]);
            }

            var ans = 0;
            for (int i = Lmax; i <= Rmin; i++)
                ans++;
            Println(ans);
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



Measured memory_bytes: 15440
<?php
fscanf(STDIN, "%d %d", $n, $k);
$a = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
	if ($a[$i] == 1) {
		$x = $i; break;
	}
}
$k--;
$a = ceil($x / $k);
echo $a + ceil(($n - $a * $k - 1) / $k);

Measured memory_bytes: 12792
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] a = new int[N];
        int max = (int)Math.pow(10, 5);
        int[] c = new int[max+2];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            if(a[i] == 0){
                c[a[i]]++;
                c[a[i]+1]++;
            } else {
                c[a[i]-1]++;
                c[a[i]]++;
                c[a[i]+1]++;
            }
        }
        sc.close();
        Arrays.sort(c);

        System.out.println(c[max+1]);
        
    }
}

Measured memory_bytes: 50016
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
  

int main() {
	int n; cin >> n;
	vector<int>hs(n);
	for (int i = 0; i < n; ++i)cin >> hs[i];
	sort(hs.begin(), hs.end(), greater<int>());

	long long int ans = 0;
	for (int i = 0; i < hs.size(); ++i) {
		int minus = i ? i / 4 + 1 : 0;
		int plus = hs[i]+1;
		if (plus < minus)break;
		else ans += plus - minus;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3148
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# ac_py.main
# Date: 2020/06/11
# Filename: main 
# Author: acto_mini

def main():
    n = int(input())
    ans = 0
    arr = []
    for i in range(n):
        arr.append(int(input()))
    print(len(set(arr)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
N,C=list(map(int,input().split()))
A=[list(map(int,input().split())) for _ in range(N)]
T=0
for i in A:
    T=max(i[1],T)
timelist=[0 for _ in range((T)*2)]
ch=[[] for _ in range(C)]
for item in A:
    ch[item[2]-1].append(item)


count=0
for channel in ch:
    count+=1
    for item in channel:
        starttime=item[0]
        endtime=item[1]
        for time in range(starttime*2-2,endtime*2-2,2):
            timelist[time]+=1
            if(timelist[time]>count):
                timelist[time]=count
            timelist[time+1]+=1
            if(timelist[time+1]>count):
                timelist[time+1]=count
        timelist[time+2]+=1
        if(timelist[time+2]>count):
                timelist[time+2]=count
print  (max (timelist))

Measured memory_bytes: 32088
N,M=map(int,input().split())
G=[[] for i in range(3*N)]
L=[-2 for i in range(3*N)]
for i in range(0,M):
  u,v=map(int,input().split())
  G[N*0+u-1].append(N*1+v-1)
  G[N*1+u-1].append(N*2+v-1)
  G[N*2+u-1].append(N*0+v-1)
  
  
#print(G)
S,T=map(int,input().split())
S=S-1
T=T-1
L[S]=0
Now=[S]
while Now:
  x=Now.pop(0)
  for i in range(len(G[x])):
    #print(x,"x",Now,"Now")
    #print(L)
    g=G[x]
    if L[g[i]]<0:
      L[g[i]]=L[x]+1
      Now.append(g[i])
print(L[T]//3)
      
      

Measured memory_bytes: 59824
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
 
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	answer := make([]string, n)

	for i := 0; i < n; i++ {
		sc.Scan()
		j, _ := strconv.Atoi(sc.Text())
		answer[j - 1] = strconv.Itoa(i + 1)
	}
	fmt.Print(strings.Join(answer, " "))

	fmt.Println()
}

Measured memory_bytes: 5760
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s;
  cin >> s;

  cout << string(s.size(), 'x') << endl;

}


Measured memory_bytes: 256
N = int(input())

def main():
    btc_coeff = 380000
    ans = 0
    for _ in range(N):
        x, u = [s for s in input().split()]
        if u == 'JPY':
            ans += float(x)
        elif u == 'BTC':
            ans += float(x) * btc_coeff
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
h, w = map(int, input().split())

M = [str(input()) for _ in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        if M[i][j] == '.':
            ans += 1

M = ['#'*w] + M + ['#'*w]
M = ['#'+c+'#' for c in M]

from collections import deque
q = deque()
q.append((1, 1))
visit = [[-1]*(w+2) for _ in range(h+2)]
visit[1][1] = 0

while q:
    y, x = q.popleft()
    for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):
        ny, nx = y+dy, x+dx
        if visit[ny][nx] == -1 and M[ny][nx] != '#':
            visit[ny][nx] = visit[y][x]+1
            q.append((ny, nx))

if visit[h][w] == -1:
    print(-1)
else:
    ans = ans -visit[h][w]-1
    print(ans)

Measured memory_bytes: 40048
#include <bits/stdc++.h>
#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

#define FOR(i,n) for(ll i=0;i<n;i++)

struct edge{ll to,cost;};

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0); 
   vector<int>N(3);
   int K;
   cin >> N[0] >> N[1] >> N[2] >> K;
   sort(N.begin(),N.end());
   cout << N[0] + N[1] + N[2]*pow(2,K) << endl;
   return 0;
}


Measured memory_bytes: 384
asc :: [Int] -> Int -> Int
asc [] acc = acc
asc (x:xs) acc
  | xs == [] = acc
  | x <= head xs = asc xs acc
  | otherwise = solve xs acc

desc :: [Int] -> Int -> Int
desc [] acc = acc
desc (x:xs) acc
  | xs == [] = acc
  | x >= head xs = desc xs acc
  | otherwise = solve xs acc

solve :: [Int] -> Int -> Int
solve [] acc = acc
solve (x:xs) acc
  | xs == [] = acc + 1
  | x == head xs = solve xs acc
  | x < head xs = asc xs (acc + 1)
  | otherwise = desc xs (acc + 1)

main = do
  n <- getLine
  line <- getLine
  let as = fmap (read :: String -> Int) (words line) in
    putStrLn $ show $ solve as 0


Measured memory_bytes: 36220
import os
import sys

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

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


# MOD = 998244353


class KMP:
    def __init__(self, needle):
        """
        https://ja.wikipedia.org/wiki/クヌース–モリス–プラット法
        :param typing.Sequence needle: 何を検索するか
        """
        self._needle = needle
        kmp = [0] * (len(needle) + 2)
        kmp[0] = -1
        kmp[1] = 0
        i = 2
        j = 0
        while i < len(needle):
            if needle[i - 1] == needle[j]:
                kmp[i] = j + 1
                i += 1
                j += 1
            elif j > 0:
                j = kmp[j]
            else:
                kmp[i] = 0
                i += 1
        self._kmp = kmp

    def index_of(self, haystack, m=0, i=0):
        """
        m + (haystack[m:] の何番目に needle があるか)
        見つからなければ -1
        needle[i:] のみ比較する
        :param typing.Sequence haystack: 何から検索するか
        :param int m: The position of the current character in haystack
        :param int i: The position of the current character in needle
        :rtype: int
        """
        while m + i < len(haystack):
            if self._needle[i] == haystack[m + i]:
                i += 1
                if i == len(self._needle):
                    return m
            else:
                m += i - self._kmp[i]
                if i > 0:
                    i = self._kmp[i]
        return -1

    def search(self, haystack):
        """
        ret[i]: haystack[i:i+len(needle)] == needle
        :param typing.Sequence haystack: 何から検索するか
        :rtype: list of bool
        """
        ret = [False] * len(haystack)
        m = 0
        i = 0
        while m + i < len(haystack):
            m = self.index_of(haystack, m=m, i=i)
            if m < 0:
                break
            ret[m] = True
            m += len(self._needle) - self._kmp[len(self._needle) - 1] - 1
            i = max(0, self._kmp[len(self._needle) - 1])
        return ret


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


def test():
    ans = []
    # k が決まれば x も決まる
    for k in range(N):
        b = np.roll(B, k)
        x = A[0] ^ b[0]
        a = A ^ x
        if np.all(a == b):
            ans.append((k, x))
    for r in ans:
        print(*r)


# 解説
# 隣合う値同士の XOR が全て等しければ OK
xa = []
xb = []
for a1, a2 in zip(A, A[1:] + [A[0]]):
    xa.append(a1 ^ a2)
for b1, b2 in zip(B, B[1:] + [B[0]]):
    xb.append(b1 ^ b2)

kmp = KMP(xb)
k_ok = kmp.search(xa + xa)
for k in range(N):
    if k_ok[k]:
        x = A[k] ^ B[0]
        print(k, x)


Measured memory_bytes: 104340
#include <bits/stdc++.h>
using namespace std;
int gcdf(int a, int b){
  if(a>b) swap(a,b);
  int amari = 1;
  while(amari != 0){
    amari = a%b;
    a = b;
    b = amari;
    //printf("amari = %d a = %d b = %d\n",amari,a,b); 
  }
  
  return a;
}
int gcdf3(int a, int b, int c){
  return gcdf(gcdf(a,b), gcdf(b,c));
}

int main(){
  int K,sum=0;
  cin >> K;
  for(int a=1;a<=K;a++){
    for(int b=1;b<=K;b++){
      for(int c=1;c<=K;c++){
        int gcd_abc;
        gcd_abc = gcdf3(a,b,c);
        //printf("gcd_%d%d%d = %d\n",a,b,c,gcd_abc);
        sum += gcd_abc;
      }
    }
  }
  cout << sum << endl;
        
}

Measured memory_bytes: 3636
/*
 * yaswanth phani kommineni
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';

vector <ll> st((1<<20));

void update(ll u,ll k){
	u+=(1<<19);
	while(u){
		st[u] = max(k,st[u]);
		u/=2;
	}
}

ll maxQ(ll a,ll b){
	a+=(1<<19);
	b+=(1<<19);
	ll ans = 0;
	while(a<=b){
		if(a&1) ans = max(ans,st[a++]);
		if(!(b&1)) ans = max(ans,st[b--]);
		a/=2;
		b/=2;
	}
	return ans;
}

void solve(){
	ll n,k;
	cin >> n >> k;
	vector <ll> v(n);
	ll ans = 0;
	for(ll i=0;i<n;i++){
		cin >> v[i];
		ll u = v[i];
		ll cur = maxQ(max((ll)0,u-k),min(u+k,(ll)3e5))+1;
		update(v[i],cur);
		ans = max(ans,cur);
	}
	cout << ans << endl;
}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int z;
	z = 1;
	//cin >> z;
	for(int z1=1;z1<=z;z1++){
		solve();
	}
	return 0;
}



Measured memory_bytes: 13756
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/
int a[200],m;
int n,q;

bool solve(int sum, int now){
  if(sum==m)return true;
  if(now>n)return false;
  return solve(sum+a[now], now+1) || solve(sum, now+1);
}

int main(){
  cin>>n;
  rep(i,n)cin>>a[i];
  cin>>q;
  rep(i,q){
    cin>>m;
    if(solve(0,0))cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

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

int top,S[1000];

void push(int x){
    top++;
    S[top] = x;
}

int pop(){
    top--;
    return S[top+1];
}

int main(){
    int a,b;
    top = 0;
    char s[100];
    while(cin >> s){
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a+b);
        }else if(s[0] == '-'){
            a = pop();
            b = pop();
            push(b-a);
        }else if(s[0] == '*'){
            a = pop();
            b = pop();
            push(a*b);
        }else{
            push(atoi(s));
        }
        if(getchar() == '\n'){
            break;
        }
    }
    cout << pop() << endl; 
    return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>

int main(){
   int S, h, m, s;

   scanf("%d", &S);
   h = S / 3600;
   m = (S % 3600) / 60;
   s = (S % 3600) % 60;

   printf("%d:%d:%d\n", h, m, s);
   return 0;
}


Measured memory_bytes: 2064
// Believe in yourself
#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Pair vector<pair<ll,ll>>
#define vec vector <ll> 
#define all(a) a.begin(),a.end()
#define mo 1000000007
#define decimal(i,n) fixed << setprecision(i) << n
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define show_nl(a) for(auto xyz:a)cout<<xyz<<endl;


void eea(ll a,ll b,ll &x,ll &y)
{
    if (a == 1)
    {
        x = 1; y = 0;
        return;
    }
    ll x1, y1;
    eea(b%a,a,x1,y1);
    x=y1-(b/a)*x1;
    y=x1;
}
ll mi(ll a,ll m)
{
    ll x,y;
    eea(a,m,x,y);
    x= (x%m+m)%m;
    return x;
}

/*
Enter the test case


Some helpful points
1.) Calm yourself
2.) check for semicolon or data type mismatch
*/


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);    
    ll t=1;
    // cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       int a[n];
       for(int i=0;i<n;i++)
       cin>>a[i];
       sort(a,a+n);
       int x=0;
       for(int i=1;i<n;i++)
       if(a[i]==a[i-1])
       x=1;
       if(x==1)
       cout<<"NO\n";
       else
       cout<<"YES\n";
    }
}



Measured memory_bytes: 4412
#define X (x-P>0?x-P:P-x)
#define Y (y-Q>0?y-Q:Q-y)
#define N (P<x?1:-1)
#define M (Q<y?1:-1)
#define p(x,y) (A[++S]=x,B[S]=y) 
t,k,x,y,P,Q,S,i=1,A[1<<20],B[1<<20];main(){scanf("%d%d%d",&k,&x,&y);!(k&1)&&(x+y&1)&&(exit(puts("-1")&0),0);while(X+Y>k*2)X>k?(P+=k*N):(Q+=k*M),p(P,Q);X+Y!=k&&((k%2&&(X+Y)%2)&&(Y<=k?(P+=(k-Y)*N,Q=y):(Q+=(k-X)*M,P=x),p(P,Q)),t=k*2-X-Y>>1,X<Y?p(x+t*N,Q+(k-X-t)*M):p(P+(k-Y-t)*N,y+t*M));p(x,y),printf("%d\n",S);for(;i<=S;)printf("%d %d\n",A[i++],B[i]);}

Measured memory_bytes: 4864
ab = input().split(" ", 2)
a = int(ab[0])
b = int(ab[1])
if -1000 <= a and a <= 1000 and -1000 <= b and b <= 1000:
    if a < b:
        print("a < b")
    elif a > b:
        print("a > b")
    else:
        print("a == b")


Measured memory_bytes: 5596
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

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

    int d = a - 2*b;

    if(d < 0){
        d = 0;
    }

    cout << d;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,i,m,j,a,b;
	char s[102][102];
	scanf("%d%d",&a,&b);
	getchar();
	for(j=0;j<a;j++)
	{
		for(i=1;i<b+1;i++)
		{
			scanf("%c",&s[i][j]);	
		}
		getchar();
	}

	for(i=0;i<b+2;i++)
	{
		printf("#");
		if(i==b+1)
		printf("\n");
	}
	
	for(i=0;i<a;i++)
	{
		s[0][i]='#';
	}
	
	for(i=0;i<a;i++)
	{
		s[b+1][i]='#';
	}
	
	for(j=0;j<a;j++)
	{
		for(i=0;i<b+2;i++)
		{
			printf("%c",s[i][j]);
			if(i==b+1)
			printf("\n");
		}
	}
	
	for(i=0;i<b+2;i++)
	{
		printf("#");
		if(i==b+1)
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>


using namespace std;


void white_cells()
{
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  cout << (H * W) - (h * W) - (H * w) + (h * w) << "\n";
}


void double_helix()
{
  char b;
  cin >> b;

  if (b == 'A') cout << "T\n";
  else if (b == 'T') cout << "A\n";
  else if (b == 'C') cout << "G\n";
  else  cout << "C\n";

}


void five_antennas()
{
  vector<int> a(5);
  for (int i = 0; i < 5; ++i) cin >> a[i];
  int k;
  cin >> k;

  if (a[4] - a[0] > k)
  {
    cout << ":(\n";
    return;
  }
  cout << "Yay!\n";

}

void buttons()
{
  int a, b;
  cin >> a >> b;

  int v_max = 0;
  for (int i = 0; i < 2; ++i) {
    if (a > b) {
      v_max += a;
      --a;
    }
    else
    {
      v_max += b;
      --b;
    }
  }
  cout << v_max << "\n";
}


void biscuit_generator()
{
  int a, b, t;
  cin >> a >> b >> t;

  cout << t / a * b << "\n";
}


void changing_a_character()
{
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  s[k - 1] += 32;
  cout << s <<"\n";
}


void ferris_wheel()
{
  int a, b;
  cin >> a >> b;

  if (a >= 13) cout << b << "\n";
  else if(a >= 6) cout << b / 2 << "\n";
  else cout << 0 << "\n";
}


int main()
{
  //white_cells();
  //double_helix();
  //five_antennas();
  //buttons();
  //biscuit_generator();
  //changing_a_character();
  ferris_wheel();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     int a[3][3],c[3][3];
     
     for(int i=0;i<3;i++)
     { for(int j=0;j<3;j++)
	 {
	 	cin>>a[i][j];
	  }
	   }
	    for(int i=0;i<3;i++)
     { for(int j=0;j<3;j++)
	 {
	     c[i][j]=0;
	  }
	   }
     int n,b;
     cin>>n;
     while(n--)
     {
     	cin>>b;
      for(int i=0;i<3;i++)
     { for(int j=0;j<3;j++)
	 {
	 	if(a[i][j]==b) c[i][j]=1; 
	  }
	   }
	 }
	 for(int i=0;i<3;i++)
	 {
	 	if(c[i][0]+c[i][1]+c[i][2]==3) {
	 		cout<<"Yes";
	 		return 0;
		 }
	 }
	 for(int i=0;i<3;i++)
	 {
	 	if(c[0][i]+c[1][i]+c[2][i]==3) {
	 		cout<<"Yes";
	 		return 0;
		 }
	 }
	 if(c[0][0]+c[1][1]+c[2][2]==3) {
	 	cout<<"Yes";
	 	return 0;
	 }
	 else if(c[2][0]+c[1][1]+c[0][2]==3) {
	 	cout<<"Yes";
	 	return 0;
	 }
	 else cout<<"No";
 } 

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int[] x = new int[3];
		int ans = 1;


		for (int i = 0; i < 3 ;i++) {
			x[i] = sc.nextInt();
		}

		Arrays.sort(x);


		for (int i = 0; i < 2; i++) {
			if (x[i] != x[i+1]){
				ans++;
			}
		}



		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 10192
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Stream;

/**
 *
 * @author Pradyumn Agrawal coderbond007
 */

public class Main{
    public static InputStream inputStream = System.in;
    public static StringTokenizer tok = null;
    public static BufferedReader br = new BufferedReader(new InputStreamReader(inputStream), 32768);
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args) throws java.lang.Exception{
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    new Main().run();
                    out.close();
                } catch(IOException e){

                }
            }
        }, "1", 1 << 26).start();
    }
    public void run() throws IOException
    {
        int a = ni();
        int b = ni();
        out.println((a + b)%24);
    }
    public static int ni() throws IOException {
        return Integer.parseInt(ns());
    }
    public static long nl() throws IOException {
        return Long.parseLong(ns());
    }
    public static double nd() throws IOException {
        return Double.parseDouble(ns());
    }
    public static char nc() throws IOException {
        return ns().charAt(0);
    }
    public static BigInteger nextBigInteger() throws IOException {
        return new BigInteger(ns());
    }
    public static String ns() throws IOException {
        while(tok == null || !tok.hasMoreTokens()){
            try {
                tok = new StringTokenizer(br.readLine());
            } catch (IOException e){
                throw new RuntimeException(e);
            }
        }
        return tok.nextToken();
    }
    public static int[] na(int n) throws IOException {
        int[] a = new int[n];
        for(int i = 0;i < n; i++){
            a[i] = ni();
        }
        return a;
    }
    public static long[] nal(int n) throws IOException {
        long[] a = new long[n];
        for(int i = 0;i < n; i++){
            a[i] = nl();
        }
        return a;
    }
    public static char[] ns(int n) throws IOException {
        return ns().substring(0,n).toCharArray();
    }
    public static char[][] nm(int n, int m) throws IOException{
        char[][] map = new char[n][];
        for(int i = 0;i < n; i++){
            map[i] = ns(m);
        }
        return map;
    }
    public static String readLine() {
    	try {
    		return br.readLine();
    	} catch(IOException e){
    		throw new RuntimeException(e);
    	}
    }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dl;
const int iNF = 1e9 + 100;
//const ll INF = 1e18 + 100;
typedef pair<int, int> pii;
 
#define EPS (1e-9)
#define inf 1e19
#define PI acos(-1.0)

int main(){
   int n;
   cin >> n;
   int a;
   bool ok = 0;
   while(n > 0){
      a = n % 10;
      if(a == 7){ ok = 1; break;}
      n /= 10;
   }
   if(ok){
      cout << "Yes";
   }else{
      cout << "No";
   }
   return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int count=0;
    int ans=0;
    

    for(int i=1; i<=N; i++){
       int b =i;
       while(b>0){
           b /=10;
           count ++;
       }
       if(count %2 ==1) ans++;
       count =0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define L 14
#define M 1046527

char H[M][L];

int getChar(char m){
    if(m=='A')
        return 1;
    else if(m=='C')
        return 2;
    else if(m=='G')
        return 3;
    else if(m=='T')
        return 4;
    else
        return 0;
}

int h1(int key){
    return key%M;
}

int h2(int key){
    return 1+(key%(M-1));
}

long long getkey(char str[]){
    long long sum=0,p=1,i;
    for(i=0;i<strlen(str);i++){
        sum+=p*getChar(str[i]);
        p*=5;
    }
    return sum;
}

int find(char str[]){
    long long key,i,h;
    key=getkey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0)
            return 1;
        else if(strlen(H[h])==0)
            return 0;
    }
}

int insert(char str[]){
    long long key,i,h;
    key=getkey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0)
            return 1;
        else if(strlen(H[h])==0){
            strcpy(H[h],str);
            return 0;
        }
    }
}

int main(){
    int i,n;
    char str[L],com[7];
    
    scanf("%d",&n);

    for(i=0;i<M;i++)
        H[i][0]='\0';
    for(i=0;i<n;i++){
        scanf("%s %s", com, str);
    
        if(com[0]=='i'){
            insert(str);
        }else{
            if(find(str)){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 14916
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	vector<int>abcd(4);
	int n;
	cin >> n;

	for (int i = 3; i >= 0; i--) {
		abcd[i] = n % 10;
		n /= 10;
	}

	vector<char> ans(3);

	// + か - だけでいい

	// 全探索でいいじゃん　楽勝

	rep(bit, 1 << 3) {
		int tmp = abcd[0];
		rep(i, 3) { // 1でプラス
			if (bit & 1 << i) {
				tmp += abcd[i + 1];
			}
			else {
				tmp -= abcd[i + 1];
			}
		}
		if (tmp == 7) {
			rep(i, 3) {
				if (bit & 1 << i) {
					ans[i] = '+';
				}
				else {
					ans[i] = '-';
				}
			}
			break;
		}
	}

	cout << abcd[0];
	rep(i, 3) {
		cout << ans[i] << abcd[i + 1];
	}
	cout << "=" << 7 << endl;

	return 0;
}

Measured memory_bytes: 256
A,B,M=map(int,input().split())
at=list(map(int,input().split()))
bt=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for i in range(M)]

minc=min(at)+min(bt)

for i in range(M):
    minc=min(minc,at[xyc[i][0]-1]+bt[xyc[i][1]-1]-xyc[i][2])
    
print(minc)

Measured memory_bytes: 80324
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

inline ll readll()
{
	ll x=0;int f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int n;
priority_queue<ll,vector<ll>,greater<ll> > q;
vector<pair<int,ll> > a[2];

int main()
{
	int T=read();
	while (T--)
	{
		n=read();ll ans=0;
		a[0].clear();a[1].clear();
		rep(i,1,n)
		{
			int k=read(),l=read(),r=read();
			if (l>r)
			{
				int x=l-r;ans+=r;
				a[0].pb(mkp(k,x));
			}
			else
			{
				int x=r-l;k=n-k;
				ans+=l;
				if (k) a[1].pb(mkp(k,x));
			}
		}
		rep(i,0,1)
		{
			sort(a[i].begin(),a[i].end());
			//a[i].pb(mkp(maxd,0));
			int len=a[i].size();
			rep(j,0,len-1)
			{
				q.push(a[i][j].sec);
				while ((int)q.size()>a[i][j].fir) q.pop();
			}
			while (!q.empty())
			{
				ll x=q.top();q.pop();ans+=x;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
			

Measured memory_bytes: 8320
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	int l=-110,r=110;
	rep(i,n){
		int a;
		cin>>a;
		l=max(l,a);
	}
	rep(i,m){
		int a;
		cin>>a;
		r=min(r,a);
	}
	// (x,y] and (l,r]
	if(max(x,l)<min(y,r))cout<<"No War"<<endl;
	else cout<<"War"<<endl;
}







Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    N = int(input())

    dp = [float('inf')]*(N+1)
    dp[0] = 0
    for i in range(N+1):
        t = 1
        while t<=i:
            dp[i] = min(dp[i], dp[i-t]+1)
            t *= 6
        t = 9
        while t<=i:
            dp[i] = min(dp[i], dp[i-t]+1)
            t *= 9
    
    print(dp[N])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3828
import numpy as np

N, K = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
MOD = 10**9 + 7

a = np.matrix(a, dtype=object)
ans = np.matrix(np.diag([1]*N), dtype=object)

while K:
    K, m = divmod(K, 2)
    if m:
        ans = ans * a
        ans = np.mod(ans, MOD)
    a = a*a
    a = np.mod(a, MOD)

print(ans.sum() % MOD)

Measured memory_bytes: 12608
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int N, M;
char bits[100001];
vector<int> poslist;

int main(void) {
	cin >> N >> M;
	for (int i = 0; i <= N; i++) {
		cin >> bits[i];
	}
	int pos = N;
	while (pos > 0) {
		int newpos = -1;
		int diff;
		for (int i = min(M, pos); i >= 1; i--) {
			if (bits[pos - i] == '0') {
				newpos = pos - i;
				diff = i;
				break;
			}
		}
		if (newpos == -1) {
			cout << "-1\n";
			return 0;
		}
		pos = newpos;
		poslist.push_back(diff);
	}
	for (vector<int>::const_reverse_iterator it = poslist.rbegin(); it != poslist.rend(); it++) {
		cout << *it << ' ';
	}
	return 0;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}
	
	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=1e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=5e3+10;
	//------------------FIXED------------------
	//求重心
	vc<int> to[N];int siz[N];
	int G,SUM,mxs[N];
	void getrt(int x,int fa)
	{
		mxs[x]=0;siz[x]=1;
		for(auto y:to[x]) if(y!=fa) getrt(y,x),siz[x]+=siz[y],chmax(mxs[x],siz[y]);
		chmax(mxs[x],SUM-siz[x]);if(mxs[x]<mxs[G]) G=x;
	}
	ll f[N],g[N];
	void main()
	{
		int n=qread();fo(i,2,n){ int x=qread(),y=qread();to[x].PB(y),to[y].PB(x); }
		SUM=n,mxs[G=0]=INF;getrt(1,0);debug("G=%d\n",G);
		f[0]=1;int sum=0;ll mul=1;
		for(auto y:to[G])
		{
			int aa=(siz[y]>siz[G]?n-siz[G]:siz[y]);mul=mul*fac[aa]%MOD;
			mem(g,0);
			fo(i,0,sum) fo(j,0,aa) add(g[i+j],f[i]*Comb(aa,j)%MOD*facinv[aa-j]%MOD );
			swap(f,g);sum+=aa;
			deb;
		}ll ans=0;fo(i,0,n-1) add(ans,f[i]*fac[n-i]%MOD*(i&1?MOD-1:1)%MOD );write(ans*mul%MOD);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 24320
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;

ll dp[110][110000];

int main(){
  int N,L,maxL,ch;
  cin>>N>>L;
  maxL=L+N-1;
  if(L<=0 && maxL>=0) ch=0;
  else if(L<0) ch=maxL;
  else ch=L;
  cout<<(maxL+L)*N/2-ch<<endl;
}


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

#define REP(i,a,b) for(int i=a,i##_end_=b;i<=i##_end_;++i)
#define DREP(i,a,b) for(int i=a,i##_end_=b;i>=i##_end_;--i)
#define debug(x) cout<<#x<<"="<<x<<" "
#define pii pair<ll,ll>
#define fi first
#define se second
#define mk make_pair
#define pb push_back
typedef long long ll;

using namespace std;

void File(){
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
}

template<typename T>void read(T &_){
	_=0; T f=1; char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())_=(_<<1)+(_<<3)+(c^'0');
	_*=f;
}

const int maxn=2e5+10;
int n;
ll a[maxn],f[maxn],g[maxn],ans=1e18;

int main(){
	//File();
	read(n);
	REP(i,1,n)read(a[i]);

	stack<pii>s1;
	REP(i,2,n){
		f[i]=f[i-1];
		ll pre=a[i-1],now=a[i];
		while(pre<a[i]){
			pre*=4;
			if(s1.empty())f[i]+=(i-1)*2;
			else{
				pii p=s1.top(); s1.pop();
				f[i]+=(i-p.fi)*2;
				if(--p.se)s1.push(p);
			}
		}
		ll cnt=0;
		while(now*4<=pre)now*=4,++cnt;
		if(cnt)s1.push(mk(i,cnt));
	}

	reverse(a+1,a+n+1);

	stack<pii>s2;
	REP(i,2,n){
		g[i]=g[i-1];
		ll pre=a[i-1],now=a[i];
		while(pre<a[i]){
			pre*=4;
			if(s2.empty())g[i]+=(i-1)*2;
			else{
				pii p=s2.top(); s2.pop();
				g[i]+=(i-p.fi)*2;
				if(--p.se)s2.push(p);
			}
		}
		ll cnt=0;
		while(now*4<=pre)now*=4,++cnt;
		if(cnt)s2.push(mk(i,cnt));
	}

	reverse(g+1,g+n+1);

	REP(i,0,n)ans=min(ans,f[i]+g[i+1]+i);

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

	return 0;
}

Measured memory_bytes: 4992