akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a <= 0 && b >= 0) cout << "Zero" << endl;
    else if(a > 0 && b > 0) cout << "Positive" << endl;
    else{
        if((a - b) % 2) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    }
}


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

const int MOD = 1e9+7;
const int N_MAX = 1e5;
long long int dp[N_MAX + 1][13];

void do_dp(int a, int dig, int mod_13){
  for(int k = 0; k <= 12; k++){
    if(k >= dig) dp[a][k] += dp[a+1][k-dig];
    else dp[a][k] += dp[a+1][13+k-dig];
    
    dp[a][k] %= MOD;
  }
}

int main(){
  string s; cin>>s;
  int n = s.size();
  
  memset(dp, 0, sizeof dp);
  
  int mod_13 = 10;
  
  if(s[n-1] == '?'){
    for(int i = 0; i <= 9; i++) dp[n-1][i] = 1;
  }else{
    dp[n-1][s[n-1] - '0'] = 1;
  }
  
  for(int i = n-2; i>=0; i--){
    int dig;
    if(s[i] == '?'){
      for(int j = 0; j <= 9; j++){
        dig = (mod_13 * j) % 13;
        do_dp(i, dig, mod_13);
      }
    }else{
      dig = s[i] - '0';
      dig = (mod_13 * dig) % 13;
      do_dp(i, dig, mod_13);
    }
    
    mod_13 = (mod_13 * 10) % 13;
  }

  cout<< dp[0][5]<<endl;
}

Measured memory_bytes: 10624
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);
    
    while (in.hasNext()) {
      int N = in.nextInt();
      int max = 0;
      int sum = 0;
      
      for (int i = 0; i < N; ++i) {
        int L = in.nextInt();
        
        max = Math.max(max, L);
        sum += L;
      }
      
      sum -= max;
      
      if (sum > max) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
}

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

long long read() {
	long long x = 0;
	int f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return f ? -x : x;
}

int main() {
	long long a, b, c;
	a = read(), b = read(), c = read();
	b = b * 100 + c;
	a *= b;
	a /= 100;
	std::cout << a;
	return 0;
}

Measured memory_bytes: 3632
n = input()
op_cntttt = len(n) - 1 
for i in range(2 ** op_cntttt):
    op = ["-"] * op_cntttt
    for j in range(op_cntttt):
        if ((i >> j) & 1):
            op[op_cntttt - 1 - j] = "+" 

    formula = ""
    for p_n, p_o in zip(n, op + [""]):  
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Measured memory_bytes: 38384
#include<stdio.h>
int main()
{
	long long int a,b,c=0,d=0,i;
	scanf("%lld %lld",&a,&b);
	for(i=1;i<=b;i++){
		c=a*i;
		d=c%b;
		if(d==0){
			printf("%lld\n",c);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n;cin>>n;
    if(n%2 == 0){
      cout<<n/2*n/2;
    }
    else{
      int a = (n-1)/2;
      int b = n-a;
      cout<<a*b;
    }
    return 0;
}

Measured memory_bytes: 3632
MOD = 10**9+7
fac = [1]*(2020)
for i in range(2,2020) :
    fac[i] *= fac[i-1] * i

def comb(n, k) :
    a = fac[n]
    b = fac[k] * fac[n-k]
    return (a//b) % MOD


N,K = map(int,input().split())

for i in range(1,K+1) :
    a = comb(N-K+1, i)
    b = comb(K-1, i-1)
    res = (a*b) % MOD
    print(res)


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

const ll mod = 1000000007;

int main(){
    int n,m;  cin >> n >> m;
    vector<int>a(m);
    rep(i, m)   cin >> a[i];
    //dp
    vector<ll>dp(n+5);
    dp[0] = 1;
    int ptr = 0;    
    rep(i, n){
        if(m){
            if(i == a[ptr]){
                ptr++;
                continue;
            }
            if(i+1 == a[ptr]){
                    if(i+2 == a[ptr+1]){
                        cout << 0 << endl;
                        return 0;
                    }else{
                        dp[i+2] += dp[i];
                        dp[i+2] %= mod;
                    }
            }else{
                dp[i+1] += dp[i];
                dp[i+1] %= mod;
                if(i+2 != a[ptr]){
                    dp[i+2] += dp[i];
                    dp[i+2] %= mod;
                }
            }
        }else{
            dp[i+1] += dp[i];
            dp[i+1] %= mod;
            dp[i+2] += dp[i];
            dp[i+2] %= mod;
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
#define S(i) ((int)(A[i]>=Pos))
#define LL long long
using namespace std;
int N,A[300001],INF=10000000;
bool Check(int Pos){
	int m[2];
	m[0]=m[1]=INF;
//	For(i,1,2*N-1) printf("%d ",S(i));puts("");
	For(i,N,2*N-2)
		if(S(i)==S(i+1)){
			m[S(i)]=min(m[S(i)],i-N);
//			cout<<'-'<<i<<' '<<S(i)<<endl;
			break;
		}
	Rof(i,N,2)
		if(S(i)==S(i-1)){
			m[S(i)]=min(m[S(i)],N-i);
			break;
		}
//	cout<<m[1]<<' '<<m[0]<<endl;
	if(m[0]==INF&&m[1]==INF)return (S(N)^(N&1)^1);
	if(m[1]<m[0])return 1;
	return 0;
}
int main(){
	scanf("%d",&N);For(i,1,2*N-1) scanf("%d",&A[i]);
	int l=1,r=2*N-1,Mid,Ans;
//	cout<<Check(4);

	while(l<=r){
		Mid=l+r>>1;
		if(Check(Mid))
			Ans=Mid,l=Mid+1;
		else
			r=Mid-1;
	}

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

	return 0;
}
/*
3
1 5 2 4 3
*/

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n, m;
	cin >> n >> m;
	priority_queue<int> q;
	rep(i,n){
		int k;
		cin >> k;
		q.push(k);
	}
	rep(i,m){
		int now = q.top();
		q.pop();
		now /= 2;
		q.push(now);
	}
	ll ans = 0;
	while(q.size()){
		int p = q.top();
		q.pop();
      	ans += p;
	}
	cout << ans << endl;
}

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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

ll mini(ll a,ll b){	return a<b?a:b;}
ll maxi(ll a,ll b){	return a>b?a:b;}
ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

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

    ll n,w;
    cin>>n>>w;
    
    vector<ll> dp[n+1];
    for(ll i=0;i<=n;++i)    dp[i].resize(w+1,0);

    ll row[n+1][2];
    row[0][0] = row[0][1] = 0;
    for(ll i=1;i<=n;++i)    cin>>row[i][0]>>row[i][1];

    for(ll i=1;i<=n;++i){
        for(ll j=1;j<=w;++j){
            if(row[i][0] <= j)  dp[i][j] = max(dp[i-1][j], dp[i-1][j-row[i][0]] + row[i][1]);
            else                dp[i][j] = dp[i-1][j];
        }
    }

    cout<<dp[n][w]<<"\n";

    return 0;
}

Measured memory_bytes: 82300
N,M = map(int,input().split())
X=sorted(map(int, input().split()))
if N==1:
  print(X[M-1]-X[0])
elif N>=M:
  print(0)
else:
  print(sum(sorted([i-j for i,j in zip(X[1:],X)],reverse=True)[N-1:]))

Measured memory_bytes: 13968
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val s = sc.nextLine()
    val k = sc.nextInt()
    val n = s.length
    val lst = s.toCharArray().distinct().sorted()
    val set = mutableSetOf<String>()
    for (c in lst) {
        for (i in 0 until n) {
            if (s[i] == c) {
                for (j in i + 1..Math.min(n, i + k)) {
                    val t = s.substring(i until j)
                    set.add(t)
                }
            }
        }
        if (set.count() >= k) {
            val l = set.sorted()
            println(l[k - 1])
            return
        }
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 38456
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    REP(i, 9){
        REP(j, 9){
            if ((i+1) * (j+1) == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;

    cout << (N % 2 == 0 ? 0.5 : ((double)(N + 1)) / ((double)(2 * N)))  << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string s;cin >>s;
  for(int i =0; i < 3; i++){
    if(s[i] == '9')s[i] = '1';
    else if(s[i] == '1') s[i] = '9';
  }
  cout << s << endl;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    bool f = false;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        f |= x % 2;
    }
    if (f) {
        cout << "first" << endl;
    } else {
        cout << "second" << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
using System;

namespace Testcode
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] d = Console.ReadLine().Split();
            int W = int.Parse(d[0]);
            int H = int.Parse(d[1]);
            int x = int.Parse(d[2]);
            int y = int.Parse(d[3]);
            int r = int.Parse(d[4]);



            if ((r <= x && x <= W - r) && (r <= y && y <= H - r))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}



Measured memory_bytes: 17940
#include<stdio.h>
struct Node{
  int a,b,c;
};
struct Node N[10000];
int depth(int);
int sibling(int);
int n;
int D[10000],S[10000];
int main(){
  int i,j,k,l,m,q,r,s;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    N[i].a=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&q,&r,&s);
    N[q].b=r;
    N[q].c=s;
    if(r!=-1){
      N[r].a=q;
    }
    if(s!=-1){
      N[s].a=q;
    }
  }
  for(i=0;i<n;i++){
    D[i]=depth(i);
    S[i]=0;
  }
  for(i=0;i<n;i++){
    if(N[i].b==-1 && N[i].c==-1){
      S[i]=0;
      k=N[i].a;
      l=1;
      while(1){
        if(k==-1){
          break;
        }
        if(S[k]<l){
          S[k]=l;
        }
        l++;
        k=N[k].a;
      }
    }
  }
  for(i=0;i<n;i++){
    j=0;
    printf("node %d: ",i);
    printf("parent = %d, ",N[i].a);
    printf("sibling = %d, ",sibling(i));
    if(N[i].b!=-1){
      j++;
    }
    if(N[i].c!=-1){
      j++;
    }
    printf("degree = %d, ",j);
    printf("depth = %d, ",D[i]);
    printf("height = %d, ",S[i]);
    if(N[i].a==-1){
      printf("root\n");
    }
    else if(N[i].b==-1 && N[i].c==-1){
      printf("leaf\n");
    }
    else{
      printf("internal node\n");
    }
    }
    return 0;
}

int depth(int r){
  int c=0;
  while(1){
    r=N[r].a;
    if(r==-1){
      break;
    }
    c++;
  }
  return c;
}

int sibling(int s){
  if(N[s].a==-1){
    return -1;
  }
  if(N[N[s].a].b!=s && N[N[s].a].b!=-1){
    return N[N[s].a].b;
  }
  if(N[N[s].a].c!=s && N[N[s].a].c!=-1){
    return N[N[s].a].c;
  }
  return -1;
}



Measured memory_bytes: 2040
import math
from functools import reduce
N = int(input())
T = [int(input()) for _ in range(N)]

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(T))

Measured memory_bytes: 9528
from collections import deque

H,W = map(int,input().split())
s = [['#'] * (W+2) for i in range(H+2)]
black = 0
for h in range(H):
    S = input()
    for w in range(W):
        s[h+1][w+1] = S[w]
        if S[w] == '#':
            black += 1

dxy = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def bfs(gh,gw):
    st = deque()
    sts = deque()
    push,pop = st.append, st.pop
    pushs,pops = sts.append, sts.pop
    cnt = 1
    push([-1,-1])
    pushs([-1,-1])
    push([1,1])
    g = 0
    while g < 1:
        t = 0
        for i in range(999999):
            now = pop()
            if now == [-1,-1]:
                push([-1,-1])
                break
            pushs(now)
        cnt += 1
        c = 0
        while t < 1:
            now = pops()
            #print(now,c)
            if now == [-1,-1]:
                if c == 0:
                    return -1
                    break
                pushs([-1,-1])
                t = 1
                break
            c = 1

            
            for dx,dy in dxy:
                if s[now[0]+dx][now[1]+dy] == '#':
                    continue
                if [now[0]+dx,now[1]+dy] == [gh,gw]:
                    g = 1
                    #print(cnt,black)
                    return H*W-black-cnt
                if s[now[0]+dx][now[1]+dy] == '.':
                    push([now[0]+dx,now[1]+dy])
                    s[now[0]+dx][now[1]+dy] = '#'

print(bfs(H,W))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int K,A,B;
  cin >> K >> A >> B;

  for(int i=A;i<=B;i++){
    if(i%K==0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;

  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 5100000;
const int MOD = 1e9 + 7;

const double PI=3.14159265358979323846;


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

vector<double> cx, cy, c;
 ll MM = 1e12;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}

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

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}



int main(){
    ll n,m;
    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2;
    return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAX 32

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

int n, m;

bool exist[MAX][MAX];

int main(void) {
    while (cin >> n) {
        if (n == 0) break;
        for (int i = 0; i <= 20; i++) {
            for (int j = 0; j <= 20; j++) {
                exist[i][j] = false;
            }
        }
        for (int i = 0; i < n; i++) {
            int x, y;
            cin >> x >> y;
            exist[y][x] = true;
        }
        int nowx = 10;
        int nowy = 10;
        cin >> m;
        for (int i = 0; i < m; i++) {
            //printf("now pos (%d %d)\n", nowx, nowy);
            char d;
            int l;
            cin >> d >> l;
            if (exist[nowy][nowx]) exist[nowy][nowx] = false;
            if (d == 'N') {
                for (int j = 0; j < l; j++) {
                    nowy++;
                    if (exist[nowy][nowx]) exist[nowy][nowx] = false;
                }
            }
            if (d == 'S') {
                for (int j = 0; j < l; j++) {
                    nowy--;
                    if (exist[nowy][nowx]) exist[nowy][nowx] = false;
                }
            }
            if (d == 'E') {
                for (int j = 0; j < l; j++) {
                    nowx++;
                    if (exist[nowy][nowx]) exist[nowy][nowx] = false;
                }
            }
            if (d == 'W') {
                for (int j = 0; j < l; j++) {
                    nowx--;
                    if (exist[nowy][nowx]) exist[nowy][nowx] = false;
                }
            }
        }
        if (exist[nowy][nowx]) exist[nowy][nowx] = false;
        bool ok = true;
        for (int y = 0; y <= 20; y++) {
            for (int x = 0; x <= 20; x++) {
                if (exist[y][x]) {
                    ok = false;
                    break;
                }
            }
            if (!ok) break;
        }
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        Integer[] h = new Integer[n];
        for(int i = 0; i < n; i++) h[i] = scan.nextInt();
        Arrays.sort(h, Comparator.reverseOrder());
        try{for(int i = 0; i < k; i++) h[i] = 0;}catch(Exception e){}
        long out = 0;
        for(int i = 0; i < n; i++) out += h[i];
        System.out.println(out);
        scan.close();
    }
}

Measured memory_bytes: 54048
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	vll a(n),b(n),c(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) >> b.at(i) >> c.at(i) ;
	ll ans = -INF ;
	vll sub(n) ;
	ll cnt1,cnt2 ;
	for(int i=0;i<n;i++) sub.at(i) = a.at(i)+b.at(i)+c.at(i) ;
	sort(all(sub)) ;
	cnt1 = 0 ; cnt2 = 0 ;
	for(int i=0;i<m;i++){
		cnt1 -= sub.at(i) ;
		cnt2 += sub.at(n-1-i) ;
	}
	ans = max(ans,max(cnt1,cnt2)) ;
	for(int i=0;i<n;i++) sub.at(i) = a.at(i)+b.at(i)-c.at(i) ;
	sort(all(sub)) ;
	cnt1 = 0 ; cnt2 = 0 ;
	for(int i=0;i<m;i++){
		cnt1 -= sub.at(i) ;
		cnt2 += sub.at(n-1-i) ;
	}
	ans = max(ans,max(cnt1,cnt2)) ;
	for(int i=0;i<n;i++) sub.at(i) = a.at(i)-b.at(i)+c.at(i) ;
	sort(all(sub)) ;
	cnt1 = 0 ; cnt2 = 0 ;
	for(int i=0;i<m;i++){
		cnt1 -= sub.at(i) ;
		cnt2 += sub.at(n-1-i) ;
	}
	ans = max(ans,max(cnt1,cnt2)) ;
	for(int i=0;i<n;i++) sub.at(i) = -a.at(i)+b.at(i)+c.at(i) ;
	sort(all(sub)) ;
	cnt1 = 0 ; cnt2 = 0 ;
	for(int i=0;i<m;i++){
		cnt1 -= sub.at(i) ;
		cnt2 += sub.at(n-1-i) ;
	}
	ans = max(ans,max(cnt1,cnt2)) ;
	cout << ans << endl ;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T>
inline bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template <class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

int main(){
    int n,k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    int sum = 0;
    for (int i = 0; i < k; i++){
        bool flag = false;
        for (int j = i; j < n; j+=k){
            if (j >= k && t[j] == t[j - k] && flag)
                flag = false;
            else{
                if (t[j] == 'r')
                    sum += p;
                else if (t[j] == 's')
                    sum += r;
                else if (t[j] == 'p')
                    sum += s;
                flag = true;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define N 100005
#define M 10000000000
#define endl "\n"
using namespace std;

int m, k;


vector<vector<int>> cost;

long long  MAX = 0;


int dp[N][4];




int maxCost(int i, int j)
{


	if (i == m)
		return 0;


	if (dp[i][j] != -1)
		return dp[i][j];

	int  choice = 0;



	for (int k = 0; k < 3; ++k)
	{

		if (k != j)
		{

			choice = max(choice, cost[i][k] + maxCost(i + 1, k));
		}


	}


	return dp[i][j] = choice;


}


int32_t main()
{

	cin >> m ;



	cost.resize(m, vector<int>(3));


	for (int i = 0; i < m; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin >> cost[i][j];

		}
	}

	// for (int i = 0; i < m; ++i)
	// {
	// 	for (int j = 0; j < 3; ++j)
	// 	{
	// 		cout << cost[i][j] << " ";

	// 	}

	// 	cout << endl;
	// }


	memset(dp, -1, sizeof(dp));



	cout << maxCost(0, 3) << endl;

}

Measured memory_bytes: 18032
import java.util.Scanner;
import java.math.*;
import java.math.*;
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		//int a = sc.nextInt();
		// スペース区切りの整数の入力
		//int b = sc.nextInt();
		//int c = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		//1文字ずつ
		//s.atChar(i);
		// 出力
		//System.out.println("");
		//int count=0;
		//int N=sc.nextInt();
		
		String s =sc.next();
		int n=0;
		for(int i=0;i<4;i++){
			if(s.charAt(i)=='+'){
				n++;
			}else{
				n--;
			}
		}
		System.out.println(n);
	}
}

Measured memory_bytes: 23764
using System;
using System.Collections.Generic;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題166



            string S = Console.ReadLine();

            if (S == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }

        }


    }
}


Measured memory_bytes: 25868
#include <iostream>
#include <cstdio>
#define int long long 
using namespace std;
 
signed main(){
 
  int a[3];
  int x, num;
  num = 0;
 
  for(int i = 0; i < 3; i++)
    scanf("%d", &a[i]);
  scanf("%d", &x);
 
  for(int i = 0; i <= a[0]; i++)
  {
    for(int j = 0; j <= a[1]; j++)
    {
      for(int k = 0; k <= a[2]; k++)
      {
        int sm = i * 500 + j * 100 + k * 50;
        if(sm == x)
          num++;
      }
    }
  }
  printf("%d", num);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main(){
 
    int n = 0;
    std::cin >> n;
    
    if(n == 111){
     
        std::cout << "999" << std::endl;
        
    }else if(n == 119){
     
        std::cout << "991" << std::endl;
        
    }else if(n == 191){
     
        std::cout << "919" << std::endl;
        
    }else if(n == 199){
     
        std::cout << "911" << std::endl;
        
    }else if(n == 911){
     
        std::cout << "199" << std::endl;
        
    }else if(n == 919){
     
        std::cout << "191" << std::endl;
        
    }else if(n == 991){
     
        std::cout << "119" << std::endl;
        
    }else{
    
        std::cout << "111" << std::endl;

    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));

struct UnionFind{
	vector<int> data;
	
	UnionFind(int sz){
		data.assign(sz, -1);
	}
	
	bool unite(int x, int y){
		x = find(x); y = find(y);
		if(x == y) return false;
		if(data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	
	int find(int k){
		if(data[k] < 0) return k;
		else return data[k] = find(data[k]);
	}
	
	bool same(int x, int y){
		if(find(x) == find(y)) return true;
		else return false;
	}
	
	int size(int k){
		return -data[find(k)];
	}
};

int n,A,B;

int main(){
	cin >> n >> A >> B;
	
	UnionFind uf1(n), uf2(n);
	REP(i,0,A){
		int a,b; cin >> a >> b;  a--; b--;
		uf1.unite(a, b);
	}
	
	REP(i,0,B){
		int a,b; cin >> a >> b; a--; b--;
		uf2.unite(a, b);
	}
	
	vector<P> vec;
	REP(i,0,n) vec.push_back({uf1.find(i), uf2.find(i)});
	sort(vec.begin(), vec.end());
	
	REP(i,0,n){
		P p = P(uf1.find(i), uf2.find(i));
		int pos = upper_bound(vec.begin(), vec.end(), p) - lower_bound(vec.begin(), vec.end(), p);
		cout << pos << " ";
	} cout << endl;
	return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i< (n);i++)
#define rep1(i,n) for(int i=1;i<= (n);i++)
using namespace std;
typedef long long ll;
const static ll MOD = (1e+9)+7;

int main(){
    int K;cin>>K;
    vector<ll> lst={1,2,3,4,5,6,7,8,9};
    while(true){
        if(K<lst.size()){
            cout<<lst[K-1]<<endl;
            break;
        }
        K-=lst.size();
        vector<ll> old;
        swap(old,lst);
        for(ll x:old){
            for(int i=-1;i<=1;i++){
                int tmp = x%10 + i;
                if(tmp >= 0 && tmp<=9){
                    lst.push_back(x*10+tmp);
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        string S;
        cin >> N >> S;
        vll e_cnt(N+1, 0);
        vll w_cnt(N+1, 0);
        rep(i, 0, N) {
                e_cnt[i+1] = e_cnt[i] + (int)(S[i] == 'E');
        }
        for (int i = N; i >= 1; --i) {
                w_cnt[i-1] = w_cnt[i] + (int)(S[i-1] == 'W');
        }

        rep(i, 1, N+1) {
                e_cnt[i] += w_cnt[i-1];
        }
        ll pos = max_element(all(e_cnt)) - e_cnt.begin();
        if (pos == 0 or pos == 1) {
                cout << count(S.begin()+1, S.end(), 'E') << endl;
        } else if (pos == N) {
                cout << count(S.begin(), S.end()-1, 'W') << endl;
        } else {
                cout << count(S.begin(), S.begin()+pos-2, 'W') + count(S.begin()+pos, S.end(), 'E') << endl;
        }
}

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

#define int long long
#define ld long double

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>b;i--)

#define pb push_back
#define mp make_pair
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define precise(i) fixed << setprecision(i)
#define fi first
#define se second

#define err() cout<<"\n==================================\n";
#define errA(A) for(auto i:A) cout<<i<<" "; cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n";
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n";
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n";
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<"\n";

const int logN = 20;
const int M = 998244353;
const int INF = 1e12;
#define PI 3.14159265;
const int N = 200005;

#define Pii pair<int,int>
#define Vi vector<int>
#define Vpii vector<Pii>

void solve()
{
       int n,s;
       Vi a(3001);
       vector<Vi> dp(3001, Vi(3001));
       cin>>n>>s;
       rep(c,1,n+1)
       {
              cin>>a[c];
       }
       dp[0][0]=1;
       rep(c,1,n+1)
       {
              rep(d,0,s+1)
              {
                     dp[c][d]+=2*(dp[c-1][d]);
                     dp[c][d]%=M;
                     if((d+a[c])<=s)
                     {
                            dp[c][d+a[c]]+=dp[c-1][d];
                            dp[c][d+a[c]]%=M;
                     }
                     
              }
       }
       cout<<dp[n][s]<<"\n";
}

int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)
    {
           solve();
    }
    return 0;
}

Measured memory_bytes: 73628
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

bool isprime[1000000];
int x;

void erastos(int n){
	rep(i, n){
		isprime[i] = true;
	}
	isprime[0] = false;
	isprime[1] = false;

	REP(i, 2, n){
		if (isprime[i]){
			int j = i * 2;
			while (j <= n){
				isprime[j] = false;
				j += i;
			}
		}
	}
}

int main() {

	cin >> x;

	erastos(100100);

	while (!isprime[x])x++;

	cout << x << endl;

	return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

int main(void)
{
  int n;
  int sumb=0;
  int s[300010];
  cin>>n;
  for(int i=0;i<n;i++)
    {
      char tmp;
      cin>>tmp;
      if(tmp=='E')
	{
	  s[i]=-1;
	}
      else
	{
	  s[i]=1;
	}
      sumb+=s[i];
    }
  int suma=0;
  int iti=0;
  sumb-=s[0];
  int max=sumb-suma;
  for(int i=1;i<n;i++)
    {
      suma+=s[i-1];
      sumb-=s[i];
      if(max<(sumb-suma))
	{
	  max=sumb-suma;
	  iti=i;
	}
    }
  int ans=0;
  for(int i=0;i<iti;i++)
    {
      if(s[i]==1)ans++;
    }

  for(int i=iti+1;i<n;i++)
    {
      if(s[i]==-1)ans++;
    }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1408
N=int(input())
answer=[3,5,7]
for i in range(8):
  A=[i*10+3 for i in answer]
  C=[i*10+5 for i in answer]
  B=[i*10+7 for i in answer]
  answer.extend(A)
  answer.extend(B)
  answer.extend(C)
s=0
answer=list(set(answer))
for i in answer:
  if i<=N:
    if set(str(i))=={"3","5","7"}:
      s+=1
print(s)

Measured memory_bytes: 84320
#include <stdio.h>
#include <algorithm>
using namespace std;

int n, a[100005];

int main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", &a[i]);
    sort(a, a+n);
    int cont = 0;
    int j = 0;
    while(cont < n-1){
        /*for(int i=0; i<n; i++)
            printf("%d   ", a[i]);*/
        for(int i=j+1; i<n; i++){
            a[i] = a[i]%a[j];
            if(a[i] == 0)
                cont++;
        }
        sort(a, a+n);
        j = cont;
        //printf("\n");
    }
    printf("%d\n", a[n-1]);
}


Measured memory_bytes: 512
n,m,l = map(int,input().split())
A = []
B = []

for _ in range(n):
    A.append(list(map(int,input().split())))
for _ in range(m):
    B.append(list(map(int,input().split())))

ans = []
for i in range(n):
    row = []
    for j in range(l):
        total = 0
        for k in range(m):
            total += A[i][k] * B[k][j]
        row.append(total)
    ans.append(row)

for line in ans:
    print(' '.join(map(str, line)))



Measured memory_bytes: 6908
#include<iostream>
#include<cctype>
#include<vector>
#include <ctype.h>
#include<algorithm>
#include<queue>
#include<string>
#include <math.h>
using namespace std;
char op;
int a, b;
int main() {
	cin >> a >> op >> b;
	if (op == '+')cout << a + b << endl;
	else cout << a - b << endl;
	return 0;
	}




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


int main(){
  int S,m,s,h;
  cin >> S;

  h = S/3600;
  
  m = (S-(h*3600))/60;
  
  s = (S-(h*3600)-(m*60));
  
  cout << h <<":" << m << ":" << s << endl;
  
  return 0;
}

Measured memory_bytes: 1168
H,W = map(int,input().split())
#l = sorted([int(input()) for i in range(N)],reverse=True)
def three(h,w):
    ans = h*w
    for i in range(1,h):
        A = w*i
        B = w*((h-i)//2)
        C = w*((h-i+1)//2)
        ans = min(ans,max(A,B,C)-min(A,B,C))
    return ans
def onetwo(h,w):
    ans = h*w
    for i in range(1,h):
        A = w*i
        B = (h-i)*(w//2)
        C = (h-i)*((w+1)//2)
        ans = min(ans,max(A,B,C)-min(A,B,C))
    return ans
print(min(three(H,W),three(W,H),onetwo(H,W),onetwo(W,H)))

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#define mp make_pair
#define pb push_back

using LL = long long;
using namespace std;

typedef pair<int, int> pii;

bool dp[10000000];

int main() {
	int M, N;
	while (cin >> M >> N, M) {
		memset(dp, 0, sizeof(dp));
		int x = M;
		int cnt = 0;
		for (;;) {
			if (!dp[x]) {
				for (int j = x + x; j < 10000000; j += x) {
					dp[j] = true;
				}
				++cnt;
			}
			if (cnt > N) {
				break;
			}
			++x;
		}
		cout << x << endl;
	}
}


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

using namespace std;

int n;
map<int, int> orig;
int a[112123];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		orig[a[i]] = i;
	}
	int ans = 0;
	sort(a, a + n);
	for (int i = 0; i < n; i++)
	{
		if (i % 2 != orig[a[i]] % 2)
			ans++;
	}
	cout << ans / 2 << '\n';
	return 0;
}



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

using namespace std;

const int N = 1e5+7;

int n;
int cnt[42];
long long a, k, res;
long long mind = -1, dis;

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a;
        for (int j = 0; j <= 40; ++j) {
            if (a&(1ll<<j)) ++cnt[j];
        }
    }
    for (int j = 40, flag = 1; j >= 0; --j) {
        if ((1ll<<j) > k) {
            res += cnt[j]*(1ll<<j);
            continue;
        }
        if (flag) {
            int choose = cnt[j] >= n-cnt[j] ? 0 : 1;
            dis = (n-cnt[j]-cnt[j])*(1ll<<j);
            if ((k&(1ll<<j)) && choose == 0) {
                flag = 0;
                res += cnt[j]*(1ll<<j);
            } else if ((choose == 1 && (k&(1ll<<j))) || (choose == 0 && (k&(1ll<<j)) == 0)) {
                res += max(cnt[j], n-cnt[j])*(1ll<<j);
            } else if (choose == 1 && (k&(1ll<<j)) == 0) {
                if (dis >= mind) {
                    flag = 0;
                    res += (n-cnt[j])*(1ll<<j) - mind;
                } else {
                    res += cnt[j]*(1ll<<j);
                }
            }
            if (choose && (mind == -1 || mind > dis)) mind = dis;
        } else {
            res += max(cnt[j], n-cnt[j])*(1ll<<j);
        }
    }
    cout << res << endl;
    return 0;
}

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

int x,y,tx,ty,kx,ky,cou;
int mas[51][51];
int ans=0;
bool used[51][51][51][51];
int dx[]={-1,0,0,1};
int dy[]={0,-1,1,0};
struct P{
  int tx,ty,kx,ky,cou;
  P(int tx,int ty,int kx,int ky,int cou):tx(tx),ty(ty),kx(kx),ky(ky),cou(cou){}
};
int bfs();

int main(){
  while(1){
    cin >> x >> y;
    if(x==0 && y==0) break;
    memset(used,false,sizeof(used));
    cin >> tx >> ty;
    cin >> kx >> ky;
    for(int i=0;i<y;i++){
      for(int j=0;j<x;j++){
	cin >> mas[i][j];
      }
    }
    ans = bfs();
    if(ans==-1) cout << "NA" << endl;
    else cout << ans << endl;
  }
}

int bfs(){
  queue<P> que;
  que.push(P(tx-1,ty-1,kx-1,ky-1,0));
  used[tx-1][ty-1][kx-1][ky-1] = true;
  while(!que.empty()){
    P p=que.front();
    if(p.tx==p.kx && p.ty==p.ky) return p.cou;
    else if(p.cou>=100) return -1;
    for(int i=0;i<4;i++){
      int ntx=p.tx+dx[i];
      int nty=p.ty+dy[i];
      int nkx=p.kx+dx[3-i];
      int nky=p.ky+dy[3-i];
      if(ntx<0 || ntx>=x || nty<0 || nty>=y || mas[nty][ntx]==1){
	ntx=p.tx;
	nty=p.ty;
      }
      if(nkx<0 || nkx>=x || nky<0 || nky>=y || mas[nky][nkx]==1){
	nkx=p.kx;
	nky=p.ky;
      }
      if(used[ntx][nty][nkx][nky]==false){
	que.push(P(ntx,nty,nkx,nky,p.cou+1));
	used[ntx][nty][nkx][nky] = true;
      }
    }
    que.pop();
  }
  return -1;
}

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

const int N = 2e5;
int cnt[N];

int main() {
	int n; scanf("%d", &n);
	int a; rep(i,n-1) scanf("%d", &a), ++cnt[a-1];
	rep(i,n) printf("%d\n", cnt[i]);
}

Measured memory_bytes: 4540
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

int N;

double dp[301][301][301];

double func(int a, int b, int c) {
	int sum = a + b + c;
	if(sum==0) {
		return 0;
	}
	if(dp[a][b][c]==0) {
		double ret = (double)N / sum;
		if(a) {
			ret += func(a-1, b, c) * a / sum;
		}
		if(b) {
			ret += func(a+1, b-1, c) * b / sum;
		}
		if(c) {
			ret += func(a, b+1, c-1) * c / sum;
		}
		dp[a][b][c] = ret;
	}
	return dp[a][b][c];
}

int main() {
	scanf("%d", &N);
	int cnt[1024] = {0};
	for(int n=0; n<N; ++n) {
		int a;
		scanf("%d", &a);
		++cnt[a];
	}
	printf("%.20f\n", func(cnt[1], cnt[2], cnt[3]));
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

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

	int x =  a[0]*a[4];
	int y = 0;
	if(a[4] > a[2]) y = a[1]+(a[4]-a[2])*a[3];
	else y = a[1];

	cout << min(x,y) << endl;

	return 0;

}



Measured memory_bytes: 3216
#include <iostream>

int main()
{
    int in[5];
    std::cin >> in[0];
    std::cin >> in[1];
    std::cin >> in[2];
    std::cin >> in[3];
    std::cin >> in[4];

    int md = 10;
    int mi = -1;
    for (int i = 0; i < 5; ++i)
    {
        int m = in[i] % 10;
        if (m != 0 && m < md)
        {
            md = m;
            mi = i;
        }
    }

    int ans = 0;
    for (int i = 0; i < 5; ++i)
    {
        if (i != mi)
        {
            ans += (int)(in[i] / 10) * 10;
            if (in[i] % 10 != 0)
            {
                ans += 10;
            }
        }
    }

    ans += in[mi];

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
sm = sum(A)

ans = None
# if A[7] >= sm * (1/(4*M)):
if 4 * M * A[M-1] >= sm:
    ans = True
else:
    ans = False

if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	int n;
	cin >> n;
	vl a(n);
	rep(i,0,n) {
		cin >> a[i];
	}
	ll ret = 0;
	rep(iter,0,10000) {
		vl p(n);
		rep(i,0,n) {
			p[i] = a[i]/n;
			a[i] = a[i]%n;
		}
		ll total = 0;
		rep(i,0,n) {
			total += p[i];
		}
		rep(i,0,n) {
			a[i] += total-p[i];
		}
		ret += total;
	}
	cout << ret << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define add push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

int L, n;
int cur, ans[111][3];

void add(int a,int b,int c){
	ans[cur][0]=a;
	ans[cur][1]=b;
	ans[cur][2]=c;
	cur++;
}
main(){
    #define task "TASK"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);

	L=in, n=1;
	int cap=2;
	while(cap<=L){
        n++;
        cap*=2;
	}
	cur=0;
	int dig=1;
	fordec(i,n,2){
        add(i-1,i,0);
        add(i-1,i,dig);
        dig*=2;
	}
	L-=cap/=2;
	int v=cap;
	forinc(i,2,n){
        cap/=2;
        if(L>=cap){
            add(1,i,v);
            L-=cap;
            v+=cap;
        }
	}
	cout<<n<<" "<<cur<<"\n";
	forinc(i,0,cur-1){
        forinc(j,0,2) cout<<ans[i][j]<<" ";
        cout<<"\n";
	}
}



Measured memory_bytes: 256
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!
 
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	let K = parseInt(input[0].split(" ")[0]);
	let N = parseInt(input[0].split(" ")[1]);
	let A = input[1].split(" ").map(Number);
	let s=0,t=-Infinity;
	for(let i=1;i<N;i++){
	    if(A[i]-A[i-1]>t){
	        s=i;
	        t=A[i]-A[i-1];
	    }
	    //console.log(s,t);
	}
    if(A[0]+K-A[N-1]>t){
	        s=0;
	        t=A[0]+K-A[N-1];
	}
	//console.log(s,t);
	//console.log(A[s],A[s==0?N-1:s-1])
    if(A[s]>A[s==0?N-1:s-1]){
        console.log(A[s==0?N-1:s-1]+K-A[s]);
    }else{
        console.log(A[s==0?N-1:s-1]-A[s]);
    }
    
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 36116
function Main(s){
	s=s.split(/\n|\s/);
	s.forEach(function(e,i,a){a[i]=Number(a[i]);});
	var a=s[0]+s[1];
	var b=s[0]-s[1];
	var c=s[0]*s[1];
	a=a>b?a:b;
	a=a>c?a:c;
	
	console.log(a|0);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

int main () {
    int a, b; std::string s;
    std::cin >> a >> b >> s;

    bool f = true;
    for(int i = 0; i < s.size(); i++) {
        if(a != i) {
            if(s[i] == '-') {
                f = false;
            }
        } else {
            if(s[i] != '-') {
                f = false;
            }
        }
    }

    std::string ans = f?"Yes":"No";
    std::cout << ans << "\n";
}

Measured memory_bytes: 3608