akhauriyash/Code-Regression huggingface dataset:
# A
n = input()

if n[-1] == '2' or n[-1] == '4' or n[-1] == '5' or n[-1] == '7' or n[-1] == '9':
    print('hon')
elif n[-1] == '0' or n[-1] == '1' or n[-1] == '6' or n[-1] == '8':
    print('pon')
elif n[-1] == '3':
    print('bon')

Measured memory_bytes: 9128
#include<stdio.h>
#include<string.h>
int main()
{
    long n;
    scanf("%ld", &n);
    char s[100001][7];
    printf("0\n");
    fflush(stdout);
    scanf("%s", s[0]);
    if (s[0][0] == 'V')
        return 0;
    int i;
    long min = 0, max = n;
    for (i = 1; i < 19; i++)
    {
        printf("%ld\n", (max + min) / 2);
        fflush(stdout);
        scanf("%s", s[(max+min)/2]);
        if (s[(max+min)/2][0] == 'V')
            break;
        if (((long)((max+min)/2)-min) % 2 == 0)
        {
            if (s[min][0] == s[(max+min)/2][0])
                min = (max + min) / 2;
            else
                max = (max + min) / 2;
            continue;
        }
        else
        {
            if (s[min][0] == s[(max+min)/2][0])
                max = (max + min) / 2;
            else
                min = (max + min) / 2;
            continue;
        }
    }
    return 0;

}

Measured memory_bytes: 852
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
#define INF 100000000
using namespace std;
typedef pair<string,int>P;

int bfs(string worm){
  queue<P>que;
  map<string,int>d;
  que.push(P(worm,0));
  while(!que.empty()){
    P p = que.front(); 
    string str = p.first;
    que.pop();
    if(d[p.first])continue;

    bool flag = false;
    for(int i = 0 ; i < str.size()-1 ; i++ ) {
      if(str[i] != str[i+1]){
	flag = true;
	break;
      }
    }
    if(!flag)return p.second;
    d[p.first] = p.second;
    for(int i = 0 ; i < str.size()-1 ; i++ ){
      if(str[i]!=str[i+1]){
	char tmp;
	if(str[i] != 'r' && str[i+1] != 'r' ){
	  tmp = 'r';
	}else if(str[i] != 'g' && str[i+1] != 'g'){
	  tmp = 'g';
	}else {
	  tmp = 'b';
	}
	string next = str;
	next[i] = next[i+1] = tmp; 
	que.push(P(next,p.second+1));
      }
    }
  }
  return -1;
}

int main(){
  string worm;
  while(cin >> worm){
    if(worm[0] == '0')break;
    int res = bfs(worm);
    if(res>=0)cout << res << endl;
    else cout << "NA" <<endl;
  }
  return 0;
}

Measured memory_bytes: 3192
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	double p=0.01*b;
	double ret=0;
	if(a%2){
		ret=p*(1+(a-1)/2/p)+(1-p)*(1+(a+1)/2/p);
	}else{
		ret=a/2/p;
	}
	printf("%.12f\n",ret);
}

Measured memory_bytes: 128
import collections
def solve():
    _ = input()
    v = list(map(int, input().split()))
    if v.count(v[0]) == len(v):
        print(len(v) // 2)
        return
    even = v[0::2]
    odd = v[1::2]
    even_cnt = list(sorted(collections.Counter(even).items(), key=lambda x: x[1], reverse=True))
    odd_cnt = list(sorted(collections.Counter(odd).items(), key=lambda x: x[1], reverse=True))
    ev = even_cnt[0][0]
    od = odd_cnt[0][0]
    if even_cnt[0] == odd_cnt[0]:
        if len(even_cnt) == 1:
            ev = even_cnt[1][0]
        elif len(odd_cnt) == 1:
            od = odd_cnt[1][0]
        elif even_cnt[1][1] > odd_cnt[1][1]:
            ev = even_cnt[1][0]
        else:
            od = odd_cnt[1][0]
    print(len(even) - even.count(ev) + len(odd) - odd.count(od))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 21212
N = int(input())
A = [int(input()) for _ in range(N)]

sum_A = sum(A)
MOD = 998244353

dp1 = [0] * (sum_A + 1)
dp2 = [0] * (sum_A + 1)
dp1[0] = dp2[0] = 1
tmp_sum = 0

for a in A:
    for i in reversed(range(tmp_sum + 1)):
        dp1[i] %= MOD
        dp2[i] %= MOD
        dp1[i + a] += dp1[i]
        dp1[i] <<= 1
        dp2[i + a] += dp2[i]
    tmp_sum += a


ans = pow(3, N, MOD)
for i in range(sum_A + 1):
    if i * 2 >= sum_A:
        ans = (ans - dp1[i] * 3 + MOD * 3) % MOD
    if i * 2 == sum_A:
        ans = (ans + dp2[i] * 3) % MOD
print(ans)


Measured memory_bytes: 42204
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int N;

    scan(N);

    int ans;

    foreach (i ; 0 .. N) {
        int li, ri;
        scan(li, ri);
        ans += ri - li + 1;
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct SegmentTree {
private:
    int n;
    vector<ll> node;
 
public:
    SegmentTree() {
        int sz = 300005;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);
        for(int i=0; i<sz; i++) node[i+n-1] = 0;
        for(int i=n-2; i>=0; i--) node[i] = (node[2*i+1] + node[2*i+2]);
    }
 
    void update(int x, ll val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = (node[2*x+1] + node[2*x+2]);
        }
    }
    // hannkaikukann 
    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];
 
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return (vl + vr);
    }
};


int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    int a[4][100500];
    for(int i = 1; i <= 3; i++){
        for(int j = 1; j <= n; j++){
            cin >> a[i][j];
        }
    }
    ll OddReverse = 0, EvenReverse = 0;
    for(int i = 1; i <= n; i += 2){
        if(a[1][i] % 6 == 1){
            if((a[2][i] - a[1][i] != 1) || (a[3][i] - a[2][i] != 1)){
                cout << "No" << endl;
                return 0;
            }
            continue;
        }
        if(a[1][i] % 6 == 3){
            if((a[2][i] - a[1][i] != -1) || (a[3][i] - a[2][i] != -1)){
                cout << "No" << endl;
                return 0;
            }
            OddReverse++;
            continue;
        }
        cout << "No" << endl;
        return 0;
    }
    for(int i = 2; i <= n; i += 2){
        if(a[1][i] % 6 == 4){
            if((a[2][i] - a[1][i] != 1) || (a[3][i] - a[2][i] != 1)){
                cout << "No" << endl;
                return 0;
            }
            continue;
        }
        if(a[1][i] % 6 == 0){
            if((a[2][i] - a[1][i] != -1) || (a[3][i] - a[2][i] != -1)){
                cout << "No" << endl;
                return 0;
            }
            EvenReverse++;
            continue;
        }
        cout << "No" << endl;
        return 0;
    }
    //cout << OddReverse << " " << EvenReverse << endl;
    SegmentTree odd, even;
    ll OddInversion = 0, EvenInversion = 0;
    for(int i = 1; i <= n; i += 2){
        int now = a[1][i];
        OddInversion += odd.getsum(now, 300001);
        odd.update(now, 1);
    }
    for(int i = 2; i <= n; i += 2){
        int now = a[1][i];
        EvenInversion += even.getsum(now, 300001);
        even.update(now, 1);
    }
    //cout << OddInversion << " " << EvenInversion << endl;
    if((OddInversion % 2) != (EvenReverse % 2)){
        cout << "No" << endl;
        return 0;
    }
    if((EvenInversion % 2) != (OddReverse % 2)){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 17792
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

prev = -1
ans = 0
a.each do |i|
  ans += b[i-1]
  ans += c[prev-1] if prev == i-1
  prev = i
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 int a, b;
 cin >> a >> b;
 if(a-2*b>0) cout << a-2*b;
 else cout << 0;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>

int ctoi(char c) {
    return c - '0';
}

int main() {
    char t[20];
    scanf("%s", t);
    int l = strlen(t);
    int m1 = 0, m2 = ctoi(t[0])-1+9*(l-1);
    for (int i = 0; i < l; i++) {
        m1 += ctoi(t[i]);
    }
    if (m1 < m2) {
        m1 = m2;
    }
    printf("%d\n", m1);
    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(abs(a-c)<=d) {
    cout << "Yes" << endl;
    return 0;
  }
  if(abs(a-b)<=d&&abs(b-c)<=d) {
    cout << "Yes" << endl;
    return 0;
  }
  else {
    cout << "No" << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L


int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int x, y, k;
        cin >> x >> y >> k;
        x--;y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int ans = 0;
    vector<bool> visited(n);
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            ans++;
            queue<int> q;
            q.push(i);
            visited[i] = true;
            while (!q.empty()) {
                int u = q.front(); q.pop();
                for (auto v : g[u]) {
                    if (visited[v]) continue;
                    q.push(v);
                    visited[v] = true;
                }
            }
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 9592
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
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;
}

vector<long long> dev;
vector<int> id;

void prime_factor(long long N){
    for(int i=2;(long long)i*i<=N;i++){
        int cnt = 0;
        while(N%i == 0){
            cnt++;
            N /= i;
        }
        if(cnt){
            dev.push_back(i);
            id.push_back(cnt);
        }
    }
    if(N != 1){
        dev.push_back(N);
        id.push_back(1);
    }
    return;
}
int main(){
    ll n;
    cin >> n;
    prime_factor(n);
    int res = 0;
    for(auto x:id){
        int K = 0;
        for(int i=1;i<=1000000;i++){
            if(K+i>x){
                break;
            }else{
                K += i;
                res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3180
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

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

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	S := readBytes()
	a := make([]int64, len(S))

	for i := range a {
		a[i] = int64(S[i] - '0')
	}

	var ans int64
	var rec func(accm, bccm int64, a []int64)
	rec = func(accm, bccm int64, a []int64) {
		if len(a) == 0 {
			ans += accm + bccm
			return
		}
		rec(accm, bccm*10+a[0], a[1:])
		rec(accm+bccm, a[0], a[1:])
	}

	rec(0, a[0], a[1:])
	println(ans)
}

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


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

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[][] A = new int[2][N];
		A[0] = nextIntArray(sc, N);
		A[1] = nextIntArray(sc, N);

		sc.close();

		int[][] dp = new int[2][N];
		dp[0][0] = A[0][0];
		dp[1][0] = dp[0][0] + A[1][0];

		for (int i = 1; i < N; i++) {
			dp[0][i] = dp[0][i - 1] + A[0][i];
			dp[1][i] = Math.max(dp[0][i], dp[1][i - 1]) + A[1][i];
		}

		out.println(dp[1][N - 1]);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	set<string> cnt;
	string now;
	bool flag=true;
	rep(i,n){
		string s;cin>>s;
		if(i==0){
			cnt.insert(s);
			now=s;
		}else{
			if(cnt.find(s)!=cnt.end()){
				flag=false;
			}
			if(now.back()!=s[0]){
				flag=false;
			}
			cnt.insert(s);
			now=s;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
import numpy as np
from numba import njit
R,C,K=map(int,input().split())
vl=np.zeros((R,C), np.int64)
for _ in range(K):
  r,c,v=map(int,input().split())
  vl[r-1][c-1]=v
@njit
def main():
  dp=np.zeros((R+1,C+1,4), np.int64)
  for i in range(1,R+1):
    for j in range(1,C+1):
      for k in range(4):
        dp[i][j][k]=max(dp[i][j-1][k],dp[i-1][j][3])
      for k in range(3,0,-1):
        dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]+vl[i-1][j-1])
  return dp[R][C][3]
print(main())



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



string s;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>s;

    if (s[2]==s[3] && s[4]==s[5]) out("Yes");
    out("No");
  

    return 0;
}


Measured memory_bytes: 256
n = int(input())
ans = []

if n == 0:
	print(0)
else:

	i = 0
	#num = 0
	while n != 0:
		if n % (2 ** (i + 1)) != 0:
			ans.append("1")
			n -= (-2) ** i
		else:
			ans.append("0")

		i += 1

	print("".join(ans[::-1]))

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
private static final int _8KETA = 100000000;
// あえてBigIntegerは使わない方法で
public static void main(String[] args) {
  Scanner in = new Scanner(System.in);

  for (int dataSet = in.nextInt(); dataSet > 0; dataSet--) {
	String a = in.next();
	String b = in.next();
	boolean isOverflow = a.length() > 80 || b.length() > 80;
	int[] cal = new int[10];
	if (!isOverflow) {
	  int[] aVal = makeIntArray(a);
	  int[] bVal = makeIntArray(b);
	  for (int i = 0; i < 10; i++) {
		int ai = aVal[i];
		int bi = bVal[i];
		int cali = ai + bi;
		cal[i] = cali % _8KETA;
		if (cali >= _8KETA) {
		  if (i == 9) isOverflow = true;
		  else aVal[i + 1] += cali / _8KETA;
		}
	  }
	}
	if (isOverflow) {
	  System.out.println("overflow");
	} else {
	  StringBuilder sb = new StringBuilder();
	  for (int i = 0; i < 10; i++) {
		sb.insert(0, cal[i]);
		if (cal[i] < 1000000) {
		  sb.insert(0, "00000000", 0, 8 - (sb.length() % 8));
		}
	  }
	  while (sb.charAt(0) == '0' && sb.length() != 1) {
		sb.deleteCharAt(0);
	  }
	  System.out.println(sb);
	}
  }
}

private static int[] makeIntArray(String a) {
  int[] val = new int[10];
  StringBuilder sb = new StringBuilder(a)
	  .insert(0, "        ", 0, 8 - a.length() % 8);
  int keta8x = sb.length() / 8;
  for (int i = keta8x; i > 0; i--) {
	String trim = sb.substring((i - 1) * 8, i * 8).trim();
	if (!"".equals(trim)) {
	  val[keta8x - i] = Integer.parseInt(trim);
	}
  }
  return val;
}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
// #pragma GCC optimize ("-O3")
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long double PI = 3.14159265358979323846;  /* pi */

int main() {
    long long n;
    cin >> n;
    vector<long long> ans(n + 1, 0);
    for (long long x = 1; x <= n; x++)
    {
        long long x2 = x * x;
        if (x2 > n)
            break;
        for (long long y = 1; y <= n; y++)
        {
            long long x2y2 = x2 + y * y;
            if (x2y2 > n)
                break;
            for (long long z = 1; z <= n; z++)
            {
                long long v = x2y2 + z * z + x*y + y*z + z*x;
                if (v > n)
                    break;
                ans[v] ++;

            }
        }
    }
    for (long long i = 1; i <= n; i++)
        cout << ans[i] << "\n";

    return 0;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}


signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int a, b;
  rep(i, 4){
    cin >> a >> b;
    if(a == 1){
      b *= 6000;
    } else if(a == 2){
      b *= 4000;
    } else if(a == 3){
      b *= 3000;
    } else {
      b *= 2000;
    }
    cout << b << '\n';
  }
  return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    for (int i = 0; i < a; i++) cin >> p[i];
    for (int i = 0; i < b; i++) cin >> q[i];
    for (int i = 0; i < c; i++) cin >> r[i];
    sort(rbegin(p), rend(p));
    sort(rbegin(q), rend(q));
    sort(rbegin(r), rend(r));
    priority_queue<int, vector<int>, greater<int>> qr, qg;
    ll sr = 0, sg = 0;
    for (int i = 0; i < x; i++) {
        sr += p[i];
        qr.push(p[i]);
    }
    for (int i = 0; i < y; i++) {
        sg += q[i];
        qg.push(q[i]);
    }
    for (auto x : r) {
        int red = qr.top();
        int green = qg.top();
        sr -= red;
        sg -= green;
        qr.pop();
        qg.pop();
        if (x <= red && x <= green) {
            sr += red;
            sg += green;
            qr.push(red);
            qg.push(green);
            break;
        }
        if (red > green) {
            sr += red;
            sg += x;
            qr.push(red);
            qg.push(x);
        } else {
            sr += x;
            sg += green;
            qr.push(x);
            qg.push(green);
        }
    }
    cout << sr + sg << endl;
}

Measured memory_bytes: 2552
n, k, q = gets.split.map(&:to_i)
a = q.times.map{gets.to_i}

ans = {}
point = 0

a.each do |i|
  ans[i] = ans[i].nil? ? 1 : ans[i] + 1
end

(1..n).each do |i|
  point = ans[i].nil? ? k - q : k - q + ans[i]
  puts point > 0 ? 'Yes' : 'No'
end

Measured memory_bytes: 7220
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

int main(){
    int N, A, B_prev, B;
    long long ans = 0;

    std::cin >> N;
    vector<int> Bs(N);

    for(int i = 0; i < N-1; i++){
        std::cin >> B;
        if(i == 0){
            ans = ans + B;
        }else{
            ans = ans + min(B, B_prev);
        }
        B_prev = B;
    }
    ans = ans + B;

    std::cout << ans;
}

Measured memory_bytes: 3596
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007



void solve()
{
    ll n , x , m;
    cin >> n >> x >> m;
    ll a[100005];

    a[1] = x;

    map <ll, ll> mp;
    mp[x] = 1;

    ll pref[100005] = {0} , l ,r;

    pref[1] = x;

    for (ll i = 2 ; i < 100005 ; ++i) {

        a[i] = (a[i - 1] * a[i - 1] ) % m;
        pref[i] += pref[i - 1] + a[i];

         if(i == n) {
            cout << pref[i];
            return;
         }


        if (!mp.count(a[i])) {
            mp[a[i]] = i;
        }
        else {
            l = mp[a[i]];
            r = i - 1;
            break;
        }
    }


    ll len = r - l + 1;
    ll f = pref[l - 1];

    n -= (l - 1);
    ll t = n / len;

    ll y = n % len;

    f += t * (pref[r] - pref[l-1]);


        y--;
        f += pref[l + y] - pref[l - 1];
    



   cout << f;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    //TEST
    solve();
}



Measured memory_bytes: 7784
import sys
# sys.setrecursionlimit(1000000)
# N, Q = map(int, sys.stdin.readline().split())
# a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(N-1)]
# p_x = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]
s = input()
t = input()
count = 0
for i in range(3):
        if s[i] == t[i]:
                count += 1
print(count)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using vl  = vector<ll>;
using vvl = vector<vl>;
const int INF = 1e9;
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    vl ans(n,0);
    vvl edges(n);
    rep(i,n-1) {
        edges[i].push_back(i+1);
        edges[i+1].push_back(i);
    }
    edges[x].push_back(y);
    edges[y].push_back(x);

    rep(i,n-1) {
        vector<bool> visited(n,false);
        vl dist(n,0);
        priority_queue<pll> que;
        que.push(pll(0,i));
        while (!que.empty()) {
            ll d = -que.top().first, node = que.top().second;
            que.pop();
            if (visited[node]) continue;
            visited[node] = true;
            dist[node] = d;
            for (auto e : edges[node]) {
                que.push(pll(-d-1,e));
            }
        }
        for (int j = i+1; j < n; ++j) {
            ans[dist[j]]++;
        }
    }
    rng(j,1,n) cout << ans[j] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF 1000000007
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll T1,T2,A1,A2,B1,B2; cin>>T1>>T2>>A1>>A2>>B1>>B2;

    if(T1*A1+T2*A2==T1*B1+T2*B2){
        cout<< "infinity" <<"\n"; return;
    }

    if(T1*A1>T1*B1 and T1*A1+T2*A2>T1*B1+T2*B2) {cout<< 0 <<"\n"; return;}
    if(T1*A1<T1*B1 and T1*A1+T2*A2<T1*B1+T2*B2) {cout<< 0 <<"\n"; return;}

    if(A1>B1){
        swap(A1,B1);
        swap(A2,B2);
    }

    ll As=T1*A1;
    ll Bs=T1*B1;
    ll AX=T1*A1+T2*A2;
    ll BX=T1*B1+T2*B2;

    ll x=(As-Bs)/(BX-AX);

    ll ans=x*2+1;
    if((As-Bs)%(BX-AX)==0) --ans;

    cout<< ans<<"\n";



}   
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

/* msi1427 */

#define ll           long long
#define llu          long long unsigned
#define FOR(i,n)     for(int i=0;i<n;i++)
#define FLR(i,n)     for(ll i=0;i<n;i++)
#define RFOR(i,n)    for(int i=n-1;i>=0;i--)
#define RFLR(i,n)    for(ll i=n-1;i>=0;i--)
#define rep(i,a,b)   for(int i=a;i<=b;i++)
#define repl(i,a,b)  for(ll i=a;i<=b;i++)
#define casep(z)     cout << "Case " << z << ": ";
#define Fast         ios_base::sync_with_stdio(0);cin.tie(0);
#define sz(a)        a.size()
#define all(x)       x.begin(),x.end()
#define SORT(a,n)    sort(a,a+n)
#define RSORT(a,n)   sort(a,a+n,greater<int>())
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define VSORT(v)     sort(all(v))
#define VRSORT(v)    sort(all(v),greater<int>())
#define pb           push_back
#define pf           push_front
#define pob          pop_back()
#define pof          pop_front()
#define ff           first
#define ss           second
#define tt           true
#define fs           false
#define MP           make_pair
#define ms(x,n)      memset((x),n,sizeof(x))
#define bsrch(a,n,x) binary_search(a,a+n,x)
#define vi           vector<int>
#define vll          vector<ll>
#define PI           acos(-1.0)
#define LB(a,x)      (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)      (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define PQ           priority_queue
#define heap         PQ< ll , vll , greater < ll > >
#define REV(x)       reverse(all(x))
#define mpii         map<int,int>
#define mpll         map<ll,ll>
#define cig          cin.ignore()
#define INF          1e10
#define prec(n)      fixed << setprecision(n)
#define lb           lower_bound
#define ub           upper_bound
#define lcm(a, b)    ((a)*((b)/__gcd(a,b)))
#define fin          freopen("in.txt","r",stdin)
#define fout         freopen("out.txt","w",stdout)
#define sc           scanf
#define pt           printf
#define np           next_permutation
#define IT(it,x)     for(it=x.begin();it!=x.end();it++)

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))

ll n,x;
vll vv;
mpll mp;

int main()
{
    Fast
    cin >> n;
    FLR(i,n)
    {
        cin >> x;
        mp[x]++;
        vv.pb(x);
    }
    VSORT(vv);
    ll c=0,mx=0;
    FLR(i,n)
    {
        c=mp[vv[i]]+mp[vv[i]+1]+mp[vv[i]+2];
        mx=max(mx,c);
    }
    cout << mx << endl;
}


Measured memory_bytes: 7028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  string s;
  cin >> s;
  if(s.at(0) == '7' || s.at(1) == '7' ||s.at(2) == '7'){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; }return 0; }
constexpr int INF = 1 << 28, MAX = 1e5 + 5, MOD = 1e9 + 7;
constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N;
vv<int> graph;
vi visited;
int dist;

int dfs(int v, int depth) {
    if (depth != 0 && (v == N - 1 || v == 0)) {
        dist = depth;
        return -1;
    }

    visited[v] = true;
    int size = 1;

    for (const int next : graph[v]) {
        if (!visited[next]) {
            int ret = dfs(next, depth + 1);

            if (ret < 0 && depth >= (dist + 1) / 2) size = -1;
            else if (ret > 0 && size > 0) size += ret;
        }
    }

    return size;
}

int main() {
    cin >> N;
    graph.resize(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    visited.resize(N, false);
    int B = dfs(0, 0);
    visited.assign(N, false);
    int W = dfs(N - 1, 0);
    B += N - B - W;

    write(B > W ? "Fennec" : "Snuke");
}

Measured memory_bytes: 10752
from scipy.misc import comb
mod = 10**9 + 7
 
n,k = map(int,input().split())

for i in range(1,k+1):
    #まず青を並び替える。
    a = int(comb(k-1, i-1, exact=True)) % mod
    #全体から青の数だけ引いて赤玉の入れられる場合の数を求める。
    b = int(comb(n-k+1, i, exact=True)) % mod 
    print(a*b%mod)

Measured memory_bytes: 13740
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define puu pair<ull,ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vll vector<ll>
#define Vull vector<ull>
#define nl cout<<endl
#define sp cout<<" "
#define MOD 1000000007
#define all(x) x.begin(),x.end()

int main() 
{
	 // #ifndef ONLINE_JUDGE
  //       freopen("input.txt", "r", stdin);
  //       freopen("output.txt", "w", stdout);
  //   #endif
  //   fastio();
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    loop(i,0,n)
    	cin>>v[i];
    vector<ll> dp(n,INT_MAX);
    dp[0] = 0;
    loop(i,1,n)
    {
    	loop(j,1,k+1)
    	{
    		if(i-j<0)
    			break;

    		dp[i] = min(dp[i],dp[i-j] + abs(v[i] - v[i-j]));
    	}
    }
    // loop(i,0,n)
    // 	cout<<dp[i]<<" ";
    // cout<<endl;
    cout<<dp[n-1];


}

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

using namespace std;

int main()
{
	int N, X;
	cin >> N >> X;
	vector < int >m(N);
	for (int i = 0; i < N; i++) {
		cin >> m[i];
	}

	sort(m.begin(), m.end());
	int sum = accumulate(m.begin(), m.end(), 0);

	X -= sum;

	cout << N + (X / m[0]) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int a, p, pie;
  cin >> a >> p;
  
  p += a * 3;
  for(int i = 0; p > 1; i++) {
    p -= 2;
    pie++;
  }
  cout << pie << endl;
  
}



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

int N;

struct P{
	int x,y,z;
	int dist(P p){
		return abs(x-p.x) + abs(y-p.y) + abs(z-p.z);
	}
	P rotZ(){ return {y,N-x-1,z}; }
	P rotY(){ return {z,y,N-x-1}; }
	P rotX(){ return {x,z,N-y-1}; }

	bool valid(){
		if( x < 0 || x >= N ) return false;
		if( y < 0 || y >= N ) return false;
		if( z < 0 || z >= N ) return false;
		return true;
	}
	string toString(){
		stringstream ss;
		ss << "(" << x << " " << y << " " << z << ")";
		return ss.str();
	}
};
bool operator < (const P &a,const P &b){
	if( a.x != b.x ) return a.x < b.x;
	if( a.y != b.y ) return a.y < b.y;
	return a.z < b.z;
}
bool operator == (const P &a,const P &b){
	if( a.x != b.x ) return false;
	if( a.y != b.y ) return false;
	return a.z == b.z;
}

P operator + (P a,P b){
	a.x += b.x;
	a.y += b.y;
	a.z += b.z;
	return a;
};


struct NODE{
	vector<P> p;
	int phase;
	int cost;
};
bool operator < (const NODE &a,const NODE &b){
	if( a.phase != b.phase ) return a.phase < b.phase;
	return a.p < b.p;
}

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

vector<P> rot(vector<P> p,int id){
	
	if( id == 0 ){
		if( p[0].z == p[1].z ) return p;
		p[0] = p[0].rotZ();
		
	}
	if( id == 1 ){
		if( p[0].y == p[1].y ) return p;
		p[0] = p[0].rotY();
	}
	if( id == 2 ){
		if( p[0].x == p[1].x ) return p;
		p[0] = p[0].rotX();
		
	}
	if( id == 3 ){
		if( p[0].z == p[1].z ) return p;
		p[0] = p[0].rotZ().rotZ().rotZ();
	}
	if( id == 4 ){
		if( p[0].y == p[1].y ) return p;
		p[0] = p[0].rotY().rotY().rotY();
	}
	if( id == 5 ){
		if( p[0].x == p[1].x ) return p;
		p[0] = p[0].rotX().rotX().rotX();
	}
	return p;

}

int main(){
	cin >> N;
	vector<P> c; 
	for(int i = 0 ; i < 2 ; i++){
		int x,y,z;
		cin >> x >> y >> z;
		c.push_back({x,y,z});
	}
	//c.resize(2);
	//N = 100000;
	//c[0] = {0,0,0};
	//c[1] = {N-1,N-1,N-1};
	
	//assert(c[0].rotY().rotY().rotY().rotY() == c[0]);
	//assert(c[1].rotZ().rotZ().rotZ().rotZ() == c[1]);
	//assert(c[1].rotX().rotX().rotX().rotX() == c[1]);


	map<NODE,int> done;

	deque<NODE> Q;

	int ans = 1e9;
	Q.push_back({c,0,0});
	int count = 0;
	while( Q.size() ){
		NODE q = Q.front(); Q.pop_front();
		count++;
		if( done[q]++ ) continue;
		//cout << q.phase << "|" << q.p[0].toString() << " " << q.p[1].toString() << "|" << q.cost << endl;
		ans = min(ans,q.cost + q.p[0].dist(q.p[1]));
		if( q.phase == 2 ) continue;

		if( q.phase == 0 ){
			for(int i = 0 ; i < 6 ; i++){
				P ne = q.p[0] + P{dx[i],dy[i],dz[i]};
				if( !ne.valid() ) continue;
				
				NODE nextq = q;
				nextq.cost ++;
				nextq.p[0] = ne;
				nextq.phase++;
				if( !done[nextq] ) Q.push_back(nextq);
			}
		}else if( q.phase == 1 ){
			for(int i = 0 ; i < 6 ; i++){
				NODE nextq = q;
				nextq.cost++;
				nextq.p = rot(nextq.p,i);
				if( !done[nextq] ) Q.push_back(nextq);
			}
		}
		// next phase 
		q.phase++;
		if( !done[q] ) Q.push_front(q);
	}
	//cout << count << endl;
	//cout << done.size() << "|" << count << endl;
	cout << ans << endl;
}

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



int f(int n){
  int sum =0;
  while(n>0){
    sum +=n%10;
    n/=10;
  }
  return sum;
}
  
  
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int k=0;
  rep(i,n+1){
    int sum =f(i);
    if(a <=sum && sum <=b){
      k+=i;
    }
  }
  cout << k << endl; 
  
}

Measured memory_bytes: 3596
from collections import defaultdict
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
roads = defaultdict(list)

for i in range(M):
    a, b = nl()
    roads[a].append(b)
    roads[b].append(a)

for i in range(N):
    if i+1 in roads:
        print(len(roads[i+1]))
    else:
        print(0)



Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    /*vector<int> s(n+1, 0);
    s[0]=0;
    rep(i, 1, n+1) s[i]=s[i-1]+a[i-1];
    int ans=0;
    rep(i, 0, n+1) rep(j, i+1, n+1)if(s[j]-s[i]==0) ans++;*/
    vector<ll> s(n+1,0);
    //部分和はsi-sjで表すsi-sj=0⇒si=sjとなるものを探す
    map<ll, ll> nums;
    rep(i, 0, n) s[i+1]=s[i]+a[i];
    rep(i, 0, n+1) nums[s[i]]++;//和がs[i]になる配列が何個あるか
    ll ans=0;
    for(auto it: nums){
        ll num = it.second;
        ans+=num*(num-1)/2;//numC2
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 15872
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split()
            .Select(x => int.Parse(x))
            .ToArray();
        var n = nm[0];
        var m = nm[1];
        var edgesQuery =
            from i in Enumerable.Range(1, m)
            let vu = Console.ReadLine().Split()
                .Select(x => int.Parse(x))
                .ToArray()
            select new[] { vu, vu.Reverse() } into dual
            from e in dual
            group e.Last() by e.First() into g
            select g;
        var edges = edgesQuery.ToDictionary(x => x.Key, x => x.ToArray());

        var path = new LinkedList<int>(new[] { 1 });
        var nodes = new HashSet<int>() { 1 };
        var end = new[] { 1, 1 };
        var length = 1;
        for (int i = 0; i < 2; ++i)
        {
            var addToPath = i == 0
                ? (Action<int>)(x => path.AddFirst(x))
                : (Action<int>)(x => path.AddLast(x));

            while (true)
            {
                end[i] = edges[end[i]].FirstOrDefault(x => !nodes.Contains(x));
                if (end[i] == 0)
                {
                    break;
                }

                nodes.Add(end[i]);
                addToPath(end[i]);
                ++length;
            }
        }

        Console.WriteLine(length);
        Console.WriteLine(string.Join(" ", path));
    }
}


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==5&&b==5&&c==7){
    cout<<"YES"<<endl;
  }
  else if(a==5&&b==7&&c==5){
    cout<<"YES"<<endl;
  }
  else if(a==7&&b==5&&c==5){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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


	int r;
	cin >> r;
	cout << r * r << "\n";

	return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define bit(x,j) ((x>>j)&1)
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
long long power(long long a, long long b) {
    //a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
    }
  ll int binomial(ll int n, ll int k) 
{ 
    ll int C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll int i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (int j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 
  vector<int> pr;
  bool prime[10000000];
void Sieve(ll int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            pr.push_back(p);
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
 


//It reurns Fn,Fn+1
pair<int, int> fib (int n) {
    if (n == 0)
        return {0, 1};

    auto p = fib(n >> 1);
    int c = p.first * (2 * p.second - p.first);
    int d = p.first * p.first + p.second * p.second;
    if (n & 1)
        return {d, c + d};
    else
        return {c, d};
}
int sum(int n)  
{  
    if (n == 0)  
    return 0;  
    return (n % 10 + sum(n / 10));  
}  
ll int factorial(ll int n,ll int m) 
{ 
    ll int fact = 1; 
    for(int i=2;i<=n;i++) { 
        fact = (fact * i)%m; 
    } 
    return fact%m; 
} 

void reverse(string& str) 
{ 
    int n = str.length(); 
  
    // Swap character starting from two 
    // corners 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
} 


int main() {
    ios;
   ll int n;
   cin>>n;
   if(n<=599)
   {
       cout<<8<<endl;
   }
   else if(n<=799)
   {
       cout<<7<<endl;
   }
   else if(n<=999)
   {
       cout<<6<<endl;
   }
   else if(n<=1199)
   {
       cout<<5<<endl;
   }
   else if(n<=1399)
   {
       cout<<4<<endl;
   }
   else if(n<=1599)
   {
       cout<<3<<endl;
   }
   else if(n<=1799)
   {
       cout<<2<<endl;
   }
   else
   cout<<1<<endl;
}


Measured memory_bytes: 3652
N = int(input())
ans = "Yes"
i = 0
while i < N:
    t,x,y = [int(num) for num in input().split()]
    if x+y <= t and (t-x-y)%2 == 0:
        i += 1
    else:
        ans = "No"
        break
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<queue>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<int> a;
    for(int i=0;i<n;i++){
        int num;
        cin>>num;
        a.push(num);
    }
    while(m-->0){
        int val=a.top()/2;a.pop();
        a.push(val);
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=a.top();a.pop();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 892