akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

int main()
{
    string s, t;
    cin >> s >> t;
    string flag = "Yes";
    for (int i = 0; i < s.size(); i++)
    {
        if (s.at(i) != t.at(i))
        {
            flag = "No";
            break;
        }
    }

    cout << flag << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
  string s1,s2;
  ll count=0;
  cin>>s1>>s2;
  for(ll i=0;s1[i]!='\0';i++){
    if(s1[i]!=s2[i]){
    	count++;
    }
  }
  cout<<count;
}


Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  vector<int64_t> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  int k;
  cin >> k;
  sort(a.begin(),a.end());
  cout << a.at(0) + a.at(1) + (a.at(2) << k) << endl;
}

Measured memory_bytes: 256
def main():
    x1, y1, x2, y2 = map(int, input().split())

    ans = editorial(x1, y1, x2, y2)
    # assert ans == twi(x1, y1, x2, y2)
    print(*ans)


def twi(x1, y1, x2, y2):
    """
    https://twitter.com/akensho/status/1035924165205716992
    https://twitter.com/hogeover30/status/1035903937830764545
    """
    import math
    cos90 = int(math.cos(math.pi / 2))
    sin90 = int(math.cos(math.pi / 2))

    x = x2 - x1
    y = y2 - y1
    x4 = x * cos90 - y * sin90 + x1
    y4 = x * sin90 + y * cos90 + y1

    x = x1 - x4
    y = y1 - y4
    x3 = x * cos90 - y * sin90 + x4
    y3 = x * sin90 + y * cos90 + y4

    return x3, y3, x4, y4


def editorial(x1, y1, x2, y2):
    x = x2 - x1
    y = y2 - y1

    x3 = x2 - y
    y3 = y2 + x
    x4 = x1 - y
    y4 = y1 + x

    return x3, y3, x4, y4


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1;i<=n;i++) {
        int sum = 0;
        for(int j = 1;j <= n; j++) {
            if(i % j == 0) sum += 1;
        }
        if(sum == 8 && i % 2 == 1) ans += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    int a[n][m], b[m], temp[n][m];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            scanf("%d", &a[i][j]);       
        }
    }
    for (int i = 0; i < m; i++){
        scanf("%d", &b[i]);
    }
    for (int i = 0; i < n; i++){
        int sum = 0;
        for (int j = 0; j < m; j++){
            temp[i][j] = a[i][j] * b[j];
            sum = sum + temp[i][j];
        }
        printf("%d\n", sum);
    }
    return 0;
}


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

int main() {
	//cout<<"GfG!";
	int j,k,n,i,c=0;
	cin>>n;
	map<int,int>mp;
	for(i=1;i<105;i++)
	{
	for(j=1;j<105;j++)
	{
	for(k=1;k<105;k++){
	    mp[i*i+j*j+k*k+i*j+j*k+k*i]++;
	}}}
	for(i=1;i<=n;i++)
	cout<<mp[i]<<endl;
//	return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{

    lint n,x;
    cin >> n;

    lint ans;
    double m = sqrt(n);
    x = floor(m);

    IFOR(i,1, x+1){
        if(n%i==0){
            ans = n / i + i - 2;
            break;
        }
    }
    
    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  
 int n;
 cin>>n;
 long long a[n+1];
 long long whole[n+1]={0};
 int cat[n+1]={0};
 for (int i=1;i<=n;i++)
 {
     cin>>a[i];
     whole[a[i]]++;
 }
 long long tot=0;
 for (int i=1;i<=n;i++)
 {    long long t=whole[i];
     t=(t*(t-1))/2;
     tot=tot+t;
 }
 
 //cout<<whole[3]<<" "<<cat[3]<<endl;
 for (int i=1;i<=n;i++)
 {

      long long ans=tot-(whole[a[i]]-1);
      cout<<ans<<endl;
 }
 
}

Measured memory_bytes: 6528
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;
int n,k,a[1000000+100],maxx,nzd;
int main()
{
    scanf("%d %d",&n,&k);

    for (int i=1;i<=n;i++)scanf("%d",&a[i]),maxx = max(a[i],maxx);
    if (k>maxx){cout<<"IMPOSSIBLE"<<endl;return 0;}
    nzd = a[1];
    for (int i=1;i<=n;i++)nzd = __gcd(nzd,a[i]);
    for (int i=1;i<=n;i++)
    {
        if (a[i]==k){cout<<"POSSIBLE"<<endl;return 0;}
        if (k>a[i])continue;
        if ((a[i]-k)%nzd==0){cout<<"POSSIBLE"<<endl;return 0;}
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

int main(){
	
	char a[10001];
	int b,astr,ansj=0,ansi=0;
	
	while(scanf("%s",a)!=EOF){
		astr=strlen(a);
		ansj=0,ansi=0;
		for(b=0;b<astr;b++){
			if(a[b]=='J' && a[b+1]=='O' && a[b+2]=='I')ansj+=1;
			if(a[b]=='I' && a[b+1]=='O' && a[b+2]=='I')ansi+=1;
		}
		printf("%d\n%d\n",ansj,ansi);
	}
	return 0;
} 

Measured memory_bytes: 0
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] A = new int[n];
		for (int i = 0; i < n; i++) {
			A[i] = scan.nextInt();
		}
		for (int i = 0; i <= A.length - 1; i++) {
			int v = A[i];
			int j = i - 1;
			while (j >= 0 && A[j] > v) {
				A[j + 1] = A[j];
				j--;
			}
			A[j + 1] = v;
			for (int k = 0; k < A.length; k++) {
				System.out.print(A[k]);
				if(k<A.length-1){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

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

  in(int, n);
  in(string, s);
  V<int> l(n), r(n);
  for (int i = 1; i < n; ++i) {
    l[i] = l[i - 1] + (s[i - 1] == 'W');
  }
  for (int i = n - 2; i >= 0; --i) {
    r[i] = r[i + 1] + (s[i + 1] == 'E');
  }
  int ans = n;
  rep(i, n) ans = min(ans, l[i] + r[i]);
  out(ans);
}


Measured memory_bytes: 6076
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n,m;
    cin >> n >> m;
    vi a(n+1,-1);
    vi b(m+1,-1);
    rep(i,n) cin >> a[i+1];
    rep(i,m) cin >> b[i+1];
    sort(all(a));
    sort(all(b));
    rep(i,n)if(a[i] == a[i+1]){
        cout << 0 << endl;
        return 0;
    }
    rep(i,m)if(b[i] == b[i+1]){
        cout << 0 << endl;
        return 0;
    }
    int x = n;
    int y = m;
    int numx = 0, numy = 0;
    int ans = 1;
    for(int i = n*m; i > 0; i--){
        if(a[x] == i){
            numx++;
        }
        if(b[y] == i){
            numy++;
        }
        if(a[x] == i && b[y] == i){
            x--;y--;
            continue;
        }
        int diff = i - (n*m - numx*numy);
        //cout << i << " " << numx << " " << numy << " " << diff << endl;
        if(diff <= 0){
            cout << 0 << endl;
            return 0;
        }
        if(a[x] == i){
            ans = ans * numy % MOD;
            x--;
        }else if(b[y] == i){
            ans = ans * numx % MOD;
            y--;
        }else{
            ans = ans * diff % MOD;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int h = scanner.nextInt(),w = scanner.nextInt();
		char[][] picture = new char[h*2][w];
		for(int i=0;i<h*2;i++){
			String s = scanner.next();
			picture[i] = s.toCharArray();
			picture[i+1] = s.toCharArray();
			i++;
		}
		for(int i=0;i<h*2;i++){
			for(int j=0;j<w;j++){
				System.out.print(picture[i][j]);
			}
			System.out.println();
		}
	}

}


Measured memory_bytes: 29112
h,w=map(int,input().split())
grid =[list(input()) for i in range(h)]
visited=[[False]*w for i in range(h)]
ans=0
for i in range(h):
  for j in range(w):
    if visited[i][j]:
      continue
    q=[(i,j)]
    d={'#':0,'.':0}
    while q:
      cy,cx=q.pop(0)
      for ny,nx in ((cy+1,cx),(cy-1,cx),(cy,cx+1),(cy,cx-1)):
        if not(0<=ny<h and 0<=nx<w) or grid[cy][cx]==grid[ny][nx] or visited[ny][nx]:
          continue
        d[grid[ny][nx]]+=1
        visited[ny][nx]=True
        q.append((ny,nx))
    ans+=d['.']*d['#']
print(ans)

Measured memory_bytes: 5748
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <iterator>
#include <utility>
#include <unordered_map>


using namespace std;


vector<string> splitString(const string& str, const string& separator = " ") {
	vector<string> ret;

	std::size_t bp, ep;
	bp = ep = 0;
	while((ep = str.find_first_of(separator, bp)) != string::npos){
		if(bp != ep){
			ret.push_back(string(str.begin() + bp, str.begin() + ep));
		}
		bp = ep + 1;
	}

	if(bp <= str.size() - 1){
		ret.push_back(string(str.begin() + bp, str.end()));
	}

	return ret;
}


class ConversionTable {
public:
	ConversionTable(const std::vector<std::string>& data_set) {
		for(auto ite = std::begin(data_set); ite != std::end(data_set); ++ite) {
			auto data = splitString(*ite);
			table[data[0][0]] = data[1][0];
		}
	}

	char convertData(char data) {
		return (table.find(data) != std::end(table) ? table[data] : data);
	}

private:
	std::unordered_map<char, char> table;
};


template <class T>
T convertStringToNumber(const string& str) {
	stringstream ss;
	T ret;

	ss << str;
	ss >> ret;

	return ret;
}


vector<vector<string>> inputData() {
	vector<vector<string>> data_set;

	string buffer;

	while(true){
		getline(cin, buffer);
		int n = convertStringToNumber<int>(buffer);

		if(!n)
			break;

		vector<string> temp;
		for(int i = 0; i < n; ++i) {
			getline(cin, buffer);
			temp.push_back(buffer);
		}

		data_set.push_back(temp);
	}

	return data_set;
}


void one_process(const vector<string>& table, const vector<string>& data) {
	ConversionTable ct(table);

	for(auto ite = begin(data); ite != end(data); ++ite) {
		cout << ct.convertData((*ite)[0]);
	}
	cout << endl;
}


void doAllProcess() {
	auto data_set = inputData();

	for(auto ite = begin(data_set); ite != end(data_set); ite+=2)
		one_process(*ite, *(ite+1));
}


int main() {
	doAllProcess();

	return 0;
}


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

using namespace std;

using ll = long long;

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

    ll N, T, t;
    cin >> N >> T;

    ll sum = 0, bf = 0;
    for (int i = 0; i < N; ++i) {
        cin >> t;
        sum += min(T, t - bf);
        bf = t;
    }
    sum += T;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut it = s.split_whitespace();
	let n: usize = it.next().unwrap().parse().unwrap();
	let q: usize = it.next().unwrap().parse().unwrap();
	let mut rw = Vec::with_capacity(n);
	for _ in 0..n {
		let s: i32 = it.next().unwrap().parse().unwrap();
		let t: i32 = it.next().unwrap().parse().unwrap();
		let x: i32 = it.next().unwrap().parse().unwrap();
		rw.push((s, t, x));
	}
	rw.sort_by_key(|a| a.0);

	let mut e = vec![];
	for (s, t, x) in rw {
		let l = s - x;
		let r = t - x;
		e.push((l, x));
		e.push((r, -x));
	}
	e.sort();

	use std::io::Write;
	let out = std::io::stdout();
	let mut out = out.lock();
	let mut set = std::collections::BTreeSet::new();
	let mut e = e.into_iter().peekable();
	for d in it.take(q).map(|a| a.parse::<i32>().unwrap()) {
		while match e.peek() {
			Some(e) if e.0 <= d => true,
			_ => false,
		} {
			let e = e.next().unwrap();
			if e.1 > 0 {
				set.insert(e.1);
			} else {
				set.remove(&(-e.1));
			}
		}
		writeln!(out, "{}", set.iter().next().unwrap_or(&-1)).unwrap();
	}
}


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

using namespace std;

int main() {
	vector<int> v(10);
	for (int i=0; i<10; i++) cin >> v[i];
	sort(v.begin(), v.end());
	for (int i=0; i<3; i++) cout << v[9-i] << endl;
	return 0;
}

Measured memory_bytes: 1212
<?php
  $A = [];
  for($i=0; $i<3; $i++){
    $A[] = explode(" ",trim(fgets(STDIN)));
  }
  $line=[[],[],[]];
  $N = fgets(STDIN);
  for($j=0; $j<$N; $j++){
    $b = fgets(STDIN);
    for($p=0; $p<3; $p++){
      for($q=0; $q<3; $q++){
      	if($b == (int)$A[$p][$q]){
          $line[$p][] = $q;
        }
      }
    }
  }
  if(in_array(0,$line[0]) && in_array(0,$line[1]) && in_array(0,$line[2]) ||
     in_array(1,$line[0]) && in_array(1,$line[1]) && in_array(1,$line[2]) ||
     in_array(2,$line[0]) && in_array(2,$line[1]) && in_array(2,$line[2]) ||
     in_array(2,$line[0]) && in_array(1,$line[1]) && in_array(0,$line[2]) ||
     in_array(0,$line[0]) && in_array(1,$line[1]) && in_array(2,$line[2]) ||
     in_array(0,$line[0]) && in_array(1,$line[0]) && in_array(2,$line[0]) ||
     in_array(0,$line[1]) && in_array(1,$line[1]) && in_array(2,$line[1]) ||
     in_array(0,$line[2]) && in_array(1,$line[2]) && in_array(2,$line[2])){
    echo "Yes\n";
  }else{
    echo "No\n";
  }

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

const int MAX_N = 20;

int n;

long long ans;

int lst[MAX_N][MAX_N];

int get_first(int val) {
  while (val > 9) {
    val /= 10;
  }
  return val;
}

int get_last(int val) {
  return val % 10;
}

int main() {
  std::cin >> n;
  for (int i = 1; i <= n; ++i) {
    ++lst[get_first(i)][get_last(i)];
  }
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      ans = (1LL * ans + (1LL * lst[i][j] * (lst[j][i])));
    }
  }
  std::cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(A: int, B: int, C: int, K: int):
    if K <= A:
        print(K)
    elif K <= A+B:
        print(A)
    else:
        print(A-(K-(A+B)))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)


if __name__ == '__main__':
    main()


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

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


int main() {
	ll c,d;
  	cin>>c>>d;
  
  	ll ans=gcd(c,d);

  	
	
 
  
  cout <<c*d/ans<< endl;
  
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
	int count[4][3][10] = {0};
	int n, i, j, k, x = 0;
	int b, f, r, v;
	
	scanf("%d", &n);
	while(x < n){
		x++;
		scanf("%d %d %d %d", &b, &f, &r, &v);
		count[b-1][f-1][r-1] += v;
	}
	
	for(i = 0;i < 4; i++){
		if(i > 0) printf("####################\n");
		for(j = 0;j < 3; j++){
			for(k = 0;k < 10;k++){
				printf(" %d", count[i][j][k]);
			}
			printf("\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 2736
#include<stdio.h>
int main()
{
	char b;
	scanf("%c",&b);
	if(b=='A'){
		printf("T\n");
	}
	else if(b=='G') {
		printf("C\n");
	}
	else if (b=='T'){
		printf("A\n");
	}
	else {
		printf("G\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding space */
// IT 5000兆　欲しい
int main(){
  int n; cin >> n;
  ll sum = 0;
  ll tmp = LLINF;
  bool flag = 0;
  rep(i,n){
    ll a,b; cin >> a >> b;
    if(a != b) flag = 1;
    sum += a;
    if(a > b)
      tmp = min(tmp,b);
  }
  if(flag)
    cout << sum - tmp << endl;
  else
    cout << 0 << endl;
}

Measured memory_bytes: 384
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

void Init() {
	std::cin.tie(0); std::ios::sync_with_stdio(false);
	struct Init_caller { Init_caller() { Init(); } }caller;
}

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define rep(i,n) for(LL i=0;i<n;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INT_INF 1<<29
#define LL_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using ppi = pair<pi, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;
using vppi = vector<ppi>;


#pragma endregion

struct edge {
	int from, to, cost;
};

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL vmax(vi v, LL n) {
	int MAX = 0;
	f(i, 0, n) {
		MAX = max(MAX, v[i]);
	}
	return MAX;
}

LL vmin(vi v, LL n) {
	int MIN = LL_INF;
	f(i, 0, n) {
		MIN = min(MIN, v[i]);
	}
	return MIN;
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//エラトステネスの篩
void sieve(LL n) {
	vb s(n + 1, true);
	f(i, 2, n + 1) {
		for (int j = 2; i*j <= n; j++) {
			s[i*j] = false;
		}
	}
	cout << "2から" << n << "までの素数" << endl;
	f(i, 2, n + 1) {
		if (s[i]) {
			cout << i << " ";
		}
	}
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}


#pragma endregion 


/*****************************************************************************/

signed main() {
	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a*b));
	return 0;
}

Measured memory_bytes: 256
tmp = 10 ** 9 + 7

def div(n,T):
    _ = 1
    for t in range(T):
        _ *= n
        _ %= tmp
    return _
    
N = int(input())
a = div(10,N)
b = div(9,N)
c = div(8,N)

print((a + c - 2 * b) % tmp)

Measured memory_bytes: 63936
from itertools import product

N, M, X = map(int, input().split())
INF = 10**15
ans = INF
cl, al  = [], []
for _ in range(N):
    c, *a, = map(int, input().split())
    cl.append(c)
    al.append(a)

for i in product(range(2), repeat=N):
    b = [0]*M
    tc = 0
    for j, k in enumerate(i):
        if k:
            tc += cl[j]
            for o, p in enumerate(al[j]):
                b[o] += p
    if all(map(lambda x:x>=X, b)):
        ans = min(ans, tc)
print(ans if ans!=INF else -1)


Measured memory_bytes: 9224
#include <iostream>
#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 <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  lint cur = 0;
  lint ans = 0;
  lint n; cin >> n;
  for (int i = 0; i < n; i++) {
    lint a; cin >> a;
    if (i == 0) {
      cur = a;
    }
    if (cur > a) {
      ans += cur - a;
    }
    
    cur = max(cur, a);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int dp[55][55][3000];


main() {
    int N,A; cin >> N >> A;  
    int X[N]; rep(i,N) cin >> X[i];
    dp[0][0][0]=1;
    rep(i,N){
        rep(j,N){
            rep(k,2550){
                if(dp[i][j][k]==0) continue;
                dp[i+1][j+1][k+X[i]]+=dp[i][j][k];
                dp[i+1][j][k]+=dp[i][j][k];
            }
        }
    }
    ll ans=0;
    for (int i = 1; i <= N; i++)
    {
        ans+=dp[N][i][i*A];
    }
    cout << ans << endl;
    


    return 0;
}

Measured memory_bytes: 65792
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String ary[][] = new String[N][3];
		for(int i = 0; i < N; i++) {
			ary[i][0] = sc.next();
			ary[i][1] = sc.next();
			ary[i][2] = i + "";
		}
		
		Arrays.sort(ary, (a, b) -> Integer.compare(Integer.parseInt(b[1]), Integer.parseInt(a[1])));
		Arrays.sort(ary, (a, b) -> a[0].compareTo(b[0]));
		for(int i = 0; i < N; i++) {
			System.out.println(Integer.parseInt(ary[i][2]) + 1);
		}
	}
}

Measured memory_bytes: 26452
#include <stdio.h>
int main(void){
  int i, x[5];
  for (i=0; i<5; i++) {
    scanf("%d ", &x[i]);
  }
  for (i=0; i<5; i++) {
    if (x[i] == 0) {
      printf("%d\n", i+1);
      break;
    }
  }
}

Measured memory_bytes: 1732
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
//#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[5]={-1,0,1,0,0};
int dy[5]={0,-1,0,1,0};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------

    int n;cin>>n;
    V<string>s(n);
    set<string>ss;
    for(int i=0;i<n;i++){cin>>s[i];ss.insert(s[i]);}
    cout<<ss.size()<<endl;

    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

















































Measured memory_bytes: 25044
import sys
import math

n, k = [int(x) for x in sys.stdin.readline().rstrip().split()]

ipt = sys.stdin.readlines()
li = [0 for x in range(n)]

for i in range(1, len(ipt), 2):
	for j in ipt[i].split():
		x = int(j)
		li[x - 1] += 1

print(li.count(0))

Measured memory_bytes: 9224
#include <stdio.h>

int main(int argc, const char * argv[]) {
    long long int K,A,B;
    long long int i,vis=1;
    
    scanf("%lld %lld %lld",&K,&A,&B);
    
    if(B-A < 2){
        vis = vis+K;
    }
    else{
        i = K-(A-1);
        if(i>0){
        vis = A;
        vis += (i/2)*(B-A);
        vis += i % 2;
        }
    }
    printf("%lld\n",vis);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
int main(void){
    // Your code here!
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    int ans = 0;
    rep(i,h) cin >> s[i];
    rep(si,h) {
        rep(sj,w) {
        if(s[si][sj] == '#') continue;
        vector<vector<int>> dist(h,vector<int>(w,INF));
        queue<pair<int,int>> q;
        if (dist[si][sj] !=INF) continue;
        dist[si][sj] = 0;
        q.push(make_pair(si,sj));
        auto update = [&](int i ,int j, int x){
            if (dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(make_pair(i,j));
        };
        update(si,sj,0);
        while (!q.empty()) {
            int i = q.front().first;
            int j = q.front().second;
            q.pop();
            rep(dir,4) {
                int ni = i+di[dir],nj = nj = j + dj[dir];
                if ( ni<0 || ni>=h||nj<0||nj>=w)continue;
                if (s[ni][nj] == '#') continue;
                update(ni,nj,dist[i][j]+1);
            }
        }
        rep(i,h){
            rep(j,w) {
            if (dist[i][j] == INF)continue;
            ans = max(ans,dist[i][j]);
        }
        }
    }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s1[4], s2[4];
    int i, cnt = 0, l;
    scanf("%s %s", s1, s2);
    l = strlen(s1);
    for (i=0; i<l; i++) {
        if (s1[i] == s2[i]) cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    if (s[1] > s[0] || s[1] == s[0] && s[2] > s[0]) {
        s[0]++;
        s[2]=s[1] = s[0];        
    }
    else {
        s[2] = s[1] = s[0];
    }
    cout << s << endl;
}
    

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,k;
ll s[50];
ll dp[50][2];
int main(){
	scanf("%lld%lld",&n,&k);
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		rep(j,0,50)if(bit(t,j))s[j]++;
	}
	for(int j=45;j>=0;j--){
		if(bit(k,j)){
			dp[j][0]=dp[j+1][0]+((n-s[j])<<j);
			if(dp[j+1][1]==0)dp[j][1]=dp[j+1][0]+(s[j]<<j);
			else dp[j][1]=max(max(dp[j+1][1]+(s[j]<<j),dp[j+1][1]+((n-s[j])<<j)),dp[j+1][0]+(s[j]<<j));
		}else{
			dp[j][0]=dp[j+1][0]+(s[j]<<j);
			if(dp[j+1][1]==0)dp[j][1]=0;
			else dp[j][1]=max(dp[j+1][1]+(s[j]<<j),dp[j+1][1]+((n-s[j])<<j));
		}
	}
	printf("%lld\n",max(dp[0][0],dp[0][1]));
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
Interest Rates
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0240

"""
import sys


def solve(y, banks):
    return sorted([(1 + r * y / 100, b) if t == 1 else ((1 + r / 100) ** y, b) for b, r, t in banks])[-1][-1]


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        y = int(input())
        banks = [(int(i) for i in input().split()) for _ in range(n)]
        ans = solve(y, banks)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



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

int main()
{
    ll h, ans = 1;
    cin >> h;
    while(ans < h)
    {
        ans = ans * 2 + 1;
    }
    cout << ans << endl;
    return 0;
}


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

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

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

    for(int i=0;i<n-1;i++)
    {
        if(ar[i]!=i+1)
            count++;
    }

    if(count<=2)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    b:usize,
    c:usize,
    d:String,
    }
    let mut d=d.chars().collect_vec();
    let mut e=0;
    let mut f=0;
    for i in 0..a{
        if d[i]=='a'&&b+c>e+f{
            e+=1;
            println!("Yes")
        }
        else if d[i]=='b'&&b+c>e+f&&c>f{
            f+=1;
            println!("Yes")
        }
        else{println!("No")}
    }
}

Measured memory_bytes: 2644
import javax.swing.plaf.synth.SynthTextAreaUI;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        float ans = 0;
        for(int i = 0; i < n; i++){
            float x = sc.nextFloat();
            String u = sc.next();
            if(u.equals("BTC")){
                x *= 380000;
            }
            ans += x;
        }
        System.out.println(ans);
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 100100;

vector<pair<int, int>> roads;

int a[2];

void read() {
  cin >> a[0] >> a[1];

  for (int j = 0; j < 2; ++j) {
    for (int i = 0; i < a[j]; ++i) {
      int x;
      cin >> x;
      roads.emplace_back(x, j);
    }
  }
}

void kill() {
  sort(roads.begin(), roads.end());

  ll ans = 0;

  for (auto e : roads) {
    int cost = e.first;
    int j = e.second;
    ans += 1ll * cost * (a[j ^ 1] + 1);
    a[j]--;
  }

  cout << ans << endl;
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 2420
#include<stdio.h>
int main()
{
	int n;
	long long int a, b;
	scanf("%d %lld %lld", &n, &a, &b);
	int i;
	long long int x[100005];
	for (i = 0; i < n; i++)
		scanf("%lld", &x[i]);
	long long int ans = 0;
	for (i = 1; i < n; i++)
	{
		if (a * (x[i] - x[i - 1]) < b)
			ans += a * (x[i] - x[i - 1]);
		else
			ans += b;
	}
	printf("%lld\n", ans);
	return 0;
}

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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define MOD 1000000007
const double PI=3.14159265358979323846;
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; }
template<typename T> T Ceil(T a, T b){return (a+b-1)/b;}

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

ll n;
ll c[(int)2e5+100];
vint edges[(int)2e5+100];

ll memo[(int)2e5+100];
ll cnt_i[(int)2e5+100];
ll cnt;
ll ans[(int)2e5+100];

void f(ll par, ll now){

    memo[now] = cnt - cnt_i[c[now]];

    for(auto to:edges[now]){
        if(to == par) continue;
        f(now, to);
        ll tmp = (cnt - cnt_i[c[now]]) - memo[now];
        // cout<<"tmp: "<<tmp<<endl;
        ans[c[now]] -=  tmp*(tmp+1)/2;
        cnt_i[c[now]] += tmp;
    }
    cnt++;
    cnt_i[c[now]]++;
}

int main() {
    cout<<fixed<<setprecision(10);

    cnt = 0;
    cin>>n;
    rep(i,n){ cin>>c[i+1];}
    rep(i,n-1){
        ll a,b; cin>>a>>b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    edges[0].push_back(1);
    f(0, 1);
    repf(i,1,n+1){
        ll tmp = (cnt-cnt_i[i]);
        ans[i] -= tmp*(tmp+1)/2;
    }

    repf(i,1,n+1){
        cout<< ans[i] + n*(n+1)/2<<endl;
    }



    return 0;

}

Measured memory_bytes: 36220
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
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;}
ll INF = 1e+18;
int iINF = 1e9;

int N;
vector<double> arr;
vector<vector<double>> dp;

double
rec(int n, int front)
{
  if(dp[n][front] != 0) return dp[n][front];
  if(n == 0) return 1.0;
  
  rec(n - 1, front - 1);

  for(int i = n; i > 0; --i){
    dp[n][i] += dp[n - 1][i - 1] * arr[n - 1];
    dp[n][i - 1] += dp[n - 1][i - 1] * (1.0 - arr[n - 1]);
  }

  return dp[n][front];
}


int main()
{
  cin >> N;
  arr.resize(N);
  rep(i, 0, N) cin >> arr[i];
  dp.assign(N + 1, vector<double>(N + 1, 0));
  dp[0][0] = 1.0;

  rec(N, N);

  double ans = 0.0;
  repe(i, N / 2 + 1, N){
    ans += dp[N][i];
  }
  
  printf("%.10f\n", ans);
}


Measured memory_bytes: 74060
#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>;
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 (a>b) { a=b; return 1; } return 0; }

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

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

    UnionFind uf(n);

    rep(i,m){
        int a, b;
        cin >> a >> b;
        uf.unite(a,b);
    }

    int ans = 0;
    rep(i,n) chmax(ans, uf.size(i));

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

Measured memory_bytes: 3988
#include <iostream>
#include <string>
using namespace std;
int main() {
    string date;
    int dd = 0;
    cin >> date;
    dd += (date[5] -48)*1000;
    dd += (date[6] -48)*100;
    dd += (date[8] -48)*10;
    dd += (date[9] -48);

    if(dd <= 430){
        cout << "Heisei";
    } else{
        cout << "TBD";
    }
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    // data
    val map = mapOf('A' to 'a', 'B' to 'b', 'C' to 'c')

    // input
    val (length, index) = readLine()?.let { it.split(" ") }!!.map { it.toInt() }
    val text = readLine() ?: throw RuntimeException("no input.")

    // process
    val target = text.get(index - 1)

    // println(text.replace(target, map.get(target) ?: 'x'))
    println(text.substring(0..index-2)
            + map.get(target)
            + text.substring(index, length)
    )
}

Measured memory_bytes: 37908
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < (int) n; i++)
#define forin(i, a, b) for(int i = a; i < (int) b; i++) 
#define rofin(i, a, b) for(int i = a; i > b; i--)
#define v vector
#define sync ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define debug(i) cout << #i << ": " << i << endl
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int MOD = 2019;

int main() {
    sync;
    string s;
    cin >> s;
    int n = s.length();

    int suf = 0;
    int power_of_ten = 1;
    vector<int> cnt_suf(MOD);
    cnt_suf[0] = 1;
    ll answer = 0;

    rofin(i, n - 1, -1) {
        int digit = s[i] - '0';
        suf = (suf + digit * power_of_ten) % MOD;
        power_of_ten = 10 * power_of_ten % MOD;
        answer += cnt_suf[suf];
        cnt_suf[suf]++;
        // debug(power_of_ten);
        // debug(suf);
        // debug(cnt_suf[suf]);
    }

    cout << answer << endl;
}

Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
	while(1){
		int n,a,b,c,d; cin >>n>>a>>b>>c>>d;
		if(n==0&&a==0&&b==0&&c==0&&d==0)break;
		vector<int> y(n);
		for(int i=0;i<n;i++){
			cin >> y[i];
		}
		int ans=0;
		for(int i=0;i<n;i++){
			if(d==y[i]){}
			else{
				while(d!=y[i]){
					ans++;
					d=(a*d+b)%c;
					if(ans>10001)break;
				}
			}
			if(ans>10001)break;
			ans++;
			d=(a*d+b)%c;
		}
		if(ans-1>10000) cout << -1 << endl;
		else cout << ans-1 << endl;
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  map<char, int> mp;
  int n;
  cin >> n;
  rep(i, 0, n) {
    char a;
    cin >> a;
    mp[a]++;
  }
  if(mp.size() == 4) {
    cout << "Four" << endl;
  }else {
    cout << "Three" << endl;
  }
}


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

s=1
for i in range(n):
    s=s*a[i]

# sが奇数なら
if s%2==1:
    print("APPROVED")
    exit()

p=[]
for i in range(n):
    p.append(1)

z=0
for i in range(n):
    if a[i]%2==1:
        p[i]=0
    else:
        if a[i]%6==0:
            p[i]=0
        elif a[i]%10==0:
            p[i]=0
    z=z+p[i]

if z==0:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc140
{
    class abc140b
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
            var b = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
            var c = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
            var r = Solve(a, b, c);
            Console.WriteLine(r);
        }

        static int Solve(List<int> a, List<int> b, List<int> c)
        {
            var prev = 1000;  //前回食べた料理
            var s = 0;  //満足度
            for(var i = 0; i != a.Count; ++i) {
                s += b[a[i] - 1];
                if(a[i] == prev + 1)
                    s += c[a[i] - 2];
                prev = a[i];
            }
            return s;
        }
    }
}


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

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

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

void solve_A(){
    int a;
    cin >> a;
    cout << a + a*a + a * a * a; 
}

int main(void){
    solve_A();
    
    return 0;
}

Measured memory_bytes: 3592