akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=2e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
#define x first
#define y second
int x[N],y[N];
vector<int>e[N];
struct P{ int x,y,id; }p[N];
int f[N],sum[N],w[N];
bool vis[N];
LL ans;
inline bool cmp(const P &a,const P &b) { return a.x==b.x?a.y<b.y:a.x<b.x; }
inline void link(int a,int b) { e[a].push_back(b); e[b].push_back(a); }
inline void solve(int n,int dx,int dy) {
	int i,l,r,L,R,t;
	for (i=1;i<=n;i++) p[i]=(P){x[i],y[i],i};
	sort(p+1,p+1+n,cmp);
	for (i=1;i<=n;i++) sum[i]=f[i]=0;
	for (i=1,l=1,r=0;i<=n;i++) {
		while (p[i].x-p[l].x>dx) l++;
		while (p[i].x-p[r+1].x>=dx) r++;
		if (l>r) continue;
		for (L=l-1,t=1<<17;t;t>>=1) if (L+t<=r&&p[L+t].y<p[i].y-dy) L+=t;
		for (R=l-1,t=1<<17;t;t>>=1) if (R+t<=r&&p[R+t].y<=p[i].y+dy) R+=t;
		if (L>=R) continue;
		sum[R]++,sum[L]--,f[R]++,f[L+1]--;
		link(p[i].id,p[R].id);
	}
	for (i=n;i;i--) {
		sum[i]+=sum[i+1];
		w[p[i].id]+=sum[i];
		if (f[i]+=f[i+1])
			link(p[i-1].id,p[i].id);
	}
}
inline void dfs(int k) {
	if (vis[k]) return;
	vis[k]=true;ans+=w[k];
	for (auto t:e[k]) dfs(t);
}
int main()
{
	int n=gi(),i,a=gi(),b=gi(),d;
	for (i=1;i<=n;i++)
		x[i]=gi(),y[i]=gi(),x[i]+=y[i],y[i]=x[i]-y[i]-y[i];
	d=max(abs(x[a]-x[b]),abs(y[a]-y[b]));
	solve(n,d,d);
	for (i=1;i<=n;i++) swap(x[i],y[i]);
	solve(n,d,d-1);
	dfs(a);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 17920
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long int n, ans=0;
    cin >> n;cin.ignore();
    string s;
    string a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> s;
        sort(s.begin(), s.end());
        a[i]=s;
    }
    sort(a, a+n);
    for(int i = 0; i < n; i++)
    {
        s=a[i];
        int j=i+1;
        long long int nb;
        while(j < n && a[j]==a[i])
            j++;
        nb=j-i;
        i=j-1;
        ans+=(((nb-1)*nb)/2);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 6272
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>

//#define int long long

using namespace std;

void Main()
{
	int N;
	cin >> N;
	vector<int> H(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}

	string ans = "Yes";
	for (int i = N - 2; i >= 0; i--) {
		if (H[i + 1] >= H[i]) {
			//NOP
		}
		else if (H[i + 1] == H[i] - 1) {
			H[i]--;
		}
		else {
			ans = "No";
			break;
		}
	}

	cout << ans << endl;
}
 
int32_t main()
{
	Main();
	return 0;
}



Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int count = 0;
    String S,SS;
    SS = sc.next();
    //System.out.println(SS);
    while(true){
      S = sc.next();
      if(S.equals("END_OF_TEXT")){
        break;
      }else{
        if(S.equalsIgnoreCase(SS)){
          count++;
        }
      } 
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 26164
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);

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

    int c = 0, p;
    for (int i = 0; i < n; i++) {
        cin >> p;
        if (p != i + 1) {
            c++;
        }
    }

    if (c <= 2) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pii pair<ll,ll>
#define vec vector<ll>
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repd(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define M 1000000007

using namespace std;


int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll s,w; cin>>s>>w;
	if(w>=s)cout<<"unsafe";
	else cout<<"safe";
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 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;}

int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) 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;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
  int n,p; cin >> n >> p;
  mod = p;
  string s; cin >> s;
  if(p==2){
    ll ans = 0;
    FOR(i,0,s.length()-1){
      int a = (int)s[i] - '0';
      if(a%2==0) ans += i+1;
    }
    cout << ans << "\n";
    return 0;
  }
  if(p==5){
    ll ans = 0;
    FOR(i,0,s.length()-1){
      int a = (int)s[i] - '0';
      if(a%5==0) ans += i+1;
    }
    cout << ans << "\n";
    return 0;
  }
  string copy = s;
  reverse(copy.begin(),copy.end());
  s = copy;
  mint mp[n+1];
  map<int,ll> m;
  mp[0] = 0;
  ++m[0];
  mint ten = 1;
  ten /= 10;
  FOR(i,1,s.length()){
    int a = (int)s[i-1] - '0';
    ten *= 10;
    // cout << ten.x << endl;
    mp[i] = ten * a + mp[i-1];
    ++m[mp[i].x];
    // cout << ten.x << " " << mp[i].x << "\n";
  }
  ll ans = 0;
  for(auto x: m){
    ans += x.second * (x.second-1) / 2;
  }
  cout << ans << "\n";


}


Measured memory_bytes: 2752
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string s; cin >> s;
    int ans = 0, cur = 0;
    for (auto c : s) {
        if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
            cur++;
        } else {
            ans = max(ans, cur);
            cur = 0;
        }
    }
    ans = max(ans, cur);
    cout << ans << endl;
    return 0;
}

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

int main()
{
        int n; cin>>n;
        int c=0;
        rep(i,n){
                string s; cin>>s;
                if(s=="A") c++;
                else c--;
                if(c<0){
                        cout<<"NO"<<endl;
                        goto g;
                }
        }
        if(c==0) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
g:;
}

Measured memory_bytes: 3160
#include <stdio.h>
#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

#define SIZE 500

struct action{
	int y,x,y2,x2;
};

int coin[SIZE][SIZE]{};
vector<action> actions;

int h,w;

int main() {
	cin >> h >> w;
	int ki = 0;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cin >> coin[i][j];
			ki += (coin[i][j]%2==1)?1:0;
		}
	}
	ki = (ki/2)*2;

	int x=0,y=0;
	int px,py;
	bool mode = false;
	int ki2 = 0;
	while(true) {
		if(ki==ki2) break;
		//printf("%d,%d\n",y,x);
		if(mode) {
			actions.push_back((action){py,px,y,x});
		}
		if(coin[y][x]%2==1) {
			mode = !mode;
			ki2++;
		}
		px=x;
		py=y;
		if((x==0&&y%2==1)||(x==w-1&&y%2==0)) y++;
		else x+=(y%2==0)?1:-1;
		if(y>=h) break;
	}

	printf("%d\n",actions.size());
	for(action a : actions) {
		printf("%d %d %d %d\n",a.y+1,a.x+1,a.y2+1,a.x2+1);
	}

	return 0;
}


Measured memory_bytes: 5232
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define all(v)    ((v.begin()),(v.end()))
#define sz(v)     ((int)(v.size()))
#define forv(i, v) for(int i = 0; i < sz(v); ++i)
#define forn(i,n)   for(int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector< vi >    vii;
typedef vector< vd >    vdd;
typedef vector<string>  vs;


int main()
{
	string a;
	vector<char>x, y;
	cin >> a;
	//cout << a;
	int q;
	scanf("%d", &q);
	int r = 1;
	while (q--) {
		int t;
		scanf("%d", &t);
		if (t == 1) r++;
		else {
			int f;
			scanf("%d", &f);
			char c;
			cin >> c;
			//cout << c;
			if (r & 1) {
				if (f == 1) x.push_back(c);
				else y.push_back(c);
			}
			else {
				if (f == 1) y.push_back(c);
				else x.push_back(c);
			}
		}
	}
	if (r & 1) {
		for (int i = x.size() - 1; i >= 0; i--) cout << x[i];
		cout << a;
		for (int i = 0; i < y.size(); i++) cout << y[i];
	}

	else {
		for (int i = y.size() - 1; i >=  0; i--) cout << y[i];
		for (int i = a.size() - 1; i >= 0; i--) cout << a[i];
		for (int i = 0; i < x.size(); i++ ) cout << x[i];
	}

	cout << "\n";
	return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-6
#define MOD 998244353ll
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;

inline void solve()
{
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes";
	else
		cout << "No";
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	while (q--)
	{
		solve();
		cout << '\n';
	}
}

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

int *check(char *str, int len, int *cnt) {
    int i, j = 0;
    int *list = (int*)malloc(len * sizeof(int));
    list[j] = 0; ++j;
    for(i = 1; i < len; ++i) {
        if(str[i-1] != str[i]) { list[j] = i; ++j; }
    }
    list[j] = i; ++j;
    *cnt = j;
    return list;
}

void solve(char *str, int len, int try) {
    int i, j, k, max = 1, tmp, cnt;
    int *list = check(str, len, &cnt);
    //for(i = 0; i < cnt; ++i) { printf("%d ", list[i]); }
    //printf("\n");
    for(i = 0; i < cnt-1; ++i) {
        j = list[i];
        if(str[j] == '0') {
            if( i + 2*try < cnt) {
                k = (list[i+2*try] < len) ? list[i+2*try] : len;
            }
            else { k = len; }
        } else {
            if( i + 2*try + 1 < cnt) {
                k = (list[i+2*try+1] < len) ? list[i+2*try+1] : len;
            }
            else { k = len; }
        }
        tmp = k - j;
        max = (max < tmp) ? tmp : max;
    }
    printf("%d\n", max);
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    char *str = (char*)malloc((n+4)*sizeof(char));
    scanf("%s", str);
    solve(str, n, k);
    return 0;
}

Measured memory_bytes: 640
//=============================================================
// Name        : a
// Date        : Mon Jun 10 10:10:23 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//=============================================================
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) {
    cin >> a[i];
  }
  int ans = 1e9;
  for (int i = 0; i < 3; ++i) {
    for (int j = i + 1; j < 3; ++j) {
      ans = min(ans, a[i] + a[j]);
    }
  }
  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
int Gets(char *buff,int buffMaxSize)
{
	buff[0]='\0';
	if (fgets(buff,buffMaxSize,stdin)==NULL){
		return -1;
	}
	size_t strLen = strlen(buff);
	if (strLen>0){
		while (buff[strLen-1] == '\r' || buff[strLen-1]=='\n'){//改行コード
			strLen--;
			buff[strLen]='\0';
		}
	}
	return (int)strLen;
}
int GetData(vector<string> &dataList,char *line,char *deli)
{
	char *p = new char[strlen(line)+1];
	strcpy(p,line);
	char* token = strtok(p, deli);
	while (token != NULL) {
		dataList.push_back(token);
		token = strtok(NULL, deli);
	}
	delete[] p;
	return 0;
}
int main(int argc, char* argv[])
{
	char s[1024];
	Gets(s,1024);
	vector<string> dataList;
	vector<string> opList;
	GetData(dataList,s,"+-");
	GetData(opList,s,"0123456789 ");

	switch(opList[0].c_str()[0]){
	case '+':
		cout<<atol(dataList[0].c_str())+atol(dataList[1].c_str())<<endl;
		break;
	case '-':
		cout<<atol(dataList[0].c_str())-atol(dataList[1].c_str())<<endl;
		break;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

E = 1e+10
p = -1
for i in range(N):
    a = T - 0.006 * H[i]
    e = abs(A - a)
    if e < E:
        E = e
        p = i

print(p+1)


Measured memory_bytes: 3060
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, M = MI()
    print(int((100*(N-M)+1900*M)/((1/2)**M)))
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
c = []
A = 0
for i in range (N):
    if V[i] - C[i] > 0:
        c.append(i)
for j in c:
    A += V[j] - C[j]
print(A)

Measured memory_bytes: 3060
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int R[] = {sc.nextInt(),sc.nextInt(),sc.nextInt()};
		sc.close();
		int max = R[0];
		int min = R[0];
		for (int i=0;i<R.length;i++) {
			max = Math.max(max,R[i]);
			min = Math.min(min,R[i]);
		}
		String ans = (R[2]!=max&&R[2]!=min)?"Yes":"No";
		System.out.print(ans+"\n");
	}
}

Measured memory_bytes: 23764
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();

        if(a*b%2==0){
		    System.out.println("Even");  
        }else{
            // 出力
		    System.out.println("Odd");
        }
	}
}

Measured memory_bytes: 35420
if __name__ == "__main__":
    N, K = map(int, input().split())
    S = input()

    res = 0
    for i in range(N-1):
        if S[i+1] == S[i]:
            res += 1

    res = min([res + 2 * K, N - 1])
    print(res)


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

const int INF = 1001001001;
const vector<int> dx = {-1, 0, 1, 0};
const vector<int> dy = {0, -1, 0, 1};

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  int ans = 0;
  rep(si, h) rep(sj, w) {
    if (s[si][sj] == '#') continue;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    queue<P> q;

    auto update = [&](int i, int j, int x) {
      if (dist[i][j] != INF) return;
      dist[i][j] = x;
      q.push(P(i, j));
    };

    update(si, sj, 0);
    while (!q.empty()) {
      int cx = q.front().first, cy = q.front().second;
      q.pop();
      rep(i, 4) {
        int nx = cx + dx[i], ny = cy + dy[i];
        if (nx < 0 || h <= nx || ny < 0 || w <= ny) continue;
        if (s[nx][ny] == '#') continue;
        update(nx, ny, dist[cx][cy] + 1);
      }
    }
    rep(i, h) rep(j, w) {
      if (dist[i][j] == INF) continue;
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DRestoringRoadNetwork solver = new DRestoringRoadNetwork();
        solver.solve(1, in, out);
        out.close();
    }

    static class DRestoringRoadNetwork {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints();
            int[][] a = in.ints(n, n);
            long ans = 0;
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    boolean r = true;
                    for (int i = 0; i < n; i++) {
                        if (a[j][k] > a[j][i] + a[i][k]) {
                            out.println(-1);
                            return;
                        } else if (i != j && i != k && a[j][k] == a[j][i] + a[i][k]) {
                            r = false;
                        }
                    }
                    if (r) {
                        ans += a[j][k];
                    }
                }
            }
            out.println(ans / 2);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

        public int[] ints(int length) {
            return IntStream.range(0, length).map(x -> ints()).toArray();
        }

        public int[][] ints(int height, int width) {
            return IntStream.range(0, height).mapToObj(x -> ints(width)).toArray(int[][]::new);
        }

    }
}



Measured memory_bytes: 37564
import java.io.*;
import java.util.*;
import java.util.stream.*;

class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		long n = saori.saorihayami();
		long k = saori.saorihayami();
		long ans = 0;
		long num = 0;
		if(n > k){
			num = n%k;
			ans = Math.min(num,Math.abs(k-num));
		} else {
			ans = Math.min(n, Math.abs(n-k));
		}

		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

typedef long long ll;

ll N;
vector<ll> A;
vector<ll> SumMaxEarly, SumMinLate;
ll R = -(1ll << 60);

int main() {
  cin >> N;
  A.resize(3 * N);
  for (ll i = 0; i < 3 * N; ++i) cin >> A[i];
  multiset<ll> max_early;
  ll sum_max_early = 0;
  for (ll i = 0; i < N; ++i) {
    max_early.insert(A[i]);
    sum_max_early += A[i];
  }
  SumMaxEarly.push_back(sum_max_early);
  for (ll i = N; i <= 2 * N - 1; ++i) {
    auto min_now = max_early.begin();
    if (*min_now < A[i]) {
      sum_max_early -= *min_now;
      max_early.erase(min_now);
      sum_max_early += A[i];
      max_early.insert(A[i]);
    }
    SumMaxEarly.push_back(sum_max_early);
  }
  multiset<ll> min_late;
  ll sum_min_late = 0;
  for (ll i = 3 * N - 1; i >= 2 * N; --i) {
    min_late.insert(A[i]);
    sum_min_late += A[i];
  }
  SumMinLate.push_back(sum_min_late);
  for (ll i = 2 * N - 1; i >= N; --i) {
    auto max_now = prev(min_late.end());
    if (A[i] < *max_now) {
      sum_min_late -= *max_now;
      min_late.erase(max_now);
      sum_min_late += A[i];
      min_late.insert(A[i]);
    }
    SumMinLate.push_back(sum_min_late);
  }
  for (ll i = 0; i <= N; ++i) {
    R = max(R, SumMaxEarly[i] - SumMinLate[N - i]);
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 14328
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin>>S;
  string ans="Yes";
  if(S.size()%2==1) {
    ans="No";
  }
  for(int i=0;i<S.size()-1;i+=2) {
    if(S.at(i)!='h'||S.at(i+1)!='i') {
      ans="No";
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include <map>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()


int main() {
	ll n, k;
	cin >> n >> k;
	int recent0 = INT_MIN;
	int a[n];
	rep(i, n) {
		cin >> a[i];
		if (i >= k) {
			if (a[i] > a[i - k]) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
	}

}

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 200005;

int t[4*MX] = { 0 };

struct Segtree {
    void build(int a[], int v, int tl, int tr) {
        if (tl == tr) {
            t[v] = a[tl];
        } else {
            int tm = (tl + tr) / 2;
            build(a, v*2, tl, tm);
            build(a, v*2+1, tm+1, tr);
            t[v] = max(t[v*2], t[v*2+1]);
        }
    }

    int get_max(int v, int tl, int tr, int l, int r) {
        if (l > r) 
            return 0;
        if (l == tl && r == tr) {
            return t[v];
        }
        int tm = (tl + tr) / 2;
        return max(get_max(v*2, tl, tm, l, min(r, tm)),
               get_max(v*2+1, tm+1, tr, max(l, tm+1), r));
    }

    void update(int v, int tl, int tr, int pos, int new_val) {
        if (tl == tr) {
            t[v] = new_val;
        } else {
            int tm = (tl + tr) / 2;
            if (pos <= tm)
                update(v*2, tl, tm, pos, new_val);
            else
                update(v*2+1, tm+1, tr, pos, new_val);
            t[v] = max(t[v*2], t[v*2+1]);
        }
    }
};

int N, A, B;
int a[MX], best[MX], ans[MX];
vector<int> tree[MX];
map<int, int> compressed;
Segtree segtree;

void dfs(int v, int p) {
    // cout << "on node: " << v << "\n";
    int before = best[a[v]];
    ans[v] = 1;
    int ext = segtree.get_max(1, 0, N - 1, 0, a[v] - 1) + 1;
    chmax(ans[v], ext);
    
    if (ans[v] > best[a[v]]) {
        segtree.update(1, 0, N - 1, a[v], ans[v]);
        best[a[v]] = ans[v];
    }
    chmax(ans[v], ans[p]);
    // cout << v << ": " << best[a[v]] << "\n";
        
    for (auto& u : tree[v]) {
        if (u != p) dfs(u, v);
    }
    
    best[a[v]] = before;
    segtree.update(1, 0, N - 1, a[v], before);
}

void solve() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    
    for (int i = 0; i < N; i++) compressed[a[i]];
    
    int pos = 0;
    for (auto& i : compressed) {
        i.second = pos++;
    }
    
    for (int i = 0; i < N; i++) a[i] = compressed[a[i]];
    
    for (int i = 0; i < N - 1; i++) {
        cin >> A >> B;
        A--; B--;
        tree[A].push_back(B);
        tree[B].push_back(A);
    }
    segtree.build(best, 1, 0 , N - 1);
    
    dfs(0, -1);
    for (int i = 0; i < N; i++) cout << ans[i] << "\n";
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 47500
import java.util.*;
import java.io.*;
class Main {

	//最大公約数・最小公倍数（セットで使う）
static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
static int lcm (int a, int b) {return a*b/gcd(a,b);}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
      	
      	String s = sc.next();
      	String t = sc.next();
      	int cnt = 0;
      	
      	for(int i=0;i<s.length();i++){
        	if(s.charAt(i) != t.charAt(i)){
            	cnt++;
          }
        }
      System.out.println(cnt);
      }
	}

Measured memory_bytes: 41120
import heapq as hp
n,m=[int(x) for x in input().rstrip().split()]
a=[-int(x) for x in input().rstrip().split()]

hp.heapify(a)
a.sort()

while(m):
  
  m-=1
  now=hp.heappop(a)
  now=-((-now)//2)
  hp.heappush(a,now)
  
print(-sum(a))

Measured memory_bytes: 14180
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[100010] = {}, f[100010] , counto = 0, counto1 = 1145148;
double syo = 0, su = 0;
bool mazi = false, gi[110] = { false };
pair<int, int>n[110];
vector<int> r;
int main() 
{
	
	cin >> a>>b;
	for (int i = 0; i < b; i++) {
		cin >> e[i];
	}
	sort(e, e + b);
	for (int i = 0; i < b-1; i++) {
		f[i] = e[i + 1] - e[i];
	}
	sort(f, f + b);
	for (int i = 0; i < b - a+1; i++) {
		counto += f[i];
	}
	cout << counto << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
map<int,int>f;int x,n,i,max1,max2;
int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	  scanf("%d",&x),f[x]++;
	for (map<int,int>::iterator it=--f.end();;--it){
		if (it->second>=2){
			if (it->second>=4){
				if (!max1)
			    max1=max2=it->first;
			  else max2=it->first;
			  break;
			}
			if (it->second>=2){
				if (!max1) max1=it->first;
				else {max2=it->first;break;}
		  }
		}
		if (it==f.begin()) break;
	}
	if (max1&&max2) cout<<1ll*max1*max2<<endl;else cout<<0<<endl;
}

Measured memory_bytes: 4992
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
long long dp[200][300];
int main(){
	dp[0][0] = 1;
	int n, k;
	cin >> n >> k;
	REP(i, n) {
		int a;
		cin >> a;
		for (int j = i; j >= 0;--j) {
			REP(q, 256) {
				dp[j + 1][q ^ a] += dp[j][q];
				dp[j + 1][q ^ a] %= MAX_MOD;
			}
		}
	}
	long long ans = dp[0][k];
	long long hoge = 1;
	for (int i = 1; i <= n; ++i) {
		hoge *= i;
		hoge %= MAX_MOD;
		ans += hoge * dp[i][k];
		ans %= MAX_MOD;
	}
	cout << ans << endl;
}

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

using namespace std;

const int mxn = 2e5;

char s[mxn + 11];
int cnt[mxn + 11];

int main(){
	scanf("%s", s);
	int slen = strlen(s);
	int carry = 1;
	memset(cnt, 0, sizeof(cnt));
	cnt[0] = 1;
	int cur = 0;
	for (int i = slen - 1; i >= 0; i--){
		int digit = s[i] - '0';
		cur += digit * carry;
		cur %= 2019;
		cnt[cur]++;
		carry = carry * 10 % 2019;
	}
	int ans = 0;
	for (int i = 0; i < 2019; i++){
		ans += (cnt[i] * (cnt[i] - 1) ) >> 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4748
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define lint long long
using namespace std;

//最大公約数
lint gcd(lint a,lint b);
//最小公倍数
lint lcm(lint a,lint b);

int main()
{
  int A,B;
  cin>>A>>B;
  cout<<lcm(A,B)<<endl;
  return 0;
}

lint gcd(lint a,lint b)
{
  if(a>b){return gcd(b,a);}
  int m=1;
  while(m!=0){
    m=b%a;
    b=a;
    a=m;
  }
  return b;
}

lint lcm(lint a,lint b)
{
  return (a*b)/gcd(a,b);
}


Measured memory_bytes: 256
/**
 *  author: mahfuzz
 *  created: 28.03.2020
**/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    int p, n; cin >> p >> n;
    vector<int> vec;
    
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        vec.push_back(x);
    }
    
    vector<int> clock, aClock;
    
    for(int i = 0; i < n; i++){
        //clock wise
        int k = i + 1;
        if(i + 1 >= n)
            k = i - 1;
        int a;
        
        a = p - abs(vec[k] - vec[i]);
        aClock.push_back(a);
        
        
        k = i - 1;
        if(k < 0)
            k = n - 1;
        if(k == n - 1){
            a = abs(vec[k] - vec[i]);
        }else{
            a = p - abs(vec[k] - vec[i]);
        }
        clock.push_back(a);
        
    }
    
    sort(clock.begin(), clock.end());
    sort(aClock.begin(), aClock.end());
    
    cout << min(clock[0], aClock[0]) << "\n";
    
    return 0;
}


Measured memory_bytes: 3444
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key))sum++;
  }
  printf("%d\n", sum);
  return 0;
}



Measured memory_bytes: 2768
#if 0

#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int N, M;
int C[25];
int cnt[25][50010];

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) cin >> C[i];
  sort(C, C+M);
  for (int i = 0; i < M; i++) {
    for (int c = 0; c <= N; c++) {
      if (i == 0)
        cnt[i][c] = c;
      else if (c == 0)
        cnt[i][c] = 0;
      else if (c-C[i] < 0)
        cnt[i][c] = cnt[i-1][c];
      else {
        int a[3] = {1 + cnt[i][c-C[i]],1 + cnt[i-1][c-C[i]], cnt[i-1][c]};
        cnt[i][c] = *min_element(a, a+3);
      }
    }
  }
  cout << cnt[M-1][N] << endl;
}



Measured memory_bytes: 7080
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[100000];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int ans=0;
	for(int i=0;i<n;i++)
		ans+=a[a[i]-1]-1==i;
	cout<<ans/2<<endl;
}


Measured memory_bytes: 640
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vll as(n), bs(n);
  rep(i, n) { cin >> as[i]; }
  rep(i, n) { cin >> bs[i]; }

  ll soz = 0;
  bool upd = true;
  while (upd) {
    upd = false;
    rep(i, n) {
      ll im = (i + n - 1) % n;
      ll ip = (i + 1) % n;
      if(bs[i] > bs[im] && bs[i] > bs[ip]){
        ll dv = bs[im] + bs[ip];
        ll q = (bs[i] - as[i]) / dv;
        if(q > 0){
          soz += q;
          bs[i] -= q * dv;
          upd = true;
        }
      }
    }
  }
  bool ok = true;
  rep(i, n) if (as[i] != bs[i]) ok = false;

  ll ans = ok ? soz : -1;
  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

template <typename T>
struct SegTree {
    const T INF = numeric_limits<T>::max();
    int n;
    vector<T> dat;
    SegTree(int n_): n(), dat(n_ * 4, 0) {
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }

    void update(int i, T x) {
        i += n - 1;
        dat.at(i) = x;
        while (i > 0) {
            i = (i - 1) / 2;
            dat.at(i) = max(dat.at(i * 2 + 1), dat.at(i * 2 + 2));
        }
    }

    T query(int a, int b) {return query_sub(a, b, 0, 0, n);}
    T query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return 0;
        else if (a <= l && r <= b) return dat.at(k);
        else {
            T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }

};


int N;
vector<ll> H;
vector<ll> A;

SegTree<ll> dp(1 << 18);


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

    cin >> N;
    A.resize(N + 1);
    H.resize(N + 1);

    REP(i, N) cin >> H.at(i);
    REP(i, N) cin >> A.at(i);

    REP(i, N) {
        ll opt = dp.query(0, H.at(i)) + A.at(i);
        dp.update(H.at(i), opt);
    }

    cout << dp.query(0, N+1) << endl;

    return 0;
}

Measured memory_bytes: 11648
#include <vector>
#include <queue>
#include <stdio.h>
using namespace std;

int main(void) {
    int n, m;
    scanf("%d %d", &n, &m);

    vector<vector<int> > graph(n);
    for (int i = 0 ; i < m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> dist(n, -1);
    queue<int> que;
    vector<int> pre(n, -1);

    dist[0] = 0;
    que.push(0);

    while(!que.empty()) {
        int u = que.front();
        que.pop();
        for (int v : graph[u]) {
            if (dist[v] != -1)
                continue ;
            dist[v] = dist[u] + 1;
            que.push(v);
            pre[v] = u;
        }
    }

    printf("Yes\n");
    for (int i = 1; i < n; ++i)
        printf("%d\n", (pre[i] + 1));
}

Measured memory_bytes: 10060
#include <iostream>
#include <algorithm>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n,m; cin>>n>>m;
	long ans=1,div=1000000007;
	if(abs(n-m)>1) ans=0;
	else{
		for(int i=1;i<=n;i++) ans=ans*i%div;
		for(int i=1;i<=m;i++) ans=ans*i%div;
		if(n==m) ans=ans*2%div;
	}
	cout<<ans<<endl;
  	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  bool ok=false;
  string s;
  string ss[4]={"dream","dreamer","erase","eraser"};
  cin>>s;
  reverse(all(s));
  reverse(all(ss[0]));
  reverse(all(ss[1]));
  reverse(all(ss[2]));
  reverse(all(ss[3]));

  int stop=s.size();
  int cnt=0;

  while(1){
    if(cnt==stop){
      ok=true;
      break;
    }

    bool cont=false;
    rep(i,4){
      rep(j,ss[i].size()){
	if(ss[i][j]!=s[j+cnt])break;
	if(j==ss[i].size()-1){
	  cont=true;
	  cnt+=ss[i].size();
	  break;
	}
      }
      if(cont)break;
    }
    if(!cont)break;
  }
  if(ok)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;


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

    int64_t ans = 0;
    for (int b = 0; b < (1 << (s.size() - 1)); b++)
    {
        string t;
        for (int i = 0; i < s.size(); i++)
        {
            t += s[i];
            if (b & (1 << i)) {
                t += ' ';
            }
        }

        istringstream iss(t);
        int64_t sum = 0;
        for (int64_t cur; iss >> cur; ) {
            sum += cur;
        }

        ans += sum;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  int d[n+1]={};
  int tim[13]={};
  for(int i=0;i<n;i++){
    cin>>d[i];
    tim[d[i]]++;
  }

  for(int i=0;i<=12;i++){
    if(tim[i]>=3){
      cout<<0<<endl;
      return 0;
    }
  }
  if(tim[0]>=1||tim[12]>=2){
    cout<<0<<endl;
    return 0;
  }

  int ans=0;
  for(int i=0;i<(1<<11);i++){
    vector<int> res;
    res.push_back(0);
    if(tim[12]==1) res.push_back(12);
    for(int j=0;j<11;j++){
      if(tim[j+1]==2){
        res.push_back(j+1);
        res.push_back(24-(j+1));
      }else if(tim[j+1]==1){
        if(i&(1<<j)) res.push_back(j+1);
        else res.push_back(24-(j+1));
      }
    }

    sort(res.begin(),res.end());
    int sub=min(res[res.size()-1],24-res[res.size()-1]);
    for(int j=0;j<res.size()-1;j++){
      sub=min(sub,res[j+1]-res[j]);
    }
    ans=max(ans,sub);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    if (s[k - 1] == 'A') s[k - 1] = 'a';
    else if (s[k - 1] == 'B') s[k - 1] = 'b';
    else if (s[k - 1] == 'C') s[k - 1] = 'c';
    cout << s << endl;
}


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

typedef long long int LL;
#define REP(n) for(LL i = 0; i < (n); i++)
#define COUT(val) cout << (val) << endl
#define CIN(val) cin >> (val)
#define SORT(vec) sort(vec.begin(), vec.end())
#define SORT_GRE(vec) sort(vec.begin(), vec.end(), greater<LL>())

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(c-a) <= d || (abs(b-a) <= d && abs(c-b) <= d)){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//
 
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
 
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer return cout << 0, 0;
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)
 
const int MXN = 2e5 + 200;
const long long MNN = 2e3 + 520;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;
 
typedef long long llong;
typedef unsigned long long ullong;
 
using namespace std;

llong n, k, b[MXN], dp[MXN];

void add(llong& a, llong b){
    a += b;
    if(a < 0) a += MOD;
    while(a >= MOD) a -= MOD;
}

int main () {
    ios;
    cin >> n >> k;
    dp[0] = 1;
    for(int i = 1; i <= n; i++){
        cin >> b[i];
        llong d[MXN];
        memset(d, 0, sizeof(d));
        for(int j = k; j >= 0; j--){
            if(j + 1 < j + min(b[i], k - j) + 1){
                d[j + 1] += dp[j];
                if(j + min(b[i], k - j) + 1 <= k){
                    d[j + min(b[i], k - j) + 1] += -dp[j];
                }
            }
        }
        llong sum = 0;
        for(int j = 0; j <= k; j++){
            add(sum, d[j]);
            add(dp[j], sum);
        }
    }
    cout << dp[k];
}


Measured memory_bytes: 2560