akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if a + b >= 10:
        print("error")
    else:
        print(a + b)
    return

#B
def B():
    s = S()
    if len(s) == len(set(s)):
        print("yes")
    else:
        print("no")
    return

#C
def C():
    n = II()
    m = inf
    ans = 0
    for _ in range(n):
        s = II()
        ans += s
        if s % 10:
            m = min(m, s)
    if ans % 10:
        print(ans)
    else:
        if m != inf:
            print(ans - m)
        else:
            print(0)
    return

#D
def D():
    return


#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 38640
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<' ';
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int cd = __gcd(a,b);
    vint c(110,0); int p = 0;
    for(int i = 1; i<=cd; ++i){
        if(cd%i == 0){c[p] = i; ++p;}
    }
    cout<<c[p-k]<<endl; return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  string s;
  cin >> s;
  int a = (int)s[0] - 48, b = (int)s[1] - 48, c = (int)s[2] - 48, d = (int)s[3] - 48;

  rep(i, 0, 2) rep(j, 0, 2) rep(k, 0, 2) {
    int kb, kc, kd;
    if(i == 0) kb = a + b;
    if(i == 1) kb = a - b;
    if(j == 0) kc = kb + c;
    if(j == 1) kc = kb - c;
    if(k == 0) kd = kc + d;
    if(k == 1) kd = kc - d;
    if(kd == 7) {
      cout << a << (!i ? '+' : '-') << b << (!j ? '+' : '-') << c << (!k ? '+' : '-') << d << "=7" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data',function(chunk){
var a = chunk.split(' ');
var b = parseInt(a[0],10);
var c = parseInt(a[1],10);
var menseki = b*c;
var nagasa = b*2+c*2;
console.log(menseki+' '+nagasa);
});

Measured memory_bytes: 15384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef double db;
const int N = 305, mod = 1000000007;
int n, m, T, q, a[N][N], d[N], c[N], ans = N;
int main()
{
	scanf ("%d%d", &n, &m);
	Rep(i, 1, n) {
		Rep(j, 1, m) {
			int k;
			scanf ("%d", &k);
			a[i][k] = m - j + 1;
		}
		Rep(j, 1, m) {
			if (a[i][ d[i] ] < a[i][j]) d[i] = j;
		}
		c[d[i]] ++;
	}
	Rep(t, 1, m) {
		int k = 0;
		Rep(j, 1, m) if (c[j] > c[k]) k = j;
		ans = min(ans, c[k]);
		c[k] = -n;
		Rep(i, 1, n) if (d[i] == k) {
			d[i] = 0;
			Rep(j, 1, m) if (c[j] >= 0) {
				if (a[i][ d[i] ] < a[i][j]) d[i] = j;
			}
			c[d[i]] ++;
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
    int a[5];
    int k;
    bool flag=true;
    for(int i=0; i<5; i++) cin>>a[i];
    cin>>k;
    for(int i=0; i<5; i++) {
        for(int j=i; j<5; j++) {
            if(a[j]-a[i]>k) {
                flag=false;
                break;
            }
        }
        if(!flag) break;
    }

    flag? cout<<"Yay!"<<endl: cout<<":("<<endl;
}


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

const int INF = 1000000000;

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

		if(n==0 && m==0)
			break;

		int C[100][100];
		int T[100][100];
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				if(i==j){
					C[i][j] = T[i][j] = 0;
				}
				else{
					C[i][j] = T[i][j] = INF;
				}
			}
		}

		for(int i=0; i<n; i++){
			int a, b, c, t;
			cin >> a >> b >> c >> t;

			C[a-1][b-1] = C[b-1][a-1] = c;
			T[a-1][b-1] = T[b-1][a-1] = t;
		}

		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(C[i][j]>C[i][k]+C[k][j]){
						C[i][j]=C[i][k]+C[k][j];
					}
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
					}
				}
			}
		}
	
	int k;
	cin>>k;
	for(int i=0;i<k;i++){
		int s,g,r;
		cin>>s>>g>>r;
		if(r==1){
			cout<<T[s-1][g-1]<<endl;
		}else{
			cout<<C[s-1][g-1]<<endl;
		}
	}
}
	return 0;
}

Measured memory_bytes: 3080
n, m = map(int, input().split())
city = []
for i in range(m):
    p, y = map(int, input().split())
    city.append([i, p, y])

city = sorted(city, key=lambda x: (x[1], x[2]))

c_num = 0
for i, c in enumerate(city):
    if c_num != c[1]:
        p_num = 1
        c_num = c[1]
    else:
        p_num += 1
    city[i].append(str(c[1]).zfill(6) + str(p_num).zfill(6))

city = sorted(city, key=lambda x: x[0])

for c in city:
    print(c[3])

Measured memory_bytes: 35132
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]
Alice = 0
Bob = 0
for i in range(N):
  if(i % 2 == 0):
    Alice = Alice + A.pop(0)
  else:
    Bob = Bob + A.pop(0)
print(str(Alice - Bob))
  

Measured memory_bytes: 3060
using System;
namespace inonoa{
    class Ino{
        static void Main(){
            string[] input = Console.ReadLine().Split();
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            int x = int.Parse(input[3]);
            int y = int.Parse(input[4]);

            int ans = 0;

            if((a+b)/2.0f<=c){
                ans = a*x + b*y;
            }else{
                if(a>b){
                    if(b>2*c){
                        ans = 2*c*Math.Max(x,y);
                    }
                    else{
                        if(a>2*c){
                            if(x>y){
                                ans = x*2*c;
                            }
                            else{
                                ans = x*2*c + (y-x)*b;
                            }
                        }
                        else{
                            if(x>y){
                                ans = y*2*c + (x-y)*a;
                            }
                            else{
                                ans = x*2*c + (y-x)*b;
                            }
                        }
                    }
                }else{
                    if(a>2*c){
                        ans = 2*c*Math.Max(x,y);
                    }
                    else{
                        if(b>2*c){
                            if(y>x){
                                ans = y*2*c;
                            }
                            else{
                                ans = y*2*c + (x-y)*a;
                            }
                        }
                        else{
                            if(y>x){
                                ans = x*2*c + (y-x)*b;
                            }
                            else{
                                ans = y*2*c + (x-y)*a;
                            }
                        }
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
using System;
using System.IO;

class Solve{
    static void Main(string[] args){
        var arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var A = arr[0];
        var B = arr[1];
        var M = arr[2];
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var a_min = 100000;
        var b_min = 100000;
        for (int i = 0; i < A; i++){
            if (a[i] == 1){
                a_min = 1;
                break;}
            if (a[i] < a_min) a_min = a[i];}
        for (int i = 0; i < B; i++){
            if (b[i] == 1){
                b_min = 1;
                break; }
            if (b[i] < b_min) b_min = b[i];}
        var answer = a_min + b_min;
        for (int i = 0; i < M; i++){
            var xyc = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var disctTgt = a[xyc[0] - 1] + b[xyc[1] - 1] - xyc[2];
            answer = disctTgt < answer ? disctTgt : answer;}
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

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

int main() {
  int R;
  cin>>R;
  if(R<1200){
    cout<<"ABC"<<endl;
  }else if(R>=1200&&R<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<string>
#include<vector>
using namespace std;
int main(){
    int N;
    cin>>N;
    int max_H;
    int cnt=1;
    cin>>max_H;
    for(int i=1;i<N;i++){
        int H;
        cin>>H;
        if(max_H<=H){
            max_H=H;
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class ABC333
{
    static void Main()
    {
        int state=0;
        foreach(int i in Console.ReadLine().Split(' ').Select(x => int.Parse(x)))
        {
            if(i %2 ==1)
                state++;
        }
        if(state==2)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}


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

using namespace std;
#define ll long long int
#define X first
#define Y second
const int MAXN = 1e5 + 5;
ll n, W, w[MAXN], v[MAXN], dp[105][MAXN];

ll solve(int idx = 1, int rem = W)
{
	if (idx > n) return 0;

	ll &ret = dp[idx][rem];
	if (~ret) return ret;
	ret = 0;

	ret = solve(idx + 1, rem);
	if (rem - w[idx] >= 0)
		ret = max(ret, solve(idx + 1, rem - w[idx]) + v[idx]);

	return ret;
}

int main()
{
	cin >> n >> W;
	for (int i = 1; i <= n; i++) cin >> w[i] >> v[i];
	memset(dp, -1, sizeof dp);
	cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

const int mod = 998244353;
int ar[100005];
int cnt[100005];
int n;

int32_t main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
		cnt[ar[i]]++;
	}
	int ans = 1;
	if(ar[1]){
		ans = 0;
	}
	for(int i=2;i<=n;i++){
		ans *= cnt[ar[i]-1];
		ans %= mod;
	}
	cout<<ans;
}


Measured memory_bytes: 1792
import numpy as np
n, m, k = map(int, input().split())
li_a = np.array(list(map(int, input().split())))
li_b = np.array(list(map(int, input().split())))
a_i, b_i = np.hstack([np.array([0]),li_a.cumsum()]), np.hstack([np.array([0]),li_b.cumsum()])

j = m
ans = 0
for i in range(n+1):
    if a_i[i]>k:
        break
    while(b_i[j] > k - a_i[i]):
        j -= 1
    ans = max(ans, i+j)
print(ans)

Measured memory_bytes: 53056
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int n, q;
  cin >> n >> q;
  string a;
  cin >> a;

  vector<int > numAC(n,0);
  for(int i = 1; i < n; i ++){
    if(a.substr(i - 1,2) == "AC"){
      numAC[i] = numAC[i - 1] + 1;
    }else{
      numAC[i] = numAC[i - 1];
    }
  }
  // REP(i,n)cout << numAC[i] << endl;
  int l, r;
  REP(i, q){
    cin >> l >> r;
    cout << numAC[r - 1] - numAC[l - 1] << endl;
  }
}


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

int gcd(int A,int B){
  if(B>A)swap(A,B);
  if(B==0)return A;
  return gcd(B,A%B);
}

int main(){
  int N;
  cin >> N;
  vector<double>x(N);
  vector<string>u(N);
  for(int i=0;i<N;i++){
    cin >> x[i];
    cin >> u[i];
  }
  double ans=0.0;
  for(int i=0;i<N;i++){
    if(u[i]=="JPY"){
      ans+=x[i];
    }
    else{
      ans+=x[i]*380000.0;
    }
  }
  cout << ans << endl;
  
  
}
  
  

Measured memory_bytes: 256
#include<vector>
template<typename T> class BinaryIndexedTree {
 public:
  BinaryIndexedTree(int s) : node_(s + 1) {}
  T find(int index) const {
    T result = 0;
    for(auto i = index + 1; i > 0; i -= i & -i) result += node_[i];
    return result;
  }
  T find(int left, int right) const {return find(right) - find(left - 1);}
  void update(int index, T value) {for(int i = index + 1; i < node_.size(); i += i & -i) node_[i] += value;}
 private:
  std::vector<T> node_;
};

#include<bits/stdc++.h>
using namespace std;

using I = long long;

I dist(auto S, auto T) {
  I res = 0;
  int N = S.size();
  reverse(begin(T), end(T));

  BinaryIndexedTree<I> BIT(N);
  map<char, queue<int>> idx;
  for(auto i=0; i<N; ++i) idx[S[i]].emplace(i);
  for(auto i=0; i<N; ++i) {
    auto c = T[i];
    auto n = idx[c].front();
    idx[c].pop();
    auto x = n - BIT.find(0, n);
    BIT.update(n, 1);
    res += x;
  }

  return res;
}

I solve() {
  string S;
  cin >> S;

  auto M = S.size() / 2;
  map<char, int> all, former, latter;
  for(auto i=0; i<S.size(); ++i) {
    ++all[S[i]];
    if(i<M) ++former[S[i]];
    else    ++latter[S[i]];
  }

  vector<char> odd;
  for(auto i: all) if(i.second&1) odd.emplace_back(i.first);
  if(2<=odd.size()) return -1;

  for(auto& i: all) i.second /= 2;
  map<char, int> r, l;
  for(auto i: former) r[i.first] = max(0, i.second - all[i.first]);
  for(auto i: latter) l[i.first] = max(0, i.second - all[i.first]);

  auto move = accumulate(begin(r), end(r), I(0), [](auto s, auto i) {return s + i.second;});
  I res = 0;
  string left, right;
  string to_r, to_l;

  auto fix = 0;
  for(I i=M-1; 0<=i; --i) {
    if(0<r[S[i]]--) to_r = S[i] + to_r, res += fix;
    else            left = S[i] + left, ++fix;
  }
  fix = 0;
  for(I i=M; i<S.size(); ++i) {
    if(0<l[S[i]]--) to_l  += S[i], res += fix + move;
    else            right += S[i], ++fix;
  }

  if(!odd.empty()) {
    for(I i=0; i<to_r.size(); ++i) if(to_r[i]==odd[0]) {
      res += i;
      to_r.erase(begin(to_r) + i);
      break;
    }
    for(I i=to_l.size()-1; 0<=i; --i) if(to_l[i]==odd[0]) {
      res += to_l.size()-1 - i;
      to_l.erase(begin(to_l) + i);
      break;
    }
  }

  res += dist(left+to_l, to_r+right);

  return res;
}

int main() {
  cout << solve() << endl;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll w, h, v, t, x, y, p, q;
vector<ll> inih, iniw;
ll ans = 0;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> w >> h >> v >> t >> x >> y >> p >> q;
    t *= v;
    v = 0;
    if(x == p) {
        iniw.push_back(2 * w);
        iniw.push_back(p - x);
        iniw.push_back(2 * w - x - p);
        iniw.push_back(x + p);
        iniw.push_back(2 * w - p + x);
    } else {
        if(p < x) swap(p, x);
        iniw.push_back(p - x);
        iniw.push_back(2 * w - x - p);
        iniw.push_back(x + p);
        iniw.push_back(2 * w - p + x);
    }
    if(y == q) {
        inih.push_back(2 * h);
        inih.push_back(q - y);
        inih.push_back(2 * h - y - q);
        inih.push_back(y + q);
        inih.push_back(2 * h - q + y);
    } else {
        if(q < y) swap(q, y);
        inih.push_back(q - y);
        inih.push_back(2 * h - y - q);
        inih.push_back(y + q);
        inih.push_back(2 * h - q + y);
    }
    for(auto sh : inih) {
        for(auto sw : iniw) {
            ll dh = 2 * h;
            ll dw = 2 * w;
            if(sh == 0) dh = 0;
            if(sw == 0) dw = 0;
            for(ll DH = 0; DH <= 1e6; DH++) {
                if(DH >= 1 and dh == 0) break;
                if(DH * dh + sh > 1e9) break;
                ll ok = 0;
                ll ng = 2e6;
                if(dw == 0) ng = 2;
                while(abs(ok - ng) > 1) {
                    ll mid = (ok + ng) / 2;
                    if((mid - 1) * dw + sw > 1e9) {
                        ng = mid;
                        continue;
                    }
                    ll h = dh * DH + sh;
                    ll w = dw * (mid - 1) + sw;
                    //cerr << h << " " << w << " " << t << endl;
                    if(h * h + w * w <= t * t) ok = mid;
                    else ng = mid;
                }
                if(ok >= 1) {
                    //cerr << sh << " " << sw << " " << DH << " " << ok << endl;
                }
                ans += ok;
            }
            //cerr << sh << " " << dh << " " << sw << " " << dw << endl;
            //cerr << sh << " " << dh << " " << sw << " " << dw << " " << ok << endl;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3216
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int city  = sc.nextInt();
		long[] monster = new long[city+1];
		long[] brave = new long[city];
		long anser = 0;
		for(int i=0;i<city+1;i++) {
			monster[i] = sc.nextLong();
		}
		for(int i =0;i<city;i++) {
			brave[i] = sc.nextLong();
		}

		//勇者の攻撃がなくなるまで
		for(int i = 0; i<brave.length;i++) {
			//AとBの小さいほうをanserにいれる
			anser += Math.min(monster[i],brave[i]);
			//A(i+1)と（B-A）の小さいほうを入れる。
			anser += Math.min(monster[i+1],Math.max(brave[i]-monster[i], 0));
			//A(i+1) = A(i+1)とmax(0,(B-A))の小さいほうを引く
			monster[i+1] -= Math.min(monster[i+1],Math.max(brave[i]-monster[i], 0));
		}
		System.out.println(anser);
	}
}

Measured memory_bytes: 86824
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = x[0];
            int b = x[1];
            if (a - b < 0)
            {
                Console.WriteLine("a < b");
            }
            if (a - b > 0)
            {
                Console.WriteLine("a > b");
            }
            if(a-b ==  0)
            {
                Console.WriteLine("a == b");
            }
        }
    }
}



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

int main()
{
	ll n,d;cin>>n>>d;
	int ans=0;
	for(int i=0;i<n;i++){
		ll x,y;cin>>x>>y;
		if(sqrt(x*x + y*y)<=d)	ans++;
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int d, t, s;    cin >> d >> t >> s;
    if(t*s >= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
import math
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = [i for i in S()[:-1]]

if len(set(N[1:])) == 1 or len(set(N[:-1])) == 1:
	print("Yes")
else:
	print("No")

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    string s,t;
    cin>>s>>t;
    vector<int> arr[26];
    //memset(arr,0,sizeof(arr));
    int n=s.size(),m=t.size();
    f1(i,0,n)
    {
    	arr[s[i]-'a'].pb(i);
    }
    // f1(i,0,26)
    // {
    // 	f1(j,0,arr[i].size())
    // 	cout<<arr[i][j]<<gp;
    // 	cout<<endl;
    // }
    int ans=0,val=0,cur=-1;
    f1(i,0,m)
    {
    	if(arr[t[i]-'a'].size()==0)
    		{
    			cout<<"-1";
    			return 0;
    		}
    	auto temp=upper_bound(arr[t[i]-'a'].begin(),arr[t[i]-'a'].end(),cur);
    	if(temp!=arr[t[i]-'a'].end())
    	{
    		val+=(*temp-cur);
    			cur=*temp;
    	}
    	// f1(j,0,arr[t[i]-'a'].size())
    	// {	
    	// 	if(arr[t[i]-'a'][j]>cur)
    	// 	{
    			
    	// 		//cout<<1<<gp<<val<<gp;
    	// 		break;
    	// 	}

    	// }
    	else
    	{
    		val+=(((n-1)-cur)+(arr[t[i]-'a'][0]+1));
    		cur=arr[t[i]-'a'][0];
    		//cout<<2<<gp<<val<<gp<<ans<<gp;
    		ans+=(val/n);
    		val%=n;
    		
    	}
    	//cout<<ans<<gp<<val<<endl;
    }
    ans+=(val/n);
   	val%=n;
    cout<<ans*n+val;
    return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);cout<<"\n";};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...);}
//FUNCTION

//BELOW
void solve(void)
{ 
  int N;
  cin>>N;
  cout<<N*(N-1)/2 - N/2<<endl;
  for (int i = 1; i < N; i++)
  {
    for (int j = i + 1; j <= N; j++)
    {
      if(N%2 == 0)
      {
        if(i+j != N+1)
        {
          cout<<i<<" "<<j<<endl;
        }
      }
      else
      {
        if(i+j != N)
        {
          cout<<i<<" "<<j<<endl;
        }
      }
      
    }
    
  }
  
  return;
}
  
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

_ = sys.stdin.readline()
A = list(map(int, sys.stdin.readline().split()))
Q = int(sys.stdin.readline())
replace_map = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

nums = {}
for a in A:
    nums[a] = nums[a] + 1 if a in nums else 1

previous_sum = 0
for search, replace in replace_map:
    replaced_count = 0
    if search in nums:
        replaced_count = nums[search]
        nums[replace] = nums[replace] + replaced_count if replace in nums else replaced_count
        del nums[search]
    if previous_sum == 0:
        previous_sum = np.dot(list(nums.keys()), list(nums.values()))
    else:
        previous_sum += replaced_count * (replace - search)
    print(previous_sum)


Measured memory_bytes: 56024
#include <iostream>
#include <utility>
static int ssort(int *a, int n) {
    int c = 0;
    for (int i = 0; i < n; ++i) {
        int min = i;
        for (int j = i + 1; j < n; ++j) {
            if (a[j] < a[min]) {
                min = j;
            }
        }
        if (min > i) {
            std::swap(a[i], a[min]);
            ++c;
        }
    }
    return c;
}
int main() {
    int n, a[100], c;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    c = ssort(a, n);
    for (int i = 0; i < n; ++i) {
        std::cout << ((i == 0) ? "" : " ") << a[i];
    }
    std::cout << std::endl << c << std::endl;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define maxn 1000005
#define mod 1000000007
using namespace std;
typedef long long LL;
LL read()
{
    char c=getchar();LL f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
LL n,ans;
LL dp[maxn],sum[maxn];
int main()
{
	n=read();
	dp[1]=1;
	for(int i=1;i<=n;i++)
	{
		if(i>=3) dp[i]=(dp[i]+sum[i-3])%mod;
		dp[i]=(dp[i]+dp[i-1])%mod;
		sum[i]=(sum[i-1]+dp[i])%mod;
	}
	for(int i=1;i<n;i++) ans=(ans+dp[i]*(n-1)%mod*(n-1)%mod)%mod;
	for(LL i=1;i<n;i++) ans=(ans+dp[i]*min(i+1,n-1)%mod)%mod;
	ans=(ans+dp[n]*n%mod)%mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 15872
import java.util.*

fun main(args: Array<String>) {
    var n = IO.readInt()
    var ans = 0
    for (i in 1..n) {
        if (i.toString().length % 2 == 1) { ans = ans + 1}
    }   
    println(ans)
}

object IO {
    fun readInt(): Int {
        return readLine()!!.toInt()
    }
    fun readIntList(): List<Int> {
        return readLine()!!.split(" ").map(String::toInt)
    }
}

Measured memory_bytes: 38404
def main():
    ans = 'Yes'
    a,b,c,d = map(int, input().split())
    while True:
        c -= b
        if c <= 0:
            break
        a -= d
        if a <= 0:
            ans = 'No'
            break    
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
#n=int(input())
n,m,x,y=map(int,input().split())
xl=list(map(int,input().split()))
yl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

ans="War"

for z in range(x+1,y+1,1):
    if max(xl)<z and min(yl)>=z:
        ans="No War"
        break

print(ans)

Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = (0 until n).map { sc.next() }
    val m = sc.nextInt()
    val t = (0 until m).map { sc.next() }
    println(problem091b(n, s, m, t))
}

fun problem091b(
    n: Int,
    s: List<String>,
    m: Int,
    t: List<String>
): Int {
    val sMap = s.groupBy { it }
    val tMap = t.groupBy { it }
    val map = mutableMapOf<String, Int>()
    sMap.forEach {
        map[it.key] = it.value.size - (tMap[it.key]?.size ?: 0)
    }
    val res = map.maxBy { it.value }!!.value
    return if (res < 0) 0 else res
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  ll K;
  cin >> K;
  vector<ll> ans(50);
  ll x = (K+50-1)/50;
  rep(i,50){
    ans[i] = x+i;
  }
  ll y;
  if(K%50==0)y=0;
  else y=50-K%50;

  rep(i,y){
    sort(all(ans));
    rep(j,50){
      if(j==49)ans[j]-=50;
      else ans[j]++;
    }
  }

  cout << 50 << endl;
  rep(i,50){
    cout << ans[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 256
def main
  n = gets.to_i

  name_size = 1
  max_idx = 0
  max_idx_kari = 0
  loop do
    max_idx_kari += 26**name_size
    break if n <= max_idx_kari
    max_idx += 26 ** name_size
    name_size += 1
  end
  diff = n - max_idx

  name = ""
  name_size.times do |i|
    first = diff / 26 ** (name_size - i - 1)
    diff = diff % 26 ** (name_size - i - 1)
    if diff == 0 && (name_size - i - 1) > 0
      first -= 1
      diff += 26 ** (name_size - i - 1)
    end
    if name_size - i - 1 == 0
      name += (first+96).chr
    else
      name += (first+97).chr
    end
  end

  puts name
end

main



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

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

using namespace std;

int main(){
	string s; cin>>s;
	int a=stoi(s.substr(0,2));
	int b=stoi(s.substr(2));

	bool f1=(1<=b && b<=12);
	bool f2=(1<=a && a<=12);
	if     ( f1 &&  f2) cout<<"AMBIGUOUS"<<endl;
	else if( f1 && !f2) cout<<"YYMM"<<endl;
	else if(!f1 &&  f2) cout<<"MMYY"<<endl;
	else                cout<<"NA"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>
#include <cmath>
#define ll long long

using namespace std;

const double pi = 3.14159265358979323846;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);


	int N, K, d;

	cin >> N >> K;

	vector<vector<int>> g(N + 1);

	for (int i = 0; i < K; i++) {

		cin >> d;

		vector<int> a(d + 1);

		for (int j = 1; j <= d; j++) {
			cin >> a[j];
			g[a[j]].push_back(j);
		}
	}

	int num = 0;

	for (int x = 1; x <= N; x++) {
		if (g[x].empty()) {
			num++;
		}
	}


	cout << num << endl;
	return 0;
}

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

int main(){
  ll a,b  ; cin>>a>>b  ;
  if((max(a,b)-min(a,b))%2==0)
  cout<<(max(a,b)-min(a,b))/2+min(a,b)<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int h, w, a, b; cin >> h >> w >> a >> b;
    // if ((a == 0 && b != 0) || (a != 0 && b == 0)) {
    //     cout << "No\n";
    //     return 0;
    // }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++)
            cout << (((i < b) == (j < a)) ? 1 : 0);
        cout << endl;
    }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    for(int i=0; i<N; i++){
        cin >> P.at(i);
    }
    for(int i=0; i<N; i++){
        cin >> Q.at(i);
    }
    int count=0;
    if(P<Q){
        while(next_permutation(P.begin(),P.end())){
            count++;
            if(P==Q) break;
        }
    }
    else if(P>Q){
        while(next_permutation(Q.begin(),Q.end())){
            count++;
            if(P==Q) break;
        }
    }
    else{
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	int H, A;
	cin >> H >> A;
	cout << (H + A - 1) / A << endl;
	return 0;
}

Measured memory_bytes: 256
/*    Don’t Quit
    
    When things go wrong as they sometimes will;
        When the road you’re trudging seems all uphill;
            When the funds are low, and the debts are high;
                And you want to smile, but you have to sigh;
                    When care is pressing you down a bit
                        Rest if you must, but don’t you quit.
*/
#pragma gcc optimize ("unroll-loop")
#pragma gcc optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e5+5;
int gcd(int n,int m)
{
    if(n==0)
        return m;
    else
        return gcd(m%n,n);
}
int a[N],b[N],c[N];
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        cin>>a[i];
    }
    if(n==2)
    {
        cout<<2*a[1]<<endl;
        return 0;
    }
    int mn;
    int sum=a[1];

    for(int i=1;i<n-1;i++)
    {
        mn=min(a[i],a[i+1]);
        sum+=mn;
    }
    sum+=a[n-1];
    cout<<sum<<endl;




    
         
}


Measured memory_bytes: 2304
#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 drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    int ans = 0;

    rep(si, h)rep(sj, w){
        if(s[si][sj]=='#') continue;
        vvi dist(h, vi(w, INF));
        queue<P> q;
        
        
        auto update = [&](int i, int j, int x){
            if(dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i, j));
        };
        

        update(si, sj, 0);

        while(!q.empty()){
            int i = q.front().fi;
            int j = q.front().se;
            q.pop();
            rep(dir, 4){
                int di = i + dx[dir];
                int dj = j + dy[dir];
                if(di<0||di>=h||dj<0||dj>=w) continue;
                if(s[di][dj] == '#') continue;
                update(di, dj, dist[i][j]+1);
            }
        }

        rep(i, h)rep(j, w){
            if(dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll h,w; cin>>h>>w;
  vector<string> a(h);
  rep(i, h) cin>>a[i];
  ll cnt = 0;
  rep(i, h) rep(j, w) if (a[i][j] == '#') cnt++;
  if (cnt == h+w-1) cout << "Possible" << endl;
  else cout << "Impossible" << endl;

  return 0;
}


Measured memory_bytes: 3620
using System;

namespace AOJ.Volume0
{
    public class SumOfIntegers
    {
        private static int answer;
        private static int goal;

        private static void Sum(int current, int rest, int now)
        {
            if (current == goal && rest == 0)
            {
                answer++;
                return;
            }
            if (rest == 0) { return; }

            for (int i = now; i <= 9; i++)
            {
                Sum(current + i, rest - 1, i + 1);
            }
            return;
        }

        public static void Main()
        {
            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                int n = int.Parse(input[0]);
                goal = int.Parse(input[1]);
                if (n == 0) { break; }

                answer = 0;
                if (goal <= 45)
                {
                    Sum(0, n, 0);
                }

                Console.WriteLine(answer);
            }
        }
    }
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    sort(all(a));
    sort(rall(b));
    ll ans = 0;
    int m = n/2;
    if (n % 2 == 1) {
        ans = b[m] - a[m] + 1;
    } else {
        int a1, a2, b1, b2;
        a1 = a[m-1];
        a2 = a[m];
        b1 = b[m-1];
        b2 = b[m];
        ans = b1 + b2 - a1 - a2 + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<int,int> P;

int h, w, k;
int ans = MOD;
bool b[800][800];
int dis[800][800];

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

int main(){
    I(h,w, k);
    int sh, sw;
    rep(i,h) rep(j,w){
        char tmp;
        cin >> tmp;
        if(tmp == 'S'){
            sh = i; sw = j;
            b[i][j] = false;
        } else if(tmp == '#'){
            b[i][j] = true;
        } else{
            b[i][j] = false;
        }
    }
    rep(i,h) rep(j,w) dis[i][j] = -1;
    queue<P> que;
    que.push(P(sh, sw));
    dis[sh][sw] = k;
    while(que.size()){
        P q = que.front();
        que.pop();
        int hh = q.first, ww = q.second;
        ans = min(ans, (hh+k-1)/k);
        ans = min(ans, (ww+k-1)/k);
        ans = min(ans, (h-hh-1+k-1)/k);
        ans = min(ans, (w-ww-1+k-1)/k);
        if(dis[hh][ww] == 0) continue;
        rep(i,4){
            int th = hh+dh[i], tw = ww+dw[i];
            if(th < 0 || th >= h || tw < 0 || tw >= w) continue;
            if(dis[th][tw] != -1) continue;
            if(b[th][tw]) continue;
            dis[th][tw] = dis[hh][ww]-1;
            que.push(P(th, tw));
        }
    }
    cout << ans+1 << endl;
}
































Measured memory_bytes: 4480
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>
#include <string>

#include <cfenv>
#include <cmath>
typedef long long int ll;

using namespace std;

int main()
{

    string S, T;

    cin >> S;
    cin >> T;


    if(S.length() +1 == T.length()){

          for(int i=0; i<S.length(); i++){


        if(S[i] != T[i]){


            cout << "No" << endl;
            return 0;
        }
    }




    }
    else{


        cout << "No" << endl;

        return 0;
    }


    cout <<  "Yes" << endl;


    return 0;
  


    





    

    

    
    return 0;
}

Measured memory_bytes: 3556
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>

int main() {

        int a, b;
        std::cin >> a >> b;

        if (a * b % 2 == 0) {
                std::cout << "No" << std::endl;
        }
        else {
                std::cout << "Yes" << std::endl;
        }

        return 0;
}

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

static const int maxn=10000;

struct Node {
  int p,l,r;
};

Node T[maxn];

void preParse(int u) {
  if (u==(-1)) {
    return ;
  }
  cout<<" "<<u<<flush;
  preParse(T[u].l);
  preParse(T[u].r);
}
void inParse(int u) {
  if (u==(-1)) {
    return ;
  }
  inParse(T[u].l);
  cout<<" "<<u<<flush;
  inParse(T[u].r);
}
void postParse(int u) {
  if (u==(-1)) {
    return ;
  }
  postParse(T[u].l);
  postParse(T[u].r);
  cout<<" "<<u<<flush;
}

int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin>>n;
  for (int i=0; i<n; i++) {
    T[i].p=(-1);
  }
  for (int i=0; i<n; i++) {
    int v,l,r;
    cin>>v>>l>>r;
    T[v].l=l;
    T[v].r=r;
    if (l!=(-1)) 
      T[l].p=v;
    
    if (r!=(-1)) 
      T[r].p=v;
    
  }
  int root=0;
  for (int i=0; i<n; i++) {
    if (T[i].p==(-1)) 
      root=i;
  }
  cout<<"Preorder"<<endl;
  preParse(root);
  cout<<endl;
  cout<<"Inorder"<<endl;
  inParse(root);
  cout<<endl;
  cout<<"Postorder"<<endl;
  postParse(root);
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    constexpr int Z = 26;
    string s,t;
    cin >> s >> t;
    vector<vector<int>> vvs(Z,vector<int>());

    REP(i,s.size()) {
        vvs[s[i] - 'a'].emplace_back(i+1);
    }


    bool imp = false;
    ll ans = 0;
    ll loop = 0;
    int c = -1;
    
    REP(i,t.size()) {
        int tp = t[i] - 'a'; 

        if (vvs[tp].size() == 0) {
            imp = true;
            break;
        }

        auto it = upper_bound(ALL(vvs[tp]),c);
        if (it == vvs[tp].end()) {
            loop++;
            // reset
            c = vvs[tp][0];            
        } else {
            c = *it;
        }
    }
    //cerr << loop << endl;
    ans = loop * s.size() + c;

    if (imp) {
        cout << "-1" << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>

unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
	return a % b ? gcd(b, a%b) : b;
}

unsigned long long int lcm(unsigned long long int a, unsigned long long int b) {
	return a * (b / gcd(a, b));
}
int main() {

	int N, M;
	std::cin >> N >> M;
	std::string S, T;
	std::cin >> S;
	std::cin >> T;

	int step = gcd(N, M);
	unsigned long long int L = lcm(N, M);

	bool flag = true;
	for (int i = 0; i < step; ++i) {
		if (S[i*L / M] != T[i*L / N])flag = false;
	}

	if (flag)std::cout << L << std::endl;
	else std::cout << -1 << std::endl;

	//d**n**s**u**s**r**a**y**u**k**u**a**i**i**a**
	//d****u****j****r****u****n****u****m****a****

	return 0;
}


Measured memory_bytes: 512
data Die = Die { numb :: [Int] } deriving (Show)
roll :: Die -> Char -> Die
roll die 'E' = Die [(numb die) !! 3, 
                     (numb die) !! 1,
                     (numb die) !! 0,
                     (numb die) !! 5,
                     (numb die) !! 4,
                     (numb die) !! 2]
roll die 'N' = Die [(numb die) !! 1, 
                     (numb die) !! 5,
                     (numb die) !! 2,
                     (numb die) !! 3,
                     (numb die) !! 0,
                     (numb die) !! 4]
roll die 'S' = Die [(numb die) !! 4, 
                     (numb die) !! 0,
                     (numb die) !! 2,
                     (numb die) !! 3,
                     (numb die) !! 5,
                     (numb die) !! 1]
roll die 'W' = Die [(numb die) !! 2, 
                     (numb die) !! 1,
                     (numb die) !! 5,
                     (numb die) !! 0,
                     (numb die) !! 4,
                     (numb die) !! 3]
roll die _ = die

roll_n :: Die -> String -> Die
roll_n die [] = die
roll_n die [c] = roll die c
roll_n die (c:s) = roll_n (roll die c) s

main = do
  line <- getLine :: IO String
  let arr = map read (words line) :: [Int]
  roll_direction <- getLine
  let first_die = Die {numb = arr }
  print $ head $ numb $ roll_n first_die roll_direction

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  string s;

  cin >> s;

  REP(i, 3) {
    if (s[i] == '9') printf("1");
    else printf("9");
  }
  printf("\n");
}


Measured memory_bytes: 256