akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int INF=1e9;
const int di[]={-1,0,1,0};
const int dj[]={0,-1,0,1};

int main()
{
  int H,W;
  cin >> H >> W;
  vector<string> field(H);
  int all_white = 0;
  for(int i=0;i<H;i++)
  {
    char buf[64];
    scanf("%s",buf);
    for(int j=0;j<W;j++)
    {
      if(buf[j]=='.') all_white++;
    }
    field[i]=buf;
  }

  vector<vector<int> > dp(H,vector<int>(W,INF));
  dp[0][0]=0;

  queue<pair<int,int> > q;
  q.emplace(0,0);

  while(!q.empty())
  {
    int i=q.front().first, j=q.front().second;
    q.pop();
    if(field[i][j] != '.'){
      continue;
    }

    for(int k=0;k<4;k++)
    {
      int I=i+di[k], J=j+dj[k];

      if(I<0||H<=I||J<0||W<=J) continue;
      if(dp[I][J] < dp[i][j]){
        continue;
      }
      if(dp[I][J] == '#'){
        continue;
      }
      if(I==H-1&&J==W-1)
      {
        printf("%d\n",all_white-(dp[i][j]+2));
        return 0;
      }
      dp[I][J]=dp[i][j]+1;
      field[i][j] = '+';
      q.emplace(I,J);
    }
  }
  printf("-1\n");
  return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    print(N // 3)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8916
#include <bits/stdc++.h>
using namespace std;
 //Compiler version g++ 6.3.0
int main()
{
    int N, M;
    string s;
    map<string, int> m;
    
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> s;
        m[s]++;
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        cin >> s;
        m[s]--;
    }
    
    int ans = 0;
    for (auto i = m.begin(); i != m.end(); i++) {
        ans = max(i->second, ans);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
l = list(map(int, input().split()))
cnt = Counter(l)
res = len(cnt) == 1 and 0 in cnt
if not res and n % 3 == 0:
    if len(cnt) == 3 and all(v == n // 3 for v in cnt.values()):
        x = sorted(cnt.keys())
        res = x[0] ^ x[2] == x[1]
    if len(cnt) == 2 and cnt.get(0, 0) == n // 3:
        res = True
print("Yes" if res else "No")

Measured memory_bytes: 14468
#include <stdio.h>
 
using namespace std;
 
int main(){
    int m,f,r;
    char grade;
    while(true){
        scanf("%d %d %d",&m,&f,&r);
        if(m == -1 && f == -1 && r == -1) break;
        if(m == -1 || f == -1){
            grade = 'F';
        }else if(m+f >= 80){
            grade = 'A';
        }else if(m+f >= 65){
            grade = 'B';
        }else if(m+f >= 50){
            grade = 'C';
        }else if(m+f >= 30){
            grade = (r >= 50)? 'C':'D';
        }else{
            grade = 'F';
        }
        printf("%c\n",grade);
    }
}


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

int main() {
	int n;
	cin>>n;
	vector<ll> v;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		v.push_back(x);
	}
	ll ans=0;
	for(int i=0;i<n-1;i++){
		if(v[i]>v[i+1]){
			ans+=(v[i]-v[i+1]);
			v[i+1]=v[i];
		}
	}
	cout<<ans;
	return 0;
	
}

Measured memory_bytes: 5360
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(n**0.5)+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp /= i
      arr.append([i, cnt])
      
  if temp!=1:
    arr.append([temp, 1])
    
  if arr==[]:
    arr.append([n, 1])
    
  return arr

a = factorization(int(input()))
b = [1, 3, 6, 10, 15, 21, 28, 36, 45]

ans = 0

if len(a) == 1 and a[0][0] == 1:
  print(0)
  exit()
  
for i in a:
  for j in range(len(b)):
    if i[1] < b[j]:
      ans+=j
      break
    
print(ans)


Measured memory_bytes: 9432
import copy

N, M = map(int, input().split())
L = []

for i in range(M):
    k = list(map(int, input().split()))
    l = [i-1 for i in k[1:]]  # indexを渡していることに注意
    L.append(l)

p = list(map(int, input().split()))


def calc(idx, lampe):
    if idx == N:
        ans = 0
        for l in range(M):
            if sum([lampe[v] for v in L[l]]) % 2 != p[l]:
                return 0

        return 1

    ans = 0
    ans += calc(idx+1, lampe)
    lampe2 = copy.copy(lampe)
    lampe2[idx] = 1
    ans += calc(idx+1, lampe2)
    return ans


ans = calc(0, [0]*N)
print(ans)


Measured memory_bytes: 3444
open System
open System.Collections.Generic

let n, m =
    let l = Console.ReadLine().Split(' ') |> Array.map int
    l.[0], l.[1]

let connCondition: Map<int, ResizeArray<int>> =
    let concond =
        Map(
            seq {
                for i in 0 .. n - 1 do
                    (i, new ResizeArray<int>())
            })

    for i in 1 .. m do
        let a, b =
            let l = Console.ReadLine().Split(' ') |> Array.map int
            l.[0] - 1, l.[1] - 1
        concond.[a].Add(b)
        concond.[b].Add(a)

    concond

let path = Array.init n (fun i -> if i = 0 then 0 else -1)

let q = Queue<int>()
q.Enqueue(0)
let mutable cnt = 0

while q.Count <> 0 do
    let i = q.Dequeue()

    for j in connCondition.[i] do
        if path.[j] = -1 then
            cnt <- cnt + 1
            q.Enqueue(j)
            path.[j] <- i
        else
            ()

if cnt = n - 1 then
    Console.WriteLine "Yes"

    for i in 1 .. n - 1 do
        Console.WriteLine (path.[i] + 1)
else
    Console.WriteLine "No"

Measured memory_bytes: 54768
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    int k;
    bool d[10];
    fill(d, d + 10, 0);
    cin >> n >> k;
    imfor(i, k) {
        int D;
        cin >> D;
        d[D] = true;
    }
    while (true) {
        string s = to_string(n);
        bool f = true;
        for (int i = 0; i < s.size(); i++) {
            if (d[(s[i] - '0')] == true) {
                f = false;
            }
        }
        if (f) {
            break;
        }
        else {
            n++;
        }
    }
    cout << n << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    K = int(input())
    A, B = inpl()

    print("OK" if K * ((A + K - 1) // K) <= B else "NG")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
def resolve():
    h, w = map(int, input().split())
    L = []
    dx = [-1, -1, -1, 0, 0, 1, 1, 1]
    dy = [-1, 0, 1, -1, 1, -1, 0, 1]
    for i in range(h):
        L.append(list(input()))

    for i in range(h):
        for j in range(w):
            if L[i][j] == '#':
                pass
            else:
                count = 0
                for k in range(8):
                    x = i + dx[k]
                    y = j + dy[k]

                    if x < 0 or x > h - 1:
                        pass
                    elif y < 0 or y > w - 1:
                        pass
                    else:
                        if L[x][y] == "#":
                            count += 1
                L[i][j] = count

    for i in range(h):
        print(''.join(list(map(str, L[i]))))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
#include<numeric>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> tot(n+1, 0);

  rep (i, m) {
    int tmpa, tmpb;
    cin >> tmpa >> tmpb;
    tot[tmpa]++; tot[tmpb]++;
  }
  rep (i, n+1) {
    if (tot[i] % 2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 3796
H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            d = C[i][k] + C[k][j]
            if C[i][j] > d:
                C[i][j] = d

cost = [C[j][1] for j in range(10)]
ans = 0

for _ in range(H):
    for n in map(int, input().split()):
        if n == -1:
            continue
        ans += cost[n]
print(ans)

Measured memory_bytes: 40428
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int n,m,ans;
int p[100005],q[100005];
int main(void){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)p[i]=1;
    q[1]=1;
    for(int i=0;i<m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        if(q[x]){
            if(p[x]==1){
                q[x]=0;
                q[y]=1;
                p[y]++;
                p[x]=0;
            }else{
                p[x]--;
                p[y]++;
                q[y]=1;
            }
        }else{
            p[x]--;
            p[y]++;
        }
    }
    for(int i=1;i<=n;i++)if(q[i])ans++;
    printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const long long BASE1 = 1234567;
const long long BASE2 = 7654321;
const long long MOD = 1000000007;
int main(){
  vector<long long> pow1(26);
  pow1[0] = 1;
  for (int i = 0; i < 25; i++){
    pow1[i + 1] = pow1[i] * BASE1 % MOD;
  }
  vector<long long> pow2(26);
  pow2[0] = 1;
  for (int i = 0; i < 25; i++){
    pow2[i + 1] = pow2[i] * BASE2 % MOD;
  }
  string s1;
  cin >> s1;
  string s2;
  cin >> s2;
  int N = s1.size();
  int M = s2.size();
  int ans = 0;
  for (int i = 1; i <= min(N, M); i++){
    long long hash1 = 0, hash2 = 0;
    for (int j = 0; j < i; j++){
      hash1 += pow1[s1[j] - 'a'];
      hash1 %= MOD;
      hash2 += pow2[s1[j] - 'a'];
      hash2 %= MOD;
    }
    set<pair<long long, long long>> st;
    st.insert(make_pair(hash1, hash2));
    for (int j = 0; j < N - i; j++){
      hash1 += pow1[s1[i + j] - 'a'];
      hash1 -= pow1[s1[j] - 'a'];
      hash1 += MOD;
      hash1 %= MOD;
      hash2 += pow2[s1[i + j] - 'a'];
      hash2 -= pow2[s1[j] - 'a'];
      hash2 += MOD;
      hash2 %= MOD;
      st.insert(make_pair(hash1, hash2));
    }
    hash1 = 0;
    hash2 = 0;
    for (int j = 0; j < i; j++){
      hash1 += pow1[s2[j] - 'a'];
      hash1 %= MOD;
      hash2 += pow2[s2[j] - 'a'];
      hash2 %= MOD;
    }
    if (st.count(make_pair(hash1, hash2))){
      ans = i;
    }
    for (int j = 0; j < M - i; j++){
      hash1 += pow1[s2[i + j] - 'a'];
      hash1 -= pow1[s2[j] - 'a'];
      hash1 += MOD;
      hash1 %= MOD;
      hash2 += pow2[s2[i + j] - 'a'];
      hash2 -= pow2[s2[j] - 'a'];
      hash2 += MOD;
      hash2 %= MOD;
      if (st.count(make_pair(hash1, hash2))){
        ans = i;
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	string s;
	cin >> s;

	int result = 0;
	int len = (int)s.size();
	len -= (len & 1) ? 1 : 2;

	for( ; len > 0; len -= 2 ) {
		bool eq = true;

		for( int j = 0; j < len/2; ++j ) {
			if( s[j] != s[len/2 + j] ) {
				eq = false;
				break;
			}
		}

		if( eq ) {
			result = len;
			break;
		}
	}

	cout << result << endl;

	return 0;
}


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

int	main()
{
    string S;
    cin >> S;
    int size = S.size();
    int len;
    for (len = size - 2; len > 0; len -= 2) {
        bool is_feasible = true;
        for (int j = 0; j < len / 2; ++j) {
            if (S.at(j) != S.at(len / 2 + j)) {
                is_feasible = false;
                break;
            }
        }
        if (is_feasible)
            break;
    }
    cout << len << endl;
}


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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=1e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int n;

int main()
{
    read(n);
    puts(n>=30?"Yes":"No");
    return 0;
}

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


int main() {
    int N, M, j, a, count;
    cin >> N;
    cin >> M;
    
    vector <int> vec(N, 0);
    vector <int> zero(N, false);
    
    count = 0;
    
    
    if (!(M==0)){
    for (int i=0; i<M; i++){
        cin >> j;
        cin >> a;
        if (zero.at(j-1) == true && !(vec.at(j-1) == a)){
            cout << -1 << endl;
            break;
        }
        else if (zero.at(j-1) == true && vec.at(j-1)==a){
           vec.at(j-1)=a;
           zero.at(j-1) = true;
           count++;
        }
        else{
           vec.at(j-1)=a;
           zero.at(j-1) = true;
           count++;
        }
    }
    }
    
  if (count < M){
      
  }
  else {
  if (vec.size() == 1 &&vec.at(0)==0){
      cout << 0 << endl;
  }
  
  else if (M==0){
      if (N==1) cout << 0 << endl;
      else if (N==2) cout << 10 << endl;
      else if (N==3) cout << 100 << endl;
  }
  
  else if (vec.at(0)==0 && zero.at(0)==false){
      vec.at(0) = 1;
      for (int i=0; i<N; i++){
      cout << vec.at(i);
  }
  cout << endl;
      
  }
  
  else if (vec.at(0)==0){
      cout << -1 << endl;
  }
  else {
  for (int i=0; i<N; i++){
      cout << vec.at(i);
  }
  cout << endl;
  }
  }
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		D(sc);
	}
	
	public static void A(Scanner sc) {
		int N = sc.nextInt();
		int A = sc.nextInt();
		if(N%500 <=A) out.println("Yes");
		else out.println("No");
	}
	
	public static void B(Scanner sc) {
		int N = sc.nextInt();
		int ret = 0;
		Integer[] a = new Integer[N];
		for(int i=0;i<N;i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a,Collections.reverseOrder());
		for(int i=0;i<N;i++) {
			if(i%2==0) ret+=a[i];
			else ret-=a[i];
		}
		out.println(ret);
	}
	
	public static void C(Scanner sc) {
		int[][] c = new int[4][4];
		for(int i=1;i<4;i++) {
			for(int j=1;j<4;j++) {
				c[i][j] = sc.nextInt();
			}
		}
		if(c[1][1]-c[1][2]==c[2][1]-c[2][2] && c[2][1]-c[2][2]==c[3][1]-c[3][2] &&
				c[1][2]-c[1][3]==c[2][2]-c[2][3] && c[2][2]-c[2][3]==c[3][2]-c[3][3] &&
				c[1][1]-c[1][3]==c[2][1]-c[2][3] && c[2][1]-c[2][3]==c[3][1]-c[3][3]) out.println("Yes");
		else out.println("No");
	}
	
	public static void D(Scanner sc) {
		int h = sc.nextInt();
		int w = sc.nextInt();
		boolean cango[][] = new boolean[h][w];
		int firstblack = 0;
		for(int i=0;i<h;i++) {
			String s = sc.next();
			for(int j=0;j<w;j++) {
				if(s.charAt(j)=='.') cango[i][j]=true;
				else firstblack++;
			}
		}
		int dist = mindist(cango);
		if(dist<0) {
			out.println(dist);
			return;
		}
		out.println(h*w - (dist+1) - firstblack);
	}
	
	// 最短距離を返す cango:通ることができる   到達できない場合は、-1を返す
	public static int mindist(boolean[][] cango) {
		int h = cango.length;
		int w = cango[0].length;
		
		Point start = new Point(0,0,0);
		start.passlength = 0;
		
		boolean[][] visit = new boolean[h][w];
		visit[0][0] = true;
		
		LinkedList<Point>  que = new LinkedList<Point>();
		que.add(start);
		
		while(!que.isEmpty()) {
			Point p = que.removeFirst();
			for(Point np : p.makeneigh(h, w, visit, cango)) {
				if(np.i==h-1 && np.j==w-1) return np.passlength;
				visit[np.i][np.j] = true;
				que.add(np);
			}
		}
		return -1;
	}
	
	public static class Point{
		int i;
		int j;
		int passlength;
		
		public Point(int i, int j, int pl) {
			this.i = i;
			this.j = j;
			this.passlength = pl;
		}
		// Pointの周囲４マスについて、存在して、unvisitかつcangoなら作成して返す。
		public ArrayList<Point> makeneigh(int h, int w, boolean[][] visit, boolean[][] cango){
			ArrayList<Point> ret = new ArrayList<Point>();
			if(i-1>=0 && !visit[i-1][j] && cango[i-1][j]) ret.add(new Point(i-1,j,passlength+1));
			if(i+1<h && !visit[i+1][j] && cango[i+1][j]) ret.add(new Point(i+1,j,passlength+1));
			if(j-1>=0 && !visit[i][j-1] && cango[i][j-1]) ret.add(new Point(i,j-1,passlength+1));
			if(j+1<w && !visit[i][j+1] && cango[i][j+1]) ret.add(new Point(i,j+1,passlength+1));
			return ret;
		}

	}
}


Measured memory_bytes: 23124
X=input()
Y=int(X)
if Y<=99:
    print(0)

else:
    a=10*int(X[-2])+int(X[-1])
    b=a//5
    if a%5!=0:
        b+=1
    if b>Y//100:
        print(0)
    else:
        print(1)

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

int a[5][105];

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  for (int i = 1; i <= 2; i++)
  for (int j = 1; j <= n; j++) {
    cin >> a[i][j];
    a[i][j] += max(a[i - 1][j], a[i][j - 1]);
  }
  cout << a[2][n] << '\n';
}


Measured memory_bytes: 3568
using System;

namespace AOJ.ITP
{
    public class Print_A_Chessboard
    {
        public static void Main()
        {
            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                int h = int.Parse(input[0]);
                int w = int.Parse(input[1]);
                if (h <= 0 || w <= 0) { break; }

                // 偶数行と奇数行の文字列を作成
                string odd = "";
                string even = "";
                for (int i = 0; i < w; i++)
                {
                    if (i % 2 == 0)
                    {
                        odd += "#";
                        even += ".";
                    }
                    else
                    {
                        odd += ".";
                        even += "#";
                    }
                }

                for (int i = 1; i <= h; i++)
                {
                    if (i % 2 == 0) { Console.WriteLine(even); }
                    else { Console.WriteLine(odd); }
                }

                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 19712
import sys

sys.setrecursionlimit(2 * 10 ** 5 + 5)


def dfs(v, p, links):
    farthest_d = 0
    farthest_v = v

    for u in links[v]:
        if u == p:
            continue
        res_d, res_v = dfs(u, v, links)
        if res_d > farthest_d:
            farthest_d = res_d
            farthest_v = res_v
    return farthest_d + 1, farthest_v


def solve(n, links):
    if n == 1:
        return True

    d, v = dfs(0, -1, links)
    d, v = dfs(v, -1, links)
    if (d + 1) % 3 == 0:
        return False
    return True


n = int(input())
links = [set() for _ in [0] * n]
for line in sys.stdin:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
print('First' if solve(n, links) else 'Second')


Measured memory_bytes: 255892
#include<bits/stdc++.h>
#define ms(x) memset(x,0,sizeof(x))
#define sws ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=1e9+7;
inline ll read()
{
    register ll now = 0;
    register char ch = getchar();
    register bool sign = false;
    while (!isdigit(ch)) {
        if (ch == '-') sign = true;
        ch = getchar();
    }
    while (isdigit(ch)) {
        now = (now << 1) + (now << 3) + ch - '0';
        ch = getchar();
    }
    return (sign == true ? -now : now);
}
inline unsigned long long get_hash()
{
    register unsigned long long ret = 1;
    register char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) {
        ret = (ret * 31 + ch);
        ch = getchar();
    }
    return ret;
}
int a[maxn];
int bit[22];
bool expend(int x){
	for(int i=0;i<=21;i++)if(x&(1<<i)){
		 if(bit[i]) return false;
	}
	for(int i=0;i<=21;i++) if(x&(1<<i)) bit[i]=1;
	return true;
}
void del(int x){
	for(int i=0;i<=21;i++)if(x&(1<<i)){
		 bit[i]=0;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	ll l=1,r=1;
	ll ans=0;
	while(l<=r&&r<=n){
		while(r<=n&&expend(a[r])) r++;
		if(r>n) {
			ans+=1ll*(r-l)*(r-l+1)/2;
			break;
		}
		ans+=r-l;
	    del(a[l]);
	    l++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
struct data
{
    int a;
    int b;
    int c;
    int d;
};
data mark[110000];
priority_queue<pair<int,int >  > PQ;

int main()
{
    int n,a,b,c,d,m;
   scanf("%d%d",&n,&m);
   int mn=10000000;
    for(int i=0; i<n; i++)
    {
        scanf("%d%d",&a,&b);
        if(b<=m)
        {
            if(a<mn)
                mn=a;
        }
    }
    if(mn==10000000)
    {
        cout<<"TLE"<<endl;
    }
    else
        cout<<mn<<endl;

}


Measured memory_bytes: 256
li = list(map(int, input().split())) 
L = li[0]
R = li[1]
d = li[2]

#print(L)
#print(R)
#print(d)

count = 0

for X in range (L,R+1):
 if X % d == 0:
  count = count + 1
 else:
  pass

print(count)

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;

ll dp[101][100001];

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

    cout << dp[n][w];

    return 0;
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;GG(e<0);
        while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    int a[N],b[N];
    void main()
    {
        int n=qread();fo(i,1,n) a[i]=b[i]=qread();sort(b+1,b+n+1);
        int ans=0;fo(i,1,n) ans+=(lower_bound(b+1,b+n+1,a[i])-b-i)%2!=0;
        GG(ans&1) write(ans/2);
    }
};//(ans+MOD)%MOD
int main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	string s;
	int n;
	cin >> n >> s;
	bool ok = true;
	if (n % 2 != 0) ok = false;
	rep (i, n / 2) {
		if (s[i] != s[i + n / 2]) ok = false;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<ll, int> ll_i;

int main() {
    ll N, K;
    cin >> N >> K;
    ll x[N];
    for (int i = 0; i < N; ++i){
        cin >> x[i];
    }
    ll ans = 300000000;
    ll left = 0;
    while(left < N - K + 1){
        ll right = left + K - 1;
        ll tmp = min(abs(x[left])+abs(x[left]-x[right]), abs(x[right])+abs(x[right]-x[left]));
        ans = min(ans, tmp);
        left++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
use strict;
use warnings;
use 5.010;

use Data::Dumper;

chomp(my $n = <STDIN>);
chomp(my $line = <STDIN>);
my @x = split / /, $line;
my @idx = sort { $x[$b] <=> $x[$a] } 0..$#x;
# say "@idx";
my @y = sort { $a <=> $b } @x;

my @ans;
for (0..$#y) {
    if ($_ >= $n / 2) {
        $ans[$idx[$_]] = @y[$n / 2];
    }
    else {
        $ans[$idx[$_]] = @y[$n / 2 - 1];
    }
}

say(join("\n", @ans));



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

// Optimization

//#pragma GCC optimize("O3")
// #define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 1e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e18 + 7;
const ll infll = 1e18 + 7;

int k;
int ans;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> k;
    if (k == 2) Ptest(1);
    for (int i = 2; i * i <= k; i++){
        int x = k;
        while (x % i == 0) x /= i;
        if (x % i == 1) ans++;
    }
    k--;
    for (int i = 1; i * i < k; i++){
        if (k % i == 0) ans++;
    }
    cout << ans + 1;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    int n, k;
    cin >> n >> k;
    priority_queue<int> price;

    rep(i,n) {
        int input;
        cin >> input;
        price.push(-1 *input);
    }

    int ans = 0;
    rep(i,k) {
        ans += price.top();
        price.pop();
    }

    cout << -1 * ans << endl;
  return 0;
}

Measured memory_bytes: 3640
a,b,c,x=map(int,open(0).read().split())

total=0
for a_ in range(0,a+1):
  for b_ in range(0,b+1):
    for c_ in range(0,c+1):
      if 500*a_+b_*100+c_*50 == x:
        total+=1
        break
print(total)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int[][] dp = new int[S.length()+1][13];
    for (int i = 1; i <= S.length(); i++) {
      char c  = S.charAt(i-1);
      for (int j = 0; j < 13; j++) {
        if (i > 1 && dp[i-1][j] == 0) {
          // skip
          continue;
        }
        
        if (c == '?') {
          for (int k = 0; k <= 9; k++) {
            int val = k;
            if (dp[i-1][j] > 0) {
              val += 10*j;
              dp[i][val%13] += dp[i-1][j];
            } else {
              dp[i][val%13] = 1;
            }
            dp[i][val%13] %= 1_000_000_007;
          }
        } else {
          int val = c - '0';
          if (dp[i-1][j] > 0) {
            val += 10*j;
            dp[i][val%13] += dp[i-1][j];
          } else {
            dp[i][val%13] = 1;
          }
          dp[i][val%13] %= 1_000_000_007;
        }
      }
    }
    //System.out.println(Arrays.deepToString(dp));
    System.out.println(dp[S.length()][5]);
  }
}

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

int main(void){
    int n ; cin >> n;
    vector<ll>v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    sort(v.begin(),v.end());
    double ave=v[0];
    for(int i=0;i<n;i++){
        ave = (ave+double(v[i]))/2;
    }
    cout << ave << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
typedef long long ll;
ll a[1005],b[1005],n;
ll max(ll a,ll b)
{
	return (a>=b)? a:b;
}
int main()
{
 	scanf("%lld",&n);
 	ll c,d;
 	for(int i=1;i<=n;i++)
 	{
 	scanf("%d%d",&a[i],&b[i]);
 	if(i==1)
 	c=a[1],d=b[1];
  if(i>=2)
  {
  	ll p=(c+a[i]-1)/a[i];
  	ll q=(d+b[i]-1)/b[i];
  	ll z=max(p,q);
  	c=z*a[i];
  	d=z*b[i];
  }
	
} 
 printf("%lld\n",c+d);
 return 0;	
	
}

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



int main() {
	string str;
	cin >> str;
	
	int max = 0;
	int s = 0;
	int l = str.length();
	for (int i = 0; i < l; i++) {
		if (str[i] == 'A') {
			int aa=str.rfind('Z')-i+1;
			if (max < aa) {
				max = aa;
			}
		}
	}
	cout << max;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    signed int K, X;
    cin >> K >> X;
    for (signed int i = X - K + 1; i <= X + K - 1; i++)
    {
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define in insert
#define er erase
#define ct count
#define ep empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-6;
const double pi = acos(-1.0);
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2,mod); }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }


signed main() {
    //ifstream cin("E:\\acm dream\\in.in");
	//ofstream cout("E:\\acm dream\\out.out");
	FIO;
    #ifdef err
	double be = clock();
    #endif

    int k;cin>>k;
    int T=k,r=0,f=0;
    while(T--){
        r*=10,r+=7;
        r%=k;
        if(!r){
            f=1;
            break;
        }
    }
    if(f)cout<<k-T;
    else cout<<-1;
    
    #ifdef err
	double en = clock();
    cout<<"time: "<<fixed<<setprecision(8)<<en-be;
    #endif
	return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
 
int main()
{
 
    LL N,D,parson,i,range;
 
    scanf("%lld %lld",&N,&D);
 	
  	parson=1;
  	range=2*D+1;
  	while(N-range>0){
      N-=range;
      parson++;
    }
  
    printf("%lld", parson);
 	
  	return 0;
  
}

Measured memory_bytes: 128
#include <iostream>

int main() {
  int n, m;
  std::cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int val;
    std::cin >> val;
    n -= val;
  }
  if (n < 0) n = -1;
  std::cout << n << std::endl;
  return 0;
}


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

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

    int n, m;
    cin >> n >> m;
    vector<int> A(m);
    for(int i = 0; i < m; i++){
        cin >> A[i];
    }

    int total = 0;
    for(int i = 0; i < m; i++){
        total += A[i];
    }

    n -= total;

    if(n < 0){
        cout << -1 << endl;
    }else{
        cout << n << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;


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

    ll d = c - a - b;
    if (4 * a * b < d * d && d > 0) yn
    return 0;
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long double r;cin >> r;
    cout << fixed << setprecision(10);
    cout << 2*r*3.1415926535 << endl;
    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < N; i++) a[i]--;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (a[a[i]] == i) {
            a[a[i]] = -2;
            a[i] = -1;
            cnt++;
        }
    }
    cout << cnt << '\n';
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,r,d,f[13][30];
bool ans(int x=m);
int main(){
  while(cin >>n,n){
    cin >>m>>r>>d;
    for(int i=0; i<13; i++) for(int j=0; j<30; j++) f[i][j] = 0;
    for(int i=0; i<d; i++) for(int j=0; j<n-1; j++) scanf("%1d",&f[j+1][i]);
    if(ans()){cout <<"0"<<endl;goto jump;}
    for(int i=0; i<d; i++){
      for(int j=1; j<n; j++){
	if(f[j][i] == 0 && f[j-1][i] == 0 && f[j+1][i] == 0){
	  f[j][i] = 1;
	  if(ans()){cout <<i+1<<" "<<j<<endl;goto jump;}
	  f[j][i] = 0;
	}
      }
    }
    cout <<"1"<<endl;
  jump:;
  }
  return 0;
}
bool ans(int x){
  for(int i=0; i<d; i++){
    if(f[x-1][i] == 1) x--;
    else if(f[x][i] == 1) x++;
  }
  return x == r;
}

Measured memory_bytes: 1244
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

int func(vector<set<pair<int, int>>>xs, vector<set<pair<int, int>>>ys, vector<int>&x, vector<int>&y, vector<char>&c, int st) {
	int cx = x[st], cy = y[st];
	int ret = 1;
	xs[cx].erase(xs[cx].lower_bound({ cy,0 }));
	ys[cy].erase(ys[cy].lower_bound({ cx,0 }));
	char nx = c[st];
	while (ret < N) {
		if (nx == '^') {
			auto it = xs[cx].lower_bound({ cy,0 });
			if (xs[cx].begin() == it)break;
			it = prev(it);
			ret++;
			cy = it->first;
			nx = c[it->second];
		}
		else if (nx == '<') {
			auto it = ys[cy].lower_bound({ cx,0 });
			if (ys[cy].begin() == it)break;
			it = prev(it);
			ret++;
			cx = it->first;
			nx = c[it->second];
		}
		else if (nx == 'v') {
			auto it = xs[cx].lower_bound({ cy,0 });
			if (xs[cx].end() == it)break;
			ret++;
			cy = it->first;
			nx = c[it->second];
		}
		else {
			auto it = ys[cy].lower_bound({ cx,0 });
			if (ys[cy].end() == it)break;
			ret++;
			cx = it->first;
			nx = c[it->second];
		}
		xs[cx].erase(xs[cx].lower_bound({ cy,0 }));
		ys[cy].erase(ys[cy].lower_bound({ cx,0 }));
	}
	return ret;
}

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

	cin >> N;
	vector<int>x(N);
	vector<int>y(N);
	vector<char>c(N);
	map<int, int>xp;
	map<int, int>yp;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> c[i];
		xp[x[i]] = 0;
		yp[y[i]] = 0;
	}
	int cnt = 0;
	for (auto &i : xp) {
		i.second = cnt++;
	}
	cnt = 0;
	for (auto &i : yp) {
		i.second = cnt++;
	}
	vector<set<pair<int, int>>>xx(xp.size());
	vector<set<pair<int, int>>>yy(yp.size());
	for (int i = 0; i < N; i++) {
		x[i] = xp[x[i]];
		y[i] = yp[y[i]];
		xx[x[i]].insert({ y[i],i });
		yy[y[i]].insert({ x[i],i });
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans = max(ans, func(xx, yy, x, y, c, i));
	//	cout << i << " " << ans << endl;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3908
import sys
stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, K = rl()
R, S, P = rl()
T = list(rs())
dict = {'r': P, 's': R, 'p': S}
def count(X):
    ret = 0
    cur = None
    for a in X:
        if a != cur:
            ret += dict[a]
            cur = a
        else:
            cur = None
    
    return ret

answer = 0
for i in range(1, K+1):
    x = T[i-1::K]
    answer += count(x)

print(answer)


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

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

using namespace std;
using lint=long long;

int main(){
	int n;
	lint a,b,h[100000]; cin>>n>>a>>b;
	rep(i,n) cin>>h[i];

	lint lo=0,hi=1e9;
	while(hi-lo>1){
		lint mi=(lo+hi)/2;
		lint cnt=0;
		rep(i,n) cnt+=(max(h[i]-b*mi,0LL)+a-b-1)/(a-b);
		if(mi>=cnt) hi=mi;
		else        lo=mi;
	}
	cout<<hi<<endl;

	return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>

#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589

using namespace std;
       
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
       
/* 
const ll MAX_MEM = 25e7;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
       
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
       
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
       
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
       
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
       
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("circlecover.in", "r", stdin);
    //freopen("circlecover.out", "w", stdout);
}

int n, m;
vector <vector <char>> c;
queue <pii> q;
vector <vector <int>> d;
vector <int> dx=  {1, 0, -1, 0}, dy = {0, 1, 0, -1};
bool check(int i, int j)
{
    if (i < 0 || j < 0 || i >= n || j >= m)
        return false;
    if (c[i][j] == '#')
        return false;
    return true;
}
const int INF = 1e9;
int bfs(int xs, int ys)
{
    q.emplace(xs, ys);
    int ans = 0;
    d.assign(n, vector <int> (m, INF));
    d[xs][ys] = 0;
    while (!q.empty())
    {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int t = 0; t < 4; ++t)
        {   
            int i = x + dx[t], j = y + dy[t];
            if (check(i, j) && d[i][j] > d[x][y] + 1)
            {
                d[i][j] = d[x][y] + 1;
                ans = max(ans, d[i][j]);
                q.emplace(i, j);
            }
        }
    }
    return ans;
}

signed main()
{
    Start();
    cin >> n >> m;
    c.assign(n, vector <char> (m));
    cin >> c;
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if (c[i][j] == '.')
                ans = max(ans, bfs(i, j));
        }
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long int
#define Max(x, y) (x > y ? x : y)
#define Min(x, y) (x < y ? x : y)
#define Abs(x) ( (x) > 0 ? (x) : -(x) )
#define Swap(x,y) do{x = x ^ y; y = x ^ y; x = x ^ y;}while(0)
#define IO_BOOST                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0)
#define setp(x) fixed << setprecision(x)
#define INF 0x3f3f3f3f
#define Lowbit(x) ((x) & (-x))
#define Pii pair<int, int>
#define x first
#define y second
#define MOD ((int)1e9+7)
using namespace std;

struct Node{
    int a, b, c;
};
Node a[(int)2e5+5];
int dp[(int)2e5+5][3] = {0};
int n, k;
void solve(){
    
    for(int i = 1 ; i <= n ; i++){
        dp[i][0] = Max( dp[i-1][1], dp[i-1][2] ) + a[i].a;
        dp[i][1] = Max( dp[i-1][0], dp[i-1][2] ) + a[i].b;
        dp[i][2] = Max( dp[i-1][0], dp[i-1][1] ) + a[i].c;
    }
    cout << *max_element(dp[n], dp[n]+3) << '\n';

}
int main(){
    IO_BOOST;
    cin >> n;
    for(int i = 1 ; i <= n ; i++)
        cin >> a[i].a >> a[i].b >> a[i].c;
    solve();

}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int n , m ;
	cin >> n >> m ;
	string s[n] ;
	for(int i = 0 ; i < n ; i++)
		cin >> s[i] ;
	ll dp[n + 1][m + 1] ;
	memset(dp , 0 , sizeof(dp)) ;
	for(int i = 0 ; i < m ; i++){
		if(s[0][i] == '#')
			break ;
		dp[0][i] = 1 ;
	}
	for(int i = 0 ; i < n ; i++){
		if(s[i][0] == '#')
			break ;
		dp[i][0] = 1 ;
	}
	dp[0][0] = 1 ;
	for(int i = 1 ; i < n ; i++){
		for(int j = 1 ; j < m ; j++){
			if(s[i -1 ][j] == '.'){
				dp[i][j] += dp[i - 1][j] ;
				dp[i][j]%=mod ;
			}
			if(s[i][j - 1] == '.'){
				dp[i][j] += dp[i][j - 1] ;
				dp[i][j]%=mod ;
			}
		}
	}
	cout<< dp[n - 1][m - 1] ;
}

Measured memory_bytes: 9088
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n, m) for (int i = m; i < (n); i++)
typedef long long ll;

using namespace std;

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

  int ans = -1;
  rep2(i, 1001, 1) {
    int ax = i * 8 / 100;
    int bx = i * 10 / 100;
    if (a == ax && b == bx) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
}


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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> c;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    ll a=0,p=0;
    for(int i=N-1;i>0;--i) {
        int c = 1;
        for(int j=i-1;j>0;--j) {
            if(A[i] != A[j]) break;
            ++c;
        }
        if(c>=4) {
            cout << (ll)A[i]*A[i] << endl;
            return 0;
        }
        else if(c>=2) {
            a = A[i];
            p = i-c;
            break;
        }
    }
    if(!a) {
        cout << 0 << endl;
        return 0;
    }
    ll b=0;
    for(int i=p;i>0;--i) {
        if(A[i] == A[i-1]){
            b = A[i];
            break;
        }
    }
    if(!b) {
        cout << 0 << endl;
        return 0;
    }
    cout << a*b << endl;
    
}


Measured memory_bytes: 640
from collections import deque
k = int(input())
num = deque()
for i in range(1,10):
    num.append(i)
while True:
    l = len(num)
    if l >= k:
        print(num[k-1])
        exit()
    else:
        k -= l
        for i in range(l):
            left = num.popleft()
            last = left%10
            add1,add2,add3 = 10*left+last-1,10*left+last,10*left+last+1
            if 0 < last < 9:
                num.append(add1)
                num.append(add2)
                num.append(add3)
            elif last == 0:
                num.append(add2)
                num.append(add3)
            else:
                num.append(add1)
                num.append(add2)


Measured memory_bytes: 9324