akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if (w > v) {
        cout << "NO" << endl;
    } else {
        if (llabs(v-w)*t >= llabs(a-b))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

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

  vector<string> s(N), a(N);
  vector<int> st(N), at(N);
  for(int i=0; i<N; i++) {
    char b1[128], b2[128];
    int h1, h2, m1, m2;

    scanf(" %d:%d %s %d:%d %s", &h1, &m1, b1, &h2, &m2, b2);
    s[i] = b1, a[i] = b2;
    st[i] = 60 * h1 + m1;
    at[i] = 60 * h2 + m2;
  }

  vector<string> c;
  vector<int> ct;
  for(int i=1; i<N; i++) {
    int diff = st[i] - at[i-1];
    if(diff >= T) {
      c.push_back(s[i]);
      ct.push_back(diff);
    }
  }

  cout << c.size() << endl;
  for(size_t i=0; i<c.size(); i++) {
    cout << c[i] << " " << ct[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3268
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> p(N+1);
    for(int i=0; i<N; i++) {
        cin >> A[i];
        p[A[i]] = i;
    }
    for(int i=1; i<=N; i++) {
        cout << p[i]+1 << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;

int main() {
  int n,m,k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);

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

  long long t = 0;
  for(int i = 0; i < m; i++){
    t += b[i];
  }

  int j = m;
  int ans = 0;
  for(int i = 0; i < n+1; i++){
    while(j > 0 && t > k){
      --j;
      t -= b[j];
    }
    if(t > k) break;
    ans = max(ans, i+j);
    if(i == n) break;
    t += a[i];
  }
  cout << ans << endl;
  return 0;
 }

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

int main() {
	vector<char> o(9);
	rep(i, 9) {
		cin >> o.at(i);
	}
	cout << o.at(0) << o.at(4) << o.at(8) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    int m,f,r;
    while(1){
        cin>>m>>f>>r;if(m==-1)
        if(m==-1&&f==-1&&r==-1) break;
        if(m==-1||f==-1) cout<<'F'<<endl;
        else{
            if(m+f>=80) cout<<'A'<<endl;
            else if(65<=m+f&&m+f<80) cout<<'B'<<endl;
            else if((50<=m+f&&m+f<65)||r>=50) cout<<'C'<<endl;
            else if(30<=m+f&&m+f<50) cout<<"D"<<endl;
            else cout<<'F'<<endl;
        }
    }
}


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

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

typedef long long ll;

using namespace std;

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

  // 問題に対するAC済み,WA数
  map<int, pair<bool, int>> tmpResult;
  rep(i, M) {
    int p;
    string S;
    cin >> p >> S;

    // AC
    if (S[0] == 'A') {
      if (!tmpResult[p].first) {
        tmpResult[p].first = true;
      }
    } else {
      // WA
      if (tmpResult[p].first) {
        // 処理なし
      } else {
        tmpResult[p].second++;
      }
    }
  }

  int ac = 0;
  int wa = 0;
  for (auto it : tmpResult) {
    if (it.second.first) {
      ac++;
      wa += it.second.second;
    }
  }

  cout << ac << " " << wa << endl;

  return 0;
}


Measured memory_bytes: 6528
allmember = Hash.new
3.times do
    member = Hash.new
    fast_time1 = 10000
    fast_time2 = 100000
    8.times do
        x = gets
        y = x.split(" ")
        id = y[0].to_i
        time = y[1].to_f
        if time < fast_time1
            fast_time2 = fast_time1
            fast_time1 = time
        elsif time < fast_time2
            fast_time2 = time
        end
        member.store(id,time)
        allmember.store(id,time)
    end
    winner1 = member.find{|k,v| v == fast_time1}
    winner2 = member.find{|k,v| v == fast_time2}
    puts "#{winner1[0]} #{winner1[1]}"
    puts "#{winner2[0]} #{winner2[1]}"

    allmember.delete(winner1[0])
    allmember.delete(winner2[0])
    
end

ds = allmember.min{ |x, y| x[1] <=> y[1] }
puts "#{ds[0]} #{ds[1]}"
allmember.delete(ds[0])

za =  allmember.min{ |x, y| x[1] <=> y[1] }
puts "#{za[0]} #{za[1]}"




Measured memory_bytes: 6884
#!/usr/bin/perl

my ($n,$k) = map {$_ - 0} split(/\s+/o,<STDIN>);
my $s = <STDIN>;

my %c = ( 'A'=>'a', 'B'=>'b', 'C'=>'c' );

my $c1 = substr($s,$k-1,1);
substr($s,$k-1,1) = $c{$c1};

print "$s";

exit(0);




Measured memory_bytes: 512
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()

    m = {}
    m['ABC'] = True
    def f(s):
        if s in m:
            return m[s]
        t = s.replace('ABC', 'x')
        if s == t:
            m[s] = False
            return False
        for c in 'ABC':
            if c in t:
                continue
            if f(t.replace('x',c)):
                return True
        m[s] = False
        return False

    if f(s):
        return 'Yes'

    return 'No'


print(main())




Measured memory_bytes: 24560
#include <iostream>
using namespace std;
 
int main() {
    int N,cnt=0;
    cin >> N;
 
    for (int i=1; i<=N;  i++) {
        if (i % 2 == 1) {
            int c = 0;
            for (int j=1; j<=i; j++) {
                if (i % j == 0) c++;
            }
            if (c == 8) cnt++;
        }
    }
 
    cout << cnt << endl;
    return 0;
}

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

int main (){
int a,b,c;
cin>>a>>b>>c;
if(a>b){
if(a>c&&b<c) cout <<"Yes"<<endl;
else cout << "No"<<endl;
}
if(a<b){
if(a<c&&b>c) cout <<"Yes"<<endl;
else cout << "No"<<endl;
}
return 0;
}


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

int main(){
	int n;
	scanf("%d", &n);
	long dp0 = 0, dp1 = 0, dp2 = 0;
	for(int i = 0; i < n; i++) {
		long n;
		scanf("%ld", &n);
		long t1 = max(dp0, dp1) + n;
		scanf("%ld", &n);
		long t2 = max(dp1, dp2) + n;
		scanf("%ld", &n);
		dp1 = max(dp2, dp0) + n;
		dp2 = t1;	dp0 = t2;
	}
	printf("%ld\n", max(dp0, max(dp1, dp2)));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
#define mx 1000000000
#define mod 1000000009
#define pii pair<int,int>
#define psi pair<string,int>
#define vi vector<int>
typedef long long ll;
using namespace std;
void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("inputf.txt", "r", stdin);
    freopen("outputf.txt", "w", stdout);
#endif
    fastio();
    int i,j,t,n,m,r;
    //cin>>t;
    //while(t--){
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)cin>>a[i];
    int c=1;
    int mn=a[0];
    for(i=1;i<n;i++){
      if(a[i]<mn){
        c++;
        mn=a[i];
      }
    }
    cout<<c<<endl;
    //}
 return 0;
}



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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    string s;
    cin >> s;
    int cur=0;
    rep(i, s.size()) cur += (s[i] == '+' ? 1 : -1);
    cout << cur << endl;
}


Measured memory_bytes: 256
/**
*    author:  souzai32
*    created: 13.08.2020 13:57:44
**/

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

int main() {

    int n;
    string s;
    cin >> n >> s;
    bool x,y,z;
    int ans=0;

    rep(i,10){
        rep(j,10){
            rep(k,10){
                x=false; y=false; z=false;
                for(int l=0; l<s.size(); l++){
                    if(!x && s.at(l)-'0'==i) x=true;
                    else if(!y && x && s.at(l)-'0'==j) y=true;
                    else if(y && s.at(l)-'0'==k) z=true;
                }
                if(z){
                    ans++;
                    // cout << i << j << k << endl;
                }
                //  cout << i << j << k << endl;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ff first
#define ss second

long long prime_fac(long long n, vector<pair<long long, long long> >&l){
  long long s = floor(sqrt(n));
  long long r;
  pair<long long, long long> x;
  for(long long i=2; i<=s; i++){
    if(n%i==0){
      r=0;
      do{
        r++;
        n /= i;
      }while(n%i==0);
      x = make_pair(i, r);
      l.push_back(x);
    }
  }

  if(n>s){
    x = make_pair(n, 1);
    l.push_back(x);
  }

  return l.size();
}

ll counter(ll n){
  ll ans = 0;
  for(ll i=1; i<=n; i++){
    n -= i;
    ans++;
  }
  return ans;
}

int __main(){
  int a;cin>>a;
  cout<<counter(a)<<endl;
}

int main(){
  ll N;cin>>N;
  vector<pair<long long, long long> >l;
  prime_fac(N, l);

  ll ans = 0;
  for(pair<long long, long long>x: l){
    ans += counter(x.ss);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
int N, t[55], ans;
string s[55], X;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s[i] >> t[i];
  }
  cin >> X;
  for (int i = N - 1; i >= 0; i--) {
    if (s[i] == X) break;
    ans += t[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
W, H, x, y, r = map(int, input().split())

x1 = x-r
x2 = x+r
y1 = y-r
y2 = y+r

flag = 1

if x1 < 0:
    flag = 0

if x2 > W:
    flag = 0

if y1 < 0:
    flag = 0

if y2 > H:
    flag = 0

if flag < 1:
    print("No")

else:
    print("Yes")
    


Measured memory_bytes: 5596
readlines.each do |l|
	output_str = Array.new
	input_ary = l.chomp.split('')
	counter = 0
	0.upto(input_ary.size-1) do |i|
		if counter > 0
			counter -= 1
			next
		end
		if input_ary[i] == '@'
			n = input_ary[i+1].to_i
			c = input_ary[i+2]
			n.times{output_str << c}
			counter = 2
		else
			output_str << input_ary[i]
		end
	end
	puts output_str.join
end

Measured memory_bytes: 6108
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
immutable long MOD = 1000000007;
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    long S;
    S = input.front.to!long;
    input.popFront;

    solve(S);
}

void solve(long S)
{
    auto dp = new long[](max(S + 1, 4));
    dp[0] = 1;
    foreach (i; 3 .. S + 1)
    {
        dp[i] = dp[i - 3] + dp[i - 1];
        dp[i] %= MOD;
    }
    dprint(dp);
    writeln(dp[S]);
}


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

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

vector<int> e[2010];

int dfs(int u, int p, int d){
    if(d == 0) return 1;
    int res = 1;
    for(int v: e[u]) if(v != p) res += dfs(v, u, d-1);
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;

    int a, b;
    rep(i, N-1){
        cin >> a >> b;
        e[a-1].push_back(b-1);
        e[b-1].push_back(a-1);
    }

    int maxlen = 0;
    if(K&1){
        rep(u, N){
            for(int v: e[u]){
                if(u >= v) continue;
                int len = 0;
                len += dfs(u, v, K/2);
                len += dfs(v, u, K/2);
                maxlen = max(maxlen, len);
            }
        }
    }else{
        rep(u, N){
            int len = dfs(u, -1, K/2);
            maxlen = max(maxlen, len);
        }
    }
    cout << N-maxlen << endl;
}


Measured memory_bytes: 384
#include <math.h>
#include <stdio.h>  
#include <stdlib.h>

int compare_int(const void *a, const void *b){
    return *(long int*)a - *(long int*)b;
}

int main(){
  int i,N,M;
  long long ANS=0;
  scanf("%d %d", &N, &M);
  long int A[N],S[N+1];
  long int s=0;
  S[N]=0;
  for(i=0;i<N;i++){
    scanf("%ld", &A[i]);
    S[i]=(s+A[i])%M;
    s=(s+A[i])%M;
  }

  qsort(S, N+1, sizeof(long int), compare_int);

  long long int n=1;
  for(i=0;i<=N;i++){
    if(S[i+1]==S[i]){
      n++;
    }else{
      ANS=ANS+(n-1)*n/2;
      n=1;
    }
  }
  ANS=ANS+n*(n-1)/2;
  printf("%lld", ANS);
  return 0;
}



Measured memory_bytes: 2556
class SkewNode{
  r; l;
  constructor(v){ this.v = v; }
}
class SkewQ {
  constructor(v) {
    this.h = v?new SkewNode(v):void 0;
  }
  static meld(a,b) {
    if ( a === void 0 ) return b;
    if ( b === void 0 ) return a;
    if ( a.v < b.v ) [a,b] = [b,a];
    a.r = SkewQ.meld(a.r,b);
    [a.r,a.l] = [a.l,a.r];
    return a;
  }
  pop(){
    const v = this.h.v;
    this.h = SkewQ.meld(this.h.r,this.h.l);
    return v;
  }
  push(v){
    const b = new SkewNode(v);
    this.h = SkewQ.meld(this.h,b);
  }
}
console.log((args=>{
  const [[N,M],A] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  const q = new SkewQ(A[0]);
  for ( let i = 1; i < N; i++ ) q.push(A[i]);
  for ( let i = 0; i < M; i++ ) q.push( q.pop()>>1 );
  let s = 0;
  for ( let i = 0; i < N; i++ ) s += q.pop();
  return s;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 57144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 15;
int dp[10][N];
int tot[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int k;
    cin >> k;
    if (k <= 9) {
        cout << k << "\n";
        return 0;
    }
    for (int i = 0; i <= 9; i++) {
        dp[i][1] = 1;
    }
    tot[1] = 9;
    for (int i = 2; i <= N - 1; i++) {
        for (int j = 0; j <= 9; j++) {
            for (int t = max(0, j - 1); t <= min(9, j + 1); t++) {
                dp[j][i] += dp[t][i - 1];
            }
        }
        tot[i] = tot[i - 1];
        for (int j = 1; j <= 9; j++) {
            tot[i] += dp[j][i];
        }
    }
    int len = 0;
    for (int i = 1; i <= N - 1; i++) {
        if (tot[i] >= k) {
            len = i;
            break;
        }
    }
    int sum = 0;
    int x = -1;
    for (int j = 1; j <= 9; j++) {
        sum += dp[j][len];
        if (tot[len - 1] + sum >= k) {
            x = j;
            cout << x;
            k -= tot[len - 1] + sum - dp[j][len];
            for (int i = len - 1; i >= 1; i--) {
                if (x == 0) {
                    if (k <= dp[0][i]) {
                        x = 0;
                        cout << x;
                    }
                    else {
                        k -= dp[0][i];
                        x = 1;
                        cout << x;
                    }
                }
                else if (x == 9) {
                    if (k <= dp[8][i]) {
                        x = 8;
                        cout << x;
                    }
                    else {
                        k -= dp[8][i];
                        x = 9;
                        cout << x;
                    }
                }
                else {
                    if (k <= dp[x - 1][i]) {
                        x = x - 1;
                        cout << x;
                    }
                    else if (k <= dp[x - 1][i] + dp[x][i]) {
                        k -= dp[x - 1][i];
                        x = x;
                        cout << x;
                    }
                    else {
                        k -= dp[x - 1][i] + dp[x][i];
                        x = x + 1;
                        cout << x;
                    }
                }
            }
            break;
        }
    }

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double x = 0.0, y = 0.0, deg = 90.0;
            int d = -1, a = -1;

            while (d != 0 && a != 0)
            {
                string[] input = Console.ReadLine().Split(',');
                d = int.Parse(input[0]);
                a = int.Parse(input[1]);

                x += d * Math.Cos(deg * Math.PI / 180);
                y += d * Math.Sin(deg * Math.PI / 180);

                deg -= a;
            }

            Console.WriteLine("{0}\n{1}", (int)x, (int)y);
        }
    }
}

Measured memory_bytes: 9108
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<sstream>
#include<fstream>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
/*freopen{"input.txt","r",stdin};
freopen{"output.txt","w",stdout};*/
#define mp make_pair
#define pb push_back
const int INF=1000*1000*1000;
const int maxn=2e5; 
typedef long long ll;
typedef long double ld;
typedef pair<int,int>PII;
//priority_queue <int,vector<int>,greater<int> > q1;  //从小到大 
//priority_queue <int,vector<int>,less<int> >q2;  //从大到小 

//set multiset vector queue priority_queue map multimap pair string structure 

//枚举 思维 贪心 搜索 模拟 预处理 二分 排序 

int main(){
	//ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
	int a,b;
	cin>>a>>b;
	int ans=0,tmp=1;
	if(b==1) ans=0;
	else{
		while(tmp<b){
			tmp+=a-1;
			ans++;
		}
		
		
		
	}
	cout<<ans;
	return 0;
}



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B, R = C + D;
  
  if (L > R) {
    cout << "Left" <<endl;
  }
  else if (L < R) {
    cout << "Right" <<endl;
  }
  else {
    cout << "Balanced" <<endl;
  }
}


Measured memory_bytes: 256
import math
while True:
  try:
    n = int(input())
    ans = []
    while n != 0:
      if n%2 == 1:
        n -= 1
        ans.append( 1 )
      else:
        buff = []
        tmp = n
        while True:
          tmp //= 2
          buff.append(2)
          if tmp%2 != 0:
            n -= math.pow(2, len(buff))
            ans.append( math.pow(2, len(buff)) )
            break
    print( ' '.join( [f'{int(a)}' for a in ans] ) )
  except:
    break


Measured memory_bytes: 5700
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define pai 3.1415926535

int main(void) {
	char O[51], E[51];
	scanf("%s %s", O, E);
	char S[101];
	int count = 0;
	for (int i = 0;i<strlen(O);i++) {
		S[count] = O[i];
		count+=2;
	}
	count = 1;
	for (int i = 0; i < strlen(E); i ++) {
		S[count] = E[i];
		count+=2;
	}
	S[strlen(O) + strlen(E)] = '\0';
	printf("%s\n", S);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n;i++)
using namespace std;
using ll = long long;
#define int ll
int INF=1000000000000000;
signed main(){
    int n; cin>>n;
    vector<vector<int>>d(n,vector<int>(n,INF));
    rep(i,n)rep(j,n){
        int cost; cin>>cost;
        d[i][j]=cost;
    }
    rep(k,n)rep(i,n)rep(j,n)if(d[i][j]>d[i][k]+d[k][j])return puts("-1")*0;
    int cost=0;
    vector<vector<bool>>used(n,vector<bool>(n,true));
    rep(k,n)rep(i,n)rep(j,n){
        if(i==j||j==k||k==i)continue;
        if(d[i][j]==d[i][k]+d[k][j])used[i][j]=false;
        }
    rep(i,n)rep(j,n)if(used[i][j])cost+=d[i][j];
    cout<<cost/2<<endl;
}


Measured memory_bytes: 1024
N = int(input())
dp = [0] * (N + 1)
dp[0] = 0
for i in range(1, N + 1):
    cnt = i
    for j in range(1, 7):
        q = 6 ** j
        if i >= q:
            cnt = min(cnt, dp[i - q] + 1)
    for j in range(1, 6):
        q = 9 ** j
        if i >= q:
            cnt = min(cnt, dp[i - q] + 1)
    dp[i] = cnt
print(dp[N])


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define MOD 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define all(c) (c).begin(),(c).end()
#define ss second
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> > 
#define vvpi vector<vector<pair<int,int> > >
#define Inp(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define Out(a,n,ch) for(int i=0;i<n;i++)cout<<a[i]<<ch;cout<<endl;
 
int a[3005][3005],dp[3005][3005][4];

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

	int K,R,C,ans=0;
	cin>>R>>C>>K;
	for(int i=0;i<=R;i++)
	{
		for(int j=0;j<=C;j++)
		{
			for(int k=0;k<4;k++)
				dp[i][j][k] = 0;
			a[i][j] = 0;
		}
	}
	for(int i=0;i<K;i++)
	{
		int r,c,v;
		cin>>r>>c>>v;
		a[r][c] = v;
	}
	for(int i=1;i<=R;i++)
	{
		for(int j=1;j<=C;j++)
		{
		    if(a[i][j]!=0)
		    {
			//from top
			int mtop=0;
			for(int k=0;k<4;k++)
				mtop = max(mtop,dp[i-1][j][k]);
			dp[i][j][3] = max(dp[i][j][3],mtop); //max from this ;
			dp[i][j][2] = max(dp[i][j][2],mtop) +a[i][j];

			//from left
			dp[i][j][3] = max(dp[i][j][3],dp[i][j-1][3]);
			dp[i][j][2] = max(dp[i][j][2],dp[i][j-1][3]+a[i][j]);
			dp[i][j][2] = max(dp[i][j][2],dp[i][j-1][2]);
			dp[i][j][1] = max(dp[i][j][1],dp[i][j-1][2]+a[i][j]);
			dp[i][j][1] = max(dp[i][j][1],dp[i][j-1][1]);
			dp[i][j][0] = max(dp[i][j][0],dp[i][j-1][1]+a[i][j]);
			dp[i][j][0] = max(dp[i][j][0],dp[i][j-1][0]);
		    }
		    else
		    {
		        for(int k=0;k<4;k++)
		            dp[i][j][k] = max(dp[i-1][j][k],dp[i][j-1][k]);
		    }


		}
	}
	for(int i=0;i<4;i++)
		ans = max(ans,dp[R][C][i]);
	cout<<ans<<endl;


	
	
	return 0;
}

Measured memory_bytes: 355864
import sys
import bisect
input = sys.stdin.readline

a,b,q = map(int,input().split())

ans = 10**100

s = [-ans] + [int(input()) for i in range(a)] + [ans]
t = [-ans] + [int(input()) for i in range(b)] + [ans]
#x = [int(input()) for i in range(q)]


ans = 10**100

for i in range(q):
    x = int(input())
    ans = 10**100
    s_idx = bisect.bisect_left(s,x)
    t_idx = bisect.bisect_left(t,x)
    s_idx -= 1
    t_idx -= 1
    #print(x[i],s_idx,t_idx)
    for j in s[s_idx+0],s[s_idx+1]:
        for k in t[t_idx+0],t[t_idx+1]:
            ans = min(ans,abs(x - j) + abs(j - k),abs(x - k) + abs(j - k))
            
    print(ans)

Measured memory_bytes: 12816
def resolve():
  N = int(input())
  X = input()

  if N == 1:
    if X.count("1"):
      print(0)
    else:
      print(1)
    return True

  base_1_count = X.count("1")
  if base_1_count == 0:
    for _ in range(N):
      print(1)
    return True

  X_int = int(X, 2)
  X_int_p = X_int%(base_1_count + 1)

  # RE 対策
  if base_1_count == 1:
    for i in range(N):
      if X[i] == "1":
        print(0)
      else:
        if i == N - 1:
          Xi = X_int_p + 1
        else:
          Xi = X_int_p
        count = 1
        while Xi != 0:
          Xi %= bin(Xi).count("1")
          count += 1
        print(count)
    return True

  X_int_m = X_int%(base_1_count - 1)
  for i in range(N):
    # 初期値計算を高速にやる
    if X[i] == "1":
      temp_1_count = base_1_count-1
      pow_2 = pow(2, N-i-1, base_1_count-1)
      if X_int_m <= pow_2:
        Xi = X_int_m - pow_2 + base_1_count-1
      else:
        Xi = X_int_m - pow_2
    else:
      temp_1_count = base_1_count+1
      Xi = X_int_p + pow(2, N-i-1, base_1_count+1)
      while Xi >= base_1_count+1:
        Xi %= base_1_count+1

    # print("1_c={0}".format(temp_1_count))
    if temp_1_count == Xi:
      print(1)
      continue

    count = 1
    while Xi != 0:
      num_of_1 = bin(Xi).count("1")
      Xi %= num_of_1
      count += 1
    print(count)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9496
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
int inv(int a) {
	return 2 - a;
}
int mul(int a, int b) {
	if (a == 0 || b == 0)return 0;
	if (a == 1 || b == 1)return 1;
	return 2;
}
int add(int a, int b) {
	if (a == 2 || b == 2)return 2;
	if (a == 1 || b == 1)return 1;
	return 0;
}
int main() {
	string s;
	while (cin >> s) {
		if (s == ".")break;
		int len = s.length();
		int out = 0; int cnt;
		rep(i, 3) {
			rep(j, 3) {
				rep(k, 3) {
					cnt = 0;
					int sum[100] = {}; vector<char> ope[100];
					rep(l, len) {
						if (s[l] == '(')cnt++;
						else if (s[l] == ')') {
							cnt--;
							int res = sum[cnt + 1];
							int r = ope[cnt].size();
							per(x, r) {
								if (ope[cnt][x] == '-') {
									res = inv(res);
								}
								else if (ope[cnt][x] == '+') {
									res = add(res, sum[cnt]);
								}
								else {
									res = mul(res, sum[cnt]);
								}
							}
							sum[cnt] = res;
							ope[cnt].clear();
						}
						else if ('0' <= s[l] && s[l] <= '2') {
							int r = ope[cnt].size();
							int res=s[l]-'0';
							per(x, r) {
								if (ope[cnt][x] == '-') {
									res = inv(res);
								}
								else if (ope[cnt][x] == '+') {
									res = add(res, sum[cnt]);
								}
								else {
									res = mul(res, sum[cnt]);
								}
							}
							sum[cnt] = res;
							ope[cnt].clear();
						}
						else if (s[l] == 'P' || s[l] == 'Q' || s[l] == 'R') {
							int r = ope[cnt].size();
							int res;
							if (s[l] == 'P')res = i;
							else if (s[l] == 'Q')res = j;
							else {
								res = k;
							}
							per(x, r) {
								if (ope[cnt][x] == '-') {
									res = inv(res);
								}
								else if (ope[cnt][x] == '+') {
									res = add(res, sum[cnt]);
								}
								else {
									res = mul(res, sum[cnt]);
								}
							}
							sum[cnt] = res;
							ope[cnt].clear();

						}
						else {
							ope[cnt].push_back(s[l]);
						}
					}
					if (sum[0] == 2)out++;
				}
			}
		}
		cout << out << endl;
	}
	return 0;
}


Measured memory_bytes: 3020
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    double L;
    scanf("%lf",&L);
    double henn=L/3;
    double V=henn*henn*henn;
    printf("%lf\n",V);
}

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

using namespace std;

int main(){
    int a,b,c,d,e,k;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;
    if ((e - a) > k){
        cout << ":(" << endl;
    }else
    {
        cout << "Yay!" << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	set<string>S;
	string S1 = "hi";
	string S2="hi";
	for (int i = 0; i < 11; i++) {
		S.insert(S2);
		S2 += S1;
	}
	if (S.find(s) != S.end()) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
}



Measured memory_bytes: 256
from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)

T = int(input())
INF = 10**18

for _ in range(T):
    N, A, B, C, D = map(int, input().split())
    DC = tuple(zip((2, 3, 5), (A, B, C)))

    @lru_cache(maxsize=None)
    def search(now):
        if now == 0:
            return 0

        ret = now * D
        for div, cost in DC:
            q, r = divmod(now, div)
            ret = min(
                ret,
                search(q) + cost + r * D,
                search(q + 1) + cost + (div - r) * D if q + 1 < now else INF,
            )
        return ret

    print(search(N))


Measured memory_bytes: 11916
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;

typedef long long ll;

ll L, R;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> L >> R;
    if(R - L + 1 >= 5000)
        cout << 0;
    else
    {
        ll mini = 2019;
        for(ll i = L; i <= R; ++i)
            for(ll j = i+1; j <= R; ++j)
            {
                ll pr = i * j;
                mini = min(mini, pr % 2019);
            }
        cout << mini;
    }
    return 0;
}


Measured memory_bytes: 256
lr = list(map(int, input().split()))

l = lr[0]
r = lr[1]

ans=2018
tr=min(2019, r-l)
for i in range(l, l+tr):
    for j in range(l+1, l+tr+1):
        ans = min(ans, (i*j)%2019)
        
        
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 200005, MAXM = 3003, Mod = 1000000007 , MAXLog = 20;



int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i= 0 ; i < n; ++i) {
        cin >> arr[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        bool f = true;
        for (int j = 0; j < i; ++j) {
            f &= arr[j] <= arr[i];
        }
        ans += f;
    }
    
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int IsPrime(int);
int main() {
  int i,count=0,n,*sosu;
    scanf("%d",&n);
    
    sosu = (int *)malloc(n * sizeof (int));
    
   
    
    for(i=n-1;i>=0;i--){
        scanf("%d",&sosu[i]);
        if(IsPrime(sosu[i]) == 1) count++;
    }
    printf("%d\n",count);
    return 0;
}

 int   IsPrime(int n){


    


   int i;

    if (n < 2)
        return 0;
    else if (n == 2)
        return 1;

    if (n % 2 == 0)
        return 0;

    for (i = 3; i <= n / i; i += 2)
         if (n % i == 0)
            return 0;
    return 1;

}



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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cout << (n-2) * 180 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;


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

    int a,b;
    cin>>a>>b;
    if(b%a==0){
        cout<<a+b<<"\n";
    }
    else{
        cout<<b-a<<"\n";
    }


	return 0;
}

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

int main() {
  double N, M;
  cin >> N >> M;
  vector<vector <int> > to(N);
  rep(i, M) {
    int s, t;
    cin >> s >> t;
    --s; --t;
    to[s].push_back(t);
  }
  vector<double> DP(N);
  for (int v = N - 2; v >= 0; --v) {
    double now = 0;
    for (int u : to[v]) {
      now += DP[u];
    }
    now /= to[v].size();
    now += 1;
    DP[v] = now;
  }
  double ans = DP[0];
  for (int nv = 0; nv < N -1; nv++) {
    if (to[nv].size() == 1) continue;
    int nu = to[nv][0];
    for (int u : to[nv]) {
      if (DP[nu] < DP[u]) nu = u;
    }

    double now = [&]{
      vector<double> DP(N);
      for (int v = N - 2; v >= 0; --v) {
        double now = 0;
        for (int u : to[v]) {
          if (v == nv && u == nu) continue;
          now += DP[u];
        }
        int deg = to[v].size();
        if (v == nv) deg--;
        now /= deg;
        now += 1;
        DP[v] = now;
      }
      return DP[0];
    }();
    ans = min(ans, now);
  }

  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
int main(void){
  ll n,t;
  cin >> n>>t;
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i];
  }
  vector<ll> amin(n,a[0]);//ここから、ここを含む左にあるものでもっとも小さい値
  vector<ll> amax(n,a[n-1]);//ここから、ここを含む左にあるものでもっとも大きい値
  rep(i,n-1){
    if(a[i+1]<amin[i]){
      amin[i+1]=a[i+1];
    }else{
      amin[i+1]=amin[i];
    }
  }
  rep(i,n-1){
    if(a[n-1-(i+1)]>amax[n-1-i]){
      amax[n-1-(i+1)]=a[n-1-(i+1)];
    }else{
      amax[n-1-(i+1)]=amin[n-1-i];
    }
  }
  ll diff=0;
  rep(i,n){
    diff=max(amax[i]-amin[i],diff);
  }
  ll tmpmin=llMAX;
  ll tmpmax=-1;
  int cnt=0;
  int stack=0;
  rep(i,n){
    /*tmpmin=min(a[i],tmpmin);
    tmpmax=max(a[i],tmpmax);*/
    if(stack==0){
      tmpmin=a[i];
      tmpmax=a[i];
      stack=1;
    }else{
      if(tmpmin>a[i]){
        tmpmin=a[i];
        tmpmax=a[i];
        stack=1;
      }else if(tmpmin==a[i]){
        stack++;
      }else{
        tmpmax=max(tmpmax,a[i]);
      }
      if(tmpmax-tmpmin==diff){
        cnt++;
        stack--;
      }else if(tmpmax-tmpmin>diff){
        cout<<"algorithm ERROR"<<endl;
      }
    }
  }
  cout<<cnt <<endl;
  return 0;
}

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

int main() {
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

int binary_search(ll x, vel a){
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin() ;
    } else {
        return -1;
    }

}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}


int main() {
    ll N, Y, x, y, z, ichiman, amari, num;
    bool ans = false;
    cin >> N >> Y;

    REP(sen, N+1){
        if(ans) break;
        REP(gosen, N+1){
            amari = Y - (sen * 1000) - (gosen * 5000);
            ichiman = amari / 10000;
            amari %= 10000;
            if(amari == 0 && N == ichiman + gosen + sen && ichiman >= 0 && amari >= 0) {
                x = ichiman;
                y = gosen;
                z = sen;
                ans = true;
                break;
            }
        }
    }

    if(ans){
        cout << x << " " << y << " " << z << endl;
    } else {
        cout << "-1 -1 -1" << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
N = int(input())
W_list = [input() for i in range(N)]
W_set = set(W_list)
answer = 'Yes'
if len(W_list) != len(W_set):
    answer = 'No'
for i in range(len(W_list) - 1):
    if W_list[i][-1] != W_list[i+1][0]:
        answer = 'No'
print(answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  string S;
  string test="YAKI";
  std::cin >> S;
  if(S.size()<4){
    printf("No\n");
    return 0;
  }
  for (size_t i = 0; i < 4; i++) {
    if(S[i]!=test[i]){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


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

typedef pair<int,int> P;

int main() {
  string s[12];
  while(cin >> s[0]) {
    for(int i=1; i<12; i++) cin >> s[i];
    bool d[12][12];
    for(int i=0; i<12; i++) {
      for(int j=0; j<12; j++) d[i][j]=false;
    }
    int cnt=0;
    for(int i=0; i<12; i++) {
      for(int j=0; j<12; j++) {
	if(s[i][j]=='1' && !d[i][j]) {
	  cnt++;
	  queue<P> que;
	  d[i][j]=true;
	  que.push(P(i,j));
	  while(!que.empty()) {
	    P p=que.front();
	    que.pop();
	    int nx=p.first,ny=p.second;
	    int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
	    for(int i=0; i<4; i++) {
	      int x=nx+dx[i],y=ny+dy[i];
	      if(x>=0 && x<12 && y>=0 && y<12) {
		if(s[x][y]=='1' && !d[x][y]) {
		  d[x][y]=true;
		  que.push(P(x,y));
		}
	      }
	    }
	  }
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}


Measured memory_bytes: 1192
N,M=map(int,input().split()) 
L=[list(input().split()) for i in range(M)]
W=[0]*N
A=[0]*N
a=0
w=0
for i in range(M):
  if L[i][1]=="AC":
    A[int(L[i][0])-1]=1
    
  elif L[i][1]=="WA" and A[int(L[i][0])-1]==0:
    W[int(L[i][0])-1]+=1
#for i in A:
  #a+=i
#for i in W:
  #w+=i
for i in range(N):
  if A[i]>0:
    a+=1
    w+=W[i]
print(a,w)



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

int main() {

    int a, b;

    cin >> a >> b;

    int i;
    for(i = 1; i <= 1000; ++i) {

        int at = i * 0.08;
        int bt = i * 0.1;

      //  cout << at << " " << bt << endl;

        if(at == a && bt == b) {
            cout << i << endl;
            return 0;

        }
            
    }

    cout << -1 << endl;

    return 0;

}

Measured memory_bytes: 256
a, b, k = map(int, input().split())

ans = set()
for i in range(a, min(b, a + k)):
    ans.add(i)
for i in range(max(a ,b - k + 1), b + 1):
    ans.add(i)

l = list(ans)
l.sort()
for n in l:
    print(n)

Measured memory_bytes: 3060
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<LL,LL> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

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

    return 0;
}


Measured memory_bytes: 3616
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

X,t=get_i
if X<t
    puts 0
else
    puts X-t
end

Measured memory_bytes: 1788
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int u[20010], v[20010], d[20010], c[20010];

struct edge{int to, cost, c;};

int n, D[10010];
vector<edge> g[10010];

void dijkstra(int s) {
  priority_queue<PII, vector<PII>, greater<PII>> que;
  fill(D, D+n, INF);
  D[s] = 0;
  que.push(PII{0, s});

  while(que.size()) {
    PII p = que.top(); que.pop();
    int v = p.second;
    if(D[v] < p.first) continue;
    for(edge e: g[v]) {
      if(D[e.to] > D[v] + e.cost) {
        D[e.to] = D[v] + e.cost;
        que.push(PII{D[e.to], e.to});
      }
    }
  }
}

signed main(void)
{
  while(true) {
    int m;
    cin >> n >> m;
    if(!n) break;
    REP(i, n) g[i].clear();
    REP(i, m) {
      cin >> u[i] >> v[i] >> d[i] >> c[i];
      u[i]--, v[i]--;
      g[u[i]].PB({v[i], d[i], c[i]});
      g[v[i]].PB({u[i], d[i], c[i]});
    }
    // 0??????????????¢????±???????
    dijkstra(0);

    int ret = 0;
    FOR(i, 1, n) {
      int tmp = INF;
      for(edge j: g[i]) {
        if(D[i] == D[j.to] + j.cost) {
          chmin(tmp, j.c);
        }
      }
      ret += tmp;
    }

    cout << ret << endl;
  }

  return 0;
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
const int N=100005;
typedef long long ll;
int n,a[N];
using namespace std;

int main()
{
	//freopen ("code.in","r",stdin);
	//freopen ("code.out","w",stdout);
	scanf ("%d",&n);
	int i,j,t=1,x,y;
	for (i=1;i<=n;i++) scanf ("%d",&a[i]);
	sort(a+1,a+1+n);
	ll ans=0;x=y=a[1];
	for (i=2,j=n;i<=j;)
	if (t)
	{
		if (i==j) ans+=max(abs(a[i]-x),abs(a[i]-y));
		else ans+=max(abs(a[j]-x)+abs(a[j-1]-y),abs(a[j-1]-x)+abs(a[j]-y));
		x=a[j],y=a[j-1];
		j-=2,t=0;
	}
	else
	{
		if (i==j) ans+=max(abs(a[i]-x),abs(a[i]-y));
		else ans+=max(abs(a[i]-x)+abs(a[i+1]-y),abs(a[i+1]-x)+abs(a[i]-y));
		x=a[i],y=a[i+1];
		i+=2,t=1;
	}
	ll ans1=ans;
	reverse(a+1,a+1+n);
	ans=0;x=y=a[1];t=1;
	for (i=2,j=n;i<=j;)
	if (t)
	{
		if (i==j) ans+=max(abs(a[i]-x),abs(a[i]-y));
		else ans+=max(abs(a[j]-x)+abs(a[j-1]-y),abs(a[j-1]-x)+abs(a[j]-y));
		x=a[j],y=a[j-1];
		j-=2,t=0;
	}
	else
	{
		if (i==j) ans+=max(abs(a[i]-x),abs(a[i]-y));
		else ans+=max(abs(a[i]-x)+abs(a[i+1]-y),abs(a[i+1]-x)+abs(a[i]-y));
		x=a[i],y=a[i+1];
		i+=2,t=1;
	}
	printf ("%lld",max(ans,ans1));
	return 0;
}


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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int n,a[maxn];

int check(int x) {
    map<int,int > t;
    for(int i=1;i<=n;i++) {
        if(a[i]<=a[i-1]) {
            auto p=t.lower_bound(a[i-1]+1);// cerr<<"OK"<<endl;
            while(p!=t.end()) {auto q=p;p++;t.erase(q);}
            t[a[i]]++;
            int v=a[i];
            while(t[v]==x) t[v]=0,t[v-1]++,v--;
            // cerr<<"?"<<endl;
            if(v<=0) return 0;
        }
    }
    return 1;
}

int main() {
    read(n);int bo=1;
    for(int i=1;i<=n;i++) {
        read(a[i]);
        if(a[i]<=a[i-1]) bo=0;
    }
    if(bo) return puts("1"),0;
    int l=2,r=n,ans=n;
    while(l<=r) {
        int mid=(l+r)>>1;
        if(check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    write(ans);
    return 0;
}


Measured memory_bytes: 1152