akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;
using ll= long long;


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

    long long ans = 0;
    while (X >= 500) {
        X -= 500;
        ans += 1000;
    }
    while (X >= 5) {
        X -= 5;
        ans += 5;
    }
    cout << ans << endl;

    

}

Measured memory_bytes: 256
X = int(input())
if(X>=400 and X<600):
    print("8")
if(X>=600 and X<800):
    print("7")
if(X>=800 and X<1000):
    print("6")
if(X>=1000 and X<1200):
    print("5")
if(X>=1200 and X<1400):
    print("4")
if(X>=1400 and X<1600):
    print("3")
if(X>=1600 and X<1800):
    print("2")
if(X>=1800 and X<2000):
    print("1")

Measured memory_bytes: 9196
import sys
input = sys.stdin.readline
from heapq import *

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x-1, a))
lr = []
cnt = 0

for i in range(n-1):
    ai, aj = a[i], a[i+1]
    
    if ai<aj:
        lr.append((ai+1, aj))
        cnt += aj-ai
    else:
        lr.append((ai-m+1, aj))
        lr.append((ai+1, m-1))
        cnt += m+aj-ai
    
lr.sort(key=lambda t: t[0])
#print(lr)
idx = 0
ans = cnt
decre = 0
pq = []

for i in range(m):
    while len(pq)>0 and pq[0][0]<i:
        r, l = heappop(pq)
        #print(l, r, decre)
        decre -= r-l+1
        
    while idx<len(lr) and i>=lr[idx][0]:
        decre += i-lr[idx][0]
        #print(decre)
        heappush(pq, (lr[idx][1], lr[idx][0]))
        idx += 1
    
    ans = min(ans, cnt-decre)
    decre += len(pq)

print(ans)

Measured memory_bytes: 83796
X, N = map(int, input().split())
try:
  p = list(map(int, input().split()))
except:
  p = []


l = [0]*200

for i in range(N):
  l[abs(p[i] - X)] += 1

#print(p.index(9))

if N == 0:
  print(X)
else:
  for i in range(N+1):
    if i == 0:
      if l[0] == 1:
        continue
      else:
        print(X)
        break
    else:
      if l[i] == 0:
        print(X-i)
        break
      elif l[i] == 1:
        try:
          p_index = p.index(X-i)
          print(X+i)
        except:
          print(X-i)
        break

Measured memory_bytes: 9164
def zalgo(S):
    # SとS[i:n]のlcpの長さを記録した配列を返す
    n = len(S)
    A = [0] * n
    j = 0
    for i in range(1, n):
        if i+A[i-j] < j+A[j]:
            A[i] = A[i-j]
        else:
            k = max(0, A[j]-i+j)
            while i+k < n and S[k] == S[i+k]:
                k += 1
            A[i] = k
            j = i
    A[0] = n
    return A


n = int(input())
S = input()
l = 0
for i in range(n):
    A = zalgo(S[i:])
    B = [min(j, a) for j, a in enumerate(A)]
    l = max(l, max(B))
print(l)


Measured memory_bytes: 61660
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	if(m==n)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.array;
import std.algorithm;
import std.range;
import std.string;
alias println = writeln;
alias print = write;

int readint() {
  return readln.chomp.to!int;
}

void main() {
  if (readint() == 1) {
    println("Hello World");
  } else {
    println(readint() + readint());
  }
}


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

using namespace std;

int main() {
	string o, e;
	cin >> o >> e;

	string ans;
	for (int i = 0; i < o.size(); ++i) {
		
		ans = ans + o[i];
		if (i < e.size()) {
			ans = ans + e[i];
		}
	}
	cout << ans << endl;
}

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 100 * 1000 + 17;

ll n, a[MAXN], b[MAXN], ans;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i];
	for (int i = n; i; i--) {
		a[i] += ans;
		ll t = (a[i] + b[i] - 1) / b[i];
		t *= b[i];
		ans += t - a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std; 

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

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

	for(auto i:m){
		if(i.ss>=2){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
}

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll N; cin >> N;
	map<ll, ll> m;
	REP(i, N)
	{
		ll a; cin >> a;
		++m[a];
	}

	if (m.size() & 1)
		std::cout << m.size() << std::endl;
	else
		std::cout << m.size() - 1<< std::endl;
}

Measured memory_bytes: 6528
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		String ans = "YES";

		Arrays.sort(a);

		for (int i = 0; i < n - 1; i++) {
			if (a[i] == a[i + 1]) ans = "NO";
		}

		System.out.println(ans);

		scan.close();
	}
}


Measured memory_bytes: 64868
N = int(input())
H = list(map(int, input().split()))

for i in range(1, N):
	if H[N-i-1] > H[N-i]:
		H[N-i-1] -= 1
	
for i in range(N-1):
	if H[i] > H[i+1]:
		print("No")
		exit(0)

print("Yes")


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


// ABC118A - B +/- A
// https://atcoder.jp/contests/abc118/tasks/abc118_a
void ABC118A() {
	int A, B;
	cin >> A >> B;

	if (B % A == 0) {
		cout << A + B;
	}
	else {
		cout << B - A;
	}
}

int main() {
	ABC118A();

	return 0;
}


Measured memory_bytes: 256
n,a,b,*h=map(int,open(0).read().split());i,j=0,2**30
while j-i>1:
 k=c=(j+i)//2
 for t in h:c+=min(0,(b*k-t)//(a-b))
 if c<0:i=k
 else:j=k
print(j)

Measured memory_bytes: 14092
n,m = map(int,input().split())
arr = list(map(int,input().split()))

bod = sum(arr)/(4*m)

arr.sort(key=lambda x:-x)

flag = True
for i in range(m):
    if arr[i] < bod:
        flag = False


if flag:
    print("Yes")
else:
    print("No")

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

using namespace std;

const long long MOD = 1e9+7;

long long fact[200005];

long long modpow(int a, int b){
	if(b == 0){
		return 1;
	}else if(b == 1){
		return a%MOD;
	}else if((b%2) == 0){
		long long temp = modpow(a, b/2);
		return temp*temp%MOD;
	}else{
		long long temp = modpow(a, b/2);
		return ((temp*temp%MOD) * a)%MOD;
	}
}

long long ncr(int i, int j){
	return fact[i]*modpow((fact[i-j]*fact[j])%MOD, MOD-2)%MOD;
}

int main(){
	int N, A, B, C;
	scanf("%d%d%d%d", &N, &A, &B, &C);
	
	long long Q = modpow(A+B, 2*N)%MOD;
	
	fact[0] = 1;
	for(int i = 1; i <= 2*N; i ++){
		fact[i] = (fact[i-1] * i) % MOD; 
	}
	
	long long P = 0;
	for(int M = N; M < 2*N; M ++){
		long long ncr1 = ncr(M-1, N-1);
		long long temp = M*(modpow(A, N)*modpow(B, M-N)%MOD + modpow(A, M-N)*modpow(B, N)%MOD) %MOD * ncr1%MOD * modpow(A+B, 2*N-1-M)%MOD * 100 %MOD;
		P += temp;
		//printf("%d %lld\n", i, temp);
	}
	
	P = P%MOD;
	//printf("%lld %lld\n", P, Q);
	
	long long R = P*modpow(Q, MOD-2)%MOD;
	
	printf("%lld", R);
	
	return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if (s.length() == 1) {
    cout << 0 << endl;
  } else {
    int r_cnt = 0;
    int b_cnt = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '0') r_cnt++;
      if (s[i] == '1') b_cnt++;
    }
    cout << min(r_cnt, b_cnt) * 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

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

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

    long long res = 1LL << 61;
    for (long long i = 0, l = a[0], r = accumulate(a.begin() + 1, a.end(), 0LL); i < n - 1; i++, l += a[i], r -= a[i]) {
        res = min(res, l > r ? l - r : r - l);
    }

    cout << res << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        auto table = make_v(10, 10, 0LL);

        FOR(i, 1, n + 1) {
                string s = to_string(i);
                int p = s[0] - '0', q = s[s.size() - 1] - '0';
                table[p][q]++;
        }

        ll ans = 0;
        REP(i, 10)REP(j, 10) {
                ans += table[i][j] * table[j][i];
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	long long  a,b,c,d=0;
	scanf("%lld%lld%lld",&a,&b,&c);
	//printf("%d %d %d %d",(4*a*b),(c*c),(2*c)*(a*b),(a*b)*(a*b));
	d=c*c;
	d+=(a+b)*(a+b);
	d-=(2*c)*(a+b);
	if(4*(a*b)<d){
		if(c-(a+b)>0){
		printf("Yes");
	}else{
			printf("No");
	}
	}else{
		printf("No");
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair
#define sz size
#define inf 1e9+5
 
 
int main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    ll flag=0;
    for(ll i=0;i<s.length();i++)
    {
        if(i%2==0){
            if(s[i]=='L')flag=1;
        }else{
            if(s[i]=='R')flag=1;
        }
    }
    if(flag)cout<<"No";
    else
        cout<<"Yes";
    return 0;  
}

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

#define mp make_pair
#define pb push_back
#define fiint(a) memset(a,0,sizeof(a))

typedef long long ll;
typedef long double ld;

ll func(ll arr[],ll n, ll mid)
{
    if (mid == 0) return INT_MAX;
    ll ans = 0;
    for (ll i=0;i<n;i++)
    {
        ans+= (arr[i]-1)/mid;
    }
    //cout<<mid<<" "<<ans<<"\n";
    return ans;
}


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n,k; cin>>n>>k;

    ll arr[n]; for(ll i=0;i<n;i++) cin>>arr[i];


    ll low = 0, high = 1e9+10;
    while(low<high)
    {
        ll mid = low+(high-low)/2;
        ll cut = func(arr,n,mid);

        if(cut>k) low = mid+1;
        else high = mid;

    }
    cout<<low<<"\n";

    return 0;
}




Measured memory_bytes: 5192
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  string s;
  cin >> s;
  int n = s.size();
  string tmp;
  REP(i,n){
    if(s[i] == 'B'){
      if(tmp.size() >= 1){
	tmp = tmp.erase(tmp.size() - 1);
      }
    }else{
      tmp += s[i];
    }
  }
  cout << tmp << endl;
} 



Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int a,b,c,temp,i,ob=0,ac=0,ri=0,cosA;
    for (i=0; ; i++) {
        scanf("%d%d%d",&a,&b,&c);
        if (b>a) {
            temp=b;
            b=a;
            a=temp;
        }
        if (c>a) {
            temp=c;
            c=a;
            a=temp;
        }
        if (b+c<=a) break;
        cosA=b*b+c*c-a*a;
        if (cosA>0) {
            ac++;
        } else if (cosA<0) {
            ob++;
        } else {
            ri++;
        }
    }
    printf("%d %d %d %d\n",i,ri,ac,ob);
    return 0;
}

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

typedef long long ll;

int main(){
    ll n;
    cin>>n;
    
    int ans = 0, prev;

    int b[n-1];

    for(int i=0;i<n-1;i++){
        cin>>b[i];
        if(i == 0){
            ans += b[i] + b[i];
            prev = b[i];
            continue;
        }
        if(b[i] < prev){
            ans -= prev;
            ans += b[i] + b[i];
            prev = b[i];
        }
        else{
            ans += b[i];
            prev = b[i];
        }   
    }
    cout<<ans<<endl;
}

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

int main() {
  float r, g;
  cin >> r >> g;
  cout << (2 * g - r) << endl;
  return 0;
}

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

int main(){

  int x;
  cin>>x;

  int h = x / 3600;
  int m = (x / 60) % 60;
  int s = x % 60;
  cout<<h<<":"<<m<<":"<<s<<endl;

  
  return 0;
}
  


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

int main(){
    string s;
    cin>>s;
    set<char> set;
    for(int i=0;i<3;i++){
        set.insert(s[i]);
    }
    if(set.size()==3)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool palin(int a) {
  if ((a % 10) == (a / 10000) && ((a / 10) % 10) == (a / 1000) % 10) return 1;
  return 0;
}

int main() {
  int a, b, ans = 0;
  cin >> a >> b;
  for (int i = a; i <= b; ++i) if (palin(i)) ans += 1;
  cout << ans << '\n';
  return 0;
}

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

template <int MOD> struct ModInt {
    static const int Mod = MOD;
    unsigned x;
    ModInt() : x(0) {}
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) {
        if ((x += that.x) >= MOD)
            x -= MOD;
        return *this;
    }
    ModInt &operator-=(ModInt that) {
        if ((x += MOD - that.x) >= MOD)
            x -= MOD;
        return *this;
    }
    ModInt &operator*=(ModInt that) {
        x = (unsigned long long)x * that.x % MOD;
        return *this;
    }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const {
        long long a = x, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            std::swap(a, b);
            u -= t * v;
            std::swap(u, v);
        }
        return ModInt(u);
    }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const {
        ModInt t;
        t.x = x == 0 ? 0 : Mod - x;
        return t;
    }
};
template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) {
    st << a.get();
    return st;
};
template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1;
    while (k) {
        if (k & 1)
            r *= a;
        a *= a;
        k >>= 1;
    }
    return r;
}
using mint = ModInt<(int)1e9 + 7>;

// https://www.hamayanhamayan.com/entry/2020/04/12/225411
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<mint> cnt(K + 1);
    for (int g = K; g >= 1; g--) {
        // ^ は XORではなくpower
        cnt[g] = mint(K / g) ^ N;
        int gg = g * 2;
        while (gg <= K) {
            cnt[g] -= cnt[gg];
            gg += g;
        }
    }
    mint ans = 0;
    FOR(i, 1, K + 1) { ans += cnt[i] * i; }
    cout << ans << endl;

    return 0;
}


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

#define MAX_N 101
#define MAX_VALUE 100001 // 10^3 * 100 is max value that sum of values can be
#define MAX 1000000001
typedef long long ll;

ll n, w;
ll V[MAX_N], W[MAX_N];
ll dp[MAX_N][MAX_VALUE]; // holds the minimum weight needed to get that value

int main()
{
    cin >> n >> w;
    for(int j = 0; j < n; j++){
        cin >> W[j] >> V[j];
    }

    for(int i = 0; i < MAX_N; i++){
        for(int j = 0; j < MAX_VALUE; j++){
            dp[i][j] = MAX;
        }
    }

    dp[0][0] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < MAX_VALUE; j++){
            if(j-V[i-1] >= 0){
                dp[i][j] = min(dp[i-1][j-V[i-1]] + W[i-1], dp[i-1][j]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    ll ans = 0;
    for(int i = MAX_VALUE-1; i >= 0; i--){
        if(dp[n][i] <= w){
            ans = i;
            break;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
#define N 3010
ll dp[N][N],flag[N][N],n,m;
char a[N],b[N];
int main(){
	cin>>a+1>>b+1;
	n=strlen(a+1),m=strlen(b+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i][j]=dp[i-1][j];flag[i][j]=1;
			if(dp[i][j-1]>dp[i][j]){dp[i][j]=dp[i][j-1];flag[i][j]=2;}
			if(dp[i-1][j-1]+1>dp[i][j]&&a[i]==b[j]){dp[i][j]=dp[i-1][j-1]+1;flag[i][j]=3;}
		}
	}
	ll nowi=n,nowj=m;
	string ans="";
	while(nowi&&nowj){
		ll p=flag[nowi][nowj];
		if(p==1)nowi--;
		else if(p==2)nowj--;
		else ans+=a[nowi],nowi--,nowj--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    string S,T;
    cin >> S >> T;
    int cnt = 0;
    for(int i=0;i<S.size()-T.size()+1;i++){
        int tmp = 0;
        for(int j=0;j<T.size();j++){
            if(S[i+j]==T[j])tmp++;
        }
        cnt = max(cnt,tmp);
    }
    cout << T.size()-cnt << endl;
    return 0;
}

Measured memory_bytes: 3624
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("avx2")
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>
#include <numeric>

using namespace std;
#define open_streams ifstream fin("olympiad.in");ofstream fout("olympiad.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define UNIQ(a) a.resize(unique(all(a)) - a.begin())
#define eps 1e-6
//const double PI = M_PI;
const int INF = INT_MAX;
const ll limit = 1LL * 1e18;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
//---------------------------------------------------------------------------
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;




signed main() {
	speed;
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(rall(a));
	ll ans = 0;
	vector<int> used(n);
	used[0] = 1;
	int last = 0;
	for (int i = 0; i < n; ++i) {
		if (!i) {
			continue;
		}
		if (used[last] < 2) {
			ans += a[last];
		}
		else {
			ans += a[++last];
		}
		used[last]++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4740
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0);}



int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int& x : a)
        cin >> x;
        
    int mx = *max_element(begin(a), end(a));
    int mn = *min_element(begin(a), end(a));
    if (mx > -mn)
    {
        cout << 2 * n - 2 << endl;
        int idx = max_element(a.begin(), a.end()) - a.begin();
        cout << idx + 1 << ' ' << n << '\n';
        cout << idx + 1 << ' ' << n << '\n';
        for(int i = 2; i < n; ++i)
        {
            cout << n << ' ' << i << endl;
            cout << n << ' ' << n << endl;
        }
    }
    else
    {
        cout << 2 * n - 2 << endl;
        int idx = min_element(a.begin(), a.end()) - a.begin();
        cout << idx + 1 << ' ' << 1 << '\n';
        cout << idx + 1 << ' ' << 1 << '\n';
        for(int i = n - 1; i >= 2; --i)
        {
            cout << 1 << ' ' << i << endl;
            cout << 1 << ' ' << 1 << endl;
        }
    }
}       

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s;
    cin >> s;


    int f=-1,e=-1;
    bool aPaici=false;
    for(int i=0; i<SZ(s) ; i++){
        if( !aPaici && s[i]=='A'){
            f=i;
            aPaici=true;
        }
        if(s[i]=='Z'){
            e=i;
        }
    }

    //cout << f <<" "<<e<<endl;

    if(f==-1 || e==-1) cout << 0 << endl;
    else cout << e-f+1<< endl;
    return 0;
}


Measured memory_bytes: 720
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n = int(input())
	ddd=[]
	for _ in range(n):
		a,b=IN()
		ddd.append([a,b])
	ddd=sorted(ddd, key=lambda vv : vv[1])
	cc=0
	for a,b in ddd:
		#print(cc,a,b)
		cc += a
		if cc > b:
			return 'No'
		
	return 'Yes'
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 89432
s=(input())
s1=int(s[:2])
s2=int(s[2:])
 
if 1<= s1 <=12 and 1<= s2 <= 12:
    print("AMBIGUOUS")
 
elif 0<= s1 <=99 and 1<= s2 <= 12:
    print("YYMM")
 
elif 1<= s1 <=12 and 0<= s2 <= 99:
    print("MMYY")
 
else:
    print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i=0; i<2; ++i) {
    if(s[i] == s[i+1] && s[i] == s[i+2]){
      cout << "Yes" << endl;
      return 0;
    }
  };
  cout << "No" << endl;
}

Measured memory_bytes: 3540
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

s=input()
t=input()
c=0
for i in range(3):
  if s[i]==t[i]:
    c+=1
print(c)

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

#define ll long long int
#define db double
#define fl float
#define endl '\n'

#define mod (ll)(1000000007)
#define mod1 (ll)998242353
#define mod2 (ll)998244353
#define PI 3.1415926535897932384626433832795

#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pob pop_back

#define Sort(v) sort(v.begin(),v.end())
#define Sortd(v) sort(v.begin(),v.end(),greater<>())

#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define rf(i,n) for(int i=n-1;i>=0;--i)
#define rf1(i,n) for(int i=n-1;i>=1;--i)
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repn(i,a,b) for(int i=a;i<=b;++i)

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;

//nC2
ll C2(ll n){
    ll ans= max(((n*(n-1))/2),(ll)0);
    return ans;
}
//square
ll sq(ll n){
    return n*n;
}

//GCD
ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    if(b==0){
        return a;
    }    
    else{
        return gcd(b,a%b);
    }
}

//LCM
ll lcm(ll a,ll b){
    if(a==0 || b==0){
        return 0;
    }
    else{
        return((ll)((a*b)/gcd(a,b)));
    }
}

//sort pair by second values
bool sortsec(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.second < b.second); 
}
//sort pair by first vals in descending
bool sortinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.first > b.first); 
} 

//Binary Exponentiation
ll BinExp(ll a, ll b, ll m){
    a%=m;
    ll res =1;
    while(b>0){
        if(b&1){
            res = (res * a)%m;
        }
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}


int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin>>s;
    int ans=0;
    if(s[1]!='R'){
        if(s[0]=='R' || s[2]=='R')cout<<1<<endl;
        else cout<<0<<endl;
    }
    else{
        if(s[0]=='R' && s[2]=='R')cout<<3<<endl;
        else if(s[0]=='R' || s[2]=='R')cout<<2<<endl;
        else cout<<1<<endl;
    }
    


    return 0;
}



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

#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOD(i,b,a) for(i=a;i>=b;i--)
#define pa pair<int,int>
#define fi first
#define se second
#define task "x"

typedef long long ll;
const ll M=1e6+1;
const ll N=1e4+1;
using namespace std;

ll i, j, n, ans = 0;
string s;

void input()
{
    cin >> s ;

}

void solve()
{ j = 0, ans =0;
  s = s+ '!';
    FOR(i,0,s.size()-1)
    {
      if(s[i] == 'R') j++;
      else{ ans = max(ans,j);j = 0;}
    }
    cout<<ans;
}

int main()
{
  	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	if(fopen(task".inp","r"))
        {
 	  freopen(task".inp","r",stdin);
 	  freopen(task".out","w",stdout);
	}
	input();
	solve();

   return 0;
}


Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner s = new Scanner(System.in);
          double x = Double.parseDouble(s.next());
          double money = 100;
          int count = 0;
      	while(x > money) {
          money *= 1.01;
          money = Math.floor(money);
          count++;
        }

      	System.out.println(count);
    }
}

Measured memory_bytes: 35736
#include <iostream>
#include <math.h>
#include <map>
using namespace std;
int p,q,a,b; double s;
int main() {
    scanf("%d%d",&a,&b);
    p=a/b;
    q=a%b;
    s=(double)a/(double)b;
    printf("%d %d %f\n",p,q,s);
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define chk(a) rep(i, a.size()) cout << a[i] << " "
#define SORT(c) sort((c).begin(),(c).end())
#define ll long long
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)


using namespace std;
typedef pair<int, int> pii;

string itos(int i) {
	ostringstream s;
	s << i;
	return s.str();
}

int main(void) {
	int n, k;
	cin >> n >> k;
	set<char> v;
	rep(i, k) {
		int lll;
		cin >> lll;
		v.insert(itos(lll)[0]);
	}

	while (1) {
		auto isok = true;
		string tmp = itos(n);
		rep(i, tmp.length()) {
			if (v.count(tmp[i]) != 0) {
				isok = false;
				break;
			}
		}
		if (isok) {
			cout << n << endl;
			break;
		}
		n++;
	}

	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()

	cnt := 0
	num := 1
	for num < b {
		num += (a - 1)
		cnt++
	}
	fmt.Println(cnt)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1772
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	m := n
	d := 0
	for n != 0 {
		d += n % 10
		n /= 10
	}
	if m%d == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define foi(i,a,n) for(i = (a); i <= (n); i++)
#define pd(x) cout<<x
#define sd(x) cin>>x
#define nl cout<<endl
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//ll fibonacci[2][2] = {{0,1},{1,1}};
//ll identity[2][2] = {{1,0},{0,1}};

ll n,m;
vll v;

bool poss(ll val) {
	ll lo = 2*val, hi = 2*n-1;
	while(lo < hi) {
		if (v[lo] + v[hi] < m) return false;
		lo++; hi--;
	}
	return true;
}


int main() {
	ll i,j,k;
	cin>>n>>m;
	v.resize(2*n);
	fo(i,0,2*n) cin>>v[i];
	sort(all(v));
	ll lo = -1, hi = n;
	while (hi-lo > 1) {
		ll mid = ((lo+hi)/2);
		if (poss(mid)) {
			hi = mid;
		} else {
			lo = mid+1;
		}
	}
	ll val = (poss(lo)?lo:hi);
	ll ans = -INFLL;
	lo = 0; hi = 2*val - 1;
	while(lo < hi) {
		ans = max(ans, (v[lo++]+v[hi--])%m);
	}
	lo = 2*val; hi = 2*n-1;
	while(lo < hi) {
		ans = max(ans, (v[lo++]+v[hi--])%m);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    
    void calc()
    {
        if (calc2()) Console.WriteLine("POSSIBLE");
        else Console.WriteLine("IMPOSSIBLE");
    }

    bool calc2()
    {

        cin = new Scanner();
        int N, K;
        N = cin.nextInt();
        K = cin.nextInt();
        int[] A = new int[N];
        long g = A[0];
        long max = 0;
        for (int i = 0; i < N; i++)
        {
            A[i] = cin.nextInt();
            g = gcd(g, A[i]);
            max = Math.Max(max, A[i]);
        }
        return (max >= K) && (K % g == 0);
    }

    long gcd(long a, long b)
    {
        if (b == 0) return a;
        return gcd(b, a % b);
    }




}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();

        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}

const ll INF=1e9+1;
int dx[4]={1,0,0,-1};
int dy[4]={0,-1,1,0};
 
bool inbounds(int x,int y,int n,int m)
{
  return (x>=0&&x<n&&y>=0&&y<m);
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    int n,m,s1,s2,f1,f2;
    cin>>n>>m>>s1>>s2>>f1>>f2;
    s1--;s2--;
    f1--;f2--;

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

    int dist[n][m];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i==f1 && j==f2)
                dist[i][j]=0;
            else
                dist[i][j]=INF;
        }
    }

    deque<pair<int,int>> dq;
    dq.push_back({f1,f2});

    while(!dq.empty())
    {
        int x0=dq.front().first,y0=dq.front().second;
        dq.pop_front();

        for(int i=0;i<4;i++)
        {
            int x=x0+dx[i],y=y0+dy[i];
            if(inbounds(x,y,n,m) && s[x][y]!='#' && dist[x][y]>dist[x0][y0])
            {
                dist[x][y]=dist[x0][y0];
                dq.push_front({x,y});
            }
        }

        for(int i=-2;i<=2;i++)
        {
            for(int j=-2;j<=2;j++)
            {
                int x=x0+i,y=y0+j;
                if(inbounds(x,y,n,m) && s[x][y]!='#' && dist[x][y]>dist[x0][y0]+1)
                {
                    dist[x][y]=dist[x0][y0]+1;
                    dq.push_back({x,y});
                }
            }
        }
    }

    if(dist[s1][s2] == INF)
        cout<<-1<<endl;
    else
        cout<<dist[s1][s2]<<endl;
    
    return 0;
}

Measured memory_bytes: 8620
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(i*j == n){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var W = parseInt(input[0].split(" ")[1]);
  var V = new Array(W);
  for(var i=0;i<N+1;i++){
    tmp=new Array(W+1).fill(0);
    V[i]=tmp;
  }
  var w = new Array(N);
  var v = new Array(N);
  for(var i=0;i<N;i++){
    tmp=input[i+1].split(" ");
    w[i] = parseInt(tmp[0]);
    v[i] = parseInt(tmp[1]);
  }
  var ans =0;
  for(var i=1;i<N+1;i++){
    for(var j=0;j<W+1;j++){
      if(w[i-1]<=j){
        V[i][j]=Math.max(V[i-1][j-w[i-1]]+v[i-1],V[i-1][j]);
      }else{
        V[i][j]=V[i-1][j];
      }
      ans=Math.max(ans,V[i][j]);
    }
  }

  console.log('%s', ans);
  return ans;
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 189328
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
/*-*/

int main() {
	lnt a; std::string b;
	std::cin >> a >> b;
	std::string c;
	for(char x:b) if(x!='.') c+=x;
	a*=std::stoi(c);
	print(a/(lnt)100);
}


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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

struct Edge {
    int to, cost;
};
vector<Edge> G[100];

typedef pair<int,int> P;

int min_cost(int s, int t, int n) {
    int d[100];
    fill(d, d+100, 1e9);

    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    int cnt = 0;
    while ( ! que.empty()) {
        P p = que.top(); que.pop();
        if (d[p.second] <= p.first) continue;
        d[p.second] = p.first;
        if (++cnt >= n) break;
        for (Edge &e: G[p.second]) {
            if (d[e.to] > p.first + e.cost) {
                que.push(P(p.first + e.cost, e.to));
            }
        }
    }

    return (d[t] == 1e9 ? -1 : d[t]);
}

void reset() {
    for (int i=0; i<100; ++i) G[i].clear();
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    rdfile("_input.txt");

    int n, k;
    while (cin >> n >> k) {
        if (n == 0) break;

        reset();

        int f, a, b, c;
        for (int i=0; i<k; ++i) {
            cin >> f;
            if (f == 0) {
                cin >> a >> b;
                a--; b--;
                cout << min_cost(a, b, n) << endl;
            } else {
                cin >> a >> b >> c;
                a--; b--;
                G[a].push_back((Edge){ b, c });
                G[b].push_back((Edge){ a, c });
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    string a, b;
    cin >> a >> b;
    string x = "Yes";
    for (int i = 0; i < a.size(); i++) {
        if (a.at(i) != b.at(i))x = "No";
    }
    cout << x << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(x) (x).begin(),(x).end()

int main () {
  int n, x;
  vector<int> xs;
  int mymin = INT_MAX;

  cin >> n;

  REP(i, n) {
    cin >> x;
    xs.push_back(x);
  }

  auto mymax = max_element(ALL(xs));
  REP(i, *mymax) {
    int acc = 0;

    REP(j, n) {
      acc += ((xs[j] - (i+1)) * (xs[j] - (i+1)));
    }

    mymin = min(mymin, acc);
  }

  cout << mymin << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P){
  int i = 0,j;
  for(j = 0; j < k; j++){
    llong s = 0;
    while(s + T[i]<=P){
      s += T[i];
      i++;
      if(i==n) return n;
    }
  }
  return i;
}

int solve(){
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while(right - left > 1){
    mid = (left + right) / 2;
    int v = check(mid);
    if(v >=n) right = mid;
    else left = mid;
  }
  return right;
}

int main(){
  int i;
  scanf("%d%d",&n,&k);
  for(i = 0; i<n;i++) scanf("%d",&T[i]);
  llong ans = solve();
  printf("%d\n",ans);  
    return 0;
    
}


Measured memory_bytes: 2540
using System;

class quiz
{
    public int solve(int[] AB)
    {
        if (AB[1] % AB[0] == 0)
            return (AB[0] + AB[1]);
        else
            return (AB[1] - AB[0]);
    }

    public int[] ParseIntBySpace(string str)
    {
        int[] array = new int[str.Length];
        int lastloc = 0, spaceloc = -1;

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == ' ')
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc - 1));
                spaceloc = i;
            }
            else if (i == str.Length - 1)
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc));
            }
        }

        Array.Resize(ref array, lastloc);

        return array;
    }
}

class Example
{
    static void Main()
    {
        quiz ex = new quiz();

        Console.WriteLine(ex.solve(ex.ParseIntBySpace(Console.ReadLine())));
    }
}

Measured memory_bytes: 13140
N, M = map(int, input().split())

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

to = [[] for i in range(N)]

for i in range(M):
    A, B = map(int, input().split())

    to[A-1].append(B-1)
    to[B-1].append(A-1)

ans = 0
for i in range(N):
    flg = True
    if len(to[i]) == 0:
        ans += 1
        continue
    else:
        for j in to[i]:
            if H[j] >= H[i]:
                flg = False

        if flg:
            ans += 1

print(ans)

Measured memory_bytes: 92732