akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void visit(int);
void dfs();
int n,M[N][N];
int color[N],d[N],f[N],tt;

int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
  for(j=0;j<k;j++){
    scanf("%d",&v);
    v--;
    M[u][v]=1;
  }
}
dfs();
return 0;
}

void visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==WHITE) {
      visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}
void dfs(){
  int u;
  for(u=0;u<n;u++) color[u]=WHITE;
  tt=0;

  for(u=0;u<n;u++){
    if(color[u]==WHITE)visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}


Measured memory_bytes: 2044
N = gets.to_i
abcs = (N - 1).times.map { gets.split.map(&:to_i) }
Q, K = gets.split.map(&:to_i)
xys = Q.times.map { gets.split.map(&:to_i) }

graph = Array.new(N) { [] }
abcs.each do |(a, b, c)|
  a -= 1
  b -= 1
  graph[a].push([b, c])
  graph[b].push([a, c])
end

def dijkstra(s, graph)
  d_list = Array.new(graph.size, 1 << 60)
  d_list[s] = 0
  queue = [[s, 0]]
  while !queue.empty?
    v, d = queue.shift
    next if d > d_list[v]
    graph[v].each do |(u, c)|
      if d_list[u] > d_list[v] + c
        d_list[u] = d_list[v] + c
        queue.push([u, d_list[u]])
      end
    end
  end
  d_list
end

d_list = dijkstra(K - 1, graph)
xys.each do |(x, y)|
  x -= 1
  y -= 1
  ans = d_list[x] + d_list[y]
  puts ans
end


Measured memory_bytes: 42364
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	a := nextFloat(sc)
	b := nextFloat(sc)
	c := nextFloat(sc)

	cRad := c * math.Pi / 180

	h := b * math.Sin(cRad)
	s := a * h / 2.0
	l := a + b + math.Sqrt(a*a+b*b-2*a*b*math.Cos(cRad))

	fmt.Println(s)
	fmt.Println(l)
	fmt.Println(h)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextFloat(sc *bufio.Scanner) float64 {
	i, err := strconv.ParseFloat(nextString(sc), 64)
	if err != nil {
		panic(err)
	}
	return i
}



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

int main(void) {
    int k, s, ans = 0;
    cin >> k >> s;
    for(int x = 0; x <= k; x++) {
        for(int y = 0; y <= k; y++) {
            if(0 <= s - (x + y) && s - (x + y) <= k)    ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
vw = [list(map(int, input().split())) for _ in range(N)]

dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        v, w = vw[i]

        if j + w <= W:
            dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)

        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(dp[N][W])



Measured memory_bytes: 42788
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

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

	int max_num = max(max(a, b), c);
	ll ans = 0;
	if (a == max_num) {
		ans += (b + c);
	}
	else if (b == max_num) {
		ans += (a + c);
	}
	else {
		ans += (a + b);
	}
	ans += max_num * pow(2,K);
	cout << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
//#define double long double
using namespace std;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
signed main()
{
    int x=read();
    int res=0;
    while(res<x)
    {
        res+=1000;
        if(res>=x) { printf("%lld\n",res-x); return 0; }
    }
    return 0;
}

Measured memory_bytes: 3760
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

        int[] h = new int[n];
        int[] map = new int[n];
        int max = 0;
        int x;

        for(int i = 0; i < n; i++){
            h[i] = sc.nextInt();
        }

        map[n-1] = 0;
        for(int i = 2; i < n+1; i++){
            x = h[n-i+1];
            if(x <= h[n-i]){
                map[n-i] = map[n-i+1] + 1;
                max = Math.max(max, map[n-i]);
            }
            else map[n-i] = 0;
        }

        System.out.println(max);

    }

}


Measured memory_bytes: 51616
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		String s = in.next();

		String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
		String result = "";
		for (int i=0; i<s.length(); i++)
			result += letters.charAt(s.charAt(i) - 'A' + n);

		System.out.println(result);
	}
}



Measured memory_bytes: 147540
N=int(input())
C=list(map(int,input().split()))
mod=10**9+7
C.sort()
C.reverse()
ans=0
for i in range(N):
  ans+=C[i]*(i+2)
  ans%=mod

p=pow(4,N-1,mod)
ans=ans*p%mod
print(ans)

Measured memory_bytes: 27108
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int A,B;

int main()
{
  cin >> A >> B;
  cout << max({A+(A-1), B+(B-1), A+B}) << endl;

  return 0;
}


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

int main(){
  int n, ct=0;
  cin >> n;
  vector<int> P(n);
  rep(i, n) cin >> P[i];
  rep(i, n){
    if(P[i] != i+1) ct++;
  }
  if(ct<=2) cout << "YES" << endl;
  else cout << "NO" << endl;

}

Measured memory_bytes: 384
n,m=map(int,input().split())
ac,wa=0,0
ac_set=set()
wa_cnt=[0]*(n+1)
for i in range(m):
  p,s=map(str,input().split())
  p=int(p)
  if s=="AC":
    if p in ac_set:
      continue
    ac_set.add(p)
  else:
    if p in ac_set:
      continue
    wa_cnt[p]+=1
ac=len(ac_set)
for a in ac_set:
  wa+=wa_cnt[a]
print(ac,wa)

Measured memory_bytes: 12652
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int a,b;
	char op;
	while(1){
	cin>>a>>op>>b;
		if(op=='+'){
			cout<<a+b<<endl;
		}if(op=='-'){
			cout<<a-b<<endl;
		}if(op=='*'){
			cout<<a*b<<endl;
		}if(op=='/'){
			cout<<a/b<<endl;
		}if(op=='?'){
			break;
		}
	}
  return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  string s;
  cin >> s;

  s += "@";

  set<char> chars;
  chars.insert('A');
  chars.insert('C');
  chars.insert('G');
  chars.insert('T');

  ll max_len = 0;
  ll len = 0;
  for (ll i = 0; i < s.size(); i++) {
    bool has = (chars.find(s[i]) != chars.end());
    if (has) {
      len += 1;
    } else {
      max_len = max(max_len, len);
      len = 0;
    }
  }
  cout << max_len << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned uint;
typedef pair<int, int> pairInt;
typedef pair<uint, uint> pairUInt;
#define FOR(i,n) for(int i=0; i<int(n); i++)
#define FOR1(i,m,n) for(int i=int(m); i<int(n); i++)

const int MAXK=640000;

int main(int argc, char *argv[])
{
    int H, W, K;
    scanf("%d%d%d", &H, &W, &K);

    char maze[H+2][W+2];
    int dist[H+2][W+2];
    
    FOR(i,H+2) {
        dist[i][0] = dist[i][W+1] = MAXK+1;
    }
    
    FOR(i,W+2) {
        dist[0][i] = dist[H+1][i] = MAXK+1;
    }

    pairInt start;
    FOR1(i,1,H+1) {
        FOR1(j,1,W+1) {
            char a;
            scanf(" %c", &a);
            maze[i][j] = a;

            if (a == 'S') {
                dist[i][j] = 0;
                start.first = i;
                start.second = j;
            }
            else
                dist[i][j] = MAXK+1;
        }
    }

    int up, low, left, right;
    up = low = start.first;
    left = right = start.second;

    bool flag;
    FOR1(k,1,K+1) {
        flag = false;
        for (int i=max(start.first-k, 1);
             i <= min(start.first+k, H);
             i++) {
            for (int j=max(start.first+start.second-k-i, 1);
                 j <= min(start.second-start.first+k+i, W);
                 j++) {
                if (maze[i][j] == '.' &&
                    dist[i][j] > k &&
                    (dist[i-1][j] == k-1 ||
                     dist[i+1][j] == k-1 ||
                     dist[i][j-1] == k-1 ||
                     dist[i][j+1] == k-1)) {
                    dist[i][j] = k;
                    if (i < up)
                        up = i;
                    else if (i > low)
                        low = i;
                    if (j < left)
                        left = j;
                    else if (j > right)
                        right = j;
                    flag = true;
                }
            }
        }
        if (flag == false)
            break;
    }

    int tmp = min(min(up-1, H-low), min(left-1, W-right));
    int ans = (tmp + 2*K - 1) / K;

    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FOD(i, a, b) for (int i=a; i>=b; i--)
#define fi first
#define se second
#define sqr(x) (x)*(x)
#define sze(x) (int) x.size()

using namespace std;
typedef pair<int, int> pi;
const int N = 1e5 + 5;

vector<vector<int>> g;
int n, m;
vector<int> ans;
bool vis[N];
int dp[N];
int res;

void dfs(int u)
{
    if (vis[u]) return;
    vis[u] = true;
    for (int v: g[u]) dfs(v);
    ans.push_back(u);
}

void toposort()
{
    for (int i=0; i<n; i++) dfs(i);
    //reverse(ans.begin(), ans.end());
}

int32_t main()
{
    fastio
    cin >> n >> m;
    g.resize(n);
    for (int i=0; i<m; i++)
    {
        int u, v; cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
    }
    toposort();
    for (int u: ans)
    {
        for (int v: g[u])
        {
            dp[u] = max(dp[u], dp[v] + 1);
        }
        res = max(res, dp[u]);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 8824
import java.util.Scanner;

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

		long ans = 0;
		for (int i = 0; i < N; i++) {
			long a;
			a = sc.nextLong();

			while(a % 2 == 0) {
				ans++;
				a /= 2;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35648
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int n, m;
	cin >> n >> m;
	vector<int> res(n, -1);
	vector<int> s(m), c(m);
	REP(i, m) {
		cin >> s[i] >> c[i];
		s[i]--;
	}
	REP(i, m) {
		if (res[s[i]] < 0) {
			res[s[i]] = c[i];
		} else {
			if (res[s[i]] != c[i]) {
				put(-1);
				return 0;
			}
		}
	}
	if (res[0] == 0 && n!=1) {
		put(-1);
		return 0;
	}
	if (res[0] < 0 && n == 1) {
		res[0] = 0;
	}else if (res[0] < 0) {
		res[0] = 1;
	}
	FOR(i, 1, n) {
		if (res[i] < 0) {
			res[i] = 0;
		}
	}
	REP(i, n) {
		cout << res[i];
	}
	put("");
	return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> v(n);
    for(auto& i : v) cin >> i;

    vector<ll> cost(n);
    ll ans = INF;

    REP(i, n){
        ll sum = 0;
        REP(j, n){
            if(i == 0){
                cost[j] = v[j];
            }else{
                cost[j] = min(cost[j], v[(j-i+n)%n]);
            }
            sum += cost[j];
        }
        sum += i * x;
        chmin(ans, sum);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if (m == -1 && f == -1 && r == -1) {
                break;
            } else if (m == -1 || f == -1) {
                System.out.printf("F\n");
            } else if (m + f >= 80) {
                System.out.printf("A\n");
            } else if (m + f >= 65 && m + f < 80) {
                System.out.printf("B\n");
            } else if (m + f >= 50 && m + f < 65) {
                System.out.printf("C\n");
            } else if (m + f >= 30 && m + f < 50) {
                if (r >= 50) {
                    System.out.printf("C\n");
                } else {
                    System.out.printf("D\n");
                }
            } else if (m + f < 30) {
                System.out.printf("F\n");
            }
        }
    }
}


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

int X;
int R = 1;

int main() {
  cin >> X;
  for(int b = 2; b * b <= X; ++b) {
    int c = b * b;
    while(b * c <= X) c *= b;
    R = max(R, c);
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

int main(){
    int w,h,n; cin >> w >> h >> n;
    int s[101][101];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            s[i][j] = 1;
        }
    }
    for(int i = 0; i < n; i++){
        int x,y,a; cin >> x >> y >> a;
        x--; y--;
        if (a == 1){
            for(int i = 0; i <= x; i++){
                for(int j = 0; j < h; j++){
                    s[j][i] = 0;
                }
            }
        } else if (a == 2){
            for(int i = x+1; i < w; i++){
                for(int j = 0; j < h; j++){
                    s[j][i] = 0;
                }
            }
        } else if (a == 3){
            for(int i = 0; i <= y; i++){
                for(int j = 0; j < w; j++){
                    s[i][j] = 0;
                }
            }
        } else {
            for(int i = y+1; i < h; i++){
                for(int j = 0; j < w; j++){
                    s[i][j] = 0;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if (s[i][j] == 1) ans++;
            //cout << s[i][j] << " ";
        }
        //cout << endl;
    }
    cout << ans << endl;
}
  



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define D double
#define ll long long 
#define PI 3.141592653589793
const D M=180.0;
D ans;
D a,b,x;
D v,V;
int main(){
    cin>>a>>b>>x;
    V=(a*a*b)-x;
    if(V<=(a*a*b)/2){
        v=(V*2)/(a*a*a);
        ans=atan(v);
        ans*=(M/PI);
    }
    else{
        v=(a*b*b)/(2*x);
        ans=atan(v);
        ans*=(M/PI);
    }
    printf("%.10lf",ans);
    return 0;
}

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

int main() {
    long long N; cin >> N;
	stack<char> res;

	while(N > 0) {
	    --N;
	    res.push(N % 26);
		N /= 26;
	}
	while(!res.empty()) {
	    cout << (char)('a' + res.top());
		res.pop();
	}
	cout << '\n';
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define llong long long
using namespace std;

const int N = 1e5;
llong a[N+3];
int n;
llong m;

int main()
{
	scanf("%d%lld",&n,&m);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	llong mx = a[1]+a[2]; int t = 1;
	for(int i=1; i<n; i++)
	{
		if(a[i]+a[i+1]>a[t]+a[t+1]) {t = i; mx = a[i]+a[i+1];}
	}
	if(mx>=m)
	{
		printf("Possible\n");
		for(int i=n-1; i>t; i--) printf("%d\n",i);
		for(int i=1; i<=t; i++) printf("%d\n",i);
	}
	else
	{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 1536
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
int main() {
    IO;
   
    int n;
    cin >> n;
    int d[5] = {0};
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        if (s[0] == 'M') d[0]++;
        if (s[0] == 'A') d[1]++;
        if (s[0] == 'R') d[2]++;
        if (s[0] == 'C') d[3]++;
        if (s[0] == 'H') d[4]++;
    }
    ll res = 0;
    for (int st = 0; st < (1 << 5); st++) {
        ll v = 1;
        int cnt = 0;
        for (int i = 0; i < 5; i++)
            if ((st >> i) & 1) {
                cnt++;
                v *= (ll) d[i];
            }
        if (cnt == 3) res += v;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
# 木によってLISを作り、dfsで抜けるときにLISをその前の状態まで復元する

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina1(x):
    return int(x) - 1


def read_ints(mina=None):
    ret = map(int, read().split())
    if mina == None:
        return list(ret)
    else:
        return list(map(mina1, ret))


def read_a_int():
    return int(read())


from bisect import bisect_left, bisect_right
from collections import defaultdict
N = read_a_int()
A = read_ints()
tree = defaultdict(lambda: [])
for _ in ra(N - 1):
    u, v = read_ints(mina=1)
    tree[u].append(v)
    tree[v].append(u)

LIS = []
ans = [0] * N  # 各ノードのlen(LIS)を記録


def dfs(now, p):  # 現在のノード、親
    a = A[now]
    # LISの更新
    idx = bisect_left(LIS, a)
    is_append = False
    if idx == len(LIS):
        LIS.append(a)
        is_append = True
    else:
        old = LIS[idx]   # なんの値だったか持っておく
        LIS[idx] = a  # aに更新

    ans[now] = len(LIS)  # 答えを記録
    # 次のノードを探索
    for to in tree[now]:
        if to == p:
            continue
        dfs(to, now)

    # 抜けるときにLISを復元
    if is_append:
        del LIS[idx]
    else:
        LIS[idx] = old


dfs(0, -1)
print(*ans, sep='\n')


Measured memory_bytes: 232456
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		int ans = 2 * n;
		if(n % 2 == 0)ans = n;
		System.out.println(ans);
	}

}


Measured memory_bytes: 22868
#!/usr/bin/env python3
a, b, c, x, y = map(int, input().split())
ans = a * x + b * y
for i in range(1, max(x, y) + 1):
    d = a * max(0, (x - i)) + b * max(0, (y - i)) + (c * 2) * i
    ans = min(ans, d)
print(ans)

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

void solve(){
  int a, b; cin >> a >> b;
  if(b >= a) cout << a << endl;
  else cout << a - 1 << endl;
}

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


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

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

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

  int h, w;
  cin >> h >> w;
  int ci, cj;
  cin >> ci >> cj;
  int di, dj;
  cin >> di >> dj;
  --ci, --cj, --di, --dj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];

  vector<vector<int>> dist(h, vector<int>(w, INF));
  deque<P> q;
  dist[ci][cj] = 0;
  q.emplace_back(ci, cj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();

    rep(mv,4) {
      int ni = i + dx[mv];
      int nj = j + dy[mv];
      if (ni < 0 || nj < 0 || ni >= h || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }

    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i + ei;
        int nj = j + ej;
        if (ni < 0 || nj < 0 || ni >= h || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[di][dj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
}

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

using namespace std;

typedef long ll;


bool ps[9][9];

ll n, k;

// #define DB


int keta(ll n)
{
	int ans = 1;

	while (n >= 10) {
		n /= 10;
		ans++;
	}

	return ans;
}


int main(int, char**)
{
	int ans = 0;
	cin >> n >> k;

	vector<pair<int,int>> op;

	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		op.push_back({ a, b });
	}

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

	for (auto i : op) {

#ifdef DB
		cerr << i.first << ":" << i.second << "=" << k << endl;
#endif // DB

		if (i.second >= k) {
			cout << i.first << endl;
			break;
		}

		k -= i.second;
	}

	return 0;
}



Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
const int INF = 1e9+5;
int n,m,l,a,b,c,d[305][305];
void wf(){rep(k,n) rep(i,n) rep(j,n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);}

int main() {
  cin >> n >> m >> l; n++;
  fill(d[0],d[n],INF);
  rep(i,m) {
    cin >> a >> b >> c;
    d[a][b] = d[b][a] = c;
  }
  wf();
  rep(i,n) rep(j,n) d[i][j] = d[i][j] <= l ? 1 : INF;
  wf();
  cin >> c;
  rep(i,c) {
    cin >> a >> b;
    cout << (d[a][b] == INF ? -1 : d[a][b] - 1) << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  string s;
  cin>>s;
  ll count0 = 0;
  ll count1 = 0;
  rep(i,sz(s)){
    if(s[i]=='0'){
      count0++;
    }
    else{
      count1++;
    }
  }
  ll ans = 2 * min(count0, count1);
  print(ans);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=1e7+1;
ll a[N];
/*vector<ll>v;
ll go(ll n)
{
    ll l=1,r;
    for(ll x:v)
    {
        if((x*x)>n)
        {
            break;
        }
        r=0;
        while(n%x==0)
        {
            n/=x;
            r++;
        }
        l*=(r+1);
    }
    if(n>1)
    {
        l*=2;
    }
    return l;
}*/
int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>n;
    /*for(i=3;i<=n;i+=2)
    {
        for(j=i*i;j<=n;j+=2*i)
        {
            a[j]=1;
        }
    }
    v.pb(2ll);
    for(i=3;i<=n;i+=2)
    {
        if(a[i]==0)
        {
            v.pb(i);
        }
    }*/
    for(i=1;i<=n;i++)
    {
        for(j=i;j<=n;j+=i)
        {
            a[j]++;
        }
    }
    l=0;
    for(i=1;i<=n;i++)
    {
        l+=i*a[i];
    }
    cout<<l<<"\n";
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

#define pb push_back
#define ff first
#define ss second
#define SIZE 1000001
#define INF int(2e9 + 9)
#define BIG_INF ll(4e18 + 9)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define _sz(v) int((v).size())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

//#pragma GCC optimize("Ofast")

ll binpow(ll a, ll b, ll mod = BIG_INF)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
        a %= mod;
        res %= mod;
    }
    res %= mod;
    return res;
}




int T = 1, n, k, a[SIZE], x;
string s;

bool used[SIZE];




void solve()
{
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(i == n - 1)
        {
            if(!used[a[i]]) ans++;
            continue;
        }else
        {
            int kol = 1;
            while(i < n - 1 && a[i] == a[i + 1])
            {
                kol++;
                i++;
            }
            if(!used[a[i]] && kol == 1) ans++;

            for(int j = a[i]; j < SIZE; j += a[i])
            {
                used[j] = 1;
            }
        }
    }
    cout << ans << '\n';

}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

//    cin >> T;

    while(T--)
    {
        solve();
    }




    return 0;
}


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

#define check cnt=0;for(j=0;j<6;j++)if(d[q][j]==d[r][j])cnt++;
#define m tmp=d[r][1];d[r][1]=d[r][3];d[r][3]=d[r][4];d[r][4]=d[r][2];d[r][2]=tmp;
#define y tmp=d[r][0];d[r][0]=d[r][3];d[r][3]=d[r][5];d[r][5]=d[r][2];d[r][2]=tmp;

bool same(int d[][6],int q,int r){
 int tmp,cnt,j,a=1,i,k,l;
 check
   if(cnt==6)a=0;

 while(a){
  for(i=0;i<5;i++){
   for(k=0;k<4;k++){
    check
    if(cnt==6)break;
    m
   }
   check
   if(cnt==6)break;
   tmp=d[r][0];
   d[r][0]=d[r][1];
   d[r][1]=d[r][5];
   d[r][5]=d[r][4];
   d[r][4]=tmp;
  }
  if(cnt==6)break;
  y
  for(k=0;k<4;k++){
   check
   if(cnt==6)break;
   m
  }
  if(cnt==6)break;
  y
  y
  for(k=0;k<4;k++){
   check
   if(cnt==6)break;
   m
  }
  a=0;
 }

 if(cnt==6)return true;
 return false;

}


int main(){
 int n,tmp,cnt,j,a=1,i,k,l,judge=0;

 cin >> n;

 int d[n][6];

 for(i=0;i<n;i++){
  for(j=0;j<6;j++){
   cin >> d[i][j] ;
  }
 }

 for(i=0;i<n-1;i++){
  for(l=i+1;l<n;l++){
  int q=i;
  int r=l;
  if(same(d,q,r))judge++;
  }
 }
 if(judge>0)cout << "No" << endl ;
 else cout << "Yes" << endl ;

 return 0;
}

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;
#define ll  long long
#define PI  acos(-1)
#define pb  push_back
#define ins insert
#define INF 5000000000000000007 //1e18+7
#define mk  make_pair
#define ff  first
#define ss  second
#define endl "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a) (ll)a.size()
#define double long double
#define coud(a,b) cout << fixed << setprecision((b)) << (a)
#define mset(x,y)  memset(x,y,sizeof(x))
#define all(x)   (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bp(n)  __builtin_popcountll(n)
#define mxt(a)  *(max_element(a.begin(),a.end()))
#define mnt(a)  *(min_element(a.begin(),a.end()))
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define trav(a, x)    for(auto &a : x)

const double eps=1e-7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int d8x[8]={+1, +1, +1, 0, 0, -1, -1, -1};
int d8y[8]={+1, 0, -1, +1, -1, +1, 0, -1};
int d4x[4]={1, 0, 0, -1};
int d4y[4]={0, -1, 1, 0};
ll power(ll x,ll y){ll ans=1;x=x;while(y>0){if(y&1)ans=(ans*x);y=y>>1;x=(x*x);}return ans;}
ll sqr(ll x) { return x * x;}

template <typename T> T gcd(T a,T b){ if(a==0) return b; return gcd(b%a,a); }
template <class T> inline void chmax(T &x,T y){ x = max((x), (y));}
template <class T> inline void chmin(T &x,T y){ x = min((x), (y));}
template <class T> T abs(T x) { return x>0 ? x : -x;}
template <typename T> T powm(T a,T b, ll m){T cnt=1; while(b>0) { if(b%2==1) cnt=(cnt*a)%m; b/=2; a=(a*a)%m; }return cnt%m;}
typedef pair<int,int>  pii;
typedef pair<ll,ll>  pll;
typedef vector<pll>  vpll;
typedef vector<pii>  vpii;
typedef vector<ll>   vll;
typedef vector<int>  vii;
#define minpq priority_queue<T,vector<T>,greater<T> >;
// #define T int
// #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
//*X.find_by_order(k) returns the kth largest element (0-based).
//X.order_of_key(val) returns the no. of values less than val.
ll ncr(ll n,ll r) {ll ans=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){ans*=(n-i);ans/=(i+1);}return ans;}
const int MOD = 1000000007;   
const int N = 200010;

struct compare{
    bool operator() (const int &a,const int &b) const {
        return a>b;
    }
};
// 🎲

int32_t main() {
  cin.sync_with_stdio(0);cin.tie(0);
  cin.exceptions(cin.failbit);
  
  ll n;
  cin >> n;
  vll a(n);
  for(int i=0; i<n; ++i) {
    cin >> a[i];
  }
  sort(all(a));
  ll ans = 0;
  for (int i=0; i<n; ++i) {
    for (int j=i+1; j<n; ++j) {
      for(int k=j+1; k<n; ++k) {
        set<int> s;
        s.ins(a[i]);
        s.ins(a[j]);
        s.ins(a[k]);
        if(a[k] < a[i] + a[j] and sz(s) == 3) ans++;
      }
    }
  }
  cout << ans;
  return 0; 
}

/* 
    stuff you shoulds look for
    * int overflow,array bounds.
    * special cases (n=1?).
    * N,MOD value.
*/

Measured memory_bytes: 3660
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
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++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long ll;
typedef unsigned long long ull;
const int IINF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

struct P {
	vvi v;
	int cnt;
	vector<pi> space;
};

bool done(vvi a) {
	REP(i, 4) {
		REP(j, 7) {
			if(a[i][j] != (i+1)*10 + j+1)
				return false;
		}
	}
	return true;
}

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


	int n; cin >> n;
	REP(_, n) {
		set <vvi> s;
		queue<P> q;
		P p;
		p.v.resize(4);
		REP(i, 4) {
			p.v[i].resize(8);
			FOR(j, 1, 8) {
				cin >> p.v[i][j];
				if(p.v[i][j] % 10 == 1) {
					p.v[i][j] = 0;
					p.space.pb(pi(i, j));
				}
			}
		}
		p.v[0][0] = 11;
		p.v[1][0] = 21;
		p.v[2][0] = 31;
		p.v[3][0] = 41;
		p.cnt = 0;
		q.push(p);
		bool flg = false;
		while(q.size()) {
			p = q.front(); q.pop();
			if(done(p.v)) {
				flg = true;
				break;
			}
			REP(i, 4) {
				P p2(p);
				int num = p2.v[p.space[i].first][p.space[i].second-1]+1;
				if(num % 10 == 8)
					continue;
				REP(j, 4) REP(k, 8) {
					if(p2.v[j][k] == num) {
						p2.v[p2.space[i].first][p2.space[i].second] = num;
						p2.v[j][k] = 0;
						p2.space[i] = pi(j, k);
						if(!s.count(p2.v)) {
							p2.cnt++;
							q.push(p2);
							s.insert(p2.v);
						}
						break;
					}
				}
				/*
				REP(j, 4) {
					REP(k, 8)
						cout << p2.v[j][k] << ' ';
					cout << endl;
				}
				*/
			}
		}
		cout << (flg ? p.cnt : -1) << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    char inp[111];
    scanf("%s", inp);
    
    for(int i = 0; i <= strlen(inp); i++)
        if(i == 4)
            printf(" ");
        else
            printf("%c", inp[(i < 4 ? i : i - 1)]);
    printf("\n");
    
    return 0;
}

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

const int MaxN=2e5+5;
const int MaxM=(1<<19)+5;
const int Mod=924844033;

int N,M,InvM;
int Size[MaxN],Cnt[MaxN];
int R[MaxM],A[MaxM],B[MaxM],C[MaxM];
int Fac[MaxN],Inv[MaxN],Ans[MaxN];

vector<int> To[MaxN];

void DFS(int u,int fa){
	Size[u]=1;
	for(int v:To[u])
		if(v^fa){
			DFS(v,u);
			Size[u]+=Size[v];
		}
	if(u>1)
		Cnt[Size[u]]++;
}

int Pow(int base,int n){
	int ans=1;
	if(n<0)
		n+=Mod-1;
	for(;n;n>>=1){
		if(n&1)
			ans=1ll*ans*base%Mod;
		base=1ll*base*base%Mod;
	}
	return ans;
}

void NTT(int *a,int f){
	int i,j,k,wn,w,x,y;
	for(i=0;i<M;i++)
		if(i<R[i])
			swap(a[i],a[R[i]]);
	for(i=1;i<M;i<<=1){
		wn=Pow(5,f*(Mod-1)/(i<<1));
		for(j=0;j<M;j+=i<<1)
			for(w=1,k=0;k<i;k++){
				x=a[j+k],y=1llu*w*a[j+k+i]%Mod;
				a[j+k]=(x+y)%Mod,a[j+k+i]=(x-y+Mod)%Mod;
				w=1llu*w*wn%Mod;
			}
	}
}

int Binom(int n,int m){
	return n<m?0:1llu*Fac[n]*Inv[m]%Mod*Inv[n-m]%Mod;
}

int main(){
	int i,j,u,v;
	scanf("%d",&N);
	Fac[0]=Fac[1]=Inv[0]=Inv[1]=1;
	for(i=2;i<=N;i++){
		Fac[i]=1llu*Fac[i-1]*i%Mod;
		Inv[i]=1llu*(Mod-Mod/i)*Inv[Mod%i]%Mod;
	}
	for(i=2;i<=N;i++)
		Inv[i]=1llu*Inv[i-1]*Inv[i]%Mod;
	for(i=1;i<N;i++){
		scanf("%d%d",&u,&v);
		To[u].push_back(v);
		To[v].push_back(u);
	}
	DFS(1,0);
	for(i=0;i<=N;i++){
		A[i]=1llu*Fac[i]*(Cnt[i]+Cnt[N-i])%Mod;
		B[N-i]=Inv[i];
	}
	for(j=0,M=1;M<=2*N;j++,M<<=1);
	for(i=0;i<M;i++)
		R[i]=(R[i>>1]>>1)+((i&1)<<j-1);
	InvM=Pow(M,Mod-2);
	NTT(A,1),NTT(B,1);
	for(i=0;i<M;i++)
		C[i]=1llu*A[i]*B[i]%Mod;
	NTT(C,-1);
	for(i=1;i<=N;i++)
		printf("%d\n",(1llu*N*Binom(N,i)%Mod-1llu*C[N+i]*InvM%Mod*Inv[i]%Mod+Mod)%Mod);
	return 0;
}

Measured memory_bytes: 35840
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using mint = atcoder::modint998244353;
vector<mint> ten;
vector<mint> one;

struct S {
  mint val;
  int len;
};
using F = int;

S op(S sl, S sr) {
  mint next = sl.val * ten[sr.len] + sr.val;
  return {next, sl.len + sr.len};
}

S e() { return {0, 0}; }

S mapping(F f, S s) {
  if (f == -1) return s;
  mint next = f * one[s.len];
  return {next, s.len};
}

F composition(F f, F g) {
  if (f == -1) return g;
  return f;
}

F id() { return -1; }

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

  ten.resize(N + 1);
  one.resize(N + 1);
  ten[0] = 1;
  one[0] = 0;
  rep(i, N) {
    ten[i + 1] = ten[i] * 10;
    one[i + 1] = one[i] * 10 + 1;
  }

  vector<S> A(N, {1, 1});
  atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(A);

  vector<int64_t> answer(Q);
  rep(i, Q) {
    int L, R, D;
    cin >> L >> R >> D;
    L--;
    seg.apply(L, R, D);
    answer[i] = seg.all_prod().val.val();
  }

  rep(i, Q) cout << answer[i] << endl;
  return 0;
}


Measured memory_bytes: 13028
import java.math.BigDecimal;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		double r = scanner.nextDouble();
		
		System.out.println(BigDecimal.valueOf(Math.PI * r * r).toPlainString() + " " + BigDecimal.valueOf(2 * Math.PI * r).toPlainString());

	}

}



Measured memory_bytes: 28164
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include<stdlib.h>

int main(){
    int n;
    long long eq=0;
    scanf("%d", &n);
    long long num[n];
    for(int i=0; i<n;++i)
        scanf("%lld", &num[i]);
    long long pp= num[0];
    for(int i=1; i<n; ++i){
        if(pp>num[i])
            eq+= pp-num[i];
        else
            pp=num[i];
    }
    printf("%lld\n", eq);
    return 0;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

void Impossible(){
	cout<<"Impossible"<<endl;
	exit(0);
}

const int Nmax=100010;
vi g[Nmax];
bool vis[Nmax];

pi dfs(int v,int par){
	vector<pi> waf;
	for(auto to:g[v])if(to!=par)
		waf.PB(dfs(to,v));
	pi res;
	{
		int zc=0;
		int p=0;
		for(auto w:waf){
			if(w.first==0)zc++;
			p+=w.first;
		}
		if(zc>1)p+=zc-1;
		res.first=p;
	}
	{
		int zc=0;
		int p=1;
		for(auto w:waf){
			if(w.first==0)zc++;
			p+=w.first;
		}
		if(zc>0)p+=zc;
		res.second=p;
	}
	{
		if(int(waf.size())==1){
			int zc=0;
			int p=0;
			if(waf[0].second==0)zc++;
			p=waf[0].second;
			if(zc>0)p+=zc;
			chmin(res.second,p);
		}else{
			int zc=0;
			int p=0;
			for(auto w:waf){
				if(w.first==0)zc++;
				p+=w.first;
			}
			if(zc>0)p+=zc;
			chmin(res.second,p);
		}
	}
	return res;
}

signed main(){
	int n=read();
	REP(i,n-1){
		int a=read(),b=read();
		g[a].PB(b);
		g[b].PB(a);
	}
	int par=-1;
	REP(i,n)if(int(g[i].size())==1)par=i;
	int root=g[par][0];
	pi w=dfs(root,par);
	cout<<max(min(w.first+1,w.second),int(1))<<endl;
}

Measured memory_bytes: 16768
import math
n,m=map(int,input().split())
ans = 0
if n >= 2:
    ans = math.factorial(n) // (math.factorial(n-2) * math.factorial(2))
if m >= 2:
    ans += math.factorial(m) // (math.factorial(m-2) * math.factorial(2))
print(ans)

Measured memory_bytes: 3188
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>         // abs
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back

int main()
{  
    int A,B,C;
    cin >> A >> B >> C;
    bool ans = false;
    for(int i = 1; i <= 100; i++){
        if((A*i)%B == C){
            ans = true;
        }
    }
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
#include"algorithm"
#include"stack"
#include"queue"
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long
#define MAXN 1000005 

int n,a[MAXN];
int cnt=0;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n-2;i++)
	{
		for(int j=i+1;j<=n-1;j++)
		{
			for(int k=j+1;k<=n;k++)
			{
				if(a[i]==a[j]||a[j]==a[k]||a[i]==a[k]) continue;
				int now1=max(a[i],max(a[j],a[k]));
				int now2=min(a[i],min(a[j],a[k]));
				int now3=a[i]+a[j]+a[k]-now1-now2;
				if(now2+now3>now1&&now1-now2<now3) cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
} 

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
#define dirty 1
#define clean 0 // 課題とAOJのやることを合わせるため
#define MAXN 1400 // >=h,w
int dp[MAXN+1][MAXN+1];
int graph[MAXN+1][MAXN+1];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int h,w; cin >> h >> w;
    int ma = 0;
    rep(i,0,h){
        rep(j,0,w){
            int tmp; cin >> tmp;
            if(tmp==0)graph[i][j] = clean;
            else graph[i][j] = dirty;
            if(graph[i][j]==clean) ma = 1;
        }
    }
    rep(i,0,w) dp[0][i] = (graph[0][i]==clean);
    rep(i,0,h) dp[i][0] = (graph[i][0]==clean);
    rep(i,1,h){
        rep(j,1,w){
            if(graph[i][j]==dirty) dp[i][j] = 0;
            else dp[i][j] = min(dp[i-1][j-1],min(dp[i][j-1],dp[i-1][j]))+1;
            ma = max(dp[i][j],ma);
        }
    }
    cout << ma*ma << endl;
}


Measured memory_bytes: 18476
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

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

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	string s;
	int k;
	cin >> s >> k;

	int count = 0;
	if (k <= s.size())
	{
		for (int i = 0; i < k; i++)
		{
			if (s[i] == '1') count++;
		}
	}
	if (count == k)
	{
		cout << 1 << endl;
		return 0;
	}

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != '1')
		{
			cout << s[i] << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#define N 50
using namespace std;
typedef long long LL;
LL a[N+1];
LL knapsack[N+1][N+1][N*N+1]; //Considering from 1 to x, choose i such that the weight is w
LL dp(int x, int i, int w)
{
	if(i>x) return 0; //cant take more than I have
	if(i==0) return w==0;
	if(x==1) return w==a[1]; //i==1 since i!=0 and i <= x
	if(w<=0) return 0; //a[i] >= 1, so impossible for i!=0 and have a zero result
	
	if(knapsack[x][i][w]!=-1)
		return knapsack[x][i][w];
	else
		return knapsack[x][i][w] = dp(x-1,i-1,w-a[x])+dp(x-1,i,w);
}
int main()
{
	memset(knapsack,-1,sizeof knapsack);
	int n, A; cin >> n >> A;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
		
	LL ans = 0;
	for(int len = 1; len <= n; len++)
		ans += dp(n,len,len*A);
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 51072