akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

use std::time::Instant;
fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: BTreeSet<_> = (0..n + 1).collect();
    let r2: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    while !rems.is_empty() {
        while let Some(s_idx) = q.pop_front() {
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            // if let Some(destv) = dests.remove(&s_num) {
            //     for dest in destv {
            //         q.push_back(dest);
            //     }
            // }
            if let Some(destv) = dests.get_mut(&s_num) {
                for &dest in destv.iter() {
                    q.push_back(dest);
                }
                destv.clear();
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
        if let Some(&_) = r2.iter().next() {
        }
    }
    println!("{}", ans);
    std::process::exit(0);
}


Measured memory_bytes: 27576
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0 

using namespace std;
using ll = long long;

void testcase() {
    int n, k;
    cin >> n >> k;

    vector<vector<int> > adj(n+1);

    rep (i, 1, k) {
    	int d; cin >> d;
    	while (d--) {
    		int type; cin >> type;
    		adj[type].push_back(i);
    	}
    }

    int res = 0;
    rep (i, 1, n)
    	if (adj[i].size() ==0)
    		res++;

    cout << res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

int main(){
  int N,M,X;
  cin>>N>>M>>X;
  int ami=0;int ama=0;
  LOOP(i,M){
    int a;
    cin >> a;
    if(a>X) ama++;
    else    ami++;
  }
  cout << (ama>ami?ami:ama) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  int a,b;
  cin>>a>>b;
  for(int i=max(-1000000,b-a+1);i<=min(1000000,b+a-1);i++){
    cout<<i;
    if(i==min(1000000,b+a-1))
      cout<<endl;
    else
      cout<<' ';
  }
}

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    int N;
    cin >> N;
    vector<vector<int>> vec(N, vector<int> (3));

    REP(i, N) REP(j, 3) cin >> vec[i][j];

    REP(i, N) sort(ALL(vec[i]));

    set<vector<int>> s;

    REP(i, N)
    {
        s.insert(vec[i]);
    } 

    cout << N - s.size() << endl;

    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
  ll N,a=1,b;
  cin>>N;
  ll A[N];
  for(ll i=0;i<N;i++){
    cin>>A[i];
    if(A[i]%2==0) a*=2;
  }
  b=pow(3,N);
  cout<<b-a<<endl;
}


Measured memory_bytes: 512
n = int(input())
oth = [int(input()) for _ in range(n)]
mod = 10**9 + 7
l = list()
for x in oth:
    if l and l[-1] == x:
        continue
    l.append(x)
lenl = len(l)
last = [-1] * 200001
l2 = [-1] * 200001
for i, a in enumerate(l):
    l2[i] = last[a]
    last[a] = i

dp = [0] * lenl
dp[0] = 1
for i in range(1, lenl):
    prev = 0 if l2[i] < 0 else dp[l2[i]]
    dp[i] = (dp[i - 1] + prev) % mod
print(dp[-1])


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

long long a, b, dp[1005];
int main(){
	cin >> a >> b;
	for(int i = 1; i <= 1004; i++) dp[i] = dp[i-1]+i;
	for(int i = 1; i <= 1003; i++){
		if(dp[i]-a == dp[i+1]-b){
			cout << dp[i]-a;
			break;
		}
	}
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        string inpt = Reader.ReadLine();

        bool isGood = false;
        if(inpt.Skip(1).Distinct().Count() == 1) {
            isGood = true;
        }
        if(inpt.Take(3).Distinct().Count() == 1) {
            isGood = true;
        }

        string ans = isGood ? "Yes" : "No";
        Console.WriteLine(ans);
    }


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



1118



";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <queue>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define all(v) v.begin(),v.end()
#define show(v) for(int i = 0; i < v.size(); ++i){cout<<i<<": "<<v[i]<<" "<<endl;}
#define enld endl
#define INF 999999999
//----------------------------------------------------
struct edge { int to, cost; };//辺が伸びている頂点、その頂点までのコスト
typedef pair<int, int> P;//pair<最短距離,頂点番号>
int MAX_V;
int v;//頂点数
vector<edge> G[100010];//隣接リスト
vector<int> d(100010, INF);//頂点sからの最短距離
void Adjacent_List_Dijkstra(int s)
{
	priority_queue<P, vector<P>, greater<P>> que;
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); ++i)
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
//----------------------------------------------------
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int e, r; cin >> v >> e >> r;
	loop(i, e)
	{
		int s, t, d; cin >> s >> t >> d;
		edge tmp = { t,d };
		G[s].push_back(tmp);
	}
	Adjacent_List_Dijkstra(r);
	loop(i, v)
	{
		if (d[i] == INF) cout << "INF" << enld;
		else cout << d[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 12940
use std::io::stdin;
use std::io::BufRead;
fn main() {
  let mut v = String::new();
  stdin().read_line(&mut v);
  let m1 = v.split_whitespace().next().unwrap().parse::<usize>().unwrap();
  let mut vv = String::new();
  stdin().read_line(&mut vv);
  let m2 = vv.split_whitespace().next().unwrap().parse::<usize>().unwrap();
  println!("{}", (m1 != m2) as usize);
}

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

int main(){
  int n,x,i,j;
  int d[30];
  bool can[1000001];

  for(;;){
    cin >> n >> x;
    if(!n && !x)break;

    for(i=0;i<n;i++)cin >> d[i];
    for(i=1;i<=x;i++)can[i] = false;
    can[0] = true;

    for(i=0;i<n;i++){
      for(j=0;j+d[i]<=x;j++){
	if(can[j])can[j+d[i]] = true;
      }
    }

    if(!(x&1))x--;
    for(i=x;i>=0;i-=2)
      if(can[i] && i&1){
	bool f=true;
	for(j=3;j*j<=i;j+=2)
	  if(!(i%j)){
	    f = false;
	    break;
	  }
	if(f)break;
      }
    if(i<0)cout << "NA" << endl;
    else cout << i << endl;
  }
}

Measured memory_bytes: 0
from itertools import product

N,M = map(int,input().split())
sw = []
for i in range(M):
  sw.append(list(map(int,input().split()))[1:])
p = list(map(int,input().split()))

ans = 0

for state in product([0,1],repeat=N):
  f = True
  for i in range(M):
    tmp = 0
    for s in sw[i]:
      tmp += state[s-1]
    f = tmp % 2 == p[i]
    if not f:
      break
  if f:
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int A, B;
  cin >> A >> B;
  cout << A * B << endl;
  return 0;
}


Measured memory_bytes: 3640
N,K=map(int,input().split())
A=list(map(int,input().split()))
imos=[0 for i in range(N+1)]
ANS=[str(N)]*N
if K>=50:
  ans=" ".join(ANS)
  print(ans)
else:
  for t in range(K):
    for i in range(N):
      l=max(0,i-A[i])
      r=min(N,i+A[i]+1)
      imos[l]+=1
      imos[r]-=1
    for i in range(0,N):
      imos[i+1]+=imos[i]
      A[i]=imos[i]
    imos=[0 for i in range(N+1)]
  for i in range(N):
    A[i]=str(A[i])
  ans=" ".join(A)
  print(ans)  
      

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

using namespace std;

int main()
{
	int n, m, place = 1, sum = 0, i = 0;
	cin >> n;
	m = n;
	for (; m != 0; i++)
	{
		sum += m % 10;
		m = (m - m % 10) / 10;
	}
	if (n%sum == 0) cout << "Yes\n";
	else cout<< "No\n";
	return 0;
}

Measured memory_bytes: 256
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                var a = int.Parse(input[0]);
                var op = input[1];
                var b = int.Parse(input[2]);
                var result = 0;

                switch (op)
                {
                    case "+":
                        result = a + b;
                        break;
                    case "-":
                        result = a - b;
                        break;
                    case "*":
                        result = a * b;
                        break;
                    case "/":
                        result = a / b;
                        break;
                    default:
                        return;
                }
                Console.WriteLine(result);
            }

        }
    }
}

Measured memory_bytes: 5712
package main

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

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)
	var N, M, C int
	if scanner.Scan() {
		str := scanner.Text()
		cols := strings.Split(str, " ")
		N, _ = strconv.Atoi(cols[0])
		M, _ = strconv.Atoi(cols[1])
		C, _ = strconv.Atoi(cols[2])
	}

	B := make([]int, M)
	if scanner.Scan() {
		str := scanner.Text()
		cols := strings.Split(str, " ")
		for j := 0; j < M; j++ {
			B[j], _ = strconv.Atoi(cols[j])
		}
	}

	var sum int
	for i := 0; i < N; i++ {
		var F int
		if scanner.Scan() {
			str := scanner.Text()
			cols := strings.Split(str, " ")
			for j := 0; j < M; j++ {
				a, _ := strconv.Atoi(cols[j])
				F += B[j] * a
			}
			F += C
		}
		if F > 0 {
			sum++
		}

	}

	fmt.Fprintln(wtr, sum)
	_ = wtr.Flush()
}


Measured memory_bytes: 640
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
H = III()

ans = 0
temp = 0
for i in range(1,N)[::-1]:
    if H[i] <= H[i-1]:
        temp += 1
    else:
        if ans < temp:
            ans = temp
        temp = 0

print(max(ans,temp))

Measured memory_bytes: 63984
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
ll high_order_bit(ll n){
    ll tmp=1,i=-1;
    while(tmp<=n){
        tmp*=2;
        i++;
    }
    if(n==0) return 0;
    else return i;
}
vector<ll> binary_expansion(ll n){
    vector<ll> B(high_order_bit(n)+1);
    ll tmp=n;
    for(ll i=high_order_bit(n);i>=0;i--){
        B[i]=tmp/pw2[i];
        tmp%=pw2[i];
    }
    return B;
}
vector<ll> divisor(ll x){
    vector<ll> div;
    for(int i=1;i*i<=x;i++){
        if(i*i!=x && x%i==0){
            div.pb(i);
            div.pb(x/i);
        }
        else if(x%i==0) div.pb(i);
    }
    return div;
}
vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}

int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    ll ans=0;
    rep1(i,N){
        if((i%3 != 0) && (i%5!=0)) ans+=i;
    }
    cout<<ans;
}

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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<int> to(n + 1);
  to[0] = 1;
  range(i, 1, n + 1) to[i] = to[i - 1] * 3;

  string a;
  cin >> a;
  int sz = a.length();

  vector<int> p; // 3^n
  vector<int> pos; // sz
  p.resize(1);
  pos.resize(sz);

  for(int ex = 1; ex <= n; ex++) {
    int total = 0;
    vector<int> add(to[ex]);
    range(i, 0, to[ex]) add[i] = i / to[ex - 1];

    p.resize(to[ex]);
    range(i, to[ex - 1], to[ex]) p[i] = p[i % to[ex - 1]];

    vector<int> new_pos(sz);

    for(int i = 0; i < sz; i++) {
      {
        int ps = pos[i];
        assert(~ps);
        for(int j = ps; j <= ps + 2 * to[ex - 1]; j += to[ex - 1]) {
          int c = add[j];
          if(total) {
            if(c > 0) c = 3 - c;
          }
          if(c == 2) new_pos[i] = j;
        }
      }
      char com = a[i];
      if(com == 'S') {
        total ^= 1;
      } else {
        int ps = pos[i];
        assert(~ps);
        int ter = -1;
        for(int j = ps; j <= ps + 2 * to[ex - 1]; j += to[ex - 1]) {
          int c = add[j];
          if(total) {
            if(c > 0) c = 3 - c;
          }
          c = (c + 1) % 3;
          if(total) {
            if(c > 0) c = 3 - c;
          }
          add[j] = c;
        }
      }
    }

    if(total) {
      for(int i = 0; i < to[ex]; i++) {
        if(add[i] > 0) add[i] = 3 - add[i];
      }
    }

    for(int i = 0; i < to[ex]; i++) {
      p[i] += add[i] * to[ex - 1];
    }

    swap(pos, new_pos);
  }
  for(int i : p) cout << i << " ";
  return 0;
}


Measured memory_bytes: 11456
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a,b,c,d;
    string s,t;

    cin >> a >> b;//>> c >> d;
    //cin >> s >> t;
    cout << a * a - b << endl;

    return 0;
}

Measured memory_bytes: 256
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>

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

#define int long long

using namespace std;

int prime[200];
bool is_prime[1010];

int sieve(int n) {
    int p = 0;
    for (int i=0; i<=n; i++) is_prime[i] = true;
    for (int i=2; i<=n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j=2*i; j<=n; j+=i) is_prime[j] = false;
        }
    }
}

vector<int> primeFactorization(int n)
{
    vector<int> ret;
    int p = 0;
    while (n > 1) {
        while (n % prime[p] == 0) {
            ret.push_back(prime[p]);
            n /= prime[p];
        }
        p++;
    }
    return ret;
}

void printV(vector<int> vi)
{
    rep(i,vi.size()) {
        cout << vi[i] << " ";
    }
    cout << endl;
}

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int N;
    map<int, int> cnt;

    cin >> N;

    sieve(1000);

    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }

    for (int i=2; i<=N; i++) {
        vector<int> factors = primeFactorization(i);
        rep(j,factors.size()) {
            cnt[factors[j]]++;
        }
    }

    int ans = 1;
    for (map<int, int>::iterator it = cnt.begin(); it != cnt.end(); it++) {
        ans *= (it->second + 1);
        ans %= 1000000007;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n, t = map(int, input().split())
dices = map(int, input().split())
avg = list(map(lambda n: (n+1)/2, dices))
s = prev = sum(avg[0:t])

for i in range(1, n-t+1):
  prev = prev - avg[i-1] + avg[i+t-1]
  s = max(s, prev)
print(s)


Measured memory_bytes: 23524
package main

import (
	"bufio"
	"fmt"
	"log"
	"math/big"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	a := new(big.Int)
	a, ok := a.SetString(input(), 10)
	if !ok {
		log.Fatalln("SetString: error")
	}

	b := new(big.Int)
	b, ok = b.SetString(input(), 10)
	if !ok {
		log.Fatalln("SetString: error")
	}

	result := a.Cmp(b)

	if result == 1 {
		fmt.Println("GREATER")
	} else if result == 0 {
		fmt.Println("EQUAL")
	} else {
		fmt.Println("LESS")
	}
}


Measured memory_bytes: 640
(* O(n log n) *)
let n = read_int ()
let primes n =
  if n <= 1 then [|false; false|]
  else
    let flags = Array.make (n + 1) true in
    flags.(0) <- false; flags.(1) <- false;
    for i = 2 to n do
      if flags.(i) then
        let j = ref @@ i + i in
        while !j <= n do flags.(!j) <- false; j := !j + i done done;
    flags
let rec ord_fact i n = let rec f m = if n / m = 0 then 0 else n / m + f (m * i) in f i
let ans = ref 1
let _ =
  Array.iteri (fun i b -> if b then ans := !ans * (ord_fact i n + 1) mod 1_000_000_007) @@ primes n;
  Printf.printf "%d\n" @@ !ans

Measured memory_bytes: 384
#include <iostream>
#include<math.h>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main() {

    vector<int> R(3);

    cin >> R[0] >> R[1] >> R[2];

    sort(R.begin(), R.end());
    cout << R[0] * R[1] / 2 << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
r,s,p = map(int,input().split())
points = {'r':r, 's':s, 'p':p}
hands = {'r':'p', 's':'r', 'p':'s'}
t = list(input())
rpsList = ['']*n
ans = 0

for i,hand in enumerate(t):
    rpsList[i] += hands[hand]
    if i>=k and rpsList[i]==rpsList[i-k]:
        last_hand= rpsList[i-k]
        next_hand = hands[t[i+k]] if i+k<n else ''
        for j in ['r','s','p']:
            if j!=last_hand and j!=next_hand:
                rpsList[i] = j
    else:
        ans += points[hands[hand]]

print(ans)

Measured memory_bytes: 10556
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main(){
    int a;
    int b;
    cin >> a >> b;
    if(a<=8 && b<=8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vi cnt(n, 0);
  rep (i, m) {
    int a, b;
    scanf("%d%d", &a, &b);
    cnt[a-1] += 1;
    cnt[b-1] += 1;
  }
  rep (i, n) {
    if (cnt[i] % 2 == 1) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");

  return 0;
}


Measured memory_bytes: 640
n = int(input())

def factorization(n):
    arr = []
    tmp = n
    for i in range(2, int(n**0.5)+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            arr.append([i, cnt])

    if tmp != 1:
        arr.append([tmp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr

if n == 1:
    print(0)
    exit()

arr = factorization(n)
#print(arr)

ans = 0
for x, cnt in arr:
    for i in range(100):
        if i * (i - 1) // 2 <= cnt < i * (i + 1) // 2:
            ans += i - 1
            break

print(ans)

Measured memory_bytes: 9488
#include <iostream>
#include <stdio.h>
#define MAX 100005
#define NIL -1

struct Node {
    int parent, left, right;
};

Node T[MAX];
int n, D[MAX];

void rec(int u, int p) {
    D[u] = p;
    if (T[u].right != NIL) rec(T[u].right, p);
    if (T[u].left  != NIL) rec(T[u].left, p+1);
}

void printChildren (int id) {
    printf("node %d: parent = %d, depth = %d, ", id, T[id].parent, D[id]);
    if (T[id].left != NIL || T[id].parent == NIL) {
        if (T[id].parent == NIL) printf("root, [");
        else printf("internal node, [");
        int pri_ch = T[id].left;
        while (pri_ch != NIL) {
            printf("%d", pri_ch);
            pri_ch = T[pri_ch].right;
            if (pri_ch != NIL) printf(", ");
        }
        printf("]");
    } else {
        printf("leaf, []");
    }
    printf("\n");
}


int main() {
    int id;
    int num_ch;
    int ch_id;
    int left = 0;
    int root = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) T[i].parent = T[i].left = T[i].right = NIL;
    
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &id, &num_ch);
        for (int j = 0; j < num_ch; j++) {
            scanf("%d", &ch_id);
            if(j==0) T[id].left = ch_id;
            else T[left].right = ch_id;
            left = ch_id;
            T[ch_id].parent = id;
        }
    }
    
    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) root = i;
    }
    
    rec(root, 0);
    for (int i = 0; i < n; i++) {
        printChildren(i);
    }
    
    return 0;
}

Measured memory_bytes: 7800
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch DivideTheProblems | diff DivideTheProblems.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address DivideTheProblems.cpp && ./a.out

/*
 
 6/29/2019
 
 5:06-5:10 WA
 5:14
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

int solve__() {
  sort(A,A+N);
  int res=0;
  REPE(K,1e5) {
    auto p=lower_bound(A,A+N,K)-A;
    if(p==N/2) ++res;
  }
  return res;
}

int solve() {
  sort(A,A+N);
  int p=N/2;
  if(A[p]==A[p-1]) return 0;
  return A[p]-A[p-1];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  cout<<solve()<<endl;
  
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
public class Test
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] p = new int[n + 1];
        for (int i = 0; i < n; i++)
        {
            var tmp = int.Parse(Console.ReadLine());
            p[tmp] = p[tmp - 1] + 1;
        }
        Console.WriteLine(n - p.Max());
    }
}

Measured memory_bytes: 17336
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, 10000)
	// scanner.Buffer(buf, 1000000)
	return scanner
}

func scanInt() int {
	if sc.Scan() {
		t := sc.Text()
		if v, err := strconv.Atoi(t); err == nil {
			return v
		}
		panic(fmt.Sprintln("Could't scan int from input", t))
	}
	panic(sc.Err())
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

var sc *bufio.Scanner = newScanner()

func main() {
	n := scanInt()
	a := scanInts(n)

	var r, sum, ans int
	for i := 0; i < n; i++ {
		for r < n && sum&a[r] == 0 {
			sum += a[r]
			r++
		}
		ans += r - i
		sum -= a[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3840
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<unordered_set>
#include<cmath>
#include<tuple>
#include<numeric>
#include<iterator>
#include<set>
#include<unordered_map>
#include<map>
#include<queue>
#include<cstring>
#include<stdio.h>
#include<fstream>


#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define foru(i , a , b) for(ll i = a ; i < b ; i++)
#define ford(i , a , b) for(ll i = a ; i >= b ; i--)
#define dbg(a) cerr << #a << ": " << a << "\n";
#define ain(a , n) for(ll i = 0 ; i < n ; i++) cin >> a[i]
#define aout(a , n) for(ll i = 0 ; i < n ; i++) cout << a[i] << " "
#define M 1000000007
#define mp make_pair
#define mt make_tuple
#define cend cout << "\n"
#define all(x) x.begin() , x.end()
#define aout2(a , n , m) for(ll i = 0 ; i < n ; i++){for(ll j = 0 ; j < m ; j++){cout << a[i][j] << " ";} cout << endl;}
#define ain2(a , n , m) for(ll i = 0 ; i < n ; i++){for(ll j = 0 ; j < m ; j++){cin >> a[i][j];}}
#define ff first
#define ss second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <char> vch;
typedef vector <string> vs;

/*----------------------------- # --- MATH ALGORITHMS --- # -----------------------------*/

template <class T> T gcd(T a , T b){ while(a != 0){T temp = a; a = b % a; b = temp;}return b;}
template <class T> T egcd(T a , T b , T &x , T &y){T gcd , xt , yt;if(a == 0){gcd = b;x = 0 , y = 1;}else {gcd = egcd(b % a , a , xt , yt);x = yt - (b/a)*xt; y = xt;}return gcd;}
template <class T> T expo(T base , T exp , T mod){T res = 1;base = base % mod;while (exp > 0){if (exp & 1)res = (res*base) % mod;exp = exp>>1;base = (base*base) % mod;}return res;}
template <class T> T modinv(T a , T mod){T x , y; egcd<T>(a , mod , x , y);while(x < 0) x += mod; while(x >= mod) x -= mod; return x;}
template <class T> T modinvfermat(T a , T mod){return expo<T>(a , mod - 2 , mod);}
template <class T> bool rev(T a , T b){return a > b;}
template <class T> ll maxpower(T a , T b){ll ans = 0;while(a > 0 && a % b == 0){ans++;a /= b;}return ans;}


/*----------------------------- # --- MAIN CODE --- # -----------------------------*/

int main(){
    fastio;
#ifndef ONLINE_JUDGE
    freopen("testcase.txt" , "r" , stdin);
    freopen("error.txt" , "w" , stderr);
    freopen("output.txt" , "w" , stdout);
#endif
    double r;cin>>r;
    cout << 2* 3.14159265*r;
}
























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

using namespace std;

int main(){
    int n, suma = 0,suma2 = 0, a;
    vector<int> v;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a;
        v.push_back(a);
        suma+=a;
    }
    sort(v.begin(), v.end());
    if(suma % 10 == 0){
        for (int i = 0; i < n; i++){
            suma -= v[i];
            suma2 += v[i];
            if(v[i] < suma2 && (suma + suma2 - v[i]) % 10 != 0){
                suma += suma2 -v[i];
                break;
            }
            
            if(suma % 10)            
                break;
        }
    }
    cout << suma;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> H(N); rep(i, N){cin >> H.at(i);}
    ll prev = H.at(N-1);
    bool flag = true;
    rrep(i, N-2, 0){
        if (H.at(i) > prev + 1){
            flag = false;
            break;
        } else if (H.at(i) == prev + 1){
            prev = H.at(i) - 1;
        } else {
            prev = H.at(i);
        }
    }
    if (flag) {cout << "Yes" << endl;} else {cout << "No" << endl;}
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1024
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
pp=gsmi
q=gsmi
dict=(1..n).to_a.permutation(n).collect{|a|a}

i=dict.index(pp)
i2=dict.index(q)
puts (i-i2).abs

Measured memory_bytes: 6780
use std::str::FromStr;
use std::cmp::max;
use std::cmp::min;

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let v : Vec<i32> = get_vec();
    println!("{}", max(0,min(v[1],v[3]) - max(v[0],v[2])));

}

Measured memory_bytes: 4352
import sys
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

X=int(input())
ans=[0]*2
for i in range(0,1000):
    for j in range(i+1,1001):
        if(j**5-i**5==X):
            ans[0]=j
            ans[1]=i

for i in range(0,1001):
    for j in range(i+1,1001):
        if(j**5+i**5==X):
            ans[0]=j
            ans[1]=-i


print(*ans)

Measured memory_bytes: 9252
#include<bits/stdc++.h>
using namespace std;
int n, a[1100000], c, g[20],r,i,j;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	g[0] = 1;
	c = 0;
	while (true)
	{
		g[c + 1] = g[c] * 3 + 1;
		if (g[++c] >= n)
			break;
	}
	r = 0;
	for (i = c - 1; i >= 0; i--)
	{
		for (j = g[i]; j < n; j++)
		{
			int v = a[j], w = j - g[i];
			while (w >= 0 && a[w] > v)
			{
				a[w + g[i]] = a[w];
				w -= g[i];
				r++;
			}
			a[w + g[i]] = v;
		}
	}
	cout << c << endl;
	for (int i = c - 1; i >= 0; i--)
		printf(i ? "%d " : "%d\n", g[i]);
	cout << r << endl;
	for (int i = 0; i < n; i++)
		printf("%d\n", a[i]);
}


Measured memory_bytes: 7132
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

ll calc(const ll N, const ll M) {
    ll ans = 0;

    // (1) the first line
    {
        // left
        ;
        // middle
        ;
        // right
        ;
    }

    // (2) the middle line
    {
        // left
        ;
        // middle
        if (N >= 3 && M >= 3) {
            ans += (N - 2) * (M - 2);
        }
        // right
        ;
    }

    // (3) the bottom line
    {
        // left
        ;
        // middle
        ;
        // right
        ;
    }

    return ans;
}

int main(void) {
    ll N, M;
    cin >> N >> M;
    // assume that N <= M
    if (N > M) {
        swap(N, M);
    }

    ll ans = 0;

    if (N == 1) {
        if (M == 1) {
            ans = 1;
        } else if (M == 2) {
            ans = 0;
        } else {
            ans = M - 2;
        }
    } else {
        ans = calc(N, M);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3552
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>


using namespace std;

char N[101],len;

int K,i,j,k,memo[101][2][4],num;

int dp(int n,int m,int u)
{
  if(memo[n][m][u]!=-1)
  {
    return memo[n][m][u];
  }
  
  int s,t;
  
  if(m==1)
  {
    if(N[n]-'0'==0)
    {
      s=dp(n-1,m,u);
      memo[n][m][u]=s;
      return s;
    }
    else if(u>0)
    {
      s=dp(n-1,m,u-1);
      memo[n][m][u]=s;
      return s;
    }
  }
  
  if(m==0)
  {
    s=dp(n-1,m,u);
    if(u>0)
    {
      s+=dp(n-1,m,u-1)*9;
    }
    
    if(N[n]-'0'>0)
    {
      s+=dp(n-1,1,u);
      if(u>0)
      {
        s+=dp(n-1,1,u-1)*(N[n]-'0'-1);
      }
    }   
    
    memo[n][m][u]=s;
    
    return s;
    
  }
  
  
  
  
}


int main()
{

  cin >>N>>K;
  
  len=strlen(N);
  
  for(i=0;i<len;i++)
  {
    for(k=0;k<4;k++)
    {
      memo[i][0][k]=-1;
      memo[i][1][k]=-1;
    }
    memo[i][0][0]=1;
    memo[i][1][0]=0;

  }
  
  memo[0][0][0]=1;
  memo[0][0][1]=N[0]-'0'-1;
  memo[0][1][1]=1;
  
  memo[0][1][0]=0;
  
  for(i=2;i<4;i++)
  {
    memo[0][0][i]=0;
    memo[0][1][i]=0;
  }
  
  cout << dp(len-1,0,K)+dp(len-1,1,K);
  
  
  
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
    int n,q;
    cin >> n;
    vector<int> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> q;
    vector<int> t(q);
    for(int i=0;i<q;i++){
        cin >> t[i];
    }
    int ans=0;
    for(int i=0;i<q;i++){
        auto itr = binary_search(s.begin(),s.end(),t[i]);
        ans += itr;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

signed main () {
    int temp;cin >> temp;
    if(temp>=30)cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
  int N,k=0;
  bool a=false,b=false,c=false,d=false;
  string s;
  
  cin>>N;
  
  for(int i=0;i<N;i++){
    cin>>s;
    if(s=="P"){
      if(a){continue;}
      k++;a=true;
    }else if(s=="W"){
      if(b){continue;}
      k++;b=true;
    }else if(s=="Y"){
      if(c){continue;}
      k++;c=true;
    }else {
      if(d){continue;}
      k++;d=true;
    }
  }
  
  if(k==3){cout<<"Three"<<endl;}
  if(k==4){cout<<"Four"<<endl;}
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main(){
    int n,m;
    while(cin>>n>>m,n || m){
        queue<int>Q;
        int field[10000];
        for(int i=0;i<10000;i++)field[i]=0;
        for(int i=0;i<n;i++)cin>>field[i];
        for(int i=0;i<m;i++){
            int a;
            cin>>a;
            Q.push(a);
        }
        int cnt=0,pnt=0;
        while(Q.size()){
            cnt++;
            pnt+=Q.front();
            pnt+=field[pnt];
            Q.pop();
            if(pnt>=n)break;
        }
        cout<<cnt<<endl;


    }
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll dp[200010][2];

void solve() {
    string S;
    cin >> S;
    ll n = (ll)S.size();

    for (ll i = 0; i < n; i++) {
        if (i - 1 >= 0 && S[i] != S[i - 1]) {
            chmax(dp[i + 1][0], dp[i][0] + 1);
        }
        chmax(dp[i + 1][0], dp[i][1] + 1);
        if (i - 2 >= 0) {
            chmax(dp[i + 1][1], dp[i - 1][0] + 1);
            chmax(dp[i + 1][1], dp[i - 1][1] + 1);
        }
    }
    prints()(max(dp[n][0], dp[n][1]));
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(nullptr), cout.tie(nullptr);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 6924
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
  A, B, C, D = map(int, input().split())

  a = A
  c = C
  for i in range(200):
    if i%2 == 0:
      c -= B
      if c <= 0:
        print('Yes')
        return
    else:
      a -= D
      if a <= 0:
        print('No')
        return

if __name__ == '__main__':
  main()

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

#define int long long
const int MOD=1e9+7;
int pw(int n,int k){
  assert(k>=0);
  int res=1;
  while(k){
    if(k&1)(res*=n)%=MOD;
    (n*=n)%=MOD;
    k>>=1;
  }
  return res;
}
std::vector<int> Factorial(5e6),Finverse(5e6);
inline void Cinit(){// limit is 5e6 /// write pw /// this takes 792ms at AtCoder
  Factorial[0]=1;
  for(int i=1;i<5e6;i++)Factorial[i]=(Factorial[i-1]*i)%MOD;
  for(int i=0;i<5e6;i++)Finverse[i]=pw(Factorial[i],MOD-2);
}
int nCk(int n,int k){
  if(n<k)return 0;if(k<0)return 0;
  if(!Factorial[0])Cinit();
  int res=Factorial[n];
  (res*=Finverse[k])%=MOD;
  (res*=Finverse[n-k])%=MOD;
  return res;
}
/*
大きい方から見てi番目(1-indexed)のやつがDとして加算されるのは
nCk(i-1,D-1)*pw(N-i)通り
つまり
REP(i,1~N){
  REP(D,1~i){
    ans+=D*nCk(i-1,D-1)*pw(2,N-i)*v[i];
  }
}

REP(D,1~i)D*nCk(i-1,D-1)=REP (D-1)*nCk(i-1,D-1) + nCk(i-1,D-1)

REP (D-1)*nCk(i-1,D-1)=(i-1)*1/2*pw(2,i-1)
REP nCk(i-1,D-1)=pw(2,i-1)
*/
int X(int a,int b){
  return a*b%MOD;
}
int X(int a,int b,int c){
  return X(X(a,b),c);
}


signed main(){
  int n;cin>>n;
  vector<int>v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.rbegin(),v.rend());
  int ans=0;
  for(int i=1;i<=n;i++)
    (ans+=X(X(i-1,pw(2,MOD-2),pw(2,i-1))+pw(2,i-1),pw(2,n-i),v[i-1]))%=MOD;
  cout<<X(ans,pw(2,n))<<endl;
}


Measured memory_bytes: 80000