akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int long long
main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> a(n),b(m);
    for(int i = 0; i < n; i++){
        int c,d;
        cin >> c >> d;
        a[i] = make_pair(c,d);
    }
    for(int i = 0; i < m; i++){
        int c,d;
        cin >> c >> d;
        b[i] = make_pair(c,d);
    }
    
    vector<int> e(n);
    for(int i = 0; i < n; i++){
        int g = 1e16;
        for(int j = 0; j < m; j++){
            int f = 0;
            f = abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second);
            if(f < g){
                e[i] = j + 1;
                g = f;
            }
        }
    }
    for(int i = 0; i < n; i++){
        cout << e[i] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <math.h>
#include <time.h>   //srand((unsigned int)time(NULL));
#include <unistd.h> //sleep
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <unordered_map>
#include <set>
#include <cassert> //assart
#include <numeric>
#include <iterator>
#include <list>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(int i=(max);i>=(min);i--)
const int MOD=1e9+7;
const int MOD2=998244353;

const int INF=2000000001;
const ll INFll=2e18;
//const int MAX_V=10000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INFll || MOD2){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}
#define elif else if

#define issame(a,b,c,d) ((a)==(b) and (b)==(c) and (c)==(d))
#define isdiff3(a,b,c) ((a)!=(b) and (b)!=(c) and (c)!=(a))
#define isdiff4(a,b,c,d) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c))
#define Func3(f,a,b,c) (f)((f)((a),(b)),(c))
#define Func4(f,a,b,c,d) (f)((f)((f)((a),(b)),(c)),(d))
inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
inline ll  gcd(ll a,ll b){ if(b==0)return a;else return gcd(b,a%b);}//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
inline ll  lcm(ll a,ll b){return a*b/gcd(a,b);}//MODやオーバーフローには注意！
//inline ll  ceil(double a){return (ll)a+1;}


//Eと名のつくのはデバッグ用！
int EintN(ll array[],const ll num){
    for(int i=0;i<num;i++){cerr<<array[i]<<" ";}
    br;
    return 0;
}
int EintNN(const int heighth,const int width,int array[heighth][width]){
    FOR(i, 0, heighth){
        FOR(k, 0, width){
            {cerr<<array[i][k]<<" ";}
        }
        br;
    }
    br;
    return 0;
}
int Eint(string str,const ll num){
    cerr<<str<<" is "<<num<<" now."<<endl;
    return 0;
}











ll bamboo[8];
ll N,A,B,C;

ll re(ll num,ll useA,ll useB,ll useC){
    if(num==N){
//        if( min({useA,useB,useC})==0)return INF;
        if( Func3(min,useA,useB,useC)==0)return INF;
        else return abs(A-useA)+abs(B-useB)+abs(C-useC)-30;
    }
    ll ans0=re(num+1,useA,useB,useC);
    ll ans1=re(num+1,useA+bamboo[num],useB,useC)+10;
    ll ans2=re(num+1,useA,useB+bamboo[num],useC)+10;
    ll ans3=re(num+1,useA,useB,useC+bamboo[num])+10;
    return Func4(min,ans0,ans1,ans2,ans3);
}

int prob(){
    ll ans;ans=0;
    cin>>N>>A>>B>>C;
    inarray(bamboo, 0, N);
    OutputAndReturn0(re(0,0,0,0));
    return 0;
}


signed main(){
    prob();
    return 0;
}


Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())

x_1 = a * math.cos(((90-30*h-0.5*m)/180)*math.pi)
y_1 = a * math.sin(((90-30*h-0.5*m)/180)*math.pi)
x_2 = b * math.cos(((90-6*m)/180)*math.pi)
y_2 = b * math.sin(((90-6*m)/180)*math.pi)

# print(x_1, y_1, x_2, y_2)
print(math.sqrt((x_1-x_2)**2 + (y_1-y_2)**2))



Measured memory_bytes: 9576
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    if a[i]>=b[i]:
        a[i]=a[i]-b[i]
        ans+=b[i]
    elif a[i+1]-(b[i]-a[i])>=0:
        a[i+1]=a[i+1]-(b[i]-a[i])
        a[i]=0
        ans+=b[i]
    else:
        ans+=a[i]+a[i+1]
        a[i+1]=0
        a[i]=0
print(ans)

Measured memory_bytes: 24228
from sys import stdin
N = int(stdin.readline().rstrip())

dp = [99999999]*(N+1)
dp[0] = 0
for i in range(0, N):
    dp[i+1] = min(dp[i] + 1, dp[i+1])
    k = 6
    while i+k <= N:
        dp[i+k] = min(dp[i]+1, dp[i+k])
        k *= 6
    k = 9
    while i+k <= N:
        dp[i+k] = min(dp[i]+1, dp[i+k])
        k *= 9
print(dp[N])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7

int main(){
    int s,w;
    cin >> s >> w;
    cout << (s <= w ? "unsafe" : "safe") << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
	double x1, y1, x2, y2;
	cin >> setprecision(10) >> x1;
	cin >> setprecision(10) >> y1; 
	cin >> setprecision(10) >> x2;
	cin >> setprecision(10) >> y2;
	cout << setprecision(10) << sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include<vector>
#include<math.h>
#include<string>

typedef long long ll;
typedef unsigned short int unsi;
typedef unsigned int uni;
typedef unsigned long int unli;

using namespace std;

int main(){
	int N, K;
	scanf("%d%d", &N, &K);
	if (K != 1) {
		printf("%d", N - K);
	}else {
		printf("%d", 0);
	}
	
}

Measured memory_bytes: 128
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))

ball_dict = {}
uni_A = list(set(A))

if len(uni_A) <= k:
    print(0)

else:
    for uni_a in uni_A:
        ball_dict[uni_a] = 0

    for a in A:
        ball_dict[a] += 1

    val = sorted(ball_dict.values())

    # print(val)

    print(sum(val[:-k]))


Measured memory_bytes: 38452
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int main() {
	int k[5];
	for (int i = 0; i < 4; ++i) { cin >> k[i]; }
	sort(k, k + 4);
	if (k[0] == k[1] && k[2] == k[3]) {
		cout << "yes" << endl;
		return 0;
	}
	cout << "no" << endl;
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
typedef long long ll;
typedef pair<ll, int> P;
const int MAX_V = 1e5;
const int MAX_E = 1e5*2;
//unionfind
int par[MAX_V];
int ranks[MAX_V];

void init(int n){
  rep(i, n) par[i] = i, ranks[i] = 0;
}

int find(int x){
  if(par[x] == x){
    return x;
  } else{
    int r = find(par[x]);
    return par[x] = r;
  }
}

void unite(int x, int y){
  x = find(x); y = find(y);
  if (x == y) return;
  if (ranks[x] < ranks[y]) swap(x, y);
  if (ranks[x] == ranks[y]) ranks[x]++;
  par[y] = x;
}

bool same(int x, int y){
  return find(x) == find(y);
}

struct edge {
  int u, v;
  ll cost;
};

bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}

vector<edge> es;
int V, E = 0;

int kruskal() {
  sort(es.begin(), es.end(), comp);
  init(V);
  ll res = 0;
  rep(i, E){
    edge e = es[i];
    if(!same(e.u, e.v)){
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}


int main(){
  cin >> V;
  vector<P> x, y;
  rep(i, V){
    ll a, b;
    cin >> a >> b;
    x.push_back(P(a,i)), y.push_back(P(b,i));
  }
  sort(x.begin(), x.end()), sort(y.begin(), y.end());
  rep(i, V-1){
    es.push_back({x[i+1].second, x[i].second, x[i+1].first-x[i].first});
    es.push_back({y[i+1].second, y[i].second, y[i+1].first-y[i].first});
    E += 2;
  }

  cout << kruskal() << endl;
  return 0;
}


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

using namespace std;


int main() {
	int N, M;
	cin >> N >> M;

	bool* lis = new bool[M];
	for (int i = 0; i < M; i++) {
		lis[i] = false;
	}

	int K;
	cin >> K;
	for (int i = 0; i < K; i++) {
		int num;
		cin >> num;
		lis[num-1] = true;
	}

	bool* lis2 = new bool[M];
	for (int i = 1; i < N; i++) {
		cin >> K;

		for (int i = 0; i < M; i++) {
			lis2[i] = false;
		}

		for (int j = 0; j < K; j++) {
			int num;
			cin >> num;
			lis2[num-1] = true;
		}

		for (int i = 0; i < M; i++) {
			if (lis[i] == true && lis2[i] == false)
			{
				lis[i] = false;
			}
		}
	}

	int cnt = 0;
	for (int i = 0; i < M; i++) {
		if (lis[i] == true) {
			cnt++;
		}
	}
	cout << cnt;

	delete lis;
	delete lis2;

	return 0;
}

Measured memory_bytes: 256
/*
 * Author       : YangDavid
 * Created Time : 2019年08月24日 星期六 23时34分01秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 555, N = 512;
int G[maxn][maxn];
int main() {
    for(int lv = 1; lv <= 9; ++lv) {
        int d = 1 << (lv - 1);
        for(int i = d; i < 2 * d; ++i)
            for(int j = i + 1; j < 2 * d; ++j)
                G[i][j] = G[i - d][j - d];
        for(int i = 0; i < d; ++i)
            for(int j = d; j < 2 * d; ++j)
                G[i][j] = lv;
    }
    int n; cin >> n;
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j < n; ++j)
            printf("%d%c", G[i][j], " \n"[j == n - 1]);
    }
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll m;cin>>m;
    ll ans=0;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
            for(int k=1;k<=m;k++){
                ll res=0;
                res=gcd(res,i);
                res=gcd(res,j);
                res=gcd(res,k);
                ans+=res;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int n;
   cin>>n;
   int arr[n];
   int i;
   for(i=0;i<n;i++) cin>>arr[i];
    int dp[n]={0};
    for(i=1;i<n;i++){
        int a=INT_MAX;
        int b=INT_MAX;
        if(i>=1) a=dp[i-1]+abs(arr[i]-arr[i-1]);
        if(i>=2) b=dp[i-2]+abs(arr[i]-arr[i-2]);
        dp[i]=min(a,b);
    }
   // printarray(dp,n);
    cout<<dp[n-1]<<endl;
  return 0;
}

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

int main(){
    int cards[4][13]; // 0:S, 1:H, 2:C 3:D
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            cards[i][j]=0;
        }
    }
    int n;
    char color;
    int num;
    cin >> n;
     // do while n>0
    while(n--){
        cin >> color >> num;
        if(color=='S')      cards[0][num-1]=1;
        else if(color=='H') cards[1][num-1]=1;
        else if(color=='C') cards[2][num-1]=1;
        else if(color=='D') cards[3][num-1]=1;
    }
    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++){
            if(cards[i][j]==0){ // if not cin
                if(i==0)      cout<< "S " << j+1 <<endl;
                else if(i==1) cout<< "H " << j+1 <<endl;
                else if(i==2) cout<< "C " << j+1 <<endl;
                else if(i==3) cout<< "D " << j+1 <<endl;
            } 
        }
    }
}


Measured memory_bytes: 3072
//problem_c.go

package main

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

const (
	constMod = int(1e9) + 7
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

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

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntSlice(n int) []int {
	ns := []int{}
	for i := 0; i < n; i++ {
		ns = append(ns, getInt())
	}
	return ns
}

func getIntDoubleSlice(m int, n int) [][]int {
	var nds [][]int
	for i := 0; i < m; i++ {
		ns := getIntSlice(n)
		nds = append(nds, ns)
	}

	return nds
}

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

func getStringSlice(n int) []string {
	ss := []string{}
	for i := 0; i < n; i++ {
		ss = append(ss, getString())
	}
	return ss
}

func getStringDoubleSlice(m int, n int) [][]string {
	sds := [][]string{}
	for i := 0; i < m; i++ {
		ss := getStringSlice(n)
		sds = append(sds, ss)
	}

	return sds

}

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

// Sort Fanction

func sortIntSlice(ns []int) []int {
	sort.Sort(sort.IntSlice(ns))
	return ns
}

func sortIntReverseSlice(ns []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(ns)))
	return ns
}

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

// Num Fanction

//numAbs(x) = abs(s)
func numAbs(x int) int {
	if x < 0 {
		return -x
	}

	return x
}

//numModPow(a, n, m) = a^n % m
func numModPow(a int, n int, m int) int {
	result := 1

	for n > 0 {
		if n%2 == 1 {
			result = (result * a) % m
		}

		a = (a * a) % m
		n >>= 1
	}

	return result
}

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

	return numGcd(b, a%b)
}

// numLcm(a, b) = lcm(a, b)
func numLcm(a int, b int) int {
	return a * b / numGcd(a, b)
}

// numModInv(a, p) = a^(-1) % p
func numModInv(a int, p int) int {
	if a == 1 {
		return 1
	}

	return p - numModInv(p%a, p)*(p/a)%p
}

// numModFrac(n) = n! % constMod
func numModFrac(n int) []int {
	frac := []int{1}

	for i := 1; i <= n; i++ {
		frac = append(frac, i*frac[i-1]%constMod)
	}

	return frac
}

// numModConb(n, r) = nCr % constMod
func numModConb(n int, r int) int {
	frac := numModFrac(n)

	return (frac[n] / ((frac[n-r] * frac[r]) % constMod)) % constMod
}

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

func solve() {

	n, k := getInt(), getInt()

	result := n % k

	if result < numAbs(result-k) {
		fmt.Fprintln(wr, result)
	} else {
		fmt.Fprintln(wr, numAbs(result-k))

	}
}

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

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

constexpr int N_MAX = 2000;
constexpr ll MOD = 1000000007;

ll fact[N_MAX+1], rfact[N_MAX+1];

ll perm(ll n, ll k) {
    if(n-k < 0LL) return 0LL;
    return (fact[n] * rfact[n-k]) % MOD;
}

ll comb(ll n, ll k) {
    if(n-k < 0LL) return 0LL;
    return (perm(n, k) * rfact[k]) % MOD;
}

ll modpow(ll a, ll p) {
    ll ret = 1LL;
    while(p) {
        if(p & 1) {
            ret = (ret * a) % MOD;
        }
        a = (a * a) % MOD;
        p >>= 1;
    }
    return ret;
}

void init_fact(ll n) {
    fact[0] = fact[1] = 1;
    rfact[0] = rfact[1] = 1;
    for(ll i=2;i<=n;++i) {
        fact[i] = (fact[i-1] * i) % MOD;
        rfact[i] = modpow(fact[i], MOD-2);
    }
}

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

    init_fact(n);

    ll ans = 0LL;
    for(int i=1;3*i<=n;++i) { // 数列の長さ
        ll nn = n - 3 * i;
        ans += comb(nn+i-1, i-1);
        ans %= MOD;
    }

    cout << ans << endl;
}


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

void solve(std::string T)
{
    for (int i = 0; i < T.length(); i++)
    {
        if (T[i] == '?')
            T[i] = 'D';
    }
    cout << T << endl;
}

int main()
{
    std::string T;
    std::cin >> T;
    solve(T);
    return 0;
}

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

bool search1(int v,int n,int a[])
{
    int flag = false;
    for(int i=0; i<n ; i++)
    {
        if(v == a[i])
        {
            flag = true;
        }
    }
    return flag;
}

int main()
{
    int x,n,s,l;
    cin >> x >> n;
    int a[n];
    for(int &i:a)
    {
        cin >> i;
    }
    s = x;
    l = x;
    while(1)
    {
        if(!search1(s,n,a))
        {
            cout << s;
            break;
        }
        if(!search1(l,n,a))
        {
            cout << l;
            break;
        }
        s--;
        l++;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n,i,j,k,A=0,B=0,count=0;
	string str1,str2,str;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> str1 >> str2;
		str = str1 + str2;
		for (j = 0; j < str.size(); j++) {

			if (str1[j] < str2[j]) {
				B += 3;
				break;
			}
			else if (str1[j] > str2[j]) {
				A += 3;
				break;
			}
			else if (str1 == str2) {
				A += 1;
				B += 1;
				break;
			}
			else if (str1[j] == str2[j]) {
				continue;
			}
		}
	}
	cout << A <<" "<< B<<endl;
	return 0;
}

Measured memory_bytes: 3144
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans


'''
p = 10 ** 9 + 7
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
'''


#a = list(map(int, input().split()))

k, q = list(map(int, input().split()))
d = list(map(int, input().split()))

que = []
for i in range(q):
    que.append(list(map(int, input().split())))
    
#print(que)

dsum = [0]

for i in range(k):
    dsum.append(dsum[-1]+d[i])

    
for i in range(q):
    dr = [d[j]%que[i][2] for j in range(len(d))]
    #print(dr)
    drsum = [0 for i in range(k+1)]
    for j in range(k):
        drsum[j+1] = drsum[j] + dr[j]
    count0 = [0 for i in range(k+1)]
    for j in range(k):
        if(dr[j]==0):
            count0[j+1] = count0[j]+1
        else:
            count0[j+1] = count0[j]
            
    times = (que[i][0]-1) // k
    amari = (que[i][0]-1) % k
    
    #print(drsum)
    #print(count0)
    #print(times,amari)
    
    total = que[i][1] + drsum[-1]*times + drsum[amari]
    num0 = count0[-1]*times + count0[amari]
    #print("num0",num0)
    ans = total//que[i][2] - que[i][1]//que[i][2]
    ans = que[i][0] - ans - num0 - 1
    
    print(ans)





















Measured memory_bytes: 122196
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    rep(i,n-1)if(a[i] == a[i+1]){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
using namespace std;

typedef pair<int,int> P;

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

int h,w,res = 0,pos = 0;
int field[1010][1010];
int cnt[1010][1010];
bool used[1010][1010];
stack<P> que;
queue<P> visit;

int main(){
	cin >> h >> w;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++) scanf("%d",&field[i][j]);
	}
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			bool flag = true;
			for(int k = 0;k < 4;k++){
				int nx = i + dx[k],ny = j + dy[k];
				if(nx >= 0 && nx < h && ny >= 0 && ny < w && field[nx][ny] < field[i][j]) flag = false;
			}
			if(flag){
				que.push(P(i,j));
				while(!que.empty()){
					P p = que.top();que.pop();
					int x = p.first,y = p.second;
					visit.push(P(x,y));
					for(int i = 0;i < 4;i++){
						int nx = x + dx[i],ny = y + dy[i];
						if(nx >= 0 && nx < h && ny >= 0 && ny < w && field[nx][ny] > field[x][y] && !used[nx][ny]){
							cnt[nx][ny]++;
							if(cnt[nx][ny] < 3){
								used[nx][ny] = true;
								que.push(P(nx,ny));
							}
						}
					}
				}
			}
			while(!visit.empty()){
				int x = visit.front().first,y = visit.front().second;visit.pop();
				used[x][y] = false;
			}
		}
	}
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++) if(cnt[i][j] >= 2) res++;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 20016
from itertools import permutations as per
from copy import deepcopy
k = int(input())
b = [["."]*8 for _ in range(8)]
st = [[False]*8 for _ in range(8)]

def setQueen(r,c):
    if st[r][c]: return False
    for i in range(8):
        st[i][c] = True
        st[r][i] = True
    d = abs(r-c)
    y,x = d,0
    if r < c: y,x = x,y
    for i in range(8-d): st[y+i][x+i] = True
    d = abs(7-r-c)
    y,x = d,0
    if 7-r < c: y,x = x,y
    for i in range(8-d): st[7-y-i][x+i] = True
    b[r][c] = "Q"
    return True

sr = [True]*8
sc = [True]*8
for _ in range(k):
    r,c = map(int,input().split())
    b[r][c] = "Q"
    setQueen(r,c)
    sr[r] = False
    sc[c] = False

row = [i for i in range(8) if sr[i]]
col = [i for i in range(8) if sc[i]] 

tmpb = b
tmpst = st
for p in per(row):
    b = deepcopy(tmpb)
    st = deepcopy(tmpst)
    for r,c in zip(p,col):
        if not setQueen(r,c): break
    else:
        for i in range(8): print("".join(b[i]))
        break


Measured memory_bytes: 6324
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
 
const int N = 2e5 + 5;
const int LG = log2(N) + 1;
 
int n, q, ct = 0, num = 0;
int a[N], root[N], level[N], ans[N];
int st[21*N], lc[21*N], rc[21*N];
int tim=0;
int parent[LG][N];
map<int, int> comp, rcomp;
vector<int> g[N];
 
int build(int L, int R)
{
	int node = ++ct;
	if(L==R)
		return node;
	int M = (L+R)/2;
	lc[node] = build(L, M);
	rc[node] = build(M+1, R);
	return node;
}
 
int update(int onode, int L, int R, int pos, int val)
{
	int node = ++ct;
	if(L==R)
	{
		st[node] = max(st[onode], val);
		return node;
	}
	int M = (L+R)/2;
	lc[node] = lc[onode];
	rc[node] = rc[onode];
	if(pos <= M)
		lc[node] = update(lc[onode], L, M, pos, val);
	else
		rc[node] = update(rc[onode], M+1, R, pos, val);
	st[node] = max(st[lc[node]], st[rc[node]]);
	return node;
}
 
int query(int node, int L, int R, int i, int j)
{
	if(j<L || i>R)
		return 0;
	if(i<=L && R<=j)
		return st[node];
	int M = (L+R)/2;
	int leftval = query(lc[node], L, M, i, j);
	int rightval = query(rc[node], M + 1, R, i, j);
	return max(leftval, rightval);
}
 
void dfs(int u, int par)
{
	int onode = root[par];
	int len = query(onode, 1, num, 1, a[u] - 1);
 	root[u] = update(onode, 1, num, a[u], len + 1);
	ans[u] = query(root[u], 1, num, 1, num);
	for(auto &it:g[u])
	{
		if(it==par)
			continue;
		dfs(it, u);
	}
}
 
int32_t main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		comp[a[i]];
	}
	for(auto &it:comp)
	{
		it.second = ++num;
		rcomp[num] = it.first;
	}
	for(int i=1;i<=n;i++)
		a[i] = comp[a[i]];
	for(int i=1;i<=n-1;i++)
	{
		int u, v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	root[0] = build(1, num);
	dfs(1, 0);
	for(int i = 1; i <= n; i++)
		cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 88320
import sys
import copy

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():
    N, A = in_nn()
    X = in_nl()
    X = [x - A for x in X]

    dp = [0] * 5050
    dp[2525] = 1

    for i in range(N):

        next_dp = copy.copy(dp)
        for t in range(5050):
            if X[i] + t < 5050:
                next_dp[X[i] + t] += dp[t]

        dp = next_dp

    print(dp[2525] - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9344
#include<iostream>
#include<string>
using namespace std;
 
int main(){
  int n;
  cin >> n;
 
  int *h;
  h = new int[n];
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  
  string s = "Yes";
  for(int i=n-2; i>=0; i--){
    if(h[i+1]<h[i]){
      h[i] -= 1;
      if(h[i+1]<h[i]){
        s = "No";
        break;
      }
    }
  }
 
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<iostream>
#define llong long long
using namespace std;

inline int read()
{
    int x=0; bool f=1; char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
    for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
    if(f) return x;
    return -x;
}

const int N = 2e5;
struct Element
{
    int u,v,typ;
} a[N+3];
int uf[N+3];
int n,q,c; llong m;

int findfa(int u) {return uf[u]==u?u:uf[u]=findfa(uf[u]);}

int main()
{
    scanf("%d%lld%d",&n,&m,&q);
    for(int i=1; i<=n; i++) uf[i] = i;
    for(int i=1; i<=q; i++)
    {
        scanf("%d%d%d",&a[i].u,&a[i].v,&a[i].typ); a[i].u++; a[i].v++;
        if(a[i].typ==0)
        {
            int uu = findfa(a[i].u),vv = findfa(a[i].v);
            if(uu!=vv) {uf[uu] = vv;}
        }
    }
    int cnt1 = 0; c = 0;
    for(int i=1; i<=n; i++) {if(i==findfa(i)) c++;}
    for(int i=1; i<=q; i++)
    {
        if(a[i].typ==1)
        {
            cnt1++;
            int uu = findfa(a[i].u),vv = findfa(a[i].v);
            if(uu==vv) {puts("No"); return 0;}
        }
    }
    llong l = cnt1?max(3ll,(llong)c):c-1ll,r = 1ll*c*(c-1ll)/2ll;
    if(m-(n-c)>=l && m-(n-c)<=r) {puts("Yes");}
    else {puts("No");}
    return 0;
}

Measured memory_bytes: 1920
n = int(input())
s = input()

dp = [[0 for i in range(5005)] for j in range(5005)]

for i in range(n - 1, -1, -1):
    for j in range(n - 1, -1, -1):
        dp[i][j] = 0 if s[i] != s[j] else dp[i + 1][j + 1] + 1

res = 0
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        curr = min(dp[i][j], j - i)
        res = max(res, curr)

print(res)

Measured memory_bytes: 247560
#include <bits/stdc++.h>
#define Mod 1000000007
#define INF 9e8
#define INFL 9e18
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define N 500005
#define fs first
#define sc second 
#define UNIVISITED 0
#define EXPLORED 1
#define VISITED 2
using namespace std;
typedef  long long int ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector <ll> vi;

ll dp1[N],dp2[N],a1[N],a2[N];
int main()
{

ios::sync_with_stdio(false);
cin.tie(0);
ll a,b;
cin>>a>>b;
cout<<a+2*(b-a)<<endl;




return 0;


}

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

int main()
{
    int N;
    cin >> N;
    set<int> X;
    int d;
    for (int i = 0; i < N; i++)
    {
        cin >> d;
        X.insert(d);
    }
    cout << X.size() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int pos[200005], deg[2][200005];
vector<int> adj[200005];
vector<pair<int, int> > vec;
map<int, int> del[200005];
void dfs(int u)
{
	while (true) {
		int idx = pos[u]++;
		if (idx >= (int)adj[u].size()) {
			break;
		}
		int v = adj[u][idx];
		if (del[u][v]) {
			continue;
		}
		del[u][v] = del[v][u] = true;
		dfs(v);
		vec.push_back({u, v});
	}
}
int main()
{
	// freopen("AGC018-F.in", "r", stdin);
	auto adde = [&] (int u, int v) { adj[u].push_back(v); adj[v].push_back(u); };
	int n;
	scanf("%d", &n);
	for (int T = 0; T < 2; T++) {
		for (int i = 0; i < n; i++) {
			int fa;
			scanf("%d", &fa);
			if (-1 == fa) {
				adde(i + n * T, n << 1);
			} else {
				deg[T][--fa]++;
				adde(i + n * T, fa + n * T);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		deg[0][i] &= 1;
		deg[1][i] &= 1;
		if (deg[0][i] != deg[1][i]) {
			puts("IMPOSSIBLE");
			return 0;
		}
		if (!deg[0][i]) {
			adde(i, i + n);
		}
	}
	dfs(0);
	vector<int> ans(n, 0);
	for (auto &e : vec) {
		int u = e.first, v = e.second;
		if (u < n && v >= n && v < n * 2) {
			ans[u] = 1;
		}
		if (v < n && u >= n && u < n * 2) {
			ans[v] = -1;
		}
	}
	puts("POSSIBLE");
	for (int i = 0; i < n; i++) {
		printf("%d%c", ans[i], " \n"[i + 1 == n]);
	}
	return 0;
}


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

ll mod = 1e9+7;

int main(){
    int N;
    string S;
    cin >> N >> S;
    vector<ll> cnt(26, 0);
    for (char c : S) cnt[c-'a']++;
    ll ans = 1;
    for (ll n : cnt) ans = ans*(n+1)%mod;
    cout << (ans-1+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 512
## ABC 054 b
import sys
import numpy as np

n,m = (int(_) for _ in input().split())
a = np.array([list(input()) for i in range(n)])
b = np.array([list(input()) for i in range(m)])

for i in range(n-m+1):
    for j in range(n-m+1):
        if ((b[:, :] == a[i:i+m, j:j+m]).all()):
            print('Yes')
            sys.exit(0)

print('No')

Measured memory_bytes: 12476
//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read(),d=read(),a[200005];
struct edge{
	int u,v,w;
	edge(){}
	edge(int _u,int _v,int _w){
		u=_u;v=_v;w=_w;
	}
	friend bool operator <(edge a,edge b){
		return a.w<b.w;
	}
};
edge e[200005<<8];
int cnt=0;
inline int calc(int i,int j){
	return d*abs(i-j)+a[i]+a[j];
}
inline void conquer(int l,int r){
	if(l==r)	return;
	int mid=(l+r)>>1;
	int mx1=0x3f3f3f3f3f3f3f3fll,ind1=0;
	fz(i,l,mid)		if(mx1>a[i]-i*d)	mx1=a[i]-i*d,ind1=i;
	int mx2=0x3f3f3f3f3f3f3f3fll,ind2=0;
	fz(i,mid+1,r)	if(mx2>a[i]+i*d)	mx2=a[i]+i*d,ind2=i;
	if(ind2)	fz(i,l,mid)		e[++cnt]={i,ind2,calc(i,ind2)};
	if(ind1)	fz(i,mid+1,r)	e[++cnt]={ind1,i,calc(ind1,i)};
	conquer(l,mid);conquer(mid+1,r);
} 
struct _ufs{
	int fa[200005];
	inline void init(){
		fz(i,1,n)	fa[i]=i;
	}
	inline int find(int x){
		return (fa[x]==x)?x:fa[x]=find(fa[x]);
	}
} ufs;
signed main(){
	fz(i,1,n)	a[i]=read();
	conquer(1,n);
	ufs.init();
	sort(e+1,e+cnt+1);
	int ans=0;
	fz(i,1,cnt){
		int u=e[i].u,v=e[i].v,w=e[i].w;
		int _u=ufs.find(u),_v=ufs.find(v);
		if(_u!=_v){
			ufs.fa[_u]=_v;
			ans+=w;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

struct UnionFind {
    vector<int> data;
    int __size;
    UnionFind(int size) : data(size, -1), __size(size) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) != (y = root(y))) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x; __size--;
        }
        return x != y;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return __size; }
};

template <typename T>
struct Edge { int src, dst; T cost;
    Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { }
    Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { }
};
template <typename T> using Edges = vector<Edge<T>>;
template<typename T>
pair<T, Edges<T>> kruskal(Edges<T> &edges, int v) {
    sort(begin(edges), end(edges), [](const Edge<T> &a, const Edge<T> &b) {
        return a.cost < b.cost;
    });
    UnionFind uf(v);
    T total = 0; Edges<T> F;
    for (auto &e: edges) {
        if (uf.unionSet(e.src, e.dst)) total += e.cost, F.emplace_back(e);
    }
    return {total, F};
}

int main() {
    int V, E; cin >> V >> E;
    Edges<int> edges;
    while (E--) {
        int s, t, w; cin >> s >> t >> w;
        edges.emplace_back(s, t, w);
    }
    cout << kruskal(edges, V).first << endl;
    return 0;
}


Measured memory_bytes: 4516
//190528AGC016A　結果　RE　原因不明で修正できず

#include<stdio.h>
#include<string.h>
#include<stdbool.h>


char S[102];//文字列//初期化のためグローバル宣言とした
char s[102];//操作用文字列//初期化のためグローバル宣言とした

int main() {

	//方針
	//初期状態において全て同じアルファベットならば終了する
	//全てのアルファベットで何回書き換えが必要か全探索する

	//変数
	//char S[100];//文字列//初期化のためグローバル宣言とした
	int  len_S;//文字列の文字数
			   //char s[100];//操作用文字列//初期化のためグローバル宣言とした
	int  len_s;//操作用文字列の文字数
	char word;//指定文字
	int change_cnt = -1;//操作用文字列での必要書き換え回数（探索用）
	int result[26];//操作用文字列での必要書き換え回数//初期化のためグローバル宣言とした
	int match_cnt;//探索時２つ共同じ文字であった回数

	int i;
	bool fin = false;
	int ans = 10000;

	//文字列を入力する
	scanf("%s", S);
	len_S = strlen(S);

	//アルファベット全探索(所定文字でのループ）
	for (word = 97; word < 123; word++)
	{
		//操作用文字列を作成する
		strcpy(s, S);
		len_s = strlen(s);

		//変数の初期化
		change_cnt = -1;

		for (int i = 0; i < 26; i++)
		{
			result[i] = 1000;
		}

		while (fin == false)//この文字で文字毎のループ
		{
			//変数の初期化
			match_cnt = -1;

			change_cnt++;

			if (len_s == 1)
			{
				result[word - 97] = change_cnt;//この文字における必要な文字列書き換え回数の結果
											   //printf("result[%c] : %d\n", word, result[word - 97]);
				fin = true;//この文字でのシミュレーションは終了した
				break;//この文字でのシミュレーションは終了した
			}
			else
			{

				for (i = 0; i < len_s - 1; i++)//文字列の全ての文字に対して最初から最後のひとつ前まで
				{
					if (s[i] == word && s[i + 1] == word)//二つともこの文字と一致
					{
						match_cnt++;//回数をカウントする
									//s[i] = word;//この文字に変更する
					}
					else if (s[i] == word || s[i + 1] == word)//二つのいずれかがこの文字と一致
					{
						s[i] = word;//この文字にする
					}
					else//二つのいずれもこの文字と一致しない
					{
						if (len_s == 2)//len_sが２だったらこの文字のみの文字列にはならない
						{
							//result[word - 97]の値は変更しない
							//printf("result[%c] : %d\n", word, result[word - 97]);
							fin = true;//この文字でのシミュレーションは終了した
							break;//この文字でのシミュレーションは終了した
						}
					}

					if (i == match_cnt && i == len_s - 2)//全てこの文字になっていた場合
					{
						result[word - 97] = change_cnt;//この文字における必要な文字列書き換え回数の結果
													   //printf("result[%c] : %d\n", word, result[word - 97]);
						fin = true;//この文字でのシミュレーションは終了した
						break;//この文字でのシミュレーションは終了した
					}
				}
			}
			len_s--;//一番右の文字を削除する代わりに文字列長さをひとつ減らす

		}//この文字で文字毎のループ

		if (result[word - 97] < ans)
		{
			ans = change_cnt;
		}

		fin = false;
	}//アルファベット全探索(所定文字でのループ）

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

	return 0;
}


Measured memory_bytes: 128
s = list(input())

MOD = pow(10, 9) + 7

n = len(s)

dp = [[0] * 13 for _ in range(n)]

#r = list(range(10))

#init
if s[-1] == "?":
    for j in range(10):
        dp[0][j] = 1
else:
    q = int(s[-1])
    dp[0][q] = 1

r = 1

for i in range(1, n):
    r = r * 10 % 13
    # for l in range(10):
    #     r[l] = r[l] * 10 % 13

    #print(r)

    if s[n-i-1] == "?":
        for j in range(10):
            q = j * r % 13
            for k in range(13):
                dp[i][k] += dp[i-1][k-q] % MOD
    
    else:
        q = int(s[n-i-1]) * r % 13
        #print(q)
        for k in range(13):
            dp[i][k] += dp[i-1][k-q] % MOD
    #print(dp[i])

print(dp[n-1][5] % MOD)

Measured memory_bytes: 101196
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a%mod; a = a * a%mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
// head

const int MAXN = 500000+5;
int N,K;
int P[MAXN];
int pos[MAXN];
int temp[MAXN];
int minp[MAXN];

void solve(int l, int r) {
    if(l==r) return;
    int mid = (l+r)>>1;
    solve(l,mid); solve(mid+1,r);

    rep(i,l,r+1) temp[i] = pos[i];
    minp[mid] = temp[mid];
    per(i,l,mid) minp[i] = min(minp[i+1], temp[i]);

    int p = l;
    int i = l, j = mid+1;
    while(i<=mid && j<=r) {
        if(minp[i]-temp[j]<K) pos[p++] = temp[i++];
        else pos[p++] = temp[j++];
    }
    while(i<=mid) pos[p++] = temp[i++];
    while(j<=r) pos[p++] = temp[j++];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifdef RG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
#endif

    cin>>N>>K;
    rep(i,0,N) cin>>P[i];

    rep(i,0,N) pos[P[i]] = i;

    solve(1,N);

    rep(i,1,N+1) P[pos[i]] = i;

    rep(i,0,N) cout<<P[i]<<endl;
    
    return 0;
}

Measured memory_bytes: 11392
#include <stdio.h>
int main(){
  char num[1200];
  int sum=0, i=0, number;

  while(1){
    scanf("%s",num);
    if(num[0]=='0')break;
    while(1){
      if(num[i]=='\0')break;
      number=num[i]-'0';
      sum=sum+number;
      i++;
    }
    printf("%d\n",sum);
    sum=0;
    i=0;
  }
  return 0;
}

Measured memory_bytes: 540
#include <stdio.h>
#define M 100002

//Queue P87

typedef struct{
    char name[10];
    int t;
} Q;


Q Que[M];
int head,tail; //この時Que[M]はリング状になってて、先頭と末尾の表現が必要

void enqueue(Q x){
  Que[tail]=x;
  tail=(tail+1)%M; //キューの末尾に並ばせてtail++(リング状なので%Mが必要)
}

Q dequeue(){
  Q x;
  x=Que[head];   //エンキューと同じ
  head=(head+1)%M;
  return x;
}

int main(void){
  int i,n,q,p=0,s;
  Q in,de;
  head=tail=0;
    
  scanf("%d %d",&n,&q); //n:入力数 q:一回に処理できる時間、処理できない分は後に回す
  for(i=0;i<n;i++){
    scanf("%s %d",in.name,&in.t);
    enqueue(in);
  }
    
  while(head!=tail){ //head==tailはqueueが空っぽ
    de=dequeue();
    s=de.t-q;
    if(s>0) {
      de.t=s;
      enqueue(de);
      p+=q; //p:
    }
    else {
      p+=de.t;
      printf("%s %d\n",de.name,p);
            
    }
  }
  return 0;
}



Measured memory_bytes: 3284
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

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


//main関数
int main() {
	int H,M,h,m,K;
	scanf("%d %d %d %d %d",&H,&M,&h,&m,&K);
	
	int jikan = 60*(h-H) + m-M-K;
	printf("%d",jikan);
	return 0;
}

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

int freq[300];
vector<int> adj[300];

int main(){
    
    string s, t; cin >> s >> t;
    for(char c : s)
        freq[c]++;
    for(char c : t)
        if(!freq[c]){
            cout << "-1" << endl;
            return 0;
        }
    for(int i = 0; i < s.size(); i++)
        adj[s[i]].push_back(i);
    int len = s.size();
    ll res = 0;
    int last = -1;
    for(int i = 0; i < t.size(); i++){
        char c = t[i];
        auto it = upper_bound(adj[c].begin(), adj[c].end(), last);
        
        int p = -1;
        if(it == adj[c].end()) p = adj[c].front();
        else p = *it;
        
        if(last < p) res += (p-last);
        else res += (len-last-1)+(p+1);
        last = p;
        // cout << i << " " << last << endl;
    }
    cout << res << endl;
	return 0;
}


Measured memory_bytes: 1216
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
    int n;
    cin >> n;
    double maxd[2] = {-1, -1};
    double tim[2] = {-1, -1};
    int t, a, f, x, y;
    cin >> t >> a >> f >> x >> y;
    for(int i = 1; i < n; i++){
        int nf, na, nt, nx, ny;
        cin >> nt >> na >> nf >> nx >> ny;
        if(f == nf && a != na){
            double d = sqrt(pow(nx-x,2.0)+pow(ny-y,2.0));
            if(maxd[f] < d || (maxd[f]==d && (nt-t)/60.0 < tim[f])){
                maxd[f] = d;
                tim[f] = (nt-t)/60.0;
            }
        }
        f = nf, a = na, t = nt, x = nx, y = ny;
    }
    for(int i = 0; i < 2; i++){
        cout << fixed << setprecision(12) << maxd[i] << " " << tim[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, K;
  cin >> N >> K;

  map<int,int> memo;
  rep(i,K){
    int d;
    cin >> d;
    rep(j,d){
      int a;
      cin >> a;
      memo[a]++;
    }
  }

  cout << N - memo.size() << endl;
  
  
  return 0;
}


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

using namespace std;

#define ll long long

int main()
{
	char d,e;
	cin>>d>>e;
	int n = d-'0';
	int m = e-'0';
	string a;
	if(n == m)
	{
		for(int i = 0;i<n;i++)
		{
			a+=d;
		}
	}
	else if(n<m)
	{
		for(int i = 0;i<m;i++)
		{
			a+=d;
		}
	}
	else if(n>m)
	{
		for(int i = 0;i<n;i++)
		{
			a+=e;
		}
	}
	cout<<a;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    static int mod = (int)1e9+7;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long A[] = new long[N];
        for(int i=0;i<N;i++)A[i]=sc.nextLong();
        sc.close();

        long ans = 0;
        for(int i=0;i<61;i++) {
            int cnt = 0;
            for(int j=0;j<N;j++) {
                if(((A[j]>>i)&1)==1) cnt++;
            }
            ans += (long)cnt * (((long)(N-cnt) * (((long)1<<i)%mod))%mod);
            ans %= mod;
//            System.out.println(ans);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 98096
#include <iostream>
#include <iomanip>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

const double INF = 1e+10;

typedef double Weight;
struct Edge{
  int src, dest; Weight weight;
  Edge(int src_, int dest_, Weight weight_):src(src_),dest(dest_),weight(weight_){}
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

// Dijkstra (Verified: AOJ2005)
void dijkstra(Graph &g, Array &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  typedef pair<Weight,int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        que.push(P(d[e.dest], e.dest));
      }
    }
  }
}

int main() {
  while(1){
    int n,m;
    cin>>n>>m;
    if(!n)break;
    int s,t;
    cin>>s>>t;
    --s;--t;
    vector<int> x(m);
    vector<int> y(m);
    vector<int> d(m);
    vector<int> c(m);
    vector<int> ecnt(n);
    REP(i,m){
      cin>>x[i]>>y[i]>>d[i]>>c[i];
      --x[i];--y[i];
      ++ecnt[x[i]];
      ++ecnt[y[i]];
    }
    vector<int> psum(n+1);
    partial_sum(begin(ecnt),end(ecnt),begin(psum)+1);
    Graph g(psum.back() * 31 * 2 + 1);
    int half = psum.back() * 31;
    vector<int> cpect = ecnt;
    REP(i,m){
      --ecnt[x[i]];
      --ecnt[y[i]];
      int index = psum[x[i]] + ecnt[x[i]];
      int index_to = psum[y[i]] + ecnt[y[i]];
      index *= 31;
      index_to *= 31;
      REP(j,c[i]+1){
        if(j==0)continue;
        g[index + j].emplace_back(index + j, index_to + j + half, double(d[i])/j);
        g[index_to + j].emplace_back(index_to + j, index + j + half, double(d[i])/j);
      }
    }
    REP(i,n){
      REP(j,31){
        if(j==0)continue;
        REP(k,cpect[i])
          REP(l,k){
            int i_s = (psum[i] + k) * 31 + j;
            int i_t = (psum[i] + l) * 31 + j;
            g[i_s + half].emplace_back(i_s + half, i_t, 0);
            g[i_t + half].emplace_back(i_t + half, i_s, 0);
            if (j > 1) {
              g[i_s + half].emplace_back(i_s + half, i_t - 1, 0);
              g[i_t + half].emplace_back(i_t + half, i_s - 1, 0);
            }
            if (j < 30) {
              g[i_s + half].emplace_back(i_s + half, i_t + 1, 0);
              g[i_t + half].emplace_back(i_t + half, i_s + 1, 0);
            }
          }
      }
    }
    double mint = INF;
    REP(i,cpect[s]){
      g[half * 2].emplace_back(half*2, (psum[s] + i)*31+1, 0);
    }
    Array dist(psum.back() * 31 * 2 + 1);
    dijkstra(g, dist, half*2);
    REP(i,cpect[t]){
      mint = min(mint, dist[(psum[t]+i)*31+1 + half]);
    }
    if (mint < INF)
      cout << setprecision(8) << fixed << mint << endl;
    else
      cout << "unreachable" << endl;
  }
  return 0;
}

Measured memory_bytes: 54716