akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner

import scala.collection.mutable


object Main {

  def main(args: Array[String]): Unit = {

    val sc = new Scanner(System.in)
    val n = sc.nextInt() //sunuke
    val k = sc.nextInt() //okasiの数

    val store = mutable.Set.empty[Int]

    (1 to k).foreach { _ =>
      val d = sc.nextInt()
      Vector.fill(d)(sc.nextInt()).foreach(a => store += a)
    }

    println(n - store.size)

  }
}


Measured memory_bytes: 57128
bingo = []
card = [[0,0,0],[0,0,0],[0,0,0]]
ans = 0
for i in range(3):
    A = list(map(int,input().split()))
    bingo.append(A)
N = int(input())
for i in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                card[i][j] += 1
if card[0][0]+card[0][1]+card[0][2] >= 3:
    ans += 1
if card[0][0]+card[1][0]+card[2][0] >= 3:
    ans += 1
if card[1][0]+card[1][1]+card[1][2] >= 3:
    ans += 1
if card[2][0]+card[2][1]+card[2][2] >= 3:
    ans += 1
if card[0][1]+card[1][1]+card[2][1] >= 3:
    ans += 1
if card[0][2]+card[1][2]+card[2][2] >= 3:
    ans += 1
if card[0][0]+card[1][1]+card[2][2] >= 3:
    ans += 1
if card[0][2]+card[1][1]+card[2][0] >= 3:
    ans += 1
if ans > 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

int ans = 0;
int a[120000];
int n;
vector<int> eds[120000];
int k;

int dfs1(int v) {
	int mx = 0;
	for (int u: eds[v])
		mx = max(mx, dfs1(u));
	if (v != 0 && a[v] != 0) {
		if (mx == k - 1) {
			++ans;
			return 0;
		}
	}
	return mx + 1;
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i), --a[i];
	ans = 0;
	if (a[0] != 0)
		++ans, a[0] = 0;
	for (int i = 1; i < n; ++i)
		eds[a[i]].push_back(i);
	dfs1(0);
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 11264
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int X = ceil(1.0 * A / D);
    int Y = ceil(1.0 * C / B);
    cout << (X >= Y ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3616
N = int(input())
S = input()

s1 = set()
s2 = set()
s3 = set()
for c in S:
    for c2 in s2: s3.add(c2+c)
    for c1 in s1: s2.add(c1+c)
    s1.add(c)

print(len(s3))

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	string ans = "Yes";
	if ((a == b && b == c) || (a != b && b != c && a != c))
		ans = "No";

	cout << ans << endl;
}


Measured memory_bytes: 256
// +build ignore
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	S := sc.nextStr()
	T := sc.nextStr()

	if S == T[:len(T)-1] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 1756
#include <stdio.h>
#define MAX 1000

int main(void)
{
    char num[MAX];
    int sum, i;

    scanf("%s", num);

    while (num[0] != '0') {
        sum = 0;
        i=0;
        while (num[i] != '\0') {
            sum += (num[i] - '0');
            i++;
        }
        printf("%d\n", sum);
        scanf("%s", num);
    }
    return 0;
}


Measured memory_bytes: 2048
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
for(;;){
int n=sc.nextInt();
if(n==0)break;
int taro[]=new int[2*n]; 
int hanako[]=new int[2*n];
for(int i=0;i<2*n;i++)hanako[i]=1;
for(int i=0;i<n;i++){
int m=sc.nextInt()-1;
taro[m]=1;hanako[m]=0;
}
int tp=n,hp=n,max=-1; boolean f=true;
for(;;){
for(int i=0;i<2*n;i++){
	if(f==true)max=-1;
	if(max<i&&taro[i]==1){
     max=i; taro[i]=0;
     hp-=1; f=true;
     break;
     }}
if(hp==0)break;
for(int i=0;i<2*n;i++){
	if(f==false)max=-1;
	if(max<i&&hanako[i]==1){
     max=i; hanako[i]=0;
     tp-=1; f=false;
     break;
     }}
if(tp==0)break;
}
System.out.println(tp);
System.out.println(hp);
}
}
}

Measured memory_bytes: 20588
from collections import Counter
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int, readline().split()))
q = int(readline())

c = Counter(a)
l = [0]*(10 ** 5 + 1)
for k, v in c.items():
    l[k] = v

sm = sum(a)

for i in range(q):
    b, c = map(int, readline().split())
    sm += ((c-b) * l[b])
    print(sm)
    l[c] += l[b]
    l[b] = 0

Measured memory_bytes: 19888
#include <stdio.h>
#include<string.h>
int main(void){
while(1){
    char a[201],b[201];
    scanf("%s",a);
    
    if(a[0]=='-')
    break;
    
    int n,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        
        strcpy(b,a);
        
        for(j=x;j<strlen(a)+x;j++){
            a[j-x]=b[j%strlen(a)];
        }
        
    }
    printf("%s\n",a);
    
}
    return 0;
}

Measured memory_bytes: 2748
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

ls = [A,B,C,D,E]
m = 10**10

for l in range(0,5):
    c = 0
    for j in range(0,5):
        if l == j:
            c+=ls[j]
        else:
            x = ls[j]
            while x%10 != 0:
                x+=1
            c+=x
    m = min(m,c)
print(m)


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

int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> xs(N), ys(M);
    for (int i = 0; i < N; i++) cin >> xs[i];
    for (int i = 0; i < M; i++) cin >> ys[i];
    xs.push_back(X);
    ys.push_back(Y);
    cout << (*max_element(xs.begin(), xs.end()) < *min_element(ys.begin(), ys.end()) ? "No War" : "War") << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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



VB isPrime;

void Eratosthenes(int n){
    if(n + 1 <= SZ(isPrime)) return;
    isPrime.resize(n+1, true);
    isPrime[0] = isPrime[1] = false;

    for(int i = 2; i * i <= n; ++i){
        if(isPrime[i]){
            for(int j = i; i * j <= n; ++j)
                isPrime[i*j] = false;
        }
    }
}
int main(){
    int N, K; cin >> N >> K;
    int R, S, P; cin >> R >> S >> P;
    string T; cin >> T;
    char prv = 0;
    int ans = 0;
    REP(i, K){
        prv = 0;
        for(int j = i; j < N; j += K){
            if(prv != T[j]){
                prv = T[j];
                if(T[j] == 'r') ans += P;
                else if(T[j] == 's') ans += R;
                else ans += S;
            }
            else prv = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		string S = GetString();
		int N = S.Length;

		var dict = new Dictionary<char, char>();
		dict['b'] = 'd';
		dict['d'] = 'b';
		dict['p'] = 'q';
		dict['q'] = 'p';
		
		char[] tmp = new char[N];
		for(int i = 0; i < N; i++)
			tmp[i] = dict[S[N - 1 - i]];

		string T = new String(tmp);

		Console.WriteLine(S.Equals(T) ? "Yes" : "No");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 14304
using System;
class Hellow
{
    public static void Main(string[] args)
    {
        var str = Console.ReadLine();
        var q = int.Parse(Console.ReadLine());
        for (int i = 0; i < q; i++)
        {
            var line = Console.ReadLine().Split();
            var a = int.Parse(line[1]);
            var b = int.Parse(line[2]);
            var str1 = str.Substring(0, a);
            var str2 = "";
            var str3 = (b == str.Length - 1) ? "" : str.Substring(b + 1);
            
            switch (line[0])
            {
                case "print":
                    Console.WriteLine(str.Substring(a, b - a + 1));
                    break;
                case "reverse":
                    foreach (var item in str.Substring(a, b - a + 1))
                    {
                        str2 = item + str2;
                    }
                    str = str1 + str2 + str3;
                    break;
                case "replace":
                    str2 = line[3];
                    str = str1 + str2 + str3;
                    break;
                default:
                    break;
            }
        }
    }
}


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

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,a,b;
	cin >> n >> a >> b;
	ll p[n];
	rep(i,0,n){
		cin >> p[i];
	}
	sort(p,p+n);
	ll x=0,y=0,z=0;
	for(ll i=0; i<n; i++){
		if(p[i]<=a) x++;
		if(p[i]>a && p[i]<=b) y++;
		if(p[i]>b) z++;
	}
	ll res=min3(x,y,z);
	cout << res;
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
  char s[100001];
  int a[100000];
  int i;
  scanf("%s",s);
  a[0]=1;
  for(i=1;s[i]!='\0';i++)a[i]=a[i-1]+(s[i]=='g')*2-1;
  printf("%d",a[i-1]/2);
}


Measured memory_bytes: 640
s=input()
t=input()
s*=2
next=[[-1]*26 for _ in range(len(s))]
alph=[[]for _ in range(26)]
for i in range(len(s)):
	alph[ord(s[i])-ord("a")].append(i)
from bisect import bisect_right
for i in range(len(s)//2):
	for j in range(26):
		if len(alph[j])>bisect_right(alph[j],i):
			next[i][j]=alph[j][bisect_right(alph[j],i)]
ans=1
now=len(s)//2-1
for x in t:
	r=ord(x)-ord("a")
	now=next[now][r]
	if now==-1:
		print(-1)
		exit()
	if now>=len(s)//2:
		ans+=len(s)//2
		now-=len(s)//2
print(ans+now-len(s)//2)

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

int main(){
  long long A;
  string S;
  cin >> A >> S;
  
  long long B = (S[0]-'0')*100;
  B += (S[2]-'0')*10;
  B += S[3]-'0';
  
  cout << (A*B)/100 << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;
#include <string>
typedef long long int ll;
#include <algorithm>
#include <stack>
#include <vector>
#include <array>

int search(vector<int> v,int e){
  int hantei=0;
  int val = 0;
  for(int i=0 ;i<v.size(); i++){
    val = v.back();
    v.pop_back();
    if(val==e){
      hantei=1;
      break;
    }
  }
  return hantei;
}

int search2(vector<int> v,int e){
  int hantei=0;
  int val = 0;
  for(int i: v){
    if(i==e){
      hantei=1;
      break;
    }
  }
  return hantei;
}

int main(){

    //stack<int> s;
  int N;
  int Q;
  cin >> N >>Q;
  vector<vector<int> > v(N);
  vector<int> p(N,0);

  for(int i=0;i<N-1;i++){
    int a,b; cin >>a>>b;
    v[a-1].push_back(b-1);
    v[b-1].push_back(a-1);
    //printf("v[%d]=%d\n",a-1,b-1);
    //printf("v[%d]=%d\n",b-1,a-1);
  }
  for(int i=0;i<Q;i++){
    int p_,x;
    cin >>p_>>x;
    p[p_-1]+=x;
  }

  vector <int> sta(N);
  vector <int> root(N,0);
  vector <int> ans(N,0);
  sta.push_back(0);
  int size_ = sta.size();
  int t=0;
  int val = 0;
  int time=0;
  int e = 0;
  ans[0]=p[0];
  while(sta.size()>0){
    time += 1;
    //printf("%dtime\n",time );
    t=sta.back();
    val = ans[t];
    //cout << val<<endl;
    //cout << 2;
    root.push_back(t);
    root[t]=1;
    sta.pop_back();
    //cout << 1;
    for(int e:v[t]){
      e=v[t].back();
      v[t].pop_back();

      if(root[e]==0){
        //printf("push[%d]\n",e+1);
        sta.push_back(e);
        root[e]=1;
        ans[e]=val+p[e];
      }
    }

  }

  for(int i=0;i<N;i++){
    printf("%d\n",ans[i]);
  }



  //初期化 std::vector<型名> 変数名(要素数,値);



  return 0;
}


Measured memory_bytes: 20024
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			List<int>[] tree = new List<int>[n];
			for (int i = 0; i < n; i++) {
				tree[i] = new List<int>();
			}
			long[,] dp = new long[n, 2];

			for (int i = 0; i < n - 1; i++) {
				int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
				int x = vs[0] - 1;
				int y = vs[1] - 1;
				tree[x].Add(y);
				tree[y].Add(x);
			}
			saiki(tree, 0, dp);
			long ans = (dp[0, 0] + dp[0, 1]) % mod;
			Console.WriteLine(ans);


			Console.Out.Flush();
		}

		static void saiki(List<int>[] tree, int node, long[,] dp)
		{
			dp[node, 0] = 1;
			dp[node, 1] = 1;
			foreach (var i in tree[node]) {
				if (dp[i, 0] == 0) {
					saiki(tree, i, dp);
					dp[node, 0] *= dp[i, 0] + dp[i, 1];
					dp[node, 0] %= mod;
					dp[node, 1] *= dp[i, 0];
					dp[node, 1] %= mod;
					//System.Diagnostics.Debug.WriteLine($"{node}({dp[node, 0]},{dp[node, 1]}) -> {i}({dp[i, 0]},{dp[i, 1]})");
				}
			}
		}

	}
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
int INF = 1e8;
int main(){
    int H, W;
    cin >> H >> W;
    int d[H][W];
    vector<vector<char>> s(H, vector<char> (W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) {
            cin >> s[i][j];
            d[i][j] = INF;
        }
    }
    d[0][0] = 0;
    int dx[4] = {-1, 0, 1, 0};
    int dy[4] = {0, -1, 0, 1};
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            for(int k = 0; k < 4; k++){
                int th = i + dy[k];
                int tw = j + dx[k];
                if(0 <= th && th < H && 0 <= tw && tw < W){
                    if(s[i][j] == '.' && s[th][tw] == '#') d[th][tw] = min(d[th][tw], d[i][j] + 1);
                    else d[th][tw] = min(d[th][tw], d[i][j]);
                }
            }
        }
    }
    if(s[0][0] == '#') cout << d[H - 1][W - 1] + 1 << endl;
    else cout << d[H - 1][W - 1] << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func solve(n int) int {
	i := 0
	for {
		if val := math.Pow(2, float64(i)); val*2 > float64(n) {
			return int(val)
		}
		i++
	}
}

func main() {
	for {
		var n int
		_, err := fmt.Scan(&n)
		if err != nil {
			break
		}

		res := []int{}
		for {
			val := solve(n)
			res = append(res, val)
			n -= val

			if n <= 0 {
				break
			}
		}

		for i := range res {
			if i != 0 {
				fmt.Print(" ")
			}
			fmt.Print(res[len(res)-i-1])
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1132
n = int(input())
a = list(map(int, input().split()))

ma = -1
for i in range(n - 1):
    for j in range(i + 1, n):
        pro = a[i] * a[j]

        digit = [pro % (10 ** k) // (10 ** (k - 1)) for k in range(1, 10)]

        while digit[-1] == 0:
            digit = digit[:-1]

        if len(digit) == 1:
            ma = max(ma, pro)
            continue

        flag = True
        for k in range(len(digit) - 1):
            if digit[k + 1] - digit[k] != -1:
                flag = False
                break

        if flag:
            ma = max(ma, pro)

print(ma)


Measured memory_bytes: 5628
import sys
 
sys.setrecursionlimit(10 ** 6)
n = int(input())
 
edge = [[] for i in range(n)]
ans = [-1] * n
odd = []
even =[]
nums = [[],[],[]]
for i in range(1,n+1):
    nums[i % 3].append(i)
 
def dfs(x, last = -1, d = 0):
    if d % 2 == 0: even.append(x)
    else: odd.append(x)
    for nxt in edge[x]:
        if nxt == last:continue
        dfs(nxt, x, d + 1)
 
for i in range(n-1):
    a, b = map(int, input().split())
    a-=1
    b-=1
    edge[a].append(b)
    edge[b].append(a)
 
dfs(0)
 
zerocnt = len(nums[0])
 
if len(even) <= zerocnt:
    for even_node in even:
        ans[even_node] = nums[0].pop()
    rest = nums[0] + nums[1] + nums[2]
    for odd_node in odd:
        ans[odd_node] = rest.pop()
 
elif len(odd) <= zerocnt:
    for odd_node in odd:
        ans[odd_node] = nums[0].pop()
    rest = nums[0] + nums[1] + nums[2]
    for even_node in even:
        ans[even_node] = rest.pop()
 

else:
    for num in nums[1]:
        ans[even.pop()] = num
    for num in nums[2]:
        ans[odd.pop()] = num
    rest = nums[0]
    for even_node in even:
        ans[even_node] = rest.pop()
    for odd_node in odd:
        ans[odd_node] = rest.pop()
 
print(*ans)

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

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

    vector<int> H(N);
    rep(i, N) cin >> H.at(i);

    int position = 0;

    vector<int> costs(N);
    rep(i, N)
    {
        if (i == 0)
        {
            costs.at(i) = 0;
        }
        else if (i == 1)
        {
            costs.at(i) = abs(H.at(i - 1) - H.at(i));
        }
        else
        {
            costs.at(i) = min(costs.at(i - 1) + abs(H.at(i - 1) - H.at(i)), costs.at(i - 2) + abs(H.at(i - 2) - H.at(i)));
        }
    }

    cout << costs.at(N - 1) << endl;
    return 0;
}

Measured memory_bytes: 4024
package main

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

// const abcd = "abcdefghijklnmopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}

var inf int = 1e9

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	s := next.Line()
	ans := make([]byte, 0)
	for i := 0; i < len(s); i += 2 {
		ans = append(ans, s[i])
	}

	fmt.Println(string(ans))
}

// ---------------------------------------------------------

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

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

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

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

int const MAGIC = 15;

int k;

vll all;

int getsum(ll x) {
	int res = 0;
	while (x) {
		res += (x % 10);
		x /= 10;
	}
	return res;
}

void check(ll n) {
	ll p10 = 1;
	fo(1, MAGIC) {
		ll m = n + p10;
		if (getsum(m) * n > getsum(n) * m) {
			return;
		}
		p10 *= 10;
	}
	all.pb(n);
}

void rec(int qa, int q9, ll cur) {
	if (qa == 0) {
		fo(1, q9) {
			cur *= 10;
			cur += 9;
		}
		check(cur);
		return;
	}	
	fi(0, 9) {
		if (cur == 0 && i == 0) continue;
		ll ncur = cur * 10 + i;
		rec(qa - 1, q9, ncur);
	}
}

void solve() {
	fi(1, 9) all.pb(i);
	fi(2, 15) {
		rec(min(4, i / 2), i - min(4, i / 2), 0LL);
	}		
	sort(all.begin(), all.end());

	assert(k - 1 < sz(all));
	fi(0, k - 1) {
		printf("%lld\n", all[i]);
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &k);
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

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

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define maxn 100005

void addEdge(vector<int> adj[], int u, int v)
{
    adj[u].push_back(v);
}

int dp[maxn];
bool vis[maxn];

void dfs(vector<int> adj[], int i)
{
    vis[i] = true;
    for(int v : adj[i])
    {
        if(!vis[v])
            dfs(adj,v);
        dp[i] = max(dp[i],1+dp[v]);
    }
}

int main()
{
    FASTIO
    memset(dp,0,sizeof(dp));
    memset(vis,false,sizeof(vis));
    int n, m, x, y;
    cin >> n >> m;
    vector<int> adj[n];
    for(int i=0; i<m; i++)
    {
        cin >> x >> y;
        addEdge(adj,x-1,y-1);
    }
    for(int u=0; u<n; u++)
    {
        if(!vis[u])
            dfs(adj,u);
    }
    cout << *max_element(dp,dp+n) << "\n";
    return 0;
}

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

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        //input
        String[] num  = br.readLine().split(" ");        
        int A = Integer.parseInt(num[0]);
        int B = Integer.parseInt(num[1]);
        
        //for algorithm
        long result = 1;
        int count_A = 0, count_B = 0;
        //int count_big_A = 0, count_big_B = 0;
        int max = 100000;
        //int prime_max = (int)Math.sqrt(max);
        boolean[] table = new boolean[max+1];
        List<Integer> prime = new  ArrayList<>();

        Arrays.fill(table, true);

        table[0] = table[1] = false;
        int count = 0;

        for(int i = 2; i <= max; i++){
          if(table[i]){
            prime.add(i);
            count++;
            int j = i + i;
            while(j <= max){
              table[j] = false;
              j = j + i;
            }
          }
        }

        

        //algorithm
        for(int i = 0; i < prime.size(); i++){
          if(A < prime.get(i) && B < prime.get(i)){
            break;
          }

          count_A = count_B = 0;

          while( A%prime.get(i) == 0){
            A /= prime.get(i);
            count_A++;
            //count_big_A++;
          }
          
          while( B%prime.get(i) == 0){
            B /= prime.get(i);
            count_B++;
            //count_big_B++;
          }

          if(count_A != 0 || count_B != 0){
            //System.out.println(prime.get(i));
            //System.out.println((double)Math.max(count_A, count_B));
            result *= (long)Math.pow((double)prime.get(i), (double)Math.max(count_A, count_B));
          }
        }
        System.out.println(result);
      }

    }
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll X, Y;
	cin >> X >> Y;
	if(X%Y==0){
		cout << -1 << endl;
		return 0;
	}else{
		cout << X << endl;
		return 0;
	}
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] A = new long[n+1];
        for(int i = 1; i<=n;i++) A[i] =sc.nextLong();
        Flow sl = new Flow(A);
        long res = sl.max_flow(0,n+1);
        long sum = 0;
        for(int i=1;i<=n;i++) sum += Math.max(0,A[i]);
        System.out.println(sum-res);
    }
    static class Flow{
        long inf = Long.MAX_VALUE/10000;
        int n;
        int[] level;
        int[] iter;
        ArrayList<Edge>[] map;

        public Flow(long[] A){
            n = A.length-1;
            level = new int[n+2];
            iter = new int[n+2];
            map = new ArrayList[n+2];
            for(int i=0;i<=n+1;i++) map[i] = new ArrayList<>();
            for(int i=1;i<=n;i++){
                if(A[i]<=0) add_Edge(0,i,Math.abs(A[i]));
                if(A[i]>0) add_Edge(i,n+1,A[i]);
            }
            for(int i=1;i<=n;i++){
                for(int j=2*i; j<=n; j+=i) add_Edge(i, j, inf);
            }
        }

        void add_Edge(int from, int to, long cap){
            map[from].add(new Edge(to, cap, map[to].size()));
            map[to].add(new Edge(from, 0, map[from].size()-1));
        }

        void bfs(int s){
            Arrays.fill(level, -1);
            LinkedList<Integer> que = new LinkedList<>();
            level[s]=0;
            que.add(s);
            while(que.size()>0){
                int v = que.poll();
                for(int i=0;i<map[v].size();i++){
                    Edge e = map[v].get(i);
                    if(e.cap>0&&level[e.to]<0){
                        level[e.to] = level[v]+1;
                        que.add(e.to);
                    }
                }
            }
        }

        long dfs(int v, int t, long f){
            if(v==t) return f;
            int start = iter[v];
            for(int i=start;i<map[v].size();i++){
                Edge e = map[v].get(i);
                if(e.cap>0&&level[v]<level[e.to]){
                    long d = dfs(e.to,t,Math.min(f,e.cap));
                    if(d>0){
                        e.cap -= d;
                        map[e.to].get(e.rev).cap += d;
                        return d;
                    }
                }
                iter[v]++;
            }
            return 0;
        }

        long max_flow(int s, int t){
            long flow = 0;
            for(;;){
                bfs(s);
                if(level[t]<0) return flow;
                Arrays.fill(iter,0);
                long f = dfs(s,t,inf);
                while(f>0){
                    flow += f;
                    f = dfs(s,t,inf);
                }
            }
        }

    }
    static class Edge{
        long cap;
        int to;
        int rev;
        public Edge(int t, long c, int r){
            this.to = t;
            this.cap = c;
            this.rev = r;
        }
    }
}


Measured memory_bytes: 24148
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
long long int gcd(long long int a,long long int b){
  if(b==0){
    return a;
  }
  else{
    return gcd(b,a%b);
  }
};
int main(){
  long long int c,n,a[100010],i;
  scanf("%lld\n",&n);
  for(i=0;i<n;i++){
    scanf("%lld ",&a[i]);
  }
  c=gcd(a[0],a[1]);
  for(i=2;i<n;i++){
    c=gcd(c,a[i]);
  }
  printf("%lld\n",c);
  return 0;
}

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

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int memo[100010] = {};

    for(int i = n-2;i >= 0;i--){
        memo[i] = memo[i+1];
        if(s[i] == 'A' && s[i+1] == 'C'){
            memo[i]++;
        }
    }

    for(int i = 0;i < q;i++){
        int l, r;
        cin >> l >> r;
        l--;
        int ans = memo[l] - memo[r];
        if(s[r-1] == 'A' && s[r] == 'C'){
            ans--;
        }

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



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  string S;
  while(N != 0){
    if(N % 26 == 0){
      S += 'z';
      N -= 26;
    }else {
      S += (N % 26) + 'a' - 1;
    }
    N /= 26;
  }
  for(int i = S.size() - 1; i >= 0; i--)cout << S.at(i);
  cout << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
int main()
{
  int n,m,a[100][100],b[1000],i,j,sum=0;
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++)
  for(j=0;j<m;j++)
  scanf("%d",&a[i][j]);
  for(i=0;i<m;i++)
  scanf("%d",&b[i]);

  for(i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    {
      sum+=b[j]*a[i][j];
    }
    printf("%d\n",sum);
    sum=0;
  }
  return 0;
}

Measured memory_bytes: 644
#include<cstdio>
#include<functional>
#include<algorithm>
#define MM 200000000
using namespace std;
int main(void)
{
	int n,m,i,j,k,a,b,c,d,mi[21][21],s,g,v,p,sum;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)	{
		for(j=1;j<=n;j++)	{
			if(i==j)	mi[i][j]=0;
			else mi[i][j]=MM;
		}
	}
	for(i=0;i<m;i++)	{
		scanf("%d,%d,%d,%d",&a,&b,&c,&d);
		mi[a][b]=c;	mi[b][a]=d;
	}
	scanf("%d,%d,%d,%d",&s,&g,&v,&p);
	for(k=1;k<=n;k++)	{
		for(i=1;i<=n;i++)	{
			for(j=1;j<=n;j++)	{
				mi[i][j]=min(mi[i][j],mi[i][k]+mi[k][j]);
			}
		}
	}
	sum=v-p-mi[s][g]-mi[g][s];
	printf("%d\n",sum);
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;

const int dh[] = {1, -1, 0, 0};
const int dw[] = {0, 0, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> a(H);

    queue<P> q;
    vector< vector<int> > memo(H, vector<int>(W, INF));
    for (int i = 0; i < H; i++) {
        cin >> a[i];
        for (int j = 0; j < W; j++) {
            if (a[i][j] == '#') {
                memo[i][j] = 0;
                q.emplace(i, j);
            }
        }
    }

    while (!q.empty()) {
        P p = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            int h = p.first + dh[i], w = p.second + dw[i];
            if (h < 0 || h >= H || w < 0 || w >= W) continue;
            if (memo[h][w] < INF) continue;
            memo[h][w] = memo[p.first][p.second] + 1;
            q.emplace(h, w);
        }
    }

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ans = max(ans, memo[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){

  char har[9];
  cin >> har[0] >> har[1] >> har[2];
  cin >> har[3] >> har[4] >> har[5];
  cin >> har[6] >> har[7] >> har[8];

  cout << har[0] << har[4] << har[8] << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np

n, d = list(map(int, input().split()))
xxx = [np.array(list(map(int, input().split()))) for _ in range(n)]
ans = 0
for i, x in enumerate(xxx):
    for y in xxx[i + 1:]:
        a = np.linalg.norm(x - y)
        if abs(a - int(a)) < 0.00001:
            ans += 1
print(ans)


Measured memory_bytes: 12496
MOD = 10 ** 9 + 7
N, M = gets.split.map(&:to_i)
A = M.times.map { gets.to_i }

danger = Array.new(N + 10, false)
A.each do |a|
  danger[a] = true
end
dp = Array.new(N + 10, 0)
dp[0] = 1

0.upto(N - 1) do |i|
  next if danger[i]

  if !danger[i + 1]
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD
  end

  if !danger[i + 2]
    dp[i + 2] = (dp[i + 2] + dp[i]) % MOD
  end
end

puts dp[N]


Measured memory_bytes: 4660
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

while(len(np.nonzero(A)[0]) != 1):
    devisor = np.min(A[np.nonzero(A)])
    devisor_i = np.where(A==devisor)[0][0]
    A = np.array([A[devisor_i], *(A%devisor)[:devisor_i], *(A%devisor)[devisor_i+1:]])
    
print(*A[np.nonzero(A)])

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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

ll n,a,b;
vll h;

bool isOk(ll mid){
  ll cnt=0;
  ll x=mid*b;
  rep(i,n){
    if(h[i]>x) cnt+=(h[i]-x+(a-b-1))/(a-b);
  }
  return cnt<=mid;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  cin>>n>>a>>b;
  h.resize(n);
  rep(i,n) cin>>h[i];
  
  ll ng=0, ok=1e9;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    if(isOk(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
}

Measured memory_bytes: 3964
a, b, c, x, y = (int(i) for i in input().split())

ans = []

ans.append(a*x + b*y)
ans.append(c*max(x, y)*2)
if x-y > 0:
    ans.append(a*(x-y) + c*min(x, y)*2)
elif x-y < 0:
    ans.append(b*(y-x) + c*min(x, y)*2)
    
print(min(ans))

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

int main() {
  int l, m, n;
  while(cin >> l && l) {
    int ans = -1;
    for(int i=0; i<12; i++) {
      cin >> m >> n;
      l -= m-n;
      if(ans == -1 && l <= 0) { ans = i+1; }
    }
    if(ans == -1) cout << "NA" << endl;
    else cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n;
string s[110];
ll ans, t[110];
int main() {
	cin >> n;
	REP(i, n) {
		cin >> s[i] >> t[i];
	}
	string x;
	cin >> x;
	bool ok = false;
	REP(i, n) {
		if (ok)ans += t[i];
		if (s[i] == x) ok = true;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
        
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String line = sc.nextLine();
        String[] ar = line.split("");

        for (int i = 0; i < ar.length; i++) {
            try{
                if(ar[i].equals("?")) {
                    if (i == 0) {
                        if (ar[i + 1].equals("D")) {
                            ar[i] = "P";
                        } else if (ar[i + 1].equals("P")) {
                            ar[i] = "D";
                        } else if (ar[i + 1].equals("?")) {
                            ar[i] = "P";
                        }
                    } else if (i == ar.length - 1) {
                        ar[i] = "D";
                    } else {
                        if (ar[i - 1].equals("P")) {
                            ar[i] = "D";
                        } else if (ar[i - 1].equals("D")) {
                            if (ar[i + 1].equals("P")) {
                                ar[i] = "D";
                            } else {
                                ar[i] = "P";
                            }
                        }
                    }
                }
            } catch(Exception e) {
                ar[i] = "D";
            }
        }
        Arrays.stream(ar).forEach(e -> System.out.print(e));
    }
}

Measured memory_bytes: 68840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int INF = 1 << 20;
const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1};
int H, W;
string s[50];
int dis[50][50];
int black;

bool contain(int y, int x) {
  return y >= 0 && y < H && x >= 0 && x < W;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> s[i];
    for (int j = 0; j < W; j++) {
      black += s[i][j] == '#';
    }
  }
  using P = tuple<int, int>;
  queue<P> que;
  que.emplace(0, 0);
  fill_n((int*)dis, 50 * 50, INF);
  dis[0][0] = 1;
  while (!que.empty()) {
    int y, x;
    tie(y, x) = que.front(); que.pop();
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (contain(ny, nx) && s[ny][nx] != '#' && dis[ny][nx] == INF) {
        dis[ny][nx] = dis[y][x] + 1;
        que.emplace(ny, nx);
      }
    }
  }
  if (dis[H - 1][W - 1] == INF) cout << -1 << endl;
  else cout << (H * W - dis[H - 1][W - 1] - black) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int count = 1;
    rep(i, n){
        if(count==a[i]){
            count++;
        }
    }
    if(count==1){
        cout << -1 << endl;
        return 0;
    }
    cout << a.size() - count + 1 << endl;

    return 0;
}

Measured memory_bytes: 1152
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let mut k: i64 = s.next().unwrap().parse().unwrap();
	let a: Vec<_> = s.take(n).map(|a| a.parse::<usize>().unwrap() - 1).collect();
	let mut dbl = vec![vec![0; n]; 64];
	dbl[0] = a.clone();
	for i in 1..dbl.len() {
		for j in 0..n {
			let to = dbl[i - 1][dbl[i - 1][j]];
			dbl[i][j] = to;
		}
	}
	let mut ans = 0;
	let mut bit = 0;
	while k > 0 {
		if k % 2 != 0 {
			ans = dbl[bit][ans];
		}
		k /= 2;
		bit += 1;
	}
	println!("{}", ans + 1);
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  ll left = -INF, right = INF;
  while (right - left > 1) {
    ll x = (left + right) / 2;
    ll s = 0, t = 0;
    rep(i, n) {
      if (a[i] > 0) {
        int l2 = -1, r2 = n;
        while (r2 - l2 > 1) {
          int m = (l2 + r2) / 2;
          if (a[i] * a[m] <= x)
            l2 = m;
          else
            r2 = m;
        }
        s += r2;
      } else if (a[i] < 0) {
        int l2 = -1, r2 = n;
        while (r2 - l2 > 1) {
          int m = (l2 + r2) / 2;
          if (a[i] * a[m] <= x)
            r2 = m;
          else
            l2 = m;
        }
        s += n - r2;
      } else if (x >= 0)
        s += n;
      if (a[i] * a[i] <= x) t++;
    }
    ll num = (s - t) / 2;
    if (num >= k)
      right = x;
    else
      left = x;
  }
  cout << right << endl;
}


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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;

  if (s1[s1.size()-1] == s2[0] && s2[s2.size()-1] == s3[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
letters_mapping = {num: {num2:[] for num2 in range(10)} for num in range(10)}

for num in range(1, n + 1):
    first_letter = str(num)[0]
    last_letter = str(num)[-1]
    letters_mapping[int(first_letter)][int(last_letter)].append(num)

count = 0
for i, v in letters_mapping.items():
    for j, x in letters_mapping[i].items():
        for num in letters_mapping[i][j]:
            count += len(letters_mapping[j][i])
            
print(count) 

Measured memory_bytes: 11636
/*
在太阳西斜的这个世界里
置身天上之森。
等这场战争结束之后
不归之人与望眼欲穿的众人
人人本着正义之名
长存不灭的过去
逐渐消逝的未来
我回来了
纵使日薄西山
即便看不到未来
此时此刻的光辉
盼君勿忘
*/

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
const int N=2010,mod=1000000007;

int S,dp[N];

int main(){
    cin>>S;
    for(int i=3; i<=S; i++) dp[i]=1;
    for(int i=3; i<=S; i++)
    	for(int j=3; j<=i; j++)
    	    dp[i]=(dp[i]+dp[i-j])%mod;
    cout<<dp[S];
	return 0;
}

Measured memory_bytes: 3600