akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 998244353;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll min(ll a, ll b) {
	if (a < b)
		return a;


	return b;
}

ll max(ll a, ll b) {
	if (a < b)
		return b;

	return a;
}


vector<ll> a;
ll N, x;

ll m[2000];

int main() {
	cin >> N >> x;
	a.resize(N);
	rep(i, N) {
		cin >> a[i];
		m[i] = a[i];
	}


	ll ans = inf, sum = 0;
	rep(kaisu, N) {
		sum = 0;
		rep(j, N) {
			ll index;

			if (j - kaisu >= 0) {
				index = j - kaisu;

			}
			else {
				index = N - (kaisu - j);
			}

			m[j] = min(m[j], a[index]);
			sum += m[j];

		}


		ans = min(ans, x * kaisu + sum);


	}

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


Measured memory_bytes: 256
fn solve(a: Vec<i64>) -> Option<(i64, i64)> {
    let mut l = 2;
    let mut r = 2;
    for x in a {
        let nl = ((l + x - 1) / x) * x;
        let nr = (r / x) * x + (x - 1);
        l = nl;
        r = nr;
        if !(l <= r) {
            return None
        }
    }
    Some((l, r))
}
fn main() {
    let k: usize = readln();
    let mut a: Vec<i64> = readln();
    a.reverse();
    match solve(a) {
        Some((l, r)) => println!("{} {}", l, r),
        None => println!("-1"),
    }
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashSet;

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n { vs.push(readln()); }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 8444
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}

using namespace std;
#pragma endregion
signed main() {
	int x=0;
	string s;
	cin >> s;
	rep(i, s.size()) {
		if (s[i] == '1')
			x++;
	}
	cout << x;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 17.01.2020 01:59:15       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  auto IsSubset = [&](long long a, long long b) {
    return ((a & b) == a);
  };
  auto Get = [&](long long X, long long Y) {
    int z = 0;
    for (int i = 0; i < n; i++) {
      if (Y >= y[i]) {
        z ^= IsSubset(Y - y[i], X + Y - x[i] - y[i]);
      }
    }
    return z % 2;
  };
  const long long inf = (long long) 5e17;
  long long X = inf;
  long long Y = 0;
  assert(Get(X, Y) == 1);
  for (int bit = 60; bit >= 0; bit--) {
    if (Get(X - (1LL << bit), Y + (1LL << bit))) {
      X -= 1LL << bit;
      Y += 1LL << bit;
    }
  }
  cout << X << '\n';
  return 0;
}


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

int main()
{
  ll n, x, ans = 0;
  ll all = 0;
  ll minimum = 1000;
  ll m;
  cin >> n >> x;

  for (int i = 0; i < n; i++)
  {
    cin >> m;
    all += m;
    minimum = min(minimum, m);
  }

  ans = n;
  x -= all;
  ans += x / minimum;
  cout << ans << endl;
}


Measured memory_bytes: 3548
#include <stdio.h>

int search(int[],int,int);

int main(){
  int S[10001],T,i,j,n,q,count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&T);
    if(search(S,n,T))count++;
  }
  printf("%d\n",count);
  return 0;
}


int search(int S[],int n,int T){
  int i=0;

  S[n]=T;

  while(S[i] != T)i++;

  return i != n;
}



Measured memory_bytes: 2104
#include <cstdio>
#include <climits>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

struct edge {
    int from;
    int to;
    ll cost;

    edge(int f, int t, int c) : from(f), to(t), cost(c) {  }
    edge() : from(0), to(0), cost(0) {  }
};

#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i <= n; i++)

const ll inf = 100000000000000ll;

int n, m, c, s, g;

// distance = G[company][from][to]
ll G[21][101][101];

int ps[21];
ll qs[21][51];
ll rs[21][51];
ll T[21][51];

vector<edge> E;
ll cost[101];

ll calc_cost(int ci, ll d) {
    for (int i = 0; i <= ps[ci]; i++) {
        if (qs[ci][i] > d) {
            return T[ci][i - 1] + (d - qs[ci][i - 1]) * rs[ci][i];
        }
    }
    return inf;
}

ll solve() {
    REP1(ci, c) {
        T[ci][0] = 0;
        REP1(i, ps[ci]) {
            T[ci][i] = T[ci][i - 1] + (qs[ci][i] - qs[ci][i - 1]) * rs[ci][i];
        }
    }

    REP(ci, 21) REP(i, 101) { G[ci][i][i] = 0; }
    REP1(ci, c) REP1(k, 100) REP1(i, 100) REP1(j, 100) {
        G[ci][i][j] = min(G[ci][i][j], G[ci][i][k] + G[ci][k][j]);
    }

    E.resize(0);
    REP(i, 101) {
        cost[i] = inf;
    }
    REP1(ci, c) REP1(i, 100) REP1(j, 100) {
        if (G[ci][i][j] != inf && i != j) {
            ll co = calc_cost(ci, G[ci][i][j]);
            E.push_back(edge(i, j, co));
        }
    }

    cost[s] = 0;
    for (;;) {
        bool update = false;
        REP(i, (int)E.size()) {
            int from = E[i].from;
            int to = E[i].to;
            ll co = E[i].cost;
            if (cost[to] > cost[from] + co) {
                cost[to] = cost[from] + co;
                update = true;
            }
        }
        if (!update) { break; }
    }

    if (cost[g] == inf) {
        return -1;
    }
    return cost[g];
}

int main() {
    for (;;) {
        scanf("%d%d%d%d%d", &n, &m, &c, &s, &g);

        if (!n) { break; }

        REP(i, 21) REP(j, 101) REP(k, 101) {
            G[i][j][k] = inf;
        }

        REP(i, m) {
            int xi, yi, ci;
            ll di;
            scanf("%d%d%lld%d", &xi, &yi, &di, &ci);
            ll d = min(G[ci][xi][yi], di);
            G[ci][xi][yi] = G[ci][yi][xi] = d;
        }

        REP1(i, c) {
            scanf("%d", &ps[i]);
        }

        REP1(i, c) {
            qs[i][0] = 0;
            REP1(j, ps[i] - 1) {
                scanf("%lld", &qs[i][j]);
            }
            qs[i][ps[i]] = inf;

            REP1(j, ps[i]) {
                scanf("%lld", &rs[i][j]);
            }
        }

        printf("%lld\n", solve());
    }
    return 0;
}

Measured memory_bytes: 7772
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
#define pb        emplace_back
#define fi        first
#define se        second
#define show(...)  fprintf(stderr, __VA_ARGS__ )
#define outl(x)   cout << (x) << '\n'
#define rep(i,n)     for(int i=0; i<(n); ++i)
#define inside(x,y,w,h) ((x)>=0 && (y)>=0 && (x)<(w) && (y)<(h))
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
typedef long long ll;
constexpr int       INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};
constexpr int MX = 100010;

typedef pair<int,int> pii;

int N, E, s;
vector<pii> G[MX];
int mcos[MX];

bool bellman_ford(int src)
{
    memset(mcos, INF, sizeof(mcos));
    mcos[src] = 0;

    rep(i, N) {
        rep(s, N) {
            for (const auto &e: G[s]) {
                if (mcos[s] != INF && chmin(mcos[e.se], mcos[s]+e.fi)) {
                    if (i == N-1) return true;
                }
            }
        }
    }
    return false;
}

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

   cin >> N >>E >> s;
   rep(i, E) {
       int s, t, c;
       cin >>s >> t >> c;
       G[s].pb(pii(c,t));
   }

   if (bellman_ford(s)) {
       outl("NEGATIVE CYCLE");
       return (0);
   }

   rep(i, N) {
       if (mcos[i] == INF) outl("INF");
       else outl(mcos[i]);
   }
}




Measured memory_bytes: 5932
s = input().split()
ss = []
for w in s:
    a = w.find('apple')
    p = w.find('peach')
    if a != -1:
        w = w.replace('apple','peach')
    elif p != -1:
        w = w.replace('peach','apple')
    ss.append(w)
print(' '.join(ss))

Measured memory_bytes: 7344
/// input macro from https://qiita.com/tanakh/items/1ba42c7ca36cd29d0ac8
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn solve() {
    input!(a: i64, b: i64, c: i64, d: i64);
    let x = a * c;
    let y = b * d;
    let z = a * d;
    let w = b * c;

    let max_value = {
        let xy = x.max(y);
        let zw = z.max(w);

        xy.max(zw)
    };

    println!("{}", max_value);
}
fn main() {
    std::thread::Builder::new()
        .name("solve".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}


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

int main()
{
	vector<bool> prime(50001, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i <= 223; i++) {
		if (prime[i]) {
			for (int j = i * 2; j <= 50000; j += i) {
				prime[j] = false;
			}
		}
	}
	int n, res;
	while (cin >> n, n) {
		res = 0;
		if (n % 2) {
			if (prime[n - 2])
				res = 2;
		}
		else if (n == 4) {
			res = 2;
		}
		else {
			for (int i = 3; i <= n - 3; i += 2) {
				if (prime[i] && prime[n - i]) {
					res++;
					if (i == n - i)
						res++;
				}
			}
		}
		cout << res / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 2968
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int w = sc.nextInt();
			int h = sc.nextInt();
			if (w == 0 && h == 0)
				break;
			String[] str = new String[h];
			for (int i = 0; i < h; i++)
				str[i] = sc.next();
			String[][] field = new String[h][w];
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++)
					field[i][j] = "";
			switch (str[0].charAt(0)) {
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				field[0][0] = str[0].substring(0, 1);
				break;
			default:
				field[0][0] = "";
				break;
			}
			String max = field[0][0];
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++) {
					switch (str[i].charAt(j)) {
					case '0':
					case '1':
					case '2':
					case '3':
					case '4':
					case '5':
					case '6':
					case '7':
					case '8':
					case '9':
						if (i > 0) {
							if (field[i - 1][j].equals("")
									|| field[i - 1][j].equals("0"))
								field[i][j] = maxString(field[i][j],
										str[i].substring(j, j + 1));
							else
								field[i][j] = maxString(
										field[i][j],
										field[i - 1][j]
												+ str[i].substring(j, j + 1));
						}
						if (j > 0) {
							if (field[i][j - 1].equals("")
									|| field[i][j - 1].equals("0"))
								field[i][j] = maxString(field[i][j],
										str[i].substring(j, j + 1));
							else
								field[i][j] = maxString(
										field[i][j],
										field[i][j - 1]
												+ str[i].substring(j, j + 1));
						}
						break;
					default:
						field[i][j] = "";
						break;
					}
					max = maxString(max, field[i][j]);
				}
			System.out.println(max);
		}
		sc.close();
	}

	static String maxString(String a, String b) {
		String result = "";
		if (a.length() > b.length())
			result = a;
		if (a.length() < b.length())
			result = b;
		if (a.length() == b.length()) {
			if (a.compareTo(b) < 0)
				result = b;
			else
				result = a;
		}
		return result;
	}
}

Measured memory_bytes: 74684
use proconio::*;

fn run() {
    input! {
        mut a: [usize; 3],
        k: usize,
    }
    let mut cnt = 0;
    for i in 1..3 {
        while a[i] <= a[i - 1] {
            a[i] *= 2;
            cnt += 1;
        }
    }
    if cnt <= k {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    run();
}

Measured memory_bytes: 2164
/*

This Submission is to determine how many 120/240 min const. delivery point there are.

//info
120 req. steps <= 5
*/
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)

unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(min((double)1.0, max((double)-1.0, cosine)));
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		double now_length = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa - now_min >= eps||(abs(goa - now_min) <= eps&&(abs(a[i] - a[starter]) - now_length) >= eps)) {
					now_min = goa;
					now_go = i;
					now_length = abs(a[i] - a[starter]);
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
int main() {
	int n;
	cin >> n;
	vector<int> H;
	REP(i, n) {
		int a;
		cin >> a;
		H.push_back(a);
	}
	int ans = 0;
	int now = 0;
	for (int i = 1; i < H.size(); ++i) {
		if (H[i - 1] < H[i]) {
			ans = max(ans, now);
			now = 0;
		}
		else {
			now++;
		}
	}
	cout << max(ans, now) << endl;
}

Measured memory_bytes: 892
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU
 
import qualified Data.Map as Map
 
main = putStrLn . solve . lines =<< getContents
 
solve (hw:xs) = if ans then "Yes" else "No" where
    f m c = Map.insertWith (+) c 1 m
    (fth, chs) = unzip
               $ map (`divMod` 4)
               $ Map.elems
               $ foldl (foldl f) Map.empty xs
    [h, w] = map read $ words hw
    sat = 4 * sum fth >= (div h 2) * (div w 2) * 4
    ans | h > 1 && w > 1 && not sat = False
        | even h && even w = all (== 0) chs
        | even h || even w = all even chs
        | otherwise = (== 1) $ length $ filter odd chs 

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

int main(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  cout<<x2-y2+y1<<" "<<y2+x2-x1<<" "<<x1-y2+y1<<" "<<y1+x2-x1<<endl;
}

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

const int MaxN = 100000;
int S[ MaxN + 10 ];

int main()
{
long long i;
long long N;
long long M;
long long A;
long long x;
long long iCnt;
long long iSum;

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

	cin >> N;
	cin >> M;

	iSum = 0;
	iCnt = 0;
	for( i = 1; i <= N; i++ )
	{
		cin >> A;

		iSum += A;
		iSum %= M;
		S[ i ] = iSum;
	}

	sort( S, S + ( N + 1 ) );

	x = 0;
	for( i = 1; i <= N; i++ )
	{
		if( S[ i - 1 ] == S[ i ] )
			x++;
		else
		{
			iCnt += ( x + 1 ) * x / 2;
			x = 0;
		}
	}

	if( x > 0 ) iCnt += ( x + 1 ) * x / 2;

	cout << iCnt << endl;

	return 0;
}






Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <algorithm>

struct Point{
	double x,y;
};

int main(){

	Point point[1001];
	point[2].x = 1.0;
	point[2].y = 1.0;

	double degree,pre_slope,next_slope;

	pre_slope = sqrt(2);

	for(int i = 3; i <= 1000; i++){
		next_slope = sqrt(pre_slope*pre_slope+1);
		degree = acos((pre_slope*pre_slope+next_slope*next_slope-1)/(2*pre_slope*next_slope));
		point[i].x = (cos(-1*degree)*point[i-1].x-sin(-1*degree)*point[i-1].y)*(next_slope/pre_slope);
		point[i].y = (sin(-1*degree)*point[i-1].x+cos(-1*degree)*point[i-1].y)*(next_slope/pre_slope);
		pre_slope = next_slope; //
	}

	int n;

	while(true){
		scanf("%d",&n);
		if(n == -1)break;

		printf("%.2lf\n%.2lf\n",point[n].y,point[n].x);

	}

	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define int long long
#define endl "\n"

int rec(int h)
{
    if(h==1)
        return 1;
    return 1+(2*rec(h/2));    
}

int32_t main()
{
    IOS;
    
    int h;
    cin>>h;
    
    cout<<rec(h);
    
    return 0;
}

Measured memory_bytes: 256
#素因数分解した結果をリストで返す
def factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

Q = int(input())
alist = factorize( Q )
print(str(Q)+':',end='')
for a in alist:
    print( ' '+str(a), end = '')
print('')




Measured memory_bytes: 5596
#include <iostream>
using namespace std;
#define ll long long

int main () {
  int N, K;
  cin >> N >> K;
  static int white[1000][1000] = {};
  static int black[1000][1000] = {};
  ll x, y;
  char c;     
  for (ll i = 0; i < N; i++) {
    cin >> x >> y >> c;
    if ((x / K) % 2 == (y / K) % 2) {
      if (c == 'W') {
        white[y % K][x % K]++;  
      }         
      else {
        black[y % K][x % K]++;  
      }
    }
    else {
      if (c == 'W') {
        black[y % K][x % K]++;  
      }  
      else {
        white[y % K][x % K]++;  
      }
    }
  }

  // 二次元累積和だと.....?
  int sum_white[1000][1000] = {};
  int sum_black[1000][1000] = {};
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < K; j++) {
      if (i == 0) {
        if (i == 0 && j == 0) {
          sum_white[i][j] = white[i][j];
          sum_black[i][j] = black[i][j];  
        }  
        else {
          sum_white[i][j] = white[i][j] + sum_white[i][j - 1];  
          sum_black[i][j] = black[i][j] + sum_black[i][j - 1];  
        }
      }
      else {
        if (j == 0) {
          sum_white[i][j] = sum_white[i - 1][j] + white[i][j];
          sum_black[i][j] = black[i][j] + sum_black[i - 1][j];  
        }  
        else {
          sum_white[i][j] = sum_white[i - 1][j] + white[i][j] + sum_white[i][j - 1]
                          - sum_white[i - 1][j - 1];  
          sum_black[i][j] = sum_black[i - 1][j] + black[i][j] + sum_black[i][j - 1]
                          - sum_black[i - 1][j - 1];
        }
      }
    }  
  }
  /*
  for (ll i = 0; i < K; i++) {
    for (ll j = 0; j < K; j++) {
      cout << sum_white[i][j] << " ";  
    }
    cout << endl;
  }
  for (ll i = 0; i < K; i++) {
    for (ll j = 0; j < K; j++) {
      cout << sum_black[i][j] << " ";  
    }
    cout << endl;
  }
  */

  ll ans = 0;
  for (ll i = 0; i < K; i++) {
    for (ll j = 0; j < K; j++) {
      ll sub = sum_white[i][j] + (sum_black[i][K - 1] - sum_black[i][j]);
      sub = sub + (sum_black[K - 1][j] - sum_black[i][j]);
      sub = sub + (sum_white[K - 1][K - 1] - sum_white[K - 1][j] - sum_white[i][K - 1]);
      sub = sub + sum_white[i][j];
      if (ans < sub) {
        ans = sub;  
      }  
    }  
  }
  for (ll i = 0; i < K; i++) {
    for (ll j = 0; j < K; j++) {
      ll sub = sum_black[i][j] + (sum_white[i][K - 1] - sum_white[i][j]);
      sub = sub + (sum_white[K - 1][j] - sum_white[i][j]);
      sub = sub + (sum_black[K - 1][K - 1] - sum_black[K - 1][j] - sum_black[i][K - 1]);
      sub = sub + sum_black[i][j];
      if (ans < sub) {
        ans = sub;  
      }  
    }  
  }
  cout << ans << endl;
}


Measured memory_bytes: 15872
/*
	* ernestvw
	* C++
	* April 2020
	* ABC164/C
*/

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

#define int long long

#define x first
#define y second
#define pb push_back
#define pii pair<int, int>
#define veci vector<int>
#define vecs vector<string>
#define amax(x, v) x = max(x, (v))
#define amin(x, v) x = min(x, (v))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define nl '\n'

using ll = long long;
using ld = long double;
template <class T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

const int oo = 1e9; // INT_MAX
const int OO = 1e18; // LLONG_MAX
const double eps = 1e-9;

#define TEST_CASES 0

void solve(int test_case);

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

	int T = 1;
	if(TEST_CASES) cin >> T;
	for(int t = 1; t <= T; t++)
		solve(t);

	return 0;
}

// ---------------------------------------------------

set<string> s;
int n;

void solve(int test_case) {
	cin >> n;
	for(int i = 0; i < n; i++){string g;cin>>g;s.insert(g);}
	cout<<sz(s)<<endl;
}



















































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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    vector<LL> v(N);
    LL l[SIZE], r[SIZE];
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
    }

    LL x = 0;
    for(int i = 0; i < N; ++i) {
        x ^= v[i];
        l[i] = x;
    }

    x = 0;
    for(int i = N - 1; i >= 0; --i) {
        x ^= v[i];
        r[i] = x;
    }

    cout << r[1] << " ";
    for(int i = 1; i < N - 1; ++i) {
        cout << (l[i - 1] ^ r[i + 1]) << " ";
    }
    cout << l[N - 2] << endl;
    return 0;
}


Measured memory_bytes: 7912
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   int r,g,b;
   int num;
   
   cin >> r >> g >> b;
   
   //num = (10*g)+b;
   num = (100*r)+(10*g)+b;
   
   if(num%4==0)
        cout << "YES";
    else
        cout << "NO";
   
   
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int x,y;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0 && y==0)break;
        if(x>y){
            printf("%d %d\n",y,x);}
            else printf("%d %d\n",x,y);
}
return 0;
}


Measured memory_bytes: 1996
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main()
{
    int a;
    cin >> a;
    if (a >= 30) cout << "Yes";
    else cout << "No";
    //cout << a;
        cout << '\n';
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, q;
    cin >> n >> q;
    vector<pair<int, P>> v;
    for(int i = 0; i < n; ++i) {
        int s, t, x;
        cin >> s >> t >> x;
        v.pb(MP(s - x, MP(1, x)));
        v.pb(MP(t - x, MP(0, x)));

    }

    for(int i = 0; i < q; ++i) {
        int d;
        cin >> d;
        v.pb(MP(d, MP(2, i)));

    }
    sort(all(v));

    int res[SIZE];
    multiset<int> st;
    for(int i = 0; i < v.size(); ++i) {
        int x = v[i].F;
        int t = v[i].S.F;
        int val = v[i].S.S;
        if(t == 1) st.insert(val);
        if(t == 0) st.erase(st.lower_bound(val));
        if(t == 2) {
            if(st.empty()) res[val] = -1;
            else res[val] = *(st.begin());

        }
    }

    for(int i = 0; i < q; ++i) {
        cout << res[i] << endl;

    }
    return 0;
}



Measured memory_bytes: 19304
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;

class Qu{
    public:
    int l,r,d;
    Qu(int _l,int _r,int _d):l(_l), r(_r),d(_d){}
};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,m;
    cin>>n>>m;
    
    vector<vector<pair<int,int>>> graph(n+1);
    
    vector<Qu> vq;
    
    for(int i=0; i<m; i++){
        int l,r,d;
        cin>>l>>r>>d;
        vq.push_back(Qu(l,r,d));
        graph[l].push_back({r,d});
        graph[r].push_back({l,-d});
    }
    
    vector<int> pos(n+1,-MOD);
    
    
    for(int i=1; i<=n; i++){
        //cout<<i<<" "<<pos[i]<<endl;
        if(pos[i]==-MOD){
            pos[i]=0;
            queue<int> q;
            q.push(i);
            while(q.size()){
                int cur=q.front();
                //cout<<cur<<endl;
                q.pop();
                for(auto p:graph[cur]){
                    if(pos[p.first]==-MOD){
                        pos[p.first]=pos[cur]+p.second;
                        q.push(p.first);
                    }
                }
            }
        }
    }
    
    for(auto q:vq){
        if(pos[q.r] != pos[q.l] +q.d){
            cout<<"No";
            return 0;
        }
    }/*
    
    for(int i=1; i<=n; i++){
        cout<<pos[i]<<endl;
    }
  */  
    cout<<"Yes";
    
    
    
   
    
    return 0;
}

Measured memory_bytes: 11824
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

int main()
{
    int N, W = 0, B = 0;
    string S;
    cin >> N >> S;

    for (int i = 0; i < N; i++) {
        if (S[i] == '.') W++;
    }
    ll min = W;
    for (int i = 0; i < N; i++) {
		if (S[i] == '.')W--;
		if (S[i] == '#')B++;
		if (min > (W + B)) {
			min = (W + B);
		}
	}
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 640
def has8(x):
    count = 0
    for i in range(1,x+1):
        if x%i == 0:
            count += 1
    if count == 8:
        return True
    else:
        return False

n = int(input())
ans = 0
for i in range(1,n+1):
    if i%2==1 and has8(i):
        ans += 1
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
/*
string S_str[H];
cins(S_str, S_str + H);
S_str[i][j];
*/
inline int at(ll x, int k){ return (x >> k) & 1; }
#define rep(i, n) for(int i = 0; i < n; i++)


int main(){
  ll x;
  ll ans=0;
  cin >> x;
  while(x>=500){
    x -= 500;
    ans += 1000;
  }
  while(x>=5){
    x -= 5;
    ans += 5;
  }
  cout << ans << endl;
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

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

    int N;
    cin >> N;
    vector<ll> d(N);

    REP(i, N) cin >> d[i];

    for(int i = N - 2; 0 <= i; i--) if(i != N - 1) d.push_back(d[i]);


    ll maxDist = 0;

    REP(i, d.size())
    {
        if(i * 10 <= maxDist)
        {
            maxDist = max(maxDist, d[i] + i * 10);
        }
    }

    cout << (10 * (d.size() - 1) <= maxDist ? "yes" : "no") << endl;

    return 0;
}


Measured memory_bytes: 7584
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

constexpr int INF = 1 << 29;

int N, K, arr[101010];

vector<vector<int>> graph;

pair<int, int> search(int v) {
    int perge_count = 0, max_dist = 1;
    for (const int w: graph[v]) {
        auto p = search(w);
        perge_count += p.first;
        if (v != 0 && p.second == K) {
            ++perge_count;
            continue;
        }
        max_dist = max(max_dist, p.second+1);
    }
    return make_pair(perge_count, max_dist);
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K;
    for (int j = 0; j < N; ++j) {
        cin >> arr[j];
        --arr[j];
    }

    int offset = 0;
    if (arr[0] != 0) {
        ++offset;
        arr[0] = 0;
    }

    graph.resize(N);
    for (int j = 1; j < N; ++j) {
        graph[arr[j]].push_back(j);
    }

    queue<pair<int, int>> qq;
    vector<int> dist(N, INF);
    dist[0] = 0;
    qq.emplace(0, 0);
    int lx = 0;
    while (!qq.empty()) {
        auto p = qq.front(); qq.pop();
        int v = p.first, d = p.second;
        for (int w: graph[v]) {
            lx = dist[w] = d+1;
            qq.emplace(w, d+1);
        }
    }

    auto result = search(0);
    cout << offset + result.first << endl;

    return 0;
}


Measured memory_bytes: 11264
<?php
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%s", $T);
$len = strlen($S);
$arrS = str_split($S);
$arrT = str_split($T);
$sumS = array();
$sumT = array();
$curS = 0;
$curT = 0;
$noFlg = false;
for ($i = 0; $i < $len; $i++) {
    $searchS = array_search($arrS[$i], $sumS);
    if ($searchS === false) {
        $curS++;
        $sumS[] = $arrS[$i];
    }
    $searchT = array_search($arrT[$i], $sumT);
    if ($searchT === false) {
        $curT++;
        $sumT[] = $arrT[$i];
    }
    if ($searchS === false) {
        if ($curS === $curT) {

        } else {
            $noFlg = true;
        }
    } else {
        if ($searchS === $searchT) {

        } else {
            $noFlg = true;
        }
    }
}
echo $noFlg ? "No" : "Yes";


Measured memory_bytes: 33272
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct { int parent, left, right;} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL)
    h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL)
    h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int main(void) {
  int c=0, v, l, r, root = 0;
  scanf("%d",&n);
  for(int i=0;i<n;i++) T[i].parent = NIL;
  for(int i=0;i<n;i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].left  = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }

  for(int i=0; i<n; i++)
  if(T[i].parent == NIL) root = i;

  setDepth(root,0);
  setHeight(root);

  for(int i=0;i<n;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].parent);

    if( T[i].parent == NIL ){
      printf("sibling = %d, ",NIL);
      c++;
    }
  else if(T[T[i].parent].left != i && T[T[i].parent].left != NIL ){
    printf("sibling = %d, ",T[T[i].parent].left);
    c++;
  }
    else if(T[T[i].parent].right != i && T[T[i].parent].right != NIL ){
      printf("sibling = %d, ",T[T[i].parent].right);
      c++;
    }
  else {
    printf("sibling = %d, ",NIL);
  }
    int deg = 0;
    if(T[i].left  != NIL) deg++;
    if(T[i].right != NIL) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[i]);
    printf("height = %d, ",H[i]);

    if(T[i].parent == NIL) {
      printf("root\n");
    } else if(T[i].left == NIL && T[i].right == NIL) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2112
a=input()
b=[]
last="R"
cnt=1
for i in range(1,len(a)):
    if last!=a[i]:
        b.append(cnt)
        cnt=1
        last=a[i]
    else:
        cnt+=1
b.append(cnt)


for i in range(0,len(b),2):
    c=b[i]//2
    d=b[i+1]//2
    b[i]=b[i]-c+d
    b[i+1]=b[i+1]+c-d


my_bool=True
cnt=0
c=[0 for i in range(len(a))]
c[0]=0
for i in range(1,len(a)):
    if my_bool:
        if a[i]=="L":
            c[i-1]=b[cnt]
            cnt+=1
            c[i]=b[cnt]
            cnt+=1
            my_bool=False
        else:
            c[i]=0
    else:
        if a[i-1]=="L" and a[i]=="R":
            my_bool=True
            my_bool_2=True
        c[i]=0

if cnt!=len(b) and a[-2]=="R" and a[-1]=="L":
    c[-2]=b[cnt]
    c[-1]=b[cnt+1]

#print(*a)
print(*c)

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


void solve() {
  int N;
  scanf("%d", &N);
  pair<pair<string, int>, int> p[110];
  char in[20];
  int t;

  rep(i, N) {
    scanf("%s%d", in, &t);
    p[i] = make_pair(make_pair(in, -t), i+1);
  }
  sort(p, p+N);
  rep(i, N) {
    printf("%d\n", p[i].second);
  }

}

int main() {
  solve();
  return 0;
}


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

int main( int argc, char *argv[] )
{
int iCnt;
long long X;
long long Y;

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

	cin >> X;
	cin >> Y;

	iCnt = 0;
	while( X <= Y )
	{
		X *= 2;
		iCnt++;
	}

	cout << iCnt << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1e9+7;
// const ll INF = 1000000000000000000LL;
 
 
 int main() {
	 int n;
	 cin >> n;
	 vector<int> x(n);
	 rep(i,n) cin >> x[i];
	 int nin = INF;
	 for(int i=1;i<=100;i++){
		 int cur=0;
		 rep(j,n){
			 cur += pow(x[j]-i,2);
		 }
		 nin = min(cur,nin);
	 }
	 cout << nin << endl;
	 return 0;
 }


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int N;
vector<int> graph[222];
int indeg[222];

int dp[222][222];
int dp2[222][222][222];
int sz[222];

int dp3[2][222];

int dfs(int u) {
  sz[u] = 1;

  if(graph[u].empty()) {
    dp[u][1] = 1;
    return sz[u];
  }

  for(int v : graph[u]) sz[u] += dfs(v);

  memset(dp3, 0, sizeof(dp3));
  int *curr = dp3[0];
  int *next = dp3[1];
  int ch = graph[u][0];
  rep(i, sz[ch]+1) curr[i] = dp[ch][i] % mod;
  for(int v : graph[u]) {
    if(v == ch) continue;
    rep(j, 222) next[j] = 0;
    rep(j, sz[u]) rep(k, sz[u]) rep(l, sz[v]+1) {
      (next[j] += curr[k]%mod*dp[v][l]%mod*dp2[k][l][j]%mod) %= mod;
    }
    swap(next, curr);
  }

  rep(i, sz[u]) dp[u][i+1] = curr[i];

  return sz[u];
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  memset(dp2, 0, sizeof(dp2));
  dp2[0][0][0] = 1;
  rep(i, 201) rep(j, 201) rep(k, 201) {
    (dp2[i+1][j][k+1] += dp2[i][j][k]) %= mod;
    (dp2[i][j+1][k+1] += dp2[i][j][k]) %= mod;
    (dp2[i+1][j+1][k+1] += dp2[i][j][k]) %= mod;
  }
  /*
  rep(i, 10) {
    rep(j, 10) cout << " " << dp2[0][i][j];
    cout << endl;
  }
  */
  memset(indeg, 0, sizeof(indeg));
  cin >> N;
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    indeg[b]++;
  }

  int root = -1;
  rep(i, N) if(!indeg[i]) root = i;

  memset(dp, 0, sizeof(dp));
  memset(sz, 0, sizeof(sz));
  dfs(root);

  int ans = 0;
  rep(i, N+1) (ans += dp[root][i]) %= mod;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 89040
object Main {
  def main(args: Array[String]): Unit = {
    val str = io.StdIn.readLine().toArray
    val q = io.StdIn.readInt()
    for (_ <- 0 until q) {
      val line = io.StdIn.readLine().split(" ")
      Operation(line).run(str)
    }
  }

  sealed trait Operation {
    def a: Int
    def b: Int
    def run(str: Array[Char]): Unit = this match {
      case Replace(a, b, r) =>
        r.zip(a to b).foreach { case (c, i) => str(i) = c }
      case Reverse(a, b) =>
        (0 to (b - a) / 2).foreach { i =>
          val buf = str(b - i)
          str(b - i) = str(a + i)
          str(a + i) = buf
        }
      case Print(a, b) =>
        println(str.subSequence(a, b + 1))
    }
  }
  object Operation {
    def apply(values: Array[String]): Operation = values match {
      case Array("replace", a, b, r) => Replace(a.toInt, b.toInt, r)
      case Array("reverse", a, b) => Reverse(a.toInt, b.toInt)
      case _ => Print(values(1).toInt, values(2).toInt)
    }
  }

  case class Replace(a: Int, b: Int, replacement: String) extends Operation
  case class Reverse(a: Int, b: Int) extends Operation
  case class Print(a: Int, b: Int) extends Operation
}

Measured memory_bytes: 45132
n, k = map(int, input().split())
a = list(map(int, input().split()))
x = [1]
y = set()
y.add(1)
index = 0
for i in range(n):
    next_index = a[index]
    x.append(next_index)
    y.add(next_index)
    index = next_index - 1
    if len(x) != len(y):
        second = i
        target = next_index
        break
index = 0
for i in range(n):
    next_index = a[index]
    index = next_index - 1
    if next_index == target:
        first = i
        break

num = second - first
if num == 0:
    first = -1
    num = second - first

if first > k:
    print(x[k])
    exit()

k -= (first + 1)
k %= (second - first)
print(x[first+1+k])



Measured memory_bytes: 32456
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int power(int x, unsigned int y, unsigned int m) 
    { 
        if (y == 0) 
            return 1; 
        int p = power(x, y/2, m) % m; 
        p = (p * p) % m; 
      
        return (y%2 == 0)? p : (x * p) % m; 
    } 
int find(int n,int r){
	n++;r++;
	int ans=1;
	int res=1;
	for(int i=1;i<=r;i++){
		ans*=(n+r-i+1);
		res*=i;
		ans%=M;
		res%=M;
	}
	return (ans*power(res,M-2,M))%M;
}
int solve(){


	// int n,m;cin>>n>>m;
	int r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;
	int ans=find(r2 , c2) - find(r2 , c1 - 1) - find(r1 - 1 , c2)  + find(r1 - 1 , c1 - 1);
	ans+=2*M;
	ans%=M;
	cout<<ans<<endl;

    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;




int main(){
    int n;
    int m;
    cin >> n >> m;
    int sum = 0;
    rep(i,m){
        int a;
        cin >> a;
        sum += a;
    }
    if (sum>n){
        cout << -1;
    }
    else{
        cout << n-sum;
    }
    
}









Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;


int main(){
    string s, t;
    cin >> s >> t;

    int ans = 0;
    if (s[0] == t[0]) ans++;
    if (s[1] == t[1]) ans++;
    if (s[2] == t[2]) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx;
  int dy = ty - sy;
  for (int i = 0; i < dx; i++)
    cout << "R";
  for (int i = 0; i < dy; i++)
    cout << "U";
  for (int i = 0; i < dx; i++)
    cout << "L";
  for (int i = 0; i < dy; i++)
    cout << "D";
  cout << "L";
  for (int i = 0; i < dy + 1; i++)
    cout << "U";
  for (int i = 0; i < dx + 1; i++)
    cout << "R";
  cout << "D";
  cout << "R";
  for (int i = 0; i < dy + 1; i++)
    cout << "D";
  for (int i = 0; i < dx + 1; i++)
    cout << "L";
  cout << "U" << endl;
}

Measured memory_bytes: 256