akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const ll mod = 1000000007;
const int N = 3e3+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n, m, p;
vi e[N], c[N], re[N];
ll dis[N];
bool in[N];
int cnt[N], can[N];
void bfs() {
	mt(can, 0);
	queue<int> q;
	q.push(n); can[n] = 1;
	while(sz(q)) {
		int u = q.front(); q.pop();
		for(auto v: re[u]) {
			if(can[v]) continue;
			q.push(v); can[v] = 1;
		}
	}
	// rep(i, 1, n + 1) dd(i), de(can[i]);
}
ll spfa() {
	mt(dis, -1); mt(in, false); mt(cnt, 0);
	dis[1] = 0;
	queue<int> q;
	q.push(1); in[1] = 1;
	while(sz(q)) {
		int u = q.front(); q.pop();
		in[u] = 0;
		rep(i, 0, sz(e[u])) {
			int v = e[u][i], w = c[u][i];
			if(!can[v]) continue;
			if(dis[v]==-1||dis[v]<dis[u]+w) {
				dis[v] = dis[u] + w;
				if(!in[v]) {
					q.push(v), in[v] = 1;
					cnt[v]++;
					if(cnt[v] > n) return -1;
				}
			}
		}
	}
	return max(dis[n], 0ll);
}
int main() {
	scanf("%d%d%d",&n, &m, &p);
	rep(i, 0, m) {
		int u, v, w; scanf("%d%d%d", &u, &v, &w);
		e[u].pb(v);
		re[v].pb(u);
		c[u].pb(w-p);
	}
	bfs();
	printf("%lld\n", spfa());
    return 0;
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

ll calc(int n, vector< vector<int> >& vs) {
    priority_queue<int, vector<int>, greater<int> > pq;
    for (int i = 1; i <= n; i++) {
        for (int x : vs[i]) {
            pq.push(x);
        }

        while (pq.size() > i) pq.pop();
    }

    ll res = 0;
    while (!pq.empty()) {
        res += pq.top();
        pq.pop();
    }
    return res;
}

ll solve(int n, vector<int>& K, vector<int>& L, vector<int>& R) {
    ll ans = 0;
    vector< vector<int> > vs1(n + 1), vs2(n + 1);
    for (int i = 0; i < n; i++) {
        ans += min(L[i], R[i]);
        if (L[i] >= R[i]) vs1[K[i]].push_back(L[i] - R[i]);
        else vs2[n - K[i]].push_back(R[i] - L[i]);
    }

    ans += calc(n, vs1) + calc(n, vs2);
    return ans;
}

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

    int t;
    cin >> t;

    for (int loop = 0; loop < t; loop++) {
        int n;
        cin >> n;

        vector<int> K(n), L(n), R(n);
        for (int i = 0; i < n; i++) {
            cin >> K[i] >> L[i] >> R[i];
        }

        cout << solve(n, K, L, R) << newl;
    }

    return 0;
}

Measured memory_bytes: 20276
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    int[] bricknumber=new int[N];
    int[] index=new int[N+2];//iのあったbricknumberのindex
    int[] check=new int[N+2];
    int last=N;
    
    for(int h=0;h<N;h++){
      bricknumber[h]=sc.nextInt();
    }
    
    check[1]=0;//check[i]はi－1番目の数を見つけたインデックス。そこからiを探し始める
    for(int k=0;k<=N;k++){
      index[k]=-1;
    }
    
    for(int i=1;i<=N;i++){
      for(int j=check[i];j<N;j++){
        if(bricknumber[j]==i){
          index[i]=j;
          check[i+1]=j;
          break;
        }
      }
      if(index[i]==-1){
        last=i-1;
        break;
      }
      
    }
    if(last==0){
      last=N+1;
    }
    
    System.out.println(N-last);
    
  }
}

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

int main() {
    int N,A,B;
    cin >> N >> A >> B;

    int count=0;
    
    for(int j=0;j<N;j++){
        int a=0;
        int s=j+1;
        int k=0;
        int t=s;
        for(int i=0; i<5;i++){
            t=t-k*(pow(10,5-i));
            k=t/pow(10,(4-i));
            a+=k;
        }
        if (A<=a && a<=B){
            count+=s;
        }
    }
    cout << count << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b[110000],ma=0;
string s;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>b[i];
		if(ma-1>b[i]){
			cout<<"No";
			return 0;
		}
		ma=max(ma,b[i]);
	}
	cout<<"Yes";
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>

using namespace std;


int main(void)
{
	int n;
	int i;
	int a[120];
	set<int> st;
	int count = 0;
	int min = 0, max = 0;

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

		if (1 <= a[i] && a[i] <= 399) {
			st.insert(0);
		}

		else  if (400 <= a[i] && a[i] <= 799) {
			st.insert(1);
		}

		else if (800 <= a[i] && a[i] <= 1199) {
			st.insert(2);
		}

		else if (1200 <= a[i] && a[i] <= 1599) {
			st.insert(3);
		}

		else if (1600 <= a[i] && a[i] <= 1999) {
			st.insert(4);
		}

		else if (2000 <= a[i] && a[i] <= 2399) {
			st.insert(5);
		}

		else if (2400 <= a[i] && a[i] <= 2799) {
			st.insert(6);
		}

		else if (2800 <= a[i] && a[i] <= 3199) {
			st.insert(7);
		}
		else {
			count++;
		}
	}

	
	min = st.size();

	if (min == 0 && count >= 1) {
		min = 1;
		max = count;
		cout << min << " " << max << endl;
		return 0;
	}



		max = min + count;

	cout << min << " " << max << endl;

	return 0;

}

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

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

const double eps=1e-5;
const long long INF=(LL)(1e9)*(LL)(1e9);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> p(n),x(n);
    FOR(i,1,n)
        cin>>p[i];
    REP(i,n)
        cin>>x[i];
    vector<vector<int>> g(n);
    FOR(i,1,n)
    {
        p[i]--;
        g[p[i]].push_back(i);
    }
    function<PII(int)> dfs=[&](int v){
        vector<PII> d;
        for(auto&& e:g[v])
        {
            PII t=dfs(e);
            //cout<<e<<" "<<t.first<<" "<<t.second<<endl;
            d.push_back(t);
        }
        int s=0;
        REP(i,d.size())
        {
            s+=d[i].second;
            if(d[i].second<0)
                return PII(-1,-1);
        }

        if(s<x[v])
        {
            //cout<<"ok:"<<x[v]<<endl;
            int sf=0;
            REP(i,d.size())
                sf+=d[i].first;
            return PII(sf,x[v]);
        }

        vector<vector<char>> dp(d.size()+1, vector<char>(x[v]+1));
        dp[0][0]=1;
        
        REP(i,d.size())
        {
            REP(j,x[v]+1)
            {
                if(!dp[i][j])continue;
                if(j+d[i].first<dp[0].size())
                    dp[i+1][j+d[i].first]=1;
                if(j+d[i].second<dp[0].size())
                    dp[i+1][j+d[i].second]=1;
            }    
        }
        int p=-1;
        for(int i=x[v];i>=0;i--)
        {
            if(dp[d.size()][i])
            {
                //cout<<i<<endl;
                p=i;break;
            }
            if(i==0)
            {
                return PII(-1,-1);
            }
        }
        REP(i,d.size())
            s+=d[i].first;
        PII t=x[v]<s-p?PII(x[v],s-p):PII(s-p,x[v]);
        return t;
    };
    PII ans=dfs(0);
    if(ans.first<0) cout<<"IMPOSSIBLE"<<endl;
    else cout<<"POSSIBLE"<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < (ll)V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path; vl A; vl dp; vl Ans;
//***********//
int main() {
	cin >> K;
	vl A(K);
	for (i = 0; i < K; i++) cin >> A[i];
	reverse(A.begin(), A.end());
	ll ans1 = 2;
	ll ans2 = 2;
	for (i = 0; i < K; i++) {
		if (A[i] > ans2) {
			cout << -1;
			exit(0);
		}
		else if (ans1 < A[i]) ans1 = A[i];
		ans1 = (ans1 + A[i] - 1) / A[i] * A[i];
		ans2 = ans2 - ans2 % A[i] + A[i] - 1;
	}
	if (ans1 > ans2) {
		cout << -1;
		exit(0);
	}
	cout << ans1 << " " << ans2;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	HashMap<String, Boolean> hash = new HashMap<String, Boolean>();
	boolean check(String s) {
		if (s.isEmpty()) return true;
		if (hash.containsKey(s)) return hash.get(s);
		int len = s.length();
		if (s.charAt(0) != 'm' || s.charAt(len-1) != 'w') {
			hash.put(s, false);
			return false;
		}

		for (int i = 1; i < len - 1; i++) {
			if (s.charAt(i) == 'e') {
				if (check(s.substring(1, i)) && check(s.substring(i+1, len - 1))) {
					hash.put(s, true);
					return true;
				}
			}
		}
		
		hash.put(s, false);
		return false;
	}
	
	public void run() {
		String s = in.next();
		System.out.println(check(s) ? "Cat" : "Rabbit");
		out.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

Measured memory_bytes: 47976
n,a=int(input()),list(map(int,input().split()));b=[0]
for i in range(n):b.append(b[i]+a[i])
b.sort();c=1;ans=0
for i in range(n):
  if b[i]==b[i+1]:c+=1
  else:
    if c>=2:ans+=(c*(c-1))//2
    c=1
if c>=2:ans+=(c*(c-1))//2
print(ans)

Measured memory_bytes: 26720
//B - Increment Decrement:
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, ans, num;
    string s;
    cin >> n;
    cin >> s;
    ans = num = 0;
    loop(i, 0, s.size()) {
        if(s[i] == 'I') num++;
        else num--;
        ans = max(ans, num); 
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
mod=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=0
 
for i in range(60):
  x=0
  for j in range(N):
    if A[j]>>i&1: x+=1
  ans+=x*(N-x)*(2**i)
print(ans%mod)

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

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

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    vector<vector<vector<ll>>> dp(n,vector<vector<ll>>(2, vector<ll>(2, -1e9)));
    dp.at(0).at(1).at(1) = a.at(0); 
    dp.at(0).at(0).at(1) = 0;
    dp.at(0).at(0).at(0) = 0;

    dp.at(1).at(1).at(1) = a.at(1);
    dp.at(1).at(1).at(0) = a.at(0);
    dp.at(1).at(0).at(0) = 0;
    for(i = 2;i < n;++i){
        j = i+1;
        if(j%2 == 0){
            dp.at(i).at(1).at(1) = dp.at(i-1).at(0).at(0) + a.at(i);
            dp.at(i).at(1).at(0) = dp.at(i-1).at(1).at(1);
            dp.at(i).at(0).at(0) = max(dp.at(i-1).at(0).at(1), dp.at(i-1).at(0).at(0)); 
        }else if(j%2 == 1){
            dp.at(i).at(1).at(1) = dp.at(i-1).at(1).at(0) + a.at(i);
            dp.at(i).at(0).at(1) = dp.at(i-1).at(0).at(0) + a.at(i);
            dp.at(i).at(0).at(0) = max(dp.at(i-1).at(1).at(1), dp.at(i-1).at(1).at(0)); 
        }
    }
    if(n%2 == 0){
        cout << max(dp.at(n-1).at(1).at(1), dp.at(n-1).at(1).at(0)) << endl;
    }else{
        cout << max(dp.at(n-1).at(0).at(1), dp.at(n-1).at(0).at(0)) << endl;
    }
    return 0;
}

Measured memory_bytes: 34420
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int long long
#define ll long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
 
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int32_t main()
{
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    ll n,x;
    cin>>n>>x;
    vl v(n);
    vl a(n);
    ll ans=0;
    for(int i=0;i<n;i++)
    {
    	cin>>v[i];
    	a[i]=v[i];
    	ans+=v[i];
    }
    for(int j=1;j<n;j++)
    {
    	ll lans=0;
    	for(int i=0;i<n;i++)
    	{
    		a[i]=min(a[i],v[(i-j+n)%n]);
    		lans+=a[i];
    		//trace3(v[i],v[(i-j+n)%n],a[i]);
    		
    	}
    	lans+=x*j;
    	ans=min(ans,lans);
    }
    cout<<ans;

    
    return 0;
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30

int main()
{
    int N;
    cin >> N;
    vector<int> X(N);
    REP(i,N)cin >> X[i];
    int minP = INF;
    sort(X.begin(),X.end());
    int m = X[0];
    int M = X[N-1];
    FOR(i,m,M+1){
        int P = 0;
        REP(j,N){
            P += pow(X[j]-i,2);
        }
        if(P<minP)minP = P;
    }
    cout << minP << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

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

// __attribute__((constructor)) void initial() {
// cin.tie(nullptr);
// ios::sync_with_stdio(false);
//   cout << fixed << setprecision(15);
// }


signed main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);

  vector<int> A(M), B(M);
  rep(i, M) {
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;
    G[A[i]].pb(B[i]);
  }

  int sz = INF;
  vector<int> ans;

  rep(i, M) {
    int s = B[i], g = A[i];
    vector<int> dist(N, -1);
    vector<int> back(N, -1);
    back[s] = g;
    dist[s] = 0;

    queue<int> q;
    q.push(s);


    while (!q.empty()) {
      int now = q.front();
      q.pop();

      for (auto next : G[now]) {
        if (dist[next] != -1)
          continue;
        dist[next] = dist[now] + 1;
        q.push(next);
        back[next] = now;
      }
    }

    if (dist[g] == -1)
      continue;

    int temp = dist[g] + 1;
    if (chmin(sz, temp)) {
      ans.clear();
      rep(j, temp) {
        ans.pb(g);
        g = back[g];
      }
    }
  }

  if (sz == INF) {
    cout << -1 << '\n';
    return 0;
  }

  cout << sz << "\n";
  rep(i, len(ans)) {
    cout << (ans[i] + 1) << "\n";
  }
}

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

using namespace std;
#define MOD 998244353
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

long long mult(long long a, long long b) {
	a = (a % MOD * b % MOD) % MOD;
	return a;
}
long long add(long long a, long long b) {
	a += b;
	if (a >= MOD) a %= MOD;
	return a;
}

int main() {

	int a, b, c, d; cin >> a >> b >> c >> d;
	vector<vector<long long>> dp(c + 1, vector<long long>(d + 1, 0));

	dp[a][b] = 1;
	for (int j = b + 1; j <= d; j++)  dp[a][j] = mult(dp[a][j - 1] , a);
	for (int i = a + 1; i <= c; i++)  dp[i][b] = mult(dp[i - 1][b] , b);

	for (int i = a + 1; i <= c; i++) {
		for (int j = b + 1; j <= d; j++) dp[i][j] = (add(mult(dp[i][j - 1] , i) , mult(dp[i - 1][j] , j))
												        - mult(dp[i - 1][j - 1] , (i - 1) * (j - 1)) + MOD) % MOD;
	}

	cout << dp[c][d];


	return 0;
}

Measured memory_bytes: 73672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		Classifier cf = new Classifier();
		
		while(true){
			String str = br.readLine();
			
			if(str == null){
				break;
			}
			
			double input = Double.parseDouble(str);
			System.out.println(cf.className(input));
		}

	}

}

class Classifier {
	String[] classNames = {
			"light fly",
			"fly",
			"bantam",
			"feather",
			"light",
			"light welter",
			"welter",
			"light middle",
			"middle",
			"light heavy",
			"heavy"
	};
	
	double[] border = {0,48,51,54,57,60,64,69,75,81,91};
	
	String className(double w){
		for(int i = 0; i < border.length - 1 ; i++){
			if(w > border[i] && w <= border[i + 1]){
				return classNames[i];
			}
		}
		
		return classNames[classNames.length - 1];
	}
	
}

Measured memory_bytes: 24232
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
struct edge{int to,cost;};
vector<int> es[114];
signed main(){
    int a,b,c;cin>>a>>b>>c;
    if(a==b&&a==c){
        if(a%2)cout<<0<<endl;
        else cout<<-1<<endl;
        return 0;
    }
    int count=0;
    while(a%2==0&&b%2==0&&c%2==0){
        int d=a/2,e=b/2,f=c/2;
        a=e+f,b=d+f,c=d+e;
        count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, k;
    cin>>n>>k;
    double p[200020];
    for(int i=0; i<n; i++){
        cin>>p[i];
        p[i]=(p[i]+1)/2.0;
    }
    double s[200020];
    s[0]=0;
    for(int i=0; i<n; i++) s[i+1]=s[i]+p[i];
    double ans=0;
    for(int i=0; i<=n-k; i++){
        ans=max(ans, s[i+k]-s[i]);
    }
    printf("%.7lf\n", ans);
    return 0;
}


Measured memory_bytes: 3328
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let a: usize = sc.cin();
    let b: usize = sc.cin();
    for x in 1..100000 {
        if x * 8 / 100 == a
            && x * 10 / 100 == b {
                put!(x);
                return;
        }
    }
    put!(-1);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


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

using namespace std;

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

#define int ll


main(){
	int num[100]={0};

	int n,k;
	cin >> n >> k;
	for(int i=0;i<k;i++){
		int d;
		cin >> d;
		for(int j=0;j<d;j++){
			int a;
			cin >> a;
			num[a-1]++;
		}
	}

	int ans = 0;
	for(int i=0;i<n;i++){
		if(num[i]==0) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n;
    cin >> n;
    auto tmp = n;
    map<int, int> cnt;
    for (int i = 2; i * i <= n; ++i) {
        int res = 0;
        while (tmp % i == 0) {
            ++res;
            tmp /= i;
        }
        if (res != 0) cnt[i] = res;
    }

    if (tmp != 1) cnt[tmp] = 1;

    int ans = 0;
    each(val, cnt) {
        int res = sqrt(val.second * 2);
        if (val.second * 2 < res * (res + 1)) --res;
        if (res > 0)
            ans += res;
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

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

int main() {
  double Ans = 0;  // 回答：
  int R; cin >> R;  // 半径

//  cout << Ans << setprecision(7);	// 計算前に桁数指定
//  Ans = R * 2 * 3.1415926;
  Ans = R * 2 * 3141159;
  Ans /= 1000000;
  cout << Ans << endl;
}


Measured memory_bytes: 3784
import java.util.Arrays;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int k = sc.nextInt();
		long h[] = new long[n];
		long sum = 0;
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextLong();
		}
		Arrays.sort(h);

		for(int i = 0; i < h.length - k; i++) {
			sum += h[i];
		}

		System.out.println(sum);

		sc.close();
	}
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

typedef pair<ll, ii> iii;

const int lim = 5000, MX = lim;
int n, m, s, to[MX], a[MX], b[MX], c[MX], d[MX];
ll dis[105][lim], res[105];
vi adj[MX];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> m >> s;

	forn (i, m) {
		int u, v, x, y;
		cin >> u >> v >> x >> y;

		adj[u].pb(2 * i);
		to[2 * i] = v;
		a[2 * i] = x;
		b[2 * i] = y;

		adj[v].pb(2 * i + 1);
		to[2 * i + 1] = u;
		a[2 * i + 1] = x;
		b[2 * i + 1] = y;
	}

	for (int i = 1; i <= n; i++)
		cin >> c[i] >> d[i];

	priority_queue<iii, vector<iii>, greater<iii>> pq;
	memset(dis, -1, sizeof(dis));
	memset(res, -1, sizeof(res));
	pq.emplace(0, ii(1, min(s, lim)));
	dis[1][min(s, lim)] = 0;

	while (pq.size()) {
		auto top = pq.top();
		pq.pop();

		int u = top.se.fi;
		int t = top.se.se;
		ll w = top.fi;

		if (dis[u][t] < w) continue;
		if (res[u] == -1) {
			res[u] = w;
		}

		int k = min(t + c[u], lim);
		if (dis[u][k] == -1 || dis[u][k] > w + d[u]) {
			dis[u][k] = w + d[u];
			pq.emplace(w + d[u], ii(u, k));
		}

		for (int i : adj[u]) {
			int v = to[i];
			if (t - a[i] < 0) continue;

			if (dis[v][t - a[i]] == -1 || dis[v][t - a[i]] > w + b[i]) {
				dis[v][t - a[i]] = w + b[i];
				pq.emplace(w + b[i], ii(v, t - a[i]));
			}
		}
	}

	for (int i = 2; i <= n; i++)
		cout << res[i] << endl;

	return 0;
}


Measured memory_bytes: 11628
# 猫のすぬけ君の提出コピペ（少し修正）
# 後で書き換える

import sys
input = sys.stdin.readline


def make_cnt(a):
    cnt_ = {}
    for i in range(n):
        if a[i] not in cnt_:
            cnt_[a[i]] = [i]
        else:
            cnt_[a[i]].append(i)
    return cnt_


def get_any(cnt_, x):
    for key in cnt_.keys():
        if key != x:
            return key
    assert False


def update_cnt(cnt_, x):
    cnt_[x].pop()
    if len(cnt_[x]) == 0:
        del cnt_[x]


def use(x):
    q[cnt[x]].remove(x)
    cnt[x] -= 1
    q[cnt[x]].add(x)


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

cnt = [0] * (n + 1)
for x in a + b:
    cnt[x] += 1

q = [set() for i in range(n + 1)]
for i in range(1, n + 1):
    if cnt[i] > n:
        print("No")
        exit(0)
    q[cnt[i]].add(i)

print("Yes")

cnt_a = make_cnt(a)
cnt_b = make_cnt(b)

ans = [-1] * n

# 個数がiの数字が何種類あるかで場合分け
# 0,1,2種類の計3通り
for i in range(n, 0, -1):
    s = list(q[i])
    x, y = 0, 0
    # 0種類
    if len(s) == 0:
        x = get_any(cnt_a, -1)
        y = get_any(cnt_b, x)
    # 1種類
    elif len(s) == 1:
        x = s[0]
        if x not in cnt_a:  # bから
            y = x
            x = get_any(cnt_a, y)
        else:  # aから
            y = get_any(cnt_b, x)
    # ２種類
    else:
        x, y = s
        if x not in cnt_a:
            x, y = y, x

    ans[cnt_a[x][-1]] = y
    update_cnt(cnt_a, x)
    update_cnt(cnt_b, y)
    use(x)
    use(y)

print(*ans)


Measured memory_bytes: 192368
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

//#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



int main() {
	int n,a,t=0,ans=2000000000;
	cin >> n;
	vector<int>vec(n);
	rep(i, n) {
		cin >> a;
		t += a;
		vec[i] = t;
	}
	rep(i, n) {
		ans = min(ans, max(t - vec[i] * 2, vec[i] * 2 - t));
	}
	cout << ans << endl;
}


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

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  if(a>b) cout << 0 << endl;
  else{
    if(n<2&&a!=b){
      cout << 0 << endl;
      return 0;
    }
    ll min_sum=a+a*(n-2)+b;
    ll max_sum=a+b*(n-2)+b;
    cout << max_sum-min_sum+1 << endl;
    return 0;
  }
}

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

int main() {
  string c;
  cin >> c;
  if((c=="a")||(c=="i")||(c=="u")||(c=="e")||(c=="o")){
    cout << "vowel" << endl;
}
  else {
  cout << "consonant" << endl;
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};

int main(){
  ll n;
  cin >> n;
  ll a[n],b[n+1];
  for(ll i=0;i<n+1;i++)b[i]=0;
  for(ll i=0;i<n-1;i++){
    cin >> a[i];
    b[a[i]]++;
  }
  for(ll i=1;i<=n;i++){
    cout << b[i] << endl;
  }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    int64_t ans = 0;
    rep(i,n) {
        int64_t d = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        int64_t u = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += d * u;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 10010010010
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;


int n;

int calc(int n){
    int count = 0;
    while (n) {
        n /= 10;
        count++;
    }
    return count;
}



int main(){
    cin >> n;
    
    int ans = 0;
    for(int i=1; i<=n; i++){
        if(calc(i)%2 == 1){
            ans++;
        }


    }
    cout << ans << endl;
    




}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> Pi;

int main(){
  int n;
  while(cin >> n , n){
    Pi match[10];
    string team[10];
    for(int i=0;i<n;i++){
      cin >> team[i];
      match[i].first.first = 0; match[i].first.second = 0;
      match[i].second = i;
      for(int j=0;j<n-1;j++){
	int a; cin >> a;
	if(a == 0) match[i].first.first--;
	else if(a == 1) match[i].first.second++;
    }
    }
    sort(match,match+n);
    for(int i=0;i<n;i++){
      cout << team[match[i].second] << endl;
    }
  }
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 500010;
const int SZ = 1 << 19;

struct segtree_max {
	vector<pii> dat;

	void init() {
		dat.resize(SZ * 2);
		rep(i, SZ * 2) dat[i] = mp(INT_MIN, -1);
	}

	void update(int pos, int x) {
		pos += SZ - 1;
		dat[pos] = mp(x, pos - (SZ - 1));

		while (pos > 0) {
			pos = (pos - 1) / 2;
			dat[pos] = max(dat[pos * 2 + 1], dat[pos * 2 + 2]);
		}
	}

	pii get(int a, int b, int k = 0, int l = 0, int r = SZ) {
		if (b <= l || r <= a) return mp(INT_MIN, -1);
		if (a <= l && r <= b) return dat[k];
		return max(get(a, b, k * 2 + 1, l, (l + r) / 2), get(a, b, k * 2 + 2, (l + r) / 2, r));
	}
} seg;

int N, K;
int P[MN], Q[MN];
vi g[MN];
int in[MN];

int main() {
	scanf("%d %d", &N, &K);

	rep(i, N) {
		scanf("%d", &P[i]);
		--P[i];
		Q[P[i]] = i;
	}

	seg.init();

	rep(i, N) {
		int p = Q[i];

		pii r = seg.get(p, min(N, p + K));
		pii l = seg.get(max(0, p + 1 - K), p);

		if (r.fi != INT_MIN) {
			++in[p];
			g[r.se].pb(p);
		}

		if (l.fi != INT_MIN) {
			++in[p];
			g[l.se].pb(p);
		}

		seg.update(p, i);
	}

	priority_queue<int, vi, greater<int>> que;

	rep(i, N) {
		if (in[i] == 0) {
			que.push(i);
		}
	}

	vi res(N), ans(N);
	int now = 0;

	while (!que.empty()) {
		int v = que.top(); que.pop();
		res[now++] = v;

		for (int to : g[v]) {
			if (--in[to] == 0) {
				que.push(to);
			}
		}
	}

	rep(i, N) ans[res[i]] = i;

	rep(i, N) printf("%d\n", ans[i] + 1);

	return 0;
}

Measured memory_bytes: 49408
import numpy as np

n = int(input())

a = input().split(' ')

a = np.array(a).astype(int)


while a[a>0].shape[0] > 1:
  not_0_a = a[a!=0]
  min_ = not_0_a.min()#0じゃない最小値
  min_i = np.where(a == min_)#最小値のインデックス
  a = a % min_
  a[min_i[0][0]] = min_

  """
  if a[a>0].shape[0] == 1:
    not_0_a = a[a!=0]
    min_ = not_0_a.min()
  """
  
print(min_)

Measured memory_bytes: 27424
N = int(input())
H = list(map(int, input().split()))

ans = 0

count = 0
for i in range(N-1):
    if (H[N-1-i] <= H[N-2-i]):
        count += 1
        if i == N-2:
            ans = max(ans, count)

    else:
        ans = max(ans, count)
        count = 0

print(ans)

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

int h, w, n;
bool flg[32][32];
char t[32][32], tt[32][32];

void copy(char to[32][32], char from[32][32]){
  for(int i = 0; i < 32; i++){
    for(int j = 0; j < 32; j++){
      to[i][j] = from[i][j];
    }
  }
}

void show(){
  cout << "====\n";
  for(int i = 0; i < h; i++){
    cout << t[i] << endl;
  }
  cout << "====\n\n";
}

void fallBlock(){
  for(int i = h - 1; i >= 0; i--){
    for(int j = 0; j < w; j++){
      if(t[i][j] == '.'){
        int k = i;

        for( ; 0 <= k && t[k][j] == '.'; k--);

        if(k != -1){
          t[i][j] = t[k][j];
          t[k][j] = '.';
        }
      }
    }
  }
}

bool delBlock(){
  bool res = false;

  memset(flg, 0, sizeof(flg));

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(t[i][j] == '.') continue;

      if(i + n <= h){
        int k = i;
        for( ; k < h && t[k][j] == t[i][j]; k++);
        if(n <= k - i){
          for(k--; k >= i; k--) flg[k][j] = true;
          res = true;
        }
      }
      if(j + n <= w){
        int k = j;
        for( ; k < w && t[i][k] == t[i][j]; k++);
        if(n <= k - j){
          for(k--; k >= j; k--) flg[i][k] = true;
          res = true;
        }
      }
    }
  }

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(flg[i][j]){
        t[i][j] = '.';
      }
    }
  }

  return res;
}

bool checkDelAll(){
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(t[i][j] != '.'){
        return false;
      }
    }
  }
  return true;
}

bool solve(){
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w - 1; j++){
      copy(t, tt);
      if(t[i][j] == '.' && t[i][j + 1] == '.') continue;
      swap(t[i][j], t[i][j + 1]);
      fallBlock();

      while(true){
        bool delFlg = delBlock();
        if(!delFlg) break;
        fallBlock();
      }

      if(checkDelAll()) return true;
    }
  }

  return false;
}

int main(){
  while(cin >> h >> w >> n){
    for(int i = 0; i < h; i++){
      cin >> tt[i];
    }
    cout << (solve() ? "YES" : "NO") << endl;
  }
}

Measured memory_bytes: 0
s=input()
if(s=="SUN"):
  print(7)
if(s=="MON"):
  print(6)
if(s=="TUE"):
  print(5)
if(s=="WED"):
  print(4)
if(s=="THU"):
  print(3)
if(s=="FRI"):
  print(2)
if(s=="SAT"):
  print(1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>//万能头文件
using namespace std;
char a[10001];
bool f=false;
int main()
{
    cin>>a;
    int l=strlen(a);
    for(int i=0;i<=l-1;i++){
        if(a[i]=='C'){
            for(int j=i;j<=l-1;j++){
                if(a[j]=='F')f=true;
            }
        }
    }
    if(f==true)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from collections import deque as deq

An, Bn, Mn = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = [list(map(int, input().split())) for i in range(Mn)]

mia = 10**5 + 10**5
for a in A:
    mia = a if a < mia else mia

mib = 10**5 + 10**5
for b in B:
    mib = b if b < mib else mib

R = mia + mib
for m in M:
    c = A[m[0] - 1] + B[m[1] - 1] - m[2]
    R = c if c < R else R

print(R)


Measured memory_bytes: 38820
#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
	int h, w;
	scanf("%d %d", &h, &w);
	
	ll c[10][10];
	for(int i=0; i<100; i++) scanf("%ld", &c[i/10][i%10]);
	for(int k=0; k<10; k++) for(int i=0; i<10; i++) for(int j=0; j<10; j++){
		c[i][j] = std::min(c[i][j], c[i][k]+c[k][j]);
	}

	ll ans = 0;
	for(int i=0; i<h*w; i++){
		int x;
		scanf("%d", &x);
		if(x>=0) ans += c[x][1];
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int gr[MAXN];
int mark[MAXN];
vector<int> G[MAXN];

void dfs(int node, int par){
	for (int v:G[node]) if (v!=par){
		dfs(v, node);
		gr[node]^=gr[v]+1;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<n; i++){
		cin>>u>>v;
		G[u].pb(v);
		G[v].pb(u);
	}
	dfs(1, 1);
	
	if (gr[1]) kill("Alice")
	kill("Bob")
	
	return 0;
}


Measured memory_bytes: 13952