akhauriyash/Code-Regression huggingface dataset:
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll gcm(ll a,ll b){
  if(a%b==0)return b;
  else return(gcm(b,a%b));
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

int main() {
  ll a,b;
  cin >> a >> b;
  cout <<lcm(a,b)<<endl;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  rep(i, w + 2){
    cout << '#';
  }
  cout << '\n';
  string s;
  rep(i, h){
    cin >> s;
    cout << '#' << s << '#' << '\n';
  }
  rep(i, w + 2){
    cout << '#';
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstring>
#include<stdlib.h>
using namespace std;
int main(void){
    char x[256],str1,str2,str3;
    int cmp,ans=9999;
    cin>>x;
    for(int i=0;i<strlen(x)-2;i++){
        str1=x[i];
        str2=x[i+1];
        str3=x[i+2];
        cmp = (str1-'0')*100 + (str2-'0')*10 + (str3-'0');
        if(ans>abs(753-cmp))
        ans=abs(753-cmp);
    }
    cout<<ans;
}


Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    std::string S;
    std::cin >> S;

    int a = S[0] - '0';
    int b = S[1] - '0';
    int c = S[2] - '0';
    int d = S[3] - '0';

    for (int i = 0; i < 1<<3; ++i) {
        int ans = a;
        char op1, op2, op3;
        if (i & (1<<2)) {
            ans += b;
            op1 = '+';
        }
        else {
            ans -= b;
            op1 = '-';
        }

        if (i & (1<<1)) {
            ans += c;
            op2 = '+';
        }
        else {
            ans -= c;
            op2 = '-';
        }

        if (i & (1<<0)) {
            ans += d;
            op3 = '+';
        }
        else {
            ans -= d;
            op3 = '-';
        }

        if (ans == 7) {
            std::cout
                << a
                << op1
                << b
                << op2
                << c
                << op3
                << d
                << "=7" << std::endl;
            return 0;
        }
    }
    return 0;
}


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

#define rep(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define repn(i, m, n) for (ll (i) = (m) ; (i) < (ll)(n) ; ++(i))
#define rep_rev(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define repn_rev(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= (m) ; --(i))

#define INF 2e9
#define ll long long
#define MOD 1e9+7

vector<int> z_algorithm(string s){
    vector<int> a((int)s.size());
    a[0] = (int)s.size();
    int i = 1, j = 0;
    while(i < (int)s.size()){
        while(i + j < (int)s.size() && s[j] == s[i + j])j++;
        a[i] = j;
        if(j == 0){
            i++;
            continue;
        }
        int k = 1;
        while(i + k < (int)s.size() && k + a[k] < j)a[i + k] = a[k], k++;
        i += k;
        j -= k;
    }
    return a;
}

int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans = 0;

    rep(i, n) {
        string t = s.substr(i);
        vector<int> v = z_algorithm(t);
        rep(j, v.size()) {
            ans = max(ans, min(v[j], (int)j));
        }
    }

    
    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
typedef pair<ll,ll> P;
const ll INF = 1e10;
const ll MOD = 1e9+7;
int main(){
    string s,t;
    cin >> s >> t;
    PRINT(t+s);
}


Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))
degit = len(format(10**12,"b"))
bit_1 = [0]*degit
bit_0 = [0]*degit
for a in A:
    string = format(a,"b")
    length = len(string)
    for i in range(length):
        index = degit - length + i
        if string[i] == "1":
            bit_1[index] += 1
        elif string[i] == "0":
            bit_0[index] += 1
    for j in range(degit-length):
        bit_0[j] += 1
        
ideal = ["0"]*degit
for i in range(degit):
    if bit_1[i] >= bit_0[i]:
        ideal[i] = "0"
    elif bit_1[i] < bit_0[i]:
        ideal[i] = "1"

candidate = []
hoge = []
K_bin = format(K,"b")
for i in range(len(K_bin)):
    if K_bin[i] == "1":
        candidate.append(hoge+["0"]+ideal[degit-len(K_bin)+i+1:])
        hoge.append("1")
    elif K_bin[i] == "0":
        hoge.append("0")
    if len(hoge) == len(K_bin):
        candidate.append(hoge)    
ans = 0
for c in candidate:
    c = "".join(c)
    c = c.lstrip("0")
    if c == "":
        c = "0"
    c = int(c,2)
    res = 0
    for a in A:
        res += c ^ a
    if res > ans:
        ans = res

print(ans)

Measured memory_bytes: 14136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
string n;
cin >> n;
int len=(int)(n.length());

ll dp[len][2]={};
dp[0][0]=2;
dp[0][1]=1;

rep1(i,len){
    if(n[i]=='1'){
        dp[i][0]=dp[i-1][0]*2;
        dp[i][0]%=mo;
        dp[i][1]=dp[i-1][0]+dp[i-1][1]*3;
        dp[i][1]%=mo;
    }
    if(n[i]=='0'){
        dp[i][0]=dp[i-1][0];
        dp[i][1]=dp[i-1][1]*3;
        dp[i][1]%=mo;
    }
}

ans=dp[len-1][0]+dp[len-1][1];
ans%=mo;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
 
using namespace std;

queue<int> que;
vector<int> v(55556,0);

void pre(){
    queue<int> p;
    for(int i=2; i<55556; i++){
        if(v[i] == 0)   p.push(i);
        for(int j=i; j<55556; j+=i) v[j] = 1;
    }
    while(!p.empty()){
        int x = p.front();
        p.pop();
        if(x%5 == 1)    que.push(x);
    }
}
int main(){
    pre();
    int N;  cin >> N;
    for(int i=0; i<N; i++){
        cout << que.front() << " ";
        que.pop();
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
  int n, t;
  int dp[101][101];
  int A[101];
  cin >> n;
  cin >> A[0] >> A[1];
  for(int i = 1; i < n; i++) {
    cin >> t >> A[i+1];
  }
  for(int i = 1; i <= n; i++) dp[i][i] = 0;
  for(int l = 2; l <= n; l++) {
    for(int i = 1; i <= n-l+1; i++) {
      int j = i + l - 1;
      dp[i][j] = 1e9;
      for(int k = i; k <= j-1; k++) {
	int q = dp[i][k] + dp[k + 1][j] + A[i - 1]*A[k]*A[j];
	dp[i][j] = min(dp[i][j], q);
      }
    }
  }
  /*
    for(int i = 1; i <= n; i++) {
    for(int j = n; j >= 1; j--)cout << dp[i][j] << " ";	
    cout << endl;
    }
  */
  cout << dp[1][n] << endl;
  return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  cout<<fixed<<setprecision(10);
  ll count=0;
  ll N;
  cin >> N;
  vector<vector<char>> s(N, vector<char>(10));
  for(ll i=0; i<N; ++i){
    for (ll j=0; j<10; ++j) cin >> s.at(i).at(j);
    sort(s.at(i).begin(),s.at(i).end());
  }
  sort(s.begin(),s.end());
  vector<ll> same;
  ll hoge=0;
  for(ll i=0; i<N-1; ++i){
    if(s.at(i)==s.at(i+1)) ++hoge;
    else {
      same.push_back(hoge);
      hoge=0;
    }
  }
  if(hoge!=0) same.push_back(hoge);
  for(ll i=0; i<same.size(); ++i){
    if(same[i]!=0) for(ll j=1; j<=same[i]; ++j) count += j;
  }
  cout << count << endl;
}


Measured memory_bytes: 6904
#include<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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


int main(){

	while(true){

		int n,m;
		char p,q,r;
		vector<char>u;
		vector<char>v;

		cin >> n;
		if(n==0) break;

		rep(i,n){
		cin >> p >> q;

		u.push_back(p);
		v.push_back(q);
		}



		cin >> m;

		rep(i,m){
		cin >> r;

        bool f=false;
        int s;
		rep(j,n)
		if(u[j]==r){ s=j; f=true; break;}

		if(f) cout << v[s];
		else cout << r;

	    }

		cout << endl;
        u.clear(); v.clear();
	}




	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int n,m,a[22],b[22];
char c[22][22];
string s[22];
void dd1(int x,bool bl)
{
	if(x==m)
	{
		cout<<"YES"<<endl;
		exit(0);
	}
	else if(b[x]!=-1)
	{
		dd1(x+1,bl);
	}
	else
	{
		for(int i=x+1;i<m;i++)
		{
			if(b[i]!=-1)
			{
				continue;
			}
			int j;
			for(j=0;j<n;j++)
			{
				if(c[j][x]!=c[a[j]][i])
				{
					break;
				}
			}
			if(j==n)
			{
				b[x]=i;
				b[i]=x;
				dd1(x+1,bl);
				b[x]=-1;
				b[i]=-1;
			}
		}
		if(!bl)
		{
			int j;
			for(j=0;j<n;j++)
			{
				if(c[j][x]!=c[a[j]][x])
				{
					break;
				}
			}
			if(j==n)
			{
				b[x]=x;
				dd1(x+1,true);
				b[x]=-1;
			}
		}
	}
}
void dd2(int x,bool bl)
{
	if(x==n)
	{
		dd1(0,m%2==0);
	}
	else if(a[x]!=-1)
	{
		dd2(x+1,bl);
	}
	else
	{
		for(int i=x+1;i<n;i++)
		{
			if(a[i]!=-1)
			{
				continue;
			}
			if(s[x]!=s[i])
			{
				continue;
			}
			a[x]=i;
			a[i]=x;
			dd2(x+1,bl);
			a[x]=-1;
			a[i]=-1;
		}
		if(!bl)
		{
			a[x]=x;
			dd2(x+1,true);
			a[x]=-1;
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>c[i][j];
		}
	}
	for(int i=0;i<n;i++)
	{
		s[i]=c[i];
		sort(s[i].begin(),s[i].end());
	}
	for(int i=0;i<n;i++)
	{
		a[i]=-1;
	}
	for(int j=0;j<m;j++)
	{
		b[j]=-1;
	}
	dd2(0,n%2==0);
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    string S; cin>>S;
    for(int bit=0;bit<(1<<3);bit++){
        int ans=S[0]-'0';
        for(int i=0;i<3;i++){
            if(bit & 1<<(2-i)){
                ans+=S[i+1]-'0';
            }
            else{
                ans-=S[i+1]-'0';
            }
        }
        if(ans==7){
            cout<<S[0];
            for(int i=0;i<3;i++){
                if(bit & 1<<(2-i)){
                    cout<<'+'<<S[i+1];
                }
                else{
                    cout<<'-'<<S[i+1];
                }
            }
            cout<<"=7";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int Q;
	while(cin>>Q){
		int N;
		REP(k,0,Q){
			int ans=0;
			set<int> s;
			cin>>N;
			while(N/10>0){
				int mx=0;
				int waru=10;
				s.insert(N);
				for(int i=0;N/waru>0;i++){
					int l=N/waru;
					int r=N%waru;
					mx=max(mx,l*r);
					waru*=10;
				}
				N=mx;
				ans++;
				if(s.find(N)!=s.end()){
					ans=-1;
					break;
				}
			}
			p(ans);
		}
	}

	return 0;
}

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

int main() {
	string S;
	cin >> S;

	vector<char> C(S.size());
	vector<int> num(C.size());
	for (int i = 0; i < S.size(); i++) {
		C.at(i) = S.at(i);
		num.at(i) = (int)(C.at(i) - '0');
	}
	int res = 0;
	for (int i = 0; i < C.size() - 1; i++) {
		if (num.at(i) == 1 && num.at(i + 1) == 1) {
			num.at(i + 1) = 0;
			res++;
		}
		else if (num.at(i) == 0 && num.at(i + 1) == 0) {
			num.at(i + 1) = 1;
			res++;
		}
	}
	cout << res << endl;
}

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

int n;
string str;

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

	set<char> A,B;

	int mx=0;

	for(int i=1;i<n;i++){
		int cc=0;
		A.clear();B.clear();

		for(int j=0;j<i;j++){
			A.insert(str[j]);
		}

		for(int k=i;k<n;k++){
			B.insert(str[k]);
		}

		for(char c: A){
			if(B.find(c)!=B.end())
				cc++;
		}

		mx=max(mx,cc);
	}

	cout << mx << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll nums[200009], memo[100000009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    rep(i,N) cin>>nums[i];
    rep(i,N-1) nums[i+1]+=nums[i];
    
    memo[0]=1;
    map<ll,int> dic;
    ll cnt=0;
    rep(i,N){
        if(nums[i]>=0&&nums[i]<=100000000){
            cnt+=memo[nums[i]]++;
        }else{
            cnt+=dic[nums[i]]++;
        }
    }
    cout1(cnt)
}

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

const ll INF = 1LL << 60;

ll A, B, C;
int main() {
    cin >> A >> B >> C;


    if (A + B >= C - 1) {
        cout << B + C << endl;
    } else {
        cout << A + B + 1 + B << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<climits>
using namespace std;
int main(void){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0;i < n;i++){
          cin >> h[i];
    }
    vector<int> dp(n,INT_MAX);
    dp[0] = 0;
    
    for(int i = 1;i < n;i++){
          for(int j = 1;j <= k;j++){
                if(i - j >= 0){
                      dp[i] = min(dp[i],dp[i - j] + abs(h[i] - h[i - j]));
                }
          }
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 4016
#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;

int main(){
  
  int n, q, command, t, x;
  
  cin >> n;
  stack<int> S[n];
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> command;
    
    if(command == 0){
      cin >> t >> x;
      S[t].push(x);
    }else if(command == 1){
      cin >> t;
      if(S[t].size()) cout << S[t].top() << endl;
    }else if(command == 2){
      cin >> t;
      if(S[t].size()) S[t].pop();
    }
  }
  
  return 0;
}


Measured memory_bytes: 4400
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<=(b);++i)
#define DEC(i,a,b) for(int i=(a);i>=(b);--i)
#define DEBUG(x) cerr<<#x" == "<<x<<endl
using namespace std;
typedef long long ll;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	if(c>=a&&c<=a+b)puts("YES");else puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define mx 200005
#define inf 2e9
#define nitro ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
bool flag = true ;
int main()
{
    nitro ;
    int n;
    cin>>n;
    if(n%2 == 0)
        cout<<n/2<<endl;
    else
        cout<<n/2 +1<<endl;
}

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

namespace ABC089D
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = line1[0];
            int W = line1[1];
            int D = line1[2];

            int[] X = new int[H * W + 1];
            int[] Y = new int[H * W + 1];
            for (int i = 0; i < H; i++)
            {
                var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for(int j = 0; j < W; j++)
                {
                    X[line[j]] = i + 1;
                    Y[line[j]] = j + 1;
                }
            }

            int[] cost = new int[H * W + 1];
            for (int i = 1 + D; i <= H * W; i++)
            {
                int d = Math.Abs(X[i] - X[i - D]) + Math.Abs(Y[i] - Y[i - D]);
                cost[i] = cost[i - D] + d;
            }

            var Q = int.Parse(Console.ReadLine());
            int[] ans = new int[Q];
            for(int i = 0; i < Q; i++)
            {
                var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
                ans[i] = cost[line[1]] - cost[line[0]];
            }

            foreach (int a in ans) Console.WriteLine(a);
            Console.ReadKey();
        }
    }
}


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

using namespace std;

const int MAXN = 1000;

int arr[MAXN+1][MAXN+1];
int max(int p,int q){return p>q?p:q;
}

int main()
{
	int n,m;
	
	scanf("%d%d",&n,&m);
	
	
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
	{
		char c;
		scanf(" %c",&c);
		if(c=='#')arr[i][j]=1;
	}
	
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			int sum = arr[i-1][j]+arr[i+1][j]+arr[i][j-1]+arr[i][j+1];
			if(!sum&&arr[i][j]){
				printf("No"); return 0;
			}
		}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string b;
    cin>>b;
    rep(i,0,b.length()){
        if(b[i]=='A') cout <<"T";
        if(b[i]=='T') cout <<"A";
        if(b[i]=='C') cout <<"G";
        if(b[i]=='G') cout <<"C";
    }
    cout<<"\n";
}

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

using namespace std;

int main(void){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n];c[0] = 0;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 1; i < n; i++) cin >> c[i];
    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += b[a[i]-1];
        if(0 < i && a[i] == a[i-1]+1) sum += c[a[i]-1];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int min(int a,int b){return(a<b)?a:b;}
int main(void)
{
  int a=0,b=1,c,i=0;char s[1000005];
  if(scanf("%s",s)==1)scanf("%s",s);else return 0;
  while(i<strlen(s)){c=a;a=min(a+s[i]-48,b+58-s[i]);b=min(c+s[i]-47,b+57-s[i]);i++;}
  return printf("%d",a),0;
}

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

    int N,M,Q;
    cin >> N >> M >> Q;
    vector<int> a(Q),b(Q),c(Q),d(Q);
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    vector<int> A(10);
    int ans=0;
    
    for(int A1=1; A1<=M; A1++){
        A[0]=A1;
        for(int A2=A1; A2<=M; A2++){
            A[1]=A2;
            for(int A3=A2; A3<=M; A3++){
                A[2]=A3;
                for(int A4=A3; A4<=M; A4++){
                    A[3]=A4;
                    for(int A5=A4; A5<=M; A5++){
                        A[4]=A5;
                        for(int A6=A5; A6<=M; A6++){
                            A[5]=A6;
                            for(int A7=A6; A7<=M; A7++){
                                A[6]=A7;
                                for(int A8=A7; A8<=M; A8++){
                                    A[7]=A8;
                                    for(int A9=A8; A9<=M; A9++){
                                        A[8]=A9;
                                        for(int A10=A9; A10<=M; A10++){
                                            A[9]=A10;
                                            int sum=0;
                                            rep(i,Q){
                                                if(c[i]==A[b[i]-1]-A[a[i]-1]) sum+=d[i];
                                            }
                                            ans=max(ans,sum);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
 cout << ans << endl;


}

Measured memory_bytes: 3632
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

ll dp[1005][1<<13];
ll arr[1005];
ll cost[1005];
ll n;

ll func(ll idx, ll mask)
{
	if(mask == ((1ll<<n)-1))
		return 0;
	if(idx == -1)
		return INF;
	if(dp[idx][mask]!=-1)
		return dp[idx][mask];
	return dp[idx][mask] = min(func(idx-1,mask), cost[idx]+func(idx-1, mask|arr[idx]));
}

int main()
{
	fast;
	ll m,x,y;
	cin>>n>>m;
	memset(dp,-1,sizeof(dp));
	memset(arr,0,sizeof(arr));
	for(ll i=0;i<m;i++)
	{
		cin>>cost[i];
		cin>>x;
		for(ll j=0;j<x;j++)
		{
			cin>>y;
			--y;
			arr[i] |= (1<<y);
		}
	}
	ll ans = func(m-1,0);
	if(ans == INF)
		ans = -1;
	cout<<ans;
	return 0;
}


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

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

	vector<string> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	string ans = "";
	rep(i, n) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main(void){
    int N;
    map<int, int> m;
    cin >> N;
    for(int i=0; i<N; i++) {
        int v;
        cin >> v;
        m.insert(make_pair(v, 1));
    }
    cout << m.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=105;

int main()
{
    ll a,b;
    scanf("%lld%lld",&a,&b);
    ll t1=a-(a%8);
    ll t2=b-(b%8);
    ll ans=0;
    for(ll i=t1;i<a;i++)ans^=i;
    for(ll i=t2;i<=b;i++)ans^=i;
    printf("%lld\n",ans);
    return 0;
}
/*
struct node
{
    ll a,b;
}p[maxn];
ll n,m;
ll cmp(node x,node y)
{
    return x.a<y.a;
}
int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)scanf("%lld%lld",&p[i].a,&p[i].b);
    sort(p+1,p+n+1,cmp);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        if(m>=p[i].b){m-=p[i].b;ans+=p[i].b*p[i].a;}
        else {ans+=m*p[i].a;break;}
    }
    printf("%lld\n",ans);
    return 0;
}
/*
int b[maxn];
int a[maxn][maxn];
int main()
{
    int n,m,c;
    scanf("%d%d%d",&n,&m,&c);
    for(int i=1;i<=m;i++)scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        int ans=0;
        for(int j=1;j<=m;j++)
        {
            ans+=a[i][j]*b[j];
        }
        if(ans+c>0)cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}
/*
int a[maxn];
int main()
{
    int H,W;
    int h,w;
    scanf("%d%d",&H,&W);
    scanf("%d%d",&h,&w);
    int ans=(H-h)*(W-w);
    printf("%d\n",ans);
    return 0;
}
*/


Measured memory_bytes: 256
x, y = 0, 0
θ = 90
loop do
  given = $<.gets.split(",").map(&:to_i)
  break if given == [0, 0]
  x += given[0] * Math.cos(Math::PI * θ / 180)
  y += given[0] * Math.sin(Math::PI * θ / 180)
  θ -= given[1]
end
puts x.to_i
puts y.to_i


Measured memory_bytes: 6948
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
	public static void main(String[]args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		String[]arr=str.split(" ");
		int a = Integer.parseInt(arr[0]);
		int b = Integer.parseInt(arr[1]);
		System.out.printf("%d %d %.8f%n",a/b,a%b,(double)a/b);
	}
}

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

int main(){
  int w,h,n;
  cin >> w >> h >> n;
  int x1 = 0, y1 = 0, x2 = w, y2 = h;
  for(int i = 0; i < n; i++){
    int x, y, a;
    cin >> x >> y >> a;
    if(a == 1){
      x1 = max(x1,x);
    }else if(a == 2){
      x2 = min(x2,x);
    }else if(a == 3){
      y1 = max(y1,y);
    }else if(a == 4){
      y2 = min(y2,y);
    }
  }
  cout << max(0,x2-x1)*max(0,y2-y1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int N,A,B,C,D;
	cin >> N >> A >> B >> C >> D;
	A--; B--; C--; D--;
	string S;
	cin >> S;

	bool canOvertake=false;
	bool canArrive=true;
	int i;
	if (C>D) {
		//すぬけ君がふぬけ君を抜かせるか -> S中のD-1以下に"..."が存在することを確認
		for (i=B-1; i<D; i++){
			if (S.substr(i,3)=="...") {
				canOvertake=true;
				break;
			}
		}
	} else {
		canOvertake=true;
	}
	//目的地にたどり着けるか -> S中のmax(C,D)-2以下に"##"が存在しないことを確認
	for (i=A+1; i<max(C,D)-1; i++){
		if (S.substr(i,2)=="##"){
			canArrive=false;
			break;
		}
	}

	if (canOvertake && canArrive) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N, M; cin >> N >> M;
	vector<ll> s(N+1), t(M+1);
	for (int i = 1; i <= N; i++) {
		cin >> s[i];
	}

	for (int i = 1; i <= M; i++) {
		cin >> t[i];
	}

	ll dp[2005][2005]={0};
	ll sum[2005][2005]={0};
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			if (s[i] == t[j])
				dp[i][j] = (sum[i - 1][j - 1] + 1) % DIV;
			sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]+DIV)%DIV;
		}
	}

	cout << (sum[N][M] + 1) % DIV << endl;
}


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

using namespace std;

int main() {
    vector<int> pqr = vector<int>(3);
    cin >> pqr[0] >> pqr[1] >> pqr[2];
    sort(pqr.begin(), pqr.end());
    cout << pqr[0] + pqr[1] << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools
n, m = map(int, input().split())
a = list(map(int,input().split()))
acc = list(itertools.accumulate(a))
ans = 0
reminder = {}
reminder[0] = 0
for i in range(n):
    rem = acc[i] % m
    if rem == 0:
        reminder[rem] += 1
        ans += reminder[rem]
        continue
    if rem not in reminder:
        reminder[rem] = 1
    else:
        ans += reminder[rem]
        reminder[rem] += 1
print(ans)


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

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

  vector<bool> v(N+1, true);
  rep(i,0,M-1) {
    int a;
    cin >> a;
    v[a] = false;
  }

  int mod = 1'000'000'007;
  vector<ll> dp(N+1); dp[0] = 1;
  rep(i,0,N-1) {
    rep(j,i+1,min(N,i+2)) {
      if (v[j]) {
        dp[j] += dp[i];
        dp[j] %= mod;
      }
    }
  }

  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 4004
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

// mod
int mod = 1e9 + 7;

struct mint {
    unsigned x;

    mint() : x(0) {}

    mint(signed sig) { x = sig < 0 ? sig % mod + mod : sig % mod; }

    mint(signed long long sig) { x = sig < 0 ? sig % mod + mod : sig % mod; }

    int get() const { return (int) x; }

    mint& operator+=(mint that) {
        if ((x += that.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator-=(mint that) {
        if ((x += mod - that.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator*=(mint that) {
        x = (unsigned long long) x * that.x % mod;
        return *this;
    }

    mint& operator/=(mint that) { return *this *= that.inverse(); }

    mint operator+(mint that) const { return mint(*this) += that; }

    mint operator-(mint that) const { return mint(*this) -= that; }

    mint operator*(mint that) const { return mint(*this) *= that; }

    mint operator/(mint that) const { return mint(*this) /= that; }

    mint inverse() const {
        long long a = x, b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            std::swap(a, b);
            u -= t * v;
            std::swap(u, v);
        }
        return mint(u);
    }

    bool operator==(mint that) const { return x == that.x; }

    bool operator!=(mint that) const { return x != that.x; }

    mint operator-() const {
        mint t;
        t.x = x == 0 ? 0 : mod - x;
        return t;
    }
};

class CUbiquity {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        if (N < 2) {
            cout << 0 << endl;
            return;
        }

        mint res = 1;
        REP(i, N) res *= 10;
        mint sub = 1;
        REP(i, N) sub *= 9;
        mint sub2 = 1;
        REP(i, N) sub2 *= 8;
        res -= sub * 2;
        res += sub2;
        cout << res.get() << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CUbiquity solver;
    solver.solve(in, out);
    return 0;
}


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

int a[100015];

int main(){
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		a[tmp]++;
		a[tmp-1]++;
		a[tmp+1]++;
	}
	for(int i = 0; i < 100005; i++) ans = max(ans, a[i]);

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<complex>
using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;

typedef complex<double> P;

double cross(const P &a, const P &b){
    return imag(conj(a)*b);
}

double dot(const P &a, const P &b){
    return real(conj(a)*b);
}

int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > 0) return +1;
    if(cross(b,c) < 0) return -1;
    if(dot(b,c) < 0) return +2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

bool intersectLL(const L &l, const L &m){
    return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS ||
    abs(cross(l[1]-m[0], m[1]-m[0])) < EPS;
}

bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

int main(){
  int q;
  double x0,y0,x1,y1, x2, y2;
  cin >> x0 >> y0 >> x1 >> y1 >> q;
  P p0(x0, y0), p1(x1, y1);

  for (int i=0;i<q;i++){
    cin >> x2 >> y2;
    P p2(x2, y2);
    int res = ccw(p0, p1, p2);
    if(res == 1) cout << "COUNTER_CLOCKWISE" << endl;
    if(res == -1) cout << "CLOCKWISE" << endl;
    if(res == 2) cout << "ONLINE_BACK" << endl;
    if(res == -2) cout << "ONLINE_FRONT"<< endl;
    if(res == 0) cout << "ON_SEGMENT" << endl;
  }
  return 0;
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
int var(int a){
  if(a>=0)return a;
  else return -a;
}

int main() {
  int n,x,y;
  cin>>n>>x>>y;
  vector<int> a(n-1);
  for(int i=0;i<n-1;i++)cin>>a.at(i);
  for(int i=1;i<n;i++){
    for(int j=i+1;j<=n;j++){
      int dis=min(j-i,var(x-i)+1+var(y-j))-1;
      a.at(dis)++;
    }
  }
  for(int i=0;i<n-1;i++){
    cout<<a.at(i)<<endl;
  }
}

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N;
deque<int> bit;
bool mn=false;

void input() {
	cin>>N;
	if(N<0) {
		mn=true;
		N*=-1;
	}
}

void solve() {
	if(N==0) {
		cout<<0<<endl;
		return;
	}
	for(int i=0; N; i++) {
		if(N&1) {
			bit.push_front(1);
			if(mn^(i%2)) N++;
			else N--;
		}
		else {
			bit.push_front(0);
		}
		N>>=1;
	}

	while(!bit.empty()) {
		cout<<bit.front();
		bit.pop_front();
	}
	cout<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<vector<ll>> a(n,vector<ll>(n));
	rep(i,n)rep(j,n){
		cin>>a[i][j];
	}
	vector<ll> dp(1<<n,0),sum(1<<n,0);
	rep(S,1<<n){
		rep(i,n)FOR(j,i+1,n){
			if(S & 1<<i)if(S & 1<<j){
				sum[S]+=a[i][j];
			}
		}
	}
	rep(S,1<<n){
		for(int T=S;T>0;T=(T-1)&S){
			chmax(dp[S],dp[S-T]+sum[T]);
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int digit(int x){
    int result = 1;

    while(x / 10 != 0){
        x = x / 10;
        result++;
    }

    return result;

}

int main(){

    int n;
    cin >> n;

    int ans = 0;

    rep(i,n){
        if(digit(i + 1) % 2 == 1) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, M = map(int, input().split())
    n = 1
    m = 1
    for i in range(N, N-2, -1):
        n *= i
    for i in range(M, M-2, -1):
        m *= i
    print((n + m) // 2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define fl(i,x,y) for( int i=x;i<y;i++)
#define w(t) while(t--)
#define vi vector<ll>
#define vvi vector< vi >
#define si set<ll>
#define msi multiset<ll>
#define si_d set<ll, greater<ll> >
#define mii map<ll,ll>
#define pb push_back
#define msi_it  multiset<ll> :: iterator
#define si_it set<ll> :: iterator
#define sort1(v) sort(v.begin(),v.end());
#define F first
#define S second
using namespace std;
#define N 1000000007
#define mod 15000000000031
int main()
{
	int a[3][3];
	fl(i,0,3)
	{
		fl(j,0,3)
		{
			cin>>a[i][j];
		}
	}
	int n;cin>>n;
	w(n)
	{
		int b;cin>>b;
		fl(i,0,3)
		{
			fl(j,0,3)
			{
				if(a[i][j]==b) a[i][j]=0;
			}
		}
	}
	if(a[0][0]==0 && a[0][1]==0 && a[0][2]==0 || a[1][0]==0 && a[1][1]==0 && a[1][2]==0
		|| a[2][0]==0 && a[2][1]==0 && a[2][2]==0 || a[0][0]==0 && a[1][0]==0 && a[2][0]==0
		||a[0][1]==0 && a[1][1]==0 && a[2][1]==0 || a[0][2]==0 && a[1][2]==0 && a[2][2]==0
		|| a[0][0]==0 && a[1][1]==0 && a[2][2]==0 || a[0][2]==0 && a[1][1]==0 && a[2][0]==0)
		cout<<"Yes";
	else cout<<"No";
}

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

int main()
{
    int n;
    std::cin>>n;
    std::vector<int> h(n);
    std::vector<int> dp(n,2000000000);     //dp[i] : 足場iに行くための最小コスト

    for(int i=0;i<n;i++)std::cin>>h[i];
    dp[0] = 0;
    dp[1] = std::abs(h[0] - h[1]);
    for(int i=2;i<n;i++){
        dp[i] = std::min(dp[i-1] + std::abs(h[i] - h[i-1]),dp[i-2] + std::abs(h[i] - h[i-2]));
    }
    std::cout<<dp[n-1]<<std::endl;
}

Measured memory_bytes: 1024
#include<cstdio>

int k, q;
int d[5003];

int main() {
  scanf("%d %d", &k, &q);
  for (int i = 0; i < k; i++) {
    scanf("%d", &d[i]);
  }
  for (int i = 0; i < q; i++) {
    int n, x, m;
    scanf("%d %d %d", &n, &x, &m);
    x %= m;
    long long sum = 0;
    int cz = 0;
    for (int j = 0; j < k; j++) {
      sum += d[j] % m;
      if (d[j] % m == 0) {
        ++cz;
      }
    }
    sum *= (n - 1) / k;
    cz *= (n - 1) / k;
    for (int j = 0; j < (n - 1) % k; j++) {
      sum += d[j] % m;
      if (d[j] % m == 0) {
        ++cz;
      }
    }
    sum += x;
    printf("%lld\n", n - cz - sum / m - 1);
  }
}


Measured memory_bytes: 256
if __name__ == '__main__':
    n, m = map(int, input().split())
    ans = [-1]*n
    ansstr =""

    for i in range(m):
        b, c = map(int, input().split())
        if n >1 and b ==1 and c ==0:
            ansstr = "-1"
            break
        elif ans[b-1] != c and ans[b-1] >-1:
            ansstr = "-1"
            break
        else:
            ans[b-1]= c
    if ansstr == "":
        for i in range(n):
            if ans[i] == -1:
                if n >1:
                    if i == 0:
                        ansstr = ansstr + "1"
                    else:
                        ansstr = ansstr + "0"
                else:
                    ansstr = ansstr + "0"
            else:
                ansstr = ansstr + str(ans[i])
    print(ansstr)




Measured memory_bytes: 3064
function Main(input) {
    let s = input.split("\n");
    let r = RegExp(s[0] + '[a-z]');
    (/[a-z]{0,10}/.test(s[0]) && r.test(s[1])) ? console.log('Yes') : console.log('No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29628
#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
	int H, W;

	while (true) {
		cin >> H >> W;
		if (H == 0 && W == 0) break;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << "#";
			}
			cout << "\n";
		}
		cout << "\n";
	}
}

Measured memory_bytes: 1120
import numpy as np
N,K=map(int,input().split(" "))
p_list=list(map(int,input().split(" ")))
def expect(i):
    return 0.5*(p_list[i]+1)

e_list=[expect(i) for i in range(N)]
accum_expect=[0]+list(np.cumsum(e_list))

n=N-K+1
expect_list=[accum_expect[i+K]-accum_expect[i] for i in range(0,n)]

print(max(expect_list))

Measured memory_bytes: 41124
/**Bismillahir Rahmanir Rahim.**/
#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long int            ll;
typedef long double              ld;
#define Faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi                 acos(-1);
#define test        int t; cin>>t; while(t--)
//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());
//cin.getline(array,size);
int main()
{
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n,i,j,a,b,c=0,p=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a>>b;
        if(a==b)
        {
            c++;
            if(c==3)
                p=1;
        }
        else
            c=0;
    }
    if(p==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
    #ifndef ONLINE_JUDGE
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>

using namespace std;




int main()
{
	long a, b;
	long d, r;
	double f;
	
	cin >> a >> b;
	d = a / b;
	r = a % b;
	f = 1.000000 * a / b;
	cout << d << " " << r << " ";
	printf("%.5lf\n", f);
	
	return 0;
}

Measured memory_bytes: 1244
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)


int main(){
    int n;
    cin>>n;
    
    int r;
    rep(i,n+100){
        if( (ll)(i+1)*i/2>=n ){
            r=i;
            break;
        }
    }
    
    vector<int> v;
    n-=r;
    v.pb(r);
    for(int i=r-1;i>=1;i--){
        if(n>=i){
            v.pb(i);
            n-=i;
        }
    }
    
    rep(i,v.size())cout<<v[i]<<endl;
}

Measured memory_bytes: 256