akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

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

    int a, b;
    cin >> a >> b;
    vector<bool> c(3, true);
    c[--a] = false;
    c[--b] = false;
    for (int i = 0; i < 3; ++i) {
        if (c[i]) {
            cout << i + 1;
            break;
        }
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int judge(int n){
    int s = n / 10;
    if(n%10 != 0)
        s++;
    return s;
}
int main(){
    int a[5], sum = INT_MAX;
    for(int i = 0; i < 5; i++){
        cin >> a[i];
    }
    sort(a,a+5);
    do{
        int sum1 = 0;
        for(int i = 0; i < 4; i++){
            sum1 += judge(a[i])*10;
            }
    sum1 += a[4];
    sum = min(sum,sum1);
    }while(next_permutation(a,a+5));
            cout << sum << endl;
    return 0;
}


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

int main(void){
	string str;
	while(getline(cin,str)){
		for(int i=0; i<str.size(); i++){
			if(str[i]>='a' && str[i]<='z')
				str[i] += 'A'-'a';
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()
 
 
def main():
    h, w = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    Ch -= 1
    Cw -= 1
    Dh -= 1
    Dw -= 1
    s2 = [list(input()) for i in range(h)]
    s2[Ch][Cw] = 0
    d = deque()
    d.append([Ch, Cw])
    while d:
        nowh, noww = d.popleft()
        for i, j in [[0, 1], [1, 0], [0, -1], [-1, 0]]:
            if ((0 <= nowh+i < h) and (0 <= noww+j < w)):
                if s2[nowh+i][noww+j] == '.':
                    s2[nowh+i][noww+j] = s2[nowh][noww]
                    d.appendleft([nowh+i, noww+j])
                elif s2[nowh+i][noww+j] != '#':
                    if s2[nowh+i][noww+j] > s2[nowh][noww]:
                        s2[nowh+i][noww+j] = s2[nowh][noww]
                        d.appendleft([nowh+i, noww+j])
        for i in [-2,-1,0,1,2]:
            for j in [-2,-1,0,1,2]:
                if ((0 <= nowh+i < h) and (0 <= noww+j < w)):
                    if s2[nowh+i][noww+j] == '.':
                        s2[nowh+i][noww+j] = s2[nowh][noww]+1
                        d.append([nowh+i, noww+j])
                    elif s2[nowh+i][noww+j] != '#':
                        if s2[nowh+i][noww+j] > s2[nowh][noww]+1:
                            s2[nowh+i][noww+j] = s2[nowh][noww]+1
                            d.append([nowh+i, noww+j])
    if s2[Dh][Dw] == '.':
        print(-1)
    else:
        print(s2[Dh][Dw])
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 195232
#include <cmath>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

const long long lim = 40000000;
const long long inf = 0x3f3f3f3f3f3f3f3f;

signed main(void)
{
	int n, m, s; cin >> n >> m >> s;

	vector<pair<pair<int, int>, int > > edge;

	for (int i = 0, u, v, w; i < m; ++i)
	{
		cin >> u >> v >> w;
		edge.push_back(make_pair(make_pair(u, v), w));
	}

	vector<long long> dis(n); for (auto &i : dis)i = inf; dis[s] = 0;

	for (int i = 0; i < n; ++i)for (auto j : edge)
		if (dis[j.first.second] > dis[j.first.first] + j.second)
			dis[j.first.second] = dis[j.first.first] + j.second;

	for (auto i : edge)if (dis[i.first.second] > dis[i.first.first] + i.second)
		if (dis[i.first.second] <= lim)return cout << "NEGATIVE CYCLE" << endl, 0;

	for (auto i : dis)if (i < lim)cout << i << endl; else cout << "INF" << endl;
}

Measured memory_bytes: 3116
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000
using ll = long long;
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);

}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans = 0, n = 0, m = 0, count = 0, sum = 0;
	llint k, a, b;
	bool check = false;
	string ss;
	vector<llint> array;
	vector<char> ch;
	cin >>ss;
	if (ss == "ABC")cout << "ARC" << endl;
	else cout << "ABC" << endl;
	
	please AC;
}


Measured memory_bytes: 3616
mod = 1000000007

N = int(input())

pos = []
neg = []
zer = []
inf = []
sol = 0

###除外すべき組み合わせの個数を数える
NG = []

for i in range(N):
    a,b = map(int,input().split())
    if a*b > 0:
        pos.append((abs(a),abs(b)))
    elif a*b < 0:
        neg.append((-abs(a),abs(b)))
    elif a == 0 and b != 0:
        inf.append((0,b))
    elif a != 0 and b == 0:
        zer.append((a,0))
    else:
        sol += 1

NG.append((len(inf),len(zer)))
free = len(pos)+len(neg)


# 以下しばらくneg,posに含まれるものに関する議論

pos.sort(key=lambda x:(x[1]/x[0]))
neg.sort(key=lambda x:(x[1]/x[0]))

x = 0
y = 0


while (x < len(pos) and y < len(neg)):
    if pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] == 0:
        s = 1
        t = 1
        while x+1 < len(pos) and pos[x+1][0]*neg[y][0]+pos[x+1][1]*neg[y][1] == 0:
            x += 1
            s += 1
        while y+1 < len(neg) and pos[x][0]*neg[y+1][0]+pos[x][1]*neg[y+1][1] == 0:
            y += 1
            t += 1
        NG.append((s,t))
        x += 1
        y += 1
        free -= (s+t)
        continue


    if x >= len(pos)-1 and y >= len(neg)-1:
        break

    elif y+1 < len(neg) and pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] > 0:
        y += 1
    elif x+1 < len(pos) and pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] < 0:
        x += 1
    elif x >= len(pos)-1:
        y += 1
    elif y >= len(neg)-1:
        x += 1

ans = pow(2,free,mod)

for s,t in NG:
    # s個のうち1個以上入れる or t個のうち1個以上入れる or どちらも1つも入れない
    ans *= pow(2,s,mod)-1 +pow(2,t,mod)-1 +1
    ans %= mod

#print('free',free)
#print('NG',NG)

# 1つも選ばないものの除外、solは単体で選べばOK
print((ans+sol-1)%mod)



Measured memory_bytes: 101380
#!/usr/bin/env python3
import sys
import numpy as np
input = sys.stdin.readline

a, b = map(int, input().split())
c, d = map(int, input().split())
t = int(input())
if b==d :
    print('NO')
elif (abs(a-c)/(b-d))<= t and d<b :
    print('YES')
else:
    print('NO')

Measured memory_bytes: 27128
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;


const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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 h, w;
vector<string> v(400);
class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
    vector<ll> siz_B;
    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1), siz_B(sz_,0)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        par.resize(sz_);
        siz.assign(sz_, 1);
        siz_B.assign(sz_, 0);
        for (ll i = 0; i < sz_; ++i){
            par[i] = i;
            if (v[i / w][i % w] == '#')
            {
                siz_B[i]=1;
            }
        }
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        siz_B[x]+=siz_B[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
    ll size_B(ll x){
        return siz_B[root(x)];
    }
};

int main()
{
    cin >> h >> w;
    REP(i,h){
        cin >> v[i];
    }
    UnionFind uf(h * w);
    uf.init(h*w);
    REP(i,h){
        REP(j,w){
            if(j!=w-1&&v[i][j]!=v[i][j+1]){
                uf.merge(i*w+j,i*w+j+1);
            }
            if(i!=h-1&&v[i][j]!=v[i+1][j]){
                uf.merge(i*w+j,(i+1)*w+j);
            }
        }
    }
    set<ll> ne;
    REP(i,h){
        REP(j,w){
            ne.insert(uf.root(i*w+j));
        }
    }
    ll ans=0;
    for(auto& k:ne){
        ans+=(uf.size(k)-uf.size_B(k))*(uf.size_B(k));
    }
    cout << ans << endl;
}


Measured memory_bytes: 13216
/*----------------*/
/* 	^_HAR HAR MAHADEV_^
   	|Om namah shivaya|
*/
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pb(temp) push_back(temp)
#define mp make_pair
#define mod 1000000007
#define br "\n"
//using namespace boost::multiprecision;
using namespace std ;
typedef unsigned long long int ulli;

ulli gcd(ulli x,ulli y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
ulli factorial(ulli n)
{
    if (n == 0)
    return 1;
    return n * factorial(n - 1);
}
ll findS(ll s)
{
	return (sqrtl(8*s + 1) - 1)/2;
}
ll prime(ll a){
    if(a==1)return 0;
    if(a==2 || a==3)return true;
    if(a%2==0 ||a%3==0)return 0;
    for(ll i=5;i<=sqrt(a);i+=6)
        if(a%i==0 || a%(i+2)==0)
            return 0;

    return 1;
}
ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % mod;
    p = (p * p) % mod;

    return (y%2 == 0)? p : (x * p) % mod;
}
ll nCr(ll n,ll k)
{
    ll C[k+1];
    //memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%(ll)(1e9 + 7);
    }
    return C[k];
}
ll LOGN(ll n , ll r){
	return (n > r-1) ? (1 + LOGN(n / r , r)) : 0 ;
}
void dfs(vector<ll> v[], bool visited[], ll current_node){
	visited[current_node]=true;
	for(ll nxt_node : v[current_node]){
		if(visited[nxt_node]==false){
			dfs(v , visited, nxt_node);
		}
	}
	return;
}

void bfs(vector<ll> v[], bool visited[], ll root){

    int current_node;
    queue<int> q;

    q.push(root);

    while(!q.empty()){

        current_node=q.front();

        visited[current_node]=true;

        for(int x:v[current_node])
            if(!visited[x])
                q.push(x);
    }
}
int main(){
	fast;
	int n ;cin >> n ;
	string s ;
	cin >> s ;
	int cnt = 0 ;
	f(i,0,n-2){
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')cnt ++ ;
	}
	cout << cnt ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;
llint mod = 1000000007;

int gcd(int x, int y) {
  int M = max(x, y);
  int m = min(x, y);
  while (M%m!=0) {
    int p = M % m;
    M = m;
    m = p;
  }
  return m;
}

int main() {
  int n;
  cin >> n;
  int count = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = i; j < n + 1; j++) {
      for (int k = j; k < n + 1; k++) {
        int g = gcd(i, gcd(j, k));
        if (i == j && j == k) {
          count += g;
        }
        else if (i != j && j != k && k != i) {
          count += 6 * g;
        }
        else {
          count += 3 * g;
        }
      }
    }
  }
  cout << count <<endl;
} 

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

template<int mod>
struct ModInt{
	int x;

	ModInt() : x(0){}
	ModInt(long long y) : x(y>=0 ? y%mod : (mod-(-y)%mod)){}

	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}

	ModInt operator-() const{return ModInt(-x);}
	ModInt operator+(const ModInt &p) const{return ModInt (*this)+=p;}
	ModInt operator-(const ModInt &p) const{return ModInt (*this)-=p;}
	ModInt operator*(const ModInt &p) const{return ModInt (*this)*=p;}
	ModInt operator/(const ModInt &p) const{return ModInt (*this)/=p;}
	bool operator==(const ModInt &p) const{return x==p.x;}
	bool operator!=(const ModInt &p) const{return x!=p.x;}
	friend ostream &operator<<(ostream &os, const ModInt &p){return os<<p.x;}
	friend istream &operator>>(istream &is,ModInt &a){
		int t;
		is>>t;
		a=ModInt<mod>(t);
		return (is);
	}

	ModInt inverse() const{
		int a=x, b=mod, u=1, v=0, t;
		while(b>0){
			t=a/b;
			a-=t*b;
			swap(a,b);
			u-=t*v;
			swap(u,v);
		}
		return ModInt(u);
	}
	
	ModInt pow(int e) const{
		long long a=1,p=x;
		while(e>0){
			if(e%2==0){p=(p*p)%mod; e/=2;}
			else {a=(a*p)%mod; e--;}
		}
		return ModInt(a);
	}
};

const int p=1000000007;
int mod_pow(int a,int N){
	if(N==0)return 1;
	if(N%2==1)return (a*mod_pow(a,N-1))%p;
	int tmp=mod_pow(a,N/2);
	return (tmp*tmp)%p;
}

using modint=ModInt<p>;

signed main(){
	int N,K; cin>>N>>K;
	vector<modint> div(K+1,0);
	modint ans=0;
	for(int d=K;d>0;d--){
		div[d]=mod_pow(K/d,N);
		int now=2*d;
		while(now<=K){
			div[d]-=div[now];
			now+=d;
		}
	}
	for(int i=1;i<=K;i++)ans+=modint(i)*div[i];
	cout<<ans<<endl;
}



Measured memory_bytes: 3952
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	X := getInt()
	x := (X - 400) / 200
	out(8 - x)
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  for (int i = 0; i < N; i++){
    cin >> V[i];
  }
  int ans = -INF;
  for (int i = 0; i <= N; i++){
    for (int j = 0; j <= N - i; j++){
      if (i + j <= K){
        vector<int> A;
        for (int k = 0; k < i; k++){
          A.push_back(V[k]);
        }
        for (int k = 0; k < j; k++){
          A.push_back(V[N - 1 - k]);
        }
        sort(A.begin(), A.end());
        int C = K - (i + j);
        int sum = 0;
        for (int k = 0; k < i + j; k++){
          if (k < C){
            sum += max(A[k], 0);
          } else {
            sum += A[k];
          }
        }
        ans = max(ans, sum);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        int min = (int)Math.max(-1000000, x-k+1);
        int max = (int)Math.min(1000000, x+k-1);
        for(int i = min; i<=max; i++) System.out.print(i + " ");
        System.out.println();
    }
}

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

template <typename T, T (*op)(T, T), T id>
struct SegmentTree {
    int size;
    vector<T> node;

    SegmentTree(int n) {
        size = 1;
        while (size < n) size <<= 1;
        node.resize(2 * size, id);
    }

    T operator[](int k) {
        return node[k + size];
    }

    void build(const vector<T>& v) {
        for (int k = 0; k < v.size(); k++) node[k + size] = v[k];
        for (int k = size - 1; k > 0; k--) node[k] = op(node[2 * k], node[2 * k + 1]);
    }

    void update(int k, const T& x) {
        k += size;
        node[k] = x;
        while (k >>= 1) {
            node[k] = op(node[2 * k], node[2 * k + 1]);
        }
    }

    T query(int l, int r) {
        T L = id, R = id;
        for (l += size, r += size; l < r; l >>= 1, r >>= 1) {
            if (l & 1) L = op(L, node[l++]);
            if (r & 1) R = op(node[--r], R);
        }
        return op(L, R);
    }

    template <typename F>
    int find_subtree(int l, const F& check, T& x, bool type) {
        while (l < size) {
            T nxt = type ? op(node[2 * l + type], x) : op(x, node[2 * l + type]);
            if (check(nxt)) l = 2 * l + type;
            else x = nxt, l = 2 * l + 1 - type;
        }
        return l - size;
    }

    template <typename F>
    int find_first(int l, const F& check) {
        T cur = id;
        int r = 2 * size;
        for (l += size; l < r; l >>= 1, r >>= 1) {
            if (l & 1) {
                T nxt = op(cur, node[l]);
                if (check(nxt)) return find_subtree(l, check, cur, false);
                cur = nxt;
                l++;
            }
        }
        return -1;
    }

    template <typename F>
    int find_last(int r, const F& check) {
        T cur = id;
        int l = size;
        for (r += size; l < r; l >>= 1, r >>= 1) {
            if (r & 1) {
                r--;
                T nxt = op(node[r], cur);
                if (check(nxt)) return find_subtree(r, check, cur, true);
                cur = nxt;
            }
        }
        return -1;
    }
};

int op(int a, int b) {
    return max(a, b);
}

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

    int N, Q;
    cin >> N >> Q;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    SegmentTree<int, op, 0> st(N);
    st.build(A);
    for (int i = 0; i < Q; i++) {
        int T;
        cin >> T;
        if (T == 1) {
            int X, V;
            cin >> X >> V;
            st.update(X - 1, V);
        } else if (T == 2) {
            int L, R;
            cin >> L >> R;
            cout << st.query(L - 1, R) << "\n";
        } else {
            int X, V;
            cin >> X >> V;
            int j = st.find_first(X - 1, [&](int v) { return v >= V; });
            cout << (j == -1 ? N + 1 : j + 1) << "\n";
        }
    }
}

Measured memory_bytes: 6120
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

using pt = complex<ld>;
const int N = 60;
int n, k;
ld x[N], y[N], c[N];

vector<pt> cxc(pt c1, ld r1, pt c2, ld r2) {
  ld dq = norm(c1-c2), rq=r1*r1-r2*r2;
  pt c = (c1+c2)+(c2-c1)*rq/dq; c*=.5;
  ld dt=2*dq*(r1*r1+r2*r2)-dq*dq-rq*rq;
  if (dt < -EPS) return {};
  if (dt < EPS) return {c};
  dt=sqrt(dt)/2/dq;
  pt d = (c2-c1)*pt(0,1)*dt;
  return {c+d, c-d};
}

bool poss(ld t) {
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      auto pts = cxc({x[i], y[i]}, t/c[i], {x[j], y[j]}, t/c[j]);
      for (pt p : pts) {
        int cnt = 0;
        for (int l = 0; l < n; ++l) {
          pt o = {x[l], y[l]};
          ld d = abs(o-p);
          if (d - EPS < t/c[l]) {
            cnt++;
            if (cnt >= k) return true;
          }
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    pt p(x[i], y[i]);
    int cnt = 0;
    for (int l = 0; l < n; ++l) {
      pt o = {x[l], y[l]};
      ld d = abs(o-p);
      if (d - EPS < t/c[l]) {
        cnt++;
        if (cnt >= k) return true;
      }
    }
  }
  return false;
}

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> c[i];
  }
  ld lo = 0, hi = 1e10;
  while (abs(hi - lo) > EPS) {
    ld mid = (lo+hi)/2;
    if (poss(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << hi << nl;

  return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define int long long
#define print(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = (1LL << 30);
const ll MOD = 1000000007;

//=============================================================
//=============================================================
int N;
vector<int> p;
void solve()
{
    sort(p.rbegin(),p.rend());
    p[0] /= 2;
    int ans = 0;
    for (auto x: p)ans += x;
    cout<<ans<<endl;
}
signed main()
{
    cin>>N;
    p = vector<int>(N);
    rep(i,N)cin>>p[i];



    solve();
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int lcm(int a,int b){
  return (a*b)/__gcd(a,b);	
}
void solve(){
   int n;
   cin>>n;
   cout<<lcm(2,n)<<endl;
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}

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

int main() {
  int N,K,now;
  cin >> N >> K;
  now = 1;
  for(int i=0; i < N; i++){
    if(now < K){
      now *=2;
    }
    else {
      now += K;
    }
  }
  cout << now <<endl;
 }
 


Measured memory_bytes: 256
program main
	implicit none
    integer(16)::n,a,b,d,ans
    read(*,*) n,a,b
    d=n/(a+b)
    
    ans=d*a
    if(n-d*(a+b)>a)then
    	ans=ans+a
    else
    	ans=ans+n-d*(a+b)
    end if
    write(*,*) ans
    stop
end program main

    



Measured memory_bytes: 2720
N = int(input())
resulter = "abcdefghijklmnopqrstuvwxyz"

ans_list = []
while True:
    N = N - 1
    mod = N % 26
    ans_list.append(resulter[mod])
    N = N // 26
    if N < 1:
        break

ans_list.reverse()
print("".join(ans_list))



Measured memory_bytes: 9112
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;


int main() {
	int A, B, K;
	cin >> A >> B >> K;
	if (B - A <= K * 2 - 1) {
		for (int i = 0; i <= B - A ; i++) {
			cout << A + i << endl;
		}
	} else {
		for (int i = 0; i < K; i++) {
			cout << A + i << endl;
		}
		for (int i = 0; i < K; i++) {
			cout << B - K + 1 + i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;

struct P{
	int x,y;
};
P p[40];

P operator - (P a,P b){
	return {a.x - b.x, a.y - b.y};
}

int cross(P a,P b){
	return a.x * b.y - a.y * b.x;
}
P bP;
bool operator < (const P &a,const P &b){
	return cross(a-bP,b-bP) > 0;
};
int cmp(int i,int j){
	return p[i] < p[j];
}
int area(int i,int j,int k){
	return cross(p[j]-p[i],p[k]-p[i]);
}

// dp[1st][k][k-1th][kth]
int dp[40][41][40][40];
int prv[40][41][40][40];

int main(){
	for(int i = 0 ; i < 40 ; i++)
		for(int j = 0 ; j < 41 ; j++)
			for(int k = 0 ; k < 40 ; k++)
				for(int l = 0 ; l < 40 ; l++)
					dp[i][j][k][l] = inf;

	int N;
	cin >> N;
	for(int i = 0 ; i < N ; i++){
		cin >> p[i].x >> p[i].y;
	}
	for(int i = 0 ; i < N ; i++){
		vector<int> id;
		for(int j = 0 ; j < N ; j++)
			if( i != j && p[i].x <= p[j].x ) id.push_back(j);
		
		bP = p[i];
		sort(id.begin(),id.end(),cmp);
		for(int J = 0 ; J < id.size() ; J++){
			int j = id[J];
			for(int K = J+1 ; K < id.size() ; K++){
				int k = id[K];
				if( cmp(j,k) ){
					dp[i][3][j][k] = area(i,j,k);
					prv[i][3][j][k] = i;
				}
			}
		}
		for(int s = 4 ; s <= 40 ; s++)
			for(int J = 0 ; J < id.size() ; J++){
				int j = id[J];
				for(int K = J+1 ; K < id.size() ; K++){
					int k = id[K];
					if( dp[i][s-1][j][k] == inf ) continue;
					for(int L = K+1 ; L < id.size() ; L++){
						int l = id[L];
						if( cross(p[k]-p[j],p[l]-p[j]) > 0  && dp[i][s][k][l] > dp[i][s-1][j][k] + area(i,k,l) ){
							dp[i][s][k][l] = dp[i][s-1][j][k] + area(i,k,l);
							prv[i][s][k][l] = j;
						}
					}
				}
			}
	}
	int Q;
	cin >> Q;
	for(int i = 0 ; i < Q ; i++){
		int s;
		cin >> s;
		int a,b,c;
		int ans = inf;
		for(int j = 0 ; j < N ; j++){
			for(int k = 0 ; k < N ; k++){
				for(int l = 0 ; l < N ; l++){
					if( ans > dp[j][s][k][l] ){
						ans = dp[j][s][k][l];
						a = j;
						b = k;
						c = l;
					}
				}
			}
		}
		if( ans == inf ) cout << "NA" << endl;
		else{
			vector<int> idx;
			while(s > 3 ){
				idx.push_back(c);
				int t = prv[a][s][b][c];
				c = b;
				b = t;
				s--;
			}
			idx.push_back(c);
			idx.push_back(b);
			idx.push_back(a);
			reverse(idx.begin(),idx.end());
			int lowX = inf;
			int lowY = inf;
			int pos;
			for(int j = 0 ; j < idx.size() ; j++)
				if( lowY > p[idx[j]].y ){
					lowY = p[idx[j]].y;
					lowX = p[idx[j]].x;
					pos = j;
				}else if( lowY == p[idx[j]].y ){
					if( lowX > p[idx[j]].x ){
						lowX = p[idx[j]].x;
						pos = j;
					}
				}
			rotate(idx.begin(),idx.begin()+pos,idx.end());
			for(int j = 0 ; j < idx.size() ; j++)
				cout << idx[j]+1 << " \n"[j+1==idx.size()];
		}

	}
}

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

#define mp(x, y) make_pair((x), (y))

typedef long long ll;

ll ten[42];

int dig;

int main()
{
	ten[1]=1;
	for(int i=2; i<=14; i++) ten[i]=10*ten[i-1];

	dig=-1;
	for(int i=2; i<=10; i++) {
		printf("? %lld\n", ten[i]);
		fflush(stdout);
		char c;
		scanf(" %c", &c);
		if(c=='N') {
			dig=i-1;
			break;
		}
	}
	if(dig==-1) {
		for(int i=9; i>=1; i--) {
			printf("? %lld\n", ten[i+1]-1);
			fflush(stdout);
			char c;
			scanf(" %c", &c);
			if(c=='N') {
				printf("! %lld\n", ten[i+1]);
				fflush(stdout);
				return 0;
			}
		}
		printf("! 1\n");
		fflush(stdout);
		return 0;
	}

	ll l=ten[dig];
	ll r=ten[dig+1]-1;

	while(l<r) {
		ll m=(l+r)/2;
		printf("? %lld\n", 10*m);
		fflush(stdout);
		char c;
		scanf(" %c", &c);
		if(c=='Y') r=m;
		else l=m+1;
	}
	printf("! %lld\n", l);
	fflush(stdout);

	return 0;
}

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

int main() {
    long long int n, b;
    std::cin >> n;
    std::vector<long long int> a(n);
 
    for (long long int i = 0; i < n; i++) {
        std::cin >> a[i];
        a[i] -= i;
    }
 
    std::sort(a.begin(), a.end());
    if (n % 2 == 0) b = a[n/2];
    else b = a[(n-1)/2];
 
    long long ret = 0;
 
    for (auto j : a) {
        ret += std::abs(j - b);
    }
 
    std::cout << ret << std::endl;
 
    return 0;
}

Measured memory_bytes: 1792
package main

import "fmt"

func main() {
	// Code for B - Contest with Drinks Easy
	var N int
	fmt.Scanf("%d", &N)

	var sum int = 0
	T := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &T[i])
		sum += T[i]
	}

	var M int
	fmt.Scanf("%d", &M)
	var P, X int
	for i := 0; i < M; i++ {
		fmt.Scanf("%d %d", &P, &X)
		fmt.Println(sum - T[P-1] + X)
	}

}


Measured memory_bytes: 1844
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int a,b;
  string s;
  rep(i,9){
    cin>>s>>a>>b;
    cout<<s<<" "<<a+b<<" "<<200*a+300*b<<endl;
  }
}

Measured memory_bytes: 3176
// Tree_Walk.cs

using System;
using System.Collections.Generic;

class Tree_Walk {

    public static void Main() {

        int n = int.Parse(Console.ReadLine());

        var node = new List<Node>();

        for(int i = 0; i < n; i++) node.Add(new Node());

        for(int i = 0; i < n; i++) {

            string[] str = Console.ReadLine().Split(' ');
            int ID = int.Parse(str[0]);
            int left = int.Parse(str[1]);
            int right = int.Parse(str[2]);

            if(left != -1) {
                node[ID].left = left;
                node[left].parent = ID;
            }

            if(right != -1) {
                node[ID].right = right;
                node[right].parent = ID;
            }
        }

        for(int i = 0; i < n; i++) {
            if(node[i].parent == -1) {

                Console.WriteLine("Preorder");
                Node.preorder(node, i);
                Console.WriteLine();
                Console.WriteLine("Inorder");
                Node.inorder(node, i);
                Console.WriteLine();
                Console.WriteLine("Postorder");
                Node.postorder(node, i);
                Console.WriteLine();

            }
        }

    }
}

class Node {

    public int right, left, parent;

    public Node() {
        right = left = parent = -1;
    }

    public static void preorder(List<Node> node, int ID) {

        Console.Write(" {0}", ID);

        if(node[ID].left != -1) preorder(node, node[ID].left);
        if(node[ID].right != -1) preorder(node, node[ID].right);
    }

    public static void inorder(List<Node> node, int ID) {

        if(node[ID].left != -1) inorder(node, node[ID].left);
        
        Console.Write(" {0}", ID);

        if(node[ID].right != -1) inorder(node, node[ID].right);
    }

    public static void postorder(List<Node> node, int ID) {

        if(node[ID].left != -1) postorder(node, node[ID].left);
        if(node[ID].right != -1) postorder(node, node[ID].right);
        
        Console.Write(" {0}", ID);
    }

}

Measured memory_bytes: 9212
<?php
$myCoin = 0;

fscanf(STDIN,"%d %d",$buttonA,$buttonB);

for($i=0;$i<=1;$i++){
if($buttonA > $buttonB){
    $myCoin+=$buttonA;
    $buttonA--;
}else{
    $myCoin+=$buttonB;
    $buttonB--;
}
}
echo $myCoin;

?>


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int x, a, y, b, c;
ll p[MN], q[MN], r[MN];
vll bst;

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

    cin >> x >> y >> a >> b >> c;
    F0R(i, a) cin >> p[i];
    F0R(i, b) cin >> q[i];
    F0R(i, c) cin >> r[i];
    sort(p, p+a, greater<ll>() );
    sort(q, q+b, greater<ll>() );
    sort(r, r+c, greater<ll>() );
    F0R(i, x) bst.pb(p[i]);
    F0R(i, y) bst.pb(q[i]);
    F0R(i, c) bst.pb(r[i]);
    sort(bst.begin(), bst.end(), greater<ll>() );

    ll sm = 0;
    F0R(i, x+y){
        sm += bst[i];
    }
    cout << sm << "\n";
    
    return 0;
}


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


void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

#define ll long long
#define ld long double
#define ull unsigned long long
#define ull unsigned long long
#define mod 1000000007
#define pi (3.1415926)

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

#define scd(a)  scanf("%lld",&a)
#define scdd(a,b)	scanf("%lld%lld",&a,&b)
#define scddd(a,b,c)	scanf("%lld%lld%lld",&a,&b,&c)
#define ptab(a)	printf("%lld ",a)
#define pdn(a)	printf("%lld\n",a)
#define pddn(a,b)	printf("%lld %lld\n",a,b)
#define pdddn(a,b,c)	printf("%lld %lld %lld\n",a,b,c)

#define forr(n) for(ll i=0;i<n;i++)
#define rev(n) for(ll i=n-1;i>=0;i--)
#define forp(x, y) for(ll i=x;i<y;i++)
#define loop( j, k, in) for (ll i=j ; i<k ; i+=in)

#define in  cin>>
#define out cout<<
#define en "\n"
#define sp " "
#define eps 1.0E-14


int N;
char ans[111];

void DFS(int cur,int mx){
//    printf("cur = %d\n",cur);
    if(cur==N){
        ans[N]='\0';
        printf("%s\n",ans);
        return;
    }
    for(int i=0;i<=cur;i++){
        ans[cur]='a'+i;
        DFS(cur+1,max(mx,i));
        if(i>mx) break;
    }
}

void work(){
    scanf("%d",&N);
    DFS(0,0);
}

ll sum (int n ){return ((n*(n+1)) / 2) ;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main()
{
    init();

    work();
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
	int h,m,s;
	while(1){
        scanf("%d %d %d",&h,&m,&s);
        if(h == -1 && m == -1 && s == -1) break;
        int ans1 = 7200;
        int ans2 = 7200;
        ans1 -= h*3600 + m * 60 + s;
        ans2 = ans1 * 3;

        printf("%02d:%02d:%02d\n%02d:%02d:%02d\n",ans1/3600,(ans1%3600)/60,ans1%60,ans2/3600,(ans2%3600)/60,ans2%60);
	}

	return 0;
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc080.contest.atcoder.jp/tasks/arc080_a>
問題文============================================================
 長さ N の数列 a=(a1,a2,…,aN) があります。 各 ai は正の整数です。
 
 すぬけ君の目標は、a の要素を自由に並べ替え、次の条件が成り立つようにすることです。
 
 各 1≤i≤N−1 について、ai と ai+1 の積は 4 の倍数である。
 すぬけ君が目標を達成できるか判定してください。

=================================================================

解説=============================================================

 まず、4の倍数の数値(4の倍数を v 、４の倍数でない値を x とする）が存在する時
 
 x v x v x v x v ... とおいていけば条件を満たす
 つまり、4の倍数である値の個数を V とすると 2*V 分カバーできる
 
 注意：
     x v x v x v ... x v x
 で数列が終了する時 2*V + 1 ＝＝　N をカバーできる
 
 2*c で　数列全てをカバーできない時, ２の倍数をb とすると
 
 x v x v x v x v ... x v b b b b b b .... b
 
 とおいていけば条件を満たす
 
 よって上の注意ケースを除いて,２の倍数の個数とBとすると
 
 2*V + B >= N
 
 となっていれば条件を満たす

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> a(N);
    for(auto & in:a) cin >> in;
    ll four = 0, two = 0;
    for(int i = 0; i < N;i++){
        if(a[i]%4 == 0) four++;
        if(a[i]%2 == 0) two++;
    }
    two -= four;
    if(four*2 + 1 >= N){
        cout << "Yes" << endl;
        return 0;
    }
    if(four*2 + two >= N){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
 
int main(){
    long long int N, sum = 0;
    scanf("%lld", &N);
    for (int i=0 ; i<=N ; i++){
        if (i%3 == 0 || i%5 == 0 ){
            continue;
        }
        else {
            sum+=i;
        }
    }
    printf("%lld", sum);

    return 0;
}

Measured memory_bytes: 1704
/*#define _USE_MATH_DEFINES
#include<cmath>*/
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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(nullptr);
	ios::sync_with_stdio(false);

	int n; cin >> n;
	vector<int>p(n);
	rep(i, n)cin >> p[i];
	vector<int>q(n);
	rep(i, n)cin >> q[i];
	vector<int>a = p;
	sort(all(a));
	int x, y;
	int cnt = 1;
	do {
		vector<int>vec;
		for (auto v : a) {
			vec.push_back(v);
		}
		if (vec == p)x = cnt;
		if (vec == q)y = cnt;
		++cnt;
	} while (next_permutation(all(a)));
	cout << abs(x-y) << "\n";


	return 0;
}


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

namespace CS.Solve1
{
    class Program
    {
        static void Main(string[] args)
        {
            int givenN = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int[] countsW = new int[givenN + 1];
            countsW[0] = 0;
            for(int i = 0; i < givenN; i++)
            {
                if (s[i] == 'W')
                {
                    countsW[i + 1] = countsW[i] + 1;
                }
                else
                {
                    countsW[i + 1] = countsW[i];
                }
            }
            int result = givenN;
            for(int i = 0; i < givenN; i++)
            {
                int leftW = countsW[i];
                int rightW = countsW[givenN] - countsW[i + 1];
                int rightE = givenN - 1 - i - rightW;
                result = Math.Min(result, leftW + rightE);
            }

            Console.WriteLine(result);

            
        }
    }
}


Measured memory_bytes: 13280
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var N=Int32.Parse(Console.ReadLine());
        var array = new int[N + 1];
        for (int i=2;i<=N;++i)
        {
            var num = i;
            for (int j=2;j<=N;++j)
            {
                var count = 0;
                while (num%j==0)
                {
                    num /= j;
                    count++;
                }
                array[j] += count;
                if (num == 1) break;
            }
        }
        var counter = 1L;
        for (int i=2;i<=N;++i)
        {
            if (array[i] == 0) continue;
            var num = array[i] + 1;
            counter = (counter * num) % 1000000007;
        }
        Console.WriteLine(counter);
    }
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  vector<int> vec = {a,b,c};
	sort(vec.begin(),vec.end());

  
  cout << vec.at(0) + vec.at(1) << endl;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
    int n;
    std::string s;
    cin>>n;
    cin>>s;
    int cum_w[300003]={};
    int cum_e[300003]={};
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='W')
        {
            cum_w[i]=cum_w[i-1]+1;
            cum_e[i]=cum_e[i-1];
        }
        else
        {
            cum_w[i]=cum_w[i-1];
            cum_e[i]=cum_e[i-1]+1;
        }
    }

    int min=300003;
    int m1;
    for(int i=1;i<=n;i++)
    {
        m1=cum_w[i-1]+cum_e[n]-cum_e[i];
        if(m1<min)min=m1;
    }

    cout<<min<<endl;
	
    return 0;
}


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

int main(void){
    int n;
    cin >> n;
    
    vector<long long> a(n+1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    
    long long money = 1000;
    long long kabu = 0;
    vector<int> check(n+1,0);
    for (int i = 1; i <= n-1; i++){
        if (a[i+1] - a[i] > 0) check[i] = 1;
    }
    
    for (int i = 1; i <= n-1; i++){
        
        if (check[i] == 1 ){
          if(money >= a[i]){
            kabu = money / a[i];
            money = money -  (kabu * a[i]);
          }
        }
        else{
            money += (kabu * a[i]);
            kabu = 0;
        }
    }
    
    if (kabu > 0) money += (kabu * a[n]);
    cout << money << endl;
    
}

/*
priority: https://blacktanktop.hatenablog.com/entry/2020/07/26/100829
*/


Measured memory_bytes: 3648
import sys, collections
sys.setrecursionlimit(10000000)
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", \
    "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

def solve():
    input = sys.stdin.readline
    mod = 7 + 10 ** 9
    N = int(input())
    A = [int(a) for a in input().split()]
    if len(set(A)) > 3: print("No")
    elif len(set(A)) == 3:
        B = list(set(A))
        count = [0, 0, 0]
        for a in A:
            if a == B[0]: count[0] += 1
            elif a == B[1]: count[1] += 1
            else: count[2] += 1
        if count[0] == count[1] and count[1] == count[2] and B[0] ^ B[1] == B[2]: print("Yes")
        else: print("No")
    elif len(set(A)) == 2:
        if 0 not in A: print("No")
        else:
            B = list(set(A))
            B.sort()
            count = [0, 0]
            for a in A:
                if a == 0: count[0] += 1
                else: count[1] += 1
            if count[0] * 2 == count[1]: print("Yes")
            else: print("No")
    else:
        if A[0] == 0: print("Yes")
        else: print("No")

    return 0

if __name__ == "__main__":
    solve()

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

typedef long long unsigned ll;

const int N = 200002;

char cot[N];
int main(){

    //freopen("test.in","r",stdin);

    int lo,hi;

    scanf("%s",cot);
    hi=strlen(cot);
    lo=0;
    while(cot[lo]!='A')lo++;
    while(cot[hi]!='Z')hi--;

    cout<<hi-lo+1<<endl;


    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> in(h);
  for (int i = 0; i < h; i++) cin >> in[i];
  in.push_back("");
  for (int j = 0; j < w; j++) {
    if (j == w - 1) in[h].push_back('#');
    else in[h].push_back('.');
  }
  int c = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < c; j++) {
      if (in[i][j] == '#') {
        cout << "Impossible\n";
        return 0;
      }
    }
    for (int j = c; j < w; j++) {
      if (in[i + 1][j] == '#') {
        c = j;
        break;
      }
    }
    for (int j = c + 1; j < w; j++) {
      if (in[i][j] == '#') {
        cout << "Impossible\n";
        return 0;
      }
    }
  }
  cout << "Possible\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val a = cin.nextInt()
    val b = cin.nextInt()
    val h = cin.nextInt()
    val w = cin.nextInt()
    /* 
    val minus = (b/w) * (a/h)
    val plus = a*b - minus

    val minus_value = -h*w

    if (plus + minus*minus_value > 0) {
        println("Yes")
        for (i in 0..a-1) {
            var s = ""
            for (j in 0..b-1) {
                if ((j+1) % w == 0 && (i+1) % h == 0) {
                    s += minus_value
                } else {
                    s += 1
                }
                if (j != b-1) {
                    s += " "
                }
            }
            println(s)
        }
    } else {
        println("No")
    }
    */

    var minus = -1000001
    var plus = 1000000
    if (b%w == 0 && a%h == 0) {
        println("No")
    } else {
        println("Yes")

        for (i in 0..a-1) {
            var s = ""
            for (j in 0..b-1) {
                if (i%h == 0 && j%w == 0) {
                    s += plus
                } else if ((i+1)%h == 0 && (j+1)%w == 0) {
                    s += minus
                } else {
                    s += 0
                }
                s += " "
            }
            println(s)
        }
    }
}

Measured memory_bytes: 117248
#include <stdio.h>

int main()
{
	char input[4];
	int ans = 0;
	scanf("%s", input);
	
	if(input[0] == '+') ++ans;
	else --ans;
	if(input[1] == '+') ++ans;
	else --ans;
	if(input[2] == '+') ++ans;
	else --ans;
	if(input[3] == '+') ++ans;
	else --ans;

	printf("%d", ans);

	return 0;
}


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

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

    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    vector<pair<int,int>> v;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='B') {
                v.push_back(make_pair(i,j));
            }
        }
    }
    int ans=0;
    int n=v.size();
    vector<pair<int,int>> p;
    int x=v[0].first;
    sort(v.begin(),v.end());
    for(int i=0;i<n;){
        x=v[i].first;
        int ymin=v[i].second, ymax=v[i].second;
        i++;
        while(v[i].first==x){
            ymax=v[i].second;
            i++;
        }
        p.push_back(make_pair(x,ymin));
        p.push_back(make_pair(x,ymax));
        
    }
    int m=p.size();
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            ans = max(ans, abs(p[i].second - p[j].second) + abs(p[i].first - p[j].first));
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 11828