akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << res << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)

int main() {
	ll n, k;
	cin >> n >> k;
	ll res = n%k;
	res = min(res, k - res);
	pv(res)
	return(0);
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

int n;

int main(void)
{
	scanf("%d %d", &n);
	int big = 0; int tot = 0;
	while (tot < n)
	{
		++big;
		tot += big;
	}
	for (int i = big; i != 0; --i)
	{
		if (n - i >= 0)
		{
			n -= i;
			printf("%d\n", i);
		}
	}
	return 0;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;

const ll mod=1000000007;	
ll f[501010], rf[501010];

ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}

ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * bc) % mod;
}

ll P(int n, int k) {
    ll a = f[n]; // = n!
    ll b = rf[n - k]; // = (n-k)!
    return (a * b) % mod;
}

ll H(int n, int k) {
    return C(n + k - 1, k);
}

void init() {
    f[0] = 1;
    rep(i, 1, 501010) f[i] = (f[i - 1] * i) % mod;
    rf[501010 - 1] = inv(f[501010 - 1]);
    rrep(i, 501010 - 2, 0) rf[i] = (rf[i + 1] * (i + 1)) % mod;
}

int main() {
  int N,M;
  cin >> N >> M;
  init();
  ll res=0;
  ll sign=1;
  ll tmp;
  rep(i,0,N+1){
    tmp = C(N,i)*P(M,i) % mod;
    tmp = tmp*P(M-i,N-i) % mod;
    tmp = tmp*P(M-i,N-i) % mod;
    res += mod + sign*tmp;
    res = res % mod;
    sign *= -1;
  }
  cout << res;
  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }


int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    ll N, M;
    cin >> N >> M;

    vector<ll> L(M), R(M);

    for(ll i = 0; i < M; i++){
        cin >> L[i] >> R[i];
    }

    sort(L.begin(), L.end());
    sort(R.begin(), R.end());

    ll ans = max(ll(0), ll(R[0] - L[M-1] + 1));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = [0] + list(map(int, input().split())) + [0]

D = [abs(A[i] - A[i+1]) for i in range(N+1)]
D2 = [abs(A[i] - A[i+2]) for i in range(N)]
S = sum(D)

for i in range(N):
    print(S + (D2[i] - (D[i]+D[i+1])))

Measured memory_bytes: 15912
/// Bismillahir Rahmanir Rahim
/* Author: Mohammad Morsalin (aka white_space)
    Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define PI acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
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 long long MOD = 1000000007;
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
int main()
{
    IOS
    int k;
    cin>>k;
    string s;
    cin>>s;
    int n=s.size();
    if(k>=n)cout << s << endl;
    else{
        for(int i=0;i<k;i++)cout << s[i];
        cout << "...\n";
    }
    return 0;
}
///Alhamdulillah


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

int gcd(int x, int y){
  while(y>0){
  int r = x%y;
  x = y; y = r;
  }
  return x;
}

int gcd(vector<int> s, int m){
  int ans = s[0];
  for(int i = 0; i < m-1; i++) ans = gcd(ans, s[i+1]);
  return ans;
}

int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  cout << gcd(a, n) << endl;
  //cout << gcd(27, 18) << endl;
}

Measured memory_bytes: 1024
import itertools
N, M = map(int, input().split())

root_dict = {str(i) : [] for i in range(1, N+1)}
for i in range(M):
    root = input().split()
    root_dict[root[0]] = root_dict[root[0]] + [root[1]]
    root_dict[root[1]] = root_dict[root[1]] + [root[0]]
result = 0
numbers = [str(i) for i in range(2, N+1)]
numbers = ''.join(numbers)

for order in itertools.permutations(numbers, N-1):#1以降の順列
    prev_num = "1"
    flag = True
    for num in order:
        if num not in root_dict[prev_num]:
            flag = False
            break
        prev_num = num
    if flag:
        result += 1

print(result)

Measured memory_bytes: 3064
let x, n = stdin.ReadLine().Split()|> fun [| a; b |] -> int a, int b
let p = 
    stdin.ReadLine()|> function
    | "" -> Array.empty
    | x -> x.Split() |> Array.map int

// 制約がきついので総当たりで調べても間に合う
let cand x =
    let rec createCand diff =
        seq{
            if diff > 100 then ()
            elif diff = 0 then
                yield x
                yield! createCand (diff+1)
            else
                yield x - diff
                yield x + diff
                yield! createCand (diff + 1)
        }
    createCand 0 

if n = 0 then stdout.WriteLine x 
else
cand x |> Seq.find (fun x -> not (Array.contains x p)) |> stdout.WriteLine 

Measured memory_bytes: 28344
#include<stdio.h>
#include<math.h>
#define pb push_back
//#define FAST ios::sync_with_stdio(false);cin.tie(NULL),cout.tie(NULL);
//typedef long long ll;
#define pi  3.141592653589793238
//using namespace std;

int main()
{
     double r;
     scanf("%lf",&r);
     printf("%.10lf\n",2*pi*r);
//    cin>>r;
//    cout<<2*pi*r<<fixed<<setprecision(12)<<endl;
    return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n;
	cin >> n;
	map<char, ll> m;
	rep(i, n){
		string s;
		cin >> s;
		m[s[0]]++;
	}

	ll ans = 0;
	ans += m['M'] * m['A'] * m['R'];
	ans += m['M'] * m['A'] * m['C'];
	ans += m['M'] * m['A'] * m['H'];
	ans += m['M'] * m['R'] * m['C'];
	ans += m['M'] * m['R'] * m['H'];
	ans += m['M'] * m['C'] * m['H'];
	ans += m['A'] * m['R'] * m['C'];
	ans += m['A'] * m['R'] * m['H'];
	ans += m['A'] * m['C'] * m['H'];
	ans += m['R'] * m['C'] * m['H'];

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

Measured memory_bytes: 256
// failed to generate code

#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

int binarySearch(long double key) {
  if (key == 0)
    return -1;
  int left = 0;
  int right = 3501;

  //残り10以下になるまで探索
  while (right - left > 10) {
    int mid = (left + right) / 2;
    long double buf = 1.d / mid;

    if (buf == key)
      return mid;

    if (buf > key) {
      left = mid;
    } else {
      right = mid;
    }

    // cerr << left << " " << right << endl;
  }

  //あとは愚直に
  for (int i = left; i <= right; ++i) {
    long double buf = 1.d / i;

    if (buf == key) {
      return i;
    }
  }

  return -1;
}

ll N;

void think() {
  cin >> N;

  long double ans = 4.d / N;

  // if (false) {
  for (ll h = 1; h < 3501; ++h) {
    for (ll n = 1; n < 3501; ++n) {
      if ((4 * h * n - h * N - n * N) == 0)
        continue;
      ll w = h * n * N / (long double)(4 * h * n - h * N - n * N);

      if ((h * n * N) % (4 * h * n - h * N - n * N) != 0)
        continue;

      if (w <= 0)
        continue;

      dump(ans, (1.d / h + 1.d / n + 1.d / w));
      cout << h << " " << n << " " << w << endl;
      return;
    }
  }
  // }
}

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


Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
int main()
{
    std::unordered_set<int> invalid;
    int x, n, i, temp;

    std::cin >> x >> n;
    if(n == 0)
        std::cout << x << std::endl;
    
    else
    {
       for(i = 0; i < n; ++i)
        {
            std::cin >> temp;
            invalid.insert(temp);
        }

        temp = 0;
        while(true)
        {
            if(invalid.find(x-temp) != invalid.end())
            {
                if(invalid.find(x+temp) != invalid.end())
                {
                    temp++;
                    continue;
                }

                std::cout << x+temp << std::endl;
                break;
            }

            std::cout << x-temp << std::endl;
            break;
        }
    }
    
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll h, cnt = 0, ans;
  cin >> h;

  cnt = floor(log2(h));
  ans = (ll)pow(2, cnt + 1) - 1;

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


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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000 //10^12

int main() {
    int N, K, d, a;
    set<int> A;
    
    cin >> N >> K;

    REP(i, K) {
        cin >> d;

        REP(j, d) {
            cin >> a;
            A.insert(a);
        }
    }

    cout << N - SIZE(A) << endl;


    return 0;
}

Measured memory_bytes: 3640
counter = Hash.new()
(97..122).each{|ord| counter[ord] = 0 }

characters = readlines.join("").split("").select{|c| c != "\n"}

characters.each {|c|
  ord = c.ord
  ord = ord + 32 if 65 <= ord && ord <= 90
  counter[ord] += 1 if counter.has_key?(ord)
}

puts counter.keys.map {|key| "#{key.chr} : #{counter[key]}"}.join("\n")

Measured memory_bytes: 8612
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int str[1000005];
int main()
{

	memset(str,0,sizeof(str));
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		if(i%5==0||i%3==0)
		 str[i]=1;
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		if(str[i]==0)
		ans+=i;
	}
	cout<<ans<<endl;
}

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

int f(int n);

int main() {
	int s;
	int a[1000000];
	int finished = false;

	cin >> s;


	for (int i = 0; i < 1000000; i++) {
		if (i == 0)	a[i] = s;
		else a[i] = f(a[i - 1]);

		for (int j = 0; j < i; j++) {
			if (a[i] == a[j]) {
				cout << i+1 << endl;
				finished = true;
				break;
			}
		}

		if (finished)break;

	}

	
}

int f(int n) {

	if (n % 2 == 0) {
		return n / 2;
	}
	else {
		return 3 * n + 1;
	}
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    int h[n];

    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h,h+n);
    int m = h[k-1] - h[0];
    for(int i = 0; i <= n - k; i++){
        m = min(m,h[i + k - 1] - h[i]);
    }
    cout << m;
}

Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline()[:-1]
n,m=map(int,input().split())
a0=list(map(int,input().split()))
data=[list(map(int,input().split())) for i in range(m)]
for i in a0:
	data.append([1,i])
data.sort(key=lambda tup:-tup[1])
ans=0
for num,val in data:
	if n>=num:
		n-=num
		ans+=val*num
	else:
		ans+=val*n
		break
print(ans)


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

using namespace std;

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

typedef long long ll;

const int N = 3e5;
vector<int> edges[N];
int p[N], dst[N];
int n, K;
set<pair<int, int>, greater<pair<int, int> > > st;

void dfs(int v, int d) {
  dst[v] = d;
  if (dst[v] > K)
    st.insert({dst[v], v});
  for (int u : edges[v]) {
    dfs(u, d + 1);
  }
}

void deleteAll(int v, int d = 0) {
  st.erase({dst[v], v});
  if (d == K - 1) return;
  for (int u : edges[v]) {
    deleteAll(u, d + 1);
  }
}

void solve() {
  cin >> n >> K;
  int ans = 0;
  for (int v = 1; v <= n; v++) {
    int u; cin >> u;
    if (v == 1) {
      ans += (u != 1); p[1] = 1; continue;
    }
    edges[u].push_back(v);
    p[v] = u;
  }
  dfs(1, 0);
  while (!st.empty()) {
    int v = st.begin()->second; st.erase(st.begin());
    int pr = v;
    for (int iter = 0; iter < K - 1; iter++) {
      pr = p[pr];
    }
    deleteAll(pr);
    ans++;
  }
  cout << ans;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


Measured memory_bytes: 23836
#include<stdio.h>
#define ll long long int

int main(int argc, char *argv[]){

  //long long int a, b, x;
  ll a, b, x;
  scanf("%lld %lld %lld", &a, &b, &x);
  //printf("%lld %lld %lld\n", a, b, x);

  //long long cnt = b/x - a/x;
  ll cnt = b/x-a/x;
  if((a%x)==0) cnt++;
  printf("%lld\n", cnt);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
	int n,l[211];
	cin >> n;
	for(int i=0; i<2*n; i++){
		cin >> l[i];
	}
	sort(l,l+2*n);
	int ans = 0;
	for(int i=0; i<2*n; i += 2){
		ans += l[i];
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N;
    cin >> N;
    vi A(N);
    in(N,A);
    
    map<int, ll> M;
    rep(i,N) M[A[i]]++;
    
    ll ans = 0;
    for (auto p : M) {
        ans += p.se*(p.se-1)/2;
    }
    
    rep(i,N){
        ll aa = M[A[i]]-1;
        cout << ans + aa*(aa-1)/2 - aa*(aa+1)/2<< endl;
    }
    
    
    
    
    

    return 0;
}


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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

vector<int> a;
const int MAXK = 100001;
vector<int> memo(MAXK, -1);

int dp(int K, const vector<int> & a) {
  if (K <= 0) return false;
  if (memo[K] != -1) return memo[K];

  int ret = 0;
  for (int v : a) if ((v <= K) && (dp(K - v, a) == 0)) ret = 1;
  return memo[K] = ret;
}

int main(){
  int N, K;
  cin >> N >> K;
  a.resize(N);
  REP(i,N) cin >> a[i];

  cout << (dp(K, a) ? "First" : "Second") << endl;
  return 0;
}



Measured memory_bytes: 8448
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(string S) {
  S.replace(0, 4, "2018");
  cout << S << endl;
}

int main() {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}

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

  string s;
  cin >> s;

  int ans = INF;
  rep(i, 0, s.size() - 2) {
    string t = s.substr(i, 3);
    ans = min(ans, abs(stoi(t) - 753));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    int[] AS;
    foreach (_; 0..N) AS ~= readln.chomp.to!int;

    int[] cs;
    foreach (a; AS) {
        if (cs.empty || cs[$-1] >= a) {
            cs ~= a;
            continue;
        } else if (cs[0] < a) {
            cs[0] = a;
            continue;
        }

        size_t l, r = cs.length-1;
        while (l+1 < r) {
            auto m = (l+r)/2;
            if (cs[m] < a) {
                r = m;
            } else {
                l = m;
            }
        }
        cs[r] = a;
    }
    writeln(cs.length);
}

Measured memory_bytes: 3836
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c * d) << endl;
}

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

using namespace std;

int main(){
    long long int N,q,K;
    cin >> N;
    vector<long long int> len(N,-1);
    vector<vector<pair<long long int,long long int>>> graph(N);
    queue<long long int> Q;


    for(int i=0;i<N-1;i++){
        long long int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a].push_back({b,c});
        graph[b].push_back({a,c});
    }

    cin >> q >> K;
    K--;

    len[K] = 0;
    Q.push(K);

    while(!Q.empty()){
        long long int now = Q.front();
        Q.pop();
        for(int i=0;i<graph[now].size();i++){
            if(len[graph[now][i].first]== -1){
                len[graph[now][i].first] = len[now]+graph[now][i].second;
                Q.push(graph[now][i].first);
            }
        }
    }

    for(int i=0;i<q;i++){
        long long int x,y;
        cin >> x >> y;
        x--;
        y--;
        cout << len[x]+len[y] << endl;
    }
}

Measured memory_bytes: 9984
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;

int main()
{
    string S,X,res;

    string tmp;

    cin >> S;

    res = "Good";

    for(ll i = 1; i< S.size();i++)
    {
        if(S[i-1] == S[i])
        {
            res = "Bad";
        }
    }


    cout << res << endl;

}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a, b, c, d;
  int in;
  scanf("%d", &in);
  
  d = in % 10;
  in /= 10;
  c = in % 10;
  in /= 10;
  b = in % 10;
  in /= 10;
  a = in;
  
  if(a + b + c + d == 7) printf("%d+%d+%d+%d=7", a, b, c, d);
  else if(a + b + c - d == 7) printf("%d+%d+%d-%d=7", a, b, c, d);
  else if(a + b - c + d == 7) printf("%d+%d-%d+%d=7", a, b, c, d);
  else if(a + b - c - d == 7) printf("%d+%d-%d-%d=7", a, b, c, d);
  else if(a - b + c + d == 7) printf("%d-%d+%d+%d=7", a, b, c, d);
  else if(a - b + c - d == 7) printf("%d-%d+%d-%d=7", a, b, c, d);
  else if(a - b - c + d == 7) printf("%d-%d-%d+%d=7", a, b, c, d);
  else if(a - b - c - d == 7) printf("%d-%d-%d-%d=7", a, b, c, d);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rrep(i,n) for(int i = 1;i <= n;i++)
#define drep(i,n) for(int i = n;i >= 1;i--)

int a[5010], n, k;
bitset<5010> dp1[5010], dp2[5010];

int solve(int mid){
	if(a[mid] >= k)return 1;
	bitset<5010> dp = dp2[mid+1];
	rrep(i,k)if(dp1[mid-1][i])dp |= dp2[mid+1]<<i;
	dp[k] = 0;
	drep(i,k-1)if(dp[i+1])dp[i] = 1;
	return dp[k-a[mid]];
}

signed main(){
	scanf("%lld%lld", &n, &k);
	rrep(i,n)scanf("%lld", &a[i]);
	
	sort(a+1,a+n+1);
	dp1[0] = dp2[n+1] = 1;
	rrep(i,n)dp1[i] = dp1[i-1] | dp1[i-1]<<a[i];
	drep(i,n)dp2[i] = dp2[i+1] | dp2[i+1]<<a[i];
	
	int lb = 0, ub = n+1;
	while(ub-lb > 1){
		int mid = (lb+ub)/2;
		int res = solve(mid);
		if(res)ub = mid;
		else lb = mid;
	}
	printf("%lld\n", ub-1);
	return 0;
}

Measured memory_bytes: 6528
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
const ll MOD = 1e9 + 7;
ll n, k;
vector<ll> a, t, p;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    a.assign(n, 0);
    t.assign(n, 0);
    p.assign(n, 0);
    F0R(i, n) cin >> a[i];
    F0R(i, n)
    {
        FOR(j, i + 1, n)
        {
            if(a[j] < a[i]) t[j]++;
        }
    }
    F0R(i, n) F0R(j, n) if(a[j] > a[i]) p[i]++;
    ll res = 0;
    F0R(i, n) 
    {
        res += t[i] * (k) + p[i] * ((((k - 1) * k)/2) % MOD);
        res %= MOD;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,top,tmp,A=1,B=2,C=3,D=4,E=5,F=6;
    char c;
    std::deque<int> deq;
    for (int i=0;i<6;i++) {
        cin>>x;
        deq.emplace_back(x);
    }
    top=1;
    while (cin>>c) {
        if (c=='N') {
            tmp=A;
            A=B;
            B=F;
            F=E;
            E=tmp;
        } else if (c=='E') {
            tmp=C;
            C=A;
            A=D;
            D=F;
            F=tmp;
        } else if (c=='W') {
            tmp=A;
            A=C;
            C=F;
            F=D;
            D=tmp;
        } else if (c=='S') {
            tmp=A;
            A=E;
            E=F;
            F=B;
            B=tmp;
        }
    }
    cout<<deq[A-1]<<endl;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,temp;
	cin >> a >> b >> c;
	if(a>b){
		temp=a;
		a=b;
		b=temp;
	}
	if(a>c){
		temp=a;
		a=c;
		c=temp;
	}
	if(b>c){
		temp=b;
		b=c;
		c=temp;
	}
	cout << a << " " << b << " " << c << endl;
}
	
		
		


Measured memory_bytes: 3092
// D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
#include<vector>

using namespace std;

int main()
{
    string s;

    cin >> s;

    int left = 0;
    int key;
    vector<int> ans(s.size(), 0);
    int mode = 0;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (mode == 0) {
            if (s[i] == 'R') {
                cnt++;
            }
            else {
                key = i - 1;
                ans[i - 1] += (cnt + 1) / 2;
                ans[i] += cnt / 2;
                mode = 1;
                cnt = 0;
                i--;
            }
        }
        else {
            if (s[i] == 'L') {
                cnt++;
                if (i == s.size() - 1) {
                    ans[key] += cnt / 2;
                    ans[key + 1] += (cnt + 1) / 2;
                }
            }
            else {
                ans[key] += cnt / 2;
                ans[key + 1] += (cnt + 1) / 2;
                mode = 0;
                cnt = 0;
                i--;
            }
        }
    }

    for (int i = 0; i < s.size(); i++) {
        cout << ans[i] <<" ";
    }

    return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 3864
#include"bits/stdc++.h"
using namespace std;

void Main() {
  string s;
  cin >> s;
  int p = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'p') p++;
  }

  cout << s.length() / 2 - p << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 3796
package main

import (
	"fmt"
)

func main() {
	var h, w, k int
	fmt.Scan(&h, &w, &k)

	var patterns = [][]int{{0}}
	for i := 1; i < w; i++ {
		var patternsNext = [][]int{}
		for _, pattern := range patterns {
			patternN := make([]int, i+1)
			copy(patternN, pattern)
			patternN[i] = i
			patternsNext = append(patternsNext, patternN)
			if pattern[i-1] == i-1 {
				patternR := make([]int, i+1)
				copy(patternR, pattern)
				patternR[i-1] = i
				patternR[i] = i - 1
				patternsNext = append(patternsNext, patternR)
			}
		}
		patterns = patternsNext
	}

	pnums := make([][]int, w)
	for i := 0; i < w; i++ {
		pnums[i] = make([]int, w)
	}
	for _, pattern := range patterns {
		for i, p := range pattern {
			pnums[i][p]++
		}
	}

	nums := make([]int, w)
	nums[0] = 1
	for i := 0; i < h; i++ {
		numsNext := make([]int, w)
		for i, pnum := range pnums {
			for j, p := range pnum {
				numsNext[i] = (numsNext[i] + nums[j]*p) % 1000000007
			}
		}
		nums = numsNext
	}
	fmt.Println(nums[k-1])

}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	string s;
	cin >> s;
	int ans;
	cin >> ans;
	int lr = s[0] - '0';
	REP(i, s.length() / 2){
		if (s[i * 2 + 1] == '+')
			lr += s[i * 2 + 2] - '0';
		else
			lr *= s[i * 2 + 2] - '0';
	}
	int mul = 0;
	vector<int> numbers;
	REP(i, s.length() / 2 + 1){
		numbers.push_back(s[i * 2] - '0');
	}
	REP(i, (s.length() / 2)){
		if (s[i * 2 + 1] == '*'){
			numbers[i + 1] *= numbers[i];
			numbers[i] = 0;
		}
	}
	REP(i, numbers.size()){
		mul += numbers[i];
	}
	if (lr == ans&&mul == ans)
		cout << "U" << endl;
	else if (lr == ans)
		cout << "L" << endl;
	else if (mul == ans)
		cout << "M" << endl;
	else
		cout << "I" << endl;
}

Measured memory_bytes: 3224
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/dwacon6th-prelims/tasks/dwacon6th_prelims_b

//参考：
//https://drken1215.hatenablog.com/entry/2020/01/12/014200

//ポイント
//各区間ごとにスライムの通過する回数の期待値を漸化式で求める


#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//https://github.com/atcoder-live/library/blob/master/mint.cpp
struct mint {
  LL x; 
  mint(LL x=0):x((x%mod+mod)%mod){}
  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;
  }
};
 
struct combination {
  vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元
  combination(LL n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (LL i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (LL i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(LL n,LL k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

LL N;
LL X[100000];

mint ans = 0;

void solve(){
	//i!をfact[i]とする
	vector<mint> fact(N,1);
	for(int i=1;i<=N-1;i++) fact[i] = fact[i-1]*i;
	//X[i]とX[i+1]の間の距離をd[i]とする
	vector<mint> d(N);
	for(int i=0;i<=N-2;i++) d[i] = X[i+1]-X[i];
	//X[i]とX[i+1]の間をスライムが通る回数の期待値をc[i]と置いた時、
	//C[i] = c[i]*(N-1)と決める
	vector<mint> C(N);
	C[0] = fact[N-1];
	for(int i=0;i<=N-2;i++) C[i+1] = C[i] + fact[N-1]/(mint(i+2));

	for(int i=0;i<=N-2;i++) ans += d[i]*C[i];
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> X[i];

    solve();

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

Measured memory_bytes: 6060
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
// #include <bits/extc++.h>
using namespace std;

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;

inline int myrand(int l, int r) {
	int ret = rand(); ret <<= 15; ret ^= rand();
	if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
	return ret;
}

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

typedef pair<int, int> ii;

template<typename T> using min_pq =
	std::priority_queue<T, vector<T>, greater<T> >;

//int dx[] = {-1, +0, +1, +0};
//int dy[] = {+0, +1, +0, -1};

const int maxn = 1e3 + 5;
const int mod = 1e9 + 7;

int dp[maxn][maxn];
int H, W;
string s[maxn];

int32_t main () {
	// freopen("in", "r", stdin);
	cin >> H >> W;
	for(int i = 0; i < H; i++) {
		cin >> s[i];
	}
	dp[0][0] = 1;
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			if(s[i][j] == '.') {
				dp[i + 1][j] += dp[i][j]; if(dp[i + 1][j] >= mod) dp[i + 1][j] -= mod;
				dp[i][j + 1] += dp[i][j]; if(dp[i][j + 1] >= mod) dp[i][j + 1] -= mod;
			}
		}
	}
	cout << dp[H - 1][W - 1] << endl;
}

Measured memory_bytes: 5248
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N;

int main() {

	cin >> N;
	if (N == 2) {
		cout << 1 << endl;
		return 0;
	}

	vector<ll> yakusuN, yakusuN1;

	for (ll i = 2; i * i <= N; ++i) {
		if (N % i == 0) {
			yakusuN.push_back(i);
			if (N / i != i)
				yakusuN.push_back(N / i);
		}
	}

	for (ll i = 2; i * i <= N - 1; ++i) {
		if ((N - 1) % i == 0) {
			yakusuN1.push_back(i);
			if ((N - 1) / i != i)
				yakusuN1.push_back((N - 1) / i);
		}
	}

	sort(all(yakusuN));
	sort(all(yakusuN1));

	set<ll> ans;
	ans.insert(N);
	ans.insert(N - 1);
	for (auto yy : yakusuN1) ans.insert(yy);

	for (auto yy : yakusuN) {
		auto t = N;
		while (t % yy == 0) t /= yy;
		if (t % yy == 1) ans.insert(yy);
	}

	cout << ans.size() << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long m = sc.nextInt();
		long nn = (n == 1) ? 1 : Math.max(0, n - 2);
		long mm = (m == 1) ? 1 : Math.max(0, m - 2);

		System.out.println(nn * mm);
	}
}


Measured memory_bytes: 22996
/*
 *	問題: Ststic Sushi
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

ll iki[2][100002],iki_best[2][100002],modori[2][100002],modori_best[2][100002];
ll x[100002],v[100002];
int main(){
    ll N,C;
    cin >> N >> C;
    x[N+1]=C;
    for(int i=1;i<=N;i++){
        cin >> x[i] >> v[i];
        iki[0][i]=iki[0][i-1]+v[i];
        modori[0][i]=modori[0][i-1]+v[i];
    }
    for(int i=N;i>=1;i--){
        iki[1][i]=iki[1][i+1]+v[i];
        modori[1][i]=modori[1][i+1]+v[i];
    }
    for(int i=1;i<=N;i++){
        iki[0][i]-=2*x[i];
        modori[0][i]-=x[i];
        iki[1][i]-=2*(C-x[i]);
        modori[1][i]-=(C-x[i]);
    }
    for(int i=1;i<=N;i++){
        iki_best[0][i]=max(iki_best[0][i-1],iki[0][i]);
        modori_best[0][i]=max(modori_best[0][i-1],modori[0][i]);
    }
    for(int i=N;i>=1;i--){
        iki_best[1][i]=max(iki_best[1][i+1],iki[1][i]);
        modori_best[1][i]=max(modori_best[1][i+1],modori[1][i]);
    }

    ll ans=0LL;
    for(int i=0;i<=N+1;i++){
        if(i<=N)
            ans=max(ans,iki_best[0][i]+modori_best[1][i+1]);
        if(i>=1)
            ans=max(ans,iki_best[1][i]+modori_best[0][i-1]);
    }

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

Measured memory_bytes: 8064
s=list(input())
t=list(input())
dp=[[0]*(len(s)+1) for i in range(len(t)+1)]
for i in range(1,len(t)+1):
    for j in range(1,len(s)+1):
        if(s[j-1]==t[i-1]):
            dp[i][j]=dp[i-1][j-1] + 1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
# print(dp[len(t)][len(s)])
ans=""
i=len(t)
j=len(s)
while(i!=0 and j!=0):
    if(dp[i][j-1]<dp[i][j]>dp[i-1][j]):
        i-=1
        j-=1
        ans+=t[i]
    elif(dp[i][j]==dp[i-1][j]):
        i-=1
    elif(dp[i][j-1]==dp[i][j]):
        j-=1
print(ans[::-1])     

Measured memory_bytes: 144136
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

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

	rep (i, s.size() - 1) {
		if (s[i] == 'A' && s[i+1] == 'C') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
P = np.array(read().split(),np.int32)

X = 40000
A = np.arange(N) * X + 1
B = np.arange(N)[::-1] * X + 1

add = np.empty(N,np.int32)
add[P-1] = np.arange(N)
A += add

print(' '.join(A.astype(str)))
print(' '.join(B.astype(str)))

Measured memory_bytes: 17624
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define krep(n) for(ll k=0;k<(n);k++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } 

ll spf[1000006];

ll occ[1000006];
void solve(ll ts){
    ll n; cin>>n; vector<ll> arr(n); rep(n) cin>>arr[i];
    ll t=arr[0];
    for(auto i:arr) t=__gcd(i,t);
    for(auto i:arr){
        ll ti=i;
        while(ti>1){
            ll tt=spf[ti]; occ[tt]++;
            while(ti%tt==0) ti/=tt;
        }
    }
    bool pwc=true;
    for(ll i=2;i<1000006;i++) if(occ[i]>1) pwc=false;
    //cout<<t<<endl;
    //for(ll i=2;i<20;i++) cout<<i<<":"<<occ[i]<<" "; cout<<endl;
    if(pwc) cout<<"pairwise coprime\n";
    else if(t==1) cout<<"setwise coprime\n";
    else cout<<"not coprime\n";
} 
int main(){
    ffast
    rep(1000006) if(i%2==0) spf[i]=2; else spf[i]=i;
    for(ll i=3;i<1000006;i++){
        for(ll j=i*i;j<1000006;j+=i) spf[j]=min(spf[j],i);
    }
    ll t=1;
//    cin>>t;
    rep(t) solve(i+1);
}
 
 
// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)


Measured memory_bytes: 26652
fun main() {
    val x = readLine()!!.toLong()

    fun pow5(num: Int): Long{
        var tmp = num.toLong()
        repeat(5-1) {
            tmp *= num
        }
        return tmp
    }

    for (i in 1..120) {
        val a = pow5(i)
        for (j in -120..120) {
            val b = pow5(j)
            if (a - b == x) {
                println("$i $j")
                return
            }
        }
    }
}





Measured memory_bytes: 34548
#include <stdio.h>
int findMax(int a[],int n){
	int max=0;
	int j;
	for(int i=0;i<n;i++){
		if(a[i]>max){
			max=a[i];
			j=i;
		}
	}
	a[j]=0;
	return max;
}
int main()
 {
     int n,m,i,max1,max2;
     int a[200];
     int b[200],c[200];
     scanf("%d",&n);
     for(i=0;i<n;i++){
     	scanf("%d",&a[i]);
     }
     m=n;
     max1=max2=0;
     for(i=0;i<n;i++){
     	b[i]=findMax(a,m);
     	max1+=b[i];
     	c[i]=findMax(a,m);
     	max2+=c[i];
	 }
    printf("%d",max1-max2);
     return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())
#define pb push_back
#define mp make_pair
#define MODP(A,B) A=(A+B)%mod
typedef pair<ll,ll> P;
typedef pair<double,double> Pd;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

ll d[10][16];


int main(){
    ll K; cin>>K; 
    rep(i,10) d[i][0]++;
    rep(j,15) {
        rep(i,10) {
            if(i!=0) d[i-1][j+1]+=d[i][j];
            d[i][j+1]+=d[i][j];
            if(i!=9) d[i+1][j+1]+=d[i][j];
        }
    }

    vec s(16,0), SUM(17,0);
    rep(j,16) REP(i,1,10) s.at(j)+=d[i][j];
    rep(j,16) SUM.at(j+1)=SUM.at(j)+s.at(j);

    
    ll X=lower_bound(ALL(SUM),K)-SUM.begin();
    X--;
    K-=SUM.at(X);
    //cout<<X<<endl;
    //cout<<K<<endl;
    vec ans;
    for(int i=X; i>=0; i--){
        if(i==X){
            ll H=0;
            ll memory=9;
            REP(k,1,10) {
                if(H+d[k][i]<K) H+=d[k][i];
                else{
                    memory=k;
                    break;
                }
            }
            K-=H;
            ans.pb(memory);
        }
        else{
            ll P=ans.at(ans.size()-1);
            ll AA=-1,BB=0,CC=0;
            if(P!=0) AA=d[P-1][i];
            if(AA>=K) ans.pb(P-1);
            else{
                if(AA<0) AA=0;
                BB=AA+d[P][i];
                
                if(BB>=K) {ans.pb(P); K-=AA;}
                else {ans.pb(P+1); K-=BB;}
            } 
        }
    }

    
    rep(i,ans.size()) cout<<ans.at(i);
    cout<<endl;
    
}

Measured memory_bytes: 256