akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#define debug(x) cout << #x << "==" << x << endl;

using namespace std;

//??\???
#define MAX_N 44
int N;
int dp[MAX_N];

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

  cin >> N;

  dp[0] = dp[1] = 1;
  for(int i = 2; i <= N; i++) {
    dp[i] = dp[i-1] + dp[i-2];
  }

  cout << dp[N] << endl;

  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int h[100010];
int main(){
    int n;
    cin>>n;
    REP(i,n) cin>>h[i];
    bool flag=true;
    int max_h=h[0];
    for (int i = 0; i < n; i++)
    {
        
        if(h[i]-max_h<-1){
            cout<<"No"<<endl;
            return 0;
        }
        if(h[i]>=max_h){
            max_h=h[i];
        }
    }
    cout<<"Yes"<<endl;
    

    return 0;
}

Measured memory_bytes: 640
/*******************************************************************
 * 		Author : yash1402_										   *
 * 
 * 
 * 		Don't forget to comment input of T....
 ******************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int,int> pi; 
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vi> vvi;

#define all(__VEC) __VEC.begin(),__VEC.end()

#define opvec(__VEC) cout << #__VEC << " : "; for(auto _ITER:__VEC) cout << _ITER << " "; cout << "\n";
#define opv(__VAR) cout << #__VAR << " : " << _VAR << "\n";

#define MP make_pair
#define PB push_back

void solve() {
	int n;
	cin >> n;
	if(n==0) cout << "1\n";
	else cout << "0\n";
}

int main() {
	ll T=1;
	//cin >> T;
	while(T--) {
		solve();
	}
}



Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;





int main() {
    
    int a,b,c,d;
    string s;
    cin>>s;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    if(a+b+c+d==7)cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<'\n';
    else if(a+b+c-d==7)cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<'\n';
    else if(a+b-c+d==7)cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<'\n';
    else if(a+b-c-d==7)cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<'\n';
    else if(a-b+c+d==7)cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<'\n';
    else if(a-b+c-d==7)cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<'\n';
    else if(a-b-c+d==7)cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<'\n';
    else if(a-b-c-d==7)cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<'\n';

}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>
#include<map>
 
using namespace std;
 
long long i,j,k,N,M,Q,a[51],b[51],c[51],d[51],ans,A[11],temp;

void rec(long long n, long long m)
{
  
  long long s,t,u;
  
  
  if(m==N+1)
  {
    s=0;
    for(i=1;i<=Q;i++)
    {
      if(A[b[i]]-A[a[i]]==c[i]) s+=d[i];
    }
    ans=max(ans,s);
  }
  else
  {
  for(A[m]=n;A[m]<=M;A[m]++)
  {
    rec(A[m],m+1);
  }
  }
  
  
}


int main()
{
  cin>>N>>M>>Q;
  
  for(i=1;i<=Q;i++)
  {
    cin>>a[i]>>b[i]>>c[i]>>d[i];
  }
  ans=0;
  rec(1,1);
  
  cout<<ans;
 
  
  
}

Measured memory_bytes: 3652
#include <queue>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N[3];
    cin >> N[0] >> N[1] >> N[2];
    sort(N,N+3);
    int ans = 0;
    for(int i = 0;true;i++){
        if(N[0] == N[1] && N[1] == N[2]){
            break;
        }
        if(N[1] < N[2]){
            N[0]++;
            N[1]++;
            ans++;
        }else if(N[0] < N[2] - 1){
            N[0] += 2;
            ans++;
        }else if(N[0] == N[2] - 1){
            ans += 2;
            break;
        }
        
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n,m;cin>>n>>m;

  const int tn=100;
  const int tm=1900;
  m=min(m,5);
  const int st=m*tm+(n-m)*tn;

  out(st*(1<<m));


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const ll INF = (1LL << 31) - 1;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  map<ll,int>mp;
  rep(i,n){
    ll a;
    cin >> a;
    mp[a]++;
  }
  bool ok=false;
  if(mp[0]==n){
    ok=true;
  }
  else{
    ll sum=0;
    vector<ll>vec;
    for(auto p:mp){
      if(p.second){
        sum++;
        vec.push_back(p.first);
      }
    }
    
    if(n%3==0 && sum==2){
      if(mp[0]==n/3) ok = true;
    }
    if(n%3==0 && sum==3){
      bool can = true;
      for(auto t:mp){
      	if(t.second && t.second!=n/3) can = false;
      }
      ll bit=0;
      rep(i,3){
        bit^=vec[i];
      }
      if(can && !bit) ok = true;
    }
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 6264
def d_make_them_even(H, W, A):
    from itertools import product
    grid = [row for row in A]
    ans_tmp = []
    for h, w in product(range(H), range(W)):
        if grid[h][w] % 2 == 1:
            # コイン1枚をグリッドの右か下に押し付ける
            for dh, dw in zip((0, 1), (1, 0)):
                if 0 <= h + dh < H and 0 <= w + dw < W:
                    grid[h + dh][w + dw] += 1
                    grid[h][w] -= 1
                    ans_tmp.append('{} {} {} {}'.format(h + 1, w + 1, h + dh + 1, w + dw + 1))
                    break
    return str(len(ans_tmp)) + '\n' + '\n'.join(ans_tmp)

H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(H)]
print(d_make_them_even(H, W, A))

Measured memory_bytes: 18140
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[100010];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int h[100010];
    rep(i, N) cin >> h[i];
    rep(i, min(K - 1, N)) dp[i + 1] = abs(h[i + 1] - h[0]);
    REP(i, K, N - 1) {
        int minJ = INF;
        rep(j, K) {
            minJ = min(minJ, abs(h[i] - h[i - j - 1]) + dp[i - j - 1]);
        }
        dp[i] = minJ;
    }
    cout << dp[N - 1] << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())

#define dbn cerr << "\n"
#define dbg(x) cerr << #x << " : " << (x) << " "
#define dbs(x) cerr << (x) << " "

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

template <class T>
void debug(T a, T b) {
    cerr << "[";
    for (T i = a; i != b; ++i) {
        if (i != a) cerr << ", ";
        cerr << *i;
    }
    cerr << "]\n";
}

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

    int n;
    cin >> n;
    
    string s, t;
    cin >> s;
    cin >> t;

    int ans = 2 * n;
    for (int len = 1; len <= n; ++len) {
        if (s.substr(n - len) == t.substr(0, len)) {
            ans = min(ans, n + n - len);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<set>

int main() {
	int q;
	scanf("%d", &q);
	long long b_sum = 0;
	int n = 0;
	std::multiset<int> l, r;
	long long l_sum = 0, r_sum = 0;
	int median = 0;
	for(int i=0;i<q;i++) {
		int t;
		scanf("%d", &t);
		if(t == 1) {
			int a, b;
			scanf("%d %d", &a, &b);
			b_sum += b;
			if(n % 2 == 0) {
				if(median < a) {
					r.insert(a);
					r_sum += a;
					auto it = r.begin();
					median = *it;
					r.erase(it);
					r_sum -= median;
				} else {
					l.insert(a);
					l_sum += a;
					auto it = l.rbegin();
					median = *it;
					l.erase((++it).base());
					l_sum -= median;
				}
			} else {
				if(median < a) {
					l.insert(median);
					l_sum += median;
					r.insert(a);
					r_sum += a;
				} else {
					l.insert(a);
					l_sum += a;
					r.insert(median);
					r_sum += median;
					median = *(l.rbegin());
				}
			}
			n++;
		} else {
			printf("%d %lld\n", median, r_sum - l_sum + b_sum);
		}
	}
	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;

int main() {
    int k, a, b; cin >> k >> a >> b;
    bool flag = false;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            flag = true;
        }
    }
    if (flag) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
/*     !ya khoda!     */
#include <bits/stdc++.h>

#define ll long long
#define ld long double

#define pp push
#define po pop()
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
#define I insert
#define E erase

#define F first
#define S second

#define mkp make_pair
#define pll pair<ll,ll>
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define all(a) a.begin(),a.end()

#define coutghat(x)      cout<<tolower(x);
#define coutashar(x,d)   cout<<fixed<<setprecision(x)<<(ld)d
#define IOS ios_base::sync_with_stdio(false) , cin.tie(0);

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)
//#define poow(a,b,M)   b?(poow((a*a)%M,b/2)%M * (b&1?a))%M:1 ;
/*==========================================================================*/
using namespace std;
ll poow(ll x,ll n,ll Mod=1e9+7) { return (n==0?1:poow(x*x%Mod,n/2)*(n&1?x:1)%Mod); }
//#pragma optimize O3
// 107,109, 211,223, 307, 401,409, 503,509, 601,607, 701,709, 809, 907, 1009
/*==========================================================================*/
const int N=2e5+10  , M=1e4+10  , SQ=320 , LG=23 , base=2;
const int mod=1e9+7 , MOD=1e9+9;
const ll  INF=1e9   , inf=1e18 , super_inf=~0ull/4;
ll n,m,a[N]  ,  cnt[16]  ,  dp[1<<16],val[1<<16]  ,  x,k;
vector<ll>vec;
/*==========================================================================*/
int main()
{
    IOS;
    cin>>n;
	for(int i=1;i<n;i++)
	{   ll v,u,w;
        cin>>v>>u>>w;
		a[v]^=w  ,  a[u]^=w;
	}
	for(int i=0;i<n;i++)   cnt[a[i]]++;


	x=cnt[0]  ,  cnt[0]=0;
	for(int i=0;i<n;i++)
	{
		if(cnt[a[i]]%2)    vec.pb(a[i]);
		x+=cnt[a[i]]/2  ,  cnt[a[i]]=0;
	}

	m=vec.size() , k=(1<<m);
	for(int i=0;i<k;i++)
		for(int j=0;j<m;j++)
			if(i>>j&1)
				val[i]^=vec[j];

	for(int i=1;i<k;i++)
	{   dp[i]=1;
		if(val[i]!=0)   continue;
		for(int j=i;j>0;j=(j-1)&i)
			if(!val[j])
				dp[i]=max(dp[i],dp[j]+dp[i^j]);
	}

	cout<<n-(dp[k-1]+x);
	return 0;
}


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

int main() {
    int a, b, c, x, counter = 0;
    cin >> a >> b >> c >> x;

    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (i*500 + j*100 + k*50 == x) {
                    counter += 1;
                }
            }
        }
    }
    cout << counter << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
N, M = map(int, input().split())
students = [list(map(int, input().split())) for _ in range(N)]
c_points = [list(map(int, input().split())) for _ in range(M)]

for a,b in students:
    m_dis = [abs(a-c) + abs(b-d) for c,d in c_points]
    print(m_dis.index(min(m_dis)) + 1)


Measured memory_bytes: 2940
const main = lines => {
  console.log(solve(lines));
};

const solve = (lines: string[]): string => {
  const { N, A } = parseLines(lines);
  const sorted = A.slice().sort((a, b) => b - a);

  return A.map(v => (v === sorted[0] ? sorted[1] : sorted[0])).join('\n');
};

const parseLines = (lines: string[]) => {
  const N = +lines[0];
  const A = lines.slice(1).map(a => +a);
  const obj = { N, A };
  debug(obj);
  return obj;
};

const debug = (message?: any, ...optionalParams: any[]) => {
  if (!!process.env.LOCAL_DEBUG) console.log(message, ...optionalParams);
};

if (!process.env.LOCAL_DEBUG) {
  const { stdin: input, stdout: output } = process;
  input.resume();
  input.setEncoding('utf8');
  const lines = [];
  require('readline')
    .createInterface({ input, output })
    .on('line', line => lines.push(line))
    .on('close', () => main(lines));
}

export default solve;


Measured memory_bytes: 49240
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)

int main() {
	int x, n;
	cin >> x >> n;
	vector<int> p(n);
	rep(i, n)cin >> p[i];
	sort(p.begin(), p.end());

	if (n == 0) {
		cout << x << endl;
		return 0;
	}
	int cc = 0;
	rep(i, n) {
		if (p[i] == 1)cc++;
	}
	if (x == 1 && cc > 0) {
		cout << 0 << endl;
		return 0;
	}
	

	int count =0;
	rep(i, n) {
		if (p[i] != x)count++;
	}
	if (count == n) {
		cout << x << endl;
		return 0;
	}

	vector<int>countp(n, 0);
	vector<int>countm(n, 0);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (x - i != p[j])countm[i]++;
			if (x + i != p[j])countp[i]++;
			
		}
	}
	rep(i, n) {
		if (countm[i] == n) {
			cout << x - i << endl;
			return 0;
		}
		if (countp[i] == n) {
			cout << x + i << endl;
			return 0;
		}
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int n;
    bool dp[10001]={1};
    cin>>n;
    REP(i,n){
        int s;
        cin>>s;
        REPR(j,10000){
            if(dp[j])dp[j+s]=1;
        }
    }
    REPR(j,10000){
        if(!(j%10))continue;
        if(dp[j]){
            cout<<j<<endl;
            return 0;;
        }
    }
    cout<<0<<endl;
    return 0;
}


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

typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

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

    int cnt2 = 0, cnt1 = 0;
    for (int i = 1; i <= 4; i++)
        cnt2 += nei[i] == 2, cnt1 += nei[i] == 1;
    
    cout << (cnt2 == cnt1 ? "YES" : "NO") << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <cmath>

using namespace std;

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    
    map<int, pair<int, int>> a;
    
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            int tmp;
            cin >> tmp;
            a[tmp] = make_pair(j, i);
        }
    }
    
    vector<int> dp(h * w + 1, 0);
    
    for (int i = d + 1; i <= h * w; ++i)
    {
        int nowx = a[i - d].first;
        int nowy = a[i - d].second;
        
        int nextx = a[i].first;
        int nexty = a[i].second;
        dp[i] = dp[i - d] + (abs(nowx - nextx) + abs(nowy - nexty));
    }
    
    
    int q;
    cin >> q;
    
    for (int i = 0; i < q; ++i)
    {
        int l, r;
        cin >> l >> r;
        
        int ret = dp[r] - dp[l];
        
        cout << ret << endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 7040
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long x){
    i64 ans = 0;
    while(x >= 500){
        ans += 1000;
        x -= 500;
    }
    while(x >= 5){
        ans += 5;
        x -= 5;
    }
    cout << ans << endl;
}


signed main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100000010
//#define int long long
#define INF 1e9
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
inline int read()
{
	register char cc = getchar();register int cn(0), flus(1);
	while(cc > '9' || cc < '0') {if(cc == '-') flus = -flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();}
	return cn * flus;
}
signed main()
{
	int n = read(), k = read(), s = read();
	rep(i, 1, k) printf("%d ",s);
	if(s < 1e9)
	{
		rep(i, k + 1, n) printf("1000000000 ");
	}
	else rep(i, k + 1, n) printf("1 ");
	putchar(10);
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>

using namespace std;

int main()
{	int a,ans,i,n;
int v[60];
int c[60];
	cin >> n;
	for(i=0;i<n;i++)
	{
		cin >> v[i];
	}
	for(i=0;i<n;i++)
	{
		cin >> c[i];
	}
	for(i=0;i<n;i++)
	{
		if(v[i] - c[i] > 0)
		{
			ans = ans + v[i] - c[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 1e9 + 1
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

int n, R[200010];

int main() {
    cin >> n;
    REP(i, n) cin >> R[i];
    int minimum = R[0];
    int ans = -INF;
    for (int i = 1; i < n; i++) {
        int diff = R[i] - minimum;
        if (diff > ans) ans = diff;
        if (R[i] < minimum) minimum = R[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
    
    
    ll x,n,i,j;
    cin>>x>>n;
    if(n==0)cout<<x;
    else{
        ll arr[n];
        for(i=0;i<n;i++)cin>>arr[i];
        sort(arr,arr+n);
        ll ans=1000;
        for(i=-101;i<=200;i++){
            ll find=0;
            for(j=0;j<n;j++)if(i==arr[j])find=1;
            if(!find){
                if(abs(x-ans)>abs(x-i))ans=i;
            }
        }
        cout<<ans;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
signed main() {
  int a;
  int b;
  cin >> a >> b;
  int x,y,z;
  x = a+b;
  y = a-b;
  z = a*b;
  if(x >= y){
    if (x >= z){
      cout << x <<endl;
    }
    else {
      cout << z << endl;
    }
  }
  else {
    if (y >= z){
      cout << y << endl;
    }
    else {
      cout << z << endl;
    }
  }
  
}


  

  
    
  
  
 
 





















Measured memory_bytes: 256
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)

H, W, A, B = map(int, input().split())
MOD = 10**9 + 7
com = Combinatorics(H+W, MOD)
ans = com.binom(H-1+W-1, H-1)
for j in range(B):
    ans = (ans - com.binom(H-A-1+j, j) * com.binom(A-1+W-j-1, A-1)) % MOD
print(ans)

Measured memory_bytes: 78064
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

int main(){
    int h, w;
    scanf("%d%d", &h, &w);
    char c[h][w];
    rep(i, h)rep(j, w) scanf(" %c", &c[i][j]);
    int cnt[h][w][4];
    rep(i, h)rep(j, w)rep(k, 4) cnt[i][j][k] = -1;
    rep(i, h){
        int cur1 = -1;
        int cur2 = w;
        rep(j, w){
            if(c[i][j] == '#') cur1 = j;
            else cnt[i][j][0] = cur1;
            if(c[i][w-1-j] == '#') cur2 = w-1-j;
            else cnt[i][w-1-j][1] = cur2;
        }
    }
    rep(j, w){
        int cur1 = -1;
        int cur2 = h;
        rep(i, h){
            if(c[i][j] == '#') cur1 = i;
            else cnt[i][j][2] = cur1;
            if(c[h-1-i][j] == '#') cur2 = h-1-i;
            else cnt[h-1-i][j][3] = cur2;
        }
    }
    int ans = 0;
    rep(i, h)rep(j, w)if(c[i][j] == '.'){
        ans = max(ans, cnt[i][j][1]-cnt[i][j][0]+cnt[i][j][3]-cnt[i][j][2]-3);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 66688
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {


    int h = 0;
    int w = 0;
    char[][] squares = null;

    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      String[] tmp = br.readLine().split("\\s");
      h = Integer.parseInt(tmp[0]);
      w = Integer.parseInt(tmp[1]);

      squares = new char[h][w];
      for (int i = 0; i < h; i++) {
        squares[i] = br.readLine().toCharArray();
      }

    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

    int[][] count = new int[h][w];
    for (int i = 0; i < squares.length; i++) {
      char[] line = squares[i];
      for (int j = 0; j < line.length; j++) {
        if (line[j] == '#') {
          count[i][j] = -1;
          // 上
          if (0 <= i - 1 && squares[i-1][j] != '#') {
            count[i-1][j]++;
          }
          // 下
          if (i + 1 < h && squares[i+1][j] != '#') {
            count[i+1][j]++;
          }
          // 左
          if (0 <= j - 1 && squares[i][j-1] != '#') {
            count[i][j-1]++;
          }
          // 右
          if (j + 1 < w && squares[i][j+1] != '#') {
            count[i][j+1]++;
          }
          // 左上
          if (0 <= i - 1 && 0 <= j - 1 && squares[i-1][j-1] != '#') {
            count[i-1][j-1]++;
          }
          // 左下
          if (i + 1 < h && 0 <= j - 1 && squares[i+1][j-1] != '#') {
            count[i+1][j-1]++;
          }
          // 右上
          if (0 <= i - 1 && j + 1 < w && squares[i-1][j+1] != '#') {
            count[i-1][j+1]++;
          }
          // 右下
          if (i + 1 < h &&  j + 1 < w && squares[i+1][j+1] != '#') {
            count[i+1][j+1]++;
          }
        }
      }
    }

    for (int i = 0; i < count.length; i++) {
      int[] result = count[i];
      for (int j = 0; j < result.length; j++) {
        if (result[j] == -1) {
          System.out.print("#");
        } else {
          System.out.print(result[j]);
        }
      }
      System.out.print(System.lineSeparator());
    }
  }
}


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

using namespace std;
#define N 200200

int cnt, x, y, n, i, mx;
int main(){
    cin >> n;
    for (i = 0; i < n; ++i) {
        cin >> x >> y;
        if (x == y) {
            ++cnt;
        } else {
            mx = max(cnt, mx);
            cnt = 0;
        }
    }
    mx = max(cnt, mx);
    if (mx > 2) {
        cout << "Yes";
    } else
        cout << "No";
    return 0;
}


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


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

    int A,B;
    cin >> A >> B;
    string S;
    cin >> S;
    string ans="Yes";
    rep(i,A+B){
        if (i==A && S[A]!='-') {
            ans="No";
        }
        else if(i!=A && S[i]=='-') {
            ans="No";
        }
    }
    cout << ans << endl;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, int> memo = new Dictionary<string, int>();

            int maxV = 0;
            string maxS = "", longest = "";

            string[] txt = Console.ReadLine().Split(' ');

            foreach (var t in txt)
            {
                if (!memo.ContainsKey(t)) memo.Add(t, 1);
                else memo[t]++;

                if (maxV < memo[t])
                {
                    maxV = memo[t];
                    maxS = t;
                }

                if (longest.Length < t.Length) longest = t;
            }
            Console.WriteLine(maxS + " " + longest);
        }
    }
}

Measured memory_bytes: 8916
use std::error::Error;
use std::io;

fn main() {
    if let Err(e) = run() {
        println!("{}", e);
    }
}

fn run() -> Result<(), Box<Error>> {
    let mut nm = String::new();
    io::stdin().read_line(&mut nm)?;
    let a: Vec<u64> = nm.trim().split(" ").map(|e| e.parse().expect("")).collect();
    println!("{}", (a[0] - 1) * (a[1] - 1));
    Ok(())
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define ms memset
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define lower_bound lb
#define upper_bound ub

int main()
{
    int n; cin >> n;
    string S; cin >> S;
    int cnt = 0;
    for (int i = 0; i < n; i++){
        if (S[i] == '1') cnt++;
    }
    int Ap[n+1], Bp[n+1];
    Ap[0] = 1; Bp[0] = 1;
    for (int i = 1; i < n; i++){
        Ap[i] = (2*Ap[i-1]) % (cnt+1);
        if (cnt == 1) continue;
        Bp[i] = (2*Bp[i-1]) % (cnt-1);
    }
    int A = 0; int B = 0;
    for (int i = 0; i < n; i++){
        if (S[i] == '1'){
            A += Ap[n-i-1]; A %= (cnt+1);
            if (cnt == 1) continue;
            B += Bp[n-i-1]; B %= (cnt-1);
        }
    }
    for (int i = 0; i < n; i++){
        int c = 1;
        if (S[i] == '0'){
            int a = (A + Ap[n-i-1]) % (cnt+1);
            while (a > 0){
                int j = a;
                int count = 0;
                while (j > 0){
                    if (j % 2 == 1) count++;
                    j /= 2;
                }
                a %= count;
                c++;
            }
            cout << c << '\n';
        }
        else{
            if (cnt == 1){
                cout << 0 << '\n';
                continue;
            }
            int b = (B - Bp[n-i-1] + cnt-1) % (cnt-1);
            while (b > 0){
                int j = b;
                int count = 0;
                while (j > 0){
                    if (j % 2 == 1) count++;
                    j /= 2;
                }
                b %= count;
                c++;
            }
            cout << c << '\n';
        }
    }
    return 0;
}

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

using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
void c_p_c()
{
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{

	int n;
	cin >> n;
	map<string, int>ma;
	while (n--)
	{
		string s;


		cin >> s;
		ma[s]++;
	}
	int maxi = INT_MIN;
	for (auto &it : ma)
	{
		if (it.ss > maxi)
		{

			maxi = it.ss;
		}
	}
	for (auto &it : ma)
	{
		if (it.ss == maxi)
			cout << it.ff << endl;
	}

}









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

int main(void)
{
	char a[3], b[3];
	int i, j, c=0;
	cin >> a >> b;
	
	for(i=0,j=0; i<3,j<3; i++,j++)
	{
		if(a[i] == b[i])
			c++;
	}
	
	cout << c << endl;
}


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

int main() {
	// your code goes here
	char odd[100],even[100];
	int lo, le;
	int i,j,k;
	
	cin>>odd;
	cin>>even;
	lo = strlen(odd);
	le = strlen(even);
	
    if(lo > le)
        k = le;
    else
        k = lo;
	/*for(i=0,j=0;i<lo+le && j<lo; i+=2,j++){
	    big[i] = odd[j];
	    
	}
	
	for(i=1,j=0; i<le+lo && j<le; i+=2,j++){
	    big[i] = even[j];
	}
	
	for(i=0;i<lo+le;i++)
	    cout<<big[i];
	*/
	
	for(i=0,j=0;i<k; i++,j++){
	    cout<<odd[i];
	    cout<<even[j];
	}
	if(lo > le){
	    cout<<odd[lo-1];
	}else if(lo < le)
	    cout<<even[le-1];
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int n,s;
int memo[1024][1000];

int search(int stat,int sum,int dep){
	if(dep==n)	return memo[stat][sum]=(s==sum);
	if(~memo[stat][sum])	return memo[stat][sum];
	if(sum>s)	return 0;

	int cnt=0;
	for(int i=0;i<10;i++){
		if((stat&(1<<i))==0){
			stat|=1<<i;
			cnt+=search(stat,sum+i*(n-dep),dep+1);
			stat&=~(1<<i);
		}
	}
	return memo[stat][sum]=cnt;
}

int main(){
	for(;~scanf("%d%d",&n,&s);){
		for(int i=0;i<1024;i++)for(int j=0;j<1000;j++)	memo[i][j]=-1;
		if(n>10 || s>=1000){
			puts("0");
			continue;
		}
		printf("%d\n",search(0,0,0));
	}
	return 0;
}

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

using namespace std;

char s[3][3];

int judgeB(){
  for(int i = 0; i < 3; i++){
    if(s[i][0] == 'b' && s[i][1] == 'b' && s[i][2] == 'b') return 1;
  }
  for(int i = 0; i < 3; i++){
    if(s[0][i] == 'b' && s[1][i] == 'b' && s[2][i] == 'b') return 1;
  }
  if(s[0][0] == 'b' && s[1][1] == 'b' && s[2][2] == 'b') return 1;
  if(s[0][2] == 'b' && s[1][1] == 'b' && s[2][0] == 'b') return 1;

  return 0;
}

int judgeW(){
  for(int i = 0; i < 3; i++){
    if(s[i][0] == 'w' && s[i][1] == 'w' && s[i][2] == 'w') return 1;
  }
  for(int i = 0; i < 3; i++){
    if(s[0][i] == 'w' && s[1][i] == 'w' && s[2][i] == 'w') return 1;
  }
  if(s[0][0] == 'w' && s[1][1] == 'w' && s[2][2] == 'w') return 1;
  if(s[0][2] == 'w' && s[1][1] == 'w' && s[2][0] == 'w') return 1;

  return 0;
}


int main(){
 
  while(1){

    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
	cin >> s[j][k];
	if(s[j][k] == '0') return 0;
      }
    }

    int x = judgeB();
    int y = judgeW();

    if(x == 1) cout << "b" << endl;
    else if(y == 1) cout << "w" << endl;
    else cout << "NA" << endl;
  }
  
  return 0;
}

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

using namespace std;

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

  int d, t, s;
  cin >> d >> t >> s;
  cout << (d <= s * t ? "Yes" : "No");

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,h,w;
  cin>>n>>h>>w;
  cout<<(n-h+1)*(n-w+1)<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;

#define int long long

string s,t,b;
char c[100010];
int ans=0;

signed main(){
   cin>>c;
   s=c;
   int l=0,r=s.size()-1;
   while(l<=r){
       if(s[l]==s[r]){
           l++;r--;
           continue;
       }
       if(s[l]=='x'){
           l++;ans++;
           continue;
       }
       if(s[r]=='x'){
           r--;ans++;
           continue;
       }
       puts("-1");
       return 0;
   }
   cout<<ans<<endl;
   return 0;
}

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

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

	int num[3] = {};
	int ans = 0;
	for (int i = 1; i < n-1; i++) {
		num[0] = p[i-1];
		num[1] = p[i];
		num[2] = p[i+1];
		sort(num, num+3);
		if (num[1] == p[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


vector<vector<int>>ans;
void getans(vector<int>now, int pre,int rest) {
	for (int i = min(rest, pre); i >= 1; --i) {
		vector<int>v(now);
		v.push_back(i);
		if (i == rest)ans.push_back(v);
		else {
			getans(v, i, rest - i);
		}
	}
}
int main() {
	while (1) {
		ans.clear();
		int N; cin >> N;
		if (!N)break;
		getans(vector<int>(), N, N);
		for (auto v : ans) {
			for (int i = 0; i < v.size(); ++i) {
				cout << v[i];
				if (i != v.size() - 1)cout << " ";
				else cout << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 3432
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
vector< vector<int> > v(100000);
int visited[10010] = {0};
int depth[100010] = {0};
int mini[100010] = {0};
int V,E,s,t;
int inf = 1e9;
vector<int> ans;

int dfs(int n,int m){
	visited[n] = 1;
	for(int i=0;i<v[n].size();i++){
		if(visited[v[n][i]]==0){
			depth[v[n][i]] = depth[n] + 1;
			dfs(v[n][i],n);
		}
	}
	for(int i=0;i<v[n].size();i++){
		if(v[n][i]!=m) mini[n] = min(mini[n],min(depth[n],depth[v[n][i]]));
	}
}

int dfs2(int n){
	visited[n] = 1;
	for(int i=0;i<v[n].size();i++){
		if(visited[v[n][i]]==0){
			dfs2(v[n][i]);
			mini[n] = min(mini[n],mini[v[n][i]]);
			if(n!=0 && depth[n]<=mini[v[n][i]] && (ans.size()==0 || ans[ans.size()-1]!=n)) ans.push_back(n);
		}
	}
}

int main(){
	cin >> V >> E;
	for(int i=0;i<E;i++){
		cin >> s >> t;
		v[s].push_back(t);
		v[t].push_back(s);
	}
	for(int i=0;i<V;i++) mini[i] = inf;
	dfs(0,-1);
//	for(int i=0;i<V;i++) cout << mini[i] << endl;
	int count = 0;
	for(int i=0;i<V;i++){
		visited[i] = 0;
		if(depth[i]==1) count++;
	}
	if(count>=2) ans.push_back(0);
	dfs2(0);
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++){
		if(i==0 || ans[i]!=ans[i-1]) cout << ans[i] << endl;
	}
}


Measured memory_bytes: 6424
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int x = sc.nextInt();
        
        int a = x;
        int b = 0;
        
        while(a > 0){
            b = b + a % 10;
            a = a / 10;
        }
        
        if(x % b == 0){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        
        sc.close();
        
    }
}


Measured memory_bytes: 22868
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long h = scan.nextLong();
		long cnt = 0;
		while(h > 0) {
			h = h / 2;
			cnt++;
		}

		long ans = 0;

		long i;
		for(i = 0; i < cnt; i++) {
			ans += Math.pow(2, i);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

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

	vector<Int> box(N + 1);
	Int temp, cnt;
	Int M=0;
	for (Int i = N; i > 0; i--) {
		cnt = 0;
		temp = 2 * i;
		while (temp <= N) {
			if (box[temp])cnt++;
			temp += i;
		}

		if (cnt % 2) {
			if (a[i])box[i] = 0;
			else box[i] = 1, M++;
		}
		else {
			if (a[i])box[i] = 1, M++;
			else box[i] = 0;
		}
	}

	printf("%ld\n", M);
	for (Int i = 1; i < N+1; i++) {
		if (box[i])printf("%ld ", i);
	}
}

Measured memory_bytes: 3968
#include <iostream>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) begin(c), end(c)
template<class T> void read(T& x){ cin>>x; }
void read(int& x){ scanf("%d", &x); }
void read(int64_t& x){ scanf("%lld", &x); }
void read(double& x){ scanf("%lf", &x); }
template<class T, class U, class... V>
void read(T& x, U& y, V&... z){ read(x); read(y, z...); }

int main(){
    int n, y;
    read(n, y);
    REP(i,n+1){
        REP(j,n-i+1){
            if(1000*i+5000*j+10000*(n-i-j) == y){
                printf("%d %d %d", n-i-j, j, i);
                return 0;
            }
        }
    }
    printf("-1 -1 -1");
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
num = Array.new(M+1, 0)
N.times do
  as = gets.split.map(&:to_i)
  as.shift
  as.each do |a|
    num[a] += 1
  end
end
puts (1..M).count{|i| num[i] == N}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;

int main(){
  ll a,b,c,d,ans=-(ll)1e18-1;
  cin>>a>>b>>c>>d;
  ans=max(ans,b*d);
  ans=max(ans,a*c);
  ans=max(ans,a*d);
  ans=max(ans,b*c);
  if((a<=0 && b>=0)||(c<=0 && d>=0))ans=max(ans,(ll)0);
  cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    ll k;
    cin >> n >> m >> k;
    vector<int> a(n+1,0);
    vector<int> b(m+1,0);
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<=m;i++) cin >> b[i];
    vector<ll> sum(m+1,0);
    for(int i=1;i<=m;i++) sum[i]=sum[i-1]+b[i];
    int x=m;
    int res=0;
    ll now=0;
    for(int i=0;i<=n;i++)
    {
        now+=a[i];
        if(now>k) break;
        while(now+sum[x]>k) x--;
        res=max(res,i+x);
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 6368