akhauriyash/Code-Regression huggingface dataset:
//解説参考
//他者コード参考
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

static const int MAX = 50;

using namespace std;

int N, K, ans;
int D[MAX + 2];


int solve() {
    
    for ( int a = 0; a <= K && a <= N; a++ ) {
        for ( int b = 0; a + b <= K && a + b <= N; b++ ) {
            vector<int> V;
            int sum = 0;
            
            for ( int i = 0; i < a; i++ ) {
                V.push_back(D[i]);
                sum += D[i];
            }
            for ( int i = 0; i < b; i++ ) {
                V.push_back(D[N - 1 - i]);
                sum += D[N - 1 - i];
            }
            ans = max(sum, ans);

            sort(V.begin(), V.end());
            
            int i = 0;
            while ( i < V.size() && a + b + i < K && V[i] < 0 ) {
                sum -= V[i++];
            }
            ans = max(sum, ans);
            
        }
        
    }
    return ans;
    
}

int main(void) {
    
    scanf("%d %d", &N, &K);
    
    for ( int i = 0; i < N; i++ ) {
        int v;
        scanf("%d", &v);
        D[i] = v;
    }
    
    printf("%d\n", solve());
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
ans=[]
n=N
1.upto(N) do|i|
  if n>=i
      ans.push(i)
      n-=i
  else
      ans.push(i)
      diff=i-n
      ans.delete_at(ans.index(diff))
      break
  end
end
puts ans.join("\n")

Measured memory_bytes: 3836
def z(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a,b=map(int,input().split())
A=set(z(a))
B=set(z(b))
c=[i for i in A if i in B]
print(len(c)+1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

struct UnionFind{
	std::vector<int> par, rnk, cnt;
	UnionFind(int n){
		par.assign(n, 0);
		rnk.assign(n, 0);
		cnt.assign(n, 1);
		for(int i=0; i<n; i++) par[i]=i;
	}
	int root(int i){
		if(par[i]==i) return i;
		return par[i]=root(par[i]);
	}
	void unite(int i, int j){
		int ri = root(i);
		int rj = root(j);
		if(ri==rj) return;

		if(rnk[ri]==rnk[rj]){
			cnt[rj] += cnt[ri];
			par[ri] = rj;
			rnk[rj]++;
		}
		else if(rnk[ri] < rnk[rj]){
			cnt[rj] += cnt[ri];
			par[ri] = rj;
		}
		else{
			cnt[ri] += cnt[rj];
			par[rj] = ri;
		}
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	int count(int i){
		return cnt[root(i)];
	}
};

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

	vector<pair<int, int>> F(M);
	for(int i=0; i<M; i++){
		cin >> F[i].first >> F[i].second;
		F[i].first--;
		F[i].second--;
		if(F[i].first > F[i].second) swap(F[i].first, F[i].second);
	}
	vector<pair<int, int>> B(K);
	for(int i=0; i<K; i++){
		cin >> B[i].first >> B[i].second;
		B[i].first--;
		B[i].second--;
		if(B[i].first > B[i].second) swap(B[i].first, B[i].second);
	}

	UnionFind uf(N);
	for(int i=0; i<M; i++){
		uf.unite(F[i].first, F[i].second);
	}

	vector<int> ans(N);
	for(int i=0; i<N; i++){
		ans[i] = uf.count(i)-1;
	}

	for(int i=0; i<M; i++){
		ans[F[i].first]--;
		ans[F[i].second]--;
	}

	for(int i=0; i<K; i++){
		if(uf.same(B[i].first, B[i].second)){
			ans[B[i].first]--;
			ans[B[i].second]--;
		}
	}

	for(int i=0; i<N; i++) cout << ans[i] << (i==N-1?'\n':' ');

	return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

#define MAX 200000
#define INFTY 1<<30

using namespace std;

static const int N = 1000;

int lcs(string X, string Y)
{
  int dp[N+1][N+1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;

  X = ' ' + X;
  Y = ' ' + Y;
  for(int i = 0; i < m; i++) dp[i][0] = 0;
  for(int j = 0; j < n; j++) dp[0][j] = 0;

  for(int i = 1; i <= m; i++)
  {
    for(int j = 1; j <= n; j++)
    {
      if(X[i] == Y[j])
        dp[i][j] = dp[i-1][j-1] + 1;
      else
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      maxl = max(maxl,dp[i][j]);
    }
  }
  return maxl;
}

int main()
{
  int n; cin >> n;
  string s1, s2;
  for(int i = 0; i < n; i++)
  {
    cin >> s1 >> s2;
    cout << lcs(s1,s2) << endl;
  }
  return 0;
}

Measured memory_bytes: 5128
"use strict"
function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var N=input.shift();
  var last=[];//last[hoge]で色hogeの最後の位置
  for(let i=0;i<2000000;i++)last[i]="not yet";
  last[input[0]]=0;
  var dp=[1];//dp[i]で石0~iまでの色の塗られ方の場合の数
  var M=Math.pow(10,9)+7;
  for(let i=1;i<N;i++){
    let c=input[i];
    if(last[c]==="not yet"||last[c]===i-1){
      last[c]=i;
      dp[i]=dp[i-1];
      continue;
    }
    dp[i]=(dp[i-1]+dp[last[c]])%M;
    last[c]=i;
  }
  console.log(dp.pop());
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 114268
def floor(a, b):
    return ((-a)//b)*-1


N = int(input())
ratio = []
for _ in range(N):
    ratio.append(list(map(int, input().split())))

v_T = ratio[0][0]
v_A = ratio[0][1]

for t, a in ratio[1:]:
    diff_t = t - v_T
    diff_a = a - v_A

    d = max(floor(v_T, t), floor(v_A, a))
    v_T = d*t
    v_A = d*a


print(v_T+v_A)


Measured memory_bytes: 3188
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll n, k;
	ll ans = 1;

	cin >> n >> k;

	REP(i, n) {
		if (ans + k > ans * 2) {
			ans *= 2;
		}
		else {
			ans += k;
		}
	}

	cout << ans << endl;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

int main(){

    ll n, m;
    cin >> n >> m;

    ll ans = 0;
    if(m >= n*2){
        ans += n;
        m -= 2*n;
        n = 0;
        if(m < 0) m = 0;
        ans += m/4;
    }
    else{
        ans += m/2;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3556
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)

	a, b := nextInt(), nextInt()
	if a * 500 >= b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 640
///
// File:  alds1_9_b.cpp
// Author: ymiyamoto
//
// Created on Sun Oct 15 23:11:24 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

static vector<int64_t> array;

void build_heap(int32_t index)
{
  int32_t left = index * 2;
  int32_t right = index * 2 + 1;

  int64_t max_index = index;
  if (left <= (int32_t)array.size()) {
    if (array[max_index - 1] < array[left - 1]) {
      max_index = left;
    }
  }
  if (right <= (int32_t)array.size()) {
    if (array[max_index - 1] < array[right - 1]) {
      max_index = right;
    }
  }

  if (max_index != index) {
    swap(array[index - 1], array[max_index - 1]);
    build_heap(max_index);
  }
}

void build_max_heap()
{
  for (int32_t i = array.size() / 2; i > 0; i--) {
    build_heap(i);
  }
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    int64_t val;
    cin >> val;
    array.push_back(val);
  }

  build_max_heap();

  for (uint32_t i = 0; i < array.size(); i++) {
    cout << " " << array[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 6864
#include <iostream>
#include <string>
using namespace std;
int gcd(int x,int y);
int main(void)
{
    int k;
    int sum=0;
    cin>> k;
    for (int i=1;i<k+1;i++)
    {
        for (int j=1;j<k+1;j++)
        {
            for (int f=1;f<k+1;f++)
            {
                sum=sum+gcd(i,gcd(j,f));
            }
        }
    }
    cout << sum;
}
int gcd(int x, int y)
{
    int z = y;
    while(x%y!=0)
    {
        z = x%y;
        x = y;
        y = z;
    }
    return z;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    int K;
    cin >> K;
    int N = S.size();
    vector<v2ll> dp(N + 1, v2ll(10, vll(3 + 1)));
    vector<v2ll> dp2(N + 1, v2ll(10, vll(3 + 1)));
    dp[0][0][0] = 1;
    dp2[0][0][0] = 1;
    reverse(S.begin(), S.end());
    REP(i, 1, N + 1) {
        REP(j, 0, 10) {
            REP(k, 0, 4) {
                if (j != 0) {
                    if (k == 0) continue;
                    REP(l, 0, 10) {
                        dp[i][j][k] += dp[i - 1][l][k - 1];
                    }
                }
                else {
                    REP(l, 0, 10) {
                        dp[i][j][k] += dp[i - 1][l][k];
                    }
                }
            }
        }

        REP(j, 0, 10) {
            REP(k, 0, 4) {
                if (j < S[i - 1] - 0x30) {
                    dp2[i][j][k] = dp[i][j][k];
                    
                }
                else if (j == S[i - 1] - 0x30) {
                    if (j != 0) {
                        if (k == 0) continue;
                        REP(l, 0, 10) {
                            dp2[i][j][k] += dp2[i - 1][l][k - 1];
                        }
                    }
                    else {
                        REP(l, 0, 10) {
                            dp2[i][j][k] += dp2[i - 1][l][k];
                        }
                    }
                }
            }
        }
    }

    ll ans = 0;
    REP(i, 0, 10) 
        ans += dp2[N][i][K];
    //if (S[N - 1] < S[N - 2]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import java.io.*;

/**
 * Created by Ayushi on 04/08/2019.
 */

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        r.close();
        int ans = 0;
        int i;
        for (i = 1; i*10 <= n; i=i*100) {
            ans += (i*9);
        }
        ans += Math.max(n-i+1, 0);

        System.out.println(ans);
    }
}


Measured memory_bytes: 21076
import sys
ip1 = input()# your code goes here
ip2 = input()
if(len(ip1)!=len(ip2)):
	print("No\n")
	sys.exit()
if(ip1==ip2):
	print("Yes\n")
	sys.exit()
for i in range(len(ip1)):
	for j in range(i+1,len(ip1)):
		st1 = ip1[j:len(ip1)]+ip1[0:j]
		if(st1==ip2):
			print("Yes\n")
			sys.exit()
print("No\n")
sys.exit()

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

void greska(){
    fprintf(stderr, "-1\n");
    exit(EXIT_FAILURE);
}

int main(){
    int n;
    scanf("%d", &n);
    if(n<1 || n>100)
        greska();
    
    double sum=0;
    int x;
    for(int i=0; i<n; i++){
        scanf("%d", &x);
        //uslov - greska
        
        sum += 1/(double)x;
    }
    
    printf("%lf\n", 1/sum);
    
    exit(EXIT_SUCCESS);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int mp[11][11];
int d[11];

int main() {
  int h, w;
  cin >> h >> w;

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> mp[j][i];
    }
  }

  for (int i = 0; i < 10; i++) {
    d[i] = INF;
  }
  d[1] = 0;
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0,1));
  while (!que.empty()) {
    P top = que.top();
    que.pop();
    if (top.first > d[top.second]) continue;
    for (int i = 0; i < 10; i++) {
      if (i == top.second || i == 1) continue;
      if (d[i] > d[top.second] + mp[top.second][i]) {
        d[i] = d[top.second] + mp[top.second][i];
        que.push(P(d[i], i));
      }
    }
  }
  int b, ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> b;
      if (b == -1) continue;
      ans += d[b];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
const int N=1002;
bool f[N];
int i,j,k,n;
double t,x[N],y[N],r[N],d[N],a[N][N];
int main()
{
	scanf("%lf%lf%lf%lf%d",x,y,x+1,y+1,&n);
	for(i=2;i<n+2;++i)scanf("%lf%lf%lf",x+i,y+i,r+i);
	for(i=1;i<n+2;++i)for(j=0;j<i;a[j][i]=a[i][j],++j)
		if((a[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j])<0)a[i][j]=0;
	for(i=0;i<n+2;++i)d[i]=a[0][i];
	for(f[i=0]=1;i<n;++i)
	{
		for(t=2e9,j=1;j<n+2;++j)
			if(!f[j]&&d[j]<t)k=j,t=d[j];
		for(f[k]=j=1;j<n+2;++j)
			if(d[k]+a[k][j]<d[j])d[j]=d[k]+a[k][j];
	}
	printf("%.9f",d[1]);
}


Measured memory_bytes: 8064
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    l=1
    from collections import defaultdict
    dp=dict()
    ndp=dict()
    for i in range(K):
        ndp=dict()
        l=N
        s=0
        while l>0:
            d=N//l
            r=N//(d+1)
            if i==0:
                s=1
            else:
                s+=dp[d]
            ndp[l]=(l-r)*s%mod
            l=r
        dp=ndp
    ans=0
    from functools import reduce
    ans=reduce(lambda a,b:(a+b)%mod, dp.values())
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 255676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	ll A, B, K;
	cin >> A >> B >> K;

	rep1(i, K) {
		if (i % 2) {
			if (A % 2) A--;
			A /= 2;
			B += A;
		}
		else {
			if (B % 2) B--;
			B /= 2;
			A += B;
		}
	}
	cosp(A);
	co(B);

	Would you please return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

            final String sl[] = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);

            System.out.println((A - 1) * (B - 1));
        }
    }
}


Measured memory_bytes: 20692
N=int(input())
alp=[chr(ord('a')+i) for i in range(26)]


l=[0]
s=0

for i in range(1,20):
    s+=26**i
    l.append(s)
    if N <= s:
        break
x=N-l[-2]-1

ans=[0]*i
for j in range(i):
    q=x//26
    r=x%26
    x=q
    ans[-(j+1)]=alp[r]
print(''.join(ans))

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

using namespace std;

int main(){
    int n,ans = 0;
    cin >> n;
    int v[n],c[n],p[n];
    for(int i = 0; i < n ; i++){
        cin >> v[i];
    }
    for(int i = 0; i < n ; i++){
        cin >> c[i];
    }
    for(int i = 0; i < n ; i++){
        p[i] = v[i] - c[i];
    }
    sort(p,p+n,greater<int>());
    int i = 0;
    while(p[i] > 0){
        ans += p[i];
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
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(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 300010;

int main(){
        string s;
        while(getline(cin, s) && s!="."){
                stack<char> st;
                bool flag=true;
                for(char c: s){
                        if(c=='(' || c=='[') st.push(c);
                        if(c==')'){
                                if(st.empty() || st.top()!='('){
                                        flag=false;
                                        break;
                                }
                                else st.pop();
                        }
                        if(c==']'){
                                if(st.empty() || st.top()!='['){
                                        flag=false;
                                        break;
                                }
                                else st.pop();
                        }
                }
                if(flag && st.empty()) printf("yes\n");
                else printf("no\n");
        }
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    char s[100], p[100];
    string scp,s2,chk;
    scanf("%s %s",&s,&p);
    scp=s;
    chk=p;
    s2=scp+scp;
    if(s2.find(p) != string::npos){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

string b="RYGB";


int main(){fastio;
    ll h,w,d;cin>>h>>w>>d;
    ll a[h+1][w];
    if(d%2==1){
        rep(i,0,h-1)rep(j,0,w-1){
            a[i][j]=(i+j)%2;
        }
    }else{
        rep(i,0,h)rep(j,0,w-1){
            if((i+j)%2==0)continue;
            ll x=(i+j)/d%2;
            ll y=(i-j+inf)/d%2;
            a[i][j]=x*2+y;
        }
        rep(i,0,h-1)rep(j,0,w-1){
            if((i+j)%2==1)continue;
            a[i][j]=a[i+1][j];
        }
        
    }
    /*rep(i,0,h-1){
        rep(j,0,w-1){
            cout<<a[i][j];
        }cout<<endl;
    }*/
    
    rep(i,0,h-1){
        rep(j,0,w-1){
            rep(k,0,3){
                if(a[i][j]==k){
                    cout<<b[k];
                }
            }
        }cout<<endl;
    }
    
    return 0;
}








Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin>>S>>T;
  
  int a_s=S.size();
  int a_t=T.size();
  int count=0;
  int ans=0;
  
  for(int i=0 ; i< a_s - a_t + 1 ; i++){
    for(int j=0;j<a_t;j++){
      if(S.at(i+j)!=T.at(j))count++;
    }
    if(i==0)ans=count;
    if(ans>count)ans=count;
    count=0;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf 1000000000000000000

using namespace std;

void run();

signed main(){
    cout<<fixed;
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    string s,t;
    set<string> set;
    rep(i,n){
        cin>>s;
        if(i!=0&&t[t.length()-1]!=s[0]){
            puts("No");
            return;
        }
        if(set.find(s)!=set.end()){
            puts("No");
            return;
        }
        set.insert(s);
        t=s;
    }
    puts("Yes");
}

Measured memory_bytes: 256
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const D = Number(input[0][0]);
  const C = input[1].map(Number);
  const S = input.slice(2, 2 + D).map((line) => line.map(Number));
  const T = input.slice(2 + D, -1).map((line) => Number(line[0]));

  let score = 0;

  const V: number[] = [];
  const L = Array(26).fill(0);

  T.forEach((t, i) => {
    L[t - 1] = i + 1;

    score += S[i][t - 1];
    score -= C.reduce((sum, c, j) => sum + c * (i + 1 - L[j]), 0);

    V.push(score);
  });

  return V.join("\n");
};

console.log(main(read()));


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

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

    int num{0};

    for(int i{1}; i<=N; i=i+2){
        int yakusu{0};
        for(int j{1}; j<=i; ++j){
            if(i%j == 0){
                ++yakusu;
            }
        }
        if(yakusu==8){
            ++num;
            }
    }
    cout << num << endl;
}


Measured memory_bytes: 3600
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in reversed(range(n)):
    if B[i]-A[i+1] < 0:
        ans += B[i]
        A[i+1] -= B[i]
        B[i] = 0
    else:
        ans += A[i+1]
        B[i] -= A[i+1]
        A[i+1] = 0
    if B[i]-A[i] < 0:
        ans += B[i]
        A[i] -= B[i]
        B[i] = 0
    else:
        ans += A[i]
        B[i] -= A[i]
        A[i] = 0
print(ans)

Measured memory_bytes: 18624
#include<iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include<string>

using namespace std;

int main() {
	string str;
	cin >> str;
	if (str == "Sunny") cout << "Cloudy";
	else if (str == "Cloudy") cout << "Rainy";
	else cout << "Sunny";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0);

vector < vector < char > > arr;
int cache[1010][1010];
int m, n;

int dpSol(int i, int j)
{
    if(i == m && j == n)
        return 1;
        
    if(i > m || j > n)
        return 0;
        
    if(arr[i][j] == '#')
        return 0;
        
    int &res = cache[i][j];
    if(res != -1)
        return res;
        
    return res = (dpSol(i + 1, j) % MOD + dpSol(i, j + 1) % MOD) % MOD;
}

int main()
{
    fastIO
    cin >> m >> n;
    
    memset(cache, -1, sizeof(cache));
    
    arr = vector < vector < char > >(m + 1, vector < char >(n + 1));
    for(int i = 1; i <= m; ++i)
        for(int j = 1; j <= n; ++j)
            cin >> arr[i][j];
            
    cout << dpSol(1, 1);

    return 0;
}

Measured memory_bytes: 5376
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.regex.Pattern
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.collection.immutable.TreeMap
import scala.math._
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val Array(a, b, c, k) = input.split(" ").map(_.toLong)
    (if (k % 2 == 1) b - a else a - b ).toString
  }


  def factorize(x: Long): List[Long] = {
    def foo(x: Long, a: Long = 2, list: List[Long] = Nil): List[Long] = a*a > x match {
      case false if x % a == 0 => foo(x / a, a    , a :: list)
      case false               => foo(x    , a + 1, list)
      case true                => x :: list
    }
    foo(x)
  }

  def divisors(n: Long): Vector[Long] = {
    val halfList = (1 to sqrt(n).toInt).toVector.filter(_ % n == 0).map(_.toLong)
    val reversedList = if (sqrt(n).floor == sqrt(n)) halfList.reverse.tail.map(n/_) else halfList.reverse.map(n/_)
    halfList ++ reversedList
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """1 2 3 1""".stripMargin -> """1
                                   |""".stripMargin,
    """2 3 2 0""".stripMargin -> """-1""".stripMargin,
    """1000000000 1000000000 1000000000 1000000000000000000""".stripMargin -> """0""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 25500
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int compare(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
	int N;
	scanf("%d", &N);
	int d[N], i, ans=0;
	for(i=0; i<N; i++){
		scanf("%d", &d[i]);
	}

    qsort(d, N, sizeof(d[0]), compare);

	ans = d[N/2] - d[N/2-1];

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

	return 0;
}

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

using namespace std;

int main(){
	int n, m, x;
	cin >> n >> m >> x;
	std::vector<bool> A(m);
	for(int i = 0; i < m; i++){
		int tmp;
		cin >> tmp;
		A[tmp] = 1;
	}

	int front, back;
	front = back = 0;

	for(int i = 0; i < x; i++){
		if(A[i]) front++;
	}
	for(int i = x + 1; i < n; i++){
		if(A[i]) back++;
	}

	int ans = min(front, back);

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<stack>		// スタック
#include<queue>		// キュー

using namespace std;


int main()
{
	int A, B;
	cin >> A >> B;

	if (A + B >= 10)
	{
		cout << "error" << endl;
	}
	else
	{
		cout << A + B << endl;
	}

	return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n, x;
  cin >> n >> x;
  int d = 0, count = 0;
  for (int i = 0; i < n; i++) {
    int li;
    cin >> li;
    d += li;
    if (d <= x) count++;
  } 
  if (0 <= x) count++;
  cout << count << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int N,A,B,C;
vector<int> l(9);

int dfs(int i,int a,int b,int c){
    if (i == N){
        if ((a == 0) or (b==0) or (c==0)) return 1000000000;
        return abs(a-A) + abs(b-B) + abs(c-C) - 30;
    }

    int ret1 = dfs(i+1,a,b,c);
    int ret2 = dfs(i+1,a+l[i],b,c) + 10;
    int ret3 = dfs(i+1,a,b+l[i],c) + 10;
    int ret4 = dfs(i+1,a,b,c+l[i]) + 10;

    return min({ret1,ret2,ret3,ret4});
}

int main(){
    cin >> N >> A >> B >> C;

    REP(i,N){
        cin >> l[i];
    }

    cout << dfs(0,0,0,0) << "\n";
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    while 1:
        n = I()
        if n == 0:
            break
        m = 24*60**2
        a = [0]*m
        for i in range(n):
            l,r = input().split()
            l = list(map(int, l.split(":")))
            r = list(map(int, r.split(":")))
            l = l[2]+60*(l[1]+60*(l[0]))
            r = r[2]+60*(r[1]+60*(r[0]))
            a[l] += 1
            a[r] -= 1
        for i in range(m-1):
            a[i+1] += a[i]
        print(max(a))
    return

#Solve
if __name__ == "__main__":
    solve()



Measured memory_bytes: 10032
#include<stdio.h>
#include<math.h>
int main(void){
	double x1,x2,y1,y2,X,Y;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	X=x2-x1;
	Y=y2-y1;
	printf("%lf\n",hypot(X, Y));
	return 0;
}

Measured memory_bytes: 664
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

LL N,a[100010],X;

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

    int i;
    for (i=1; i<=N; i++)
        cin >> a[i];

    LL res=0;
    for (i=2; i<=N; i++){
        if (a[i]+a[i-1]<=X) continue;
        LL dif=a[i]+a[i-1]-X;

        res+=dif;
        a[i]=max(0LL,a[i]-dif);
    }

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<deque>
#include<queue>
#include<math.h>
#include<string>
#include<string.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<iomanip>
#include<map>
#include<bitset>
#include<algorithm>
#include<stack>
#include<unordered_map>
#include<cstdlib>
#include<unordered_map>
#include<algorithm>
 
#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
		
#define ii pair	<long long ,long long >
#define i64ii pair< long long, pair<int,int> >
#define i64i pair<long long , int >
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >	
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define id pair<int ,double > 
#define di pair<double, int>
 
#define pi 3.14159265359
#define nl (no<<1)
#define nr ( (no<<1)|1)
#define mid l + ( (r-l)>>1)
 
using namespace std;
 
 
typedef long long ll;	
typedef vector< int> vi;
typedef long double ld;
 
const int MAX = 800;
const int maxn = 2e5+100;

 
int main (){
	//~ in
	
	string a, b;
	cin >>a >>b;
	cout <<b+a<<'\n';
	
 
	return 0;
}




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

int main(){

  int c1,c2,c3;
  int sum;

  while(cin>>c1>>c2>>c3){
    sum = 0;

    for(int i=1; i<=10; i++){
	if(i!=c1 && i!=c2 && i!=c3 && c1+c2+i<=20)sum++;
    }

    if(sum/7.0 >= 0.5)cout << "YES" << endl;
    else cout << "NO" << endl;

  }


  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <iterator>
#include <bitset>
#include <random>
#include <assert.h>
#include <unordered_map>
#include <array>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second
#define MP make_pair
#define umap unordered_map

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> P;
typedef unsigned int uint;

struct UnionFind{
	vector<int> par, sz;
	UnionFind(int n){
		par = sz = vector<int>(n);
		for (int i = 0; i < n; ++i) par[i] = i, sz[i] = 1;
	}
	int find(int x){
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y){
		x = find(x), y = find(y);
		if (x == y) return;
		par[x] = y;
		sz[y] += sz[x];
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
	int size(int x){
		return sz[find(x)];
	}
};

int main(){
	int n;
	cin >> n;
	vector<pair<int, P>> v;
	rep(i, n - 1){
		int a, b, c;
		cin >> a >> b >> c;
		v.emplace_back(MP(c, MP(a, b)));
	}
	sort(ALL(v));

	UnionFind uf(n);

	ll ans = 0;
	for (auto edge : v){
		auto p = edge.second;
		ans += (ll)uf.size(p.first)*uf.size(p.second)*edge.first;
		uf.unite(p.first, p.second);
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 5140
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

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


void solve(){
	string S; cin >> S;
	ll dp[100005][13];
	Fill(dp,0);
	int n = S.size();
	dp[0][0] = 1;

	rep(i,n){
		int c;
		if(S[i]=='?') c = -1;
		else c = S[i] - '0';

		rep(j,10){
			if(c!=-1 && c!=j) continue;
			rep(k,13){
				dp[i+1][(k*10+j)%13] += dp[i][k];
			}
		}

		rep(j,13) dp[i+1][j] %= MOD;
	}

	cout << dp[n][5] << endl;
}


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


Measured memory_bytes: 10704
x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
c = 0
for i in range(1, n+1):
  l = len(str(i))
  count = 0
  for j in range(0, l):
    count += int(str(i)[j])
  if a <= count and count <= b:
    c += i
print(c)

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

int main () {
    int N;
    cin >> N;
    string hina;
    for (int i = 0; i < N; i++) {
        cin >> hina;
        if (hina == "Y") {
            cout << "Four" << endl;
            break;
        }
    }
    if (hina != "Y") {
        cout << "Three" << endl;
    }
}

Measured memory_bytes: 256
#pragma gcc optimize("O3")
#include <bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
int d,a,b,i2,pos,dp[102],res,tmp[102];
char k[10002];
int main()
{
    scanf("%s",&k);
    for(; k[pos]!=0; ++pos) a+=k[pos]-'0';
    scanf("%d",&d);
    dp[0]=1;
    a%=d;
    if(a==0) ++res;
    while(--pos>=0){
        if(k[pos]!='0'){
            b=k[pos]-'0';
            a-=b;
            while(a<0) a+=d;
            if(a) i2=d-a; else i2=0;
            for(int i=0; i<b; ++i){
                res+=dp[i2--];
                if(i2<0) i2+=d;
                if(res>=MOD) res-=MOD;
            }
        }
        tmp[0]=0;
        i2=d-1;
        for(int i=0; i<9; ++i){
            tmp[0]+=dp[i2--];
            if(i2<0) i2+=d;
            if(tmp[0]>=MOD) tmp[0]-=MOD;
        }
        for(int i=1; i<d; ++i){
           tmp[i]=tmp[i-1]+dp[i-1]-dp[++i2%d];
           if(tmp[i]>=MOD) tmp[i]-=MOD;
           else if(tmp[i]<0) tmp[i]+=MOD;
        }
        for(int i=0; i<d; ++i){
           dp[i]=dp[i]+tmp[i];
           if(dp[i]>=MOD) dp[i]-=MOD;
        }
    }
    if(--res<0) res+=MOD;
    printf("%d",res);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	
	public void solve(){
		Scanner sc =new Scanner(System.in);
		while(true){
			int x =sc.nextInt();
			if(x==0)
			break;//ループを抜ける
			int a = 0;
			boolean flag=false;//真偽の変数
			for(int s=0;s<x;s++){
				int r = sc.nextInt();
				if(r>0) a++;
				if(r>1) flag = true;
			}
			if(!flag) System.out.println("NA");
			else System.out.println(a+1);
		}
	}

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

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

int main() {
	ll n; cin >> n;
	vector<string> s(n); rep(i, 0, n) cin >> s[i];

	vector<char> march = { 'M','A','R','C','H' };
	map<char, ll> mp; rep(i, 0, 5) mp[march[i]];
	rep(i, 0, n) {
		if (mp.count(s[i][0])) {
			mp[s[i][0]]++;
		}
	}
	ll ans = 0;
	rep(i, 0, 3) {
		rep(j, i + 1, 4) {
			rep(k, j + 1, 5) {
				ans += mp[march[i]] * mp[march[j]] * mp[march[k]];
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6144
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){
	int N,ans=0;
	scanf("%d",&N);
	for (int i=1;i<N;i++){
		for (int j=1;j<N;j++){
			if (i*j<N){
				ans++;
			} else break;
		}
	}
	printf("%d",ans);
}

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

dic ={"AC":0,"WA":0,"TLE":0,"RE":0}

for i in range(n):
    a = input()
    dic[a] += 1

print("AC x",dic["AC"])
print("WA x",dic["WA"])
print("TLE x",dic["TLE"])
print("RE x",dic["RE"])

Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
    int w, h, c;
    cin >> w >> h >> c;
    ll t = gcd(w, h);
    cout << w / t * h / t * c << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;
typedef unsigned long long ull;



int main(){
 int n;
 cin >> n;
 vector<ll> a(n),b(n);
 rep(i,n) cin >> a[i] >> b[i];
 sort(all(a));
 reverse(all(a));
 sort(all(b));
 ll ans=a[0];
 ll h=0;
 rep(i,n*2){
   if (i%2==0){
     if (a[i/2]<=b[i/2]) break;
     ans+=a[i/2]-b[i/2];
     h=b[i/2];
   }
   else{
     if (a[i/2+1]<=b[i/2]) break;
     ans+=a[i/2+1]-b[i/2];
     h=a[i/2+1];
   }
 }
 ans+=abs(h);
 ll p=ans;
 h=0;
 ans=-b[0];
 rep(i,n*2){
   if (i%2==0){
     if (a[i/2]<=b[i/2]) break;
     ans+=a[i/2]-b[i/2];
     h=a[i/2];
   }
   else{
     if (a[i/2]<=b[i/2+1]) break;
     ans+=a[i/2]-b[i/2+1];
     h=b[i/2+1];
   }
 }
 ans+=abs(h);
 cout << max(ans,p) << endl;
}


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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    int K;
    cin >> K;
    vector<int> A(N,0);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    vector<bool> winF(K + 1,0);
    winF.at(0) = 0;

    for(int i = 1; i <= K; i++) {
        for(int j = 0; j < N; j++) {
            if(i - A.at(j) < 0) {
                break;
            }
            if(!winF.at(i - A.at(j))) {
                winF.at(i) = 1;
            }
        }
    }
    if(winF.at(K)) {
    cout << "First" << endl;
    } else {
    cout << "Second" << endl;
    }

    return 0;
}


Measured memory_bytes: 3644
def isKaibun(s):
    r = s[::-1]
    for i in range(len(s)):
        if s[i] == r[i]:continue
        else: return False
    return True

S = input()
N = len(S)
if isKaibun(S) and isKaibun(S[:(N-1)//2]) and isKaibun(S[(N+3)//2-1:N+1]):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3060
fun main(args:Array<String>) {
    val (a,b,m) = readLine()!!.split(" ").map { it.toInt() }
    val aList = readLine()!!.split(" ").map { it.toInt() }
    val bList = readLine()!!.split(" ").map { it.toInt() }
    val waribiki = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }
    var ans = aList.min()!! + bList.min()!!

    for(w in waribiki) {
        val tmp = aList[w[0]-1] + bList[w[1]-1] - w[2]
        ans = Math.min(ans, tmp)
    }
    println(ans)
}

Measured memory_bytes: 114240
import sys
def input(): return sys.stdin.readline().strip()


def main():
    D, N = map(int, input().split())
    cnt = 0
    n = 1
    while cnt < N:
        if n % (100**D) == 0 and n % (100**(D + 1)) != 0: cnt += 1
        n += 1
        if cnt == N: print(n - 1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 63348
#include<stdio.h>
#include<string.h>
int main(){
    int N;
    scanf("%d",&N);
    char judge[N][4];
    char ac[4]="AC";
    char wa[4]="WA";
    char tle[4]="TLE";
    char re[4]="RE";
    int i,a=0,w=0,t=0,r=0;
    for(i=0;i<N;i++){
        scanf("%s",judge[i]);
        if(strcmp(judge[i],ac) == 0){
            a++;
        }else if(strcmp(judge[i],wa) == 0){
            w++;
        }else if(strcmp(judge[i],tle) == 0){
            t++;
        }else if(strcmp(judge[i],re) == 0){
            r++;
        }    
    }

    printf("AC x %d\n",a);
    printf("WA x %d\n",w);
    printf("TLE x %d\n",t);
    printf("RE x %d",r);
    return 0;
}

Measured memory_bytes: 2120