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

typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back
#define END '\n'

template <class T>
inline bool Read(T &ret)
{
	char c;
	int sgn;
	if (static_cast<void>(c = getchar()), c == EOF)
		return 0;
	while (c != '-' && (c < '0' || c > '9'))
		c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
		ret = ret * 10 + (c - '0');
	ret *= sgn;
	return 1;
}

template <class T>
inline void Write(T x)
{
	if (x < 0)
		putchar('-'), Write(x);
	if (x > 9)
		Write(x / 10);
	putchar(x % 10 + '0');
}
static int a[N*2]={0};
void solve(int question_num)
{
	while(question_num--){
		int n;cin>>n;
		for(int i=1;i<n;++i){
			int k;cin>>k;
			a[k]++;
		}
		for(int i=1;i<=n;++i){
			cout<<a[i]<<endl;
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t = 1;
	// cin >> t;
	solve(t);
	return 0;
}


Measured memory_bytes: 4320
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	int a, b, c;

	cin >> a >> b >> c;

	if (c >= a && c <= b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
S = input()
N = len(S)
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
ans = 0

for i in range(0, N, 2):
  if not (S[i] in odd):
    ans += 1
for i in range(1, N, 2):
  if not(S[i] in even):
    ans += 1
 
if ans == 0:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	unsigned long long int sum = 0;
	for(int i = 0; i < n; ++i)
	{
		int input;
		cin >> input;
		sum += input;
	}
	cout << sum / n << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

ans = sum(B)
for i in range(len(A)-1):
    if A[i] +1 == A[i+1]:
        ans += C[A[i]-1]

print(ans)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	/** 白のコマ */
	private static final char WHITE = '.';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			boolean[][] s = new boolean[h + 1][w + 1];
			IntStream.range(0, h + 1).forEach(i -> Arrays.fill(s[i], false));
			int whiteCount = 0;
			@SuppressWarnings("unchecked")
			List<Path>[] pathLists = new List[h * w];
			IntStream.range(0, h * w).forEach(i -> pathLists[i] = new ArrayList<>());
			for (int i = 1; i <= h; i++) {
				char[] l = scanner.next().toCharArray();
				for (int j = 1; j <= w; j++) {
					s[i][j] = (l[j - 1] == WHITE);
					if (s[i][j]) {
						whiteCount++;
						int now = (i - 1) * w + j - 1;
						if (s[i - 1][j]) {
							int before = (i - 2) * w + j - 1;
							pathLists[now].add(new Path(now, before, 1));
							pathLists[before].add(new Path(before, now, 1));
						}
						if (s[i][j - 1]) {
							int before = (i - 1) * w + j - 2;
							pathLists[now].add(new Path(now, before, 1));
							pathLists[before].add(new Path(before, now, 1));
						}
					}
				}
			}
			int[] distances = dijkstra(pathLists, 0, h * w);
			System.out.println((distances[h * w - 1] < Integer.MAX_VALUE) ? whiteCount - distances[h * w - 1] - 1 : -1);
		}
	}

	/**
	 * @param pathLists ノード間の連結パス一覧の配列
	 * @param src       開始ノード
	 * @param n         ノードの数
	 * @return 開始ノードからの距離の配列
	 */
	private static int[] dijkstra(List<Path>[] pathLists, int src, int n) {
		int[] distances = new int[n];
		Arrays.fill(distances, Integer.MAX_VALUE);
		// 最短距離が確定したかどうか
		boolean[] fixed = new boolean[n];
		Arrays.fill(fixed, false);
		// 出発地点までの距離を0とする
		distances[src] = 0;
		Queue<Path> queue = new PriorityQueue<>();
		queue.add(new Path(src, src, 0));
		while (!queue.isEmpty()) {
			int now = queue.poll().to;
			if (!fixed[now]) {
				fixed[now] = true;
				for (Path path : pathLists[now]) {
					if (!fixed[path.to] && distances[path.to] > distances[now] + path.cost) {
						distances[path.to] = distances[now] + path.cost;
						queue.add(new Path(path.to, path.to, distances[path.to]));
					}
				}
			}
		}
		return distances;
	}

	/**
	 * ノード間の一つのパスを表すクラス
	 */
	private static class Path implements Comparable<Path> {
		/** 開始ノード */
		@SuppressWarnings("unused")
		int from;
		/** 終了ノード */
		int to;
		/** 移動コスト */
		int cost;

		Path(int from, int to, int cost) {
			super();
			this.from = from;
			this.to = to;
			this.cost = cost;
		}

		@Override
		public int compareTo(Path path) {
			return this.cost - path.cost;
		}
	}
}


Measured memory_bytes: 36832
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////
char C[1010][1010];
ll d[1010][1010];
int main() {
	int H, W; cin >> H >> W;
	queue<pii>Q;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			d[i][j] = -INF;
		}
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> C[i][j];
			if (C[i][j] == '#') {
				Q.push({ i,j });
				d[i][j] = 0;
			}
		}
	}
	while (!Q.empty()) {
		pii p = Q.front();
		int y = p.first;
		int x = p.second;
		Q.pop();
		for (int i = 0; i < 4; ++i) {
			int ny = y + dy[i];
			int nx = x + dx[i];
			if (ny >= 0 && ny < H&&nx >= 0 && nx < W&&d[ny][nx] == -INF && C[ny][nx] == '.') {
				Q.push({ ny,nx });
				d[ny][nx] = d[y][x] + 1;
				C[ny][nx] = '#';
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			ans = max(ans, d[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 17424
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    cout << (int)(ceil(n/2.0)) << endl;
}

Measured memory_bytes: 256
N, K = [int(nk) for nk in input().split()]
A = [int(a) for a in input().split()]

A_set = list(set(A))
if len(A_set) <= K:
  print(0)
else: # len(A_set) > K:
  dictionary = {}
  for n in A_set:
    dictionary[n] = 0
  for m in A:
    dictionary[m] += 1
  
  dict_val = list(dictionary.values())
  dict_val.sort(reverse = True)
  ans = N - sum(dict_val[:K])
  print(ans)

Measured memory_bytes: 38660
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	int x;

	cin >> x;

	cout << x * x * x << endl;




	return 0;
}



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

using namespace std;

#define rep(i,n) for(i=0;i<n;++i)
#define debg(s) cout<<s<<endl;
#define INF 1e9
#define rev(s) reverse(s.begin(),s.end())
int i,j,n,m;
string s,t;

int main(){ 
  cin>>s;
  int sl = s.length(); 
  reverse( s.begin(), s.end() );
  string a = "dream"; rev(a);
  string b = "dreamer"; rev(b);
  string c = "erase"; rev(c);
  string d = "eraser"; rev(d);  
  string js[4] = {a,b,c,d};
  
  int jsl;
  bool ans = true;
  for(i=0;i<sl;i+=jsl){
    bool brk=false;
    
    rep(j,4){
      jsl = js[j].length(); 
   
      if(s.substr(i,jsl) == js[j]){
        brk=true; 
        break;
      }
    }
    if(!(brk))ans=false;
  }
  cout<< ( ans ? "YES":"NO" ) <<endl;

  return 0;
}


Measured memory_bytes: 512
var
	L,R,ans,tmp,M,i,j:Longint;
begin
	read(L,R);
	M:=2019;
	ans:=M;
	if L<3 then begin
		writeln(0);
		exit;
	end;
	if L+2017<=R then begin
		writeln(0);
		exit;
	end;
	for i:=L to R do begin
		for j:=1 to 50 do begin
			if i+j>R then break;
			tmp:=i mod M*(i+j)mod M;
			if ans>tmp then ans:=tmp;
		end;
	end;
	writeln(ans);
end.

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

namespace aoj {
	public class Program {
		public static void Main() {
			Dictionary<int, int> data, rank;
			List<int> points;
			data = new Dictionary<int, int>();
			rank = new Dictionary<int, int>();
			points = new List<int>();

			int[] vs;
			while(true) {
				vs = Console.ReadLine().Split(',').Take(2).Select(s => int.Parse(s)).ToArray();
				if (vs[0] == 0) break;
				data.Add(vs[0], vs[1]);
				points.Add(vs[1]);
			}
			points.Sort((a, b) => b - a);
			rank.Add(points[0], 1);
			int v = points[0], r = 2;
			for (int i = 1; i < points.Count; i++) {
				if (v == points[i]) continue;
				else {
					v = points[i];
					rank.Add(v, r++);
				}
			}
			string str;
			while((str = Console.ReadLine()) != null)
				Console.WriteLine(rank[data[int.Parse(str)]]);
		}
	}
}

Measured memory_bytes: 10052
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    double a = 0, b = 0;
    REP(i, N){
        if((i+1)%2)a +=1;
        else b += 1;
    }
    pr(a/N);
}

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

using namespace std;



int main() {
	int n;
	cin >> n;
	vector<long long> h(n);

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

	long long ans = 0, now = 0;

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

		if (h[i] >= h[i+1]) {
			now++;
		}else {
			if (now > ans) {
				ans = now;
				
			}
			now = 0;
		}
	}

	if (now > ans) {
		ans = now;

	}

	cout << ans;

	system("pause");
	return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")

using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main() {
    string a, b;
    cin >> a >> b;
    
    (a == b) ? mes("H") : mes("D");
    
    

    
    
    
}


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

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

using namespace std;

const int mod = 1000000007;

struct Mod {
  int num;
  Mod () : num(0) {;}
  Mod (int n) : num(n) {;}
  operator int() { return num; }
};

Mod operator+(Mod a, Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator-(Mod a, Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator*(Mod a, Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator+=(Mod &a, Mod b) { return a = a + b; }
Mod operator-=(Mod &a, Mod b) { return a = a - b; }

typedef array<Mod, 52> Array;
typedef array<Array, 52> Matrix;
typedef vector<Matrix> DPTable;

typedef vector<tuple<string, vector<string>>> BNF;

string ATGC = "ATGC";
int sum;

DPTable terminal(DPTable prev_dp, const string &chars) {
  bitset<4> usable;
  REP(i,4) {
    if (find(begin(chars),end(chars),ATGC[i])!=end(chars)) usable[i] = true;
  }
  DPTable next_dp(52, Matrix());
  REP(i,51)REP(j,51)REP(k,51) {
    if (usable[0]) next_dp[i+1][j][k] += prev_dp[i][j][k];
    if (usable[1]) next_dp[i][j+1][k] += prev_dp[i][j][k];
    if (usable[2]) next_dp[i][j][k+1] += prev_dp[i][j][k];
    if (usable[3]) next_dp[i][j][k] += prev_dp[i][j][k];
  }
  return next_dp;
}

pair<DPTable, int> non_terminal(DPTable prev_dp, BNF bnf, int i) {
  int prog = 0;
  REP(j,get<1>(bnf[i]).size()) {
    if (get<1>(bnf[i])[j][0] == '[') {
      prev_dp = terminal(prev_dp, get<1>(bnf[i])[j]);
      ++prog;
    } else {
      for (int k = i+1; k < bnf.size(); ++k) {
        if (get<0>(bnf[k]) == get<1>(bnf[i])[j]) {
          int progj;
          tie(prev_dp, progj) = non_terminal(prev_dp, bnf, k);
          prog += progj;
          if (prog > sum) throw "too long";
          break;
        }
      }
    }
  }
  return make_pair(prev_dp, prog);
}
  

int main() {
  vector<int> n(4);
  REP(i,4) cin>>n[i];
  REP(i,4) sum += n[i];
  int m;
  cin>>m;
  BNF bnf;
  string line;
  getline(cin,line);
  REP(i,m) {
    string line;
    getline(cin,line);
    stringstream ss;
    ss << line;
    string nm;
    ss >> nm;
    nm.erase(end(nm)-1,end(nm));
    vector<string> cld;
    while(!ss.eof()) {
      string cs;
      ss>>cs;
      cld.push_back(cs);
    }
    bnf.emplace_back(nm,cld);
  }
  DPTable dp(52, Matrix());
  dp[0][0][0] = 1;
  try {
    auto ans = non_terminal(dp, bnf, 0);
    if (ans.second == sum) {
      cout << ans.first[n[0]][n[1]][n[2]] << endl;
    } else {
      cout << 0 << endl;
    }
  } catch (...) {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 11132
def main():
    from bisect import bisect_right
    N = int(input())
    A = sorted(list(map(int,input().split())))
    B = sorted(list(map(int,input().split())))
    C = sorted(list(map(int,input().split())))
    
    num_greater_than_b = []
    for b in B:
        num_greater_than_b.append(N-bisect_right(C,b))

    csum = [0]*(N+1)
    for i in range(N-1,-1,-1):
        csum[i] = csum[i+1]+num_greater_than_b[i]
        
    ans = 0
    for i,a in enumerate(A):
        ans += csum[bisect_right(B,a)]
    print(ans)
main()



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

bool move(int a, int b, int c){
    int x_label = 0;
    int y_label = 0;
    if(x_label == b && y_label == c && a == 0){
        return true;
    }else if(a == 0){
        return false;
    }else{
        if(b > x_label){
            return move(a - 1, b - 1, c);
        }else if (b < x_label){
            return move(a - 1, b + 1, c);
        }else{
            if(c > y_label){
                return move(a - 1, b, c - 1);
            }else if(c < y_label){
                return move(a - 1, b, c + 1);
            }else{
                return move(a - 1, b, c - 1);
            }
        }
    }
}


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

    int t[N];
    int x[N];
    int y[N];

    for(int i = 0; i < N; i++){
        cin >> t[i] >> x[i] >> y[i];
    }

    int a = 0;
    int b = 0;
    int c = 0;
    int judge = 0;

    for(int i = 0; i < N; i++){
    
        a = t[i] - a;
        b = x[i] - b;
        c = y[i] - c;

        if(move(a, b, c)){
            a = t[i];
            b = x[i];
            c = y[i];
        }else{
            judge = -1;
            break;
        }
        judge++;
    }

    if(judge == -1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 1408
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ab_sum , answer = sum(B), 0
j = M
for i in range(N+1):
  while j>0 and ab_sum >K:
    j -= 1
    ab_sum -= B[j]
  if ab_sum >K:
    break
  answer = max(answer, i+j)
  if i==N:
    break
  ab_sum += A[i]

print(answer)


Measured memory_bytes: 118492
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(int argc, char const *argv[]) {
  ll n;
  cin>>n;
  ll a[n],b[n],c[n-1];
  ll ans=0;
  for (size_t i = 0; i < n; i++) {
    /* code */
    cin>>a[i];
  }
  for (size_t i = 0; i < n; i++) {
    /* code */
    cin>>b[i];
    ans+=b[i];
  }
  for (size_t i = 0; i < n-1; i++) {
    /* code */
    cin>>c[i];
  }
  for (size_t i = 0; i < n-1; i++) {
    /* code */
    if(a[i+1]-a[i]==1)
    {
      ans+=c[a[i]-1];
    }
  }
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int i,j,h,w,c;
	cin>>h>>w;
	char s[100][100];
	memset(s,'.',sizeof(s));
	for1(i,h){
		for1(j,w) cin>>s[i][j];
		}
	for1(i,h){
		for1(j,w){
			if(s[i][j]=='.'){
				c=0;
				if(s[i][j+1]=='#') c++;
				if(s[i][j-1]=='#') c++;
				if(s[i+1][j] =='#') c++;
				if(s[i-1][j] == '#') c++;
				if(s[i-1][j+1] == '#') c++;
				if(s[i-1][j-1] == '#') c++;
				if(s[i+1][j-1] == '#') c++;
				if(s[i+1][j+1] == '#') c++;
				cout<<c;
				}
			else cout<<s[i][j];
			}
		cout<<nw;
		}
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
import java.util.jar.JarOutputStream;

public class Main {

    public static int lower_bound(long[] arr,long target){
        int low = 0;
        int high = arr.length - 1;
        while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }
        return low;
    }

    public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n= Reader.nextInt();
        int[][] cost = new int[n][3];
        for(int i=0;i<n;i++){
            for(int j=0;j<3;j++){
                cost[i][j]=Reader.nextInt();
            }
        }
        int[][] dp=new int[n][3];
        dp[0][0]=cost[0][0];
        dp[0][1]=cost[0][1];
        dp[0][2]=cost[0][2];
        for(int i=1;i<n;i++){
            dp[i][0] = cost[i][0] + Math.max(dp[i-1][1],dp[i-1][2]);
            dp[i][1] = cost[i][1] + Math.max(dp[i-1][0],dp[i-1][2]);
            dp[i][2] = cost[i][2] + Math.max(dp[i-1][1],dp[i-1][0]);
        }
        int result = Math.max(dp[n-1][0],dp[n-1][1]);
        result = Math.max(result,dp[n-1][2]);
        System.out.println(result);

    }

}






class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String nextLine() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( nextLine() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong(nextLine());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( nextLine() );
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat( nextLine() );
    }
    static int[] nextIntArray(int length) throws IOException {
        int[] arr = new int[length];
        //System.out.println(length);
        for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        }
        //System.out.println(arr);
        return arr;
    }
    static long[] nextLongArray(int length) throws IOException {
        long[] arr = new long[length];
        for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        }
        return arr;
    }

}



Measured memory_bytes: 62012
#include "bits/stdc++.h"
#include "random"
#include <unistd.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; ++i)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int Uniform_Random(int a, int b){ // (a <= x <= b)

  random_device rd;
  mt19937 mt(rd());
  
  uniform_int_distribution<int> rv1(a, b);
  return rv1(mt);
  
}
 
int main(){
  
  int s; cin >> s;
  int A = s / 100;
  int B = s % 100;
  
  bool MMYY, YYMM;
  MMYY = YYMM = false;

  if(0 < A and A <= 12){ // MMYY
    MMYY = true;
  }
  if(0 < B and B <= 12){ //YYMM
    YYMM = true;
  }

  if(MMYY and YYMM){
    cout << "AMBIGUOUS" << endl;
  }
  else if(MMYY){
    cout << "MMYY" << endl;
  }
  else if (YYMM){
    cout << "YYMM" << endl;
  }
  else{
    cout << "NA";
  }

  return 0; 
}






Measured memory_bytes: 256
// Solution for 0551: Icicles
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const int MAX_N = 100000;
int n, n2, l;
int icicles[MAX_N + 2], dp[MAX_N + 2];
int main(){
	cin >> n >> l;
	n2 = n;
	for (int i = 1; i <= n; i++){
		cin >> icicles[i];
	}

	while (n){
		for (int i = 1; i <= n2; i++){
			if (icicles[i] > icicles[i - 1] && icicles[i] > icicles[i + 1]){
				dp[i] += l - icicles[i];
				icicles[i] = 0;
				n--;
				if (icicles[i - 1])
					dp[i - 1] = max(dp[i - 1], dp[i]);
				if (icicles[i + 1])
					dp[i + 1] = max(dp[i + 1], dp[i]);
			}
		}
	}
	sort(dp, dp + n2 + 1, greater<int>());
	cout << dp[0] << endl;
	return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b;cin>>a>>b;
  int c=1;
  int res=0;
  while(c<b){
    c+=(a-1);
    res++;
  }
  cout<<res<<endl;

  return 0;
}


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

int l,r,p;

struct RSQ{
  int n=(1<<18),data[(1<<19)];
  RSQ(){memset(data,0,sizeof(data));}
  void add(int i,int v){
    i++;
    while(i<=n){
      data[i]+=v%p;
      i+=i&-i;
    }
  }
  int sum(int i){
    int res=0;
    while(i>0){
      res+=data[i];
      i-=i&-i;
      res%=p;
    }
    return res;
  }
};

signed main(){
  while(cin>>l>>r>>p,l){
    RSQ R;
    vector<string>v;
    for(int i=l;i<=r;i++){
      stringstream s; s<<i;
      v.push_back(s.str());
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++){
      int x=stoi(v[i]);
      R.add(x-l,(R.sum(x-l)+1)%p);
    }
    cout<<R.sum(r-l+1)<<endl;
  }
}


Measured memory_bytes: 12588
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

s = input()
t = input()


for i in range(len(s)):
    s = s[-1] + s[0:-1]
    if (s == t):
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 8948
#include<bits/stdc++.h>
using namespace std;
struct node
{
	int r;
	int l;
}a[100001];
bool cmp(node x1,node x2)
{
	return x1.r<x2.r;
}
int main()
{
	int n,ans=1,i,x,y;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x>>y;
		a[i].l=x-y;
		a[i].r=x+y;
	}
	sort(a+1,a+1+n,cmp);
	int p=a[1].r;
	//for(i=1;i<=n;i++)
	//cout<<a[i].l<<" "<<a[i].r<<endl;
	for(i=2;i<=n;i++)
	if(a[i].l>=p)
	{
		  ans++;
		  p=a[i].r;	
	}
	cout<<ans; 
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);


int main(){
  ll n,l;
  cin >> n >> l;
  string ans="";
  vector<string>vec(n);
  rep(i,n)cin>>vec[i];
  sort(vec.begin(),vec.end());
  rep(i,n)ans+=vec[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import heapq
N,M = map(int,input().split())
A = list(map(int,input().split()))
heap = []
for i in range(N):
    heapq.heappush(heap,-A[i])
for _ in range(M):
    a = heapq.heappop(heap)
    a = -a
    a = a//2
    heapq.heappush(heap,-a)
print(-sum(heap))

Measured memory_bytes: 92036
#include <stdio.h>
int main(){
        int num[6];
        int i,j,k;
        for(i=0;i<5;i++){
                scanf("%d", &num[i]);
        }
        for(i=0;i<5;i++){
                for(j=0;j<5;j++){
                        if(num[i]>num[j]){
                                k      = num[i];
                                num[i] = num[j];
                                num[j] = k;
                        }
                }
        }
        for(i=0;i<5;i++){
                printf("%d",num[i]);
                if(i < 4){
                        printf(" ");
                }else if(i = 4){
                        printf("\n");
                }
        }
return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define INPUT()              freopen("input.txt", "r", stdin)
                #define OUTPUT()             freopen("output.txt", "w", stdout)
                #define F                    first
                #define S                    second
            //Templatefunctions
                template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}
                template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}
                template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}
            //datatypes
                typedef long long int ll;
                typedef unsigned long long int ull;
                typedef long double ld;
            //constants
                const double INF = 1e+9;
                const double INFLL = 1e+18;
                const double EPS = 1e-9;
                const double PI = acos(-1);
                const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
                       //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
                       //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
                const int dx[] = {0 , 1 , 0 , -1};
                const int dy[] = {1 , 0 , -1 , 0};
            //helpers
                //#define MOD         1000000007LL
                #define MAX         1000005
                const ll MOD = 1000000000 + 7;
                int arr[MAX];
            //Global Variables
                int main()
                {
                    ll n , m;
                    scanf("%lld",&n);
                    ll mul = 1;
                    for(ll i = 1 ; i <= n ; i++)
                    {
                        mul = mul *  i % (1000000000 + 7);
                    }
                    printf("%lld\n",mul);
                }


Measured memory_bytes: 384
N = int(input())
d = []
for j in range(N):
    X, Y, H = map(int,input().split())
    d.append([X, Y, H])
    if H != 0:
        a = [X, Y, H]
for x in range(101):
    for y in range(101):
        flag = True
        h = a[2] + abs(a[0] - x) + abs(a[1] - y)
        for i in d:
            if i[2] != max(h - abs(i[0] - x) - abs(i[1] - y), 0):
                flag = False
                break

        if flag:
            print(x, y, h)
            exit()

Measured memory_bytes: 3064
#include <stdio.h>
int main() {
	int l,r,min=1000000000;
	scanf("%d%d", &l,&r);
	if (r-l>=2019) {
		min=0;
	} else {
		for (int i = l; i < r; i++) {
			for (int j = i+1; j <= r; j++) {
				if((i%2019)*(j%2019)%2019<min){
					min=(i%2019)*(j%2019)%2019;
				}
			}
		}
	}
	printf("%d\n", min);
	return 0;
}


Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;
using ll = long long;

int main() {
	int H, W; cin >> H >> W;
	vector<vector<int>> vec(H, vi(W));
	rep(i, H)rep(j, W) cin >> vec[i][j];

	vector<vector<int>> answers;
	int direction = 1;
	int j = -1;
	for (int i = 0; i < H; i++) {
		if (direction == 1) {
			for (int j = 0; j < W; j++) {
				if (vec[i][j] % 2 == 1) {
					if (j == W - 1) {
						if (i == H - 1) goto endloop;
						answers.push_back({ i,j,i + 1,j });
						vec[i][j]--;
						vec[i + 1][j]++;
					}
					else {
						answers.push_back({ i,j,i,j + 1 });
						vec[i][j]--;
						vec[i][j + 1]++;
					}
				}
			}
			direction *= -1;
		}
		else {
			for (int j = W-1; j > -1; j--) {
				if (vec[i][j] % 2 == 1) {
					if (j == 0) {
						if (i == H - 1) goto endloop;
						answers.push_back({ i,j,i + 1,j });
						vec[i][j]--;
						vec[i + 1][j]++;
					}
					else {
						answers.push_back({ i,j,i,j - 1 });
						vec[i][j]--;
						vec[i][j - 1]++;
					}
				}
			}
			direction *= -1;
		}

	}
endloop:
	cout << answers.size() << endl;

	for (auto a : answers) {
		cout << a[0]+1 << " " << a[1]+1 << " " << a[2]+1 << " " << a[3]+1 << endl;
	}
}

Measured memory_bytes: 11156
import sys
matrix = [input().split() for i in range(3)]
matrix.append([matrix[0][0], matrix[1][1], matrix[2][2]])
matrix.append([matrix[0][2], matrix[1][1], matrix[2][0]])
matrix.append([matrix[0][2], matrix[1][1], matrix[2][0]])
matrix.append([matrix[0][0], matrix[1][0], matrix[2][0]])
matrix.append([matrix[0][1], matrix[1][1], matrix[2][1]])
matrix.append([matrix[0][2], matrix[1][2], matrix[2][2]])

N = int(input())
bingo = [input() for i in range(N)]

for i in matrix:
    if i[0] in bingo and i[1] in bingo and i[2] in bingo:
        print('Yes')
        sys.exit()
print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const int INF = 2e9;
const ll large_P = 1e9 + 7;


int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> A(N);
  rep(i, N) cin >> A.at(i);
  
  int all_vote = 0;
  rep(i, N) all_vote += A.at(i);
  
  sort(A.begin(), A.end(), greater<int>());
  
  bool res;
  if(all_vote % (4*M) == 0){
    if(A.at(M-1) >= all_vote/(4*M)) res = true;
    else res = false;
  }else{
    if(A.at(M-1) > all_vote/(4*M)) res = true;
    else res = false;
  }
  
  if(res) cout << "Yes" << endl;
  else cout << "No" << endl;
  //rep(i, N) cout << A.at(i) << endl;
  
}

Measured memory_bytes: 256
import collections
    
n, m = map(int, input().split())
A = list(map(int, input().split()))
ans_list = [0] * (n + 1)
for i in range(1, n + 1):
  A[i - 1] %= m
  ans_list[i] = (ans_list[i - 1] + A[i - 1]) % m
ans_list.pop(ans_list[0])
ans_list = dict(collections.Counter(ans_list))
  
#print(A)
#print(ans_list)
count = 0
if 0 in ans_list:
  count = ans_list[0]
#print(count)
for v in ans_list.values():
  #print(v)
  if v != 1:
    count +=  v * (v - 1) / 2
    
print(int(count))   
    
    


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

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

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    int c[3][3], d[3][3];
    rep(i, 3) {
      rep(j, 3) {
        cin >> c[i][j];
      }
    }

    rep(i, 3) {
      REP(j, 1, 3) {
        d[i][j] = c[i][j] - c[i][j-1];
      }
    }

    REP(j, 1, 3) {
      REP(i, 1, 3) {
        if(d[i][j] != d[0][j]) {
          cout << "No" << endl;
          return 0;
        }
      }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 100000

typedef struct pp{
  char name[10];
  int time;
}P;

void enqueue(P);
P dequeue(void);

P queue[LEN];
int head = 0, tail = 0;

int main(){
  
  int elaps = 0, count = 0;
  int i, q, n;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 0; i < n; i++){
    scanf("%s", queue[i].name);
    scanf("%d", &queue[i].time);
    tail++;
  }

  while(1){
   if(count == n) break; 
     u = dequeue();   
     if((u.time-q) <= 0){
      elaps += u.time;
      printf("%s %d\n",u.name,elaps);
      count++;
    }

     else {
       u.time -= q;
       enqueue(u);
       elaps += q;
     }
    
   
  }
  
  return 0;
}

void enqueue(P x){
  int next = (tail+1)%LEN;
  if(tail+1 == head){
    printf("a\n");
    exit(2);
    }
  strcpy(queue[tail].name,x.name);
  queue[tail].time = x.time;
  tail = next;

}

P dequeue(){
  P val;
  if(head == tail) {
    printf("b\n");
    exit(3);
    }

  strcpy(val.name,queue[head].name);
  val.time = queue[head].time;
  head = (head+1)%LEN;

  return val;
  
}



Measured memory_bytes: 3360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i, 0, n) cin >> p[i];
    rep(i, 0, n) cin >> q[i];
    vector<int> x(n);
    rep(i, 0, n) x[i] = i + 1;
    int a = 0, b = 0;
    int cnt = 0;
    do {
        cnt++;
        if (x == p) a = cnt;
        if (x == q) b = cnt;
    } while(next_permutation(all(x)));
    cout << abs(a - b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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

int ab(int x){
    if(x <= 0){
        x = -x;
    }
    return x;
}

bool dp[85][85][160 * 80 + 3];


int main(){
    int h, w;
    cin >> h >> w;
    int x[100][100];
    int a[100][100];
    int b[100][100];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < (h + w) * 80; k++){
                dp[i][j][k] = false;
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> b[i][j];
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            x[i][j] = max(a[i][j], b[i][j]) - min(a[i][j], b[i][j]);
        }
    }

    dp[0][0][x[0][0]] = true;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < (h + w) * 80; k++){
                if(!dp[i][j][k]){
                    continue;
                }
                if(i + 1 < h){
                    int k1 = k + x[i+1][j];
                    int k2 = ab(k - x[i+1][j]);
                    dp[i+1][j][k1] = true;
                    dp[i+1][j][k2] = true;
                }
                if(j + 1 < w){
                    int k1 = k + x[i][j+1];
                    int k2 = ab(k - x[i][j+1]);
                    dp[i][j+1][k1] = true;
                    dp[i][j+1][k2] = true;
                }
            }
        }

    }

    int res = INT32_MAX;
    for(int k = 0; k < 1000; k++){
        if(dp[h-1][w-1][k]){
            res = k;
            break;
        }
    }
    cout << res << endl;


    return 0;
}




Measured memory_bytes: 86272
a=[]
b=[]
for i in range(3):
    a.append(list(map(int,input().split())))
n=int(input())
for i in range(n):
    b.append(int(input()))
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j]=101
for i in range(3):
    if sum(a[i])==303:
        print('Yes')
        exit()
    if a[0][i]+a[1][i]+a[2][i]==303:
        print('Yes')
        exit()
if a[0][0]+a[1][1]+a[2][2]==303 or a[0][2]+a[1][1]+a[2][0]==303:
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007



int main() {
    vi A(5);
    rep(i,5) cin >> A[i];
    int ans = 0;
    int num = 0;
    rep(i,5){
        int x = ((A[i] + 10 - 1)/10)*10;
        ans += x;
        num = max(num,x - A[i]);
    }

    cout << ans - num << endl;
}



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

int main() {
	int n, k;
	cin>>n>>k;
	vector<int> h(n);
	for(int &x : h) cin>>x;
//	for(int i=0; i<n; i++) cin>>h[i];
	vector<int> dp(n, INT_MAX);
	dp[0] = 0;
	for(int i=0; i<n; i++) {
		for(int j=i+1; j<min(i+k+1, n); j++) {
			dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
		}
		
	}
	
	cout<<dp[n-1];
	return 0;
	
	
}

Measured memory_bytes: 4048
N, T = map(int,input().split())
t = list(map(int,input().split()))
ans = 0
s, e = 0, T
for k in range(1,N):
    if e < t[k]:
        ans += e-s
        s = t[k]
        e = t[k] + T
    else:
        e = t[k] + T
ans += e-s
print(ans)


Measured memory_bytes: 26836
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  long long n;
  std::vector<long long> C, V;

  cin >> n;
  C.resize(n);
  V.resize(n);
  for (long long i=0;i<n;++i) {
    cin >> V[i];
  }
  for (long long i=0;i<n;++i) {
    cin >> C[i];
  }

  std::vector<long long> G(n);
  for (long long i=0;i<n;++i) {
    G[i] = V[i] - C[i];
  }

  long H = 0;
  for (long long i=0;i<n;++i) {
    if (G[i]>0) {
      H += G[i];      
    }
  }
  
  cout << H << std::endl;

  return 0;
}

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


using namespace std;






int main() {
    string s;
    int k;
    cin>>k;
    cin>>s;
    int n=s.size();
    if(n>k){
        for(int i=0;i<k;i++) cout<<s[i];
        cout<<"...";}
    else cout<<s;




















    return 0;
}


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

int main() {
  int N;
  string s ;
  cin >> N >> s ;
  int count = 0 ;
  int mx = 0 ;
  for ( int i=0 ; i < N ; i++){
    if ( s.at(i) == 'I' ) {
      count ++ ;
    }else count -- ;
    mx = max (count , mx) ;
  }
  cout << mx << endl;
}
  

Measured memory_bytes: 3568
def main():
    x = int(input())
    for i in range(-1000, 1000):
        m = x + i ** 5 
        if m >= 0:
            if (m ** 0.2 - int(m**0.2)) <= 10e-5:
                B = i
                break
    A = (x + B ** 5)**0.2
    print(int(A), B)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 64804
n=int(input())
a=list(map(int,input().split()))
b=[abs(i) for i in a]
m=len([i for i in a if i<0])
M=len([i for i in a if i>0])
ans=0
if (m%2==1 and M%2==0) or (m%2==M%2==1):
    ans=sum(b)-2*min(b)
else:
    ans=sum(b)
print(ans)

Measured memory_bytes: 14412
IMPOSSIBLE = 999999

h, w = gets.chomp!.split(" ").map(&:to_i)
matrix = Array(h)
h.times do |i|
    matrix[i] = gets.chomp!.chars
end

x_count = 0
matrix.each do |row|
    row.each do |ch|
        if ch == "#"
            x_count += 1
        end
    end
end

memo = Array.new(h)
h.times do |i|
    memo[i] = Array.new(w, IMPOSSIBLE)
end
memo[0][0] = 0

# h, w, cost
stack = [[0,0,0]]
while stack.empty?.!
    i, j, cost = stack.pop
    cost += 1

    if i != 0   && matrix[i-1][j  ] == "." && cost < memo[i-1][j  ] 
        memo[i-1][j  ] = cost
        stack.push([i-1, j, cost])
    end 
    if i != h-1 && matrix[i+1][j  ] == "." && cost < memo[i+1][j  ]
        memo[i+1][j  ] = cost
        stack.push([i+1, j, cost])
    end
    if j != 0   && matrix[i  ][j-1] == "." && cost < memo[i  ][j-1] 
        memo[i  ][j-1] = cost
        stack.push([i, j-1, cost])
    end
    if j != w-1 && matrix[i  ][j+1] == "." && cost < memo[i  ][j+1] 
        memo[i  ][j+1] = cost
        stack.push([i, j+1, cost])
    end

end

if memo[-1][-1] == IMPOSSIBLE
    puts -1
else
    puts h * w - (memo[-1][-1] + 1) - x_count
end


Measured memory_bytes: 2172