akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

double dx[4] = { 0, 1, 0, -1};
double dy[4] = {-1, 0, 1, 0};
string dir = "DRUL";

int n;
vector<double> x, y;
vector<char> d;

// double xx[4] = {}
// double yy[4] = {INF, 0, INF, 0}

double calc(double m){
    double MAXy = -INF, MAXx = -INF;
    double MINy = INF, MINx = INF;
    rep(i, 0, n){
        int idx = dir.find(d[i]);
        double nx = x[i] + m * dx[idx];
        double ny = y[i] + m * dy[idx];
        chmax(MAXx, nx);
        chmax(MAXy, ny);
        chmin(MINx, nx);
        chmin(MINy, ny);
    }
    return (MAXx - MINx) * (MAXy - MINy);
}

signed main(){
    cin >> n;
    x.resize(n); y.resize(n); d.resize(n);
    rep(i, 0, n){
        cin >> x[i] >> y[i] >> d[i];
    }
    double l = 0, r = 1e9;
    double MIN = INF;
    rep(i, 0, 200){
    // while(fabs(r - l) > 1e-10){
        double m1 = (l * 2 + r) / 3;
        double m2 = (l + r * 2) / 3;
        double t1 = calc(m1);
        double t2 = calc(m2);
        if(t1 < t2) r = m2;
        else l = m1;
        chmin(MIN, t1);
        chmin(MIN, t2);
    }
    printf("%.10f\n", MIN);
}

Measured memory_bytes: 1920
import collections
S = input()
c = collections.Counter(list(S))
kind_flag = len(c) == 2
if kind_flag:
    ll = list(c.values())
    flag = ll[0] == ll[1] == 2
    if flag:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3316
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
bool f(pii l, pii r){
    if(l.s < r.s) return true;
    else if(l.s > r.s) return false;
    else return l.f > r.f;
}
int main(){
    int n;
    cin >> n;
    vector<pii> a;
    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        a.pb(mp(x, y));
    }
    sort(all(a), f);
    int t = 0;
    for(int i = 0; i < n; i++){
        if(t + a[i].f <= a[i].s) t += a[i].f;
        else{
            cout << "No";;
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)

int inf=1000200000;

int max(int N){
	int max =0;
	for(int i=10; N/i>0;i=i*10){
		int kouho;
		kouho = (N/i)*(N-(N/i)*i);
		if(kouho>max){
			max = kouho;
		}
	}
	return max;
}


int main() {
	int Q;
	cin>>Q;
	Rep(i,Q){
		int N;
		cin>>N;
		int count = 0;
		rep(i,inf){
			if(N<=9){
				cout<<count<<endl;
				break;
			}
			else if(i >= inf-1){
				cout<<-1<<endl;
				break;
			}
			else{
				N =max(N);
				count++;
			}
		}
	}

	return 0;
}



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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m;
int d[125252];
vi g[125252];
int color[125252];
map<pii,int> rev;
int w[252521];

int main(){
    scanf("%d%d",&n,&m);
    REP(i,n)scanf("%d",d+i);
    REP(i,m){
        int u,v;
        scanf("%d%d",&u,&v);
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
        rev[pii(u,v)] = i;
        rev[pii(v,u)] = i;
    }
    fill(color, color+n, -1);
    vi ids(n); iota(ALL(ids),0); sort(ALL(ids),[&](int i, int j){return d[i]<d[j];});
    REP(_i,n){
        int i = ids[_i];
        // search neighbor
        bool ok = false;
        for(int to : g[i]){
            if(color[to] != -1 && d[to] == d[i]){
                ok = true;
                w[rev[pii(i,to)]] = d[i];
                continue;
            }
            if(color[to] != -1){
                ok = true;
                if(color[i] == -1){
                    color[i] = 0;
                }
                w[rev[pii(i,to)]] = color[i]==color[to] ? max(1,d[i]-d[to]) : d[i];
            }else if(d[to] == d[i]){
                ok = true;
                if(color[i] == -1){
                    color[i] = 0;
                }
                if(color[to] == -1){
                    color[to] = 1-color[i];
                }
                w[rev[pii(i,to)]] = d[i];
            }
        }
        if(!ok){
            puts("-1");
            return 0;
        }
    }
    REP(i,n)putchar("BW"[color[i]]);puts("");
    REP(i,m)printf("%d\n",w[i]);
    return 0;
}


Measured memory_bytes: 35968
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
vector<int> G[55];
bool visit[55];

void dfs(int x, int a, int b)
{
	if (visit[x]) return;
	visit[x] = true;
	rep(i,G[x].size())
	{
		if ((x != a || G[x][i] != b) && (x != b || G[x][i] != a)) dfs(G[x][i],a,b);
	}
	return;
}

int main()
{
	int N,M;
	cin >> N >> M;
	rep(i,M)
	{
		int a,b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	int ans = 0;
	rep(i,N)
	{
		rep(j,G[i].size())
		{
			rep(k,N)
			{
				visit[k] = false;
			}
			//cout << i << " " << G[i][j] << "  ";
			dfs(0,i,G[i][j]);
			bool flag = true;
			rep(k,N)
			{
				//cout << visit[k] << " ";
				if (!visit[k]) flag = false;
			}
			//cout << endl;
			if (!flag) ans++;
		}
	}
	cout << ans/2 << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
sl = []
nmul = []
for i in range(n):
  s = int(input())
  sl.append(s)
  if s % 10 != 0:
    nmul.append(s)
ssl = sum(sl)
if ssl % 10 == 0:
  if len(nmul) != 0:
    subm = ssl - min(nmul)
    print(subm)
  else:
    print(0)
else:
  print(sum(sl))

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

  int P,Q,R; cin >> P >> Q >> R;
  int a1,a2,a3,maxi;
  
  a1 = P+Q;a2 = Q+R;a3 = P+R;
  maxi = min(a1,a2);
  maxi = min(maxi,a3);
  cout << maxi;
}





Measured memory_bytes: 256
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int h, w;
	while(cin >> h >> w) {
		vector<string> a(h);
		REP(i,h) cin >> a[i];
		map<char, int> cnt;
		REP(i,h) REP(j,w) {
			cnt[a[i][j]]++;
		}
		bool f = true;
		if(h%2 == 0 and w%2 == 0){
			for(auto&& e : cnt) {
				if(e.S%4 != 0) {
					f = false;
				}
			}
		} else if(h%2 == 0 or w%2 == 0) {
			int cc = 0;
			for(auto&& e : cnt) {
				if(e.S%4 != 0) {
					if(e.S%2 == 0) cc += e.S%4;
					else f = false;
				}
			}
			int hoge;
			if(h%2 == 0) {
				hoge = h;
			} else {
				hoge = w;
			}
			if(cc <= hoge) {
				// f = true;
			}else {
				f = false;
			}
		} else {
			// for(auto&& e : cnt) {
			// 	int cc = 0;
			// 	bool ff = true;
			// 	if(e.S%4 != 0) {
			// 		if(e.S%2 == 0 and cc < 2) {
			// 			cc++;
			// 		}else if(e.S == 1 and ff){
			// 			ff = false;
			// 		} else {
			// 			f = false;
			// 		}
			// 	}
			// }
			int cc = 0;
			int co = 0;
			for(auto&& e : cnt) {
				if(e.S%4 != 0) {
					if(e.S%2 == 0) cc += e.S%4;
					else {
						cc += e.S%4;
						co++;
					}
				}
			}
			DEBUG(co); DEBUG(cc);
			DEBUG(f);
			int hoge = h+w-1;
			if(cc <= hoge and co == 1) {
				// f = true;
			}else {
				f = false;
			}
		}
		if(f) {
			cout << "Yes" << endl;
		}else {
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
s=input()
if int(s[0:4])<2019:
    print("Heisei")
elif int(s[0:4])>2019:
    print("TBD")
else:
    if int(s[5])==1 or int(s[6])>4:
        print("TBD")
    elif int(s[6])<=4:
        print("Heisei")

Measured memory_bytes: 9092
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  a += b;
  a += c;
  if(a >= 22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 10007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0

using namespace std;

// a > b
ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}

bool prime(ll a)
{
    if(a == 2) return true;
    for(ll i = 2; i * i <= a; i++)
        if(a % i == 0) return false;
    return true;
}

set<ll> divisors;
map<ll, ll> cnt;

void set_set(ll a)
{
    for(ll i = 1; i * i <= a; i++)
        if(a % i == 0)
        {
            divisors.insert(i);
            if(i * i != a)
            {
                divisors.insert(a / i);
            }
        }
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n; cin >> n; vector<ll> vec(n, 0); for(int i = 0; i < n; i++) cin >> vec[i];
    set_set(vec[0]);
    set_set(vec[1]);
    
    for(auto cur = divisors.begin(); cur != divisors.end(); cur++)
    {
        auto number = *cur;
        for(int i = 0; i < vec.size(); i++)
        {
            if(vec[i] % number == 0)
            {
                cnt[number]++;
            }
        }
    }
    
    ll ret = -1;
    
    for(auto cur = divisors.begin(); cur != divisors.end(); cur++)
    {
        auto number = *cur;
        if(cnt[number] >= n-1)
            ret = number;
    }
    
    
    cout << ret << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cctype>
#include <stdio.h>
using namespace std;

int main(){
  int alph[26] = {};
  char x;
  int num;
  for(int i = 0 ; i < 1000 ; i++){
    cin >> x;
    if( isalpha(x) ){
      if(islower(x)) num = x -'a';
      else num = x -'A';
      alph[num] ++;
    }
    x = ' ';
  }

  for(char i = 0; i < 26 ; i++){
    printf("%c : %d\n",'a'+i,alph[i]);
  }

  return 0;
}



Measured memory_bytes: 3176
#include<iostream>
using namespace std;
int main(){
  int mat[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      int x;
      cin >> x;
      mat[i][j] = x;
    }
  }
  int N;
  cin >> N;
  int ans[9];
  for(int i=0;i<9;i++){
    ans[i]=0;
  }
  for(int k=0;k<N;k++){
    int x;
    cin >> x;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        if(mat[i][j]==x) ans[i*3+j]=1;
      }
    }
  }
  int flag=0;
  if(ans[0]==1&&ans[3]==1&&ans[6]==1) flag=1;
  else if(ans[1]==1&&ans[4]==1&&ans[7]==1) flag=1;
  else if(ans[2]==1&&ans[5]==1&&ans[8]==1) flag=1;
  else if(ans[0]==1&&ans[1]==1&&ans[2]==1) flag=1;
  else if(ans[3]==1&&ans[4]==1&&ans[5]==1) flag=1;
  else if(ans[6]==1&&ans[7]==1&&ans[8]==1) flag=1;
  else if(ans[0]==1&&ans[4]==1&&ans[8]==1) flag=1;
  else if(ans[2]==1&&ans[4]==1&&ans[6]==1) flag=1;

  if(flag==1) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 0;
    if((int)s.size() == 1){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < s.size()-1; i++){
        if (s[i] != s[i+1]) cnt++;
    }
    cout << n - 1 - max(cnt - 2*k, 0) << endl;
    return 0;
}

Measured memory_bytes: 3732
/*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします！
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/

#include <bits/stdc++.h>


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


#define inf (int)(3e18)
#define int long long
#define mod (int)(1000000007)

#define intt long long
#define P pair<int,int>

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

using namespace std;

//Library
//モッドパウ
int modpow(int x, int y, int m = mod) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
            res %= m;
        }
        x = x * x % mod;
        y /= 2;
    }
    return res;
}

int mypow(int x, int y) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
        }
        x = x * x;
        y /= 2;
    }
    return res;
}
//is the number (x) a prime number?
bool prime(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (!(x % i)) {
            return false;
        }
    }
    return true;
}


//saidai-kouyakusuu
inline int gcd(int x, int y) {
    if (!y) {
        return x;
    }
    return gcd(y, x % y);
}


//number of keta
int keta(int x) {
    int ans = 0;
    while (x) {
        x /= 10;
        ans++;
    }
    return ans;
}

//sum of keta
int ketasum(int x) {
    int ans = 0;
    while (x) {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

inline int lcm(int x, int y) {
    int ans = x / gcd(x, y) * y;
    return ans;
}
int twobeki(int x) {
    int ans = 0;
    while (1) {
        if (!(x & 1)) {
            ans++;
            x /= 2;
        }
        else {
            break;
        }
    }
    return ans;
}


template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
    if (lhs < rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
    if (lhs > rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
void Yes(){
    cout<<"Yes"<<endl;
}
void No(){
    cout<<"No"<<endl;
}
void YES(){
    cout<<"YES"<<endl;
}
void NO(){
    cout<<"NO"<<endl;
}


#define fin(i) scanf("%lld",&i)
#define fout(i) printf("%lld",i)
#define fendl printf("\n")
//Library-End

int n,m,ans;
signed main() {
    cin>>n>>m;
    ans=1;
    if (abs(n-m)>1) {
        cout<<0<<endl;
        return 0;
    }
    if (n==m) {
        REP(i,n){
            ans*=i;
            ans%=mod;
        }
        REP(i,m){
            ans*=i;
            ans%=mod;
        }
        ans*=2;
        ans%=mod;
        cout<<ans<<endl;
    }else{
        REP(i,n){
            ans*=i;
            ans%=mod;
        }
        REP(i,m){
            ans*=i;
            ans%=mod;
        }
        cout<<ans<<endl;
    }
}


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

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
//}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int mod = 1e9+7;
struct mint { //逆元などを使いたければmint2{{{
  int x;
  mint(int x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
ostream& operator<<(ostream& os, const mint& a){
  os << a.x;
  return os;
} //}}}

int solve(){
  int n;cin>>n;
  string s;cin>>s;

  mint ans = 1;
  vi cntz(2*n);
  int r = 1;
  vector<int> right(2*n);
  right[0] = 1;
  rep(i, 1, 2*n){
    int t = 0;
    if (s[i]=='W') t++;
    t += r;
    t += 1;  // 自分

    dump(i, t);
    if (t%2==1){ // hidariにつなぎにいく
      dump(i, "right");
      r++;
      right[i] = 1;
    }
    else{  // migiをまつ
      dump(i, "left");
      ans *= r;
      r--;
    }
  }
  dump(r);
  if (r>0){
    cout << 0 << endl;
    return 0;
  }

  dump(right);
  dump(ans);
  rep(i, 1, n+1) ans *= i;
  cout << ans << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 3732
<?php
while(fscanf(STDIN, "%d", $n)){
    $ans = 0;

    for($i = 0; $i < 10000; $i++){
        $i_str = (string)$i;
        $sum = 0;

        for($j = 0; $j < strlen($i_str); $j++){
            $sum += (int)$i_str[$j];
        }
        if($sum == $n){
            $ans++;
        }
    }

    echo $ans . "\n";
}

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

using namespace std;

const int MOD = 1e9 + 7;

long long fact[2000005];

long long my_pow(long long a, int lv) {
	if (lv == 0) return 1LL;
	long long tmp = my_pow(a, lv / 2);
	tmp = (tmp * tmp) % MOD;
	if (lv & 1) tmp = (tmp * a) % MOD;
	return tmp;
}

long long ncr(long long a, long long b) {
	long long cool = (fact[a] * my_pow(fact[b], MOD - 2)) % MOD;
	cool = (cool * my_pow(fact[a - b], MOD - 2)) % MOD;
	return cool;
}

int main() {
	int x, y;
	scanf("%d%d", &x, &y);
	
	if (x > y) swap(x, y);
	
	int extra = y - x;
	int base = x - extra;
	
	if (base % 3 != 0 || base < 0) return 0 * printf("0\n");
	
	int tot = extra + base * 2 / 3;
	int pick = base / 3;
	
	fact[0] = 1LL;
	for (int i = 1; i <= tot; i++) fact[i] = (fact[i - 1] * i) % MOD;
	
	printf("%lld\n", ncr(tot, pick));
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<long long> L(N);
    REP(i,N) cin >> L[i];
    sort(L.begin(),L.end());

    long long ans=0;
    for(int i=N-1;i>0;i--){
        for(int j=i-1;j>0;j--){
            int limit = upper_bound(L.begin(),L.end(), L[i]-L[j])-L.begin();
            ans += max(j-limit,0);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
    
    ll n,x;
    cin >> n >> x;

    ll ans = 1;
    ll m = 0;
    rep(i,0,n){
	ll l;
	cin >> l;
	m += l;
	if(m <= x)ans++;
	    
    }
    P(ans);

    
    return  0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var str = IO.GetIntList();
            var ans = 0;
            var num = 1;
            while (num < str[1])
            {
                num += str[0] - 1;
                ans += 1;
            }

            Console.WriteLine(ans);
        }
    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    /*
    int a[n];
    std::vector<int> v;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        a[i] = tmp;
    }
    */

    int ans = n / 200;
    ans = 10 - ans;
    //cout << "Yes" << endl;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int a, b, k;
   cin >> a >> b >> k;
   int cnt = 0;
   for (int i = min(a, b); i > 0; i--) {
      if (a % i == 0 && b % i == 0) {
         cnt++;
      }
      if (cnt == k) {
         cout << i << endl;
         return 0;
      }
   }
   return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  
  int count=0;
  bool flg = true;
  while(1){    
  	for(int i=0;i<A.size();i++){
      if(A.at(i)%2!=0){
        flg=false;
        break;
      }
      A.at(i) /= 2;
    }
    if(flg==false)break;
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, A;
  cin >> N >> A;
  int new_N;
  new_N = N % 500;
  
  if (new_N <=A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

using namespace std;

ll n, MOD=1e9L+7;
ll dp[1000000][2][2];

ll util(ll i, ll j, ll k){
    if(i>=n){
        if(j && k) return 1;
        else return 0;
    }
    if(dp[i][j][k]!=-1) return dp[i][j][k];
    ll ans=0;
    for(ll dig=0; dig<=9; dig++)
        ans=(ans+util(i+1, j|(dig==0), k|(dig==9)))%MOD;
    return dp[i][j][k]=ans;
}

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

    cin >> n;
    memset(dp, -1, sizeof(dp));
    cout << util(0, 0, 0) << endl;

	return 0;
}


Measured memory_bytes: 97320
from collections import deque
n,m=map(int,input().split())
l=[[0] for _ in range(n+1)]
vi=[0 for _ in range(n+1)]

for i in range (m):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)
st=deque([1])
f=set([1])


while st:
  x=st.popleft()
  for k in l[x]:
    if k not in f:
      st.append(k)
      f.add(k)
      vi[k]=x   
  
print("Yes")
for m in vi[2:]:
  print(m)
  
  


Measured memory_bytes: 42036
#include <bits/stdc++.h>
#define ll long long
#define arena ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main() 
{
    arena
    ll n;
    cin>>n;
    vector<ll> p;
    vector<ll> q;
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        p.push_back(x);
    }
    
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        q.push_back(x);
    }
    
    vector<ll> o1;
    vector<ll> o2;
    for(ll i=1;i<=n;i++)
    {
        o1.push_back(i);
        o2.push_back(i);
    }
    
    ll cnt1=1,cnt2=1;
    while(true)
    {
        if(o1==p)
        break;
        bool val=next_permutation(o1.begin(),o1.end());
        cnt1++;
    }
    
    while(true)
    {
        if(o2==q)
        break;
        bool val=next_permutation(o2.begin(),o2.end());
        cnt2++;
    }
    
    cout<<abs(cnt1-cnt2);
}

Measured memory_bytes: 256
def findProductSum(A, n): 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
    array_sum_square = array_sum * array_sum 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
    return (array_sum_square - 
            individual_square_sum) //2
n=int(input())
M=1000000007
lst=list(map(int,input().split()))
x=findProductSum(lst,n)
print(x%M)

Measured memory_bytes: 31604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int ans = 0;
	vector<int> a(3);
	cin >> a.at(0) >> a.at(1) >> a.at(2);

	sort(a.begin(), a.end());
	cout << a.at(2) - a.at(0) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int a = scn.nextInt();
		int b = scn.nextInt();
      	int c = scn.nextInt();
      	int count5 = 0;
      	int count7 = 0;
      	if(a==5) count5++;
      	if(a==7) count7++;
      	if(b==5) count5++;
      	if(b==7) count7++;
      	if(c==5) count5++;
      	if(c==7) count7++;
      	String ans = "NO";
      	if(count5==2 && count7==1) ans = "YES";
      	System.out.println(ans);
	}
}

Measured memory_bytes: 35580
import numpy as np
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]

ans = []
for i in range(N):
    for j in range(N):
        ans.append(np.sqrt((X[i][0]-X[j][0])**2 + (X[i][1]-X[j][1])**2))

print(sum(ans) / N)

Measured memory_bytes: 12476
#include <bits/stdc++.h>
#include <algorithm>
#include <limits>
#include <cmath> 
using namespace std;

int main(){
    string s,t;
    cin>>s>>t;

    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main() {
    int x;
    cin >> x;
    int uresisa;
    uresisa = (x / 500) * 1000;
    x %= 500;
    uresisa += (x / 5) * 5;

    cout << uresisa << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<unordered_map>
#include<cmath>
using namespace std;
int main()
{
    long long int n,ans,x,y;
    double temp=0.0;
    cin>>n;
    temp=sqrt(n);
    temp=(int)temp;
    if(temp*temp!=n)
    {
        int start = temp;
        while(start>0)
        {
            if(n%start==0)
            {
                x=start;
                y=n/start;
                break;
            }
            start--;
        }
    }
    else
    {
        x=temp;
        y=temp;
    }
    ans=x+y-2;
    cout<<ans<<endl;
    return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

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

using i64=int64_t;

vector<i64> fact;
void init_fact(i64 n,i64 m){
	fact.resize(n+1);
	fact[0]=fact[1]=1;
	for(i64 i=2; i<=n; ++i) fact[i]=(i*fact[i-1])%m;
}

i64 extgcd(i64 a,i64 b,i64 &x,i64 &y){
	i64 d=a;
	if(b!=0){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	} else {
		x=1; y=0;
	}
	return d;
}

i64 mod_inverse(i64 a,i64 m){
	i64 x,y;
	if(extgcd(a,m,x,y)==1) return (x+m)%m;
	return 0;
}

i64 rep_pow(i64 x,int64_t y,i64 mod){
	i64 res(1);
	while(y>0){
		if(y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}

vector<vector<i64>> comb;
void init_mod_comb(int n,int k,i64 mod){
	comb.resize(n+1);
	for(int i=0; i<=n; ++i){
		comb[i].resize(min(i+1,k+1));
		comb[i][0]=1;
		if(i<=k) comb[i][i]=1;
	}
	for(int i=1; i<=n; ++i){
		for(int j=1; j<=min(i-1,k); ++j){
			comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])%mod;
		}
	}
}

void solve(){
	i64 mod=1000000007;
	init_mod_comb(1001,1001,mod);
	init_fact(1001*1001,mod);

	unordered_map<i64,i64> inv_table;
	auto inv=[&](i64 x){
		if(inv_table.find(x)!=inv_table.end()) return inv_table[x];
		return inv_table[x]=mod_inverse(x,mod);
	};

    i64 N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    static i64 dp[1024][1024];
    fill_n((i64*)dp,1024*1024,0);
    dp[A][0]=1;
    rep(i,C,D+1){
        if(A*i>N) break;
        dp[A][A*i]=comb[N][A*i]*fact[A*i]%mod*inv(fact[i]*rep_pow(fact[A],i,mod)%mod)%mod;
    }

	rep(i,A,B){
		rep(j,0,N+1){
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			rep(k,C,D+1){
				if(j+(i+1)*k>N) break;
				dp[i+1][j+(i+1)*k]=(dp[i+1][j+(i+1)*k]+dp[i][j]*comb[N-j][(i+1)*k]%mod*fact[(i+1)*k]%mod*inv(fact[k]*rep_pow(fact[i+1],k,mod)%mod)%mod)%mod;
			}
		}
	}

	cout << dp[B][N] << endl;
}

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


Measured memory_bytes: 20480
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        List<Integer> tmp = (ArrayList) list.clone();
        Collections.sort(tmp, Collections.reverseOrder());
        for (int i = 0; i < n; i++) {
            int answer = tmp.get(0);
            if (tmp.get(0) == list.get(i)) {
                answer = tmp.get(1);
            }
            System.out.println(answer);
        }
    }
}

Measured memory_bytes: 94268
#include <bits/stdc++.h>
using namespace std;
  
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
  
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
  
typedef long long int ll;
  
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =5*100001;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}

int32_t main()
{
    

  
    IOS
	ll a,b;
	cin>>a>>b;
	if(a<=9&&b<=9)
	{
		cout<<a*b;
	}
	else
		cout<<-1;
	
	
}
  
           
         
       


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>

int main()
{
	char s[100005];
	int *arr, i, n, checkidx = -1, tmp = 0, tmp2 = 0, tmp3;

	fgets(s, 100005, stdin);

	n = strlen(s) - 1;

	s[n] = 'A';

	arr = (int*)calloc(n, sizeof(int));

	for (i = 0; i < n; i++)
	{
		if (s[i] == 'R')
		{
			while (s[i] == s[i + 1])
			{
				tmp++;

				i++;
			}

			tmp++;

			checkidx = i;
		}
		else
		{
			while (s[i] == s[i + 1])
			{
				tmp2++;

				i++;
			}

			tmp2++;

			if ((tmp + tmp2) % 2 == 0)
			{
				arr[checkidx] = (tmp + tmp2) / 2;
				arr[checkidx + 1] = arr[checkidx];
			}
			else
			{
				if (tmp > tmp2)
				{
					arr[checkidx] = ((tmp + tmp2 - 1) / 2) + 1;
					arr[checkidx + 1] = arr[checkidx] - 1;

					if ((tmp - 1) % 2 == 1)
					{
						tmp3 = arr[checkidx];
						arr[checkidx] = arr[checkidx + 1];
						arr[checkidx + 1] = tmp3;
					}
				}
				else
				{
					arr[checkidx + 1] = ((tmp + tmp2 - 1) / 2) + 1;
					arr[checkidx] = arr[checkidx + 1] - 1;

					if ((tmp2 - 1) % 2 == 1)
					{
						tmp3 = arr[checkidx];
						arr[checkidx] = arr[checkidx + 1];
						arr[checkidx + 1] = tmp3;
					}
				}
			}

			tmp = 0;
			tmp2 = 0;
		}
	}

	for (i = 0; i < n; i++)
		printf("%d ", arr[i]);

	printf("\n");

	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

vector<vector<pair<int, P>>> num(90000, vector<pair<int, P>>(0));

ll func(int i, int j){
  if(j == 0) return 0;
  ll y1 = num.at(i).at(j-1).second.first;
  ll x1 = num.at(i).at(j-1).second.second;
  ll y2 = num.at(i).at(j).second.first;
  ll x2 = num.at(i).at(j).second.second;
  return abs(y2 - y1) + abs(x2 - x1);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll H, W, D;
  cin >> H >> W >> D;
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W ; j++){
      ll A;
      cin >> A;
      A--;
      num.at(A%D).push_back(make_pair(A, P(i, j)));
    }
  }
  for(int i = 0; i < D; i++){
    sort(ALL(num.at(i)));
  }
  vvll sum(D, vll(1, 0));
  for(int i = 0; i < D; i++){
    for(int j = 0; j < num.at(i).size(); j++){
      sum.at(i).push_back(sum.at(i).at(j) + func(i, j));
    }
  }
  ll Q;
  cin >> Q;
  vll ans(0);
  for(int i = 0; i < Q; i++){
    ll L, R;
    cin >> L >> R;
    L--; R--;
    ans.push_back(sum.at(L%D).at(R/D+1) - sum.at(L%D).at(L/D+1));
  }
  for(int i; i < ans.size(); i++) cout << ans.at(i) << "\n";
}

Measured memory_bytes: 11256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
   ll a[n];
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
   }
   ll c=0,ans=0;
   for(int i=0;i<n-1;i++)
   {
       if(a[i+1]>a[i])
       {
           ans= max(ans,c);
           c=0;
       }
       else
        c++;
   }
   ans= max(ans,c);
   cout<<ans;
}


Measured memory_bytes: 4340
#include <iostream>
#include <vector>
#include <memory>

using namespace std;

struct Node{
	int id;
	int depth;

	string state;

	shared_ptr<Node> parent;
	vector<shared_ptr<Node>> children;

	Node():
		id(-1),
		state("root")
	{}

	Node(int id):
		id(id),
		state("root"),
		depth(0)
	{
		parent = shared_ptr<Node>(new Node());
	}

	void print() const{
		cout <<  "node "+ to_string(id) +": parent = "+ to_string(parent->id)+", depth = "+ to_string(depth) +", "+state+", [";
		if( children.size() != 0){
			for(int i=0;i < children.size()-1;i++){
				cout << to_string(children[i]->id) +", ";
			}
			cout<< to_string(children[children.size()-1]->id)<<"]\n";
		}else{
			cout<<"]\n";
		}
	}

};

shared_ptr<Node> make_node(int id){
	return shared_ptr<Node>(new Node(id));
}

void deep(int pos,shared_ptr<Node> node){
	node->depth = pos;
	if(node->children.size() == 0) return;
	for(auto c:node->children){
		deep(pos+1,c);
	}
}

int main(){

  int n, id, k, c;
  cin>>n;
	vector<shared_ptr<Node>> nodes(n);

  for(int i=0;i<n;i++){
  	cin >> id >> k;
		if(nodes[id] == nullptr){
			nodes[id] = make_node(id);
		}
		if(k == 0){
			nodes[id]->state = "leaf";
		}else{
			nodes[id]->state = "internal node";
  	  for(int j=0;j<k;j++){
				cin >> c;
				if(nodes[c] == nullptr){
					nodes[c] = make_node(c);
				}
				nodes[c]->parent = nodes[id];
				nodes[id]->children.push_back( nodes[c] );
			}
		}
  }

	shared_ptr<Node> root;
	for(int i=0;i<n;i++){
		if(nodes[i]->parent->id == -1){
			root = nodes[i];
			break;
		}
	}
	root->state = "root";
	deep(0,root);

	for(int i = 0; i< n;i++){
		nodes[i]->print();
	}
  return 0;
}

Measured memory_bytes: 21000
<?php 
 list($n, $m) = explode(" ", trim(fgets(STDIN)));
 $ac = array_fill(1, $n, 0);
 $wa = array_fill(1, $n, 0);
 for($i = 0; $i < $m; $i++){
   $temp = explode(" ", trim(fgets(STDIN)));
   if($ac[$temp[0]] == 0){
     if($temp[1] == "WA"){
       $wa[$temp[0]]++;
     }else{
       $ac[$temp[0]] = 1;
     }
   }
 }
 $acCnt = 0;
 $waCnt = 0;
 for($i = 1; $i <= $n; $i++){
   $acCnt += $ac[$i];
   if($ac[$i] == 1) $waCnt += $wa[$i];
 }
 echo $acCnt." ".$waCnt;
 ?>

Measured memory_bytes: 12792
#include <stdio.h>

int main(void)
{
    double a,s;
    int i;

    while (scanf("%lf", &a) != EOF){
        s = a;
        for (i = 1 ; i < 10; i++){
            if (i % 2 != 0){
                s += a * 2;
                a *= 2;
            }else if (i % 2 == 0){
                s += a / 3;
                a /= 3;
            }
        }
        printf("%lf\n", s);
    }
    return (0);
}


Measured memory_bytes: 1976
#include <iostream>
#include <vector>
using namespace std;
bool s[31] = {0};
int main() {
  int n;
  for(int i = 1; i <= 28; ++i) {
	cin >> n;
	s[n] = 1;
  }
  for(int i = 1; i <= 30; ++i) {
	if(!s[i]) cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 3004
#include <bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int> 
#define rep(i,a,n) for(i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int i,int n,vin &a){
    rep(i,0,n){
        cin>>a.at(i);
    } 
} 

int kai(int n){
    int sum=1;
    int i;
    rep(i,1,n+1){
        sum*=(i%INF);
        sum%=INF;
    }
    return sum;
}

int mpow(int n,int m){
    n%=INF;
    int ans = 1;
    while(m != 0){
        if(m&1) ans = ans*n % INF;
        n = n*n % INF;
        m = m >> 1;
    }
    return ans;
}

int comb(int n,int m){
    int nkai=kai(n)%INF;
    int naka=(kai(m)*kai(n-m))%INF;
    int soto=mpow(naka,INF-2);
    //cout<<nkai<<" "<<km2<<" "<<last<<endl;
    return nkai*soto%INF;
}

signed main() {
    int i;
    int X,Y;
    cin>>X>>Y;
    int a,b;
    if(2*X-Y<0 || 2*Y-X<0){
        cout<<0<<endl;
        return 0;
    }
    if((2*Y-X)%3!=0 || (2*X-Y)%3!=0){
        cout<<0<<endl;
        return 0;
    }
    a=(2*Y-X)/3;
    b=(2*X-Y)/3;
    cout<<comb(a+b,min(a,b))<<endl;
    //cout<<a<<" "<<b<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define INF MAX/2
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i,n) for (int (i)=0; (i) < (n); ++i)
#define FOR(i,a,b) for (int (i)=(a); (i) < (b); ++i)
using namespace std;

int pow(int x, int n) {int res=1; while(n){if(n&1)res*=x;x*=x;n>>=1;} return res;}
int get_gcd(int a, int b) {while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b) {return a * b / get_gcd(a, b);}
bool chmin(int &a, int b) {if(a>b){a=b; return true;} else return false;}
bool chmax(int &a, int b) {if(a<b){a=b; return true;} else return false;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//-------------------------テンプレここまで-------------------------//

bool done[301][301][301];
double memo[301][301][301];
int N;
// 残り寿司が1,2,3個である皿の個数がそれぞれ
// i,j,k (1-based index)枚である状態からすべてなくなるまでの操作回数の期待値
double solve(int i, int j, int k) {
  if(done[i][j][k]) return memo[i][j][k];

  //期待値Eは次を満たす。
  // E =  i/N * (solve(i-1,j,k) + 1)
  //    + j/N * (solve(i+1,j-1,k) + 1)
  //    + k/N * (solve(i,j+1,k-1) + 1)
  //    + (N-i-j-k)/N * (E + 1)

  //従って整理すると、
  // E = (i*solve(i-1,j,k) + j*solve(i+1,j-1,k) + k*solve(i,j+1,k-1) + N) / (i+j+k)
  double ret = 0;
  if (i || j || k){
    if (i>0) ret += solve(i-1,    j,    k) * i;
    if (j>0) ret += solve(i+1,  j-1,    k) * j;
    if (k>0) ret += solve(  i,  j+1,  k-1) * k;
    ret = (ret + N) / (i+j+k);
  }
  
  done[i][j][k] = true;
  return memo[i][j][k] = ret;
}

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

  cin >> N;
  static int n[3]; //寿司の個数が1,2,3個 (0-based index)である皿の個数
  REP(i,N) {
    int a;
    cin >> a;
    n[a-1]++;
  }

  cout << setprecision(16) << solve(n[0],n[1],n[2]) << endl;

  return 0;
}


Measured memory_bytes: 239872
#include<iostream>

using namespace std;

int ans,n,s;

void search(int num,int sum,int st)
{
	if(num==0)
	{
		if(sum==s)
			ans++;
		return;
	}
	for(int i=st;i<10;i++)
	{
		search(num-1,sum+i,i+1);
	}
	return;
}

int main()
{
	for(;;)
	{
		cin >> n >> s;
		if(n==0 && s==0)
			break;
		ans=0;
		search(n,0,0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
N, W, H = map(int, input().split())
row, col = [0] * (H + 1), [0] * (W + 1)
for _ in range(N):
    x, y, w = map(int, input().split())
    row[max(0, y - w)] += 1
    row[min(H, y + w)] -= 1
    col[max(0, x - w)] += 1
    col[min(W, x + w)] -= 1
flag1 = flag2 = True
for i in range(H):
    row[i + 1] += row[i]
    flag1 &= row[i] > 0
if flag1:
    print("Yes")
    quit()
for i in range(W):
    col[i + 1] += col[i]
    flag2 &= col[i] > 0
if flag2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 15224