akhauriyash/Code-Regression huggingface dataset:
def num_cleared(N, A):
    cleared = 0
    highest_h = 0
    for i in range(N):
        h = A[i]
        if h > highest_h:
            cleared += 1
            highest_h = h
    return cleared

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    cleared = num_cleared(N, A)
    if cleared >= K:
        print(0)
        return

    ans = N * 10**9
    for i in range(1 << N):
        highest_h = A[0]
        cost = 0
        B = [A[0]]
        for j in range(1, N):
            h = A[j]
            if ((i >> j) & 1) == 0:
                highest_h = max(h, highest_h)
                B.append(h)
                continue
            if highest_h >= h:
                cost += (highest_h - h) + 1
                highest_h += 1
                B.append(highest_h)
            else:
                B.append(h)
        cleared = num_cleared(N, B)
        if cleared >= K:
            ans = min(ans, cost)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9252
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int check = 1;
		for(int i=1; i<10; i++)
		{
			int f = N%i;
			if(f == 0)
			{
				int a = N/i;
				if(a > 0 && a < 10)
				{
					check = 2;
					System.out.println("Yes");
					return;
				}
			}
			if(i == 9 && check == 1)
				System.out.println("No");
		}
	}
}

Measured memory_bytes: 23380
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
int main(void){
    long long n,y;
    cin>>n>>y;
    for(int i=0;i<=n;i++){
        for(int j=0;i+j<=n;j++){
            long long sum=10000*i+5000*j+1000*(n-i-j);
            if(sum==y){
                cout<<i<<" "<<j<<" "<<n-i-j<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
}


Measured memory_bytes: 256
import std.array;
import std.conv;
import std.string;
import std.algorithm;
import std.stdio;

void main() {
	enum Mod = 10 ^^ 9 + 7;

	auto a = readln.chomp.split(' ').map!(to!int).array;
	auto height = a[0];
	auto width = a[1];

	auto grid = new string[height];
	foreach (ref e;grid) {
		e = readln.chomp;
	}

	auto dp = new long[][height + 1];
	foreach (ref e;dp) {
		e = new long[width + 1];
	}
	dp[0][1] = 1;

	foreach (size_t j, line;grid) {
		foreach (size_t i, e;line) {
			if (e == '#') {
				dp[j + 1][i + 1] = 0;
			} else {
				dp[j + 1][i + 1] = (dp[j][i + 1] + dp[j + 1][i]) % Mod;
			}
		}
	}

	writeln(dp[height][width]);
}


Measured memory_bytes: 11804
# AOJ 0177 Distance Between Two Cities
# Python3 2018.6.19 bal4u

PI = 3.1415926535897932384626433832795
M = (PI/180.0)

import math

while True:
	y1, x1, y2, x2 = list(map(float, input().split()))
	if x1 == -1 and y1 == -1 and x2 == -1 and y2 == -1: break
	a = math.cos(y1*M)*math.cos(y2*M)*math.cos((x1-x2)*M) + math.sin(y1*M)*math.sin(y2*M)
	print(int(6378.1*math.acos(a) + 0.5))



Measured memory_bytes: 5716
#include<bits/stdc++.h>
using namespace std;
#define lps(i,j,n) for(int i=j;i<n;i++)
#define lp(i,n) lps(i,0,n)
#define DEKAI 1000000007
#define INF (1<<28)

signed main(){
  int a[20000],m[20000];
  while(1){
    lp(i,20000){
      m[i]=0;
      a[i]=0;
    }
    int n,mm;
    cin>>n>>mm;
    if(n==0&&mm==0) break;
    lp(i,mm){
      int s,k;
      cin>>s>>k;
      lp(j,k){
	int x;
	cin>>x;
	m[x]+=s;
	if(k==1){
	  a[x]+=s;
	}
      }
    }
    int ansmax=-INF,es,ansmin=INF;
    lp(i,n){
      if(ansmax<m[i+1]) es=i;
      ansmax=max(ansmax,m[i+1]);
    }
    lp(i,n){
      if(i==es) continue;
      ansmin=min(ansmin,a[i+1]);
    }
    //  cout<<ansmax<<" "<<ansmin<<endl;
    cout<<ansmax-ansmin+1<<endl;
  }
  return 0;
}



Measured memory_bytes: 3208
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int n;

char wcz[nax];

int dp[nax][3];

int por(int a, int b, int x, int y)
{
	if (b-a!=y-x)
		return 0;
	for (int i=a; i<=b; i++)
		if (wcz[i]!=wcz[i-a+x])
			return 0;
	return 1;
}

int main()
{
	scanf("%s", wcz+1);
	n=strlen(wcz+1);
	for (int i=1; i<=n; i++)
		for (int j=0; j<3; j++)
			dp[i][j]=-nax;
	for (int i=1; i<3; i++)
		dp[i][i]=1;
	for (int i=1; i<n; i++)
	{
		for (int j=1; j<3 && j<=i; j++)
		{
			for (int l=1; l<3 && i+l<=n; l++)
			{
				if (!por(i-j+1, i, i+1, i+l))
				{
					dp[i+l][l]=max(dp[i+l][l], dp[i][j]+1);
				}
			}
		}
	}
	printf("%d\n", max(dp[n][1], dp[n][2]));
	return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e5+1;
vector<int> isprime(N1,1);
set<int>prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.insert(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.insert(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};
void solve(){
  int h,w;
  cin>>h>>w;
  int a[10][10], b[h][w];
  rep(i,0,10) rep(j,0,10) cin>>a[i][j];
  rep(k,0,10)  rep(i,0,10) rep(j,0,10) a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
  rep(i,0,h) rep(j,0,w) cin>>b[i][j];
  int sum=0;
  rep(i,0,h) rep(j,0,w) if(b[i][j]!=-1) sum+=a[b[i][j]][1];
  cout<<sum<<endl;
}

int main(){
    optimizeIO();

    {solve();}
}


Measured memory_bytes: 3824
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}

	index := solve(n, aa)
	fmt.Fprintln(writer, 2*n-1)
	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", index+1, i+1))
	}
	for i := 1; i < n; i++ {
		if aa[index] < 0 {
			fmt.Fprintln(writer, fmt.Sprintf("%d %d", n-i+1, n-i))
			continue
		}
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, i+1))
	}

	writer.Flush()
}

func solve(n int, aa []int) int {
	abmax := 0
	abmaxi := 0

	for i := 0; i < n; i++ {
		abs := absint(aa[i])
		if abmax < abs {
			abmax = abs
			abmaxi = i
		}
	}

	return abmaxi

}

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


Measured memory_bytes: 640
use std::io;


fn main() {
    let (a, b) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    println!("{} {} {}", a / b, a % b, (a as f64) / (b as f64));
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 5048
MOD = 1_000_000_007
N, M = gets.split.map(&:to_i)
A = M.times.map{gets.to_i}.group_by(&:itself)
puts (1 .. N).inject([0,1]){|dp,h| A[h] ? [dp[1],0] : [dp[1],(dp[0]+dp[1])%MOD] }[1]


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    string s, t;
    string ans = "";
    cin >> s >> t;
    int lenS = s.size(), lenT = t.size();
    vector<vector<int> > dp(lenS + 1, vector<int>(lenT + 1));
    rep (i, lenS) {
        rep (j, lenT) {
            if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
            else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        }
    }
    
    int i = lenS, j = lenT;
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i - 1][j]) --i;
        else if (dp[i][j] == dp[i][j - 1]) --j;
        else {
            ans = s[i - 1] + ans;
            --i, --j;
        }
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 35584
using System;

class Transfer{
    public static void Main(String[] args){
        int A, B, C;
        string[] input;

        input = Console.ReadLine().Split(' ');
        A = int.Parse(input[0]);
        B = int.Parse(input[1]);
        C = int.Parse(input[2]);
        
        A = A - B;
        C = C - A;

        if(C <= 0 ){
            Console.WriteLine('0');
        }else{
            Console.WriteLine(C);
        }
    }
}

Measured memory_bytes: 11092
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

bool isPrime[1000000];
int primes[1000000];
int primeSize = 0;
int main()
{
	fill(isPrime, isPrime+1000000, true);
	for (int i = 2; i < 1000; ++i)
	{
		if (isPrime[i])
		{
			for (int j = 2*i; j < 1000000; j += i)
				isPrime[j] = false;
		}
	}
	for (int i = 3; i < 1000000; ++i)
		if (isPrime[i])
			primes[primeSize++] = i;

	int n;
	while (scanf("%d", &n), n)
	{
		int ans = 0;
		for (int i = 0; primes[i] <= n/2; ++i)
			if (isPrime[n - primes[i]])
				++ans;
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> h(n+1);
	for (auto& e : h) {
		cin >> e;
	}
	h[n] = 1000000000 + 1;
	int max = 0;
	int cnt = 0;
	for (int i = 0;i < n;i++) {
		if (h[i] >= h[i + 1]) {
			cnt++;
		}
		else {
			if (cnt > max) {
				max = cnt;
			}
			cnt = 0;
		}
	}
	cout << max << endl;
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		input();
	}
	
	private static void input (){
		int d;
		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()){
			d = cin.nextInt();
			output(calculation(d));
		}
	}
	
	private static int calculation (int d){
		int e;
		int a = 0;
		int i = 0;
		
		for (e = 0; e <= 600 - d; e = d * i){
			a += e * e * d;
			i++;
		}
		return (a);
	}
	
	private static void output(int a){
		System.out.println(a);
	}
}

Measured memory_bytes: 26340
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int k,len;
    while(cin>>k)
    {
        cin>>s;
        len = s.size();
        if(k>=len)
            cout<<s<<'\n';
        else
        {
            for(auto i=0; i<k; i++)
                cout<<s[i];
            cout<<"..."<<'\n';
        }
    }
    return 0;
}


Measured memory_bytes: 3564
/*||>>>> Praveen Ojha <<<<>>>> 20 July 2019 <<<<>>>> 17:28:45 <<<<||*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

int32_t main(){__
	int r;
	cin>>r;
	cout<<3*r*r<<"\n";
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  vl p(3);
  rep(i, 3) cin >> p[i];
  sort(all(p));
  cout << p[0] + p[1] << newl;
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>


int main() {


	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	long long N; std::cin >> N;

	long long power = 1;
	for (int i = 1; i <= N; i++)
	{
		
		power *= i;
		if (power > 1000000007) {
			power %= 1000000007;
		}
	}

	std::cout << power;


	return 0;


}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
class FastIO
{
    static const int rdata_sz = (1 << 22), wdata_sz = (1 << 22);
    char rdata[rdata_sz], wdata[wdata_sz], *rb, *wb;

public:
    FastIO()
    {
        fread(rdata, 1, rdata_sz, stdin);
        rb = rdata;
        wb = wdata;
    }
    ~FastIO()
    {
        fwrite(wdata, 1, wb - wdata, stdout);
    }

    template <typename T>
    inline void read(T &x)
    {
        bool neg = false;
        x = 0;
        while ((*rb < '0' || *rb > '9') && *rb != '-')
            ++rb;
        while ('0' <= *rb && *rb <= '9')
        {
            x = 10 * x + (*rb - '0');
            ++rb;
        }
        if (neg)
            x = -x;
    }

#define pc(x) *(wb++) = x
    template <typename T>
    inline void write(T x)
    {
        if (x == 0)
        {
            pc('0');
            pc(' ');
            return;
        }
        if (x == 1)
        {
            pc('1');
            pc(' ');
            return;
        }
    }
#undef pc
};
int par[500001];
int ran[500001];
//要素xが所属する木の根を再帰的に発見する
inline int root(int x)
{
    if (par[x] == x)
        return x;
    return par[x] = root(par[x]); //経路圧縮
}
//要素xが属する木と要素yが属する木の併合
inline void unite(int x, int y)
{
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
        return; //同じ木に属してたらそのまま
    if (ran[rx] < ran[ry])
    {
        par[rx] = ry; //根がryの木に併合
    }
    else
    {
        par[ry] = rx; //根がrxの木に併合
        if (ran[rx] == ran[ry])
            ran[rx]++;
    }
}
//要素xが属する木と要素yが属する木が同じならtrueを返す
inline bool same(int x, int y)
{
    return root(x) == root(y);
}
int main()
{
    FastIO io;
    int N, Q;
    io.read(N);
    io.read(Q);
    for (int i = 0; i < N; i++)
    {
        par[i] = i;
        ran[i] = 0;
    }
    for (int i = 0; i < Q; i++)
    {
        int a, b, c;
        io.read(a);
        io.read(b);
        io.read(c);
        if (a == 1)
            if (same(b, c))
                io.write(1);
            else
                io.write(0);
        if (a == 0)
            unite(b, c);
    }
    return 0;
}


Measured memory_bytes: 7028
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int N, T;
	cin >> N >> T;
	int ans = 0;
	vector<int>data(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> data[i];
	}
	data[N] = INFINITY;
	for (int i = 0; i < N; i++) {
		if (data[i + 1] - data[i] >= T) {
			ans += T;
		}
		else {
			ans += data[i + 1] - data[i];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main()
{

    // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int K, N;
    cin >> K >> N;

    vector<int> A(N);

    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    int res = 2000000;
    for (int i = 0; i < N - 1; i++)
    {
        chmin(res, K - abs(A.at(i) - A.at(i + 1)));
    }
    chmin(res, abs(A.at(0) - A.at(N - 1)));

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a,b,dp[100][100][10001],c,keta=0,cmp,cmpp,data,m,h,w,x,y,xcmp,ycmp,cmps,cmpt,sum=0,d,kk;


vector<int> z;

int aa(long long int qq){
    sum=0;
    while(qq>0){
        qq/=10;
        sum++;
    }
    return sum;
}

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
        
       cin >> n;
       ans=aa(n);
       for(long long int a=1;a*a<=n;a++){
           if(n%a==0){
               b=n/a;
           }
           else{
               continue;
           }
         cmp=aa(a);
         cmpp=aa(b);
         if(ans>max(cmp,cmpp)){
             ans=max(cmp,cmpp);
         }
       }
       Cout(ans);
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x,cou=0;
  cin >>a>>b>>c>>x;
  for(int i=0;i<=a;++i){
    for(int j=0;j<=b;++j){
      for(int k=0;k<=c;++k){
        if(i*500+j*100+k*50==x)
          ++cou;
      }
    }
  }
  cout<<cou<<endl;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static int N;
        static long K;
        static int[] A;
        static List<int> a;
        static int loop = 0;
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            N = (int)NK[0];
            K = NK[1];

            A = Console.ReadLine().Split().Select(_ => int.Parse(_) - 1).ToArray();
            a = new List<int>();
            bool[] b = new bool[N];
            search(b,0,0);

            if (a.Count<= K)
            {

                int num = a.Count-loop + (int)((K-a.Count+loop)%loop);
                Console.WriteLine(a[num]+1);
            }
            else
            {
                Console.WriteLine(a[(int)K]+1);
            }
        }

        static int search(bool[] b,int now,int count)
        {
            int ans = 0;
            if (b[now])
            {
                 loop =count - a.IndexOf(now);
                 return count;
            }
            else
            {
                b[now] = true;
                a.Add(now);
                ans = search(b, A[now], count + 1);
            }

            return ans;
        }
    }
}


Measured memory_bytes: 57096
#include<utility>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
  int n, m, i, p, s;
  pair<int,int> w[10000];
  while(cin >> n >> m && n)
    {
      for( i = 0; i < n; i++)
	{
	  cin >> w[i].second >> w[i].first;
	}
      sort(w, w+n);
      i=1;
      while( i <= n  )
	{
	  if ((m -= w[n-i].second) <= 0)
	    {
	      w[n-i].second = -m;
	      p = n-i;
	      break;
	    }
	  i++;
	}
      s = 0;
      if (i <= n) for(i = 0; i <= p; i++) s += w[i].first * w[i].second;
      cout << s << endl;
    }
  return 0;
}

Measured memory_bytes: 1240
(* O(n^2) *)
let n = read_int ()
let divsor_count n =
  let rec f i = if i > n then 0 else f (i + 1) + if n mod i = 0 then 1 else 0 in f 1
let ans = ref 0
let _ =
  for i = 1 to n do if i mod 2 = 1 && divsor_count i = 8 then incr ans done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 384
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;

bool isPrime(int n){
  int ii;
  for(ii=2;ii<sqrt(n);ii++){
    if(n % ii == 0){
      return false;
    }
  }
  return true;
}

int num[1000000+1];

int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int n;
  vector<int> a;

  memset(num,0,sizeof(num));
  cin >> n;
  a.resize(n);

  for(ii=0;ii<n;ii++){
    cin >> a[ii];
  }

  bool flg=true;
  int cnt=0;

  sort(a.begin(),a.end());
  int start;
  int loop=0;

  for(ii=0;ii<n;ii++){
    num[a[ii]]++;

    if(num[a[ii]] == 1){
      for(jj=2 * a[ii];jj<=1000000;jj+=a[ii]){
        num[jj]++;
      }
    }
  }

  for(ii=0;ii<n;ii++){
    if(num[a[ii]] == 1){
      cnt++;
    }
  }
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 7948
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

string zeropad(string s){
    while(s.size() < 6){
        s = '0' + s;
    }
    return s;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> PY(M);
    for(int i=0; i<M; i++){
        cin >> PY[i].first >> PY[i].second;
    }
    vector<vector<int>> v(N);
    for(int i=0; i<M; i++)
        v[PY[i].first-1].push_back(PY[i].second);
    for(int i=0; i<N; i++)
        sort(v[i].begin(), v[i].end());
    vector<map<int, int>> u(N);
    for(int i=0; i<N; i++)
        for(int j=0; j<v[i].size(); j++)
            u[i][v[i][j]] = j+1;

    for(int i=0; i<M; i++){
        int P = PY[i].first;
        int Y = PY[i].second;
        string sa = to_string(P);
        string sb = to_string(u[P-1][Y]);
        sa = zeropad(sa);
        sb = zeropad(sb);
        cout << sa+sb << endl;
    }


    return 0;
}


Measured memory_bytes: 17152
#define _DEBUG
#include "bits/stdc++.h"
#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int main(){
	int N,Q;
	scan(N>>Q);
	UnionFind uf(N);
	rep(i,Q){
		int t,u,v;
		scan(t>>u>>v);
		if(t==0) uf.unite(u,v);
		else prin(uf.same(u,v));
	}
	return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
// #define fore(i,a) for(auto &i:a)
// #define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
// using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
// typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
// template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
// template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using namespace std;

int main()
{
  string s;
  cin>>s;
  
  if(s=="ABC"){
    cout<<"ARC"<<endl;
  }
  else if(s=="ARC"){
    cout<<"ABC"<<endl;
  }
  else{
    ;
  }
  
  return 0;
}

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

int main() {
	
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b) << endl;
	return 0;
}

Measured memory_bytes: 256
s=input()
if (int(s[0]+s[1])>12 or int(s[0]+s[1])==00) and int(s[2]+s[3])<=12 and int(s[2]+s[3])!=00:
    print("YYMM")
elif int(s[0]+s[1])<=12 and( int(s[2]+s[3])>12 or int(s[2]+s[3])==00) and int(s[0]+s[1])!=00:
    print("MMYY")
elif int(s[0]+s[1])<=12 and int(s[2]+s[3])<=12 and (int(s[0]+s[1])!=00 or int(s[2]+s[3])!=00):
    print("AMBIGUOUS")
else:
    print("NA")

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define pb push_back

using namespace std;

const int N = 310;

int n, m;
int A[N][N], pos[N];
bool vis[N];

vector<int> s[N];

bool check(int lim){
	memset(vis, false, sizeof vis);
	For(i, 1, m) vis[i] = false, s[i].clear();
	For(i, 1, n) pos[i] = 1, s[A[i][1]].pb(i);
	For(i, 1, m){
		int p = 0;
		For(j, 1, m) if(!vis[j] && int(s[j].size()) > lim){
			p = j; 
			break;
		}

		if(!p) return true;
		if(i == m) break;

		vis[p] = true;
		for(int o : s[p]){
			while(vis[A[o][pos[o]]]) ++pos[o];
			s[A[o][pos[o]]].pb(o);
		}
	}
	return false;
}

int main(){
	scanf("%d%d", &n, &m);
	For(i, 1, n) For(j, 1, m) scanf("%d", &A[i][j]);

	int L = 1, R = n;
	while(L < R){
		int mid = (L + R) >> 1;
		if(check(mid)) R = mid;
		else L = mid + 1;
	}

	printf("%d\n", L);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[26];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    //char now,pre;
    string s,s1;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>a;
        sum+=k>2*a?a:k-a;
    }
    cout<<sum*2;
    return 0;
}



Measured memory_bytes: 256
N,M=input().split()
N=int(N)
M=int(M)
a=list(map(int, input().split()))
a=list(set(a))
a=sorted(a)
b=sum(a)
c=b/(4*M)
if len(a)==N:
    if (1<=M<=N<=100)and(a[0]>=1)and(a[N-1]<=1000):
        if a[N-M]<c:
            print("No")
        if a[N-M]>=c:
            print("Yes")

Measured memory_bytes: 3064
n , k = map(int,input().split())
if k % 2 == 1:
    cou = 0
    for i in range(1,n+1):
        if i % k == 0:
            cou += 1
    print(cou**3)
elif k % 2 == 0:
    cou = 0
    cou2 = 0
    for i in range(1,n+1):
        if i % k == 0:
            cou += 1
        elif i % k == k//2:
            cou2 += 1
    print(cou**3+cou2**3)

Measured memory_bytes: 3060
#include "stdio.h"
#include "math.h"

main(){
  
  int x, i, j, n, c, t=0;
  
  scanf("%d", &n);

  for(j=0 ; j<n ;j++){

    scanf("%d", &x);

    c = 1;

  if(x == 2){ c = 1;
  
  }else if(x<2 || x%2 == 0)
      c = 0;
    
  for(i=3; i<=sqrt(x) ; i+=2){
      if(x % i == 0)
	   c = 0;
    }
 
    if(c==1)  t++;
  }

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

  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
#define ll long long
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
struct Line{int v,next;}e[MAX<<5];
int h[MAX],cnt=1,dg[MAX];;
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;}
void Yes(){puts("Yes");exit(0);}
void No(){puts("No");exit(0);}
int n,m,cir,del,mxd;
bool vis[MAX];
multiset<int> S[MAX];
int main()
{
	n=read();m=read();
	for(int i=1,u,v;i<=m;++i)u=read(),v=read(),++dg[u],++dg[v],Add(u,v),Add(v,u),S[u].insert(v),S[v].insert(u);
	for(int i=1;i<=n;++i)if(dg[i]&1)No();
	for(int u=1;u<=n;++u)
	{
		if(S[u].size()!=2){continue;}
		vis[u]=true;
		multiset<int>::iterator it=S[u].begin();
		int v1=*it;++it;int v2=*it;
		S[v1].erase(S[v1].find(u)),S[v2].erase(S[v2].find(u));
		if(v1==v2)++cir;
		else S[v1].insert(v2),S[v2].insert(v1);
		S[u].clear();
	}
	for(int i=1;i<=n;++i)
		if(!vis[i])mxd=max(mxd,(int)S[i].size()),++del;
	cir+=mxd/2;
	if(cir>=3||del>=3)Yes();
	else No();
	return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const int mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = 3.141592653589793;

int n,m;
ll dp[305][305][305];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    dp[0][1][1]=1;
    rep2(i,1,m+1)rep2(j,1,n+1)rep2(k,1,j+1){
        if (j!=n) dp[i][j+1][k]+=(dp[i-1][j][k]*(n-j))%mod;
        dp[i][j][k]+=(dp[i-1][j][k]*(j-k))%mod;
        dp[i][j][j]+=(dp[i-1][j][k]*k)%mod;
    }
    cout << dp[m][n][n]%mod << endl;
    return 0;
}

Measured memory_bytes: 218624
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin>>S;
  int size = S.size();
  ll dp[size+5][13]={}; 
  //dp[i][j] 上からi番目(1-indexed)までの組み合わせであまりがjとなるものの総数
  dp[0][0]=1;
  REP(i,size){
    REP(k,10){
      if(S[i] != '?' && (S[i] - '0') != k) continue;
      REP(j,13){
        int tmp = (j*10+k)%13;
        dp[i+1][tmp] += dp[i][j];
        dp[i+1][tmp] %= MOD;
      } 
    }
  }
  cout<<dp[size][5];

  return 0;
}

Measured memory_bytes: 10704
//encoding:utf-8
//#include <iostream> //c++
//#include<stack> //スタックに関して　最新のデータから捨てる
//#include<queue> //キューに関して　最古のデータから捨てる
//#include<math.h>
//#include<vector>
//#include<algorithm> //sort とかにいる
#include<bits/stdc++.h>//vector,algorithm,que
#include<time.h> //時間にかんして

#define ll long long
#define MOD 1000000007
#define INF (1<<29)
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(i%2==1){
    }
    else{
      cout<<s[i];
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 512
using System;

class MainMethod
{
    static void Main()
    {
        //入力
        string[] strdata = Console.ReadLine().Split(' ');
        int A1 = Convert.ToInt32(strdata[0]);
        int A2 = Convert.ToInt32(strdata[1]);
        int A3 = Convert.ToInt32(strdata[2]);

        //出力
        if(A1+A2+A3 >= 22)
        {
            Console.WriteLine("bust");
        }
        else
        {
            Console.WriteLine("win");
        }
    }
}

Measured memory_bytes: 11220
#from pprint import pprint
from collections import deque
#from collections import defaultdict
#from collections import Counter
#from copy import deepcopy
#from itertools
#from bisect import bisect_right #二分探索用のモジュール bisect_right(a_list,value)

#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。

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

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

# = [list(map(int,input().split())) for _ in range(XXXX)]

x,n = map(int,input().split())

pset = set(map(int,input().split()))

if x not in pset:
    print(x)
    exit()



for i in range(1,100):
    if (x-i) not in pset:
        print(x-i)
        exit()
    elif (x+i) not in pset:
        print(x+i)
        exit()








Measured memory_bytes: 65072
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int R=gi();
	    int G=gi();
	    int B=gi();
	    int N=gi();

	    int c=0;
	    for (int i=0; i<Math.floorDiv(N, R)+1;i++) {
	    	if (i*R>N)break;
	    	for (int j=0; j<Math.floorDiv(N, G)+1;j++) {
	    		int a=i*R+j*G;
	    		if(a>N)break;
	    		if (((N-a)%B)==0)c++;
		    }
	    }

	    System.out.println(c);
	}

	public static double f(double r, double n, double m, double i) {
		double a = 0;
		double b=0;
		if(0<i&&i<n) {
			a=Math.abs(r-((2*r/n)*i));
			a= Math.sqrt(Math.pow(r, 2) - Math.pow(a, 2));
		}
		if(0<i-m&&i-m<n) {
			b=Math.abs(r-(2*r*(i-m)/n));
			b=Math.sqrt(Math.pow(r, 2) - Math.pow(b, 2));
		}
		return 2* Math.max(a, b);
	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 37324
#include<stdio.h>

int main()
{
    int num,tem,res=0;
    scanf("%d",&num);
    for(int i=1;i<=num;i++)
    {
        tem=0;
        if(i%2==1)
        {

            for(int j=1;j<=i;j++)
            {
            if(i%j==0)
            {
                tem++;
            }
            }
            if(tem==8) res++;
        }
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 128
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=100005;

int dp[N][3];int cost[N][3];

void solve()
{
    int n;
    cin>>n;
    
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
            cin>>cost[i][j];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
                if(j!=k)
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+cost[i][j]);
        }
    }
    int ans=max(dp[n][0],dp[n][1]);
    ans=max(ans,dp[n][2]);
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
}


int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}






Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;

string isTriangle(int a[3]);

int main(){
    int n;
    int a[3];
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> a[0] >> a[1] >> a[2];
        cout << isTriangle(a) << endl;  
    }
}
string isTriangle(int a[3]){
    sort(a, a+3, greater<int>());
    if(a[1]*a[1] + a[2]*a[2] == a[0]*a[0]){
        return "YES";
    }
    else{
        return "NO";
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

int main(){  
  int k;
  cin >> k;
  vector<ll> a(k);
  rep(i,k) cin >> a[i];
  reverse(a.begin(),a.end());

  ll cnt = 2;
  ll ans = 2;
  if(a[0]!=2){ cout << -1 << endl; return 0; }
  rep(i,k){
    if(cnt%a[i]!=0 && cnt/a[i]==ans/a[i]){
      cout << -1 << endl; return 0;
    }
    cnt = ((cnt-1)/a[i])*a[i]+a[i];
    ans = (ans/a[i])*a[i] + a[i]-1;
  }
  cout << cnt << " " << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
//#include<time.h>

int main()
{
	int m, n, flag;
	int year, count_bamboo, bamboo[500000];
	char *Year;
	//clock_t start, end;
	Year = (char*)malloc(sizeof(char) * 7368791);
	while (1)
	{
		scanf("%d %d", &m, &n);
		if (m == 0 && n == 0) break;

		//start = clock();
		//mとnの関係で判断
		// 1 m>=n の時 m+n年
		// 2 m<n の時 埋められなくなる年をカウントしてそれがnを超える年
		// 2 m<n の時 埋められなくなる年をカウントしてそれがnを超える年
		//素数探すのに似とる//エラトステネスの篩
		if (m < n)
		{
			for (int i = 1; i < 7368791; i++) Year[i] = '0';//2から7368791まで初期化
			count_bamboo = 0;
			for (year = m; year < 7368791;)
			{
				count_bamboo++;
				if (count_bamboo >n)break;
				for (int i = year-1; i < 7368791; i += year)//yearの倍数埋める
					Year[i] = '1';
				for (int i = year;; i++) //埋まってないとこ探す
					if (Year[i] == '0')
					{
						year = i;
						Year[year] = '1';
						year++;
						break;
					}
			}
			printf("%d\n",year);			
		}
		else printf("%d\n",m+n);
		//end = clock();
		//printf("%.2f秒かかりました\n", (double)(end - start) / CLOCKS_PER_SEC);
	}
	free(Year);
	return 0;
}



Measured memory_bytes: 9448
L, R = map(int, input().split())

if R-L > 2018:
    print(0)
else:
    if (L//2019) < (R//2019):
        print(0)
    else:
        c = 2019
        for i in range(L, R):
            for j in range(i+1, R+1):
              c = min((i*j)%2019, c)
        print(c)

Measured memory_bytes: 3060