akhauriyash/Code-Regression huggingface dataset:
def solve():
    N = int(input())
    S = list(input())
    right = [set() for _ in range(N)]
    for i in reversed(range(N - 1)): right[i] = right[i + 1] | {S[i + 1]}
    left = {S[0]}
    PIN = set()
    for i in range(1, N - 1):
        for ln in left:
            for rn in right[i]:
                p = ln + S[i] + rn
                PIN |= {p}
        left |= {S[i]}
    print(len(PIN))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 25716
module Main where

import Data.Functor

main :: IO ()
main =  do
 { nx@[n,x] <- getInts
 ; if nx == [0,0] then done
   else do print $ sum [ 1 | a <- [1..n], b <- [a+1 .. n], c <- [b+1 .. n], x == a+b+c ]
           main
 }

done :: IO ()
done = return ()

getInts :: IO [Int]
getInts = map read . words <$> getLine

Measured memory_bytes: 5020
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(a, b, h, m) = in.readLine().split("\\s+").map(_.toInt)

    val theta1 = 2.0 * Math.PI * (h + m / 60.0) / 12.0
    val theta2 = 2.0 * Math.PI * m / 60.0

    out.println(
      Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(theta1 - theta2))
    )

    out.flush()
  }
}


Measured memory_bytes: 54716
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int main() {
	long long n, l;
	cin >> n;
	map<long long,long long> m;
	vector<long long> v;
	for (long long i = 0; i < n; i++) {
		cin >> l;
		m[l]++;
		if (m[l] % 2 == 0) v.push_back(l);
	}
	sort(v.begin(), v.end());
	long long s;
	if (v.size() < 2) s = 0;
	else s = v[v.size() - 2] * v[v.size() - 1];
	cout << s << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<cstdio>
using namespace std;
long long n,a,b;
long long x[100010];
void read(long long &x)
{
	int ch;
	ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
}
int main()
{
	read(n);read(a);read(b);
	long long ans=0;
	read(x[1]);
	for(int i=2;i<=n;i++)
	{
		read(x[i]);
		if((x[i]-x[i-1])*a>b) ans+=b;
		else ans+=(x[i]-x[i-1])*a;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

long long TwelvefoldWay8(long long n,long long k,long long MOD){
  return (n <= k ? 1 : 0);
}

signed main(){
  ll n,k;
  cin >> n >> k;
  cout << TwelvefoldWay8(n,k,INF) << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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 long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]) {
    ll k, a, b;
    cin >> k >> a >> b;
    if(a<=(b/k)*k){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    return 0;
}


Measured memory_bytes: 3588
mod = int(1e9) + 7


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y//2)**2 % mod
    else:
        return power(x, y//2)**2 * x % mod


fact = [1] * int(1e5+2)
for i in range(1, int(1e5+2)):
    fact[i] = (i * fact[i-1]) % mod
inv = [1] * int(1e5+2)
inv[int(1e5+1)] = power(fact[int(1e5+1)], mod-2) % mod
for i in range(int(1e5), 0, -1):
    inv[i] = (inv[i+1] * (i+1)) % mod


def combination(n, r):
    return fact[n] * inv[r] * inv[n-r] % mod


def main():
    N = int(input())
    A = list(map(int, input().split()))
    idx = [-1] * (N+1)
    x = 0
    for i in range(N+1):
        if idx[A[i]] == -1:
            idx[A[i]] = i
        else:
            x = i - idx[A[i]]
    for i in range(1, N+2):
        ans = combination(N+1, i)
        if i <= (N+1-x):
            ans = (ans - combination(N+1-(x+1), i-1)) % mod
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 71116
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = 0;
    rep(i, 0, n){
        cin >> a[i];
        ans += a[i] - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    cout << 6 - a -b;
    
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  unsigned int n,a,x=0,ans=0;
  map<int,bool> ib;
  cin>>n;
  fr(i,n){
    cin>>a;
    x^=a;
    ib[a-(a&(a-1))]=1;
  }
  ifr(i,32){
    if(ib[1<<i]&&((x>>i)&1)){
      ans++;
      x^=(1<<(i+1))-1;
    }
  }
  cout<<(x?-1ll:ans)<<endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    rep(i, T.size()) {
        if (T[i] != '?') continue;
        T[i] = 'D';
    }

    cout << T << endl;
}

Measured memory_bytes: 3748
def solve(c1, c2, c3):
    if (c1[0] + c2[1] + c3[2]) * 3 == sum(c1) + sum(c2) + sum(c3):
        return "Yes"
    return "No"


if __name__ == "__main__":
    c1 = list(map(int, input().split(" ")))
    c2 = list(map(int, input().split(" ")))
    c3 = list(map(int, input().split(" ")))
    print(solve(c1, c2, c3))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,l,r,s=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>l>>r;
		s=s+r-l+1;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
using ll = long long;
int main() {
    ll n, l, r;
    while(cin >> n >> l >> r, n) {
        vector<ll> A(n);
        for(auto &x:A) cin >> x;
        auto uruu = [&]() {
            ll ctr = 0;
            for(int i = l; i <= r; i++) {
                int j = 0;
                while(j < n && i % A[j] != 0) j++;
                ctr += (j % 2 == 0);
            }
            return ctr;
        };
        cout << uruu() << endl;
    }
}


Measured memory_bytes: 3092
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <string.h>

using namespace std;
#define ll long long int

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

	ll n;
	string s;
	cin>>n>>s;
	if(s.size()<=n){
		cout<<s<<endl;
	}
	else{
		for (int i = 0; i < n; ++i)
		{
			cout<<s[i];
		}
		cout<<"..."<<endl;
	}

	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

map<ll,ll> bunkai(ll n){
  map<ll,ll> m;
  for(int i=1; i*i<=n; i++){
    if(n%i==0){
      m[i]=1;
      m[n/i]=1;
    }
  }
  return m;
}

int main(){
  
  int n,m; cin>>n>>m;
  auto s = bunkai(m);
  int ans{};
  for(auto k:s){
    
    if(m%k.first==0){
      if(n<=m/k.first){
        ans = max<ll>(ans,k.first);
      }
    }
  }
  cout << ans << endl;
}

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


namespace AtCoder
{
    class Program
    {
        public static void Main()
        {
            new Program().Solve();
        }

        void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var hashSet = new HashSet<int>();
            int count = 0;
            for (int i = 0; i < n; i++)
            {
                int d = int.Parse(Console.ReadLine());
                if (hashSet.Add(d))
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13280
#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>;

ll x = 1e9 + 7; 

int main() {
  int k;
  cin >> k;
  vector<ll> x(k+5);
  int i = 1, j = 1;
  while (j <= k) {
    if (j < 10) {
      x[j] = j;
      j++;
    }
    else {
      if (x[i]%10 == 0) {
        x[j] = x[i]*10 + 0;
        j++;
        x[j] = x[i]*10 + 1;
        j++;
        i++;
      }
      else if ((x[i]-9)%10 == 0) {
        x[j] = x[i]*10 + 8;
        j++;
        x[j] = x[i]*10 + 9;
        j++;
        i++;
      }
      else {
        x[j] = x[i]*10 + x[i]%10 - 1;
        j++;
        x[j] = x[i]*10 + x[i]%10;
        j++;
        x[j] = x[i]*10 + x[i]%10 + 1;
        j++;
        i++;
      }
    }
  }
  cout << x[k] << endl;
  return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  vector<int> memo(n + 1, -1);
  for (int i = n, j = n; i >= 0; i--) {
    if (s[i] == '0') j = i;
    memo[i] = j;
  }

  vector<int> ans;
  vector<bool> visited(n + 1, 0);
  for (int i = n; i > 0;) {
    visited[i] = 1;
    int next = memo[max(0, i - m)];
    if (visited[next]) {
      cout << -1 << endl;
      return 0;
    }
    ans.eb(i - next);
    i = next;
  }

  reverse(all(ans));

  rep(i, ans.size()) cout << ans[i] << ' ';
  cout << endl;
}


Measured memory_bytes: 1528
#include <stdio.h>
#include <stdlib.h>
typedef struct{
    long price;
    long stock;
} shop;
long long MIN(long long a, long long b){
    return a<b?a:b;
}
int compare(const void *a,const void *b){
    shop tmp1= *(shop*)a;
    shop tmp2= *(shop*)b;
    long  x=tmp1.price;
    long y=tmp2.price;
    return x<y?-1:1;
}
int main()
{   int n,m;
    scanf("%d%d",&n,&m);
    shop a[n];
    for(int i=0;i<n;i++){
        scanf("%ld%ld",&a[i].price,&a[i].stock);
    }
    qsort(a,n,sizeof(shop),compare);
    
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=MIN(m,a[i].stock)*a[i].price;
        m-=MIN(m,a[i].stock);
    }
    printf("%lld",ans);

    return 0;
}


Measured memory_bytes: 3324
n,m = list(map(int,input().split()))
PY=[list(map(int,input().split()))for _ in range(m)]
id = [[]for _ in range(n)]
for a,b in PY:
    id[a-1].append(b)
for v in id:
    v.sort()
d = {}
for i in range(n):
    k=1
    for j in range(len(id[i])):
        d[id[i][j]] = k
        k+=1
for i,j in PY:
    print("{:06g}{:06g}".format(i,d[j]))

Measured memory_bytes: 47404
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int m = ni();
    int[][] p = new int[m][4];
    for (int i = 0; i < m; i ++) {
      p[i][0] = i;
      p[i][1] = ni();
      p[i][2] = ni();
    }
    
    Arrays.sort(p, (o1, o2) -> o1[1] == o2[1] ? o1[2] - o2[2] : o1[1] - o2[1]);
    
    int np = p[0][1];
    int cnt = 1;
    for (int[] v : p) {
      if (np == v[1]) {
        v[3] = cnt ++;
      } else {
        cnt = 2;
        v[3] = 1;
        np = v[1];
      }
    }
    Arrays.sort(p, (o1, o2) -> o1[0] - o2[0]);
    for (int[] v: p) {
      out.println(String.format("%06d%06d", v[1], v[3]));
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

bool dfs(int u, int d, vector<vector<pair<int, int>>>& adj,
         vector<int>& dist, vector<int>& seen)
{
  if (d > INF) { return false; }
  seen[u] = 1;
  dist[u] = d;
  for (pair<int, int> p : adj[u]) {
    int v = p.first, c = p.second;
    if (seen[v]) {
      if (d + c != dist[v]) { return false; }
    }
    else {
      if (not dfs(v, d + c, adj, dist, seen)) {
        return false;
      }
    }
  }
  return true;
}

int main()
{
  int N, M; scanf("%d %d", &N, &M);
  vector<vector<pair<int, int>>> adj(N + 5);
  int l, r, d;
  for (int i = 0; i < M; ++i) {
    scanf("%d %d %d", &l, &r, &d);
    adj[l].push_back(make_pair(r, d));
    adj[r].push_back(make_pair(l, -d));
  }

  vector<int> seen(N + 5, 0), dist(N + 5, -1);
  bool ok = true;
  for (int u = 1; u <= N; ++u) {
    if (seen[u]) { continue; }
    if (not dfs(u, 0, adj, dist, seen)) {
      ok = false;
      break;
    }
  }
  printf("%s\n", ok ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 13312
n = int(input())
D_1 = []
D_2 = []
for _ in range(n):
    d_1, d_2 = map(int, input().split())
    D_1.append(d_1)
    D_2.append(d_2)
cnt = 0
for i in range(n-2):
    if D_1[i] == D_2[i] and D_1[i+1] == D_2[i+1] and D_1[i+2] == D_2[i+2]:
        cnt = 1
        break

if cnt == 0:
    print('No')
elif cnt == 1:
    print('Yes')

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

int h[110];

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

    int n;cin>>n;

    for(int i=0;i<n;i++)cin>>h[i];

    int ans=0;

    for(;;)
    {
        int cnt=0;
        bool zero=true;
        for(int i=0;i<n;i++)
        {
            if(zero)
            {
                if(h[i]>0)
                {
                    cnt++;
                    zero=false;
                }
            }
            else
            {
                if(h[i]<=0)zero=true;
            }    
        }
        if(cnt==0)break;
        ans+=cnt;
        for(int i=0;i<n;i++)h[i]=max(h[i]-1,0);
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>K>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++){
    B.at(i)=A.at(i+1)-A.at(i);
  }
  B.push_back(K-A.at(N-1)+A.at(0));
  sort(B.begin(),B.end());
  cout<<K-B.at(N-1)<<endl;
}


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
const int MAX = 510000;
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() {
	ll n,k;
	cin>>n>>k;
    COMinit();

    // 計算例
  //  cout << COM(100000, 50000) << endl;	
	for(ll i=0;i<k;i++){
		if(i+1>n-k+1){
			cout << 0<<endl;
			continue;
		}
		ll cnt=COM(n-k+1,i+1);
		cnt*=COM(k-1,i);
		cnt%=inf;
		cout << cnt<<endl;;
	}
	// your code goes here
	return 0;
}

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

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

using namespace std;

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

int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a != b && a != c)
    {
        cout << a << endl;
    }
    else if (b != a && b != c)
    {
        cout << b << endl;
    }
    else
    {
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int,input().split()))
X.insert(0,0)
k = N//2
Y = sorted(X)
x0 = Y[N//2]
x1 = Y[N//2+1]
for i in range(1,N+1):
    if X[i]>x0:
        print(x0)
    else:
        print(x1)

Measured memory_bytes: 93780
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  int n;
  cin >> n;
  string s;
  unordered_map<char, ll> cnt;
  rep(i, 0, n) {
    cin >> s;
    cnt[s[0]]++;
  }

  ll all = 0;
  char c[5]{'M', 'A', 'R', 'C', 'H'};
  rep(i, 0, 5) rep(j, i + 1, 5) rep(k, j + 1, 5) all +=
    cnt[c[i]] * cnt[c[j]] * cnt[c[k]];
  cout << all << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int maxm = 22;
vector<int>E[maxn];
vector<long long>V[maxn];
long long dis[maxn];
int deep[maxn],lca[maxn][maxm];
void dfs(int x,int f){
    for(int i=0;i<E[x].size();i++){
        int v = E[x][i];
        if(v==f)continue;
        deep[v]=deep[x]+1;
        lca[v][0]=x;
        for(int j=1;j<maxm;j++){
            int fa = lca[v][j-1];
            if(fa==0)continue;
            lca[v][j]=lca[fa][j-1];
        }
        dis[v]=dis[x]+V[x][i];
        dfs(v,x);
    }
}
int up(int x,int d)
{
    for(int i=maxm-1;i>=0;i--)
    {
        if(d<(1<<i))continue;
        x=lca[x][i];
        d-=(1<<i);
    }
    return x;
}
int Lca(int x,int y)
{
    if(deep[x]>deep[y])swap(x,y);
    y=up(y,deep[y]-deep[x]);
    if(x==y)return x;
    for(int i=maxm-1;i>=0;i--)
    {
        if(lca[x][i]!=lca[y][i])
            x=lca[x][i],y=lca[y][i];
    }
    return lca[x][0];
}
long long getdis(int a,int b){
    return dis[a]+dis[b]-2*dis[Lca(a,b)];
}
int main(){
    int n;cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        long long c;
        scanf("%d%d",&a,&b);
        cin>>c;
        E[a].push_back(b);
        E[b].push_back(a);
        V[a].push_back(c);
        V[b].push_back(c);
    }
    dfs(1,0);
    int q,k;
    scanf("%d%d",&q,&k);
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        cout<<getdis(a,k)+getdis(k,b)<<endl;
    }
}


Measured memory_bytes: 30336
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int nn=n,s=0;
	while(nn!=0)
	{
		s+=nn%10;
		nn/=10;
	}
	if(n%s==0)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

ll n, W, w[110], v[110];
ll dp[110][1100][110];

int main() {
	cin >> n >> W;
	REP(i, n) {
		cin >> w[i] >> v[i];
	}
	REP(i, n) {
		REP(j, n * 3 + 1) {
			FOR(k, 1, i + 2) {
				if (j - (w[i] - w[0]) >= 0) {
					dp[i + 1][j][k]
						= max(dp[i + 1][j][k], dp[i][j - (w[i] - w[0])][k - 1] + v[i]);
				}
				dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
			}
		}
	}
	ll ans = 0;
	REP(i, n + 1) {
		REP(j, 3 * n + 1) {
			FOR(k, 1, i + 2) {
				if (j + k*w[0] <= W) {
					ans = max(ans, dp[i][j][k]);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 94976
#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<string,int>mymap;
vector<string> v;
int mx ;
 main()
{
    int n;
    cin>>n;
    for(int i =0; i<n; i++) {
        string s;
        cin>>s;
        mymap[s]++;
        mx = max(mx,mymap[s]);
    }
    for(auto it = mymap.begin(); it!=mymap.end(); it++) {
        if(it->second == mx)v.push_back(it->first);
    }
    sort(v.begin(),v.end());
    for(auto j:v)
        cout<<j<<endl;

    return 0;
}


Measured memory_bytes: 26868
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i64 sum = 0;
  i32 min = 1000000000;
  i32 neg = 0;
  for (i32 i = 0; i < n; ++i) {
    i32 a;
    scanf ("%" SCNi32, &a);
    if (a < 0) {
      neg++;
    }
    i32 v = ABS(a);
    sum += v;
    min = MIN(min, v);
  }
  if (neg % 2 == 1) {
    sum -= 2 * min;
  }
  printf ("%" PRIi64 "\n", sum);
}

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


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

int main()
{
    long long X;
    cin >> X;

    long long Y[120];
    for (int i = 0; i < 120; i++) {
        Y[i] = pow(i, 5);
    }

    for (int i = 119; i >= 0; i--) {
        for (int j = 119; j >= 0; j--) {
            if (Y[i] - Y[j] == X) {
                cout << i << " " << j << endl;
                return 0;
            }
            else if (Y[i] - (Y[j] * -1) == X) {
                cout << i << " " << j * -1 << endl;
                return 0;
            }
            else if ((Y[i] * -1) - (Y[j] * -1) == X) {
                cout << i * -1 << " " << j << endl;
                return 0;
            }
        }
    }
}

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

using namespace std;

int main(void){
  std::ios_base::sync_with_stdio(false);
  map<long long, long long> s;
  long long ans = 0;
  long long N;
  cin >> N;
  for(long long i = 1; i <= N; i++){
    long long A;
    cin >> A;
    if(s.find(i - A) != s.end()) ans += s[i - A];
    s[i + A]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 16072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}
const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

LL dp[105][64];

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N; cin >> N;
    REP(i,64)
    {
        dp[3][i] = 1;
    }
    dp[3][9] = 0;
    dp[3][6] = 0;
    dp[3][33] = 0;

    FOR(i,4,N+1)
    {
        REP(j,64)
        {
            if(j == 9 || j == 6 || j == 33) continue;
            int start = j / 4;
            dp[i][j] = dp[i-1][start] + dp[i-1][start+16] + dp[i-1][start+32] + dp[i-1][start+48];
        }
        //dp[i][0] = dp[i-1][0] + dp[i-1][16] + dp[i-1][32] + dp[i-1][48];
        //dp[i][1] = dp[i-1][0] + dp[i-1][16] + dp[i-1][32] + dp[i-1][48];
        //dp[i][2] = dp[i-1][0] + dp[i-1][16] + dp[i-1][32] + dp[i-1][48];
        //dp[i][3] = dp[i-1][0] + dp[i-1][16] + dp[i-1][32] + dp[i-1][48];
//
        //dp[i][4] = dp[i-1][1] + dp[i-1][17] + dp[i-1][33] + dp[i-1][49];
        //dp[i][5] = dp[i-1][1] + dp[i-1][17] + dp[i-1][33] + dp[i-1][49];
        //dp[i][6] = dp[i-1][1] + dp[i-1][17] + dp[i-1][33] + dp[i-1][49];
        //dp[i][7] = dp[i-1][1] + dp[i-1][17] + dp[i-1][33] + dp[i-1][49];

        //dp[i][9] = 0;
        //dp[i][6] = 0;
        //dp[i][33] = 0;

        dp[i][57] -= dp[i-1][14]; //TGC
        dp[i][41] -= dp[i-1][10]; //GGC
        dp[i][45] -= dp[i-1][11];

        REP(j,64)
        {
            dp[i][j] = dp[i][j] % MOD;
        }
    }
    LL ans = 0;
    REP(i,64)
    {
        ans = (ans + dp[N][i]) % MOD;
    }
    cout << ans << endl;



}


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

int main()
{
	int N, B[120] = { 0 }, A[120] = { 0 },sum=0;
	cin >> N;
	for (int i = 0; i < N-1; i++)
	{
		cin >> B[i];
	}

	A[0] = B[0];
	A[1] = B[0];

	for (int i = 1; i < N-1; i++)
	{
		if (B[i]>=B[i-1])
		{
			A[i + 1] = B[i];
		}
		else
		{
			A[i] = B[i];
			A[i + 1] = B[i];
		}

	}
	for (int i = 0; i < N; i++)
	{
		sum += A[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;

// グローバル変数


// 関数：


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int S; cin >> S;
	int x2 = 1000000000;
	int y2 = 1;
	int x3 = (x2 - S % x2) % x2;
	int y3 = (S + x3) / x2;
	cout << 0 << ' ' <<  0 << ' ' << x2 << ' ' << y2 << ' ' << x3 << ' ' << y3 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define llint long long
#define inf 1e18

using namespace std;

llint n, k;

llint calc(llint n)
{
	if(n == 1) return 0;
	
	llint res = calc(n-1);
	llint ub = (llint)1e18+7, lb = 0, mid;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(mid - (mid+k-1)/k <= res) lb = mid;
		else ub = mid;
	}
	return lb;
}

int main(void)
{
	cin >> n >> k;
	cout << calc(n) << endl;
	
	return 0;
}


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

int main(){
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  double s = w * h / 2.0;
  if (x==w/2.0&&y==h/2.0){
    cout << s << " " << 1 << endl;
    return 0;
  }else{
    cout << s << " " << 0 << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>

using ll = long long;

ll A, B, C, K;
ll ans;

int main() {
    std::cin >> A >> B >> C >> K;
    ans = (K%2) ? B-A : A-B;
    if ( std::abs(ans) > (long) 1e18 ) {
        std::cout << "Unfair" << std::endl;
    } else {
        std::cout << ans << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
s = input()
k = int(input())

x = ['a', 'b', 'ab', 'ba', 'aba']
a=[]
m = min(s)
for i in range(len(s)):
    a.append(s[i])
    a.append(s[i:min(len(s),i+2)])
    a.append(s[i:min(len(s),i+3)])
    a.append(s[i:min(len(s),i+4)])
    a.append(s[i:min(len(s),i+5)])
a=list(set(a))
a.sort()
if a[0]=='':
    a=a[1:]
print(a[k-1])

Measured memory_bytes: 5052
def cross(ux, uy, vx, vy):
    return ux*vy - uy*vx


n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]
points.append(points[0])
points.append(points[1])

is_convex = True
for i in range(n):
    x1, y1 = points[i]
    x2, y2 = points[i + 1]
    x3, y3 = points[i + 2]
    if cross(x2 - x1, y2 - y1, x3 - x1, y3 - y1) < 0:
        is_convex = False
        break

print(1 if is_convex else 0)



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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

string s;
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> s;
	for(int i=1; i<s.length(); i++){
		if(s[i] == s[i-1]) return 0*puts("Bad");
	}
	puts("Good");
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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

lli gcd2(lli x, lli y)
{
    lli t;
    while (y != 0)
        t = x % y, x = y, y = t;
    return (x);
}

lli lcm2(lli x, lli y)
{
    lli xy = x * y;
    if (xy < 0)
        xy = -xy;
    return (xy / gcd2(x, y));
}

int main(void)
{
    lli a, b, c, d;
    cin >> a >> b >> c >> d;
    lli lcmcd = lcm2(c, d);
    lli numB = b - (lli)(b / c) - (lli)(b / d) + (lli)(b / lcmcd);
    lli numA = (a - 1) - (lli)((a - 1) / c) - (lli)((a - 1) / d) + (lli)((a - 1) / lcmcd);
    //lli numA = (a - 1) - (lli)((a - 1) / c) - (lli)((a - 1) / d) + (lli)((a - 1) / lcmcd));
    //n(9) = 7
    //40/6= 6;
    //40/8 = 5;
    //24
    //
    //6&8 = 48;
    //40
    //n(40) = 29
    cout << numB - numA;
    return 0;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n, k;
ll a[maxn], acc[maxn];

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

  cin>>n>>k;
  for (int i=1; i<=n; i++) {
    cin>>a[i];
    acc[i]=a[i]+acc[i-1];
  }

  ll ans = 0;
  map<ll,int> cnt;

  cnt[0] = 1;
  for (int i=1; i<=n; i++) {
    if (i-k>=0) {
      ll v = (acc[i-k]-(i-k))%k;
      v = (v+k)%k;
      cnt[v]--;
    }
    ll v = (acc[i]-i+k)%k;
    v = (v+k)%k;    
    ans += cnt[v];
    cnt[v]++;
  }

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


Measured memory_bytes: 19968
from itertools import permutations

x = [int(input()) for i in range(5)]

min_time = 99999999999999
for xs in list(permutations(x)):
  total = 0
  for i in range(5):
    if i != 4:
      hoge = xs[i] // 10 if xs[i] % 10 == 0 else xs[i] // 10 + 1
      total += hoge * 10
      
    else:
      total += xs[i]
      
  min_time = min(total, min_time)
print(min_time)




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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int x;
  cin >> x;
  cout << (x == 3 || x == 5 || x==7 ? "YES" : "NO") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)

using namespace std;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

ll solve(ll h, ll w) {
  ll mn = h*w;
  FOR(i,1,h) {
    ll h1 = i;
    ll s1 = h1*w;
    ll hr = h-i;
    {
      ll h2 = hr/2;
      ll s2 = h2*w;
      ll h3 = hr-h2;
      ll s3 = h3*w;
      mn = min(mn, max({s1, s2, s3}) - min({s1, s2, s3}));
    }
    {
      ll w2 = w/2;
      ll s2 = hr*w2;
      ll w3 = w-w2;
      ll s3 = hr*w3;
      mn = min(mn, max({s1, s2, s3}) - min({s1, s2, s3}));
    }
  }
  return mn;
}

int main()
{
  ll h,w;
  cin>>h>>w;
  cout<<min(solve(h,w),solve(w,h))<<endl;
  return 0;
}


Measured memory_bytes: 256
import bisect

def main():
    s = input()
    t = input()
    sletters = [0]*26
    for i in range(len(s)):
        x = ord(s[i])-ord('a')
        if sletters[x] == 0:
            sletters[x] = [i]
        else:
            sletters[x].append(i)

    ans = 0
    curr_index = -1
    for i in t:
        x = ord(i)-ord('a')
        if sletters[x] == 0:
            print(-1)
            return
        index = bisect.bisect(sletters[x],curr_index)
        #print(sletters[x],i,curr_index,index)
        if index == len(sletters[x]):
            ans += len(s)-curr_index
            curr_index = sletters[x][0]
            ans += curr_index
        else:
            ans += sletters[x][index]-curr_index
            curr_index = sletters[x][index]
        

    print(ans)


main()


Measured memory_bytes: 45808
def main():
    import sys
    input = sys.stdin.readline
    A, B, H, M = map(int, input().split())
    import math
    cos = math.cos(2*math.pi*(60*H-11*M)/720)
    print(math.sqrt(A**2+B**2-2*A*B*cos))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9500
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
   
// g++ -std=c++11 prac.cpp

int main(){
    int d,n,x,y=0,z,m,k,w,sum=0,ans=0,Max=-1e9,Min=1e9+1;
    string s,t;
    bool count=false,ok=false;
    cin >> n >> x >> y;
    VI a(n);
    VI b(3);
    rep(i,n){
        cin >> a[i];
        if(x>=a[i])
            b[0]++;
        else  if (x<a[i] && a[i]<=y)
            b[1]++;
        else
            b[2]++;
    }
    sort(ALL(b));
    cout << b[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
ll mod = 1e9+7;
const int mxx = 1e+5;

vector<int>adj[mxx];
int n;
ll dp[mxx+1][2];

void dfs(int x, int par)
{
    for (auto u:adj[x])
    {
        //cout << u <<" " << x << endl;
        if(u == par) continue;
        dfs(u,x);
        dp[x][1]*=dp[u][0];
        if(dp[x][1] > mod) dp[x][1] %= mod;
        ll kk = dp[u][0] + dp[u][1] ;
        if(kk > mod) kk%=mod;
        dp[x][0] *= kk;
        if(dp[x][0] > mod) dp[x][0] %= mod;

    }
    //cout <<x <<" " <<dp[x][0] << endl;
}

int main()
{
  cin >> n;
  for(int i = 0; i < n-1; i++)
  {
      int x, y;
      cin >> x >> y;
      adj[x].pb(y); adj[y].pb(x);
  }
  for(int i = 0; i <= n; i++) {dp[i][0] = 1; dp[i][1] = 1;}
  //cout << dp[1][0] << endl;
  dfs(1,-1);
  cout << (dp[1][0] + dp[1][1]) % mod << endl;

}


Measured memory_bytes: 12800
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>//rand()
#define rep(i,a,b) for(register int i = (a);i <= (b);++i)
#define per(i,a,b) for(register int i = (a);i >= (b);--i)
using std::string;using std::cin;using std::cout;

const int mod = 998244353;
int hh,ll,h_,l_;
long long dp[3005][3005];

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // freopen("color.in", "r", stdin);
    cin >> hh >> ll >> h_ >> l_;
    dp[hh][ll] = 1;
    rep(i,1,h_){
        rep(j,1,l_){
            if(i < hh || j < ll || (i == hh && j == ll)) continue;
            dp[i][j] = dp[i-1][j] * j % mod + dp[i][j-1] * i % mod + mod - (i-1) * (j-1) * dp[i-1][j-1] % mod;
            dp[i][j] %= mod;
        }
    }
    cout << dp[h_][l_] << "\n";
    return 0;
}


Measured memory_bytes: 73968
#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>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    rep(i,n) cin >> s[i];
    rep(i,m) cin >> t[i];

    vector<vector<mint>> dp(2100, vector<mint>(2100));
    dp[0][0] = 1;
    rep(i,n+1) rep(j, m+1){
        if(i-1 >= 0 && j-1 >= 0 && s[i-1] == t[j-1]) dp[i][j] += dp[i-1][j-1];
        if(i-1 >= 0) dp[i][j] += dp[i-1][j];
        if(j-1 >= 0) dp[i][j] += dp[i][j-1];
        if(i-1 >= 0 && j-1 >= 0) dp[i][j] -= dp[i-1][j-1];
    }
    cout << dp[n][m] << endl;
}

Measured memory_bytes: 37840
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    int res;
    FOR(i,1,int(sqrt(m))) {
        if (m % i == 0) {
            int g = i;
            int h = m / i;
            if (g >= n) res = max(res, h);
            if (h >= n) res = max(res, g);
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD				1000000007
#define MOD1			998244353
#define EPS				1e-9
#define fore(i, b, e)	for(ll i = b; i < e; i++)
#define forg(i, b, e, m)	for(ll i = b; i < e; i+=m)
//ll in(){ll r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("asd1.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, k;
	cin>>n>>k;
	int ar[n];
	string s;
	cin>>s;
	vector<int> con;
	con.pb(0);
	char ig;
	int can  =0;
	fore(i, 0, n)
	{
		if(i == 0) ig = s[i];

		if(ig != s[i])
		{
			con.pb(can);
			ig = s[i];
			can = 1;
		}
		else
			can++;
	}
	con.pb(can);
	con.pb(0);
	int l, r;
	if(s[0] == '0')
		l = 0;
	else
		l = 1;
	int su = 0;
	fore(i, l, min((int)con.size(), 2*k+ l+1) )
		su += con[i];
	r = 2*k +((l-1)) + 1;
	int res = su;
	r+=2, l+=2;
	while(r < con.size())
	{
		su -= con[l-1] + con[l-2];
		su += con[r-1] + con[r];
		res = max(res, su);
		l += 2;
		r += 2;
	}
	cout<<res<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constralls?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs ll?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 


int main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    LL n,AC=0,WA=0,TLE=0,RE=0;
    cin >> n;
    while(n--){
      string x;
      cin >> x;
      if(x == "AC"){
        AC++;
      }else if(x == "WA"){
        WA++;
      }else if(x == "TLE"){
        TLE++;
      }else{
        RE++;
      }
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;


    cout.flush();
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define int long long
#define deb(x) cout << #x << " = " << x << "\n";
using namespace std;

signed main() {
    
    string s; cin >> s;
    if(s.back() == 's') {
        s += "es";
    } else {
        s += "s";
    }
    cout << s;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main() {
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if ((a==b && a!=c) || (a==c && a!=b) || (c==b && a!=c)) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128