akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

int memo[110][4][2];
signed main() {
  rep(i, 0, 110) rep(j, 0, 4) rep(k, 0, 2) memo[i][j][k] = INF;
  string N;
  int K;
  cin >> N >> K;
  auto dfs = [&](auto fun, int i, int k, bool less) -> int {
    if (k < 0) return 0;
    if (i == sz(N)) {
      return k == 0;
    }
    auto &MEMO = memo[i][k][less];
    if (MEMO != INF) return MEMO;

    int ret = 0;
    if (less) {
      rep(d, 0, 10) { ret += fun(fun, i + 1, k - (d != 0), true); }
    } else {
      {
        int d = N[i] - '0';
        ret += fun(fun, i + 1, k - (d != 0), false);
      }
      rep(d, 0, N[i] - '0') { ret += fun(fun, i + 1, k - (d != 0), true); }
    }
    return MEMO = ret;
  };
  cout << dfs(dfs, 0, K, false) << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue>
#include <set> 
#include <stack>
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 

#include <math.h>
#include <stdlib.h>


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

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

using Graph = vector<vector<int>>;

vector<ll> ans;
map<int, int> mp;

//INT_MAX	2,147,483,647 = 2*1.0e9


void dfs(Graph& _g, int _v, int _p, int _x){
  _x += mp[_v];
  ans[_v] += _x;

  for(auto nv : _g[_v]){
    if(nv == _p) continue;
    dfs(_g, nv, _v, _x);
  }
}


int main(){
  ll N, Q;
  cin >> N >> Q;
  
  Graph g(N);
  ans.assign(N, 0);

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

  
  for(int i = 0; i < Q; i++){
    int p, x; cin >> p >> x;
    p--;
    mp[p]+=x;
  }

  dfs(g, 0, -1, 0);

  cout << ans[0];
  for(int i = 1; i < N; i++){
    cout << " " << ans[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 43008
#include <iostream>

using namespace std;

int S[110][110];

int main(){
	int n,tmp,sum;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> tmp;
			S[i+1][j+1] = S[i+1][j] + S[i][j+1] - S[i][j] + tmp;
		}
	}
	int max = S[1][1];
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			for(int k = 0; k < i; k++){
				for(int l = 0; l < j; l++){
					max = (max > S[i][j] - S[i][l] - S[k][j] + S[k][l]) ? max : S[i][j] - S[i][l] - S[k][j] + S[k][l];
				}
			}
		}
	}
	cout << max << endl;
}

Measured memory_bytes: 1204
n = int(input())
A = list(map(int,input().split()))
 
A.sort(reverse=True)
 
ans = 0
mod = 10**9+7
 
for i in range(n):
    ans = (ans+(i+2)*A[i])%mod
    # print(i,ans)
 
for i in range(n*2-2):
    ans = (ans*2) % mod
 
print(ans)

Measured memory_bytes: 27108
N = int(input())
A = list(map(int,input().split()))

def euclid(a, b):
  while b != 0:
    a, b = b, a % b
  return a

ans = A[0]
for i in range(1, len(A)):
  ans = euclid(ans, A[i])
  
print(ans)

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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define ABS(x, y) ((x) > (y) ? ((x) - (y)) : ((y) - (x)))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int main() {
  int N; scanf("%d", &N);
  int A[N], B[N], C[N];
  for (int i{}; i < N; ++i) scanf("%d", &A[i]);
  for (int i{}; i < N; ++i) {
    scanf("%d", &B[i]);
    C[i] = A[i] - B[i];
  }
  sort(C, C + N);

  set<int> mod;
  int i{}, j{N - 1};
  while (i < N && j >= 0 && C[i] < 0 && C[j] > 0) {
    int move = MIN(-C[i], C[j]);
    C[i] += move;
    C[j] -= move;
    mod.insert(i);
    mod.insert(j);
    if (C[i] == 0) ++i;
    if (C[j] == 0) --j;
  }

  printf("%d\n", i < N && C[i] >= 0 ? mod.size() : -1);
  return 0;
}


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

int order(vector<int> v){
    int n = v.size();
    vector<int> a(n);
    rep(i,n) a[i] = i+1;
    int res = 0;
    do{
        res++;
        bool same = true;
        rep(i,n){
            if (a[i] != v[i]) same = false;
        }
        if (same) break;
    }while(next_permutation(all(a)));
    return res;
}

int main(void){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    cout << abs(order(a) - order(b)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

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

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin >> n;
    vector <double> vs;
    REP(i, n){
        double v; cin >> v;
        vs.push_back(v);
    }
    sort(vs.begin(), vs.end());
    double ans = 0;
    dumparr(vs)
    REP(i, n){
        if (i == 0){
            ans += vs[i] * pow(2, i-n+1);
        } else {
            ans += vs[i] * pow(2, i-n);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

val_x = 0
for i in range(n-1):
    val_x += (i+1) * (n-1-i) * (x[i+1] - x[i])

ans = 0
for i in range(m-1):
    val_y = (i+1) * (m-1-i) * (y[i+1] - y[i])
    ans += val_x * val_y
    ans %= 10**9 + 7

print(ans)


Measured memory_bytes: 18576
sn,bn=map(int,input().split(" "))
fu=[int(sn*(sn-1)/2)]
gr_si=[n for n in range(sn+1)]
siL_gr=[[n] for n in range(sn+1)]
siL_br=[]
for _ in range(bn):
    siL_br.append(list(map(int, input().split(" "))))
siL_br=siL_br[::-1]

for bri in range(bn-1):
    si1,si2=siL_br[bri]
    gr1 = gr_si[si1]
    gr2 = gr_si[si2]
    if gr1==gr2:
        fu.append(fu[bri])
    else:
        lengr1 = len(siL_gr[gr1])
        lengr2 = len(siL_gr[gr2])
        if lengr1<lengr2:
            gr1,gr2=gr2,gr1
        fu.append(fu[bri]-lengr1*lengr2)
        for si in siL_gr[gr2]:
            gr_si[si]=gr1
        siL_gr[gr1]+=siL_gr[gr2]
        siL_gr[gr2]=[]

print(*fu[::-1],sep="\n")

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

int main(){
  string S;
  cin >> S;
  int i = 0, j = S.length() - 1, ans = 0;
  while(j > i){
    if(S.at(i) != S.at(j)){
      ans++;
      if(S.at(i) == 'x') i++;
      else if(S.at(j) == 'x') j--;
      else {
        print(-1);
        return 0;
      }
    }else{
      i++;
      j--;
    }
  }

print(ans);
}

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

int main()
{
    int r, c;
    cin >> r >> c;
    int a[r + 1][c + 1] = {};
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            a[i][c] += a[i][j];
            a[r][j] += a[i][j];
            a[r][c] += a[i][j];
        }
    }
    for (int i = 0; i < r + 1; i++)
    {
        for (int j = 0; j < c + 1; j++)
        {
            if (j == c)
            {
                cout << a[i][j] << endl;
            }
            else
            {
                cout << a[i][j] << " ";
            }
        }
    }
    return 0;
}


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

int main() {
	int n;
	cin>>n;
	
	set<int> s;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			s.insert(i*j);
		}
	}
	
	if(s.count(n))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = INT32_MAX;
const long long int Mod = 1000000007;
const long long int mod = 100000;//10^5
using ll = long long int; //long long int は64bit
using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int,int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////

ll a,b,c;

int main(){
	vi v(3);rep(i,3)cin>>v[i];
	sort(all(v));
	cout<<v[0]*v[1]/2<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

S=input()
ans=0

def rec(s,tmp):
    global ans
    if len(s)==0:
        ans+=tmp
    for i in range(1,len(s)+1):
        rec(s[i:],tmp+int(s[:i]))

rec(S,0)
print(ans)

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

int main(){
	using namespace std;
// 	ios_base::sync_with_stdio(false); 
//     cin.tie(NULL); 

// #ifndef ONLINE_JUDGE 
//     freopen("inputf.in", "r", stdin); 
//     freopen("outputf.in", "w", stdout); 
// #endif

	int n;
	cin >> n;

	int a[n], d[n];


	for(int i = 0; i < n; i++) {
		cin >> a[i];
		d[i] = 0; 
	} 

	d[1] = abs(a[1] - a[0]);
	for(int i = 2; i < n; i++) {
		d[i] = min(abs(a[i] - a[i - 1]) + d[i - 1], abs(a[i] - a[i - 2]) + d[i - 2]);
	}

	cout << d[n - 1];
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using pII = pair<int, int>;
#define fi first
#define se second
const int N = 1e6 + 10, INF = 0x3f3f3f3f;
int n, a[N], ans[N]; pII f[N];  
int main() {
	scanf("%d", &n);
	a[1 << n] = -INF;
	for (int i = 0; i < 1 << n; ++i) scanf("%d", a + i);
	for (int i = 0; i < 1 << n; ++i) f[i] = pII(i, 1 << n);
	for (int i = 0; i < n; ++i) {	
		for (int j = 0; j < 1 << n; ++j) {
			if ((j >> i) & 1) {
				int k = j ^ (1 << i);
				if (a[f[k].fi] > a[f[j].fi]) {
					f[j].se = f[j].fi;
					f[j].fi = f[k].fi;
				//	cout << j << " " << f[j].fi << " " << f[j].se << endl;
				} 
				if (f[k].fi != f[j].fi && a[f[k].fi] > a[f[j].se]) {
					f[j].se = f[k].fi;
				}
				if (f[k].se != f[j].fi && a[f[k].se] > a[f[j].se]) {
					f[j].se = f[k].se;
				} 
			//	cout << j << " " << f[j].fi << " " << f[j].se << endl;
			}
		}
	}
	memset(ans, 0, sizeof ans);
	for (int i = 1; i < 1 << n; ++i) {
		ans[i] = ans[i - 1];
	//	cout << i << " " << f[i].fi << " " << f[i].se << endl;
		if (f[i].fi != f[i].se && f[i].se != (1 << n)) {
			ans[i] = max(ans[i], a[f[i].fi] + a[f[i].se]);
		}
		printf("%d\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 15360
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair< int, int> P;

static const double EPS = 1e-8;
static const double PI = 3.141592653589;
static ll INF = 9999999;
int mod = 1000000007;

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define MIN(a,b)    (a) < (b) ? (a):(b)
#define MAX(a,b)    (a) > (b) ? (a):(b)
#define debug(x) cerr << #x << " = " << x << endl;
int dx[] = {1,-1,0,0,1,-1,1,-1};
int dy[] = {0,0,1,-1,-1,1,1,-1};

using namespace std;





int main() {
    int N,L;
    string s[102];
    cin >> N >> L;
    REP(i,N){
        cin >> s[i];
    }

    sort(s,s+N);

    REP(i,N){
        cout << s[i];
    }
    cout<< endl;



    




    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <functional>
#include <math.h>
#include <map>
#include <set>
#include <string>
using namespace std;
#define fio ios::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INT_INF = 1e9;
const ll LL_INF = 1e18;
const int MAXN = 500003;

typedef struct GE {
    int to;
    ll w;
    GE() {};
}GE;

char s[5];
int main() {
    int n, L;
    scanf("%d %d", &n, &L);
    int ans = 0;
    int midif = 10000;
    int realdif = 10000;
    for (int i = 1; i <= n; i++) {
        int cw = L + i - 1;
        if (abs(cw) < midif) {
            midif = abs(cw);
            realdif = cw;
        }
        ans += cw;
    }
    printf("%d", ans - realdif);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define pb push_back
#define mk make_pair
#define ull unsigned long long
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
    fastIO;
    ll h,w,k,flag;
    cin>>h>>w>>k;
    string str[h];
    ll straw[h]={0};
    for(int i=0;i<h;i++)
    {
        flag=0;
        cin>>str[i];
        for(char c:str[i])
        {
            if(c=='#')
            {
                flag=1;                
            }
        }
        if(flag==1)
        {
            straw[i]=1;
        }
    }
    ll x,y,count=0,j1,j;
    ll ans[h][w];
    for(int i=0;i<h;i++)    
    {
        j1=0;
        if(straw[i]==1)
        {
            count++;
            for(j=0;j<w;j++)
            {
                if(str[i][j]=='#')
                {   
                    if(j1!=0)
                    {
                        count++;
                    }
                    ans[i][j]=count;
                    j1++;
                }
                else
                {
                    ans[i][j]=count;
                }
            }
        }
        else
        {   
            if(i==0)
            {
                for(j=0;j<w;j++)
                {
                    ans[i][j]=0;
                }
            }
            else
            {
                for(j=0;j<w;j++)
                {
                    ans[i][j]=ans[i-1][j];
                } 
            }  
        }
    }
    for(int i=h-2;i>=0;i--) 
    {
        if(ans[i][0]==0)
        {
            for(j=0;j<w;j++)
            {
                ans[i][j]=ans[i+1][j];
            }
        }
    }
    for(int i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cout<<ans[i][j]<<' ';
        }
        cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 1536
import java.util.*;

public class Main {
	
	boolean[] used;
	int[] perm, p, q;
	int n, a, b, c;
	
	void solve() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		used = new boolean[n];
		perm = new int[n];
		p = new int[n];
		for(int i = 0; i < n; i++) p[i] = scan.nextInt();
		q = new int[n];
		for(int i = 0; i < n; i++) q[i] = scan.nextInt();
		a = -1;
		b = -1;
		permutation(0);
		System.out.println(Math.abs(a - b));
		scan.close();
	}
	
	void permutation(int i) {
		if(i == n) {
			c++;
			if(Arrays.equals(perm, p)) a = c;
			if(Arrays.equals(perm, q)) b = c;
		}
		for(int j = 0; j < n; j++) {
			if(!used[j]) {
				perm[i] = j + 1;
				used[j] = true;
				permutation(i + 1);
				used[j] = false;
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}


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

using namespace std;

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

  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    if (int(i * 1.08) == n) {
      cout << i;
      return 0;
    }
  }
  cout << ":(";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

struct Solution {
    vector<int> used, used2, v;
    int N;
    bool rec(int cur, int rest){
        if(!rest) return true;
        if(cur < 0) return false;
        if(used2[cur] && v[cur] <= rest){
            used2[cur] = 0;
            if(rec(cur-1, rest-v[cur])) return true;
            used2[cur] = 1;
        }
        return rec(cur-1, rest);
    }

    int ok(int cur, int rest){
        if(!rest){
            used2 = used;
            for (int i = 1; i < N; ++i) {
                if(used2[i]) continue;
                if(!rec(i-1, v[i])) return 0;
                used2[i] = 1;
            }
            return true;
        }else if(rest < v[cur]) return 0;
        used[cur] = 1;
        if(ok(cur+1, rest-v[cur])) return 1;
        used[cur] = 0;
        return ok(cur+1, rest);
    }

    void solve(int n){
        if(n == 1){
            cin >> n;
            puts("YES");
            return;
        }
        N = n;
        used.resize(n, 0);
        fill(used.begin(),used.end(),0);
        v.resize(n);
        for (auto &&i : v) scanf("%d", &i);
        sort(v.begin(),v.end());
        used[0] = 1;
        puts(ok(1, v.back()-v.front()) ? "YES" : "NO");
    }
};

int main() {
    int n;
    Solution s;
    while(cin >> n, n) s.solve(n);
    return 0;
}


Measured memory_bytes: 3204
#include <iostream>

using namespace std;

int main(){
	string s = u8"";

	cin >> s;

	size_t s_max = s.size();

	int32_t min = 1000;

	for(size_t i(0); i < s_max - 2; ++i){
		int32_t x = 100 * (s[i] - 48) + 10 * (s[i + 1] - 48) + (s[i + 2] - 48);

		if(abs(x - 753) < min){
			min = abs(x - 753);
		}
	}

	cout << min << endl;

	return(0);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = long.Parse(ReadLine());
        for(long pow = 1; pow < 5; pow++)
        {
            long ten = (long)Pow(10, pow);
            for(long a = -ten; a <= ten; a++)
            {
                for(long b = ten; -ten <= b; b--)
                {
                    if(a * a * a * a * a - b * b * b * b * b == n)
                    {
                        WriteLine($"{a} {b}");
                        return;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 18100
import java.util.*;
import java.lang.*;

class Main {
	static int[] segTree;
	static int n;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		int q = scanner.nextInt();

		initSegTree();

		for(int i = 0; i < q; i++) {
			int type = scanner.nextInt();

			if(type == 0) {
				int s = scanner.nextInt();
				int t = scanner.nextInt();
				int x = scanner.nextInt();

				// Change a[s] ... a[t] to x
				update(s,t,x);

			} else if(type == 1) {
				// Find value of a[i]
				int result = find(scanner.nextInt());
				System.out.println(result);
			}
		}
	}

	static void initSegTree() {
		int _n = 1;
		while(_n < n)
			_n *= 2;

		segTree = new int[2*_n];
		Arrays.fill(segTree, Integer.MAX_VALUE);
	}

	static void update(int s, int t, int x) {
		updateRange(1, 0, n, s, t+1, x);
	}

	/*	k: index of current node in segTree
		l & r: range covered by node k
		s & t: range of query
		x: new value to update
	*/
	static void updateRange(int k, int l, int r, int s, int t, int x) {

		if(s >= t) // out of range
			return;

		if(s == l && t == r) { // (s,t) fully inside (l,r)
			segTree[k] = x;
			return;
		}

		if(segTree[k] >= 0) {
			segTree[k*2] = segTree[k];
			segTree[k*2+1] = segTree[k];
			segTree[k] = -1;
		}

		// (s,t) and (l,r) intersect
		int mid = (l+r)/2;
		updateRange(k*2, l, mid, Math.max(s,l), Math.min(mid,t), x);
		updateRange(k*2+1, mid, r, Math.max(s,mid), Math.min(r,t), x);
	}

	static int find(int i) {
		return find(i, 0, n, 1);
	}

	static int find(int i, int l, int r, int k) {
		if(segTree[k] >= 0)
			return segTree[k];
		else {
			int mid = (l+r)/2;
			if(i < mid)
				return find(i,l,mid,k*2);
			else
				return find(i,mid,r,k*2+1);
		}
	}
}


Measured memory_bytes: 116636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int f(int n){
    int res = 0;
    while(n > 0){
        res += n%10;
        n /= 10;
    }
    return res;
}

int main(){
    //e[i]:=10^i;
    ll e[16];
    e[0] = 1;
    rep2(i, 1, 15) e[i] = 10*e[i-1];
    priority_queue<ll, vector<ll>, greater<ll> > ans;
    rep2(i, 1, 8) ans.push(i);
    //下i桁が全て9であるすぬけ数を順に列挙
    rep2(i, 1, 15){
        rep(j, 200){
            if(j%10 == 9) continue;
            elif(j-f(j) < 9*i){
                ans.push((j+1)*e[i]-1);
            }
        }
    }
    int K;
    cin >> K;
    rep(i, K){
        cout << ans.top() << endl;
        ans.pop();
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] nums = new long[n];
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextLong();
        }
        long a = nums[0];
        long b;
        for (int i = 1; i < n; i++) {
            b = nums[i];
            long large = Math.max(a, b);
            long small = Math.min(a, b);
            a = lcm(large, small);
        }
        System.out.println(a);
    }

     static long gcd(long large, long small) {
        long r = large % small;
        while(r != 0) {
            large = small;
            small = r;
            r = large % small;
        }
        return small;
     }

     static long lcm(long large, long small) {
        long gcd = gcd(large, small);
        return large / gcd * small;
     }
}


Measured memory_bytes: 22868
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 2005;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=2.718281828459045235360287471352662;
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
int a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,m,x;
    cin>>n>>m>>x;
    for(int i=1;i<=m;i++)
    {
        int pp;
        cin>>pp;
        a[pp]=1;
    }
    int minn=INF;
    int sum=0;
    for(int i=x-1;i>=0;i--)
    {
        sum+=a[i];
    }
    minn=min(minn,sum);
    sum=0;
    for(int i=x+1;i<=n;i++)
    {
        sum+=a[i];
    }
    minn=min(minn,sum);
    cout<<minn<<endl;
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

int main(void){
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> v(n);
    char now=s[0];
    int pos=0;
    v[0]=0;
    int ans=1;
    rep(i, n){
        if(now==s[i]){
            v[pos]++;
    
        }
        else{
            v.push_back(1);
            pos++;
            now=s[i];
            ans++;
        }
    }

    
    
    cout<<ans<<endl;

}

Measured memory_bytes: 1280
#include<iostream>
using namespace std;
int main()
{
	int n,t;
	cin>>n>>t;
	int a,b;
	int min=1001;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		if(b<=t)
		{
			if(min>a)
				min=a;
		}
	}
	if(min==1001)
	cout<<"TLE"<<endl;
	else
	cout<<min<<endl;
	
 } 

Measured memory_bytes: 256
s = STDIN.gets
a = s[0].to_i
b = s[1].to_i
c = s[2].to_i
d = s[3].to_i

if a + b + c + d == 7
	puts a.to_s + "+" + b.to_s+"+"+c.to_s+"+"+d.to_s+"=7"
elsif a + b + c - d == 7
	puts a.to_s+"+"+b.to_s+"+"+c.to_s+"-"+d.to_s+"=7"
elsif a + b - c - d == 7
	puts a.to_s+"+"+b.to_s+"-"+c.to_s+"-"+d.to_s+"=7"
elsif a + b - c + d == 7
	puts a.to_s+"+"+b.to_s+"-"+c.to_s+"+"+d.to_s+"=7"
elsif a - b - c + d == 7
	puts a.to_s+"-"+b.to_s+"-"+c.to_s+"+"+d.to_s+"=7"
elsif a - b + c + d == 7
	puts a.to_s+"-"+b.to_s+"+"+c.to_s+"+"+d.to_s+"=7"
elsif a - b + c - d == 7
	puts a.to_s+"-"+b.to_s+"+"+c.to_s+"-"+d.to_s+"=7"
elsif a - b - c - d == 7
	puts a.to_s+"-"+b.to_s+"-"+c.to_s+"-"+d.to_s+"=7"
end

Measured memory_bytes: 1916
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define int long long

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
vector <int> xx={1,-1,0,0};
vector <int> yy={0,0,1,-1};
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    int n,m,k;
    cin>>n>>m>>k;
    assert(n*m<MAXN);
    vll d(MAXN,INFLL);
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    x1--,x2--,y2--,y1--;
    vector <string> ss(n);
    rep(i,n)
    cin>>ss[i];
    d[x1*m+y1]=0;
    set <pii> s;
    s.insert({0,x1*m+y1});
    while (!s.empty())
    {
        auto to=s.begin();
        int dd=(*to).fi;
        int z=(*to).se;
        int x=z/m;
        int y=z%m;
        int xwas=x;
        int ywas=y;
        s.erase(to);
        for (int f=0;f<4;f++)
        {
            x=xwas;
            y=ywas;
                int g=k;
                while (g--)
                {
                    if (x+xx[f]>=0&&x+xx[f]<n&&y+yy[f]>=0&&y+yy[f]<m&&ss[x+xx[f]][y+yy[f]]=='.'&&d[(x+xx[f])*m+y+yy[f]]>=dd+1)
                    {
                        x+=xx[f];
                        y+=yy[f];
                        s.erase({d[x*m+y],x*m+y});
                        d[x*m+y]=dd+1;
                        s.insert({d[x*m+y],x*m+y});
                    }
                    else
                        break;
                }
        }
    }
    if (d[x2*m+y2]==INFLL)
        cout<<-1;
    else
        cout<<d[x2*m+y2];

    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cerr << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int N; cin >> N;
	V<int> a(N);

	rep(i, N) {
		cin >> a[i];
		--a[i];
	}

	set<int> cand;
	rep(i, N) cand.insert(i);

	V<int> ans;

	int ng = -1;

	map<int, int> cnt;
	rep(i, N) ++cnt[a[i]];

	rep(t, N-8) {
		int nx = -1;
		for (auto &v : cand) {
			if (v == ng) continue;

			bool valid = 1;
			if (cnt.size() <= 2) {
				for (auto &p : cnt) if (p.se == N-1-t && p.fi != v) {
					valid = 0;
				}
			}

			if (!valid) {
				if (a[v] == ng) {
					puts("-1");
					return 0;
				}
				nx = a[v];
			} else {
				nx = v;
			}
			break;
		}

		if (nx == -1) {
			puts("-1");
			return 0;
		}

		cnt.erase(nx);
		if (cnt.count(a[nx]) && --cnt[a[nx]] == 0) {
			cnt.erase(a[nx]);
		}
		ng = a[nx];
		cand.erase(nx);
		ans.pb(nx);
	}

	V<int> pm(ALL(cand));

	bool ok = 0;
	do {
		bool t = 1;
		rep(i, pm.size()) {
			if (i == 0) {
				if (pm[0] == ng) t = 0;
			} else if (a[pm[i-1]] == pm[i]) {
				t = 0;
			}
		}
		ok |= t;
		if (t) {
			for (int p : pm) {
				ans.pb(p);
			}
			break;
		}
	} while (next_permutation(ALL(pm)));

	if (!ok) {
		puts("-1");
		return 0;
	}

	rep(i, N) {
		printf("%d%c", ans[i] + 1, i == N-1 ? '\n' : ' ');
	}

	return 0;
}

Measured memory_bytes: 10624
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    a, b, c, k = [next_int() for _ in range(4)]
    print((a - b) * ((-1) ** k))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
// D - Lucky PIN
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define all(x) (x).begin(),(x).end()
#define lbound(x,c) lower_bound(all(x),(c))-(x).begin()

int main(){
	int N; string S; cin>>N>>S; S = "-" + S;
	vector<vi> ix(10, vi());
	rp(i, 1, N+1) ix[S[i]-'0'].push_back(i);
	int ans = 0;
	rp(a, 0, 10){
		int p = lbound(ix[a], 0); if(p >= ix[a].size()) continue;
		rp(b, 0, 10){
			int q = lbound(ix[b], ix[a][p]+1); if(q >= ix[b].size()) continue;
			rp(c, 0, 10) if(lbound(ix[c], ix[b][q]+1) < ix[c].size()) ans++;
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 512
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C&lang=ja
# https://kujira16.hateblo.jp/entry/2014/05/14/220520
# ワーシャルフロイド
import sys
v, e = map(int, input().split())

dist = [[float('inf')] * v for _ in range(v)]

for _ in range(e):
    f, t, d = map(int, input().split())
    dist[f][t] = d

for i in range(v):
    dist[i][i] = 0


for k in range(v):
    for i in range(v):
        for j in range(v):
            # iからjへの最短距離
            # 負の辺がある場合
            if dist[i][k] != float('inf') and dist[k][j] != float('inf'):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

negative = False
for i in range(v):
    if dist[i][i] < 0:
        negative = True

if negative:
    print('NEGATIVE CYCLE')
    sys.exit()

for i in dist:
    print(' '.join(map(lambda x: 'INF' if x == float('inf') else str(x), i)))
# print(dp)
# print(dist)



Measured memory_bytes: 5996
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// 入力文字列を取得
		Scanner sc = new Scanner(System.in);

		// 配列を作る
		ArrayList<Integer> list = new ArrayList<Integer>();
		int index_max = sc.nextInt();

		// リストにテキスト入力文字を格納
		for (int i = 0; i < index_max; i++) {	
			//
			list.add(sc.nextInt());
		}

		// 逆順に表示
		for (int index = index_max - 1; index >= 0; index--) {

			String number = list.get(index).toString();

			// 最後の数以外には空白を追加
			if (index != 0) {

				number = number + " ";
				System.out.print(number);
				//最後の数は改行出力
			}else{
				//
				System.out.println(number);
			}
		}

	}
}

Measured memory_bytes: 17288
#include <iostream>

using namespace std;
int main(){
  int N;
  int H[100];

  cin >> N;
  for(int i = 0; i < N; i++) cin >> H[i];

  int ans = 0;
  int max_H = 0;
  for(int i = 0; i < N; i++){
    if(max_H <= H[i]){
      max_H = H[i];
      ans += 1;
    }
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
n,d = map(int,input().split())
xd = [[int(i) for i in input().split()] for i in range(n)]
cnt = 0
for i in range(n):
  for j in range(n):
    if i != j:
      temp = 0
      for k in range(d):
        temp += (xd[i][k]-xd[j][k])**2
      if float.is_integer(temp**0.5):
        cnt += 1
print(cnt // 2)

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define tc ll t; cin >> t; while (t--)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define sz(c) (ll) c.size()
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define trav(x,c) for(auto &x : c)
#define _for(i,a,n) for(ll i = a ; i < n ; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define dm(m) trav(x,m) cout << x.f << "->" << x.s << endl;
#define godspeed cin.tie(0) -> sync_with_stdio(0);

int main() {
    godspeed;
    ll n; cin >> n;
    ll sum = 0;
    
    _for(i,1,n+1) _for(j,1,n+1) _for(k,1,n+1) sum += __gcd(i,__gcd(j,k));

    cout << sum;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;

using namespace std;
int slove(int n){
    if(n == 1 || n == 3 || n == 5 || n == 7 || n == 10 || n ==12 || n ==8){
    return 1;
    }
    else if(n == 4 || n == 6|| n == 9 || n == 11){
    return 2;
    }
    if(n == 2){
    return 3;
    }
}
int main(){
    int a, b;
    cin >> a >> b;
    if(slove(a) == slove(b)){
        cout << "Yes"  << '\n';
    }
    else{
        cout << "No" << '\n';
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    string s; cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}


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

int main(){
	int S;
	int h,m,s;
	int a,b,c;
	
	cin>>S;
	
	s=S%60;
	a=(S-s)/60;
	m=a%60;
	h=(a-m)/60;
	
	cout<<h<<":"<<m<<":"<<s<<endl;
	
return 0;
}



Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
 
// random generator
// mt19937 rndm(time(0));
 
// ll gcd(ll a, ll b)
// {
//     while (b>0)
//     {
//         ll tmp = a;
//         a = b;
//         b = tmp%b;
//     }
//     return a;
// }
 
 
// long long gcd(long long a, long long b) {
//  return a? gcd(b % a, a) : b;
// }
 
 
const int M=1e9+7;
ll powmod(ll a,ll b, ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}/* a^b%mod */
const int N=1e3+10; 



int main() {	
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	
	int H, W, h, w;
	cin>>H>>W>>h>>w;
	int ans = H*W;
	ans-=h*W;
	H-=h;
	ans-=w*H;
	cout<<ans<<endl;
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,int>;
using T = tuple<string,int,int>;

int main(){
  int n,x;
  cin >> n >> x;
  int l[n];
  for(int i = 0; i < n; i++) cin >> l[i];
  int ans = 1;
  int cur = 0;
  for(int i = 0; i < n; i++){
    cur = cur + l[i];
    if(cur <= x) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main(void){
    int n,m;
    cin >> n >> m;
    vector<int> divisor;
    for (int i = 1; i <= sqrt(m); i++) {
        if (m % i == 0) {
            divisor.push_back(i);
            divisor.push_back(m/i);
        }
    }
    sort(divisor.begin(), divisor.end(), greater<int>());
    for (int g : divisor) {
        if (m/g >= n) {
            cout << g << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

// reference: http://ir5.hatenablog.com/entry/20171209/1512821837

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

use std::mem;
use std::cmp;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let mut a = vec![false; 10];
    for i in 0..4 {
        let x: usize = sc.read();
        a[x] = true;
    }
    if a[1] && a[4] && a[9] && a[7] {
        println!("{}", "YES");
    } else {
        println!("{}", "NO");
    }
}

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

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

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int ans=0;
    if(a[0]==a[n-1])
        cout<<"0"<<endl;
    else{
    for(int i=a[0];i<=a[n-1];i++)
    {
        int ans1=0;
        for(int j=0;j<n;j++)
        {
            ans1+=abs(a[j]-i)*abs(a[j]-i);
        }
        if(i==a[0])
            ans=ans1;
        else
            ans=min(ans,ans1);
    }
    cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*


*/
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
#define MAXIN 300000
//#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
typedef long long LL;
const int N=2e5+5;

int A[N];
char IN[MAXIN],*SS=IN,*TT=IN;

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-48,c=gc());
	return now;
}
LL Solve(const int n,const int L)
{
	static LL pre[N],suf[N];
	for(int i=1; i<=n; ++i) pre[i]=pre[i-1]+A[i];
	for(int i=n; i; --i) suf[i]=suf[i+1]+L-A[i];
	LL ans=A[n];
	for(int i=1,p; i<n; ++i)
		p=i+((n-i)>>1), (n-i)&1 ? ans=std::max(ans,(suf[p+2]+pre[p]-pre[i]+A[i])*2+L-A[p+1]) : ans=std::max(ans,(suf[p+1]+pre[p-1]-pre[i]+A[i])*2+A[p]);
//		printf("i:%d p:%d val:%lld\n",i,p,(n-i)&1 ? (suf[p+2]+pre[p]-pre[i]+A[i])*2+L-A[p+1] : (suf[p+1]+pre[p-1]-pre[i]+A[i])*2+A[p]);
	return ans;
}

int main()
{
	const int L=read(),n=read();
	for(int i=1; i<=n; ++i) A[i]=read();
	LL ans=Solve(n,L);
	std::reverse(A+1,A+1+n);
	for(int i=1; i<=n; ++i) A[i]=L-A[i];
	ans=std::max(ans,Solve(n,L));
	printf("%lld\n",ans);

	return 0;
}

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

int main()
{
	int n,w;
	cin>>n>>w;
	int v[n],ww[n];
	long lookup[n+1][w+1];

	for(int i=0;i<n;i++)
		{  cin>>ww[i]>>v[i];
		}
		memset(lookup,0,sizeof(lookup));
		
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=w;j++)
			{
				if(ww[i-1]>j)
					lookup[i][j]=lookup[i-1][j];
				else
					lookup[i][j]=max(lookup[i-1][j-ww[i-1]]+v[i-1],lookup[i-1][j]);
			}
		}
		cout<<lookup[n][w];
	return 0;
}

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

typedef long long ll;

#define all(x) x.begin(), x.end()
#define sz(x) (ll) x.size()
#define deb(x) cout << (#x) << " is " << (x) << "\n";
#define debv(v) for (auto usb: v) cout << usb << " "; cout << "\n";

// n == (1 || 0) ???? memory?
ll A,B,x,y;
const ll N = 1007;
bool visited[N][N];
bool reach[N][N];
int grid[N][N];
int dist[N][N];
bool valid;

 
void dfsP(int i, int j){
	if(i == A && j == B) valid = true;
	if(reach[i][j] || valid) return;
	reach[i][j] = true;
	
	for(int c = i-2; c<=i+2; c++){
		for(int d=j-2; d <= j+2; d++){
			if(d>=0 && c>=0 && grid[c][d]){
				dfsP(c,d);
			}
		}
	}
}

void dijktra(int i, int j){
	priority_queue<pair<ll,pair<int,int>>> q;
	q.push({0LL, {i,j}});
	
	for (int ii = 0; ii < N; ii++)
		for (int jj = 0; jj < N; jj++)
			dist[ii][jj] = 1e9;
				
	dist[i][j] = 0LL;
	
	while(q.size()){
		pair<int,int> p;
		p = q.top().second;
		q.pop();
		ll a = p.first, b = p.second;
		if(visited[a][b]) continue;
		visited[a][b] = true;
	
		for(int c = a-2; c <= a+2; c++){
			for(int d = b-2; d <= b+2; d++){
				if(d>=0 && c>=0 && grid[c][d]){
					ll k = (abs(a-c) + abs(b-d) == 1) ? 0LL : 1LL;
					if(dist[a][b] + k < dist[c][d]){
						dist[c][d] = dist[a][b] + k;
						q.push({-dist[c][d], {c, d}});
					}
				}
			}
		}
	}
}

void solve(){
	ll h,w;
	cin >> h >> w;
	cin >> A >> B;
	cin >> x >> y;
	
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			char c;
			cin >> c;
			if(c == '.') grid[i+1][j+1] = 1;
		}
	}
	
	dfsP(x,y);
	if(valid) dijktra(A, B);
	
	if(valid) cout << dist[x][y] << "\n";
	else cout << "-1\n";
}

int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.precision(20);	
	solve();
	return 0;
}


Measured memory_bytes: 25904