akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int year = (s[0]-'0')*1000 + (s[1]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0');
  int month = (s[5]-'0')*10 + (s[6]-'0');
  string ans;
  if(year < 2019) ans = "Heisei";
  else if(year > 2019) ans = "TBD";
  else{
    if(month <= 4) ans = "Heisei";
    else ans = "TBD";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;

void main(){
	auto ip = readln.split.to!(int[]);
	writeln((ip[0] - 1)*(ip[1] - 1));
}

//writeln("滲み出す混濁の紋章　不遜なる狂気の器　湧き上がり　否定し　痺れ　瞬き　眠りを妨げる　爬行する鉄の王女　絶えず自壊する泥の人形　結合せよ　反発せよ　地に満ち己の無力を知れ　破道の九十　黒棺")

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

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
ll n,w=0,r=0,r_t=0;
string saidan;
  cin>>n;
  cin>>saidan;
  for(ll i=1;i<=n;i++){
   if(saidan[i-1]=='W') w++;
   else r++;
  }
  for(ll i=1;i<=n;i++){
   if(saidan[i-1]=='R')r_t++;
   if(i>=r)break;
  }
	cout<<r-r_t;
return 0;
}






ll gcd(ll a, ll b){

   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }

}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
int main(){
  char a,b,c,d;
  int count;
  cin >> a >> b >> c >> d;
  if (a=='2') count++;
  if (b=='2') count++;
  if (c=='2') count++;
  if (d=='2') count++;
  cout << count;
}

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

int main(){
  int y,m,d;
  
  scanf("%d/%d/%d",&y,&m,&d);
  
  if(y < 2019 || (y==2019&&m<=4&&d<=30)){
    puts("Heisei");
    return 0;
  }
  else
    puts("TBD");
  return 0;
}

Measured memory_bytes: 128
N,K,Q = map(int,input().split(" "))


ans = [K - Q for i in range(N)]


for i in range(Q):
    A = int(input())
    ans[A-1] = ans[A-1] + 1

for a in ans:
    if a > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 7848
from operator import itemgetter
#@profile
def calc(w,pdp,pl,pr,dp,l,r):
    if l >= r:
        return
    m = (l + r) // 2
    dp[m], i = min([(pdp[i] + w[i+1][m],i) for i in range(pl,min(m,pr))], key=itemgetter(0))
    calc(w,pdp,pl,i+1,dp,l,m)
    calc(w,pdp,i,pr,dp,m+1,r)
    return dp

import sys
f = sys.stdin

s,n,m = map(int, f.readline().split())
x = list(map(int, f.readline().split()))
tp = [list(map(int, line.split())) for line in f]

c = [ti - x[pi - 1] for ti, pi in tp]
c.sort()
min_c = c[0]
c = [ci - min_c for ci in c]
d = c[:] 
for i in range(1,len(d)):
    d[i] += d[i - 1]

w = [[0 for j in range(n)] for i in range(n)]
for j in range(1, n):
    for i in range(j): 
        w[i][j] = c[j] * (j - i + 1) - (d[j] - d[i] + c[i])

dp = w[0][:]
for bus in range(2,m + 1):
    pdp = dp 
    dp = [0] * len(pdp)
    pl = bus - 2
    pr = n-m+bus
    if pl > pr:
        continue
    dp = calc(w,pdp,pl,pr,dp,bus,n)
        
print(dp[-1])

Measured memory_bytes: 103936
#include <iostream>
#include <algorithm>
using namespace std;
static const int A=100;
int main(){
    int n,p[A+1],m[A+1][A+1];
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>p[i-1]>>p[i];
    }
    for(int i=1; i<=n; i++)m[i][i]=0;
    for(int j=2; j<=n; j++){
        for(int i=1;i<=n-j+1;i++){
        int l=i+j-1;
        m[i][l]=(1<<21);
        for(int x=i;x<=l-1;x++){
            m[i][l]=min(m[i][l],m[i][x]+m[x+1][l]+p[i-1]*p[x]*p[l]);
        }
        }
    }
cout<<m[1][n]<<endl;
return 0;
}


Measured memory_bytes: 3164
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		String digits[] = {"0111111", 
				 "0000110", 
				 "1011011", 
				 "1001111", 
				 "1100110", 
				 "1101101", 
				 "1111101", 
				 "0100111", 
				 "1111111", 
				 "1101111"};
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			if(n == -1)
			{
				break;
			}
			String s = "0000000";
			char[] current = s.toCharArray();
			for(int i = 0; i < n; ++i)
			{
				int num = stdIn.nextInt();
				for(int j = 0; j < current.length; ++j)
				{
					if(digits[num].charAt(j) == current[j])
					{
						System.out.print("0");
					}
					else
					{
						System.out.print("1");
						if(current[j] == '0')
						{
							current[j] = '1';
						}
						else
						{
							current[j] = '0';
						}
					}
				}
				System.out.println("");
			}
		}
	}
}

Measured memory_bytes: 12000
int w,h;
int d[9][9],q[9][9];
int a[4]={-1,0,1,0};
int X,Y,C,t;
int b=0;
void output(int a[9][9]){
	int i,j;
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++)printf("%d",!!a[i][j]);
		puts("");
	}
}

int chk(int x,int y){
	int i=0,ans=1;
	if(q[y][x])return 0;
	q[y][x]=1;
	if(d[y][x])return y==Y&&x==X;
	for(;i<4;i++)ans+=chk(x+a[i],y+a[(i+1)%4]);
	return ans;
}
int dfs(int x,int y,int c){
	int i=0;
	if(!c&&x==X&&y==Y)return 1;
	memset(q,0,324);
	if(d[y][x]||chk(x,y) != c+(x!=X||y!=Y))return 0;
	if(b++ > 120000)return 2;
	d[y][x]=1;
	for(;i<4;i++)if(t=dfs(x+a[i],y+a[(i+1)%4],c-1))return t;
	return d[y][x]=0;
}
int main(i,j){
	for(;C=0,b=0,scanf("%d%d\n",&w,&h),h;puts(C>3&&dfs(X,Y,C)==1?"Yes":"No")){
		memset(d,-1,324);
		for(j=0;j++<h;)for(i=0;i++<w;)scanf("%d",&t),(d[j][i]=t)||(++C,X=i,Y=j);
	}
	return 0;
}

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

int main()
{
    int n,l;
    cin >> n >> l;

    vector<string> s;
    rep(i,n){
        string tmp;
        cin >> tmp;
        s.push_back(tmp);
    }

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

    rep(i,n){
        cout << s[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
a = input()
b = input()
r = 1
if len(a) - len(b) != -1:
	r = 0
for i in range(0, len(a)):
	if a[i] != b[i]:
		r = 0
	if r == 0:
		break
print("Yes" if r == 1 else "No")

Measured memory_bytes: 9116
mod = 10**9+7
mod2 = 998244353
rng = 200001
fctr = [1]
finv = [1]
for i in range(1,rng):
    fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
    finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
    if n<0 or k<0:
        return 0
    else:
        return fctr[n]*finv[n-k]*finv[k]%mod
h,w,a,b = map(int, input().split(' '))
ans = cmb(h+w-2,h-1)
x = h-a+b-1
for i in range(1,min(a,b)+1):
    ans = (ans-(cmb(x,b-i)*cmb(h+w-2-x,w-b+i-1))%mod)%mod
print(ans)

Measured memory_bytes: 18924
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

int arr[110];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    for (int i = A; i < B; ++i)
        arr[i]++;

    for (int i = C; i < D; ++i)
        arr[i]++;

    int cnt = 0;
    for (int i = 0; i < 110; ++i)
        if (arr[i] == 2)
            cnt++;

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
// finish date: 2019/2/22

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    vi a(N);
    rep(i, N) cin >> a[i];
    vvl dp(N + 1, vl(N + 1, 0));
    a.push_back(0);

    for (int i = N - 1; i >= 0; i--) {
        FOR(j, i + 1, N + 1) {
            if ((N - (j - i)) % 2 == 0) {
//                太朗の番
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);
            } else {
//                次郎の番
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
            }
        }
    }

    cout << dp[0][N] << endl;


    return 0;
}

Measured memory_bytes: 70784
def examA():
    St = LS()
    ans = St[0][0] + St[1][0] + St[2][0]
    print(ans)




import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()


Measured memory_bytes: 3060
N[]={ 6, 14, 18, 10,  2,  9, 22, 15,  1, 17, 23,  7,  3,  5, 21, 19,  0, 13, 20, 11,  4,  8, 16, 12};
E[]={13, 17,  9,  5,  8, 21, 14,  1, 16, 22,  6,  0,  4, 20, 18,  2, 12, 23, 10,  3, 11, 19, 15,  7};
R[]={ 3,  0,  1,  2,  7,  4,  5,  6, 11,  8,  9, 10, 15, 12, 13, 14, 19, 16, 17, 18, 23, 20, 21, 22};
a;
d;
char s[9];
main(c)
{
	for(;c-48&&scanf("%s",s);a+=d/4+1)
	{
		c=*s;
		if(c<60)a&&printf("%d\n",a),a=d=0;
		if(c=='N')d=N[d];
		if(c=='S')d=N[N[N[d]]];
		if(c=='E')d=E[d];
		if(c=='W')d=E[E[E[d]]];
		if(c=='R')d=R[d];
		if(c=='L')d=R[R[R[d]]];
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    vector<int> a;
    long long s = 0;
    cin >> n;
    a.assign(n, 0);
    for(int i=0;i<n;i++){
        cin >> a[i];
        s += a[i] * ((i%2==0)?1:-1);
    }
    long long b = s;
    cout << b;
    for(int i=0;i<n-1;i++){
        b = a[i]*2 - b;
        cout << " " << b;
    }
    cout << endl;
}


Measured memory_bytes: 1664
N = gets.to_i
H = gets.split.map &:to_i
cnt = 0
ans = 0
(0..N-2).each{|i|
	if H[i] >= H[i+1]
		cnt = cnt + 1
	else
		ans = [ans, cnt].max
		cnt = 0
	end
}
p [ans, cnt].max

Measured memory_bytes: 11012
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
#include <map>

using namespace std;
using ll = long long;

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

	int s = sqrt(2 * n);

	if (s * (s + 1) != 2 * n)
		cout << "No" << endl;
	else
	{
		cout << "Yes" << endl;
		cout << s + 1 << endl;

		vector< vector<int> > v(s + 1, vector<int>(s));

		for (int i = 1; i <= s; i++)
		{
			v[0][i - 1] = i;
		}
		int max = s;
		for (int i = 1; i < s + 1; ++i)
		{
			for (int j = 0; j < i; ++j)
			{
				v[i][j] = v[j][i - 1];
			}
			for (int j = i; j < s; ++j)
			{
				max++;
				v[i][j] = max;
			}
		}

		for (auto v1 : v)
		{
			cout << s << " ";
			for (auto v2 : v1)
				cout << v2 << " ";
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 2176
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson curPos<<1
#define rson curPos<<1|1
/* namespace */
using namespace std;
/* header end */

const int maxn = 1e5 + 10;
struct Edge
{
    int u, v, w;
} edge[maxn*2];
int n, cnt, ans[maxn], vis[maxn];
vector<int> g[maxn];

void addedge(int u, int v, int w)
{
    edge[++cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].w = w;
    g[u].push_back(cnt);
}

void bfs()
{
    queue<int> Q;
    Q.push(1);
    while (!Q.empty())
    {
        int x = Q.front();
        Q.pop();
        if (vis[x]) continue;
        vis[x] = 1;
        for (int i = 0; i < g[x].size(); i++)
        {
            int cur = g[x][i];
            if (!vis[edge[cur].v])
            {
                if (edge[cur].w % 2 == 0)
                {
                    ans[edge[cur].v] = ans[x];

                }
                else
                {
                    ans[edge[cur].v] = 1 - ans[x];
                }
                Q.push(edge[cur].v);
            }
        }
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i < n; i++)
    {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        addedge(u, v, w); addedge(v, u, w);
    }
    bfs();
    for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 9088
parseInt(x) = parse(Int, x)

function main()
	n = parseInt(readline())
	if n == 1
		print(1)
	else
		x = Array{Int}(n+1)
		x[1] = 2
		x[2] = 1
		for i in 3:n+1
			x[i] = x[i-1] + x[i-2]
		end
		print(x[n+1])
	end
end

main()

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

pint INF(INT_MAX,INT_MAX);

pint dp[55555];
pint nex[55555];

int N;
int P[111];



void solve(){
    rep(i,N)cin>>P[i];

    fill_n(dp,55555,INF);
    dp[0]=pint(0,0);

    for(int i=0;i<N;i++){
        fill_n(nex,55555,INF);
        for(int j=0;j<50000;j++){
            chmin(nex[j],dp[j]);

            int p=P[i]%1000;
            if(p==0){
                pint w=dp[j];
                w.fi--;w.se+=P[i];
                if(j>=500)chmin(nex[j-500],w);
            }
            else if(p<=500){
                pint w=dp[j];
                w.fi--;
                w.se+=P[i];
                chmin(nex[j+500-p],w);
            }
            else{
                pint w=dp[j];
                w.se+=P[i];
                chmin(nex[j+1000-p],w);
                w.fi--;
                if(j-(p-500)>=0)chmin(nex[j-(p-500)],w);
            }
        }
        rep(j,55555)dp[j]=nex[j];
    }

    pint ans=INF;
    rep(i,55555)chmin(ans,dp[i]);
    cout<<-ans.fi<<" "<<ans.se<<endl;
}

signed main(){
    while(cin>>N,N)solve();
    return 0;
}

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

int main(){
	int A[4];
	for (int i = 0; i < 4; ++i) scanf("%d", A + i);
	sort(A, A + 4);
	if(A[0] == 1 && A[1] == 4 && A[2] == 7 && A[3] == 9) printf("YES\n");
	else printf("NO\n");
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int num= 0;
    for(int i = 1; i <= N; i++){
        int p;
        cin >> p;
        if(p != i) num++;
    }
    if(num <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(w,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
#define EPS = 1e-14;
using std::vector;
using std::cout;
using std::cin;
using std::endl;
using std::max;
using std::min;
using std::swap;
using std::string;
using std::fill;
using std::pair;
using std::sort;
using std::reverse;
using std::pair;
using std::greater;
using std::priority_queue;
using std::ostream;
typedef std::complex<int> P;

template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i] << endl;
	}
	return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	out << "[";
	size_t last = v.size() - 1;
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i];
		if (i != last) {
			out << ",";
		}
	}
	out << "]";
	return out;
}

const int MAX_N = 1 << 17;
//?????°???????????¨???????????°??????????????????
int n, dat[2 * MAX_N - 1];

//?????????
void init(int n_) {
	//?°????????????????????´???°???2???????????????
	//n_????¬???????????´???°, n???????????°, 2*n-1??????????´???°
	n = 1;
	while (n < n_) {
		n *= 2;
	}
	//??????????????????INT_MAX???
	for (int i = 0; i < 2 * n - 1; i++) {
		dat[i] = INT_MAX;
	}
}
//k????????????(0-indexed)???a????????´
void update(int k, int a) {
	//????????\???
	k += n - 1;
	dat[k] = a;
	//?????????????????´??°
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}

//[a,b)???????°????????±???????
//????????????????????°???????¨????????°?????????????????????°
//k?????\???????????????l, r???????????\??????[l, r)???????????\?????????????????¨?????¨???
//???????????£??????????????????query(a, b, 0, 0, n)??¨???????????¶
int query(int a, int b, int k, int l, int r) {
	//[a, b)??¨[l, r)???????????????????????°???INT_MAX
	if (r <= a || b <= l) {
		return INT_MAX;
	}
	//[a, b)???[l, r)????????¨???????????§????????°???????????\?????????
	if (a <= l && r <= b) {
		return dat[k];
	} else {
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
}

int N, Q;
int com, xq, yq;
void solve() {
	cin >> N >> Q;
	init(N);
	rep(q,0,Q)
	{
		cin >> com >> xq >> yq;
		if (com == 0) {
			update(xq, yq);
		} else {
			cout << query(xq, yq + 1, 0, 0, n) << endl;
		}
	}

}

int main() {
	solve();
}

Measured memory_bytes: 4108
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	n,m=map(int,input().split())
	
	inc=[0]*(n)
	out=[[] for _ in range(n)]
	
	for i in range(m):
		x,y=map(int,input().split())
		inc[y-1]+=1
		out[x-1].append(y-1)
	
	q={i for i,c in enumerate(inc) if c==0}
	C=[]
	
	while q:
		k=q.pop()
		C.append(k)
		for i in out[k]:
			inc[i]-=1
			if inc[i]==0:
				q.add(i)
	
	ans=[0]*n
	
	for i in C:
		for j in out[i]:
			ans[j]=max(ans[j],ans[i]+1)
	
	
	print(max(ans))
	
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 61360
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    cin>>n;
    std::map<int, int> map;
    for (int i=1;i<=n;i++) {
        cin>>a;
        map.insert(make_pair(a,i));
    }
    for (int j=1;j<=n;j++) {
        if (j==n) {
            cout<<map.at(j)<<endl;
        } else {
            cout<<map.at(j)<<" ";
        }
    }
}

Measured memory_bytes: 5504
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a+b >= 10) {
            System.out.println("error");
        } else {
            System.out.println(a+b);
        }
    }
}

Measured memory_bytes: 23508
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;
constexpr ll MOD = ll(1e9) + 7;
 
ll ModPow(ll n, ll p, ll mod) {
	
	if( p == 0 ) return 1;
	if( p % 2 == 0 ) {
		ll t = ModPow(n, p / 2, mod);
		return (t * t) % mod;
	}
	
	return (n * ModPow(n, p - 1, mod)) % MOD;
	
}

ll ModComb(ll n, ll a, ll mod) {
	if( n < a ) return 0;
	
	ll res = 1;
	
	if( n < 2 * a ) a = n - a;
	for(ll i = 1; i <= a; ++i) {
		res *= n - i + 1LL;
		res %= mod;
		res *= ModPow(i, mod - 2LL, mod);
		res %= mod;
	}
	
	return res;
}

int main(void) {
	ll n, a, b;
	cin >> n >> a >> b;
	
	ll ans = ModPow(2LL, n, MOD) - 1LL;
	
	ans -= ModComb(n, a, MOD);
	ans %= MOD;
	ans -= ModComb(n, b, MOD);
	ans %= MOD;
	
	if( ans < 0 ) ans += MOD;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int binary_search(int A[], int right, int left, int key){
    while(left < right){
        int mid = (left + right) / 2;
        if(A[mid]==key) return mid;
        else if(A[mid] > key) right=mid;
        else left=mid+1;
    }

    return 0;
}

int main(){
    int n, q, i, j, cnt=0;
    scanf("%d", &n);
    int S[n];
    for(i = 0; i< n; i++) scanf("%d", &S[i]);

    scanf("%d", &q);
    int T[q];


    for(i = 0; i< q; i++){
        scanf("%d", &T[i]);
        if(binary_search(S, n, 0, T[i]) != 0){
            cnt++;
        }
    }

    printf("%d\n", cnt);
    return 0;
}



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

using namespace std;

namespace {
    int H, W;
    int N;
    vector<int> A;
    void input() {
        cin >> H >> W >> N;
        A.resize(N);
        for (auto& a : A) cin >> a;
    }

    /** output whole vector. ex) vector<int>{1, 2, 3} -> '1 2 3'. */
    template<typename T>
    ostream& operator<<(ostream& os, const vector<T>& xs) {
       if (xs.empty()) return os;
       os << xs[0];
       for (auto i = 1; i < xs.size(); i++) os << ' ' << xs[i];
       return os;
    }

    void solve() {
        vector<vector<int>> F(H, vector<int>(W, -1));
        int y = 0, x = 0, c = 0;
        for (; c < N; c++) {
            for (; A[c] > 0; A[c]--) {
                assert(F[y][x] < 0);
                F[y][x] = c + 1;
                auto next = [&](int y, int x) {
                    int dx = y % 2 == 0 ? +1 : -1;
                    int nx = x + dx;
                    int ny = y;
                    if (nx < 0 || nx >= W) {
                        ny++;
                        nx = x;
                    }
                    return make_tuple(ny, nx);
                };
                tie(y, x) = next(y, x);
            }
        }
        for (auto L : F) {
            cout << L << endl;
        }
    }
}

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



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t N,X; cin>>N>>X;
  vector<int64_t> S(N);
  rep(i,N){
    int64_t a; cin>>a;
    S.at(i)=abs(a-X);
  }
  auto ans=S.at(0);
  rep(i,N) ans=gcd(ans,S.at(i));
  cout<<ans;
}



Measured memory_bytes: 3900
x1,y1,x2,y2 = input().split()
x1 = int(x1)
x2 = int(x2)
y1 = int(y1)
y2 = int(y2)
x = x1 - x2
y = y1 - y2
y3 = y2 - x
x3 = x2 + y
x4 = x3 + x
y4 = y3 + y
print(x3,y3,x4,y4)

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

ans = [-1,-1,-1]
for a in range(N+1):
    for b in range(N+1-a):
        c = N-a-b
        if Y == 10000*a+5000*b+1000*c:
            ans = [a,b,c]
            break

print(*ans)


Measured memory_bytes: 3060
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int T = sc.nextInt();
                for (int i = 0; i < T; i++) {
                        int N = sc.nextInt();
                        int X = sc.nextInt();
                        int ansA = 0, ansB = 0;
                        for (int j = 1; j < N; j++) {
                                int Y = sc.nextInt();
                                ansA = Math.max(Y - X, ansA);
                                ansB = Math.max(X - Y, ansB);
                                X = Y;
                        }
                        System.out.println(ansA + " " + ansB);
                }
        }
}

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

using namespace std;

#define ll long long

void solve() {
	int n;
	cin >> n;
	int cnt = 0, temp = 0;
	for(int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		if (a == b) {
			temp++;
			cnt = max(temp, cnt);
		} else {
			temp = 0;
		}
	}
	cout << (cnt > 2 ? "Yes\n" : "No\n");
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  if(a == 1 && b == 2) puts("3");
  else if(a == 1 && b == 3) puts("2");
  else if(a == 2 && b == 3)puts("1");
  else if(a == 3 && b == 1) puts("2");
  else if(a == 3 && b == 2) puts("1");
  else if(a == 2 && b == 1) puts("3");
  return 0;
}

Measured memory_bytes: 1584
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x&&x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS*max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x*x + y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;



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

	bool ok = true;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (a[i]>i)
		{
			ok = false;
		}

		if (i >= 1 && a[i] - a[i - 1] >= 2)
		{
			ok = false;
		}
	}


	if (ok)
	{
		ll ans = 0;
		for (int i = 1; i < N; ++i)
		{
			if (a[i] - a[i - 1] == 1)
			{
				ans++;
			}
			else
			{
				ans += a[i];
			}
		}
		cout << ans << endl;
	}
	else
	{
		cout << -1 << endl;
	}

	return 0;
}


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

void include3(int x,int i){
    while(true){
        if(x%10==3){
            cout<<" "<<i;
            break;
        }
        else{
            x/=10;
            if(x==0)break;
        }
    }
}

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        int x=i;
        if(x%3==0){
            cout<<" "<<i;
        }
        else{
            include3(x,i);
        }
    }
    cout<<endl;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define int long long
ll msize;
int N,Max=0;
vector<int> bit(1e7);
int lowbit(int x){
	return x&(-x);
}
void add(int x){
	for(int i=x;i<=1e7;i+=lowbit(i))
	bit[i]+=1;
}
ll sum(int a){
	ll ret = 0;
	for(int x = a;x>0;x -=x&-x)ret += bit[x];
	return ret;
}
ll count(vector<int> &c){
	ll ret = 0;
	fill(ALL(bit),0);
	for(int j=0;j<c.size();j++){
		ret += sum(c[j] + N+1);
		add(c[j] + N+1);
	}
	//cout << ret << endl;
	return ret;
}
bool check(vector<int> &a,int k){
	vector<int> b = a,c(a.size()+1);
	for(int i=0;i<b.size();i++){
		if(a[i] >= k)b[i]=1;
		else b[i] = -1;
	}
	//cout << "(msize+1)/2) =" << (msize+1)/2 <<" ";
	//cout << "k = " << k <<" ";
	c[0] = 0;
	for(int i=0;i<b.size();i++){
		c[i+1] = c[i] + b[i];
	}
	//cのある区間について、k以上の数をカウントする
	if(count(c) >= (msize+1)/2)return 1;
	else return 0;
}
signed main(void){
	
	cin >> N;
	vector<int> a(N);
	msize = (ll)N*(N+1)/2;
	for(int i=0;i<N;i++){
		cin >> a[i];
		Max = max(Max,a[i]);
	}
	int ok = -1;
	int ng = 1e9+7;
	while(abs(ok-ng)>1){
		int mid = (ok+ng)/2;
		//check(vector<int> &a,mid)はmid以上の数がmに半分以上含まれていた場合1を返す
		if(check(a,mid)){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	cout << ok << endl;
}


Measured memory_bytes: 80776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N; cin >> N;
    vector<int> s(N);
    int sum =0;
    bool f=true;
    FOR(i,0,N){
        cin >> s[i];
        sum+=s[i];
        if(s[i]%10!=0)f=false;
    }
    sort(s.begin(),s.end());
    if(f)cout<<0<<endl;
    else if(sum%10!=0)cout<<sum<<endl;
    else{
        FOR(i,0,N){
            if(s[i]%10!=0){
                cout << sum-s[i] <<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long
#define EB emplace_back
#define MOD 1000000007
#define F first
#define S second
#define N 100005
#define endl "\n"
 
 
using namespace std; 



    

int32_t main()
{
  
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int tt=1;

    //cin>>tt;
    
    while(tt--)
    {
      string str1,str2;
      cin>>str1>>str2;
      int a,b; cin>>a>>b;
      string t; cin>>t;
      map<string,int> mp;
      mp[str1] = a;
      mp[str2] = b;
        mp[t]-=1;
        cout<<mp[str1]<<" "<<mp[str2];
    }
        return 0;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll i=1,j,k,n,a,c,b,r,p,cnt=0,s=1;
    cin>>n>>k;
    vector<ll>v;
    for(i=0;i<k;i++)
    {
        cin>>c;
        v.push_back(c);
        cnt+=v[i];
    }
    if(n<=cnt)
    {
        cout<<"Yes"<<endl;
    }
    else
    cout<<"No"<<endl;

    return 0;
}


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

int main(){
    vector<bool> isprime(55556, true);
    isprime[0] = isprime[1] = false;
    for(int i=2; i*i<55556; i++){
        if(isprime[i]){
            for(int j=i*2; j<55556; j+=i){
                isprime[j] = false;
            }
        }
    }
    int n;
    cin >> n;
    for(int i=2; i<55556 && n>0; i++){
        if(isprime[i] && i%10==1){
            cout << i << " ";
            n--;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll N,K;
	int A[400001],nextd[400001],nownext[200001];
	scan(N>>K);
	fill(nownext,nownext+200001,-1);
	rep(i,N){
		scan(A[i]);
		A[i+N]=A[i];
	}
	brep(i,2*N){
		if(nownext[A[i]]==-1) nextd[i]=INF;
		else{
			nextd[i]=nownext[A[i]]-i;
		}
		nownext[A[i]]=i;
	}
	ll nowpos=0;
	while(1){
		if(nowpos>=(K-1)*N) break;
		nowpos+=nextd[nowpos%N]+1;
		//printf("%3lld  %3lld  %3lld\n",nowpos,nowpos%N,K);
		if(nowpos>=K*N){
			kaigyo;
			return 0;
		}
		if(nowpos%N==0){
			K%=nowpos/N;
			if(K==0) K=nowpos/N;
			nowpos=0;
		}
	}
	ll finalpos=nowpos%N;
	while(finalpos<N){
		if(finalpos+nextd[finalpos]>=N){
			printf("%d ",A[finalpos]);
			finalpos++;
		}
		else{
			finalpos+=nextd[finalpos]+1;
		}
	}
	kaigyo;
	return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <sstream>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <numeric>
#include <map>
using namespace std;

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

	a + b + c >= 22 ? cout << "bust" : cout << "win";
}

Measured memory_bytes: 3592
s = gets.chomp
n = s.length
l = 0
r = n - 1
ans = 0
while true
  break if l >= r
  if s[l] == "x" && s[r] == "x"
    l += 1
    r -= 1
  elsif s[l] == "x" && s[r] != "x"
    ans += 1
    l += 1
  elsif s[l] != "x" && s[r] == "x"
    ans += 1
    r -= 1
  else
    if s[l] == s[r]
      l += 1
      r -= 1
    else
      puts -1
      exit
    end
  end
end
puts ans


Measured memory_bytes: 3964
import itertools

def main():
    n = int(input())
    s = input()

    ans = 0
    output_list = []

    for i in range(1000):
        if len(str(i)) == 1:
            a = 0
            b = 0
            c = i
        elif len(str(i)) == 2:
            a = 0
            b = i // 10
            c = i - b * 10
        else:
            a = i // 100
            b = (i - a * 100) // 10
            c = i - a * 100 - b * 10
        tmp = str(a) + str(b) + str(c)
        output_list.append(tmp)
    
    for i in range(1000):
        a = output_list[i][0]
        b = output_list[i][1]
        c = output_list[i][2]
        first_flag = False
        second_flag = False
        for j in range(n):
            if not first_flag and s[j] == a:
                first_flag = True
                continue
            if first_flag and not second_flag and s[j] == b:
                second_flag = True
                continue
            if first_flag and second_flag and s[j] == c:
                ans += 1
                break

    print(ans)

if __name__ == '__main__':
    main()

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

typedef struct {
    char suit;
    char value;
} Card;

bool isStable(Card b[], Card s[], int n){
    for(int i = 0; i < n; i++){
        if(b[i].suit != s[i].suit || b[i].value != s[i].value){
            return false;
        }
    }
    return true;
}

void print(Card b[], Card s[], int n){
    for(int i = 0; i < n; i++){
        cout << b[i].suit << b[i].value;
        if(i != n-1) cout << " ";
    }
    cout << endl;
    cout << "Stable" << endl;

    for(int i = 0; i < n; i++){
        cout << s[i].suit << s[i].value;
        if(i != n-1) cout << " ";
    }
    cout << endl;
    if(isStable(b, s, n)) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
}

void bubbleSort(Card c[], int n){
    for(int i = 0; i < n; i++){
        for(int j = n - 1; j > i; j--){
            if(c[j].value < c[j - 1].value){
                swap(c[j], c[j - 1]);
            }
        }
    }
}

void selectionSort(Card c[], int n){
    for(int i = 0; i < n - 1; i++){
        int minj = i;
        for(int j = i + 1; j < n; j++){
            if(c[j].value < c[minj].value){
                minj = j;
            }
        }
        swap(c[i], c[minj]);
    }
}

int main(){
    int n;
    cin >> n;
    char a[36][3];
    Card b[36], s[36];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 2; j++){
            cin >> a[i][j];
        }
        b[i].suit = a[i][0];
        b[i].value = a[i][1];
        s[i].suit = a[i][0];
        s[i].value = a[i][1];
    }
    bubbleSort(b, n);
    selectionSort(s, n);
    print(b, s, n);
    return 0;
}



Measured memory_bytes: 3096
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())


int main(){
  ll n,m;
  cin>>n>>m;
  vp drink(n);
  REP(i,n){
    cin>>drink[i].first>>drink[i].second;
  }
  sort(drink.begin(),drink.end());
  ll ans=0;
  int i=0;
  while(m>0){
    ans+=drink[i].first*min(m,drink[i].second);
    m-=drink[i].second;
    i++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
/*
Code By: Sai Harsha K
 */

#include <bits/stdc++.h>
using namespace std;
#define lli long long int

lli solve(int i, int W, int w[], int v[], vector<vector<lli>>& dp) {
  // base case
  if(i<0 || W <= 0)
    return 0;
  if(dp[i][W] != -1)
    return dp[i][W];
  // We can either include i or not include it
  if(W < w[i]) // this if condition is must because, v[i] + 0 will be considered. W-w[i] can be 0 but not <0 in that case
    dp[i][W] = solve(i-1, W, w, v, dp);
  else
    dp[i][W] = max(solve(i-1, W, w, v, dp), v[i] + solve(i-1, W-w[i], w, v, dp));
  return dp[i][W];
}

int main() {
#ifndef ONLINE_JUDGE
  // these lines to be executed in local machine not online judge
  // get input
  freopen("input.txt", "r", stdin);
  // put output
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false); cin.tie(NULL);

  // solution
  int t = 1;
  while(t--) {
    int n, W;
    cin>>n>>W;
    int w[n], v[n];
    for(int i = 0; i < n; i++) {
      cin>>w[i]>>v[i];
    }
    vector<vector<lli>> dp(n, vector<lli> (W+1, -1)); // 0 indexed(n)
    // cant just do with dp[W+1] as we can only use each object once
    // base case
    for(int i = 0; i < n; i++) {
      dp[i][0] = 0;
    }
    // populate dp
    cout<<solve(n-1, W, w, v, dp);
  }

  return 0;
}


Measured memory_bytes: 82376
#include<stdio.h>
int main(){
    int n,k,r,s,p;
    int point=0,i,j;
    scanf("%d%d%d%d%d",&n,&k,&r,&s,&p);
    char t[n+1],u[n+1];
    scanf("%s",t);
    for(i=0;i<n;i++){
        if(i<k){
            if(t[i]=='r'){
                point+=p;
                u[i]='p';
            }
            else if(t[i]=='s'){
                point+=r;
                u[i]='r';
            }
            else{
                point+=s;
                u[i]='s';
            }
        }
        else{
            if(t[i]=='r'){
                if(u[i-k]!='p'){
                    point+=p;
                    u[i]='p';
                }
                else{
                    u[i]='a';
                }
            }
            else if(t[i]=='s'){
                if(u[i-k]!='r'){
                    point+=r;
                    u[i]='r';
                }
                else{
                    u[i]='a';
                }
            }
            else{
                if(u[i-k]!='s'){
                    point+=s;
                    u[i]='s';
                }
                else{
                    u[i]='a';
                }
            }
        }
    }
    printf("%d\n",point);
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	static int N;
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		int A[] = new int[N];
		int B[] = new int[N];
		int C[] = new int[N];
		
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
		}
		Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);
		
		long ans = 0;
		for(int i = 0; i < N; i++) {
			long temp_a = lowerbound(A, B[i]);
			//System.out.println("a:" + temp_a);
			long temp_c = upperbound(C, B[i]);
			//System.out.println("c:" + temp_c);
			ans = ans + temp_a * (N - temp_c);
		}
		System.out.println(ans);
	}
	
	public static long lowerbound(int[] arr, int value) {
	    int low = 0;
	    int high = arr.length;
	    int mid;
	    while (low < high) {
	        mid = ((high - low) >>> 1) + low;
	        if (arr[mid] < value) {
	            low = mid + 1;
	        } else {
	            high = mid;
	        }
	    }
	    return low;
	}
	
	public static long upperbound(int[] arr, int value) {
	    int low = 0;
	    int high = arr.length;
	    int mid;
	    while (low < high) {
	        mid = ((high - low) >>> 1) + low;
	        if (arr[mid] <= value) {
	            low = mid + 1;
	        } else {
	            high = mid;
	        }
	    }
	    return low;
	}
}


Measured memory_bytes: 95952
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

#define mid  ((tl+tr)>>1)
const int maxn = 1e5+5;
vector<int>t(maxn<<2,1e18),lazy(maxn<<2,1e18);
vector<pair<int,int>>g[maxn];
int n,m;
void push(int rt){
	t[rt<<1] = min( t[rt<<1] , lazy[rt] );
	t[rt<<1|1] = min( t[rt<<1|1] , lazy[rt] );
	lazy[rt<<1] = min( lazy[rt<<1] , lazy[rt] );
	lazy[rt<<1|1] = min( lazy[rt<<1|1] , lazy[rt] );
}
void update(int rt,int tl,int tr,int l,int r,int new_val){
	if( l > r )return;
	if( tl == l && tr == r ){t[rt]=min(t[rt],new_val); lazy[rt]=min(lazy[rt],new_val); return;}
	push(rt);
	update(rt<<1,tl,mid,l,min(r,mid),new_val);
	update(rt<<1|1,mid+1,tr,max(mid+1,l),r,new_val);
}
int query(int rt,int tl,int tr,int pos){
	if( tl == tr )return t[rt];
	push(rt);
	if( pos <= mid ) return query(rt<<1,tl,mid,pos);
	return query(rt<<1|1,mid+1,tr,pos);
}
int32_t main(){
	IOS
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int l,r,w;cin>>l>>r>>w;
		if( l!= r){
			g[l].push_back({r,w});
		}
	}
	update(1,1,n,1,1,0);
	for(int i=1;i<n;i++){
		int cur = query(1,1,n,i);
		//bug2(i,cur);
		for(auto [r,w]:g[i]){
			update(1,1,n,i+1,r,cur+w);
		}
	}
	int ans = query(1,1,n,n);
	cout << ( ans < 1e18 ? ans : -1 )  << endl;
}
/*
 * long long or int?
 * index out of bound?
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 14820
# -*- coding: utf-8 -*-


def main():
    from collections import defaultdict
    from collections import deque

    n = int(input())
    graph = [defaultdict(int) for _ in range(n)]
    visited = [False for _ in range(n)]
    dist = [0 for _ in range(n)]

    for i in range(n - 1):
        ai, bi, ci = map(int, input().split())
        ai -= 1
        bi -= 1
        graph[ai][bi] = ci
        graph[bi][ai] = ci

    q, k = map(int, input().split())
    k -= 1
    dist[k] = 0
    d = deque()
    d.append(k)

    while d:
        di = d.popleft()
        visited[di] = True

        for bi, ci in graph[di].items():
            if visited[bi]:
                continue

            dist[bi] = dist[di] + ci
            d.append(bi)

    for j in range(q):
        xi, yi = map(int, input().split())
        xi -= 1
        yi -= 1
        print(dist[xi] + dist[yi])


if __name__ == '__main__':
    main()


Measured memory_bytes: 106204
H,W,K = map(int, input().split())
ans = 0
board =[list(input()) for _ in range(H)]

for paint_H in range(2 ** H): #行の塗りつぶし方の全列挙
    for paint_W in range(2 ** W): #列の塗りつぶし方の全列挙
        cnt = 0
        for i in range(H):
            for j in range(W):
                if (paint_H>>i)&1==0 and (paint_W>>j)&1==0:
                    if board[i][j] == '#':
                        cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Measured memory_bytes: 9068
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let dfs vs n =
  let d = Array.make n (-1) in
  let rec doit i j =
    d.(i) <- j;
    List.iter (fun v -> if d.(v) = (-1) then doit v j) vs.(i) in
  Array.iteri (fun i e -> if e = (-1) then doit i i) d;
  d

let () =
  let read_ints () = read_line () |> split_on_char ' ' |>  List.map int_of_string in
  let (n, m) = match read_ints () with
    | [n; m] -> (n, m)
    | _ -> assert false in
  let vs = Array.make n [] in
  for _ = 0 to m - 1 do
    match read_ints () with
    | [s; t] ->
      vs.(s) <- t :: vs.(s);
      vs.(t) <- s :: vs.(t);
    | _ -> assert false
  done;
  let d = dfs vs n in
  let q = read_int () in
  for _ = 0 to q - 1 do
    match read_ints () with
    | [s; t] -> Printf.printf (if d.(s) = d.(t) then "yes\n" else "no\n")
    | _ -> assert false
  done

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

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

  if (S.size() <= K) cout << S << endl;
  else{
    for(int i=0; i<K; i++){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":"\n");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    vector<int> x(n),y(n);
    REP(i,n) {
        cin>>x[i]>>y[i];
        if(x[i]>y[i]) swap(x[i],y[i]);
    }
    int ans=INF;
    int MIN=min((*min_element(ALL(x))),(*min_element(ALL(y))));
    int MAX=max((*max_element(ALL(x))),(*max_element(ALL(y))));
    int rmx=-INF,bmn=INF;
    REP(i,n) {
        chmax(rmx,x[i]);
        chmin(bmn,y[i]);
    }
    chmin(ans,(rmx-MIN)*(MAX-bmn));

    set<pii> s;
    REP(i,n) s.insert({x[i],i});
    int mx=rbegin(s)->first,mn=begin(s)->first;
    chmin(ans,(MAX-MIN)*(mx-mn));
    REP(i,n) {
        int idx=begin(s)->second;
        s.erase({x[idx],idx});
        s.insert({y[idx],idx});
        mx=rbegin(s)->first;
        mn=begin(s)->first;
        chmin(ans,(MAX-MIN)*(mx-mn));
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 17920