akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define white 0
#define glay 1
#define black 2

int adj[100][100],n;
int color[100],d[100],f[100],tt;

void dfs_visit(int u){
  int v;
  color[u]=glay;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(adj[u][v]==0)continue;
    if(color[v]==white)dfs_visit(v);
  }

color[u]=black;
f[u]=++tt;

}

void dfs(){
  int u;
  for(u=0; u<n; u++)color[u]=white;
  tt=0;

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




int main(){int u,k,v,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)adj[i][j]=0;
  }

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


  dfs();
  return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

void bfs(vector<vector<int>> &graph, vector<int> &d, int s)
{
    queue<int> q;
    q.push(s);
    d[s] = 0;
    while (!q.empty())
    {
        int now = q.front();
        q.pop();
        for (auto v : graph[now])
        {
            if (d[v] == INF)
            {
                chmin(d[v], d[now] + 1);
                q.push(v);
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> fennec(n, INF);
    vector<int> snuke(n, INF);
    bfs(g, fennec, 0);
    bfs(g, snuke, n - 1);
    vector<int> color(n, 0);
    for (int i = 0; i < n; i++)
    {
        if (fennec[i] <= snuke[i])
        {
            color[i] = 1;
        }
        else
        {
            color[i] = -1;
        }
    }
    int f = count(ALL(color), 1);
    int s = count(ALL(color), -1);
    cout << (f <= s ? "Snuke" : "Fennec") << endl;
}

Measured memory_bytes: 6912
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  double l;
  cin>>l;
  l=l*l*l/27;

  cout<<fixed<<setprecision(12)<<l;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    AList = list(map(int, input().split()))

    answer = 0

    for i in range(1, N):
        diff = AList[i-1] - AList[i]

        if(diff > 0):
            answer = answer + diff
            AList[i] = AList[i - 1]

    print(answer)

if __name__ == "__main__":
    main()

Measured memory_bytes: 32200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define MOD 1000000007
 
int main(){
    int A, B; cin >> A >> B;

    int i = 1; int C = A;
    while(true){
        if(C >= B) break;
        C = (i+1)*A - i;
        i++;
    }
    if(B == 1) cout << 0;
    else cout << i; 
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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 ll INF=1e18;
//abc166c

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll ans=0;
    ll n,m;
    cin>>n>>m;
    V<ll> h(n);
    cinf(n,h);
    V<V<ll>> G(n);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i,n){
        bool ok=1;
        for(ll x:G[i]){
            if(h[x]>=h[i]) ok=0;
        }
        if(ok) ans++;
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 9796
#![allow(unused_imports)]

use std::cmp::{max, min};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = input().unwrap();
    let n = s.len();

    let mut ans = "NO";

    for i in 0..n {
        for j in i..n+1 {
            let mut pre = s[..i].to_string();
            let suf = &s[j..];
            pre.push_str(suf);
            if pre == "keyence".to_string() {
                ans = "YES";
                break;
            }
        }
    }

    println!("{}", ans);
}

pub fn input<T: FromStr>() -> Result<T, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    Ok(buf.trim().parse().ok().unwrap())
}

pub fn input_vec<T: FromStr>() -> Result<Vec<T>, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    Ok(buf
        .trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>())
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}


Measured memory_bytes: 4352
#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;

int len;

int f(string s, int pos){
    string str_a,str_b;
    int count = 0;
    char c = 'a';
    str_a = s.substr(0, pos + 1);
    str_b = s.substr(pos + 1, len - (pos + 1));
    for(int i = 0; i < 26; i++){
        if(str_a.find(c) != -1 && str_b.find(c) != -1){
            count++;
        }
        c++;
    }
    return count;
}

int main(int argc, const char * argv[]) {
    string s;
    cin >> len;
    cin >> s;
    int n;
    int max = 0;
    for(int i = 0; i < len - 1; i++){
        n = f(s, i);
        if(max < n){
            max = n;
        }
    }
    cout << max;
}



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

struct StAnsHist
{
  StAnsHist() : m_nProblmNo(0), m_sJudge("") { }

  int    m_nProblmNo;
  string m_sJudge;
};

void fnInput(int& rnProblmSiz, vector<StAnsHist>& rvoAnsHist)
{
  int nSubmitSiz;
  cin >> rnProblmSiz >> nSubmitSiz;
  rvoAnsHist.resize(nSubmitSiz);

  for (StAnsHist& roAnsHist : rvoAnsHist)
    cin >> roAnsHist.m_nProblmNo >> roAnsHist.m_sJudge;
}
  
void fnAnserCheck(int nProblmSiz, const vector<StAnsHist>& cnrvoAnsHist, 
                  int& rnRightAns, int& rnPenalty)
{
  vector<int> vnWACnt(nProblmSiz + 1);
  set<int> seRightAns;

  rnRightAns = 0;
  rnPenalty = 0;

  for (StAnsHist oAnsHist : cnrvoAnsHist)
    if (oAnsHist.m_sJudge == "AC")
      seRightAns.insert( oAnsHist.m_nProblmNo );
    else
      if (!seRightAns.count( oAnsHist.m_nProblmNo ))
        vnWACnt[ oAnsHist.m_nProblmNo ]++;

  rnRightAns = seRightAns.size();

  for (int nRightAns : seRightAns)
    rnPenalty += vnWACnt[nRightAns]; 
}
  
int main()
{
  int nProblmSiz;
  vector<StAnsHist> voAnsHist;
  fnInput(nProblmSiz, voAnsHist);

  int nRightAns, nPenalty;
  fnAnserCheck(nProblmSiz, voAnsHist, nRightAns, nPenalty);

  cout << nRightAns << " " << nPenalty;
  return 0;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define print(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int bexp(int a, int b, int mod)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

#define N 100010
#define MOD 1000000007

struct comp {
    bool operator() (const pair<int, int> a, const pair<int, int> b) const
    {
        return a.ss > b.ss;
    }
};


int32_t main() 
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    string s;
    cin >> s;

    if (s.back() == 's')
        s += "es";
    else
        s += "s";

    cout << s << endl;    
    return 0;
}

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

using namespace std;

#define frei(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define fred(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define fri(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define frd(i,n) for (int i = (n) - 1; i >= 0; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )

#define uint64 unsigned long long
#define int64 long long
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define ff first
#define ss second
#define pr pair

#define BIT(n) (1<<(n))
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a) | (b))
#define XOR(a,b) ((a) ^ (b))
#define sqr(x) ((x) * (x))

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define PI 3.1415926535897932385
#define INF 1000111222
#define eps 1e-7
#define maxN 5005

const int nax = 3003;
int64 dp[nax][nax];

int main(int argc, char const *argv[])
{
    /* code */
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    // new conscept of diagnol dp filling from last to upper
    // f(l, r) = max(al - f(l+1, r), ar - f(l, r-1))
    for(int l = n -1; l >= 0; l--) {
        for(int r = l; r < n; r++) {
            if(l == r) {
                dp[l][r] = a[l];
            } else {
                dp[l][r] = max(a[l] - dp[l+1][r], a[r] - dp[l][r-1]);
            }
        }
    }
    cout << dp[0][n-1] << endl;
    return 0;
}


Measured memory_bytes: 70016
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int x = 0;
    int y = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
        {
            x++;
        }
        else
        {
            y++;
        }
    }
    if (x > y)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		if(N == 1){
			Console.WriteLine(0);
			return;
		}
		if(K == 1){
			Console.WriteLine(0);
			return;
		}
		Console.WriteLine(N - (K - 1) - 1);
		
		
	}
	int N,K;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>
#include<set>
#include<stack>
#include<map>

using namespace std;

int main(){
    int N;
    long long a[10000],b[10000];
    cin>>N;
    long long sumA(0),sumB(0);
    string ans;
    for(int i=0;i<N;i++){
        cin>>a[i];
        sumA+=a[i];
    }
    for(int i=0;i<N;i++){
        cin>>b[i];
        sumB+=b[i];
    }
    long long numA=sumB-sumA;
    long long numB=sumB-sumA;
    for(int i=0;i<N;i++){
        if(a[i]<b[i]){
            numA -= (b[i]-a[i])/2;
            a[i]+=((b[i]-a[i])/2)*2;
            if(a[i]!=b[i]){
                numA--;
                numB--;
            }
        }else if(a[i]>b[i]){
            numB -= (a[i]-b[i]);
        }
    }
    if(numA>=0 && numB>= 0){
        ans="Yes";
    }else{
        ans="No";
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std ;

const int MAX = 2e5 + 10 ;

int a[MAX] , b[MAX] ;
int n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	for(int i = 0 ; i < n ; ++i)
		cin>>a[i]>>b[i] ;
	sort(a , a + n) ;
	sort(b , b + n) ;
	int x , y ;
	if(n % 2 == 0)
		x = a[n/2] + a[n/2-1] , y = b[n/2] + b[n/2-1] ;
	else
		x = a[n/2] , y = b[n/2] ;
	return cout<<y-x+1<<"\n" , 0 ;
}		

Measured memory_bytes: 5220
N, Y = map(int, input().split())
Y = Y //1000
#x, y, z =1, 5, 10
for x in range(N+1):
    y = (10*N-9*x-Y)//5
    z = ((-5*N)+Y+4*x)//5
    
    if y >= 0 and z >= 0 and x+y+z == N and x+5*y+10*z == Y:
        print(z, y, x)
        break
else:
    print(-1, -1, -1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	if (k == 1) {
		dunk(0);
		return 0;
	}
	int ans = n - k;
	dunk(ans);
	return 0;
}


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

using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
	while(u != NIL && k != u->key) {
		if(k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key   = k;
	z->left  = NIL;
	z->right = NIL;
	
	while(x != NIL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL) {
		root = z;
	} else {
		if( z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
	
int main(void) {
	int n, i, x;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		cin >> com;
		if(com[0] == 'f') {
			scanf("%d",&x);
			Node *t = find(root,x);
			if(t != NIL) printf("yes\n");
			else printf("no\n");
		} else if(com == "insert") {
			scanf("%d",&x);
			insert(x);
		} else if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 22052
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

//nCkを求める(n<∞ , k<300000)
const ll M=1000000007;
vector<ll> fac(300001); //n*(n-1)*…(n-k+1)(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//フェルマーの小定理 : X/Y=X*Y^-1 , Y^-1≡Y^(M-2) (mod M 素数)

//O(logn)でx^n(mod M)を求める
ll mpow(ll x,ll n){
  if(n==0) return 1;
  ll res=mpow(x*x%M,n/2);
  if(n&1) res=res*x%M; //nが奇数の場合
  return res;
}

ll comb(int n,int k){ //nCk(mod M)を計算
  if(n==0&&k==0)return 1;
  if(n<k||n<0)return 0;
  ll tmp=mpow(ifac[k],M-2)%M;
  return tmp*fac[k-1]%M;//n*(n-1)*…*(n-k+1)/k!
}

//O(k)で階乗の計算の準備
void set_comb(ll n){
  fac[0]=n;
  ifac[0]=1;
  for(ll i=0;i<300000;i++){
    if(n-i-1>0)
    fac[i+1]=fac[i]*(n-i-1)%M;//fac[i] : n*(n-1)*…*(n-i)
    ifac[i+1]=ifac[i]*(i+1)%M; // k!^{M-2} (mod M)
  }
}

int main(){
  ll n,a,b; cin>>n>>a>>b;
  set_comb(n);
  ll ans=mpow(2,n)-1;
  ll d=(comb(n,a)+comb(n,b))%M;
  if(ans-d<0) ans+=M;
  ans=(ans-d)%M;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

int main(void)
{
	int s[3];
	int r = 0;
	int d = 0;
	
	while (scanf("%d,%d,%d", &s[0], &s[1], &s[2]) != EOF) {
		if ((s[2] * s[2]) == (s[0] * s[0]) + (s[1] * s[1])) {
			r++;
		}
		if (s[0] == s[1]) {
			d++;
		}
	}
	
	printf("%d\n", r);
	printf("%d\n", d);
	
	return (0);
}

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

int main(){
    int a,b,i,al=0;
    cin >> a >> b;
	for(i=0;i<2;i++){
		if(a >= b){
          al+=a;
          a--;
        }else{
          al+=b;
          b--;
        }
    }
    cout << al << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
bool isMiddle(long a,long b,long c){
  vector<long> l;
  l.resize(3);
  l[0] = a;
  l[1] = b;
  l[2] = c;
  sort(l.begin(),l.end());
  if(l[1] == b){
    return true;
  }
  else{
    return false;
  }
}
int main(){
  long n,ii,sum;
  vector<long> p;
  cin >> n;
  p.resize(n);

  for(ii=0;ii<n;ii++){
    cin >> p[ii];
  }
  sum = 0;
  for(ii=1;ii<n-1;ii++){
    if(isMiddle(p[ii-1],p[ii],p[ii+1])){
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
  
}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[18]:


from collections import deque


# In[12]:


X = input()


# In[26]:


mylist = deque([])
for x in X:
    if x == "S":
        mylist.append("S")
    else:
        if len(mylist) == 0 or mylist[-1] == "T":
            mylist.append("T")
        else:
            mylist.pop()
print(len(mylist))


# In[ ]:






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

// #include <atcoder/all>

using namespace std;

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

struct UnionFind {
  vector<int> parent;
  vector<int> num_node;

  UnionFind(int N) : parent(N), num_node(N, 1) {
    for (int i = 0; i < N; i++) {
      parent[i] = i;
    }
  }

  // 根を求める
  int root(int x) {
    if (parent[x] == x) {
      return x;
    }

    // 経路圧縮
    parent[x] = root(parent[x]);
    return parent[x];
  }

  // 同一判定
  bool is_same(int x, int y) {
    return this->root(x) == this->root(y);
  }

  // 併合
  void unite(int x, int y) {
    x = this->root(x);
    y = this->root(y);

    // すでに一緒ならなにもしない
    if (x == y) {
      return;
    }
    parent[x] = y;
    num_node[y] += num_node[x];
  }

  // 同一グループのノード数
  int size(int x) {
    return num_node[root(x)];
  }
};

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

  ll n, m;
  cin >> n >> m;

  UnionFind uf(n);

  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }

  set<ll> s;
  rep(i, n) {
    s.insert(uf.root(i));
  }

  cout << s.size() - 1 << endl;

  return 0;
}


Measured memory_bytes: 7792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		int k = (a+b)/2;
		String ans = "";

		if ((a+b)%2 == 0 && Math.abs(a-k) == Math.abs(b-k)) {

			ans = String.valueOf(k);

		} else {
			ans = "IMPOSSIBLE";
		}

		System.out.println(ans);
		sc.close();

	}

}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int N; cin >> N;
  vector<int> v( 2 * N );
  for ( int i = 0; i < 2 * N; ++i ) cin >> v[i];

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

  long long ans = 0;
  for ( int i = 0; i < 2 * N; i += 2 )
  {
    ans += min( v[i], v[i + 1] );
  }

  cout << ans << endl;

  return ( 0 );
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;
  std::vector<std::vector<int>> grid(2);

  for (auto& row: grid) {
    row.resize(n);
    for (auto& cell: row) {
      std::cin >> cell;
    }
  }

  // Move down at l-th cell;
  int max = 0;
  for (int l = 0; l < n; ++l) {
    int score = 0;
    for (int x = 0; x < n; ++x) {
      if (x <= l) {
        score += grid[0][x];
      }
      if (l <= x) {
        score += grid[1][x];
      }
    }
    max = (score > max) ? score : max;
  }
  std::cout << max << std::endl;
}


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

using namespace std;

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

  long long ans = 1e18;
  for(long long i = 1; i*i <= n ; ++i){
    if(n % i != 0)  continue;
    long long j = n/i;
    ans = min(ans, i+j-2);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        char[] c = sc.next().toCharArray();
        int n = c.length;

        boolean res = true;

        for(int i=0; i<n; i++) {
            if (c[i] != c[n - 1 - i])
                res = false;
        }
        for(int i=0; i<n; i++) {
            int j = (n - 3)/2 - i;
            if(i > j) break;
            if(c[i] != c[j]) res =false;
        }
        System.out.println(res ? "Yes" : "No");
    }
}

Measured memory_bytes: 21716
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define googletestcase(x) cout<<"CASE #"<<x<<": ";
using namespace __gnu_pbds;
using namespace std;
template <class T> using Tree = tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define readint(x) scanf("%d", &x)
#define readll(x) scanf("%lld", &x)
#define readstring(x) readint(x)
#define loop(i, a, b) for(int i=a;i<b;i++)
#define loop0(i, a) for(int i=0;i<a;i++)
#define loopi(i, a, b) for(int i=a;i<=b;i++)
#define trav(i, x) for(auto i: x)
#define travedit(i, x) for(auto &i: x)
#define sz(x) (long long)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define debug(a, x) cout<<a<<" IS "<<x<<'\n';
#define all(x) x.begin(), x.end()
#define ins insert
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
const int MOD=1000000007;//1e9+7
const int MX=1000001;
void setio(string s) {
	//ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
struct BIT{
    ll nput;
    int bit[MX];
    void init(){
        for(int i=0;i<=nput+9;i++){
            bit[i]=0;
        }
    }
    void update(ll k, ll x){
        while(k<=nput){
            bit[k]+=x;
            k+=k&-k;
        }
    }
    ll sum(ll k){
        ll sum1=0;
        while(k>=1){
            sum1+=bit[k];
            k-=k&-k;
        }
        return sum1;
    }
    ll query(ll a, ll b){
        return sum(b)-sum(a-1);
    }
};
struct DSU{
	int nput;
	int dsu[MX+1];
	int sizes[MX+1];
	void init() {
		for(int i=0;i<=nput;i++) {
			dsu[i]=i;
			sizes[i]=1;
		}
	}
	int find(int a) {
		if(dsu[a]==a)
			return a;
		return(dsu[a]=find(dsu[a]));
	}
	void join(int a, int b) {
		a=find(a);
		b=find(b);
		if(a!=b){
			if(sizes[a]<sizes[b]){
				dsu[a]=b;
				sizes[b]+=sizes[a];
			}
			else{
				dsu[b]=a;
				sizes[a]+=sizes[b];
			}
		}
	}
	bool sameset(int a, int b){
		return find(a)==find(b);
	}
};
int h[100000];
int dp[100000];
int n;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>h[i];
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++){
        ll a=dp[i-1]+abs(h[i]-h[i-1]);
        ll b=dp[i-2]+abs(h[i]-h[i-2]);
        dp[i]=min(a, b);
    }
    cout<<dp[n]<<'\n';
}




Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
 
int a[3][105];
int sum[3][105];
 
int main()
{
	int n;
	cin>>n;
	long long max=0;
	for(int i=1;i<=2;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>a[i][j];
			sum[i][j]=sum[i][j-1]+a[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(sum[1][i]+sum[2][n]-sum[2][i-1]>max)
			max=sum[1][i]+sum[2][n]-sum[2][i-1];
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys, collections
sys.setrecursionlimit(10000000)

def permutation(k, r, fact, revfact, mod):
    return (fact[k] * revfact[k-r]) % mod

def dfs(now, parent, edge, mod, K, fact, revfact):
    son = 0
    ans = 1
    for next in edge[now]:
        if next != parent:
            son += 1
            ans *= dfs(next, now, edge, mod, K, fact, revfact)
            ans %= mod
    if K-2 < son: ans = 0
    elif son > 0:
        ans *= permutation(K-2, son, fact, revfact, mod)
        ans %= mod
    return ans
    

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    edge = [[] for i in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    mod = 7 + 10 ** 9

    fact = [1] * (K + 1)
    for i in range(2, K+1):
        fact[i] = (i * fact[i-1]) % mod
    revfact = [1] * (K+1)
    revfact[K] = pow(fact[K], mod - 2, mod)
    for i in reversed(range(1, K)):
        revfact[i] = ((i+1) * revfact[i+1]) % mod

    ans = K
    son = 0
    for next in edge[0]:
        son += 1
        ans *= dfs(next, 0, edge, mod, K, fact, revfact)
        ans %= mod
    ans *= permutation(K-1, son, fact, revfact, mod)
    ans %= mod

    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 92280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	string N; cin>>N;
	if(N[0]==N[1] && N[0]==N[2]) puts("Yes");
	else if(N[1]==N[2] && N[1]==N[3]) puts("Yes");
	else puts("No");
}


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

int main()
{
    double s, l, h, a, b, c, rad;
    int deg;

    cin >> a >> b >> deg;
    rad = deg * M_PI / 180;

    s = a * b * sin(rad)/2;
    c = sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*cos(rad));
    l = a + b + c;
    h = 2 * s / a;


    cout << std::fixed << std::setprecision(8)
         << s << '\n' 
         << l << '\n'
         << h << endl;

    return 0;
}


Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int A, B; cin >> A >> B;
	cout << A * B << "\n";

	return 0;
}

Measured memory_bytes: 3640
def main():
    dic = {}
    n = int(input())
    for _ in range(n):
        s = input().rstrip()
        if s in dic.keys():
            dic[s] += 1
        else:
            dic[s] =  1
    m = max(dic.values())
    ans = [key for key, val in dic.items() if val == m]
    for a in sorted(ans):
        print(a)

if __name__ == "__main__":
    main()

Measured memory_bytes: 32988
#include<stdio.h>
 
 
int main(){
 
  int n, b, f, r, v;
  int nor[4][3][10]={};
  int i, j, k;
 
  scanf("%d", &n);
 
  for(i=0;i<n;i++){
    scanf("%d %d %d %d", &b, &f, &r, &v);
    nor[b-1][f-1][r-1]+=v;
  }
 
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
    printf(" %d", nor[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3) printf("####################\n");
  }
   
  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int main()
{
    int g,t,q,w;
    double z,re=0;
    vector<ii>wq;
    scanf("%d",&t);
    for(g=0;g<t;g++){
        scanf("%d %d",&q,&w);
        wq.push_back(ii(q,w));
    }
    q=0;
    sort(wq.begin(),wq.end());
    do{
        q++;
        for(z=0,g=1;g<t;g++)
            z+=sqrt((wq[g].first-wq[g-1].first)*(wq[g].first-wq[g-1].first)+(wq[g].second-wq[g-1].second)*(wq[g].second-wq[g-1].second));
        re+=z;
    }while(next_permutation(wq.begin(),wq.end()));
    printf("%.7f\n",re/q*1.00);
    return 0;
}


Measured memory_bytes: 256
import math

N = int(input())
x = []
y = []
for _ in range(N):
  a, b = map(int, input().split())
  x.append(a)
  y.append(b)
d = []
# 道の長さをリストdに加えていく
# dは8C2=28個の要素を持つ
for i in range(N - 1):
  for j in range(i + 1, N):
    d.append(math.sqrt((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2))
#N=8のとき
#dは8*7/2/1個
#一つの道につき7!*2回使う
#道は全部で8!*7通る
#ans = (sum(d) * math.factorial(N - 1) * 2) / math.factorial(N)
ans = sum(d) * 2 / N
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = [-1]+list( map(int, input().split()) )
b = [0]*(n+1)
res = 0
ary = []

for i in range(n, 0, -1):
    tmp = 0
    for j in range( 2*i, n+1, i ):
        tmp += b[j]
    if tmp%2 != a[i]:
        res += 1
        b[i] = 1
for i in range(1, n+1):
    if b[i] == 1:
        ary.append(i)
print(res)
if res != 0:
    print(*ary)

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

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 1005
P sz[N];

int main() {
  int n, w, d;
  while(cin >> n >> w >> d && (n + w + d)) {
    sz[0] = P(w, d);
    int idx = 1;
    rep(i, n) {
      int p, s;
      cin >> p >> s;
      int c = -1;
      while(p) {
        if(sz[++c].first != -1) {
          --p;
        }
      }
      P &e = sz[c];
      s %= (e.first + e.second);
      //cout << "e" SP c SP s SP e.first SP e.second << endl;
      if(s == 0 || s == e.first) {
        cout << "Failed" << endl;
        exit(1);
      }
      if(0 <= s && s < e.first) {
        int nw = maxd(s, e.first - s);
        //cout << "w" SP s SP nw SP e.first SP e.second << endl;
        sz[idx]   = P(e.first - nw, e.second);
        sz[idx+1] = P(nw,           e.second);
      } else {
        s -= e.first;
        int nw = maxd(s, e.second - s);
        //cout << "d" SP s SP nw SP e.first SP e.second << endl;
        sz[idx]   = P(e.first, e.second - nw);
        sz[idx+1] = P(e.first, nw);
      }
      sz[c].first = -1;
      idx += 2;
    }
    vector<int> v;
    rep(i, idx) {
      P &e = sz[i];
      if(e.first != -1) {
        v.push_back(e.first * e.second);
      }
    }
    sort(ALL(v));
    rep(i, n+1) {
      cout << (i ? " " : "") << v[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.nextLine();
        int pay = 700;
        if(a.charAt(0) == 'o'){
            pay += 100;
        }
        if(a.charAt(1) == 'o'){
            pay += 100;
        }
        if(a.charAt(2) == 'o'){
            pay += 100;
        }
        System.out.println(pay);
    }
}

Measured memory_bytes: 21844
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  ll N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  map<ll, ll> dp;
  dp[0] = 0;
  dp[1] = D;
  function<ll(ll)> rec = [&](ll x) {
    // dmp(x);
    auto it = dp.find(x);
    if (it != dp.end()) return it->second;
    ll res;
    if (LLINF / D < x)
      res = LLINF;
    else
      res = x * D;
    chmin(res, rec(x / 2ll) + A + D * (x % 2));
    chmin(res, rec((x + 1) / 2ll) + A + D * (2 - x % 2));
    chmin(res, rec(x / 3ll) + B + D * (x % 3));
    chmin(res, rec((x + 2) / 3ll) + B + D * (3 - x % 3));
    chmin(res, rec(x / 5ll) + C + D * (x % 5));
    chmin(res, rec((x + 4) / 5ll) + C + D * (5 - x % 5));
    return dp[x] = res;
  };
  cout << rec(N) << endl;
  return;
}

signed main() {
  fastio();
  //   solve();
  int t;
  cin >> t;
  while (t--) solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 4472
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
//#define _GLIBCXX_DEBUG

bool test(string S) {
  rep(i, S.size()/2) {
    if(S[i] != S[S.size()/2+i]) return false;
  }
  return true;
}

signed main() {
  string S; cin >> S;
  while(true) {
    S.erase(S.size()-2);
    if(test(S)) {
      cout << S.size() << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> P;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


P f(int x){
    int a=x%10;
    int b=0;
    while(x){
        b=x;
        x/=10;
    }
    return P(a,b);
}

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

int n;
cin >> n;
map<P,int> m;
for(int i=1;i<=n;++i){
    m[f(i)]++;
}
ll ans=0;
for(int i=1;i<=n;++i){
    P p = f(i);
    P q(p.second,p.first);
    ans+=m[q];
}
fin(ans);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <iostream>

using namespace std;
#define SIZE 100001
static uint64_t array[SIZE];

int32_t main()
{
  uint64_t N;
  cin >> N;

  for (uint64_t i = 0; i < N; i++) {
    cin >> array[i];
  }

  sort(array, array + N);

  uint64_t counter = 0;
  uint64_t old = 0;
  uint64_t same_val = 0;
  for (uint64_t i = 0; i < N; i++) {
    if (array[i] == old) {
      same_val++;
    } else {
      if (same_val % 2 == 1) {
        counter++;
      }
      old = array[i];
      same_val = 1;
    }
  }

  if (same_val % 2 == 1) {
    counter++;
  }

  cout << counter << endl;
  return 0;
}


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

using namespace std;

int main(){
	int n,k;
	cin >> n >> k;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int a; cin >> a;
		if(a - k/2 > 0){
			ans += k-a;
		}
		else ans += a;
	}
	cout << 2 * ans << endl;
	return 0;
}



Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

s = 0
t = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            s += 1
            if i < j:
                t += 1

k = K * (K - 1) // 2
res = s * k + t * K
print(res % (10 ** 9 + 7))


Measured memory_bytes: 3188
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    s = input()
    if s == 'ARC':
        print('ABC')
    else:
        print('ARC')
if __name__ == '__main__':
    main()


Measured memory_bytes: 9036
#include <stdio.h>

int main()
{
    int i, n, k, a[200005], m = 0, c = 0;
    scanf("%d", &n);
    scanf("%d", &k);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        c += a[i];
        if (i >= k)
            c -= a[i - k];
        if (c > m)
        {
            m = c;
        }
    }
    m += k;
    printf("%d.", m / 2);
    printf("%d", (m & 1) * 5);
    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<queue>
#include<bitset>
#include<algorithm>
#include<climits>
#include<vector>
#include<deque>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> P;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define dump(a) rep(i,a.size()){ cout<<a[i]<<" "; } cout<<endl;
#define dumparr(a,n) rep(i,n){ cout<<a[i]<<" "; } cout<<endl;
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define FINF DBL_MAX/3
#define EPS 1e-7
#define OUT1(n1) cout<<n1<<endl
#define OUT2(n1,n2) cout<<n1<<" "<<n2<<endl
#define OUT3(n1,n2,n3) cout<<n1<<" "<<n2<<" "<<n3<<endl
#define OUT4(n1,n2,n3,n4) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<endl
#define OUT5(n1,n2,n3,n4,n5) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<endl
#define OUT6(n1,n2,n3,n4,n5,n6) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<" "<<n6<<endl
#define OUT(n, ...) OUT##n(__VA_ARGS__)

/*
 * comb(n,r)の大小関係: 直感的にはパスカルの三角形を見ればわかる
 * - (n+1,r) > (n,r)
 * - n/2 > r+1 > rならば、(n,r+1)>(n,r)
 *
 * このことから
 * (n,k)が最大になるとしたら、nは{a_i}の中の最大値
 * a_i=max({a_i}), a_j=(一番a_i/2に近いもの)とするとこれが最大。
 * なぜなら
 * - a_iでない数a_jを使って、(a_j, a_k)が最大になるとする。この時(a_i,a_k)はそれより大きいはずだから矛盾。
 */

int main(){
  ll n;
  ll a[100001];
  cin>>n;

  // 最大値
  ll m = 0;
  ll mi = -1;
  rep(i,n){
    cin>>a[i];
    if(a[i]>m) {
      m = a[i];
      mi = i;
    }
  }

  // 一番m/2に近いもの
  ld d = INF; // 距離
  ll k = -1; // index
  rep(i,n){
    ld nd = abs((ld)a[i] - (((ld)m)/2));
    if(nd <= d) {
      d = nd;
      k = a[i];
    }
  }
  OUT2(m, k);
  return 0;
}


Measured memory_bytes: 1024
package main

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

func run() {
	a := nextInt()
	b := nextInt()
	ans := 0
	cur := 1
	for cur < b {
		cur = cur + a - 1
		ans++
	}
	Println(ans)
}

// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024

func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}

func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}

func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}

func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}


Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int MAX=1001;
int lcs(string X,string Y) 
{
    int i=0,j=0,c[MAX][MAX],x=X.length(),y=Y.length();
    for(i=0;i<=x;i++)c[i][0]=0;
    for(i=0;i<=y;i++)c[0][i]=0;
    for(i=1;i<=x;i++) 
    for(j=1;j<=y;j++) 
    if(X[i-1]==Y[j-1])c[i][j]=c[i-1][j-1]+1; 
    else if(c[i-1][j]>c[i][j-1])c[i][j]=c[i-1][j];
    else c[i][j]=c[i][j-1];
    return c[x][y];
}
int main()
{
    int n;cin>>n;
    string X,Y;
    while(n--)
    {
        cin>>X>>Y;
        cout<<lcs(X,Y)<<endl;
    }
}


Measured memory_bytes: 7060
#define _USE_MATH_DEFINES
#include <iostream>

using namespace std;

int main() {
	char u[3], b[3];
	cin >> u >> b;
	for (int i = 0; i < 3; i++) {
		if (u[i] != b[2 - i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 256