akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 2e9;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n),dp(n, inf);
    for (int i = 0; i < n; i++)
        cin >> h[i];
    
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for (int i = 2; i < n; i++) 
        for (int j = i - 1, cntr = 0; j >= 0 && cntr < k; j--, cntr++) {
            dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
        }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 1024
import math
#試し割法
def trial_division(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = trial_division(int(input()))

key = []
val = []

dupli = set()
for i in range(len(N)):
    if (not N[i] in dupli):
        key.append(N[i])
        dupli.add(N[i])

for i in range(len(key)):
    val.append(N.count(key[i]))


def maxvalue(n):
    if (n < 3):
        return 1
    elif (n < 6):
        return 2
    elif (n < 10):
        return 3
    elif (n < 15):
        return 4
    elif (n < 21):
        return 5
    elif (n < 28):
        return 6
    elif (n < 36):
        return 7
    elif (n < 45):
        return 8
    elif (n < 55):
        return 9
    elif (n < 66):
        return 10

sum = 0
for i in range(len(key)):
    sum += maxvalue(val[i])
    # count = 1
    # length = val[i]
    # if (length < 3):
    #     sum += 1
    # else:
    #     while(length > 0):
    #         sum += 1
    #         length -= count
    #         if (length == count):
    #             break
    #         count += 1

print(sum)


Measured memory_bytes: 9284
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long  N=0,A=0,B=0,C=0,K=0,ans=0;
    long long asum=0,bsum=0,csum=0;

    cin>>A>>B>>C>>K;

    if(K%2==1){
        ans=B-A;
    }else{
        ans=A-B;
    }

    cout<<ans<<endl;
  

}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = InputNumList();
            int a = input[0];
            int b = input[1];
            int tmp = a;

            int cnt = 1;
            while (true)
            {
                if (a >= b) break;
                a += tmp;
                a -= 1;
                cnt++;
            }

            if (b == 1) cnt = 0;

            WriteLine(cnt);
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}

Measured memory_bytes: 13268
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto H = RDA;
	bool ans = true;
	foreach_reverse (i; 1..N)
	{
		if (H[i-1] <= H[i])
			continue;
		if (H[i-1]-1 <= H[i])
		{
			--H[i-1];
			continue;
		}
		else
		{
			ans = false;
			break;
		}
	}

	writeln(ans ? "Yes" : "No");
	stdout.flush();
	debug readln();
}

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

using namespace std;

typedef long long ll;
const int MAX=1e9+7;
int main()
{
    ll  a,b,c,x,y,Min,ab,ans;
    cin>>a>>b>>c>>x>>y;
    if((a+b)>=2*c)//buy c
    {
        if(x>y)
            Min=y;
        else
            Min=x;
        ans=Min*c*2;
        // cout<<ans<<endl;
        int f=1;
        if(2*c<a || 2*c<b)
        {
            if(2*c<a && x>y)
                {ans+=2*c*(x-y);f=0;}
            if(2*c<b && y>x)
                {ans+=2*c*(y-x);f=0;}
        }
            if(x>y && f)
                ans+=a*(x-y);
            if(x<=y && f)
                ans+=b*(y-x);

    }
    else
    {
        ans=x*a+y*b;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
li = list(map(int, input().split()))

t = sorted(li)
ans = 0

for i in range(N-1):
  if i == 0:
    ans = (t[i] + t[i+1]) / 2
  else:
    ans = (ans + t[i+1]) / 2

print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner io = new Scanner(System.in);
		int N = io.nextInt();
		long ans = 1;
		for (int i = 1; i <= N; i++) {
			ans = ans*i%1000000007;
		}
		System.out.println(ans);
	}
}	

Measured memory_bytes: 21972
import sys

n, *aaa = map(int, sys.stdin.buffer.read().split())
stock = 0
cash = 1000
aaa.append(0)
for a_today, a_tomorrow in zip(aaa, aaa[1:]):
    cash += stock * a_today
    stock = 0

    if a_today < a_tomorrow:
        stock = cash // a_today
        cash -= stock * a_today

print(cash)


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

int main() {
#ifdef HOME
	freopen("agc5a.in", "r", stdin);
	freopen("agc5a.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	string str, res;
	int ant(0);

	cin >> str;
	for (auto ch: str) {
		switch (ch) {
		case 'S': {
			res.push_back('S');
			break; }
		case 'T': {
			if (!res.empty() && res.back() == 'S')
				res.pop_back();
			else
				res.push_back('T');
			break; } } }

	cout << res.size() << endl;

	return 0; }


Measured memory_bytes: 916
import math
import itertools

k = int(input())

list= []

ans = 0

for i in range(k):
  list.append(i+1)
  
ans += sum(list)

for i in itertools.combinations(list,2):
  x,y= i
  ans += math.gcd(x,y) * 6
  
for i in itertools.combinations(list,3):
  x,y,z = i
  ans+= math.gcd(math.gcd(x,y),z) * 6
  
  
print(ans)

Measured memory_bytes: 9204
def resolve():
    n = int(input())
    s = list(int(input()) for _ in range(n))
    non0 = [si for si in s if not str(si).endswith("0")]
    total = sum(s)
    if not str(total).endswith("0"):
        print(total)
    elif non0:
        print(total - min(non0))
    else:
        print(0)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3060
#include <iostream>
#include<cmath>
#include<cstdio>
using namespace std;

struct Coordinate{
    double x, y;
    
};

double pi = 3.141592653589793;
double angle = (pi* 60.0) / 180.0;
    
void kock(int n, Coordinate p1, Coordinate p2){
    if(n == 0 ) return ;//printf("%f " "%f\n", p2.x, p2.y);
    
    Coordinate s,t,u;
    
    s.x = (2*p1.x + 1*p2.x) / 3;
    s.y = (2*p1.y + 1*p2.y) / 3;
    t.x = (1*p1.x + 2*p2.x) / 3;
    t.y = (1*p1.y + 2*p2.y) / 3;
    
    u.x = (t.x - s.x) * cos(angle) - (t.y - s.y) * sin(angle) + s.x;
    u.y = (t.x - s.x) * sin(angle) + (t.y - s.y) * cos(angle) + s.y;
    
    //cout << s.x << " " << s.y << " " << t.x << " " << t.y << " " << u.x << " " << u.y << endl;

    kock(n-1, p1, s);
    printf("%.8lf " "%.8lf\n", s.x, s.y);
    kock(n-1, s, u);
    printf("%.8lf " "%.8lf\n", u.x, u.y);
    kock(n-1, u, t);
    printf("%.8lf " "%.8lf\n", t.x, t.y);
    kock(n-1, t, p2);
    //printf("%.8lf " "%.8lf\n", p2.x, p2.y);
}

int main(void){
    // Your code here!
    int n;
    cin >> n;
    Coordinate p1, p2;
    p1.x = 0, p1.y = 0;
    p2.x = 100, p2.y = 0;
    
    //cout << p1.x << " " << p1.y << " " <<  p2.x << " " << p2.y << endl;
    
    printf("%.8lf " "%.8lf\n", p1.x, p1.y);
    kock(n, p1, p2);
    printf("%.8lf " "%.8lf\n", p2.x, p2.y);
    
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N=0, Alice=0, Bob=0;
  vector<int> a(101);
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  sort(a.rbegin(),a.rend());
  for(int i=0;i<N;i++){
    if(i%2 == 0){
      Alice+=a.at(i);
    }else{
      Bob+=a.at(i);
    }
  }
  cout << Alice-Bob << endl;
}

Measured memory_bytes: 3616
N, K = map(int, input().split())
K = K*2
S = input()
LR = []
pre = S[0]
l = 1
for s in S[1:]:
    if pre != s:
        pre = s
        if K > 0:
            K -= 1
            l += 1
            continue
        LR.append(l)
        l = 1
        continue
    l += 1
LR.append(l)
ans = sum(map(lambda x: x-1, LR))

print(ans)

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)

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

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

    int64_t sum=0,cnt=1;

    rep1(i,k){
        rep1(j,k){
            rep1(h,k){
                sum += gcd(gcd(i,j),h);
            }
        }
    }


    cout << sum << endl;
    return 0;
}

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

using namespace std;

const int N = 10;
char a[N][N];

int main() {
    int n, m, k;   cin >> n >> m >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        vector <int> row;
        for (int r = 0; r < n; r++) {
            if ((1 << r) & i) {
                row.push_back(r);
            }
        }
        for (int j = 0; j < (1 << m); j++) {
            vector <int> col;
            for (int c = 0; c < m; c++) {
                if ((1 << c) & j) {
                    col.push_back(c);
                }
            }
            int cnt = 0;
            for (auto r : row) {
                for (auto c : col) {
                    cnt += (a[r][c] == '#');
                }
            }
            ans += (cnt == k);
        }
    }
    cout << ans;
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int A, B;
    cin >> A >> B;
    vector<int> a = {1, 2, 3};
    vector<bool> b(3, true);
    b[A-1] = false;
    b[B-1] = false;
    REP(i, 3)
        if(b[i]) cout << a[i] << endl;
    return 0;
}


Measured memory_bytes: 3556
import itertools


N, M, Q = map(int, input().split())

a = []
b = []
c = []
d = []

for i in range(Q):
    ai, bi, ci, di = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)

A_pattern = []

# N = 4, M = 6
def dfs(A): # Aは配列 [1, 1, 2, 2]
    if (len(A) == N):
        A_pattern.append(A.copy())
        return
    else:
        for i in range(A[-1], M+1):
            A.append(i)
            dfs(A)
            A.pop(-1)

for i in range(1, M+1):
   dfs([i])


"""
A = [i for i in range(1, M+1)] # [1, 2, 3, 4, ... M]
A_pattern = list(itertools.combinations_with_replacement(A, N)) # Aの配列の中から重複してもいいのでN個選ぶ
"""

ans = 0

for a_pattern in A_pattern: # 数列全部調べる
    ansi = 0
    for i in range(Q): # 得点になるかどうか調べる
        if a_pattern[b[i]-1] - a_pattern[a[i]-1] == c[i]: # A[bi] - A[ai] == ci -> ansi += di
            ansi += d[i]

    ans = max(ans, ansi)

print(ans)


Measured memory_bytes: 22996
#!/usr/bin/env python3
n, k, *P = map(int, open(0).read().split())
p = [(i + 1) / 2 for i in P]
s = [float()]
for i in range(n):
    s.append(s[i] + p[i])
print(max(s[i + k] - s[i] for i in range(n - k + 1)))


Measured memory_bytes: 33268
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
	int s,t;
	scanf("%i %i",&s,&t);
	char s1[t+1],t1[s+1];
	if(t>s)
	{
		for(int i=0;i<t;i++)
		{
			printf("%i",s);
		}
	}
	else if(t<=s)
	{
		for(int i=0;i<s;i++)
		{
			printf("%i",t);
		}
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int N = Reader.Int();
        int[] A = Reader.IntArray(N), B = Reader.IntArray(N), C = Reader.IntArray(N);
        Array.Sort(A);
        Array.Sort(B);
        Array.Sort(C);
        long[] count = new long[N];

        for (int bi = 0, ai = 0; bi < N; bi++) 
        {
            while (ai < N && A[ai] < B[bi]) ai++;
            count[bi] = ai;
        }
        long ans = 0;
        long sum = 0;
        for (int ci = 0, bi = 0; ci < N; ci++)
        {
            while (bi < N && B[bi] < C[ci]) { sum += count[bi]; bi++;}
            ans += sum;
        }

        Console.WriteLine(ans);
    }
}



class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { Dispose(); A = new string[0]; }
    public static void Set(TextReader r) { Init(); reader = r; }
    public static void Set(string file) { Init(); reader = new StreamReader(file); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    public static void Dispose() { reader.Dispose(); }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int d,t,s; cin >> d >> t >> s;
  cout << (s*t >= d ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3600
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	b, _ := strconv.Atoi(sc.Text())
	diff := b - a
	sum := 0
	for i := 1; i <= diff; i++ {
		sum += i
	}
	sum -= b
	fmt.Println(sum)
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n, k;

int main(){
  cin >> n;
  vector<int>a(n), b(n), c(n);
  for(int i = 0; i<n; i++) cin >> a[i] >> b[i] >> c[i];
  
  int dp[n+1][3];//前日何をしたかのパターンを記憶するため，2次元dp
  for(int i = 0; i < n+1; i++){
    for(int j = 0; j < 3; j++) dp[i][j] = -intMAX;
  }

  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;

  for(int i = 0;i < n; i++){
    dp[i+1][0] = max(dp[i][1] + b[i], dp[i][2] + c[i]);
    dp[i+1][1] = max(dp[i][2] + c[i], dp[i][0] + a[i]);
    dp[i+1][2] = max(dp[i][0] + a[i], dp[i][1] + b[i]);
  }
  cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;

}

Measured memory_bytes: 2560
from collections import deque

H,W = map(int,input().split())
MAP = [input() for i in range(H)]

explored = [[False for i in range(W)] for j in range(H)]
dxy = [(-1,0),(1,0),(0,-1),(0,1)]
ans = 0

for h in range(H) :
    for w in range(W) :
        if not explored[h][w] :
            q = deque([(h,w)])
            black = 0
            white = 0
            
            while q :
                y,x = q.popleft()
                explored[y][x] = True
                if MAP[y][x] == "#" :
                    black += 1
                else :
                    white += 1
                
                for dy,dx in dxy :
                    ny = y+dy
                    nx = x+dx
                    
                    if (ny < 0) or (ny >= H) or (nx < 0) or (nx >= W) :
                        continue
                    if explored[ny][nx] :
                        continue
                    if MAP[ny][nx] == MAP[y][x] :
                        continue
                    explored[ny][nx] = True
                    q.append((ny,nx))
                    
            ans += black*white

print(ans)


Measured memory_bytes: 4844
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i >=(b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod1=1000000007;
ll mod2=67280421310721;
ll mod3=998244353;
ll INF=1e18;

int main()
{ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll n;
    cin>>n;
    ll h[n+1];
    FOR(i,1,n+1)
    {
        cin>>h[i];
    }
    ll dp[n+1];
    FOR(i,0,n+1)
    {
        dp[i]=INF;
    }
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    FOR(i,3,n+1)
    {
        FOR(j,1,3)
        {
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[n]<<'\n';
	return 0;
}


Measured memory_bytes: 1792
//
// Created by yamunaku on 2020/01/11.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int n;
    cin >> n;
    vector<string> s(n);
    vi t(n);
    rep(i,n) cin >> s[i] >> t[i];
    string x;
    cin >> x;
    ll ans = 0;
    bool ok =false;
    rep(i,n){
        if(ok) ans+=t[i];
        if(s[i] == x)ok=true;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,K,res,res2;
  cin >> N >> K;
  res = N/K;
  if(N % K == 0)
    res2 = 0;
  else
    res2 = 1;
  cout << res2 << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

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

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



Measured memory_bytes: 764
package main

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

func main() {
	N, K := ReadInt(), ReadInt()
	ans := 0.
	for i := 1; i <= N; i++ {
		base := 1
		for base*i < K {
			base <<= 1
		}
		ans += 1.0 / float64(base) / float64(N)
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
var lines=[];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', function (line) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines);
});

function main(lines) {
  const [_, _x] = lines[0].split(' ');
  const x = parseInt(_x);
  const grids = lines[1].split(' ').map(g => parseInt(g));
  console.log(calculate(x, grids));
}

function calculate(x, grids) {
  const values = grids.map(g => Math.abs(x - g));
  const d = gcd(values);
  return d;
}

function gcd(values) {
  var f = (a, b) => b ? f(b, a % b) : a;
  var ans = values[0];
  for (var i = 1; i < values.length; i++) {
    ans = f(ans, values[i]); 
  }
  return ans 
}


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*(._.)*/
int main(){
	int N; cin >> N;
	vector<int> H(N);
	REP(i,N){
	    cin >> H[i];
	}

	REPr(i,N-1){
	    if (H[i] > H[i+1]){
	    	H[i]--;
	    }
	}

	bool ans = true;
	REP(i,N-1){
	    if (H[i] > H[i+1]) ans = false;
	}

	if (ans) puts("Yes");
	else puts("No");

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define DN(en, ka) (F[en] * pot(F[ka] * F[en - ka] % Q, -1) % Q)
using namespace std;
typedef long long int ll;
const ll N = 1 << 16, Q = 1000000007;
ll n, a, b, c, res, F[N] = {1};
int pot(ll a, ll b){
  a %= Q;
  if(b < 0)
    return pot(pot(a, -b), Q - 2);
  if(b == 0)
    return 1;
  if(b % 2 == 1)
    return ((ll)pot(a, b - 1) * a) % Q;
  ll t = pot(a, b / 2);
  return (t * t) % Q;
}
int solve(int x, int y){
  if(b % 2 == 1 || c < y * 3 + a - x || (b == 0 && ((c - a + x) % 3 != 0 || c != y * 3 + a - x)))
    return 0;
  ll t = c - a + x - 3 * y,
    l = F[a + y + b / 2],
    m = F[x] * F[y] % Q * F[a - x] % Q * F[b / 2] % Q,
    k = b ? DN(b / 2 + t - 1, t) : 1;
  return l * pot(m, -1) % Q * k % Q;
}  
int main(){
  for(int i = 1;i < N;i++)
    F[i] = (F[i - 1] * i) % Q;
  cin >> n >> a >> b >> c;
  for(int i = 0;i <= a;i++)
    for(int j = 0;j <= c / 3;j++){
      res += solve(i, j);
    }
  cout << res % Q << endl;
}


Measured memory_bytes: 768
N, M, X = list(map(int, input().split()))

bookli = [[0 for I in range(M+1)] for II in range(N)]
for i in range(N):
    bookli[i] = list(map(int, input().split()))

ans=10**9

for j in range(1, 2**N):
    ansli = [0 for III in range(M+1)]
    keta = N
    for jj in range(keta):
        if ((j >> jj) & 1):
            ansli = [a + b for (a, b) in zip(ansli, bookli[jj])]

    for k in range(1, M+1):
        if ansli[k] >= X:
            pass
        else:
            break

        if k==M and ans > ansli[0]:
            ans=ansli[0]



if ans != 10**9:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9252
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> d(K);
    vector<vector<int>> A(K, vector<int>(N));
    vector<bool> v(N, false);
    REP(i, K){
        cin >> d[i];
        REP(j, d[i]) {
            cin >> A[i][j];
            v[A[i][j]-1] = true;
        }
    }

    ll ans = 0;
    REP(i, N) if (!v[i]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		if(N%2==0)
		{
		System.out.println(N/2);
		}
		else
		{
			System.out.println((N/2)+1);
		}

	}

}

Measured memory_bytes: 35612
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	string s,s1;
	int i;
	cin>>s;
	s1=s;
	reverse(s.begin(),s.end());
	for(i=0;i<s.size();i++){
		if(s[i]=='b'){
			s[i]='d';
		}else if(s[i]=='d'){
			s[i]='b';
		}else if(s[i]=='p'){
			s[i]='q';
		}else{
			s[i]='p';
		}
	}
	if(s==s1){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}

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

const int x=10000,y=5000,z=1000;

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<=n;i++){
		for(int j=0;i+j<=n;j++){
			if((m-i*x-j*y)/z==n-i-j&&(m-i*x-j*y)%z==0){
				cout<<i<<" "<<j<<" "<<n-i-j<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<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 rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

int main() {
    int N,H,W;
    cin >> N >> H >> W;

    cout << (N - H + 1) * (N - W + 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-7
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(n) ((n) * (n))
#define INF 300000005
#define MAXN 1000000

vvll g;
ll n; 
ll s;

void bfs()
{
	queue<int> q;
	q.push(s);
	vector<bool> used(n + 1);
	vll d(n + 1), p(n + 1);
	used[s] = true;
	p[s] = -1;
	while (!q.empty())
	{
		ll v = q.front();
		q.pop();
		REP(i,sz(g[v]))
		{
			ll to = g[v][i];
			if (!used[to])
			{
				used[to] = true;
				q.push(to);
				d[to] = d[v] + 1;
				p[to] = v;
			}
		}
	}
	if (!used[n])
	{
		printf("IMPOSSIBLE");
	}
	else 
	{
		ll col = 0;
		for (int v = n; v != -1; v = p[v])
		{
			col++;
		}
		if (col == 3)
		{
			printf("POSSIBLE");
		}
		else
		{
			printf("IMPOSSIBLE");
		}
	}
}

int main()
{
	ll m;
	scanf("%lld %lld", &n, &m);
	g.assign(n + 1, vll());
	REP(i, m)
	{
		ll a, b;
		scanf("%lld %lld", &a, &b);
		g[a].pb(b);
	}
	s = 1;
	bfs();
	return 0;
}

Measured memory_bytes: 12404
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 2e9 + 9;
const ll LINF = 1e18;
using namespace std;


int main() {
	string s;
	int ans = INF;
	cin >> s;

	for (int i = 0; i < s.size() - 2; i++) {
		int num = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + s[i + 2] - '0';
		if(abs(ans-753)>abs(num-753)){
			ans = num;

		}
	}
	cout << abs(ans-753) << endl;
	return 0;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

ll n, m, p[1000], d[600000];

int main() {
  while (scanf("%lld%lld", &n, &m), n) {
    for (ll i = 0; i < n; i++) scanf("%lld", &p[i]);
    ll counter = 0;
    for (ll i = 0; i < n; i++) for (ll j = 0; j <= i; j++) d[counter++] = p[i] + p[j];
    for (ll i = 0; i < n; i++) d[counter++] = p[i];
    sort(d, d + counter);
    ll ans = 0;
    for (ll i = 0, j = counter - 1; i < counter; i++) {
      while (d[i] + d[j] > m) j--;
      if (i > j) break;
      if (ans < d[i] + d[j]) ans = d[i] + d[j];
    }
    printf("%lld\n", ans);
  }
}



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

int main(){
  int A, B;
  int T;
  string op;
  cin >> A >> B >> T;
  
  int x=(T+0.5)/A;
  
  cout << x*B << endl;


  // ここにプログラムを追記
     
  }

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    s = input()
    t = input()

    # 構成不可能な場合
    set_s = set(s)
    for char_t in t:
        if char_t not in set_s:
            print(-1)
            exit()

    # 構成可能な場合    
    # 前処理 O(n)
    s_table = [[] for _ in range(ord('z') - ord('a') + 1)]
    for i, s_char in enumerate(s):
        s_table[ord(s_char) - ord('a')].append(i)
    # print(s_table)
    # O(nlgn)
    loop_count = 0
    prev = -1
    for t_char in t:
        candidate = s_table[ord(t_char) - ord('a')]
        j = bisect_left(candidate, prev+1)    # prev より大きくないとだめ
        if j == len(candidate):
            loop_count += 1
            prev = candidate[0]
        else:
            prev = candidate[j]
    print(prev + loop_count * len(s) + 1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 7668
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 30){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}


ll N;
ll cnt[10][10];

void solve(){
  cin >> N;
  rep(n, N + 1){
    if(n == 0) continue;
    ll j = n % 10;
    ll i;
    ll M = n;
    while(M){
      i = M;
      M /= 10;
    }
    cnt[i][j]++;
  }

  ll ans = 0;
  for(ll i = 1; i <= 9; i++){
    for(ll j = 1; j <= 9; j++){
      ans += cnt[i][j] * cnt[j][i];
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 1000000007
#define ll long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;

ll power(ll x, ll y)
{
    ll res = 1;
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1) {
            res = ((res) * (x));
        }
        y = y>>1;  // y = y/2
        x = ((x)*(x));
    }
    return res;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // int t;
    // cin>>t;

    // while(t--) {
        
        

    // }
    
    int n;
    cin>>n;

    int arr[n];
    fo(i,n){
        cin>>arr[i];
    }

    int mx=-1;
    ll ans=0;
    fo(i,n){
        if(arr[i]< mx){
            ans += mx-arr[i];
        }
        else{
            mx = arr[i];
        }
    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 4320
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

std::string S;
int32_t NOT_NUM[200000][30];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> S;
	for (char c = 'a';c <= 'z';++c)
	{
		for (int32_t i = S.size()-2; i >= 0 ; --i)
		{
			NOT_NUM[i][c - 'a'] = NOT_NUM[i + 1][c - 'a'];
			if (S[i + 1] != c) {
				++NOT_NUM[i][c - 'a'];
			}
		}
	}

	int64_t res = 1;
	for (int32_t i = 0; i < S.size(); ++i)
	{
		res += NOT_NUM[i][S[i]-'a'];
	}

	out << res << endl;
	return 0;
}
#endif


Measured memory_bytes: 23956
from collections import*
from heapq import*
(n,m),a,*q=[[*map(int,o.split())]for o in open(0)]
t=[-1]*n
def r(x):
 while t[x]>=0:x=t[x]
 return x
def u(x,y):
 x,y=r(x),r(y)
 if x!=y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
d=defaultdict(list)
for x,y in q:u(x,y)
i=0
for v in a:d[r(i)]+=v,;i+=1
if len(d)<2:exit(print(0))
*d,=map(sorted,d.values())
c=sum(heappop(t)for t in d)
l=[]
for t in d:l+=t
i=len(d)-2
print(i>len(l)and'Impossible'or c+sum(sorted(l)[:i]))

Measured memory_bytes: 42492
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N,K;
  cin>>N>>K;
  int ans=K*pow(K-1,N-1);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<cstdlib>
#include<time.h>
using namespace std;
long long k, n, a[300000];
int main()
{
	cin >> k >> n;
	for (long int i = 1; i <= n; i++)
	{
		cin >> a[i];
		//cout << a[i] << endl;
	}
	long int m = 10000000;
	m = min(a[n] - a[1], k - (a[n] - a[n - 1])); //1,k的顺
	//cout << m << endl;
	long int center;
	center = min(a[n] - a[1], k - (a[2] - a[1])); //1，k的逆
	m = min(center, m);
	//cout << m << endl;
	for (long int i = 2; i <= n- 1; i++)
	{
		center = min(k - (a[i] - a[i - 1]), k - (a[i + 1] - a[i]));
		m = min(m, center);
		//cout << k - (a[i] - a[i - 1]) << "  " << k - (a[i + 1] - a[i]) << endl;
	}
	cout << m << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, K, S, i;
  cin >> N >> K >> S;
  i64 d = (S == 1000000000 ? 1 : 1000000000);
  REP(0, N, i) {
    if(i != 0)
      cout << " ";
    cout << ((i < K) ? S : d);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1280
<?php
  
fscanf(STDIN,"%d%d",$l,$r);
$min = 2019;
for($i=$l;$i<$r;$i++){
  for($j=$l+1;$j<=$r;$j++){
    if(($i*$j)%2019==0){
      echo "0";
      exit;
    }
    $min = min(($i*$j)%2019,$min);
  }
}

echo $min;
  
  
 



Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int ka[200010];

int c(int x, int y) {
	if (y > x)return 0;
	return ka[x] * mod_pow(ka[x - y], mod - 2, mod) % mod*mod_pow(ka[y], mod - 2, mod) % mod;
}

int n, m, k;
int cnt[200010];
int ans = 1;

signed main() {
	cin >> n >> m >> k;
	ka[0] = 1;
	for (int i = 1; i <= n; i++)ka[i] = (ka[i - 1] * i) % mod;
	cnt[0] = m;
	for (int i = 1; i <= n; i++)cnt[i] = (cnt[i - 1] * (m - 1)) % mod;
	for (int i = 1; i <= k + 1; i++) ans = ans * m%mod;
	for (int i = k + 1; i < n; i++) {
		ans = (((ans - cnt[i - k - 1] * c(i - 1, k) % mod + mod) % mod)*m%mod + cnt[i - k - 1] * c(i - 1, k) % mod*(m - 1) % mod) % mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6692
lst = input().split()
a = int(lst[0])
b = int(lst[1])
c = int(lst[2])
d = int(lst[3])

if ((abs(b - a) <= d) and (abs(c - b) <= d)) or (abs(c - a) <= d):
   print('Yes')
else:
   print('No')

Measured memory_bytes: 9044
#include <iostream>
#include <queue>
#include <vector>
#include <climits>
using namespace std;
typedef pair<long long,int> NODE;
#define cost first
#define pos second
#define INF INT_MAX
int n;
long long info[100][100];

long long dijkstra(int a,int b){
	priority_queue<NODE,vector<NODE>,greater<NODE> > Q;
	Q.push( make_pair(0,a) );
	
	long long memo[100];
	for(int i=0;i<100;i++)memo[i]=INF;
	memo[a]=0;
	
	while(Q.size()){
		NODE q = Q.top();Q.pop();
		
		if(q.pos == b)return q.cost;
		
		for(int i=0;i<n;i++){
			if(memo[i] > q.cost+info[q.pos][i]){
				memo[i] = q.cost+info[q.pos][i];
				Q.push( make_pair(memo[i],i) );
			}
		}
	}
	return -1;
}

int main(){
	int k,a,b,c,r;
	while(cin >> n >> k && n || k){
		for(int i=0;i<100;i++)for(int j=0;j<100;j++)
			info[i][j]=INF;
			
		for(int i=0;i<k;i++){
			cin >> r;
			if(r){
				cin >> a >> b >> c;
				a--;b--;
				info[a][b] = info[b][a] = min<long long>(info[a][b],c);
			}else{
				cin >> a >> b;
				a--;b--;
				cout << dijkstra(a,b) << endl;
			}
		}
	}
}

Measured memory_bytes: 992