akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

const int MOD = 1e9 + 7, MAX_N = 2e5 + 5;
long long factorial[MAX_N + 1], inverse_factorial[MAX_N + 1];

long long power_mod(long long x, long long power)
{
    long long result = 1;

    while(power > 0)
    {
        if(power%2)
            result = (result*x)%MOD;

        x = (x*x)%MOD;
        power = power >> 1;
    }

    return result;
}

long long inverse(long long n)
{
    return power_mod(n, MOD - 2);
}

void precompute_factorial()
{
    factorial[0] = 1;
    for(int i = 1; i <= MAX_N; i++)
        factorial[i] = (i*factorial[i - 1])%MOD;

    inverse_factorial[MAX_N] = inverse(factorial[MAX_N]);
    for(int i = MAX_N - 1; i >= 0; i--)// i (i - 1)! = i! => (i!)^ = i^ (i - 1)^ => (i!)^ i = (i - 1)^
        inverse_factorial[i] = ((i + 1)*inverse_factorial[i + 1])%MOD;
}

long long combinations(long long n, long long r)
{
    long long numerator = factorial[n];
    long long inverse_denominator = (inverse_factorial[r]*inverse_factorial[n - r])%MOD;

    return (numerator*inverse_denominator)%MOD;
}

int main()
{
    precompute_factorial();

    long long rows, columns, k;
    cin >> rows >> columns >> k;

    long long no_of_times_each_pair_is_counted = combinations(rows*columns - 2, k - 2);

    long long x_contribution = 0;
    for(int i = 1; i <= rows; i++)
    {
        long long x = i;

        long long one_x_contribution = (columns*(i - 1)*x - columns*(rows - i)*x + MOD)%MOD;

        x_contribution += (columns*one_x_contribution)%MOD;// cout << " X = " << x_contribution << endl;
    }

    long long y_contribution = 0;
    for(int i = 1; i <= columns; i++)
    {
        long long y = i;

        long long one_y_contribution = (rows*(i - 1)*y - rows*(columns - i)*y + MOD)%MOD;

        y_contribution += (rows*one_y_contribution)%MOD; //cout << " Y = " << y_contribution << endl;
    }

    long long sum_pair_distance = (x_contribution + y_contribution)%MOD;// cout << "N = " << no_of_times_each_pair_is_counted << " S = " << sum_pair_distance << endl;

    long long answer = (no_of_times_each_pair_is_counted*sum_pair_distance)%MOD;

    cout << answer;
    return 0;
}


Measured memory_bytes: 3328
K,N=map(int,input().split())
listA=list(map(int,input().split()))
dist=[]
for i in range(N-1):
  dist+=[listA[i+1]-listA[i]]
dist+=[K-listA[N-1]+listA[0]]
MAX=max(dist)
ans=K-MAX
print(ans)

Measured memory_bytes: 26420
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int x = scan.nextInt();
		int[] l = new int[n];
		for (int i = 0; i < n; i++)
			l[i] = scan.nextInt();

		int bound = 0;
		int flag = 0;
		for (int i = 0; i < n; i++) {
			bound += l[i];

			if (bound > x) {
				System.out.println(i + 1);
				flag = 1;
				break;
			}
		}

		if (flag == 0) {
			System.out.println(n + 1);
		}

	}

}

Measured memory_bytes: 21844
#include <stdio.h>

int a[100010];
int num[4010];
int ans[4010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int t,s;
		scanf("%d.%d",&t,&s);
		num[a[i]=t*1000+s]++;
	}
	int crr=0;
	for(int i=0;i<=4000;i++){
		ans[i]=crr*3+num[i]-1;
		crr+=num[i];
	}
	for(int i=0;i<n;i++)printf("%d\n",ans[a[i]]);
}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }

int main(){
    int r; cin >> r;
    cout << r*r << endl;
    return 0;
}

Measured memory_bytes: 256
#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>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vvi a(n, vi(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }
    //__builtin_popcount()
    vvl dp(n + 1, vl(1 << n, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < (1 << n); ++j) {
            if (__builtin_popcount(j) == i) {
                for (int k = 0; k < n; ++k) {
                    if (!(1 << k & j) && a[i][k] == 1) {
                        dp[i + 1][1 << k | j] += dp[i][j];
                        dp[i + 1][1 << k | j] %= MOD;
                    }
                }
            }
        }
    }
    cout << dp[n][(1 << n) - 1] << "\n";
    return 0;
}

Measured memory_bytes: 377216
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int r = N % 10;
    if (r == 2 || r == 4 || r == 5 || r == 7 || r == 9)
    {
        cout << "hon" << endl;
        return 0;
    }
    else if (r == 0 || r == 1 || r == 6 || r == 8)
    {
        cout << "pon" << endl;
        return 0;
    }
    else
    {
        cout << "bon" << endl;
        return 0;
    }
    
    return 0;
}


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

using namespace std;
typedef long long int ll;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

pair<int, int> dp[101][50001];
bool used[101][50001];
int N, P[100];

pair<int, int> dfs(int idx, int coins) {
  if (idx == N) return make_pair(0, 0);
  if (used[idx][coins]) return dp[idx][coins];

  used[idx][coins] = true;
  // not buy;
  pair<int, int> ret = dfs(idx + 1, coins);

  // buy only with bills
  int change = (1000 - P[idx] % 1000) % 1000;
  int cnt, money; tie(cnt, money) = dfs(idx + 1, coins + change % 500);
  ret = max(ret, make_pair(cnt + (change >= 500), money - P[idx]));

  // buy with bills & coins to get 500
  if ((P[idx] + 500) % 1000 <= coins) {
    int cnt, money; tie(cnt, money) = dfs(idx + 1, coins - (P[idx] + 500) % 1000);
    ret = max(ret, make_pair(cnt + 1, money - P[idx]));
  }

  return dp[idx][coins] = ret;
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    cin >> N;
    if (not N) break;
    REP(i, N) cin >> P[i];
    memset(used, 0, sizeof(used));
    int cnt, money; tie(cnt, money) = dfs(0, 0);
    cout << cnt << ' ' << -money << endl;
  }

  return 0;
}

Measured memory_bytes: 27648
n = int(input())
MOD = 10 ** 9 + 7

ans = 0
count9 = 1
count0 = 1
other = 8
for i in range(n-1):
  ans = ans*10 + count9+count0
  count9 = count9*9 + other
  count0 = count0*9 + other
  other *= 8
  
  count9 %= MOD
  count0 %= MOD
  ans %= MOD
  other %= MOD
  
print(ans%MOD)

Measured memory_bytes: 64008
#include <cstdio>
#include <vector>
#include <map>
using namespace std;

int main() {
        int n, q;
        scanf("%d%d", &n, &q);
        vector<long long> a;
        a.push_back(n);
        for (int i = 0; i < q; i ++) {
                long long x;
                scanf("%lld", &x);
                while (!a.empty() && a.back() >= x) a.pop_back();
                a.push_back(x);
        }
        vector<map<long long, long long>> res(a.size());
        res[a.size() - 1][a.back()] = 1;
        for (int i = a.size() - 1; i >= 1; i --) {
                for (auto p : res[i]) {
                        long long x = p.first;
                        long long y = p.second;
                        long long div = x / a[i - 1];
                        long long mod = x % a[i - 1];
                        if (div > 0) res[i - 1][a[i - 1]] += div * y;
                        if (mod > 0) {
                                int t = lower_bound(a.begin(), a.end(), mod) - a.begin();
                                res[t][mod] += y;
                        }

                }
        }
        vector<long long> ans(n + 100);
        for (auto p : res[0]) ans[p.first] += p.second;
        for (int i = n; i >= 1; i --) ans[i] += ans[i + 1];
        for (int i = 1; i <= n; i ++) printf("%lld\n", ans[i]);
        return 0;
}



Measured memory_bytes: 29684
package main

import (
	"fmt"
	"regexp"
)

func main() {
	var s string
	fmt.Scan(&s)

	divide := `^(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)*$`

	if regexp.MustCompile(divide).Match([]byte(s)) {
		fmt.Println("a")
		return
	}
	fmt.Println("A")

}




Measured memory_bytes: 2124
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,y;
  cin >> n >> y;
  int flag=0;
  for(int a=0;a<=2000;a++){
    for(int b=0;b<=2000;b++){
      int c = n - a - b;
      if(c >=0 ){
        if(flag ==0){
        if(10000*a + 5000*b+1000*c == y){
          cout << a <<" "<<b <<" " <<c <<endl;
          flag = 1;
        }
        }
      }
    }
  }
  if(flag==0)cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

//main
int main(){
  int N;
  cin >> N;
  int c = 0;
  vector<int> P(N);
  rep(i,N) cin >> P[i];
  rep(i,N-2){
    if((P[i]<P[i+1] && P[i+1]<P[i+2]) || (P[i]>P[i+1] && P[i+1]>P[i+2])) c += 1;
  }
  cout << c << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private Scanner sc;
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);

		String[] nico = sc.nextLine().split(" ");

		int m = Integer.parseInt(nico[0]) - 1;
		int n = Integer.parseInt(nico[1]) - 1;
		
		System.out.println(n * m);
	}
}

Measured memory_bytes: 22228
<?php
fscanf(STDIN, "%d", $n);
$n1 = fgets(STDIN);
$n2 = fgets(STDIN);

$n1array = explode(' ', $n1);
$n2array = explode(' ', $n2);

$max = 0;
$n1arraySum = array_sum($n1array);
$n2arraySum = array_sum($n2array);

for ($i = 0; $i < $n; $i++) {
  $result = 0;
  for ($j = 0; $j < $n; $j++) {
    if ($i == $j) {continue;}
    if ($j < $i) {$result += $n1array[$j];}
    if ($i < $j) {$result += $n2array[$j];}
  }
  $result += $n1array[$i] + $n2array[$i];
  $max = max($max, $result);
}
echo $max;
?>

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
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;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M, K;
    cin >> N >> M >> K;

    ll A = 1;
    A = (A*N)%MOD;
    A = (A*N)%MOD;
    A = (A*(M-1))%MOD;
    A = (A*M)%MOD;
    A = (A*(M+1))%MOD;

    ll B = 1;
    B = (B*M)%MOD;
    B = (B*M)%MOD;
    B = (B*(N-1))%MOD;
    B = (B*N)%MOD;
    B = (B*(N+1))%MOD;

    // 前処理
    COMinit();

    ll C = COM(N*M-2, K-2) % MOD;

    cout << ((((A+B)%MOD)* modinv(6, MOD) % MOD) * C) % MOD << endl;
    return 0;
}

Measured memory_bytes: 27076
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;
 
template <class T> using V = vector<T>;
 
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 long long INF = 1LL << 60;
 
using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;


 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(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;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}

void Solve();

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 

void Solve(){
  st s;
    cin>>s;
  ll n=s.sz;
  ll ans=0;
  //count white
  ll count=0;
  FOR(i,0,n){
    if(s[i]=='B'){
      count++;
    }
    else{
      ans+=count;
      //count=0;
    }
  }
  REV(s);
  count=0;
  FOR(i,0,n){
    if(s[i]=='W'){
      count++;
    }
    else{
      ans+=count;
    }
  }
  cout<<ans/2<<endl;
}

Measured memory_bytes: 720
let (n1, n2) = (4, 16)
let n_limit = 100
let mdt = Array.make_matrix n2 n2 0
let dx = [| 0; -1; 0; 1 |]
let dy = [| 1; 0; -1; 0 |]

type puzzle = { board : int array; mutable space : int; mutable md : int }

let dfs puzzle limit =
  let rec doit i prev pzl =
    if pzl.md = 0 then begin
      Printf.printf "%d\n" limit;
      exit 0;
    end else if i + pzl.md > limit then ()
    else
      let (sx, sy) = (pzl.space / n1, pzl.space mod n1) in
      for r = 0 to 3 do
        let (tx, ty) = (sx + dx.(r), sy + dy.(r)) in
        if tx < 0 || ty < 0 || tx >= n1 || ty >= n1 then ()
        else if max prev r - min prev r = 2 then ()
        else begin
          let (space, num) = (tx * n1 + ty, sx * n1 + sy) in
          let oldmd = pzl.md in
          pzl.md <- pzl.md - mdt.(space).(pzl.board.(space)-1) + mdt.(num).(pzl.board.(space)-1);
          let olds = pzl.board.(space) in
          let oldn = pzl.board.(num) in
          pzl.board.(space) <- oldn;
          pzl.board.(num) <- olds;
          let oldspace = pzl.space in
          pzl.space <- space;
          doit (i + 1) r pzl;
          pzl.board.(space) <- olds;
          pzl.board.(num) <- oldn;
          pzl.space <- oldspace;
          pzl.md <- oldmd;
        end
      done in
  doit 0 (-n_limit) puzzle

let idastar board space =
  let (_, md) =
    Array.fold_left (fun (i, sum) e ->
      (i + 1, if e = n2 then sum else sum + mdt.(i).(e-1)))
      (0, 0) board in
  let pzl = { board; space; md } in
  for limit = pzl.md to n_limit do
    dfs pzl limit;
  done;
  assert false

let () =
  for i = 0 to n2 - 1 do
    for j = 0 to n2 - 1 do
      mdt.(i).(j) <- abs (i / n1 - j / n1) + abs (i mod n1 - j mod n1)
    done
  done;
  let board = Array.make n2 0 in
  let rec doit i space =
    if i = n2 then space
    else begin
      let x = Scanf.scanf "%d " (fun i -> i) in
      let (x, space) = if x = 0 then (n2, i) else (x, space) in
      board.(i) <- x;
      doit (i + 1) space
    end in
  doit 0 0 |> idastar board

Measured memory_bytes: 4544
#include<cstdio>
#include<algorithm>
using namespace std;

#define i64 long long int
#define ran 3033

int n;
int a[ran];
i64 f[ran][ran];
bool visd[ran][ran];

i64 dp(int l, int r) {
	if (l>r || visd[l][r]) return f[l][r];
	
	i64 t = 0;
	if ((r-l)%2 == (n-1)%2)
		t = max(dp(l+1, r) + a[l], dp(l, r-1) + a[r]);
	else
		t = min(dp(l+1, r) - a[l], dp(l, r-1) - a[r]);
	
	visd[l][r] = true;
	f[l][r] = t;
	return t;
}

int main() {
	scanf("%d", &n);
	for(int i=1;i<=n;i++) scanf("%d", &a[i]);
	printf("%lld\n", dp(1, n));
	
	return 0;
}

Measured memory_bytes: 80256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007
#define INIT mod * 3000

int n;
int a[3001];
long long int result[3001][3001][2];

long long int solve(int s, int t, bool isFirstTurn){
	if(result[s][t][isFirstTurn] != (long long int)INIT) return result[s][t][isFirstTurn];
	else if(s == t) return 0;
	if(isFirstTurn) result[s][t][isFirstTurn] = max(a[s] + solve(s + 1, t, !isFirstTurn), a[t - 1] + solve(s, t - 1, !isFirstTurn));
	else result[s][t][isFirstTurn] = min(-a[s] + solve(s + 1, t, !isFirstTurn), -a[t - 1] + solve(s, t - 1, !isFirstTurn));
	return result[s][t][isFirstTurn];
}

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		for(int j = 0; j <= n; j++){
			result[i][j][0] = result[i][j][1] = (long long int)INIT;
		}
	}
	cout << solve(0, n, true) << endl;

}

Measured memory_bytes: 141056
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
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; }
ll n;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<ll> dp(n+1,LINF);
    dp[0]=0;
    rep(i,n){
        chmin(dp[i+1],dp[i]+1);
        ll six=6;
        while(true){
            if(n<i+six)break;
            chmin(dp[i+six],dp[i]+1);
            six*=6;
        }
        ll nine=9;
        while(true){
            if(n<i+nine)break;
            chmin(dp[i+nine],dp[i]+1);
            nine*=9;
        }
    }
    cout << dp[n] << "\n";
}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
const int N=100100;
int i,j,k,n,m,ch,ff;
int nm[2],exc[2],rev[2],a[3][N],A[2][N],tmp[N];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void Gb(int *A,int l,int r,int &t) {
	if (l==r) return;
	int mid=(l+r)>>1;
	Gb(A,l,mid,t);
	Gb(A,mid+1,r,t);
	int ll=l,rr=mid+1,tt=l-1;
	while (ll<=mid && rr<=r) {
		if (A[ll]<A[rr]) {
			tmp[++tt]=A[ll];
			t^=(tt-ll)&1;
			ll++;
		}
		else {
			tmp[++tt]=A[rr];
			rr++;
		}
	}
	while (ll<=mid) {
		tmp[++tt]=A[ll];
		t^=(tt-ll)&1;
		ll++;
	}
	while (rr<=r) {
		tmp[++tt]=A[rr];
		rr++;
	}
	for (int i=l;i<=r;i++) A[i]=tmp[i];
}
int main() {
	R(n);
	for (i=0;i<3;i++)
		for (j=1;j<=n;j++) R(a[i][j]);
	for (i=1;i<=n;i++) {
		k=(a[0][i]-1)/3+1;
		if ((k&1)!=(i&1)) return puts("No"),0;
		if (k*3-2==a[0][i]) {
			if (k*3-1!=a[1][i] || k*3!=a[2][i]) return puts("No"),0;
		}
		else {
			if (k*3!=a[0][i]) return puts("No"),0;
			if (k*3-1!=a[1][i] || k*3-2!=a[2][i]) return puts("No"),0;
			rev[i&1]^=1;
		}
		A[i&1][++nm[i&1]]=k;
	}
	Gb(A[0],1,nm[0],exc[0]);
	Gb(A[1],1,nm[1],exc[1]);
	if (exc[0]!=rev[1] || exc[1]!=rev[0]) return puts("No"),0;
	puts("Yes");
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
int p[1100000];
pair<int,int>dp[1100000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<(1<<a);i++){
		scanf("%d",p+i);
	}
	int n=(1<<a);
	for(int i=0;i<n;i++){
		dp[i]=make_pair(p[i],-1);
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<n;j++){
			if(j&(1<<i)){
				pair<int,int>tmp=dp[j-(1<<i)];
				if(tmp.first>dp[j].first){
					dp[j].second=dp[j].first;dp[j].first=tmp.first;
				}else if(tmp.first>dp[j].second){
					dp[j].second=tmp.first;
				}
				if(tmp.second>dp[j].first){
					dp[j].second=dp[j].first;dp[j].first=tmp.second;
				}else if(tmp.second>dp[j].second){
					dp[j].second=tmp.second;
				}
			}
		}
	}
	int ret=0;
	for(int i=1;i<n;i++){
		ret=max(ret,dp[i].first+dp[i].second);
		printf("%d\n",ret);
	}
}


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

using namespace std;

typedef long long ll;

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

	int a, b, c;
	cin >> a >> b >> c;
	
	if(a + b >= c){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
int Min(int a,int b){return a<b?a:b;}
int Max(int a,int b){return a>b?a:b;}
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*f;
}
int n,v[100005],num[100005],ans,m1,m2,M1,M2,b1,b2,B1,B2;
int main()
{
	n=read();
	for(int i=1;i<=n;i++) v[i]=read();
	for(int i=1;i<=n;i+=2) num[v[i]]++;
	for(int i=1;i<=100000;i++)
	{
		if(num[i]>=m2)
		{
			if(num[i]>=m1)
			{
				m2=m1;b2=b1;
				m1=num[i];b1=i;
			}
			else{m2=num[i];b2=i;}
		}
	}
//	printf("%d\n",m);
	memset(num,0,sizeof num);
	for(int i=2;i<=n;i+=2) num[v[i]]++;
	for(int i=1;i<=100000;i++)
	{
		if(num[i]>=M2)
		{
			if(num[i]>=M1)
			{
				M2=M1;B2=B1;
				M1=num[i];B1=i;
			}
			else{M2=num[i];B2=i;}
		}
	}
	//printf("%d %d %d %d\n",m1,m2,M1,M2);
	if(b1!=B1) printf("%d",n-M1-m1);
	else
	{
		if(M2>0&&m2>0) return 0*printf("%d",n-Max(m1+M2,m2+M1));
		if(M2>0) return 0*printf("%d",n-m1-M2);
		if(m2>0) return 0*printf("%d",n-m2-M1);
		printf("%d",n>>1);
	}
}


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

int main()
{
  string s;
  int i,j,l;
  cin>>s;
  l = s.length();
  if(l&1)
    l--;
  else
    l-=2;
  i = 0, j = (l>>1);
  while(s.substr(i,l/2)!=s.substr(j,l/2))
  {
    l-=2;
    j--;
  }
  cout<<l<<"\n";  
  return 0;
}


Measured memory_bytes: 256
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  n = InputLine.to_s

  s = n.split('').map(&:to_i).reduce(:+)
  puts ((s % 9 == 0) ? 'Yes' : 'No')
end

if self.to_s == 'main' then
  main(ARGV)
end

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

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (stderr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 1e9, MOD = INF + 7;

/////////////////////////////////////////////////////////////////////

const int N = 1e2 + 20, M = 1e5 + 10;

int w[N], v[N], dp[N][M];

int32_t main(){

    sync;

    int n, W; cin >> n >> W;
    for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];
    for(int i = 1; i <= n; i++) for(int j = 1; j <= W; j++) {
    	dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    	if (j >= w[i]) dp[i][j] = max(dp[i][j], v[i] + dp[i - 1][j - w[i]]);
    }
    cout << dp[n][W] << endl;

    return 0;
}

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

int main() {
  std::vector<int> in(3);
  std::cin >> in[0] >> in[1] >> in[2];

  std::sort(in.begin(), in.end());

  std::cout << in[0] + in[1] << std::endl;

  return 0;
}


Measured memory_bytes: 256
import sys
#input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    l=[0]*(n+1)
    s=0
    for i in range(n):
        l[a[i]]+=1
    for i in range(n+1):
        if l[i]==0:
            continue
        else:
            s+=l[i]*(l[i]-1)//2
    for i in range(n):
        print(s-(l[a[i]]-1))

if __name__ == '__main__':
    main()

Measured memory_bytes: 83276
#include<bits/stdc++.h>
using namespace std;
long long n,k,cnt[5000][5000],mod=1e9+7;
int main()
{
	cin>>n>>k;
	for(int i=0;i<=2005;i++)
	{
		cnt[i][0]=1;
		for(int j=1;j<=i;j++)
			cnt[i][j]=(cnt[i-1][j-1]+cnt[i-1][j])%mod; 
	}
	int b=k;
	int r=n-k;
	for(int i=1;i<=b;i++)
		cout<<(cnt[b-1][i-1]*cnt[r+1][i])%mod<<endl;
	return 0;
}


Measured memory_bytes: 78336
#include <iostream>

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

   int nketa = 0;
   int n = N;
   while(n>0){
      n /= 10;
      ++nketa;
   }
   long long ans = 0;
   int m = 1;
   for(int i=1; i<nketa; ++i){
      m *= 10;
      if(i%2!=0) ans += m - m/10;
   }
   if(nketa%2!=0) ans += N - m + 1;
   std::cout << ans << std::endl;
   return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())
can = False
for i in range(x+1):
    kame = i
    tsuru = x - i
    if tsuru < 0:
        continue
    if kame + tsuru == x and kame*4+tsuru*2 == y:
        can = True
        break
print("Yes" if can else "No")


Measured memory_bytes: 61632
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    while(N){
        int suma = 0,sumb = 0;
        vector<int> A(N),B(M);
        rep(i,0,N){cin >> A[i];suma += A[i];}
        rep(i,0,M){cin >> B[i];sumb += B[i];}
        int mini = INF,ai,bi;
        rep(i,0,N)rep(j,0,M){
            int na = suma - A[i] + B[j];
            int nb = sumb + A[i] - B[j];
            if(na == nb){
                if(mini > A[i] + B[j]){
                    ai = A[i];
                    bi = B[j];
                    mini = A[i] + B[j];
                }
            }
        }
        if(mini != INF)cout << ai << " " << bi << endl;
        else           cout << -1 << endl;
        cin >> N >> M;
    }
}


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

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
const int mod = 1e9 + 7;
ll power(ll a, ll b, ll mod)
{
    ll ans = 1 % mod;
    while (b > 0)
    {
        if (b & 1)
        {
            ans = ans * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    vector<ll> cnt(K + 1);
    for (ll i = K; i >= 1; i--)
    {
        ll cur = K / i;
        ll t = power(cur, N, mod) % mod;
        ll cat = 0;
        cnt[i] = t;
        for (ll j = i * 2; j <= K; j += i)
        {
            cnt[i] = (cnt[i] - cnt[j] + mod) % mod;
        }
        ans = (ans + cnt[i] * i) % mod;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int n,m; cin >>n>>m;
    vector<int> a(m); vector<int> b(m);
    REP(i,m) cin >> a[i] >> b[i];

    set<int> ans1;
    set<int> ans2;
    for (int i = 0; i < m; i++) {
        if (a[i] == 1) {
            ans1.insert(b[i]);
        } else if (b[i] == n) {
            ans2.insert(a[i]);
        } 
    }
    set<int> ans;
    set_intersection(ans1.begin(), ans1.end(), ans2.begin(), ans2.end(), inserter(ans, ans.end()));
    if (ans.size()) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    } 

    return 0;
}




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

#define INF 1E18



int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    vector<int> c = a;
    sort(c.begin(),c.end(),greater<>());
    int first = c[0];
    int second = c[1];

    rep(i,n){
        if(a[i] == first) cout << second <<endl;
        else cout << first <<endl;
    }
    

    return 0;
}


Measured memory_bytes: 3200
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,f[1000][1000];
int main(){
	scanf("%d", &m); n=2;
	for(int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			int x;
			scanf("%d", &x);
			f[i][j] = max(f[i-1][j], f[i][j-1]) + x;
		}
	}
	printf("%d\n", f[n][m]);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
#define INF (1<<28)
typedef long long Int;

int N, B[64], C[64];
string A[64], D[64][64];
int g[64][64], vis[64];
int m, q[64];

void collect(int at) {
    if (vis[at]) return ;
    vis[at] = 1;
    q[m++] = at;
    rep (i, N) if (g[at][i]) collect(i);
}

int n, a, r[64], p[64];
Int f[64];

void prepare() {
    n = m;
    a = 0;
    rep (i, n) r[i] = q[i];
    rep (i, n) {
        p[i] = B[r[i]];
        f[i] = 0;
        rep (j, n) if (g[r[i]][r[j]]) f[i] |= 1LL<<j;
    }
}

void rec(int k, Int u) {
    int s = 0;
    rep (i, n) if (u&(1LL<<i)) s += p[i];
    if (s < a) return ;
    if (k == n) a = s;
    else {
        rep (i, k) if (!(u&(1LL<<i)) && !(f[i]&u)) return ;
        const int mask = (1LL<<n) - 1;
        if (u&(1LL<<k)) rec(k+1, u&(mask-f[k]));
        if (r[k]) rec(k+1, u&(mask-(1LL<<k)));
    }
}

int solve() {
    memset(vis, 0, sizeof(vis));
    int ans = 0;
    rep (i, N) if (!vis[i]) {
        m = 0;
        collect(i);
        prepare();
        rec(0, (1LL<<n)-1);
        ans += a;
    }
    return ans;
}

int main() {
    for (;;) {
        cin >> N;
        if (N == 0) return 0;
        map<string, int> of;
        rep (i, N) {
            cin >> A[i] >> B[i] >> C[i];
            of[A[i]] = i;
            rep (j, C[i]) cin >> D[i][j];
        }
        memset(g, 0, sizeof(g));
        rep (i, N) rep (j, C[i]) g[i][of[D[i][j]]] = 1;
        printf("%d\n", solve());
    }
}

Measured memory_bytes: 1376
a = input()
cou2 = abs(753-int(a[0]+a[0+1]+a[0+2])) 
for i in range(len(a)-2):
    cou = abs(753-int(a[i]+a[i+1]+a[i+2]))
    if cou2>cou:
        cou2=cou
print(cou2)





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

int main() {
    int N, K; cin >> N >> K;
    vector<int> P(N);
    vector<ll> C(N);
    rep(i, N){
        cin >> P[i];
        P[i]--;
    }
    rep(i, N){
        cin >> C[i];
    }

    ll ans = -1e18 - 5;
    rep(i, N){
        int cnt = 0;
        int now = i;
        ll ctotal = 0;
        while(1){
            now = P[now];
            ctotal += C[now];
            cnt++;
            if(now == i)break;
        }
        ll total = 0;
        ll nokori = min(cnt, K);
        if(ctotal > 0){
            ll loop = K / cnt;
            nokori = K % cnt;
            total += ctotal * loop;
        }
        if(nokori == 0){
            total -= ctotal;
            nokori = cnt;
        }
        ll ma = -1e18 - 5;
        if(total != 0){
            ma = total;
        }

        rep(j, nokori){
            now = P[now];
            total += C[now];
            ma = max(ma, total);
        }

        ans = max(ans, ma);
    }

    cout << ans << endl;

    return 0;
}

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

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

  vector<int> a(n,0);
  for (int i = 0; i < n; i++) cin >> a[i];

  int now = 1;
  int count = 0;
  vector<int> arrived(n+1, 0);
  while(arrived[now] == 0){
    if (now == 2) {
      cout << count << endl;
      return 0;
    }
    arrived[now]++;
    now = a[now-1];
    count++;
  }
  cout << -1 << endl;
}


Measured memory_bytes: 4000
N = int(input())
happy_list = [list(map(int, input().split())) for n in range(N)]
def chmax(a, b):
    if a > b:
        return a
    else:
        return b
dp_list = [[0, 0, 0]]
for n in range(1, N+1):
    tmp = [0, 0, 0]
    tmp[1] = chmax(tmp[1], dp_list[n-1][0] + happy_list[n-1][1])
    tmp[2] = chmax(tmp[2], dp_list[n-1][0] + happy_list[n-1][2])
    tmp[0] = chmax(tmp[0], dp_list[n-1][1] + happy_list[n-1][0])
    tmp[2] = chmax(tmp[2], dp_list[n-1][1] + happy_list[n-1][2])
    tmp[0] = chmax(tmp[0], dp_list[n-1][2] + happy_list[n-1][0])
    tmp[1] = chmax(tmp[1], dp_list[n-1][2] + happy_list[n-1][1])
    dp_list.append(tmp)
print(max(tmp))

Measured memory_bytes: 71128
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll c=0,d=0,n1,m1,n2,m2,min=100000,k=0,ans=0;
    string s,s2;
    cin >> c >> d;
    for(int i=c; i<=d;i++){
        n1 = i % 10;
        m1 = i / 10000;
        n2 = (i/1000) % 10;
        m2 = (i%100) / 10;
        if(n1==m1&&n2==m2) ans++;
    }

    cout << ans <<endl; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int mod=1e9+7;
const int MN=17;
int n,m,fac[1<<MN],inv[1<<MN],a[MN],f[MN+1][1<<MN];
inline ll C(int n,int m){return n<m?0:1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
inline int sgn(int S){return (__builtin_popcount(S)&1)?mod-1:1;}
int main(){
	scanf("%d%d",&n,&m);
	for(reg int i=1;i<=m;i++)scanf("%d",a+i);
	sort(a+1,a+1+m);
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(reg int i=2;i<=(1<<n);i++){
		fac[i]=1ll*fac[i-1]*i%mod;
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	}
	for(reg int i=2;i<=(1<<n);i++)
		inv[i]=1ll*inv[i]*inv[i-1]%mod;
	f[m+1][0]=1;
	for(reg int i=m;i;i--)
		for(reg int S=0;S<(1<<n);S++)
			if(f[i+1][S]){
				f[i][S]=(f[i][S]+f[i+1][S])%mod;
				for(reg int j=1;j<=n;j++)
					if(!(S&(1<<j-1)))
						f[i][S|(1<<j-1)]=(f[i][S|(1<<j-1)]+1ll*f[i+1][S]*C((1<<n)-S-a[i],(1<<j-1)-1)%mod*fac[1<<j-1]%mod)%mod;
			}
	reg int Ans=0;
	for(reg int S=0;S<(1<<n);S++)
		Ans=(Ans+1ll*f[1][S]*fac[(1<<n)-1-S]%mod*sgn(S)%mod)%mod;
	printf("%d\n",1ll*Ans*(1<<n)%mod);
	return 0;
}

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

#define ll long long

ll arr[10004];

ll max(ll a, ll b) {
    return a > b ? a : b;
}

int main() {
    int n,m;
    cin >> n >> m;
    ll sum = 0;
    for (int i=0;i<n;i++)
        cin >> arr[i], sum += arr[i];
    sort(arr, arr+n);
    ll cnt = 0;
    for (int i=n-1;i>=0;i--) {
        if (arr[i]*4*m >= sum)
            cnt++;
        else
            break;
        if (cnt == m) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 3612
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl



int main() {
	int n, k, x, ans = 0;
	cin >> n >> k;
	repi(i, 0, n) {
		rd(x);
		ans += min(x, k - x) * 2;
	}
	wrln(ans);
	return 0;
}

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

int main() {
  int N,K;
  int x=1;
  
  cin >> N;
  cin >> K;
  
  for(int i =0; i<N; i++){
    if (x*2 < x+K)
      x *= 2;
    else
      x += K;
  }
  
  cout << x << endl;

  
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class AL {
public:
  static void solve(istream &cin, ostream &cout) {
    int a, b, c;
    cin >> a >> b >> c;
    if (b - a == c - b) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  AL solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

using namespace std;

#pragma GCC optimize("O2")

#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())

typedef long long ll;typedef vector<int> vi;
typedef pair<int,int> ii;typedef vector<ii> vii;
typedef vector<vi> vvi;

int x[3],n;
unordered_map<int,ll> mp[52];

const int md = 1e9+7;



int good(vi& v,int init){
	int n = v.size();
	int i=init,s1=0,s2=0,s3=0;
	for(;i<n;){
		s1+=v[i++];
		if(s1>=x[0]) break;
	}
	if(s1>x[0]) return 0;
	if(s1<x[0]) return 1;
	for(;i<n;){
		s2+=v[i++];
		if(s2>=x[1]) break;
	}
	if(s2>x[1]) return 0;
	if(s2<x[1]) return 1;
	for(;i<n;){
		s3+=v[i++];
		if(s3>=x[2]) break;
	}
	if(s3>x[2]) return 0;
	if(s3<x[2]) return 1;
	return 2;
}

int ten[52];
int primes= 89142797;

int hashMe(vi& v){
	ll ans = 0;
	for(int i=0;i<v.size();i++){
		ans=ans*10;
		// if(ans>=primes) ans%=primes;
		ans+=v[i];
		// if(ans>=primes) ans-=primes;
	}
	return ans;
}

int get(int ind,vi& v){
	int completeHash = hashMe(v);
	vi red;int g;
	for(int i=0;i<v.size();i++){
		g = good(v,i);
		if(g==0)
			continue;
		else{
			red.reserve(v.size()-i+1);
			for(int x=i;x<v.size();x++)
				red.pb(v[x]);
			break;
		}
	}
	// cout<<"good score "<<g<<" red: ";
	// for(int i:red) cout<<i<<" ";
	// cout<<"\n";
	int hsh = hashMe(red);
	if(mp[ind].count(hsh))
		return mp[ind][hsh];
	if(g==2){
		// cout<<"awe ";
		// for(int i:v) cout<<i<<" ";
		// cout<<"\n";
		return ten[n-ind];
	}
	if(ind==n)
		return 0;
	ll& ans = mp[ind][hsh];
	for(int val=1;val<=7;val++){
		red.pb(val);
		ans+=get(ind+1,red);
		if(ans>=md)
			ans-=md;
		red.pop_back();
	}
	red.clear();
	ans+=3*get(ind+1,red);
	if(ans>=md) ans%=md;
	// cout<<"getres "<<ind<<"\nv: ";
	// for(int i:v) cout<<i<<" ";
	// cout<<"\nans: "<<ans<<"\n";
	return ans;
}

signed main(){
	IOS
	ten[0]=1;
	for(int i=1;i<52;i++){
		ten[i]=ten[i-1]*10%md;
	}
	cin>>n;
	forn(i,3) cin>>x[i];
	vi v;
	cout<<get(0,v)<<"\n";

}

Measured memory_bytes: 27712
import sys
input = sys.stdin.readline

import bisect

INF = 1e+11
A,B,Q=map(int, input().split())
s=[-INF]+[int(input()) for _ in range(A)]+[INF]
t=[-INF]+[int(input()) for _ in range(B)]+[INF]
x=[int(input()) for _ in range(Q)]

for i in range(Q):
    a,b=bisect.bisect_right(s,x[i]), bisect.bisect_right(t,x[i])
    ans = INF
    for j in [s[a-1], s[a]]:
        for k in [t[b-1], t[b]]:
            d1 = abs(j-x[i])+abs(j-k)
            d2 = abs(k-x[i])+abs(j-k)
            ans = min(ans, d1, d2)
    print(ans)

Measured memory_bytes: 16128
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int m,n;
int main(){
    cin>>m>>n;
    if(m==n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
let fold_int f a n =
  let rec fold f a i n =
    if i >= n then
      a
    else
      fold f (f a i) (i + 1) n
  in
    fold f a 0 n

let list_to_array n a xs =
  let res = Array.make n a in
  List.iteri (fun i x -> res.(i) <- x) xs;
  res

(* O(n * log(n)) *)
let solve n a_s =
  let sorted_as = list_to_array n 0 a_s in
  Array.sort (fun x y -> compare x y * -1) sorted_as;
  fold_int
    (fun sofar i ->
      if i mod 2 = 0 then
        sofar + sorted_as.(i) (* Alice *)
      else
        sofar - sorted_as.(i)) (* Bob *)
    0
    n

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let _ =
  let n = read_int () in
  let a_s = read_ints () in
  solve n a_s |> string_of_int |> print_endline

Measured memory_bytes: 2432
import java.util.*;

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(c >= a && c <= b){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 20564
#!/usr/bin/env python3
import sys


def solve(S: str):
    for i in range(len(S) - 1):
        if S[i] == S[i+1]:
            return 'Bad'
    return 'Good'


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: str
    print(solve(S))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940