akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

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

  int odd = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    if (a % 2) ++odd;
  }

  if (!(odd % 2)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}


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

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    int ans = 0;

    while(true) {
        bool ok = true;
        REP(i,N) {
            if (A[i] % 2 == 1) {
                ok = false;
                break;
            } else A[i] /= 2;
        }
        if (ok) ans++;
        else break;
    }

    cout << ans << endl;  

    return 0;
}

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

int main()
{
	int n, k;
	string s;
	cin >> n >> s >> k;
	char x = s.at(k - 1);
	for (int i = 0; i < n; i++)
	{
		if (s.at(i) != x)
			s.at(i) = '*';
	}
	cout << s << endl;
	return 0;
}

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

#define ll long long
#define ar array
 
using namespace std;

int main() {
	
	int n, w[100000],aux=1,aux2=0,soma1=0,soma2=0,base;
	
	cin >> n;
	
	for(int i=0;i<n;i++){
		cin >> w[i];
	}
	for(int i=0;i<n;i++){
		soma2+=w[i];
	}
	base = soma2-soma1;
	for(int i=0;i<n;i++){
		soma1+=w[aux2];
		soma2-=w[aux2];
		if((soma2-soma1)>=0 && (soma2-soma1) < base){
			base = soma2-soma1;
		}
		if((soma2-soma1)<0&&(soma1-soma2)<base){
			cout << soma1-soma2 << endl;
			return 0;
		}
		aux2++;
	}
	cout << base << endl;
   	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;

vector<vector<ll>>bits(ll N){
	vector<vector<ll>> V;
	for(int t=0;t<(1<<N);t++){
		vector<ll> vv;
		for(int i=0;i<N;i++){
			if(t&(1<<i))vv.push_back(i);
		}
		V.push_back(vv);
	}
	return V;
}

int main()
{
	ll N,M,X;
	vector<vector<ll>>V;
	vector<vector<ll>>Book;
	vector<ll>ANS;
	cin>>N>>M>>X;
	V=bits(N);
	rep(i,N){
		vector<ll>a;
		rep(j,M+1){
			ll t;
			cin>>t;
			a.push_back(t);
		}
		Book.push_back(a);
	}
	rep(i,V.size()){
		bool F=true;
		ll cost=0;
		vector<ll>skill(M,0);
		rep(j,V[i].size()){
			rep(k,M+1){
				//cout<<Book[V[i][j]][k]<<" ";
				if(k==0)cost+=Book[V[i][j]][k];
				else{
					skill[k-1]+=Book[V[i][j]][k];
				}
			}
		}
		rep(j,skill.size()){
			if(skill[j]<X)F=false;
		}
		if(F)ANS.push_back(cost);
	}
	sort(ANS.begin(),ANS.end());
	if(ANS.size()>0){
		cout<<ANS.front()<<endl;
	}else{
		cout<<"-1"<<endl;
	}
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

bool check(string a, string b){
    REP(i, a.size()){
        if(a[i]==b[i]||a[i]=='?');
        else return false;
    }
    return true;
}

int main(){
    string str, T;
    cin >> str >> T;
    for(int i = str.size() - T.size();i>=0;--i){
        if(check(str.substr(i, T.size()), T)){
            REP(j, T.size())str[i+j]=T[j];
            foreach(i, str)cout << (i=='?'?'a':i);
            cout << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
    return 0;
}


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

class Program {
    static void Main() {
        var a = NextLong();
        var b = NextLong();
        var c = NextLong();

        var s = Min(a, Min(b, c));
        var l = Max(a, Max(b, c));
        var m = a + b + c - s - l;

        foreach (var v in new long[] { s, m, l }) {
            if (v % 2 == 0) {
                WriteLine(0);
                return;
            }
        }
        WriteLine(s * m);
    }

    static long NextLong() {
        return long.Parse(NextString());
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int N = 55556;
bool prime[N];
vector<int> p;
void sieve(){
    memset(prime,1,sizeof(prime));
    for (int i = 2; i < N; ++i)
    {
        if(prime[i])
        {
            if(i%5 == 1)
                p.push_back(i);
            for(int j = 2*i ; j < N; j += i)
                prime[j] = 0;
        }
    }
}
signed main(){
    int t = 1; //cin >> t;
    while(t--){
        int n; cin >> n;
        sieve();
        for(int i = 0; i < n; i++)
            cout << p[i] << " ";
    }    
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>

void print(std::vector<std::string> readGrid){
    int sz = readGrid.size();
    for(int i = 0; i < sz; ++i){
        std::cout << readGrid.at(i) << std::endl;
    }
}
int main(){
    int h, w;
    std::cin >> h >> w;

    std::vector<std::string> grid;
    std::string dummy(w + 2, '$');
    grid.push_back(dummy);
    for(int i = 0; i < h; ++i){
        std::string s;
        std::cin >> s;
        grid.push_back("$" + s + "$");
    }
    grid.push_back(dummy);

//    print(grid);

    bool flg = true;
    int i = 1;
    while(flg && i < h - 1){
        for(int j = 1; j < w - 1; ++j){
            if('#' == grid.at(i).at(j)){
                std::string buf =   grid.at(i - 1).substr(j, 1);
                            buf +=  grid.at(i + 1).substr(j, 1);
                            buf +=  grid.at(i).substr(j - 1, 1);
                            buf +=  grid.at(i).substr(j + 1, 1);
                if(std::string::npos == buf.find("#")){
                    flg = false;
                }
            }
        }
        ++i;
    }

    std::string ans = "No";
    if(flg){
        ans = "Yes";
    }

    std::cout << ans << std::endl;

    return 0;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n;
  cin >> n;
  map<int, int> a[n];
  for(int i=0;i<n;i++){
    int num;
    cin >> num;
    for(int j=0;j<num;j++){
      int x,y;
      cin >> x >> y;
      x--;
      a[i][x] = y;
    }
  }
  int maxCount = 0;
  for(int64_t i=0;i <= (1<<(n+1));i++){
    bool isFailed = false;
    int count = 0;
    for(int j=0;j<n;j++){
      if(isFailed)break;
      if((i&(1<<j))!=0){
        count++;
        for(auto p:a[j]){
           if((i&(1<<p.first))!=0){
             if(p.second==0) isFailed = true;
           }
           else{
             if(p.second==1) isFailed = true;
           }
           if(isFailed)break;
        }
      }
    }
    if(!isFailed){
      maxCount = max(maxCount,count);
    }
  }
  cout << maxCount << endl;
  return 0;
}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastio;
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int left = a + b;
    int right = c + d;
    if (left > right)
        cout << "Left";
    else if (left < right)
        cout << "Right";
    else
        cout << "Balanced";
    cout << endl;
}

Measured memory_bytes: 3524
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
typedef long long ll;

using namespace std;
struct A
{
    int s;
    int e;
    int c;
};
A a[100005];
int b[100005], c[100005];
int cmp(A a, A b)
{
    return a.s < b.s;
}
int main()
{
    int n, C;
    cin >> n >> C;
    for(int i = 0; i < n; i++)
    cin >> a[i].s >> a[i].e >> a[i].c;
    sort(a, a+n, cmp);
    int ji = 0;
    b[ji] = a[0].e;
    c[ji++] = a[0].c;
    for(int i = 1; i < n; i++)
    {
        int mins = INF;
        int ok = -1;
        for(int j = 0; j < ji; j++)
        {
            if(a[i].c == c[j])
            {
                if(a[i].s >= b[j])
                {
                    if(b[j] < mins)
                    {
                        ok = j;
                        mins = b[j];
                    }
                }
            }
            else
            {
                if(a[i].s > b[j])
                {
                    if(b[j] < mins)
                    {
                        ok = j;
                        mins = b[j];
                    }
                }
            }
        }
        if(ok == -1)
        {
            b[ji] = a[i].e;
            c[ji] = a[i].c;
            ji++;
        }
        else
        {
            b[ok] = a[i].e;
            c[ok] = a[i].c;
        }
    }
    cout << ji << endl;
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using vi = vector<int>; using vll = vector<long long>; 
using vvi = vector<vector<int> >; using vb = vector<bool>;
using pii = pair<int,int>; 
#define pb push_back
#define all(v) v.begin(),v.end()
#define llmax 9223372036854775807
#define intmax 2147483647
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const ll mod = 1e9+7;
//////////////////////////////////////////
#define test(t) int t; cin>>t; while(t--)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
////////////////////////////////////////////
#define tki take_input 
#define tkii take_input<int>
template <typename T> void take_input(vector<T> &a, int size){ T tmp; for(int i=0;i<size;i++){ cin>>tmp; a.push_back(tmp); } }
#define prv print_vector
#define prvi print_vector<int> 
template <typename T> void print_vector(vector<T> v){ for(int i=0;i<v.size();i++){ cout<<v[i]<<" "; } cout<<endl; }
/////////////////////////////////////////

int main(){
	fastio;

	int a,b; cin>>a>>b;
	cout<<a*b<<endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

#define ll long long

int N, SN=0;

int main(){
    cin >> N;
    int buff = N;
    while(true){
        SN += buff % 10;
        if(buff < 10) break;
        else buff /= 10;
    }

    if(N % SN == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    string S; cin >> S;
    long long K; cin >> K;

    for (long long i = 0; i < K; ++i) {
        if (S[i] != '1') {
            cout << S[i] << endl;
            return 0;
        }
        if (i == K-1) {
            cout << '1' << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    ll n,k;
    ll ans=0;
    cin >>n>>k;
    ll mod0=n/k;
    ll modhalf=0;
    if(k%2==0){
        modhalf=n/(k/2)-mod0;
    }
    clog<<mod0<<" "<<modhalf<<endl;
    cout<<((ll)mod0*mod0*mod0+modhalf*modhalf*modhalf)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1))%mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	return (n + 9) / 10 * 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N,max=0,x=0;
	cin >> N;
	vector<int>H(N);
	rep(i, N)
		cin >> H[i];
	rep(i, N-1) {
		if (H[i] >= H[i + 1]) {
			x++;
			if (x > max)
				max = x;
		}
		else
			x = 0;
	}
	cout << max;
}

Measured memory_bytes: 1024
# coding: utf-8
# Your code here!

n = int(input())
height = list(map(int, input().split()))
# print(height)
l = []

for i in range(n):
    if i == 0:
        l.append(0)
    elif i == 1:
        a = height[0]
        b = height[1]
        l.append(abs(a - b))
    else:
        c = height[i - 2]
        # print(c)
        d = height[i]
        # print(d)
        a = l[i - 2] + abs(c - d)
        # print(a)
        b = l[i -1 ] + abs(height[i - 1] - height[i])
        # print(b)
        l.append(min(a, b))
    
# print(len(l))
print(l[len(l) - 1])

Measured memory_bytes: 13980
import numpy as np
from numba import njit


@njit
def solve(N, K, A):
    for _ in range(K):
        B = np.zeros(N + 1, dtype=np.int64)
        for i in range(N):
            a = A[i]
            B[max(0, i - a)] += 1
            B[min(N, i + a + 1)] -= 1
        A = np.cumsum(B)[:-1]
        if np.all(A == N):
            return A
    return A


N, K = map(int, input().split())
A = np.array(input().split(), dtype=int)
print(' '.join(map(str, solve(N, K, A))))

Measured memory_bytes: 132532
k = int(input())
r = [[i] for i in range(1,10)]

from collections import deque
que = deque(r)

if k < 10:
    print(k)
    exit()
while len(r) <= k:
    ri = que.popleft()
    for j in range(max(0, ri[-1]-1), min(9, ri[-1]+1)+1):
        rj = ri.copy()
        rj.append(j)
        r.append(rj)
        que.append(rj)
        #print(que)
#print(r[k-1])
print(''.join(map(str, r[k-1])))



Measured memory_bytes: 24052
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define int long long

int32_t main(){
	int n;
	cin >> n;
	int a[n];
	int cnt[100012] = {};
	for (int i = 0; i < n; i++){
		cin >> a[i];
		cnt[a[i]] ++;
	}
	int sum = 0;
	for (int i = 0; i < 100012; i++){
		sum += (cnt[i] * i);
	}
	int q;
	cin >> q;
	while (q--){
		int b, c;
		cin >> b >> c;
		sum += (cnt[b] * (c - b));
		cnt[c] += cnt[b];
		cnt[b] = 0;
		cout << sum << endl;
	}
}


Measured memory_bytes: 5124
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,ans=0;
  cin>>N;
  vector<int> p(N);
  for(int i=0;i<N;i++)cin>>p[i];
  for(int i=1;i<N-1;i++){
    if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1]))ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const static int N = 3;
const static int N2 = 9;
const static int dx[4] = {-1, 0, 1, 0};
const static int dy[4] = {0, -1, 0, 1};
const static char dir[4] = {'u', 'l', 'd', 'r'};

struct Puzzle{
    int f[N2];
    int space;
    std::string path;

    bool operator <(const Puzzle &p) const{
        for(int i = 0; i < N2; i++){
            if(f[i] == p.f[i]) continue;
            return f[i] > p.f[i];
        }
        return false;
    }
};

bool isTarget(Puzzle p){
    for(int i = 0; i < N2; i++){
        if(p.f[i] != i+1) return false;
    }
    return true;
}



std::string bfs(Puzzle s){
    std::queue<Puzzle> Q;
    std::map<Puzzle, bool> V;
    Puzzle u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;

    while(!Q.empty()){
        u = Q.front(); Q.pop();
        if(isTarget(u) ) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for(int r = 0; r < 4; r++){
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
            v = u;
            std::swap(v.f[u.space], v.f[tx*N+ty]);
            v.space = tx * N + ty;
            if(!V[v]){
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }

    return "unsolvable";

}

int main(void){
    Puzzle in;

    for(int i = 0; i < N2; i++){
        std::cin >> in.f[i];
        if(in.f[i] == 0){
            in.f[i] = N2;
            in.space = i;
        }
    }
    std::string ans = bfs(in);
    std::cout << ans.size() << std::endl;

    return 0;
}


Measured memory_bytes: 30600
def main():
    N = int(raw_input())
    s = [int(raw_input()) for x in range(N)]
    count = 0
    for i in s:
        if is_prime(i):
            count +=1
    print count
    
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

main()

Measured memory_bytes: 4720
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<int>> edges(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        edges[u].emplace_back(v);
        edges[v].emplace_back(u);
    }
    vector<int> size(n, 0);
    vector<vector<lint>> dp1(n, vector<lint>(n, inf));
    vector<vector<lint>> dp2(n, vector<lint>(n, inf));
    vector<lint> to1(n, inf);
    vector<lint> to2(n, inf);
    function<void(int, int)> dfs = [&](int c, int p) {
        size[c] = 1;
        if (a[c] > 0)
            dp1[c][0] = a[c];
        else
            dp2[c][0] = a[c];

        for (auto &v : edges[c]) {
            if (v == p)
                continue;
            dfs(v, c);
            to1.assign(n, inf);
            to2.assign(n, inf);
            for (int i = 0; i < size[c]; ++i) {
                for (int j = 0; j < size[v]; ++j) {
                    if (dp1[v][j] < inf || dp2[v][j] < 0) {
                        chmin(to1[i + j + 1], dp1[c][i]);
                        chmin(to2[i + j + 1], dp2[c][i]);
                    }
                    chmin(to1[i + j], dp1[c][i] + dp1[v][j]);
                    chmin(to2[i + j], dp1[c][i] + dp2[v][j]);
                    chmin(to2[i + j], dp2[c][i] + dp1[v][j]);
                    chmin(to2[i + j], dp2[c][i] + dp2[v][j]);
                }
            }
            size[c] += size[v];
            swap(to1, dp1[c]);
            swap(to2, dp2[c]);
        }
    };
    dfs(0, -1);
    for (int i = 0; i < n; ++i) {
        if (dp1[0][i] < inf || dp2[0][i] < 0) {
            cout << i << "\n";
            return 0;
        }
    }
    return 0;
}

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

int main(){
    int ans = 0;
    int n; cin >> n;
    vector<int> v(n), c(n);
    rep(i,n) cin >> v.at(i);
    rep(i,n) cin >> c.at(i);

    for(int i = 0; i < n; i++){
        if(v.at(i) - c.at(i) > 0){
            ans += v.at(i) - c.at(i);
        }
    }
    put(ans);
}

Measured memory_bytes: 256
/**
 *    author        : Saurav-Paul 
 *    created       : September 19, 2020 6:02 PM
 *    Problem Name  : B - Go to Jail
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc179/tasks/abc179_b
 *    @genarated by : ai-virtual-assistant
**/

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

using ll = long long int ;

class TC{

    public :
    void solve(){
        int N ;
        cin >> N ;
        int cnt = 0 ;

        bool ok = false ;
        for(int i = 0 ; i < N ; i++){
            int x , y ;
            cin >> x >> y ;
            if(x == y){
                cnt ++ ;
            }
            else{
                cnt = 0 ;
            }
            if(cnt == 3){
                ok = true ;
            }
        }

        cout << (ok?"Yes":"No") << endl ;

    }
};

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

    int testcases = 1;
    for(int i = 1 ; i <= testcases ; i ++){
        TC tc;
        tc.solve() ;
    }

    return 0 ;
}


Measured memory_bytes: 3648
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
    int n,i,j,zero=0;
    long long int ans=0,m=1,a[200010];
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for(i=0;i<n;i++)
    {
        if(a[i]==0)
        {
        zero++;
        }
    }
    if(zero>0)
    {
        cout << 0 << endl;
        return 0;
    }
    for(i=0;i<n;i++)
    {
        if(a[i]<=1000000000000000000/m)
        {
            m*=a[i];
        }
        else
        {
            cout << "-1" << endl;
            return 0;
        }
    }
    
    
    
    

    cout << m << endl;
    

    

}


Measured memory_bytes: 4368
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
const int INF = 999999999;
LL dp[60][60][3000];
int main(){
    int n,a;
    cin >> n >> a;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    dp[0][0][0] = 1;
    rep(i, n)rep(k, i+1)rep(j, 2501){
        if(dp[i][k][j] > 0){
            dp[i+1][k+1][j+x[i]] += dp[i][k][j];
            dp[i+1][k][j] += dp[i][k][j];
        }
    }
    LL ans = 0;
    rep1(i, n+1){
        rep(j, 2501){
            if(j%i == 0 && j/i == a)
            {
                ans += dp[n][i][j];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 69888
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c, d, e, ans;
    cin >> a >> b >> c>> d >> e;
    if (b > 0) {
        if (a < 0) {
            ans = (a * -1)* c + d + b * e;
        } else {
            ans = (b - a) * e;
        }
    } else {
        ans = (b -a) * c;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3096
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cassert>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

void update_node(vector<vector<ll>> *paths, unordered_map<ll, ll> *steps, vector<ll> *nodes, ll previous, ll node, ll current)
{
    current += (*steps)[node];
    (*nodes)[node] = current;
    for (auto &&i : (*paths)[node])
    {
        if (i == previous)
            continue;

        update_node(paths, steps, nodes, node, i, current);
    }
}

int main()
{
    ll N, Q;
    scanf("%lld", &N);
    scanf("%lld", &Q);

    vector<vector<ll>> path(N, vector<ll>());
    for (ll i = 1; i < N; i++)
    {
        ll a, b;
        scanf("%lld", &a);
        scanf("%lld", &b);
        a--;
        b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }

    unordered_map<ll, ll> steps(0);
    for (ll i = 0; i < Q; i++)
    {
        ll p, x;
        scanf("%lld", &p);
        scanf("%lld", &x);
        p--;
        steps[p] += x;
    }

    vector<ll> nodes(N);
    update_node(&path, &steps, &nodes, -1, 0, 0);

    for (ll i = 0; i < N - 1; i++)
    {
        printf("%lld ", nodes[i]);
    }
    printf("%lld\n", nodes[N - 1]);
}


Measured memory_bytes: 39536
#include <stdio.h>
int main(void){
    long long k,ans;
    scanf("%lld",&k);
    printf("50\n");
    for (int i=0; i<50; i++){
        if (i<k%50){
            ans=(50+(k/50)-1)+50-k%50+1;
        } else {
            ans=(50+(k/50)-1)-k%50;
        }
        if (i==49){
            printf("%lld\n",ans);
        } else {
            printf("%lld ",ans);
        }
    }
    return 0;
}

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

const int MAXN = 1e5 + 10;
vector<int> vt[MAXN];
int path[MAXN], vis[MAXN], indx = 0;
bool flag = false;
int root, ans = 0;

void dfs(int x, int pre){
    if(flag) return;
    path[pre] = x;
    if(x == root) flag = true;
    for(int i = 0; i < vt[x].size(); i++){
        if(vt[x][i] != pre) dfs(vt[x][i], x);
    }
}

void sol(int x, int pre){
    ans++;
    for(int i = 0; i < vt[x].size(); i++){
        if(vt[x][i] != pre) sol(vt[x][i], x);
    }
}

int main(void){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, x, y;
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        cin >> x >> y;
        vt[x].push_back(y);
        vt[y].push_back(x);
    }
    root = n;
    dfs(1, 0);
    int cnt = 0, pos = 0;
    while(path[cnt] != 0){
        cnt = path[cnt];
        vis[pos++] = cnt;
    }
    int cc = (pos + 1) >> 1;
    sol(vis[cc - 1], vis[cc]);
    if(ans > n - ans) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    return 0;
}

Measured memory_bytes: 11264
from sys import stderr
from functools import reduce
from collections import deque
from operator import add
def f(): return [int(i) for i in input().split()]
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(repr(item))
        stderr.write(sep)
    stderr.write(end)

s = deque(input())
t = deque(input())
loop = len(s)
for i in range(loop):
    if s == t:
        print("Yes")
        break
    s.append(s.popleft())
else:
    print("No")


Measured memory_bytes: 3572
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())

ans=0

for i in reversed(range(n)):
    if (a[i]+ans)%b[i]==0:
        continue
    ans+=b[i]-(a[i]+ans)%b[i]

print(ans)


Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
 
struct uyu{int a, b, c;};
 
int d, n;
int t[202];
vector<uyu> po;
 
int dp[256][256];
 
int dfs(int i=0, int pre=0)
{
   
  if (i == d) return 0;
  int &ret = dp[i][pre];
  if (ret != -1) return ret;
  if (i == 0){
    for (int j = 0; j < n; j++){
      if (t[i] < po[j].a || po[j].b < t[i]) continue;
      ret = max(ret, dfs(i + 1, j));
    }
    return ret;
  }
 
  for (int j = 0; j < n; j++){
    if (t[i] < po[j].a || po[j].b < t[i]) continue;
    ret = max(ret, dfs(i + 1, j) + abs(po[j].c - po[pre].c));
  }
 
  return ret;
}
 
int main()
{
  memset(dp, -1, sizeof(dp));
  cin >> d >> n;
  for (int i = 0; i < d; i++){
    cin >> t[i];
  }
 
  for (int i = 0; i < n; i++){
    uyu s;
    cin >> s.a >> s.b >> s.c;
    po.push_back(s);
  }
 
  cout << dfs() << endl;
}

Measured memory_bytes: 3400
s = input()

INF = float('inf')
dp = [[INF,INF] for _ in range(len(s)+1)]
dp[0][0]=0
dp[0][1]=1
for i in range(len(s)):
    dp[i+1][0] = min(dp[i][0]+int(s[i]), dp[i][1]+10-int(s[i]), dp[i][1]+int(s[i])+1)
    dp[i+1][1] = min(dp[i][0]+int(s[i])+1,dp[i][1]+10-int(s[i])-1)

print(dp[-1][0])


Measured memory_bytes: 195020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string a,b;
int n;
ll dp[12][2][2][2][10];
ll fun(int pos,int boro,int choto,int suru,int prev)
{
    if(pos==n)
    {
        return dp[pos][boro][choto][suru][prev]=1;
    }
    if(dp[pos][boro][choto][suru][prev]!=-1)
        return dp[pos][boro][choto][suru][prev];
    int lw=0;
    int hi=9;
    if(boro==0)
        lw=a[pos]-'0';
    if(choto==0)
        hi=b[pos]-'0';
    ll ret=0;
    for(int i=lw; i<=hi; i++)
    {
        if(suru==0)
        {
            ret += fun(pos+1,boro|(i>lw),choto|(i<hi),suru|(i>0),i);
        }
        else
        {
            if(abs(prev-i)<=1)
                ret += fun(pos+1,boro|(i>lw),choto|(i<hi),suru|(i>0),i);
        }
    }
    return dp[pos][boro][choto][suru][prev]=ret;
}
ll ans;
string res;
ll k;
void path(int pos,int boro,int choto,int suru,int prev)
{
    if(pos==n)
    {
        return ;
    }
    int lw=0;
    int hi=9;
    if(boro==0)
        lw=a[pos]-'0';
    if(choto==0)
        hi=b[pos]-'0';
    ll ret=0;
    ll age=0;
    for(int i=lw; i<=hi; i++)
    {
        if(suru==0)
        {
            ret += fun(pos+1,boro|(i>lw),choto|(i<hi),suru|(i>0),i);
            if(ret>=k)
            {
                k -=age;
                res.push_back(i+'0');
                path(pos+1,boro|(i>lw),choto|(i<hi),suru|(i>0),i);
                break;
            }
        }
        else
        {
            if(abs(prev-i)<=1)
                ret += fun(pos+1,boro|(i>lw),choto|(i<hi),suru|(i>0),i);
            if(ret>=k)
            {
                k -=age;
                res.push_back(i+'0');
                path(pos+1,boro|(i>lw),choto|(i<hi),suru|(i>0),i);
                break;
            }

        }
        age=ret;
    }
    return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    a="0000000001";
    b="9999999999";
    n=b.size();
    memset(dp,-1,sizeof dp);
    ans=fun(0,0,0,0,0);
    cin>>k;
    path(0,0,0,0,0);
    int i=0;
    int sz=res.size();
    while(i<sz && res[i]=='0')
    {
        i++;
    }
    while(i<sz)
    {
        cout<<res[i];
        i++;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int N; cin >> N;
    double T, A; cin >> T >> A;

    int pt = 0;
    double minDiff = 1e9;
    REP(i, N) {
        int h; cin >> h;
        double temp = T - 0.006 * h;
        if(abs(temp - A) < minDiff) {
            minDiff = abs(temp-A);
            pt = i+1;
        }
    }

    cout << pt << endl;
    
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
from heapq import heappush, heappop

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


def dijkstra(s, n): # (始点, ノード数)
    dist = [inf] * n
    hq = [(0, s)] # (distance, node)
    dist[s] = 0
    seen = [False] * n # ノードが確定済みかどうか
    while hq:
        v = heappop(hq)[1] # ノードを pop する
        seen[v] = True
        for to, cost in adj[v]: # ノード v に隣接しているノードに対して
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(hq, (dist[to], to))
    return dist

N = ni()
adj = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = na()
    adj[a-1].append((b-1, c))
    adj[b-1].append((a-1, c))

Q, K = na()
ans = []
d = dijkstra(K-1, N)

for i in range(Q):
    x, y = na()
    x -= 1
    y -= 1
    ans.append(d[x] + d[y])

for i in range(Q):
    print(ans[i])



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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 

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

#define mkp make_pair
#define pb push_back

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

int main(){

    bool flag=false;

    ll ans=0,sum=0;
    ll n,k;
    cin >>n>>k;

    map<int,ll> arr;

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

    auto p=arr.begin();
    int curans;

    while (sum < k){
        sum += p->second;
        curans = p->first;
        ++p;

        //cout << curans << endl;
    }
    

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << curans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 4224
n,m,k = input().split(' ')
a = list(map(int, input().split())) 
b = list(map(int, input().split()))
k = int(k)

a_time = [0]
for i in range(len(a)):
  a_time.append(a_time[i] + a[i])

b_time = [0]
for i in range(len(b)):
  b_time.append(b_time[i] + b[i])

b_time.reverse()
cnt = 0
best_j = 0
for i in range(len(a_time)):
  k_dumy = k - a_time[i]
  for j in range(best_j,len(b_time)):
    if b_time[j] <= k_dumy:
      cnt = max(cnt, i + len(b_time)-j-1)
      best_j = j
      break

print(cnt)

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

int main() {
  int x, y;
  cin >> x >> y;
  int tsuru,kame;
  kame = y/2-x;
  tsuru = x- kame;
  if (tsuru < 0 || kame < 0){
    cout << "No" << endl;
  }  
  else if((kame + tsuru == x) && (tsuru*2 + kame*4 == y)) {
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
    
  
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        long map[][] = new long[n][n];
        long minCost[][] = new long[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                map[i][j] = sc.nextInt();
                minCost[i][j] = map[i][j];
            }
        }

        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    map[i][j] = Math.min(map[i][j], map[i][k] + map[k][j]);
                }
            }
        }

        long sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (map[i][j] != minCost[i][j]) {
                    System.out.println(-1);
                    System.exit(0);
                }

                boolean res = false;
                for (int k = 0; k < n; k++) {
                    if (i == k || j == k) {
                        continue;
                    }

                    if (map[i][j] == map[i][k] + map[k][j]) {
                        res = true;
                        break;
                    }
                }

                if (!res) {
                    sum += map[i][j];
                }
            }
        }
        System.out.println(sum);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 64844
def biserch_min(l,key):
    left = 0; right = len(l)
    while left < right:
        mid = (left+right)//2
        if l[mid] < key:
            left = mid+1
        else:
            right = mid
    return left

def biserch_max(l,key):
    left = 0; right = len(l)
    while left < right:
        mid = (left+right)//2
        if key < l[mid]:
            right = mid
        else:
            left = mid+1
    return 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())))

ans = 0
for b in B:
    top = biserch_min(A,b)
    bottom = N - biserch_max(C,b)
    ans += top*bottom
print(ans)

Measured memory_bytes: 24264
#include <stdio.h>
int main()
{
  int h,m,s,r;
  for(;;){
    scanf("%d%d%d",&h,&m,&s);
    if(h==-1&&m==-1&&s==-1) break;
    r = 7200 - h*3600 - m*60 - s;
    printf("%02d:%02d:%02d\n",r/3600,(r%3600)/60,r%60);
    printf("%02d:%02d:%02d\n",3*r/3600,(3*r%3600)/60,3*r%60);
  }
  return 0;
}

Measured memory_bytes: 0
try:
    while True:
        a1,a2,a3,a4=map(int,input().split())
        b1,b2,b3,b4=map(int,input().split()) 
        h=0
        b=0
        if a1==b1:
            h+=1
        if a2==b2:
            h+=1
        if a3==b3:
            h+=1
        if a4==b4:
            h+=1
        A = [a1,a2,a3,a4]
        B = [b1,b2,b3,b4]
    
        for i in A:
            for j in B:
                if i == j:
                    b +=1
        b = b - h
        
        print(h,b)
except EOFError:
    pass

        


Measured memory_bytes: 5592
N,M,X,Y = tuple(map(int, input().split(" ")))
x_list = list(map(int, input().split(" ")))
y_list = list(map(int, input().split(" ")))

x_list.append(X)
y_list.append(Y)
if (max(x_list) < min(y_list)):
    print("No War")
else:
    print("War")

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

int n,m;
string mp[9];

void JIZZ(){ cout<<"Impossible"<<endl; exit(0); }

set<pair<int,int>> st;

void dfs(int i,int j){
    if(mp[i][j]!='#')JIZZ();
    // cout<<"dfs "<<i<<" "<<j<<endl;
    st.insert(make_pair(i,j));
    if(i==n-1 && j==m-1)return;
    int go=0;
    if(i<n-1 && mp[i+1][j]=='#')++go;
    if(j<m-1 && mp[i][j+1]=='#')++go;
    if(go==2 || go==0)JIZZ();
    if(i<n-1 && mp[i+1][j]=='#')dfs(i+1,j);
    if(j<m-1 && mp[i][j+1]=='#')dfs(i,j+1);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for(int i=0;i<n;++i)cin>>mp[i];
    dfs(0,0);
    for(int i=0;i<n;++i)for(int j=0;j<m;++j)if(mp[i][j]=='#'){
        if(st.find(make_pair(i,j))==st.end())JIZZ();
    }
    cout<<"Possible"<<endl;
}


Measured memory_bytes: 256
from collections import deque
import operator

N, M = map(int, input().split())
*X, = map(int, input().split())
E = []
for i in range(M):
    a, b, y = map(int, input().split())
    E.append((y, a-1, b-1))
E.sort()
*Y, = map(operator.itemgetter(0), E)

*p, = range(N)
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y

A = X[:]
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    if px < py:
        p[py] = px
        A[px] += A[py]
    else:
        p[px] = py
        A[py] += A[px]
    return 1

G = [[] for i in range(M)]
B = [0]*M
C = [-1]*N

ans = 0
for i, (y, a, b) in enumerate(E):
    pa = root(a); pb = root(b)
    ca = C[pa]; cb = C[pb]
    if unite(a, b):
        if ca != -1:
            G[i].append(ca)
        if cb != -1:
            G[i].append(cb)
        pa = root(a)
    else:
        if ca != -1:
            G[i].append(ca)
    B[i] = A[pa]
    C[pa] = i

if N > 1 and sum(X) < E[C[0]][0]:
    que = deque()
    que.append(C[0])
    while que:
        v = que.popleft()
        if B[v] < Y[v]:
            ans += 1
            que.extend(G[v])
print(ans)

Measured memory_bytes: 46740
#include <cstdio>
using namespace std;

int W, H;
char board[22][22];
int dy[] = {-1,1,0,0};
int dx[] = {0,0,1,-1};
bool visited[22][22][22][4];

bool dfs(int y, int x, int a, int d){
	if(y==-1) y=H-1;
	if(y==H) y = 0;
	if(x==-1) x=W-1;
	if(x==W) x = 0;
	if(visited[y][x][a][d]) return false;
	visited[y][x][a][d] = true;
	if(board[y][x]=='@') return true;
	if(board[y][x]=='<'){d = 3; return dfs(y+dy[d],x+dx[d],a,d); }
	if(board[y][x]=='>'){d = 2; return dfs(y+dy[d],x+dx[d],a,d); }
	if(board[y][x]=='^'){d = 0; return dfs(y+dy[d],x+dx[d],a,d); }
	if(board[y][x]=='v'){d = 1; return dfs(y+dy[d],x+dx[d],a,d); }
	if(board[y][x]=='_'){d = (a?3:2); return dfs(y+dy[d],x+dx[d],a,d); }
	if(board[y][x]=='|'){d = (a?0:1); return dfs(y+dy[d],x+dx[d],a,d); }
	if(board[y][x]=='.' || board[y][x]=='G'){return dfs(y+dy[d],x+dx[d],a,d); }
	if(board[y][x]=='+'){a = ((a+1)&15); return dfs(y+dy[d],x+dx[d],a,d); }
	if(board[y][x]=='-'){a = ((a-1)&15); return dfs(y+dy[d],x+dx[d],a,d); }
	if(board[y][x]=='?'){
		for(d=0; d<4; d++){
			if(dfs(y+dy[d],x+dx[d],a,d)) return true;
		}
		return false;
	}
	a = (board[y][x]&15);
	return dfs(y+dy[d], x+dx[d], a, d);
}

int main(){
	scanf("%d%d ",&H,&W);
	for(int i=0; i<H; i++){
		scanf("%s ",board[i]);
	}
	puts(dfs(0,0,0,2)?"YES":"NO");
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int A[N + 5], B[N + 5];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < N; i++)
    cin >> B[i];
  vector<int> CP, CM;
  for (int i = 0; i < N; i++) {
    int a = A[i], b = B[i];
    if (a - b >= 0)
      CP.push_back(a - b);
    else
      CM.push_back(a - b);
  }
  sort(CP.begin(), CP.end(), greater<int>());
  int pi = 0, pnum = CP[0];
  for (int mnum : CM) {
    while (abs(mnum) >= pnum) {
      pi++;
      if (pi >= CP.size()) {
        cout << -1 << '\n';
        return 0;
      }
      pnum += CP[pi];
    }
    pnum += mnum;
  }
  int ans = CM.size();
  if (CM.size() != 0)
    cout << ans + pi + 1 << '\n';
  else
    cout << ans << '\n';
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ans = a[n-1] - a[0];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256