akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = s[0]; 
            int A = s[1]; 
            int B = s[2];
            string input = ReadLine();

            int pass = 0;
            int 海外 = 0;
            for (int i = 0; i < N; i++)
            {
                switch (input[i])
                {
                    case 'a':
                        if (A+B>pass)
                        {
                            WriteLine("Yes");
                            pass++;
                        }
                        else
                        {
                            WriteLine("No");
                        }
                        break;
                    case 'b':
                        海外++;
                        if (A+B>pass && 海外<= B)
                        {
                            WriteLine("Yes");
                            pass++;
                        }
                        else
                        {
                            WriteLine("No");
                        }
                        break;
                    case 'c':
                        WriteLine("No");
                        break;
                }
            }
        }
    }
}


Measured memory_bytes: 15840
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
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;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n,k; string s;
    cin>>n>>s>>k;
    char c=s[k-1];
    rep(i,n){
        cout<<(s[i]!=c?'*':s[i]);
    }
    cout<<endl;
}

Measured memory_bytes: 3636
S = input()

for i in range(2**3):
    op = ['-']*3
    for j in range(3):
        if (i >> j) &1:
            op[3 - 1 - j] ='+'
    if eval(S[0] +op[0] +S[1]+ op[1]+S[2] +op[2] +S[3]) ==7:
        print(S[0] +op[0] +S[1]+ op[1]+S[2] +op[2] +S[3]+'=7')
        break


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

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

    int v[60];

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

    sort(v, v + n);
    int sum = 0;
    for(int i = n-1; i > n-1-k; --i){
        sum += v[i];
    }

    cout << sum;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("-Ofast")
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define F(i,b) for(int i= 0; i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define inp(a) for(auto& i : a) cin >> i;
#define out(a) for(auto i : a){cout << i << ' ';}cout << endl;
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define MOD 1000000007
const int N = 2e5+7 ;
string s ;

int32_t main(){_
	int n,k ;
	int a , p ;
	cin >> a >> p ;
	int t = a*3 + p ;
	int ans = t/ 2 ;
	cout << ans << endl ;
	

}





Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {a: usize, b: usize, k:usize};

    if b - a + 1 <= k * 2 {
        for i in a..b + 1 {
            println!("{}", i)
        }
    } else {
        for i in a..a + k {
            println!("{}", i)
        }

        for i in b - k + 1..b + 1 {
            println!("{}", i)
        }
    }
}


Measured memory_bytes: 2196
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    o = input()
    e = input()

    tlen = len(o) + len(e)
    for i in range(tlen):
        if i%2 == 0:
            print(o[i//2], end = '')
        else:
            print(e[i//2], end = '')

solve()


Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main{
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));}
        public FastReader(String fileName) throws FileNotFoundException{br = new BufferedReader(new FileReader(fileName));}
        String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException  e){e.printStackTrace();}}return st.nextToken();}
        int nextInt(){return Integer.parseInt(next());}
        long nextLong(){return Long.parseLong(next());}
        double nextDouble(){return Double.parseDouble(next());}
        char[][] readCharArray(int n,int m) {
        	String str;
        	char[][] arr = new char[n][m];
        	for(int i=0;i<n;i++) {
        		str=nextLine();
        		for(int j=0;j<n;j++) {
        			arr[i][j]=str.charAt(j);
        		}
        	}
        	return arr;
        }
        char[][] readCharArray(int n){
        	return readCharArray(n,n);
        }
        int[] readArray(int n){int[] a=new int[n];for (int i=0; i<n; i++) a[i]=nextInt();return a;}
        long[] readLongArray(int n){long[] a=new long[n];for (int i=0; i<n; i++) a[i]=nextLong();return a;}
        String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
    }
    static final Random random=new Random();
    static void ruffleSort(int[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n), temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
    	FastReader st = new FastReader();
    	long[] arr = st.readLongArray(4);
    	long ans;
    	ans = Math.max(arr[0]*arr[2], arr[0]*arr[3]);
    	ans = Math.max(ans, arr[1]*arr[3]);
    	ans = Math.max(ans, arr[1]*arr[2]);
    	System.out.println(ans);
    }
}

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

int main() {
	int A, B;
	char op;
	cin >> A >> op >> B;

	if( op == '+' ) {
		A += B;
	}
	else if( op == '-' ) {
		A -= B;
	}

	cout << A << endl;
}


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

int main(){
  string s;
  cin >> s;
  int l = s.length();
  vector<ll> sw(l+1,0);
  for(int i = l-1; i >= 0; i--){
    if(s[i] == 'W') sw[i] = sw[i+1] + 1;
    else sw[i] = sw[i+1];
  }
  ll ans = 0;
  rep(i,l) {
    if(s[i] == 'B') ans += sw[i+1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2180
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int n,x,i,c,mod;
long long s;
int main(){
    scanf("%d",&n);
    s=1;
    mod=1000000007;
    for(i=0;i<n;i++){
        scanf("%d",&x);
        c++;
        if(c*2-1>x){
            s=s*c%mod;
            c--;
        }
    }
    for(i=c;i>1;i--) s=s*i%mod;
    printf("%d\n",(int)s);
}


Measured memory_bytes: 256
#include <stdio.h>
#define BTC 380000.0

int main(void) {
  int N;
  scanf("%d", &N);
  double SUM = 0;

  for(int i = 0; i < N; i++) {
    double X;
    char U[4];
    scanf("%lf%s", &X, U);
    //printf("X=%d, U=%s\n", X[i], U[i]);
    if(U[0] == 'B') {
      SUM += X * BTC;
    } else {
      SUM += X;
    }
  }

  printf("%lf\n", SUM);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(void){
  ll n, y;
  cin >> n >> y;
  ll ans1 = -1, ans2 = -1, ans3 = -1;

  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n - i; j++){
      int k = n - i - j;
      ll tmp = (ll)10000 * i + (ll)5000 * j + (ll)1000 * k;
      if(tmp == y) {
        ans1 = i;
        ans2 = j;
        ans3 = k;
      }
    }
  }
  cout << ans1 << " " << ans2 << " " << ans3 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int h,w,i,j;
  
  while(1){
    scanf("%d %d",&h,&w);
    if (h==0 && w ==0)
      break;
    else{
      for(i=0;i<=h-1;i++){
	for (j=0;j<=w-1;j++){
	  if ((i+j)%2==0){
	  printf("#");
	  }
	  else if((i+j)%2==1){
	    printf(".");
	  }


	}
	printf("\n");
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 572
#include<iostream>
#include<vector>
using namespace std;
long long d[100008],p[100004],v[100004];
bool b=true;
vector<long>a[100004];
void dfs(long i)
{
   // cout<<i<<" dd "<<d[i]<<endl;
    v[i]=1;
    for(long j=0;j<a[i].size();j++)
    {
        if(v[a[i][j]]==0){dfs(a[i][j]);p[a[i][j]]=i;}
    }
    long long int s=0,m=0;
    for(long j=0;j<a[i].size();j++)
    {
        if(p[a[i][j]]==i)
        {
            s+=d[a[i][j]];
            if(d[a[i][j]]>m)m=d[a[i][j]];
        }

    }
    if(a[i].size()==1)return ;
    long long int x=s-d[i];
    long long int y=d[i]-x;
    m=s-m;
    if(x<0||y<0||m<x)b=false;
    d[i]=y;
    return ;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>d[i];
    int l;
    for(int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        a[x].push_back(y);
        a[y].push_back(x);
        if(a[x].size()>=2){l=x;}
        if(a[y].size()>=2){l=y;}
    }
    if(n==2)
    {
        if(d[1]==d[2])cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        return 0;
    }
    dfs(l);
    if(b&&d[l]==0){cout<<"YES"<<endl;}
    else cout<<"NO"<<endl;



}


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

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; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

ll dp[110][100100];

int main(){
    int n,w; cin >> n >> w;
    ll wei[n],val[n];
    rep(i,n) cin >> wei[i] >> val[i];

    rep(i,110){rep(j,100100){dp[i][j]=0;}}

    for(int i=0; i<n; i++){
        for(int j=0; j<=w; j++){
            //荷物iを入れる時
            if(wei[i]<=j) chmax(dp[i+1][j],dp[i][j-wei[i]]+val[i]);
            //荷物iを入れない時
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    COUT(dp[n][w]);
}

Measured memory_bytes: 86272
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<string, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

char judge(char a, char b){
    if((a == 'r' && b == 'b') || (a == 'b' && b == 'r')) return 'g';
    if((a == 'b' && b == 'g') || (a == 'g' && b == 'b')) return 'r';
    if((a == 'g' && b == 'r') || (a == 'r' && b == 'g')) return 'b';
}

int main(){
    while(1){
        string s; cin>>s;
        if(s == "0") return 0;

        queue<P> que;
        que.push(P(s, 0));
        map<string, bool> visited;
        visited[s] = true;
        bool valid = false;
        while(que.size()){
            string t;
            int cnt;
            tie(t, cnt) = que.front();
            que.pop();

            int isR = 0, isB = 0, isG = 0;
            for(int i=0; i<t.size(); i++){
                if(t[i] == 'r') isR = 1;
                if(t[i] == 'b') isB = 1;
                if(t[i] == 'g') isG = 1;
            }

            if(isR + isB + isG <= 1){
                valid = true;
                cout << cnt << endl;
                break;
            }

            for(int i=0; i<t.size()-1; i++){
                if(t[i] != t[i+1]){
                    string nt = t;
                    nt[i] = nt[i+1] = judge(t[i], t[i+1]);

                    if(!visited[nt]){
                        visited[nt] = true;
                        que.push(P(nt, cnt+1));
                    }
                }
            }
        }

        if(!valid){
            cout << "NA" << endl;
        }
    }
}


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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int x, y;
  cin >> x >> y;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      if (i + j == x && 2 * i + 4 * j == y) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n,m;
    cin >> n >> m;
    int count[100001] = {};
    rep(i,n){
        int x; cin>>x;
        count[x]++;
    }

    int kisuu[m] = {};
    rep(i,100001){
        if(count[i]%2==1){
            kisuu[i%m]++;
        }
    }

    int ans = 0;

    rep(i,m){
        if(i==0){
            int now = 0;
            int sum = 0;
            while(now*m<100001){
                sum += count[now*m];
                now++;
            }
            ans += sum/2;
        }else if(i*2==m){
            int now = 0;
            int sum = 0;
            while(now*m + i<100001){
                sum += count[now*m+i];
                now++;
            }
            ans += sum/2;
        }else{
            if(m<i*2)break;
            int sum1 = 0;
            int kisuu1 = kisuu[i];
            int now1 = 0; 
            while(now1*m + i<100001){
                sum1 += count[now1*m+i];
                now1++;
            }
            int sum2 = 0;
            int kisuu2 = kisuu[m-i];
            int now2 = 0;
            while(now2*m + (m-i)<100001){
                sum2 += count[now2*m+(m-i)];
                now2++;
            }

            int minikisuu = min(kisuu1,kisuu2);
            ans += minikisuu;
            kisuu1 -= minikisuu;
            kisuu2 -= minikisuu;
            sum1 -= minikisuu;
            sum2 -= minikisuu;
            if(kisuu1>0){
                int mini = min(sum2,kisuu1);
                ans += mini;
                kisuu1 -= mini;
                sum1 -= mini;
                sum2 -= mini;
                sum1 -= kisuu1;
                ans += sum1/2;
                ans += sum2/2;
            }else if(kisuu2>0){
                int mini = min(sum1,kisuu2);
                ans += mini;
                kisuu2 -= mini;
                sum2 -= mini;
                sum1 -= mini;
                sum2 -= kisuu2;
                ans += sum2/2;
                ans += sum1/2;
            }else{
                ans += sum2/2;
                ans += sum1/2; 
            }
        }
        //cout << ans;
    }

    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
    int n;

    scanf("%d", &n);
    int a[2 * n];

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

    sort(a, a + 2*n);
    int sum = 0;
    for (int i = 0; i < n; ++i)
    {
//    	printf("%d ", a[i * 2]);
      sum += a[i * 2];
    }
//    printf("\n");
    printf("%d\n", sum);
        sort(a,a+2*n);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int64_t ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= (i+1);
    ans %= 1000000007;
  }
  
  cout << ans << endl;

 
}
   

Measured memory_bytes: 3564
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int N = 2010;

int n;
char s[N];
bool vis[N];
int sub[N];
vector<int> g[N];

int iabs(int x) { return x < 0 ? -x : x; }

pair<int, int> dfs(int u) {
  vis[u] = true;
  pair<int, int> ret(0, 0);
  sub[u] = s[u] == '1';
  for (int v : g[u])
    if (!vis[v]) {
      auto cur = dfs(v);
      sub[u] += sub[v];
      cur.first += sub[v];
      cur.second += sub[v];
      if (max(cur.first, ret.first) <= min(cur.second, ret.second))
        ret = make_pair((cur.first ^ ret.first) & 1, cur.second + ret.second);
      else
        ret = make_pair(iabs(cur.first - ret.first), cur.second + ret.second);
    }
  return ret;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> (s + 1);
  for (int rep = 1; rep < n; ++rep) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = -1;
  for (int u = 1; u <= n; ++u) {
    memset(sub, 0, sizeof(sub));
    memset(vis, 0, sizeof(vis));
    auto res = dfs(u);
    if (res.first == 0)
      if (ans == -1 || ans > res.second / 2)
        ans = res.second / 2;
  }
  cout << ans << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
	x := (c + b - 1) / b
	y := (a + d - 1) / d
	if x <= y {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1820
#include<cstdio>
using namespace std;

char a[3][3];
int i,j;
int main()
{
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			scanf("%c",&a[i][j]);
		}
		getchar();
	}
	printf("%c",a[0][0]);
	printf("%c",a[1][1]);
	printf("%c",a[2][2]);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,y,z;
cin>>x>>y;
int arr[y];

for(int i=0;i<y;i++){
    cin>>arr[i];
}
sort(arr,arr+y);

for(int i=0;i<y;i++){
        if(x>0){
   int r = x-arr[i];
   x=r;
}
}
if(x>0){
    cout<<"No";
}
else{
    cout<<"Yes";
}
}


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

int main()
{
	string n;
	cin >> n;
	if(n[0] == '7' || n[1] == '7' || n[2] == '7')
    {
    	cout << "Yes" << endl; 
    }
  	else
    {
     	cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

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

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

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i] / 2;
        if (i < n - 1 && a[i] % 2 == 1 && a[i + 1] != 0) {
            a[i + 1]++;
        }
    }

    cout << ans << endl;
    return 0;
}


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

med=sum(a)/n

med_1=int(med)
med_2=int(med)+1

ans_1=0
ans_2=0
for i in range(n):
    ans_1+=(a[i]-med_1)**2
    ans_2+=(a[i]-med_2)**2
print(min(ans_1,ans_2))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
string hands[] = {"Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge","Paper","Air","Water","Dragon", "Devil","Lightning","Gun"};
int check(string s)
{
	for(int i = 0; i < 15; i++)
		if(hands[i] == s)
			return i;
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while(cin >> n, n)
	{
		int table[15][15];
		int flag[15] = {};
		memset(table, -1, sizeof(table));
		for(int i = 0; i < 15; i++)
		{
			bool flag = false;
			for(int j = 0; j < 15; j++)
			{
				int cnt = 7;
				if(i == j) 
				{
					table[i][j] = 0;
					int x = j;
					while(cnt--)
					{
						x++;
						table[i][x % 15] = 1;
					}
				}
			}
		}
		string str[n + 1];
		for(int i = 0; i < n; i++)
			cin >> str[i];
		int num[n + 1] = {};
		int max_p = 0, p;
		for(int i = 0; i < n; i++)
		{
			int y = check(str[i]);
			for(int j = 0; j < n; j++)
			{
				int x = check(str[j]);
				if(table[y][x] == -1)
				{
					num[i] = -1;
					break;
				}
				else 
					num[i] += table[y][x];
			}
			if(num[i] > max_p)
			{
				max_p = num[i];
				p = i;
			}
		}
		if(max_p == 0)
			cout << "Draw" << endl;
		else	
			cout << str[p] << endl;
	}
	return 0;
}




Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int ans = (a * n < b) ? a * n : b;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	set<int> s;
	rep(i, 3){
		int a; cin >> a;
		s.insert(a);
	}
	cout << (s.size() == 2 ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int32_t main()
{
	//freopen("input.txt", "r", stdin);
	IOS;
	
	int n; cin >> n;
	int ac, wa, tle, re;
	ac = wa = tle = re = 0;

	while(n--) {
		string s; cin >> s;
		if(s == "AC") ++ac;
		if(s == "TLE") ++tle;
		if(s == "WA") ++wa;
		if(s == "RE") ++re;
	}

	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>

using namespace std;

int a, b, c, d, e, k;
int cell[5];

bool judge(){
  bool dis = true;
  /*
  if(b - a > k){
    dis = false;
  }else if(c - b > k){
    dis = false;
  }else if(d - c > k){
    dis = false;
  }else if(e - d > k){
    dis = false;
  }else{
    dis = true;
  }
  */
 for(int i = 0; i < 5; ++i){
   for(int j = i + 1; j < 5; ++j){
     if(cell[j] - cell[i] > k){
       dis = false;
     }
   }
 }
  return dis;
}

int main(){
  cin >> a >> b >> c >> d >> e >> k;
  for(int i = 0; i < 5;++i){
    cell[0] = a;
    cell[1] = b;
    cell[2] = c;
    cell[3] = d;
    cell[4] = e;
  }
  if(judge() == true){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
use std::io;
use std::io::BufRead;
use std::collections::HashSet;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let n: usize = line.trim().parse().unwrap();
    let mut set: HashSet<String> = HashSet::new();
    let stdin = io::stdin();
    for (i, line) in stdin.lock().lines().enumerate() {
        set.insert(line.unwrap().trim().to_string());
        if i == n-1 {break};
    }
    for s in ['S', 'H', 'C', 'D'].iter() {
        for i in 1..14 {
            let s = format!("{} {}", s, i);
            if !set.contains(&s) {
                println!("{}", s);
            }
        }
    }
}


Measured memory_bytes: 5044
# e get everything
n, m = map(int, input().split())

lists = []
for i in range(m):
    price, num = map(int, input().split())
    K = list(map(int, input().split()))
    cnt = 0
    for some in K:
        cnt += 2**(n - some)
    lists.append((price, cnt))

dp = [[10**10 for i in range(2**n)]for j in range(m + 1)]
# dp[i][j]=i番目までの鍵を使用してjの状態を再現するために必要な最小の値
dp[0][0] = 0
for i in range(1, m + 1):
    price, mode = lists[i - 1][0], lists[i - 1][1]
    for j in range(2**n):
        dp[i][j] = min(dp[i - 1][j], dp[i - 1][j &(2**n-1-mode)] + price)

ans = dp[m][2**n - 1]

if ans < 10**10:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 80984
N = int(input())
A = list(map(int, input().split()))

rates = set()
cnt = 0
for a in A:
    if (a < 400):
        rates.add(0)
    elif (400 <= a and a < 800):
        rates.add(1)
    elif (800 <= a and a < 1200):
        rates.add(2)
    elif (1200 <= a and a < 1600):
        rates.add(3)
    elif (1600 <= a and a < 2000):
        rates.add(4)
    elif (2000 <= a and a < 2400):
        rates.add(5)
    elif (2400 <= a and a < 2800):
        rates.add(6)
    elif (2800 <= a and a < 3200):
        rates.add(7)
    else:
        cnt += 1

print(max(len(rates), 1), len(rates) + cnt)


Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

/*#define int ll*/
int sum(long long n) {
    int r = 0;
    while (n > 0) {
        r += n % 10;
        n /= 10;
    }
    return r;
}
int main(){
    int k;
    cin >> k;
    long long a=1;
    long long p=1;
    for(int i=1;i<=k;i++){
        cout << a<< endl;
        long long c=a+p;
        long long d=a+p*10;
        if(c* sum(d) <= d * sum(c)){
            a=c;
        }
        else {
            a=d;
            p=p*10;
        }
    }
}

Measured memory_bytes: 256
/**********************************************
 *Author*        :coderdz
 *Created Time*  : 2020/3/19 10:46:46
 *Ended  Time*  : 2020/3/19 12:14:38
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
#define IO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define rep(i,n) for(int i=1;i<=n;i++)
#define m(a,b) memset(a,b,sizeof(a))
typedef pair<int, int> PII;
typedef long long LL;
const int MAXN=2e5+10;

char Left[3][7], Right[3][7];//天平左右两边硬币
char result[3][7];

/*
1
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH even
K is the counterfeit coin and it is light.
*/

//称硬币
bool IsFake(char c, bool flag){
	//flag为true时表示轻,false表示为重
	for(int i = 0; i < 3; i++){
		char *pLeft, *pRight;//指向天平两边的字符串
		if (flag){
			pLeft = Left[i];
			pRight = Right[i];
		}
		else{
			pLeft = Right[i];
			pRight = Left[i];
		}
		switch(result[i][0]){
			case 'u'://右边轻
				if (strchr(pRight, c) == NULL) return false;
				break;
			case 'e'://两边一样重(此次称量无假币)
				if (strchr(pLeft, c) || strchr(pRight, c)) return false;
				break;
			case 'd'://左边轻
				if (strchr(pLeft, c) == NULL) return false;
				break;
		}
	}
	return true;
}

int a[MAXN];

int main(){
	//IO;
    int k, n;
    scanf("%d%d", &k, &n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    int tem = k - a[n-1] + a[0];
    for(int i = 1; i < n; i++)
    	tem = max(tem, a[i]-a[i-1]);
    cout << k - tem << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

/*
class Stack{
    private int[] stack = new int[150];
    private int tail=0;

    public void push(int x){
	if(tail<0)tail=0;
	stack[tail]=x;
	tail++;
    }

    public int pop(){
	tail--;
	return (tail>=0? stack[tail] : -1);
    }
}
*/
class Main{

    final static int LEN=150;
    static int[][] graph = new int[LEN][LEN];
    static int[] d = new int[LEN];
    static int[] f = new int[LEN];

    static int n, u, k;
    static int time;

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

	n=in.nextInt();
	for(int i=0; i<n; i++){
	    u=in.nextInt();
	    k=in.nextInt();
	    //read vartex informetion
	    for(int j=0; j<k; j++){
		graph[u-1][in.nextInt()-1]=1;
	    }
	}

	//DFS
	for(int i =0; i<n; i++){
	    if(d[i]==0){
		dfs(i);
	    }
	}

	//print
	for(int i=0; i<n; i++){
	    System.out.println( i+1 + " " + d[i] + " " + f[i]);
	}
    }

    static void dfs(int i){
	time++;
	d[i]=time;

	//visit node
	for(int j=0; j<n; j++){
	    if(graph[i][j]!=0 && d[j]==0){
		dfs(j);
	    }
	}
	time++;
	f[i]=time;
    }
}

Measured memory_bytes: 12000
package main

import (
  "fmt"
  "strings"
  "os"
  "bufio"
  "strconv"
  "math"
)

func main() {
  n, err := IntStdin()
  if err != nil {
    fmt.Println(err)
  }

  fmt.Printf("%d\n", int(math.Pow(float64(n), 3)))
}

// ????????????1?????????
func StrStdin() (stringReturned string) {
  scanner := bufio.NewScanner(os.Stdin)

  scanner.Scan()
  stringInput := scanner.Text()

  stringReturned = strings.TrimSpace(stringInput)
  return
}

// ??´??°???1?????????
func IntStdin() (int, error) {
  stringInput := StrStdin()
  return strconv.Atoi(strings.TrimSpace(stringInput))
}

// ?????????????????????????????????????????????Split()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
  stringSplited := strings.Split(stringTargeted, delim)

  for _, str := range stringSplited {
    if str != "" {
      stringReturned = append(stringReturned, str)
    }
  }

  return
}

// ??????????????§??????????????????????????????????????????
func SplitStrStdin(delim string) (stringReturned []string) {
  // ???????????§1?????????
  stringInput := StrStdin()

  // ????????§??????
  // stringSplited := strings.Split(stringInput, delim)
  stringReturned = SplitWithoutEmpty(stringInput, delim)

  return
}

// ??????????????§??????????????´??°????????????????????????
func SplitIntStdin(delim string) (intSlices []int, err error) {
  // ??????????????????????????????
  stringSplited := SplitStrStdin(" ")

  // ??´??°?????????????????????
  for i := range stringSplited {
    var iparam int
    iparam, err = strconv.Atoi(stringSplited[i])
    if err != nil {
        return
    }
    intSlices = append(intSlices, iparam)
  }
  return
}

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

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    vector<int> seq(N);
    for (int i = 0; i < N; i++)
    {
        cin >> seq.at(i);
    }

    double sum = 0.0;
    for (int i = 0; i < N; i++)
    {
        // reciprocal
        double reciprocal = 1.0 / seq.at(i);
        sum += reciprocal;
    }
    cout << fixed << setprecision(15) << 1.0 / sum << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        
        String s = scanner.next();
        String p = scanner.next();
        
        String tmp = s + s;
        
        String result = "No";
        if ( tmp.indexOf(p) == -1) {
            result = "No";
        } else {
            result = "Yes";
        }
        
        System.out.println(result);
        
    }
}


Measured memory_bytes: 26320
/*================================================
# ~  file:C.cpp
# ~~ date:2020-03-09
# ~~~author: SoMnus_L
#        |everybody finds love,in the end|
#   人の運命か,人の希望は悲しみにつづられているね
=================================================*/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define ll long long
const int N=1e6+10;
using namespace std;
typedef pair<int,int>PII;

int a,b;

bool check(int t){
    int x=floor(t*0.08); int y=floor(t*0.1);
     if(x>=a && y>=b) return true;
     else return false;
}

int main(){
 ios::sync_with_stdio(false);
  cin>>a>>b;
    int l=1; int r=N;
     while(l<r){
	int mid=l+r>>1;
	 if(check(mid)) r=mid;
	 else   l=mid+1;
     }
     int t1=floor(r*0.08); int t2=floor(r*0.1);
     if(t1==a && t2==b) cout<<r<<endl;
     else  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 256
while True :
    n, m = map(int, input().split())
    
    if n == 0 :
        break
    
    else :
        A = list(map(int, input().split()))
        s = 0
        
        As = sorted(A)
        
        for i in range(len(As) - 1) :
            for j in range(i + 1, len(As)) :
                if As[i] + As[j] <= m and As[i] + As[j] > s :
                    s = As[i] + As[j]
                    
                elif As[i] + As[j] > m :
                    break
                
        if s == 0 :
            print("NONE")
        else :
            print(s)


Measured memory_bytes: 5636
import java.util.*;
 
class Main {
      
    public static void main(String[] args) {
         
       Scanner cin=new Scanner(System.in);
       
       int n=cin.nextInt();
       long sum=0;
       int max=-1000000,min=1000000;
       for(int i=0;i<n;i++) {
    	   int x=cin.nextInt();
    	   max=Math.max(max, x);
    	   min=Math.min(min, x);
    	   sum+=x;
       }
       System.out.println(min+" "+max+" "+sum);
       
    }
     
 
}


Measured memory_bytes: 42668
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    bool grid[h][w];
    vector< vector<int> > dp(h, vector<int>(w, 0));
    for(int row = 0; row < h; row++){
        for(int col = 0; col < w; col++){
            char c;
            cin >> c;
            if(c == '.') grid[row][col] = true;
            if(c == '#') grid[row][col] = false;
        }
    }
    dp[0][0] = 1;
    for(int row = 0; row < h; row++){
        for(int col = 0; col < w; col++){
            if(grid[row][col]){
                if(row > 0){
                    dp[row][col] = (dp[row][col] + dp[row-1][col])%MOD;
                }
                if(col > 0){
                    dp[row][col] = (dp[row][col] + dp[row][col-1])%MOD;
                }
            }
            else dp[row][col] = 0;
        }
    }
    cout << dp[h-1][w-1] << endl;
}

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

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

    bool ans = true;

    if (a == b && b == c && a == c) ans = false;
    if (a != b && b != c && a != c) ans = false;
    
    if (ans) cout << "Yes" << endl;
    if (!ans) cout << "No" << endl;

    return 0;
    
}

Measured memory_bytes: 256
input_val = []
for i in range(6) :
    input_val.append(int(input()))

input_size = len(input_val)
count = 0
for i in range(5) :
    stan_val = input_val[i]
    for j in range(i+1,5) :
        diff = abs(stan_val - input_val[j])
        if diff > input_val[5] :
            count += 1
            
        else : count = count

if count == 0 :
   print("Yay!")
else : print(":(")

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( stdin.hasNextLine() ) {

	    final String input = stdin.nextLine();
	    if ( "0000".equals( input ) ) {
		break;		
	    }
	    int[] nums = new int[4];
	    for ( int i = 0; i < 4; i++ ) {
		nums[i] = input.charAt( i ) - '0';
	    }
	    if ( sameAllNumber( nums ) ) {
		System.out.println( "NA" );
	    } else {
		int count = 0;
		while ( !is6174( nums ) ) {
		    Arrays.sort( nums );
		    final int L = nums[3] * 1000 + nums[2] * 100 + nums[1] * 10 + nums[0];
		    final int S = nums[0] * 1000 + nums[1] * 100 + nums[2] * 10 + nums[3];
		    final int diff = L - S;
		    nums[3] = diff % 10;
		    nums[2] = ( diff / 10 ) % 10;
		    nums[1] = ( diff / 100 ) % 10;
		    nums[0] = ( diff / 1000 );
		    count++;
		}
		System.out.println( count );
	    }
	}	
    }

    static boolean sameAllNumber( int[] nums ) {
	return ( nums[0] == nums[1] && nums[1] == nums[2] && nums[2] == nums[3] );
    }

    static boolean is6174( int[] nums ) {
	return ( nums[0] == 6 && nums[1] == 1 && nums[2] == 7 && nums[3] == 4 );
    }    
}

Measured memory_bytes: 52492
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << endl; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;

VV G;
V c, sz;
Vll ans;
vector<map<int, ll>> dp;

void dfs(int u, int p=-1) {
  for (auto v : G[u]) {
    if (v == p) continue;
    dfs(v, u);
    ll x = sz[v] - dp[v][c[u]];
    ans[c[u]] -= x*(x+1)/2;
    if (dp[u].size() < dp[v].size()) swap(dp[u], dp[v]);
    for (auto &[a, b] : dp[v]) dp[u][a] += b;
    sz[u] += sz[v];
  }
  dp[u][c[u]] = sz[u];
}

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

  G.assign(n, V());
  c.assign(n, 0);
  sz.assign(n, 1);
  ans.assign(n, n*(n+1)/2);
  dp.assign(n, map<int, ll>());

  rep(i, n) {
    cin >> c[i];
    --c[i];
  }
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(0);
  rep(i, n) {
    ll x = sz[0] - dp[0][i];
    ans[i] -= x*(x+1)/2;
  }

  cout << ans;
  return 0;
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    ve<ve<int>> dp(n,ve<int>(n,0));
    for(int i = n-2; i >= 0; i--){
        for(int j = n-1; j > i; j--){
            if(s[i] != s[j]) continue;
            else{
                dp[i][j]++;
                if(i+1<n && j+1<n)dp[i][j] += dp[i+1][j+1];
            }
        }
    }
    int ans = 0;
    rep(i,n)rep(j,n){
        ans = max(ans, min(dp[i][j], (int)(j-i)));
    }
    cout << ans << endl;
    return 0;
}

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

#define       pb                 push_back
#define       mx                 210
#define       MOD                1000000007
#define 	  optimize           ios::sync_with_stdio(0);cin.tie(0);
#define 	  inf                0x3f3f3f3f
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);

using namespace std;

typedef       long long int      ll;
typedef       vector<int> 	     vi;

vi v[mx];

bool vis[mx];
int dis[mx], again;

int bfs(int n, int mxx=0)
{
    queue <int> q;

    q.push(n);

    dis[n] = 1;

    mxx = max(mxx, dis[n]);

    vis[n] = true;

    while(!q.empty())
    {
        int a = q.front();
        again = a;

        q.pop();

        for(int i = 0; i < v[a].size(); i++)
        {
            int x = v[a][i];

            if(vis[x]==true and dis[x]==dis[a])
            {
                cout << -1 << endl;
                exit(0);
            }

            if(vis[x]==false)
            {
                q.push(x);

                vis[x] = true;
                dis[x] = dis[a]+1;

                mxx = max(mxx, dis[x]);
            }
        }
    }

    return mxx;
}

int main()
{
    int n, u, vv, ans=0;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        string s;

        cin >> s;

        for(int j = 0; j < s.size(); j++)
        {
            u = i+1;
            vv = j+1;

            if(s[j]=='1') v[u].pb(vv);
        }
    }

    for(int i = 1; i <= n; i++)
    {
//        bfs(i);
//
        memset(vis, false, sizeof(vis));

        ans = max(ans, bfs(i));
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cmath>

int main() {
        using namespace std;

        // 1桁のみ、0が認められる
        // 2,3桁であれば、ダメ
        // また、同じ桁で別々の数字指定が入るのも有り得ない
        // 最小は、各々0, 10, 100

        int n, m, s[m], c[m], b[n],a = 0;

        cin >> n >> m;
        //cout << n << " " << m << endl;

        for (int i=0; i<m; i++)
        {
                cin >> s[i] >> c[i];
                //cout << s[i] << " " << c[i] << endl;
                // n > 1 のときのみの分岐
                if (n > 1 && s[i] == 1 && c[i] == 0)
                {
                        a = -1;
                        cout << a << endl;
                        return 0;
                }
        }

        for (int i=0; i<m-1; i++)
        {
                for (int j=i+1; j<m; j++)
                {
                        //cout << i << " " << j << endl;
                        if (s[i] == s[j] && c[i] != c[j])
                        {
                                a = -1;
                                cout << a << endl;
                                return 0;
                        }
                }
        }

        for (int i=0; i<m; i++)
        {
                b[s[i]-1] = c[i];
        }

        for (int i=0; i<n; i++)
        {
                //cout << b[i] << endl;
                //cout << b[i] << endl;
                a = a + b[i] * pow(10, n-1-i);
        }

        if (n > 1 && a < pow(10, n-1))
        {
                a = a + pow(10, n-1);
        }

        cout << a << endl;
        return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; using namespace atcoder;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> S;
	auto sa = suffix_array(S);
	auto lcp = lcp_array(S, sa);
	int N = S.length();

	ll ans = 1LL * N * (N - 1) / 2 + N;
	fore(x, lcp) ans -= x;
	cout << ans << endl;
}







Measured memory_bytes: 15620