akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.math.*;
public class Main {
    //
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        UnionFind un = new UnionFind(n);
        int q = sc.nextInt();
        for(int i = 0;i < q;i++){
            int com = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            if(com==0){
                un.union(x, y);
            }else{
                if(un.same(x,y)){
                    System.out.println(1);
                }else{
                    System.out.println(0);
                }
            }
        }
       
    }
    static class UnionFind {
        private int[] parent;
        private int[] rank;
        private int[] nodenum;
    
        /**
         * コンストラクタ
         * 
         * @param size ノード数
         */
        public UnionFind(int size) {
            parent = new int[size];
            rank = new int[size];
            nodenum = new int[size];
            for (int i = 0; i < size; i++)
                makeSet(i);
        }
    
        /**
         * ノードの作成 作成されたノードは根となる 元サイズよりも大きいノードを指定した場合エラー
         * 
         * @param x :ノード
         */
        public void makeSet(int x) {
            parent[x] = x;
            rank[x] = 0;
            nodenum[x] = 1;
        }
    
        /**
         * x,yの属している木の結合 同じ木の場合はなにもしない
         * 
         * @param x :ノード1
         * @param y :ノード2
         */
        public void union(int x, int y) {
            final int xRoot = find(x);
            final int yRoot = find(y);
            if (rank[xRoot] > rank[yRoot]) {
                parent[yRoot] = xRoot;
                nodenum[xRoot] += nodenum[yRoot];
            } else if (rank[yRoot] > rank[xRoot]) {
                parent[xRoot] = yRoot;
                nodenum[yRoot] += nodenum[xRoot];
            } else if (xRoot != yRoot) {
                parent[yRoot] = xRoot;
                nodenum[xRoot] += nodenum[yRoot];
                rank[xRoot]++;
            }
        }
        /**
         * 属している木の根を返す
         * 検索したノードは経路圧縮が行われる
         * @param x : ノード
         * @return int :根のノード
         */
        public int find(int x){
            if(x != parent[x]){
                parent[x] = find(parent[x]);//直接根に繋ぐ（経路圧縮）
            }
            return parent[x];
        }
        /**
         * 同じ木に属しているかどうかを返す
         * 同じ根かどうかで判別する
         * @param x :node
         * @param y :node
         * @return boolean :true ->同じ木
         */
        public boolean same(int x,int y){
            return find(x)==find(y);
        }
    
        public int getnodenum(int x){
            return nodenum[find(x)];
        }
    }
}






Measured memory_bytes: 99068
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (a >= 0 && c >= 0) {
        c -= b;
        if (c <= 0) return cout << "Yes", 0;
        a -= d;
        if (a <= 0) return cout << "No", 0;
    }
    return 0;
}

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

int main(){
    
    int N,W;
    cin >> N >> W;
    vector< vector<int> > DP(N+1, vector<int>(W+1,0));
    vector<int> v(N+1,0);
    vector<int> w(N+1,0);
    for(int i=1; i<=N; ++i){
        cin >> v[i] >> w[i];
    }

    // int DP[N+1][W+1] = {};
    // ??°?¢?????????£??????????????§?????????0??§???????????????????????????

    for(int i=1; i<=N; ++i){
        for(int c=1; c<=W; ++c){
            if(c-w[i]<0){
                DP[i][c] = DP[i-1][c];
            } else {
                DP[i][c] = max(DP[i][c-w[i]]+v[i], DP[i-1][c]);
            }
        }
    }

    cout << DP[N][W] << endl;
}

Measured memory_bytes: 6800
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <array>
#include <map>
#include <set>

using namespace std;

int digit(int n)
{
    int ret = 0;
    while (n > 0)
    {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int count = 0;
    for (int i = 1; i <= n; i++)
    {
        int d = digit(i);
        if (a <= d && d <= b)
        {
            count += i;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
using namespace std;
using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：
string incvec(vec p) {
	int lg = p.size();
	string ans = "YES";
	rep(i, lg-1) {
		if(p.at(i) > p.at(i+1)) ans = "NO";
	}

	return(ans);
}

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

	int N; cin >> N;
	vec p(N);
	rep(i, N) cin >> p.at(i);

	string ans = incvec(p);
	if(ans == "YES") {
		cout << ans << endl;
		return 0;
	}

	rep(i, N-1)for(int j=i+1; j<N; j++) {
	vec rt = p;
	int tp = rt.at(i);
	rt.at(i) = rt.at(j);
	rt.at(j) = tp;

	if(incvec(rt) == "YES") {
		cout << "YES" << endl;
		return 0;
		}
	}

	cout << ans << endl;
	return 0;
}
// std::string str;
// str = std::to_string(int i);
// bitset<3> s(N);


Measured memory_bytes: 256
/*ex9-2 C- Unification
ryo_1129*/

#include <stdio.h>
#include <stdlib.h>
#define SIZE 100000
//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

void pop(node **first);
void push(node **first, char elem);

int main(void){
    int counter=0;
    char cube_color[SIZE+1];
    scanf("%s", cube_color);
    //最初のノードの指す先
    node *first = NULL;
    //キューブを積み上げていく
    for(int i=0; cube_color[i] != '\0'; i++){
        if(first == NULL || first->elem == cube_color[i]){
            push(&first, cube_color[i]);
        }else{
            pop(&first);
            counter += 2;
        }
    }
    printf("%d\n",counter);

    return 0;
}

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り除く
void pop(node **first){
    node *tmp = *first;
    *first = tmp->next;
    //取り除いたノードのメモリを解放
    free(tmp);
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int a, p;
  cin >> a >> p;

  int result = (a * 3 + p) / 2;
  cout << result << endl;

  return 0;
}


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

string s;
string candidates[4] = {"maerd", "remaerd", "esare", "resare"};

void solve() {
  reverse(s.begin(), s.end());
  int pos = 0;
  while (pos < s.size() - 1) {
    bool not_found = true;
    for (int i=0;i<4;i++) {
      size_t found = s.substr(pos).find(candidates[i]);
      if (found == 0) {
        pos += candidates[i].size();
        not_found = false;
        continue;
      }
    }
    if (not_found) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}

int main() {
  cin >> s;
  solve();
}


Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))
a1=a[::2]
a2=a[1::2]
import collections
c1=collections.Counter(a1)
c2=collections.Counter(a2)
c1=c1.most_common(2)
c2=c2.most_common(2)
if a1==a2 and len(c1)==1 and len(c2)==1:
  print(len(a1))
  exit()
if len(c1)==1 and len(c2)==1 and c1[0][0]!=c2[0][0]:
  print(0)
  exit()
ans=0
if c1[0][0]!=c2[0][0]:
  ans+=n-c1[0][1]-c2[0][1]
else:
  if len(c1)==1:
    ans+=len(a2)-c2[1][1]
  elif len(c2)==1:
    ans+=len(a1)-c1[1][1]
  else :
    ans=min(len(a1)-c1[0][1]+len(a2)-c2[1][1],len(a1)-c1[1][1]+len(a2)-c2[0][1])
print(ans)

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

using namespace std;

int main()
{
    int N, L;
    int x[5010], a[5010];
    
    scanf("%d %d", &N, &L);
    
    for (int i = 0; i < N; i++) scanf("%d", x + i);
    for (int i = 0; i < N; i++) scanf("%d", a + i);
    
    int dp[2][5010] = {{0}};
    int prev = 0, now = 1;
    
    dp[prev][L] = 1;
    for (int i = N - 1; i >= 0; i--){
        for (int j = L; j >= 0; j--){
            dp[now][j] = 0;
            dp[prev][j] = (dp[prev][j] + dp[prev][j + 1]) % 1000000007;
        }
        for (int j = x[i]; j < L; j += a[i]){
            dp[now][j] = dp[prev][j + 1];
            if (!a[i]) break;
        }
        now = 1 - now;
        prev = 1 - prev;
    }
    
    int ans = 0;
    
    for (int i = 0; i < L; i++) ans = (ans + dp[prev][i]) % 1000000007;
    
    printf("%d\n", ans);
    
    return (0);
}

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

#[fastout]
#[allow(non_snake_case)]
#[allow(unused)]
fn main() {
    input! {
        N: String,
    }

    let sum = N.chars()
        .map(|x| x.to_digit(10).unwrap())
        .fold(0, |x, y| { x + y });

    let ans = if sum % 9 == 0 { "Yes" } else { "No" };
    println!("{}", ans);
}


Measured memory_bytes: 2412
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,k;
  cin >> N;
  k=1;
  vector<string> G(N);
  for(int i=0; i<N; i++)
  {
    cin>>G.at(i);
  }
  sort(G.begin(),G.end());
  for(int i=0; i<N-1; i++)
  {
    if(G.at(i+1)!=G.at(i))
      k++;
  }
  cout << k<< endl;
}


Measured memory_bytes: 9596
let analysis (area:string) =
  let len = String.length area in
  let stack = Stack.create () in
  let rec loop acc = function
      i when i = len -> acc
    | i ->
      match area.[i] with
      | '\\' -> Stack.push i stack; loop acc (i+1)
      | '/' -> loop
                 (match Stack.length stack with
                    0 -> acc
                  | _ -> let j = Stack.pop stack in
                    (((j,i),i-j)::acc))
                 (i+1)
      | _ -> loop acc (i+1)
  in loop [] 0

let summarize lst =
  let rec loop acc = function
      []  -> acc
    | [x] -> x::acc
    | ((s1,e1),v1)::((s2,e2),v2)::r when s1 < s2 && e1 > e2 ->
      loop acc (((s1,e1), v1+v2)::r)
    | a::(b::r as rest) -> loop (a::acc) rest
  in loop [] lst

let () =
  let line = read_line () in
  let count = ref 0 in
  let buf = Buffer.create 128 in
  analysis line |> summarize
  |> List.fold_left
    (fun acc (_,v) ->
       incr count;
       Buffer.add_string buf (Printf.sprintf " %d" v);
       acc+v)
    0
  |> (fun sum -> Printf.printf "%d\n%d%s\n" sum !count (Buffer.contents buf))

Measured memory_bytes: 3936
import sys
input = sys.stdin.readline
from operator import itemgetter

def main():
	a, b = map(int, input().strip().split())
	if b == 1:
		print(0)
		return
	ans = 1
	kuchi = a
	while kuchi < b:
		ans += 1
		kuchi += a-1
	print(ans)

if __name__ == '__main__':
	main()


Measured memory_bytes: 38384
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N = int(input())
A = lmi()

d = collections.defaultdict(int)
for i, a in enumerate(A):
    d[a] += 1

for i in range(1, N + 1):
    print(d[i])


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

const int maxn = 100009;
int a[maxn], x, p, n, L, T, tmp;

int main() {
	scanf("%d%d%d", &n, &L, &T);
	rep (i, 0, n-1) {
		scanf("%d%d", &x, &p);
		if (p == 1) {
			a[i] = (x + T) % L;
			tmp = (tmp + (x + T - a[i]) / L) % n;
		}
		else {
			a[i] = (x - T % L + L) % L;
			tmp = (tmp + (x - T - a[i]) / L) % n;
		}
	}
	sort(a, a+n); tmp = (tmp % n + n) % n;
	rep (i, tmp, n-1) printf("%d\n", a[i]);
	rep (i, 0, tmp-1) printf("%d\n", a[i]);
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)))
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
int n,ans;
pii x[100005],y[100005];
int root[100005];
int cnt;
struct State
{
	int x;
	int y;
	int w;
	State(int x,int y,int w):x(x),y(y),w(w){}	
};
vector<State> E;
/*---main code---*/

int find(int x)
{
	if(root[x]!=x)
	{
		root[x]=find(root[x]);
	}
	return root[x];
}

bool unite(int x,int y)
{
	x=find(x),y=find(y);
	if(x==y)
	{
		return 0;
	}
	root[x]=y;
	return 1;
}

bool cmp(State x,State y)
{
	return x.w<y.w;
}

int main()
{
	FIO;
	cin>>n;
	cnt=n;
	for(int i=1;i<=n;i++)
	{
		root[i]=i;
		cin>>x[i].first>>y[i].first;
		x[i].second=y[i].second=i;
	}
	sort(x+1,x+n+1);
	sort(y+1,y+n+1);
	for(int i=n;i>1;i--)
	{
		E.push_back(State(x[i].second,x[i-1].second,x[i].first-x[i-1].first));
		E.push_back(State(y[i].second,y[i-1].second,y[i].first-y[i-1].first));
	}
	sort(ALL(E),cmp);
	for(int i=0;i<E.size();i++)
	{
		if(unite(E[i].x,E[i].y))
		{
			ans+=E[i].w;
			cnt--;
			if(cnt==1)
			{
				break;
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 6900
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val list = mutableListOf<Triple<String, Int, Int>>()
    for (i in 1..n) {
        val line = readLine()!!.split(" ")
        val s = line[0]
        val p = line[1].toInt()
        list.add(Triple(s, p, i))
    }
    val result = mutableListOf<Triple<String,Int,Int>>()
    result.add(list[0])
    loop@for(l in 1..list.size-1){
        for (i in 0..result.size-1) {
            if(list[l].first.compareTo(result[i].first)<0){
                result.add(i,list[l])
                continue@loop
            }else if(list[l].first.compareTo(result[i].first)==0){
                if(list[l].second>result[i].second){
                    result.add(i,list[l])
                    continue@loop
                }
            }
        }
        result.add(list[l])
    }
    result.forEach { println(it.third) }
}

Measured memory_bytes: 37868
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    char[] chars = sc.next().toCharArray();
    String status = "Good";
    for(int i=1; i<chars.length; i++){
      if(chars[i-1]==chars[i]){
        status = "Bad";
      }
    }
    System.out.println(status);
  }
}

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

using namespace std;

typedef pair<pair<string,int>, int> P;

int main(){
    int n;
    cin>>n;
    vector<P> guide(n);

    for(int i=0;i<n; i++){
        cin>>guide[i].first.first;
        cin>>guide[i].first.second;
        guide[i].first.second*=(-1);
        guide[i].second=i;
    }
    sort(guide.begin(),guide.end());

    for(int i=0; i<n; i++){
        cout<<guide[i].second+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
public class Main {
    public static void main(String args[]) {
        Sc sc = new Sc(System.in);
        int N = sc.nI();
        long[] T = new long[N];
        long[] A = new long[N];
        long maxh = 0;
        int iT = -10;
        int iA = -10;
        for(int i = 0; i<N; i++) {
            T[i] = sc.nI();
            if(T[i] > maxh) {
                maxh = T[i];
                iT = i;
            }
        }
        for(int i = 0; i<N; i++) {
            A[i] = sc.nI();
        }
        for(int i = N-1; i>=0; i--) {
            if(A[i] == maxh && iA == -10) iA = i;
        }
        if(A[0] != maxh || iT > iA) {
            System.out.println(0);
            return;
        }
        long ways = 1;
        for(int i = 1; i<iT; i++) {
            if(T[i] == T[i-1]) {
                ways = (ways*T[i])%1000000007L;
            }
        }
        for(int i = N-2; i>iA; i--) {
            if(A[i] == A[i+1]) {
                ways = (ways*A[i])%1000000007L;
            }
        }
        for(int i = iT+1; i<iA; i++) {
            ways = (ways*maxh)%1000000007L;
        }
        System.out.println(ways);
    }
}
class Sc {
    public Sc(InputStream i) {
        r = new BufferedReader(new InputStreamReader(i));
    }

    public boolean hasM() {
        return peekToken() != null;
    }

    public int nI() {
        return Integer.parseInt(nextToken());
    }

    public double nD() { 
        return Double.parseDouble(nextToken());
    }

    public long nL() {
        return Long.parseLong(nextToken());
    }

    public String n() {
        return nextToken();
    }

    private BufferedReader r;
    private String line;
    private StringTokenizer st;
    private String token;

    private String peekToken() {
        if (token == null) 
            try {
                while (st == null || !st.hasMoreTokens()) {
                    line = r.readLine();
                    if (line == null) return null;
                    st = new StringTokenizer(line);
                }
                token = st.nextToken();
            } catch (IOException e) { }
        return token;
    }

    private String nextToken() {
        String ans = peekToken();
        token = null;
        return ans;
    }
}

Measured memory_bytes: 37052
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
#print(a)
ad=sum(a)
#print(ad)
ad=ad/(4*m)
#print(ad)

for i in range(m):
    if a[i]<ad:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
    return 0;
}


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

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

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

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    string s;
    cin >> s;

    if (s[2] == s[3] && s[4] == s[5])
        print("Yes");
    else
        print("No");

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

ll get(vector<pair<ll,ll>> &p, int n) {
    ll mn = p[0].first + p[0].second;
    ll mx = p[0].first + p[0].second;
    for(int i=1; i<n; ++i) {
        ll sum = p[i].first+p[i].second;
        mx = max(sum, mx);
        mn = min(sum, mn);
    }
    return mx-mn;
}

void solve(int tc) {
    int n;
    cin>>n;
    vector<pair<ll,ll>> p(n);
    for(int i=0; i<n; ++i) {
        cin>>p[i].first>>p[i].second;
    }
    ll ans = get(p, n);
    for(int i=0; i<n; ++i) {
        p[i].first *= -1;
    }
    ans = max(ans, get(p, n));
    for(int i=0; i<n; ++i) {
        p[i].first *= -1;
        p[i].second *= -1;
    }
    ans = max(ans, get(p, n));
    for(int i=0; i<n; ++i) {
        p[i].first *= -1;
    }
    ans = max(ans, get(p, n));
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    for(int tc=1; tc<=t; ++tc) {
        solve(tc);
    }    
    return 0;
}

Measured memory_bytes: 6344
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

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

    if(a >= 13) cout << b << endl;
    else if(a >= 6) cout << b / 2 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
std::string X;

void showBin( ll x ) {
  std::vector<ll> vs;
  
  while( x > 0 ) {
    vs.emplace_back( x&1 );
    x >>= 1;
  }

  repd( i, vs.size() ) 
    std::cout << vs[i];

  std::cout << std::endl;
}

void sim( ll x ) {
  while( x > 0 ) {
    showBin(x);
    x %= __builtin_popcountll(x);
  }

  return;
}

ll mod2( const std::string &x, ll mod ) {
  ll ret = 0;
  
  rep( i, x.size() ) {
    ret *= 2;
    ret %= mod;
    ret += x[i]-'0';
    ret %= mod;
  }

  return ret;
}

ll powMod[10];
ll two[200010][3];

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

  ll pop = 0;

  rep( i, N )
    pop += X[i] == '1';

  //std::cout << pop << std::endl;

  for( ll s = -1; s <= 1; ++s ) if( pop+s ) {
    powMod[s+1] = mod2( X, pop+s );
    //std::cout << powMod[s+1] << std::endl;
  }

  two[0][0] = two[0][1] = two[0][2] = 1;

  rep( i, N ) for( ll s = -1; s <= 1; ++s ) if( pop+s ) {
    two[i+1][s+1] = two[i][s+1]*2%(pop+s);
  }

  rep( i, N ) {
    ll pop2 = pop;
    ll add = 0;

    if( X[i] == '1' )
      X[i] = '0', --pop2;
    else
      X[i] = '1', ++pop2;

    ll ans = 0;

    if( !pop2 ) {
      ans = 0;
      std::cout << ans << std::endl;

      if( X[i] == '1' )
        X[i] = '0';
      else
        X[i] = '1';

      continue;
    }

    ll m = (powMod[pop2-pop+1]+(pop2-pop)*two[N-i-1][pop2-pop+1]+pop2)%pop2;
    ans = 1;

    /*std::cout << "YEs" << std::endl;
    std::cout << m << std::endl;
    std::cout << pop2 << std::endl;
    std::cout << two[21][1] << std::endl;*/

    while( m > 0 ) {
      m %= __builtin_popcount(m);
      ++ans;
    }

    std::cout << ans << std::endl;

    if( X[i] == '1' )
      X[i] = '0';
    else
      X[i] = '1';
  }

  return 0;
}

Measured memory_bytes: 8412
#include <algorithm>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  typedef struct {
    int v;
    int i;
  } t_edge;

  vector<vector<t_edge>> G(N + 1);
  vector<int> E(N, -1);
  rep(i, N - 1) {
    int a, b;
    cin >> a >> b;
    t_edge tmp0 = {b, i};
    G[a].push_back(tmp0);
    t_edge tmp1 = {a, i};
    G[b].push_back(tmp1);
  }

  queue<int> que;
  que.push(1);
  int K = 0;
  while (!que.empty()) {
    int n = que.front();
    que.pop();
    unordered_map<int, bool> mp;
    for (auto i : G[n]) {
      if (E[i.i] != -1) {
        mp[E[i.i]] = true;
      }
    }
    int col = 1;
    for (auto i : G[n]) {
      if (E[i.i] == -1) {
        while (mp[col] == true) col++;
        E[i.i] = col;
        mp[col] = true;
        que.push(i.v);
      }
    }
    K = max(K, col);
  }

  cout << K << endl;
  rep(i, N - 1) { cout << E[i] << endl; }

  return 0;
}


Measured memory_bytes: 7040
#include<stdio.h>
#include<string.h>
#define MAX 244140625
#define LMAX 12

int Atoi(char);
int getkey(char *);
int find(char *);//あったら０
void insert(char *);

char H[LMAX];
int hash[MAX];

int main(){
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
	char com[7];
	scanf("%s%s",com,H);
	if(com[0]=='f'){
		if(find(H)==0)printf("yes\n");
		else printf("no\n");
	}
	else insert(H);
  }
 
  return 0;
}

void insert(char *str){
	hash[getkey(str)]=1;
}

int getkey(char *str){
	int i,ans=0,p=1;
	for(i=0;i<strlen(str);i++){
		ans+=p*Atoi(str[i]);
		p*=5;
	}
	return ans;
}

int Atoi(char x){
	if(x=='A')return 1;
	else if(x=='C')return 2;
	else if(x=='G')return 3;
	else return 4;
}


int find(char *str){
	if(hash[getkey(str)]==1)return 0;
	else return 1;
}



Measured memory_bytes: 19656
# -*- coding: utf-8 -*-

def main():

    N = int(input())
    S = input()

    listS = list(S)
    x = 0
    listNum = [x]

    for i in listS:
        if i == 'I':
            x += 1
            listNum.append(x)

        elif i == 'D':
            x += -1
            listNum.append(x)

    ans = max(listNum)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());

		if(a+b == c || b+c == a || c+a == b) {
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 23124
/**
*    created: 01.07.2020 15:32:12
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
// const int MOD = 998244353;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;
    int mx, md, mn;
    mx = max({a,b,c});
    mn = min({a,b,c});
    md = a + b + c - (mx + mn);
    if ((mx*2-md-mn) % 2 == 0) {
        cout << (mx*2-md-mn)/2 << endl;
        return 0;
    }
    else {
        cout << (mx*2-md-mn+3)/2 << endl;
        return 0;
    }
}

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

using namespace std;

typedef complex<double> P;
#define X real()
#define Y imag()

P solve(int n){
  P res(0,1);
  for(int i=1;i<n;i++){
    P v = res ;
    v *= exp( P(0.0,3 * 90.0 * M_PI / 180.0) );
    v /= abs(v);
    res += v;
  }
  return res;
}
int main(){
  int n;
  while(cin>>n,n!=-1){
    auto ans = solve(n);
    cout<<ans.Y<<endl<<ans.X<<endl;
  }
}

Measured memory_bytes: 1248
#include<stdio.h>
int main(void)
{
	int i,n,x;
	while(scanf("%d",&n)!=EOF) {
		x=0;
		for(i=n;i>=1;i--) {
			x=x+1;
			if(39<x) {
				x=x-39;
			}
		}
		if(x<10) {
			printf("3C0%d\n",x);
		}
		else {
			printf("3C%d\n",x);
		}
	}
	return 0;
}

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

double n, a[100];
double ta = 0;
vector<pair<double, int>> mu = {};

signed main(){
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mu.push_back(make_pair(0,i));
		ta += a[i];
	}
	ta /= n;
	for (int i = 0; i < n; i++) {
		mu[i].first = max(ta, a[i]) - min(ta, a[i]);
	}
	sort(mu.begin(),mu.end());
	cout << mu[0].second << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  int sum1 = a + b;
  int sum2 = c + d;
  if (sum1 > sum2) {
    outl("Left");
  } else if (sum1 < sum2) {
    outl("Right");
  } else {
    outl("Balanced");
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    a, b, c = map(int, input().split())

    num = 2
    rem = a % b
    if rem == c:
        print('YES')
        sys.exit()
    while True:
        rem_t = (a * num) % b
        if rem_t == c:
            print('YES')
            sys.exit()
        elif rem_t == rem:
            print('NO')
            sys.exit()
        num += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 9160
def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    else:
        return gcd(y,x%y)       
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):
    ans=gcd(a[i],a[i-1])
    a[i]=ans
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>



typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;

const int MAX = 1001001;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(){
    int n;
    string s;
    cin>>n>>s;
    if (n%2!=0) {
        cout<<"No"<<endl;
        return 0;
    }
    int h=n/2;
    for(int i=0;i<h;i++){
        if (s[i]!=s[i+h]) {
            cout<<"No"<<endl;
            return 0;
            
        }
    }
    
    cout<<"Yes"<<endl;
    
    
    return 0;
}


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

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

  if (abs(b-a) <= d && abs(c-b) <= d) {
    cout << "Yes" << endl;
  } else if (abs(c-a) <= d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

left = list[0]
right = list[-1]

i = 1
j = -2
count = 0

while count != len(list)-2:
    if left < right:
        left += list[i]
        count += 1
        i += 1
    else:
        right += list[j]
        count += 1
        j -= 1

print(abs(right - left))

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

int main() {
	int M; cin >> M;
	if (M >= 400 && M <= 599)cout << 8 << endl;
	if (M >= 600 && M <= 799)cout << 7 << endl;
	if (M >= 800 && M <= 999)cout << 6 << endl;
	if (M >= 1000 && M <= 1199)cout << 5 << endl;
	if (M >= 1200 && M <= 1399)cout << 4 << endl;
	if (M >= 1400 && M <= 1599)cout << 3 << endl;
	if (M >= 1600 && M <= 1799)cout << 2 << endl;
	if (M >= 1800 && M <= 1999)cout << 1 << endl;
}

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

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

Measured memory_bytes: 256
/*---------------------------------- NEVER GIVE UP --------------------------------------------*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pii;
typedef tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL)

const ll modd=1e9+7;
const ll inff=1e18;

ll poww(ll a,ll b){
  ll ans=1;
  while(b){
    if(b&1LL) ans=(ans*a);
    a=(a*a);
    b=b>>1LL;
  }
  return ans;
}

/*-----------------------------------------------------------------------------------------------*/

const ll N = 1e4+5;

ll ans[N];

int main(){
  fastt;

  for(ll j = 1; j*j < N; j++)
        for(ll k = 1; k*k < N-j*j; k++)
            for(ll l = 1; l*l < N-j*j-k*k; l++){
                if(j*j+k*k+l*l+j*k+k*l+j*l < N) ans[j*j+k*k+l*l+j*k+k*l+j*l]++;
            }
   
  ll n;
  cin >> n;

  for(ll i = 1; i <= n; i++){
      cout << ans[i] << '\n';
  }
 
  return 0;
}

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

#define rep(i,begin,end) for(int i=begin;i<=end;i++)
#define repi(i,end,begin) for(int i=end;i>=begin;i--)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

#define MAXN 100001

int n;
int table[MAXN][3], dp[MAXN][3];

int sol(int pos, int item){
	if(dp[pos][item] != -1) return dp[pos][item];

	if(pos == 1) return dp[pos][item] = table[pos][item];

	return dp[pos][item] = max(table[pos][item] + sol(pos-1,(item+1)%3), table[pos][item] + sol(pos-1,(item+2)%3));
}

int main(){
fio

cin >> n;

memset(dp,-1,sizeof(dp));

rep(i,1,n){
	rep(j,0,2) cin >> table[i][j];
}

cout << max(max(sol(n,0),sol(n,1)),sol(n,2)) << endl;
return 0;
}

Measured memory_bytes: 8832
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	char[][] map;
	int w;
	int h;
	public void run(){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
        	w = scan.nextInt();
        	h = scan.nextInt();
        	if(w == 0 && h == 0){
        		break;
        	}
        	map = new char[h][w];
        	for(int i = 0;i < h;i++){
        		for(int j = 0;j < w;j++){
        			map[i][j] = scan.next().charAt(0);
        		}
        	}
        	int count = 0;
        	for(int i = 0;i < h;i++){
        		for(int j = 0;j < w;j++){
        			if(map[i][j] == '1'){
        				count++;
        				checkMap(i,j);
        			}
        		}
        	}
        	System.out.println(count);
        }
    }
	public void checkMap(int i,int j){
		if(map[i][j] == '0'){
			return;
		}
		map[i][j] = '0';
		for(int dx = -1;dx < 2;dx++){
			for(int dy = -1;dy < 2;dy++){
				if(i + dy >= 0 && i + dy < h &&j + dx >= 0 && j + dx < w && map[i + dy][j + dx] != '0'){
					checkMap(i + dy,j + dx);
				}
			}
		}
		return;
	}
}

Measured memory_bytes: 32692
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    // 半径の長さ
    double r = sc.nextLong();

    // 円周の長さ
    double result = 2 * r * 3.14;
    System.out.println(result);
  }
}

Measured memory_bytes: 35988
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define f first
#define s second
#define mset(m,v) memset(m,v,sizeof(m))
#define mod 1000000007
const int N = 2e5 + 5;
#define PI acos(-1.0)
long double EPS = 1e-9;
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
void solve() {
	int n;
	cin >> n;
	map<string, int>m;
	rep(i, n)
	{
		string s;
		cin >> s;
		m[s]++;
	}
	cout << sz(m) << endl;

}
signed main()
{
	fastio;
	//cout<<fixed<<setprecision(15);
	//clock_t begin = clock();
	int tc;
	tc = 1;
	//cin >> tc;
	while (tc--) {
		solve();
	}
	//clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;
}


Measured memory_bytes: 19272
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define setNil(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
#define setNegINF(x) memset((x),192,sizeof(x)) //NegINF=-INF-1
#define setNeg1(x) memset((x),255,sizeof(x))
using namespace std;
int n,cnt,ans=-2,deg[100005],par[100005],fx,fc;
bool mr[100005];
string s;
bool vis[100005];
vector<int> g[100005];
queue<int> q;
void dfs1(int x,int p){
	par[x]=p;
	for(int i=0;i<g[x].size();i++){
		int u=g[x][i];
		if(u==p)continue;
		deg[x]++;
		dfs1(u,x);
	}
}
void dfs(int x,int p,int c){
	if(c>fc){
		fc=c;
		fx=x;
	}
	for(int i=0;i<g[x].size();i++){
		int u=g[x][i];
		if(!deg[u] || u==p)continue;
		dfs(u,x,c+mr[u]);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	cin>>s;
	s="$"+s;
	int rt=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='W'){
			cnt++;
			rt=i;
		}
	}
	if(cnt<2)cout<<cnt<<endl;
	else{
		dfs1(rt,0);
		for(int i=1;i<=n;i++)if(!deg[i] && s[i]=='B')q.push(i);
		while(!q.empty()){
			int u=q.front();
			q.pop();
			for(int i=0;i<g[u].size();i++){
				int v=g[u][i];
				if(deg[v]==1 && s[v]=='B'){
					q.push(v);
					cnt++;
				}
				if(deg[v])deg[v]--;
			}
		}
		for(int i=1;i<=n;i++)deg[i]|=(s[i]=='W');
		for(int i=1;i<=n;i++){
			if(!deg[i])continue;
			ans+=2;
			int sum=0;
			for(int j=0;j<g[i].size();j++)sum+=(!!deg[g[i][j]]);
			if(sum&1)ans+=(mr[i]=(s[i]=='B'));
			else ans+=(mr[i]=(s[i]=='W'));
		}
		dfs(rt,0,mr[rt]);
		dfs(fx,fc=0,mr[fx]);
		cout<<ans-2*fc<<endl;
	}
	return 0;
}

Measured memory_bytes: 13032
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N = 2e3+20;
const int INF = 1e9;

vector<int> adj[N];

int main(){

	fastio;
	int n,x,y;
	cin >> n >> x >> y;
	for(int i = 1; i < n; ++i){
		adj[i].pb(i+1);
		adj[i+1].pb(i);
	}
	adj[x].pb(y);
	adj[y].pb(x);

	vector<int> ans(n+1,0);
	for(int i = 1; i <= n; ++i){
		queue<int> q;
		vector<int> dist(n+1,INF);
		q.push(i); dist[i] = 0;
		while(sz(q)){
			int u = q.front(); q.pop();
			for(int v : adj[u]){
				if(dist[v] == INF){
					dist[v] = dist[u] + 1;
					ans[dist[v]]++;
					q.push(v);
				}
			}
		}
	}

	for(int i = 1; i < n; ++i){
		cout << ans[i]/2 << '\n';
	}

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
//int  t,nr,ng,nb;
ll sq(int x){return 1ll*x*x;}
#define mod 1000000007
/*void solve(vector<int>a,vector<int>b,vector<int>c)
{
  for(auto x:a)
  {
   auto y=lower_bound(b.begin(),b.end(),x);
   auto z=upper_bound(c.begin(),c.end(),x);
   if(y==b.end()||z==c.begin())
        continue;
   z--;
   ans=min(ans,sq(x-*y)+sq(*y-*z)+sq(x-*z));
  }

}*/
int main()
{ios_base::sync_with_stdio(false);
ll n,m;
cin>>n>>m;
ll ans=0,t;
for(ll i=0;i<m;i++)
{
    cin>>t;ans+=t;
}
cout<<(-ans+n>=0?-ans+n:-1);
}


Measured memory_bytes: 3656
import sys, os

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

def solve():
    a,b = f()
    if a<=8 and b<=8:
        print('Yay!')
    else:
        print(':(')

solve()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n,sum = 0;
    cin >> n;
    vector<int> a,b,c;
    int x;
    for(int i = 0;i < n;i++)
    {
        cin >> x;
        a.push_back(x);
    }
    for(int i = 0;i < n;i++)
    {
        cin >> x;
        b.push_back(x);
    }
    for(int i = 0;i < n - 1;i++)
    {
        cin >> x;
        c.push_back(x);
    }
    for(int i = 0;i < n;i++)
    {
        sum = sum + b.at(a.at(i) - 1);
        if((i + 1) != n && a.at(i) == (a.at(i + 1) - 1))
        {
            sum = sum + c.at(a.at(i) - 1);
        }
    }
    cout << sum;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define N 100005
using namespace std;

int n;
string t;
bool a[N], b[N];

void g() {
	int i;
	for (i = 0; i < n; i++) printf("%c", b[i] ? 'W' : 'S');
	exit(0);
}

void f() {
	int i;
	for (i = 2; i <= n + 1; i++) b[i] = b[i - 2] ^ b[i - 1] ^ a[i - 1];
	if (b[0] == b[n] && b[1] == b[n + 1]) g();
}

int main()
{
	int i;
	cin >> n >> t;
	for (i = 0; i < t.size(); i++) a[i] = (t[i] == 'x');
	a[n] = a[0];
	b[0] = 0; b[1] = 0; f();
	b[0] = 0; b[1] = 1; f();
	b[0] = 1; b[1] = 0; f();
	b[0] = 1; b[1] = 1; f();
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 768