akhauriyash/Code-Regression huggingface dataset:
// AOJ ITP1_10_C Standard Deviation
// 2018.4.28 bal4u

#include <stdio.h>
#include <math.h>

int s[1002];

#define gc() getchar_unlocked()
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc();
	while (c >= '0');
	return n;
}

int main()
{
	int n, i, is;
	double m, fs, a;
	
	while (n = in()) {
		is = 0; for (i = 0; i < n; i++) is += s[i] = in();
		m = (double)is/n;
		fs = 0; for (i = 0; i < n; i++) {
			a = s[i]-m;
			fs += a*a;
		}
		printf("%.8lf\n", sqrt(fs/n));
	}
	return 0;
}


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

using namespace std;

using i64 = int64_t;


signed main(){
    int h, r;
    cin >> h >> r;
    if(-h == r){
        cout << 0 << endl;
    }
    else if(h < 0 && abs(h) > r){
        cout << -1 << endl;
    }
    else
        cout << 1 << endl;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

ll dp[110000][3];

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N; cin >> N;
    vll a(N), b(N), c(N);
    rep(i,N) cin >> a[i] >> b[i] >> c[i];

    for(ll i = 1; i <= N; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i-1];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i-1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i-1];
    }

    ll ans = 0;
    rep(j, 3) chmax(ans, dp[N][j]);
    cout << ans << endl;
}


Measured memory_bytes: 4992
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)
#input = sys.stdin.readline
from bisect import bisect_left

def dfs(i,before):
    global seq
    global ans
    added  = 0

    #現在地のAの値を、以前までのseqリストのどこに追加するか決める
    pos = bisect_left(seq,a[i-1])
    old = seq[pos]
    seq[pos]=a[i-1]
    ans[i-1]=bisect_left(seq,INF)

    #隣接する頂点に関して再帰
    for u in to[i]:
        if u==before:
            continue
        dfs(u,i)

    #seq配列をもとに戻す
    seq[pos]=old


N = I()
a = LI()
to = [[] for i in range(N+1)]
to[0] += [1]
for i in range(N-1):
    u,v = MI()
    to[u].append(v)
    to[v].append(u)
seq = [INF]*N
ans = [-1]*N

dfs(1,-1)
[print(i) for i in ans]


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int H, W;
  cin >> H >> W;
  int c[10][10];
  REP(i, 10)
  REP(j, 10)
  cin >> c[i][j];
  int A[H][W];
  REP(i, H)
  REP(j, W)
  cin >> A[i][j];
  REP(k, 10)
  REP(i, 10)
  REP(j, 10)
  c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
  ll ans = 0;
  REP(i, H)
  REP(j, W)
  {
    if (A[i][j] != -1)
      ans += c[A[i][j]][1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include<cstdio>
int n,m,i,u[999999],a[999999];
int main(){
  scanf("%d%d",&n,&m);
  for(i=0;i<m;i++) scanf("%d",a+i+1);
  for(;i>0;i--) if(!u[a[i]]) printf("%d\n",a[i]),u[a[i]]=1;
  for(;i<n;i++) if(!u[i+1]) printf("%d\n",i+1);
  return 0;
}

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

int main(){
    int a,b,c,t;
    while(cin>>a>>b>>c,a){
        pint q[2];
        if(b*b-4*a*c<0){
            cout<<"Impossible"<<endl;continue;
        }
        rep(i,2){
            q[i].first=2*a;q[i].second=(int)round(-b+(i==0?1:-1)*sqrt(b*b-4*a*c));
            t=__gcd(abs(q[i].first),abs(q[i].second));
            if(q[i].first<0) t*=-1;
            q[i].first /=t;q[i].second /=-t;
        }
        sort(q,q+2,greater<pint>());
        bool flag=false;
        if(a==q[0].first*q[1].first){
            if(b==q[0].first*q[1].second+q[1].first*q[0].second){
                if(c==q[0].second*q[1].second) flag=true;
            }
        }
        if(flag) cout<<q[0].first<<" "<<q[0].second<<" "<<q[1].first<<" "<<q[1].second<<endl;
        else cout<<"Impossible"<<endl;
    }
    return 0;
}

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

using namespace std;

#define ll long long int
#define MOD 1000000007
#define mt make_tuple
#define eb emplace_back
#define error(args...){string _s = #args; replace(_s.begin(),_s.end(),',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args){cerr<<*it<<" = "<<a<<endl; err(++it,args...);}



int main()
{
    ll i,j,k,l,n,m;
    string s,t;
    cin>>s>>t;
    s = s + s;
    bool an=true;
    for(i=0;i<s.size()-t.size();++i){
        if(s.substr(i,t.size())==t){
            an=false;
            break;
        }
    }
    if(!an)
        cout<<"Yes";
    else
        cout<<"No";

	return 0;
}


Measured memory_bytes: 256
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g


n,k = map(int,input().split())

print(n-k+1)









Measured memory_bytes: 3060
"use strict";

function Main(input) {
    input=input.split("\n");
    var line=input[1].split(" ").map(Number),ans="";
    line.reverse();
    for(var value in line)
        ans+=line[value]+" ";
    console.log(ans.trim());
}
    
function debug(){
	var input = document.getElementById("input").value;
	Main(input);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 15760
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    if ((100 * r + 10 * g + b) % 4 == 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
s = input()


def calc_lr(block):
    len_block = len(block)
    if len_block % 2 == 0:
        return (len_block//2, len_block//2)
    else:
        if block.index("L") % 2 == 1:
            return (-(-len_block//2), len_block//2)
        else:
            return (len_block//2, -(-len_block//2))


prev = ""
part = ""
ans = [0]*len(s)
for idx, c in enumerate(s):
    if prev == "R" and c == "L":
        idx_pair = (idx-1, idx)

    if prev == 'L' and c == "R":
        left, right = calc_lr(part)
        i, j = idx_pair
        ans[i] = left
        ans[j] = right
        part = c
    else:
        part += c
    prev = c
else:
    left, right = calc_lr(part)
    i, j = idx_pair
    ans[i] = left
    ans[j] = right


print(*ans)

Measured memory_bytes: 6512
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    string str;

    while(cin >> str)
    {
		ll sum = 0;

		for(auto it: str)
		{
			sum += (it - '0');
		}

		if(sum % 9 == 0) cout << "Yes\n";
		else cout << "No\n";
    }

}




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

using namespace std;
int main()
{
char a[100];
for(int i=0;i<=18;i++)
cin>>a[i];
for(int i=0;i<=4;i++)
cout<<a[i];
cout<<" ";
for(int i=6;i<=12;i++)
cout<<a[i];
cout<<" ";
for(int i=14;i<=18;i++)
cout<<a[i];
return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) prllf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

string S;

int main()
{
    cin >> S;
    ll ans = S.length() / 2;
    char base = S[ans];

    ll c_l, c_r;
    if(S.length() % 2 == 0) {
        c_l = ans - 1;
        c_r = ans;
    } else {
        c_l = ans - 1;
        c_r = ans + 1;
        if(S.length() == 1) {
            printf("1\n");
            return 0;
        }
        ans++;
        if(S[c_l] != S[c_r] || S[c_l] != base) {
            printf("%lld\n", ans);
            return 0;
        }
    }
    while(ans < S.length()) {
        ans++;
        if(S[c_l] != S[c_r] || S[c_l] != base) {
            ans--;
            break;
        }
        c_l--;
        c_r++;
    }

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


Measured memory_bytes: 512
#2問目
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
idouA = 0
idouB = 0
kankaku = 0

#逃げる方が大きかったら確実に捕まえられない
if W >= V:
    print("NO")
else:
    idouA = V * T
    idouB = W * T
    if A < B:
        if A < 0 and B < 0:
            kankaku = abs(A) - abs(B)
        elif A >= 0 and B >= 0:
            kankaku = abs(B) - abs(A)
        elif A <= 0 and B >= 0:
            kankaku = B - A
    elif B < A:
        if A < 0 and B < 0:
            kankaku = abs(B) - abs(A)
        elif A >= 0 and B >= 0:
            kankaku = abs(A) - abs(B)
        elif A >= 0 and B <= 0:
            kankaku = A - B
            
    if(idouB + kankaku <= idouA):
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9236
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <climits>
#include <utility>

using namespace std;

#define int long long
#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 all(a) begin(a),end(a)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

signed main()
{
	int y;cin>>y;
	int ans=y/500*1000;
	y%=500;
	ans+=y/5*5;
	cout <<ans<<endl;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	string s;
	cin >> s;
	rep(i,s.size())
	{
		if(s[i] == ',') cout << ' ';
		else cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
Module Module1

    Dim SS() As String

    Sub Main()
        Dim str As String = Console.ReadLine
        Dim S(str.Length - 1) As String

        For i As Integer = 0 To str.Length - 1
            S(i) = str.Substring(i, 1)
        Next

        SS = S

        Console.WriteLine(Dfs(0, SS(0)))
        Debug.WriteLine(Dfs(0, SS(0)))
    End Sub

    Function Dfs(i As Integer, f As String) As Long

        If i >= SS.Length - 1 Then
            Dim arr() As Long = Array.ConvertAll(Of String, Long)(f.Split("+"), AddressOf Long.Parse)
            Dim r As Long = 0
            For Each a In arr
                r += a
            Next
            Return r
        End If

        ' 分割しない場合＋分割する場合
        Return Dfs(i + 1, f + SS(i + 1)) + Dfs(i + 1, f + "+" + SS(i + 1))

    End Function
End Module


Measured memory_bytes: 27524
#include<bits/stdc++.h>
using namespace std;
#define int long long 

struct line
{
    int m, c;
    int eval(int x)
    {
        return (m*x+c);
    }
    double intersect(line &o)
    {
        return (double)(c-o.c)/(o.m-m);
    }
};

int32_t main()
{
    int n, c;
    cin>>n>>c;
    vector<int>h(n);
    for(auto &x: h)
        cin>>x;
    
    deque<line>q;
    int qs=1;
    q.push_back({-2*h[n-1], h[n-1]*h[n-1]});
    int dp=0;
    for(int i=n-2; i>=0; --i)
    {
        while(qs>1 && q[0].eval(h[i])>=q[1].eval(h[i]))
        {
            q.pop_front();
            qs--;
        }
        dp=q[0].eval(h[i])+h[i]*h[i]+c; 
        line nl={-2*h[i], dp+h[i]*h[i]};
        while(qs>1 && q[qs-1].intersect(nl)>=q[qs-2].intersect(q[qs-1]))
        {
            q.pop_back();
            qs--;
        }
        q.push_back(nl);
        qs++;
    }
    cout<<dp;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

string solve(int x,int y,int z){
    if(x==0){
        string s=solve(y,z,0);
        rep(i,s.size()){
            if(s[i]=='a')s[i]='b';
            else if(s[i]=='b')s[i]='c';
        }
        return s;
    }
    if(y==0&&z){
        string s=solve(x,z,0);
        rep(i,s.size()){
            if(s[i]=='b')s[i]='c';
        }
        return s;
    }

    if(y==0)return string(x,'a');

    if(z==0){
        if(x<=y){
            string s=solve(x,y%x,0);
            string t;
            rep(i,s.size()){
                if(s[i]=='a'){
                    t+="a";
                    t+=string(y/x,'b');
                }
                else{
                    t+="b";
                }
            }
            return t;
        }
        string s=solve(x-y,y,0);
        string t;
        rep(i,s.size()){
            if(s[i]=='a'){
                t+="a";
            }
            else{
                t+="ab";
            }
        }
        return t;
    }

    if(x<=z){
        string s=solve(x,y,z%x);
        string t;
        rep(i,s.size()){
            if(s[i]=='a'){
                t+="a";
                t+=string(z/x,'c');
            }
            else if(s[i]=='b'){
                t+="b";
            }
            else{
                t+="c";
            }
        }
        return t;
    }


    int q=y%(x-z);
    int p=x-z-q;
    int r=z;

    string s=solve(p,q,r);
    string t;
    rep(i,s.size()){
        if(s[i]=='a'){
            t+="a";
            t+=string(y/(x-z),'b');
        }
        else if(s[i]=='b'){
            t+="a";
            t+=string(y/(x-z)+1,'b');
        }
        else{
            t+="ac";
        }
    }
    return t;
}

signed main(){
    int X,Y,Z;
    cin>>X>>Y>>Z;
    cout<<solve(X,Y,Z)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin>>n;
  if (n[n.length()-1]=='2' || n[n.length()-1]=='4' || n[n.length()-1]=='5' || n[n.length()-1]=='7' || n[n.length()-1]=='9' )
    cout<<"hon\n";
  else if(n[n.length()-1]=='0' ||n[n.length()-1]=='1' ||n[n.length()-1]=='6' ||n[n.length()-1]=='8' )
    cout<<"pon\n";
  else if(n[n.length()-1]=='3')
    cout<<"bon\n";
}


Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i = a;i < b;i++)
#define _rep(i,a,b) for(int i = a;i <= b;i++)
typedef long long ll;

int main() {
	char s[110];
	cin >> s;
	ll k;
	cin >> k;
	int n = strlen(s);
	int num[110];
	int cnt = 0,cur = 1;
	for(int i = 1;i < n;i++) {
		if(s[i] == s[i-1]) cur++;
		else {
			num[cnt++] = cur;
			cur = 1;
		}
	}
	if(cur != 1 || n == 1) num[cnt++] = cur;

	ll ans = 0;
	if(cnt != 1) {
		for(int i = 1;i < cnt-1;i++) {
			ans += num[i]/2;
		}
		ans = ans*k;
		if(s[0] == s[n-1]) {
			ans += num[0]/2;
			ans += num[cnt-1]/2;
			ans += (num[0]+num[cnt-1])/2*(k-1);
		}
		else ans += (num[0]/2+num[cnt-1]/2)*k;
	}
	else {
		ans = n*k/2;
	}

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


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

int main(){
	int h[2],m[2],s[2];
	for(int i=0;i<3;i++){
		scanf("%d%d%d%d%d%d",&h[0],&m[0],&s[0],&h[1],&m[1],&s[1]);
		h[1]-=h[0];
		m[1]-=m[0];
		s[1]-=s[0];
		if(s[1]<0){
			m[1]--;
			s[1]+=60;
		}
		if(m[1]<0){
			h[1]--;
			m[1]+=60;
		}
		printf("%d %d %d\n",h[1],m[1],s[1]);
	}
}

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

using namespace std;

#define ll long long

const int nax = 3005;

ll dp[nax][nax];

int main()
{
	int n;
	cin >> n;

	vector<int> arr(n);
	for (int i = 0; i < n; i++)
	{	
		cin >> arr[i];
	}

	for (int L = n - 1; L >= 0; L--)
	{
		for (int R = L; R < n; R++)
		{
			if (R == L)
			{
				dp[L][R] = arr[L];
			}
			else
			{
				dp[L][R] = max(arr[L] - dp[L + 1][R], arr[R] - 
				dp[L][R - 1]);
			}
		}
	}

	cout << dp[0][n - 1] << endl;
}

Measured memory_bytes: 70016
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  if (a > 0) cout << b / x - (a - 1) / x << endl;
  else cout << b / x + 1 << endl;
}


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

using namespace std;

const int mod = 1e9 + 7;

int add() { return 0; }
template<typename... M> int add(int a, M... b) {
  int x = add(b...);
  return a + x - mod * (a + x >= mod);
}

int mul() { return 1; }
template<typename... M> int mul(int a, M... b) {
  return int(1ll * a * mul(b...) % mod);
}

int pwr(int a, long long x) {
  return (x ? mul(pwr(mul(a, a), x >> 1), (x & 1 ? a : 1)) : 1);
}

int dvd(int a, int b) {
  return mul(a, pwr(b, mod - 2));
}

int sub(int a, int b) {
  return a - b + mod * (a < b);
}

void inc(int& a, int b) {
  a = add(a, b);
}

void dec(int& a, int b) {
  a = sub(a, b);
}

const int N = 2e5 + 10;
vector<int> g[N];
int sz[N], ans[N], dp[N], f[N], inv[N];

int C(int n, int k) {
  if (k < 0 or k > n) {
    return 0;
  }
  return mul(f[n], inv[n - k], inv[k]);
}

void dfs(int v = 0, int p = -1) {
  sz[v] = 1;
  for (int to : g[v]) {
    if (to == p) {
      continue;
    }
    dfs(to, v);
    sz[v] += sz[to];
  }
  dp[v] = f[sz[v] - 1];
  for (int to : g[v]) {
    if (to != p) {
      dp[v] = mul(dp[v], dp[to], inv[sz[to]]);
    }
  }
}

void zhfs(int v = 0, int p = -1) {
  ans[v] = dp[v];
  for (int to : g[v]) {
    if (to == p) {
      continue;
    }
    dp[v] = dvd(dp[v], dp[to]);
    dp[v] = dvd(dp[v], C(sz[v] - 1, sz[to]));
    sz[v] -= sz[to];
    sz[to] += sz[v];
    dp[to] = mul(dp[to], dp[v]);
    dp[to] = mul(dp[to], C(sz[to] - 1, sz[v]));
    zhfs(to, v);
    dp[to] = dvd(dp[to], C(sz[to] - 1, sz[v]));
    dp[to] = dvd(dp[to], dp[v]);
    sz[to] -= sz[v];
    sz[v] += sz[to];
    dp[v] = mul(dp[v], C(sz[v] - 1, sz[to]));
    dp[v] = mul(dp[v], dp[to]);
  }
}

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

  int n;
  cin >> n;
  f[0] = inv[0] = 1;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
    f[i] = mul(f[i - 1], i);
    inv[i] = dvd(inv[i - 1], i);
  }
  dfs();
  zhfs();
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}


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


def convert_decimal_to_n_ary_number(n: int, m_ary_number: int = 2) -> int:
    '''Represents conversion from decimal number to n-ary number.
    Args:
        n: Input number (greater than 1).
        m_ary_number: m-ary number (from 2 to 10).
    Returns:
        values of m-ary number.
    Landau notation: O(log n)
    '''
    if n < m_ary_number:
        return n

    ans = ''

    while n >= m_ary_number:
        p, q = divmod(n, m_ary_number)
        n = p
        ans += str(q)

        if n < m_ary_number:
            ans += str(p)

    return int(ans[::-1])


def main():
    n, k = map(int, input().split())
    print(len(str(convert_decimal_to_n_ary_number(n, k))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;

///aとbの最大公約数を求める関数。計算量はO(log min(a, b))
Int Gcd(Int a, Int b) {
	if (a % b == 0)return b;
	else return Gcd(b, a % b);
}

void calc() {

	Int K; std::cin >> K;
	Int sum = 0;

	for (Int i = 1; i <= K; ++i)for (Int j = 1; j <= K; ++j)for (Int k = 1; k <= K; ++k) {
		sum += Gcd(i, Gcd(j, k));
	}

	std::cout << sum;

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

vector<int> Zalgo(const string &S) {
	int N = (int)S.size();
	vector<int> res(N);
	res[0] = N;
	int i = 1, j = 0;
	while (i < N) {
		while (i + j < N && S[j] == S[i + j]) ++j;
		res[i] = j;
		if (j == 0) { ++i; continue; }
		int k = 1;
		while (i + k < N && k + res[k] < j) res[i + k] = res[k], ++k;
		i += k, j -= k;
	}
	return res;
}

int main() {
	int N;
	string S;
	cin >> N >> S;
	int res = 0;
	for (int i = 0; i < N; ++i) {
		string T = S.substr(i);
		auto lcp = Zalgo(T);
		for (int j = 0; j < T.size(); ++j) {
			int l = min(lcp[j], j);
			res = max(res, l);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 384
//Union-Find??¨
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

//class DisjointSet
class DisjointSet{
	public:
		vector<int> rank, p;//rank:??¨????????? p:??????????????????
		DisjointSet(){}
		DisjointSet(int size){//???????????°
			rank.resize(size, 0);
			p.resize(size, 0);
			rep(i, size) makeSet(i);
		}
		void makeSet(int x){
			p[x] = x;
			rank[x] = 0;
		}
		//????????¨??????????????????????????????????????????
		bool same(int x, int y){
			return findSet(x) == findSet(y);
		}
		// ??¨?????????????????£?????????
		void unite(int x, int y){
			link(findSet(x), findSet(y));
		}
		//??¨??????????????????????????¨?????????????????£?????????
		void link(int x, int y){
			if(rank[x] > rank[y]){
				p[y] = x;
			}else{
				p[x] = y;
				if(rank[x] == rank[y]) rank[y]++;
			}
		}
		//????????¢???
		int findSet(int x){
			if(x != p[x]){
				p[x] = findSet(p[x]);
			}
			return p[x];
		}
};

static const int MAX_W = 100001, MAX_H = 100001;

int main(void){
	int n, w, h;
	bool cornerw = false, cornerh = false;
	cin >> n >> w >> h;
	//??????????????????????????\???????????¨?????¨????????????????????????????????¨???????????§????????????????????\??£?????????????????????????¢????????????????
	vector<int> memoX(w, -1);//???
	vector<int> memoY(h, -1);//???
	DisjointSet ds = DisjointSet(n);

	rep(i, n){
		int x, y;
		scanf("%d %d", &x, &y);
		x--; y--;//0origin
		if(x == 0 || x == w - 1) cornerw = true;
		if(y == 0 || y == h - 1) cornerh = true;
		//?????¨?¨??????§?????????????????????
		//????????????????????????????????????x??§?¨???¨y??§?¨??????±???????????????????????£?????????????????¨?????§??????
		if(memoX[x] < 0) memoX[x] = i;//???????????????????????????????????\??£????????¨???????????°X[???]=????????????????????\??????
		else ds.unite(i, memoX[x]);//?????§????????????????????????????????\??£???????????°???????????????????????¨?????£?????????
		if(memoY[y] < 0) memoY[y] = i;
		else ds.unite(i, memoY[y]);
	}
	/*
	rep(i, w){
		if(memoX[i] != -1) m++;
	}
	???????????¨?????????????????????????????£??????
	*/
	set<int> sum;
	rep(i, w){
		if(memoX[i] != -1) sum.insert(ds.findSet(memoX[i]));
	}

	int m = sum.size();//??£?????????????????°

	//printf("%d\n", m);
	if(m > 1){
		if(cornerw == true || cornerh == true){
			printf("%d\n", n + m - 2);
		}else{
			printf("%d\n", n + m - 1);
		}
	}else{
		printf("%d\n", n - 1);
	}
	return 0;
}

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

typedef long long LL;
typedef pair<int, int> II;

const int MAXN = (int)1e5 + 10;
int n, l[MAXN], r[MAXN];
int len[MAXN];

void erase(multiset<LL> &s, LL val) {
    if (s.find(val) != s.end()) {
        s.erase(s.equal_range(val).first);
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &l[i], &r[i]);
        len[i] = r[i] - l[i];
    }

    multiset<LL> sl, sr;
    LL dl = 0, dr = 0;
    LL f_opt = 0;

    sl.insert(l[1]);
    sr.insert(l[1]);
    for (int i = 2; i <= n; ++i) {
        dl -= len[i];
        dr += len[i - 1];

        if (l[i] <= *sl.rbegin() + dl) {
            sl.insert(l[i] - dl);
            sl.insert(l[i] - dl);
            sr.insert(*sl.rbegin() + dl - dr);
            erase(sl, *sl.rbegin());
            f_opt += abs(*sr.begin() + dr - l[i]);
        } else if (l[i] >= *sr.begin() + dr) {
            sr.insert(l[i] - dr);
            sr.insert(l[i] - dr);
            sl.insert(*sr.begin() + dr - dl);
            erase(sr, *sr.begin());
            f_opt += abs(*sl.rbegin() + dl - l[i]);
        } else {
            sl.insert(l[i] - dl);
            sr.insert(l[i] - dr);
        }
    }

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

Measured memory_bytes: 10752
def actual(n, a_list):
    points = [0 for _ in range(n)]

    for supervisor_idx in a_list:
        points[supervisor_idx - 1] += 1

    for p in points:
        print(p)

    return points

n = int(input())
a_list = map(int, input().split())

actual(n, a_list)

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll N,K; cin >> N >> K;
    VL A(N); REP(i,N) cin >> A[i];
    SORT(A);
    VL B(A); REVERSE(B);

    ll xl = -1000000000000000001, xr = -xl, X = (xl+xr)/2;
    while(xr-xl>1){
        ll tmpK = 0;
        REP(i,N-1){
            if(A[i] < 0){
                int l = -1, r = N-1-i, t = (l+r)/2;
                while(r-l>1){
                    if(A[i]*B[t] <= X) l = t;
                    else r = t;
                    t = (l+r)/2;
                }
                tmpK += r;
            }
            else{
                int l = i, r = N, t = (l+r)/2;
                while(r-l>1){
                    if(A[i]*A[t] <= X) l = t;
                    else r = t;
                    t = (l+r)/2;
                }
                tmpK += r-i-1;
            }
        }

        if(tmpK < K) xl = X;
        else xr = X;
        X = (xl+xr)/2;
    }
    cout << xr << endl;
    return 0;
}

Measured memory_bytes: 3456
h, w = map(int, input().split())
s = [list(input().split()) for i in range(h)]
li = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(h):
    for j in range(w):
        if s[i][j] == "snuke":
            print(li[j]+str(i+1))

Measured memory_bytes: 3060
#[allow(dead_code)]
fn rd() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().to_owned()
}

/// 1行の文字を空白で分割してVec<T>にする。
#[allow(dead_code)]
fn rd_vec<T : std::str::FromStr>() -> Vec<T> {
    rd().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

/// 1つの要素を入力で受け取る
#[allow(dead_code)]
fn rd_one<T : std::str::FromStr>() -> T {
    rd().parse().ok().unwrap()
}

/// 複数回read_splitを行う
#[allow(dead_code)]
fn rd_vec_mul<T : std::str::FromStr>(count : i32) -> Vec<Vec<T>> {
    (0..count).map(|_| rd_vec()).collect()
}

/// Vecを1列で出力する
#[allow(dead_code)]
fn op_vec<T : std::fmt::Display>(item : Vec<T>, splitter : char) {
    let cnt = item.len();
    let mut c = 0;
    for i in item.iter() {
        c+=1;
        if cnt > c {print!("{}{}", i, splitter);} else {println!("{}", i);}
    }
}

fn main() {
    let n : usize = rd_one();
    let h_vec : Vec<i64> = rd_vec();
    let mut answer = 0;
    let mut hold = 0;
    for i in 1..n {
        if h_vec[i - 1] >= h_vec[i] {
            hold += 1;
        } else {
            if answer < hold {
                answer = hold;
            }
            hold = 0;
        }
    }
    println!("{}", if answer < hold {hold} else {answer});
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//bitset<32> bset1;
//char ch;
string S, T, U;
ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL
    //int A[n];
    //scan(n);
    cin>>n>>S>>T>>U;
    forr(i,n)
    {
        if(S[i]!=T[i] && S[i]!=U[i] && T[i]!=U[i])
        {
            cnt+=2;
            T[i]=S[i];
            U[i]=S[i];
        }
        else if(S[i]!=T[i] && S[i]==U[i])
        {
            cnt++;
            T[i]=S[i];
        }
        else if(S[i]==T[i] && S[i]!=U[i])
        {
            cnt++;
            U[i]=S[i];
        }
        else if(S[i]!=T[i] && T[i]==U[i])
        {
            cnt++;
            S[i]=T[i];
        }
    }
    //cout<<S<<endl;
    //cout<<T<<endl;
    //cout<<U<<endl;
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;


long long gcd(long long m, long long n){
    if(m < n){
        return gcd(n, m);
    }
    if(n == 0){
        return m;
    }
    return gcd(n, m % n);
}

int main(){ 
    long long A;
    long long B;
    cin >> A >> B;

    long long g = gcd(A, B);
    long long tmp = g;
    long long ans = 1;
    for(int i = 2; i < sqrt(g) + 1; i++){
        if(tmp % i == 0){
            ans += 1;
            while(tmp % i == 0){
                tmp /= i;
            }
        }
    }
    if(tmp != 1){
        ans += 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int n, m, x, p = 0, q = 0;
	cin >> n >> m >> x;
	int a[101];
	for (int i = 0;i < m;i++)cin >> a[i];
	for (int j = 0;a[j] < x;j++)p++;
	for (int j = m-1;a[j] > x;j--)q++;
	cout << min(p,q) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
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(b<a)a=b;}
const int INF = 1e8;

int main() {
  int n;cin >> n;
  vector<string> v(n);
  set<string> s;
  rep(i,n){
    cin >> v[i];
    s.insert(v[i]);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 25016
N = int(input())
S = [input() for _ in range(N)]
result = []
for alp in 'abcdefghijklmnopqrstuvwxyz':
  tmp = []
  for i in range(N):
    tmp.append(S[i].count(alp))
  for j in range(min(tmp)):
    result.append(alp)
print(''.join(result))

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
     
using namespace std;
     
int main(){
 int n;
 cin >> n;
 int i=1;
 while (i <=n) {
  int x=i;
  if (x%3 == 0) {
   cout << " " << i;
  } else {
   while (x!=0) {
    if (x%10==3) {
     cout << " " <<i;
     break;
    }
   x/=10;
   }
  }
 i++;
 }
 cout << endl;
 return 0;
}


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





int main(){
  int s,t;//queの最初と最後を示す.ｔはenqueの時に格納する場所を示す
  int *que;//ラウンドロビン。各プロセスは、読み込んだ時に数字をつけて管理する。
  char **name;//各プロセスに割り振られた数字と、各プロセスの名前を対応させる
  int *time;//各プロセスの残り時間を管理する
  int sumtime=0;
  int n,q;
  int i;
  int quesize;


  //領域確保  
  scanf("%d%d",&n,&q);
  que=malloc(n*sizeof(int));
  time=malloc(n*sizeof(int));
  name=malloc(n*sizeof(char *));
  for(i=0;i<n;i++) name[i]=malloc(100*sizeof(char));


  //読み込みとqueの準備
  for(i=0;i<n;i++){
    que[i]=i;
    scanf("%s%*[^1-9]%d",name[i],&time[i]);
  }
  s=0;
  t=0;
  quesize=n;
  
  
  while(1){
    if(time[que[s]]<=q){
      sumtime+=time[que[s]];
      printf("%s %d\n",name[que[s]],sumtime);
      s=(s+1)%n;
      quesize-=1;
      if(quesize==0) break;
    }
    else{
      sumtime+=q;
      time[que[s]]-=q;
      que[t]=que[s];
      s=(s+1)%n;
      t=(t+1)%n;
    }
  }
  return 0;
}
        


  


Measured memory_bytes: 7988
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (T i : v) os << i << ' ';
    return os;
}
void co() { cout << endl; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << endl; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void) {
    ll n, m;
    cin >> n >> m;
    scc_graph scc(n);
    while (m--) {
        ll a, b;
        cin >> a >> b;
        scc.add_edge(a, b);
    }

    auto v = scc.scc();
    co(v.size());
    for (auto &i : v) co(i.size(), i);

    return 0;
}


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

int main() {
    ll N;
    cin >>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.rbegin(),A.rend());
    ll w = 0;
    ll h =0;
    for(int i=0;i<N-1;i++){
        if(A[i] == A[i+1]){
            if(w==0){
                w = A[i];
            }else if (h==0){
                h = A[i];
            }
            i++;
        }
    }
    cout << w*h << endl;
    return 0;
}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    long ans = 1;
    for(int i=1; i<=n; i++) {
      ans = (ans*i)%(int)(Math.pow(10,9)+7);
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 32456
#include<bits/stdc++.h>
using  namespace std;
#define ll long long
#define pb push_back
#define sc second
#define fr first
#define mp make_pair
const int N = 2e5 + 10 , OO = 1e9 + 2, Max = 50 + 10;
const ll  MOD = 998244353 ;
int dp[N][4] , a[N][4];
int main() {
    int n , k ;
    cin >> n ;
    for(int i = 1;i<=n;++i) {
        for(int j = 1;j<=3;++j) {
            cin >> a[i][j];
        }
    }
    for(int i = 1;i<=n;++i) {
        for(int j = 1;j<=3;++j) {
            for(int k = 1;k<=3;++k) {
                if(j==k)continue;
                dp[i][j] = max(dp[i - 1][k] + a[i][j],dp[i][j]);
            }
        }
    }
    cout << max(dp[n][1],max(dp[n][2],dp[n][3])) << endl;
}


Measured memory_bytes: 5888
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		int[] dist = new int[totalVertex];
		
		//Set all to infinity and unsettled
		for(int i = 0; i < dist.length; i++) {
			dist[i] = Integer.MAX_VALUE;
		}
		
		//set source node to 0 and settled
		dist[s] = 0;
		//ifSettled[s] = true;
		
		for(int i = 0; i < totalVertex-1; i++) {
			int closest = getUnsettledNearest(dist);
			ifSettled[closest] = true;
			
			for(int j = 0; j < totalVertex; j++) {
				
			if(!ifSettled[j] && adjMatrix[closest][j] != 0 && dist[closest] != Integer.MAX_VALUE && dist[closest] + adjWeight[closest][j] < dist[j]){
					dist[j] = dist[closest] + adjWeight[closest][j];
				}
			}
		}
		return dist;
	}
	

}

	public class Main {
	    public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}



Measured memory_bytes: 40060
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  ll x;
  cin >> n >> x;

  ll b[n + 1], p[n + 1];
  b[0] = 0; p[0] = 1;
  for(int i = 1; i <= n; i++){
    b[i] = 2l * b[i - 1] + 2;
    p[i] = 2l * p[i - 1] + 1;
  }

  ll ans = 0;
  for(int i = n; i >= 0; i--){
    ll d = b[i - 1] + p[i - 1];
    if(x >= b[i] + p[i]){
      ans += p[i];
      break;
    }
    else if(x >= 2l * d + 2){
      ans += 1 + 2l * p[i - 1];
      x -= 2l * d + 2;
    }
    else if(x >= d + 2){
      ans += p[i - 1] + 1;
      x -= d + 2;
    }
    else if(x >= d + 1){
      ans += p[i - 1];
      x -= d + 1;
    }
    else{
      --x;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256