akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 6;

set< pair< long long, int > > le, ri;
int l[N], r[N];


int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%lld %lld", l+i, r+i);
  long long now = 0;
  int tmp = 0;
  le.insert(make_pair(l[0], tmp++));
  ri.insert(make_pair(l[0], tmp++));
  long long offl = 0, offr = 0;
  for (int i = 1; i < n; i++) {
    long long bef = r[i-1]-l[i-1], cur = r[i]-l[i];
    offl -= cur;
    offr += bef;
    long long midl = (--le.end())->first+offl, midr = ri.begin()->first+offr;
    if (l[i] < midl) {
      le.insert(make_pair(l[i]-offl, tmp++));
      le.insert(make_pair(l[i]-offl, tmp++));
      auto it = --le.end();
      ri.insert(make_pair(midl-offr, tmp++));
      le.erase(it);
      now += midl-l[i];
    }
    else if (l[i] > midr) {
      ri.insert(make_pair(l[i]-offr, tmp++));
      ri.insert(make_pair(l[i]-offr, tmp++));
      auto it = ri.begin();
      le.insert(make_pair(midr-offl, tmp++));
      ri.erase(it);
      now += l[i] - midr;
    }
    else {
      le.insert(make_pair(l[i]-offl, tmp++));
      ri.insert(make_pair(l[i]-offr, tmp++));
    }
  }
  cout << now << endl;
  return 0;
}

Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





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

  set<int> p;
  int x;
  rep(i,n){
    cin>>x;
    p.insert(x);
  }

  cout << p.size() << endl;
}

Measured memory_bytes: 256
int main(){
  int a, b, c, d, e, k;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  scanf("%d", &d);
  scanf("%d", &e);
  scanf("%d", &k);

  if(((e - a) <= k) && ((e - b) <= k) && ((e - c) <= k) && ((e - d) && k) && ((d - a) <= k) && ((d - b) <= k) && ((d - c) <= k) && ((c - a) <= k) && ((c - b) <= k) && ((b - a) <= k)){
  printf("Yay!\n");
  }
  else{
  printf(":(\n");
  }
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#define N 100020
using namespace std;

char a[N][3];
char o[N];

int main(void)
{
    int n, v[3];
    int i;

    scanf("%d %d %d %d", &n, &v[0], &v[1], &v[2]);
    for(i = 0; i < n; i ++)
    {
        scanf("%s", a[i]);
        a[i][0] -= 65;
        a[i][1] -= 65;
    }

    for(i = 0; i < n; i ++)
        if(v[a[i][0]] < v[a[i][1]])
        {
            o[i] = a[i][0] + 65;
            v[a[i][0]] ++;
            v[a[i][1]] --;
        }
        else if(v[a[i][0]] > v[a[i][1]])
        {
            o[i] = a[i][1] + 65;
            v[a[i][1]] ++;
            v[a[i][0]] --;
        }
        else
        {
            if(!v[a[i][0]])
            {
                printf("No\n");
                break;
            }
            if(i < n - 1 && ((a[i][0] == a[i + 1][0] && a[i][1] != a[i + 1][1]) || (a[i][0] == a[i + 1][1] && a[i][1] != a[i + 1][0])))
            {
                o[i] = a[i][0] + 65;
                v[a[i][0]] ++;
                v[a[i][1]] --;
            }
            else
            {
                o[i] = a[i][1] + 65;
                v[a[i][1]] ++;
                v[a[i][0]] --;
            }
        }

    if(i == n)
    {
        printf("Yes\n");
        for(i = 0; i < n; i ++)
            printf("%c\n", o[i]);
    }

    return 0;
}


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

using namespace std;

#define ll  long long
#define vi  vector<int>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

int main(){

  int a, b ; cin >> a >> b;
  a--;b--;
  vector< vector<char> > vvc(110 , vector<char>(110,' ')) ;

  for(int i = 1 ; i < 101 ; i++){
    for(int j = 1 ; j < 101 ; j++){
      j < 50 ? vvc[i][j] = '.' : vvc[i][j] = '#';
    }
  }

//黒を置く
  for(int i = 1 ; i < 101 ; i++){
    for(int j = 1 ; j < 51 ; j++){
      if (b > 0){
        bool flag = true;

        rep(k,8)
          if(vvc[i + ddy[k]][j + ddx[k]] == '#') flag = false;

        if(flag){
          b--;
          vvc[i][j] = '#';
        }
      }
    }
  }

//白を置く
  for(int i = 1 ; i < 101 ; i++){
    for(int j = 51 ; j < 101 ; j++){
      if (a > 0){
        bool flag = true;

        rep(k,8)
          if(vvc[i + ddy[k]][j + ddx[k]] == '.') flag = false;

        if(flag){
          a--;
          vvc[i][j] = '.';
        }
      }
    }
  }

 cout << 100 << ' ' << 100 << endl;

  for(int i = 1;i<101;i++){
    for(int j = 1 ; j < 101 ; j++){
      cout << vvc[i][j];
    }
    cout << endl;
  }

     return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int S, h, m, s;
	scanf("%d", &S);
	
	h = (S/3600); 
	
	m = (S -(3600*h))/60;
	
	s = (S -(3600*h)-(m*60));
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    map<string,int> m;
    set<string> s;
    int a=1;
    for(int i=0; i<n; i++){
        string st;
        cin>>st;
        s.insert(st);
        if(m.count(st)){
            m.at(st)++;
            a=max(a,m.at(st));
        }
        else{
            m[st]=1;
        }
    }
    vector<string> ans;
    while(!s.empty()){
        string tmp=*begin(s);
        if(m.at(tmp)==a) ans.push_back(tmp);
        s.erase(tmp);
    }
    sort(ans.begin(),ans.end());
    for(int i=0; i<ans.size(); i++){
        cout<<ans.at(i)<<endl;
    }

}

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

using namespace std;

class SegmentTree {
	vector<int> mn;
	public:
	SegmentTree() {}
	SegmentTree(int N) : mn(N * 4 + 5, N - 1) {}

	void update(int l, int r, int x, int a, int b, int v) {
		if(l > b || r < a) {
			return;
		}
		if(l >= a && r <= b) {
			mn[x] = min(mn[x], v);		
			return;
		}
		int mid = l + r >> 1;
		update(l, mid, x << 1, a, b, v);
		update(mid + 1, r, x << 1 | 1, a, b, v);
	} 

	int query(int l, int r, int x, int p) {
		if(l == r) {
			return mn[x];
		}
		int mid = l + r >> 1;
		if(p <= mid) {
			return min(mn[x], query(l, mid, x << 1, p));
		} else {
			return min(mn[x], query(mid + 1, r, x << 1 | 1, p));
		}
	}
};

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

	int n, q;
	cin >> n >> q;

	long long ans = 1LL * (n - 2) * (n - 2);
	SegmentTree row(n);
	SegmentTree col(n);
	while(q--) {
		int type, x;
		cin >> type >> x;
		--type;
		if(type == 0) { //col
			int mn = col.query(1, n, 1, x);
			ans -= mn - 1;
			row.update(1, n, 1, 2, mn, x - 1);
		} else { //row
			int mn = row.query(1, n, 1, x);
			ans -= mn - 1;
			col.update(1, n, 1, 2, mn, x - 1);
		}
	}

	cout << ans << '\n';

	return 0;
}


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

const int MAX_N = 20000;
typedef pair<int, pair<int, int > > P;

vector<P> v;
bool vis[MAX_N];

int main() {
  int N, M;
  while(cin >> N >> M && (N || M)) {
    P p;
    v.clear();
    for(int i = 0; i < M; ++i) {
      cin >> p.first >> p.second.first >> p.second.second;
      --p.second.first; --p.second.second;
      v.push_back(p);
    }
    sort(v.begin(), v.end());
    fill(vis, vis+N, false);
    vis[0] = true;
    int ans = 1;
    for(int i = 0; i < v.size(); ++i) {
      if(vis[v[i].second.first] && !vis[v[i].second.second]) {
	vis[v[i].second.second] = true;
	++ans;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1296
n = int(input())
a = list(map(int,input().split()))

mini = 0
count = 0

for i in range(n):
    mini = i
    for j in range(i,n):
        if a[j] < a[mini]:
            mini = j
    a[i],a[mini] = a[mini],a[i]
    if mini != i:
        count += 1

for i in range(n):
    if i != n-1:
        print(a[i],end=" ")
    else:
        print(a[i])
print(count)

Measured memory_bytes: 7736
s  = input()
ans = 10**7
alp = [chr(ord('a') +i) for i in range(26)]
for x in alp:
    char = x
    res = 0
    p = s
    np = ""
    while p.count(char) != len(p):
        np  =""
        for i in range(len(p)-1):
        
            if p[i] == char or p[i+1] == char:
                np +=char
                
            else:
                np+=p[i]
        p = np
        res+=1
        if res >=50:break
    ans = min(res,ans)
print(ans)
    
                
            
        

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;


void SMTB2019C()
{
	int X;
	cin >> X;
	vi dp(X + 1);
	for (int i = 100; i <= 105; ++i)
	{
		if(i <= X)
			dp[i] = 1;
	}
	for (int i = 0; i <= X; ++i)
	{
		if (dp[i] == 1)
			continue;
		for (int j = 100; j <= 105; ++j)
		{
			int k = i - j;
			if (k >= 0 && dp[k] == 1)
			{
				dp[i] = 1;
				break;
			}
		}
	}
	if (dp[X] == 1)
	{
		cout << "1" << endl;
	}
	else
	{
		cout << "0" << endl;
	}
}



int main()
{
	SMTB2019C();
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <vector>
#include <iomanip>


int main() {


    int N;
    std::cin >> N;

    if (N == 1) {
        std::cout << "Hello World" << "\n";
    } else {
        int A, B;
        std::cin >> A >> B;
        std::cout << (A + B) << "\n";
    }


    return 0;
}


Measured memory_bytes: 256
n = int(input())
px = py = pt = 0
for i in range(n):
	t,x,y = map(int,input().split())
	d = abs(x - px) + abs(y - py)
	nt = t - pt
	if nt < d or d%2 != nt%2:
		print("No")
		exit()
	px = x
	py = y
	pt = t
print("Yes")

Measured memory_bytes: 9140
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string.h>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int from,to,cost;};
vector<edge> G;
vector<int> O[10];
P sg[10];
int d[1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int fi[1005][1005];
int ans[1005][1005]={};
bool graph[55][55];
bool visited[55];
int a[55],b[55];
int n,m;
int dp[41][405][405];
signed main(){
    int n;cin>>n;
    cout<<48-n<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

#define Pi 3.14159265                   

int main()
{
   FAST/**/
   
   ll r;
   cin>>r;
   ld ans = ((ld)2)*Pi*r;
   cout<<fixed<<setprecision(12)<<ans;
   
   return 0;        
}  
  
   


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> l(N), r(N);
	REP(i, N) cin >> l[i] >> r[i];

	ll res = 0;
	REP(i, N){
		res += (r[i]-l[i]+1);
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
7
3 1
4 1
5 9
2 6
5 3
5 8
9 7
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double

typedef pair<int,int> pi;

typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define gcd __gcd

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

const int N = 1e5+69;

int n,i,j,k;
int a[N],b[N];

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int inc = 0;
  cin >> n;
  for(i = 0;i < n;i++)cin >> a[i] >> b[i];
  for(i = n-1;i > -1;i--){
      a[i] += inc;
      if(a[i]%b[i]){
         inc += b[i]-(a[i]%b[i]);
      }
  }
  cout << inc << endl;
  return 0;
}

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

#define ll long long int

using namespace std;

int main(){
	ll x,y,i=0;
	cin>>x>>y;
	while(x<=y){
		x=x*2;
		i++;
	}
	cout<<i<<endl;
	return 0;
}


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

#define ll long long
#define P pair<int,int>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())

int main() {
    int a, b, cnt = 0;
    ostringstream oss;
    string rev;
    cin >> a >> b;
    for(int i = a; i <= b; i++) {
        oss.str("");
        oss.clear();
        oss << i;
        rev = oss.str();
        reverse(rev.begin(), rev.end());
        if(oss.str().compare(rev) == 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>

#define MOD 2019

using namespace std;

long q_pow(long x, long n){
    if(n == 0) return 1;
    if(n==1) return x;
    else if(n%2 == 0) return q_pow(x*x%MOD, n/2);
    else return x * q_pow(x, n-1) % MOD;
}

int main(){
    string S;
    cin >> S;
    int n = S.size();
    int mod[n];
    int cnt[2019]; fill(cnt, cnt + 2019, 0);
    mod[n-1] = S[n-1] - '0';

    for(int i=n-2; i>=0; i--){
        int cur = S[i] - '0';
        mod[i] = mod[i+1] + cur * q_pow(10, n - i - 1);
        mod[i] %= MOD;
    }

    for(int i=0; i<n; i++) cnt[mod[i]]++;
    cnt[0]++;

    long ans = 0;
    for(int i=0; i<2019; i++){
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4504
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 30);
ll h, m,a,b,n, sum; string s, t;
const ll MOD= 1000000007;
const ld PI = acos(-1);
vector<int> dist;
struct Corr {
    int from;
    int depth;
}; queue<Corr> q;
void bfs(vector<vector<int>> G) {
    dist[0] = 0;
    while (!q.empty()) {
        Corr now = q.front(); q.pop();
        for (int i : G[now.from]) {
            if (dist[i] != -1) continue;
            Corr next = { i,now.depth + 1 };
            dist[next.from] = now.from;
            q.push(next);
        }
    }
}
int main() {
    cin >> n >> m; vector<vector<int>> G(n);
    dist.resize(n, -1);
    rep(i,m){
        cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    Corr st = { 0,0 };
    q.push(st); bfs(G);
    rep(i, n) {
        if (dist[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }cout << "Yes" << endl;
    req(i, n - 1) {
        cout << dist[i] + 1 << endl;
    }
}

Measured memory_bytes: 16348
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

vector<vector<int> > G;
// bfs 幅優先探索
int bfs(int s)
{
    vector<int> cost(G.size(), -1);

    cost[s] = 0;
    queue<int> pos_queue;
    pos_queue.push(s);

    while (pos_queue.size())
    {
        int pos = pos_queue.front();
        pos_queue.pop();
        rep(i, G[pos].size())
        {
            int next = G[pos][i];

            if (cost[next] == -1)
            {
                cost[next] = cost[pos] + 1;
                pos_queue.push(next);
            }
        }
    }
    rep(i, G.size())
    {
      cout << i + 1 << " " << cost[i] << endl;
    }
}

int main()
{
  int N;
  cin >> N;
  G.resize(N);
  rep(i, N)
  {
    int u, k;
    cin >> u >> k;
    u--;
    rep(j, k)
    {
      int v;
      cin >> v;
      G[u].push_back(v - 1);
    }
  }
  bfs(0);
  return 0;
}


Measured memory_bytes: 3176
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int N;
    int ans=0;
    cin >> N;
    vector<pint> info[N];
    rep(i,N){
        int A;
        cin >> A;
        rep(j,A){
            int x,y;
            cin >> x >> y;
            x--;
            info[i].push_back(pint(x,y));
        }
    }
    rep(i,1<<N){
        int c=Flagcount(i);
        int che=true;
        rep(j,N){
            rep(k,info[j].size()){
                if(i&(1<<j)){
                    if(info[j][k].second==0 && (i&(1<<info[j][k].first))) che=false;
                    if(info[j][k].second==1 && !(i&(1<<info[j][k].first))) che=false;
                }
            }
        }
        if(che) ans=max(c,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int n, a, b, c;
vector<int> l;

int minCost(int x, int y, int z, int i){
	if(i==n){
		if(!x || !y || !z)
			return 10000;
		return abs(a-x)+abs(b-y)+abs(c-z)-30;
	}
	int minA = minCost(x+l[i], y, z, i+1)+10;
	int minB = minCost(x, y+l[i], z, i+1)+10;
	int minC = minCost(x, y, z+l[i], i+1)+10;
	int minD = minCost(x, y, z, i+1);
	return min({minA, minB, minC, minD});
}

int main(){
	cin >> n >> a >> b >> c;
	for(int i=0; i<n; i++){
		int tmp;
		cin >> tmp;
		l.push_back(tmp);
	}
	cout << minCost(0,0,0,0) << endl;
	return 0;
}


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

int H, W;
string S[300];

int calculate(string& s1, string& s2){
    int cost[301][301], dp[301][301];
    memset(cost, 0, sizeof(cost));
    for(int i=H-1; i>=0; i--){
        for(int j=H-1; j>=0; j--){
            cost[i][j] = cost[i+1][j+1] + (s1[i] == s2[j]);
        }
    }

    dp[0][0] = 0;
    for(int i=0; i<=H; i++){
        for(int j=0; j<=H; j++){
            if(i+j==0) continue;
            dp[i][j] = 1e9;
            if(i>0) dp[i][j] = min(dp[i][j], dp[i-1][j] + cost[i-1][j]);
            if(j>0) dp[i][j] = min(dp[i][j], dp[i][j-1] + cost[i][j-1]);
        }
    }

    return dp[H][H];
}

int main(){
    cin >> H >> W;
    for(int i=0; i<H; i++){
        string str;
        cin >> str;
        for(int j=0; j<W; j++){
            S[j].push_back(str[j]);
        }
    }
    for(int j=0; j<W; j++) reverse(S[j].begin(), S[j].end());

    int ans = 0;
    for(int j=0; j<W-1; j++) ans += calculate(S[j], S[j+1]);
    cout << ans << endl;
    return 0;
}

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


int main(){
   
    long long N,D;
    long long ans;
    cin >> N;
    cin >> D;
    if((N%(D*2+1)) == 0){
        ans = N / (D*2+1);
    }else{
        ans = N / (D*2+1)+1;
    }
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static long Solve(Scanner scan) {
        var N = scan.NextInt();
        var A = scan.ArrayInt(N);
        var len = A.Length;
        var temp = 0;
        long sum = 0;
        for (int i = 0; i < len; i++) {
            if (temp < A[i]) temp = A[i];
            else sum += temp - A[i];
        }
        return sum;
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
    public int[] ArrayInt(int len, int add = 0) {
        var array = new int[len];
        for (int i = 0; i < len; i++) array[i] = NextInt() + add;
        return array;
    }
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
#define int long long
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

signed main(void){
  int a,b;cin >> a >> b;
  int k=a+b;
  if(k%2==0)cout << k/2 << endl;
  else cout << "IMPOSSIBLE" << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int D;
    scanf("%d",&D);
    if(D==25){
        printf("Christmas");
    }
    else if(D==24){
            printf("Christmas Eve");

    }
    else if(D==23){
            printf("Christmas Eve Eve");

    }
    else if(D==22){
        printf("Christmas Eve Eve Eve");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n,m;
    cin>>n>>m;
    int item_v[100],item_w[100];
    rep(i,n){
        cin>>item_v[i]>>item_w[i];
    }
    
    int dp[101][10100]={};
    for(int i=1;i<=n;i++){
        rep(j,10001){
            dp[i][j] = dp[i-1][j];
            
            if( j-item_w[i-1]>=0 ){
                dp[i][j] = max( dp[i][j] , dp[i-1][j-item_w[i-1]] + item_v[i-1] );
            }
        }
    }
    int maximum = -1;
    rep(j,m+1){
        maximum = max( maximum , dp[n][j] );
    }
    cout<<maximum<<endl;
}

Measured memory_bytes: 5152
n = int(input())
i = 1

listA = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listB = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listC = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listD = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listE = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listF = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listG = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listH = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listI = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listJ = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listK = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
listL = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

while i < n+1:
    b, f, r, v = map(int, input().split())
    if 3 * b + f == 4:
        listA[r-1] += v
        i += 1
    
    elif 3 * b + f == 5:
        listB[r-1] += v
        i += 1
    
    elif 3 * b + f == 6:
        listC[r-1] += v
        i += 1
    
    elif 3 * b + f == 7:
        listD[r-1] += v
        i += 1
    
    elif 3 * b + f == 8:
        listE[r-1] += v
        i += 1
    
    elif 3 * b + f == 9:
        listF[r-1] += v
        i += 1
    
    elif 3 * b + f == 10:
        listG[r-1] += v
        i += 1
    
    elif 3 * b + f == 11:
        listH[r-1] += v
        i += 1
    
    elif 3 * b + f == 12:
        listI[r-1] += v
        i += 1
    
    elif 3 * b + f == 13:
        listJ[r-1] += v
        i += 1
    
    elif 3 * b + f == 14:
        listK[r-1] += v
        i += 1
    
    else:
        listL[r-1] += v
        i += 1
    
    
for i in range(9):
    print(' ' + str(listA[i]), end='')
print(' ' + str(listA[9]), end='\n')
for i in range(9):
    print(' ' + str(listB[i]), end='')
print(' ' + str(listB[9]), end='\n')
for i in range(9):
    print(' ' + str(listC[i]), end='')
print(' ' + str(listC[9]), end='\n')
print('####################')        
for i in range(9):
    print(' ' + str(listD[i]), end='')
print(' ' + str(listD[9]), end='\n')
for i in range(9):
    print(' ' + str(listE[i]), end='')
print(' ' + str(listE[9]), end='\n')
for i in range(9):
    print(' ' + str(listF[i]), end='')
print(' ' + str(listF[9]), end='\n')
print('####################')
for i in range(9):
    print(' ' + str(listG[i]), end='')
print(' ' + str(listG[9]), end='\n')
for i in range(9):
    print(' ' + str(listH[i]), end='')
print(' ' + str(listH[9]), end='\n')
for i in range(9):
    print(' ' + str(listI[i]), end='')
print(' ' + str(listI[9]), end='\n')
print('####################')
for i in range(9):
    print(' ' + str(listJ[i]), end='')
print(' ' + str(listJ[9]), end='\n')
for i in range(9):
    print(' ' + str(listK[i]), end='')
print(' ' + str(listK[9]), end='\n')
for i in range(9):
    print(' ' + str(listL[i]), end='')
print(' ' + str(listL[9]), end='\n')

    


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

int main(){
  int n; cin >> n; bool flag=false;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j == n) {cout << "Yes" << endl; flag=true; break;}
    }
    if(flag == true) break;
  }
  if(flag == false) cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(double, a, b, H, M);

    const auto toRad = [](double arg) { return arg * M_PI / 180; };

    const double argHour = 360 * ((60 * H + M) / (60 * 12));
    const double argMin = 360 * (M / 60);

    auto p1 = polar(a, toRad(argHour));
    auto p2 = polar(b, toRad(argMin));
    print(abs(p1 - p2));

    return 0;
}


Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N];


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	set<string>s;
	for(int i=0;i<n;i++){
		string str;
		cin>>str;
		s.insert(str);
	}
	cout<<s.size()<<endl;
	return 0; 
}

Measured memory_bytes: 19196
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(n);

    int cnt=n;
    int kosu[n];
      for(int i=0;i<n;i++){
      kosu[i]=0;}

  
    for(int i = 0; i < m; i++) {
        int  x, y, ppp;
        cin >> x >> y >> ppp;
        tree.unite(x-1, y-1); // xの木とyの木を併合する

    }

  
  for(int i=0;i<n;i++){
    kosu[tree.root(i)]++;}
  
  for(int i=0;i<n;i++){
    if(kosu[i]){
      cnt-=kosu[i]-1;
    }
  }

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

 

Measured memory_bytes: 1280
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int[] A  = new int[N-1];
		
		for(int i=0; i<N-1; i++) {
			A[i] = keyboard.nextInt();
		}
		
		int[] SV = new int[N+1];
		
		for(int j=0; j<N-1; j++) {
			SV[A[j]] ++;
		}
		
		for(int k=1; k<=N; k++) {
			System.out.println(SV[k]);
		}
		keyboard.close();	
	}
}


Measured memory_bytes: 60500
#include<iostream>
#include<stdio.h>
#include<algorithm>
 
using namespace std;
const  long long inf=1e12;
long long d[1000][1000],n,m,y,c,x;
int ro[1000];
void pre_floyd()
{
    for (int i=1;i<=n;i++)
        for (int j=1; j<=n;j++)
        if (i==j) d[i][j]=0; else d[i][j]=inf;
}
void floyd()
{
 for (int k=1;k<=n;k++)
    for (int i=1;i<=n;i++)
     for (int j=1;j<=n;j++)
     d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
 
int main ()
{
    int r;
    scanf("%d%d%d",&n,&m,&r);
 
 
    for (int i=1;i<=r;i++)
        cin>>ro[i];
 
   pre_floyd();
 
    for (int i=0;i<m;i++)
    {
        scanf("%d%d%d",&x,&y,&c);
        d[x][y]=c;
        d[y][x]=c;
    }
 
     floyd();
 
     sort(ro+1,ro+r+1);

        long long  ans=0;
        for (int i=2;i<=r;i++)
            ans+=d[ro[i-1]][ro[i]];
 
     while(next_permutation(ro+1,ro+r+1))
     {
 
         long long  ans1=0;
        for (int i=2;i<=r;i++)
            ans1+=d[ro[i-1]][ro[i]];
 
            ans=min(ans,ans1);
     }
 
     cout<<ans;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    map<ll,int> m;
    rep(i,n) {
        ll a;
        cin >> a;
        m[a]++;
    }
    vector<ll> can;
    for(auto p : m) {
        if(p.second == 1) continue;
        if(p.second >= 4) {
            can.pb(p.first);
            can.pb(p.first);
        } else {
            can.pb(p.first);
        }
    }
    sort(rall(can));
    cout << (can.size() >= 2 ? can[0]*can[1] : 0) << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX_A = 100100;
int p[MAX_A], q[MAX_A], r[MAX_A];
int X, Y, A, B, C;

int main()
{
    scanf("%d %d %d %d %d", &X, &Y, &A, &B, &C);
    for(int i = 0; i < A; ++i) scanf("%d", &p[i]);
    for(int i = 0; i < B; ++i) scanf("%d", &q[i]);
    for(int i = 0; i < C; ++i) scanf("%d", &r[i]);
    sort(p, p + A, greater<int>()); 
    sort(q, q + B, greater<int>()); 
    sort(r, r + C, greater<int>());

    vector<int> ans;
    for(int i = 0; i < X; ++i) ans.push_back(p[i]);
    for(int i = 0; i < Y; ++i) ans.push_back(q[i]);
    for(int i = 0; i < C; ++i) ans.push_back(r[i]);
    sort(ans.begin(), ans.end(), greater<int>());
    ll res = 0;
    for(int i = 0; i < (X + Y); ++i) res += ll(ans[i]);
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 3572
N = int(input())
import sys
sys.setrecursionlimit(500000)
def dfs(l):
    global N

    if l!=[] and N<int("".join(l)):
        return 0
    ans = 0
    if all(l.count(i)>0 for i in ["3", "5", "7"]):
        ans = 1
    for i in ["3", "5", "7"]:
        l.append(i)
        #参照渡し
        ans += dfs(l)
        l.pop()

    return ans

print(dfs([]))

Measured memory_bytes: 3188
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    ll n, m, q; cin >> n >> m >> q;
    if(m == n-1){
        //prtl("木！");
        bool B = true;
        rep(i, 0, q){
            ll a, b, c; cin >> a >> b >> c;
            if(c == 1){
                B = false;
            }
        }
        if(B){
            prtl("Yes");
        }else{
            prtl("No");
        }
        return 0;
    }
    UnionFind uff(n);
    vector<P> aft(0);
    rep(i, 0, q){
        ll a, b, c; cin >> a >> b >> c;
        if(c == 0){
            uff.merge(uff.root(a), uff.root(b));
        }else{
            aft.emplace_back(mp(a, b));
        }
    }
    for(auto x: aft){
        ll a = x.first, b = x.second;
        if(uff.root(a) == uff.root(b)){
                prtl("No");
                return 0;
        }
    }
    ll c = 0; vb al(n, false);
    rep(i, 0, n){
        //prtl(uff.root(i));
        if(al[uff.root(i)] == false){
            al[uff.root(i)] = true;
            c++;
        }
    }
    //prtl("!");
    ll S = c;
    //debug(S);
    ll mx = n + S*(S-3)/2;
    //prtl(mx);
    if(m <= mx){
        prtl("Yes");
    }else{
        prtl("No");
    }
}



Measured memory_bytes: 6872
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
    int N; cin>>N;
    vector<vector<int>> a(N,vector<int>(N-1));
    for(int i=0;i<N;i++){
        for(int j=0;j<N-1;j++){
            cin>>a[i][j]; a[i][j]--;
        }
    }

    const int V=N*N;
    vector<vector<int>> G(V);
    vector<int> indeg(V);
    for(int i=0;i<N;i++){
        for(int j=0;j<N-2;j++){
            int x=N*min(i,a[i][j])+max(i,a[i][j]);
            int y=N*min(i,a[i][j+1])+max(i,a[i][j+1]);
            G[x].push_back(y);
            indeg[y]++;
        }
    }

    stack<int> S;
    for(int i=0;i<V;i++){
        if(i/N>=i%N) continue;
        if(indeg[i]==0) S.push(i);
    }

    vector<int> dp(V);
    int cnt=0;
    while(!S.empty()){
        int v=S.top(); S.pop();
        cnt++;
        for(int u:G[v]){
            dp[u]=max(dp[u],dp[v]+1);
            indeg[u]--;
            if(indeg[u]==0) S.push(u);
        }
    }

    if(cnt<N*(N-1)/2) cout<<-1<<endl;
    else cout<<*max_element(dp.begin(),dp.end())+1<<endl;

    return 0;
}

Measured memory_bytes: 62720
#include <stdio.h>
#include <string.h>
#define lowbit(x) (x&-x)
const int MAXN=100010;
int n,c[MAXN];
void update(int x,int v)
{
    while(x>0)
    {
        c[x]+=v;
        x-=lowbit(x);
    }
}
int query(int x)
{
    int ret=0;
    while(x<=n)
    {
        ret+=c[x];
        x+=lowbit(x);
    }
    return ret;
}
main()
{
    int m,i;
    scanf("%d%d",&n,&m);
    int l,r;
    for(int i=0;i<m;i++){
    	scanf("%d%d",&l,&r);
    	update(l-1,-1);
    	update(r,1);
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		if(query(i)==m)
			sum++;
	}
	printf("%d\n",sum);
}


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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl;
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// Aliases
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

bool cmp(const pair<int, int> &x, const pair<int, int> &y) {
    return x.SND == y.SND ? x.FST > y.FST : x.SND < y.SND;
}

int main() {
    int n, t = 0;
    cin >> n;
    vector<pair<int, int>> ab(n);
    REP(i, n) {
        cin >> ab[i].FST >> ab[i].SND;
    }
    sort(ALL(ab),cmp);
    bool j = true;
    REP(i, n) {
        t += ab[i].FST;
        if(t > ab[i].SND) {
            j = false;
            break;
        }
    }

    cout << (j ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<string>
using namespace std;

char S[100000];

int main(){
    string s;
    cin>>s;
    
    int j=0;

    for(int i=0;i<s.size();i=i+2){
        S[j]=s[i];
        j++;
        
    }

    cout<<S<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000000000000
#define mod 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

class UnionFind {
private:
	vector<int>par;
public:
	UnionFind(int n) {
		for (int i = 0; i < n; i++) {
			par.push_back(-1);
		}
	}

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return;
	}

	int size(int x) {
		return -1 * par[root(x)];
	}
};

signed main() {
	int n, m;
	cin >> n >> m;
	vector<int>lan[100005];
	UnionFind uf(n);
	rep(i, n) {
		int k;
		cin >> k;
		rep(j, k) {
			int a;
			cin >> a;
			lan[a - 1].push_back(i);
		}
	}
	rep(i, m) {
		for (int j = 1; j < lan[i].size(); j++) {
			uf.unite(lan[i][j - 1], lan[i][j]);
		}
	}
	if (uf.size(0) == n) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 5240
#include<bits/stdc++.h>
using namespace std;
const int N=111;
int n,g[N],a[N],b[N],ans;
vector<int>e[N];
long long x,ans2;
int dfsg(int v,int fa){
	int res=0;
	for(int i=0;i<(int)e[v].size();i++){
		int u=e[v][i];
		if(u!=fa)res=max(res,dfsg(u,v));
	}
	return res+1;
}
void getg(){
	for(int i=1;i<=n;i++)a[i]=dfsg(i,0);int mn=n+1;
	for(int i=1;i<=n;i++)if(a[i]<mn)mn=a[i];
	for(int i=1;i<=n;i++)if(a[i]==mn)g[++g[0]]=i;
	//for(int i=1;i<=n;i++)printf("%d ",a[i]);printf("\n");
}
int dfs(int v,int fa,int dep){
	int son=0;
	for(int i=0;i<(int)e[v].size();i++){
		int u=e[v][i];
		if(u!=fa)++son,dfs(u,v,dep+1);//printf("v %d %d\n",v,u);
	}//printf("- %d f%d d%d s%d\n",v,fa,dep,son);
	ans=max(ans,dep);
	if(son)b[0]=max(b[0],dep),b[dep]=max(b[dep],son);
}
void solve2(){//printf("g %d %d\n",g[1],g[2]);
	memset(b,0,sizeof(b));ans=0;
	dfs(g[1],g[2],1);//printf("======\n");
	dfs(g[2],g[1],1);//printf("======\n");
	//printf("b");for(int i=1;i<=b[0];i++)printf(" %lld",b[i]);printf("\n");
	x=1;for(int i=1;i<=b[0];i++)x*=b[i];x<<=1;
}
void solve1(){//printf("g %d %d\n",g[1],g[2]);
	dfs(g[1],0,1);printf("%d",ans);//printf("======\n");
	//printf("b");for(int i=1;i<=b[0];i++)printf(" %lld",b[i]);printf("\n");
	x=1;for(int i=1;i<=b[0];i++)x*=b[i];ans2=x;
	for(int i=0;i<(int)e[g[1]].size();i++)g[2]=e[g[1]][i],solve2(),ans2=min(ans2,x);
	printf(" %lld",ans2);
}
int main(){
    scanf("%d",&n);
	for(int i=1;i<n;i++){int a,b;scanf("%d%d",&a,&b);e[a].push_back(b);e[b].push_back(a);}
	getg();
	//printf("g");for(int i=1;i<=g[0];i++)printf(" %d",g[i]);printf("\n");
	if(g[0]==1)solve1();
	if(g[0]==2)solve2(),printf("%d %lld",ans,x);
    return 0;
}

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

int main(){

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

	 char a,b;

	 cin>>a>>b;

	 if(a=='H') cout<<b<<"\n";

	 else {

	 	if(b=='H') cout<<'D';

	 	else cout<<'H';



	 }

}

Measured memory_bytes: 256
N = int(input())

n = 100010
prime = []
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False

for i in range(2, n + 1):
    if is_prime[i]:
        prime.append(i)
        for j in range(2 * i, n + 1, i):
            is_prime[j] = False

for v in prime:
    if v >= N:
        print(v)
        break


Measured memory_bytes: 69684
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printaa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ for(int j = 0; j < (sizeof(x[0])/sizeof(x[0][0])); j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    int ans = N;
    rep(i,0,N-1){
        if(S[i] != S[i+1]){
            int tmp = max(i+1, N-i-1);
            ans = min(ans, tmp);
        }
    }
    print(ans);
}


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

int main(){
    int n,k;
    cin>>n>>k;
    if(n-k==0){
        cout<<0<<endl;
        return 0;
    }
    ll dp[n-k][n];
    fill(dp[0],dp[n-k],LINF);
    for(int i=0;i<n;i++){
        cin>>dp[0][i];
    }
    for(int i=1;i<n-k;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<j;k++){
                dp[i][j]=min(dp[i][j],dp[i-1][k]+max(0LL,dp[0][j]-dp[0][k]));
            }
        }
    }
    ll ans=LINF;
    for(int i=0;i<n;i++){
        ans=min(ans,dp[n-k-1][i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 896