akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,a[410],dp[410][410],s[410];
int sum(int l, int r){
  return s[r] - s[l];
}
int rec(int l, int r){
  if(dp[l][r] != -1)return dp[l][r];
  if(r-l == 1)return 0;
  int ret = INF;
  repd(i,l+1,r){
    chmin(ret, sum(l,r) + rec(l,i) + rec(i,r));
  }
  return dp[l][r] = ret;
}

signed main(){
  cin>>n;rep(i,n)cin>>a[i];
  rep(i,410)rep(j,410)dp[i][j] = -1;
  rep(i,n)s[i+1] = s[i] + a[i];
  cout << rec(0, n) << endl;
}


Measured memory_bytes: 1536
n, d = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(n)]
res = 0
for i in range(n):
    for j in range(i+1, n):
        l = sum(map(lambda x: x ** 2, [a - b for a, b in zip(points[i], points[j])]))
        for k in range(200):
            if l == k ** 2:
                res += 1
                break

print(res)


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

#define ll long long
#define pb push_back

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a < b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return a / gcd(a, b)*b;

}
//最小公倍数

int main() {
	
	string S;
	ll w;
	cin>>S>>w;

	for(int i=0;i<S.size();i++){
		if(i%w==0)cout<<S[i];
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
n,m,x=map(int,input().split())
aa=list(map(int,input().split()))

cost=0
for i in range(x,n+1):
  if i in aa:
    cost+=1
    
cost2=0
for i in range(0,x+1):
  if i in aa:
    cost2+=1
print(min(cost,cost2))

Measured memory_bytes: 3064
import itertools
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)


# 素数
# Eratosthenesの篩

Q = int(input())
LR = []
for _ in range(Q):
    l, r = map(int, input().split())
    LR.append((l, r))

M = 10 ** 5 + 1
is_prime = np.ones(M, np.bool)
is_prime2 = np.ones(M, np.bool)
is_prime[1] = 0

for i in range(2, M):
    if i*i > M:
        break

    if is_prime[i]:
        is_prime[i+i::i] = 0

for i in range(3, M, 2):
    n = (i+1)//2
    is_prime2[i] = is_prime[n]

is_near_2017 = np.ones(M, np.bool)
is_near_2017[2::2] = 0
is_near_2017[1] = 0

for i in range(3, M, 2):
    is_near_2017[i] = is_prime[i] & is_prime2[i]

#cnt = list(itertools.accumulate(is_near_2017))
cnt = np.cumsum(is_near_2017)

ans = []
for l, r in LR:
    a = cnt[r] - cnt[l-1]
    ans.append(str(a))

print("\n".join(ans))


Measured memory_bytes: 33968
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define ll long long int
#define ld double
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define pu push
#define po pop
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define be begin
#define sz(a) (ll)a.size()
#define INF 1e18
 
typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
 
ll mod=1e9+7;
// ll gcd(ll a, ll b){
//     if(a<b) swap(a,b);
//     if(b==0) return a;
//     return gcd(b,a%b);
// }
 
// ll fun(ll x, ll y){
//     ll rem=1;
//     while(y!=0){
//         if(y%2==1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y/=2;
//     }
//     return rem;
// }

ll n;
ve<ve<ll>>ar(100001);
ll dp[100001]={0};

void dfs(ll x,ll p){
	if(dp[x]!=-1) return;
	dp[x]=0; ll c=1, d=1;
	for(auto i:ar[x]){
		if(i==p) continue;
		dfs(i,x);
		c=(c*dp[i])%mod;
		for(auto j:ar[i]){
			if(j==x) continue;
			d=(d*dp[j])%mod;
		}
	}
	dp[x]=(c+d)%mod;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(ll i=1,u,v;i<n;i++){
		cin>>u>>v;
		ar[u].pb(v);
		ar[v].pb(u);
	}
	for(ll i=1;i<=n;i++) dp[i]=-1;
	dfs(1,0);
	cout << dp[1] << "\n";
	return 0;
}

Measured memory_bytes: 13440
#include <bits/stdc++.h>
using ll = long long;
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
// const int MOD = 1000000007;

template <typename T>
void __print__(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void __print__(std::ostream &os, const char *del, const char *tail, const Fst &fst,
               const Rst &... rst) {
    os << fst << del;
    __print__(os, del, tail, rst...);
}

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __print__(os, ", ", "\n", __VA_ARGS__);           \
        std::cerr << os.str();                            \
    } while (0)
#else
#define dump(...)
#endif

template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    __print__(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    __print__(std::cout, " ", "\n", fst, rst...);
}

template <typename iter>
void println_(iter bgn, iter end) {
    while (bgn != end) println(*bgn++);
}

template <typename iter>
void print_(iter bgn, iter end) {
    while (bgn != end) {
        std::cout << *bgn++;
        std::cout << (bgn == end ? "\n" : " ");
    }
}

int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
         std::ios::sync_with_stdio(0), 0);

template <typename T>
std::vector<T> ndarray(int n, T v) {
    return std::vector<T>(n, v);
}
template <typename... Args>
auto ndarray(int n, Args... args) {
    auto val = ndarray(args...);
    return std::vector<decltype(val)>(n, move(val));
}

template <typename T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, true : false;
}

template <typename T>
bool umin(T &a, const T &b) {
    return a > b ? a = b, true : false;
}

using namespace std;

int n, k;
int par[100010];
vector<vector<int>> ch;
int show[100010];

int dfs(int v) {
    if (ch[v].size() == 0) {
        show[v] = true;
        return 0;
    } else {
        int mi = 1e9;
        for (auto &c : ch[v]) {
            mi = min(mi, 1 + dfs(c));
        }
        show[v] = mi < k || par[v] == -1;
        return mi;
    }
}

signed main() {
    while (cin >> n >> k && n) {
        memset(show, 0, sizeof show);
        memset(par, -1, sizeof par);
        ch.assign(n, {});
        rep(i, n) {
            cin >> par[i];
            --par[i];
            if (par[i] != -1) {
                ch[par[i]].push_back(i);
            }
        }

        rep(i, n) if (par[i] == -1) dfs(i);
        int ans = count(show, show + n, 1);
        cout << ans << endl;
    }
}

Measured memory_bytes: 13608
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> inline void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> inline void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

int main() {
    ll n,k;
    cin >> n >> k;
    ll arry[100001];
    memset(arry, 0, sizeof(arry));
    rep(i,n) {
        ll a,b;
        cin >> a >> b;
        arry[a] += b;
    }

    ll index = 0;
    ll i = 0;
    while (index<k) {
        index += arry[i];
        i++;
    }
    
    print(i-1);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n;
int a;
multiset<int> mt;
map<int,int> cnt;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		mt.insert(a);
		cnt[a]++;
	}
	vector<pair<int,int> > operations;
	while(mt.size()>2){
		int tou=*mt.begin();
		mt.erase(mt.begin());
		int wei=*mt.rbegin();
		for(__typeof(mt.end()) it=mt.end();it!=mt.begin();it--){
			if(it!=mt.end()){
				mt.erase(it);
				break;
			}
		}
		if(*mt.rbegin()<0){
			mt.insert(wei-tou);
			cnt[wei-tou]++;
			operations.push_back(make_pair(wei,tou));
		}
		else{
			mt.insert(tou-wei);
			cnt[tou-wei]++;
			operations.push_back(make_pair(tou,wei));
		}
	}
	operations.push_back(make_pair(*mt.rbegin(),*mt.begin()));
	cout<<*mt.rbegin()-*mt.begin()<<endl;
	for(int i=0;i<operations.size();i++)
		cout<<operations[i].first<<' '<<operations[i].second<<endl;
	return 0;
}


Measured memory_bytes: 8312
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static final long MOD = 1_000_000_007;

  public static void main(String[] args) {
    int N = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();
    ArrayList<ArrayList<Integer>> list = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      list.add(new ArrayList<>());
    }
    for (int i = 0; i < N; i++) {
      int C = Integer.parseInt(sc.next()) - 1;
      int W = Integer.parseInt(sc.next());
      list.get(C).add(W);
    }
    int[] min = new int[N];
    int m = 2_000_000_000;
    for (int i = 0; i < N; i++) {
      if (list.get(i).isEmpty()) continue;
      Collections.sort(list.get(i));
      min[i] = m;
      m = Math.min(m, list.get(i).get(0));
    }
    m = 2_000_000_000;
    for (int i = N - 1; i >= 0; i--) {
      if (list.get(i).isEmpty()) continue;
      min[i] = Math.min(min[i], m);
      m = Math.min(m, list.get(i).get(0));
    }
    ArrayList<Integer> count = new ArrayList<Integer>();
    int sum = 0;
    for (int i = 0; i < N; i++) {
      if (list.get(i).isEmpty()) continue;
      if (list.get(i).get(0) + min[i] > Y) continue;
      int c = 0;
      for (int j = 0; j < list.get(i).size(); j++) {
        if (list.get(i).get(j) + min[i] > Y && list.get(i).get(j) + list.get(i).get(0) > X) break;
        ++c;
      }
      count.add(c);
      sum += c;
    }
    long ans = 1;
    for (int i = 1; i <= sum; i++) {
      ans *= i;
      ans %= MOD;
    }
    for (int c : count) {
      for (int i = 2; i <= c; i++) {
        ans *= inv(i);
        ans %= MOD;
      }
    }

    System.out.println(ans);
  }

  static long inv(long v) {
    return pow(v, (int) MOD - 2);
  }

  static long pow(long b, int p) {
    if (p == 0) return 1;
    if (p == 1) return b;
    long ret = pow(b, p / 2);
    ret *= ret;
    ret %= MOD;
    if (p % 2 == 1) {
      ret *= b;
      ret %= MOD;
    }
    return ret;
  }

}


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

using namespace std;

int main(void){

	int n;

	cin >> n;
	
	vector<int> num(n);

	long long sum=0;

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

	

	cout << *min_element(num.begin(), num.end()) << " ";

	cout << *max_element(num.begin(), num.end()) << " ";	

	cout << sum << endl;

	return 0;
}


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

int count_keta(int num){
  int keta = 0;
  while(num != 0){
    keta++;
    num /= 10;
  }
  
  return keta;
}

int main(){
  int n;
  int result = 0;
  
  cin >> n;
  
  for(int i = 1; i <= n; i++){
    if(count_keta(i) % 2 == 1){
      result++; 
    }
  }
  
  cout << result << endl;
  
}

Measured memory_bytes: 256
A, B, C, D = map(int, input().split())
Alice = [A,B]
Bob = [C,D]
array = [Alice,Bob]
array.sort()
if array[0][1] <= array[1][0]:
    print(0)
elif array[1][1] <= array[0][1]:
    print(array[1][1]-array[1][0])
else:
    print(array[0][1]-array[1][0])

Measured memory_bytes: 3064
#!python3

import sys
sys.setrecursionlimit(10 ** 6)


def LI():
    return list(map(int, input().split()))

# input
N = int(input())
UVW = [LI() for _ in range(N - 1)]


# params
link = [[] for _ in range(N)]
for u, v, w in UVW:
    u -= 1
    v -= 1
    link[u].append((v, w))
    link[v].append((u, w))


def dfs(ans, x):
    for y, w in link[x]:
        if ans[y] is None:
            if w % 2 == 0:
                ans[y] = ans[x]
            else:
                ans[y] = 0 if ans[x] else 1
            dfs(ans, y)


def main():
    ans = [None] * N
    ans[0] = 0
    dfs(ans, 0)
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 97772
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>

typedef long long ll;
#define rep(i,n) for(ll i = 0; i < n; i++)

using namespace std;

int main(){
	/****input****/
	string s;
	cin >> s;

	/****calc****/
	string key;
	int len = s.length();

	rep(i,len){
		if(s[i] != s[len-i-1]){
			cout << "No" << endl;
			return 0;
		}
	}
	int mid = len / 2;
	rep(i,mid){
		if(s[i] != s[mid-i-1]){
			cout << "No" << endl;
			return 0;
		}
	}

	/****output****/
	cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;	
  string a;
  int i,ans=0,sum=0;
  cin>>n>>a;	
  for(i=0;i<n;i++)
  {
    if(a[i]=='D')
	  ans--;
    else
      ans++;
    sum=max(ans,sum);  
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define MOD 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define all(c) (c).begin(),(c).end()
#define ss second
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> > 
#define vvpi vector<vector<pair<int,int> > >
#define Inp(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define Out(a,n,ch) for(int i=0;i<n;i++)cout<<a[i]<<ch;cout<<endl;

int a[200005];
int32_t main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	
	
	string s,t;
	cin>>s>>t;
	int mx=0;
	for(int i=0;i<s.size()-t.size()+1;i++)
	{
		int len=0;
		for(int j=0;j<t.size();j++)
		{
			if(s[i+j]==t[j])
				len++;
		}
		mx = max(len,mx);
		
	}
	cout<<t.size()-mx<<endl;

	
	return 0;
}


Measured memory_bytes: 3648
#include<iostream> 
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int x;cin>>x;
	if(x%10==3) cout<<"bon"<<endl;
	else if(x%10==0||x%10==1||x%10==6||x%10==8) cout<<"pon"<<endl;
	else cout<<"hon"<<endl;
	return 0;
}

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

int main() {
	int h,w;
	cin>>h>>w;
	char a[h][w];
	for(int i=0;i<h;i++)for(int j=0;j<w;j++) cin>>a[i][j];
	for(int i=0;i<=h+1;i++)
	{
		for(int j=0;j<=w+1;j++)
		{
			if(i==0||j==0||i==h+1||j==w+1) cout<<"#";
			else cout<<a[i-1][j-1];
			if(j==w+1) cout<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn
object Main extends App {
  val List(n,m) = StdIn.readLine().split(" ").map(_.toInt).toList
  var a = new scala.collection.mutable.PriorityQueue[Long]()
  StdIn.readLine().split(" ").foreach(n => a += n.toLong)
  for (i <- 0 to m-1) a += a.dequeue() / 2
  println(a.toArray.sum)
}


Measured memory_bytes: 59048
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		double debt=100000;
		for(int i=0;i<n;i++){
			debt=debt+debt*0.05;
			debt=Math.ceil(debt/1000)*1000;
		}
		System.out.println((int)debt);
	}
}

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

using namespace std;

int n,m,ans,A,B,BA,a[120000];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%d",a+i);
	}
	sort(a+1,a+n+1);
	ans=-a[1]+a[n]; for (int i=2;i<n;++i) ans+=abs(a[i]);
	printf("%d\n",ans);
	int x=a[1],y=a[n];
	for (int i=2;i<n;++i)
		if (a[i]<0){printf("%d %d\n",y,a[i]); y-=a[i];}
		else{printf("%d %d\n",x,a[i]); x-=a[i];}
	printf("%d %d\n",y,x);
	
	return 0;
}
			

Measured memory_bytes: 2304
#include <stdio.h>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	
	if(a==1 && b==2){
		printf("3");
	}
	
	if(a==2 && b==3){
		printf("1");
	}
	
	if(a==3 && b==1){
		printf("2");
	}
	
	if(b==1 && a==2){
	    printf("3");
	}
	
	if(b==2 && a==3){
		printf("1");
	}
	
	if(b==3 && a==1){
		printf("2");
	}

	return 0;
	
}

Measured memory_bytes: 1596
import java.util.*;
public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] p = new int[n];
    for (int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }
    
    int ans = 0;
    for (int i = 2; i < n; i++) {
      int p1 = p[i-2];
      int p2 = p[i-1];
      int p3 = p[i];
      if (p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1) {
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

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

struct DisjointSet
{
    vector<int> parent, rank, size;
    DisjointSet(int n) : parent(n), rank(n, 1), size(n, 1)
    {
        iota(parent.begin(), parent.end(), 0);
    }
    int find(int u)
    {
        if (u == parent[u]) return u;
        return parent[u] = find(parent[u]);
    }
    void merge(int u, int v)
    {
        u = find(u); v = find(v);
        if (u == v) return;

        if (rank[u] > rank[v]) swap(u, v);
        parent[u] = v;
        size[v] += size[u];
        if (rank[u] == rank[v]) rank[v]++;
    }
};

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

    int n, m; cin >> n >> m;
    DisjointSet ds(n);
    for (int i = 0; i < m; i++)
    {
        int s, e; cin >> s >> e;
        ds.merge(s-1, e-1);
    }

    vector<int> v;
    for (int i = 0; i < n; i++)
    {
        if (ds.parent[i] != i) continue;
        v.push_back(ds.size[i]);
    }

    int result = *max_element(v.begin(), v.end());
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 6516
import java.util.*;

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

		for (int i = 0; i < N; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			++counter[a[i]];
			--counter[b[i] + 1];
		}
		int ans = 0;
		for (int i = 1; i < counter.length; ++i) {
			counter[i] += counter[i - 1];
			if (counter[i] + 1 >= i)
				ans = Math.max(ans, i - 1);
		}
		System.out.println(ans);

	}
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  int ans = 0;
  for (int i = 0; i < 2; i++)
  {
    if (a >= b)
    {
      ans += a;
      a--;
    }
    else
    {
      ans += b;
      b--;
    }
  }
  
  cout << ans << endl;
}

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

int main() {
  int x;
  cin >> x;
  while(true){
    for(int i =1; i <=1000;i++){
      for(int j = 2; j <= 10; j++){
        if(pow(i,j) == x){
          cout << x << endl;
          return 0;
        }
      }
    }
    x--;
  }
 } 


Measured memory_bytes: 4152
#include <stdio.h>

void selection_sort(int *a, int *a_str, int n) {
    int i, j, tmp1, tmp2, mini;

    for (i=0;i<n;i++) {
        mini=i;
        for (j=i;j<n;j++) {
            if (a[j]<a[mini]) {
                mini=j;
            }
        }
        tmp1=a[i];
        a[i]=a[mini];
        a[mini]=tmp1;
        tmp2=a_str[i];
        a_str[i]=a_str[mini];
        a_str[mini]=tmp2;
        // if (i!=mini) count++;
    }
    // return count;
}

void bubble_sort(int *a, int *a_str, int m) {
    int i, j, tmp1, tmp2;

    for (i=0;i<m;i++) {
        for (j=m-1; j>i; j--) {
            if (a[j]<a[j-1]) {
                tmp1=a[j];
                tmp2=a_str[j];
                a[j]=a[j-1];
                a_str[j]=a_str[j-1];
                a[j-1]=tmp1;
                a_str[j-1]=tmp2;
                // n++;
            }
        }
    }

    // return n;
}

void stable(int *a_str, int *a, int *b_str, int *b, int n) {
    int i, check=1;

    for (i=0; i<n; i++) {
            if (a[i]==b[i] && a_str[i]!=b_str[i]) check=0;
    }

    for (i=0;i<n;i++) {
        printf("%c%c", b_str[i], b[i]);
        if (i<n-1) printf(" ");
    }
    printf("\n");
    if (check==1) printf("Stable\n");
    else printf("Not stable\n");
}

int main(void) {
    int i, n, B_str[36], B[36], S_str[36], S[36];
    char str[3]={'\0'};

    scanf("%d", &n);
    for (i=0;i<n;i++) {
        scanf("%s", str);
        // printf("%s\n", str);
        B_str[i]=str[0];
        S_str[i]=str[0];
        B[i]=str[1];
        S[i]=str[1];
    }
    bubble_sort(B, B_str, n);
    selection_sort(S, S_str, n);
    stable(B_str, B, B_str, B, n);
    stable(B_str, B, S_str, S, n);

    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int main(void){
    int N;
    cin >> N;
    map<int, int> all;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        all[a]++;
    }
    int ans = 0;
    auto begin = all.begin(), end = all.end();
    for(auto ite = begin; ite != end; ite++){
        int x = ite->first, y = ite->second;
        if(y >= x){
            ans += min(y-x, y);
        }else{
            ans += y;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int> 
#define rep(a,n) for(int i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int n,vin &a){
    rep(0,n){
        cin>>a.at(i);
    } 
} 

int power(int N,int cnt){
    int res=1;
    N%=INF;
    while(cnt>0){
        res*=N;
        res%=INF;
        cnt--;
    }
    return res;
}

signed main() {
    int N;
    cin>>N;
    vin A(N);
    fin(N,A);

    vin cnt(N/2,0);
    if(N%2==1){
        cnt.push_back(0);
    }


    rep(0,N){
        cnt.at(A.at(i)/2)++;
    }

    // rep(0,cnt.size()){
    //     cout<<cnt.at(i)<<" ";
    // }

    bool ok=false;
    rep(0,cnt.size()){
        if(i==0){
            if(N%2==1){
                if(cnt.at(i)==1){
                    ok=true;
                    continue;
                }
                else{
                    ok=false;
                    break;
                }
            }
            else{
               if(cnt.at(i)==2){
                   ok=true;
                    continue;
                }
                else{
                    ok=false;
                    break;
                } 
            }
        }
        else{
            if(cnt.at(i)==2){
                ok=true;
                continue;
            }
            else{
                ok=false;
                break;
            }
        }
    }

    if(ok){
        cout<<power(2,N/2)<<endl;
    }
    else{
        cout<<0<<endl;
    }

return 0;
}

Measured memory_bytes: 1536
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 340
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod=1000000007;
const ll inf=1e18;
const ld pai=acos(-1);
ll n;
ll a[19][19];
ll dp[(1<<16)+9];
ll cost[(1<<16)+9];
ll calc(ll mask){
	ll sum=0;
	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			if((mask&(1<<i)) && (mask&(1<<j))){
				sum+=a[i][j];
			}
		}
	}
	return sum;
}
int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	for(ll i=0;i<(1<<n);i++)cost[i]=calc(i);
	for(ll i=1;i<(1<<n);i++){
		for(ll j=i;j;j=(j-1)&i){
			dp[i]=max(dp[i],dp[i^j]+cost[j]);
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<stack>

using namespace std;

int main()
{
    stack<int> track;
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n) track.push(n);
        else
        {
            printf("%d\n",track.top());
            track.pop();
        }
    }
    return 0;
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    map<int,int> ma;
    REP(i,n){
        int t;
        cin>>t;
        t--;
        ma[t]=i+1;
    }
    set<int> se;
    se.insert(0);
    se.insert(n+1);
    ll ans=0;
    REP(i,n){
        auto itr1=se.upper_bound(ma[i]);
        itr1--;
        auto itr2=se.upper_bound(ma[i]);
        ans+=1ll*abs(*itr1-ma[i])*abs(*itr2-ma[i])*(i+1);
        se.insert(ma[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 18944
n,m = map(int,input().split())
A = []
for _ in range(m):
    a,b = input().split()
    tmp = [int(a),b]
    A.append(tmp)
dict = {}
for a in A:
    dict.update({a[0]:[False,0]})
for a in A:
    if dict[a[0]][0] == False:
        if a[1] == "WA":
            dict[a[0]][1] += 1
        else:
            dict[a[0]][0] = True
wa = 0
ac = 0
for i in dict:
    if dict[i][0]:
        ac += 1
        wa += dict[i][1]
print("{} {}".format(ac,wa))

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int r, g, b;
    cin >> r >> g >> b;
    int num = r * 100 + g * 10 + b;
    if (num % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

int main() {
    long long K;
    scanf("%lld", &K);
    ll c = 0;
    ll ten[13];
    ten[0] = 1;
    repn(i, 12) { ten[i] = ten[i - 1] * 10; }
    vector<ll> v[13][10];
    v[0][0].emplace_back(0);
    rep(i, 13) {
        rep(j, 10) {
            if (i == 0 && j > 0) {
                v[i][j].emplace_back(j);
                c++;
                if (c == K) {
                    cout << j << endl;
                    return 0;
                }
            } else if (j != 0) {
                if (j - 1 >= 0) {
                    rep(k, (ll)v[i - 1][j - 1].size()) {
                        v[i][j].emplace_back(j * ten[i] + v[i - 1][j - 1][k]);
                        c++;
                        if (c == K) {
                            cout << j * ten[i] + v[i - 1][j - 1][k] << endl;
                            return 0;
                        }
                    }
                }
                rep(k, (ll)v[i - 1][j].size()) {
                    v[i][j].emplace_back(j * ten[i] + v[i - 1][j][k]);
                    c++;
                    if (c == K) {
                        cout << j * ten[i] + v[i - 1][j][k] << endl;
                        return 0;
                    }
                }
                if (j + 1 < 10) {
                    rep(k, (ll)v[i - 1][j + 1].size()) {
                        v[i][j].emplace_back(j * ten[i] + v[i - 1][j + 1][k]);
                        c++;
                        if (c == K) {
                            cout << j * ten[i] + v[i - 1][j + 1][k] << endl;
                            return 0;
                        }
                    }
                }
            } else if (j == 0 && i - 1 >= 0) {
                rep(k, 2) {
                    rep(l, (ll)v[i - 1][k].size()) {
                        v[i][j].emplace_back(j * ten[i] + v[i - 1][k][l]);
                        // cout << c << " " << j * ten[i] + v[i - 1][k][l] <<
                        // endl;
                    }
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 1280
def main():
    N = int(input())
    A = list(map(int, input().split()))
    colors = [0] * 9
    for i in range(N):
        c = min(A[i] // 400, 8)
        colors[c] += 1
    tmp = 0
    for i in range(8):
        if colors[i] >= 1:
            tmp += 1
    mn = max(tmp, 1)
    mx = tmp + colors[8]
    print(mn, mx)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#!/usr/bin/env python3
# -*- coding: utf-8-*-
if __name__ == '__main__':
    a = []
    for _ in range(5):
        a.append(int(input()))
    k = int(input())
    for i in range(5):
        for j in range(i+1, 5):
            if abs(a[i] - a[j]) > k:
                print(":(")
                exit()
    print("Yay!")


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

int main(){
    list<int> a;
    int q; cin >> q;
    auto itr = a.end();
    int m , n;
    rep(i ,q){
        cin >> m;
        if( m == 0 ) {
            cin >> n;
            a.insert( itr, n);
            --itr;
        } else if ( m == 1 ){
            cin >> n;
            if(n < 0) {
                rep(j , abs(n)) --itr;
            } else {
                rep(j , n) ++itr;
            }
        } else {
            itr = a.erase(itr);
        }
    }
    for( auto x : a )
        cout << x << endl;
}


Measured memory_bytes: 18636
#include <iostream>

using namespace std;

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

    int h, w; cin >> h >> w;
    int arr[h + 1][w + 1]{};
    for(int i = 1; i <= h; ++i) for(int j = 1; j <= w; ++j)
    {
        char c; cin >> c;
        if(c == '.') arr[i][j] = 0;
        else arr[i][j] = 1;
    }

    int dp[h + 1][w + 1];
    for(int i = 0; i <= h; ++i) dp[i][0] = (int)1e9;
    for(int i = 0; i <= w; ++i) dp[0][i] = (int)1e9;
    dp[1][1] = 0;
    for(int i = 1; i <= h; ++i) for(int j = 1; j <= w; ++j)
    {
        if(i == 1 && j == 1) continue;
        dp[i][j] = min(dp[i - 1][j] + (arr[i - 1][j] != arr[i][j] ? 1 : 0),
                       dp[i][j - 1] + (arr[i][j - 1] != arr[i][j] ? 1 : 0));
    }
    if(!arr[1][1] && !arr[h][w]) cout << dp[h][w] / 2;
    else if(arr[1][1] && arr[h][w]) cout << dp[h][w] / 2 + 1;
    else cout << (dp[h][w] + 1) / 2;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int n,a,b,result=0;cin>>n>>a>>b;
  rep(i,n+1){
    int t=i%10+i/10%10+i/100%10+i/1000%10+i/10000;
//    if( a<=t && t<=b )cout<<i<<' '<<t<<endl;

    if( a<=t && t<=b )result+=i;
  }

  cout<<result;
  return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
        PROGRAM-ID. AtCoder.
      
        ENVIRONMENT DIVISION.
      
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 INP PIC X(100).
        01 A PIC 9(15).
        01 B PIC 9(15).
        01 C PIC ZZZZZZZZZ.
      	01 t PIC 9(15).
	    01 temp1 PIC 9(15).
        01 temp2 PIC 9(15).
        01 N PIC 9(15).
      
        PROCEDURE DIVISION.
      	MAIN.
			ACCEPT A.
      		COMPUTE C = A * A.
			DISPLAY C.
		STOP RUN.

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	auto start = high_resolution_clock::now(); 

	int vec[] = {0, 0 , 0, 0};
	int flag = 1;

	for(int i = 0 ; i < 3 ; i++){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		vec[a]++;
		vec[b]++;

		if(vec[a] > 2 || vec[b] > 2 )
			flag = 0;
	}

	if(flag == 1)
		cout << "YES";
	else
		cout << "NO";
	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

typedef long long ll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string a;
	
	cin >> a;
	
	int size = a.size();
	
	bool flag1 = false;
	bool flag2 = false;
	
	if (size % 2 == 1) flag1 = true;
	if (a[0] != a[size - 1]) flag2 = true;
	
	if (flag1 && flag2) {
		cout << "First" << endl;
	} else if (flag1 || flag2) {
		cout << "Second" << endl;
	} else {
		cout << "First" << endl;
	}
	
	
	return 0;
	
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

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){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

struct StronglyConnectedComponents{
    vector<vector<int>> g;
    vector<vector<int>> to,from;
    vector<int> comp,order,used;
    StronglyConnectedComponents(vector<vector<int>> &g):
    g(g),to(g.size()),from(g.size()),comp(g.size(),-1),used(g.size()){
        for(int i=0;i<g.size();i++){
            for(auto x:g[i]){
                to[i].push_back(x);
                from[x].push_back(i);
            }
        }
    }
    int operator[](int k){
        return comp[k];
    }
    void dfs(int now){
        if(used[now]) return ;
        used[now]=true;
        for(int x:to[now])dfs(x);
        order.push_back(now);
    }
    void rdfs(int now,int cnt){
        if(comp[now]!=-1) return ;
        comp[now]=cnt;
        for(int x:from[now]) rdfs(x,cnt);
    }
    vector<vector<int>> build(){
        vector<vector<int>> t;
        for(int i=0;i<to.size();i++) dfs(i);
        reverse(order.begin(),order.end());
        int ptr=0;
        for(int i:order)if(comp[i]==-1)rdfs(i,ptr),ptr++;
 
        t.resize(ptr);
        for(int i=0;i<g.size();i++){
            for(auto v:to[i]){
                int x=comp[i],y=comp[v];
                if(x==y) continue;
                t[x].push_back(y);
            }
        }
        return t;
    }
};

signed main(){
    int n,m;cin>>n>>m;
    vector<vector<int>> g(n);
    rep(i,m){
        int u,v;cin>>u>>v;
        g[u].push_back(v);
    }

    StronglyConnectedComponents scc(g);
    auto t=scc.build();
    vector<vector<int>> belong(t.size());
    rep(i,n)belong[scc[i]].push_back(i);
    cout<<belong.size()<<endl;
    rep(i,belong.size()){
        cout<<belong[i].size();
        for(auto u:belong[i]) cout<<" "<<u;
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 146420
#include<stdio.h>
int main()
{
    int N;
    int b=0,sum=0;
    scanf("%d",&N);
    int M=N;
    while(M)
    {
        sum+=M%10;
        M=M/10;
    }
    if(N%sum==0)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**5+10)
N, M, K = map(int,input().split())
class UnionFind:
    def __init__(self, N):
        self.par = [-1 for i in range(N+1)]
        self.rank = [1]*(N+1)
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] > self.rank[y]:
            self.par[x] += self.par[y]
            self.par[y] = x
        else:
            self.par[y] += self.par[x]
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

UF = UnionFind(N)
friendlist = [[] for _ in range(N+1)]
for n in range(M):
    A, B = map(int,input().split())
    friendlist[A].append(B)
    friendlist[B].append(A)
    if not UF.same_check(A,B):
        UF.union(A, B)
blocklist = [[] for _ in range(N+1)]
for n in range(K):
    C, D = map(int, input().split())
    blocklist[C].append(D)
    blocklist[D].append(C)

for person in range(1,N+1):
    root = UF.find(person)
    ans = -UF.par[root]-1
    ans -= len(friendlist[person])
    for l in blocklist[person]:
        if UF.same_check(person,l):
            ans -= 1
    print(ans)

Measured memory_bytes: 55104
#include <cstdio>

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

	int i;
	unsigned int a[n];
	unsigned int allxor = 0;

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		allxor ^= a[i];
	}

	for (i = 0; i < n; i++) {
		printf("%d ", allxor ^ a[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 3240
using System;
using System.Text.RegularExpressions;

namespace Small_Large_orEqual{
	class class1{
		static void Main(string[] args){
			string input = Console.ReadLine();
			Match m = Regex.Match(input,@"(?<a>-?\d+) (?<b>-?\d+)$");
			int a = int.Parse(m.Groups["a"].Value),b=int.Parse(m.Groups["b"].Value);
			if(a < b){
				Console.Write("a < b\n");
			}
			else if(a > b){
				Console.Write("a > b\n");
			}
			else{
				Console.Write("a == b\n");
			}
			
		}
	}
}

Measured memory_bytes: 11584
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>  
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=300000+10,M=100000+10;

int n,m;
struct node { int l,r; } a[N];
bool operator <(node a,node b) { return a.r-a.l<b.r-b.l; }

int c[M];
inline void add(int x,int y) { for (;x<=m;x+=x&-x) c[x]+=y; }
inline int sum(int x) { int s=0; for (;x;x-=x&-x) s+=c[x]; return s; }

int main() {
    n=read(),m=read();
    for (re int i=1;i<=n;++i) a[i].l=read(),a[i].r=read();
    sort(a+1,a+n+1);
    for (re int i=1,p=0;i<=m;++i) {
        while (p<n&&a[p+1].r-a[p+1].l+1<=i)
            ++p,add(a[p].l,1),add(a[p].r+1,-1);
        int ans=0;
        for (re int j=i;j<=m;j+=i) ans+=sum(j);
        printf("%d\n",ans+n-p);
    }
    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  int N; cin >> N; bool flag = false;
  for(int i = 0; i < N; i++){
    char c; cin >> c; 
    if( c == 'Y'){flag = true;}}
 if(flag){cout << "Four" << endl;}
  else{cout << "Three" << endl;}
  
  return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<string,long long> m;
long long n,ans;
string s,s1[100005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		for(int j=0;j<10;j++)
			for(int k=1;k<10;k++)
				if(s[j]>s[k]) swap(s[j],s[k]);
		m[s]++;
		s1[i]=s;
	}
	for(int i=1;i<=n;i++)
	{
		if(m[s1[i]])
		{
			ans+=m[s1[i]]*(m[s1[i]]-1)/2;
			m[s1[i]]=0;
		}
	}
	cout<<ans;
	return 0;
 } 

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

string num, t = "";
int k, n;

long long rec (int j, int cnt) {
	if (cnt == k)
		return t <= num;
	long long res = 0LL;
	for (int i = j; i < n; ++i) {
		if (t[i] == '0') {
			for (char c = '1'; c <= '9'; ++c) {
				t[i] = c;
				res += rec(i + 1, cnt + 1);
				t[i] = '0';
			}
		}
	}
	return res;
}

signed main () {
	cin >> num >> k;
	n = num.size();
	t = string(n, '0');
	cout << rec(0, 0) << '\n';
}


Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;
use std::char;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>() -> (T, S) {
    let a = read();
    let b = read();
    (a, b)
}

fn toChr(n:u32) -> char {
    char::from_u32(n + 97).unwrap()
}

fn getKetaAndIndex(n:u64) -> (u64, u64) {
    let mut keta = 1;
    let mut index = n;
    loop {
        let currentMax = 26_u64.pow(keta as u32);
        if currentMax - 1 >= index {
            return (keta, index);
        } else {
            keta += 1;
            index = index - currentMax;
        }
    }
}

fn solve(n:u64) -> String {
    let (keta, index) = getKetaAndIndex(n);
    let mut v = index;
    let mut ans = String::new();
    for i in (1..keta+1) {
        let a = v % 26;
        ans.push(toChr(a as u32));
        v = v / 26;
    }
    ans.chars().rev().collect()
}



fn main() {
    let n:u64 = read();
    println!("{}", solve(n - 1));
}


Measured memory_bytes: 2156
from collections import deque



q = int(input())

A = deque([])

for _ in range(q):
    
    command, *list_num = input().split()

    if   command == "0":
        if   list_num[0] == "0":
            A.appendleft(int(list_num[1]))
        elif list_num[0] == "1":
            A.append(int(list_num[1]))
        else:
            raise
    elif command == "1":
        print(A[int(list_num[0])])
    elif command == "2":
        if   list_num[0] == "0":
            A.popleft()
        elif list_num[0] == "1":
            A.pop()
        else:
            raise
    else:
        raise



Measured memory_bytes: 21856