akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
const int maxs = 200100;
const int mod = 1000000007;
char t[maxn], d[maxn];
int main(){
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  for(int i = 0; i < q; i++) cin >> t[i] >> d[i];
  int tot = 0;
  int lo = 0, hi = n - 1, ans = -1;
  while(lo <= hi){
    int mid = (lo + hi)/2;
    int pv = mid;
    for(int i = 0; i < q && pv > - 1 && pv < n; i++) if(s[pv] == t[i]) {
      if(d[i] == 'L') pv--;
      else pv++;
    }
    if(pv < 0) ans = mid, lo = mid + 1;
    else hi = mid - 1;
  }
  tot += ans + 1;
  lo = 0, hi = n - 1, ans = -1;
  while(lo <= hi){
    int mid = (lo + hi)/2;
    int pv = mid;
    for(int i = 0; i < q && pv > - 1 && pv < n; i++) if(s[pv] == t[i]) {
      if(d[i] == 'L') pv--;
      else pv++;
    }
    if(pv >= n) ans = mid, hi = mid - 1;
    else lo = mid + 1;
  }
  if(ans != -1) tot += n - ans;
  cout << n - tot << endl;
  return 0;
}


Measured memory_bytes: 1028
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {

	public static void main(String[] args)throws Exception {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader (is);
		int num = Integer.parseInt(br.readLine());
		int []intGroup = new int[3*num];
		String []group = br.readLine().split(" ");
		int j = 0;
		for(String s: group) {
			intGroup[j] = Integer.parseInt(s);
			j++;
		}
		Arrays.sort(intGroup);
		int len = intGroup.length-2;
		long result = 0;
		for(int i = 0;i<num;i++) {
			result += intGroup[len];
			len -=2;
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 67412
S = input()
K = int(input())

D=5000000000000000

tmp=0
for s in S:
  if s=='1':
    tmp+=1
    if tmp>=K:
      print(s)
      break
    continue
    
  t=1
  for _ in range(D):
    t=t*int(s)
    if tmp+t>=K:
      print(s)
      break
  else:
    tmp+=t
    continue
  break

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

def count_letter(A,B):
  score=0
  for i in range(len(A)):
    if A[i]==B[i]:
      score+=1
  return score

count_max=0
for i in range(len(S)-len(T)+1):
  count_max=max(count_max,count_letter(S[i:i+len(T)],T))
print(len(T)-count_max)

Measured memory_bytes: 9004
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>

using namespace std;
using ll = long long;

constexpr ll INF = 1LL << 60;

ll scanll(){
    ll ret = 0;
    for(char c = getchar_unlocked(); isdigit(c); c = getchar_unlocked()){
        ret = 10 * ret + c - '0';
    }
    return ret;
}

void putll(ll x){
    if(x == 0){
        putchar_unlocked('0');
        return;
    }

    if(x < 0){
        putchar_unlocked('-');
        x = -x;
    }

    ll digits = 1;
    for(ll y = x; y /= 10; digits++);

    ll r = x % 10;
    for(x /= 10; x; r = 10 * r + x % 10, x /= 10);

    for(; r; r /= 10, digits--){
        putchar_unlocked(r % 10 + '0');
    }
    for(; digits; digits--){
        putchar_unlocked('0');
    }
}

ll f(ll b, ll n){
    ll ret = 0;
    for(; n; n /= b) ret += n % b;
    return ret;
}

ll divisors[1000000];
ll make_divisors(ll d){
    ll i = 1;
    ll j = 0;
    for(ll sq = sqrt(d); i <= sq; i++){
        if(d % i) continue;
        divisors[j++] = i + 1;
        divisors[j++] = d / i + 1;
    }

    sort(divisors, divisors + j);
    return j;
}

int main(){
    ll n = scanll();
    ll s = scanll();
    ll d = n - s;

    if(d < 0) putll(-1);
    else if(d == 0) putll(n + 1);
    else{
        make_divisors(d);

        for(const auto b : divisors){
            if(b <= 1) break;
            if(f(b, n) == s){
                putll(b);
                return 0;
            }
        }
        putll(-1);
    }

    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

ans = 10 ** 10
for i in range(h):
    x = (i + 1) * w
    mid = (h - i - 1) // 2
    y = mid * w
    z = (h - i - 1 - mid) * w
    ans = min(ans, max(x, y, z) - min(x, y, z))

    mid = w // 2
    y = (h - i - 1) * mid
    z = (h - i - 1) * (w - mid)
    ans = min(ans, max(x, y, z) - min(x, y, z))

for j in range(w):
    x = (j + 1) * h
    mid = (w - j - 1) // 2
    y = mid * h
    z = (w - j - 1 - mid) * h
    ans = min(ans, max(x, y, z) - min(x, y, z))

    mid = h // 2
    y = (w - j - 1) * mid
    z = (w - j - 1) * (h - mid)
    ans = min(ans, max(x, y, z) - min(x, y, z))

print(ans)


Measured memory_bytes: 3064
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
  if i == 0 and A[i] <= x:
    continue
  elif i == 0 and A[i] > x:
    ans += (A[i]-x)
    A[i] = x
    continue
  else:
    if A[i] + A[i-1] <= x:
      continue
    else:
      ans += (A[i]+A[i-1]-x)
      A[i] = x-A[i-1]
print(ans)

Measured memory_bytes: 14132
import std.algorithm,
       std.string,
       std.range,
       std.array,
       std.stdio,
       std.conv;

void main() {
  ulong n = readln.chomp.to!ulong;
  ulong[] a = readln.chomp.split.to!(ulong[]);

  ulong[] odds,
          evens;

  foreach (idx, elem; a) {
    if (idx % 2 == 0) {
      evens ~= elem;
    } else {
      odds ~= elem;
    }
  }

  if (n % 2 != 0) {
    std.algorithm.reverse(evens);
    foreach (elem; evens) { writef("%d ", elem); }
    foreach (elem; odds)  { writef("%d ", elem); }
  } else {
    std.algorithm.reverse(odds);
    foreach (elem; odds)  { writef("%d ", elem); }
    foreach (elem; evens) { writef("%d ", elem); }
  }
  writeln;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

template <typename T>
struct BIT{
private:
  vector<T> v;
  const int n;

public:
  BIT(int sz) : v(sz+1,0), n(sz){}

  T sum(int i){
    i++;
    T s=0;
    while(i>0){
      s+=v[i];
      i-=i&-i;
    }
    return s;
  }

  void add(int i,T x){
    i++;
    while(i<=n){
      v[i]+=x;
      i+=i&-i;
    }
  }
};

int main(){
  LL n,k;
  cin >> n >> k;
  vector<LL> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    a[i]-=k;
  }
  vector<LL> r(n+1,0);
  for(int i=0;i<n;i++) r[i+1]=r[i]+a[i];
  map<LL,int> mp;
  for(int i=0;i<=n;i++) mp[r[i]]=0;
  int c=0;
  for(auto &p:mp){
    p.second=c;
    c++;
  }
  LL ans=0;
  BIT<int> b(mp.size());
  for(int i=0;i<=n;i++){
    ans+=b.sum(mp.lower_bound(r[i])->second);
    b.add(mp[r[i]],1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16640
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for (i=0;i<VMAX+1;i++) C[i] = 0;

  for (i=0;i<n;i++){
    scanf("%hu",&A[i + 1]);
    C[A[i+1]]++;
  }

  for (i=1;i<VMAX+1;i++) C[i] = C[i] + C[i - 1];

  for (j =1;j<n+1;j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for (i=1;i<n+1;i++){
    if (i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 8464
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL
	#define debug(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(...) 42
#endif

#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define mem(x,val) memset(x,val,sizeof x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

inline string getString(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string getLine(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
typedef long long ll;

const int S=100100;
int main()
{
	int k;
	while(~sf("%d",&k))
	{
		int rem=0;
		int x=-1;
		for(int i=0;i<=k+1;i++)
		{
			rem=(rem*10)+7;
			rem%=k;
			if(rem==0)
			{
				x=i+1;
				break;
			}
		}
		pf("%d\n",x);
	}
    return 0;
}



































Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int k;
    cin >> k;
    vector<int> a(50);
    if(k == 0){
        cout << 2 << endl;
        cout << "1 1" << endl;
        return 0;
    }
    if(k == 1){
        cout << 3 << endl;
        cout << "1 0 3" << endl;
        return 0;
    }
    if(k <= 50){
        cout << k << endl;
        rep(i, 0, k){
            if(i != 0) cout << " ";
            cout << i + 1;
        }
        cout << endl;
        return 0;
    }
    rep(i, 0, 50){
        a[50 - 1 - i] = 50 - 1 - i + 1 + (k - (i + 1)) / (int)50;
    }
    cout << 50 << endl;
    rep(i, 0, 50){
        if(i != 0) cout << " ";
        cout << a[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M, C, answer = 0, cnt = 0;
    cin >> N >> M >> C;

    int B[M];
    int A[N][M];

    for (int i = 0; i < M; i++)
    {
        cin >> B[i];
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M; j++)
        {
            cnt += A[i][j] * B[j];
        }
        cnt += C;

        if (cnt > 0)
        {
            answer++;
        }
        cnt = 0;
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
import math
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        d = 0
        for k in range(2):
            d+= (xy[i][k]-xy[j][k])**2
        ans += math.sqrt(d)
print(ans*2/n)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// nCr mod を計算する O(n)
const int MAX_N = 1000010;
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    int X,Y;
    cin>>X>>Y;
    if(2*Y-X<0 || (2*Y-X)%3!=0){
        cout<<0<<endl;
        return 0;
    }

    if(2*X-Y<0 || (2*X-Y)%3!=0){
        cout<<0<<endl;
        return 0;
    }

    int a=(2*Y-X)/3;
    int b=(2*X-Y)/3;

    COMinit();
    cout<<COM(a+b,a)<<endl;

}


Measured memory_bytes: 23680
n,t=map(int,input().split())
c=[list(map(int,input().split())) for i in range(n)]
c=sorted(c)

d=[]
for i in range(n):
    w=c[i]
    if c[i][1]<=t:
        d.append(w)

if not d:
    print("TLE")
else:
    print(d[0][0])

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

int main(){
  int h,w;
  string s[110];
  cin>>h>>w;
  for(int i=0;i<h;i++) cin>>s[i];
  for(int i=0;i<h;i++) {
    if(i!=0) cout<<endl;
    cout<<s[i]<<endl<<s[i];
  }



}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [input().split() for m in range(n)]
ans = 0
cnt = 0
for i in range(n):
    for j in range(m):
        cnt += int(a[i][j])*b[j]
    if cnt+c > 0:ans+=1
    cnt = 0
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
#define inf 0x7fffffff
/*------------------------------------------------------------*/
int a[maxn];
int main(){
	int n,m;
	in2(n,m);
	int k=0;
	FOR(i,1,n){
		int c;
		in2(c,a[i]);
		k=max(c,k);
	}
	sort(a+1,a+n+1);
	int ans=0;
	FORD(i,n,1){
		if(a[i]<=k)break;
		m-=a[i];ans++;
		if(m<=0){
			out(ans);
			return 0;
		}
	}
	out(ans+m/k+(m%k!=0)); 
		
}

Measured memory_bytes: 640
#include <cstdio>

int main()
{
    int n, ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int l, r;
        scanf("%d%d", &l, &r);
        ans += (r - l + 1);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int d[100010];
inline int up(int x,int y){return x%y==0?x/y:x/y+1;}
inline int max(int a,int b){return a>b?a:b;}
int main(){
	int n,m,l,r,i,nex;
	scanf("%d%d",&n,&m);
	while(n--){
		scanf("%d%d",&l,&r);
		d[1]++;
		d[r-l+2]--;
		for(i=r-l+2;i<=r;i=nex+1){
			nex=r/(r/i);
			d[max(up(l,r/i),r-l+2)]++;
			d[nex+1]--;
		}
	}
	for(i=1;i<=m;i++)d[i]+=d[i-1];
	for(i=1;i<=m;i++)printf("%d\n",d[i]);
}

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

using namespace std;

int64_t dfs(int64_t n){
    int64_t res = n;
    int64_t b = 10;
    int64_t i = 0;
    while(b <= n){
        res += n / b * (1 << i++);
        res += dfs(n % b);
        b *= 10;
    }

    return res;

}

int main(){
    string S;
    cin >> S;
    cout << dfs(stoll(S)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    int n, x;
    while(true){
        scanf("%d %d\n", &n, &x);
        if(n == 0 && x == 0) break;
        int cnt = 0;
        for(int i = n; i > x / 3; i--){
            for(int j = i - 1; j > (x-i)/2; j--){
                if(x - (i + j) > 0) cnt++;
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}


Measured memory_bytes: 3192
use proconio::{fastout, input};

use std::collections::HashSet;

#[fastout]
fn main() {
    input! {
        (x, n): (isize, usize),
        ps: [isize; n]
    };

    let mut hash = HashSet::new();

    for p in ps {
        hash.insert(p);
    }

    for i in 0.. {
        let y = x - i;
        if !hash.contains(&y) {
            println!("{}", y);
            return;
        }

        let y = x + i;
        if !hash.contains(&y) {
            println!("{}", y);
            return;
        }
    }
}


Measured memory_bytes: 2212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn =2e3+5;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	int n=s.size();
	if(s[n-1]=='0'||s[n-1]=='1'||s[n-1]=='6'||s[n-1]=='8')
    {
        cout<<"pon"<<'\n';
    }
    else if(s[n-1]=='3')
    {
        cout<<"bon"<<'\n';
    }
    else
        cout<<"hon"<<'\n';




}



Measured memory_bytes: 3612
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CEnergyDrinkCollector solver = new CEnergyDrinkCollector();
        solver.solve(1, in, out);
        out.close();
    }

    static class CEnergyDrinkCollector {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            List<Pair<Long, Long>> stores = new ArrayList<>();

            for (int i = 0; i < n; i++) {
                long a = in.nextInt();
                long b = in.nextInt();
                stores.add(new Pair<>(a, b));
            }

            stores.sort(Comparator.comparingLong(a -> a.fs));

            long cur = 0;
            long cost = 0;
            for (int i = 0; i < n; i++) {
                if (cur >= m) {
                    break;
                }

                long max = m - cur;
                long take = Math.min(stores.get(i).sc, max);
                cur += take;
                cost += take * stores.get(i).fs;
            }
            out.println(cost);
        }
    }

    static class Pair<T, K> {

        T fs;
        K sc;

        public Pair(T fs, K sc) {
            this.fs = fs;
            this.sc = sc;
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}



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

signed main() {
  int n;
  cin>>n;
  int p[n];
  for(int i=0;i<n;i++)cin>>p[i];
  int ans=0;
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> v;
  vector<pair<int,int>> l[n],r[n],at;
  int lx[n],rx[n];
  for(int i=0;i<n;i++){lx[i]=-1;rx[i]=n;}
  for(int i=0;i<n;i++){
    while(!v.empty()&&v.top().first<p[i]){
      l[i].push_back(v.top());
      rx[v.top().second]=i;
      v.pop();
    }
    v.push(make_pair(p[i],i));
  }
  while(!v.empty())v.pop();
  for(int i=n-1;i>=0;i--){
    while(!v.empty()&&v.top().first<p[i]){
      r[i].push_back(v.top());
      lx[v.top().second]=i;
      v.pop();
    }
    v.push(make_pair(p[i],i));
  }
  int a,b;
  for(int i=0;i<n;i++){
    l[i].push_back(make_pair(0,lx[i]));
    r[i].push_back(make_pair(0,rx[i]));
  }
 
  for(int i=0;i<n;i++){
    a=l[i].size()-2;b=r[i].size()-2;
    while(a>=0||b>=0){
      //cerr<<ans<<' '<<a<<' '<<b<<endl;
      if(a<0){
        ans-=(l[i][a+1].second-i)*(r[i][b+1].second-r[i][b].second)*r[i][b].first;
         b--;
         continue;
      }
      if(b<0){
        ans-=(l[i][a+1].second-l[i][a].second)*(r[i][b+1].second-i)*l[i][a].first;
        a--;
        continue;
      }
      if(l[i][a].first>r[i][b].first){
        ans-=(l[i][a+1].second-l[i][a].second)*(r[i][b+1].second-i)*l[i][a].first;
        a--;
      }else{
         ans-=(l[i][a+1].second-i)*(r[i][b+1].second-r[i][b].second)*r[i][b].first;
         b--;
      }
    }
  }
  cout<<ans;
  

    return 0;
}


Measured memory_bytes: 17536
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

void find_divisor(ll N, vector<ll>& divisor) {
  for(int i=1; i<=sqrt(N); i++) {
    if(N % i == 0)
      divisor.push_back(i);
  }
  int n = divisor.size();
  for(int i=n-1; i>=0; i--) {
    if(N != (ll)pow(divisor[i], 2))
      divisor.push_back(N / divisor[i]);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n; cin >> n;
  vector<ll> div;
  find_divisor(n, div);
  int ans = inf;
  for(ll d: div) {
    ans = min(max((int)log10(d)+1, (int)log10(n/d)+1), ans);
  }
  cout << ans << "\n";
  return 0;
}


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

using namespace std;
typedef long long ll;




int main()
{
    
    int N,K;
    cin >> N >> K;
    vector<int> x(N);
    vector<int> f(N);
    
    rep(i,N){
        int xx;
        cin >> xx;
        if(xx<0) x[i] = -xx, f[i] = -1;
        else x[i] = (xx), f[i] = 1;
    }
    
    int ans = 1000000000;
    
    for (int i = N-1; i-K+1 >= 0; i--) {
        
        int a = x[i];
        int b = x[i-K+1];
        if (f[i]*f[i-K+1] == 1) {
            ans = min(ans, max(a,b));
        }else{
            ans = min(ans, min(a*2+b, a+b*2));
        }
        
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
   int n,i,count=0;
   scanf("%d",&n);
   char s[n];
   scanf("%s",s);
   for(i=0;i<n;i++){
      if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
         count++;
      }
   }
   printf("%d\n",count);
   return 0;
}


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

int main(){
    int n, x;
    while (true){
        int total = 0;
        cin >> n >> x;
        if (n == 0 && x == 0) { break; }
        for (int i = 1; i <= n; i++){
            for (int j = i+1; j <= n; j++){
                for (int k = j+1; k <= n; k++){
                    if (i+j+k == x){
                        total++;
                    }
                }
            }
        }
        cout << total << '\n';
    }
}



Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// total money
		int X = sc.nextInt();
		// price of cake
		int A = sc.nextInt();
		// price of daunts
		int B = sc.nextInt();

		int rmaftercake = X - A;
		int daunutsnum = rmaftercake / B;
		int rmafterdanuts = rmaftercake - B * daunutsnum;
		System.out.println(rmafterdanuts);

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
using namespace std;
long long n, ans;

bool f(int p){
    int re;
    for(re = 0; p; re++, p /= 10);
    return re % 2;
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) ans += f(i);
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int count = 0;
  for(int i = 1; i <= N; i++){
    int x = 0;
    if(i % 2 == 1){
      for(int j = 1; j <= i; j++){
        if(i % j == 0) x++;
      }
      if(x == 8) count++;
    }
  }
  cout << count << endl;
}
    
  
  

Measured memory_bytes: 3620
import sys

n = int(input())
ans = 0
tail_a = 0
head_b = 0
both = 0
for s in sys.stdin:
    s = s.rstrip()
    ans += s.count('AB')
    if s[0] == 'B':
        if s[-1] == 'A':
            both += 1
        else:
            head_b += 1
    elif s[-1] == 'A':
        tail_a += 1
if both:
    ans += both - 1
    if tail_a:
        ans += 1
        tail_a -= 1
    if head_b:
        ans += 1
        head_b -= 1
ans += min(tail_a, head_b)
print(ans)


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

int n ;

bool f ( vi v )
{
    int i=0 ;
    for ( ; i < n-1 && v[i] <= v[i+1] ; i++ ) ;

    if ( i == n-1 ) R true ;
    R false ;
}

void solve ( int test_case )
{
    cin >> n ;
    vi v ( n ) ;
    for ( int i=0 ; i < n ; i++ ) cin >> v[i] ;

    for ( int i=0 ; i < n ; i++ )
    {
        for ( int j=0 ; j < n ; j++ )
        {
            swap ( v[i] , v[j] ) ;
            bool ver = f ( v ) ;

            if ( ver ) { cout << "YES" ; return ; }
            swap ( v[i] , v[j] ) ;
        }
    }

    cout << "NO" ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

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

	vector<int64_t> A(N);
	for (int32_t i = 0; i < N; i++) {
		cin >> A[i];
		A[i] -= i + 1;
	}
	sort(A.begin(), A.end());
	int64_t b = A[N / 2];
	int64_t res = 0;
	for (int32_t i = 0; i < N; i++) {
		res += abs(A[i] - b);
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

bool f(int n, int a, int b) {
    int d = 0;
    while (n > 0) {
        d += n % 10;
        n /= 10;
    }
    return a <= d && d <= b;
}

int main() {
    int N,A,B;
    cin >> N>>A>>B;
    int ans = 0;
    REP(i, N + 1) {
        if (f(i, A, B)) {
            ans += i;
       }
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
# 貰うDP
n = int(input())
a = [1]
i = 6
while i <= n:
  a.append(i)
  i *= 6
i = 9
while i <= n:
  a.append(i)
  i *= 9
t = [float("inf")] * (n + 1)
t[0] = 0
for i in range(1, n + 1):
  k = float("inf")
  for j in a:
    if i - j >= 0 and k > t[i - j] + 1:
      k = t[i - j] + 1
  t[i] = k
print(t[n])


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<ll> divisor(ll n){
  vector<ll> ret;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      ret.push_back(i);
      if(i!=n/i) ret.push_back(n/i);
    }
  }
  return ret;
}

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

int main(){
  ll A, B;
  cin >> A >> B;

  vector<ll> a = divisor(A);
  vector<ll> b = divisor(B);

  map<ll,int> cnt;
  rep(i,a.size()) cnt[a[i]]++;
  rep(i,b.size()) cnt[b[i]]++;

  vector<ll> cmn;
  FOR(it,cnt) if(it->second == 2) cmn.push_back(it->first);

  int ret = 0;
  rep(i,cmn.size()){
    if(cmn[i] == 1) continue;
    if(cmn[i] == 0) continue;
    ret++;
    REP(j,i+1,cmn.size()){
      if(cmn[j] == 0) continue;
      if(gcd(cmn[i], cmn[j])!=1) cmn[j] = 0;
    }
  }

  cout << ret+1 << endl;

  return 0;
}



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

int main(){
    int a[3];
    int count = 0;
    int bak[200] = {0};
    for(int i = 0; i < 3;i++) {
        cin >> a[i] ;
        bak[a[i]]++;
    }
    for(int i = 0;i < 200;i++){
        if(bak[i]!= 0) count++;
    }
    

    cout << count << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for B - Shift only
	var N int
	fmt.Scanf("%d", &N)
	A := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}

	var flag int = 0
	var count int = 0
	for {

		for i := 0; i < N; i++ {
			if A[i]%2 != 0 {
				flag = 1
			} else {
				A[i] = A[i] / 2
			}
		}
		if flag == 1 {
			break
		} else {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 1844
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string S;
        cin >> S;
        ll n = len(S) / 2;
        if (even(len(S))) --n;
        ll ans = 0;
        rep(i, 0, n+1) {
                if (S[i] != S[len(S)-1-i]) ++ans;
        } 

        cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  
  sort(d.begin(),d.end());
  
  int ans;
  ans = d[n/2] - d[n/2-1];
  
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int factorial[9];
int state[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 0}}, target, ans;
queue<int> id_que, layer_que;
bool inque[362900];

int cantor(int *map){
    int rank = 0;
    for(int i=0; i<9; i++){
        int n_smaller = 0;
        for(int j=i+1; j<9; j++)
            if(map[i]>map[j])
                n_smaller += 1;
        rank += n_smaller * factorial[8-i];
    }
    return rank;
}

void inv_cantor(int rank, int *map){
    bool used[9];
    memset(used, 0, sizeof(used));
    for(int i=0; i<9; i++){
        int n_smaller = rank / factorial[8-i], cnt=0;
        rank -= n_smaller*factorial[8-i];
        for(int j=0; j<9; j++){
            if(used[j]) continue;
            if(cnt==n_smaller){
                *(map+i) = j;
                used[j] = true;
                break;
            }else 
                ++cnt;
        }
    }
}

bool check(int pos){
    return pos >= 0 && pos < 3;
}

int main(){
    factorial[0] = 1;
    for(int i=1; i<9; i++)
        factorial[i] = i * factorial[i-1];
    target = cantor(state[0]);

    
    for(int i=0; i<9; i++)
        scanf("%d", state[0]+i);
    memset(inque, 0, sizeof(inque));
    id_que.push(cantor(state[0]));
    layer_que.push(0);
    inque[id_que.front()] == true;

    if(id_que.front()==target)
        printf("0\n");
    else{
        int head, tail, layer, zx, zy, nx, ny;
        bool found=false;
        while(!id_que.empty()){
            head = id_que.front();
            layer = layer_que.front();
            id_que.pop();
            layer_que.pop();
            inv_cantor(head, state[0]);

            //find the position of zero
            for(int i=0; i<9; i++){
                if(*(state[0]+i)==0){
                    zx = i / 3;
                    zy = i % 3;
                    break;
                }
            }

            //iterator the posible positions
            for(int dir=0; dir<4; dir++){
                nx = zx + dx[dir];
                ny = zy + dy[dir];
                if(check(nx) && check(ny)){
                    state[zx][zy] = state[nx][ny];
                    state[nx][ny] = 0;
                    tail = cantor(state[0]);
                    //printf("%d\n", tail);
                    if(tail==target){
                        found = true;
                        ans = layer + 1;
                        break;
                    }else if(!inque[tail]){
                        inque[tail] = true;;
                        id_que.push(tail);
                        layer_que.push(layer + 1);
                    }
                    state[nx][ny] = state[zx][zy];
                    state[zx][zy] = 0;
                }
            }

            if(found){
                printf("%d\n", ans);
                break;
            }
        }
    }
    
    return 0; 
}


Measured memory_bytes: 3196
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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 = 1LL <<60;
const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

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

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
 int n,k;
 cin>>n>>k;
 cout<<n-k+1<<endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[114514];
signed main(){
	ic(a) 
	rep(1,i,10){
		rep(1,j,10){
			if(i*j==a){
				c("Yes")
				return 0;
			}	
		}
	}
	c("No")
}		

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
    long long x,a,b,ans,c;
    cin>>x>>a>>b;
    ans=x-a;
    c=ans/b;
    if(ans%b==0)
    cout<<"0"<<endl;
    else cout<<x-a-b*c<<endl;
    return 0;
}

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

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

    int n, m;
    cin >> n >> m;

    vector<int> l(m), r(m);
    REP(i, m) cin >> l[i] >> r[i];

    int mini = 100001;
    int maxi = 0;
    REP(i, m) {
        maxi = max(maxi, l[i]);
        mini = min(mini, r[i]);
    }

    if (mini - maxi < 0) cout << 0 << '\n';
    else cout << mini - maxi + 1 << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

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

  int Max = -1, t = -1, idx = -1;
  for(int i = 0; i < n; i++){
    if(Max < abs(a[i])){
      Max = abs(a[i]);
      t = a[i];
      idx = i;
    }
  }

  for(int i = 0; i < n; i++){
    a[i] += t;
  }
  if(t >= 0){
    for(int i = 0; i < n; i++){
      if(i > 0) a[i] += a[i-1];
    }
  }else{
    for(int i = n-2; i >= 0; i--){
      a[i] += a[i+1];
    }
  }
  //cout << a << endl;

  cout << 2 * n - 1 << endl;
  for(int i = 0; i < n; i++){
    cout << idx+1 << " " << i+1 << endl;
  }
  if(t >= 0){
    for(int i = 1; i < n; i++){
      cout << i << " " << i+1 << endl;
    }
  }else{
    for(int i = n-2; i >= 0; i--){
      cout << i+2 << " " << i+1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    int lpos, cpos;

    for( int i = 0; i < h; ++i ) {
        for( int j = 0; j < w; ++j ) {
            string s;
            cin >> s;
            if( s == "snuke" ) { lpos = i; cpos = j; }
        }
    }

    cout << (char)(cpos + 'A') << lpos + 1 << endl;
    return 0;
}



Measured memory_bytes: 256
H,W = list(map(int,input().split()))
temp = [["#" for i in range(W+2)]]
A = temp + [["#"] + (list(str(input()))) + ["#"] for i in range(H)] + temp
 
black = []
 
cnt = 0
 
for i in range(1,H+1):
    for j in range(1,W+1):
        if A[i][j] == "#":
            black.append([i,j])
 
length = len(black)
            
while (length < H*W):
    gray = []
    for l in black:
            c1 = [l[0],l[1]-1]
            if A[c1[0]][c1[1]] == ".":
                gray.append(c1)
                A[c1[0]][c1[1]] = "#"
            c2 = [l[0],l[1]+1]
            if  A[c2[0]][c2[1]] == ".":
                gray.append(c2)
                A[c2[0]][c2[1]] = "#"
            c3 = [l[0]-1,l[1]]
            if  A[c3[0]][c3[1]] == ".":
                gray.append(c3)
                A[c3[0]][c3[1]] = "#"
            c4 = [l[0]+1,l[1]]
            if  A[c4[0]][c4[1]] == ".":
                gray.append(c4)
                A[c4[0]][c4[1]] = "#"
    
    black = [l for l in gray]
    
    cnt += 1
    length += len(black)
    
print(cnt)

Measured memory_bytes: 179712
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h1 = sc.nextInt();
    int m1 = sc.nextInt();
    int h2 = sc.nextInt();
    int m2 = sc.nextInt();
    int k = sc.nextInt();    
    
    m2 -= k;
    while(m2 < 0) {
      m2 += 60;
      h2 -= 1;
    }
    
    int out = m2 - m1 + (h2-h1)*60;
    
    System.out.println(out);
  }
}

Measured memory_bytes: 35776
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
int read()
{
	int res=0,ch,flag=0;
	if((ch=getchar())=='-')             //判断正负
		flag=1;
	else if(ch>='0'&&ch<='9')           //得到完整的数
		res=ch-'0';
	while((ch=getchar())>='0'&&ch<='9')
		res=res*10+ch-'0';
	return flag?-res:res;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
//long long solve(long long test)
//{
//    int cnt=0;
//    while(test)
//    {
//        tmp[++cnt]=test%10;
//        test/=10;
//    }
//    return dfs(cnt,0,1,1);
//}
ll a[1000010];
int st[10101010];
ll sum=0;
int n;
void solve()
{
	memset(st,0,sizeof st);
	cin>>n;
	for(int i=1; i<=n; i++)
	{ 
		cin>>a[i];
		st[a[i]] ++;
		sum+=a[i];
	} 
	int q;
	cin>>q;
	while(q--)
	{
		int b,c;
		cin>>b>>c;
		sum+=st[b]*(c-b);

		st[c]+=st[b];
		st[b]=0;
		cout<<sum<<endl;
	}
}
int main()
{
	int t=1;
	while(t--)
		solve();
	return 0;
}



Measured memory_bytes: 43860
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define for_(i,n) for(int i=0;i<n;++i)
#define for_1(i,n) for(int i=1;i<=n;++i)
const int mod= 1e9 +7;
const int inf=1e7;
int n;
string s;

/*
dp[i][j]:- i th character of permutation is j
we need find sigma over j (dp[n][j])
i range from 0 to n-1

dp[i][j] = dp[i-1][1] + ... +dp[i-1][j-1] if(s[i-1] = '<')
         = dp[i-1][j+1] + ... +dp[i-1][n] if(s[i-1] = '>')
*/
void add_self(int &a, int b)
{
    a+=b;
    if(a>=mod)
    a-= mod;
}


/********************** Recursive Approach ***************************
int dp[3001][3001]; int pre[3001][3001];
int solve(int i, int j){

if(i==1 && j==1){ dp[i][j]=1; return 1;}
//else if(i==1) return 0;
else if(j>i) return 0;
else if(dp[i][j]!=-1) return dp[i][j];
else{
    dp[i][j]=0;
    if(s[i-2]=='<')
    {
        for_1(k,j-1)
        add_self(dp[i][j],solve(i-1,k));
    }
    else if(s[i-2]=='>')
    {
        for(int k=j;k<=n;++k)
        add_self(dp[i][j],solve(i-1,k));
    }
    
   return dp[i][j]; 
}
}

// --------------O(n^3)
*************************************** Recursive Approach ***************/
main()
{
   cin>>n>>s;
   
 /* memset(dp,-1,sizeof(dp));
    int ans=0;
    for_1(i,n)
        add_self(ans,solve(n,i));
    cout<<ans;
 */ 
 
 
 /*********** iterative ***********/
 vector<vector<int>> dpi(n+1,vector<int>(n+1));
 vector<vector<int>> pref(n+1,vector<int>(n+1));
dpi[1][1]=1;pref[1][1]=1;
//for_1(i,n) dpi[1][i]+=dpi[1][i-1];
 for(int len =2; len<=n;++len)
 {   for(int i =1;i<=len-1;++i)pref[len-1][i] = (pref[len-1][i-1] + dpi[len-1][i]) % mod;
     //add_self(dpi[len-1][b],dpi[len-1][b-1]);// + dpi[]       
     for(int b =1;b<=len;++b)
     { 
         int l,r;
         if(s[len-2]=='<') l=1,r=b-1;
         else l=b,r=len-1;
         if(l<=r) 
         {
             int tmp = (pref[len-1][r]+mod-pref[len-1][l-1])%mod;
             add_self(dpi[len][b],tmp);
         
     
         }
        
         }
 }

 int answer = 0;
    for(int b = 1; b <= n; ++b) {
        add_self(answer, dpi[n][b]);
    }
 cout<<answer<<endl;
}





/*
typedef struct structure{
    int x,y;
} pt;
pt p0;
bool cmp(pt a, pt b)
{
    return cw(p0,a,b);
}
bool cw(pt a, pt b, pt c){
    return ((c.y-a.y)*(b.x-a.x)-(b.y-a.y)*(c.x-a.x))>=0
}



convex_hull(vector<pt>& points)
{
   // sort(points.begin(),points.end, cmp);// sorted according to y cordinate
    p0=points[0];
    sort(points.begin(),points.end, cmp);
    vector<pt> convexHull;
    stack<pt> temp;
    convexHull.push_back(points[0]);
    
    temp.push(points[0]);temp.push(points[1]);//temp.push(points[2]);
    pt top,top0;
    for(int it=2;it<points.size();++it)
    {   
        top=temp.top(); temp.pop(); top0=temp.top();
        pt next=points[it];
        if(cw(top0,top,next))
        {
            convexHull.push_back(top);
            temp.push(top);
            top0=top;
            top=next;
        }
        else
        {
          temp.push(next);  
        }
        
    }
    
}*/












Measured memory_bytes: 141184
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, m;
    long long inf = -1000000000000000000;
    scanf("%d %d", &n, &m);
    vector<vector<pair<long long, int>>> a(n, vector<pair<long long, int>>(0));
    for(int i = 0, j, k; i < m; ++i)
    {
        long long l;
        scanf("%d %d %lld", &j, &k, &l);
        a[--j].push_back(make_pair(l, --k));
        a[k].push_back(make_pair(-l, j));
    }
    vector<long long> cost(n, inf);
    for(int i = 0; i < n; ++i)
    {
        if(cost[i] == inf)
        {
            cost[i] = 0;
            stack<int> s;
            s.push(i);
            for (int t; !s.empty(); )
            {
                t = s.top();
                s.pop();
                for(int j = 0; j < a[t].size(); ++j)
                {
                    if(cost[a[t][j].second] == inf)
                    {
                        cost[a[t][j].second] = cost[t] + a[t][j].first;
                        s.push(a[t][j].second);
                    }
                    else
                    {
                        if(cost[a[t][j].second] != cost[t] + a[t][j].first)
                        {
                            printf("No\n");
                            return 0;
                        }
                    }
                }
            }
        }
        else
        {
            for(int j = 0; j < a[i].size(); ++j)
            {
                if(cost[a[i][j].second] == inf)
                {
                    cost[a[i][j].second] = cost[i] + a[i][j].first;
                }
                else
                {
                    if(cost[a[i][j].second] != cost[i] + a[i][j].first)
                    {
                        printf("No\n");
                        return 0;
                    }
                }
            }
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 13824