akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=998244353;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}
long modInverse(long a) {return powmod(a, mod-2);}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x,a,y,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll>A(a),B(b),C(c);
    for(int i=0;i<a;i++)cin>>A[i];
    for(int i=0;i<b;i++)cin>>B[i];
    for(int i=0;i<c;i++)cin>>C[i];
    sort(A.rbegin(),A.rend());
    sort(B.rbegin(),B.rend());
    sort(C.rbegin(),C.rend());
    vector<ll>v;
    for(int i=0;i<x;i++){
        v.push_back(A[i]);
    }
    for(int i=0;i<y;i++){
        v.push_back(B[i]);
    }
    for(int i=0;i<c;i++){
        v.push_back(C[i]);
    }
    sort(v.rbegin(),v.rend());

    ll res=0;
    for(int i=0;i<x+y;i++){
        res+=v[i];
    }
    cout<<res<<endl;


    return 0;
    }


Measured memory_bytes: 8560
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  int i,k,n;
  int C[VMAX];
  unsigned short *A,*B;

  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  
  k = 0;
  for(i = 1; i <= n; i++){
    scanf("%hd",&A[i]);
    if(A[i] > k) k = A[i];
  }

  for(i = 0; i <= k; i++){
    C[i] = 0;
  }
 
  for(i = 1; i <= n; i++){
    C[A[i]]++;
  }

  for(i = 1; i <= k; i++){
    C[i] = C[i] + C[i-1];
  }

  for(i = n; i >= 1; i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }

  for(i = 1; i <= n; i++){
    printf("%d",B[i]);
    if(i != n) printf(" ");
    else printf("\n");
  }

  free(A);
  free(B);

  return 0;
}



Measured memory_bytes: 9184
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    ArrayList<String> A = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> B = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> C = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    
    String popped = A.remove(0);
    
    while (true) {
      if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } 
    }
  }
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */
vector<P> G[MAX];
vector<int> vec;
vector<int> ans;
bool seen[MAX];

int dfs(int s){
    seen[s] = true;
    int res = vec[s];
    for(P& p : G[s]){
        if(seen[p.fi]) continue;
        int d = dfs(p.fi);
        res ^= d;
        if(d) ans.push_back(p.se);
    }
    return res;
}

int main(){
    int n, m; cin >> n >> m;
    vector<P> bomb;
    rep(i, n){
        int a, b; cin >> a >> b;
        bomb.push_back(P(a, b));
    }
    sort(all(bomb));

    vec.push_back(bomb[0].se);
    rep(i, n-1) vec.push_back(bomb[i].se ^ bomb[i+1].se);
    vec.push_back(bomb[n-1].se);

    rep(i, m){
        int l, r; cin >> l >> r;
        int li = lower_bound(all(bomb), P(l, -1)) - bomb.begin();
        int ri = upper_bound(all(bomb), P(r, 2)) - bomb.begin();
        if(li == ri) continue;
        G[li].push_back(P(ri, i));
        G[ri].push_back(P(li, i));
    }

    rep(i, n+1){
        if(seen[i]) continue;
        int d = dfs(i);
        if(d){
            out(-1); return 0;
        }
    }

    sort(all(ans));
    out(ans.size());
    rep(i, ans.size()) cout << ans[i]+1 << " ";
    cout << endl;
}

Measured memory_bytes: 19312
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll> 
#define vv vector<v>
#define p pair<ll,ll>
#define mid (start+end)/2
#define fi first
#define se second
ll MOD=1e9+7;	
int main() {
	ll n;
	cin>>n;
	ll ans=(n*(n-1))/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  string s; cin >> s;
  vi cnt(3);
  rep(i,s.size()) cnt[s[i]-'a']++;
  sort(all(cnt));
  if(2 <= cnt[2]-cnt[0]) cout << "NO";
  else cout << "YES";
  cout << endl;
  return 0;
}


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

typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> AB(N);
    rep(i, N) {
        cin >> AB[i].first >> AB[i].second;
    }
    sort(AB.begin(), AB.end());
    //rep(i, N) cout << AB[i].first << " " << AB[i].second << endl;
    priority_queue<int> pq;
    int j = 0;
    ll ans = 0;
    rep(i, M) {
        auto p = AB[j];
        while (j < N && p.first <= i + 1) {
            pq.push(p.second);
            j++;
            //cout << i << "push" << p.second << endl;
            p = AB[j];
        }
        if (pq.size() == 0) continue;
        ans += pq.top();
        pq.pop();
        //cout << i << ans << endl;
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll used[10100];
ll n;
vector<ll> c;
vector<ll> G[10010];
ll cnt = 0;

void solve(ll now){
    queue<ll> que;
    que.push(0);
    used[0] = c[cnt];
    while(que.size()){
        ll now = que.front();
        que.pop();
        rep(i,G[now].size()){
            ll to = G[now][i];
            if(used[to] == -1){
                // cout << "!" << to;
                cnt++;
                used[to] = c[cnt];
                que.push(to);
            }
        }
        // cout << endl;
    }
}



int main(){
    cin >> n;
    c.resize(n);
    rep(i,n-1){
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i,n){
        cin >> c[i];
        used[i] = -1;
    }
    sort(ALL(c));
    reverse(ALL(c));
    ll ans = 0;
    rep(i,n-1)ans += c[i+1];
    cout << ans << endl;
    solve(0);
    rep(i,n)cout << used[i] << " ";
    cout << endl;
}

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

public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] A = new int[n];
        String[] in = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            A[i] = Integer.parseInt(in[i]);
        }
        int q = partition(A, 0, n - 1);
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            if(i != 0) sb.append(" ");
            if(i == q) sb.append("[").append(A[i]).append("]");
            else sb.append(A[i]);
        }
        System.out.println(sb);
    }

    public static int partition(int[] A, int p, int r){
        int x = A[r];
        int i = p - 1, temp;
        for(int j = p; j < r; j++){
            if(A[j] <= x){
                i = i + 1;
                temp = A[i];
                A[i] = A[j];
                A[j] = temp;
            }
        }
        temp = A[i + 1];
        A[i + 1] = A[r];
        A[r] = temp;
        return i + 1;
    }

}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl c(n-1),s(n-1),f(n-1);
  REP(i,n-1){
    cin >> c[i];
    cin >> s[i];
    cin >> f[i];
  }
  REP(i,n-1){
    ll time = s[i]+c[i];
    for(ll j=i+1;j<n-1;j++){
      ll start = s[j];
      if(start<time){
        ll t = (time-start-1)/f[j]+1;
        start += t*f[j];
      }
      time = start + c[j];
    }
    cout << time << endl;
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/900 < b.F.F/900)
		return 1;
	if(a.F.F/900 > b.F.F/900)
		return 0;
	if(a.F.S <= b.F.S)
		return 1;
	return 0;
}

const int N = (1e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 450;

ll a[N], fact[N], ifact[N], sum[N];

void pre()
{
	int i;
	fact[0] = ifact[0] = 1;
	fo(i,1,N)
	{
		fact[i] = (fact[i-1]*1LL*i)%mod;
		ifact[i] = inmodx(fact[i]);
	}
	return;
}

ll npr(int n, int r)
{
	if(r < 0 || n < 0 || r > n)
		return 0LL;
	ll ans = (fact[n] * inmodx(r))%mod;
	return ans;
}

ll calc(int l, int r)
{
	if(l > r)
		return 0LL;
	return (sum[r]-sum[l-1]+mod)%mod;
}

void solve()
{
	pre();
	int n, i;
	ll ans = 0, val;
	cin >> n;
	fo(i,1,n+1)
		cin >> a[i];
	sum[0] = 0;
	fo(i,1,n+1)
		sum[i] = (sum[i-1] + npr(n,i))%mod;
	fo(i,1,n+1)
	{
		val = npr(n,1);
		val = (val + calc(2,i))%mod;
		val = (val + calc(2,n-i+1))%mod;
		// cout << i << " : " << val << '\n';
		// cout << '\n';
		val = (val * a[i])%mod;
		ans = (ans + val)%mod;
	}
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	// clock_t clk;
	// clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	// clk = clock() - clk;
	// cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 3328
alphabet = ["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"]
moji = input()
for i in range(26):
    if moji == alphabet[i]:
        print(alphabet[i+1])
        exit()

Measured memory_bytes: 3060
#include <stdio.h>
 
int rec(int,int);
int n;
int A[20];
 
int main(){
  int q,i,j;
  int mi[200];

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

  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&mi[i]);
  }

  for(i = 0 ; i < q ; i++){

    if(1 == (rec(0,mi[i]))) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
 
int rec(int i,int mi){
  int a,b;
 
  if(mi < 0) return 0;
  else if(mi == 0) return 1; 
  else if(i == n)return 0;

  a = rec(i+1,mi);
  b = rec(i+1,mi-A[i]);

  if(a==1 || b==1) return 1;
  else return 0;
}

Measured memory_bytes: 580
import java.util.ArrayList;
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  ArrayList<Integer> list = new ArrayList<>();
	  while (true) {
		  String s = sc.nextLine();
		  String[] ss = s.split(" ");
		  int a = Integer.parseInt(ss[0]);
		  int b = Integer.parseInt(ss[1]);
		  if (a == 0 && b == 0) { break; }
		  list.add(a);
		  list.add(b);
	  }
	  for (int i = 0; i < list.size(); i += 2) {
		  int c = list.get(i);
		  int d = list.get(i + 1);
		  if (c > d) {
			  System.out.println(d + " " + c);
		  } else {
			  System.out.println(c + " " + d);
		  }
	  }
  }
}


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

int main(){
  int N,K,s=1;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    if(s*2<=s+K){
      s *= 2;
    }
    else{
      s +=K;
    }
  }
  cout<<s<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
ll dp[305][90005]={0};
ll dp2[305][90005]={0};
const ll mod=998244353;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll ret=pow(x,y/2);
  ret*=ret;
  ret%=mod;
  if(y%2==1) ret*=x;
  return ret%mod;
}
int main(){
  ll n,sum=0;
  cin>>n;
  ll array[305]={0};
  for(ll i=1;i<=n;i++){
    cin>>array[i];
    sum+=array[i];
  }
  for(ll i=1;i<=n;i++){
    if(array[i]>=(sum+1)/2){
      cout<<0<<endl;
      return 0;
    }
  }
  const ll ferm=pow(2,mod-2);
  //cout<<ferm<<endl;
  dp[0][0]=1;
  for(ll i=0;i<n;i++){
  //  dp[i+1][array[i+1]]+=pow(2,n-1);
    dp2[i+1][array[i+1]]++;
    for(ll j=0;j<90005;j++){
      dp[i+1][j]+=dp[i][j]*2;
      dp[i+1][j]%=mod;
      dp[i+1][j+array[i+1]]+=dp[i][j];
      dp[i+1][j+array[i+1]]%=mod;

      dp2[i+1][j]+=dp2[i][j];
      dp2[i+1][j+array[i+1]]+=dp2[i][j];
      dp2[i+1][j]%=mod;
      dp2[i+1][j+array[i+1]]%=mod;
    }
  }
  ll ans=pow(3,n);
  for(ll i=(1+sum)/2;i<90005;i++) {
    ans-=dp[n][i]*3;
    if(ans<0){
      while(ans<0) ans+=mod;
    }
    ans%=mod;
  }
//  cout<<ans<<endl;
  if(sum%2==0){
   ans+=dp2[n][sum/2]*3;
   ans%=mod;
  }
  if(ans<0){
    while(ans<0) ans+=mod;
  }
  ans%=mod;
  /*for(int i=0;i<=n;i++){
    for(int j=0;j<5;j++) cout<<dp[i][j]<<" ";
    cout<<endl;
  }*/
  cout<<ans<<endl;
}


Measured memory_bytes: 427648
/*
Author: CNYALI_LK
LANG: C++
PROG: B.cpp
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define all(x) x.begin(),x.end()
#define end(...) {printf(__VA_ARGS__);exit(0);}
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
typedef long long ll;
template<class T>void chkmin(T &a,T b){a=a<b?a:b;}
template<class T>void chkmax(T &a,T b){a=a>b?a:b;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
map<int,int> mp;
int main(){
#ifdef cnyali_lk
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int n,m,d,t;
	scanf("%d",&n);
	while(n){
		--n;
		scanf("%d",&d);
		++mp[d];
	}
	scanf("%d",&m);
	while(m){
		--m;
		scanf("%d",&t);
		if(mp[t]==0)end("NO\n")
		--mp[t];
	}
	printf("YES\n");
	return 0;
}



Measured memory_bytes: 9600
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long lint;

int main()
{
	int n;
	int dat[128];
	lint dp[128][21];
	
	scanf("%d", &n);
	
	memset(dp, 0, sizeof(dp));
	
	for (int i = 0; i < n; i++){
		scanf("%d", dat + i);
	}
	dp[0][dat[0]] = 1;
	
	for (int i = 1; i < n - 1; i++){
		for (int j = 0; j <= 20; j++){
			if (j + dat[i] <= 20){
				dp[i][j + dat[i]] += dp[i - 1][j];
			}
			if (j - dat[i] >= 0){
				dp[i][j - dat[i]] += dp[i - 1][j];
			}
		}
	}
	
	printf("%lld\n", dp[n - 2][dat[n - 1]]);
	
	return (0);
}

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

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

  int A[110] = {0};
  for (int i = 0; i < N; ++i) {
    int d;
    cin >> d;
    ++A[d];
  }

  int ans = 0;
  for (int i = 1; i <= 100; ++i) {
    ans += A[i] > 0;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[105];
int main()
{
	cin>>s;
	int n=strlen(s);
	int c=0,m=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='C') 
		{
		c=i	;
		m=1;
		break;
		}	
	}
	int f=0;
	for(int i=c+1;i<n;i++)
	{
		if(s[i]=='F') 
		{
		f=1;
		break;
		}	
	}
	if(m==1&&f==1) cout<<"Yes";
	else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
ans = 0
a = list(map(int, input().split()))

cnt_a = {}
for i in a:
  if i in cnt_a:
    cnt_a[i] += 1
  else:
    cnt_a[i] = 1
    
    
v = sorted(list(cnt_a.values()), reverse=True)
ans = sum(v[k:])
print(ans)

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

using namespace std;

vector<int> adj[100100];
map<pair<int, int>, int> cor;

void dfs(int v, int last, int color, int& maior){
    int nova = 1;
    
    for (auto x: adj[v]){
        if (x != last){
            if (nova == color) nova++;
            cor[{min(v, x),max(v,x)}] = nova;
            maior = max(nova, maior);
            dfs(x, v, nova, maior);
            nova++;
        }
    }
}

int main()
{
    int n, maior = 0;
    cin >> n;
    
    vector<pair<int ,int>> ans(n-1);
    
    for (int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        ans[i] = {a ,b};
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1, -1, -1, maior);
    cout << maior << endl;
    for (int i=0; i<n-1; i++){
        cout << cor[{ans[i].first,ans[i].second}] << endl;
    }
    return 0;
}


Measured memory_bytes: 15872
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string s;
int main(){
    getline(cin,s);
    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;

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

  vector<int> di(n,0);
  for(int i=0; i<n; i++) cin >> di[i];
  sort(di.begin(), di.end());
  cout << di[n/2] - di[n/2-1];

  return 0;
}


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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <math.h>

int main() {

    long long int x, y;
    cin >> x >> y;

    for ( long long int kame = 0; kame <= x; kame++ ) {
        long long int turu = x - kame;
        if ( kame * 4 + turu * 2 == y ) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;

}


Measured memory_bytes: 3636
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int s;
    cin>>s;
    int a=s;
    
    map<int,int>sa;
    sa[a]++;
    int i=1;
    while(++i){
        if(a%2==0)
            a/=2;
        else
            a=3*a+1;
        if(sa[a])
            break;
        else
            sa[a]++;
    }
    cout<<i<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

int main(){
    int n;
    lli sum = 0;
    cin >> n;
    for(int i=1; i<=n; i++){
        if(i%3 != 0 && i%5 != 0) sum += i; 
    }
    cout << sum << endl;
}

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

int main()
{
	int n, T;
	int ci[101];
	int ti[101];
	int cmin;
	cin >> n >> T;
	for (int i = 0; i < n; i++)
	{
		cin >> ci[i] >> ti[i];
	}
	
	int count = 0;

	if (ti[0] <= T)
	{
		cmin = ci[0];
	}
	else
	{
		count = 1;
		cmin = 10000;
	}
	
	for (int i = 1; i < n; i++)
	{
		if (T >= ti[i])
		{
			if (cmin > ci[i])
			{
				cmin = ci[i];
			}
		}
		else
		{
			count += 1;
		}
	}
	if (count == n)
	{
		cout << "TLE";
	}
	else
	{
		cout << cmin;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    stack<int> S1;
    stack<pair<int,int> > S2;
    char ch;
    int sum = 0;
    for(int i = 0; cin >> ch; i++ ){
        if(ch == '\\') S1.push(i);
        else if(ch == '/' && S1.size() > 0){
            int j = S1.top();
            S1.pop();
            sum += i-j;
            int a = i-j;
            while(S2.size() > 0 && S2.top().first > j){
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j,a));
        }
    }


    vector<int> ans;
    while(S2.size()>0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(),ans.end());
    printf("%d\n",sum);
    printf("%ld",ans.size());
    for(int i = 0; i<ans.size(); i++){
        printf(" %d",ans[i]);
    }
    printf("\n");
    return 0;

}


Measured memory_bytes: 3356
import java.util.*;
class Main {
    public static void main(String...args) {
        boolean isCollect = false;
        int count = 0;
        Scanner scan = new Scanner(System.in);
        String ring = scan.nextLine();
        String str = scan.nextLine();
        char[] chrs = ring.toCharArray();
        List<Character> ringList = new ArrayList<>();
        for(int k = 0 ; k < 2; k++) {
            for(char c :chrs) {
                ringList.add(new Character(c));
            }
        }
        for(int i = 0; i < ring.length(); i++) {
            for(int j = 0; j <str.length(); j++) {
                if(ringList.get(i + j) != str.charAt(j)) {
                    count = 0;
                    for(int k = 0 ; k < 2; k++) {
                        for(char c :chrs) {
                            ringList.add(new Character(c));
                        }
                    }   
                    break;
                }
                else {
                    //Character replace = ringList.get(0);
                    count++;
                    //ringList.add(replace);
                }
            }
            if(count == str.length()) {
                isCollect = true;
            } 
        }
        if(isCollect) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}





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

int main(void){
    string S,T;
    cin >> S >> T;
    int L=S.length();
    bool check=false;
    rep(i,L){
        string S2;
        for(int j=i;j<L;j++) S2+=S[j];
        for(int j=0;j<i;j++) S2+=S[j];
        if(S2==T) check=true;
    }
    if(check) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < 1;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		String[] strArr = str.split(" ");
		ArrayList<Long> cards = new ArrayList<Long>();
		for (int i = 0; i < N; i++) {
			cards.add(Long.parseLong(strArr[i]));
		}
		long total = 0;
		for (long n : cards) {
			// System.out.println(n);
			total += n;
		}
		long min = Long.MAX_VALUE;
		long top = 0;
		for (int i = 0; i < cards.size() - 1; i++) {
			top += cards.get(i);
			long diff = (total - top) - top;
			if (diff < 0)
				diff *= (-1);
			// System.out.println(diff);
			if (diff < min)
				min = diff;
		}

		System.out.println(min);
	}

	public void solve() {

	}
}


Measured memory_bytes: 63132
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val pss = Array(N) {
        val A = readLine()!!.toInt()
        Array(A) { readLine()!!.split(" ").map { it.toInt() } }
    }

    var res = 0
    for (i in 0 until (1 shl N)) {
        var flag = true

        for (j in pss.indices) {
            if ((i shr j) and 1 == 0) {
                continue
            }

            for (l in pss[j]) {
                flag = flag && (i shr (l[0] - 1)) and 1 == l[1]
            }
        }

        if (flag) {
            res = Math.max(res, Integer.bitCount(i))
        }
    }

    println(res)
}


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

int main()
{
	int K;
	string S;
	cin >> K >> S;

	int N = S.size();
	string ans = S;
	if( N > K ) {
		ans = S.substr( 0, K );
		ans += "...";
	}

	cout << ans << endl;
}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)

using namespace std;

typedef long long ll;

enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
template <class T>
class Dice {
public:
  Dice() {
    id[TOP] = 0; id[FRONT] = 1; id[LEFT] = 2;
    id[RIGHT] = 3; id[BACK] = 4; id[BOTTOM] = 5;
  }
  T& operator[] (FACE f) { return var[id[f]]; }
  const T& operator[] (FACE f) const { return var[id[f]]; }
  bool operator==(const Dice<T>& b) const {
    const Dice<T> &a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
      a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
      a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
  }
  void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
  void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
  void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }

private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    T tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  T var[6];
  int id[6];
};

FACE face[] = {TOP,BOTTOM,FRONT,BACK,LEFT,RIGHT};

inline int toInt(char c){ return ((c=='B')?0:((c=='E')?1:((c=='R')?2:3))); }
char F[3][3];
char initial_color[] = {'W','W','R','R','B','B'};
int mincost;
int dx[] = {1,0,-1,0}; // R, B, L, T
int dy[] = {0,1,0,-1};

inline void swap_dice(Dice<char> dice[3][3],int x1,int y1,int x2,int y2,int type){
  if( type == 0 ) rep(i,3)dice[y2][x2].roll_y();
  if( type == 1 ) rep(i,3)dice[y2][x2].roll_x();
  if( type == 2 ) dice[y2][x2].roll_y();
  if( type == 3 ) dice[y2][x2].roll_x();
  swap(dice[y1][x1],dice[y2][x2]);
}

inline int finish(Dice<char> dice[3][3]){
  int diff = 0;
  rep(i,3)rep(j,3)if( dice[i][j][TOP] != F[i][j] ) diff++;
  return diff;
}

void dfs(Dice<char> dice[3][3],int x,int y,int cost,int pre){

  if( cost >= mincost) return;

  int tmp;
  if( ( tmp = finish(dice) ) == 0 ){
    mincost = min(mincost,cost);
    return;
  }

  if( tmp )tmp--;
  if( cost + tmp >= mincost ) return;

  rep(i,4){
    if( i == pre ) continue;
    int nx = x + dx[i], ny = y + dy[i];
    if( !( 0 <= nx && nx < 3 && 0 <= ny && ny < 3 ) ) continue;
    swap_dice(dice,x,y,nx,ny,i);
    dfs(dice,nx,ny,cost+1,(i+2)%4);
    swap_dice(dice,nx,ny,x,y,(i+2)%4);
  }
}

int main(){

  int x,y;
  while(scanf("%d%d",&x,&y),x|y){
    x--,y--;
    mincost = 31;
    rep(i,3)rep(j,3)cin >> F[i][j];

    Dice<char> dice[3][3];
    rep(i,3)rep(j,3)rep(k,6)dice[i][j][face[k]] = ((i==y&&j==x)?'E':initial_color[k]);

    dfs(dice,x,y,0,-1);

    if( mincost == 31 ) puts("-1");
    else                printf("%d\n",mincost);

  }
  return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int r;
    cin >> r;
    cout << (3*r*r) << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VL a(n); cin >> a;

    int m = (n & 1 ? 2 : 1);
    auto dp = defvec<ll>(-LLINF, n + 1, m + 1);
    FOR(i, 0, m + 1)dp[i + 1][i] = a[i];
    FOR(i, 1, n)eFOR(j, 0, m) {
        chmax(dp[i + 1][j], dp[i - 1][j] + a[i]);
        if (j < m)chmax(dp[i + 1][j + 1], dp[i][j]);
    }

    cout << dp[n][m] << "\n";
}


Measured memory_bytes: 15872
n = int(input())
a = list(map(int,input().split()))
count = 0
for i in range(n):
    if a[i]%2 == 0:
        if a[i]%3 == 0 or a[i]%5 == 0:
            count += 1
        else:
            count -=200
print("APPROVED" if count >=0  else "DENIED")

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int A, B, T;
    cin >> A >> B >> T;
    int ans = 0;
    for (int i = A; i <= T; i += A) {
        ans += B;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
from collections import deque
def main():
    s = deque(input())
    q = int(input())
    top = True
    for i in range(q):
        query = list(map(str, input().split()))
        if query[0] == "1":
            top = not top
        else:
            if (query[1]=="1" and top==True) or (query[1]=="2" and top==False):
                s.appendleft(query[2])
            else:
                s.append(query[2])
    if top == False:
        for i in range(len(s)):
            print(s[len(s)-1-i],end="")
    else:
        for c in s:
            print(c,end="")
            
if __name__ == '__main__':
    main()

Measured memory_bytes: 95192
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num):>, lower_bound(A, A+N, num):>=
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>	// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>		// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>	// push(x), front(), pop()
#include <deque>
#include <stack>	// push(x), top(), pop()
#include <map>		// M[key],  insert(key, val), erase(key), find(key), 
#include <set>		// insert(key), erase(key), find(key)#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num):>, lower_bound(A, A+N, num):>=
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>	// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>		// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>	// push(x), front(), pop()
#include <deque>
#include <stack>	// push(x), top(), pop()
#include <map>		// M[key],  insert(key, val), erase(key), find(key), 
#include <set>		// insert(key), erase(key), find(key)


using namespace std;
typedef long long ll;
// typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007



void solve() {
	int N;
	cin >> N;
	if (N < 1000) {
		cout << "ABC";
	}
	else {
		cout << "ABD";
	}
}

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

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
digit = [0]*60

for i in A:
    b = i
    tmp = 0
    while(b):
        digit[tmp] += b & 1
        tmp += 1
        b >>= 1

ans = 0
for i in range(60):
    ans = (ans + (digit[i]*(N-digit[i]) % mod) * pow(2, i, mod) % mod) % mod

print(ans)

Measured memory_bytes: 122936
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int e = c + b - d;
  int f = d + c - a;
  int g = a + b - d;
  int h = b + c - a;
  cout << e << " " << f << " " << g << " " << h << endl;
  return 0;
}

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

const int MAXN = 1e5 + 10, N = 1e5;
vector<int> Mat[MAXN], d[MAXN], r[MAXN], com;
bool se[MAXN];
long long en;
int n;
void dfs(int v) {
	com.push_back(v);
	se[v] = 1;
	for (int i = 0; i < Mat[v].size(); i++)
		if (!se[Mat[v][i]])
			dfs(Mat[v][i]);
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		d[b].push_back(a);
		r[a].push_back(b);
	}
	for (int i = 1; i <= N; i++)
		for (int j = 1; j < d[i].size(); j++)
			Mat[d[i][j]].push_back(d[i][0]), Mat[d[i][0]].push_back(d[i][j]);
	for (int i = 1; i <= N; i++) {
		if (se[i])
			continue;
		com.clear();
		dfs(i);
		vector<int> x;
		for (int j = 0; j < com.size(); j++)
			for (int k = 0; k < r[com[j]].size(); k++)
				x.push_back(r[com[j]][k]);
		sort(x.begin(), x.end());
		x.resize(unique(x.begin(), x.end()) - x.begin());
		en += (long long)x.size() * (long long)com.size();
	}
	cout << en - n;
}

Measured memory_bytes: 13820
#include<bits/stdc++.h>
#include<string>
#include<deque>
#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define all(a)  (a).begin(),(a).end()
#define elif else if

signed main(){
  int x,y;
  cin>>x>>y;
  int ans=0;
  for(int i=x; i<=y; i*=2){
    ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >>s;
    int cont = 0;
    for(int i = 0;i<s.size()/2;i++){
        //cout << s[i] <<" "<<s[s.size()-i-1]<<endl;
        if(s[i]!=s[s.size()-i-1]){
            cont++;
        }
        
    }
    
    cout << cont << endl;
}


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

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

	vector<int> V(N);
	for (int i = 0; i < N; i++){
		cin >> V[i];
}

	vector<int> C(N);
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}

	int A = 0;
	for (int i = 0; i < N; i++) {
		if (V[i] > C[i])
			A += V[i] - C[i];
	}

	cout << A << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する

int main(){
    double a,b;
    cin>>a>>b;
    //cout<<a/0.08<< " "<<b/0.10<<endl;
    for(int x=1;x<=10000;x++){
        if(int(x*0.08)==a&&int(x*0.10)==b){
            cout<<x<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

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

long f(long n){
  if(n%2==0) return n/2;
  else return 3*n+1;

}

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

  long n=s;
  int i=1;
  while(n!=4 && n!=2 && n!=1){
    n=f(n);
    i++;
  }
  cout << i+3 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public static class Solution
{
    public static void Main()
    {

        var N = int.Parse(Console.ReadLine());
        var A = new long[N];
        var B = new Tuple<int, int>[N];
        for (int i = 0; i < N; i++)
        {
            var vals = Console.ReadLine().Split(".");
            if (vals.Length == 1)
            {
                A[i] = long.Parse(vals[0]) * (long)1e9;
            }
            else
            {
                A[i] = long.Parse($"{vals[0]}{vals[1]}{new string('0', 9 - vals[1].Length)}");
            }
        }

        // [2の個数, 5の個数]
        var counts = new int[19, 19];

        for (int i = 0; i < N; i++)
        {
            var a = A[i];
            var two = 0;
            var five = 0;
            while (a > 0)
            {
                if (a % 2 == 0)
                {
                    a /= 2;
                    two++;
                }
                else
                {
                    break;
                }
            }
            while (a > 0)
            {
                if (a % 5 == 0)
                {
                    a /= 5;
                    five++;
                }
                else
                {
                    break;
                }
            }
            two = Math.Min(two, 18);
            five = Math.Min(five, 18);
            B[i] = Tuple.Create(two, five);
            counts[two, five]++;
        }

        long count = 0;
        for (int i = 0; i < N; i++)
        {
            var b = B[i];
            var two = b.Item1;
            var five = b.Item2;
            counts[two, five]--;

            for (int tw = 18 - two; tw <= 18; tw++)
            {
                for (int fi = 18 - five; fi <= 18; fi++)
                {
                    count += counts[tw, fi];
                }
            }
        }

        Console.WriteLine(count);
    }
}

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

int main(){
  vector<int64_t> v(3);
  for(int i=0;i<3;i++){
    cin >> v.at(i);
    if(v.at(i)%2==0){
      cout << 0 << endl;
      return 0;
    }
  }
  cout << min({v.at(0)*v.at(1),v.at(1)*v.at(2),v.at(0)*v.at(2)}) << endl;
  return 0;
}


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

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
        	String S = sc.next();
        	int sindex = S.indexOf('A');
        	int eindex = S.lastIndexOf('Z');
            System.out.println(eindex - sindex + 1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
  {
     cin >> a.at(i);
  }
  for (int j = 0; j < k; j++)
  {
     vector<int> b(n+1);
     for (int i = 0; i < n; i++)
     {
        int l = max(0, i-a.at(i));
        int r = min(i+a.at(i)+1, n);
        b.at(l)++;
        b.at(r)--;
     }
     for (int i = 0; i < n; i++)
     {
        b.at(i+1) += b.at(i);
     }
     b.pop_back();
     if (a == b)
     {
        break;
     }
     a = b;
     
  }
  for (int i = 0; i < n; i++)
  {
     cout << a.at(i) << endl;
  }
  
   
  return 0;
}

Measured memory_bytes: 4780
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

a#b = abs$a-b

main = B.interact$B.pack.show.f.unfoldr(B.readInt.B.dropWhile isSpace)
f (n:h1:h2:hv)=snd $ fst $ foldl' proc ((0,h1#h2),h1:h2:hv) [3..n]
proc ((u1,u2),h1:h2:h3:hv) _ = ((u2, min (u1+h1#h3) (u2+h2#h3)), h2:h3:hv)


Measured memory_bytes: 18812