akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;


int main() {
	ll n, m, x,mem,ans= 10000000;
	cin >> n >> m >> x;
	vector<int> c(n);
	vector<int> calca(m);
	ll calcc = 0;
	graph a(n);
	for (int i = 0; i < n; i++) {
		cin >> mem;
		c[i] = mem;
		for (int j = 0; j < m; j++) {
			cin >> mem;
			a[i].push_back(mem);
		}
	}
	for (int bit = 0; bit < (1 << n); bit++) {
		for (int j = 0; j < m; j++) {
			calca[j] = 0;
		}
		calcc = 0;
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				calcc = calcc + c[i];
				for (int j = 0; j < m; j++) {
					calca[j] = calca[j] + a[i][j];
				}
			}
		}
		bool joken = true;
		for (int i = 0; i < m; i++) {
			if (calca[i] < x) {
				joken = false;
				break;
			}
		}
		if (joken == true && ans > calcc)ans = calcc;
	}
	if (ans == 10000000) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}

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

#define MAX 256

int main(void){
	int i;
	int l = 0;
	char str[21];
	char str1[21];
	cin >> str;
	for (i = 0; str[i] != '\0'; i++){
	}
	for (int k = i-1; k>=0;l++,k--){
		cout << str[k];
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 2992
a_list = [[int(i) for i in input().split()] for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

flag = False

for i in range(3):
    for i in range(3):
        if all([True if a_list[j][i] in b else False for j in range(3)]):
            if flag == False:
                print('Yes')
            flag = True
            break

if flag == False:
    for i in range(3):
        if all([True if a_list[i][j] in b else False for j in range(3)]):
            if flag == False:
                print('Yes')
            flag = True
            break

if flag == False:
    temp1 = [(0,0), (1,1), (2,2)]
    if all([True if a_list[i][j] in b else False for (i,j) in temp1]):
        print('Yes')
        flag = True

if flag == False:
    temp2 = [(0,2), (1,1), (2,0)]
    if all([True if a_list[i][j] in b else False for (i,j) in temp2]):
        print('Yes')
        flag = True
    
if flag == False:
    print('No')

Measured memory_bytes: 3064
s = input()
s = list(s)
res = [0] * len(s)
i = 0
while i < len(s) - 1:
  if s[i] == 'R' and s[i + 1] == 'L':
    rc, lc = 0, 0
    for j in range(i, -1, -1):
      if s[j] == 'R':
        rc+=1
      else:
        break
    for j in range(i + 1, len(s)):
      if s[j] == 'L':
        lc+=1
      else:
        break
    res[i] = (rc + lc) // 2
    res[i + 1] = (rc + lc) // 2
    if (rc + lc) % 2 == 1:
      if rc % 2 == 1:
        res[i] += 1
      else:
        res[i + 1] += 1
    i += lc
  i += 1
print(" ".join(str(x) for x in res))

Measured memory_bytes: 58504
// ConsoleApplication.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdio.h"
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string>
#include <vector>

using namespace std;

void selectionSort(vector<int>& intArray, int& swapCount)
{
	swapCount = 0;
	const int numberOfElements = intArray.size();
	for (int i = 0; i != numberOfElements - 1; ++i) {
		int minIndexJ = i;
		for (int j = i; j != numberOfElements; ++j) {
			if (intArray.at(j) < intArray.at(minIndexJ)) {
				minIndexJ = j;
			}
		}
		if (minIndexJ != i) {
			swap(intArray.at(i), intArray.at(minIndexJ));
			++swapCount;
		}
	}
}

int main()
{
	int n;
	cin >> n;
	vector<int> intArray(n);
	for (auto& i : intArray) {
		cin >> i;
	}

	int swapCount;
	selectionSort(intArray, swapCount);
	const string values = accumulate(intArray.begin() + 1, intArray.end(), to_string(intArray.front())
		, [](const string& init, const int v) {return init + " " + to_string(v); });
	cout << values << endl;
	cout << swapCount << endl;

	return 0;
}


Measured memory_bytes: 3232
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int m;
int ar[N];
int pos[N];
int parent[N];

int getP(int u){
    if(parent[u] == u)
        return u;
    return parent[u] = getP(parent[u]);
}

void join(int u , int v){
    u = getP(u);
    v = getP(v);
    parent[v] = u;
}

int main(){
    scanf("%d%d" , &n , &m);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &ar[i]);
        pos[ar[i]] = i;
        parent[i] = i;
    }
    for(int i = 1; i <= m; i++){
        int u , v;
        scanf("%d%d" , &u , &v);
        join(u , v);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans += getP(pos[ar[i]]) == getP(ar[i]);
    }
    printf("%d\n" , ans);
}


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

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

    int n, m, maxi = -1;
    cin >> n >> m;

    vector<int> A(100010, 0);
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        A[l]++;
        A[r + 1]--;
        maxi = max(maxi, r + 1);
    }

    int ans = 0;
    for(int i = 0; i <= maxi; i++){
        if(i > 0) A[i] += A[i - 1];
        if(A[i] == m) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
from scipy.sparse import*
n,_,*L=map(int,open(0).read().split())
s=csgraph.floyd_warshall(csr_matrix((L[2::3],(L[::3],L[1::3])),[n+1]*2),0)
print(sum(s[f,t]<c for f,t,c in zip(*[iter(L)]*3)))

Measured memory_bytes: 17428
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

int main() {
  int n,i,j,e,sum,u,v,minv,M[MAX][MAX],d[MAX],p[MAX],vis[MAX];

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) {
    for(j = 0 ; j < n ; j++) {
      scanf("%d",&e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }

  for(i = 0 ; i < n ; i++) {
    d[i] = INFTY;
    p[i] = -1;
    vis[i] = 0;
  }

  d[0] = 0;

  while(1) {
    minv = INFTY;
    u = -1;
    for(i = 0 ; i < n ; i++) {
      if(minv > d[i] && !vis[i]) {
	u = i;
	minv = d[i];
      }
    }
    if(u == -1)
      break;
    vis[u] = 1;
    for(v = 0 ; v < n ; v++) {
      if(!vis[v] && M[u][v] != INFTY) {
	if(d[v] > M[u][v]) {
	  d[v] =  M[u][v];
	  p[v] = u;
	}
      }
    }
  }

  sum = 0;

  for(i = 0 ; i < n ; i++) {
    if(p[i] != -1)
      sum += M[i][p[i]];
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2112
#include<iostream>
using namespace std;
typedef long long ll;
long long a[51], p[51];
ll f(ll n, ll x);
int main() {
    ll n, x;
    cin >> n >> x;
    a[0] = p[0] = 1; //レベル0バーガー Pのみ
    for (int i = 1; i <= n; i++) {
        a[i] = 1 + a[i - 1] + 1 + a[i - 1] + 1;
        p[i] = p[i - 1] + 1 + p[i - 1];
    }
    cout << f(n, x) << endl;
}
ll f(ll n, ll x) {
    if (n == 0) { //レベル0バーガー
        if (x <= 0) { //下から0層 ないでしょ
            /* <= を == にしたら input 2 7 で事故った
             2 7
             else return p[1] + 1 + f(1, 7 - (1 + a[1] + 1) = 3 + 1 + f(1, 0)
             1 0
             レベル1バーガーの下から0層？ 0
             a[-1]?
             */
            return 0;
        } else {
            return 1;
        }
    } else if (x <= 1 + a[n - 1]) { // B + (前のバーガー)
        return f(n - 1, x - 1); //一番下のBを除いた
    } else { //上の P + (前のバーガー) + B
        return p[n - 1] + 1 + f(n - 1, x - (1 + a[n - 1] + 1));
        //下の B + (前のバーガー) + P を除く 一番上のBはどうでもいい
        //1層下のバーガーで下から、上のバーガーで除いた B + () + P を除いた残りの個数をみる
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, T, A, s, cnt;
  double ans;
  int H[1010];
  cin >> N >> T >> A;
  for ( int i = 0; i < N; i++ ){
    cin >> H[i];
  }
  s = T - A;
  ans = 300;
  for ( int i = 0; i < N; i++ ) {
  if ( ans > abs(s -H[i] * 0.006 ) ){
    ans = abs(s -H[i] * 0.006 );
    cnt = i + 1;
  }
  }
  cout << cnt << endl;
}

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

using namespace std;

int main(){
    string S; cin >> S;
    vector<long long> res(S.size()+1, 0);
    for(int i=0;i<S.size();i++){
        if(S[i] == '<') res[i+1] = max(res[i+1], res[i]+1);
    }
    for(int i=S.size();i>0;i--){
        if(S[i-1] == '>') res[i-1] = max(res[i-1], res[i]+1);
    }
    cout << accumulate(res.begin(), res.end(), 0LL) << endl;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  string s ;
  deque <char>  data ;
  int n ;
  cin >> s >> n ;
  rep(i,s.size()) data.push_back(s.at(i)) ;
  int now = 0 ;
  
  rep(i,n){
    int T ;
    cin >> T ;
    if(T == 1) now ++ ;
    else{
      int F ;
      char c ;
      cin >> F >> c ;
      if(F == 1){ 
        if(now%2 == 0) data.push_front (c) ;
        else           data.push_back(c) ;
      }
      else {
        if(now%2 == 1) data.push_front (c) ;
        else           data.push_back  (c) ;
    }
  }
    
}
 
  if(now % 2 == 0)   rep(i,data.size()) cout << data.at(i) ;
  else               rep(i,data.size()) cout << data.at(data.size() - i-1) ;
  
}


Measured memory_bytes: 3980
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int ans = 0;

		for(int i = 1; i <= N; i++) {
			if(String.valueOf(i).length() % 2 == 1) {
				ans++;
			}
		}

		System.out.println(ans);
	}
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,P[40];
ll mk[5];
ll i,j,ans;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &P[i]);
    }
    fornum(i,2,N){
        if(P[i-2]<P[i-1]&&P[i-1]<P[i]){
            ans++;
        }
        if(P[i-2]>P[i-1]&&P[i-1]>P[i]){
            ans++;
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int d = scan.nextInt();
        int n = scan.nextInt();
        System.out.println((int) Math.pow(100.0, (double) d) * (n + n / 100));
    }

}


Measured memory_bytes: 22736
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;

	vll A(N), B(N);

	rep(i, 0, N) {
		std::cin >> A[i];
	}
	rep(i, 0, N) {
		std::cin >> B[i];
	}

	ll sub=0;
	rep(i, 0, N) {

		if (A[i] > B[i]) {
			sub += A[i] - B[i];
		}
		else {
			sub -= (B[i] - A[i]) / 2;
		}

	}
	if (sub <=0) {
		std::cout << "Yes" << endl;
	}
	else {
		std::cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	fmt.Println(solve(N))
}

func solve(N int) int {
	if N%2 == 1 {
		return 0
	}
	ans := 0
	denom := 10
	for N >= denom {
		ans += N / denom
		denom *= 5
	}
	return ans
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a==b && b==c){
  cout <<"No"<< endl;}
  else if (a == b || b == c || c == a){
    cout <<"Yes"<< endl;
  }
  else{
    cout <<"No"<< endl;
  }
}

Measured memory_bytes: 256
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
const int INF =100100100;
const int MOD = (int)1e9+7;
const double EPS = 1e-9;
typedef long long ll;
typedef long li;
#define pb push_back 
#define mp make_pair

signed main (){	
	int XX,YY,ZZ,KK;
	ll t;
	vector <ll> x,y,z,all;
	cin >> XX >> YY >> ZZ >> KK ;
	rep(i,XX){
		cin >> t;
		x.pb(t);
	}
	rep(i,YY){
		cin >> t;
		y.pb(t);
	}
	rep(i,ZZ){
		cin >> t;
		z.pb(t);
	}
	sort(x.rbegin(),x.rend());
	sort(y.rbegin(),y.rend());
	sort(z.rbegin(),z.rend());

	rep(i,XX){
		rep(j,YY){
			rep(k,ZZ){
				if(i*j*k > KK) {
					break;
				} else {
					all.pb(x[i]+y[j]+z[k]);
				}
			}
		}
	}
	sort(all.rbegin(),all.rend());
	rep(i,KK){
		cout << all[i] << endl;
	}
	return 0;
}


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


int main() 
{
  int N, K;
  cin >> N >> K;
  vector<ll> X(N), sortedX(N), Y(N), sortedY(N);
  for (int i = 0; i < N; ++i)
  {
    cin >> X.at(i) >> Y.at(i);
    sortedX.at(i) = X.at(i);
    sortedY.at(i) = Y.at(i);
  }
  sort(sortedX.rbegin(), sortedX.rend());
  sort(sortedY.rbegin(), sortedY.rend());
  ll result = (sortedX.at(0) - sortedX.at(N - 1)) * (sortedY.at(0) - sortedY.at(N - 1));
  for (int xi = 0; xi < N - 1; ++xi) {
    for (int xj = xi + 1; xj < N; ++xj) {
      for (int yi = 0; yi < N - 1; ++yi) {
        for (int yj = yi + 1; yj < N; ++yj) {
          ll upperX = sortedX.at(xi), lowerX = sortedX.at(xj),
          upperY = sortedY.at(yi), lowerY = sortedY.at(yj);
          int cnt = 0;
          for (int i = 0; i < N; ++i) {
            ll x = X.at(i), y = Y.at(i);
            if (lowerX <= x && x <= upperX && lowerY <= y && y <= upperY) {
              ++cnt;
            }
          }
          
          if (K <= cnt) {
            ll area = (upperX - lowerX) * (upperY - lowerY);
            result = min(result, area);
          }
        }
      }
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(S: str):

    Sr = list(S)[::-1]

    ans = 0
    for i in range(len(S)):
        if S[i] != Sr[i]:
            ans += 1

    print(ans//2)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
str = input()
#print(int(a[-4]), int(a[-3]), int(a[-2]), int(a[-1]))
a=str[-4]
b=str[-3]
c=str[-2]
d=str[-1]
count = 0
if(a is b):
    #print("No")
    count += 1
elif(a is c):
    #print("No")
    count += 1
elif(a is d):
    #print("No")
    count += 1
else:
    pass
if(b is c):
  count += 1
elif(b is d):
  count += 1
else:
  pass

if(c is d):
  count += 1
else:
  pass

if(count is 2):
  print("Yes")
else:
  print("No")
    

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

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

Measured memory_bytes: 256
object Main extends App {
  val primes: Stream[Int] = 2 #:: (Stream.from(3, 2) filter {n =>
    primes takeWhile {_ <= Math.sqrt(n).toInt} forall {n % _ != 0}
  })
  println(primes.filter(_ % 5 == 1).take(io.StdIn.readLine.toInt).mkString(" "))
}

Measured memory_bytes: 25412
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#define _GLIBCXX_DEBUG//.at(i)を[i]と書いても許される
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
int n;

int main(){
	cin >> n ;
	vector<int> A(n);//押したら次に光るボタンの番号
	rep(i,n){
		cin>>A.at(i);
	}
	int ans = 0;//`押す回数　2にならなきゃ-1にする
	//ずっと同じところでくるくる回っても、最終的にfalseのままだから問題ない
	int bomb = 0;//次に押すボタン
	bool a = false;
	rep(i,n){
		ans ++;
		if(A[bomb]==2){
			a = true;
			break;
		}
		else{
			bomb = A[bomb]-1;
		}
	}
	if(a){
		cout<<ans<<endl;
	}
	else{
		cout<<-1<<endl;
	}
}
			



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

int main()
{
    string s, t;
    cin >> s >> t;
    vector<vector<int>> alphabet_count(30);
    rep(i, s.size())
    {
        alphabet_count[s[i] - 'a'].push_back(i + 1);
    }

    long long index = 0;
    long long loop_count = 0;
    rep(i, t.size())
    {
        int c = t[i] - 'a';
        if (alphabet_count[c].size() == 0)
        {
            cout << -1 << endl;
            return 0;
        }
        else
        {
            auto it = upper_bound(alphabet_count[c].begin(), alphabet_count[c].end(), index);
            if (it == alphabet_count[c].end())
            {
                loop_count++;
                index = alphabet_count[c][0];
            }
            else
            {
                index = *it;
            }
        }
    }

    long long ans = index + loop_count * s.size();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
  	int b4 = 0;
  	int b = 0;
  	cin >> n;
  	vector<int> a(n);
  	for(int i=0;i<n;i++) {
    	cin >> a[i];
    }
  	sort(a.begin(), a.end());
  	
  	for(int i=0;i<n;i++) {
    	if(b4!=a[i]) {
        	b+=1;
          	b4 = a[i];
        }
    }
  	cout << b-1+(b%2) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ll x; cin >> x;
    for(ll i=0;i<=1000;i++){
        for(ll j=-1000;j<=1000;j++){
            if(pow(i,5) - pow(j,5) == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4068
use std::io::*;
use std::str::FromStr;

//portable utility
#[allow(dead_code)]
fn switch<T>(flag: bool, true_value: T, false_value: T) -> T {
    if flag {
        true_value
    } else {
        false_value
    }
}

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

#[allow(dead_code)]
fn read_string() -> Vec<char> {
    read::<String>().chars().collect()
}

#[allow(dead_code)]
fn read_vector<T: FromStr>(number: usize) -> Vec<T> {
    (0..number).map(|_| read()).collect()
}

fn main() {
    let text = read_string();
    if text == vec!['A', 'B', 'C'] {
        println!("ARC");
    } else {
        println!("ABC");
    }
}


Measured memory_bytes: 2108
import Control.Applicative
main = do
    solve
solve = do
    n <- fmap (read :: String -> Int) . words <$> getLine
    let area = (n !! 0) * (n !! 1)
        length = ((n!!0) + (n!!1)) * 2
    putStrLn $ show area ++ " " ++ show length

Measured memory_bytes: 3620
// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl
#define Nayon ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define gcd(a,b)         __gcd(a,b)
#define lcm(a,b)         (a/gcd(a,b))*b


using namespace std;


int main()
{
	Nayon;
	int i,len=0,result=0;
	string s;
	cin>>s;
	for(i=0;i<s.size();i++){
		if(s[i]=='R'){
			len++;
			result=max(result,len);
		}
		else{
			len=0;
		}
	}
	cout<<result<<nl;
	return 0;
}

//Happy Coding......

Measured memory_bytes: 3612
#include <stdio.h>

int main(int argc, char const *argv[])
{
	long int n;
	int i;


	scanf("%ld",&n);
	if (n >= 1 && n <= 20) {
		for(i = n - 1; i > 0; --i) {
			n *= i;
			// printf("%ld %d\n", n,i);
			// デバッグ
		}
		printf("%ld\n", n);
	}
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define push_back pb
#define make_pair mp
using ll =  long long;
const int INF = 0x3f3f3f3f;

ll r,D,x;

void solve()
{
	for(int i=0;i<10;++i){
		ll cur = r*x-D;
		cout << cur << "\n";
		x=cur;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> r >> D >> x;
	solve();
	return 0;
}

Measured memory_bytes: 256
Var
     a: Array[1..100] Of Integer;
     b: Array[1..100] Of Integer;
     i,j,m,n,f,count,max,min,ans: Longint;
Begin
  read(n);
  For i:=1 To n Do
    read(a[i]);
		ans:=2000000;
  For j:=-100 To 100 Do
    Begin
      count := 0;
      For i:=1 To n Do
        Begin
          count := count+Sqr(j-a[i]);
        End;
			if ans>count then ans:=count;
    End;
  Write(ans);
End.


Measured memory_bytes: 128
N,*L = map(int, open(0).read().split())
L.sort()
if N <= 2:
    print(0)
else:
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            for k in range(j+1,N):
                if L[i] == L[j] or L[j] == L[k]:
                    continue
                else:
                    if L[i] + L[j] > L[k]:
                        ans += 1
    print(ans)

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

ll N,K,a,idx;


int main(void){
    cin >> N >> K;
    rep(i,N){
        cin >> a;
    }
    if((N-1)%(K-1)==0)cout << (N-1)/(K-1) << endl;
    else     cout << (N-1)/(K-1)+1 << endl;
}


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

int main(){
  int xl=0,xr,yu=0,yt,n,x,y,a;cin>>xr>>yt>>n;
  REP(i,n){
    cin>>x>>y>>a;
    if(a==1) xl=max(xl,x);
    else if(a==2) xr=min(xr,x);
    else if(a==3) yu=max(yu,y);
    else yt=min(yt,y);
  }

  cout<<max(0,(xr-xl))*max(0,(yt-yu));
}


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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer;

        tokenizer = new StringTokenizer(reader.readLine());
        int N = Integer.parseInt(tokenizer.nextToken());

        tokenizer = new StringTokenizer(reader.readLine());
        int i = 0;
        int[] arr = new int[N];

        while (tokenizer.hasMoreTokens()) {
            arr[i] = Integer.parseInt(tokenizer.nextToken());
            i++;
        }

        int[] cost = new int[N];

        cost[N-1] = 0;
        cost[N-2] = Math.abs(arr[N-2] - arr[N-1]);

        for (int j=N-3; j>=0; j--) {
            cost[j] = Math.min(Math.abs(arr[j] - arr[j+1]) + cost[j+1], Math.abs(arr[j] - arr[j+2]) + cost[j+2]);
        }

        System.out.println(cost[0]);
    }
}


Measured memory_bytes: 31448
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int x=(a+b);
    int y=(b+c);
    int z=(c+a);
     x=min(x,y);
     z=min(x,z);
    cout<<z<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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() {
    int d, n; cin >> d >> n;
    vector<int> t(d), a(n), b(n), c(n);
    REP(i, d) cin >> t[i];
    REP(i, n) cin >> a[i] >> b[i] >> c[i];

    // dp[i][j] := i日目に服jをきた時の最大値
    auto dp = make_v(d + 1, n, 0);

    // i日目に服jを着ることが可能か
    auto check = [&](int i, int j) {
        return a[j] <= t[i] && t[i] <= b[j];
    };

    REP(i, d - 1)REP(j, n)REP(k, n){
        if (check(i + 1, j) && check(i, k)) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abs(c[j] - c[k]));
        }
    }

    int ans = *max_element(dp[d - 1].begin(), dp[d - 1].end());
    
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3276
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <algorithm>
typedef long long ll;
typedef long double ld;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define INF INT_MAX
#define fi first
#define sec second
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--){solve();}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#define pq_max priority_queue<ll>
#define pq_min priority_queue<ll,vector<ll>,greater<ll>>
using namespace std;

void solve()
{
   //code
}


int main() {
	// your code goes here
	fast;
    ll n;
    cin>>n;
    int c=0;
    string f="No";
    fr(i,n){
        int a,b;
        cin>>a>>b;
         if(a==b)
         {
             c++;
         }
         else
         {
             c=0;
         }
         if(c==3)
         {
             f="Yes";
         }
    }
    cout<<f<<endl;
	return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int N, D;

    cin >> N >> D;

    cout << ceil((double)((double)N / (2 * (double)D + 1))) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int r, d, x, i;
    
    scanf("%d%d%d",&r,&d,&x);
    
    for(i=0;i<10;i++){
        x=r*x-d;
        printf("%d\n",x);
    }
    return 0;
}

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

public class P
{
    public int x { get; set; }
    public int y { get; set; }
}

public class Q
{
    public int x { get; set; }
    public int y { get; set; }
    public int L { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var n = int.Parse(line[2]);
        var map = new bool[h, w];
        var d = new Dictionary<int, P>();
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                if (s[j] == 'S') d[0] = new P { x = i, y = j };
                else if (s[j] == 'X') map[i, j] = true;
                else if (s[j] != '.') d[int.Parse(s[j].ToString())] = new P { x = i, y = j };
        }
        var count = 0;
        var start = new P();
        var g = new P();
        for (int i = 1; i <= n; i++)
        {
            start.x = d[i - 1].x; start.y = d[i - 1].y;
            g.x = d[i].x; g.y = d[i].y;
            count += goBfs(map, start, g);
        }
        Console.WriteLine(count);
    }
    public static int goBfs(bool[,] map, P s, P g)
    {
        var h = map.GetLength(0);
        var w = map.GetLength(1);
        var map2 = new bool[h, w];
        var dx = new int[] { 0, 1, 0, -1 };
        var dy = new int[] { 1, 0, -1, 0 };
        var q = new Queue<Q>();
        q.Enqueue(new Q { x = s.x, y = s.y, L = 0 });
        map2[s.x, s.y] = true;
        while (q.Count() > 0)
        {
            var t = q.Dequeue();
            if (t.x == g.x && t.y == g.y) return t.L;
            for (int i = 0; i < 4; i++)
            {
                var nx = t.x + dx[i];
                var ny = t.y + dy[i];
                if (nx >= 0 && nx < h && ny >= 0 && ny < w && !map[nx, ny] && !map2[nx, ny])
                { map2[nx, ny] = true; q.Enqueue(new Q { x = nx, y = ny, L = t.L + 1 }); }
            }
        }
        return 0;
    }
}






Measured memory_bytes: 17076
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {
  
  int x;
  cin >> x;
  cout << (1 - x) << endl;

  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,x,a[N];
int main()
{
	scanf("%d%d",&x,&n);
	for(int i=1;i<=n;i++)
	{
		int y;
		scanf("%d",&y);
		a[y]=1;
	}
	for(int i=0;;i++)
	{
		if(!a[x-i])
		{
			printf("%d\n",x-i);
			break;
		}
		if(!a[x+i])
		{
			printf("%d\n",x+i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3824
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	boolean[][][] dice = new boolean[6][3][3];
	
	int minrote(int n) {
		if (n == 0) {
			if ((dice[0][2][0] || dice[0][2][1] || dice[0][2][2]) && (dice[2][2][0] || dice[2][2][1] || dice[2][2][2]))
				return 0;
			if ((dice[0][0][2] || dice[0][1][2] || dice[0][2][2]) && (dice[2][0][0] || dice[2][1][0] || dice[2][2][0]))
				return 1;
			if ((dice[0][0][0] || dice[0][1][0] || dice[0][2][0]) && (dice[2][0][2] || dice[2][1][2] || dice[2][2][2]))
				return 1;
			if ((dice[0][0][0] || dice[0][0][1] || dice[0][0][2]) && (dice[2][0][0] || dice[2][0][1] || dice[2][0][2]))
				return 2;
		}
		if (n == 1) {
			if ((dice[1][0][2] || dice[1][1][2] || dice[1][2][2]) && (dice[3][0][0] || dice[3][1][0] || dice[3][2][0]))
				return 2;
			if ((dice[1][0][0] || dice[1][1][0] || dice[1][2][0]) && (dice[3][0][2] || dice[3][1][2] || dice[3][2][2]))
				return 2;
			if ((dice[1][2][0] || dice[1][2][1] || dice[1][2][2]) && (dice[3][2][0] || dice[3][2][1] || dice[3][2][2]))
				return 3;
			if ((dice[1][0][0] || dice[1][0][1] || dice[1][0][2]) && (dice[3][0][0] || dice[3][0][1] || dice[3][0][2]))
				return 3;
		}
		if (n == 2) {
			if ((dice[4][2][0] || dice[4][2][1] || dice[4][2][2]) && (dice[5][0][0] || dice[5][0][1] || dice[5][0][2]))
				return 1;
			if ((dice[4][0][0] || dice[4][0][1] || dice[4][0][2]) && (dice[5][2][0] || dice[5][2][1] || dice[5][2][2]))
				return 1;
			if ((dice[4][0][2] || dice[4][1][2] || dice[4][2][2]) && (dice[5][0][2] || dice[5][1][2] || dice[5][2][2]))
				return 2;
			if ((dice[4][0][0] || dice[4][1][0] || dice[4][2][0]) && (dice[5][0][0] || dice[5][1][0] || dice[5][2][0]))
				return 2;
			
		}
		return 10000;
	}
	
	void run() {
		String s;
		
		while (true) {
			s = sc.nextLine();
			if (s.equals("#")) break;
			
			for (int i = 0; i < 6; i++) {
				for (int j = 0; j < 3; j++) {
					for (int k = 0; k < 3; k++) {
						dice[i][j][k] = s.charAt(k) == '*';
						
					}
					s = sc.nextLine();
				}
			}
			
			int min = 10;
			for (int i = 0; i < 3; i++)
				min = Math.min(min, minrote(i));
			
			out.println(min);
			
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 25376
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
 
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //  cin >> tc;
    while (tc--)
    {
        string s;
        cin >> s;
        for (int i = 0; i < s.size();i++){
            if(s[i]=='?'){
                s[i] = 'D';
            }
        }
        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 3784
N = int(input())
A = list(map(int, input().split())) 
 
goukei = 0

sumA = sum(A)
for i in range(N):
    a = A[i]
    sumA = sumA - a
    goukei = goukei + sumA*a

k = 10**9 + 7
print(goukei%k)

Measured memory_bytes: 31636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    int p[m];
    string s[m];
    rep(i, 0, m) {
        cin >> p[i] >> s[i];
        p[i]--;
    }
    bool ac[n] = {};
    int wa[n] = {};
    int ans1 = 0, ans2 = 0;
    rep(i, 0, m) {
        if (s[i] == "WA") {
            if (!ac[p[i]]) {
                wa[p[i]]++;
            }
        } else {
            if (!ac[p[i]]) {
                ans1++;
                ac[p[i]] = true;
                ans2 += wa[p[i]];
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}


Measured memory_bytes: 6528
// Author:Eleus Ahammad, CSE, KUET
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define vii vector<pii>
#define vi vector<int>
#define F first
#define S second
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ifile freopen("input.txt", "r", stdin)
#define ofile freopen("output.txt", "w", stdout)
#define MOD 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0) return a;
    return gcd(b, a%b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
ll modpow(ll a, ll b, ll m)
{
    if (b == 0) return 1%m;
    ll u = modpow(a, b / 2, m);
    u = (u * u)%m;
    if (b%2) u = (a * u)%m;
    return u;
}
ll egcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll x1, y1;
    ll d = egcd(b, a%b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
// Code begins here

void solve()
{
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << endl;
}


int main()
{
    fastio;
    int t = 1;
    //cin >> t;

    while (t--) {
        solve();
    }
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
    string s;
    int K;
    cin >> s;
    scanf("%d", &K);
    
    for ( int i = 0; i < s.size(); i++ ) {
	if ( K == 0 ) break;
	int dist = ('z' + 1 - s[i]) % ('z' + 1 - 'a');
	if ( dist <= K ) {
	    s[i] = 'a';
	    K -= dist;
	}
    }

    if ( K > 0 ) {
	if ( (s[s.size()-1] + K) > 'z' ) {
	    K -= 'z' - s[s.size()-1] + 1; // 'a'にする
	    s[s.size()-1] = 'a' + K % ('z' - 'a' + 1);
	    K = 0;
	}
	else {
	    s[s.size()-1] += K;
	    K = 0;
	}
    }

    cout << s << endl;

    return 0;
}


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

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

  int n, d, x;
  cin >> n >> d >> x;
  int a, ans = x;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    for (int j = 1; j <= d; ++j) {
      if ((j - 1) % a == 0)
        ++ans;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define dbg(x) cerr << #x"=" << x << endl;
const int MAX_N = 110;
int n;
int sum[MAX_N];

int main(){
  //  freopen("in.txt", "r", stdin);
    cin >> n;
    int x;
    sum[0] = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> x;
        sum[i] = x+sum[i-1];
    }
    int ans = 1 << 30;
    for(int i = 1; i <= n; ++i){
        ans = min(ans, abs(sum[i] - (sum[n]-sum[i])));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
 
int main() {
    ll x, k, d;
    cin >> x >> k >> d;
 
    if(x < 0) {
        x *= -1;
    }
 
    ll a = x/d;
    ll b = x%d;
 
    if(k < a) {
        out(x - d*k);
    }
    else {
        if(k%2 == a%2) {
            out(b);
        }
        else {
            out(d - b);
        }
    }
    
    re0;
}

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

int main()
{
    int n,x;

    cin>>n>>x;
    vector<int>a(n);

    for(int i=0;i<n;i++)
    {
        cin>>a.at(i);
    }

    sort(a.begin(),a.end());
    int flag=0;
    for(int i=0;i<n;i++)
    {
        x=x-a.at(i);

        if(x<0)
        {
          break;
        }
        flag++;

    }

    if(x>0)
    {
        flag--;
    //cout<<" "<<flag<<endl;
    }
    cout<<flag<<endl;
    return 0;

}


Measured memory_bytes: 3640
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include<time.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
struct edge {
	int to,Next;
}Edge[maxn<<1];
int Head[maxn],tot;
ll val[maxn],sum[maxn],sz[maxn],rev[maxn];
void Add(int from, int to) {
	Edge[tot]={to,Head[from]};
	Head[from]=tot++;
	Edge[tot]={from,Head[to]};
	Head[to]=tot++;
}
void dfs(int u, int fa) {
	sz[u]=1;
	ll num=sum[val[u]];
	ll Last=sum[val[u]];
	for (int i=Head[u]; ~i; i=Edge[i].Next) {
		int v=Edge[i].to;
		if (v==fa) continue;
		dfs(v,u);
		sz[u]+=sz[v];
		ll cnt=sz[v]-(sum[val[u]]-Last);
		rev[val[u]]+=(1+cnt)*cnt/2;
		Last=sum[val[u]];
	}
	sum[val[u]]+=sz[u]-(sum[val[u]]-num);
} 
int main(){
	memset(Head,-1,sizeof(Head));
    int n;
    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
    	scanf("%lld",&val[i]);
	}
    for (int i=1; i<n; i++) {
    	int u,v;
    	scanf("%d%d",&u,&v);
    	Add(u,v);
	}
    dfs(1,0);
    ll Max=1ll*n*(n+1)/2;
    for (int i=1; i<=n; i++) {
    	if (sum[i]<n) {
    		ll cnt=n-sum[i];
    		rev[i]+=(cnt+1)*cnt/2;
		}
	}
	for (int i=1; i<=n; i++) printf("%lld\n",Max-rev[i]);
    return 0;
}


Measured memory_bytes: 32536
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for(int (I)=(A);(I)<(B);++(I))
#define ALL(C) (C).begin(),(C).end()
#define INPUT(P) cin>>(P);
#define INPUT2(P1,P2) cin>>(P1)>>(P2);
#define INPUT3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3);
#define INPUTS(I,A,B,V) FOR(I,A,B)cin>>V[I];
#define OUTPUT(P) cout<<P<<endl;
#define OUTPUTS(I,A,B,V) FOR(I,A,B)cout<<V[i]<<endl;
typedef long long ll;
const double INF = 1e9;
inline void solve()
{
  int N,T;
  INPUT2(N,T)
  vector<pair<int, int> > D;
  FOR(i,0,N) {
    int tmp1,tmp2;
    INPUT2(tmp1,tmp2)
    D.push_back(pair<int,int>(tmp1,tmp2));
  }
  sort(ALL(D));
  bool output = false;
  FOR(i,0,N) {
    if (D[i].second <= T) {
      OUTPUT(D[i].first)
      output = true;
      break;
    }
  }
  if (!output) {
    OUTPUT("TLE")
  }
}
int main(int argc,char**argv)
{
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  cout << n*(n+1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
An = list(map(int, input().split()))
An.sort(reverse=True)
ans = An[0]
for i in range(1,n):
  if An[i] == 0:
    ans = 0
    break
  if An[i] > (10 ** 18):
    ans = -1
    break;
if ans > 0:
  ans = An[0]
  for i in range(1,n):
    if An[i] > (10 ** 18):
      ans = -1
      break
    ans *= An[i]
    if ans > (10 ** 18):
      ans = -1
      break

print(str(ans))


Measured memory_bytes: 21592
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

string s;
int cnt[212345];
set<int> ss[26];

int main() {
	cin >> s;
	
	int done[26] = {}, c = 0, now = 0;
	for (int i = s.size() - 1; i >= 0; i--) {
		cnt[i] = now;
		if (!done[s[i]-'a']) {
			done[s[i]-'a'] = true;
			if (++c == 26) {
				c = 0;
				REP(j, 26) done[j] = false;
				now++;
			}
		}
		
		ss[s[i]-'a'].insert(i);
	}
	
	string ans = "";
	int pos = -1;
	
	while (true) {
		bool f = false;
		REP(i, 26) {
			set<int>::iterator it = ss[i].upper_bound(pos);
			if (it != ss[i].end() && cnt[*it] >= now) continue;
			
			ans += i + 'a';
			now--;
			pos = *it;
			if (it == ss[i].end()) f = true;
			break;
		}
		if (f) break;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 10628
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int n;
vvi G;
pii dfs(int a,int p){
	int sum=0,co=0,c=0,h=1;
	rep(i,G[a].size())if(G[a][i]-p){
		pii t=dfs(G[a][i],a);
		sum+=t.first;
		c++;
		co+=t.second;
		if(!t.second)h=0;
	}
	if(c>=2)h=0;
	if(co)sum+=co-1;
	return {sum,h};
}
signed main(){
	cin>>n;
	G=vvi(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		G[a].pb(b);
		G[b].pb(a);
	}
	int it=-1;
	rep(i,n)if(G[i].size()>2)it=i;
	if(it+1)cout<<dfs(it,-1).first<<endl;
	else cout<<1<<endl;
}















Measured memory_bytes: 10240