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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


struct SegmentTreeSUM{
  ll n;
  vll tree;

  SegmentTreeSUM(ll len){
    n=1;
    while(len>n)
      n*=2;

    tree.assign(2*n-1, 0);
  }

  void update(ll index, ll value){
    index += n-1;
    tree[index] = value;

    while(index>0){
      index=(index-1)/2;
      tree[index] = tree[index*2+1]+tree[index*2+2];
    }
  }


  //[a, b)
  ll query(ll a, ll b){
    return query(a,b,0,0,n);
  }

  ll query(ll a, ll b, ll index, ll l, ll r){
    if(b<=l || r<=a)
      return 0;

    if(a<=l && r<=b)
      return tree[index];

    ll value_l = query(a,b,2*index+1,l,(l+r)/2);
    ll value_r = query(a,b,2*index+2,(l+r)/2,r);
    return value_l+value_r;
  }
};


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

  ll n,q;
  cin>>n>>q;

  vll c(n);
  REP(i,n)cin>>c[i];
  vll l(q), r(q);
  REP(i,q){
    cin>>l[i]>>r[i];
    l[i]--;
    r[i]--;
  }


  vvll index(n+2,vll());
  REP(i,n)index[c[i]].push_back(i);

  SegmentTreeSUM st(n);

  vpl qu(q);
  REP(i,q){
    qu[i].FI=r[i];
    qu[i].SE=l[i];
  }
  sort(ALL(qu));


  map<pll,ll> ans;
  ll cur=-1;
  REP(i,q){
    for(ll j=cur+1; j<=qu[i].FI; j++){
      auto it=lower_bound(ALL(index[c[j]]),j);
      if(it!=index[c[j]].begin())
        st.update(*(it-1),0);

      st.update(*it,1);
    }
    cur=qu[i].FI;

    ll a=st.query(qu[i].SE,qu[i].FI+1);
    ans[pll(qu[i].SE,qu[i].FI)]=a;
  }

  REP(i,q)cout<<ans[pll(l[i],r[i])]<<endl;


}



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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	int a[n];
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if ((a[i] * 1.0) >= (sum * 1.0) / (4 * m)) {
			cnt++;
		}
	}
	if (cnt >= m) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}
	
	return 0;
}


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

int main(int argc, char const *argv[])
{
	int n,k;
	string s;
	cin>>n>>s>>k;--k;
	for (int i = 0; i < n; ++i)
	{
		if (s.at(i)!=s.at(k))
		{
			s.at(i)='*';
		}
	}
	cout<<s<<endl;
	return 0;
}


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

int main() {
	string S;
	cin >> S;
	if (S.size() == 3) reverse(S.begin(), S.end());
	cout << S;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

やるだけ
*/

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;
const ll mod = 1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string L;
    cin >> L;
    ll sum = 0;
    int count1 = 0;
    REP(i,L.size()){
        if(L.at(i) == '1'){
            ll count2 = 1,count3 = 1;
            REP(l,count1){
                if(l == 0){
                    REP(q,(count1) / 30){
                        count2 =count2*73741817%mod;
                        }
                    l += ((count1) / 30)*30;
                }
                if(l != count1){
                    count2 = count2*2%mod;
                }
            }
            REP(l,L.size()-i-1){
                if(l == 0){
                    REP(q,(L.size()-i-1) / 19){
                        count3 = count3*162261460%mod;
                        }
                    l += ((L.size()-i-1) / 19)*19;
                }
                if(l != L.size()-i-1){
                    count3 = count3*3%mod;
                }
            }
            sum = (sum + count2 * count3)%mod;
            count1++;
        }
    }
    ll count2 = 1;
    REP(l,count1){
        if(l == 0){
            REP(q,(count1) / 30){
                count2 =count2*73741817%mod;
                }
            l += ((count1) / 30)*30;
        }
        if(l != count1){
            count2 = count2*2%mod;
        }
    }
    sum += count2;
    cout <<sum % mod<< "\n";
}

Measured memory_bytes: 512
N = gets.to_i
a = gets.split(" ").map(&:to_i)
b = N/2
c = a.clone
ball = Array.new
for i in 0..b
    ball << b+i+1 if a[b+i] == 1
end
(b-1).downto(0) do |i|
    count = 0
    i.step(N-1, i+1) do |j|
        count += 1 if c[j] == 1
    end
    if count % 2 == a[i]
        if c[i] == 1
            ball << i+1
        end
    else
        if c[i] == 1
            c[i] = 0
        else
            c[i] = 1
            ball << i+1
        end
    end
end
puts ball.length
puts ball.join(" ") if ball.length != 0


Measured memory_bytes: 22024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = in.ni(), b = in.ni();
            out.println(Math.max(a + b, Math.max(2 * a - 1, 2 * b - 1)));
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}



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

int A[1000000],n;

int search(int key){
    int left=0;
    int right=n;
    int mid;
    while(left<right){
        mid=(left+right)/2;
        if(key==A[mid])return 1;
        if(key>A[mid])left=mid+1;
        else if (key<A[mid])right=mid;
    }
    return 0;
}

int main(){
    int q,k,sum=0;
    cin>>n;
    for (int i=0; i<n; i++)cin>>A[i];
    cin>>q;
    for (int i=0; i<q; i++) {
        cin>>k;
        if(search(k))sum++;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3460
#include<bits/stdc++.h>
using namespace std;int64_t p[1<<20],g,N,i,c,b,n[1<<20],d[1<<20];main(){for(cin>>N;i<N;)cin>>c>>b,c+=1e9,p[i++]=(c<<32)+c+b;sort(p,p+N);for(;c=i--;g=d[i]=(g+d[n[i]=c]+1)%998244353)for(;c<N&p[c]<p[i]<<32;c=n[c]);cout<<*d+1;}

Measured memory_bytes: 5888
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	string s;
	cin >> s;
	string p = "hi";
	string cur ="";
	for (int i = 0; i < 10; i++) {
		cur += p;
		if (cur == s) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int n,k;
vector <int> temp;
int fpb(int a,int b){
	if(b==0)
		return a;
	else
		return fpb(b,a%b);
}
int main()
{
	int angka;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		int input;
		cin>>input;
		if(i==1)
			angka=input;
		else	
			angka=fpb(angka,input);
		if(input>=k)
		{
			temp.pb(input-k);
		}
	}
	bool bisa=false;
	for(auto beda:temp)
	{
		if(beda%angka==0)
			bisa=true;
	}
	if(bisa)
		cout<<"POSSIBLE"<<endl;
	else
		cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 892
#include<stdio.h>

int main(void){
	unsigned long long int k,n,a[131072],b[131072],r=0,i;
	scanf("%llu",&n);
	for(i = 1;i <= n;i++){scanf("%llu%llu",&a[i],&b[i]);}
	for(i = n;i >= 1;i--){
		if((a[i]+r)%b[i] == 0){continue;}
		k = ((a[i]+r)/b[i])+1;
		r+=((k*b[i])-(a[i]+r));
	}
	printf("%llu\n",r);
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double area = r*r*pi;
        double length = 2*r*pi;
        System.out.printf("%f %f",area,length);
        sc.close(); 
    }
}


Measured memory_bytes: 28248
N = int(input())
T, A = input().split()
H = input().split()

min = 10000000
index = -1

for i in range(N):
  temp = int(T) - int(H[i]) * 0.006
  if min > abs(int(A) - temp):
    min = abs(int(A) - temp)
    index = i

print(index+1)


Measured memory_bytes: 3060
n, k = map(int, input().split())
p = list(map(int, input().split()))
e = []

for i in range(n):
    e.append(p[i] + 1)

sum_e = [0]

for i in range(1,n+1):
    sum_e.append(sum_e[i-1]+e[i-1])

ans = []

for i in range(n-k+1):
    ans.append(sum_e[i+k]-sum_e[i])

print(max(ans)/2)

Measured memory_bytes: 37076
# Not working correctly
import math


D, G = map(int, input().split())
p_c_list = [list(map(int, input().split())) for _ in range(D)]

min_n_solved = 1000000000
for p_combi in range(1 << D):
    tmp_score = 0
    n_solved = 0
    selected_p_idxs = []  # Selected indexes of problems
    for digit in range(D):
        if (p_combi >> digit) & 1:
            # p_i: p_c_list[digit][0]
            # c_i: p_c_list[digit][1]
            tmp_score += \
                100 * (digit+1) * p_c_list[digit][0] + p_c_list[digit][1]
            n_solved += p_c_list[digit][0]
            selected_p_idxs.append(digit)
    score_diff = tmp_score - G
    # print('1:', n_solved, 'score_diff:', score_diff)
    if score_diff >= 0:
        # Fine-tuning to reduce "n_solved" problems over solved
        # "selected_p_idxs" already sorted by probrems from low points to high
        p_idx_lowest = selected_p_idxs[0]
        score_per_p = 100 * (p_idx_lowest + 1)
        # if score_diff - bonus_point > 0
        n_oversolved = None
        score_diff_wo_bonus = score_diff - p_c_list[p_idx_lowest][1]
        if score_diff_wo_bonus > 0:
            n_oversolved = round(score_diff_wo_bonus / score_per_p)
            if n_oversolved < p_c_list[p_idx_lowest][0]:
                n_solved -= n_oversolved
        # print('2:', n_solved)
    else:
        not_selected_p_idxs = \
            [p_idx for p_idx in range(D) if p_idx not in selected_p_idxs]
        not_selected_p_idxs = sorted(not_selected_p_idxs, reverse=True)
        # Add n_solved where problems are searched oredred by points DESC
        not_selected_p_idx_highest = not_selected_p_idxs[0]
        addable_score = 100 * p_c_list[not_selected_p_idx_highest][0] * (not_selected_p_idx_highest+1)
        if score_diff + addable_score > 0:
            score_per_p = 100 * (not_selected_p_idx_highest + 1)
            n_undersolved = math.ceil(abs(score_diff) / score_per_p)
            if n_undersolved < p_c_list[not_selected_p_idx_highest][0]:
                n_solved += n_undersolved
            # print('3:', n_solved)
    if n_solved > 0 and score_diff >=0:
        min_n_solved = min(n_solved, min_n_solved)

print(min_n_solved)

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

using namespace std;

int main () 
{
    int A , B , C ;
    
    cin >> A >> B >> C ;
    
    if (A==5 && B==5 && C==7)
    {
        cout << "YES \n" ;
    }
    else if (A==5 && B==7 && C ==5) 
    {
        cout << "YES\n" ;
    }
    else if (A==7 && B==5 && C==5)
    {
        cout << "YES\n" ;
    }
    else
    {
        cout << "NO\n" ;
    }
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 int r,g,b;
	 cin>>r>>g>>b;
	 int k;
	 cin>>k;
	 while(g<=r && k>0)
	 {
		 g*=2;
		 --k;
	 }
	 while(b<=g && k>0)
	 {
		 b*=2;
		 --k;
	 }
	 if(b>g && g>r)
	 {
		 cout<<"Yes";
	 }
	 else
	 {
		 cout<<"No";
	 }
	 return 0;
}


Measured memory_bytes: 3596
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    int s = S.length();
    
    int ans = 0;
    for(int i = 0; i < s/2; i++){
      if(S.charAt(i) != S.charAt(s-i-1)){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

X = ir()

A = np.arange(-300, 300, dtype=np.int64)
A5 = A ** 5
B = np.subtract.outer(A5, A5)
index = np.where(B == X)
a = index[0][0] - 300
b = index[1][0] - 300
assert a ** 5 - b ** 5 == X
print(a, b)


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  VI xs(3);
  REP(i,3) cin >> xs[i];
  SORT(xs);

  cout << (xs == VI{5,5,7}? "YES": "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String s = br.readLine();
			String p = br.readLine();
			String c;
			int flg=0;
			for(int i=0; i<s.length(); i++){
				if(i+p.length()<=s.length()){
					c = s.substring(i, p.length()+i);
				} else{
					c = s.substring(i, s.length()) + s.substring(0, p.length()-(s.length()-i));
				}
				if(p.equals(c)){
					flg = 1;
					break;
				}
			}
			if(flg==1) System.out.println("Yes");
			else       System.out.println("No");
		} catch(IOException e){
			System.out.println("Exception :" + e);
		}
	}
}

Measured memory_bytes: 17020
#include<stdio.h>
#include<algorithm>

using namespace std;

int A[1000000], n;

int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;

    while(left < right){
        mid = ( left + right) / 2;
        if(A[mid] == key){
            return 1;
        }else if(key > A[mid] ){
            left = mid + 1;
        }else{
            right = mid;
        }
    }
    return 0;
}

int main(){
    int i, q, k, sum = 0;

    scanf("%d", &n);
        for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    sort(A, A + n);
    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &k);
        if(binarySearch(k)){
            sum++;
        }
    }
    printf("%d\n", sum);
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()

const int MOD = 1000000007;
const int N = 1000005;
const double PI =4*atan(1);
ll n,k,x;
ll dp[N];
ll h[N];


int main(){
    ios::sync_with_stdio(0);
    //freopen("baklava.in","r",stdin);
    cin.tie(0);
    cout.tie(0);
    //start
    cin >> n ;
    k=2;
    for(int i=0;i<n;i++){
    	cin >> h[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
    	dp[i]=1e18;
    	for(int j=i-1;j>=max(i-k,0ll);j--){
    		dp[i]=min(dp[i],abs(h[i]-h[j])+dp[j]);
    	}
    }
    cout << dp[n-1];

    return 0;
}


Measured memory_bytes: 5120
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Sun Apr  1 19:11:47 2018
//
package main

import (
	"fmt"
	"sort"
)

var N, C, K int

func main() {
	fmt.Scan(&N, &C, &K)

	T := make([]int, N)
	for i := range T {
		fmt.Scan(&T[i])
	}
	sort.Ints(T)

	count := 0
	start := 0
	num := 0
	for i := range T {
		t := T[i]
		if start == 0 {
			start = t
			num++
			count++
		} else if start+K < t {
			start = t
			num = 1
			count++
		} else {
			if num == C {
				start = t
				num = 1
				count++
			} else {
				num++
			}
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 5504
#include "bits/stdc++.h"

using namespace std;

int N,M,K,L,R,H,W;

const long long int MOD=1000000007;



int main(){
	
	int l,N;
	while(cin>>l>>N,l){
		vector<int>damage(N);
		vector<int>exp(N);
		vector<int>req(N);
		for(int i=0;i<N;i++){
			cin>>damage[i]>>exp[i]>>req[i];
		}
		vector<vector<int>>dp(l+1,vector<int>(101,MOD));
		dp[l][0]=0;
		for(int i=l;i>0;i--){
			for(int k=0;k<=100;k++){
				for(int l=0;l<N;l++){
					if(k<req[l])continue;
					int left=max(0,i-damage[l]);
					int nxexp=min(100,k+exp[l]);
					dp[left][nxexp]=min(dp[left][nxexp],dp[i][k]+1);
				}
			}
		}
		int ans=MOD;
		for(int i=0;i<=100;i++)ans=min(ans,dp[0][i]);
		if(ans==MOD)cout<<"NA\n";
		else cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3208
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int[] H = new int[N];
		for(int i=0; i<N; i++) {
			H[i] = sc.nextInt();
		}

		Graph g = new Graph(N);
		for(int i=0; i<M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();

			g.addEdge(g.getNode(A), g.getNode(B));
			g.addEdge(g.getNode(B), g.getNode(A));
		}

		int ans = 0;
		for(int i=1; i<=N; i++) {
			Node n = g.getNode(i);

			if(n.edges.size() == 0) {
				ans++;
			}else {
				boolean isGood = true;
				for(int j=0; j<n.edges.size(); j++) {
					Node to = n.edges.get(j).to;
					if(H[n.value-1] <= H[to.value-1]) {
						isGood = false;
						break;
					}
				}

				if(isGood)
					ans++;
			}
		}

		System.out.println(ans);

	}


	//一般的なグラフ
	public static class Graph{
		int n;
		Map<Integer, Node> nodes;	//(ノード番号, ノード)

		//1~Nまでをもつグラフ
		public Graph(int n) {
			this.n = n;
			nodes = new HashMap<>(n);

			for(int i=0; i<n; i++) {
				nodes.put(i+1, new Node());
			}
		}

		public Graph(int n, int[] values) {
			this.n = n;
			nodes = new HashMap<>(n);

			for(int i=0; i<n; i++) {
				nodes.put(values[i], new Node(values[i]));
			}
		}

		public Node getNode(int node_n) {
			//ノード番号を指定してノードを取得
			return nodes.get(node_n);
		}

		public void addEdge(Node from, Node to) {
			//重みが1のグラフの場合(重みが均等な場合にも場合によっては使える)
			from.edges.add(new Edge(to, 1));
		}

		public void addEdge(Node from, Node to, long weight) {
			//エッジの重みが異なる場合
			from.edges.add(new Edge(to, weight));
		}

		public void removeEdge(Node from, Node to) {
			//指定したノード間のエッジを削除
			from.edges.remove(new Edge(to, 1));
		}
	}

	public static int count = 0;
	//ノードを表すクラス
	public static class Node{

		int value;
		List<Edge> edges;
		boolean visited = false;
		Node root;

		public Node(){
			value = count+1;
			edges = new LinkedList<Edge>();
			count++;
		}

		public Node(int value) {
			this.value = value;
			edges = new LinkedList<Edge>();
		}

		@Override
		public boolean equals(Object obj) {
			if(obj instanceof Node) {
				Node n = (Node)obj;
				if(this.value == n.value)
					return true;
				else
					return false;
			}

			return false;
		}

		@Override
		public int hashCode() {
			return Objects.hash(this.value);
		}
	}

	//エッジを表すクラス
	public static class Edge{
		Node to;		//行き先
		long weight;		//重み

		public Edge(Node to, long weight) {
			this.to = to;
			this.weight = weight;
		}

		@Override
		public boolean equals(Object obj) {
			if(obj instanceof Edge) {
				Edge e = (Edge)obj;
				if(this.to.equals(e.to))
					return true;
				else
					return false;
			}

			return false;
		}

		@Override
		public int hashCode() {
			return Objects.hash(this.to);
		}
	}

}


Measured memory_bytes: 81544
package main

import (
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	n   = 0
	ans = 0
)

func main() {
	fmt.Scan(&n)
	for i := 0; ; i++ {
		dfs(i, "")
	}
}

func dfs(rest int, s string) {
	if rest == 0 {
		if i, _ := strconv.Atoi(s); i > n {
			fmt.Println(ans)
			os.Exit(0)
		}
		for _, v := range "357" {
			if !strings.Contains(s, string(v)) {
				return
			}
		}
		ans++
	} else {
		for _, c := range "357" {
			dfs(rest-1, s+string(c))
		}
	}
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int N=2e6+5;
inline int read(){
    int x=0; char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x;
}
int x[N],y[N],f[N];
set<int>sx[N],sy[N];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
int main(){
	int n=read();
	for(int i=0;i<n;i++)x[i]=read(),y[i]=read();
	for(int i=0;i<N;i++)f[i]=i;
	for(int i=0;i<n;i++)f[find(x[i])]=find(y[i]+N/2);
	for(int i=0;i<n;i++){
		int fa=find(x[i]);
		sx[fa].insert(x[i]);
		sy[fa].insert(y[i]);
	}
	long long ans = 0;
	for(int i=0;i<N;i++)ans+=1ll*sx[i].size()*sy[i].size();
	printf("%lld",ans-n);
	return 0;
}

Measured memory_bytes: 203520
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
int height[10],pos,max[3];
for(int i=0;i<10;++i)cin >> height[i];
for(int i=0;i<3;++i){
 int tmp = 0;
 for(int n=0;n<10;++n){
  if(tmp<height[n]){
   tmp = height[n];
   pos = n;
  }
 }
 max[i] = tmp;
 height[pos] = 0;
}
for(int i=0;i<3;++i)
 cout << max[i] << "\n";
 return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <regex>

/*
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;



using ll = long long;
using ull = unsigned long long;
constexpr ll N = 2e5;

constexpr ull max_num = 1e18;
ull a[N];
*/

using ull = unsigned long long;
using ll = long long;

using namespace std;



int main() {
   
	char s;
	cin >> s;
	if ('A' <= s && s < 'a')
	{
		cout << 'A';
	}
	else {
		cout << 'a';
	}
	//printf("A:%d a:%d", 'A', 'a');

	
	
	return 0;
	
}



Measured memory_bytes: 2996
height, width = map(int, input().split())
F = [list(map(int, input().split())) for n in range(height)]

A = []
count = 0


def next_box(h_, w_, wid):
    if w_+1 == wid:
        return h_ + 1, w_

    return h_, w_ + 1


for h in range(height):
    for w in range(width):
        # last one
        if h+1 == height and w+1 == width:
            break
        # even num
        elif F[h][w] % 2 == 0:
            pass
        # odd num
        else:
            n_h, n_w = next_box(h, w, width)
            F[h][w] -= 1
            F[n_h][n_w] += 1

            A.append([h+1, w+1, n_h+1, n_w+1])
            count += 1


print(count)
for a in A:
    print(*a, sep=' ')


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

int main() {
  int n;
  cin>>n;
  
  int n1 = n/10, n2 = n%1000;
  if(n1%111==0 || n2%111==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define elif else if
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string

signed main(){
  int N,M,O,P=0,c=0,c2=0,crash=0,nowtab=1;
  double D,D2;
  char C;
  str S,T,U;
  vint v(0);
  cin>>N>>M;
  N*500>=M?cout<<"Yes"<<endl:cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll H, W, N, i, j, a[100001], count, count2, ch=0, h, w, color[101][101], d=-1;
    
    cin >> H >> W >> N;

    for(i=1; i<=N; i++){
        cin >> a[i];
    }

    count = 1;
    h = 1; w = 1;
    
    while(1){
        color[h][w] = count;
        ch++;

        count2++;

        if(count2 >= a[count]){
            count2 = 0;
            count++;
        }

        if(ch==H*W){
            break;
        }
        else if(d==-1 && h<H){
            h++;
        }
        else if(d==-1){
            d = 1;
            w++;
        }
        else if(d==1 && h>1){
            h--;
        }
        else if(d==1){
            d = -1;
            w++;
        }
    }

    for(i=1; i<=H; i++){
        for(j=1; j<=W; j++){
            cout << color[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main() {
  int n,cnt = 0,c = 0,cc = 0;
  cin >> n;
  vector<int> p(n),p1(n),c2(60);
  for (int i = 0; i < n; i++){
    cin >> p[i];
    p1[i] = p[i];
  }
  sort(p1.begin(),p1.end());
  for (int i = 0; i < n; i++){
    if (p1[i] != p[i]){
      cnt++;
      c2[i]++;
      if (c != 0){
        c = i;
      }
      else{
        cc = i;
      }
    }
  }
  if (cnt > 2 || cnt == 1){
    cout << "NO\n";
    return 0;
  }
  else{
    cout << "YES\n";
  }
  
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    string s, t;
    cin >> s >> t;
    ll ns = s.size(), nt = t.size();
    map<char, vec> alpha;
    string ss = s + s;
    loop(i, ns * 2)
    {
        char nowalpha = ss[i];
        alpha[nowalpha].push_back(i);
    }
    ll ans = 0;
    ll now = -1;
    for (char al : t)
    {
        if (alpha[al].empty())
        {
            putout(-1);
            return 0;
        }
        ll next = *high2way(alpha[al], now);
        ans += next - now;
        now = next % ns;
    }
    putout(ans);
    return 0;
}


Measured memory_bytes: 5872
from fractions import gcd

mod = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))

lcm = 1
for s in A:
    lcm = s * lcm // gcd(lcm, s)

ans = lcm * sum([pow(s, mod - 2, mod) for s in A]) % mod

print(int(ans % mod))


Measured memory_bytes: 6200
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
using lint = long long;

#pragma GCC optimize ("O3", "unroll-loops")
#pragma GCC target ("arch=ivybridge")

const int nmax = 204800, block = 8192, unrl = 8;
int a[nmax], b[nmax];

int main() {

	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	for (int i = 0; i < N; i++) scanf("%d", &b[i]);

	int ans = 0;
	for (int i = 0; i + unrl <= N; i += unrl) {
		for (int j = 0; j + block <= N; j += block) {
			for (int k = j; k < block + j; k++) {

				ans ^= (a[i + 0] + b[k]) ^ (a[i + 1] + b[k]);
				ans ^= (a[i + 2] + b[k]) ^ (a[i + 3] + b[k]);
				ans ^= (a[i + 4] + b[k]) ^ (a[i + 5] + b[k]);
				ans ^= (a[i + 6] + b[k]) ^ (a[i + 7] + b[k]);

			}
		}
	}

	for (int i = 0; i < N / unrl * unrl; i++) {
		for (int j = N / block * block; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}	
	for (int i = N / unrl * unrl; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1792
// https://atcoder.jp/contests/abc177/tasks/abc177_f

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll H, W;
  cin >> H >> W;

  map<int, int> pos_to_start;
  multiset<int> min_steps;

  rep(w, W) {
    pos_to_start[w] = w;
    min_steps.insert(0);
  }

  rep(h, H) {
    ll l, r;
    cin >> l >> r;
    --l;

    auto it = pos_to_start.lower_bound(l);

    int most_right = -1;

    while (it != pos_to_start.end()) {
      auto [pos, start] = *it;
      unless(pos <= r) break;

      chmax(most_right, start);
      int diff = pos - start;
      min_steps.erase(min_steps.find(diff));
      pos_to_start.erase(it++);
    }

    if (most_right != -1 && r < W) {
      min_steps.insert(r - most_right);
      pos_to_start[r] = most_right;
    }

    int res = -1;
    if (min_steps.size() > 0) {
      res = *min_steps.begin() + (h + 1);
    }

    cout << res << "\n";
  }
}


Measured memory_bytes: 22372
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>



int main(int argc, char* argv[])
{
  using std::cin;
  using std::cout;
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;
  std::string S;
  cin >> S;

  std::vector<int> b(N);
  for (int i = 0; i < N; ++i)
  {
    b[i] = (i ? b[i-1] : 0) + ((S[i] == '#') ? 1 : 0);
  }

  std::vector<int> w(N+1);
  w[N] = 0;
  for (int i = N-1; i >= 0; --i)
  {
    w[i] = w[i+1] + ((S[i] == '.') ? 1 : 0);
  }

  int res = w[0];
  for (int i = 0; i < N; ++i)
  {
    res = std::min(res, b[i] + w[i+1]);
  }
  cout << res << "\n";

  return 0;
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, z, w;
ll a[3000];

int main(int argc, char** argv) {
	//freopen("in.txt","r",stdin);
	cin>>n>>z>>w;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	if(n == 1) {
		cout<<abs(a[1] - w)<<endl;
		return 0;
	}
	cout<<max(abs(a[n] - w), abs(a[n - 1] - a[n]))<<endl;
	return 0;
}

Measured memory_bytes: 256
def resolve():
    H, W = list(map(int, input().split()))
    A = ["#"+input()+"#" for i in range(H)]
    sharpline = "".join(["#" for i in range(W+2)])
    [print(line) for line in [sharpline]+A+[sharpline]]




if '__main__' == __name__:
    resolve()

Measured memory_bytes: 3060
#include<stdio.h>


int main(){
	int A, B, C, D, E, F;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	
	
	if(A<=B)	E=A;
	else	E=B;
	
	if(C<=D)	F=C;
	else	F=D;
	
	
	printf("%d", E+F);
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(c>=a && c<=a+b){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;cin>>N;
    long long T;cin>>T;
    vector<long long>V(N);
    for(int i=0;i<N;i++)cin>>V[i];
    long long ans=0;
    for(int i=0;i<N-1;i++){
        if(V[i+1]-V[i] >= T)ans+=T;
        else ans+=(V[i+1]-V[i]);
    }
    cout<<ans+T<<endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxd = 1e5+10;
int n;
char s[maxd];
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%d %s",&n,s);
    if(n>=3200) printf("%s",s);
    else printf("red");

    return 0;
}

Measured memory_bytes: 128
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

	N, K := getInt(), getInt()
	h := make([]int, N)
	for i := 0; i < N; i++ {
		h[i] = getInt()
	}

	dp := make([]int, N)
	dp[0] = 0
	for i := 1; i < N; i++ {
		dp[i] = math.MaxInt32
	}

	for i := 1; i < N; i++ {
		for j := 1; j <= K; j++ {
			if i-j >= 0 {
				c := asub(h[i], h[i-j])
				dp[i] = min(dp[i], dp[i-j]+c)
			}
		}
	}
	out(dp[N-1])
}


Measured memory_bytes: 2816
#include <iostream>
#include <unordered_set>

using namespace std;

int main(){
    int n; cin >> n;
    unordered_set<int> as;
    for(int i=0; i<n; ++i){
        int a; cin >> a;
        if(as.find(a)==as.end()) as.insert(a);
        else as.erase(a);
    }
    cout << as.size() << endl;
    return 0;
}


Measured memory_bytes: 4388
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<long long int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	int ans = 0;
	while (1) {
		for (int i = 0; i < N; i++) {
			if (!(A[i] % 2)) A[i] = A[i] / 2;
			else goto a;
		}
		ans++;
	}
a:
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

const LL mod = 998244353;

int n, m, k;
int xx1, yy1, xx2, yy2;
vector<string> s;
vector<vector<int>> vis, nxt[4];

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

int run() {
  queue<pair<int, int>> q;
  q.push({xx1, yy1});
  vis[xx1][yy1] = 0;

  while (q.size() > 0) {
    int x = q.front().first;
    int y = q.front().second;
    int w = vis[x][y];
    q.pop();

    for (int i = 0; i < 4; i++) {
      int nx = x, ny = y;
      int maxxj = 0;
      for (int j = 0; j <= k; ) {
        nx = x + dx[i] * j;
        ny = y + dy[i] * j;
        if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] == '.') {
          j += nxt[i][nx][ny];
          maxxj = j;
        } else {
          break;
        }
      }
      for (int j = 0; j <= k;) {
        nx = x + dx[i] * j;
        ny = y + dy[i] * j;
        if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] == '.') {
          if (vis[nx][ny] == -1) {
            vis[nx][ny] = w + 1;
            q.push({nx, ny});

            if (nx == xx2 && ny == yy2) {
              return w + 1;
            }
          }
          int cur = maxxj - j;
          j += nxt[i][nx][ny];
          nxt[i][nx][ny] = cur;
        } else {
          break;
        }
      }
   }
  }
  return -1;
}
int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  scanf("%d%d%d", &n, &m, &k);
  scanf("%d%d%d%d", &xx1, &yy1, &xx2, &yy2);
  xx1--, yy1--, xx2--, yy2--;

  s = vector<string>(n);
  vis = vector<vector<int>>(n, vector<int>(m, -1));
  nxt[0] = nxt[1] = nxt[2] = nxt[3] = vector<vector<int>>(n, vector<int>(m, 1));

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

  printf("%d\n", run());


#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 26856
import java.util.*;
import java.math.*;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);
	BigInteger bi;

	while(sc.hasNext()){
	    int cnt = 0;
	    for(int i = sc.nextInt(); i >= 1; --i){
		bi = new BigInteger(sc.next());
		if(bi.isProbablePrime(1000)) ++cnt;
	    }
	    System.out.printf("%d\n", cnt);
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 13000
import java.util.Arrays;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static boolean nextPermutation(int[] a) {
		for (int i = a.length - 1; i > 0; --i) {
			if (a[i - 1] < a[i]) {
				int swapIndex = find(a[i - 1], a, i, a.length - 1);
				int temp = a[swapIndex];
				a[swapIndex] = a[i - 1];
				a[i - 1] = temp;
				Arrays.sort(a, i, a.length);
				return true;
			}
		}
		return false;
	}

	// destより大きい要素の中で最小のもののインデックスを二分探索で探す
	private static int find(int dest, int[] a, int s, int e) {
		if (s == e) {
			return s;
		}
		int m = (s + e + 1) / 2;
		return a[m] <= dest ? find(dest, a, s, m - 1) : find(dest, a, m, e);
	}

	static void listup(int arr[], Set<String> result, int N) {
		int perm[] = new int[N];
		int idx = 0;
		for (int a = 0; a < arr.length; ++a) {
			for (int j = 0; j < arr[a]; ++j) {
				if(arr[a] == 1){
					perm[idx++] = -1;
				}else{
					perm[idx++] = a;					
				}
			}
		}
		do {
			StringBuilder sb = new StringBuilder();
			int map[] = new int[arr.length];
			Arrays.fill(map, -1);
			int m = 0;
			for (int i = 0; i < perm.length; ++i) {
				int v = perm[i];
				if(v < 0){
					char c = (char) ('a' + m);
					m++;
					sb.append(c);
				}else{
					if (map[v] < 0) {
						map[v] = m;
						m++;
					}
					char c = (char) ('a' + map[v]);
					sb.append(c);					
				}
			}
			result.add(sb.toString());
			// System.out.println(Arrays.toString(perm)+" "+sb);
		} while (nextPermutation(perm));
	}

	static void rec(int N, int K, int[] arr, int i, int up, Set<String> result,
			int L) {
		if (K == 0) {
			if (N == 0) {
//				System.out.println(Arrays.toString(arr));
				listup(arr, result, L);
			}
			return;
		}
		for (int u = up; u <= N; ++u) {
			arr[i] = u;
			rec(N - u, K - 1, arr, i + 1, u, result, L);
			arr[i] = 0;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<String> result = new TreeSet<String>();
		for (int K = 1; K < N; ++K) {
			// System.out.println(K);
			int arr[] = new int[K];
			rec(N, K, arr, 0, 1, result, N);
		}
		// K == N
		String sb = "";
		for(int i = 0 ; i < N ; ++i){
			sb = sb + (char)('a' + i);
		}
		result.add(sb);
//		System.out.println(result.size());
		for (String r : result) {
			System.out.println(r);
		}
	}
}


Measured memory_bytes: 74628
import std.stdio;
import std.string;
import std.math;
import std.conv;
import std.algorithm;
import std.bigint;

void main(){
    while(true){
	string input = readln();
	if(stdin.eof()) break;
	auto s = to!real(chomp(input));
	for(int i=1;;i++){
	    if(s*s < 19.6 * (5*i-5)) {
		writeln(i);
		break;
	    }
	}
    }
}

Measured memory_bytes: 2392
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D,T,S; cin >> D >> T >> S;
    cout << ((D+S-1)/S<=T?"Yes":"No") << '\n';
}

Measured memory_bytes: 3644