akhauriyash/Code-Regression huggingface dataset:
N = int(input())


def f(v):
    cnt = 0
    for i in range(1, v + 1):
        if v % i == 0:
            cnt += 1
    return cnt


ans = 0
for i in range(1, N + 1, 2):
    if f(i) == 8:
        ans += 1
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    ft
    int t,i,j,n,m,l,r;
    string s,p;
    cin>>s>>p;
    n=s.size();
    m=p.size();
    int dp[n+1][m+1];
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=m;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(s[i-1]==p[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
            }
        }
    }
    string ans;
    for(i=n,j=m;i>0 && j>0;)
    {
        if(s[i-1]==p[j-1])
        {
            ans+=s[i-1];
            i--,j--;
        }
        else
        {
            if(dp[i][j]==dp[i-1][j])
            {
                i--;
            }
            else
            {
                j--;
            }
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 38768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        HashSet<Integer>hs = new HashSet<>();
        for(int i=0;i<3;i++)hs.add(s.nextInt());
        if(hs.size()==2) System.out.println("Yes");
        else System.out.println("No");
    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; // [9,223,372,036,854,775,807 to -9.....808] 19 digits
typedef long double ld;
#define inc(i, a, b) for (long long int i = a; i <= b; i++)
#define dec(i, a, b) for (long long int i = a; i >= b; i--)
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define lv vector<ll>
#define cv vector<char>
#define dv vector<ld>
#define rall(c) (c).rbegin(), (c).rend()
#define lpr pair<ll, ll>
#define mp make_pair
#define cin(c) \
    ll c;      \
    cin >> c;
#define lmap unordered_map<ll, ll>
#define vinp(a, n) \
    inc(i, 1, n)   \
    {              \
        cin(k);    \
        a.pb(k);   \
    }
#define LIM 1000000007
#define F first
#define S second
#define fr(i, n) inc(i, 0, n - 1)
#define fri(n, a) \
    inc(i, 0, n - 1) { cin >> a[i]; }
#define debug(p) cout << p;
#define umap unordered_map
#define uset unordered_set
#define fill(a, val, n) \
    inc(i, 0, n - 1) { a[i] = val; }
void i_love_Accepted()
{
    string s,t;
    cin>>s>>t;
    ll ans=0;
    fr(i,s.size())
    {
        if(s[i]!=t[i])
            ans++;
    }
    cout<<ans;
}   
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        i_love_Accepted();
        cout<<"\n";
    } 
}


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

int main(void)
{
  vector<int> vi(3);
  cin >> vi[0] >> vi[1] >> vi[2];
  sort(vi.begin(), vi.end());
  cout << abs(vi[0] - vi[1]) + abs(vi[1] - vi[2]) << endl;
  
  return 0;
}


Measured memory_bytes: 256
//48
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int ans=-1<<30,seq=-1<<30;
    while(n--){
      int i;
      cin>>i;
      seq=max(seq+i,i);
      ans=max(ans,seq);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

signed main(){
    int n,m;
    cin >> n >> m;
    vector<int> v(n, 0);
    rep(m){
        int a, b;
        cin >> a >> b;
        if(a == 1){
            if(v[b-1] == 1){
                cout << "POSSIBLE";
                return 0;
            }
            v[b-1]++;
        }
        if(b == n){
            if(v[a-1] == 1){
                cout << "POSSIBLE";
                return 0;
            }
            v[a-1]++;
        }
    }
    cout << "IMPOSSIBLE";
    return 0;
}


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

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

    int N, n[200000], diff = -1000000000;
    cin>>N>>n[0];  //入力
    int min = n[0];

    for (int i = 1; i < N; i++) {
        cin>>n[i]; //入力
        if(n[i] - min > diff) diff = n[i] - min;
        if(min > n[i]) min = n[i];
    }

    cout<<diff<<endl; //出力
    return 0;
}



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

using namespace std;

int main()
{
    int N;
    cin >> N;
    
    vector<int> vec;
    
    for(int i = 0; i < N; ++i)
    {
        int Num;
        cin >> Num;
        vec.push_back(Num);
    }
    
    cin >> N;
    for(int i = 0; i < N; ++i)
    {
        int Start, End; 
        cin >> Start >> End;
        
        reverse(vec.begin() + Start, vec.begin() + End);
    }
    
    for(size_t i = 0; i < vec.size(); ++i)
      cout << (i == 0 ? "" : " ") << vec[i];
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

int N, h[1 << 17], dp[1 << 17];

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> h[i + 1];
    }
    dp[1] = 0;

    for (int i = 2; i <= N; i++)
    {
        if (i - 2 > 0)
            dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
        else
            dp[i] = abs(h[i] - h[i - 1]);
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
fn main() {
    let k = read::<usize>();

    let mut index = 10;
    let mut len = 1;
    while index <= k {
        index = (index - 2) * 3 + 4;
        len += 1;
    }

    len += 1;

    let mut seq = Vec::new();
    for i in 1..10 {
        seq.push(i);
        seq.append(&mut gen(i, len));
    }

    seq.sort();
    // println!("{:?}", seq);
    println!("{:?}", seq[k - 1]);
}


fn gen(num: i64, len: usize) -> Vec<i64> {
    if num.to_string().len() >= len {
        return Vec::new()
    }
    let mut ans = Vec::new();
    let lb = num % 10;
    let seq = if lb == 0 {
        vec![lb, lb + 1] 
    } else if lb == 9 {
        vec![lb - 1, lb]
    }else {
        vec![lb-1, lb, lb+1]
    };

    for i in seq.iter() {
        ans.push(num * 10 + i);
    }

    for n in ans.clone().iter() {
        ans.append(&mut gen(*n, len));
    }

    ans
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 13200
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
S=s2(n)

C=[0]*26
for i in range(97,123):
    c=100
    for ss in S:
        c=min(c,ss.count(chr(i)))
    C[i-97]=c

ans=""
for i in range(26):
    ans+=chr(i+97)*C[i]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 10000;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const double pi = 3.141592653589793;





int main(){
    ll H, W;
    cin>>H>>W;
    vector<vector<char>> S(H, vector<char>(W));
    vector<vector<ll>> Visit(H, vector<ll>(W, INF));
    ll White=0;
    rep(i, H){
        rep(j, W){
            cin>>S[i][j];
            if(S[i][j]=='.')White++;
        }
    }
    if(S[0][0]=='#'||S[H-1][W-1]=='#'){
        cout<<-1<<endl;
        return 0;
    }
    Visit[0][0]=0;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> Q;
    Q.push(make_pair(0, 0));
    while(!Q.empty()){
        pair<ll, ll> P=Q.top(); Q.pop();
        ll v=P.second;//cout<<v<<endl;
        if(Visit[v/W][v%W]<P.first)continue;
        ll x, y;
        x=v/W;
        y=v%W;
        for(ll i=-1; i<=1; i++){
            for(ll j=-1; j<=1; j++){
                if((i*j)!=0)continue;
                if(i==0&&j==0)continue;
                if((x+i)<0||(x+i)>=H)continue;
                if((y+j)<0||(y+j)>=W)continue;
                if(S[x+i][y+j]=='#')continue;
              	//cout<<x<<" "<<y<<" "<<Visit[x+i][y+j]<<" "<<Visit[x][y]<<" "<<x+i<<" "<<y+j<<endl;
                if(Visit[x+i][y+j]>Visit[x][y]+1){
                    Visit[x+i][y+j]=Visit[x][y]+1;
                    Q.push(make_pair(Visit[x+i][y+j],(x+i)*W+y+j));
                  	//cout<<(x+i)*W+y+j<<endl;
                }
            }
        }    
    }
  	/*rep(i, H){
        rep(j, 20){
            cout<<Visit[i][j]<<" ";
        }
      	cout<<endl;
    }*/
    if(Visit[H-1][W-1]==INF){
        cout<<-1<<endl;
        return 0;
    }
  	
    cout<<White-Visit[H-1][W-1]-1<<endl;
  	
}
    

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <algorithm>
#include <utility>
#define INF INT_MAX / 2
using namespace std;

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

int main(void) {
	int n;

	while(cin >> n,n!=0){
	int l,r;
	l = r = 1;
	int sum = 0,cnt = 0;
	for(;;){
		while(sum <= n && r<=n){
			sum += r;
			if(sum == n)cnt++;
			r++;
		}
		if(r == n+1)break;
		sum -= l;
		if(sum == n && l != r-1)cnt++;
		l++;
	}
	if(n == 1)cout << 0 << endl;
	else cout << cnt << endl;
}
}

// command shift d duplicate
// command ctrl 上下
// command D
// command caps G → '' ""
// vector<vector<int>> a(N,vector<int>(M,-1));

Measured memory_bytes: 1160
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const int N = 1e6 + 5;

ll a, b, c, d;
map <ll, ll> mp;

ll find (ll n) {
	if (n == 0)	return 0;
	if (n == 1)	return d;
	if (mp.count(n))	return mp[n];
	ll res = 1e18;
	if (n < res/d)	res = n*d;
	res = min (res, 1LL*abs((n%2)*d + a + find (n/2)));
	res = min (res, 1LL*abs((2-(n%2))*d + a + find((n + 1)/2)));
	res = min (res, 1LL*abs((n%3)*d + b + find(n/3)));
	res = min (res, 1LL*abs(3*d - (n%3)*d + b + find((n + 2)/3)));
	res = min (res, 1LL*abs((n%5)*d + c + find(n/5)));
	res = min (res, 1LL*abs((5 - (n%5))*d + c + find((n+4)/5)));
	// cout << n << " " << res << "\n";
	mp[n] = res;
	return res;
}

void solve() {
	mp.clear();
	ll n;
	cin >> n >> a >> b >> c >> d;
	cout << find(n) << "\n";
}

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

Measured memory_bytes: 4432
#include <iostream>
#include <stdlib.h>
#include <cstdio>
using namespace std;
static const int N = 100;
static const int WHITE = 0, GRAY = 1, BLACK = 2;
static const int INFI = (1<<21);  // data type?

int n, sum, M[N][N], d[N], p[N], color[N];

void prim()
{
	for(int u = 0; u < n; u++) d[u] = INFI; 
	int u = 0;
	d[0] = 0;
	
	while(true)
	{
		//update current MST.
		int mincost = INFI;
		int i;
		for(i = 0; i < n; i++)
		{
			if(color[i] != BLACK && d[i] < mincost)
			{
				mincost = d[i];
				u = i;
			}
		}
//		printf("yes1");
		if(mincost == INFI) break;
		color[u] =  BLACK; 
		
	
		//update weight of candidates.
		for(int v = 0; v < n ; v++)
		{
			if(color[v] != BLACK && M[u][v] != -1)
			{	
				if(M[u][v] < d[v])
				{
					d[v] = M[u][v];
					//printf("%d-%d: %d", u, v, d[v]);
					//printf("yes");
					p[v] = u;
					color[v] = GRAY;
				} 				
			}
		}	
	}
	
	for(int i = 0; i < n; i++)
	{
		sum += d[i];
//		printf("%d ", d[i]);
	}
	
	printf("%d\n", sum);
}


int main() {
	sum = 0;
	scanf("%d", &n);
	for(int u = 0; u < n; u++)
	{
		for(int v = 0; v < n; v++)
		{
			int value;
			scanf("%d", &value);
			M[u][v] = value;
		}
	}
	
	prim();
	
//	system("pause");
	return 0;
}


Measured memory_bytes: 3240
N = eval(input())
H = list(map(int, input().split()))
dp = [0, abs(H[1] - H[0])]
if N > 2:
    for i in range(2, N):
        dp.append(min(abs(H[i] - H[i-2])+dp[-2], abs(H[i] - H[i-1])+dp[-1]))
else:
    print(dp[-1])
    exit()
print(dp[-1])

Measured memory_bytes: 13928
#!/usr/bin/env python3
n = int(input())
a, b, c = [list(map(int, input().split())) for i in[0]*3]
ans = b[a[0]-1]
prev = a[0]
for i in range(1, n):
    ans += b[a[i]-1]
    if prev+1==a[i]:
        ans += c[prev-1]
    prev = a[i]
print(ans)



Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

/**
 * 深さ優先探索(再帰)
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja">ALDS1_11_B</a>
 */
public class Main{

	private static final int N = 100;
	private static final int WHITE = 0;
	private static final int GRAY = 1;
	private static final int BLACK = 2;

	private static int n, tt;
	// 隣接行列
	private static int M[][] = new int[N][N];
	// 頂点の訪問状態
	private static int color[] = new int[N];
	// タイムスタンプ d[v]: v を最初に発見した発見時刻を記録
	private static int d[] = new int[N];
	// タイムスタンプ f[v]: v の隣接リストを調べ終えた完了時刻を記録
	private static int f[] = new int[N];
	// 各頂点の次に訪問する頂点のインデックスを記録
	private static int nt[] = new int[N];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for (int x[] : M) {
			Arrays.fill(x, 0);
		}

		for (int i = 0; i < n; i++) {
			int u = sc.nextInt();
			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				int v = sc.nextInt();
				M[u - 1][v - 1] = 1;
			}
		}

		initColor();
		for (int i = 0; i < n; i++) {
			if (color[i] == WHITE) dfsRecursion(i);
		}

		for (int i = 0; i < n; i++) {
			System.out.println((i + 1) + " " + d[i] + " " + f[i]);
		}

		sc.close();
	}

	private static void initColor() {
		for (int i = 0; i < n; i++) {
			color[i] = WHITE;
		}
	}

	private static void dfsRecursion(int u) {
		color[u] = GRAY;
		d[u] = ++tt;
		for (int i = 0; i < n; i++) {
			if (M[u][i] == 1 && color[i] == WHITE) {
				dfsRecursion(i);
			}
		}
		color[u] = BLACK;
		f[u] = ++tt;
	}

}



Measured memory_bytes: 28296
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

vector<complex<long double>> fft(vector<complex<long double>> a,
                                 bool inverse = false) {
  int n = a.size();
  int h = 0; // 高さ
  for (int i = 0; (1 << i) < n; i++) {
    h++;
  }

  // bit reverseしてfftする前の配列の並びをいい感じにする
  for (int i = 0; i < n; i++) {
    int j = 0;
    for (int k = 0; k < h; k++)
      j |= (i >> k & 1) << (h - 1 - k);
    if (i < j)
      swap(a[i], a[j]);
  }

  // b: ブロックサイズの半分
  for (int b = 1; b < n; b *= 2) {
    for (int j = 0; j < b; j++) {
      complex<long double> w =
          polar(1.0, -(2 * M_PI) / (2 * b) * j * (inverse ? 1 : -1));
      for (int k = 0; k < n; k += b * 2) {
        complex<long double> s = a[j + k];
        complex<long double> t = a[j + k + b] * w;
        a[j + k] = s + t;
        a[j + k + b] = s - t;
      }
    }
  }
  if (inverse)
    REP(i, n) { a[i] /= n; }
  return a;
}

vector<complex<long double>> fft(vector<long double> a, bool inverse = false) {
  vector<complex<long double>> a_complex(a.size());
  REP(i, a.size()) a_complex[i] = complex<long double>(a[i], 0);
  return fft(a_complex, inverse);
}

vector<long double> convolve(vector<long double> a, vector<long double> b) {
  int s = a.size() + b.size() - 1;
  int t = 1;
  while (t < s)
    t *= 2;
  a.resize(t);
  b.resize(t);
  vector<complex<long double>> A = fft(a);
  vector<complex<long double>> B = fft(b);
  for (int i = 0; i < t; i++) {
    A[i] *= B[i];
  }
  A = fft(A, true);
  a.resize(s);
  for (int i = 0; i < s; i++)
    a[i] = A[i].real();
  return a;
}

int main() {
  int n;
  ll m;
  cin >> n >> m;
  vector<long double> cum(100001, 0);
  vector<long double> ccum(100001);
  REP(i, n) {
    int a;
    cin >> a;
    cum[a] += 1;
    ccum[a] += 1;
  }

  auto ans = convolve(cum, ccum);

  ll res = 0LL;
  ll rest = m;
  for (ll i = 2 * 100000; i >= 0; i--) {
    ll c = (ll)(ans[i] + 0.5);
    res += min(c, rest) * i;
    rest -= c;
    if (rest <= 0) {
      break;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 42304
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 126688
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

#define FOR(i, l, r) for (i = (l); i < r; i++ )

using namespace std;
typedef long long ll;

typedef struct {
    int p;			// parent
    int l;			// left child
    int r;			// right child
    int dep;			// depth
    int hei;			// height
    bool is_l;			// whether this is left child.
    int deg;		// the number of children.
} Node;

#define MAX_N (30)
#define NIL (-1)
int n;
Node N[MAX_N];

void output( int id ) {
    int sib = -1;
    char type[100];

    if ( N[id].p != NIL ) {
	if ( N[id].is_l ) 
	    sib = N[N[id].p].r;
	else 
	    sib = N[N[id].p].l;
    }

    if ( N[id].p == NIL )
	sprintf( type, "root" );
    else if ( N[id].l == NIL && N[id].r == NIL ) 
	sprintf( type, "leaf" );
    else 
	sprintf( type, "internal node" );
	
    printf("node %d: ", id);
    printf("parent = %d, ", N[id].p );
    printf("sibling = %d, ", sib );
    printf("degree = %d, ", N[id].deg );
    printf("depth = %d, ", N[id].dep );
    printf("height = %d, ", N[id].hei );
    printf("%s", type );
    printf("\n");
    return;
}

int set_depth_height( int id, int dep ) {
    N[id].dep = dep;
    int hei = 0;
    if ( N[id].l != NIL ) {
	hei = max( hei, set_depth_height( N[id].l, dep + 1 ) );
    }

    if ( N[id].r != NIL ) {
	hei = max( hei, set_depth_height( N[id].r, dep + 1 ) );
    }

    N[id].hei = hei;

    return N[id].hei + 1;
}

int main()
{
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
	N[i].p = N[i].l = N[i].r = NIL;
    }

    for ( int i = 0; i < n; i++ ) {
	int id;
	scanf("%d", &id);
	scanf("%d %d", &N[id].l, &N[id].r);
	if (N[id].l != -1 ) {
	    N[id].deg++;
	    N[N[id].l].is_l = true;
	    N[N[id].l].p = id;
	}

	if (N[id].r != -1 ) {
	    N[id].deg++;	
	    N[N[id].r].is_l = false;
	    N[N[id].r].p = id;
	}
    }

    int root = -1;
    for ( int i = 0; i < n; i++ ) {
	if ( N[i].p == NIL ) {
	    root = i;
	    break;
	}
    }

    set_depth_height( root, 0 );

    for ( int i = 0; i < n; i++ ) {
	output( i );
    }

    return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	string s,t;
	ll n;
	cin >> n >> s >> t;
	FOR(i,0,n){
		cout << s[i] << t[i];
	}
	cout << endl;
}

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

ll dp[200010][10];
ll a[200010];

int main(){
    int n;
    cin >> n;
    rep(i, n) cin >> a[i];    
    rep(i, n+1) rep(j, 3) dp[i][j] = -LINF;

    dp[1][0] = a[0];
    dp[2][1] = a[1];
    if (n > 2) dp[3][2] = a[2];

    for(int i = 0; i < n; i++){
        rep(j, 3){
            for(int d = 0; d < 3-j; d++){
                int p = i-d-1; // 何日前を見るか
                if (p > 0){
                    dp[i+1][j+d] = max(dp[i+1][j+d], dp[p][j] + a[i]);
                }
            }
        }
    }
    
    ll ans = -LINF;

    int m = 1 + n%2;
    for(int d = 0; d <= m; d++){ // 最後を空ける箇所を全てチェック
        int i = n-d;
        ans = max(ans, dp[i][m-d]);
    }
    cout << ans << endl;
    return 0;
}

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

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'



signed main() {
    fio();
    ll n, x, m;
    cin >> n >> x >> m;

    vll dp(m, vl(40));
    vll sum(m, vl(40));
    rep (i, m) {
        dp[i][0] = (ll)i * i % m;
        sum[i][0] = i;
    }

    for (int j = 1; j < 40; j++) {
        rep (i, m) {
            dp[i][j] = dp[dp[i][j - 1]][j - 1];
            sum[i][j] = sum[i][j - 1] + sum[dp[i][j - 1]][j - 1];
        }
    }
    // DEBUG_MAT(dp);
    // DEBUG_MAT(sum);

    ll now = x;
    ll ans = 0;
    while (n > 0) {
        ll mask = 1LL << 40;
        int cnt = 40;
        while (mask > n) {
            mask >>= 1;
            cnt--;
        }
        ans += sum[now][cnt];
        now = dp[now][cnt];
        n -= mask;
    }
    cout << ans << endl;
}

Measured memory_bytes: 73412
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

ll yaku(ll a, ll b){
    if(a>b) return yaku(b,a);
    return b%a ? yaku(b%a,a) : a;
}
int main(){
    ll N; cin>>N;
    vec d(N);
    rep(i,N) cin>>d[i];
    ll ret=d[0];
    REP(i,1,N) ret=yaku(ret,d[i]);
    cout<<ret<<endl;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
long long po(long long x){
	return x*x*x*x*x;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long x;
	cin>>x;
	for(int i=-150;i<=150;i++){
		for(int j=-150;j<=i;j++){
			if(po(i)-po(j)==x){
				cout<<i<<" "<<j;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3592
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];





int main(){
   long long a;
   cin>>a;
   vector <long long> vec(a);
   vector<long long> tes(1000000,0);
   rep(i,a){
       cin>>vec.at(i);
       tes.at(vec.at(i))++;
   }
   long long sum=0;
   rep(i,200002){
       sum+=tes.at(i)*(tes.at(i)-1)/2;
   }
   long long min=0;
   rep(i,a){
       cout<<max(min,(sum-tes.at(vec.at(i))+1))<<endl;
   }
}



Measured memory_bytes: 11904
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=0;
var obj={};
var abc=[];
for(var i=0;i<Arr.length;i++){
   if(n==0){
      if(i!=0){
         abc.sort(function(a,b){return a-b;});
         for(var k in obj){
            if(obj[k]==abc[0]){console.log(k);break;}
         }
      }
      if(Arr[i]==0)break;
      n=Arr[i];
      abc=[];
      obj={};
    }else{
      n--;
      var arr=Arr[i].split(" ").map(Number);
      var h=arr[1]/100;
      var bmi=Math.abs(22-arr[2]/(h*h));
      abc.push(bmi);
      obj[arr[0]]=bmi;
   }
}

Measured memory_bytes: 11072
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;

int n,k,ans = 0,flg = 0;
int a[500005];
int mx[500005] = {0};

int main(){
	ios::sync_with_stdio(false); 
	cin >> n;
	memset(mx,-0x3f,sizeof(mx));
	mx[0] = 0;
	for(int i = 1;i <= n;i ++) cin >> a[i];
	for(int i = 1;i <= n;i ++){
		if(a[i] == 1) flg = 1;
		mx[a[i]] = max(mx[a[i]],mx[a[i] - 1] + 1);
		ans = max(ans,mx[a[i]]);
	}
	if(!flg) cout << -1 << endl;
	else cout << n - ans << endl;
	return 0;
}

Measured memory_bytes: 2944
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Long> list = new ArrayList<>();
        int n  = sc.nextInt();

        for (int i = 0; i < n; i++) {
            list.add(sc.nextLong());
        }
        List<Long> ans = new ArrayList<>(list);
        Collections.sort(list);

        long high, low;
        high = list.get((n / 2));
        low = list.get((n / 2) - 1);

        for (long num : ans){
            System.out.println( num < high ? high : low);
        }

    }
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
  string a,b,c;cin >> a >> b >> c;
  cout << a[0] << b[0]<< c[0] << endl;
    
    

}


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

//ユークリッドの互除法
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll A,B;
cin>>A>>B;
ll k=gcd(A,B);
vector<ll> cd;
for(ll i=2;i*i<k;i++){
    if(k%i==0){
        cd.pb(i);
        while(k%i==0){
            k/=i;
        }
    }
}

if(k>1)cd.pb(k);
cout<<cd.size()+1<<endl;
 
//system("pause");
return 0;
}

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

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}
bool b[100000];

int main(){
    ll n,m; cin >> n >> m;
    ll a[n+1];a[0] = 1;
    for(int i = 0;i < m;i++){
        ll x; cin >> x;
        b[x] = true;
    }
    
    if(!b[1]) {
        a[1] = 1;
    }else{
        a[1] = 0;
    }
    
    for(int i = 2;i <= n;i++){
        a[i] = 0;
        if(!b[i]){
            if(!b[i-1]){
                a[i] += a[i-1];
            }
            if(!b[i-2]){
                a[i] += a[i-2];
            }
        }
        a[i] %= MOD;
    }
    cout << a[n];
    
    
}



Measured memory_bytes: 4368
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <deque>

using namespace std;

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

	int n, a;
	cin >> n >> a;

	int t = n % 500;
	if (t <= a) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <climits>
using namespace std;

bool comp(pair<int, string> a, pair<int, string> b){
  if(a.first != b.first) return a.first > b.first;
  else return a.second < b.second;
}
 
int main(){
  string w;
  cin >> w;

  bool flag = true;

  for(int i = 0; i < w.size(); ++i){
    int count = 0;
    for(int j = 0; j < w.size(); ++j){
      if(w[i] == w[j])
        count++;
    }
    if(count % 2 == 1){
      flag = false;
    }
  }


    if(flag)
      cout << "Yes";
    else
      cout << "No";

  cout << endl;
}

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

int n;
int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

signed main()
{
	cin>>n;
	cout<<a[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
n1 = int(input())

na1 = [int(i) for i in input().split()]

r1 = 100000
for i1 in range(n1 - 1):
    na2 = na1[0:i1 + 1]
    na3 = na1[i1 + 1:n1]

    r1 = min(r1, abs(sum(na2) - sum(na3)))

print(r1)



Measured memory_bytes: 2940
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(K: int):
    return (K // 2) * (K // 2 + (K % 2))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    result = solve(K)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5140
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}


int main(){
  char a,b;
  cin>>a>>b;
  if((a=='H'&&b=='H')||(a=='D'&&b=='D')) cout<<'H'<<endl;
  else cout<<'D'<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 #define ll long long
int main(){
 
  ll int n;
  cin>>n;
  vector<ll int>arr(n);
  for(ll int i=0;i<n;i++)cin>>arr[i];
  
  ll int ans=0;
  
  for(ll int i=1;i<n;i++){
    
    if(arr[i-1]>arr[i]){
    	ans+=arr[i-1]-arr[i];
      arr[i] = arr[i-1];
    }
    
  }
  
  cout<<ans<<endl;
  
  
}

Measured memory_bytes: 4764
import qualified Data.ByteString as B
import qualified Data.IntMap     as M
import           Data.List

main :: IO ()
main = do
    [_, m] <- readInts <$> B.getLine
    as <- readInts <$> B.getLine
    print $ solve m as

readInts :: B.ByteString -> [Int]
readInts = map readInt . B.split 0x20

readInt :: B.ByteString -> Int
readInt xs
    | B.null xs = 0
    | y == 0x20 = 0
    | otherwise = (fromIntegral y - 0x30) + 10 * readInt ys
    where Just (ys, y) = B.unsnoc xs

solve :: Int -> [Int] -> Int
solve m =  M.foldl' (+) 0
     . fmap (\x -> x * (x - 1) `div` 2)
     . foldr (M.alter $ return . maybe 1 succ)  M.empty
     . map (`mod` m)
     . scanl' (+) 0

Measured memory_bytes: 20092
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;

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

   int a, b;
   cin >> a >> b;

   int ans = a;
   if (b < a) {
      --ans;
   }

   outl(ans);
}




Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define ARRAY_SIZE 5
int main()
{
	char inputN[ARRAY_SIZE];

	scanf("%s", inputN);

	if (strcmp(inputN, "AAA") == 0 || strcmp(inputN, "BBB") == 0)
	{
		printf("No \n");
	}
	else
	{
		printf("Yes \n");
	}
	
	return 0;
}

Measured memory_bytes: 128
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

ans1 = 0
for i in range(0, X + 1):
    if i in A:
        ans1 += 1

ans2 = 0
for i in range(X, N):
    if i in A:
        ans2 += 1

ans = min(ans1, ans2)
print(ans)


Measured memory_bytes: 9108
ab = list(map(int, input().split()))
a = ab[0]
b = ab[1]

s = list(input())
fff = "Yes"

for i in range(0, len(s)):
    if i == a:
        if s[i] != "-":
            fff = "No"
    else:
        if s[i] not in "0123456789":
            fff = "No"

print(fff)

Measured memory_bytes: 3064
n = int(input())
prime = [2]
for i in range(3,n+1,2):
  for j in prime:
    if i % j == 0:
      break
    elif i**0.5 < j:
      prime.append(i)
      break
di = dict(zip(prime,[0]*len(prime)))
for i in range(1,n+1):
  for j in prime:
    if i == 1:
      break
    c = 0
    while i % j == 0:
      i = i//j
      c += 1
    di[j] += c
a = len([i for i in di.values() if i >= 74])
b = len([i for i in di.values() if i >= 24])
c = len([i for i in di.values() if i >= 14])
d = len([i for i in di.values() if i >= 4])
e = len([i for i in di.values() if i >= 2])
print(a + b*(e-1) + c*(d-1) + d*(d-1)*(e-2)//2)

Measured memory_bytes: 39024
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);

		int a = stdIn.nextInt();
		int b = stdIn.nextInt();

		if ((a * b) % 2 == 0) {
			System.out.println("Even");
		}else{
			System.out.println("Odd");
		}
	}

}


Measured memory_bytes: 19796
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int res = 0;
        for (int i = a[0]; i <= a[1]; i++)
        {
            var s = i.ToString();
            if (s[0] == s[4] && s[1] == s[3]) res++;
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 15316
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int mod=1e9+7;
const int64_t INF=1e18;

int main() {
  int N;
  string s,t;
  cin>>N>>s>>t;
  string r=s;
  reverse(r.begin(),r.end());
  for(int l=N;l>=0;l--){ 
    string k=r.substr(0,l);
    reverse(k.begin(),k.end());
    if(k==t.substr(0,l)){cout<<2*N-l<<endl;return 0;}
  }
  return 0;  
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
typedef struct aaaaa{
  int x,y,t;
}Grid;
using namespace std;
ll calc(ll b,ll n){
  ll ret=0;
  while(n>=b){
    ret += n%b;
    n/=b;
  }
  return ret+n;
}
int main(){
  ll n,s;cin>>n>>s;
  if(n==s){
    cout<<n+1<<endl;
    return 0;
  }
  for(ll i=2;i<=sqrt(n);i++){
    if(s == calc(i,n)){
      cout<<i<<endl;
      return 0;
    }
  }
  ll ans=llINF;
  for(ll i=1;i<sqrt(n);i++){
    if((n-s)%i!=0)continue;
    ll b=(n-s)/i+1;
    if(b>0){
    if(s == calc(b,n)){
      ans=min(ans,b);
    }
    }
  }
  if(ans==llINF)
  cout<<-1<<endl;
  else
    cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#python3
from operator import itemgetter 
from itertools import accumulate
def main():
    n = int(input())
    d = []
    for _ in range(n):
        x, y = map(int, input().split())
        d.append((x, y))
    d.sort(key=itemgetter(1))
    acc = 0
    f = True
    for i in range(n):
        acc = acc+d[i][0] 
        if acc > d[i][1]:
            f = False
    if f:
        print('Yes')
    else:
        print('No')
main()


Measured memory_bytes: 75352
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int x;
bool prime(int x){
	for(int i=2;i*i<=x;i++){
		if(x%i==0)
			return false;
	}
	return true;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>x;
	for(int i=x;;i++){
		if(prime(i)){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main(void){
    double r;
    std::cin >> r;
    
    std::cout << std::fixed;
    std::cout << std::setprecision(5)<<r*r*M_PI<<" "<<std::setprecision(5)<<r*2*M_PI<<std::endl;
}


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

#define ll long long
#define mod 1000000007

using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,t;
    cin>>n>>t;
    ll c[n+1],tt[n+1];
    vector<pair<ll,ll>>v;
    for(int i=1;i<=n;i++){
        cin>>c[i]>>tt[i];
        v.push_back({c[i],tt[i]});
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        if(v[i-1].second<=t){
            cout<<v[i-1].first<<endl;return 0;
        }
    }
    cout<<"TLE\n";
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
 
using namespace std;
 
int main() {
    int N;
    cin >> N;
 
    // AC, WA, TLE, RE
    int C[4] = {};
    string tmp;
 
    for (int i=0; i < N; i++) {
        cin >> tmp;
        if(tmp == "AC"){
            C[0]++;
        } else if (tmp == "WA") {
            C[1]++;
        } else if (tmp == "TLE") {
            C[2]++;
        } else if (tmp == "RE") {
            C[3]++;
        }
    }
 
    cout << "AC x " << C[0] << endl;
    cout << "WA x " << C[1] << endl;
    cout << "TLE x " << C[2] << endl;
    cout << "RE x " << C[3] << endl;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

string s;

main() {
    cin >> s;
    s[3] = '8';
    ct(s)
}






Measured memory_bytes: 256
a,b,c,x,y=list(map(int,input().split()))

#abピザをab枚使う
ans=float("INF")
for ab in range(0,2*max(x,y)+1,2):
  #使うお金
  #ABピザ
  cnt=ab*c
  #Aピザ
  cnt+=a*max(0,x-ab//2)
  #Bピザ
  cnt+=b*max(0,y-ab//2)
  ans=min(cnt,ans)

print(ans)

  
  

Measured memory_bytes: 65748
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int i = 0; i<5; i++) {
		int a = sc.nextInt();
		if(a == 0) {
			System.out.println(i+1);
			System.exit(0);
		}
		}
		sc.close();
	}
}

Measured memory_bytes: 35724
n, x = map(int, input().split())
a = list(map(int,input().split()))
a.sort()
c = 0
while x-a[c] >= 0:
    x -= a[c]
    c += 1
    if x == 0:
        break
    elif c == n:
        c -= 1
        break
print(c)

Measured memory_bytes: 38384