akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int N,M,Q,S[400010],T[400010];
ll sum = 0,dist[4001][4001],C[400010];
vector<vector<int>> mst(4010);
int visited[4010] = {0};

int p[4010] = {0},r[4010] = {0};
void init(int N){
	for(int i=0;i<=N;++i) p[i] = i;
}

int root(int a){
	if(p[a] == a) return a;
	return (p[a] = root(p[a]));
}

bool is_same_set(int a,int b){
	return root(a) == root(b);
}

void unite(int a, int b){
	a = root(a);
	b = root(b);
	if(a==b) return;
	if(r[a]<r[b]){
		p[a] = b;
	}else{
		p[b] = a;
		if(r[a] == r[b]) r[a]++;
	}
}

void dfs(int s,int n,ll cost){
	visited[n] = 1;
	for(int i=0;i<mst[n].size();i++){
		int t = mst[n][i];
		if(visited[t]==0){
			ll ma = max(cost,dist[n][t]);
			dist[s][t] = ma;
			dist[t][s] = ma;
			dfs(s,t,ma);
		}
	}
}

int main(){
	cin >> N >> M;
	init(N);
	vector<pair<ll,int>> v;
	for(int i=0;i<M;i++){
		cin >> S[i] >> T[i] >> C[i];
		dist[S[i]][T[i]] = C[i];
		dist[T[i]][S[i]] = C[i];
		v.push_back({C[i],i});
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		int t = v[i].second;
		if(!is_same_set(S[t],T[t])){
			sum += C[t];
			unite(S[t],T[t]);
			mst[S[t]].push_back(T[t]);
			mst[T[t]].push_back(S[t]);
		}
	}
	for(int i=1;i<=N;i++){
		dfs(i,i,0);
		for(int j=1;j<=N;j++) visited[j] = 0;
	}
	cin >> Q;
	int a,b;
	for(int i=0;i<Q;i++){
		cin >> a >> b;
		cout << sum-dist[a][b] << endl;
	}
}

Measured memory_bytes: 141676
#include<stdio.h>
#include<stdlib.h>
 
int main(int argc,char** argv)
{
	int a, b, x, y;
	scanf("%d%d",&a, &b);
	x = a + b;
	y = x / 2;
	if(x % 2 > 0){
		y++;
	}
	printf("%d\n",y);
	return(0);
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
import copy
line = sys.stdin.readline() 
line = line.rstrip('\r\n')
face = line.split()

line = sys.stdin.readline() 
line = line.rstrip('\r\n')
face2 = line.split()


for i in range(5):
    if face[1] == face2[1]:
        break
    face_old = copy.deepcopy(face)
    face[0] = face_old[1]
    face[1] = face_old[5]
    face[2] = face_old[2]
    face[3] = face_old[3]
    face[4] = face_old[0]
    face[5] = face_old[4]
else:
    face_old = copy.deepcopy(face)
    face[0] = face_old[3]
    face[1] = face_old[1]
    face[2] = face_old[0]
    face[3] = face_old[5]
    face[4] = face_old[4]
    face[5] = face_old[2]
for i in range(5):
    if face[1] == face2[1]:
        break
    face_old = copy.deepcopy(face)
    face[0] = face_old[1]
    face[1] = face_old[5]
    face[2] = face_old[2]
    face[3] = face_old[3]
    face[4] = face_old[0]
    face[5] = face_old[4]
for i in range(5):
    if face[0] == face2[0]:
        break
    face_old = copy.deepcopy(face)
    face[0] = face_old[3]
    face[1] = face_old[1]
    face[2] = face_old[0]
    face[3] = face_old[5]
    face[4] = face_old[4]
    face[5] = face_old[2]

if face == face2:
    print("Yes")
else:
    print("No")



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

int main()
{
  int i,n,x;
  cin>>n;

  for(i=1;i<n+1;i++){
    x=i;
    if(x%3==0){
      cout<<" "<<i;
    }else{
      while(x>0){
        if(x%10==3){
          cout<<" "<<i;
          break;
        }else{
          x /= 10;
        }
      }
    }
  }
  cout<<endl;

  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node  find(Node u,int k){
  while(u!=NIL && k!=u->key){
    if(k < u->key)u=u->left;
    else u=u->right;
  }
return u;
}
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else{
    if(z->key < y->key) y->left = z;
  else y->right = z;
  }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if(com[0]=='f'){
      scanf("%d",&x);
      Node t = find(root, x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
       }
  }

  return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    for(int i = 0; i < N - 1; i++) cin >> C[i];
    int ans = 0;
    for(int i = 0; i < N; i++ ){
        ans += B[A[i] - 1];
        if(i < N - 1 && A[i + 1] == A[i] + 1) ans += C[A[i] - 1];
    }
    cout << ans << endl;
    cin >> N;
    return 0;
}

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

/*  using namespace  */
using namespace std;

/*  local var  */
string s;

/*  define  */
#define loop(i,j) for(int i = 0; i < j; i++)
#define scan1(d) scanf("%d",&d);
#define scan2(a,b) scanf("%d %d",&a,&b);

/*  typedef  */
//None

/*  main program  */
int main()
{
	cin>>s;
	loop(i,s.size())if(i==3)cout<<8;
	else cout<<s[i];
	cout<<endl;
}


Measured memory_bytes: 256
import numpy as np
N, K = map(int, input().split())
M = 10**9+7
xs = []
for _ in range(N):
    xs.append(list(map(int, input().split())))
X = np.array(xs, dtype="object")
S = np.ones(N, dtype="object")
#Xs = [X]
for _ in range(60):
#    Xs.append(np.dot(Xs[-1],Xs[-1])%M)
    if K%2:
        S = np.dot(X, S)%M
    K = K//2
    X = np.dot(X, X)%M
S = np.array(S, dtype="int64")
r = 0
for s in S:
    r = (r + s)%M
print(r)


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

int main() {
  int n;
  int sum, max = 0;
  string s;
  string x, y;
  cin >> n >> s;

  for (int k = 0; k < (int)s.size(); k++) {
    sum = 0;
    x = s.substr(0, k);
    y = s.substr(k, (int)s.size() - 1);
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    y.erase(unique(y.begin(), y.end()), y.end());
    for (int l = 0; l < (int)x.size(); l++) {
      for (int m = 0; m < (int)y.size(); m++) {
        if (x[l] == y[m]) sum++;
      }
    }
    if (max < sum) max = sum;
  }
  cout << max << endl;
}

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

int maximum(int x) {
    return ceil(x / 10.0) * 10;
}

int remained(int x) {
    return maximum(x) - x;
}

int main() {
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    int sum = maximum(A) + maximum(B) + maximum(C) + maximum(D) + maximum(E);
    sum -= max({remained(A),remained(B),remained(C),remained(D),remained(E)});
    cout << sum << endl;

}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        long ans = K;
        for (int i = 1; i < N; i++) {
            ans = ans * (K-1);
        }
        System.out.println(ans);
    }
}

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

int ctoi(char c){
  if(c>='0'&&c<='9'){
    return c-'0';
  }
  return 0;
}

int main(){
  string s;
  cin>>s;
  int vecb[s.size()];
  ll ans=0;
  ll q=0;
  for(int bit=0;bit<(1<<s.size()-1);bit++){
    for(int i=0;i<s.size()-1;i++){
      if(bit&(1<<i)){
        vecb[i]=1;
      }
      else{
        vecb[i]=0;
      }
    }
    q=0;
    for(int i=0;i<s.size();i++){
      if(i==s.size()-1){
        q*=10;
        q+=ctoi(s[s.size()-1]);
        ans+=q;
        break;
      }
      if(vecb[i]==0){
        q*=10;
        q+=ctoi(s[i]);
      }
      else{
        q*=10;
        q+=ctoi(s[i]);
        ans+=q;
        q=0;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

const int msg_size = 80;
const char int2alp[26] = {
	'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
	'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
	'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
	'y', 'z'
};

typedef map<char, int> myMap;
myMap alp2int;

int get_length(char *data) {
	for (int i = 0;; i++) {
		if (data[i] == '\0') {
			return i;
		}
	}
}

bool is_match(char *data) {
	for (int i = 0; i < 81; i++) {
		if (data[i] == 't' && data[i+1] == 'h') {
			if (data[i+2] == 'e') {
				return true;
			}
			else if (data[i+2] == 'i' && data[i+3] == 's'){
				return true;
			}
			else if (data[i+2] == 'a' && data[i+3] == 't') {
				return true;
			}
		}
	}
	return false;
}

bool gen_caesar(char *data, int size, int length) {
	char prev[100], back[100];
	prev[length] = back[length] ='\0';
	for (int i = 0; i < length; i++) {
		if (data[i] == ' ' || data[i] == '.' || data[i] == '\n') {
			prev[i] = data[i];
			back[i] = data[i];
		}
		else {
			prev[i] = int2alp[(alp2int[data[i]]+size) % 26];
			back[i] = int2alp[(alp2int[data[i]] >= size) ? alp2int[data[i]]-size : 26-(size-alp2int[data[i]])];
		}
	}
	if (is_match(prev)) {
		printf("%s", prev);
		return true;
	}
	if (is_match(back)) {
		printf("%s", back);
		return true;
	}
	return false;
}

void init_alp2int() {
	alp2int.insert(myMap::value_type('a', 0));
	alp2int.insert(myMap::value_type('b', 1));
	alp2int.insert(myMap::value_type('c', 2));
	alp2int.insert(myMap::value_type('d', 3));
	alp2int.insert(myMap::value_type('e', 4));
	alp2int.insert(myMap::value_type('f', 5));
	alp2int.insert(myMap::value_type('g', 6));
	alp2int.insert(myMap::value_type('h', 7));
	alp2int.insert(myMap::value_type('i', 8));
	alp2int.insert(myMap::value_type('j', 9));
	alp2int.insert(myMap::value_type('k', 10));
	alp2int.insert(myMap::value_type('l', 11));
	alp2int.insert(myMap::value_type('m', 12));
	alp2int.insert(myMap::value_type('n', 13));
	alp2int.insert(myMap::value_type('o', 14));
	alp2int.insert(myMap::value_type('p', 15));
	alp2int.insert(myMap::value_type('q', 16));
	alp2int.insert(myMap::value_type('r', 17));
	alp2int.insert(myMap::value_type('s', 18));
	alp2int.insert(myMap::value_type('t', 19));
	alp2int.insert(myMap::value_type('u', 20));
	alp2int.insert(myMap::value_type('v', 21));
	alp2int.insert(myMap::value_type('w', 22));
	alp2int.insert(myMap::value_type('x', 23));
	alp2int.insert(myMap::value_type('y', 24));
	alp2int.insert(myMap::value_type('z', 25));
}

int main(int argc, char *argv[]) {
	init_alp2int();
	char rcv[100];
	
	while(NULL != fgets(rcv, 80, stdin)) {
		int length = get_length(rcv);
	
		for (int i = 0; i < 26; i++) {
			if (gen_caesar(rcv, i, length)) {
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pi pair<ll,ll>
using namespace std;
int main(){
	//	freopen("in.txt","r",stdin);
	int H,W;
	char C[110][110];
	cin >> H >> W;
	for (int i = 0; i < H; ++i)
	{
		scanf("%s",C[i]);
	}
	for (int i = 0; i < H; ++i)
	{
		printf("%s\n",C[i]);
		printf("%s\n",C[i]);
	}
	return 0;
}

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

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

int main() {
    int x,n;cin>>x>>n;
    int tmp;
    int a[105];
    rep(i,105){
        a[i] = i - 1;
    }
    rep(i,n){
        cin>>tmp;
        a[tmp+1]=999;
    }
    
    int ans = 999;
    int ans2 = 999;
    rep(i, 105){
        if(abs(a[i]-x) < ans){
            ans2 = i - 1;
            ans = abs(a[i]-x);
        }
    }
    cout<<ans2<<endl;
	return 0;
}

Measured memory_bytes: 3636
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  string S;
  cin >> S;
  int ans = 0;
  for(int i= 0; i<4;i++){
    if(S[i] == '+'){
      ans++;
    } else {
      ans--;
    }
  }

  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++)
int main() {
  int N;
  string S;
  cin>>N;
  
  rep(i,N){
    cin>>S;
    if(S=="Y"){N=0;break;}
}
if(N==0){cout<<"Four"<<endl;}
  else{cout<<"Three"<<endl;}
}

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

int main() {
  
  int64_t N, M; cin >> N >> M; int64_t ans = 0;
  
  vector<pair<int64_t, int64_t>> vec(N);
  
  for (int i = 0; i < N; i++) cin >> vec[i].first >> vec[i].second;
  
  sort(vec.begin(), vec.end());
  
  for (int i = 0; i < N; i++) {
    
    if (vec[i].second < M) {
      ans += vec[i].first * vec[i].second;
      M -= vec[i].second;
    }
    
    else {
      ans += vec[i].first * M;
      break;
    }
    
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
#define mpi map<ll,ll>
#define  si set<ll>
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define reP(i,a,n) for(ll i=a;i<=n;i++)
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define st string
#define sz size()
#define case(i,n) Case<<" "<<i<<": "<<n<<endl;
#define tc ll t;cin>>t;while(t--)
int main()
{
    ll n;cin>>n;
    ll ara[n+1],sum=0;
    mpi mp;
    for(ll i=0;i<n;i++)
    {
        cin>>ara[i];
        mp[ara[i]]++;
        sum+=ara[i];
    }
    ll m;cin>>m;
    while(m--)
    {
        ll a,b;cin>>a>>b;
        sum-=(mp[a]*a);
        sum+=(mp[a]*b);
        mp[b]+=mp[a];
        mp[a]-=mp[a];
        cout<<sum<<endl;
    }
}


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



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    long long ans = 0;
    int r = 0;
    while(n--){
        int x;
        cin >> x;
        ans += (x+r)>>1;
        r = x > 0 ? (x + r) % 2 : 0;

    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
Scanf.scanf "%s" (fun s ->
    let n = String.length s in
    let rec loop i plen acc =
        if i = n then acc else
            if plen = 2 then loop (i + 1) 1 (acc + 1) else
                if s.[i] <> s.[i - 1] then loop (i + 1) 1 (acc + 1) else
                    if i = n - 1 then acc else loop (i + 2) 2 (acc + 1)
    in
    loop 1 1 1 |> Printf.printf "%d\n"
)


Measured memory_bytes: 4560
#include<bits/stdc++.h>
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#define max(a,b)            (((a) > (b)) ? (a) : (b))
using namespace std;


class TaskA
{
public:
	vector<vector<int>> transforms;
	vector<vector<int>> minimums_between;
	vector<vector<int>> processed;
	void solve(istream &is, ostream &os)
	{
		int h, w;
		is >> h >> w;
		transforms.resize(10);
		for (auto &i : transforms)
			i.resize(10);
		for (auto &i : transforms)
			for (auto &j : i)
				cin >> j;
		processed.resize(h);
		for (auto &i : processed)
			i.resize(w);
		for (auto &i : processed)
			for (auto &j : i)
				cin >> j;
		int result = 0;
		minimums_between.resize(10);
		for (auto &i : minimums_between)
			i.resize(10);
		for (int j = 0; j < 10; j++)
			for (int k = 0; k < 10; k++)
				minimums_between[j][k] = transforms[j][k];
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				for (int k = 0; k < 10; k++)
					minimums_between[j][k] = min(minimums_between[j][k], minimums_between[j][i] + minimums_between[i][k]);
		for (auto &i : processed)
			for (auto &j : i)
				if (j != -1)
				{
					if (j == 1)
						result += 0;
					else
						result += minimums_between[j][1];
				}
		os << result << endl;
	}
};
int main()
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	TaskA taskA;
	taskA.solve(cin, cout);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<stdlib.h>

typedef long long int lli;
using namespace std;

void yespr(){cout<<"Yes\n"<<endl;}
void nopr(){cout<<"No\n"<<endl;}

int main(void){
    int n;

    cin>>n;
    printf("%.6f\n",2.0*(double)n*3.14159265);

    return 0;
}

Measured memory_bytes: 3760
#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--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

const int MAX = 2000000;
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

ll modinv(ll x, ll n){
    return modpow(x, n - 2);
}


int main(){
    int k;
    cin >> k;
    string s;
    cin >> s;
    int n = s.size();

    ll ans = 0;
    COMinit();

    for(int i = 0; i <= k; i++){
        ll tmp = modpow(25, k-i);
        tmp %= MOD;
        tmp *= modpow(26, i);
        tmp %= MOD;
        tmp *= COM(n+k-i-1, n-1);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 51204
n = int(input())
ans = 0
for i in range(n + 1):
    # rangeはnが10だと0から9までになってしまい iで10を指定できない
    # print(i)
    if i % 15 == 0:
        # print(i ,"FizzBuzz")
        continue;
    elif i % 5 == 0:
        # print(i, "Buzz")
        continue;
    elif i % 3 == 0:
        # print(i, "Fizz")
        continue;
    # elif i == 1:
        
    else:
        # print(i)
        ans += i

        # print()
    # print(ans)
print(ans)

Measured memory_bytes: 9204
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		return F?n:-n;
	}
}
int pc[111111];
int main()
{
	int n=io::F();
	for(register int i=1;i<=n;++i)
		pc[i]=i%10==0?pc[i/10]:pc[i-1]+1;
	int ans=0x3f3f3f3f;
	for(register int i=1;i<n;++i)
		cmin(ans,pc[i]+pc[n-i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
int main() {
    bool a[31];
    int input;
    for (int i = 0; i < 31; ++i) {
        a[i] = false;
    }
    for (int i = 0; i < 28; ++i) {
        std::cin >> input;
        a[input] = true;
    }
    for (int i = 1; i < 31; ++i) {
        if (a[i] == false) {
            std::cout << i << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3096
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	lint X, Y;
	cin >> X >> Y;
	
	if (X % Y == 0) {
		puts("-1");
	} else {
		lint g = __gcd(X, Y);
		if (g == X) {
			lint k = Y / X;
			cout << (k + 1) * X << endl;
		} else {
			lint a = X / g;
			while (X < Y) X *= a;
			cout << X << endl;
		}
	}
}
//--------------8---------------->> coding space <<-----------------8-------------//


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

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int,mat> P;

bool check(mat A){
  
  string ans = "123456780";
  string s;
  
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++) s += (char)( A[i][j] + '0' );
  }
  
  return ans == s;  
}

int bfs(mat s){
  
  queue<P> Q;
  map<mat,int> memo;
  
  Q.push( P( 0, s ) );
  memo[ s ] = 0;
  
  while( !Q.empty() ){
    
    P t = Q.front(); Q.pop();
    
    int cost = t.first;
    mat A = t.second;
    
    if( check( A ) == true ) return cost;
    
    int y, x;
    
    for(int i=0;i<3;i++){
      
      for(int j=0;j<3;j++){
	
	if( A[i][j] == 0 ) y = i, x = j;
	
      }
      
    }
    
    int dy[4] = {-1,0,1,0};
    int dx[4] = {0,1,0,-1};
    
    for(int i=0;i<4;i++){
      
      int ny = y + dy[i], nx = x + dx[i];
      
      if( ny < 0 || nx < 0 || 3 <= ny || 3 <= nx ) continue;
      
      mat nA = A;
      int ncost = cost + 1;
      
      swap( nA[y][x], nA[ny][nx] );
      
      if( memo.count( nA ) ) continue;
      
      memo[nA] = ncost;
      Q.push( P( ncost, nA ) );
      
    }
    
  }
  
  return 0; 
}

signed main(){
  
  mat s = mat( 3, vec( 3 ) );
  
  for(int i=0;i<3;i++){
    
    for(int j=0;j<3;j++){
      
      cin>>s[i][j];
      
    }
    
  }
  
  cout<<bfs(s)<<endl;
  
  return 0;
}



Measured memory_bytes: 49432
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

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

int main()
{
    ios::sync_with_stdio(false);
    vector<ii> nums;
    int n;
    cin>>n;
    int a,b;
    int rm=1000000001,rma=-1,bm=1000000001,bma=-1;
    for(int ctr1 = 0; ctr1 < n; ctr1++) {
        cin>>a>>b;
        nums.push_back(make_pair(a,ctr1));
        nums.push_back(make_pair(b,ctr1));
        if(a>b)
            swap(a,b);
        rm=min(rm,a);
        rma=max(rma,a);
        bm=min(bm,b);
        bma=max(bma,b);
    }
    sort(nums.begin(),nums.end());
    int ar[202020];
    int idx[202020];
    memset(ar,-1,sizeof(ar));
    int total_in = 0;
    ll rez = ((ll)(rma-rm))*(bma-bm);
    int f_s = n;
    multiset<int> uniq;
    for(int ctr1 = 0; ctr1 < nums.size(); ctr1++) {
        if(total_in == n) {
            rez = min(((ll)(*uniq.rbegin() - *uniq.begin()))*(nums[nums.size()-1].first-nums[f_s].first),rez);
        }
        if(ar[nums[ctr1].second] != -1) {
            f_s = min(f_s, idx[nums[ctr1].second]);
            uniq.erase(uniq.find(ar[nums[ctr1].second]));
            total_in--;
        }
        uniq.insert(nums[ctr1].first);
        ar[nums[ctr1].second] = nums[ctr1].first;
        idx[nums[ctr1].second] = ctr1;
        total_in++;
    }
    cout<<rez;
    return 0;
}


Measured memory_bytes: 15344
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    ll t,a;
    ll T=0,A=0;
    rep(i,n){
        cin >> t >> a;
        if(t >= a){
            if(A <= a){
                if(T <= t){
                    T = t;
                    A = a;
                }else{
                    if(T % t != 0) T += t - (T % t);
                    A = T / t * a;
                }
            }else{
                if(A % a != 0) A += a - (A % a);
                if(T <= A / a * t) T = A / a * t;
                else{
                    if(T % t != 0) T += t - (T % t);
                    A = T / t * a;
                }
            }
            //cout << T << " " << A << endl;
        }else{
            if(T <= t){
                if(A <= a){
                    A = a;
                    T = t;
                }else{
                    if(A % a != 0) A += a - (A % a);
                    T = A / a * t;
                }
            }else{
                if(T % t != 0) T += t - (T % t);
                if(A <= T / t * a) A = T / t * a;
                else{
                    if(A % a != 0) A += a - (A % a);
                    T = A / a * t;
                }
            }
        }
        //cout << T << " " << A << endl;
    }
    cout << A + T << endl;
}

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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  string S; cin >> S;
  string result;
  if (S=="Sunny") result = "Cloudy";
  if (S=="Cloudy") result = "Rainy";
  if (S=="Rainy") result = "Sunny";
  cout << result << endl;
  return 0;
}

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

int main(){
    int a,b,c,i,n=0,sum=0;
    
    cin >> a >> b >> c;
    while(sum < c){
        sum+=a;
        n++;
        if(n%7 == 0)sum+=b;
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3124
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(a == b && b == c){
      System.out.println(1);
    }else if(a == b || b == c || c ==a){
      System.out.println(2);
    }else{
      System.out.println(3);
    }
  }
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if( a + b > c + d) cout << "Left";
  else if ( a + b == c + d) cout << "Balanced";
  else cout << "Right";
  cout << endl;
}

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

map<char, char> p = {{'A', 'T'}, {'T', 'A'}, {'C', 'G'}, {'G', 'C'}};

int main() {
  char b;
  cin >> b;
  cout << p[b] << endl;
  return 0;

}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n,c) v.clear(),v.resize(n,c)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll n,i,c=1e18;
	cin>>n;
	for(i=1;i*i<=n;i++) if(n%i==0) c=min(c,i+n/i-2);
	cout<<c<<endl;
}


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

using namespace std;

int main () {
    ios::sync_with_stdio(false);
    string S; int K; cin >> S >> K;

    for (auto &c : S) {
        if (c == 'a')
            continue;
        int todo = 26 - (c - 'a');
        if (todo <= K) {
            K -= todo;
            c = 'a';
        }
    }
    K %= 26;
    S.back() = (S.back() - 'a' + K) % 26 + 'a';
    cout << S << "\n";
}


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

int main() {
  int S;
  cin >> S ;
  
  vector<long long> ans(2004);
  ans.at(0)=0; ans.at(1)=0; ans.at(2)=0;
  ans.at(3)=1; ans.at(4)=1; ans.at(5)=1;
  
  for(int i=6;i<2004;i++){
    ans.at(i) = ans.at(i-3)+ans.at(i-1);
    ans.at(i) = ans.at(i)%1000000007;
  }
  
  cout << ans.at(S) << endl;
  
}

Measured memory_bytes: 3608
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

N = int(input())
aa = list(map(int,input().split()))

flag = True
ans1 = ans2 = 0
sum1 = sum2 = 0

for i in range(N):
	sum1 += aa[i]
	sum2 += aa[i]
	if flag:
		if sum1 <= 0:
			ans1 += 1 - sum1
			sum1 = 1
		if sum2 >= 0:
			ans2 += sum2 - (-1)
			sum2 = -1
		flag = False
	else:
		if sum1 >= 0:
			ans1 += sum1 - (-1)
			sum1 = -1
		if sum2 <= 0:
			ans2 += 1 - sum2
			sum2 = 1
		flag = True

print(min(ans1,ans2))

Measured memory_bytes: 15144
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;

struct Card{
  char suit;
  int value;
};

void BubbleSort(Card c[],int n){
  rep(i,0,n){
    for(int j=n-1;j>i;--j){
      if(c[j].value<c[j-1].value) swap(c[j],c[j-1]);
    }
  }
}
void SelectionSort(Card c[],int n){
  rep(i,0,n){
    int min=i;
    rep(j,i,n)
      if(c[min].value>c[j].value) min=j;
    if(min!=i) swap(c[min],c[i]);
  }
}
void print(Card c[],int n){
  rep(i,0,n) cout<<c[i].suit<<c[i].value<<(i==n-1?"\n":" ");
}
bool isStable(Card a[],Card b[],int n){
  rep(i,0,n) if(a[i].suit!=b[i].suit) return false;
  return true;
}
int main(){
  int n;
  Card a[37],b[37];
  cin>>n;
  rep(i,0,n){
    cin>>a[i].suit>>a[i].value;
    b[i].suit=a[i].suit;
    b[i].value=a[i].value;
  }
  BubbleSort(a,n);
  print(a,n);
  cout<<"Stable\n";
  SelectionSort(b,n);
  print(b,n);
  if(isStable(a,b,n)) cout<<"Stable\n";
  else cout<<"Not stable\n";
  return 0;
}

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

int main(void) {
    const int MAX = 100;
    int A,B,C;
    int flag = 0;
    int rem[MAX] = {};
    
    cin >> A >> B >> C;
    for (int i =0; i <B; ++i) {
        rem[i] = (i*A)%B;
    }
    for (int i =0; i <B; ++i) {
        if (rem[i] == C) {
            flag = 1;
            break;
        }
    }
    
    if (flag == 1) {
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
    
    return 0;
}

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

int main()
{
int W,H,x,y,r;
cin>>W>>H>>x>>y>>r;

if((x+r>W)||(x-r<0))
cout<<"No"<<'\n';

else if((y+r>H)||(y-r<0))
cout<<"No"<<'\n';

else
cout<<"Yes"<<'\n';
                                                                                       

return 0;
}

Measured memory_bytes: 1124
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
    int ans = 0;
    int n,m;
    cin>>n>>m;
    vector<int>gr[n+2];
    int height[n+1];
    repa(i,1,n)
        cin>>height[i];
    repa(i,1,m)
        {
            int u,v;
            cin>>u>>v;
            gr[u].pb(v);
            gr[v].pb(u);
        }   
    repa(i,1,n)
    {
        bool isGood = true;
        for (auto it:gr[i])
            if ( height[it]>=height[i] )
              isGood = false;
        if (isGood)
            ans++;
    }
    cout<< ans <<endl;
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

int main() {
    ll N;
    ll T[50] = {};
    string S[50] = {};
    string X;
    cin >> N;
    rep(i,N) {
        cin >> S[i];
        cin >> T[i];
    }
    cin >> X;
    ll ans = 0;
    rep(i,N) {
        if(S[i].compare(X)==0) {
            REP(j,i+1,N) {
                ans += T[j];
            }
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readInt, readLine}
object Main {
    def main(args: Array[String]): Unit = {
        val cnt = readInt;
        val binTree = new BinaryTree[Long,Boolean]((k1, k2) => if (k1 < k2) -1 else if (k1 > k2) 1 else 0);
        (0 until cnt).foreach { i =>
            readLine.split(" ") match {
                case Array("insert", key) => binTree.insert(key.toLong, true);
                case Array("print") => {
                    println(" " + binTree.fetchInorder.map(_._1).mkString(" "));
                    println(" " + binTree.fetchPreoder.map(_._1).mkString(" "));
                }
            }
        }
    }
}
class BinaryTree[A,B](val compare: (A,A) => Int) {
    case class TreeNode(key: A, value: B, var left: TreeNode, var right: TreeNode);
    var tree: TreeNode = null;
    
    def isEmpty(): Boolean = if (tree == null) true else false;
    
    def insert(key: A, value: B): Unit = {
        def _insert(curr: TreeNode): Unit = {
            if (compare(key, curr.key) < 0) { // 追加対象ノードのほうが小さい
                if (curr.left == null) curr.left = TreeNode(key, value, null, null) else _insert(curr.left);
            } else if (compare(key, curr.key) > 0) { // 追加対象ノードのほうが大きい
                if (curr.right == null) curr.right = TreeNode(key, value, null, null) else _insert(curr.right);
            }
        }
        if (isEmpty) tree = TreeNode(key, value, null, null) else _insert(tree);
    }

    // 先行巡回で要素を返す
    def fetchPreoder(): List[(A, B)] = {
        def _fetchPreoder(curr: TreeNode, ret: List[(A, B)]): List[(A, B)] = {
            if (curr == null) {
                ret;
            } else {
                val ret1 = (curr.key, curr.value) :: ret;
                val ret2 = _fetchPreoder(curr.left, ret1);
                val ret3 = _fetchPreoder(curr.right, ret2);
                ret3;
            }
        }
        _fetchPreoder(tree, Nil).reverse;
    }
    
    // 中間巡回で要素を返す
    def fetchInorder(): List[(A, B)] = {
        def _fetchInorder(curr: TreeNode, ret: List[(A, B)]): List[(A, B)] = {
            if (curr == null) {
                ret;
            } else {
                val ret1 = _fetchInorder(curr.left, ret);
                val ret2 = (curr.key, curr.value) :: ret1;
                val ret3 = _fetchInorder(curr.right, ret2);
                ret3;
            }
        }
        _fetchInorder(tree, Nil).reverse;
    }
}


Measured memory_bytes: 498544
import java.util.Scanner;

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

    while (in.hasNext()) {
      int a = in.nextInt();
      int b = in.nextInt();
      int c = in.nextInt();
      int d = in.nextInt();

      if (Math.abs(b - a) <= d && Math.abs(b - c) <= d || Math.abs(c - a) <= d) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l,i;
    string s;
    set<string>x;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>s;
        x.insert(s);
    }
    l=x.size();
    cout<<l<<endl;
}


Measured memory_bytes: 19228
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

using namespace std;

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

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

int R,C,K;
ll dp[3010][3010][10];
ll val[3010][3010];

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>R>>C>>K;
	
	for(int i=1;i<=K;i++)
	{
		int r,c,v;cin>>r>>c>>v;
		
		val[r][c]=v;
	}
	
	for(int r=1;r<=R;r++)for(int c=1;c<=C;c++)
	{
		ll maxv=0ll;
		
		for(int i=0;i<4;i++)maxv=max(maxv,dp[r-1][c][i]);
		
		for(int i=1;i<4;i++)dp[r][c][i]=max(maxv+val[r][c],max(dp[r][c-1][i],dp[r][c-1][i-1]+val[r][c]));
	}
	
	ll ans=0;
	for(int i=0;i<=3;i++)ans=max(ans,dp[R][C][i]);
	
	cout<<ans;
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


Measured memory_bytes: 779316
#include<bits/stdc++.h>
using namespace std;
int a,b,c,k;
int main()
{
	scanf("%d%d%d%d",&c,&b,&a,&k);
	while(b<=c)b*=2,k--;
	while(a<=b)a*=2,k--;
	puts(k>=0?"Yes":"No");
	return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
using namespace std;
 
//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|  
//  code

const int N = 1e5 + 5;
vector<vector<int> > adj;
vector<int> dp;
vector<int> vis;

void dfs(int n){
    for(int i = 0;i < adj[n].size();i++){
        if(!vis[adj[n][i]]){
            vis[adj[n][i]] = true;
            dfs(adj[n][i]);
        }
        dp[n] = max(dp[n],1 + dp[adj[n][i]]);
    }
}

int main(){
    init;
    int n,m,i,j,k,l;
    cin>>n>>m;
    vis.resize(n+1);
    dp.resize(n+1);
    adj.resize(n+1);
    for(i=0;i<m;i++){
        cin>>j>>k;
        adj[j].push_back(k);
    }
    for(i = 1; i <= n;i++){
        if(!vis[i]){
            vis[i] = true;
            dfs(i);
        }
    }
    k = -1;
    for(i=1;i<=n;i++){
        k = max(k,dp[i]);
    }
    cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




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

  ld A,B,C,D,E,F;
  cin >> A >> B >> C >> D >> E >>F;

  vector<ld> W, S;
  rep(i,F/A+1){
    rep(j,F/B+1){
      ld w = i*A*100.0 + j*B*100;
      if(w > F) continue;
      W.pb(w);
    }
  }
  rep(i, F/C+1){
    rep(j, F/D+1){
      ld s = i*C + j*D;
      if(s > F) continue;
      S.pb(s);
    }
  }

  rmsame(W), rmsame(S);

  ld ans = 0.0;
  ld water = min(A,B);
  ld sugar = 0.0;
    
  rep(i,W.size()){
    if(W[i] == 0) continue;
    ld w = W[i];
    ld max_s = w/100.0 * E;
    max_s = min(max_s, F-w);
    ld s;
    rep(j,S.size()){
      if(S[j] <= max_s) s = S[j];
      else break;
    }

    ld ret = (100.0*s) /(w + s);
    if(ret >= ans){
      ans = ret;
      water = w, sugar = s;
    }
  }

  cout << water+sugar  << " " << sugar << endl;

    
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 5616
n,m,k = gets.chomp.split.map(&:to_i)

h = Hash.new(0)
bl = Hash.new(0)


class UnionFind
  attr_accessor :parent, :size

  def initialize(n)
    @parent = Array.new(n, &:itself)
    @size = []
    n.times do |i|
      @size[i] = 1
    end
  end

  def unite(x,y)
    x,y = root(x),root(y)
    return if x==y

    x,y = y,x if @size[x] < @size[y]
    @size[x] += @size[y]
    @parent[y] = x
  end

  def same_group?(x, y)
    root(x) == root(y)
  end

  def root(x)
    return x if @parent[x] == x

    @parent[x] = root(@parent[x])
  end

  # グループ数
  def count_group
    # 値と根が一致するものの数がグループ数
    @parent.map.with_index.count{ |n, i| n == i }
    # @parent.map.with_index.count(&:==)
  end

  # 特定のグループに所属する要素数
  # 計算量が多くなるのでこれはだめ
  def size(x)
    return @size[root(x)]
  end
end

uf = UnionFind.new(n)

m.times do |i|
  a, b = gets.chomp.split.map(&:to_i)
  # 友達の数をカウント
  h[a-1] += 1
  h[b-1] += 1
  unless uf.same_group?(a-1, b-1)
    uf.unite(a-1,b-1)
  end
end

k.times do |i|
  c, d = gets.chomp.split.map(&:to_i)

  if uf.same_group?(c-1, d-1)
    bl[c-1] += 1
    bl[d-1] += 1
  end
end

n.times do |i|
  puts uf.size(i) - h[i] - 1 - bl[i]
end



Measured memory_bytes: 16072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)

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

    ll n, k;
    cin >> n >> k;
    if (2 * k > n + 1) {
        cout << -1 << endl;
        return 0;
    }
    vector<ll> a(n), b(n), c(n);
    rep(i, 0, n) {
        a[i] = k + i;
        b[i] = k + 2 * n - 1 - i;
    }
    if (n % 2 == 1) {
        rep(i, 0, n / 2 + 1) {
            a[i] = k + (n / 2 - i);
            c[i] = k + 3 * n - 1 - 2 * i;
        }
        rep(i, n / 2 + 1, n) {
            a[i] = k + n - 1 - (i - n / 2 - 1);
            c[i] = k + 3 * n - 2 - 2 * (i - n / 2 - 1);
        }
    } else {
        rep(i, 0, n / 2 + 1) {
            a[i] = k + n / 2 - i;
            c[i] = k + 3 * n - 1 - 2 * i;
        }
        c[n / 2] = k + 2 * n;
        rep(i, n / 2 + 1, n) {
            a[i] = k + n - 1 - (i - n / 2 - 1);
            c[i] = k + 3 * n - 2 - 2 * (i - n / 2 - 1);
        }
    }

    rep(i, 0, n) {
        cout << a[i] << ' ' << b[i] << ' ' << c[i] << endl;
    }
    return 0;
}


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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};

using namespace std;
bool  f(string a){
  for(int i=0,j=a.size()-1;i<j;i++,j--)
          if(a[i]!=a[j])
                return false;
 return true;

}
void solve(){
int x;
   cin>>x;
   string s=to_string(x);
 if(f(s))
      cout<<"Yes";
  else cout<<"No";
}

int main(){
   std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
      solve(); 
   return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string;

int[50] CITY;

void main()
{
    auto nm = readln.chomp.split(" ").map!(to!int);
    auto n = nm[0];
    auto m = nm[1];

    auto city = CITY[0..n];
    foreach (_i; 0..m) {
        auto ab = readln.chomp.split(" ").map!(to!int);
        ++city[ab[0]-1];
        ++city[ab[1]-1];
    }

    city.each!(writeln);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	
	string x[100];
	string a="#";
	int h,w;
	
	cin>>h>>w;
	
	for(int i=0;i<h;i++){
		cin>>x[i];
	}
	for(int i=0;i<w+2;i++){
		cout<<a;
	}
	cout<<endl;
	for(int i=0;i<h;i++){
		cout<<a<<x[i]<<a<<endl;
	}
	for(int i=0;i<w+2;i++){
		cout<<a;
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> mem(N);
  vector<int> var(8,0);
  int any =0;
  int count=0;
  for (int j = 0; j < N; j++) {
    cin >> mem.at(j);
    }
  for(int j = 0; j < N; j++){
    if(mem.at(j)<=399) var.at(0)++;
    else if(mem.at(j)<=799) var.at(1)++;
    else if(mem.at(j)<=1199) var.at(2)++;
    else if(mem.at(j)<=1599) var.at(3)++;
    else if(mem.at(j)<=1999) var.at(4)++;
    else if(mem.at(j)<=2399) var.at(5)++;
    else if(mem.at(j)<=2799) var.at(6)++;
    else if(mem.at(j)<=3199) var.at(7)++;
    else any++;
  }
  for(int i=0;i<8;i++){
    //cout << var.at(i) << endl;
    if(var.at(i)>0) count++;
  }
  cout << max(count,1) << " " << count+any<< endl;

  }


Measured memory_bytes: 256
#pragma G++ optimize (2)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#define INF 0x3f3f3f3fLL
#define NO 300005
#define MO 100005
typedef long long ll;
using namespace std;
inline ll read()
{
	char ch = ' ', last;
	ll ans = 0;
	while (ch < '0' || ch > '9')
		last = ch, ch = getchar();
	while (ch >= '0' && ch <= '9')
		ans = ans * 10 + int(ch - '0'), ch = getchar();
	if (last == '-')
		return -ans;
	return ans;
}
void write(ll x)
{
	if (x >= 10)
		write(x / 10);
	putchar(x % 10 + '0');
}
//head

ll n, m, q, a[NO], b[NO];
//variable

void init()
{
	n = read(), m = read(), q = read();
	for (int i = 1; i <= n; i++)
		a[i] = read();
	for (int j = 1; j <= m; j++)
		b[j] = read();
}
//functions

int main()
{
	init();
	while (q--)
	{
		ll x = read(), l = 0, r = n, posa, posb, ans = INF * INF;
		while (l <= r)
		{
			int mid = l + r >> 1;
			if (a[mid] > x)
				r = mid - 1;
			else
				l = mid + 1;
		}
		posa = l - 1;
		l = 0, r = m;
		while (l <= r)
		{
			ll mid = l + r >> 1;
			if (b[mid] > x)
				r = mid - 1;
			else
				l = mid + 1;
		}
		posb = l - 1;
		//cout << a[posa] << ' ' << b[posb] << ',' << a[posa + 1] << ' ' << b[posb + 1] << endl;
		if (a[posa] && b[posb])
			ans = min(ans, x - min(a[posa], b[posb]));
		if (a[posa + 1] && b[posb + 1])
			ans = min(ans, max(a[posa + 1], b[posb + 1]) - x);
		if (a[posa] && b[posb + 1])
			ans = min(ans, min(2 * b[posb + 1] - x - a[posa], -(2 * a[posa] - x - b[posb + 1])));
		if (a[posa + 1] && b[posb])
			ans = min(ans, min(2 * a[posa + 1] - x - b[posb], -(2 * b[posb] - x - a[posa + 1])));
		cout << ans << endl;
	}
	return 0;
}
//main


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = tuple<ll,ll,int>;

int main(){
    int n; cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(ALL(a));
    sort(b.rbegin(),b.rend());
    if(n%2 == 1){
        int x = n/2;
        cout << b[x]-a[x]+1 << endl;
    }
    else {
        int x = n/2-1;
        ll a1 = a[x],a2 = a[x+1],b1 = b[x+1],b2 = b[x];
        cout << b1+b2-a1-a2+1 << endl;
    }
}

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


int main(){	
	string A;
	cin >> A;
	int x = 0;
	for (int i=0; i<A.length(); i++) {
		if (A[i] == 'x') x++;
	}
	if (x < 8) cout << "YES" << endl; else cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 256