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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

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

    ll n, m;
    cin>>n>>m;
    vector<ll> v[m];
    loop(i,0,m){
        ll k;
        cin>>k;
        loop(j,0,k){
            ll x;
            cin>>x;
            v[i].pb(x);
        }
    }
    ll p[m];
    loop(i,0,m) cin>>p[i];
    ll ans = 0;
    for(ll i=0; i<(1<<n); i++){
        bool all = 1;
        for(ll j=0; j<m; j++){
            bool b=1;
            ll cnt=0;
            for(auto x: v[j]){
                ll bulb = x-1;
                if((i & (1<<bulb))){
                    cnt++;
                }
            }
            if(cnt%2 != p[j]){
                b=0;
            }
            if(b==0) all = 0;
        }
        
        if(all == 1) ans++;
    }
    print(ans);
        
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[13][13],b[13],c[13];
int main()
{
	int n,m,k,ans=1e9;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&c[i]);
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	}
	for(int i=0;i<(1<<n);i++)
	{
		int cost=0;
		for(int j=1;j<=n;j++)b[j]=0;
		for(int j=1;j<=n;j++)
			if(i&(1<<(j-1)))
			{
				cost+=c[j];
				for(int l=1;l<=m;l++)b[l]+=a[j][l];
			}
		bool flag=1;
		for(int j=1;j<=m;j++)if(b[j]<k)flag=0;
		if(flag)ans=min(ans,cost);
	}
	if(ans!=1e9)cout<<ans;
	else cout<<-1;
}

Measured memory_bytes: 3764
class csr:
    def __init__(self,N,edges):
        self.start = [0]*(N+1)
        self.elist = [0]*len(edges)
        for e in edges:
            self.start[e[0]+1] += 1
        for i in range(1,N+1):
            self.start[i] += self.start[i-1] 
        counter = self.start[:]
        for e in edges:
            self.elist[counter[e[0]]] = e[1]
            counter[e[0]] += 1

class scc_graph:
    __slots__ = ['N','edges']
    def __init__(self,N):
        self.N = N
        self.edges = []
    
    def add_edge(self,v,w):
        self.edges.append((v,w))

    def scc_ids(self):
        N = self.N
        g = csr(N,self.edges)
        now_ord = group_num = 0
        visited = []
        low = [0]*N
        order = [-1]*N
        ids = [0]*N
        parent = [-1]*N
        stack = []
        for i in range(N):
            if order[i] == -1:
                stack.append(i);stack.append(i)
                while stack:
                    v = stack.pop()
                    if order[v] == -1:
                        low[v] = order[v] = now_ord
                        now_ord += 1
                        visited.append(v)
                        for j in range(g.start[v],g.start[v+1]):
                            to = g.elist[j]
                            if order[to] == -1:
                                stack.append(to);stack.append(to)
                                parent[to] = v
                            else:
                                low[v] = min(low[v],order[to])
                    else:
                        if low[v] == order[v]:
                            while True:
                                u = visited.pop()
                                order[u] = N
                                ids[u] = group_num
                                if u == v:
                                    break
                            group_num += 1
                        if parent[v] != -1:
                            low[parent[v]] = min(low[parent[v]],low[v])
        for i,x in enumerate(ids):
            ids[i] = group_num-1-x

        return group_num,ids
    
    def scc(self):
        group_num,ids = self.scc_ids()
        groups = [[] for _ in range(group_num)]
        for i,x in enumerate(ids):
            groups[x].append(i)
        return groups
    
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N,M = map(int,readline().split())
ab = list(map(int,read().split()))
sg = scc_graph(N)

it = iter(ab)
for a,b in zip(it,it):
    sg.add_edge(a,b)

scc = sg.scc()
print(len(scc))
for group in scc:
    print(str(len(group))+' '+' '.join(map(str,group)))

Measured memory_bytes: 212900
#include<iostream>
#include<algorithm>
using namespace std;
#define INFTY 1000000001
int cnt;

void merge(int *A, int left, int mid, int right) {
    int na = mid - left;
    int nb = right - mid;
    int L[na+1], R[nb+1];
    for (int i=0; i<na; i++) {
        L[i] = A[left+i];
    }
    for (int i=0; i<nb; i++) {
        R[i] = A[mid+i];
    }
    L[na] = INFTY;
    R[nb] = INFTY;
    int i=0, j=0;
    for (int k = left; k<right; k++) {
        cnt ++;
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i = i+1;
        } else {
            A[k] = R[j];
            j = j + 1;
        }
    }
}

void mergeSort(int *A, int left, int right) {
    if (left + 1 < right) {
        int mid = (left+right)/2;
        mergeSort(A,left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main() {
    int n;
    cin >> n;
    int S[n];
    for (int i=0; i<n; i++) {
        cin >> S[i];
    }
    cnt = 0;
    mergeSort(S, 0, n);
    for (int i= 0; i<n-1; i++) {
        cout << S[i] << " ";
    }
    cout << S[n-1] << endl;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 6912
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, d = M()
ans = 0
for _ in range(n):
    x, y = M()
    if x**2 + y**2 <= d**2:
        ans += 1
print(ans)

Measured memory_bytes: 75220
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+1;
int n,a[N],l,r,t;
vector<int>p,q;
bool C(int k)
{
	p.clear(),q.clear();
	for(int i=2;i<=n;i++)
		if(a[i]<=a[i-1])
		{
			if(k==1)
				return false;
			while(!p.empty()&&p[p.size()-1]>a[i])
				p.pop_back(),q.pop_back();
			if(!p.empty()&&p[p.size()-1]==a[i])
				q[q.size()-1]++;
			else
				p.push_back(a[i]),q.push_back(1);
			while(!p.empty()&&q[q.size()-1]==k)
			{
				t=p[p.size()-1],p.pop_back(),q.pop_back();
				if(!p.empty()&&p[p.size()-1]==t-1)
					q[q.size()-1]++;
				else
					p.push_back(t-1),q.push_back(1);
			}
			if(p[0]==0)
				return false;
		}
	return true;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	l=1,r=n;
	while(l<r)
		if(C((l+r)/2))
			r=(l+r)/2;
		else
			l=(l+r)/2+1;
	cout<<l;
	return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

void solve() {
  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int t; cin >> t;
    if (s.count(t)) s.erase(t);
    else s.insert(t);
  }
  cout << s.size() << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 8236
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

struct Fish
{
    ll beauty;
    ll taste;
};

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll f(ll n) {
    if (n % 2 == 0) {
        return n /2;
    } else {
        return 3 * n + 1;
    }
}
int main()
{
    ll s;
    cin >> s;

    ll cur = s;
    vector<ll> vec;
    vec.push_back(cur);

    map<ll, ll> mp;

    for (ll i = 2; i < 1000000; i++)
    {
        cur = f(cur);
        vec.push_back(cur);
        mp[cur] += 1;
    }

    ll ans = 0;
    for (ll i = 0; i < 1000000; i++)
    {
        if (mp[vec[i]] > 1) {
            ans = vec[i];
            break;
        }
    }

    ll res = 0;
    for (ll i = 0; i < 1000000; i++)
    {
        if (vec[i] == ans && res == 1) {
            cout << (i + 1) << endl;
            return 0;
        }
        if (vec[i] == ans) {
            res += 1;
        }
    }
}


Measured memory_bytes: 10220
def cin():  return list(map(int,input().split()))

N = cin()[0]
A = cin()
S = sum(A)
INF = 10 ** 9 + 7
ans = 0
for i in range(N):
    S -= A[i]
    ans += A[i] * S
    ans %= INF
print(ans)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()%
//#define int long long

signed main(){
    string s;
    cin >> s;
    sort(ALL(s));
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
/////////////////////////////////////////////////
/////             Give me AC!!!!            /////
/////////////////////////////////////////////////
//↑これじゃ気合いが足りない！
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////             お願いしますACをくださいそうじゃないと僕泣きますお願いしますACをくださいJudge様....            /////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const int MOD = 1000000007;
const int MAX = 100000;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> P;
typedef pair<ll,ll> PLL;
ld rad(ld a) {return a * 180 / PI;}
const int dx[4] = {1, 0, -1, 0};//2次元グリッド上のx軸方向
const int dy[4] = {0, 1, 0, -1};//2次元グリッド上のy軸方向

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

vector<pair<ll, ll>> prime_factorize(ll N) {
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

//dpTable
vector<ll> dp(100,MAX);

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}

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

char upper(char c){
    if('a' <= c && c <= 'z'){
        c = c - ('a' - 'A');
    }
    return c;
}
char lower(char c){
    if('A' <= c && c <= 'Z'){
        c = c + ('a' - 'A');
    }
    return c;
}

const ll INF = 10000000000;
struct edge{ll to, cost;};

int main(){
    int a,b;
    cin >> a >> b;
    int bc = b,keta = 0;
    while (bc != 0) {
        keta++;
        bc /= 10;
    }
    int rui = a * pow(10,keta) + b;
    bool ans = false;
    for (int i = 1; i < 3000; i++) {
        if (i * i == rui) ans = true;
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3952
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,a[100111],b[100111];
int main()
{
	get1(n);for(int i=0;i<n;i++)get1(a[i]);
	memcpy(b,a,sizeof(a));sort(b,b+n);
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		int id=lower_bound(b,b+n,a[i])-b;
		if(i%2!=id%2)cnt++;
	}
	printendl(cnt>>1);
	return 0;
}

Measured memory_bytes: 1024
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        a:i64,b:i64
    }

    println!("{}", a ^ b);
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long a[] = new long[3 * N];
		for(int i = 0; i < 3 * N; i++) {
			a[i] = sc.nextLong();
		}
		
		Queue<Long> queue1 = new PriorityQueue<>();
		long sum1 = 0;
		for(int i = 0; i < N; i++) {
			queue1.add(a[i]);
			sum1 += a[i];
		}
		
		Queue<Long> queue2 = new PriorityQueue<>(new MyComparator());
		long sum2 = 0;
		for(int i = 2 * N; i < 3 * N; i++) {
			queue2.add(a[i]);
			sum2 += a[i];
		}
		
		long ans_ary[] = new long[N + 1];
		ans_ary[0] += sum1;
		ans_ary[N] -= sum2;
		for(int k = 0; k < N; k++) {
			queue1.add(a[N + k]);
			sum1 += a[N + k];
			sum1 -= queue1.poll();
			ans_ary[k + 1] += sum1;
			
			queue2.add(a[2 * N - 1 - k]);
			sum2 += a[2 * N - 1 - k];
			sum2 -= queue2.poll();
			ans_ary[N - k - 1] -= sum2;
		}
		long ans = Long.MIN_VALUE;
		for(int i = 0; i <= N; i++) {
			ans = Math.max(ans, ans_ary[i]);
		}
		System.out.println(ans);
	}
}

class MyComparator implements Comparator {
    public int compare(Object obj1, Object obj2) {
         
        long num1 = (long)obj1;
        long num2 = (long)obj2;
         
        if(num1 < num2) {
            return 1;
        } else if(num1 > num2) {
            return -1;
        } else{
            return 0;
        }
    }
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

vint pos(5);
int k;
bool check=true;

int main(){
    int d;
    cin>>d;
    if(d==25)cout<<"Christmas"<<endl;
    if(d==24)cout<<"Christmas Eve"<<endl;
    if(d==23)cout<<"Christmas Eve Eve"<<endl;
    if(d==22)cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");
//    	Scanner sc = new Scanner(file);

    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();
    	String S = sc.next();
    	sc.close();

    	if(N%2!=0) {
    		System.out.println("No");
    	} else {
    		char[] s = S.toCharArray();
    		boolean flg = true;
    		for(int i=0;i<S.length()/2;i++) {
    			if(s[i]!=s[i+S.length()/2]) {
    				flg = false;
    			}
    		}
    		if(flg) {
    			System.out.println("Yes");
    		} else {
    			System.out.println("No");
    		}
    	}


    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N=200005;
const int MOD=1e9+7;
const int Inv=500000004;
int add (int x,int y)   {x=x+y;return x>=MOD?x-MOD:x;}
int mul (int x,int y)   {return (LL)x*y%MOD;}
int dec (int x,int y)   {x=x-y;return x<0?x+MOD:x;}
int Pow (int x,int y)
{
	if (y==1) return x;
	int lalal=Pow(x,y>>1);
	lalal=mul(lalal,lalal);
	if (y&1) lalal=mul(lalal,x);
	return lalal;
}
int b,w; 
int JC[N],inv[N];
int t[N];
int h[N],g[N];
int sum[N],sum1[N];
int C (int x,int y){return mul(JC[x],mul(inv[y],inv[x-y]));}
int n;
void Init ()
{
	JC[0]=1;for (int u=1;u<=n;u++) JC[u]=mul(JC[u-1],u);
	inv[n]=Pow(JC[n],MOD-2);
	for (int u=n-1;u>=0;u--) inv[u]=mul(inv[u+1],(u+1));
	//printf("%d %d %d\n",C(0,0),JC[0],inv[0]);
	t[0]=1;for (int u=1;u<=n;u++) t[u]=mul(t[u-1],Inv);
	for (int u=b;u<n;u++)	h[u]=mul(C(u-1,b-1),t[u]);
	h[n]=mul(C(n-1,b-1),t[n-1]);
	for (int u=w;u<n;u++)	{g[u]=mul(C(u-1,w-1),t[u]);}
	g[n]=mul(C(n-1,w-1),t[n-1]);
	for (int u=1;u<=n;u++) sum[u]=add(sum[u-1],h[u]);
	for (int u=1;u<=n;u++) sum1[u]=add(sum1[u-1],g[u]);
}
int main()
{
	scanf("%d%d",&b,&w);n=b+w;
	Init();
	for (int u=1;u<=n;u++)
	{
		int ans=0;
		int tot=1;
		ans=add(ans,sum1[u-1]);
		tot=dec(tot,sum[u-1]);
		tot=dec(tot,sum1[u-1]);
		ans=add(ans,mul(tot,Inv));
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD long(1e9 + 7)
#define INF 98765431219876543
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

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

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

  for (ll i = 0; i < gcd(a, b); i++) {
    if (s[i * a / (gcd(a, b))] != t[i * b / gcd(a, b)]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << (a * b) / gcd(a, b) << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,k;cin >> a >> b >> c >> k;
    for(int i=0;i<=k;i++){
        for(int j=0;i+j<=k;j++){
            for(int l=0;i+j+l<=k;l++){
                if(a*(1<<i)<b*(1<<j)&&b*(1<<j)<c*(1<<l)){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
//#include <boost/functional/hash.hpp>
//example: unordered_set< pair<int,int>,boost::hash< std::pair<int, int> > > used;
//priority_queue< pair<int,pair<int,int> >, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int> > > > pqueue;    //cost, vertex(行き先)
using namespace std;

#define MODULE 1000000007
#define MP make_pair
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<class T, class U>
inline void chmin(T &t, U f) { if (t > f)t = f; }

template<class T, class U>
inline void chmax(T &t, U f) { if (t < f)t = f; }

template<typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val) { //usage: int dp[10][10]; Fill(dp,INF);
    std::fill((T *) array, (T *) (array + N), val);
}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9 LLの時はLLONG_MAX

/*const int MAXN = 100001;

struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};*/

//-----Template---------
bool checkString(string &s, string &checker, int pos) {
    for (int i = 0; i < checker.length(); ++i) {
        if (i + pos >= s.length())
            return false;
        if (s[i + pos] != checker[i])
            return false;
    }
    return true;
}

string s;

int main() {
    ios::sync_with_stdio(false); //cout<< fixed << setprecision(10);
    cin >> s;
    bool nexter = false;
    string nexterStr;
    bool found = false;
    unsigned long i = 0;
    vector<string> tmp;
    tmp.push_back("dream");
    tmp.push_back("erase");
    while (i < s.length()) {
        for (int j = 0; j < 2; ++j) {
            unsigned long long l = s.find(tmp[j], i);
            if (l != string::npos && l==i) {
                i = l+tmp[j].length();
                nexter = true;
                found = true;
                nexterStr = tmp[j] == "dream" ? "er" : "r";
                break;
            }
        }
        if (!found && nexter) {
            unsigned long l = s.find(nexterStr,i);
            if(l!= string::npos && l==i){
                i=l+nexterStr.length();
                found=true;
                nexter=false;
            }
        }
        if(i>=s.length() || !found){
            break;
        }
        found=false;
    }
    if(found){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

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

typedef long long ll;
const int N = 2e5 + 100;

int n, k, a, ps[N];
ll ans;
unordered_map<int, int> cnt;

int main() {
	cin >> n >> k;
	cnt[0]++;
	int now = 0;
	int add = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		now = (now + a) % k;
		add = (add + 1) % k;
		ps[i] = now;
		if (i >= k)
			cnt[(ps[i - k] + k - add) % k]--;
		ans += cnt[(now - add + k) % k];
		cnt[(now - add + k) % k]++;
	}
	cout << ans;
}


Measured memory_bytes: 9288
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    int rest = n;
    rep(i,m){
        int a;
        cin >> a;
        rest -= a;
    }
    if (rest >= 0){
        cout << rest << endl;
    }else{
        cout << -1 << endl;
    }


    
}

Measured memory_bytes: 3588
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	int a,b;
	double h,m;
	cin >> a >> b >> h >> m;
	double mang = m / 60, hang = (60*h + m) / (12 * 60);
	double angDiff = abs(mang - hang) * 2 * M_PI;
	angDiff = min(angDiff, 2 * M_PI - angDiff);
	// cout << mang << ' ' << hang << endl;
	// cout << angDiff << endl;
	double res = sqrt(a*a + b*b - 2.*a*b*cos(angDiff));
	printf("%.20lf\n", res);
}

Measured memory_bytes: 4280
#include <bits/stdc++.h>
typedef long long ll;
const int MAXN=1e6+7;
using namespace std;
int c[MAXN+5];
int main()
{
    string s,t;
    int n; cin>>n; cin>>s>>t;
    if(s[0]!=t[0]|| s.length()!=t.length()) { return 0*puts("-1"); }
    int ans=0,k=0,sum=0;
    for(int i=n-1,j=n-1;i>=0;i--)
    {
        sum+= c[i+k];
        if( j>i || t[i]!=s[j])
        {
            while( j>=0 &&( j>i|| t[i]!=s[j])) j--;
            if(j==i) continue;
            if(j<0)
            {
                return 0*puts("-1");
            }
            k++,sum++;
            c[i+k-1]=0,c[j+k-1]--;
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6024
/*==============================================*\
ID:          shahidul_brur
 
Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh
 
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = (int)2e5+5;
const int logn = 20;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int s,t;
    cin>>s>>t;
    int c = 0, cur = 1;
    while(cur<t){
        c++;
        cur+=s-1;
    }
    cout << c;
    return 0;
}


Measured memory_bytes: 256
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper

a, b = inl()
print((a-1)*(b-1))

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

int main() {
    int w,a,b;
    cin>>w>>a>>b;

    if(abs(b-a)<=w){
        cout<<0<<endl;
    }
    else {
        cout<<abs(b-a)-w<<endl;;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<complex>
#include<cmath>
using namespace std;
typedef complex<double>P;
main(){
  P o,p,q;
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",
	      &o.real(),&o.imag(),&p.real(),&p.imag(),&q.real(),&q.imag())==6){
    P N(p.real()-o.real(),p.imag()-o.imag());
    P L(q.real()-o.real(),q.imag()-o.imag());
    double t=abs(L);
    L/=abs(L);
    N/=abs(N);
    double d=2*(N.real()*L.real()+N.imag()*L.imag());
    P R(d*N-L);
    printf("%.8lf %.8lf\n",o.real()+t*R.real(),o.imag()+t*R.imag());
  }
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int,input().rstrip().split(" ")))
b1 = []
b2 = []
ans = []
if n % 2 == 0:
    for i in range(n):
        if i % 2 == 0:
            b1.append(a[i])
        else:
            b2.append(a[i])
    b2.reverse()
    ans = b2 + b1
    print(" ".join(str(i) for i in ans))
else:
    for i in range(n):
        if i % 2 == 0:
            b1.append(a[i])
        else:
            b2.append(a[i])
    b1.reverse()
    ans = b1 + b2
    print(" ".join(str(i) for i in ans))

Measured memory_bytes: 37016
#include <iostream>
#include <algorithm>
#include <cmath>

int n, v[105];
long long m;
long long w[105];
long long dp[105][100005];
int main() {
	std::cin >> n >> m;
	for (int i = 0; i < n; ++i)
		std::cin >> w[i] >> v[i];

	std::fill(dp[0], dp[0] + 100005, 9999999999999);

	dp[0][0] = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < 100005; ++j) {
			if (j < v[i])
				dp[i + 1][j] = dp[i][j];
			else
				dp[i + 1][j] = std::min(dp[i][j], dp[i][j - v[i]] + w[i]);
		}

	int ans = 0;
	for (int i = 0; i < 100005; ++i)
		if (dp[n][i] <= m)
			ans = std::max(ans, i);

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

	return 0;
}


Measured memory_bytes: 80128
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a>b){
    swap(a, b);
  }
  if(a == 1){
    if(b == 2) cout << 3;
    else cout << 2;
  }else if(a==2) cout << 1;
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

ll mygcd(ll a, ll b)
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return mygcd(b, a % b);
    }
}

signed main()
{
    int n;
    cin >> n;
    vector<ll> as;
    rep(i, n)
    {
        ll a;
        cin >> a;
        as.push_back(a);
    }
    int ans = as[0];
    rep(i, n)
    {
        ans = mygcd(ans, as[i]);
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define ALL(x) begin(x), end(x)

typedef long long ll;
typedef pair<int, int> ipair;

//const int INF = (int)1.1e9;

int main() {
    #ifndef MY
    // freopen("cards.in", "r", stdin);
    // freopen("cards.out", "w", stdout);
    cin.tie(0);
    #endif
    ios_base::sync_with_stdio(0);

    string s;
    cin >> s;
    cout << s.substr(0, 4) + " " + s.substr(4) << "\n";
}


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

typedef long long ll;

int main(){
    ll x;
    cin >> x;
    ll now = 100;
    for(int i = 0;; i++){
        now = (ll)((double)(now) * 1.01);
        if(now >= x){
            cout << i+1 << endl;
            return 0;
        }
    }    
}

Measured memory_bytes: 3592
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
constexpr int INF = std::numeric_limits<int>::max() / 2;  // 1.073741823e9
constexpr int64 INF64 = std::numeric_limits<int64>::max() / 2;  // 4.611686018427387903e18
constexpr int MOD = 1000000007;

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, m; cin >> n >> m;
  multiset<int> ms;
  rep(i, n) {
    int a; cin >> a;
    ms.insert(a);
  }
 
  rep(i, m) {
    auto it = ms.end();
    --it;
    int x = *it;
    x >>= 1;
    ms.erase(it);
    ms.insert(x);
  }
 
  int64 ans = 0;
 
  while (!ms.empty()) {
    auto it = ms.end();
    --it;
    int x = *it;
    ans += static_cast<int64>(x);
    ms.erase(it);
  }
 
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>

int main(void){
    char x[1003];
    int sum,i;

    while(1){
        scanf("%s",x);
        if(x[0] ==  '0' && x[1] == '\0')
            break;
        sum = 0;i = 0;
        while(x[i] != '\0')
            sum += x[i++] - '0';
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
using namespace std;
typedef signed long long lint;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int x, y;
  cin >> x >> y;
  for (int k=0; k<=100; ++k) {
    for (int t=0; t<=100; ++t) {
      if (k+t==x && k*4+t*2==y) {
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef long int li;

int main()
{
    IOS;
    //freopen("fr1.txt","r",stdin);
    int a,b,c;
    cin>>a>>b;
    int sum=a+b;
    cout<<6-sum<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
typedef pair<int,int> P;

int dist[1005][1005];
int dxdy[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int main(){
    int h,w;
    cin >> h >> w;
    queue<P> que;
    rp(i,h){
        rp(j,w){
            char a;
            cin >> a;
            if(a=='#'){
                dist[j][i]=1;
                que.push(make_pair(j,i));
            }
        }
    }
    int max=1;
    while(!que.empty()){
        int x = que.front().first;
        int y = que.front().second;
        for(auto d:dxdy){
            if(x+d[0]<0||x+d[0]>=w||y+d[1]<0||y+d[1]>=h)
            continue;
            if(dist[x+d[0]][y+d[1]]==0){
                dist[x+d[0]][y+d[1]]=dist[x][y]+1;
                if(dist[x+d[0]][y+d[1]]>max)
                max=dist[x+d[0]][y+d[1]];
                que.push(make_pair(x+d[0],y+d[1]));
            }
        }
        que.pop();
    }
    cout << max-1 << endl;
    return 0;
}

Measured memory_bytes: 12304
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
//template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  vector<vector<int>> d(a,vector<int>(b));
  fo(i,a){
    fo(j,b)
      cin>>d[i][j];
  }
  int e;
  cin>>e;
  vector<pair<int,int>> f(e);
  fo(i,e)
    cin>>f[i].fi>>f[i].se;
  V<int> g(a*b,0);
  V<P<int,int>> z(a*b);
  int x=0,y=0;
  int x1,x2,y2,y1;
  fo(i,a){
    fo(j,b)
      z[d[i][j]-1].fi=i,z[d[i][j]-1].se=j;
  }
  for(int i=c;i<a*b;i++){
    g[i]=g[i-c]+abs(z[i-c].fi-z[i].fi)+abs(z[i-c].se-z[i].se);
  }
  fo(i,e){
    if(f[i].se==f[i].fi)
      cout<<0<<endl;
    else{
      cout<<g[f[i].se-1]-g[f[i].fi-1]<<endl;
    }
  }
}


Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n) { //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}

ll comb(ll a, ll b) { //aCbをmod計算
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
int main() {
  fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
	ll n, m, i, ans = 1,cm,count;
	cin >> n >> m;
	cm = m;
	for (i = 2; i*i <= m; i++) {
		count = 0;
		while (cm%i == 0) {
			count++;
			cm /= i;
		}
		ans = ans * comb(n - 1 + count, count)%M;
	}
	if (cm !=1)
		ans =ans*n%M;
	cout << ans << endl;
}

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

int n,m;

int main(){

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

    cin>>n>>m;
    for(int i=1,l=m;l>=1;l-=2,i++){
        cout<<i<<' '<<i+l<<endl;
    }
    for(int i=m+2,l=m-1;l>=1;l-=2,i++){
        cout<<i<<' '<<i+l<<endl;
    }

    return 0;
}

Measured memory_bytes: 3652