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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n; i < (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
void debug(vector<vector<ll>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
void debug(vector<ll>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
//m.emplace(x,0).fi->second++;

int main(){
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  string s;cin>>s;
  reverse(ALL(s));
  ll n=s.size();
  vector<vector<ll>>dp(n+1,vector<ll>(13));
  dp[0][0]=1;
  buf=1;
  ll tmp=1;
  rep(i,0,n){
    if(s[i]!='?'){
      rep(j,0,13){
        pmod(dp[i+1][(j+tmp*(s[i]-'0'))%13],dp[i][j]);
      }
    }
    else{
      rep(j,0,10){
        rep(o,0,13){
          pmod(dp[i+1][(o+tmp*j)%13],dp[i][o]);
        }
      }
    }
    tmp*=10;
    tmp%=13;
  }
  cout<<dp[n][5]<<endl;
  //debug(dp,n+1,13);
  return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
int n,a[100002],b[100002],c[100002],d,s;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
     cin>>n;
     for(int i=1;i<n+1;i++){
	     cin>>a[i]>>b[i]>>c[i];
     }
     for(int i=2;i<n+1;i++){
         a[i]=a[i]+max(b[i-1],c[i-1]);
         b[i]=b[i]+max(a[i-1],c[i-1]);
         c[i]=c[i]+max(a[i-1],b[i-1]);
     }
     d=max(a[n],b[n]);
     s=max(d,c[n]);
     cout<<s;
return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int h[] = new int[n];
        for(int i=0;i<n;i++)h[i]=sc.nextInt();

        long dp[]= new long[n];
        dp[0]=0;
        dp[1]=Math.abs(h[1]-h[0]);

        for(int i=2;i<n;i++){
            dp[i]=Long.MAX_VALUE;
            for(int j=1;j<Math.min(i,k)+1;j++){
                //System.out.println(i-j+" "+i);
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(h[i-j]-h[i]));
            }
        }
        System.out.println(dp[n-1]);
    }
}


Measured memory_bytes: 49988
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

vector<bool> bit(int X) {
	vector<bool> V(30);
	for (int i = 29;i >= 0;i--) {
		V[i] = X & 1;
		X >>= 1;
	}
	return V;
}

int main(){
	int N, K;
	cin >> N >> K;
	vector<bool> KB = bit(K);

	vector<pair<ll, vector<bool>>> W;
	vector<bool> X;
	ll A, B;

	for (int i = 0;i < N;i++) {
		cin >> A >> B;
		W.push_back(make_pair(B, bit(A)));
	}
	sort(all(W));reverse(all(W));

	ll ans = 0, a;
	for (int i = 0;i <= 30;i++) {
		if (!KB[i])continue;
		KB[i] = 0;
		a = 0;
		for (int j = 0;j < N;j++) {
			tie(B, X) = W[j];
			for (int k = 0;k <= i;k++) {
				if ((!KB[k]) && X[k]) {
					B = 0;break;
				}
			}
			a += B;
		}
		KB[i] = 1;
		ans = max(ans, a);
	}
	a = 0;
	for (int j = 0;j < N;j++) {
		tie(B, X) = W[j];
		for (int k = 0;k < 30;k++) {
			if ((!KB[k]) && X[k]) {
				B = 0;break;
			}
		}
		a += B;
	}
	ans = max(ans, a);
	cout << ans << endl;
}

Measured memory_bytes: 10288
#include <bits/stdc++.h>
using namespace std;
 
bool d[10];
 
bool check(int n) {
  while (n > 0) {
    if (d[n % 10]) return false;
    n /= 10;
  }
  return true;
}
 
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    int t;
    cin >> t;
    d[t] = true;
  }
  for (int i = n;; ++i) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read() {
	char c=getchar(); int x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int main() {
	int k=read(),a=read(),b=read();
	ll ans=k+1;
	if (a-1<=k) {
		k-=a-1;
		ll now=a;
		if (b-a>2) now+=1LL*(b-a)*(k/2);
		if (k&1) ++now;
		ans=max(ans,now);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll MOD = 1e16 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
long long longpow(long long n, long long a, long long mod) {
  if (a == 0) return 1;
  if (a == 1) return n % mod;
  if (a % 2 == 1) return (n * longpow(n, a - 1, mod)) % mod;
  ll t = longpow(n, a / 2, mod) % mod;
  return (t * t) % mod;
}
int main() {
  int n;
  int sum = 0;
  string S;
  cin >> n >> S;
  for (int i = 0; i < n; i++) {
    if (S[i] == '1') sum++;
  }
  if (sum == 0) {
    for (int i = 0; i < n; i++) {
      cout << 1 << endl;
    }
    return 0;
  }
  vector<int> count_p1(n), count_m1(n);
  count_p1[0] = 1 % (sum + 1);
  if (sum != 1) count_m1[0] = 1 % (sum - 1);
  for (int i = 1; i < n; i++) {
    count_p1[i] = (count_p1[i - 1] * 2) % (sum + 1);
    if (sum != 1) count_m1[i] = (count_m1[i - 1] * 2) % (sum - 1);
  }
  int r_p1 = 0, r_m1 = 0;
  for (int i = 0; i < n; i++) {
    if (S[i] == '1') {
      r_p1 += count_p1[n - 1 - i];
      if (sum != 1) r_m1 += count_m1[n - 1 - i];
      r_p1 %= sum + 1;
      if (sum != 1) r_m1 %= sum - 1;
    }
  }
  for (int i = 0; i < n; i++) {
    int r = 0;
    if (S[i] == '1') {
      if (sum == 1) {
        cout << 0 << endl;
        continue;
      }
      r = r_m1;
      r -= count_m1[n - 1 - i];
      while (r < 0) r += sum - 1;
    } else {
      r = r_p1;
      r += count_p1[n - 1 - i];
      r %= sum + 1;
    }
    int cnt = 1;
    while(r>0){
      int x = r;
      int popcount = 0;
      while(x>0){
        if (x % 2 == 1) popcount++;
        x /= 2;
      }
      r %= popcount;
      cnt++;
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
long long n,a[100002],z=1,ans=0;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=2;i<=n;i++)
    {
        if(a[i]==a[i-1])
		{
			z=(z+1)%2;
		}
        else
		{
			ans+=z;
			z=1;
		}
    }
    if(z%2==1)ans++;
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int res = 0;
    int N = S.length();
    string S1 = S.substr(0,(N-1)/2);
    string S2 = S.substr((N+3)/2-1,N-((N+3)/2-1));
    for(int i = 0; i < N ; i++){
        if(S[i] != S[N-1-i]) res = 1;
    }

    for(int i = 0; i < S1.length() ; i++){
        if(S[i] != S[S1.length()-1-i]) res = 1;
    }
    for(int i = 0; i < S2.length() ; i++){
        if(S[i] != S[S2.length()-1-i]) res = 1;
    }
    if(res == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> fromOne(0);
  vector<int> toN(0);
  for(int i=0;i<m;i++) {
    int a, b;
    cin >> a >> b;
    if(a == 1) fromOne.push_back(b);
    if(b == n) toN.push_back(a);
  }

  sort(fromOne.begin(), fromOne.end());
  sort(toN.begin(), toN.end());

  vector<int> intersection;

  set_intersection(fromOne.begin(), fromOne.end(), toN.begin(), toN.end(), back_inserter(intersection));

  if(intersection.size()) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 1276
INF = float('inf')
N, M = map(int, input().split())
dp = [INF for _ in range(2**N)]
dp[0] = 0
for i in range(M):
    a, _ = map(int, input().split())
    *C, = map(int, input().split())
    open_bit = 0
    for i in C: open_bit |= 1 << i-1
    for i in range(2**N):
        temp = dp[i] + a
        if dp[i|open_bit] > temp: dp[i|open_bit] = temp
print(dp[-1] if dp[-1] != INF else -1)

Measured memory_bytes: 3188
package main

import "fmt"

func main() {
	var w, a, b int
	fmt.Scan(&w, &a, &b)

	ans := 0
	if a+w < b {
		ans = b - (a + w)
	} else if b+w < a {
		ans = a - (b + w)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	bool ans=true;
	cin>>n>>m;
	ll l,r,d;
	vb vstd(n,false);
	vl dist(n);
	vector<vector<pii>> ch(n);
	rep(i,m){
		cin>>l>>r>>d;
		l--;r--;
		ch[l].push_back(pii(r,d));
		ch[r].push_back(pii(l,-d));
	}
	rep(i,n){
		if(vstd[i])continue;
		dist[i]=0;
		stack<int> s;
		s.push(i);
		while(!s.empty()){
			int t=s.top();s.pop();
			for(auto x:ch[t]){
				if(vstd[x.fs]){
					if(dist[x.fs]!=dist[t]+x.sc){
						cout<<"No\n";
						return 0;
					}
				}
				else{
					vstd[x.fs]=true;
					dist[x.fs]=dist[t]+x.sc;
					s.push(x.fs);
				}
			}

		}
	}
	cout<<"Yes\n";
}


Measured memory_bytes: 9728
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif


int n;

int main() {
	scanf("%d",&n);
	int c = 1;
	REP(i,1,n) c ^= rd()&1;
	puts(c?"YES":"NO");
}








Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define ORIGIN 100

int vx[6] ={1, 1, 0, 0, -1, -1};
int vy[6] ={1, 0, 1, -1, 0, -1};
int cell[ORIGIN*2][ORIGIN*2];

int func(int x, int y, int turn){
	int ans=0;

	if(cell[y][x] >= turn || turn <= 0) return 0;
	if(cell[y][x] == 0)ans++;
	cell[y][x]=turn;

	for(int i=0; i<6; i++){
		ans += func(x+vx[i], y+vy[i], turn-1);
	}
	return ans;
}


int main(void){
	int turn, n, x, y, tmp_x, tmp_y, ans;

	while(1){
		scanf("%d %d", &turn, &n);
		if(turn == 0 && n == 0) break;

		memset(cell, 0, sizeof(cell));
		for(int i=0; i<n; i++){
			scanf("%d %d", &tmp_x, &tmp_y);
			cell[tmp_y+ORIGIN][tmp_x+ORIGIN] =500;
		}
		scanf("%d %d", &x, &y);

		ans = func(x+ORIGIN, y+ORIGIN, turn+1);
		printf("%d\n", ans);
	}//endwhile
	return 0;
}


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

using namespace std;

int n, m, c, cnt;
int b[25];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> c;
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    while (n--) {
        int cur = 0;
        for (int i = 0, a; i < m; i++) {
            cin >> a;
            cur += (a * b[i]);
        }
        if (cur + c > 0) {
            cnt++;
        } 
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1000000000
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> cost(n, INF);
  cost[0] = 0;
  cost[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; i++) {
    cost[i] = min(cost[i - 2] + abs(h[i] - h[i - 2]), cost[i - 1] + abs(h[i] - h[i - 1]));
  }
  cout << cost[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 4032
n, a, b = map(int, input().split())
if a % 2 == b % 2:
    print(abs(a-b)//2)
else:
    print(min(a-1, n-b)+1+((b-a)//2))
    # print(min(a-1, n-b))
    # print(1)
    # print(((b-a)//2))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

const int MOD = 1e9 + 7;
int dp[64][2][3];

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int64_t n;
    cin >> n;

    dp[62][0][0] = 1;
    for (int k = 61; k >= 0; --k) {
        int64_t r = 1LL << k;
        for (int64_t cput = 0; cput <= r; cput += r) {
            for (int i = 0; i < 2; ++i) {
                for (int pi = 0; pi < 2; ++pi) {
                    if (i == 0 && pi == 1) {
                        continue;
                    }
                    if (i == 1 && pi == 0 && !((n & r) != 0 && cput == 0)) {
                        continue;
                    }
                    if (i == 0 && pi == 0 && cput != (r & n)) {
                        continue;
                    }
                    if (cput == 0) {
                        if (n & r) {
                            dp[k][i][2] += dp[k + 1][pi][1];
                            dp[k][i][2] %= MOD;
                            dp[k][i][2] += dp[k + 1][pi][1];
                            dp[k][i][2] %= MOD;
                            dp[k][i][2] += dp[k + 1][pi][2];
                            dp[k][i][2] %= MOD;
                            dp[k][i][2] += dp[k + 1][pi][2];
                            dp[k][i][2] %= MOD;
                            dp[k][i][1] += dp[k + 1][pi][0];
                            dp[k][i][1] %= MOD;
                        } else {
                            dp[k][i][0] += dp[k + 1][pi][0];
                            dp[k][i][0] %= MOD;
                            dp[k][i][0] += dp[k + 1][pi][1];
                            dp[k][i][0] %= MOD;
                            dp[k][i][2] += dp[k + 1][pi][1];
                            dp[k][i][2] %= MOD;
                            dp[k][i][2] += dp[k + 1][pi][2];
                            dp[k][i][2] %= MOD;
                            dp[k][i][2] += dp[k + 1][pi][2];
                            dp[k][i][2] %= MOD;
                        }
                    } else {
                        if (n & r) {
                            dp[k][i][0] += dp[k + 1][pi][0];
                            dp[k][i][0] %= MOD;
                            dp[k][i][1] += dp[k + 1][pi][1];
                            dp[k][i][1] %= MOD;
                            dp[k][i][2] += dp[k + 1][pi][2];
                            dp[k][i][2] %= MOD;
                        } else {
                            dp[k][i][1] += dp[k + 1][pi][1];
                            dp[k][i][1] %= MOD;
                            dp[k][i][2] += dp[k + 1][pi][2];
                            dp[k][i][2] %= MOD;
                        }
                    }
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
            ans = (ans + dp[0][i][j]) % MOD;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)

signed main(){
  ll n;cin>>n;
  vector<ll> v(n),t(0);//見たならtrue
  rep(i,n)cin>>v[i];

  t.pb(v[0]);
  for(int i=1;i < n;i++)
  {
    int itr=lower_bound(all(t),v[i])-t.begin();

    if(!itr)t.insert(t.begin(),v[i]);
    else t[itr-1]=v[i];

  }
  cout<<siz(t)<<endl;
}

Measured memory_bytes: 2168
import sys

input = sys.stdin.readline


def g(N):
    if N == -1:
        return 0
    r = N % 4
    if r == 0:
        return N
    elif r == 1:
        return 1
    elif r == 2:
        return N + 1
    else:
        return 0


def main():
    A, B = map(int, input().split())
    ans = g(A - 1) ^ g(B)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9120
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    string s, t; cin >> s >> t;
    ll s_size = s.size();
    ll t_size = t.size();

    vector<vector<ll>> dp(s_size+1, vector<ll>(t_size+1));

    rep(i, s_size+1){
        dp[i][0] = i;
    }
    rep(i, t_size+1){
        dp[0][i] = i;
    }

    rep(i, s_size){
        rep(j, t_size){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j];
            }else{
                ll tmp = min(dp[i+1][j]+1, dp[i][j+1]+1);
                tmp = min(tmp, dp[i][j]+1);
                dp[i+1][j+1] = tmp;
            }
        }
    }

    cout << dp[s_size][t_size] << endl;
    

}


Measured memory_bytes: 10868
N, K = map(int, input().split())
mod = 10 ** 9 + 7
S = [[0] * (K + 1) for i in range(N + 1)]
S[0][0] = 1
for n in range(1, N + 1):
	for k in range(1, K + 1):
		S[n][k] = (S[n - 1][k - 1] + k * S[n - 1][k]) % mod
print(S[N][K])



Measured memory_bytes: 29344
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[2000];
  int ans=0;
  rep(i,n){
    int num;
    cin>>a[i];
    
  }
  sort(a,a+n);
  rep(i,n){
    repi(j,i+1,n){
      int num=a[i]+a[j];
      int point=lower_bound(a,a+n,num)-lower_bound(a+j+1,a+n,a[j]);
      // cout<<i<<" "<<j<<" "<<point<<endl;
      //cout<<" "<<lower_bound(a,a+n,num)-a<<" "<<lower_bound(a+j+1,a+n,a[j])-a<<endl;
      ans+=point;
    }
  }
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	ll a;
	cin>>a;
	string b;
	cin>>b;
	ll B=0,p=1;
	for(int i=L(b)-1;i>=0;i--)
	{
		if(b[i]=='.') continue;
		B+=p*(b[i]-'0');
		p*=10;
	}
	cout<< a*B/100;
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,i;
	cin>>n;
	set<string> st;
	for(i=0;i<n;i++)
	{
		string s;
		cin>>s;
		st.insert(s);
	}
	cout<<st.size();
	return 0;
}

Measured memory_bytes: 19180
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, k;
  cin >> n >> k;

  double ans = 0;
  for(int i = 1; i <= min(k - 1, n); i++){
    ans += (1.0 / n) * (1.0 / (1 << (int)ceil(log2((double)k / i))));
  }

  if(n - k + 1 >= 0) ans += (double)(n - k + 1) / n;

  printf("%.9lf\n", ans);

  return 0;
}


Measured memory_bytes: 1016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, X;
   cin >> K >> X;
  int z = X - K + 1;
for (int i = 0; i < K * 2 - 1; i++) {
  cout << z + i << " ";
}
    cout  << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
//#include<limits.h>
using namespace std;
int solve(int E)
{
  int ans =999999;
  for (int z=0; z*z*z<=E; z++)
    for (int y=0; y*y<=E; y++)
      {
	//cout<<"z="<<z<<" y="<<y<<endl;
	int x=E-z*z*z-y*y;
	//cout<<"x="<<x<<endl;
	//cout<<"x+y*y+z*z*z="<<x+y*y+z*z*z<<endl;
	if ((x+y*y+z*z*z == E)&&(x>=0))
	{

	  if((x+y+z)<ans)
	  {
	    ans=x+y+z;
	    //cout<<"ans="<<ans<<endl;
	  }
	}
      }
  return ans;
}
int main()
{
  int E;
  while (cin >> E && E>0)
  {
    cout << solve(E) << endl;
  }
}

Measured memory_bytes: 3076
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanInt(Z);
    scanInt(W);
    scanVecInt(A, N);
    if (2 <= N){
        cout << max(abs(A[N - 2] - A[N - 1]), abs(A[N - 1] - W)) << endl;
    }else{
        cout << abs(A[N - 1] - W) << endl;
    }
    // vector<int> B(A.rbegin(), A.rend());
    // A.clear();
    // vector<pair<int, int>> score(N);
    // score
}


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

int lcm(int a,int b){	//a,b < 20だしいいよね
		if (a < b){
			swap(a,b);
		}
		int times = a * b;
		vector<int> num;
		int gcd,lcm;
		while(1){
			int n;
			n = a % b;
			if(n == 0){	break;}
			a = b;
			b = n;
		}
		gcd = b;
		lcm = times / gcd;
	return lcm;
}

int main(){
	int h,w;
	while(1){
		cin >> h >> w ;
		if(h == 0 && w == 0){	break;}
		char donut[10][20];
		for(int i=0;i<10;i++){
			for(int j=0;j<20;j++){
				donut[i][j] = 0;
			}
		}
		string code[1600];
		bool much[1600];
		for(int i = 0; i < 1600; i++){
			code[i] = "";
			much[i] = true;
		}	//初期化…

		int l = lcm(w,h);	//ななめの最大数
		int a = 0;	//strの数を数えます

		for(int i = 0; i < h; i++){
			for(int j =0; j < w; j++){
				cin >> donut[i][j];
			}
		}	//input

		for(int y = 0; y < h; y++){
			for(int x = 0; x < w; x++){
				for(int i = 0; i < h; i++){	//縦列
					code[a].append(1,donut[(y + i)%h][x]);
					code[a+1].append(1,donut[abs(h-(y + i)%h-1)][x]);
				}
				a += 2;
				for(int j = 0; j < w; j++){	//横列
					code[a].append(1,donut[y][(x + j)%w]);
					code[a+1].append(1,donut[y][abs(w-(x+j)%w-1)]);
				}
				a += 2;
				for(int k = 0; k < l; k++){	//ななめ
					code[a].append(1,donut[(y + k)%h][(x + k)%w]);
					code[a+1].append(1,donut[(y + k)%h][(l + x - k)%w]);
					code[a+2].append(1,donut[(l + y - k)%h][(x + k)%w]);
					code[a+3].append(1,donut[(l + y - k)%h][(l + x - k)%w]);
				}
				a += 4;
			}
		}
		string mag = "";
		//a:strの数-1

		sort(code,code+a);//nとn+1を比べます

		for(int i = 0; i < a-1; i++){
			if(code[i][0] != code[i+1][0]){
				much[i+1] = false;
			}
		}
		for(int i = 1; i < l; i++){	//2文字目から
			for(int j = a-1; j > 0; j--){	//逆順
				if(much[j] == true && code[j].length() >= i+1 && code[j-1].length() >= i+1){
					//jのi+1文字目とj-1のi+1文字目を比べるよ
					if(code[j][i] != code[j-1][i]){
						much[j] = false;
					}else{
						mag = code[j];
						mag.resize(i+1);
					}
				}
			}
		}
		if(mag == ""){
			cout << "0" << endl;
		}else{
			cout << mag << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1532
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cstdlib>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define ULL unsigned long long
int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
#define MAXN 200005
#define INF 0x3f3f3f3f
bool f[MAXN+5],pan;
vector<int> G[MAXN+5];
void DFS(int u,int fa){
	if(int(G[u].size())==1)
		f[u]=1;
	int cnt=0;
	for(int i=0;i<int(G[u].size());i++){
		int v=G[u][i];
		if(v==fa) continue;
		DFS(v,u);
		if(f[v]==1)
			cnt++;
	}
	if(cnt>=2){
		puts("First");
		exit(0);
	}
	f[u]=cnt^1;
	return ;
}
int main(){
	int n=read();
	for(int i=2;i<=n;i++){
		int u=read(),v=read();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	DFS(1,0);
	puts(f[1]?"First":"Second");
	return 0;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;

signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    if(k==1){
        if(n==1) cout<<1<<endl;
        else cout<<0;
        return 0;
    }
    int ans=k;
    Vi a(n-1),b(n-1);
    VVi connect(n);
    REP(i,0,n-1){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        connect[a[i]].pb(b[i]);
        connect[b[i]].pb(a[i]);
    }
    
    Vi pk1(k),pk2(k-1);
    pk1[0]=1;
    pk2[0]=1;
    REP(i,1,k){
        pk1[i]=(pk1[i-1]*(k-i))%MOD;
    }
    REP(i,1,k-1){
        pk2[i]=(pk2[i-1]*(k-i-1))%MOD;
    }

    queue<Tiii> q;
    q.push(mt(0,-1,0));
    while(!q.empty()){
        int now,past,dnow;
        tie(now,past,dnow)=q.front();
        q.pop();
        if(connect[now].size()>=k){cout<<0<<endl; return 0;}
        if(dnow>0 && connect[now].size()==1) continue;
        if(dnow==0){
            ans = (ans*pk1[connect[now].size()])%MOD;
        }else{
            ans = (ans*pk2[connect[now].size()-1])%MOD;
        }
        REP(i,0,connect[now].size()) if(connect[now][i]!=past) q.push(mt(connect[now][i],now,dnow+1));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12020
#include <bits/stdc++.h>
#define MAX_N 15
#define INF -1
using namespace std;
int n;
int board[MAX_N][MAX_N];

void create() {
    int y = n/2, x = y;
    y++;
    int num = 1;
    //中央に１を入れる
    board[y][x] = num++;
    while(num <= n*n) {
        y++;x++; //右斜め下へ移動
        do {
            if(x >= n) { //右にはみ出した
                x = 0;//左端へ
            } else if(y >= n) { //下にはみ出した
                y = 0;//上へ
            } else if(x < 0) { //左にはみ出した
                x = n-1;//右端へ
            } else if(board[y][x] != INF) { //すでに数字が入っていた
                y++;x--;//左斜め下へ
            }
            //cout << "do-while roop" << endl;
        }while((x<0||x>=n||y<0||y>=n)||(board[y][x]!=INF));
        board[y][x] = num++;
    }
}

void print() {
    for(int r = 0; r < n; r++) {
        for(int c = 0; c < n; c++) {
            printf("%4d", board[r][c]);
            if(c == n - 1) putchar('\n');
        }
    }
}

int main(void) {
    while(cin >> n, n != 0) {
        memset(board, INF, sizeof(board));
        create();
        print();
    }
    return(0);
}

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

typedef long long ll;

ll N, sum = 0;
vector<ll> A;
vector<ll> s;

int main(void) {

    cin >> N;
    A.reserve(N + 2);
    s.reserve(N + 2);
    A[0] = 0;
    A[N + 1] = 0;
    s[0] = 0;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        s[i] = abs(A[i - 1] - A[i]);
        sum += s[i];

    }

    s[N + 1] = abs(A[N] - A[0]);
    sum += s[N + 1];

    for (int i = 1; i <= N; i++) {
        cout << (sum - s[i] - s[i + 1] + abs(A[i - 1] - A[i + 1])) << endl;
    }

    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n,k,q,a;
    cin>>n>>k>>q;
    vector<long long> ans(n,k-q);
    f(i,0,q){
        cin>>a;
        ans[a-1]++;
    }
    f(i,0,n){
        if(ans[i]>0){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3908
/*||>>>> Praveen Ojha <<<<>>>> 29 August 2019 <<<<>>>> 21:31:11 <<<<||*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=200005;
int dp[N];
int n;
template <typename T>
class fenwick{
  public:
  vector <T> fenw;
  int n;
  fenwick(int x):n(x+2){
    fenw.resize(n);
  }

  void update(int x,T val){
    while(x<n){
      fenw[x]=max(fenw[x],val);
      x+=(x&-x);
    }
  }

  T get(int x){
    T v{};
    while(x>0){
      v=max(v,fenw[x]);
      x-=(x&-x);
    }
    return v;
  }
};
int32_t main(){__
	cin>>n;
	vi a(n),h(n);
	for(int i=0;i<n;i++)
		cin>>h[i];
	for(int i=0;i<n;i++)
		cin>>a[i];
	fenwick <int> st(n);
	for(int i=0;i<n;i++){
			dp[h[i]]=st.get(h[i]-1)+a[i];
			st.update(h[i],dp[h[i]]);
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans=max(ans,dp[h[i]]);
	}
	cout<<ans<<"\n";
return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
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);
    return (data[k] = find(data[k]));
  }

  bool same(int x, int y){
      return find(x) == find(y);
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

struct Edge{long long u,v,cost;};
using Edges = vector<Edge>;

bool comp(const Edge &a, const Edge &b){
    return a.cost < b.cost;
}


int kruskal(Edges &es,int V){
    sort(es.begin(),es.end(),comp);
    UnionFind uf(V);
    int res = 0;
    for(auto e : es){
        long long cost = e.cost;
        int u = e.u,v = e.v;
        if(!uf.same(u,v)){
            uf.unite(u,v);
            res += cost;
        }
    }
    return res;
}

int main(){
    int N;cin >> N;
    Edges edges;
    vector<pair<int,int>> xcity(N),ycity(N);
    for(int i = 0; i < N ; i++){
        int x,y;
        cin >> x >> y;
        xcity[i].first = x;xcity[i].second = i;
        ycity[i].first = y;ycity[i].second = i;
    }
    sort(xcity.begin(),xcity.end());
    sort(ycity.begin(),ycity.end());
    for(int i = 0; i < N-1 ; i++){
        Edge e;
        e.u = xcity[i].second;e.v = xcity[i+1].second;e.cost = abs(xcity[i].first-xcity[i+1].first);
        edges.push_back(e);
        e.u = ycity[i].second;e.v = ycity[i+1].second;e.cost = abs(ycity[i].first-ycity[i+1].first);
        edges.push_back(e);
    }

    int res = kruskal(edges,N);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 10096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else if (a == b) {
			System.out.println("a == b");
		}
		sc.close();
	}
}


Measured memory_bytes: 26088
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int m, n;
	int[][] a, b;

	void run(){
		for(;;){
			m=sc.nextInt();
			n=sc.nextInt();
			if((m|n)==0){
				break;
			}
			a=new int[m][m];
			b=new int[n][n];
			for(int j=0; j<m; j++){
				for(int i=0; i<m; i++){
					a[j][i]=sc.nextInt();
				}
			}
			for(int j=0; j<n; j++){
				for(int i=0; i<n; i++){
					b[j][i]=sc.nextInt();
				}
			}
			solve();
		}
	}

	void solve(){
		int[][][] c=new int[4][n][n];
		for(int j=0; j<n; j++){
			for(int i=0; i<n; i++){
				c[0][j][i]=b[j][i];
				c[1][i][n-1-j]=b[j][i];
				c[2][n-1-j][n-1-i]=b[j][i];
				c[3][n-1-i][j]=b[j][i];
			}
		}

		int p=m*m;
		for(int i=0; i<4; i++){
			p=min(p, match(c[i]));
		}
		if(p==m*m){
			println("NA");
		}else{
			println((p%m+1)+" "+(p/m+1));
		}
	}

	int match(int[][] c){
		for(int y=0; y+n<=m; y++){
			for(int x=0; x+n<=m; x++){
				boolean f=true;
				for(int j=0; j<n; j++){
					for(int i=0; i<n; i++){
						f&=c[j][i]==-1||c[j][i]==a[y+j][x+i];
					}
				}
				if(f){
					for(int j=0; j<n; j++){
						for(int i=0; i<n; i++){
							if(c[j][i]!=-1){
								return (y+j)*m+(x+i);
							}
						}
					}
				}
			}
		}
		return m*m;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5020;
int d[N],len,D; ll Ans,f[N][2][2];
inline ll DynamicProgram(int n)
{
    int Lim = n/2; ll res = 0;
    for (int i=0;i<=Lim;i++)
        for (int j=0;j<=1;j++)
            for (int k=0;k<=1;k++)
                f[i][j][k] = 0;
    f[0][0][0] = 1;
    for (int i=0;i<Lim;i++)
        for (int j=0;j<=1;j++)
            for (int k=0;k<=1;k++)
                if ( f[i][j][k] != 0 )
                    for (int l=0;l<=9;l++)
                    {
                        int raw = l + d[i+1] + k , num = raw % 10;
                        int _k = raw / 10 , _j = j * 10 + l - num - d[n-i];
                        if ( _j < 0 || _j > 1 ) continue;
                        if ( i == 0 && ( l == 0 || num == 0 ) ) continue;
                        f[i+1][_j][_k] += f[i][j][k];
                    }
    if ( n % 2 == 1 )
        for (int j=0;j<=1;j++)
            for (int k=0;k<=1;k++)
            {
                if ( f[Lim][j][k] != 0 )
                    for (int i=0;i<=9;i++)
                    {
                        int num = i + d[(n+1)/2] + k;
                        if ( num % 10 == i && num / 10 == j )
                            res += f[Lim][j][k];
                    }
            }
    else for (int j=0;j<=1;j++) res += f[Lim][j][j];
    return res;
}
int main(void)
{
    scanf("%d",&D);
    while ( D ) d[++len] = D%10 , D /= 10;
    for (int i=len;i<=2*len;i++)
        Ans += DynamicProgram(i);
    return printf("%lld\n",Ans) , 0;
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

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

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}


   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
const ll MAX_H = 1e3, MAX_W = 1e3;
ll H, W;
char grid[MAX_H][MAX_W];
ll dp[MAX_H+1][MAX_W+1] = {};
int main(){
  cin >> H >> W;
  REP(i, H){
    REP(j, W){
      cin >> grid[i][j];
    }
  }
  dp[1][1] = 1;
  REP(i, H){
    REP(j, W){
      if (grid[i][j] == '.' && (i > 0 || j > 0)){
        dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j]) % MOD;
      }
    }
  }
  cout << dp[H][W] << endl;
}


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

int main() 
{ 
    int h,n;
    cin>>h>>n;
    int dp[10007];
    dp[0]=0;
    int a[n],b[n];
    for(int i=0;i<n;i++) cin>>a[i]>>b[i];
    for(int i=1;i<=h;i++){
        dp[i]=INT_MAX;
        for(int j=0;j<n;j++){
            if(a[j]<=i){
                dp[i]=min(dp[i],dp[i-a[j]]+b[j]);                
            }else{
                dp[i]=min(dp[i],b[j]);
            }
        }
    }
    cout<<dp[h];
	return 0; 
} 


Measured memory_bytes: 256
from itertools import product

def inpl(): return tuple(map(int, input().split()))

N = int(input())

for b, c in product(range(max(1, N//4), 3500), range(max(1, N//4), 3500)):
    top = N*b*c
    bottom = 4*b*c - N*c -N*b

    if bottom > 0 and (top%bottom == 0):
        a = top // bottom
        print(a, b, c)
        break

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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int K = int.Parse(Console.ReadLine());
        int[] x = new int[N];
        string[] str = Console.ReadLine().Split(' ');
        int cnt = 0;

        for(int i=0; i<N; i++){
            x[i] = int.Parse(str[i]);
        }

        for(int i=0; i<N; i++){
            if((x[i] * 2) < ((K - x[i]) * 2)){
                cnt += x[i] * 2;
            }else{
                cnt += (K - x[i]) * 2;
            }
        }

        Console.WriteLine(cnt);

    }
}



Measured memory_bytes: 11092
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
    int H, W;
    
    while (true) {
        cin >> H >> W;
        
        if (H == 0 && W == 0) break;
        
        for (int h = 0; h < H; h++) {
            if (h == 0 || h == H-1) {
                for (int w = 0; w < W; w++) {
                    
                    cout << "#" << flush;
                }
            } else {
                for (int w = 0; w < W; w++) {
                    if (w == 0 || w == W-1) {
                        cout << "#" << flush;
                    } else {
                        cout << "." << flush;
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3032
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a,b;
	cin >> n >> a>>b;
	cout << max(0,b - (n - a));

}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
			int n=sc.nextInt();
		long a[]=new long[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextLong();
		}
		long ans=0;
		long max=a[0];
		for(int i=0;i<n;i++) {
			if(a[i]>=max) {
				max=a[i];
				continue;
			}
			else {
				ans+=max-a[i];
			
				
				
			}
		}
		System.out.println(ans);
					
				
			}
		
	}
	   



Measured memory_bytes: 62912