akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL N,K;cin >> N >> K;
    vector<LL> A(N);
    rep(i,N){
        LL a;cin >> a;
        a--;
        A[i] = a;
    }

    map<LL,LL> m;
    rep(i,N){
        m[i] = A[i];
    }

    vector<bool> ok(N);

    vector<LL> st;

    LL start = -1;
    LL end = -1;
    LL now = 0;
    ok[0] = true;
    st.push_back(0);

    rep(i,N){
        if(ok[m[now]]){
            start = m[now];
            end = now;
            break;
        }
        
        ok[m[now]] = true;
        now = m[now];
        st.push_back(now);
    }


    // cout << start << " " << end  << endl;
    // rep(i,st.size())cout << st[i] << " ";
    // cout  << endl;

    if(st.size() > K){
        cout << st[K]+1 << endl;
    }
    else{
        LL sind = -1;
        for(LL i = 0;i < st.size();i++){
            if(start == st[i]){
                sind = i;
            }
            if(end == st[i]){
                end = i;
            }
        }


        //cout << sind << " " << end << endl;
        LL num = (K-sind) % (end - sind + 1LL);
        LL ans = st[sind + num];

        cout << ans + 1LL << endl;
    }
    

    
}

Measured memory_bytes: 19460
N, M = map(int, input().split())
 
# issafe => 0段目からN段目まで, 安全ならTrue, 壊れているならFalse
issafe = [1] * (N+1)
for i in range(M):
  a = int(input())
  issafe[a] = 0

# 動的計画法（漸化式）
# dp => 0段目からN段目まで, その移動方法の数
dp = [0] * (N+1)
dp[0] = 1
if issafe[1]: dp[1] = 1
for i in range(2, N+1):
  if issafe[i-1]: dp[i] += dp[i-1]
  if issafe[i-2]: dp[i] += dp[i-2]
  dp[i] %= 10**9+7
    
print(dp[N])

Measured memory_bytes: 13536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
//		String[] tmpArray = br.readLine().split(" ");
//		int n = Integer.parseInt(br.readLine());
//		int b = Integer.parseInt(tmpArray[1]);
//		int c = Integer.parseInt(tmpArray[2]);
//		int y = Integer.parseInt(tmpArray[3]);
//		int r = Integer.parseInt(tmpArray[4]);

//		String[] tmpArray = br.readLine().split(" ");
//		int[] input = new int[n];
//		long sum = 0;
//		for(int i = 0; i < n; i++){
//			input[i] = Integer.parseInt(tmpArray[i]);
//			sum += input[i];
//		}
//		
//		Arrays.sort(input);
//		System.out.printf("%d %d %d\n", input[0], input[input.length - 1], sum);
//		
		while(true){
			String[] tmpArray = br.readLine().split(" ");
			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);
			if(a == 0 && b == 0){
				break;
			}
			
			for(int i = 0; i < a; i++){
				for(int j = 0; j < b; j++){
					if((i + j)%2 == 1){
						System.out.print(".");
					}
					else{
						System.out.print("#");
					}
				}
				System.out.println();
			}
			System.out.println();
		}

		//		int[] array = new int[3];
//		array[0] = a; array[1] = b; array[2] = c;
//
//		Arrays.sort(array);
//		System.out.printf("%d %d %d\n", array[0], array[1], array[2]);
		/*
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}*/
	}

}

Measured memory_bytes: 33028
import collections
DIVISOR = 10 ** 9 + 7

def check(n, a_count):
    if n % 2 == 1:
        if set(a_count.keys()) == set(range(0, n, 2)):
            if a_count[0] == 1 and all([a_count[key] == 2 for key in a_count if key != 0]):
                ans = (2 ** (n // 2)) % DIVISOR
                return ans
                
    else:
        if set(a_count.keys()) == set(range(1, n, 2)):
            if all([a_count[key] == 2 for key in a_count]):
                ans = (2 ** (n // 2)) % DIVISOR
                return ans
    return 0


n = int(input())
a = list(map(int, input().split()))

a_count = collections.Counter(a)
print(check(n, a_count))            

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

ll N, C;
vector<ll> x, v;

int main () {
  cin >> N >> C;
  x.resize(N), v.resize(N);
  rep(i,N) cin >> x[i] >> v[i];


  ll ans = 0;
  ll y = 0, z = 0;
  vector<ll> r(N+1, 0), l(N+1, 0);
  rep(i,N) {
    y += v[i];
    z += v[N-1-i];
    r[i+1] = max(r[i], y - x[i]);
    l[i+1] = max(l[i], z - (C - x[N-i-1]));
    ans = max(ans, max(r[i+1], l[i+1]));
  }

  y = 0, z = 0;
  rep(i,N) {
    y += v[i];
    z += v[N-1-i];
    ans = max(ans, y - 2*x[i] + l[N-i-1]);
    ans = max(ans, z - 2*(C - x[N-1-i]) + r[N-i-1]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
N=int(input())
X=list(map(int, input().split()))
X2=sorted(X)
medi_candi=[X2[N//2-1],X2[N//2]]

for i in X:
    if i <= medi_candi[0]:
        print(medi_candi[1])
    elif i >= medi_candi[1]:
        print(medi_candi[0])

Measured memory_bytes: 93780
#include<iostream>
int main()
{
int a,b;
std::cin >> a;
std::cin >> b;
if((a+b)%3 == 0 || a%3 == 0 || b%3 == 0)
{
std::cout << "Possible" << std::endl;
}
else
{
std::cout << "Impossible" << std::endl;
}
return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val ans = Array(n + 1) { 0 }
    for (x in 1..100) {
        for (y in 1..100) {
            for (z in 1..100) {
                val v = x * x + y * y + z * z + x * y + y * z + z * x
                if (v <= n) {
                    ans[v]++
                }
            }
        }
    }
    for (i in 1..n) {
        println(ans[i])
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 36600
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{
  int a, b, d, g; //かっている数//最大100

  cin >> d >> g;

  vector<long> p(d);
  vector<long> c(d);

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

  long ans = MOD;

  for(int mask = 0; mask < (1 << d); ++mask){//要素数10までのbitDP
        long s = 0, num = 0, rest_max = -1;

        for(int i = 0; i < d; ++i){
            if(mask >> i & 1){//各i*100の問題が全完しているとき
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;//そうじゃないとき,全完していない問題のうち配点が最大のものの添字
            }
        }

        if(s < g){
            int s1 = 100 * (rest_max + 1);    //1問あたりの係数
            int need = (g - s +(s1-1)) / s1; //目標得点 - 現在得点 の切り上げテクニック
            if(need >= p[rest_max])continue; //全完以上ならcontinueして飛ばす
            num += need;//問題数
        }
        ans = min(ans, num);

    }



  cout << ans;

  return 0;
}


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

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<math.h>

using namespace std;



int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	long long int n;
	cin >> n;
	long long int k;
	cin >> k;
	long long int arr[n];
	long long int brr[n];
	for (long long int i = 0; i < n; i++)
		cin >> arr[i] >> brr[i];
	long long int crr[n + 1][k + 1];
	for (long long int i = 0; i <= n; i++)
	{
		for (long long int j = 0; j <= k; j++)
		{
			crr[i][j] = 0;
		}
	}



	for (long long int i = 1; i <= n; i++)
	{
		for (long long int j = 1; j <= k; j++)
		{
			if (arr[i - 1] <= j)
			{
				crr[i][j] = max(brr[i - 1] + crr[i - 1][j - arr[i - 1]], crr[i - 1][j]);
			}
			else {
				crr[i][j] = crr[i - 1][j];
			}

		}
	}
	cout << crr[n][k] << endl;

	return 0;


}


Measured memory_bytes: 82380
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	string a;
	string b = "AC";
	string c = "WA";
	string d = "TLE";
	string e = "RE";
	int p = 0;
	int i = 0;
	int j = 0;
	int q = 0;
	while(n > 0){
		cin >> a;
		if(a == b){
			p += 1;
		}
		else if(a == c){
			i += 1;
		}
		else if(a == d){
			j += 1;
		}
		else if(a == e){
			q += 1;
		}
		n -= 1;
	}
	cout << "AC" << " x " << p << endl;
	cout << "WA" << " x " << i << endl;
	cout << "TLE" << " x " << j << endl;
	cout << "RE" << " x " << q << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 1000001
 
int ru[MAX],cu[MAX];
int rv[MAX],cv[MAX];
int a[MAX],b[MAX],c,d;
int e[MAX],f[MAX],g,h;
 
int main(){
  int N,u,v,m,in;
  cin >> N >> u >> v >> m;
  for(int i = 0 ; i < MAX ; i++){
    ru[i] = cu[i] = rv[i] = cv[i] = -1;
    a[i] = b[i] = N;
    e[i] = f[i] = N;
  }
  c = d = g = h = N;
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N ; j++){
      cin >> in;
      ru[in] = i;
      cu[in] = j;
    }
  }
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N ; j++){
      cin >> in;
      rv[in] = i;
      cv[in] = j;
    }
  }
  
  bool usagi = false,neko = false;
  int x;
  while(m--){
    cin >> x;
    if(N == 1){
      if(ru[x] != -1){
        u--;
      }
      if(rv[x] != -1){
        v--;
      }
      if(u == 0){ usagi = true; }
      if(v == 0){ neko = true; }
      if(usagi || neko){ break; }
      continue;
    }
    if(ru[x] != -1){
      a[ru[x]]--;
      b[cu[x]]--;
      if(ru[x] == cu[x]){
        if( N/2 == ru[x] && (N & 1) ){
          c--;
          d--;
        }else{
          c--;
        }
        if(c == 0){ c = -1; u--; }
        if(d == 0){ d = -1; u--; }
      } else if(ru[x]+cu[x] == N-1){
        d--;
        if(d == 0){ d = -1; u--; }
      }
      if(a[ru[x]] == 0){ ru[x] = -1; u--; }
      if(b[cu[x]] == 0){ cu[x] = -1; u--; }
    }
 
    if(rv[x] != -1){
      e[rv[x]]--;
      f[cv[x]]--;
      if(rv[x] == cv[x]){
        if(N/2 == rv[x] && (N&1) ){
          g--;
          h--;
        }else{
          g--;
        }
        if(g == 0){ g = -1; v--; }
        if(h == 0){ h = -1; v--; }
      } else if(rv[x]+cv[x] == N-1){
        h--;
        if(h == 0){ h = -1; v--; }
      }
      if(e[rv[x]] == 0){ rv[x] = -1; v--; }
      if(f[cv[x]] == 0){ cv[x] = -1; v--; }
    }
    if(u <= 0){ usagi = true; }
    if(v <= 0){ neko = true; }
    if(usagi || neko){
      break;
    }
  }
  while( cin >> x ){}
  if((usagi && neko) || (!usagi && !neko)){
    cout << "DRAW" << endl;
  }else if(usagi){
    cout << "USAGI" << endl;
  }else{
    cout << "NEKO" << endl;
  }
  return 0;
}

Measured memory_bytes: 32408
//AUTHOR - NIMISH UPADHYAY
//FROM IIIT ALLAHABAD
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define NIMISH ios_base::sync_with_stdio(false);cin.tie(NULL);
int main(){
    NIMISH
    ll n,j=0,k=0,x,y;
    cin>>n;
    while(n--){
        cin>>x>>y;
        if(x!=y)
        j=0;
        else{
            j++;
            if(j==3)
            k=1;
        }
    }
    if(k==1)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 3648
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

ans = 0
for b in B:
    lower_A = bisect.bisect_left(A, b)  # b以上の値が初めて現れるインデックスが得られる
    upper_C = bisect.bisect_right(C, b)  # bより真に大きい値が初めて現れるインデックスが得られる
    ans += lower_A * (N-upper_C)

print(ans)


Measured memory_bytes: 105572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  ll n, k;
  cin >> n >> k;
  ll m = n-k;
  ll j = m/k*k;
  cout << min(abs(n-j),min(abs(n-j-k),abs(n-j-k-k))) << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
ans = 0

for i in range(1, n + 1):
    count = 0
    for j in range(1, n + 1):
        if i % 2 == 0:
            break
        if i % j == 0:
            count += 1
    if count == 8:
        ans += 1
        
print(ans)

Measured memory_bytes: 2940
/*
 * AOJ 2230: How to Create a Good Game
 * ?¢?????????????????????????????????????????????¨??????????????°????????????????????????????????????????¢???????????????????????±??????§????¢??????????????????????
 * ?±???????????°??´?
 * ??????????????\?????????????????\??????INF??±?´?????´????????????????Dijkstra?±????????????????????????°???????????\?????????????????±?´???????????????????????????????s?±?t???s?????\?????§????????????????????????????????±?´??????¬??????1??±?´?0?????????????????§??????t????±??????????????±???????????°??´??????????????????£???????????????????´???????????????\????????????????????°??????????????????
 */

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;

int in[110], out[110];

struct Edge {
  Edge() {}

  Edge(int _v, int _cap, int _cost, int _rev) : v(_v), cap(_cap), cost(_cost), rev(_rev) {}

  int v, cap, cost, rev;
};

vector<Edge> e[110];
int n;
int h[110], d[110];
int pv[110], pe[110];
priority_queue<pii, vector<pii>, greater<pii> > pq;

void AddEdge(int u, int v, int cap, int cost) {
  e[u].push_back(Edge(v, cap, cost, e[v].size()));
  e[v].push_back(Edge(u, 0, -cost, e[u].size() - 1));
}

int MinCostFlow(int s, int t, int f) {
  int ans = 0;
  memset(h, 0, sizeof(h));
  while (f > 0) {
    memset(d, 0x3f, sizeof(d));
    d[s] = 0;
    pq.push(make_pair(0, s));
    while (!pq.empty()) {
      int u = pq.top().second;
      int pre = pq.top().first;
      pq.pop();
      if (d[u] < pre) continue;
      for (int i = 0; i < e[u].size(); ++i) {
        Edge &te = e[u][i];
        int v = te.v;
        if (te.cap > 0 && d[v] > d[u] + h[u] - h[v] + te.cost) {
          d[v] = d[u] + h[u] - h[v] + te.cost;
          pv[v] = u;
          pe[v] = i;
          pq.push(make_pair(d[v], v));
        }
      }
    }

    if (d[t] == INF) {
      return -1;
    }
    for (int i = 0; i < n; ++i) {
      h[i] += d[i];
    }

    int cur = f;
    for (int i = t; i != s; i = pv[i]) {
      cur = min(cur, e[pv[i]][pe[i]].cap);
    }
    ans += cur * h[t];
    f -= cur;
    for (int i = t; i != s; i = pv[i]) {
      Edge &te = e[pv[i]][pe[i]];
      te.cap -= cur;
      e[i][te.rev].cap += cur;
    }
  }
  return ans;
}

int main() {
  int m;
  scanf("%d%d", &n, &m);
  int s = n, t = n + 1;
  int sum = 0;
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    AddEdge(u, v, INF, -c);
    sum += c;
    ++in[v];
    ++out[u];
  }
  int degree = 0;
  for (int i = 0; i < n; ++i) {
    if (in[i] > out[i]) {
      degree += in[i] - out[i];
    }
  }
  MinCostFlow(0, n - 1, degree);

  for (int i = 0; i < n; ++i) {
    if (in[i] > out[i]) {
      AddEdge(s, i, in[i] - out[i], 0);
    } else {
      AddEdge(i, t, out[i] - in[i], 0);
    }
  }
  AddEdge(n - 1, 0, INF, -d[n - 1]);
  n += 2;
  int ans = MinCostFlow(s, t, degree) - sum;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 2836
#include <iostream>
#include <cmath>
#define NMAX 10000
using namespace std;

/* time limit exceeded
bool chkPrime(int a) {
    bool flag = true;
    for (int i = 2; i < a; i++) {
        if (a % i == 0) flag = false;
    }
    return flag;
}
*/

bool chkPrime(int a) {
    float sqrta = sqrt(a);
    for (int i = 2; i <= sqrta; i++) {
        if (a % i == 0) return false;
    }
    return true;
}

int cntPrime(int *A, int n) {
    int num_p = 0;
    for (int i=0; i<n; i++) {
        if ( chkPrime( A[i] ) ) {
            num_p++;
        }
    }
    return num_p;
}

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

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

    // solve
    int num_p;
    num_p = cntPrime(A, n);

    // output
    cout << num_p << endl;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a[200005],b[200005],one,two;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    one=b[n-1];
    two=b[n-2];
    for(int i=0;i<n;i++){
        if(a[i]!=one){
            cout<<one<<endl;
        }
        else{
            cout<<two<<endl;
        }
    }
    return(0);
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The Value Of " << #val << " is : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 1e5+5;
ll ans=0, n, arr[nax];
unordered_map<ll, bool>vis;
 
int main(){
	IOS
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i];	
		if(vis[arr[i]]){
			ans--;
			vis[arr[i]]=0;
		}
		else{
			ans++;
			vis[arr[i]]=1;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 7920
#include <stdio.h>

int main (){
	int L, R, d;
	int a, b;
	scanf("%d %d %d", &L, &R, &d);
	b = 0;
	
	for ( int i = 1; i < 101; i++){
		a = i * d;
		if ( a <= R && a >= L){
			b++;
		}
	}
	printf("%d", b);
	
	return 0;
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
double dis(double a,double b,double c,double d)
{
    double dd=(a-c)*(a-c)+(b-d)*(b-d);
    return sqrt(dd);
}
double fact(double n)
{
    if(n==1)
        return 1;
    return n*(n-1);
}
int main()
{
    FIO;
    double n,s=0;
    cin>>n;
    vector<double>u(n),v(n);
    for(int i=0;i<n;i++)
        cin>>u[i]>>v[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            s+=dis(u[i],v[i],u[j],v[j]);
        }
    }

    cout<<fixed<<setprecision(10)<<(s*(n-1))/fact(n)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>

int main(int argc, const char * argv[]) {
    
    int a, b ;
    char op ;
    int ans ;
    
    while (1) {
        std::cin >> a >> op >> b ;
        
        switch (op) {
            case '+':
                ans = a + b ;
                break;
                
            case '-':
                ans = a - b ;
                break;
                
            case '*':
                ans = a * b ;
                break;
                
            case '/':
                ans = a / b ;
                break;
                
            default:
                return 0 ;
        }
        
        printf("%d\n", ans);
    }
    return 0 ;
}


Measured memory_bytes: 3216
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n

#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define FOR(i,m,n) for(int (i)=(m);(i)<(n); i++)
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
  ll N,K;cin>>N>>K;
  ll ret=0;
  for(int i=0;N>=pow(K,i);i++){
    ret++;
  }
  cout<<ret;
  return 0;
}


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

int solve(vector<vector<int> > &g, vector<bool> &used, int v = 0, int depth = 0){
  int n = g.size();
  bool all_use = true;
  used[v] = true;
  for (int i = 0; i < n; i++) all_use &= used[i]; 
  if(all_use){
    used[v] = false;
    return 1; 
  }
  int res = 0;
  for (int i = 0; i < g[v].size(); i++) {
    if(used[g[v][i]])continue;
    res += solve(g, used, g[v][i], depth + 1);
  }
  used[v] = false;
  return res;
}

int main(){
  int n, m;
  std::cin >> n >> m;
  vector<vector<int> > g(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    std::cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<bool> used(n, false);
  std::cout << solve(g, used) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int a, b, c, d;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> a >> b >> c >> d;
    if (a+b > c+d) cout << "Left" << endl;
    else if (a+b == c+d) cout << "Balanced" << endl;
    else cout << "Right" << endl;
    return 0;
}


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

}

Measured memory_bytes: 1736
h,w = map(int,input().split())
data = [input() for _ in range(h)]
t = True
for i in range(h):
    for j in range(w):
        if data[i][j] == '#':
            if i >= 0 and data[i-1][j] == '#':continue
            elif h-1 > i  and data[i + 1][j] == '#': continue
            elif j >= 0 and data[i][j - 1] == '#': continue
            elif w-1 > j and data[i][j + 1] == '#': continue
            else:
                t = False
                break

if t:print("Yes")
else:print("No")

Measured memory_bytes: 39024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
	int n, m, s, t;
	cin >> n >> m >> s >> t;

	vector<vector<pair<int, pair<ll, ll>>>> city(n + 1);
	for (int i = 0; i < m; i++) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		city[u].push_back(make_pair(v, make_pair(a, b)));
		city[v].push_back(make_pair(u, make_pair(a, b)));
	}

	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
	vector<ll> yen(n + 1, 1e15);
	vector<bool> visit(n + 1);
	pq.emplace(0, s);
	yen[s] = 0;

	while (!pq.empty()) {
		pair<ll, int> x = pq.top();
		visit[x.second] = true;
		pq.pop();

		for (auto edge : city[x.second]) {
			if (visit[edge.first]) continue;

			if (yen[edge.first] > yen[x.second] + edge.second.first) {
				yen[edge.first] = yen[x.second] + edge.second.first;
				pq.emplace(yen[edge.first], edge.first);
			}

		}

	}
	
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq2;
	vector<ll> su(n + 1, 1e15);
	vector<bool> visit2(n + 1);
	pq2.emplace(0, t);
	su[t] = 0;

	while (!pq2.empty()) {
		pair<ll, int> x = pq2.top();
		visit2[x.second] = true;
		pq2.pop();

		for (auto edge : city[x.second]) {
			if (visit2[edge.first]) continue;

			if (su[edge.first] > su[x.second] + edge.second.second) {
				su[edge.first] = su[x.second] + edge.second.second;
				pq2.emplace(su[edge.first], edge.first);
			}

		}

	}
	/*
	for (int i = 1; i <= n; i++) {
		cout << "i=" << i << " ";
		cout << yen[i] << " ";
		cout << su[i] << endl;
	}
	*/

	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq3;
	for (int i = 1; i <= n; i++) {
		pq3.emplace(yen[i] + su[i], i);
	}

	for (int i = 0; i < n; i++) {
		while (pq3.top().second <= i) {
			pq3.pop();
		}
		cout << (ll)1e15 - pq3.top().first << endl;
	}
}


Measured memory_bytes: 14964
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> A(n);
	for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
	int lo = 1, hi = 1000000000;
	while (lo < hi) {
		int m = (lo + hi) >> 1;
		ll need = 0;
		for (int i = 0; i < n; ++i) {
			need += (A[i] - 1) / m;
		}
		if (need <= k) hi = m;
		else lo = m + 1;
	}
	printf("%d\n", lo);
}


Measured memory_bytes: 3948
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
    int h,a;
    cin>>h>>a;
    if(h%a==0)cout<<h/a<<endl;
    else cout<<h/a+1<<endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
k = len(s)
a = [0]*(k+1)
for i in range(k):
  if s[i] == '<':
    a[i+1] = max(a[i+1],a[i]+1)
for j in range(k-1,-1,-1):
  if s[j] == '>':
    a[j] = max(a[j],a[j+1]+1)
print(sum(a))

Measured memory_bytes: 23336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

void out(int a, int b){
    cout << a << ' ' << b << endl;
}

int main(){
    int N;
    cin >> N;
    int memo = N;
    while(memo%2 == 0) memo /= 2;
    if(memo == 1) {cout << "No" << endl; return 0;}
    cout << "Yes" << endl;
    if(N%4 == 1){
        rep2(i, 2, N-1) out(i, i+1);
        out(N, N+2);
        rep2(i, 2, N-1) out(N+i, N+i+1);
        out(1, N+2), out(N+1, N+3);
    }elif(N%4 == 2){
        rep2(i, 2, N-2) out(i, i+1);
        out(N-1, N+2);
        rep2(i, 2, N-2) out(N+i, N+i+1);
        out(1, N+2), out(N+1, N+3);
        out(N-1, N), out(1, 2*N);
    }elif(N%4 == 3){
        rep2(i, 1, 2*N-1) out(i, i+1);
    }else{
        int a = N & (-N);
        rep2(i, 1, N-2) out(i, i+1);
        out(N-1, N+1);
        rep2(i, 1, N-2) out(N+i, N+i+1);
        out(N-a+1, N), out(N+a, 2*N);
    }
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }

int n;
int m;
int kkk = 0;
int d[2000];
int tin[2000];
int tout[2000];
int ct;
vi res;
vi v[2000];
int p[2000];
int x[2000];
int y[2000];
int good[2000];

void rot (int v) {
	res.pb (v);
	kkk++;
	int last = x[0];
	while (v != 0) {
		y[last] = v;
		swap (last, x[v]);
		v = p[v];
	}
	y[last] = 0;
	x[0] = last;
}

int go (int x) {
	tin[x] = ct++;
	for (int i = 0; i < sz (v[x]); i++) {
		int y = v[x][i];
		d[y] = d[x] + 1;
		go (y);
	}
	tout[x] = ct++;
	re 0;
}

int isanc (int a, int b) {
	re int (tin[a] <= tin[b] && tout[a] >= tout[b]);
}

int main () {
	scanf ("%d", &n);
	for (int i = 1; i < n; i++)	{
		scanf ("%d", &p[i]);
		v[p[i]].pb (i);
	}	
	for (int i = 0; i < n; i++) {
		scanf ("%d", &x[i]);
		y[x[i]] = i;
	}
	d[0] = 0;
	go (0);
	int cur = n - 1;
	while (true) {
		while (cur > 0 && y[cur] == cur) cur--;
		if (cur == 0) break;
		for (int j = cur; j >= 0; j--)
			if (!good[j] && x[j] == j) {
				good[j] = 1;
				for (int k = 0; k < sz (v[j]); k++)
					if (!good[v[j][k]]) {
						good[j] = 0;
						break;
					}
			}
		int best = x[0];
//		if (isanc (best, y[cur])) best = y[cur];
		for (int j = cur; j >= 0; j--)
			if (!good[j] && isanc (best, y[j]) && (!isanc (j, y[j]) || !isanc (x[0], j)))
				best = y[j];
		rot (best);
/*		printf ("%d: ", kkk);
		for (int i = 0; i < n; i++) printf ("%d ", x[i]);
		printf ("\n");*/
	}
	printf ("%d\n", sz (res));
	for (int i = 0; i < sz (res); i++) printf ("%d\n", res[i]);
	return 0;
}

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

int main() {
    int N;
    int arr[105];
    scanf("%d", &N);

    for(int i = 0; i < N; i++){
        scanf("%d", &arr[i]);
    }

    for(int i = N-1; i >= 0; i--){
        printf("%d", arr[i]);

        if(i == 0){
            printf("\n");
        }else{
            printf(" ");
        }
    }

    return 0;
}



Measured memory_bytes: 3172
/*************************************************************************

**  **  **  ****   ****    ******   **    **  **     **   **   **   **              
** **   **  ** ** ** **   **     *  **    **  **   *    *    *    *    *
****    **  **   *   **   **        ********  **   *         *         *
****    **  **       **   **        ********  **     *     *   *     *
** **   **  **       **   **     *  **    **  **        *         *
**  **  **  **       **    ******   **    **  **  ***********************      

*************************************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef pair <long,long> ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long n, ans = 0;
    cin >> n;
    long heg[101];
    heg[0] = 0;
    for (int i = 1; i <= n; ++i) cin >> heg[i];
    for (int i = 1; i <= n; ++i) 
    		if (heg[i] > heg[i-1]) ans+=(heg[i] - heg[i-1]);
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
	fio();
	map<ll, ll> mp;
	int n;
	cin >> n;
	ll sum = 0;
	rep (i, n) {
		int x;
		cin >> x;
		mp[x]++;
		sum += x;
	}

	int q;
	cin >> q;
	while (q--) {
		int b, c;
		cin >> b >> c;
		ll num = mp[b];
		sum -= b * num;
		sum += c * num;
		mp[b] = 0;
		mp[c] += num;
		cout << sum << '\n';
	}
}

Measured memory_bytes: 9568
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<deque>
using namespace std;
typedef long long ll;
deque<char>q;
int main(){
    string str;
    cin>>str;
    int len=str.length();
    for(int i=0;i<len;i++){
        q.push_back(str[i]);
    }
    int m;
    cin>>m;
    int T;
    int cnt=0;
    while(m--){
        scanf("%d",&T);
        if(T==1){
          cnt++;
        }
        else{
            int f;
            char op[2];
            scanf("%d%s",&f,op);
            if(cnt%2==0){
              if(f==1)
              q.push_front(op[0]);
              else{
              q.push_back(op[0]);
              }
            }
            else{
              if(f==2)
              q.push_front(op[0]);
              else{
              q.push_back(op[0]);
              }
            }
        }
        
    }
    if(cnt%2==0){
        while(!q.empty()){
            cout<<q.front();
            q.pop_front();
        }
    }
    else{
         while(!q.empty()){
            cout<<q.back();
            q.pop_back();
        }
    }
    return 0;
}

Measured memory_bytes: 960
#include<iostream>

using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N+1],B[N+1],C[N+1];
  for(int i = 1; i <= N; i++) cin >> A[i];
  for(int i = 1; i <= N; i++) cin >> B[i];
  for(int i = 1; i <= N-1; i++) cin >> C[i];
  int sum = B[A[1]];
  for(int i = 2; i <= N; i++){
    sum += B[A[i]];
    if(A[i-1]+1 == A[i]) sum += C[A[i-1]];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  string a, b;cin>>a>>b;
  if((a[0]==b[2]&&a[1]==b[1])&&a[2]==b[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

using namespace std;

int main() {

	int n;
	cin >> n;

	vector<int> x(n);
	vector<int> y(n);
	vector<long long int> h(n);

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

	int cx, cy;
	long long int H;

	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {

			long long int ans = -1;

			for (int k = 0; k < n; k++) {
				long long int xx = (long long int)abs(x[k] - i);
				long long int yy = (long long int)abs(y[k] - j);
				if (h[k] > 0) {
					ans = h[k] + xx + yy;
					break;
				}
			}

			for (int k = 0; k < n; k++) {
				long long int xx = (long long int)abs(x[k] - i);
				long long int yy = (long long int)abs(y[k] - j);
				if (h[k] != max(ans - xx - yy, 0LL)) {
					ans = -1;
					break;
				}
			}

			if (ans >= 1) {
				cx = i;
				cy = j;
				H = ans;
			}
		}
	}

	cout << cx << ' ' << cy << ' ' << H << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
N = input()
N = int(N)
l = input().split()
l = list(map(int, l))

if N != len(l):
    print('Error')
    sys.exit()
Alice = []
Bob = []

while len(l) > 0:
    if len(l) > 0:
        saidai = max(l)
        Alice.append(saidai)
        l.remove(saidai)
    if len(l) > 0:
        saidai = max(l)
        Bob.append(saidai)
        l.remove(saidai)

Alice_num = 0
for i in range(0, len(Alice)):
    Alice_num += Alice[i]
Bob_num = 0
for i in range(0, len(Bob)):
    Bob_num += Bob[i]
kekka = Alice_num - Bob_num
print(kekka)


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

typedef long long ll;

string s;
ll k;

int main(){
    cin >> s;
    cin >> k;
    bool check = false;
    int index = -1;

    for (int i = 0; i < s.size(); i++){
        if (s[i] != '1' &&  i < k){
            cout << s[i] << endl;
            return 0;
        }
    }

    cout << 1 << endl;
}

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

using namespace std;

namespace {
    int N;
    vector<int> A;
    void input() {
        cin >> N;
        A.resize(N);
        for (int i = 0; i < N; i++) cin >> A[i];
    }

    /** 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<int> C(3, 0);
        for (auto& a : A) {
            if (a % 4 == 0) C[0]++;
            else if (a % 2 == 0) C[1]++;
            else C[2]++;
        }
        vector<int> X(N, 0);
        for (int i = 1, j = 0; i < N and j < C[0]; i += 2, j++) {
            X[i] = 4;
        }
        for (int i = 0; i < N and C[2] > 0; i++) {
            if (X[i] != 0) continue;
            X[i] = 1;
            C[2]--;
        }
        for (int i = 0; i < N; i++) {
            if (X[i] == 0) X[i] = 2;
        }
        auto check = [&]() {
            for (int i = 0; i < N - 1; i++) {
                if (X[i] * X[i + 1] % 4 != 0) {
                    return false;
                }
            }
            return true;
        };
        cout << (check() ? "Yes" : "No") << endl;
        //cout << X << endl;
    }
}

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



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


int N;
int A[100000], B[100000], C[100000];

int main() {
	cin >> N;
	rep(i, N){ cin >> A[i]; }
	rep(i, N){ cin >> B[i]; }
	rep(i, N){ cin >> C[i]; }
	sort(&A[0], &A[N]);
	sort(&B[0], &B[N]);
	sort(&C[0], &C[N]);

	int a = -1;
	int c = 0;
	ll ret = 0;

	rep(b, N){
		while(true){
			if(a < N-1 && A[a+1] < B[b]) a++;
			else break;
		}
		while(true){
			if(c < N && C[c] <= B[b]) c++;
			else break;
		}
		ret += (ll)(a+1) * (ll)(N-c);
        // fprintf(stderr, "b:%d, %d - %d * %d\n", b, B[b], (a+1), (N-c));
	}

	cout << ret << endl;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
ll P = 998244353;

ll pow(ll e, ll x) {
  ll r = 1;
  while (x) {
    if (x % 2) {
      r = (r * e) % P;
    }
    e = (e * e) % P;
    x >>= 1;
  }
  return r;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  if (d[0] > 0) {
    cout << 0 << endl;
    return 0;
  }
  sort(d.begin(), d.end());
  ll ans = 1;
  ll mx = 0;
  map<ll, ll> mp;
  for (int i = 0; i < n; i++) {
    mx = max(mx, d[i]);
    mp[d[i]]++;
  }
  if (mp[0] != 1) {
    cout << 0 << endl;
    return 0;
  }
  for (ll i = 1; i <= mx; i++) {
    ans *= pow(mp[i - 1], mp[i]);
    ans %= P;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define DIM 107
#define modulo 1000000007
using namespace std;

long long n,k,a[DIM],p[DIM][100007];

int main()
{
    cin>>n>>k;
    for(int i = 1; i <= n; ++i)
        cin>>a[i];

    for(int i = 0; i <= k; ++i)
        p[0][i] = 1;

    for(int i = 1; i <= n; ++i)
        for(int j = 0; j <= k; ++j)
    {
        p[i][j] = p[i][j-1] + p[i-1][j];
        if(a[i]<j) p[i][j]-=p[i-1][j-a[i]-1];
        p[i][j]+=modulo;
        p[i][j]%=modulo;
    }

    cout<<(p[n][k]-p[n][k-1]+modulo)%modulo;
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int c = 1;
  for (int i = 0; i < N; i++) {
    if (c * 2 < c + K) {
      c *= 2;
    } else {
      c += K;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 3620
'use strict'

function Main(input) {
  const inputArr = input.split(" ");
  const a = Number(inputArr[0]);
  const b = Number(inputArr[1]);

  let a_b = a;
  let b_a = b;

  for (let i = 1; i < b; i++) {
    a_b = a_b + a * Math.pow(10, i)
  }
  for (let j = 1; j < a; j++) {
    b_a = b_a + b * Math.pow(10, j)
  }

  // console.log(a_b, b_a)
  // console.log(Number(a_b.toString().charAt(0)), Number(b_a.toString().charAt(0)));
  console.log(Number(a_b.toString().charAt(0)) >= Number(b_a.toString().charAt(0)) ? b_a : a_b)

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
from itertools import product
from collections import deque
import numpy as np
inputs = open(0).readlines()
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, row in zip(range(h), grid):
            for j, val in zip(range(w), row):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, row)) for row in self.grid])
    def __getitem__(self, x):
        return self.grid[x]
    def __setitem__(self, x, val):
        self.grid[x] = val

h, w = map(int, inputs[0].split())
grid = Grid(inputs[1:], function=lambda x: int(x == '#'))

def dfs(root):
    count = 1
    stack = [root]
    while stack:
        x, y = stack.pop()
        for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
            if grid.is_valid_xy(x+dx, y+dy) and grid[y+dy, x+dx]:
                stack.append((x+dx, y+dy))
                grid[y+dy, x+dx] = 0
                count += 1
    return count
    
ans = 'Yes'
for i, j in product(range(h), range(w)):
    if grid[i, j]:
        if dfs((j, i)) == 1:
            ans = 'No'
            break
print(ans)

Measured memory_bytes: 12344
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var threthold = int.Parse(Console.ReadLine());
            var prime = GeneratePrimes(threthold * 2).First(x => x >= threthold);
            Console.WriteLine(prime);
        }

        static IEnumerable<int> GeneratePrimes(int limit)
        {
            var numbers = Enumerable.Range(2, limit).ToList();
            var primes = new List<int>();

            while (true)
            {
                var prime = numbers.First();
                if (prime * prime > limit) break;
                primes.Add(prime);
                var i = 0;
                while (i < numbers.Count())
                {
                    var num = numbers[i];
                    if (num % prime == 0)
                    {
                        numbers.RemoveAt(i);
                        continue;
                    }
                    i++;
                }
            }
            foreach (var val in numbers) primes.Add(val);
            return primes;
        }

    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
using Graph=vector<vector<int>>;
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; }

char c[10][10];
char c2[10][10];
int h,w,k;
void copy(){
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            c2[i][j]=c[i][j];
        }
    }
}

int main(){
    cin>>h>>w>>k;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cin>>c[i][j];
        }
    }
    int cnt=0;
    long long ans=0;
    for(int bith=0;bith<(1<<h);++bith){
        for(int bitw=0;bitw<(1<<w);++bitw){
            copy();
            for(int i=0;i<h;++i){
                if(bith&(1<<i)){
                    for(int j=0;j<w;++j) c2[i][j]='r';
                }
            }
            for(int j=0;j<w;++j){
                if(bitw&(1<<j)){
                    for(int i=0;i<h;++i) c2[i][j]='r';
                }
            }
            int nk=0;
            for(int i=0;i<h;++i){
                for(int j=0;j<w;++j){
                    if(c2[i][j]=='#') ++nk;
                }
            }
            if(k==nk) ++ans;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3612
N, M = gets.chomp.split(" ").map(&:to_i)
A = Array.new(N)

M.times do 
  s, c = gets.chomp.split(" ").map(&:to_i)
	if A[s-1] == nil || A[s-1] == c
        A[s-1] = c
  else
      A[4] = -1
  end
end

if A[0] == nil
  if N ==1 
  A[0] = 0
  else 
    A[0] = 1
  end
elsif A[0] == 0 && N != 1
  A[4] = -1 
end

if A.include?(-1) 
  puts "-1"
elsif A.include?(nil)
    A.map!{|x| x==nil ? 0 : x}
  	A.map!(&:to_s)
  if A.inject(:+).to_i != 0
    puts "#{A.inject(:+).to_i}"
  else
    puts "-1"
  end
else 
  A.map!(&:to_s)
  puts "#{A.inject(:+).to_i}"
end



Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
int main(){
  string d;
  cin >> d;
  if(d == "SUN"){
    cout << 7 << endl;
  }else if(d == "MON"){
    cout << 6 << endl;
  }else if(d == "TUE"){
    cout << 5 << endl;
  }else if(d == "WED"){
    cout << 4 << endl;
  }else if(d == "THU"){
    cout << 3 << endl;
  }else if(d == "FRI"){
    cout << 2 << endl;
  }else if(d == "SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256