akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

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

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

    int H, W;
    cin >> H >> W;

    vector<string> grid(H);
    vvi dist(H, vi(W, -1));

    queue<array<int, 2>> bfs;
    for (int h = 0; h < H; h++) {
        cin >> grid[h];
        for (int w = 0; w < W; w++) {
            if (grid[h][w] == '#') {
                dist[h][w] = 0;
                bfs.push({ h, w });
            }
        }
    }

    int ans = 0;

    while (!bfs.empty()) {
        int h = bfs.front()[0],
            w = bfs.front()[1];
        bfs.pop();
        int d = dist[h][w];
        ans = max(ans, d);

        if (h && dist[h-1][w] == -1) {
            dist[h-1][w] = d + 1;
            bfs.push({ h-1, w });
        }

        if (h+1 < H && dist[h+1][w] == -1) {
            dist[h+1][w] = d + 1;
            bfs.push({ h+1, w });
        }

        if (w && dist[h][w-1] == -1) {
            dist[h][w-1] = d + 1;
            bfs.push({ h, w-1 });
        }

        if (w+1 < W && dist[h][w+1] == -1) {
            dist[h][w+1] = d + 1;
            bfs.push({ h, w+1 });
        }
    }

    cout << ans << endl;

    return 0;
}



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

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

    vector<int> a(3 * N);

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

    sort(a.begin(), a.end());

    long ans = 0;
    for (int i = N; i < 3 * N; i += 2)
    {
        ans += a.at(i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
int numCnt[100001];
int main() {
	int n, a, ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a > 1e5)
			ans++;
		else
			numCnt[a]++;
	}
	for (int i = 1; i <= 1e5; i++) {
		if (numCnt[i] >= i) {
			ans += numCnt[i] - i;
		} else {
			ans += numCnt[i];
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

/* Starry Sky Tree */
//0-index

struct StarrySkyTree{
  typedef int Type;
  int segn2;
  vector<Type> data,s_data;
  
  StarrySkyTree(int n){
    for(segn2=1;segn2<n;segn2*=2);
    data.assign(segn2*2,0);
    s_data.assign(segn2*2,0);
  }
  
  //get maximum value of [a,b]
  Type query(int a,int b,int l=0,int r=-1,int k=0){
    if(r==-1) r+=segn2;
    if(r<a || b<l) return -INF; //大きさに注意
    if(a<=l && r<=b) return data[k] + s_data[k];
    return max(query(a,b,l,(l+r)/2,k*2+1),query(a,b,(l+r)/2+1,r,k*2+2))+s_data[k];
  }
  
  //add x to [a,b]
  Type add(int a,int b,Type x,int l=0,int r=-1,int k=0){
    if(r==-1) r+=segn2;
    if(a<=l && r<=b){
      s_data[k]+=x;
    }else if(a<=r && l<=b){
      data[k] = max(add(a,b,x,l,(l+r)/2,k*2+1),add(a,b,x,(l+r)/2+1,r,k*2+2));
    }
    return data[k] + s_data[k];
  }
  
};

bool hasnext[SIZE], hasown[SIZE];
int prevmax[SIZE];

int main(){
  int n, m, x;

  scanf("%d", &n);

  for(int i=0;i<n;i++) prevmax[i] = -1;
  
  for(int i=0;i<n;i++){
    scanf("%d", &m);
    for(int j=0;j<m;j++){
      scanf("%d", &x);
      x--;
      hasnext[i] |= x == i+1;
      hasown[i] |= x == i;
      if(x < i) prevmax[i] = max(prevmax[i], x);
    }
  }

  StarrySkyTree seg(n+1);

  seg.add(1,n, -INF);
  
  for(int i=0;i<n;i++){
    if(!hasown[i] && !hasnext[i]){
      seg.add(prevmax[i]+1, i, 1);
    }

    int res = seg.query(0,i);
    
    seg.add(i+1, i+1, res - seg.query(i+1, i+1));

    if(!hasown[i] && hasnext[i]){
      seg.add(prevmax[i]+1, i, 1);
    }
  }

  cout << n - seg.query(0,n) << endl;
  
  return 0;
}



Measured memory_bytes: 5476
ss = list(input())
MOD = 10**9 + 7

dp = [[0 for _ in range(13)] for _ in range(len(ss)+1)]


dp[0][0] = 1

for i,s in enumerate(ss):
    if s == "?":
        for j in range(10):
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k] % MOD
    else:
        for k in range(13):
            dp[i+1][(k*10+int(s))%13] += dp[i][k] % MOD
            

print(dp[-1][5]%MOD)

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

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

int main()
{
    string c1,c2,c3;
    cin >> c1 >> c2 >> c3;
    cout << c1[0] << c2[1] << c3[2] << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $N, $M);
$X = array_map('intval', explode(" ", trim(fgets(STDIN))));
sort($X);
$diff = [];
for ($i = 0; $i < $M - 1; $i++) {
    $diff[] = $X[$i + 1] - $X[$i];
}
sort($diff);
$ans = array_slice($diff, 0, max(0, $M - $N));
echo array_sum($ans);


Measured memory_bytes: 18932
<?php
fscanf(STDIN,"%d",$n);
$a_li = explode(" ",trim(fgets(STDIN)));
//for($i=0;$i<$n;$i++)
$re = $a_li[0];
if(in_array(0,$a_li)){
  echo "0\n";
  exit;
}

for($i=1;$i<count($a_li);$i++){
  if($a_li[$i]>10**18 || $a_li[0]>10**18){
    echo "-1\n";
    exit;
  }
  $re *= $a_li[$i];
}

 if($re>10**18){
    echo "-1\n";
    exit;
  }else{
   echo $re."\n";
 }



Measured memory_bytes: 25400
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

ll A,B;

ll f(ll x){
    if((x+1)%2==0){
        if((x+1)/2%2==0) return 0;
        else return 1;
    }else{
        if((x+1)/2%2==0) return 0^x;
        else return 1^x;
    }
}

int main(){
    cin>>A>>B;

    ll ans=f(A-1)^f(B);

    cout<<ans<<endl;
}

Measured memory_bytes: 256
var
    a,b:longint;
begin
    read(a,b);
    if b<10 then b:=b+10*a
    else if b<100 then b:=b+100*a
        else b:=b+1000*a;
    if trunc(sqrt(b))=sqrt(b) then writeln('Yes')
    else writeln('No');
end.

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int main(void) {
	char x; cin >> x;
	switch (x)
	{
	case 'A':cout << 'T' << endl;
		break;
	case 'C':cout << 'G' << endl;
		break;
	case 'G':cout << 'C' << endl;
		break;
	case 'T':cout << 'A' << endl;
		break;
	default:
		break;
	}
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#define MAX 100000
int n, k;
double T[MAX];
int check(double p){
  int i = 0, j = 0;
  double s;
  for( j = 0 ; j < k ; j++){
    s = 0.0;
    while( s + T[i] <= p){
      s += T[i];
      i++;
      if( i == n ) return n;
    }
  }

  return i;
}

int solve(){

  double l = 0.0;

  double r = 100000*10000;
  double m;
  int v;

  while( r - l > 1){
    m = ( l + r ) / 2;
    v = check(m);
    if( v >= n ) r = m;
    else l = m;
  }
  return r;
}

int main(){
  int i;
  double ans;
  scanf("%d%d", &n, &k);
  for( i = 0 ; i < n ; i++) scanf("%lf", &T[i]);
  ans = solve();
  printf("%d\n", (int)ans);

  return 0;
}



Measured memory_bytes: 2604
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    set<char> s;
    for (char c : S) s.insert(c);
    if (s.size() == 2) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}


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

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n,d,i,j,k,ans;
  float dist,thisDist;
  cin>>n>>d;
  int x[n][d];
  for (i=0;i<n;i++)
  {
  	for (j=0;j<d;j++)
  	{
  		cin>>x[i][j];
  	}
  }
  ans=0;
  for (i=0;i<n;i++)
  {
  	for (j=i+1;j<n;j++)
  	{
  		//cout<<i<<" "<<j<<"\n";
  		dist=0;
  		for (k=0;k<d;k++)
  		{
  			thisDist = x[i][k] - x[j][k];
  			thisDist*=thisDist;
  			dist+=thisDist;
  		}
  		dist = sqrt(dist);
  		if (floor(dist) == dist)
  		{
  			//cout<<"test\n";
  			ans++;
  		}
  	}
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> 
using namespace std; 
int main()
{ 
 	int n;  
	cin>>n;  
	int a[n]; 	 
 	for (int i=0;i<n;i++)   
	  cin>>a[i]; 
 	int f,count=0; 
 	do {  	 	
		f=0; 
 		for (int i=0;i<n;i++)
		{  	 	 	
			if (a[i]%2==0)
			{  	 	 	 	
				a[i]=a[i]/2; 
 	 		} 
 	 		else
			{  	 	 	 	
				f=1;  	 	 	 	
				break; 
 	 		} 
 		} 
	 	if (f==0) 
		  count++; 
	}while (f==0); 
 	cout<<count<<endl;  
 	return 0; 
} 



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


int main(){
  int a,b;
  cin >> a >> b;
  if(b%a==0 &&b>=a){
    cout << a+b << endl;
  }else{
    cout << b-a << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int mod = 998244353;
		
		int[] l = new int[k];
		int[] r = new int[k];
		long[] sum = new long[k];
		for(int i = 0; i < k; i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		
		long[] dp = new long[n*2];
		dp[1] = 1;
		
		for(int i = 1; i <= n; i++){
			for(int j = 0; j < k; j++){
				int ra = Math.min(n, i - l[j]);
				ra = Math.max(0, ra);
				int la = Math.max(0, i - r[j]);
				la = Math.min(n, la);
				
				sum[j] += dp[ra];
				dp[i] += sum[j];
				sum[j] -= dp[la];
			}
			dp[i] %= mod;
		}
		System.out.println(dp[n]);
	}
}

Measured memory_bytes: 39916
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int *a = new int[n];
	int tmp = 0;
	int r2 = 0, r4 = 0;
	while (n--)
		cin >> a[tmp++];
	for (int i = 0; i < tmp; i++)
	{
		if (a[i] % 4 == 0)
			r4++;
		else
		{
			if (a[i] % 2 == 0)
				r2++;
		}
	}
	if(tmp%2==1)//jishu
		cout << ((2 * r4 + r2 >= tmp - 1) ? "Yes" : "No") << endl;
	else
		cout << ((2 * r4 + r2 >= tmp) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
#from collections import ChainMap
input()
rp = sys.stdin.readlines()
cm = {}#ChainMap()

for i in rp:
    if i[0] == 'i':
        cm[i[7:]] = 0
    else:
        if i[5:] in cm:
            print('yes')
        else:
            print('no')

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

int main()
{
  string s, t;
  cin >> s >> t;
  
  vector<int> rs(26, -1), rt(26, -1);
  for (int i = 0; i < (int)s.size(); i++)
  {
    char st = s[i], tt = t[i];
    int si = s[i] - 'a', ti = t[i] - 'a';

    if (rs[si] >= 0)
    {
      if (rs[si] != ti)
      {
        cout << "No" << endl;
        return 0;
      }
    }
    else if (rs[si] < 0)
    {
      rs[si] = ti;
    }

    if (rt[ti] >= 0)
    {
      if (rt[ti] != si)
      {
        cout << "No" << endl;
        return 0;
      }
    }
    else if (rt[ti] < 0)
    {
      rt[ti] = si;
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 776
//解説コピー
//テスト用　自力では無い

#include <bits/stdc++.h>

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
const ll INF = 1LL<<60;

int main() {
    int N,M;
    cin>>N>>M;
    vector<pair<int,ll>> tonari[1001];
    for(int i = 0; i < M; ++i) {
        int a,b; ll w;
        cin>>a>>b>>w;
        tonari[a-1].push_back({b-1,-w});
    }

    bool heikei=false;
    vector<ll> dist(N,INF);
    dist[0]=0;
    for(int i=0;i<= 2*N;i++){
        for(int v=0;v<N;v++) {
            if (dist[v] >= INF/2) continue;
            for (auto next:tonari[v]) {
                if (dist[next.first] > dist[v] + next.second) {
                    dist[next.first] = dist[v] + next.second;
                    if (next.first == N - 1 &&i==2*N) heikei=true;
                }
            }
        }
    }
    if(heikei) cout<<"inf"<<endl;
    else cout<<-dist[N-1]<<endl;

    return 0;
}



Measured memory_bytes: 384
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
using namespace std;
typedef pair<double,double> P;
int b[19][19];


int main(){
	
	int n;
	
	while(cin>>n,n!=0){
		long long ans=0;
		long long time=0;
		vector<int> input(n);
		for(int i=0;i<n;i++)
			cin>>input[i];
		sort(input.begin(),input.end());
		
		for(int i=0;i<n;i++){
			ans+=time;
			time+=input[i];
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3172
n,m = gets.split.map(&:to_i)

abs = []
n.times do
  abs << gets.split.map(&:to_i)
end

abs.sort!{|a,b| a[0] <=> b[0]}

ans = 0
rem = m
abs.each do |ab|
  if rem == 0
    break
  end
  if rem <= ab[1]
    ans += rem * ab[0]
    rem = 0
  elsif rem > ab[1]
    rem -= ab[1]
    ans += ab[1] * ab[0]
  end
end

puts ans


Measured memory_bytes: 10488
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
vin l;
int ans=inf;
int n;
void f(int x,int a,int b,int c,int flag,int p,int q,int r){
 if(flag==0){
   a-=l[x];
   p++;
 }
 else if(flag==1){
   b-=l[x];
   q++;
 }
 else if(flag==2){
   c-=l[x];
   r++;
 }
 
  if(x==n-1){
    int cnt=abs(a)+abs(b)+abs(c);
    if(p==0||q==0||r==0)return;
    if(p>=2)cnt+=10*(p-1);
    if(q>=2)cnt+=10*(q-1);
    if(r>=2)cnt+=10*(r-1);
    //if(cnt==120)cout<<c<<endl;
   chmin(ans,cnt); 
    return ;
  }
 rep(i,0,4){
   f(x+1,a,b,c,i,p,q,r);
 }
}


int main(){cout<<fixed<<setprecision(10);
		   //aに使うか,bに使うか,cに使うか,使わない全探索O(4^n)
           int a,b,c;
           cin>>n>>a>>b>>c;
           l.resize(n);
           rep(i,0,n)cin>>l[i];
           rep(i,0,4)
           f(0,a,b,c,i,0,0,0);
           cout<<ans<<endl;
}

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

pub 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")
}

use std::cmp::{max, min};

fn main() {
  let n = read::<i64>();

  let n_str = n.to_string();
  let n_char: Vec<char> = n_str.chars().collect();

  let mut a: i64 = 0;
  for i in n_char {
    a += i.to_string().parse::<i64>().unwrap();
  }

  // println!("{} {} ", a, n);

  if n % a == 0 {
    println!("Yes");
  } else {
    println!("No");
  }

}



Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
namespace io{
    #define re register
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline 
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
int a;
char s[20]; 
int main(){
	read(a);
	scanf(" %s",s);
	if(a>=3200) printf("%s",s);
	else puts("red");
	return 0;
}

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

int main(void){
  string n;
  cin >> n;
  for(int i = 0; i < 3; i++){
    if(n[i] == '7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    ll a[n], ans = 1, m = pow(10, 18);
    rep(i, n) cin >> a[i];

    rep(i, n) if(a[i] == 0) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, n) {
        if(a[i] > m / ans) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4372
#include <iostream>
#include <vector>
using namespace std;
long n, x, y, MOD;
vector<vector<long>> g;
long dp[100010], ans[100010];

void dfs1(int v, int p) {
  dp[v] = 1;
  for(int nv : g[v]) {
    if(nv == p) continue;
    dfs1(nv, v);
    dp[v] = dp[v] * -~dp[nv]%MOD;
  }
}

void dfs2(int v, int p) {
  ans[v] = 1;
  for(int nv : g[v]) ans[v] = ans[v] * -~dp[nv]%MOD;

  int N = g[v].size();
  vector<long> L(N+1,1), R(N+1,1);
  for(int i = 0; i < N; ++i) L[i+1] = L[i] * -~dp[g[v][i]]%MOD;
  for(int i =N-1;i > 0; --i) R[i-1] = R[i] * -~dp[g[v][i]]%MOD;

  for(int i = 0; i < N; ++i) {
    if(g[v][i] == p) continue;
    dp[v] = 1;
    dp[v] = dp[v] * L[i]%MOD * R[i]%MOD;
    dfs2(g[v][i], v);
  }
}

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

  cin >> n >> MOD;
  g.resize(n);
  for(int i = 0; i < n-1; ++i) {
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  dfs1(0, -1);
  dfs2(0, -1);
  for(int i = 0; i < n; ++i) 
    cout << ans[i] << '\n';
  return 0;
}

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

int main() {
  int h, w;
  while (cin >> h >> w, h | w) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3056
class UF:
    def __init__(self, N):
        self.uf = [-1]*N
        self.n = N

    def find(self, x):
        if self.uf[x]<0: return x
        self.uf[x] = self.find(self.uf[x])
        return self.uf[x]

    def size(self, x):
        return -self.uf[self.find(x)]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x==y: return
        if self.size(x) > self.size(y): x, y = y, x
        self.uf[y] += self.uf[x]
        self.uf[x] = y
        self.n -= 1

N, M = list(map(int,input().split()))
uf = UF(N)
for _ in range(M):
    X, Y, Z = list(map(int,input().split()))
    uf.union(X-1,Y-1)
print(uf.n)

Measured memory_bytes: 7060
# for i in range(m):
# for i in range(int(input())):
#n,k= map(int, input().split())
#for _ in range(int(input())):
    #n,k= map(int, input().split())
#from collections import Counter
n=int(input())
if n%360==0:
    print(0)
    exit()
else:
    var=1
    while (var*n)%360!=0:
        var+=1
    print(var)


Measured memory_bytes: 9068
' Imports System.Collections.Generic
' Imports System.Globalization
' Imports System.IO
' Imports System.Linq
' Imports System.Text
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim A, B, C As Integer
        Dim arr() As String
        arr = Split(Console.ReadLine())
        A = arr(0) : B = arr(1) : C = arr(2)
        Console.WriteLine(If(A < B + C, B + C - A, 0))
        Return
    End Sub
End Class

Measured memory_bytes: 28236
D = gets.to_i
C,*S = (0..D).map{gets.split.map &:to_i}
C.count(0)>1 and S.each {|s|
  26.times {|i| if s[i]==0 && i!=(z||=i); s[z]<s[i] ? (s[z]=0; z=i) : (s[i]=0) end }
}
L,M,N = [-1]*27,2,9
def calc(d,n)
  s = S[d]
  t = (0..25).map {s[_1] > 0 ? C[_1]*(d-L[_1])+s[_1] : 0}
  i = (0..25).max_by(M){t[_1]}.max_by {|i|
    next t[i]  if n == 0 || d+1 >= D || t[i] == 0
    l,L[i] = L[i],d
    calc(d+1,n-1)[1].tap {L[i]=l}
  }
  [i, t[i]]
end
D.times { p 1 + i=calc(_1,N)[0]; L[i]=_1 }

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

int main() {
  int a, b, k;
  std::cin >> a >> b >> k;

  if (a > b) std::swap(a,b);
  int ans;
  int count = 0;
  for(int n = a;; --n) {
    if(a % n == 0 && b % n == 0) {
      ans = n;
      count++;
    }
    if(count == k) break;
  }

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


Measured memory_bytes: 256
/*
        Author: Prokash
                CSE48, JU

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    FAST;
    map<ll,int>mp;
    int t,in;
    cin>>t;
    while(t--)
    {
        cin>>in;
        mp[in]++;
    }
    ll sum=0;
    for(auto it:mp)
    {
        if((it.second)%2==1)
        {
            sum+=1;
        }
    }
    cout<<sum<<endl;
    return 0;
}

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

int main(){
	vector<int> a(5);
	rep(i,5){ cin >> a[i];}
	int k;
	cin >> k;
	string ans = "Yay!";
	int max = *max_element(a.begin(), a.end());
	int min = *min_element(a.begin(), a.end());
	if(max - min > k) ans = ":(";
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  int a, b, c;
  std::cin >> a >> b >> c;
  if ((a <= c && c <= b) || (b <= c && c <= a)) {
    std::cout << "Yes\n";
  } else {
    std::cout << "No\n";
  }
  return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> values;
  vector<int> costs;
  for (int n = 0; n < N; ++n) {
    int val;
    cin >> val;
    values.push_back(val);
  }
  for (int n = 0; n < N; ++n) {
    int cost;
    cin >> cost;
    costs.push_back(cost);
  }
  int value = 0;
  for (int n = 0; n < N; ++n) {
    int val = values[n];
    int cost = costs[n];
    if (val > cost) {
      value += (val - cost);
    }
  }
  cout << value;
  return 0;
}

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

long long n, all = 0;
vector<string> s;
vector<int> req[2], sum[2], id[2];

bool solve();

int main() {
  cin >> n;
  s.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    int len = s[i].size(), cnt = 0, now = 0;
    for (int j = 0; j < len; ++j)
      if (s[i][j] == '(')
        ++cnt, ++all;
      else
        --cnt, --all;
    if (cnt > 0) {
      sum[0].push_back(cnt);
      cnt = 0;
      for (int j = 0; j < len; ++j) {
        if (s[i][j] == '(')
          ++cnt;
        else
          --cnt;
        now = min(now, cnt);
      }
      req[0].push_back(now);
    } else {
      sum[1].push_back(-cnt);
      cnt = 0;
      for (int j = len - 1; j >= 0; --j) {
        if (s[i][j] == '(')
          --cnt;
        else
          ++cnt;
        now = min(now, cnt);
      }
      req[1].push_back(now);
    }
  }
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}

bool solve() {
  if (all != 0) return 0;
  for (int t = 0; t < 2; ++t) {
    int len = sum[t].size();
    for (int i = 0; i < len; ++i) id[t].push_back(i);
    auto f = [&](int l, int r) {
      if (req[t][l] != req[t][r]) return req[t][l] > req[t][r];
      return sum[t][l] > sum[t][r];
    };
    sort(id[t].begin(), id[t].end(), f);
    int cnt = 0;
    for (int i = 0; i < len; ++i) {
      if (cnt < -req[t][id[t][i]]) return 0;
      cnt += sum[t][id[t][i]];
    }
  }
  return 1;
}

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

int main() {
    int a, b; cin >> a >> b;
    string ans;
    if(a<=b){
        rep(i, b) ans += to_string(a); 
        cout << ans << endl;
    }
    else{
        rep(i, a) ans += to_string(b); 
        cout << ans << endl;
    }
}


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

using namespace std;

#ifdef LOCAL
#define DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) 0
#endif

using ll = long long;
using ull = unsigned long long;

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

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

int h,a;cin >> h >>a;

ll ans = h/a;

if(h % a != 0){
	++ans;
}

cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
		while(true){
			c -= b;
			if(c <= 0){
				System.out.println("Yes");
				break;
			}
			a -= d;
			if(a <= 0){
				System.out.println("No");
				break;
			}
		}	
	}
}


Measured memory_bytes: 35672
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		String str = "abcdefghijklmnopqrstuvwxyz";

		Scanner sc = new Scanner(System.in);

		String tmp = sc.next();

		int a = str.indexOf(tmp);
		tmp = str.substring(a+1,a+2);

		System.out.println(tmp);

	}
}


Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(),M = sc.nextInt();
		int students[][] = new int [N][2];
		int cp[][] = new int [M][2];

		for(int i = 0; i < N;i++) {
			students[i][0] = sc.nextInt();
			students[i][1] = sc.nextInt();
		}

		for(int i = 0; i < M;i++) {
			cp[i][0] = sc.nextInt();
			cp[i][1] = sc.nextInt();
		}

		for (int[] student : students) {
			int distance = 1000000000;
			int ans = 0;
			for (int i = 0; i < cp.length ; i++){
				int[] p = cp[i];
				int xy = Math.abs(student[0] - p[0]) + Math.abs(student[1] - p[1]);
				if(distance > xy) {
					distance = xy;
					ans = i+1;
				}
			}
			System.out.println(ans);
		}
	}
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    vector<ll> h(n);
    for(auto &x:h)cin >> x;
    vector<ll> ok(n,1);
    for(i=0;i<m;i++){
        ll x,y;
        cin >> x>> y;
        --x,--y;
        if(h[x]>h[y]){
            ok[y]=0;
        }else if(h[x]<h[y]){
            ok[x]=0;
        }else{
            ok[x]=ok[y]=0;
        }
    }
    ll ret = accumulate(ok.begin(),ok.end(),0);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4844
fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    val canUseCharCount = Array<Int>(26, { Int.MAX_VALUE })
    
    for (i in 1..n) {
        val s = readInputLine().toCharArray()
        
        for (j in 0 until 26) {
            val count = s.count { it == 'a' + j }
            
            if (count < canUseCharCount[j]) {
                canUseCharCount[j] = count
            }
        }
    }
    
    for (i in 0 until 26) {
        for (j in 1..canUseCharCount[i]) {
            print(('a' + i).toString())
        }
    }
    
    println()
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 31840
#!/usr/bin/python

import datetime

days = [
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday',
    'Sunday'
        ]

while True:
    m, d = map(int, input().split(' '))
    if m == 0: break
    print(days[datetime.date(2004, m, d).weekday()])

Measured memory_bytes: 7056
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int N, M;
vector<int>v;
bool DP[100001][100];
int BFS(int ans, int num) {
	queue<pair<int, int> > q;
	pair<int, int> p;
	p.first = num;
	p.second = ans;
	q.push(p);
	while (!q.empty()) {
		pair<int, int> tmp;
		tmp = q.front();
		q.pop();
		if (DP[tmp.first][tmp.second])continue;
		DP[tmp.first][tmp.second] = true;
		if (tmp.first == 0) {
			return tmp.second;
		}
		for (int i = 0; i<v.size(); i++) {
			if (tmp.first < v[i])continue;
			pair<int, int> p1;
			p1.first = tmp.first - v[i];
			p1.second = tmp.second + 1;
			q.push(p1);
		}
	}
}
int main() {
	cin >> N;
	int ans=0;
	
	v.push_back(1);
	int tmp = 6;
	while (tmp <= 100000) {
		v.push_back(tmp);
		tmp *= 6;
	}
	tmp = 9;
	while (tmp <= 100000) {
		v.push_back(tmp);
		tmp *= 9;
	}
	sort(v.begin(),v.end());
	cout << BFS(0,N) << endl;
	return 0;
}

Measured memory_bytes: 20488
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <unordered_map> //C++11
using namespace std;

typedef long long ll;


int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (b - a <= 0) cout << "delicious" << endl;
	else if (b - a <= x) cout << "safe" << endl;
	else cout << "dangerous" << endl;
	return 0;
}


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

#define INF (1e9+5)
using namespace std;
typedef long long ll;

ll mod = 998244353;
int a[100005];

int main() {
  int n;
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    int x;
    scanf("%d", &x);
    if ((i==0) != (x==0)) {
      printf("0\n");
      return 0;
    }
    a[x]++;
  }

  ll ans=1;
  for (int i=1; i<n+1; i++) {
    ll pls = 1;
    for (int j=0; j<a[i]; j++) {
      pls = (pls * a[i-1]) % mod;
    }
    ans = (ans * pls) % mod;
  }

  printf("%lld\n", ans);
}


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

void main(void)
{
  int n,k,d;
  scanf("%d%d",&n,&k);
  int a[n+1],b[n+1];
    for(int i=1;i<=n;i++){
    a[i]=b[i]=0;
  }
  for(int i=1;i<=k;i++){
    scanf("%d",&d);
    for(int j=1;j<=d;j++){
      scanf("%d",&b[j]);
      a[b[j]]++;
      b[j]=0;
    } 
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    if(a[i]==0) ans++;
  }
  printf("%d",ans);
  
}

Measured memory_bytes: 1732
#include<iostream>
#include<algorithm>

using namespace std;

int field[52][52];

void DFS(int x, int y){
    if(field[x][y]==1){
        field[x][y]=-1;
        DFS(x-1,y-1);
        DFS(x,y-1);
        DFS(x+1,y-1);
        DFS(x-1,y);
        DFS(x+1,y);
        DFS(x-1,y+1);
        DFS(x,y+1);
        DFS(x+1,y+1);
    }
}


int main(){
    int w,h;
    while(cin>>w>>h){
        if(w==0&&h==0)break;
        for(int i=0; i<50; i++){
            for(int j=0; j<50; j++){
                field[i][j]=0;
            }
        }
        
        for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
                cin>>field[i][j];
            }
        }
        int sum=0;
        for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
                if(field[i][j]==1){
                    sum++;
                    DFS(i,j);
                }
            }
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 1312
from collections import Counter,defaultdict,deque
import sys
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

def extgcd(a,b): # ax+by=1 をみたす(x,y)の組を求める
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return ( m + x%m ) % m
    
def nPk(n,k):
    res = 1
    for i in range(n,n-k,-1):
        res = (res*i)%mod
    return res

def main():
    n,k=inpm()
    g=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b=inpm()
        a-=1
        b-=1
        g[a].append(b)
        g[b].append(a)
    ans=k
    did = [False for _ in range(n)]
    did[0] = True
    que = copy.copy(g[0])
    for i in g[0]:
        did[i]=True
    ans = (ans*nPk(k-1,len(que)))%mod
    while len(que)>0:
        go=que.pop()
        ans=(ans*nPk(k-2,len(g[go])-1))%mod
        for i in g[go]:
            if did[i]:
                continue
            did[i]=True
            que.append(i)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 72008
n = int(input())
a = list(map(int, input().split()))
l = (2 * 10 ** 5) + 1
b = [0] * l


def nC2(n):
    return n * (n - 1) // 2


for i in range(n):
    b[a[i]] += 1

ttl = 0
for j in range(l):
    ttl += b[j] * (b[j] - 1) // 2

for k in range(n):
    print(ttl - nC2(b[a[k]]) + nC2(b[a[k]] - 1))


Measured memory_bytes: 33324
n, m = map(int, input().split())
a=sorted(list(map(int, input().split())), reverse = True)
bc = sorted([list(map(int, input().split())) for _ in range(m)], key = lambda x:x[1], reverse = True)
i=0
j=0
cnt=0
ans=0
while True:
    if j<m and a[i]<bc[j][1]:
        ans+=min(n-cnt, bc[j][0])*bc[j][1]
        cnt+=min(n-cnt, bc[j][0])
        j+=1
    else:
        ans+=a[i]
        i+=1
        cnt+=1
    if cnt==n:
        break
print(ans)

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

int main(void)
{
    stack<int> s;
    int n;
    while (cin >> n) {
        if (n == 0) {
            cout << s.top() << endl;
            s.pop();
        }
        else
            s.push(n);
    }
    return 0;
}






Measured memory_bytes: 3004
#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>

using namespace std;

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

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

    if(N % 2 == 1){
        double n = (double)(N+1) / (double) N / 2.0;
        printf("%.10f\n", n);
    }
    else{
        double n = 0.5;
        printf("%.10f\n", n);
    }

    return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;};
void qmod(ll &a,ll b){a=(a*b)%MOD;};
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j,o;
  ll result=0,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
  string s;cin>>s;
 
    buf1=0;
    buf=0;
    for(i=a-1;i<=c-1;i++){
      if(s[i]=='#')buf++;
      else{
        chmax(buf1,buf);
        buf=0;
      }
    }
    //cout<<buf1 spa buf2 spa buf3<<endl;
  buf2=0;
  buf=0;
  for(i=b-1;i<=d-1;i++){
      if(s[i]=='#')buf++;
      else{
        chmax(buf2,buf);
        buf=0;
      }
    }
    //cout<<buf1 spa buf2 spa buf3<<endl;
  buf3=0;
  buf=0;
  if(s[b-2]=='.')buf++;
  for(i=b-1;(i<=d-1||s[i]=='.')&&i<n;i++){
      if(s[i]=='.')buf++;
      else{
        chmax(buf3,buf);
        buf=0;
      }
  }
  //cout<<buf1 spa buf2 spa buf3<<endl;
  if(s[d-2]!='#')chmax(buf3,buf);
  if(c<d){
    ans1(buf1<=1&&buf2<=1);
  }  
  else{
    ans1(buf1<=1&&buf2<=1&&buf3>=3);
  }
  //cout<<buf1 spa buf2 spa buf3<<endl;
  //cout<<s<<endl;
  
  return 0;
}

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

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define xmax(x,y) ((x) = max((x),(y)))
#define xmin(x,y) ((x) = min((x),(y)))
#define all(x) (x).begin(),(x).end()
#define mem(x) memset(x , 0 , sizeof(x))
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define FP(a , b , c)  for(ll (a) = (b) ; (a) < (c) ; (a++));
#define FM(a , b , c)  for(ll (a) = (b) ; (a) >= (c) ; (a--));
#define connect(a , b , c) a[b].pb(c) , a[c].pb(b)

typedef long long int ll;
typedef unsigned long long int ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <string> vs;

const ll Maxn3 = 1e3 + 10;
const ll Maxn4 = 1e4 + 10;
const ll Maxn5 = 1e5 + 10;
const ll Maxn6 = 1e6 + 10;
const ll Maxn7 = 1e7 + 10;
const ll Maxn8 = 1e8 + 10;
const ll Maxn9 = 1e9 + 10;
const ll Maxn18 = 1e18 + 10;
const ll Mod1 = 1e7 + 7;
const ll Mod2 = 1e9 + 7;
const ll LLMax = LLONG_MAX;
const ll LLMin  = LLONG_MIN;
const ll INTMax = INT_MAX;
const ll INTMin  = INT_MIN;

ll mn = LLMax , mx = LLMin;
ll t[5];
int main()
{_
    ll n , res = 0 , s = 1; cin >> n; str d;
    for(ll i = 0 ; i < n ; i++)
    {
        cin >> d;
        if(d[0] == 'M') t[0]++;
        if(d[0] == 'A') t[1]++;
        if(d[0] == 'R') t[2]++;
        if(d[0] == 'C') t[3]++;
        if(d[0] == 'H') t[4]++;
    }
    for(ll i = 0 ; i < 5 ; i++)
        if(t[i] != 0) res++;
    if(res == 0) return cout << 0 , 0;
    for(ll i = 0 ; i < 5 ; i++)
        if(t[i])for(ll j = i + 1 ; j < 5 ; j++)
            if(t[j])for(ll k = j + 1 ; k < 5 ; k++)
                if(t[k]) s += (t[i] * t[j] * t[k]);
    return cout << s - 1 , 0;
}
///SAliB


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

signed main() {
  int h,w,a,b;
    scanf("%d%d%d%d",&h,&w,&a,&b);
    	std::string s(a,'0');
    	std::string t(w-a,'1');
        std::string ans=s+t;
  		std::string S(a,'1');
  		std::string T(w-a,'0');
  		std::string Ans=S+T;
  for(int i=0;i<h;i++){
    if(i<b){
    	printf("%s\n",ans.c_str());
    }
    else{
    	printf("%s\n",Ans.c_str());
    }
  }
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N;
const int M = 86400,K = 10800;
int t [M];

int main()
{
	scanf("%d",&N);
	vector< pair<int,int> > A(N);
	int curr = 0;
	FOR(i,0,N){
		scanf("%d%d",&A [i].first,&A [i].second);
		(curr += A [i].first) %= M;
		t [curr]++;
		(curr += A [i].second) %= M;
	}

	int ans = 1,cnt = 0;
	for(int l = 0,r = 0;l < M;l++){
		while((r - l + M) % M <= K){
			cnt += t [r];
			(++r) %= M;
		}
		chmax(ans,cnt);
		cnt -= t [l];
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 1408
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    println!("{}", if b % a == 0 { a + b } else { b - a });
}

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


Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>

int main(void)
{
	int a, b, r;
	double da, db, dr;
	double pi = acos(-1);
	scanf("%d %d %d", &a, &b, &r);
	da = (double)a;
	db = (double)b;
	dr = (double)r;

	printf("%lf\n", da * db * sin(dr * pi / 180.0) / 2.0);
	printf("%lf\n", da + db + sqrt(da * da + db * db - 2.0 * da * db * cos(dr * pi / 180.0)));
	printf("%lf\n", db * sin(dr * pi / 180.0));
	return 0;
}



Measured memory_bytes: 2064
#include<iostream>
using namespace std;
int h, w;
int main() {
	while (cin >> h >> w, h) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if ((i + j) % 2) cout << ".";
				else cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define itrep(itr, base) for (auto itr = base.begin(); itr != base.end(); itr++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int m[2], d[2];
  rep (i, 2) {
    cin >> m[i] >> d[i];
  }
  if (m[0] == m[1]) P(0);
  else P(1);

  return 0;
}



Measured memory_bytes: 256
import math

n = int(input())
vec = []

xs, ys = 0, 0
for _ in range(n):
    x, y = map(int, input().split())
    t = math.atan2(y, x)
    if t < 0:
        t += 2 * math.pi
    xs += x
    ys += y
    vec.append((t, x, y))
vec.sort()

max_val = xs * xs + ys * ys
for l in range(n):
    for m in range(1, n):
        val = 0
        x, y = 0, 0
        for i in range(l, l + m):
            _, xi, yi = vec[i % n]
            x += xi
            y += yi
        max_val = max(max_val, x * x + y * y)
print(math.sqrt(max_val))

Measured memory_bytes: 69492
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
long long n,k,arr[200001],tot;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for (int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for (int i=0;i<n-k;i++){
        tot+=arr[i];
    }
    cout<<tot;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> col(8, 0);
  int ncnt = 0;
  for (int i=0; i<N; i++) {
    int a;
    cin >> a;
    if (a <= 399) col[0]++;
    else if (a <= 799) col[1]++;
    else if (a <= 1199) col[2]++;
    else if (a <= 1599) col[3]++;
    else if (a <= 1999) col[4]++;
    else if (a <= 2399) col[5]++;
    else if (a <= 2799) col[6]++;
    else if (a <= 3199) col[7]++;
    else ncnt++;
  }

  int minval = 0;
  for (int i=0; i<col.size(); i++) {
    if (col[i] > 0) minval++;
  }
  int maxval = minval + ncnt;

  if (minval == 0) minval = 1;

  cout << minval << " " << maxval << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


const ll MOD = 1e9 + 7;

ll f(ll z)
{
	if (z < 0)
	{
		return 0;
	}

	ll sum = 0;
	for (ll i = (z/4LL)*4LL; i <= z; ++i)
	{
		sum ^= i;
	}
	return sum;
}

int main()
{
	ll A, B;
	cin >> A >> B;

	cout << (f(B) ^ f(A - 1)) << endl;

	return 0;
}


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

int main(){
  int W, H, N;
  cin >> W >> H >> N;
  
  vector<vector<bool>> s(W, vector<bool>(H));
  for (int i = 0; i < W; i++){
    for (int j = 0; j < H; j++){
      s.at(i).at(j) = false;
    }
  }
  
  int x, y, a;
  for (int i = 0; i < N; i++){
    cin >> x >>  y >> a;
    if (a == 1){
      for (int j = 0; j < x; j++){
        for (int k = 0; k < H; k++){
          s.at(j).at(k) = true;
        }
      }  
    }
    else if(a == 2){
      for (int j = x; j < W; j++){
        for (int k = 0; k < H; k++){
          s.at(j).at(k) = true;
        }
      }
    }
    else if(a == 3){
      for (int j = 0; j < W; j++){
        for (int k = 0; k < y; k++){
          s.at(j).at(k) = true;
        }
      }
 
    }
    else{
      for (int j = 0; j < W; j++){
        for (int k = y; k < H; k++){
          s.at(j).at(k) = true;
        }
      }    
    }
  }
  
  int ans = 0;
  for (int i = 0; i < W; i++){
    for (int j = 0; j < H; j++){
      if(s.at(i).at(j) == false){
        ans++;
      }
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=3005;
int n,P,fac[N],ifac[N],inv[N],S[N][N],pw[N],pwpw[N];
int fpow(int k1,int k2,int P=::P){
	int k3=1;
	for(;k2;k2>>=1,k1=1LL*k1*k1%P)if(k2&1)k3=1LL*k3*k1%P;
	return k3;
}
int C(int k1,int k2){
	if(k1<0||k2<0||k1-k2<0)return 0;
	return 1LL*fac[k1]*ifac[k2]%P*ifac[k1-k2]%P;
}
int main(){
	scanf("%d%d",&n,&P);
	fac[0]=fac[1]=ifac[0]=ifac[1]=inv[0]=inv[1]=1;
	rep(i,2,N-1)fac[i]=1LL*fac[i-1]*i%P,inv[i]=1LL*(P-P/i)*inv[P%i]%P,ifac[i]=1LL*ifac[i-1]*inv[i]%P;
	S[0][0]=1;
	rep(i,1,N-1)rep(j,1,N-1)S[i][j]=(S[i-1][j-1]+1LL*S[i-1][j]*j%P)%P;
	rep(i,0,N-1)pw[i]=fpow(2,i),pwpw[i]=fpow(2,fpow(2,i,P-1));
	int ans=0;
	rep(i,0,n){
		int w=1,bs=pw[n-i];
		rep(j,0,i){
			if(j){
				w=1LL*w*bs%P;
			}
			(ans+=(i&1?P-1LL:1LL)*C(n,i)%P*S[i+1][j+1]%P*pwpw[n-i]%P*w%P)%=P;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 39108