akhauriyash/Code-Regression huggingface dataset:
/*
    Author      : Dinesh Verra
    College     : ABV-IIITM
    Date        : 21/08/2020
*/
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision; 
using namespace std;
typedef long long ll;
// #define ll int
typedef unsigned long long ull;
#define cu continue
#define br break
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define inf INT_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define F first
#define S second
#define vll vector <ll>
#define vpll vector <pll>
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define all(v) v.begin(),v.end()
#define nl cout<<'\n'

template <typename A1>
void prn(A1&& arg)
{
	cout<<arg<<'\n';
}
template <typename A1, typename... A>
void prn(A1&& arg, A&&... args)
{
	cout<<arg<<' ';
	prn(args...);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


	string s;
	cin>>s;
	ll n=s.length();
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		ans=(ans+(s[i]-'0'))%9;
	}
	if((ans%9)==0) prn("Yes");
	else prn("No");
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
int table[3][3], vis[3][3], bvis[110], n, in;
map<int, pair<int, int> > pos;

bool Check_vis(){
	bool ans = (vis[0][0] && vis[1][1] && vis[2][2]);
	ans |= (vis[2][0] && vis[1][1] && vis[0][2]);
	
	ans |= (vis[0][0] && vis[0][1] && vis[0][2]);
	ans |= (vis[1][0] && vis[1][1] && vis[1][2]);
	ans |= (vis[2][0] && vis[2][1] && vis[2][2]);
		
	ans |= (vis[0][0] && vis[1][0] && vis[2][0]);
	ans |= (vis[0][1] && vis[1][1] && vis[2][1]);
	ans |= (vis[0][2] && vis[1][2] && vis[2][2]);
	
	return ans;
}

int main(){
	memset(vis, 0, sizeof(vis));
	memset(bvis, 0, sizeof(bvis));
	
	for(int i = 0 ; i < 3 ; i++){
		for(int j = 0 ; j < 3 ; j++){
			cin >> table[i][j];	
			bvis[table[i][j]] = 1;
			pos[table[i][j]] = make_pair(i, j);
		}
	}
	
	cin >> n;
	bool ok = false;
	
	while(n--){
		cin >> in;
		if(bvis[in]) vis[pos[in].first][pos[in].second] = 1;
		
		if(Check_vis()){
			ok = true;
			break;
		}
	}
	
	if(!ok) cout << "No" << endl;
	else cout << "Yes" << endl;

	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
string m[15];
int solve(int x,int y){
  if(m[x][y]=='1'){
    m[x][y]='0';
    if(x-1>=0 && x-1<12 && m[x-1][y]) solve(x-1,y);
    if(x+1>=0 && x+1<12 && m[x+1][y]) solve(x+1,y);
    if(y-1>=0 && y-1<12 && m[x][y-1]) solve(x,y-1);
    if(y+1>=0 && y-1<12 && m[x][y+1]) solve(x,y+1);
    return 1;
  }
  else return 1;
}
int main(void){
  int n;
  while(cin >> m[0]){
    for(int i=1;i<12;i++) cin >> m[i];
    n=0;
    for(int i=0;i<12;i++){
      for(int j=0;j<12;j++){
	if(m[i][j]=='1'){
	  solve(i,j);
	  n++;
	}
      }
    }
    cout << n << endl;
  }
}


Measured memory_bytes: 1192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = 0, a = 0;;
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			a = sc.nextInt();
			while(a%2==0) {
				a /= 2;
				count++;
			}
		}
		System.out.println(count);
		sc.close();
	}
}

Measured memory_bytes: 35848
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
int x=0,y=0,z=0,w=0,n=0,m=0;
std::vector<std::vector<int>> v(3,std::vector<int>(3));
rep(i,3){
  Rep(j,3){
    std::cin >> v[i][j];
  }
}
std::cin >> x;
while(x>0){
  x--;
  std::cin >> y;
  rep(i,3){
    Rep(j,3){
      if(v[i][j]==y){
        v[i][j]=0;
      }
    }
  }
}
rep(i,3){
  Rep(j,3){
    if(v[i][j]==0)z++;
    if(v[j][i]==0)w++;
  }
  if(w==3||z==3){
    std::cout << "Yes"<< '\n';
    return 0;
  }else{
    w=0;
    z=0;
  }
  if(v[i][i]==0)n++;
  if(v[i][2-i]==0)m++;
}
if(n==3||m==3){
  std::cout << "Yes" << '\n';
}else{
  std::cout << "No" << '\n';
}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
	int p[20][20], i, j, x, y, size, con = 0, max;
	char cm;
	
	for(i = 0; i < 10; i++){
		for (j = 0; j < 10; j++)p[i][j] = 0;
	}
	
	while (scanf("%d%c%d%c%d", &x, &cm, &y, &cm, &size) != EOF){
		for (i = 0; i < 10; i++){
			for (j = 0; j < 10; j++){
				if (abs(i - y) + abs(j - x) <= 1)p[i][j]++;
				if (size == 2 && abs(i - y) == 1 && abs(j - x) == 1)p[i][j]++;
				else if (size == 3 && abs(i - y) + abs(j - x) == 2)p[i][j]++;
			}
		}
	}
	
/*	for (i = 0; i < 10; i++){
		for (j = 0; j < 10; j++){
			printf("%d", p[i][j]);
			if (j == 9)puts("");
			else printf(" ");
		}
	}*/
	max = p[0][0];
	for (i = 0; i < 10; i++){
		for (j = 0; j < 10; j++){
			if (p[i][j] == 0)con++;
			if (p[i][j] > max)max = p[i][j];
		}
	}
	printf("%d\n%d\n", con, max);
	return (0);
}

Measured memory_bytes: 600
using System;
using System.Linq;

class Problem
{
  public static void Main()
  {
    var len = int.Parse(Console.ReadLine());
    var s = Console.ReadLine();

    var ans = 0;
    for (var i = 1; i < s.Length - 1; i++)
    {
      var a = s.Take(i).ToArray();
      var b = s.Skip(i).ToArray();
      ans = Math.Max(ans, a.Intersect(b).Count());
    }
    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 13396
/* 
   AOJ 2440
   Kagisys
   2015.4.26
 */

#include<stdio.h>
#include<string.h>
char id[256][11];

void registration(int registration_num)
{
  int i;
  for(i = 0; i < registration_num; i++)
    {
      scanf("%s", id[i]);
    }
  
}

void output_message(int certification_num, int registration_num)
{
  int i, j, opened = 1, closed = 0, door = closed;
  char input_id[11];
  for(i = 0; i < certification_num; i++)
    {
      scanf("%s", input_id);
      for(j = 0; j < registration_num; j++)
	{
	  if(strcmp(input_id, id[j]) == 0)
	    {
	      switch(door)
		{
		case 0:
		  printf("Opened by %s\n", input_id);
		  door = opened;
		  break;
		case 1:
		  printf("Closed by %s\n", input_id);
		  door = closed;
		  break;
		}
	      break;
	    }
	}
      if(j >= registration_num)
	{
	  printf("Unknown %s\n", input_id);
	}
    }
}

int main(void)
{
  int n, m, i;
  scanf("%d", &n);
  registration(n);
  
  scanf("%d", &m);
  output_message(m, n);
  return 0;
}

Measured memory_bytes: 604
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func floatSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	x := make([][10]int, 10)
	for i := 1; i <= n; i++ {
		j := strconv.Itoa(i)
		x[stringToInt(string(j[0]))][stringToInt(string(j[len(j)-1]))]++
	}
	ans := 0
	for i := 0; i < 10; i++ {
		for j := 0; j < 10; j++ {
			if i == j {
				ans += x[i][j] * x[i][j]
			} else {
				ans += x[i][j] * x[j][i]
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3116
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>

using namespace std;

long long n,m,d;
long long ans,cnt;

int main()
{
	cin>>n>>m>>d;
	if(!d)printf("%.7lf",(double)(m-1)/n);
	else printf("%.7lf",(double)2*(n-d)/n*(m-1)/n);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int uruu(int year);
int ndays(int y,int m);
int syori(int y,int m,int d);
int main(){
    int  cnt = 0;
    int fromnen,fromtuki,fromday,tonen,totuki,today;
    while(1){
        scanf("%d %d %d %d %d %d",&fromnen,&fromtuki,&fromday,&tonen,&totuki,&today);
        if(fromnen<0||fromtuki<0||fromday<0||tonen<0||totuki<0||today<0) break;
        cnt=syori(tonen,totuki,today)-syori(fromnen, fromtuki, fromday);
        printf("%d\n",cnt);
        cnt=0;
    }
    return 0;
}
int syori(int y,int m,int d){
    int cnt=0,i;
    for(i=0;i<y;i++){
        cnt+=365;
        if(uruu(i)==1)cnt++;
    }
    for(i=1;i<m;i++){
        cnt+=ndays(y, i);
    }
    for(i=1;i<d;i++){
        cnt++;
    }
    return cnt;
}



int ndays(int y, int m){
    int result;
    switch(m){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:result=31;
            break;
        case 2:result=28;
            break;
        case 4:
        case 6:
        case 9:
        case 11:result=30;
            break;
    }
    if(uruu(y)==1&&m==2){
        result+=1;
    }
    return result;
}
int uruu(int year){
    int result=0;
    if(year%400==0){
        result=1;
    }else if(year%100==0){
        result=0;
    }else if(year%4==0){
        result=1;
    }
    return result;
}

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

int main() {
	int H, W;
	cin >> H >> W;
	vector<char> vec1(W + 2, '.'), vec2(W + 2, '.'), vec3(W + 2, '.'), vec4(W + 2, '.');
	vector<char> s(W);
	int count = 0;
	for (int i = 0; i < H; i++) {
		count = 0;
		if (i == 0) {
			for (int j = 0; j < W; j++)
				cin >> vec2.at(j + 1);
			for (int j = 0; j < W; j++)
				cin >> vec3.at(j + 1);
		}
		else if (i == H - 1) {
			vec1 = vec2;
			vec2 = vec3;
			vec3 = vec4;
		}
		else {
			vec1 = vec2;
			vec2 = vec3;
			for (int j = 0; j < W; j++)
				cin >> vec3.at(j + 1);
		}
		for (int j = 0; j < W; j++) {
			count = 0;
			if (vec2.at(j + 1) == '#') s.at(j) = '#';
			else {
				for (int k = 0; k < 3; k++) {
					if (vec1.at(j + k) == '#') count++;
					if (vec3.at(j + k) == '#') count++;
				}
				if (vec2.at(j) == '#') count++;
				if (vec2.at(j + 2) == '#') count++;
				s.at(j) = count + 48;
			}
		}
		for (int j = 0; j < W; j++)
			cout << s.at(j);
		cout << endl;
	}
}

Measured memory_bytes: 256
s = gets.chomp.to_s
k = gets.to_i

strings_1 = []
strings_2 = []
strings_3 = []
strings_4 = []
strings_5 = []

(0...s.size).each do |index|
  strings_1 << s[index]
end
strings_1.uniq!

(1...s.size).each do |index|
  strings_2 << s[index - 1..index]
end
strings_2.uniq!

(2...s.size).each do |index|
  strings_3 << s[index - 2..index]
end
strings_3.uniq!

(3...s.size).each do |index|
  strings_4 << s[index - 3..index]
end
strings_4.uniq!

(4...s.size).each do |index|
  strings_5 << s[index - 4..index]
end
strings_5.uniq!

strings_all = strings_1 + strings_2 + strings_3 + strings_4 + strings_5
strings_all.sort!

puts strings_all[k - 1]

Measured memory_bytes: 3448
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main(){
	int a[3];
	std::cin >> a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]+a[1]==a[2])std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 素因数分解
map<int, int> prime_factor(int n) {
    map<int, int> res;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) {
        res[1] = 1;
    }
    return res;
}

int main(){
  ll N,M; cin>>N>>M;
  // 前処理
  COMinit();

  map<int, int> m = prime_factor(M);

  ll ans = 1;
  for(int i = 1; i * i < M; i++ ){
    if(m[i] >= 1){
      ans *= COM(m[i] + N - 1 , m[i]);
      ans %= MOD;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
#define N 100006
#define mo 1000000007
using namespace std;
int n,m,ans,sum,a[N],b[N],c[N],d[N];
int ksm(int x,int y)
{
	if(y==0)return 1;if(y==1)return x;
	int p=ksm(x,y>>1);
	if(y&1)return 1LL*p*p%mo*x%mo;return 1LL*p*p%mo;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),c[i]=1LL*i*(n-i)%mo;
	for(int i=1;i<=m;i++)scanf("%d",&b[i]),d[i]=1LL*i*(m-i)%mo;
	int p=b[2]-b[1];
	for(int i=1;i<n;i++)sum=(sum+1LL*c[i]*p%mo*(a[i+1]-a[i])%mo)%mo;
	ans=1LL*d[1]*sum%mo;
	for(int i=2;i<m;i++){
		sum=1LL*sum*ksm(b[i]-b[i-1],mo-2)%mo*(b[i+1]-b[i])%mo;
		ans=(ans+1LL*d[i]*sum%mo)%mo;
	}
	printf("%d\n",ans);
}

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

int main(){
  vector<int> e(1e5 + 1);
  vector<int> o(1e5 + 1);
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    int temp;
    cin >> temp;
    if(i % 2 == 0){
      e[temp]++;
    }else{
      o[temp]++;
    }
  }
  int maxe1 = 0, maxe2 = 0;
  int maxe1idx;
  int maxo1 = 0, maxo2 = 0;
  int maxo1idx;
  for(int i = 0; i < 1e5 + 1; i++){
    if(e[i] > maxe1){
      maxe2 = maxe1;
      maxe1 = e[i];
      maxe1idx = i;
    }else if(e[i] > maxe2){
      maxe2 = e[i];
    }
    if(o[i] > maxo1){
      maxo2 = maxo1;
      maxo1 = o[i];
      maxo1idx = i;
    }else if(o[i] > maxo2){
      maxo2 = o[i];
    }
  }

  if(maxe1idx == maxo1idx){
    cout << min(n - maxe1 - maxo2, n - maxo1 - maxe2) << endl;
  }else{
    cout << n - maxe1 - maxo1 << endl;
  }
 
  return 0;
}

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

using namespace std;
const int MAX = 1e6+10;

long long fac[MAX];

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

    long long ans = 0;
    for(int i = 1; i <= N; ++i ){
        if( i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3532
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    H, W = map(int, input().split())
    maze = [[_ for _ in input()] for _ in range(W)]
    INF = 10 ** 5
    
    # dp[i][j]:=(i,j)に到達するまでに黒壁を壊す回数の最小値
    dp = [[INF] * W for _ in range(H)]
    
    if maze[0][0] == '#':
        dp[0][0] = 1
    else:
        dp[0][0] = 0
    
    for i in range(H):
        for j in range(W):
            for [dy, dx] in [[1, 0], [0, 1]]:
                ny, nx = i + dy, j + dx
                if ny >= H or nx >= W:
                    continue
                else:
                    if maze[i][j] == '.' and maze[ny][nx] == '#':
                        dp[ny][nx] = min(dp[ny][nx], dp[i][j] + 1)
                    else:
                        dp[ny][nx] = min(dp[ny][nx], dp[i][j])
    print(dp[H - 1][W - 1])


resolve()

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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int A[200][200], D[200], X[200];
int main() {
    int N, K;
    cin >> N >> K;
    
    rep(i, K){
        cin >> D[i];
        rep(j, D[i]){
            int a;
            cin >> a;
            X[a]++;
        }
    }
    int ans = 0;
    reps(i, 1, N + 1){
        if (X[i] == 0){
            ans++;
        }
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main()
{
    vector<int> prime {};
    for(int i = 2; i < 1000; i++){
        bool f = true;
        int s = prime.size();
        for(int j = 0; j < s; j++){
            if(i % prime[j] == 0){
                f = false;
            }
        }
        if(f){
            prime.push_back(i);
        }
    }
    int k = prime.size();
    ll n;
    cin >> n;
    ll cp[500] {0};
    for(int i = 1; i <= n; i++){
        int l = i;
        for(int j = 0; j < k; j++){
            while(l % prime[j] == 0){
                cp[j]++;
                l /= prime[j];
            }
        }
    }
    ll ans = 1;
    for(int i = 0; i < k; i++){
        ans = ans * (cp[i] + 1) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100001],k;
int ans(int a[],int n)
{if(n==0) return dp[0];
 if(n==1) return dp[1];
 if(dp[n]!=-1) return dp[n];
 int min=INT_MAX;
 for(int i=n;i>n-k&&i>0;i--)
 {   int temp=ans(a,i-1)+abs(a[n]-a[i-1]);
     if(temp<min) min=temp;
 }
 dp[n]=min;
 return dp[n];
}
int main()
{   ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int n;
    cin>>n>>k;
    int a[n];
    int i;
    for(i=0;i<n;i++) cin>>a[i];
    memset(dp,-1, sizeof(dp));
    dp[0]=0;dp[1]=abs(a[1]-a[0]);
    cout<<ans(a,n-1)<<endl;
    return 0;
} 


Measured memory_bytes: 8832
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int n;
int main(){
    cin >> n;
    int succ = 0;
    bool yes = false;
    rep(i, 0, n){
        int a, b; cin >> a >> b;
        if(a == b) succ++;
        else succ = 0;
        if(succ >= 3) yes = true;
    }
    if(yes) cout << "Yes" << el;
    else cout << "No" << el;
    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
long long n, q;
long long ans[100005];
long long b, c;
int main()
{
       ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
       cin >> n;
       long long sum=0;
       for (long long i=0; i<n; i++)
       {
             long long temp;
             cin >> temp;
             ans[temp]++;
             sum+=temp;
       }
       cin >> q;
       while(q--)
       {
             cin >> b >> c;
             sum=sum+(c-b)*ans[b];
             ans[c]+=ans[b];ans[b]=0;
             cout << sum << endl;
       }
	return 0;
}


Measured memory_bytes: 4440
import java.util.* ; 
import java.math.*;
class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner (System.in);
	String s = scan.next() ;
    String s2 = s.substring(s.indexOf('A') , s.lastIndexOf('Z')+1);
    
    
    System.out.println(s2.length());
  }
}


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

int main() {
	long int n,k;
	cin >> n >> k;
	vector<long int> v(n);
	for(int i=0;i<n;i++){
		cin >> v.at(i);
	}
	sort(v.begin(),v.end());
	if(n<=k){
		cout << 0 << endl;
	}else{
		long int sum=0;
		for(int i=0;i<n-k;i++){
			sum = sum + v.at(i);
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int x = int.Parse(input[1]);
            long[] ai = Console.ReadLine().Split(' ').Select(w => long.Parse(w)).ToArray();
            long ans = 0;
            long work;
            if (ai[0] > x && ai[1] > x)
            {
                ans += ai[0] - x;
                ai[0] = x;
            }
            else if (ai[0] + ai[1] >= x)
            {
                if (ai[0] > ai[1])
                {
                    work = ai[0];
                    ai[0] = x - ai[1];
                    ans += work - ai[0];
                }
            }

            for (int i = 0; i < ai.Length - 1; ++i)
            {
                if (ai[i] + ai[i + 1] > x)
                {
                    work = ai[i + 1];
                    ai[i + 1] = x - ai[i];
                    ans += work - ai[i + 1];
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 19160
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

int main() {
    int n; cin >> n;
    cout << n * 800 - n / 15 * 200 << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <string.h>

void rotation(char * str,int n)
{
  char buf;
  int i;

  buf = str[n-1];

  for(i = (n-1); i > 0; i --)
    str[i] = str[i-1];

  str[0] = buf;
}

int main(void)
{
  char s[102],t[102];
  int n,i;

  scanf("%s",s);
  scanf("%s",t);

  n = strlen(s);

  i=0;
  while(i < n){
    if(! strcmp(s,t)){
      printf("Yes\n");
      return(0);
    }
    rotation(s,n);
    
    i++;
  }

  printf("No\n");
  return(0);
}


Measured memory_bytes: 128
def main():
    n = int(input())
    a = list(map(int, input().split()))

    s = 0

    i = 1
    while i < n:
        while True:
            if (a[i-1] <= a[i]) :
                i+=1
                if i == n:
                    break
                continue
            else:
                s += a[i-1] - a[i]
                a[i]  = a[i-1]
                break
        i += 1
        
    print(s)
        
if __name__=='__main__':
    main()


Measured memory_bytes: 32232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
    vector<ll> a(n,0);
    vector<ll> b(n,0);
    for (ll i = 0;i<m;i++){
        ll s,t;
        cin>>s>>t;
        s--;
        t--;
        if (s == 0) a[t] = 1;
        if (t == n - 1) b[s] = 1;
    }
        bool flag = false;
    for (ll i = 1; i < n-1; i++) {
        if (a[i] and b[i]) flag = true;
    }
    cout << (flag ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  double ans;
  double c = double(a), d = double(b);
  ans = (c+d)/2;
  if(ans - ((a+b)/2) > 0){
    ans++;
  }
  cout << int(ans) << endl;
}

Measured memory_bytes: 3572
/***
* When I wrote this
* only God & I understood
* what I was doing
* Now, God only knows
/***/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
#define rep(i,a,n) for (int i=a;i<=n;i++)/*i为循环变量，a为初始值，n为界限值，递增*/
#define per(i,a,n) for (int i=a;i>=n;i--)/*i为循环变量， a为初始值，n为界限值，递减*/
const int mod = 1e9 + 7;
using namespace std;
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; }
//fixed<< setprecision(2)
void slove()
{

}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s;
    while (cin >> s)
    {
        ll len = s.length();
        if (len == 1)cout << "-1 -1\n";
        else if (len == 2)
        {
            if (s[0] == s[1])cout << "1 2\n";
            else cout << "-1 -1\n";
        }
        else {
            int flag = 1;
            for (int i = 0; i < len - 2; i++)
            {
                if ((s[i] != s[i + 1]) && s[i] != s[i + 2] && s[i + 1] != s[i + 2])continue;
                else {
                    cout << i+1 << " " << i + 3 << '\n';
                    flag = 0;
                    break;
                }
            }
            if (flag)cout << "-1 -1\n";
        }
    }
}

Measured memory_bytes: 3268
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>


int main()
{
	unsigned long a, b, c;
	while (scanf("%ld %ld %ld", &a, &b, &c) > 0) {
		if (b + 2 < c && a>b) {
			unsigned long long  n = (a - (b - 1)) / 2;
			unsigned long long q = (c - b) * n ;
			printf("%llu\n", (c-b)*n+(a-b+1)%2+b);
		} else printf("%u\n",a+1);
	}
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	ll n,m;cin>>n>>m;
	if(n==1&&m==1){
		cout<<1<<endl;
	}
	else if(n==1){
		cout<<m-2<<endl;
	}
	else if(m==1){
		cout<<n-2<<endl;
	}
	else cout<<(n-2)*(m-2)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

	int N, A; cin >> N >> A;

	int res = N * N - A;
	cout << res << endl;

	return 0;
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

void solve(){
    ll a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout << a <<" " << b << " "<< c;
    
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if (A+B+C<=21) {
			System.out.println("win");
		} else {
			System.out.println("bust");
		}
	}
}

Measured memory_bytes: 21972
from collections import deque
n, q = map(int, input().split())
d = deque()
for i in range(n):
    tmp = input().split()
    tmp[1] = int(tmp[1])
    d.append(tmp)
time = 0
while len(d) > 0:
    tmp = d.popleft()
    time += min(q, tmp[1])
    if tmp[1] > q:
        tmp[1] -= q
        d.append(tmp)
    else:
        print(tmp[0] + ' ' + str(time))


Measured memory_bytes: 17288
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int people[] = new int[100005];
		int n = Integer.parseInt(br.readLine());

		for (int i = 0; i < n; i++) {
			String str[] = br.readLine().split(" ");
			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);
			people[a]++;
			people[b + 1]--;
		}

		int sum = 1;
		int ans = 0;
		for (int i = 0; i < 100005; i++) {
			sum += people[i];
			if (i <= sum) {
				ans = i;
			}
		}
		System.out.println(ans - 1);
	}
}


Measured memory_bytes: 64168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

vector<vector<ll>> d(100,vector<ll>(100,1e18));

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> A(M), B(M), C(M);
    rep(i,M){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--; B[i]--;
        d[A[i]][B[i]] = C[i];
        d[B[i]][A[i]] = C[i];
    }
    rep(i,N){
        d[i][i] = 0;
    }
    warshall_floyd(N);
    ll ans = 0;
    rep(i,M){
        bool flag = false;
        rep(j,N){
            rep(k,N){
                if(d[j][A[i]] + C[i] + d[B[i]][k] == d[j][k]){
                    flag = true;
                    break;
                }
            }
            if(flag) break;
        }
        if(!flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3708
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;


int x, y,a,b,c;
ll p[100005], q[100005], r[100005];
vector<ll>V, V1, V2;

void input(){
    cin >> x >> y >> a  >> b >> c;
    for(int i = 0; i < a; ++i){
        cin >> p[i];
        V1.push_back(p[i]);
    }
    for(int i = 0; i < b; ++i){
        cin >> q[i];
        V2.push_back(q[i]);
    }
    for(int i = 0; i < c; ++i){
        cin >> r[i];
        V.push_back(r[i]);
    }
    sort(V1.begin(), V1.end());
    sort(V2.begin(), V2.end());
}

ll solve(){
    int tmp1 = V1.size() - 1;
    int cnt1 = 0;
    while(cnt1 < x){
        cnt1++;
        V.push_back(V1[tmp1]);
        tmp1--;
    }
    int tmp2 = V2.size() - 1;
    int cnt2 = 0;
    while(cnt2 < y){
        cnt2++;
        V.push_back(V2[tmp2]);
        tmp2--;
    }
    sort(V.begin(), V.end());
    //for(int i = 0; i < V.size(); ++i){
    //    cout << V[i] << endl;
    //}
    int cnt = 0;
    int tmp = V.size() - 1;
    ll ans = 0;
    while(cnt < x + y){
        cnt++;
        ans += V[tmp];
        tmp--;
    }

    return ans;
}

int main(){
    input();
    cout << solve() << endl;
}

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

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

  int A[N], B[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  sort(A, A + N);
  sort(B, B + N);

  if (N % 2) {
    int a = A[(N + 1) / 2 - 1];
    int b = B[(N + 1) / 2 - 1];
    cout << b - a + 1 << endl;
  } else {
    double a = (A[(N / 2) - 1] + A[N / 2]) / 2.0;
    double b = (B[(N / 2) - 1] + B[N / 2]) / 2.0;
    cout << (int)((b - a) / 0.5 + 1) << endl;
  }
}

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



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

using namespace std;
#define ll long long
const long double EPS = 1e-8;
const long double PI = acos(-1);
const int N = 1e5 + 2;
const int mod = 1e5 + 7;
int mem[N][2];
int arr[N];
int n, k;

int solve(int i = 0, int rem = k, int player = 0) {
    if (rem < 0)return !player;
    if (rem < arr[0]) {
        return player;
    }
    if (~mem[rem][player])return mem[rem][player];
    if (!player) {
        mem[rem][player] = max(solve(0, rem - arr[i], !player), (i == n - 1) ? 0 : solve(i + 1, rem, player));
    } else {
        mem[rem][player] = min(solve(0, rem - arr[i], !player), (i == n - 1) ? 1 : solve(i + 1, rem, player));
    }
    return mem[rem][player];
}

int main() {
    cin >> n >> k;
    memset(mem, -1, sizeof mem);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    if (solve())cout << "First\n";
    else cout << "Second\n";
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main(){
    int b,a,c,d;
    cin>>a>>b>>c>>d;
    if((a+b)>(c+d)){
        cout<<"Left"<<endl;
        
    }else if((a+b)<(c+d)){
        cout<<"Right"<<endl;
    }else{
        cout<<"Balanced"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3604
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

ll n, a, o = 0, w = 0, h = 0;
vector< vector< vector<double> > > dp;

double solve(int i, int j, int k) {
    if (dp.at(i).at(j).at(k) >= 0) return dp.at(i).at(j).at(k);
    dp.at(i).at(j).at(k) = n;
    if (i > 0) dp.at(i).at(j).at(k) += solve(i - 1, j, k) * i;
    if (j > 0) dp.at(i).at(j).at(k) += solve(i + 1, j - 1, k) * j;
    if (k > 0) dp.at(i).at(j).at(k) += solve(i, j + 1, k - 1) * k;
    return dp.at(i).at(j).at(k) /= i + j + k;
}

int main() {
    scanf("%lld", &n);
    for (ll i = 0; i < n; ++i) {
        scanf("%lld", &a);
        switch (a) {
            case 1: ++o; break;
            case 2: ++w; break;
            case 3: ++h; break;
        }
    }
    dp = vector< vector< vector<double> > >(o + w + h + 1, vector< vector<double> >(w + h + 1, vector<double>(h + 1, -1.0)));
    dp.at(0).at(0).at(0) = 0.0;
    printf("%.15lf\n", solve(o, w, h));
    return 0;
}

Measured memory_bytes: 216960
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> S(n);
    rep(i, n) cin >> S[i];
    sort(ALL(S));
    string ans = "";
    rep(i, n) ans+=S[i];
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=1e18;
ll MOD=INF;
ll mod=INF;


int main() {
  int n;
  cin >> n;
  vector<vector<int>> e(n,vector<int>(0));
  rep(i,n-1){
      int f,g;
      cin >> f >> g;
      e[f-1].push_back(g-1);
      e[g-1].push_back(f-1);
  }
  ll r=0,c=1,ans=0;
    for (int i=n-1;i>=0;i--){
        r+=c;
        c++;
        rep(j,e[i].size()){
            if (e[i][j]>i){
                ll w=n-e[i][j];
                r-=w;
            }
        }
        ans+=r;
    }
    cout << ans << endl;
}


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

int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;

  vector<int> acCnt(n);
  for (int i = 1; i < n; i++) {
    acCnt[i] = acCnt[i - 1];
    if (s[i - 1] == 'A' && s[i] == 'C') {
      acCnt[i]++;
    }
  }

  vector<int> ans(q);
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    ans[i] = acCnt[r] - acCnt[l];
  }

  rep(i, q) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

typedef long long int ll;
typedef pair<int, int> P;

int main()
{
// 入力

	int n;
	cin >> n;
	vector<int> p(n);
	vector<int> ID(n);
	REP(i, n)
	{
		cin >> p[i];
		ID[--p[i]] = i;
	}

// 処理

	set<int> s;
	ll ans = 0;
	for (int x = n - 1; x >= 0; x--)
	{
		int i = ID[x];
		s.insert(i);
		{
			vector<int> l(2, -1);
			vector<int> r(2, n);
			auto it = s.find(i);
			REP(j, 2)
			{
				if (it == s.begin()) break;
				it--;
				l[j] = *it;
			}
			it = s.find(i);
			REP(j, 2)
			{
				it++;
				if (it == s.end()) break;
				r[j] = *it;
			}
			// 左側に大きな値をとる場合
			ans += (ll)(l[0] - l[1]) * (r[0] - i) * (x + 1);
			// 右側に大きな値をとる場合
			ans += (ll)(r[1] - r[0]) * (i - l[0]) * (x + 1);
		}
	}

// 出力

	cout << ans;
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int n;
string s;

bool exists(int val) {
  // cout << "val:" << val << endl;
  char s100 = val / 100 + 0x30;
  char s10 = (val - (s100 - 0x30) * 100) / 10 + 0x30;
  char s1 = val - (s100 - 0x30) * 100 - (s10 - 0x30) * 10 + 0x30;

  // cout << s100 << " " << s10 << " " << s1 << endl;

  int p100 = INT_MAX;
  for (int i = 0; i < n; i++) {
    if (s[i] == s100) {
      p100 = i;
      break;
    }
  }
  if (p100 == INT_MAX) {
    return false;
  }

  int p10 = INT_MAX;
  for (int i = p100 + 1; i < n; i++) {
    if (s[i] == s10) {
      p10 = i;
      break;
    }
  }
  if (p10 == INT_MAX) {
    return false;
  }

  int p1 = INT_MAX;
  for (int i = p10 + 1; i < n; i++) {
    if (s[i] == s1) {
      p1 = i;
      break;
    }
  }
  if (p1 == INT_MAX) {
    return false;
  }

  // auto iter = lower_bound(s.begin(), s.end(), s100);
  // if (iter == s.end()) {
  //   return false;
  // }
  // int p100 = iter - s.begin();
  // cout << "p100:" << p100 << endl;
  // iter = lower_bound(s.begin() + p100 + 1, s.end(), s10);
  // if (iter == s.end()) {
  //   return false;
  // }
  // int p10 = iter - s.begin();
  // cout << "p10:" << p10 << endl;
  // iter = lower_bound(s.begin() + p10 + 1, s.end(), s1);
  // if (iter == s.end()) {
  //   return false;
  // }
  // cout << "p1:" << iter - s.begin() << endl;

  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> s;
  int ans = 0;
  for (int i = 0; i <= 999; i++) {
    if (exists(i)) {
      // cout << "exitst" << endl;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define W V<long long>
#define L long long
#define R(n) for(L i=0;i<n;i++)
W S(V<W>&p,L E){if(!E){return{1,0};}V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1){T[(x[1]+1)&1].push_back({x[0]/2,(x[1]+1)/2});}}V<W>c(3,W(2));R(2){for(W x:T[i]){L Q=(2*x[0]+x[1])%3;if((Q+1)%2){c[i][0]^=1;}if(Q){c[i][1]^=1;}}}R(2){if(c[1-i]==c[2]){W ans=S(T[i],E-1);ans[0]*=2;ans[1]*=2;ans[1]+=i;return ans;}}for(W&v:p){v[0]++;}W A=S(p,E);A[0]--;return A;}
int main(){L M=2e17;L n;cin>>n;V<W>p(n);R(n){L a,b;cin>>a>>b;p[i]={a+M,b+M};}W Q=S(p,70);cout<<Q[0]-M<<" "<<Q[1]-M;}

Measured memory_bytes: 37052
h,w = map(int, input().split())
Hli,Wli = [0 for _ in range(h)],[0 for _ in range(w)]
A = []
for i in range(h):
    l = input()
    for j in range(w):
        if l[j] == "#":
            Hli[i] = 1
            Wli[j] = 1
    A.append(l)
# print(Hli,Wli)
for i in range(h):
    str = ""
    for j in range(w):
        if Hli[i]*Wli[j] == 1:
            str += A[i][j]
    if str != "": print(str)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};


int main(){
    int N; cin >> N;
    
    cout << 800*N - 200*(N/15) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

struct edge {
    int v;
    ll w;
    ll cost;
    edge() {}
    edge(int v, ll w, ll cost) : v(v), w(w), cost(cost) {};
};

vector<ll> dijkstra(int n, vector<vector<edge> >& G, int s) {
    vector<ll> d(n, LLONG_MAX/10); d[s] = 0;
    priority_queue<pair<ll, int> > que;
    que.push(make_pair(0ll, s));
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        int u = p.second;
        ll dist = -p.first;
        if (dist > d[u]) continue;
        for (edge e : G[u]) {
            if (d[e.v] > d[u]+e.w) {
                d[e.v] = d[u] + e.w;
                que.push(make_pair(-d[e.v], e.v));
            }
        }
    }
    return d;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    while (cin >> N >> M) {
        if (N==0 && M==0) break;
        vector<vector<edge> > G(N);
        while (M--) {
            int u, v, d, c;
            cin >> u >> v >> d >> c;
            u--; v--;
            G[u].emplace_back(v, d, c);
            G[v].emplace_back(u, d, c);
        }
        auto dist = dijkstra(N, G, 0);
        ll ans = 0;
        for (int i = 1; i < N; i++) {
            ll mini = 101010;
            for (edge e : G[i]) {
                if (dist[i] == dist[e.v]+e.w) {
                    mini = min(mini, e.cost);
                }
            }
            ans += mini;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4948
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <utility>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long 
#define pii pair<int,int> 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

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

vector<int> t;
vector<int> a;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin >> n >> k;
	cout << ((n % k > 0) ? 1 : 0 ) << '\n';
	return 0;
}


Measured memory_bytes: 256
def preorder(T, index):
    print(" %d" %T[index][3], end="")
    if T[index][1] != -1:
        preorder(T, T[index][1])
    if T[index][2] != -1:
        preorder(T, T[index][2])


def inorder(T, index):
    if T[index][1] != -1:
        inorder(T, T[index][1])
    print(" %d" %T[index][3], end="")
    if T[index][2] != -1:
        inorder(T, T[index][2])

def insert(T, z):
    if len(T) == 0:
        T.append([0, -1, -1, z])
    else:
        i = 0
        T.append([0, -1, -1, z])
        while True:
            if T[i][3] > z and T[i][1] == -1:
                T[i][1] = len(T) - 1
                T[-1][0] = i
                break
            elif T[i][3] < z and T[i][2] == -1:
                T[i][2] = len(T) - 1
                T[-1][0] = i
                break
            elif T[i][3] > z:
                i = T[i][1]
            elif T[i][3] < z:
                i = T[i][2]


n = int(input())
a = [input().split() for _ in range(n)]

ans = []
for i in a:
    if i[0] == 'insert':
        insert(ans, int(i[1]))
    else:
        inorder(ans, 0)
        print("")
        preorder(ans, 0)
        print("")






Measured memory_bytes: 228100
#include<bits/stdc++.h>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	char a,b; cin >> a >> b;

	if (a  == 'H') {
		cout << b << endl; 
	}else{
		if (b == 'H'){
			cout << 'D' << endl;
		}else{
			cout << 'H' << endl;
			
		}
	}
	return 0;
}





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

int main(void){

    static const long long MOD = 1000000007LL;

    string S;
    cin >> S;

    vector<vector<long long>> res(100001, vector<long long>(13, 0LL));

    res[0][0]=1LL;

    int idxC = 0;
    int bufC;
    for(char C: S){
        idxC++;
        if(C == '?'){
            for(int i=0; i<13; i++){
                for(int j=0; j<10; j++){
                    res[idxC][(i*10+j)%13]+=res[idxC-1][i];
                    res[idxC][(i*10+j)%13]=res[idxC][(i*10+j)%13]%MOD;
                }
            }
        }else{
            bufC = C-'0';
            for(int i=0; i<13; i++){
                res[idxC][(i*10+bufC)%13]=res[idxC-1][i];
            }
        }
    }

    cout << res[idxC][5] << endl;

    return 0;
}

Measured memory_bytes: 13696