akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"


using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

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

	cin >> N >> K;
	UnionFind uf(N);
	while (K--) {
		int a, b, c;
		cin >> a >> b >> c;
		if (a) {
			cout << uf.Check_Same(b, c) << endl;
		}
		else {
			uf.Unite(b, c);
		}
	}
}

Measured memory_bytes: 4788
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
 
using namespace std;

queue<ll> que;

void pre(){
    ll x = 0;
    queue<ll> tmp;
    tmp.push(3);
    tmp.push(5);
    tmp.push(7);
    que = tmp;
    while(x < MOD){
        x = tmp.front();
        tmp.pop();
        for(int i=3; i<8; i+=2){
            tmp.push(x*10+i);
            que.push(x*10+i);
        }
    }
}

int main(){
    pre();
    int N, cnt, p;  cin >> N;
    ll x = 0;
    cnt = 0;
    while(x <= N){
        x = que.front();
        que.pop();
        p = 1;
        ll tmp = x;
        if(x <= N){
            while(tmp > 0){
                for(int i=3; i<8; i+=2) if(tmp%10 == i) p *= i;
                tmp /= 10;
            }
            if(p%105 == 0)  cnt++;
        }
    }
    print(cnt);
    return 0;
}

Measured memory_bytes: 4576
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
void sove(long long int h,long long int w)
{
    long long int tem1=10000000000,tem2=10000000000,tem3=10000000000,tem4=10000000000;
    if(h%3==0||w%3==0)
    {
        cout<<'0'<<endl;
        return ;
    }
    if(h==2&&w==2)
    {
        cout<<1<<endl;
        return ;
    }
    else
    {
        long long int ma=w*h;
        long long int mi=0;
        {
            long long int w1=w/2;
            for(long long int i=1;i<h;i++)
            {
                long long int s1=w*i;
                  long long int s2=(h-i)*w1;
                   long long int s3=w*h-s1-s2;
                  ma=max(s1,max(s2,s3));
                  mi=min(s1,min(s2,s3));
                tem1=min(tem1,ma-mi);
            }
        }
        {
          long long  int h1=h/2;
           for(long long int i=1;i<w;i++)
           {
                 long long int s1=i*h;
                 long long  int s2=((w-i)*h1);
                  long long int s3=w*h-s1-s2;
                  ma=max(s1,max(s2,s3));
                  mi=min(s1,min(s2,s3));
                tem1=min(tem1,ma-mi);
           }
        }
        {
            long long int h1=h/3;
            long long  int h2=(h-h1)/2;
            long long   int h3=(h-h1-h2);
            long long int s1=h1*w;
            long long int s2=h2*w;
            long long int s3=h3*w;
            tem3=max(s1,max(s2,s3))-min(s1,min(s2,s3));
        }
        {
            long long  int w1=w/3;
            long long  int w2=(w-w1)/2;
            long long  int w3=(w-w1-w2);
            long long int s1=w1*h;
            long long int s2=w2*h;
            long long int s3=w3*h;
            tem4=max(s1,max(s2,s3))-min(s1,min(s2,s3));
        }
        cout<<min(min(tem1,tem2),min(tem3,tem4))<<endl;
        return ;
    }
    return ;
}
int main()
{
    int h,w;
    cin>>h>>w;
    sove(h,w);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M;
  cin >> N >> M;
  int k[M]{0};
  int s[M][N]{0};
  int p[M];
  
  for(int i=0;i<M;i++)
  {
    cin >> k[i];
    for(int j=0; j<k[i];j++)
    {
      cin >> s[i][j];
    }
  }
  for(int i=0;i<M;i++)
  {
    cin >> p[i];
  }
  int num=0;
  int onnum=0;
  int ans=0;
  int a=0;
  for(int count=0;count<pow(2,N);count++)
  {
    onnum=0;
    //各電球について
    for(int i=0;i<M;i++)
    {
      num=0;
      //それぞれのスイッチが
      for(int j=0;j<k[i];j++)
      {
        a=pow(2,s[i][j]-1);
        //cout <<k[i]<<" "<< i <<" "<<j << endl;
        if(count%(a*2)/a==1)num++;
      }
      if(num%2==p[i]) onnum++;
    }
    if(onnum==M) ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

  int a,b;

  cin >> a >> b;

  cout <<"a ";

  if(a<b)
    cout <<"<";
  if(a==b)
    cout << "==";
  if(a>b)
    cout << ">";

  cout <<" b"<<endl;

  return 0;

}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



int main(){
    ll n;
    cin >> n;
    int d[n];
    REP(i,n){
        cin >> d[i];
    }

    ll ans = 0;

    REP(i,n-1){
        FOR(j,i+1,n){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF MOD
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    string s;
    cin >> s;
    Int su = 0;
    for (int i = 0; i < s.size(); i++) {
        su += s[i] - '0';
    }
    if (su % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3712
package main

import (
	"fmt"
	"bufio"
	"os"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)

	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}

		buf = append(buf, l...)

		if !p {
			break
		}
	}

	return string(buf)
}

func solve(H, W int, rows []string) int {
	h := make([][]int, H)
	v := make([][]int, H)

	for i := 0; i < H; i++ {
		h[i] = make([]int, W)
		v[i] = make([]int, W)
	}

	for i := 0; i < H; i++ {
		ct := 0
		from := 0
		for j := 0; j <= W; j++ {
			if j == W || rows[i][j] == '#' {
				for k := from; k < j; k++ {
					h[i][k] = ct
				}
			}

			if j == W {
				continue
			}

			if rows[i][j] == '#' {
				h[i][j] = 0
				ct = 0
				from = j+1
			} else {
				ct++
			}
		}
	}

	for j := 0; j < W; j++ {
		ct := 0
		from := 0
		for i := 0; i <= H; i++ {
			if i == H || rows[i][j] == '#' {
				for k := from; k < i; k++ {
					v[k][j] = ct
				}
			}

			if i == H {
				continue
			}

			if rows[i][j] == '#' {
				v[i][j] = 0
				ct = 0
				from = i+1
			} else {
				ct++
			}
		}
	}

	max := 0

	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			res := h[i][j] + v[i][j] - 1

			if res > max {
				max = res
			}
		}
	}

	return max
}

func main() {
	var H, W int

	fmt.Scan(&H)
	fmt.Scan(&W)

	rows := make([]string, H)

	for i := 0; i < H; i++ {
		rows[i] = readLine()
	}

	output := solve(H, W, rows)

	fmt.Println(output)
}


Measured memory_bytes: 72576
#include <cstdio>
#include <vector>
#include <cstdlib>
using namespace std;

int n;
long long a[200005];

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n ; ++i)
        scanf("%lld", &a[i]), a[i] += a[i - 1];
    long long Sol = 1000000000000000000;
    for(int i = 1; i < n ; ++i){
        long long x = a[i] -( a[n] - a[i] );
        if(x < 0) x = -x;
        if(x < Sol) Sol = x;

    }
    printf("%lld", Sol);
    return 0;
}


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

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

    rep(i, 3) {
        if (n[i] == '1') n[i] = '9';
        else if (n[i] == '9') n[i] = '1';
    }

    cout << n << endl;

    return 0;
}

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

typedef long long LL;

const int N=500;
const LL INF=(1LL<<50)-1;

int n,a[N+9][N+9];

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i)
	for (int j=1;j<=n;++j)
	  if (i^j) scanf("%d",&a[i][j]);
}

LL sum[2][N+9][N+9];

void Get_sum(){
  for (int i=1;i<=n;++i){
	for (int j=1;j<=n;++j){
	  if (i^j) sum[i>j][i][j]=a[i][j];
	  for (int k=0;k<2;++k) sum[k][i][j]+=sum[k][i][j-1];
	}
	for (int j=1;j<=n;++j)
	  for (int k=0;k<2;++k) sum[k][i][j]+=sum[k][i-1][j];
  }
}

LL Get_sum(int id,int x0,int y0,int x1,int y1){
  return sum[id][x1][y1]-sum[id][x0-1][y1]-sum[id][x1][y0-1]+sum[id][x0-1][y0-1];
}

LL dp[N+9][N+9],ans;

void Get_dp(){
  for (int i=0;i<=n;++i)
	for (int j=0;j<=n;++j) dp[i][j]=INF;
  dp[0][0]=0;
  for (int i=0;i<=n;++i)
	for (int j=0;j<i||j<1;++j)
	  for (int k=i+1;k<=n;++k)
		dp[k][i]=min(dp[k][i],dp[i][j]+Get_sum(1,k+1,j+1,n,i)+Get_sum(0,i+1,i+1,k,k));
  ans=INF;
  for (int i=1;i<=n;++i) ans=min(ans,dp[n][i]);
}

void work(){
  Get_sum();
  Get_dp();
}

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

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 10760
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 305
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';

ll abs1(ll x) {
  if (x < 0)
    return -x;
  return x;
}
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
ld dp[N][N][N];
ll n;
ld recur(ll a, ll b, ll c) {

  

  if (a < 0 or b < 0 or c < 0)
    return 0;
  if (a == 0 && b == 0 && c == 0)
    return 0;
  if (dp[a][b][c] >= 0)
    return dp[a][b][c];

  dp[a][b][c] = 1 + (ld)(a) / n * recur(a - 1, b, c) +
                (ld)(b) / n * recur(a + 1, b - 1, c) +
                (ld)(c) / n * recur(a, b + 1, c - 1);
  dp[a][b][c] *= (ld)n / (a + b + c);

  return dp[a][b][c];
}

ll cnt[4];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++) {
      for (ll k = 0; k < N; k++)
        dp[i][j][k] = -1;
    }
  }
  memset(cnt, 0, sizeof(cnt));

  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    cnt[x]++;
  }

  cout << fixed << setprecision(12) << recur(cnt[1], cnt[2], cnt[3]) << en;

  return 0;
}


Measured memory_bytes: 443648
from math import *
c60 = cos(radians(60))
s60 = sin(radians(60))
def koch(d, p1, p2):
    if d == 0:
        return
    sx = (2 * p1[0] + p2[0]) / 3
    sy = (2 * p1[1] + p2[1]) / 3
    tx = (p1[0] + 2 * p2[0]) / 3
    ty = (p1[1] + 2 * p2[1]) / 3
    ux = (tx - sx) * c60 - (ty - sy) * s60 + sx
    uy = (tx - sx) * s60 + (ty - sy) * c60 + sy
    koch(d - 1, p1, (sx, sy))
    print("{0:.8f} {1:.8f}".format(sx, sy))
    koch(d - 1, (sx, sy), (ux, uy))
    print("{0:.8f} {1:.8f}".format(ux, uy))
    koch(d - 1, (ux, uy), (tx, ty))
    print("{0:.8f} {1:.8f}".format(tx, ty))
    koch(d - 1, (tx, ty), p2)
n = int(input())
ax, ay = 0, 0
bx, by = 100, 0
print("{0:.8f} {1:.8f}".format(ax, ay))
koch(n, (ax, ay), (bx, by))
print("{0:.8f} {1:.8f}".format(bx, by))



Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<long double> A(N);
    rep(i,N){
        cin >> A[i];
        if(A[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    long double ans = 1;
    rep(i,N){
        ans*=A[i];
        if(ans>1000000000000000000){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << (ll)ans << endl;
    return 0;
}

Measured memory_bytes: 4844
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

int main () {
  int n;
  cin >> n;
  string h;
  vector<int> ans(26, 0);
  for (int i = 0; i < n; i++) {
    cin >> h;
    if (i == 0) {
      for (int j = 0; j < h.size(); j++) {
        ans[h[j] - 97]++;  
      }    
    }      
    else {
      vector<int> sub(26, 0);
      for (int j = 0; j < h.size(); j++) {
        sub[h[j] - 97]++;  
      }  
      for (int j = 0; j < 26; j++) {
        if (ans[j] > sub[j]) {
          ans[j] = sub[j];  
        }    
      }
    }
  }  
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < ans[i]; j++) {
      cout << char (i + 97);  
    }
  }
  cout << endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        char[] input = Console.ReadLine().ToCharArray();
        string ans = "";
        for(int i = 0; i < input.Length; i++)
        {
            int temp = input[i]+N;
            if (temp > 'Z') temp = temp - ('Z' - 'A'+1);
            ans += (char)temp;
        }
        Console.WriteLine(ans);
    }
}


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

typedef long long ll;

using namespace std;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    string s;
    cin >> s;

    if ((s == "RSS") || (s == "SSR") || (s == "SRS") || (s == "RSR"))
    {
        cout << 1 << endl;;
    }

    else if((s == "SRR") || (s == "RRS"))
    {
        cout << 2 << endl;
    }

    else if(s == "RRR")
    {
        cout << 3 << endl;;
    }

    else
    {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include <cstdlib>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include <assert.h>
#include<map>
#include<set>
#include<bitset>
#include <iomanip>
#include<stack>
#include <unordered_map>
#include<cmath>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m,n) for (int i = m;  i < n; i++)
#define PII pair<int,int>
#define PLL pair<long, long>
#define ft first
#define sd second
#define pb push_back
const int maxn=333333,mod=1000000009;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){char ch=getchar();int x=0,f=0;while(ch<'0'||ch>'9')f|=ch=='-',ch=getchar();while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();return f?-x:x;} 

const int N  = 105;
bool a[N];
int main()
{
  //STDIN
    int n, k; cin >> n >> k;
    while (k--)
    {
        int d; cin >> d;
        for (int i = 0;  i < d; i++)
        {
          int t; cin >> t;
          a[t] = 1;
        }
        
        
    }int cnt = 0;
    for (int i = 1; i <= n; i++)
        {
          if (!a[i]) cnt++;
        }
        cout << cnt << endl;
}

Measured memory_bytes: 3196
/* ex7_3
   tamayama */

#include<stdio.h>
#include<stdlib.h>

int main(void){
    int field_Height;
    int field_Width;
    char **ia;
    int i,j,k;
    int count=0;

    //メモリの動的確保
    scanf("%d %d",&field_Height,&field_Width);
    ia = (char**)calloc(field_Height,sizeof(char*));
    if(ia == NULL){
        exit(1);
    }
    for(i=0;i<field_Height;i++){
        ia[i] = (char*)calloc(field_Width,sizeof(char));
        if(ia[i] == NULL){
            exit(1);
        }
    }
    
    //配列の入力
    for(i=0;i<field_Height;i++){
        for(j=0;j<field_Width;j++){
            scanf(" %c",&ia[i][j]);
        }
    }

    //横一行に'.'が並んでいるかチェック
    for(i=0;i<field_Height;i++){
        for(j=0;j<field_Width;j++){
            if(ia[i][j] == '.' || ia[i][j] == 'x'){
                count++;
                if(count == field_Width){    //削除する行に'x'を入れる
                    for(k=0;k<field_Width;k++){
                        ia[i][k] = 'x';
                    }
                }
            }
        }
        count = 0;
    }
    
    //縦一行に'.'が並んでいるかチェック
    for(j=0;j<field_Width;j++){
        for(i=0;i<field_Height;i++){
            if(ia[i][j] == '.' || ia[i][j] == 'x'){
                count++;
                if(count == field_Height){    //削除する行に'x'を入れる
                    for(k=0;k<field_Height;k++){
                        ia[k][j] = 'x';
                    }
                }
            }
        }
        count = 0;
    }



    for(i=0;i<field_Height;i++){    //出力の際にｘを読まない
        for(j=0;j<field_Width;j++){
            if(ia[i][j] != 'x'){
                printf("%c",ia[i][j]);
            }else{
                count++;
            }
        }
        if(count != field_Width){    //行を表示しないときは改行しない
            printf("\n");
        }
        count = 0;
    }

    for(i=0;i<field_Height;i++){    //メモリの解放
        free(ia[i]);
    }
    free(ia);
    return 0;
}

Measured memory_bytes: 1648
#include<bits/stdc++.h>
using namespace std;
vector<int> h;
int n,temp;
vector<long long> sum;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        h.push_back(temp);
        sum.push_back(INT_MAX);
    }
    sum[0]=0;
    for(int i=0;i<n-1;i++)
    {
        if(i+1<n && sum[i+1]>sum[i]+abs(h[i+1]-h[i]))
            sum[i+1]=sum[i]+abs(h[i+1]-h[i]);
        if(i+2<n && sum[i+2]>sum[i]+abs(h[i+2]-h[i]))
            sum[i+2]=sum[i]+abs(h[i+2]-h[i]);
    }
    cout<<sum[n-1]<<endl;
    return 0;

}


Measured memory_bytes: 1780
#include <stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct
{
    int p, l, r;
};
/*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/

typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u)
{
    int i, c;
    printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

    if (T[u].p == NIL /*ここを埋める (fill this blank)*/)
        printf("root, ");
    else if (T[u].l == NIL /*ここを埋める(fill this blank)*/)
        printf("leaf, ");
    else
        printf("internal node, ");

    printf("[");
    for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r)
    {
        if (i)
            printf(", ");
        printf("%d", c);
    }
    printf("]\n");
}

void calcDepth(int u, int p)
{
    D[u] = p;
    if (T[u].r != NIL /*ここを埋める(fill this blank)*/)
        calcDepth(T[u].r, p /*ここを埋める(fill this blank)*/);
    if (T[u].l != NIL /*ここを埋める(fill this blank)*/)
        calcDepth(T[u].l, p + 1 /*ここを埋める(fill this blank)*/);
}

int main()
{
    int i, j, k;
    int n;
    int id, sib, child;
    int root = NIL;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        T[i].p = T[i].l = T[i].r = NIL;

    for (i = 0; i < n; i++)
    {
        scanf("%d %d", &id, &k);
        for (j = 0, sib = NIL; j < k; j++)
        { //子を入力する (input children)
            scanf("%d", &child);
            T[child].p = id;
            if (j == 0)
                T[id].l = child; //idの一番左の子 (the most left child of id)
            else
                T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
            sib = child;          //次の子供の左の兄弟 (the left sibling of the next child)
        }
    }

    //根を求める (find the root)
    for (i = 0; i < n; i++)
    {
        if (T[i].p == -1)
            root = i;
    }

    //それぞれのノードの深さを求める (find depth of each node)
    calcDepth(root, 0);

    //出力 (output)
    for (i = 0; i < n; i++)
        print(i);

    return 0;
}



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

using namespace std;
 
int main()
{
    int a[8][8] = {
	{1, 2, 1, 2, 1, 4, 1, 4},
	{1, 2, 1, 4, 1, 4, 1, 2},
	{1, 4, 1, 2, 1, 2, 1, 4},
	{1, 4, 1, 4, 1, 2, 1, 2},
	{2, 1, 2, 1, 4, 1, 4, 1},
	{2, 1, 4, 1, 4, 1, 2, 1},
	{4, 1, 2, 1, 2, 1, 4, 1},
	{4, 1, 4, 1, 2, 1, 2, 1}
    }; 
 
    int b[8];
 
    while (~scanf("%d" ,&b[0])) {
	int ans[8], min_ = (1<<29);
	for(int i = 1 ; i < 8 ; i++){
	    scanf("%d" ,b + i);
	}
     
	for (int i = 0; i < 8; i++) {           
	    int npas = 0;
	    for (int j = 0; j < 8; j++) {
		int d = b[j] - a[i][j];
		if (d > 0) {
		    npas += d;
		}
	    }
	    if (min_ > npas) {
		min_ = npas;
		for (int j = 0; j < 8; j++) {
		    ans[j] = a[i][j]; 
		}
	    }
	}
 
	for (int i = 0; i < 8; i++) {
	    if (i != 7) {
		printf("%d ", ans[i]);
	    } else {
		printf("%d\n", ans[i]);
	    }
	}
    }
    return 0;
}

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

using namespace std;

#define MOD 1000000007
typedef long long int ll;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);
        
	int k,n;
	cin>>k>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int ans=a[n-1]-a[0];
	for(int i=1;i<n;i++){
		ans=min(ans,k-a[i]+a[i-1]);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;


int main(){
    int k;
    while(cin>>k){
        if(k==0)break;
    
        int sum=0;
        for(int i=0;i<k*(k-1)/2;i++){
            int a;
            cin>>a;
            sum+=a;
        }
        cout<<sum/(k-1)<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

int N;
vector<string> groups;
vector<vector<string>> names;
vector<set<string>> dp;

int getNum(string name) {
    rep(i, N) {
        if (name == groups[i]) {
            return i;
        }
    }
    return -1;
}

void merge(set<string> &s, set<string> t) {
    for (auto x : t) s.insert(x);
}

set<string> dfs(int i = 0, set<string> st = set<string>{}) {
    if (!dp[i].empty()) return dp[i];

    for (auto name : names[i]) {
        int ni = getNum(name);
        if (ni == -1) {
            st.insert(name);
        } else {
            merge(st, dfs(ni, st));
        }
    }
    return dp[i] = st;
}

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

    while (cin >> N, N) {
        groups.clear();
        groups.resize(N);
        names.clear();
        names.resize(N);
        dp.clear();
        dp.resize(N);
        rep(i, N) {
            string s;
            cin >> s;
            s.back() = ',';
            stringstream ss(s);
            getline(ss, groups[i], ':');
            string t;
            while (getline(ss, t, ',')) {
                names[i].emplace_back(t);
            }
        }

        cout << dfs().size() << endl;

        // rep(i, N) {
        //     cout << groups[i] << ":";
        //     for (auto x : names[i]) cout << x << " ";
        //     cout << endl;
        // }
        // cout << endl;
    }
}

Measured memory_bytes: 5464
#include "cstdio"

using namespace std;
int main()
{
  int a,b,c,d;

  while(scanf("%1d%1d%1d%1d",&a,&b,&c,&d)!=EOF)
  {

      if (a+b+c+d==7) printf("%d+%d+%d+%d=7\n",a,b,c,d);
      else if (a+b+c-d==7) printf("%d+%d+%d-%d=7\n",a,b,c,d);
      else if (a+b-c+d==7) printf("%d+%d-%d+%d=7\n",a,b,c,d);
      else if (a+b-c-d==7) printf("%d+%d-%d-%d=7\n",a,b,c,d);
      else if (a-b+c+d==7) printf("%d-%d+%d+%d=7\n",a,b,c,d);
      else if (a-b+c-d==7) printf("%d-%d+%d-%d=7\n",a,b,c,d);
      else if (a-b-c+d==7) printf("%d-%d-%d+%d=7\n",a,b,c,d);
      else if (a-b-c-d==7) printf("%d-%d-%d-%d=7\n",a,b,c,d);


  }





}



Measured memory_bytes: 128
//#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
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; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  int sum = 0;
  REP(i,n){ 
    sum += a[i];
    a[i] *= n;
  }
  
  int mn = INF;
  int ind = -1;
  REP(i,n){
    if(chmin(mn, abs(sum-a[i]))) ind = i;
  }

  cout << ind << endl;
  return 0;
}


Measured memory_bytes: 3592
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

void solve(){
   cin>>n;

   int div = n / 100;
   int tmp  = n;
   n %= 100;

   for (int b = 0; b <= 100; ++b)
   {
      for (int c = 0; c <= 100; ++c)
      {
         for (int d = 0; d <= 100; ++d)
         {
            for (int e = 0; e <= 100; ++e)
            {
               int f = n - (b + 2*c + 3*d+4*e);
               if(f % 5)continue;
               f /= 5;
               if(f < 0)continue;
               assert(b + 2*c + 3*d+4*e+5*f == n);
               int a = div - (b + c + d + e + f);
               if(a < 0)continue;
               if(b == 1 and c == 1 and d == 1 and e == 1 and f == 1)
                  tr(a, b, c, d, e, f);
               if(100 * a + 101 * b + 102*c + 103*d+104*e+105*f == tmp){
                  cout<<1;
                  return ;
               }
            }
         }
      }
   }

   cout<<0;
}

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

   while(t--){
     solve();
     cout << endl;
   }
   

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define matr vector<vector<int> > 
 
#define all(x) x.begin(), x.end()
 
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 1e9 + 9, inf = 1e9, MAXN = 1e6 + 7;
const double eps = 1e-9;
mt19937 rnd(time(0));
int n; 
int cnt[maxn]; 
int dp[maxn]; 

void solve() { 
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> cnt[i]; 
    dp[n - 1] = 1;
    int ans = 1; 
    for (int i = n - 1; i >= 0; --i) {
        if (cnt[i] >= cnt[i + 1]) dp[i] = dp[i + 1] + 1; 
        else dp[i] = 1;  
        ans = max(ans, dp[i]); 
    }        
    cout << ans - 1; 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

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


int A[15]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};

int ans[10][10];
int tmp[10][10];

int main(){
  for(int i=15;i>=0;i--){

    for(int a=0;a<15;a++){

      int from=A[a];
      int to=A[ (a+i)%15 ];
      
      ans[ from ][ to ]=i;
      tmp[ from ][ to ]=a;
    }
  }

  int tc;
  cin>>tc;

  for(int Tc=0;Tc<tc;Tc++){

    int from;
    int to;
    cin>>from>>to;

    for(int i=0;i<=ans[from][to];i++){
      if(i>0)cout<<' ';

      cout<< A[ (tmp[from][to]+i)%15 ];
    }
    cout<<endl;
    
  }
  
  return 0;
}



Measured memory_bytes: 3088
using System;
class Program
 {
        static void Main(string[] args)
        {
            var count = Console.ReadLine();
            var boss = Console.ReadLine().Split(' ');
            var buka = new int[boss.Length + 1];

            foreach(var boss_value in boss)
                buka[int.Parse(boss_value) - 1]++;
            
            foreach(var buka_value in buka)
                Console.WriteLine( buka_value );
        }
 }

Measured memory_bytes: 41976
//dhur


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


int N;
map<pair<int,int>,int>m;
int ara[100001];
int dp(int a,int b,int sum)
{
        if(b>=N){
                return 999999999;
        }
        else if(m.find(make_pair(a,b))!=m.end())return m[make_pair(a,b)];
        else if(b==N-1){
                return sum+=abs(ara[a]-ara[b]);
        }
        else{
                sum+=abs(ara[a]-ara[b]);


                sum+=min(dp(b,b+1,0),dp(b,b+2,0));
                m[make_pair(a,b)]=sum;
                return sum;


        }
}

int main()
{
       ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
     cin>>N;
     for(int i=0;i<N;i++){
        cin>>ara[i];
     }

     int sum=dp(0,0,0);
     cout<<sum<<endl;
     return 0;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3+5;

int main(){	
	int n,r;
	scanf("%d%d",&n,&r);
	if(n >= 10) cout << r;
	else cout << r+100*(10-n); 
	return 0;
}

Measured memory_bytes: 764
//ABC154_A.Remaining Balls
//文字列S:A個、文字列T:B個
//文字列Uを一つ捨てた時、S,Tがそれぞれいくつ残っているか。
//STUは英小文字のみの文字列、長さは１以上１０以下
//A、Bは１以上１０以下

//入力
//*S T
//*A B
//*U

#include <stdio.h>
#include <string.h>

int main() {
    
    char S[15], T[15], U[15];
    int A, B;
    
    //標準入力から条件を入力
    scanf("%s%s",S,T);
    scanf("%d%d",&A,&B);
    scanf("%s",U);
    
    if ( strcmp ( S, U ) ){
        B -= 1;
    } else if ( strcmp ( T, U ) ){
        A -= 1;
    } else {
        printf("UはS、Tのどちらとも一致しません\n");
    }
    
    printf("%d %d\n",A,B);
    return 0;
    
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using Graph = vector<vector<int> >;
using P = pair<int, int>; 
// MOD
const int mod = 1000000007;
using ll = long long;
long long INF = 1<<30;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
//int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
 
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}
 
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI=3.14159265358979323846;
bool seen[100][100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second< y.second;
}


struct Unionfind{
    vector<int> par;

    Unionfind(int n) : par(n, -1){}

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    } 

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x]>par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};


int main() {
    int n, a, b; cin >> n >> a >> b;
    mint ans = f(n);
    ans -= 1;
    ans -= choose(n, a);
    ans -= choose(n, b);
    cout << ans.x << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 1e5+10;
vi es[MAX_N];
int k;
int cnt = 0;

// int dfs(int cur, int par) {
// 	int height = 0;
// 	for(auto& to: es[cur]) {
// 		int h = dfs(to, cur);
// 		if(h == k && cur != 0) {
// 			// cerr << h << " " << k << " " << cur << " " << par << "!"<<endl;
// 			cnt++;
// 			continue;
// 		}
// 		if(h == k-1 && par != 0 && cur != 0) {
// 			// cerr << h << " " << k << " " << cur << " " << par << "?"<<endl;
// 			cnt++;
// 			return 0;
// 		}
// 		height = max(height, h);
// 	}
// 	// cerr << " " << cur << " " << height+1 << endl;
// 	return height +1;
// }

int dfs(int cur, int p) {
	int h = 0;
	for(auto& to :es[cur]) {
		h = max(h, dfs(to, cur)+1);
	}
	if(h == k-1 && cur != 0 && p != 0) {
		++cnt;
		h = -1;
	}
	return h;
}
int main(){
#ifdef LOCAL_TEST
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif
	// cerr << endl;
	int n;
	cin >> n >> k;
	vi a(n);
	rep(i, n) cin >> a[i], --a[i];
	REP(i, 1, n) es[a[i]].pb(i);
	dfs(0, -1);
	cout << cnt + (a[0] == 0 ? 0 : 1) << endl;
	return 0;
}

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

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

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    string s = to_string(i);
    int sum = 0;
    for (char c : s) sum += c - '0';
    if (A <= sum && sum <= B) ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
S = input()
S = [int(s) for s in S]

a = S[0] * 10 + S[1]
b = S[2] * 10 + S[3]


if a > 12 or a == 0:
    if b > 12 or b == 0:
        print('NA')
    else:
        print('YYMM')
else:
    if b > 12 or b == 0:
        print('MMYY')
    else:
        print('AMBIGUOUS')

Measured memory_bytes: 38384
my @DB;
my @bingo;

for(my $j=0;$j<3;$j++){
for(my $k=0;$k<3;$k++){
    $bingo[$j][$k] = 0;
}
}

for(1..3){
 my $s = <>;chomp $s;
 my @dat = split(/ /,$s);
 push (@DB,\@dat);
}

my $N=<>;
for(my $i=0;$i<$N;$i++){
    my $num = <>;
    chomp $num;
    for(my $j=0;$j<3;$j++){
    for(my $k=0;$k<3;$k++){
      if($num == $DB[$j][$k] ){
          $bingo[$j][$k] = 1;
      }
    } 
    }
}
my $flag =0;

for(my $j=0;$j<3;$j++){
    if($bingo[$j][0]*$bingo[$j][1]*$bingo[$j][2] ){ $flag = 1;} 
}
for(my $k=0;$k<3;$k++){
    if($bingo[0][$k]*$bingo[1][$k]*$bingo[2][$k] ){ $flag = 1;}
}
if($bingo[0][0]*$bingo[1][1]*$bingo[2][2] ){ $flag = 1;}
if($bingo[0][2]*$bingo[1][1]*$bingo[2][0] ){ $flag = 1;}

if($flag){
    print "Yes";
}else{
   print "No";
}

Measured memory_bytes: 512
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
def resolve():
    S=input()
    ans=753
    for i in range(len(S)-2):
        temp=S[i:i+3]
        #print(temp)
        ans=min(ans,abs(int(temp)-753))
    print(ans)
        
#%%submit!    
resolve()


Measured memory_bytes: 63852
using System;
using System.Linq;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var date = Console.ReadLine();
            var after = date.Skip(4);
            var str = String.Join("", after);
            Console.WriteLine($"2018{str}");
        }
    }
}

Measured memory_bytes: 26536
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)

int cmpAsc(const void* a, const void* b){
    int x = *(int*)a, y = *(int*)b;
    if(x < y){
        return 1;
    }
    if(x > y){
        return -1;
    }
    return 0;
}

int main(){
    int n;
    scanf("%d", &n);
    int a[1000], len = 0;
    a[0] = 1; len++;
    int x = 6;
    while(x <= n){
        a[len++] = x;
        x *= 6;
    }
    x = 9;
    while(x <= n){
        a[len++] = x;
        x *= 9;
    }
    qsort(a, len, sizeof(int), cmpAsc);
    int t[len+1][n + 1];
    rep(i, 0, len+1){
        t[i][0] = 0;
    }
    rep(i, 1, n + 1){
        t[0][i] = 100000;
    }
    rep(i, 1, len+1){
        rep(j, 1, n + 1){
            int z = a[i-1];
            if(j < z){
                t[i][j] = t[i-1][j];
            }else{
                if(t[i][j-z] + 1 < t[i-1][j]){
                    t[i][j] = t[i][j-z] + 1;
                }else{
                    t[i][j] = t[i-1][j];
                }
            }
        }
    }
    /*rep(i, 0, len+1){
        printf("%d ", t[i][n]);
    }*/
    printf("%d", t[len][n]);

    return 0;
}

Measured memory_bytes: 5248
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<ll> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        ll show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    rep(i,n) par[i] = i;
    rep(i,n) ran[i] = 0;
    rep(i,n) size[i] = 1;
};

int union_find::find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

ll union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

bool union_find::same(int x, int y) {
    return (find(x) == find(y));
};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
        --p[i];
    }
    union_find uf(n);
    rep(i,m){
        int x, y;
        cin >> x >> y;
        --x; --y;
        uf.unite(x, y);
    }
    int ans = 0;
    rep(i,n){
        if(uf.same(p[i], i)) ++ans;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define read() freopen("input.txt", "r", stdin)

#define ll64 long long
#define BASE 100000007
#define MOD 100000077

ll64 BP[300010];
bool visited[100010];
vector<int> graph[100010];
map<ll64, ll64> C_M;

ll64 dfs(int u)
{
    //printf("=>%d\n", u);
    visited[u] = true;
    ll64 hsh = 1;
    for(auto v: graph[u]){
        if(!visited[v]){
            hsh += (dfs(v) * BASE) % MOD;
            hsh %= MOD;
        }
    }
    C_M[hsh] += 1;
    return hsh;
}

int main()
{
    //read();
    ll64 temp = 1;
    for(int i = 0; i < 200000; i++){
        BP[i] = temp;
        temp = (temp * BASE) % MOD;
    }
    int N;
    scanf("%d", &N);
    for(int i = 0; i < N - 1; i++){
        int u, v;
        scanf("%d%d", &u, &v);
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    dfs(1);
    ll64 ans = 0;
    for(auto &it: C_M){
        ll64 x = it.second;
        ans += (x * (x - 1)) / 2;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 22932
#include<stdio.h>

int main(){

	int D;

	scanf("%d",&D);

	if(D==25)
		puts("Christmas");
	else if(D==24)
		puts("Christmas Eve");
	else if(D==23)
		puts("Christmas Eve Eve");
	else 
		puts("Christmas Eve Eve Eve");

	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void){
  int N,a,b,c,d;
  scanf("%d\n",&N);
  d=N%10;
  c=(N%100-d)/10;
  b=(N%1000-(N%100))/100;
  a=N/1000;
  if((a==b&&b==c)||(b==c&&c==d)){
  printf("Yes\n");
  }else{
  printf("No\n");
  }
}

Measured memory_bytes: 128
#include <stdio.h>
 
int main(int argc, char *argv[]){
    int n, f, i;
    long long int ID, price, num;
    long long int sum[4001];
    int ln, list[4000];
    while(1){
        scanf("%d ", &n);
        if(!n) break;
        f=0;ln=0;
        for(i=1;i<4001;i++) sum[i]=0;
        while(n--){
            scanf("%lld %lld %lld ", &ID, &price, &num);
            sum[ID] += price * num;
            list[ln++] = ID;
        }
        for(i=0;i<ln;i++)
            if(1000000 <= sum[list[i]]){
                printf("%d\n", list[i]);
                f = 1;
                sum[list[i]] = 0;
            }      
        if(!f) printf("NA\n");
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ll N, M;
    cin >> N >> M;
    ll a, b;
    pair<ll , ll> p[100000];
    for(int i=0;i<N;i++){
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    
    ll ans = 0, count = 0;
    // 昇順ソート（第一要素）
    sort(p, p + N);
    for(int i=0;;i++){
        if(count + p[i].second < M){
            ans += p[i].first*p[i].second;
            count += p[i].second;
            // cout << "ans : " << ans << "count : " << count << endl;
        }else{
            ans += p[i].first*(M - count);
            break;
        }
    }

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

Measured memory_bytes: 1920
#include <cstdio>
#include <cstring>
#include <algorithm>
#define pli pair<long long,int>
#define s1 first
#define s2 second
using namespace std;
int n,k;long long a[200001];pli q[200001];int c[200001];
int query(int x){++x;int ans=0;for(int i=x;i;i-=i&-i)ans+=c[i];return ans;}void add(int x,int p){++x;for(int i=x;i<=n+1;i+=i&-i)c[i]+=p;}
int main()
{
	scanf("%d%d",&n,&k);for(int i=1;i<=n;++i)scanf("%lld",a+i),a[i]+=a[i-1];for(int i=0;i<=n;++i)q[i]=pli(a[i]-1ll*k*i,i);
	long long ans=0;sort(q,q+1+n);for(int i=0;i<=n;++i)
	{
		int pt=i;while(pt<=n&&q[++pt].s1==q[i].s1);--pt;
		for(int j=i;j<=pt;++j)add(q[j].s2,1);for(int j=i;j<=pt;++j)ans+=query(q[j].s2),--ans;i=pt;
	}
	printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    set<char>st;
    for(char c : s) st.insert(c);
    if(st.count('N') + st.count('S') == 1) cout << "No";
    else if(st.count('E') + st.count('W') == 1) cout << "No";
    else cout << "Yes";
    cout << endl;
}

Measured memory_bytes: 256
check x a b = x == (a ^ 5 - b ^ 5)


sqrt5Round x
	| x >= 0 = round $ exp (0.2 * log (fromIntegral x))
	| otherwise = (0 - ) $ sqrt5Round $ 0 - x

solve :: Int -> (Int, Int)
solve x = head [(a, (sqrt5Round ((a ^ 5) - x))) | a <- [0..], check x a (sqrt5Round ((a ^ 5) - x))]

show' :: (Int, Int) -> String
show' (a, b) = show a ++ " " ++ show b


main :: IO ()
main = interact $ show' . solve . read


Measured memory_bytes: 4304
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
	string str;
	getline(cin, str);
	for (auto &c : str) {
		if (c == '?') {
			c = 'D';
		}
	}
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 3748