akhauriyash/Code-Regression huggingface dataset:
N = int(input())+1
D = list(map(int,input().split()))+[0]+[24]
D.sort()
for i in range(1,N,2):
    D[i] = 24-D[i]
D.sort()
ans = 24
for i in range(N):
    ans = min(ans,abs(D[i+1]-D[i]))
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX_B 100'000

using namespace std;

int main() {
  int N;
  cin >> N;
  int _b = MAX_B;
  int res = 0;
  for (int i = 0; i < N - 1; ++i) {
    int b;
    cin >> b;
    res += min(_b, b);
    _b = b;
  }
  printf("%d\n", res + _b);
}

Measured memory_bytes: 3152
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, K;
    std::cin >> N >> K ;

    // std::string S;
    // std::cin >> S;

    if (N % K != 0) {
        std::cout << 1 << std::endl;
    }
    else {
        std::cout << 0 << std::endl;
    }

    return 0;
}


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

int k;
bool vis[100005];
deque<pair<int,int> > q;

int main()
{
	scanf("%d",&k);
	q.push_back(make_pair(1,1));
	while(!q.empty())
	{
		int u=q.front().first,s=q.front().second;
		q.pop_front();
		if(vis[u]) continue;
		vis[u]=1;
		if(u==0)
		{
			printf("%d\n",s);
			return 0;
		}
		q.push_front(make_pair(u*10%k,s));
		q.push_back(make_pair((u+1)%k,s+1));
	}
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MOD 1000000007LL

long long dp[5010][5010] = {{0}};

int main() {
	int i, j, len, N;
	long long exp, prod, t;
	char s[5010];
	scanf("%d%s", &N, &s);
	len = strlen(s);

	dp[0][0] = 1;
	dp[1][0] = 1; dp[1][1] = 2;
	for (i=2;i<=N;i++) {
		dp[i][0] = (dp[i-1][0] + dp[i-1][1]) % MOD;
		for (j=1;j<i-1;j++) {
			dp[i][j] = (2*dp[i-1][j-1] + dp[i-1][j+1]) % MOD;
		}
		dp[i][i-1] = (2*dp[i-1][i-2]) % MOD;
		dp[i][i]   = (2*dp[i-1][i-1]) % MOD;
	}
//	for (i=0;i<=N;i++) {for (j=0;j<=i;j++) printf("%lld\t", dp[i][j]); printf("\n");}

	exp = MOD - 1 - len;
	prod = 1LL;
	t = 2LL;
	while (exp) {
		if (exp & 1) prod = (prod*t) % MOD;
		t = (t*t) % MOD;
		exp >>= 1;
	}
//	printf("2^(%lld) = %lld\n", MOD - 1 - len, prod);

	printf("%lld\n", (dp[N][len]*prod)%MOD);

	return 0;
}


Measured memory_bytes: 116864
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, m):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

def main():
    rr = []
    pr = Prime(100000**2)
    tl = len(pr.T)

    while True:
        n,a,b = LI()
        if n == 0:
            break
        m = fractions.Fraction(a,b)
        sn = n ** 0.5
        r = 0
        rs = ''
        for ni in range(tl):
            i = pr.T[ni]
            if i > sn:
                break
            j = min(n // i, int(i/m)+1)
            if j < i:
                continue
            while not pr.is_prime(j):
                j -= 1
            ji = pr.T.index(j)
            while fractions.Fraction(i,pr.T[ji]) < m:
                ji -= 1
            j = pr.T[ji]
            if i*j <= r:
                continue
            r = i*j
            rs = '{} {}'.format(i,j)

        rr.append(rs)

    return '\n'.join(map(str, rr))


print(main())




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

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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        int tmp = 0;
        cin >> tmp;
        tmp--;
        a.at(i) = tmp;
    }

    int now = 0, c = 0;
    for (;;)
    {
        if(now == 1)
        {
            cout << c << endl;
            break;
        }
        if(c >= N)
        {
            cout << -1 << endl;
            break;
        }
        c++;
        now = a[now];
    }
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
import itertools
def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    all_per = itertools.permutations(range(2,N+1))
    # 隣接行列作成
    matrix = [[0]*N for _ in range(N)]

    for aa,bb in zip(a,b):
        matrix[aa-1][bb-1] = 1
        matrix[bb-1][aa-1] = 1
    answer = 0
    for per in all_per:
        if matrix[0][per[0]-1] == 0:
            continue
        for i in range(N-2):
            if matrix[per[i]-1][per[i+1]-1] == 0:
                break
        else:
            answer += 1

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

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

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

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

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pair<int,int> a, pair<int,int> b) {
	return a < b;
}

// mod. m での a の逆元 a^{-1} を計算する
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;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

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

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		String s = nextString();


		System.out.println("2018/"+s.substring(5));

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

a = input().split()

a = [int(x) for x in a]

am = max(a)
ai = 0
r = abs(a[0] - (am/2)) 

for i in range(n):
    if r >= abs(a[i]-(am/2)):
        r = abs(a[i]-(am/2))
        ai = a[i]
        
print("{0} {1}".format(am,ai))

Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

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

    int n; cin>>n;
    vector<int> a(n),b(n);
    rep(i,n)cin>>a.at(i);
    rep(i,n)cin>>b.at(i);
    
    vector<int> ra(n),rb(n);
    int ans=0;
    rep(i,30){
        rep(j,n){
            ra.at(j)=a.at(j)%((int)1<<(i+1));
            rb.at(j)=b.at(j)%((int)1<<(i+1));
        }
        sort(all(rb));
        int cnt=0;
        int h=(int)1<<(i+1),l=(int)1<<(i);
        rep(j,n){
            if(l-ra.at(j)>=0){
                cnt+=lower_bound(all(rb),h-ra.at(j))-lower_bound(all(rb),l-ra.at(j));
            }else{
                cnt+=lower_bound(all(rb),h-ra.at(j))-rb.begin();
                cnt+=lower_bound(all(rb),h)-lower_bound(all(rb),h+l-ra.at(j));   
            }
        }
        if(cnt%2==1)ans+=(int)1<<i;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 6528
import copy
N,M = [int(hoge) for hoge in input().split()]
Ball = [False]*N
BallNum = [1] * N
Ball[0] = True
for i in range(M):
    x,y = [int(hoge) - 1  for hoge in input().split()]
    BallNum[x] -= 1
    BallNum[y] += 1
    if Ball[x]:
        Ball[y] = True 
    if BallNum[x] == 0:
        Ball[x] = False
print(sum(Ball))

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

N,X,Y=map(int,input().split())
E=[[] for i in range(N+1)]
for i in range(1,N):
    E[i].append(i+1)
    E[i+1].append(i)
E[X].append(Y)
E[Y].append(X)

ANS=[0]*(N+1)
from collections import deque
for i in range(1,N+1):
    Q=deque()
    Q.append(i)
    D=[-1]*(N+1)
    D[i]=0
    
    while Q:
        x=Q.popleft()
        for to in E[x]:
            if D[to]==-1:
                D[to]=D[x]+1
                Q.append(to)
                ANS[D[to]]+=1
    #print(D)
for i in range(1,N):
    print(ANS[i]//2)
    


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

int main(void){

	int n;
	cin >> n;

	int price[200000];
	int maxi;
	int mini;

	for (int i = 0; i < n; i++) cin >> price[i];

	mini = price[0];
	maxi = price[1] - mini;

	for (int i = 1; i < n; i++){

		maxi = max(maxi, price[i] - mini);
		if (mini > price[i]) mini = price[i];
	}

	cout << maxi << endl;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int64 INF = 1LL << 40 - 1;
constexpr int64 LINF = 1LL << 60 + 1;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)


signed main() {
  INIT;
	VAR(int, n);
	map< int, int > mp;
	vector< int > a;
	REP(i, n) {
		VAR(int, j);
		a.push_back(j);
		mp[j]++;
	}

	sort(ALL(a));
	a.erase(unique(ALL(a)), a.end());

	int ans = 0;
	RREP(i, a.size()) {
		RREP(j, 31) {
            int target = (1 << j) - a[i];
            if (!mp.count(target)) continue;
			if (target == a[i]) {
				int tmp = mp[target] / 2;
				mp[target] -= tmp * 2;
				ans += tmp;
			} else {
				int tmp1 = mp[target];
				int tmp2 = mp[a[i]];
				mp[target] -= min(tmp1, tmp2);
				mp[a[i]] -= min(tmp1, tmp2);
				ans += min(tmp1, tmp2);
			}
		}
	}

	OUT(ans)BR;
  
  return 0;
}


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

using namespace std;

int main() {
  int A, B, C, D, L, R;
  
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if(L > R) {
    cout << " Left" << endl;
  } else if(L < R) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
int N;
long long ans = -INFL;
void solve() {
    cin >> N;
    vector<long long> a(3 * N);
    for (int i = 0; i < (3 * N); i++) {
        cin >> a.at(i);
    }
    vector<long long> front((3 * N) + 1);
    vector<long long> back((3 * N) + 1); 
    priority_queue<long long, vector<long long>, greater<long long>>f_que;
    priority_queue<long long> b_que;
    for (int i = 0; i < (3 * N); i++) {
        long long b = 0;
        f_que.push(a[i]);
        if (f_que.size() == (N + 1)) { 
            b = f_que.top();
            f_que.pop();
        }
        front[i + 1] = front[i] + a[i] - b;
    }
    for (int i = (3 * N) - 1; i > -1; i--) {
        long long b = 0;
        b_que.push(a[i]);
        if (b_que.size() == (N + 1)) {
            b = b_que.top();
            b_que.pop();
        }
        back[i] = back[i + 1] + a[i] - b;
    }
    for (int i = N; i <= (2 * N); i++) {
        ans = max(ans, (front[i] - back[i]));
    } 
    cout << ans << endl;
    return;
}
//逆元を求める関数
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;
}
int main(int args, char* argv[]) {
    solve();
}

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

int main()
{
	ll n,q,sum=0;
	cin>>n;
	vector<ll> fr(MX+1,0);
	for(int i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		fr[a]++;
		sum += a;
	}
	cin>>q;
	vector<int> res;
	for(int i=0;i<q;i++)
	{
		ll b,c;
		cin>>b>>c;
		sum += c*fr[b];
		sum -= b*fr[b];
//		arr[c]=true;
		fr[c] += fr[b];
		fr[b]=0;
		cout<<sum<<endl;
	}
}
	


Measured memory_bytes: 3972
import java.io.*;
import java.util.*;
 
public class Main {
    static final long MOD = 1000000007L;
    static final int INF = 50000000;
    static final int NINF = -50000000;
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);
        
        int N = sc.ni();
        long[] nums = new long[N];
        for (int i = 0; i < N; i++)
        	nums[i] = sc.nl();
        Arrays.sort(nums);
        long ans = nums[N-1];
        int X = N-2;
        for (int i = N-2; i >= 0; i--) {
        	if (X <= 2) {
        		ans += X*nums[i];
        		break;
        	} else {
        		ans += 2*nums[i];
        		X -= 2;
        	}
        }
        pw.println(ans);
        
        pw.close();
    }
    
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int ni() {
            return Integer.parseInt(next());
        }
 
        long nl() {
            return Long.parseLong(next());
        }
 
        double nd() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 57380
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
LL n, m;
int main() {
	LL i, j, k;
	scanf("%lld%lld", &n, &m);
	if(n == 1 && m == 1) printf("1\n");
	else if(n == 1 || m == 1){
		if(n > m) swap(n, m);
		printf("%lld\n", m-2);
	} else printf("%lld\n", (n-2)*(m-2));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cstdio>

#define MAX_ELEMENT 1000000
#define MAX_LEN 12

char H[MAX_ELEMENT + 1][MAX_LEN + 1];

int getKey(char c)
{
  switch (c)
  {
  case 'A':
    return 1;
  case 'C':
    return 2;
  case 'G':
    return 3;
  case 'T':
    return 4;
  }
  return -1;
}

unsigned int hash(const char *str)
{
  unsigned int h = 0;

  do
  {
    h += getKey(*str);
    h *= 5;
  } while (*++str);
  // std::cout << "               => " << std::hex << h << std::endl;
  return h % MAX_ELEMENT;
}

void insert(const char *str)
{
  unsigned int idx = hash(str);

  while (!(H[idx][0] == 0 || !strcmp(H[idx], str)))
  {
    idx = (idx + 1) % MAX_ELEMENT;
  }
  strcpy(H[idx], str);
  return;
}

int find(const char *str)
{
  unsigned int idx = hash(str);
  // std::cout << "H[idx]: " << H[idx] << std::endl;
  while (!(H[idx][0] == 0 || !strcmp(H[idx], str)))
  {
    idx = (idx + 1) % MAX_ELEMENT;
  }
  return !strcmp(H[idx], str);
}

int main()
{
  int n;
  char cmd[10], str[14];

  std::cin >> n;
  for (int i = 0; i < n; i++)
  {
    //std::cin >> cmd >> str;
    scanf("%s %s", cmd, str);
    if (cmd[0] == 'i')
    { // insert
      insert(str);
    }
    else
    { // find
      std::cout << (find(str) ? "yes" : "no") << std::endl;
    }
  }

  return 0;
}


Measured memory_bytes: 11796
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,M = LI()
    root = [[] for _ in range(N)]
    for _ in range(M):
        a,b = LI()
        root[a-1].append(b-1)
        root[b-1].append(a-1)
    node = [0] * N

    ans = 0
    q = []
    q.append((0,1))

    while q:
        u,d = q.pop()
        if d < 0:
            node[u] = 0
        else:
            node[u] = d
            q.append((u,-1))
            for v in root[u]:
                if node[v]: continue
                if d+1 == N: ans += 1
                else:
                    q.append((v,d+1))

    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
    int n;cin>>n;
    int H[n+1];//インデックス0は欠番。
    for(int i=0;i<n;i++)cin>>H[i+1];

    //順に出力していく
    for(int j=1;j<n+1;j++){
        cout<<"node "<<j<<": key = "<<H[j]<<", ";
        if(j/2 > 0){//親のkeyが存在しているか
            cout<<"parent key = "<<H[j/2]<<", ";
        }
        if(2*j < n+1){//左の子の存在性
            cout<<"left key = "<<H[2*j]<<", ";
        }
        if(2*j+1 < n+1){//右の子の存在性
            cout<<"right key = "<<H[2*j+1]<<", ";
        }
        cout<<endl;
    }
    return 0;
}


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

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

  int ans = 0;
  for(int i=0;i<n;i++){
    cout << "lst " <<  i << endl;
    int k;
    cin >> k;
    vector<int> d(k);
    for(int j=0;j<k;j++) cin >> d[j];

    ans += k*(k-1);
  }

  cout << "ans " << ans << endl;
}

Measured memory_bytes: 3108
nums = input().split(" ")
A = int(nums[0])
B = int(nums[1])
K = int(nums[2])

"""
ここで、まずはAとKの比較を行って、Aの方が大きければその場で試行は終了
し、Kの方が大きければ、A=0となり、その差|A-K|は残りのBから引くものになる。
"""
if A >= K:
  A -= K
  print(A, end=" ")
  print(B)
else:
  K -= A
  A = 0
  B -= K
  if B < 0:
    B = 0
  print(A, end=" ")
  print(B)

Measured memory_bytes: 3188
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  LL x;
  cin >> x;
  LL ans = x / 11;
  ans *= 2;
  x %= 11;
  if(x) ans++;
  if(x > 6) ans++;
  cout << ans << "\n";
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  long A, cnt[200000][2] = {}, ans = 0;
  for (int i=0; i<N; i++) {
    cin >> A;
    if (A+i<N-1)
      cnt[A+i][0]++;
    if (i-A>0)
      cnt[i-A][1]++;
  }
  for (int i=1; i<N-1; i++)
    ans += cnt[i][0]*cnt[i][1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6756
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= K; j++) {
            if (S - i - j >= 0 && S - i - j <= K) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=2e5+5;
const ll MOD=1e9+7;
const ll INF=1e18;
ll n,m,s,t,vis1[MAXN],vis2[MAXN],vis3[MAXN];
vector<ll>G[MAXN];
void solve()
{
    queue<pair<ll,ll> >q;
    q.push(make_pair(s,0));
    while(!q.empty())
    {
        pair<ll,ll> up=q.front();
        ll u=up.first,step=up.second;
        if(u==t)
        {
            printf("%lld\n",step);
            return;
        }
        q.pop();
        for(ll i=0;i<G[u].size();i++)
        {
            ll v1=G[u][i];
            if(vis1[v1])continue;
            vis1[v1]=1;
            for(ll j=0;j<G[v1].size();j++)
            {
                ll v2=G[v1][j];
                if(vis2[v2])continue;
                vis2[v2]=1;
                for(ll k=0;k<G[v2].size();k++)
                {
                    ll v3=G[v2][k];
                    if(vis3[v3])continue;
                    q.push(make_pair(v3,step+1));
                    vis3[v3]=1;
                }
            }
        }
    }
    printf("-1\n");
}
int main()
{
//    freopen("c://duipai//data.txt","r",stdin);
//    freopen("c://duipai//wa.txt","w",stdout);
    while(~scanf("%lld %lld",&n,&m))
    {
//        string ss;
//        cin>>ss;
//        cout<<ss<<endl;
       for(ll i=1;i<=m;i++)
       {
           ll u,v;
           scanf("%lld %lld",&u,&v);
           G[u].push_back(v);
       }
       scanf("%lld %lld",&s,&t);
       solve();
    }
}
/*
5
76578820211343624  293297008968192 189152283861189120 324294649604739072 20266198324215808
*/


Measured memory_bytes: 11904
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] data = Console.ReadLine().Split(' ');
        int W = int.Parse(data[0]);
        int H = int.Parse(data[1]);
        int x = int.Parse(data[2]);
        int y = int.Parse(data[3]);
        int r = int.Parse(data[4]);

        if (H >= y + r && W >= x + r && y - r >= 0 && x - r >= 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 17588
// https://atcoder.jp/contests/abc160/tasks/abc160_e
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> va(A), vb(B), vc(C);
    for (auto &x : va)
        cin >> x;
    for (auto &x : vb)
        cin >> x;
    for (auto &x : vc)
        cin >> x;

    // 降順ソート
    sort(ALLR(va));
    sort(ALLR(vb));
    sort(ALLR(vc));

    queue<int> qa, qb;
    // 上位X個を小さい順に格納
    for (int i = X - 1; i >= 0; i--) {
        qa.push(va[i]);
    }
    for (int i = Y - 1; i >= 0; i--) {
        qb.push(vb[i]);
    }

    for (auto &x : vc) {
        // 最も小さい値を取り出す
        int t1 = qa.front();
        int t2 = qb.front();
        if (t1 < t2) {
            if (t1 < x) {
                qa.pop();
                qa.push(x);
            } else {
                break;
            }
        } else {
            if (t2 < x) {
                qb.pop();
                qb.push(x);
            } else {
                break;
            }
        }
    }
    int sum = 0;
    while (!qa.empty()) {
        sum += qa.front();
        qa.pop();
    }
    while (!qb.empty()) {
        sum += qb.front();
        qb.pop();
    }

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


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<typename U, typename V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}
 
int main() {
    FAST_IO();
    int N; cin >> N;
    vector<int> A(3*N + 1);
    repp(i, 1, 3*N) cin >> A[i];
    vector<int> psum(3*N + 1);
    repp(i, 1, 3*N) psum[i] = psum[i-1] + A[i];
    set<pii> L_stay, R_stay, L_remove, R_remove;
    ll L_sum = 0, R_sum = 0;
    repp(i, 1, N) {
        L_stay.insert({A[i], i});
        L_sum += A[i];
    }
    repp(i, N + 1, 3*N) {
        R_stay.insert({-A[i], i});
        R_sum += A[i];
    }
    rep(i, N) {
        R_remove.insert({-R_stay.begin()->first, R_stay.begin()->second});
        R_sum += R_stay.begin()->first;
        R_stay.erase(R_stay.begin());
    }
    ll ans = L_sum - R_sum, diff = ans;
    repp(i, N+1, 2*N) {
        diff += A[i];
        L_stay.insert({A[i], i});
        diff -= L_stay.begin()->first;
        L_remove.insert(*L_stay.begin());
        L_stay.erase(L_stay.begin());
        if(R_stay.find({-A[i], i}) != R_stay.end()) {
            diff += A[i];
            R_stay.erase({-A[i], i});
            diff -= R_remove.begin()->first;
            R_stay.insert({-R_remove.begin()->first, R_remove.begin()->second});
            R_remove.erase(R_remove.begin());
        } else {
            R_remove.erase({A[i], i});
        }
        ans = max(ans, diff);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 16640
S = input()

max_length = 0

for i in range(0, len(S)):
    for j in range(i + 1, len(S) + 1):
        sub = S[i:j]
        #print(sub.replace('ACGT', ''))
        if len(sub.translate(str.maketrans({'A':'','C':'','G':'','T':''}))) == 0:
            max_length = max(len(sub), max_length)


print(max_length)



Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, W;

    cin>>n>>W;
    vector<pair<int, int> > item(n);
    for(int i =0; i<n; i++)
        cin>>item[i].first>>item[i].second;

    vector<vector<ll> > dp(2,vector<ll> (W+1));


    for(int i =0; i< n; i++)
    {
        for(int j = 0; j<=W; j++)
        {
            if(i==0)
            {
                if(j>=item[i].first)
                    dp[i%2][j] = item[i].second;
            }
            else 
            {
                if(j>=item[i].first)
                    dp[i%2][j] = max(dp[(i-1)%2][j], item[i].second + dp[(i-1)%2][j - item[i].first]);
                else
                    dp[i%2][j] = dp[(i-1)%2][j];

            }   

        }
    }

    cout<<dp[(n-1)%2][W]<<"\n";
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int nx[4]={0,1,-1,0};
int ny[4]={1,0,0,-1};
int main(){
  ll n;
  cin>>n;
  vll a(n),t(n);
  rep(i,n) cin>>a[i]>>t[i];
  for(int i=1;i<n;i++){
    ll k=max((a[i-1]+a[i]-1)/a[i],(t[i-1]+t[i]-1)/t[i]);
    a[i]*=k;
    t[i]*=k;
  }
  COUT(a[n-1]+t[n-1]);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define repprev(i,a,b) for(ll i=b-1;i>=a;i--)
#define reprev(i,n) repprev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1<<1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1<<2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1<<3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1<<4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1<<5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1<<6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1<<7) // 0000 0000 1000 0000
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;

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

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;
}

struct UnionFind {
    vector<ll> par;

    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }

    ll root(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    ll size(ll x) {
        return -par[root(x)];
    }
};

int main() {
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    vector<int> a(MAX, 0);
    for (int i = 0; i < MAX; ++i) {
        if (i % 2 == 0) continue;
        if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }

    vector<int> s(MAX+1, 0);
    for (int i = 0; i < MAX; ++i) s[i+1] = s[i] + a[i];

    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;
        ++r;
        cout << s[r] - s[l] << endl;
    }
}

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

typedef long long ll;

int main() {
  ll N, A, B, C, D ,E; cin >> N >> A >> B >> C >> D >> E;
  ll a[5];
  a[0] = A; a[1] = B; a[2] = C; a[3] = D; a[4] = E;
  sort(a, a+5);
  if(N % a[0] == 0) cout << (N/a[0] + 4) << endl;
  else cout << (N/a[0] + 1) + 4 << endl;
  return 0;
}

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

int main(void) {
  int a, b, c;
  int flg = 0;
  
  cin >> a >> b >> c;
  
  for (int i=1; i<=b; i++) {
    if (i*a % b == c) flg = 1;
  }
  
  if (flg==0) cout << "NO" << endl;
  else cout << "YES" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,n,m) for(int i=n;i<=m;i++)
using namespace std;
int main(){
    int a[5];
    FOR(i,1,3)
    cin>>a[i];
    sort(a+1,a+4);

    if(a[1]+a[2]==a[3])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3576
#include<iostream>
using namespace std;
long long n,p,ans=1,a,cnt0,cnt1;
main(){
    cin>>n>>p;
    for(int i=0;i<n;i++){
        cin>>a;
        ans*=2;
        if(a%2)cnt1++;
        else cnt0++;
    }
    if(cnt0==n and p==0)cout<<ans<<endl;
    else if(cnt0==n and p==1)cout<<0<<endl;
    else cout<<ans/2<<endl;
}

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

using ll = long long;

string S;

void solve(){
    string T(S);
    int ans = 0;
    reverse(T.begin(), T.end());
    for(int i = 1; i <= S.size(); ++i){
        if(S[i - 1] != T[i - 1]) {
            ans++;
        }
    }
    cout << ans / 2;
}
int main(){
    cin >> S;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007
int acs(const void* a, const void* b) { return *(int*)a - *(int*)b; } // 1,2,3,4
int des(const void* a, const void* b) { return *(int*)b - *(int*)a; } // 8,7,6,5
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab

#define N 1001

int main() {
	
	int n, k, p[1009],sum=0;
	scanf("%d%d", &n, &k);
	rep(i, n)scanf("%d", p + i);
	qsort(p, n, sizeof(int), acs);
	rep(i, k)sum += p[i];
	printf("%d", sum);
}

Measured memory_bytes: 1744
N,K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * 10 ** 5

dp[0] = 0
for i in range(1, N):
  tmp = i
  if tmp > K:
    tmp = K
  for j in range(1,tmp + 1):
      dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]))

print(dp[N-1])


Measured memory_bytes: 55008
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    N = Scanner.int()
    MOD = 1000000007
    ans = pow(10, N, MOD)
    ans -= pow(9, N, MOD)

    ans -= pow(9, N, MOD)
    ans += pow(8, N, MOD)
    while ans < 0:
        ans += MOD
    ans %= MOD
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()
    # T = Scanner.int()
    # for _ in range(T):


if __name__ == "__main__":
    main()


Measured memory_bytes: 10420
S=input()
T=input()

len_s=len(S)
len_t=len(T)

ans=0
for i in range(len_s-len_t+1):
    cnt=0
    for j in range(len_t):
        if S[i+j]==T[j]:
            cnt += 1
    ans = max(ans,cnt)
    
print(len_t-ans)

Measured memory_bytes: 72488
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

func main() {
	n := nextInt()
	a := make([]int, 0, n)
	bb := make([]int, n-1)
	for index := 0; index < n-1; index++ {
		bb[index] = nextInt()
	}

	f := bb[0]
	ff := bb[1:]
	a = append(a, f)
	for _, item := range ff {
		a = append(a, Min(item, f))
		f = item
	}
	a = append(a, f)

	// f := bb[n-2]
	// a = append(a, f)
	// ff := bb[0 : n-2]
	// fmt.Printf("%#v\n", ff)
	// for _, item := range ff {
	// 	a = append(a, Min(item, f))
	// 	f = item
	// }
	// a = append(a, f)
	var re int
	for _, item := range a {
		re += item
	}
	fmt.Println(re)
}

func Min(nums ...int) int {
	if len(nums) == 0 {
		panic("function min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func Max(nums ...int) int {
	if len(nums) == 0 {
		panic("function max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    static StringBuilder max(StringBuilder a, StringBuilder b){
        if(a.length() > b.length())
            return a;
        return b;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();

        int[][] dp = new int[s.length()+1][t.length()+1];

        for(int i = 1; i < s.length()+1; i++){
            for(int j = 1; j < t.length()+1; j++){
                dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]);
                if(s.charAt(i-1) == t.charAt(j-1))
                    dp[i][j] = Math.max(dp[i][j],dp[i-1][j-1]+1);
            }
        }

        StringBuilder sb = new StringBuilder();

        int r = s.length();
        int c = t.length();

        while (r >= 1 && c >= 1){
           if(s.charAt(r-1) == t.charAt(c-1)){
               sb.append(s.charAt(r-1));
               r--;
               c--;
           }else{
               if(dp[r-1][c] > dp[r][c-1]){
                   r--;
               }else{
                   c--;
               }
           }
        }

        System.out.println(sb.reverse());
    }
}


Measured memory_bytes: 90064
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = 25005;
const int MAXK = 405;
const int MOD = 1e9 + 7;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

namespace ModCalculator {
	inline void Inc(int &x, int y) {
		x += y; if (x >= MOD) x -= MOD;
	}
	inline void Dec(int &x, int y) {
		x -= y; if (x < 0) x += MOD;
	}
	inline int Mul(int x, int y) {
		return 1LL * x * y % MOD;
	}
}
using namespace ModCalculator;

inline int ksm(int x, int k) {
	int ret = 1;
	while (k) {
		if (k & 1) ret = Mul(ret, x);
		x = Mul(x, x);
		k >>= 1;
	}
	return ret;
}

int n, k, m, a[MAXN], lst[MAXK];
int fac[MAXN], finv[MAXN];
int ans, dp[MAXN][MAXK], ds[MAXN][MAXK];

void init() {
	read(n); read(k); read(m);
	for (int i = 1; i <= m; ++i) {
		read(a[i]);
	}
	int mx = max(n, k);
	fac[0] = 1;
	for (int i = 1; i <= mx; ++i) {
		fac[i] = Mul(fac[i - 1], i);
	}
	finv[mx] = ksm(fac[mx], MOD - 2);
	for (int i = mx - 1; i >= 0; --i) {
		finv[i] = Mul(finv[i + 1], i + 1);
	}
	ans = Mul(n - m + 1, ksm(k, n - m));
}

void solve() {
	int mxd = 0;
	for (int i = 1, mn = 0; i <= m; ++i) {
		mn = min(mn + 1, i - lst[a[i]]);
		mxd = max(mxd, mn);
		lst[a[i]] = i;
	}
	if (mxd == k) {
		printf("%d\n", ans);
		return;
	}
	
	if (mxd == m) {
	
		dp[0][0] = 1;
		for (int i = 1; i <= n; ++i) {
			int ps = 0, ss = 0;
			for (int j = k - 1; j >= 1; --j) {
				Inc(ps, dp[i - 1][j]);
				Inc(dp[i][j], ps);
				Inc(dp[i][j], Mul(dp[i - 1][j - 1], k - j + 1));
				Inc(ss, ds[i - 1][j]);
				Inc(ds[i][j], ss);
				Inc(ds[i][j], Mul(ds[i - 1][j - 1], k - j + 1));
				if (j >= m) {
					Inc(ds[i][j], dp[i][j]);
				}
			}
		}
		int tmp = 0;
		for (int i = 1; i < k; ++i) {
			Inc(tmp, ds[n][i]);
		}
		Dec(ans, Mul(tmp, Mul(finv[k], fac[k - m])));
		
	} else {
		
		int ld, rd;
		mset(lst, 0);
		for (int i = 1; i <= m; ++i) {
			if (lst[a[i]]) {
				ld = i - 1;
				break;
			}
			lst[a[i]] = 1;
		}
		mset(lst, 0);
		for (int i = m; i >= 1; --i) {
			if (lst[a[i]]) {
				rd = m - i;
				break;
			}
			lst[a[i]] = 1;
		}
		dp[0][ld] = ds[0][rd] = 1;
		for (int i = 1; i <= n - m; ++i) {
			int ps = 0, ss = 0;
			for (int j = k - 1; j >= 1; --j) {
				Inc(ps, dp[i - 1][j]);
				Inc(dp[i][j], ps);
				Inc(dp[i][j], Mul(dp[i - 1][j - 1], k - j + 1));
				Inc(ss, ds[i - 1][j]);
				Inc(ds[i][j], ss);
				Inc(ds[i][j], Mul(ds[i - 1][j - 1], k - j + 1));
			}
		}
		for (int i = 0; i <= n - m; ++i) {
			int ls = 0, rs = 0;
			for (int j = 1; j < k; ++j) {
				Inc(ls, dp[i][j]);
				Inc(rs, ds[n - m - i][j]);
			}
			Dec(ans, Mul(ls, rs));
		}
		
	}
	printf("%d\n", ans);
}

int main() {
	init();
	solve();
	return 0;
}



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

string mul(int n){
    string s="";
    fol(i,3){
        s+=to_string(n);
    }
    return s;
}

void solve(){
    string n;cin>>n;
    bool flag = false;
    fol(i,10){
        if (n.find(mul(i))!=-1) flag=true;
    }
    if (flag) cout << "Yes" <<endl;
    else cout << "No" <<endl;
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#define ll long long int32_t 
#define int long long int
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const double PI = atan(1.0)*4;
const int64_t INF=1000000000000000003;
const int32_t LOG=21;
const int MOD=MOD1;
int h[200005];
int dp[200005];
int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
           int n,k;
           cin>>n>>k;
           rep(i,0,n)cin>>h[i];
           dp[0]=0;
           rep(i,1,n)
           {
           	   dp[i]=INF;
           	   rep(dec,1,k+1)
           	   {
           	   	   int j=i-dec;
           	   	   if(j>=0)
                   dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j])); 
           	   }
           }
           cout<<dp[n-1]<<endl;
      }
      return 0;     
}


Measured memory_bytes: 1792