akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  int count = 0;
  for(int i = 0; i < n; i++)cin >> a[i];
  for(int i = 1; i < n-1; i++){
    if(a[i] < max({a[i-1], a[i], a[i+1]}) && a[i] > min({a[i-1], a[i], a[i+1]}))count++;
  }
  cout << count << 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;
typedef pair <double,double> P;

int main() {
  int n;
  cin>>n;
  ll a[200000];
  ll sum=0;
  rep(i,n) {
    cin>>a[i];
    sum+=a[i];
  }
  ll sum2=0;
  ll ans=1e18;
  rep(i,n) {
    sum2+=a[i];
    ans=min(ans,abs(sum2-(sum-sum2)));
  }
  cout<<ans<<endl;
  return 0;
}




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

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

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1'000'000'007;
// constexpr i64 MOD = 998'244'353;
using m64 = modint<MOD>;

m64 modpow(m64 x, i64 n) {
    m64 res = 1;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

void solve() {
    i64 n;
    cin >> n;

    vector<p64> ab(n);
    map<p64, p64> cnt;
    i64 ans0 = 0;
    for (auto& [ a, b ] : ab) {
        cin >> a >> b;
        if (a == 0 && b == 0) {
            ans0++;
        } else if (a == 0) {
            cnt[{ 1, 0 }].first++;
        } else if (b == 0) {
            cnt[{ 1, 0 }].second++;
        } else {
            if (b < 0) a *= -1, b *= -1;
            i64 g = gcd(a, b);
            a /= g, b /= g;
            (a < 0 ? cnt[{ b, -a }].first : cnt[{ a, b }].second)++;
        }
    }

    m64 ans1 = 1;
    for (auto& [ ignore, v ] : cnt) {
        ans1 *= modpow(2, v.first) + modpow(2, v.second) - 1;
    }
    cout << ans1 - 1 + ans0 << endl;
}

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


Measured memory_bytes: 21880
n= int(input())
s=[]
a=[0,0,0,0]
for i in range(n):
    temp=input()
    if temp=="AC":
        a[0]+=1
    elif temp=="WA":
        a[1]+=1
    elif temp=="TLE":
        a[2]+=1
    else:
        a[3]+=1
print("AC x",a[0])
print("WA x",a[1])
print("TLE x",a[2])
print("RE x",a[3])

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	double n;
	cin >> n;
	double k = n / 3;
	cout << setprecision(10) << fixed << double(k * k * k) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005 

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

typedef tuple<int, int, int> tpl;

//繋げる方向を一方向にする
typedef struct union_find {

	vector<ll> pa;//親
	vector<ll> ra;//木の深さ
	vector<ll> siz;
	//n要素で初期化
	void init(ll n) {
		pa.resize(n);
		ra.resize(n);
		siz.resize(n);
		for (ll i = 0; i < n; i++) {
			pa[i] = i;/*各ノードに番号を振る,この時par[x]=xとなる時は木の根となる*/
			ra[i] = 0LL;/*各ノード自体の高さは0*/
			siz[i] = 1LL;
		}
	}
	//木の根を求める
	ll find(ll x) {
		if (pa[x] == x) {
			return x;/*根ならそのノードの番号を返す*/
		}
		else {
			return pa[x] = find(pa[x]);/*根でないならさらにノードの根を探す*/
		}
	}

	//xとyの属する集合を併合する
	void unite(ll x, ll y) {
		x = find(x);//xの根の番号を探す
		y = find(y);//yの根の番号を探す
		if (x == y) {//一致すればつながっている
			return;
		}
		pa[y] = x;
		siz[x] += siz[y];
	}

	//xとyが同じ集合に属するか判定
	bool same(ll x, ll y) {
		return find(x) == find(y);//同じ集合なら1、違うなら0が返る
	}
}UF;

int main() {

	ll n;
	cin >> n;
	vector<tpl> vec(n-1);
	for (int i = 0; i < n-1; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		vec[i] = tpl(c, a, b);
	}

	UF tree;
	tree.init(n);
	
	sort(vec.begin(), vec.end());

	ll ans = 0;

	for (int i = 0; i < n-1; i++)
	{
		ll a, b, c;
		tie(c, a, b) = vec[i];
		a = tree.find(a);
		b = tree.find(b);
		if (!tree.same(a, b))
		{
			ans += 1LL * c * tree.siz[a] * tree.siz[b];
			tree.unite(a, b);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 9960
import java.util.*;
import java.lang.*;
public class Main{
	  public static void main(String args[])
	  {
	    Scanner sc=new Scanner(System.in);
	    int K=sc.nextInt();
        sc.nextLine();
        String S=sc.nextLine();
	    if(S.length()<=K)
	    {
	      System.out.println(" "+S);
	    }
	    else
	    {
	      String str=S.substring(0,K);
	      str=str+"...";
	      System.out.println(" "+str);
	    }
	  }
	}



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

int main(){
    long long n;
    cin >> n;
    long long a[n+1];
    for(long long i=0;i<=n;i++) cin >> a[i];
    bool flag=true;
    if(n==0&&a[0]!=1){
        cout << -1 << endl;
        return 0;
    }
    if(n==0&&a[0]==1){
        cout << 1 << endl;
        return 0;
    }
    long long b[n+1],c[n+1];
    b[n]=a[n];
    for(long long i=n-1;i>=0;i--){
        b[i]=b[i+1]+a[i];
    }
    c[0]=1;
    for(long long i=1;i<=n;i++){
        long long m=(c[i-1]-a[i-1])*2;
        if(m<=0) flag=false;
        c[i]=min(m,1000000000000000LL);
    }
    if(c[n]<a[n]) flag=false;
    long long ans=0;
    for(long long i=0;i<=n;i++){
        ans+=min(b[i],c[i]);
    }
    if(flag) cout << ans << endl;
    else cout << -1 << endl;
}


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

int main()
{
	int n,m;
	while(cin >> n >> m){
		if(n==0 && m == 0)
			break;
		int stone[50] = {0};
		int j = 0;
		int a = 100;
		int max_m = m;
		while(true){
			for(int i=0;i<n;i++){
				if(stone[i] == max_m)
					a = i;
			}
			if(a != 100)
				break;
		
			if(m > 0){
				stone[j]++;
				m--;
			}
			else{
				m = stone[j];
				stone[j] = 0;
			}
		
			j = (j+1)%n;
		}
		cout << a << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define ll long long
#define eb emplace_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>

int main() {
	int n, q;
	cin >> n >> q;
	dsu d(n);
	rep(i,q) {
		int t, u, v;
		cin >> t >> u >> v;
		if (t == 0) d.merge(u, v);
		else cout << d.same(u, v) << endl;
	}
	return 0;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

/*
0123
n = 4
i<2

*/
void solve()
{
	string s;
	cin>>s;
	int fav = 753;
	int minPos = INT_MAX;
	int n = s.length();
	for(int i=0; i<n-2; i++)
	{
		int ones = s[i+2]-'0';
		int tens = s[i+1]-'0';
		int hundreds = s[i]-'0';
		int num = ones + tens*10 + hundreds*100;
		minPos = min(minPos, abs(num-fav));
	}
	cout<<minPos<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3624
#require 'prime'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi.sort
b=gsmi.sort
c=gsmi.sort

ar=[]
b.each do |i|
  idx=a.bsearch_index{|x|x>=i}||n
  ar<<idx
end


c.each do |i|
  idx=b.bsearch_index{|x|x>=i}||n
  h[idx-1]+=1
end

cnt=0
sum=0
(n-1).downto 0 do |i|
  cnt+=h[i]
  sum+=ar[i]*cnt
end

puts sum

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

int main()
{
	int n;
	int count;

	cin >> n;

	count = n;

	vector<string> data(n);

	for (int i = 0; i < n; i++) 
		cin >> data.at(i);

	sort(data.begin(), data.end());

	for (int i = 0; i < n - 1; i++) {
		if (data.at(i) == data.at(i + 1))
			count--;
	}

	cout << count << endl;

}

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

int main(){
  int N,ans,work;

  while(true){
    cin >> N;
    if(N == 0) break;
    ans = 0;
    for(int i = 1; i<N/2.0; ++i){
      work = i;
      for(int k = i+1;k<=N/2.0+1;++k){
	work += k;

	if(work > N){
	  break;
	}else if(work == N){
	  ++ans;
	  break;
	}
      }
    }

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



Measured memory_bytes: 3056
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int next_int(){
    int i;
    cin >> i;
    return i;
}

long next_long(){
    long l;
    cin >> l;
    return l;
}

string next_line(){
    string s;
    cin >> s;
    return s;
}

int main(){
    const int a=next_int();
    const int b=next_int();
    const int c=next_int();
    const long k=next_long();

    if(k%2){
        cout << b-a << endl;
    }
    else{
        cout << a-b << endl;
    }

    return 0;
}



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

int arr[101] = {0};

int main()
{
	int a, b, k, l;
	cin >> a >> b;
	for(int i=0; i<b; i++)
	{
		cin >> arr[i];
	}
	for(int i=a; i>=0; i--)
	{
		int t=0;
		for(int j=0; j<b; j++)
		{
			if(arr[j] != i)
			{
				t++;
			}	
		}
		if(t == b)
		{
			k=i;
			break;
		}	
	}
	for(int i=a; i<=101; i++)
	{
		int t=0;
		for(int j=0; j<b; j++)
		{
			if(arr[j] != i)
			{
				t++;
			}	
		}
		if(t == b)
		{
			l=i;
			break;
		}	
	}
	if(l-a > a-k)
	{
		cout << k;	
	}	
	else if(l-a < a-k)
	{
		cout << l;
	}
	else
	{
		cout << k;
	}
}



Measured memory_bytes: 3584
#include <iostream>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int x,y,a,b;
    cin>>x>>y;
    For(i,0,x)
    {
        a=i;b=x-i;
        if(a*2+b*4==y)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3648
import collections

n,m = list(map(int,input().split()))
n_list = list(map(int,input().split()))
eliminate_list = []

for i in range(0,m):
  a,b = list(map(int,input().split()))
  if n_list[a-1] > n_list[b-1]:
    eliminate_list.append(b-1)
  elif n_list[a-1] < n_list[b-1]:
    eliminate_list.append(a-1)
  else:
    eliminate_list.append(a-1)
    eliminate_list.append(b-1)

print(n - len(collections.Counter(eliminate_list)))

Measured memory_bytes: 22140
def main():
    S = input()
    N = len(S)
    count1 = 0
    count2 = 0
    for i in range(N):
        count1 += (str(i%2) != S[i])
        count2 += (str((i+1)%2) != S[i])
    return min(count1, count2) 

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		while (true) {
			int n = s.nextInt();
			int r = s.nextInt();

			if (n == 0 && r == 0)
				break;

			int[] a = new int[n];
			int[] b = new int[n];

			for (int t = 0; t < n; t++) {
				a[t] = t + 1;
				b[t] = t + 1;
			}

			for (int i = 0; i < r; i++) {
				int p = s.nextInt();
				int c = s.nextInt();

				for (int x = 0; x < c; x++)
					b[n - c + x] = a[n - p + 1 - c + x];

				for (int y = 0; y < p - 1; y++)
					b[n - c - p + 1 + y] = a[n - p + 1 + y];

				for (int j = 0; j < n; j++)
					a[j] = b[j];
			}
			System.out.println(b[n - 1]);
		}
		s.close();
	}
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 065_arc_b / Link: https://arc065.contest.atcoder.jp/tasks/arc065_b?lang=en  ----- */
/* ------問題------

N 個の都市があり、K 本の道路と L 本の鉄道が都市の間に伸びています。 i 番目の道路は pi 番目と qi 番目の都市を双方向に結び、 i 番目の鉄道は ri 番目と si 番目の都市を双方向に結びます。 異なる道路が同じ 2 つの都市を結ぶことはありません。同様に、異なる鉄道が同じ 2 つの都市を結ぶことはありません。
ある都市から別の都市に何本かの道路を通って到達できるとき、それらの都市は道路で連結しているとします。また、すべての都市はそれ自身と道路で連結しているとみなします。
鉄道についても同様に定めます。
全ての都市について、その都市と道路・鉄道のどちらでも連結している都市の数を求めてください。

-----問題ここまで----- */
/* -----解説等-----

これ昔できなかった気がする
連結グラフの番号がアレばいいので適当にかんりすればよい。

----解説ここまで---- */

LL N, K, L;

LL ans = 0LL;
void dfs(int v, int p, VVI& G, VI& color, int k) {
	color[v] = k;
	FOR(i, 0, SZ(G[v])) {
		int nx = G[v][i];
		if (nx != p&&color[nx]==0)dfs(nx, v, G, color, k);
	}
}

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

	cin >> N >> K >> L;

	VVI Rd(N);
	FOR(i, 0, K) {
		int p, q; cin >> p >> q;
		Rd[p - 1].push_back(q - 1);
		Rd[q - 1].push_back(p - 1);
	}
	VVI Ra(N);
	FOR(i, 0, L) {
		int p, q; cin >> p >> q;
		Ra[p - 1].push_back(q - 1);
		Ra[q - 1].push_back(p - 1);
	}

	VI rdc(N, 0);
	VI rac(N, 0);
	int k = 1;

	FOR(i, 0, N) {
		if (rdc[i] == 0)dfs(i, -1, Rd, rdc, k++);
	}
	k = 1;
	FOR(i, 0, N) {
		if (rac[i] == 0)dfs(i, -1, Ra, rac, k++);
	}
	map<PII, int>Map;
	FOR(i, 0, N) {
		Map[PII(rdc[i], rac[i])] ++;
	}
	FOR(i, 0, N) {
		cout<< Map[PII(rdc[i], rac[i])]<<endl;
	}

	return 0;
}


Measured memory_bytes: 27776
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    // variable
    ll ans = 0;
    vector<int> v(3);

    // input
    cout << fixed << setprecision(10);
    rep(i, 3) cin >> v[i];
    sort(ALL(v));

    // solve
    bool ok = false;
    if(v[0] == v[1] && v[1] != v[2]) ok =true;
    if(v[0] != v[1] && v[1] == v[2]) ok = true;
    yesno(ok);
    
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
#include "atcoder/dsu.hpp"
using namespace std;
using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,q; cin>>n>>q;
    dsu uf(n);
    rep(_,q){
        int t,u,v; cin>>t>>u>>v;
        if(t==0){
            uf.merge(u,v);
        }
        else{
            printf("%d\n",(int)uf.same(u,v));
        }
    }
}


Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    cout<<x*min(n,k)+y*max(0,n-k)<<endl;
}


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

struct node {
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x) {
  while(x -> left != NIL) {
    x = x -> left;
  }
  return x;
}

Node treeSearch(Node u, int k) {
  if(u == NIL || k == u -> key) {
    return u;
  }
  if(k < u -> key) {
    return treeSearch(u -> left, k);
  }
  else {
    return treeSearch(u -> right, k);
  }
}

Node treeSuccessor(Node x) {
  Node y;
  if(x -> right != NIL) {
    return treeMinimum(x -> right);
  }
  y = x -> parent;
  while(y != NIL && x == y -> right) {
    x = y;
    y = y -> parent;
  }
  return y;
}

void treeDelete(Node z) {
  Node y;
  Node x;
  
  if(z -> left == NIL || z -> right == NIL) {
    y = z;
  }
  else {
    y = treeSuccessor(z);
  }
  
  if(y -> left != NIL) {
    x = y -> left;
  }
  else {
    x = y -> right;
  }
  
  if(x != NIL) {
    x -> parent = y -> parent;
  }
  
  if(y -> parent == NIL) {
    root = x;
  }
  else if(y == y -> parent -> left) {
    y -> parent -> left = x;
  }
  else {
    y -> parent -> right = x;
  }
  
  if(y != z) {
    z -> key = y -> key;
  }
} 

void insert(int k) {
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;
  
  while(x != NIL) {
    y = x;
    if(z -> key < x -> key) {
      x = x -> left;
    }
    else {
      x = x -> right;
    }
  }
  z -> parent = y;
  if(y == NIL) {
    root = z;
  }
  else if(z -> key < y -> key) {
    y -> left = z;
  }
  else {
    y -> right = z;
  }
}

void inorder(Node u) {
  if(u != NIL) {
    inorder(u -> left);
    printf(" %d", u -> key);
    inorder(u -> right);
  }
}

void preorder(Node u) {
  printf(" %d", u -> key);
  if(u != NIL) {
    if(u -> left != NIL) {
      preorder(u -> left);
    }
    if(u -> right != NIL) {
      preorder(u -> right);
    }
  }
}

main() {
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for(i = 0; i < n; i++) {
    scanf("%s", com);
    if(com[0] == 'f') {
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com[0] == 'i') {
      scanf("%d", &x);
      insert(x);
    }
    else if(com[0] == 'p') {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com[0] == 'd') {
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}

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

#ifndef ONLINE_JUDGE
#define debarr(a,x,y)cerr<<#a<<":";for(int i=x;i<=y;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define deb(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S, class T>ostream &operator<<(ostream &os, const pair<S, T> &p) {return os << "(" << p.first << "," << p.second << ")";}
template<class T>ostream &operator<<(ostream &os, const vector<T> &p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const set<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const multiset<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class S, class T>ostream &operator<<(ostream &os, const map<S, T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>void dbs(string str, T t) {cerr << str << ":" << t << "\n";}
template<class T, class...S>void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);}
#else
#define deb(...){}
#define debarr(a,x,y){}
#define debmat(mat,row,col){}
#endif

#define int              long long
#define fi               first
#define se               second
#define mp               make_pair
#define pb               push_back
#define rr               return
#define sz(x)            (int)x.size()
#define all(x)           x.begin(),x.end()
#define ini(x,y)         memset(x,y,sizeof(x))
#define rep(i,n)         for(int i=0;i<n;i++)
#define fr(i,a,b)        for(int i=a;i<=b;i++)
#define fb(i,a,b)        for(int i=a;i>=b;i--)

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

const int inf = 4e18;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int n;
int a[25][25];
int dp[22][1 << 22];

int go(int idx, int mask)
{
	if (idx == n) return (mask == 0);
	if (dp[idx][mask] != -1) return dp[idx][mask];
	int ret = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[idx][i] && (mask & (1 << i)))
		{
			ret = (ret + go(idx + 1, mask ^ (1 << i))) % mod;
		}
	}
	return dp[idx][mask] = ret;
}
void solve()
{
	cin >> n;
	rep(i, n) rep(j, n) cin >> a[i][j];
	ini(dp, -1);
	cout << go(0, (1 << n) - 1);
}

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

	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 721280
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
  int n, m, x, y;
  cin >> n >> m;
  vector<int> R(n, 0);
  vector<int> C(n, 1);
  R[0] = 1;
  rep(i, m){
    cin >> x >> y;
    C[x-1]--;
    C[y-1]++;
    if(R[x-1]==1){
      if(R[y-1]==0) R[y-1] = 1; 
    }
    if(C[x-1]==0) R[x-1]=0;
    
  }
  int ans=0;
  //rep(i, n) cout << C[i] << R[i] << endl;
  rep(i, n){
    if(R[i]==1) ans++;
  }
  cout << ans << endl; 
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
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;}
 
const ll INF=1e9+7;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i,n){
        cin >> h[i];
    }
    vector<ll> dp(n,INF);
    dp[0]=0;
    for(ll i=0;i<n;i++){
        for(ll j=1;j<=k;j++){
            if(i+j<=n-1){
                dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
            }
        }
    }
    cout << dp[n-1] << endl;
    return 0;
} 

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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3 = x2 - (y2 - y1);
  int y3 = y2 - (x1 - x2);
  int x4 = x1 + x3 - x2;
  int y4 = y1 + y3 - y2;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding Space*/
map<ll,map<ll,ll>> m;
ll func(ll s,ll x){
  if(m[s][x] != 0) return m[s][x];
  if(s == 0)  return 1;
  ll ret = ( func(s/2,x/2)+func((s-1)/2,(x-1)/2)+(s < 2?0:func((s-2)/2,x/2)) ) %DIV;
  m[s][x] = ret;
  return ret;
}
int main(){
  ll n; cin >> n;
  cout << func(n,n) %DIV << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve()
{
	ll x,k,d,ans;
	cin>>x>>k>>d;
	x=abs(x);
	
	if((x/d)>=k) ans=abs(x-k*d);
	else
	{
		ll tt=x/d;
		x=x-(d*tt);
		k=k-tt;
		if(k%2==0)
		{
			ans=x;
		}
		else
		{
			ans=x-d;
			if(ans<0) ans=ans*(-1);
		}
	}
	cout<<ans;
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
int main()
{
    int n=1;
    int k=1;
  	int i,j;
  	int tmp;
  	int sum=0;
    //種類
    scanf("%d ", &n);
  	//買う果物
  	scanf("%d\n", &k);
  	//種類ごとの価格
  	int p[n];
      for(i=0;i<n;i++){
        scanf("%d ",&p[i]);
      }
  	//バブルソート
  		for(i = 0; i < n; i++){
          for (j = i + 1; j < n; j++){
          	if (p[i] > p[j]){
				tmp = p[i];
				p[i] = p[j];
				p[j] = tmp;
			}
          }
        }
  	//出力
  		for(i=0;i<k;i++){
        	sum+=p[i];
        }
  		printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 1728
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int i = scan.nextInt();
		long max = -1000000, min = 1000000, sum = 0;
		for (int j = 0; j < i; j++) {
			long x = scan.nextLong();
			sum += x;
			if (x > max)
				max = x;
			if (x < min)
				min = x;
		}

		scan.close();
		System.out.println(min + " " + max + " " + sum);

	}
}

Measured memory_bytes: 31776
import java.util.Scanner;

import java.util.Arrays;
import java.util.ArrayList;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long sum = 0;
		if (N <= 2) {
			System.out.println(0);
		}
		else {
			for (int i = 1; i<Math.sqrt(N); i++) {
				if (N % i == 0) {
					if(N/i != i + 1) {
					sum += N/i -1;
					}
				}
			}
		
			System.out.println(sum);
		}
		
	}
}	


Measured memory_bytes: 24020
#include <stdio.h>

int main (){
	int input;
	int temp=0;
	scanf ("%d",&input);
	int cek=input;
	while(input>0){
		temp+=input%10;
		input/=10;
	}
	//printf ("%d",temp);
	if(cek%temp==0){
		printf ("Yes\n");
	}else printf ("No\n");
}

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

int main()
{
    int a,b,c;
    //int counter = 0;
    int answer;
    cin >> a >> b >> c;
    while( a <= b ){
        if (c % a == 0){
            ++answer;
        }
        ++a;
    }
    cout << answer << endl;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
  	int b=0;
  	for(int i=0;i<s.size()/2;i++)
    	if(s[i]!=s[s.size()-1-i])
        	b++;
    cout<<b;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a, b, c;
    scanf("%d %d", &a, &b);
    c = a * b;
    if (a <= 9 && b <= 9)
    {
        printf("%d\n", c);
    }
    else
    {
        printf("-1\n");
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.math.BigDecimal;

public class Main {	

	private static void solve(){
		//Implement solution here.
		int K = ni();
		int N = ni();
		int[] A = na(N);
		
		int[] D = new int[N];
		D[0] = A[0] + K - A[N - 1];
		int maxd = D[0];
		for(int i = 0; i < N - 1; i++) {
			maxd = Math.max(maxd, A[i + 1] - A[i]);
		}
		System.out.println(K - maxd);
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 49616
using System;

class Program
{
  static void Main(string[] args)
  {
    string s = Console.ReadLine();
    if(s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[2] == s[3]) Console.WriteLine("Yes");
    else Console.WriteLine("No");
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    int a[n],b[n],c[n],ans=0;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    rep(i,n-1){
        cin>>c[i];
    }
    rep(i,n){
        ans+=b[a[i]-1];
        if(a[i+1]-1==a[i])ans+=c[a[i]-1];
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3656
use proconio::{fastout, input};

use proconio::marker::Usize1;

#[fastout]
fn main() {
    input! {
        r: usize, c: usize, k: usize,
        rcv: [(Usize1, Usize1, u64); k],
    }
    let mut w = vec![vec![0; c]; r];
    let mut dp = vec![vec![vec![0; c + 1]; r + 1]; 4];
    for (i, j, v) in rcv {
        w[i][j] = v;
    }
    for i in 0..r {
        for j in 0..c {
            dp[0][i + 1][j + 1] = *[
                dp[0][i][j + 1],
                dp[1][i][j + 1],
                dp[2][i][j + 1],
                dp[3][i][j + 1],
                dp[0][i + 1][j],
            ]
            .iter()
            .max()
            .unwrap();
            dp[1][i + 1][j + 1] = *[
                dp[0][i][j + 1] + w[i][j],
                dp[1][i][j + 1] + w[i][j],
                dp[2][i][j + 1] + w[i][j],
                dp[3][i][j + 1] + w[i][j],
                dp[0][i + 1][j] + w[i][j],
                dp[1][i + 1][j],
                //
            ]
            .iter()
            .max()
            .unwrap();
            dp[2][i + 1][j + 1] = *[
                dp[1][i + 1][j] + w[i][j],
                dp[2][i + 1][j],
                //
            ]
            .iter()
            .max()
            .unwrap();
            dp[3][i + 1][j + 1] = *[
                dp[2][i + 1][j] + w[i][j],
                dp[3][i + 1][j],
                //
            ]
            .iter()
            .max()
            .unwrap();
        }
    }
    println!(
        "{}",
        [
            dp[0][r][c],
            dp[1][r][c],
            dp[2][r][c],
            dp[3][r][c],
            //
        ]
        .iter()
        .max()
        .unwrap()
    );
}


Measured memory_bytes: 362000
#include <stdio.h>
#define N 45

int dp[N];

int fibonacci(int n){
  if(n == 0 || n == 1){
    dp[n] = 1;
    return 1;
  }
  if(dp[n] != -1) return dp[n];
  dp[n] =fibonacci(n-1) + fibonacci(n-2);
  return dp[n];
}

int main(){
  int n;
  for(int i = 0; i < N;i++) dp[i] = -1; 
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}



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

const int N = 8080;

inline void Guess(int x, int y) {
	printf("? %d %d\n", x - 1, y - 1);
	fflush(stdout);
}
inline int Receive(void) {
	static char c;
	for (c = getchar(); c != 'Y' && c != 'N'; c = getchar()) {
		swap(c, c);
	}
	return c == 'Y';
}

int a, b, n, top;
int sta[N], ans[N];
vector<int> q;

int main(void) {
	cin >> a >> b;
	n = a + b;
	if (a <= b) {
		printf("Impossible");
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		if (!top) {
			sta[++top] = i;
		} else {
			Guess(sta[top], i);
			if (Receive()) sta[++top] = i;
			else --top;
		}
	}
	for (int i = 1; i <= n; i++) {
		Guess(sta[top], i);
		ans[i] = Receive();
	}
	putchar('!'); putchar(' ');
	for (int i = 1; i <= n; i++)
		putchar('0' + ans[i]);
	putchar('\n');
	return 0;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

int main(){

    int n;
    cin >> n;
    map<ll, ll> mp;
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        mp[a]++;
    }
    ll ans = 0;
    for(auto b : mp){
        if(b.first < b.second){
            ll x = b.second - b.first;
            ans += min(x, b.second);
        }
        else if(b.first > b.second){
            ans += b.second;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9588
#include<iostream>
using namespace std;
#define INF 100000;
int main(){
    int a,b;
    a=b=INF;
    for(int i=0;i<3;i++){
        int c;
        cin>>c;
        a=min(a,c);
    }
    for(int i=0;i<2;i++){
        int c;
        cin>>c;
        b=min(b,c);
    }
    cout<<a+b-50<<endl;
    return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  string s;
  int k; 
  cin >> s >> k;
  int i;
  int left = k;
  int n = s.size();
  rep(i,n-1)
  {
    if(s[i] == 'a')continue;
    if(left >= 'z'-s[i]+1)
    {
      left -= 'z'-s[i]+1;
      s[i] = 'a';
    }
  }
  left %= 26;
  s[n-1] -= 26;
  s[n-1] += left;
  if(s[n-1] < 'a') s[n-1] += 26;
  cout << s << endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll n, i;
    cin >> n;
    ll a[n+1], b[n+1], c[n+1] = {0};
    a[0] = -1;
    for(ll i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(ll i = 1; i <= n; i++){
        cin >> b[i];
    }
    for(ll i = 2; i <= n; i++){
        cin >> c[i];
    }
    ll s = 0;
    for(i = 1; i <= n; i++){
        s += b[a[i]];
        if(a[i] == a[i-1]+1){
            s += c[a[i]]; 
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func rot(x int, y int) (int, int) {
	return -y, x
}

func main() {
	sc.Split(bufio.ScanWords)
	x1, _ := strconv.Atoi(read())
	y1, _ := strconv.Atoi(read())
	x2, _ := strconv.Atoi(read())
	y2, _ := strconv.Atoi(read())
	dx := x2 - x1
	dy := y2 - y1
	dx, dy = rot(dx, dy)
	x3 := x2 + dx
	y3 := y2 + dy
	dx, dy = rot(dx, dy)
	x4 := x3 + dx
	y4 := y3 + dy
	fmt.Printf("%d %d %d %d\n", x3, y3, x4, y4)
}


Measured memory_bytes: 640
from collections import deque

def main():
    
    # input & initialize
    n, q = map(int, input().split())

    total_time = 0

    dname = deque()
    dtime = deque()

    for i in range(n):
        nametmp, timetmp = input().split()
        dname.append(nametmp)
        dtime.append(int(timetmp))
    
    while dname or dtime: # queueになにか入っていればTrue
        name = dname.popleft()
        time = dtime.popleft()
        if time <= q: # q以下だったら除外
            total_time += time
            print(name, total_time)
        else: # q以上だったらtime減らしてFIFOに戻す
            total_time += q
            time -= q
            dname.append(name)
            dtime.append(time)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9884
S = list(input())


L = []
M = []

for i in range(len(S)//2):
    L.append("0")
    L.append("1")
    M.append("1")
    M.append("0")

if (len(S)) % 2 != 0:
    
    L.append("0")
    M.append("1")
    

cn_1 = 0
cn_2 = 0

for i in range(len(S)):
    if S[i] != L[i]:
        cn_1 = cn_1 + 1
    else:
        cn_2 = cn_2 + 1
        
print(min(cn_1, cn_2))

Measured memory_bytes: 85220
n = int(input())

h = list(map(int, input().split()))

jug = True
for i in range(n-1):
    if h[i] <= h[i+1]:
        continue
    if h[i] == h[i+1] + 1:
        h[i+1] += 1
    else:
        jug = False

if jug == True:
    print("Yes")
elif jug == False:
    print("No")

Measured memory_bytes: 63856
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

cnt = 0
for i in range(0,N):
  if B[i]-A[i]<0:
    cnt += B[i]
    #print(cnt)
  else:
    if A[i+1]-(B[i]-A[i])<0:
      cnt += A[i+1]+A[i]
      A[i+1] = 0
      #print(cnt,1)
    else:
      cnt += B[i]
      A[i+1] -= (B[i]-A[i])
      #print(cnt,2)
    #print(A,B)
print(cnt)

Measured memory_bytes: 18624
// ALDS 1_3_A Stack
import java.io.*;


class Main {

   static int[] S = new int[1000];
   static int top = 0;

   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      try {
         int x;
         int a, b;
         String[] in = br.readLine().split(" ");
         for (int i = 0; i < in.length; i++) {
            if (in[i].equals("+")) {
               a = pop();
               b = pop();
               push(a + b);
            } else if (in[i].equals("-")) {
               b = pop();
               a = pop();
               push(a - b);
            } else if (in[i].equals("*")) {
               a = pop();
               b = pop();
               push(a * b);
            } else {
               x = Integer.parseInt(in[i]);
               push(x);
            }
         }
         System.out.println(pop());
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
   static void push(int x) {
      top++;
      S[top] = x;
   }
   static int pop() {
      top--;
      return S[top + 1];
   }
}

Measured memory_bytes: 24420
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b){
        cout << c;
    }else if(a==c){
        cout << b;
    }else{
        cout << a;
    }
}

Measured memory_bytes: 256
N, Y = map(int, input().split())

a = -1
b = -1
c = -1
for i in range(N+1):
    for j in range(N+1):
        total = 10000*i + 5000*j + 1000*(N-i-j)
        if total == Y and N-i-j >= 0:
            a = i
            b = j
            c = N-i-j
            break
print("{} {} {}".format(a,b,c))

Measured memory_bytes: 3064
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

float metric(vector<int>& a, vector<int>& b) {
  float sum = 0;

  rep(i, a.size()) { sum += (a[i] - b[i]) * (a[i] - b[i]); }
  return sqrt(sum);
}

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  rep(i, N) { cin >> p[i]; }
  int count = 0;
  rep(i, N - 1) {
    if (p[i] != i + 1) {
      count++;
    }
  }

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int
#define FIO  ios::sync_with_stdio(false); cin.tie(0);   cout.tie(0);
#define all(in) in.begin(), in.end()
typedef pair<ll, ll> pll;


void solve(){
    ll n;   cin >> n;
    vector<ll> x(n), y(n);
    vector<ll> v1(n), v2(n);
    for(ll i = 0 ; i < n ; i++){
        cin >> x[i] >> y[i];
        v1[i] = x[i] + y[i];
        v2[i] = x[i] - y[i];
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    ll ans = max(v1[n-1] - v1[0], v2[n-1] - v2[0]);
    cout << ans << endl;
}

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


Measured memory_bytes: 9536
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int ans=0;
  if(n>9){
    ans+=9;
    if(n>99){
      if(n>999){
        ans+=900;
        if(n>9999){
          if(n>99999) ans+=90000;
          else ans+=n-9999;
        }
      }else {
        ans+=n-99;
      }
    }
  }else ans=n;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int main(){
  int N,i = 0,c = 0;

  cin>>N;

  int a[N];
  bool j[N];

  REP(i,N){
    cin>>a[i];
    j[i] = true;
  }

  while(1){
    j[i] = false;
    i = a[i]-1;
    c++;
    if(i == 1){
      cout<<c<<endl;
      break;
    }
    if(!j[i]){
      cout<<-1<<endl;
      break;
    }

  }

  return 0;
}


Measured memory_bytes: 768
from math import gcd
mod = 1000000007
n = int(input())
zero = 0
bad = {}
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = gcd(x, y)
    x //= g
    y //= g
    if y < 0: x, y = -x, -y
    if y==0 and x<0: x, y = -x, -y
    is_rotate90 = (x <= 0)
    if is_rotate90:
        x, y = y, x
        y = -y
    if not (x, y) in bad:
        bad[x, y] = [0, 0]
    if is_rotate90:
        bad[x, y][0] += 1
    else:
        bad[x, y][1] += 1

# print(bad)

cnt = 1
for x, y in bad:
    c1, c2 = bad[x, y]
    c3 = 1
    c3 += pow(2, c1, mod) - 1
    c3 += pow(2, c2, mod) - 1
    cnt = cnt * c3 % mod

ans = (cnt + zero - 1) % mod

# print('cnt',cnt)
# print('zero',zero)
# print('ans',ans)
print((ans+mod) % mod)


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for(int i=0; i<M; i++) cin >> s[i] >> c[i];
  
  string num(N,'0');
  num[0]='1';
  int start=stoi(num);
  num+='0';
  int end=stoi(num);
  if(N==1) start=0;
  for(int i=start; i<end; i++){
    string check=to_string(i);
    bool x=true;
    for(int j=0; j<M; j++){
      if (check[s[j]-1]!=c[j]+'0'){
        x=false;
        break;
      }
    }
    if (x){
      cout << i <<endl;
      return 0;
    }
  }
  cout << -1 <<endl;
}


Measured memory_bytes: 256