akhauriyash/Code-Regression huggingface dataset:
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, Y);
    REP(x, N + 1)
    {
        REP(y, N + 1)
        {
            ll z = (Y - 10000 * x - 5000 * y) / 1000;
            if (x + y + z == N and z >= 0)
            {
                vi ans = vi({x, y, z});
                JOUT(ALL(ans)) << endl;
                return 0;
            }
        }
    }
    OUT("-1 -1 -1");
}

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

using namespace std;

int main(){

    int N,M,X;
    cin >> N >> M >> X;
    int A[110];
    for (int &i : A) i = 0;
    for (int i = 0 ; i < M ; i ++){
        int buf;
        cin >> buf;
        A[buf] = 1;
    }

    int zsum = 0;
    for(int zi = 0 ; zi < X ; zi ++){
        zsum += A[zi];
    }

    int nsum = 0;
    for(int ni = X ; ni < N ; ni ++){
        nsum += A[ni];
    }

    cout << min(zsum , nsum) << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n,alice=0,bob=0;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    for(int i=0;i<n;i++){
        if(i%2 == 0) alice += a[i];
        if(i%2 == 1) bob += a[i];
    }
    cout << alice - bob << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const int MAXN = 2e5 + 1;
const ll INF = 1e18;
const ld pi = acos(-1);

ll x, y, ans = INF;

int main() {

    faster();

    cin >> x >> y;

    if(x <= y){
        ans = min(ans, y - x);
    }
    if(x <= -y){
        ans = min(ans, - y - x + 1);
    }
    if(-x <= -y){
        ans = min(ans, - y + x + 2);
    }
    if(-x <= y){
        ans = min(ans, y + x + 1);
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	int x;
	int ans;
	
	public void shori(){
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		ans = x*x*x;
		System.out.println(ans);
		sc.close();
	}
	public static void main(String[] args){
		Main obj =  new Main();
		obj.shori();
	}
}

Measured memory_bytes: 17360
using System;

public class ABC162_B {
	private static void Main(string[] args) {
		var n = ReadInt();
		long answer = 0;

		for (int i = 1; i <= n; i++)
			if (i % 3 != 0 && i % 5 != 0)
				answer += i;

		Console.WriteLine(answer);
	}

	private static int ReadInt() => int.Parse(Console.ReadLine().Trim());
}

Measured memory_bytes: 27540
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = (N - a * 1000) / 100;
  c = (N - a * 1000 - b * 100) / 10;
  d = N - a * 1000 - b * 100 - c * 10;
  if(a == b && b == c){
    cout << "Yes" << endl;
  }else if(b == c && c == d){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N,M,K = gets.chomp.split.map(&:to_i)
a = 1
for i in 0..N
   for j in 0..M
      if (i*M + j*N - i * j * 2) == K then
           print "Yes"
           a = 0
           break
      end
   end
   if a == 0 then
      break
   end
end
if a == 1
   print "No"
end

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

void swap(int *a,int *b){
    int tmp=0;
    tmp=*a;
    *a=*b;
    *b=tmp;
}

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

    if(b<a) swap(a,b);
    if(c<a) swap(a,c);
    if(c<b) swap(b,c);
    
    cout << a << " " << b << " " << c <<endl;
        
    return 0;
}


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

const long H = 1000000000;
const long W = 1000000000;
const long N = 100000;

long cnt[10] = {};

long a[N + 10] = {};
long b[N + 10] = {};

long h, w, n;

bool eexists(long x, long y)
{
  if (x <= 0 || y <= 0 || x > w - 2 || y > h - 2)
  {
    return false;
  }

  return true;
}

int main()
{
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i] >> b[i];
  }
  // cnt[0] = (h - 2) * (w - 2);
  // input

  vector<pair<long, long>> v;

  for (int i = 0; i < n; i++)
  {
    // y
    for (int j = -2; j <= 0; j++)
    {
      // x
      for (int k = -2; k <= 0; k++)
      {
        long x = b[i] + j;
        long y = a[i] + k;
        if (eexists(x, y))
        {
          pair<long, long> t(x, y);
          v.push_back(t);
        }
      }
    }
  }
  sort(v.begin(), v.end());
  /*
  cout << "=======" << endl;
  for (auto itr = v.begin(); itr != v.end(); ++itr)
  {
    cout << (*itr).first << " " << (*itr).second << endl;
  }
  cout << "======" << endl;
*/
  if (n != 0)
  {
    int c = 1;
    pair<long, long> same = *(v.begin());
    for (auto itr = v.begin() + 1; itr != v.end(); ++itr)
    {
      if (same == *itr)
      {
        c++;
      }
      else
      {
        cnt[c]++;
        same = *itr;
        c = 1;
      }
    }
    cnt[c]++;
  }

  long sum = 0;
  for (int i = 1; i < 10; i++)
  {
    sum += cnt[i];
  }
  cnt[0] = (h - 2) * (w - 2) - sum;

  for (int i = 0; i < 10; i++)
  {
    cout << cnt[i] << endl;
  }
}

Measured memory_bytes: 20328
#include<bits/stdc++.h>
using namespace std;
int n,c,k;
long long t[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>c>>k;
	for(int i=1;i<=n;i++)
		cin>>t[i];
	sort(t+1,t+n+1);
	int res=0;
	for(int beg=1;beg<=n;beg=beg){
		long long ed=t[beg]+k;
		int i;
		for(i=beg;t[i]<=ed&&i-beg+1<=c&&i<=n;i++){
			ed+=0;
		}
		i--;
		beg=i+1;
		res++;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int N;
  ll A, B;
  while (scanf("%d%lld%lld", &N, &A, &B) != EOF) {
    vector<ll> x(N);
    for (int i : range(N)) scanf("%lld", &x[i]);

    ll ret = 0;
    for (int i : range(1, N)) {
      ret += min(B, A * (x[i] - x[i - 1]));
    }
    printf("%lld\n", ret);
  }
}


Measured memory_bytes: 1024
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c=[]
d,p=0,a[0]
for x in a:
  if p==x:
    d+=1
  else:
    c.append(d)
    d=1
    p=x
c.append(d)
c.sort(reverse=1)
k=min(k,len(c))
print(sum(c[k:]))

Measured memory_bytes: 86992
//15
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int d,n,m;cin>>d>>n>>m,d;){
    int sh[100001]={};
    for(int i=1;i<n;i++){
      cin>>sh[i];
    }
    sh[n]=d;
    sort(sh,sh+n+1);
    int ans=0;
    for(int i=0;i<m;i++){
      int k;
      cin>>k;
      int x=upper_bound(sh,sh+n+1,k)-sh;
      ans+=min(sh[x]-k,k-sh[x-1]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1568
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cout << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cout << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	ll N = in();
	ll A = in();
	ll B = in();
	vint h(N);
	rep(i,N) h[i] = in();
	sort(h.begin(), h.end());
	
	ll left = 0;
	ll right = INF;
	// (left, right]
	while (right - left >= 2) {
		ll mid = (left + right) / 2;
		ll least = mid * B;
		ll times = 0;
		for (int i = N - 1; i >= 0; i--) {
			if (h[i] <= least) break;
			ll res = h[i] - least;
			times += (res + A - B - 1) / (A - B);
		}
		if (times <= mid) right = mid;
		else left = mid;
	}
	cout << right << endl;
	return 0;
}


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

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r)
{
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

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

template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T>
ostream &operator<<(ostream &out, multiset<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << "\n" << (i->first) <<  ":"  << (i->second);
    return out;
}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll

int solve() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];

    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    for (int i = 1; i < n; i++) {
        a[i] += a[i - 1];
    }
    int anss = 0;
    for (int i = 1; i < m; i++) {
        b[i] += b[i - 1];
        if (b[i] <= k) {
            anss = i + 1;
        }
    }
    for (int i = 0; i < n; i++) {
        int curr = a[i];
        int rem = k - curr;
        if (rem < 0) continue;
        int l = 0, r = m - 1;
        int mid, ans = 0;
        while (l <= r) {
            mid = (l + r) / 2;
            // tr(rem, b[i]);
            if (b[mid] <= rem) {
                ans = mid + 1;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        // tr(i, ans);
        anss = max(anss, i + 1 + ans);
    }
    cout << anss << endl;
    return 0;
}

int32_t main(){ _
    int t;
    // cin >> t;
    t = 1;
    while (t--) solve();
    return EXIT_SUCCESS;	
}


Measured memory_bytes: 6368
num = int(input())

EPS = 0.00000000001

for _ in range(num):
    x1, y1, x2, y2, x3, y3, x4, y4 = [float(x) for x in input().split()]
    
    abx = x2 - x1
    aby = y2 - y1
    cdx = x4 - x3
    cdy = y4 - y3
    # abx : aby = cdx : cdy
    # aby * cdx - abx * cdy = 0 ( < EPSilon)
    
    if abs(aby * cdx - abx * cdy) < EPS:
        print("YES")
    else:
        print("NO")
    



Measured memory_bytes: 5612
import math

a, b = input().split() # a = result * 0.08, b = result * 0.1
a, b = int(a), int(b)
 
result_a = int(math.ceil(a / 0.08))
result_b = int(math.ceil(b / 0.1))
 
if result_a < 0 or result_b < 0:
  print(-1)
elif result_a > result_b:
  c = int(result_a * 0.1)
  if b == c:
    print(result_a)
  else:
    print(-1)
else:
  c = int(result_b * 0.08)
  if a == c:
    print(result_b)
  else:
    print(-1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define MAXN 3000
#define MOD 1000000007

int N, dp[MAXN + 3][MAXN + 3], prefix[MAXN + 3][MAXN + 3];
string s;

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

    memset(dp, 0, sizeof(dp));
    memset(prefix, 0, sizeof(prefix));
    dp[1][1] = 1;
    for (int j = 1; j <= N; j++)
        prefix[1][j] = (prefix[1][j - 1] + dp[1][j])%MOD;

    for (int i = 2; i <= N; i++) {
        for (int j = 1; j <= i; j++) {
            if (s[i - 2] == '>')
                dp[i][j] = (prefix[i - 1][N] - prefix[i - 1][j - 1] + MOD)%MOD;
            else
                dp[i][j] = (prefix[i - 1][j - 1]);
        }

        for (int j = 1; j <= N; j++)
            prefix[i][j] = (prefix[i][j - 1] + dp[i][j])%MOD;
    }

    cout << prefix[N][N] << endl;
}


Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct ST_team {
public:
	int no;
	int score;
	int rank;
public:
	ST_team() { no = 0; score = 0; rank = 0; }
	ST_team(int n, int s) { no = n; score = s; rank = 0; }
};
typedef struct ST_team team;

bool desc_score(const ST_team& t1, const ST_team& t2) { return t1.score > t2.score; }
bool asc_no(const ST_team& t1, const ST_team& t2) { return t1.no < t2.no; }

int main()
{
	vector<team> t;
	char dummy;
	int no, score;
	
	while (true) {
		cin >> no >> dummy >> score;
		if (no == 0 && score == 0) break;
		team tmp_t(no, score);
		t.push_back( tmp_t );
	}
	
	sort(t.begin(), t.end(), desc_score);
	
	int curr_rank = 0;
	int curr_score = 100;
	for (vector<team>::iterator it = t.begin(); it != t.end(); it++) {
		if ( curr_score > (*it).score ) { curr_rank++; curr_score = (*it).score; }
		(*it).rank = curr_rank;
	}
	
	sort(t.begin(), t.end(), asc_no);
	
	//for (vector<team>::iterator it = t.begin(); it != t.end(); it++) cout << (*it).no << ":" << (*it).score << "," << (*it).rank << endl;
	
	int q;
	while (cin >> q) cout << t.at(q-1).rank << endl;
	
	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001

using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
const int INF=1e9;
const ll LINF=1e18;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
    int h,w;
    cin>>h>>w;
    vvi a(h+1,vi(w+1));
    vector<tuple<int,int,int,int>>ans;
    rep(i,h)rep(j,w)cin>>a[i][j];
    rep(i,h){
        rep(j,w){
            if(a[i][j]%2==1){
                if(i<h-1){
                    a[i][j]--;
                    a[i+1][j]++;
                    ans.emplace_back(i+1,j+1,i+2,j+1);
                }
                else if(j<w-1){
                    a[i][j]--;
                    a[i][j+1]++;
                    ans.emplace_back(i+1,j+1,i+1,j+2);
                }
            }
        }
    }
    cout<<ans.size()<<endl;
    rep(i,(int)ans.size()){
        int a,b,c,d;
        tie(a,b,c,d)=ans[i];
        cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
    }

    return 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s.size() == 2){
    cout << "1 1" << endl;
    return 0; 
  }
  s = s + "R";
  int n = s.size();
  vector<int> ans(n,0);
  int pos = 0;
  int index = 0;
  char now = 'R';
  while(index<n){
    if(now == s[index]){
      index++;
      continue;
    }
    if(now == 'R'){
      int num = index - pos + 1;
      ans[index] += (num + 1) / 2;
      ans[index-1] += num / 2;
      now = s[index+1];
      pos = index + 1;
      index = pos;
      continue;
    }
    if(now == 'L'){
      int num = index - pos - 1;
      ans[pos-2] += num / 2 + 1;
      ans[pos-1] += (num+1) / 2;
      now = s[index];
      pos = index;
      index = pos;
    }
  }
  rep(i,n-2) cout << ans[i] << " ";
  cout << ans[n-2] << endl;
}



Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000000;
int gcd(int a, int b)
{
    if (a < b)
        return gcd(b, a);
    if (a % b)
        return gcd(b, a % b);
    return b;
}
int main()
{
    char c;
    cin >> c;
    if (c == 'A')
        cout << 'T';
    if (c == 'T')
        cout << 'A';
    if (c == 'G')
        cout << 'C';
    if (c == 'C')
        cout << 'G';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

vll dijkstra(ll n, vector<vector<vll>> nx, ll start) {
  vll dist(n, inf);
  dist[start] = 0;

  priority_queue<vll, vector<vll>, greater<vll>> pq;
  for (ll i = 0; i < nx[start].size(); i++) {
    pq.push(nx[start][i]);
  }

  for (ll i = 0; i < n - 1; i++) {
    vll w = pq.top();
    pq.pop();
    dist[w[1]] = w[0];
    for (ll j = 0; j < nx[w[1]].size(); j++) {
      if (dist[nx[w[1]][j][1]] == inf) {
        pq.push({dist[w[1]] + nx[w[1]][j][0], nx[w[1]][j][1]});
      }
    }
  }
  return dist;
}

int main() {
  ll n;
  cin >> n;
  vector<vector<vll>> nx(n, vector<vll>(0));
  for (ll i = 0; i < n - 1; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    nx[a - 1].push_back({c, b - 1});
    nx[b - 1].push_back({c, a - 1});
  }
  ll q, k;
  cin >> q >> k;
  vll dist = dijkstra(n, nx, k - 1);
  for (ll i = 0; i < q; i++) {
    ll x, y;
    cin >> x >> y;
    cout << dist[x - 1] + dist[y - 1] << endl;
  }
}

Measured memory_bytes: 35760
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        string S;
        string d[4] = {"dream",
                       "dreamer",
                       "erase",
                       "eraser"};
        cin >> S;
        reverse(all(S));
        rep(i, 4) reverse(all(d[i]));

        bool can = true;
        for (int i = 0; i < S.size();)
        {
                bool can2 = false;
                rep(j, 4)
                {
                        string moji = d[j];
                        if (S.substr(i, moji.size()) == d[j])
                        {
                                can2 = true;
                                i += moji.size();
                        }
                }
                if (!can2)
                {
                        can = false;
                        break;
                }
        }
        if(can)
                cout << "YES" << endl;
        else
                cout << "NO" << endl;


        return 0;
}


Measured memory_bytes: 512
def clear_maze(sx, sy, maze):

    INF=-10**9
    global cnt
    cnt=0
    distance = [[INF for i in range(w+1)] for j in range(h+1)]
    #    distance = [[None]*field_x_length]*field_y_length

    def bfs():
        global cnt
        queue = []

        queue.insert(0, (sx, sy))

        distance[sx][sy] = 0

        while len(queue):
            x, y = queue.pop()

            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]


                if (0 <= nx and  0 <= ny  and maze[nx][ny] != '#' and distance[nx][ny] == INF):
                    queue.insert(0, (nx, ny))

                    distance[nx][ny] = distance[x][y] + 1
                    if cnt<distance[nx][ny]:
                        cnt=distance[nx][ny]
        return cnt
    return bfs()


h,w = map(int, input().split())
maze=[list(input()) for i in range(h)]
t=[[0]*w for i in range(h)]

for i in range(h):
    maze[i]=['#']+maze[i]+['#']
maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]]

ans=0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if maze[i][j] == '#':
            continue
        v = (clear_maze(i, j, maze))

        if ans <= v:
            ans = v
print(ans)

Measured memory_bytes: 44140
import math


def is_prime(n):
    global primes
    if n == 1:
        return False

    if n == 2:
        return True

    if n % 2 == 0:
        return False

    s = int(math.sqrt(n))
    for x in range(3, s + 1, 2):
        if n % x == 0:
            return False
    else:
        return True


N = int(input())
d = [int(input()) for _ in range(N)]
d.sort()
print([is_prime(x) for x in d].count(True))

Measured memory_bytes: 7948
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

int H, W;

void fill(vector<string>& s, vector<vector<char>>& ans, int h, int w) {
  ans[h][w] = '#';
  vector<int> hh, ww;
  if (h-1 >= 0) hh.push_back(h-1);
  hh.push_back(h);
  if (h+1 < H) hh.push_back(h+1);
  if (w-1 >= 0) ww.push_back(w-1);
  ww.push_back(w);
  if (w+1 < W) ww.push_back(w+1);
  for (int y : hh) {
    for (int x : ww) {
      if (y == h && x == w) continue;
      if (s[y][x] != '#') ans[y][x] += 1;
    }
  }
}

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

  cin >> H >> W;
  vector<string> s(H);
  rep(i, H) cin >> s[i];
  vector<vector<char>> ans(H, vector<char>(W, '0'));
  rep(h, H) rep(w, W) {
    if (s[h][w] == '#') fill(s, ans, h, w);
  }

  rep(i, H) {
    for (int j = 0; j < W; j++) {
      printf("%c", ans[i][j]);
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n, t = 0, h = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    char taro[128], hanako[128];
    scanf("%s %s", taro, hanako);
    int ind = 0;
    while(1){
      if(taro[ind] > hanako[ind]){
        t += 3;
        break;
      }
      else if(taro[ind] < hanako[ind]){
        h += 3;
        break;
      }
      else{
        ind++;
        if(taro[ind] == '\0' && hanako[ind] == '\0'){
          t++;
          h++;
          break;
        }
        else if(taro[ind] == '\0'){
          h += 3;
          break;
        }
        else if(hanako[ind] == '\0'){
          t += 3;
          break;
        }
      }
    }
  }
  printf("%d %d\n", t, h);
}



Measured memory_bytes: 2752
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    // R * r + G * g + B * b = N
    int ans = 0;
    for(int r = 0; r <= (N / R); r++) {
        int N2 = N - r * R;
        if (N2 < 0) continue;
        for(int g = 0; g <= (N2 / G); g++) {
            int N3 = N2 - g* G;
            if (N3 < 0) continue;
            if (N3 % B == 0) {
                ans += 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
  long long int N;
  cin >> N;
  long long int max=1;
  for (long long int i=1;i<=sqrt(N)+1;i++){
    if(N%i==0) max = i;
  }
  cout << max+N/max-2;
}


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

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

  string s, t;
  cin >> s>> t;

  int ans=t.size();
  rep(i, s.size()-t.size()+1){
    int cnt=0;
    string u=s.substr(i, t.size());
    rep(j, t.size())if(t[j]!=u[j])cnt++;
    if(ans>cnt)ans=cnt;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3656
// abc054b: Template Matching
#include <bits/stdc++.h>
using namespace std;
using vs = vector<string>;

#define rep(i,n) for(int i=0;i<(n);i++)
#define in(x) cin>>(x)
#define oute(x) cout<<(x)<<endl

bool page(int ox, int oy, vs &map, vs &man){
  int n=man.size();
  rep(y,n) if(map[oy+y].substr(ox,n) != man[y]) return false;
  return true;
}

int main(){
  int n, m; in(n); in(m);
  vs a(n), b(m);
  rep(i,n) in(a[i]);
  rep(i,m) in(b[i]);
  int on = n-m+1;
  rep(oy,on) rep(ox,on) if(page(ox,oy,a,b)){ oute("Yes"); return 0; }
  oute("No");
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
typedef long long ll;

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 (b<a) { a=b; return 1; } return 0; }

int main()
{
  int N;
  cin >> N;
  vector<string> S(N);
  vector<string> ans(N+N);
  for(int i=0; i<N; i++)
    cin >> S[i];

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


  // for(int i=0; i<N; i++)
  //cout << S[i]<< " ";
  //cout << endl;

  fill(ans.begin(), ans.end(), "zzzzzzzzzz");
	    
  int count=0;
  int j=0;
  int max = 0;
  for(int i=0; i<N-1; i++)
    {
      if(S[i]==S[i+1])
	{
	  count++;
	}
      else
	{
	  if(count>max)
	    {
	      j=0;
	      fill(ans.begin(), ans.end(), "zzzzzzzzzz");
	      ans[j++]=S[i];
	      max=count;
	    }
	  else if(count==max)
	    {
	      ans[j++]=S[i];
	    }
	  count=0;
	}
	 	
    }

  if(count>max)
    {
      j=0;
      fill(ans.begin(), ans.end(), "zzzzzzzzzz");
      ans[j++]=S[N-1];
      max=count;
    }
  else if(count==max)
    {
      ans[j++]=S[N-1];
    }
  
  

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

  for(int i=0; ans[i]!="zzzzzzzzzz" && i<N; i++)
    {
      cout << ans[i] << endl;
    }

  return 0;
}


//cout << setprecision(13);
//next_permutation(v.begin(), v.end());



Measured memory_bytes: 36096
import math
N = int(input())

lst = []

for _ in range(N):
    X, Y = map(int, input().split())
    lst.append([X, Y])

ans = 0
for X, Y in lst:
    for x, y in lst:
        ans += math.sqrt((X - x) ** 2 + (Y - y) ** 2)

ans *= math.factorial(N - 1)

print (ans / math.factorial(N))

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

int main() {
    int k, t;
    cin >> k >> t;
    int a[t];
    for (int i = 0; i < t; ++i) {
        cin >> a[i];
    }

    sort(a, a + t);

    cout << max(0, a[t - 1] - k + a[t - 1] - 1) << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

signed main() {
  int H, W; 
  cin >> H >> W;

  vector<string> s(H);
  REP(i, H) cin >> s[i];

  queue<pair<int, int>> q;
  q.push({0, 0});

  vector<vector<int>> dist(H, vector<int>(W, INF));
  dist[0][0] = 0;

  while(!q.empty()){
    int x = q.front().first;
    int y = q.front().second; q.pop();
    REP(i, 4){
      int xx = x+dx[i];
      int yy = y+dy[i];
      if(OUT(0, xx, H)) continue;
      if(OUT(0, yy, W)) continue;
      if(s[xx][yy] == '#') continue;
      int d = dist[x][y]+1;
      if(dist[xx][yy] <= d) continue;
      dist[xx][yy] = d;
      q.push({xx, yy});
    }
  }

  if(dist[H-1][W-1] == INF){
    cout << -1 << "\n";
    return 0;
  }

  int ans = H*W-dist[H-1][W-1]-1;
  REP(i, H) REP(j, W){
    if(s[i][j] == '#') ans--;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
#define pb push_back
#define ll long long
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int main() 
{
    fast_io();
    int n; cin >> n;
    string s; cin >> s;
    string a = "";
    for (int i = 0; i < n/2; ++i)
    	a += s[i];
    a += a;
    if (a == s)
    	cout << "Yes";
    else
    	cout << "No";
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
H = [int(x) for x in stdin.readline().rstrip().split()]
INF = float("inf")
dp = [INF]*N
dp[0] = 0
dp[1] = abs(H[0]-H[1])
for i in range(2,N):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i],dp[i-j]+abs(H[i]-H[i-j]))
print(dp[-1])

Measured memory_bytes: 55008
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define ull unsigned long long

int main(){
    char s[102]={},t[102]={};
    scanf("%s%s",s,t);
    printf("%s%s",t,s);
    return 0;
}



Measured memory_bytes: 128
n, pri = gets.split.map(&:to_i)
s = gets.chomp

ans = 0
if pri == 2 || pri == 5
    n.times do |i|
        ans += i + 1 if s[i].to_i % pri == 0
    end
else
    mod_10 = Array.new(n,1)
    (n-1).times {|i| mod_10[i+1] = mod_10[i] * 10 % pri}

    h = Hash.new(0)
    mod = 0
    (n-1).downto(0) do |i|
        mod = (mod + s[i].to_i * mod_10[n-1-i]) % pri
        ans += 1 if mod == 0
        ans += h[mod]
        h[mod] += 1
    end
end

puts ans

Measured memory_bytes: 6140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 string s;
 cin>>s;
 int n=s.size();
 int ans1=0,ans2=0;
 for(int i=0;i<n;i++) {
  if(i&1){
   if(s[i]=='0') ans1++;
   else ans2++; 
  }
  else{
   if(s[i]=='1') ans1++;
   else ans2++;
  }
 }
 cout<<min(ans1,ans2)<<endl;
 return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vii;
typedef long long ll;
typedef pair<int,int> pii;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
long long a,b;
long long GCD,LCM;
int main()
{
    while(~scanf("%lld %lld",&a,&b))
    {
        GCD=gcd(a,b);
        LCM=a/GCD*b;
        printf("%lld %lld\n",GCD,LCM);
    }
}



Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<string> vstr;
typedef long long int llint;



int main(void) {
	llint N, M, maxL, minR,ans;
	maxL = 0;
	minR = 1000000;
	cin >> N >> M;
	vint L(M), R(M);
	for (int i = 0; i < M; i++)cin >> L[i] >> R[i];

	for (int i = 0; i < M; i++){
		maxL = max(maxL, L[i]);
		minR = min(minR, R[i]);
	}
	if ((minR - maxL + 1) < 0)ans = 0;
	else ans = minR - maxL + 1;
	cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.Comparator;
        import java.util.Scanner;


public class Main {
    Scanner sc = new Scanner(System.in);
    int n;
    public void run(){
        n = sc.nextInt();
        solve();
    }
    public void solve(){
        int ans = 0;

        int t = n % 10;
        n = n / 10;
        if(t == 9) t = 1;
        else t = 9;
        ans += t;

        t = n % 10;
        n = n / 10;
        if(t == 9) t = 1;
        else t = 9;
        ans += t * 10;

        t = n;
        if(t == 9) t = 1;
        else t = 9;
        ans += t * 100;

        System.out.println(ans);

    }

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

    static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }
    static class Edge{
        int to, cost;
        public Edge(int a, int b){
            this.to = a;
            this.cost = b;
        }
    }
    class MyComparator implements Comparator {
        @Override
        public int compare (Object arg0, Object arg1) {
            int x = ((Pair)arg0).first;
            int y = ((Pair)arg1).first;

            if (x < y) {
                return 1;
            } else if (x > y) {
                return -1;
            } else{
                return 0;
            }
        }
    }
    static class UnionFind{
        int par[];
        int rank[];

        //n要素で初期化
        public UnionFind(int maxn){
            par = new int[maxn];
            rank = new int[maxn];

            for(int i = 0; i < maxn; i++){
                par[i] = i;
                rank[i] = 0;
            }
        }

        //木の根を求める
        int find(int x){
            if(par[x] == x){
                return x;
            }
            else {
                return par[x] = find(par[x]);
            }
        }

        // xとyの属する集合を併合
        void unite (int x, int y){
            x = find(x);
            y = find(y);
            if(x == y){
                return;
            }

            if(rank[x] < rank[y]){
                par[x] = y;
            }
            else{
                par[y] = x;
                if(rank[x] == rank[y]) rank[x]++;
            }
        }

        // xとyが同じ集合に属するか否か
        boolean same(int x, int y){
            return find(x) == find(y);
        }
    }

}

Measured memory_bytes: 23764
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int n,x[16],y[16],d[16],D[16],p[16];
ll ans[16];
int main() {
#ifdef LOCAL
    freopen("in1.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif

    memset(ans , 0x3f , sizeof(ans));
    cin >> n;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i]>>p[i];
    }

    for(int i=0;i<n;i++){
        D[i] = min(abs(x[i]) , abs(y[i]));
    }
    ans[0] = 0;
    for(int i=0;i<n;i++){
        ans[0] += (ll)D[i]*p[i];
    }
    for(int i=1;i<(1<<n);i++){
        int j = i;
        do{
            memcpy(d,D,sizeof(D));
            for(int k=0;k<n;k++){
                if(i>>k&1){
                    if(j>>k&1){
                        for(int q=0;q<n;q++){
                            d[q] = min(d[q] , abs(x[q] - x[k]));
                        }
                    }
                    else{
                        for(int q=0;q<n;q++){
                            d[q] = min(d[q] , abs(y[q] - y[k]));
                        }
                    }
                }
            }
            ll tmp = 0;
            for(int i=0;i<n;i++) tmp += (ll)d[i] * p[i];
            ans[__builtin_popcount(i)] = min(ans[__builtin_popcount(i)] , tmp);
            j = (j-1) & i;
        }while(j != i);
    }
    for(int i=0;i<=n;i++) cout<<ans[i]<<endl;
    return 0;
}









Measured memory_bytes: 3644
/**
 * A - Rounding
 * https://atcoder.jp/contests/abc130/tasks/abc130_a
 **/
#include<iostream>

using namespace std;

int X, A;

int main() {
    cin >> X >> A;
    if (X < A) {
        cout << 0 << endl;
    } else {
        cout << 10 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,ll> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RREP(i,n) for (int i=n-1;i>=0;i--)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (ll)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int a[MAXn],b[MAXn];
ii pos[MAXn];
int id[MAXn];
bitset<MAXn> vis;
vector<int> e[MAXn];
void dfs(int x){
    vis[x] = true;
    for (auto i:e[x]) {
        if (vis[i]) continue;
        dfs(i);
    }
}
int main(){
    IOS();
    int n;
    cin >> n;
    REP (i,n) {
        cin >> a[i];
        id[i] = i;
    }
    REP (i,n) {
        cin >> b[i];
        pos[i] = ii(b[i],a[i]);
    }
    sort(a,a+n);
    sort(b,b+n);
    sort(pos,pos+n);
    sort(id,id+n,[&](const int x,const int y){return pos[x].Y < pos[y].Y;});
    pary(pos,pos+n);
    pary(id,id+n);
    REP (i,n) {
        if (a[i] > b[i]) return cout << "No" << endl,0;
    }
    REP (i,n-1) {
        if (a[i+1] <= b[i]) return cout << "Yes" << endl,0;
    }

    REP (i,n) e[id[i]].eb(i);

    int cnt = 0;
    REP (i,n) {
        if (vis[i]) continue;
        cnt++;
        dfs(i);
    }
    if (cnt == 1) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 10752
/*
* Welcome to my code!
*---------------------------------------------*
* author : lynmisakura(twitter : @andoreiji11)
*/

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size()) 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using pl = pair<ll,ll>;
using vpl = vector<pl>;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){ int sz = a.size();
for(int i=0;i<a.size();i++)cout << a[i] << (i < sz-1 ? ' ' : '\n'); }
void ioboost(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}
///////////////////////////////////////////////////////////

int main(int argc, char const *argv[])
{
	ioboost();
	int n,k;cin >> n >> k;
	vector<int> cnt(n,0);
	rep(i,k){
		int d;cin >> d;
		rep(j,d){
			int p;cin >> p;
			cnt[--p]++;
		}
	}
	int ans = 0;
	rep(i,n)ans += (cnt[i] == 0);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    string s,t;
    cin>>s>>t;
    string ans;
    rep(i,100) ans=ans+'z';
    string x=ans;
    rep(i,s.size()){
        if(i<=s.size()-t.size()){
            int z=1;
            rep(j,t.size()) if(s[i+j]!=t[j]&&s[i+j]!='?'&&t[j]!='?') z=0;
            if(z){
                string a;
                rep(j,s.size()){
                    if(i<=j&&j-i<t.size()) a=a+t[j-i];
                    else{
                        if(s[j]=='?') a=a+'a';
                        else a=a+s[j];
                    }
                }
                ans=min(a,ans);
            }
        }
    }
    if(ans==x) cout<<"UNRESTORABLE";
    else cout<<ans;
    cout<<"\n";
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))

    color = [False] * 8
    over = False
    cnt_anycolor = 0

    for i in a:
        if i <= 399:
            color[0] = True
        elif i <= 799:
            color[1] = True
        elif i <= 1199:
            color[2] = True
        elif i <= 1599:
            color[3] = True
        elif i <= 1999:
            color[4] = True
        elif i <= 2399:
            color[5] = True
        elif i <= 2799:
            color[6] = True
        elif i <= 3199:
            color[7] = True
        else:
            over = True
            cnt_anycolor += 1

    min_color = 0
    max_color = 0

    for c in color:
        if c:
            min_color += 1
            max_color += 1

    if over:
        if min_color == 0:
            min_color += 1
        max_color += cnt_anycolor

    print(min_color, max_color)


if __name__ == '__main__':
    main()

    

Measured memory_bytes: 9132