akhauriyash/Code-Regression huggingface dataset:
// Problem : C - XYZ Triplets
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
	int n;cin>>n;
	int ans[n+1]={0};
	for(int i=1;i<=100;i++)
	{
		for(int j=1;j<=100;j++)
		{
			for(int k=1;k<=100;k++)
			{
				int x=i*i+j*j+k*k+i*j+j*k+k*i;
				if(x<=n)
				ans[x]++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	cout<<ans[i]<<"\n";
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3592
import sys
input = sys.stdin.readline
def calc(x):
    l, r = 0, (N+1)//2
    while r - l > 1:
        m = (l+r) // 2
        if A[m] + A[2*m] >= 2 * x:
            l = m
        else:
            r = m
    return l
    
N, Q = map(int, input().split())
A = [int(a) for a in input().split()][::-1]
B = [A[0]] + [0] * (N-1)
for i in range(1, N):
    B[i] = B[i-1] + A[i]
C = [A[0]] + [0] * (N-1)
for i in range(2, N, 2):
    C[i] = C[i-2] + A[i]
C[-1] += C[-2]
for _ in range(Q):
    x = int(input())
    c = calc(x)
    print(B[c] + (C[-1] - C[2*c] if c*2<=N else 0))


Measured memory_bytes: 65388
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if (c == 'a') {
    cout << "vowel" << endl;
  }
  else if (c == 'e'){
    cout << "vowel" << endl;
  }
  else if (c == 'i'){
    cout << "vowel" << endl;
  }
  else if (c == 'o'){
    cout << "vowel" << endl;
  }
  else if (c == 'u'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long INF = 1e18;

int main(){

    int n,k;
    cin>>n>>k;
    int h[n+100];
    for(int i=0; i<n ;i++){
        cin>>h[i];
    }
    long long dp[100010];
    for(int i=0; i<100010; i++) dp[i] = INF;
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    

    for(int i=0; i<n; i++){
       for(int j=1; j<=min(n-i-1,k); j++){
           dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
        
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1408
import math
N= int(input())
A = list(map(int, input().split()))
M = [0] * (10**6+1)
g = A[0]
for i in A:
    M[i] += 1
    g = math.gcd(g, i)
if g > 1:
    print('not coprime')
    exit()
for i in range(2,10**6+1):
    c = 0
    for j in range(i,10**6+1,i):
        c += M[j]
    if c > 1:
        print('setwise coprime')
        exit()
print('pairwise coprime')


Measured memory_bytes: 195000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define str string
#define all(x) (x).begin(),(x).end()
#define rep(x,b,c) for(int x=b;x<c;x++)
#define  pb(x) push_back(x)
int main(){
    vector<int>v;
	ll ans,n;
	cin>>ans>>n;
	for(int i=0;;i++){
		if(ans==0) break;
		v.pb(ans%n);
		ans/=n;
	}
	cout<<v.size(); 
	return 0;
}

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

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

    int d[N]={};

    for(int i = 0;i<N;i++){
        cin >> d[i];
    }
    sort(d,d+N);

  	if(N%2==0){
		cout << d[N/2] - d[N/2-1] ;
    }
  
  	

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define pb push_back
#define mp make_pair
#define f first
#define s second
int countDivisor(int n)
{
	int divisor = 0;
	for (int i = 1; i * i <= n; i++)
	{
		if (i * i == n)
		{
			divisor += 1;
		}
		else if (n % i == 0)
		{
			divisor += 2;
		}
	}
	return divisor;
}
int main()
{
	int n,ret,i;
	ll ans=0;
	scanf("%d",&n);
	for(i=1; i<n; i++)
	{
		ret=countDivisor(n-i);
		ans+=ret;
	}
	printf("%lld",ans);
}


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

int main()
{
    int x,y;
    cin>>x>>y;
    while(x!=0||y!=0){
    if(x<y){cout<<x<<" "<<y<<endl;}
    else{cout<<y<<" "<<x<<endl;}
    cin>>x>>y;
    }
    
    }


Measured memory_bytes: 3012
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input!(n: usize);
    for i in n..1000 {
        if i % 111 == 0 {
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 4352
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
LL n, m, x, flag = 0;
string st[2];
int main(){
	cin >> n;
	LL A = pow((LL)sqrt(n), 2);
	cout << A << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin >> s >> t;
	if(s == t) cout << "EQUAL" << endl;
	else if(s.size() > t.size()) cout << "GREATER" << endl;
	else if(s.size() < t.size()) cout << "LESS" << endl;
	else if(s > t) cout << "GREATER" << endl;
	else cout << "LESS" << endl;
}


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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define vi vector<int>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

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

void Main() {
  int n, m;
  cin >> n >> m;
  vector<ll> ken(n, 1);
  vector<tuple<int,int,int>> num;
  rep(i, m) {
    int p, y;
    cin >> p >> y; p--;
    num.emplace_back(p, y, i);
  }
  sort(num.begin(), num.end());
  vector<ll> ans(m);
  rep(i, m) {
    ll p = get<0>(num[i]);
    ll y = get<1>(num[i]);
    int j = get<2>(num[i]);
    ans[j] = (p+1) * 1000000 + (ken[p]++);
  }
  rep(i, m) {
    printf("%012lld\n", ans[i]);
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

int Value(int a){
    
    int total = 0;
    while(1){
        
        if( a%2 != 0 ) break;
        a /= 2;
        total++;
    }
    return total;
}
int main(){
    int N,A; cin >> N;
    ll sum = 0;
    for(int i=0;i<N;i++){ cin >> A; sum += Value(A); }
    cout << sum << endl;
}

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

const int N = 51;

int main () {
	int n; cin >> n;
	string in[n];
	for (int i = 0; i < n; i++)
		cin >> in[i];
	int letters[26], temp[26];
	for (int i = 0; i < 26; i++)
		letters[i] = N;
	for (int i = 0; i < n; i++) {
		memset(temp, 0, sizeof temp);
		for (int j = 0; j < in[i].size(); j++)
			temp[in[i][j]-'a']++;
		for (int j = 0; j < 26; j++)
			letters[j] = min(letters[j], temp[j]);
	}

	for (int i = 0; i < 26; i++)
		for (int j = 0; j < letters[i]; j++)
			cout << (char)('a'+i);
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in(),m=in();
    struct mondai{
        bool aced=false;
        ll penacnt=0;
    };
    vector<mondai>mv(n);
    ll seito=0;
    for(ll i=0;i<m;++i){
        ll p=in()-1;
        string s;cin>>s;
        if(s=="AC"){
            if(!mv[p].aced)++seito;
            mv[p].aced=true;
        }else{
            if(!mv[p].aced)++mv[p].penacnt;
        }
    }
    ll pena=0;
    for(auto i:mv)if(i.aced)pena+=i.penacnt;
    cout<<seito<<' '<<pena<<endl;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

  COMinit();

  ll ans = 0;

  int n, m;
  cin >> n >> m;

  if(m < n){
    cout << 0 << endl;
    return 0;
  }

  rep(i, n+1){

    ll tmp = COM(n, i);

    ll coef = 1;    
    if(i%2==1){
      coef = -1;
    }

    tmp = (tmp * coef + MOD) % MOD;

    tmp = (tmp * fac[m-i]) % MOD;
    tmp = (tmp * finv[m-n]) % MOD;

    ans = (ans + tmp) % MOD;

  }

  ans = (ans * fac[m]) % MOD;
  ans = (ans * finv[m-n]) % MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 15604
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int arr[3];
    cin>>arr[0]>>arr[1]>>arr[2];
    sort(arr,arr+3);
    cout<<(arr[0]*arr[1]/2)<<endl;

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b;
	cin>>a>>b;
	cout<<max({a+a-1,a+b,b+b-1})<<endl;
	return 0;

}


Measured memory_bytes: 256
n,m = map(int, input().split())

check = {}
error = {}

ans_ac = 0
ans_wa = 0

for i in range(m):
    p,s = map(str, input().split())
    p = int(p)
    if p in check:
        pass
    else:
        if s == "WA":
            if p in error:
                error[p] += 1
            else:
                error[p] = 1
        else:
            if p in check:
                check[p] += 1
            else:
                check[p] = 1
            if p in error:
                ans_wa += error[p]
            ans_ac += 1
print(str(ans_ac) + " " + str(ans_wa) )

Measured memory_bytes: 15072
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f,max_n=100005;
inline ll lowbit(ll x){return x&(-x);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
double r,pi=acos(-1);
long long a,b,x;
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	cin>>a>>b;
	for(int i=1;i<=b;i++)
	{
		cin>>x;
		a-=x;
	}
	if(a<0)
	{
		cout<<"-1";
	}
	else cout<<a;
	return 0;
}

Measured memory_bytes: 3656
f = readLn :: IO Int

f' :: [(Int, Int)] -> [Int]
f' [] = []
f' ((a, b) : xs) = [abs(a - b)] ++ f' xs

solve :: [Int] -> Int -> String
solve x k
    | maximum x > k = ":("
    | otherwise = "Yay!" 

main = do
    a <- f
    b <- f
    c <- f
    d <- f
    e <- f
    k <- f

    let lst = [(a, b)] ++ [(a, c)] ++ [(a, d)] ++ [(a, e)] ++ [(b, c)] ++ [(b, d)] ++ [(b, e)] ++ [(c, d)] ++ [(c, e)] ++ [(d, e)]

    let ans = f' lst
    putStrLn (solve ans k)


Measured memory_bytes: 508
#include<iostream>
using namespace std;
int main(){
	int a[6],b[6],c[6];
	for(int i=0;i<6;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	int A,B,C,D,E,F;
	A=a[0]*3600+b[0]*60+c[0];
	D=a[1]*3600+b[1]*60+c[1];
	B=a[2]*3600+b[2]*60+c[2];
	E=a[3]*3600+b[3]*60+c[3];
	C=a[4]*3600+b[4]*60+c[4];
	F=a[5]*3600+b[5]*60+c[5];
	cout<<(D-A)/3600<<" "<<(D-A)%3600/60<<" "<<(D-A)%60<<endl;
	cout<<(E-B)/3600<<" "<<(E-B)%3600/60<<" "<<(E-B)%60<<endl;
	cout<<(F-C)/3600<<" "<<(F-C)%3600/60<<" "<<(F-C)%60<<endl;
	return 0;
}	



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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int a;
    cin >> a;

    cout << a + a * a + a * a * a << "\n";

    return 0;
}


Measured memory_bytes: 3612
s = list(map(int, input().split()))
t = list(map(int, input().split()))

if(s[0] >= s[1]):
  print(0)
else:
  t.sort()
  u=[]
  for i in range(s[1]-1):
    u.append(t[i+1]-t[i])
  u.sort()
  total=0
  for i in range(s[1]-s[0]):
    total+=u[i]
  print(total)

Measured memory_bytes: 13960
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

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

  out(min(a+b,min(b+c,c+a)));

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e10
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
    const ll MOD = INF + 7;
     
     
     
    int main(){
       int n, m;
       cin >> n >> m;
       int d = 0;
       rep(i, m){
          if(n % 2 == 0){
             int j = n - i;
             if(2 * (j - i - 1) == n){d = 1;j -= d;}
             if(m / 2 < i)j = j -  1;
             //cout << i + 1 << " " << j << "   " << j - i - 1 << " " << n - (j - i - 1) << endl;
            cout << i + 1 << " " << j << endl;
          }
          else cout << i + 1 << " " << n - i - 1 << endl;
       }
    }





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

typedef long long ll;
#ifndef MY_ALGORITHM
template<typename T>
struct UnionFind
{
    vector<T> parents;
    vector<T> rank;
    UnionFind(T n);
    T root(T x);
    bool unite(T x, T y);
    bool same(T x, T y);
};
#endif

template<typename T>
UnionFind<T>::UnionFind(T n):parents(n),rank(n,0){
        for (T i=0;i<n;i++){
            parents[i] = i;
        }
    }


template<typename T>
T UnionFind<T>::root(T x){
        //再帰的に根をつけなおす//rootを返す
        return parents[x] == x ? x: parents[x] = root(parents[x]);
}

template<typename T>
bool UnionFind<T>::unite(T x, T y){
        if (x==y) return false;
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        parents[y] = x;
        return true;
}

template<typename T>
bool UnionFind<T>::same(T x, T y){
        if (x==y) return true;
        return root(x) == root(y);
}
template<typename NodeIdx, typename Cost>
Cost kruskal(vector<tuple<NodeIdx,NodeIdx,Cost>> graph, NodeIdx V, NodeIdx E){
    using Edge =  tuple<NodeIdx,NodeIdx,Cost>;
    auto comp = [ ](const Edge &e1,const Edge &e2){
        return get<2>(e1) < get<2>(e2);
    };
    sort(graph.begin(),graph.end(),comp);
    UnionFind<NodeIdx> uf(V);
    Cost res = 0;
    for (const auto e: graph){
        if (!uf.same(get<0>(e),get<1>(e))){
            uf.unite(get<0>(e),get<1>(e));
            res +=get<2>(e);
        }

    }
    return res;



}


int main(){
    vector<tuple<ll,ll,ll>> graph;
    ll N,E;
    cin >> N >> E;
    for (ll i=0;i<E;i++){
        ll v1,v2,c;
        cin >> v1 >> v2 >> c;
        graph.push_back(make_tuple(v1,v2,c));
    }
    ll ret = kruskal(graph,N,E);

    printf("%lld\n",ret);
}


Measured memory_bytes: 7804
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll h,w;
  cin >> h >> w;
  string c[h];
  for(int i=0;i<h;i++){
    cin >> c[i];
  }
  for(int i=0;i<h;i++){
    cout << c[i]<<endl;
    cout << c[i]<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define debug(x) cout << #x << '=' << x << '\n'
const long long MOD=1e9+7;
//const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?'\n':' ');
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,A,B,C; cin >> N >> A >> B >> C;
    vector<string> S(N);
    for (int i=0;i<N;++i) cin >> S[i];
    int a=-A,b=-B,c=-C;
    vector<vector<int>> minwin(3,vector<int>(N+1,0));
    for (int i=0;i<N;++i){
        for (int j=0;j<3;++j) minwin[j][i+1]=minwin[j][i];
        if (S[i]=="AB"){
            ++a,++b;
            minwin[0][i+1]=(0<a?(a+1)/2:0);
            minwin[1][i+1]=(0<b?(b+1)/2:0);
        } else if (S[i]=="BC"){
            ++b,++c;
            minwin[1][i+1]=(0<b?(b+1)/2:0);
            minwin[2][i+1]=(0<c?(c+1)/2:0);
        } else {
            ++c,++a;
            minwin[2][i+1]=(0<c?(c+1)/2:0);
            minwin[0][i+1]=(0<a?(a+1)/2:0);
        }
    }
    for (int i=0;i<=N;++i){
        int sum=0;
        for (int j=0;j<3;++j) sum+=minwin[j][i];
        if (i<sum){cout << "No" << '\n'; return 0;}
    }
    cout << "Yes" << '\n';
    a=b=c=0;
    for (int i=0;i<N;++i){
        int ma=minwin[0][i+1],mb=minwin[1][i+1],mc=minwin[2][i+1];
        int na=upper_bound(minwin[0].begin(),minwin[0].end(),a)-minwin[0].begin();
        int nb=upper_bound(minwin[1].begin(),minwin[1].end(),b)-minwin[1].begin();
        int nc=upper_bound(minwin[2].begin(),minwin[2].end(),c)-minwin[2].begin();
        char ans;
        if (S[i]=="AB"){
            if (a<ma) ans='A',++a;
            else if (b<mb) ans='B',++b;
            else if (na<nb) ans='A',++a;
            else ans='B',++b;
        } else if (S[i]=="BC"){
            if (b<mb) ans='B',++b;
            else if (c<mc) ans='C',++c;
            else if (nb<nc) ans='B',++b;
            else ans='C',++c;
        } else {
            if (c<mc) ans='C',++c;
            else if (a<ma) ans='A',++a;
            else if (nc<na) ans='C',++c;
            else ans='A',++a;
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 7920
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
vint a;
vint b;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vint a(n);
    vint b(m);
    REP(i,n){
        cin >> a[i];
    }
    REP(i,m){
        cin >> b[i];
    }
    sort(ALL(a));
    sort(ALL(b));
    int nm = n*m;
    ll ans=1;
    int ai=0;
    int bi=0;
    int sp=0;
    if(a[n-1]!=nm&&b[m-1]!=nm){
        ans=0;
    }else{
        REP(i,n-1){
            if(a[i]==a[i+1]){
                cout << 0 << endl;
                return 0;
            }
        }
        REP(i,m-1){
            if(b[i]==b[i+1]){
                cout << 0 << endl;
            }
        }
        while(ai<n&&bi<m){
            if(a[ai]==b[bi]){
                if(!(nm-(n-ai-1)*(m-bi-1)<=a[ai]&&(n-ai-1)*(m-bi-1)>=nm-a[ai])){
                    //cout << "0:"<<a[ai] <<":" <<b[bi]<<endl;
                    cout << 0 << endl;
                    return 0;
                }
                for(int i=1;i<=n+m-ai-bi-2;i++){
                    ans*=(ll)(a[ai]-i-sp);
                    ans%=mod;
                }
                sp+=n+m-ai-bi-1;
                ai++;
                bi++;
            }else if(a[ai]>b[bi]){
                if(!(nm-(n-ai)*(m-bi-1)<=b[bi]&&(n-ai)*(m-bi-1)>=nm-b[bi])){
                    // cout <<"1:"<< a[ai] <<":" <<b[bi]<<endl;
                    cout << 0 << endl;
                    return 0;
                }
                ans*=n-ai;
                ans%=mod;
                for(int i=1;i<=n-ai-1;i++){
                    ans*=(ll)(b[bi]-i-sp);
                    ans%=mod;
                }
                sp+=n-ai;
                bi++;
            }else{
                if(!(nm-(n-ai-1)*(m-bi)<=a[ai]&&(n-ai-1)*(m-bi)>=nm-a[ai])){
                    // cout <<"2:"<< a[ai] <<":" <<b[bi]<<endl;
                    cout << 0 << endl;
                    return 0;
                }
                ans*=m-bi;
                ans%=mod;
                for(int i=1;i<=m-bi-1;i++){
                    ans*=(ll)(a[ai]-i-sp);
                    ans%=mod;
                }
                sp+=m-bi;
                ai++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
N = int(input())
A = []
dist = []

#リストに値を入れる
for i in range(N):
    A.append(list(map(int,input().split())))

#距離を求める
for i in range(N-1):
    for j in range(i+1,N):
        dist.append(math.sqrt((A[j][0] - A[i][0])**2 + (A[j][1] - A[i][1])**2))
print((sum(dist) * 2) / N)

Measured memory_bytes: 3064
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    bl = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                bl += 1

    ql = [[0, 0, 0]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(list)
    fq[0, 0]
    mc = 10 ** 10
    while True:
        if len(ql) != 0:
            cost, xv, yv = ql.popleft()
            if xv == h - 1 and yv == w - 1:
                mc = min(mc, cost)
            for xv, yv in [[xv + 1, yv], [xv - 1, yv], [xv, yv + 1], [xv, yv - 1]]:
                if 0 <= xv < h and 0 <= yv < w:
                    if (xv, yv) not in fq and s[xv][yv] != "#":
                        ql.append([cost + 1, xv, yv])
                        fq[xv, yv]
        else:
            break
    print(h * w - mc - 1 - bl if mc != 10 ** 10 else -1)


if __name__ == '__main__':
    solve()


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

int main()
{
    ll n;cin>>n;
    ll arr[n+1];
    for(int i=1;i<=n;i++) arr[i]=1;
    for(ll i=2;i<=n;i++)
    {
        arr[i]++;
        for(ll j=i*2;j<=n;j+=i) arr[j]++;
    }
    //for(int i=1;i<=n;i++) cout<<arr[i]<<" "; cout<<endl;
    ll ans=0;
    for(ll i=1;i<=n;i++)
        ans+=i*arr[i];
    cout<<ans;
}


Measured memory_bytes: 81720
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  int ans=0;
  for(int i=a[0];i<a[N-1];i++){
    int p=0;
    for(int j=0;j<N;j++){
      p+=(i-a[j])*(i-a[j]);
    }
    if(i==a[0]){
      ans=p;
    }
    if(i>a[0]&&ans>p){
      ans=p;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;

bool compare(pair<string, int> p, pair<string, int> q) {
	if (p.first != q.first)return p.first < q.first;
	else return p.second > q.second;
}

bool used[110];

int main(void) {
	string s;
	int n, x;
	cin >> n;
	vector<pair<string, int>>p(n), q(n);
	for (int i = 0;i < n;i++) {
		cin >> s >> x;
		p[i] = make_pair(s, x);
		q[i] = make_pair(s, x);
	}
	stable_sort(p.begin(), p.end(),compare);
	/*for (int i = 0;i < n;i++) {
		cout << p[i].first << " " << p[i].second << endl;
	}*/
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			if ((p[i].first == q[j].first) && (p[i].second==q[j].second) && !used[j]) {
				cout << j + 1 << endl;
				used[j] = true;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	cout << fixed << setprecision(16);
	int r;
	cin >> r;
	cout << acos(-1) * r * 2 << endl;
}


Measured memory_bytes: 3224
object Main extends App {
  val in = io.StdIn.readLine.split(' ').map(_.toInt)

  val N = in.head
  val M = in.last

  val Ks = for (i <- 1 to N) yield io.StdIn.readLine.split(' ').map(_.toInt)

  val out = Ks.foldLeft(Ks(0).toSet)((accum, as) => as.tail.toSet.intersect(accum)).size

  println(out)
}


Measured memory_bytes: 27208
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int x = sc.nextInt();
		int max = 1;
		for (int i = 2; i * i <= x; i++) {
			int t = i;
			while (t <= x) {
				t = t * i;
			}
			max = Math.max(max, t / i);
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<vector>
using namespace std;

vector<int> IntegerToVector(int bit, int N) {
	vector<int> S;
	for (int i = 0; i < N; ++i) {
		if (bit & (1 << i)) {
			S.push_back(i);
		}
	}
	return S;
}


int main() {

	int h,w,k;
	char c;
	int ans = 0;
	cin >> h >> w >> k;
	int d[6][6];

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> c;
			
			if (c == '.') {
				d[i][j] = 0;
			}
			else {
				d[i][j] = 1;
			}
		}
	}

	for (int bit = 0; bit < (1 << h); ++bit) {
		vector<int>S = IntegerToVector(bit, h);
		for (int bit2 = 0; bit2 < (1 << w); ++bit2) {
			vector<int>S2 = IntegerToVector(bit2, w);
			int cnt = 0;
			int dx[6][6];
			for (int x = 0; x < h; x++) {
				for (int y = 0; y < w; y++) {
					dx[x][y] = d[x][y];
				}
			}
			for (int i : S) {
				for (int yoko = 0; yoko < w; yoko++) {
					dx[i][yoko] = -1;
				}
			}
			for (int i : S2) {
				for (int tate = 0; tate < h; tate++) {
					dx[tate][i] = -1;
				}
			}

			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (dx[i][j] == 1)cnt++;
				}
			}
			if (cnt == k)ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3624
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		long[] A = new long[N + 1];
		long[] B = new long[N + 1];

		for (int i = 1; i <= N; i++) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
		}

		sc.close();

		long ans = 0;

		for (int i = N; i >= 1; i--) {
			A[i] += ans;

			long c = (B[i] - (A[i] % B[i])) % B[i];
			ans += c;
		}

		out.println(ans);

	}

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


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

int main() {
  int N,M;
  cin >>N>>M;
  vector<int> ans(M+1,0);
  for(int i=0;i<N;i++){
    int K;
    cin >>K;
    for(int j=0;j<K;j++){
      int a;
      cin >>a;
      ans.at(a)++;
    }
  }
  int res=0;
  for(int i=0;i<M+1;i++){
    if(ans.at(i)==N){
      res++;
    }
  }
  cout <<res<<endl;
}

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

typedef int32_t i32;

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 min = n;
  for (i32 i = 0; i <= n; ++i) {
    i32 cnt = 0;
    i32 t = i;
    while (t > 0) {
      cnt += t % 6;
      t /= 6;
    }
    t = n - i;
    while (t > 0) {
      cnt += t % 9;
      t /= 9;
    }
    if (min > cnt) {
      min = cnt;
    }
  }
  printf ("%" PRIi32 "\n", min);
}

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


Measured memory_bytes: 128
import math

# input
N, M = map(int, input().split())

if abs(N - M) >= 2:
    print(0)
elif abs(N - M) == 1:
    ans = (math.factorial(N) * math.factorial(M)) % (10 ** 9 + 7)
    print(ans)
else:
    ans = (math.factorial(N) * math.factorial(M) * 2) % (10 ** 9 + 7)
    print(ans)


Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int main() {
	cin >> n;
	int j = 1;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		if(a[i] == j) j++;
	}
	if(j == 1) {
		cout << "-1" << endl;
	} else {
		cout << n - j + 1 << endl;
	}
	return 0;
}

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

vector<int>g[200001];
int a[200001];
long long f[31][200001];
int p[31][200001];
int ans[200001];
int main(){
	int n;
	long long k;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		g[a[i]].push_back(i);
	}
	for(int i=0;i<n;i++){
		int w=lower_bound(g[a[i]].begin(),g[a[i]].end(),i)-g[a[i]].begin();
		if(w==g[a[i]].size()-1){
			p[0][i]=(g[a[i]][0]+1)%n;
			f[0][i]=1+(g[a[i]][0]==n-1?1:0);
		}
		else{
			p[0][i]=(g[a[i]][w+1]+1)%n;
			f[0][i]=g[a[i]][w+1]==n-1?1:0;
		}
	}
	for(int i=0;i<30;i++)
		for(int j=0;j<n;j++){
			f[i+1][j]=f[i][j]+f[i][p[i][j]]+f[i][p[i][p[i][j]]]+f[i][p[i][p[i][p[i][j]]]];
			p[i+1][j]=p[i][p[i][p[i][p[i][j]]]];
		}
//	for(int i=0;i<n;i++)
//		printf("%d %d %lld\n",i,p[0][i],f[0][i]);
	int o=0;
	k--;
	for(int i=30;i>=0;i--){
		while(f[i][o]<=k){
			k-=f[i][o];
			o=p[i][o];
		}
	}
	if(k!=0)return 0;
	for(;;){
		if(f[0][o]&&(f[0][o]!=1||p[0][o])){
			ans[++ans[0]]=a[o];
			o++;
			if(o==n)break;
		}
		else{
			if(f[0][o]==1&&p[0][o]==0)break;
			o=p[0][o];
		}
	}
	for(int i=1;i<=ans[0];i++)
		printf("%d%c",ans[i],i==ans[0]?'\n':' ');
}


Measured memory_bytes: 88280
#include <bits/stdc++.h>
#include<set>
#define ll long long 
#include <string>
using namespace std;
int main()
{
	ll int n,k,s=0;
	cin>>n>>k;
	ll int a[n],i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n,greater<ll int>());
	if (k>=n)
	s=0;
	else
	for(i=k;i<n;i++)
	{
		s+=a[i];
		
	}
	cout<<s<<endl;


}




Measured memory_bytes: 1792
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    string S;
    int K;
    cin >> S >> K;
    int N = S.size();
    set<string> sub;
    for (int i=0;i<N;i++) for (int j=1;j<=min(5,N-i);j++) {
        sub.insert(S.substr(i,j));
    }
    auto itr = sub.begin();
    for (int i=0;i<K-1;i++) itr++;
    cout << *itr << endl;

    // vector<set<string,greater<string>>> sub(N+1);
    // for (int i=0;i<N;i++) for (int j=1;j<=N-i;j++) {
    //     sub[j].insert(S.substr(i,j));
    // }
    // int j = N, v = 0;
    // for (j=N;j>=0 && v<K;j--) {
    //     v += sub[j].size();
    // }
    // auto itr = sub[j+1].begin();
    // for (int i=0;i<v-K-1;i++) itr++;
    // cout << *itr << endl;
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct PLAN{
  int type;
  double par;
  int cost;
};

PLAN plan[101];
int kinds,year,n,startMoney;
void solve(){
  long maxMoney = -1;

  for(int i = 0; i < kinds; i++){
    long money = startMoney;
    long rishi = 0;
    for(int j = 0; j < year; j++){
      if(plan[i].type == 0){//単利
        rishi += plan[i].par * money;
        money -= plan[i].cost;
      }
      else{//複利
        money += plan[i].par * money;
        money -= plan[i].cost;
      }
    }
    if(plan[i].type == 0) maxMoney = max(maxMoney, money + rishi);
    else maxMoney = max(maxMoney,money);
  }
  cout << maxMoney << endl;
  return ;
}



int main(){
  cin >> n;
  for(int input = 0 ; input < n; input ++){
    cin >> startMoney;
    cin >> year;
    cin >> kinds;
    for(int i = 0; i < kinds; i++){
      cin >> plan[i].type >> plan[i].par >> plan[i].cost;
    }
    solve();
  }
  return 0;
}



Measured memory_bytes: 3076
use proconio::input;

fn main() {
    input!(n: usize, k: u64, a: [u64; n]);

    let mut ng = 0;
    let mut ok = 1_000_000_000;
    while ng + 1 < ok {
        let mid = (ng + ok) / 2;
        *if eval(mid, k, &a) { &mut ok } else { &mut ng } = mid;
    }

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

fn eval(t: u64, k: u64, a: &[u64]) -> bool {
    let dc = |a, b| (a + b - 1) / b;
    a.iter().map(|a| dc(a, t) - 1).sum::<u64>() <= k
}


Measured memory_bytes: 5468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<vector<int>>> c(n, vector<vector<int>>(4, vector<int>(4)));
    map<vector<int>, int> mp;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) {
            cin >> c[i][0][j];
        }
        for (int j = 1; j < 4; j++) {
            c[i][j] = c[i][j - 1];
            c[i][j].insert(c[i][j].begin(), c[i][j].back());
            c[i][j].pop_back();
        }
        sort(c[i].begin(), c[i].end());
        mp[c[i][0]]++;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        mp[c[i][0]]--;
        for (int j = i + 1; j < n; j++) {
            mp[c[j][0]]--;
            for (int k = 0; k < 4; k++) {
                vector<int> a = c[i][0], b = c[j][k];
                vector<vector<int>> s = {
                    {b[1], b[0], a[1], a[0]},
                    {a[1], b[0], b[3], a[2]},
                    {a[3], a[2], b[3], b[2]},
                    {b[1], a[0], a[3], b[2]}};
                vector<int> val(4, 1);
                for (int l = 0; l < 4; l++) {
                    vector<vector<int>> x(4, s[l]);
                    for (int m = 1; m < 4; m++) {
                        x[m] = x[m - 1];
                        x[m].insert(x[m].begin(), x[m].back());
                        x[m].pop_back();
                    }
                    sort(x.begin(), x.end());
                    s[l] = x[0];
                    for (int m = 1; m < 4; m++) {
                        if (x[0] == x[m]) {
                            val[l]++;
                        }
                    }
                }
                ll cnt = 1;
                for (int l = 0; l < 4; l++) {
                    cnt *= mp[s[l]] * val[l];
                    mp[s[l]]--;
                }
                for (int l = 0; l < 4; l++) {
                    mp[s[l]]++;
                }
                ans += cnt;
            }
            mp[c[j][0]]++;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 140160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    string s, a = "2019/04/30";
    cin >> s;
    if(s <= a) cout << "Heisei" << endl;
    else cout << "TBD" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    double x1,y1,x2,y2,xq,yq;
    double a,b;
    double xr,yr;
    
    while(scanf("%lf,%lf,%lf,%lf,%lf,%lf\n",&x1,&y1,&x2,&y2,&xq,&yq)==6){
        if(x2-x1!=0){
            a=(y2-y1)/(x2-x1);
            b=y1-a*x1;
            yr=(2*a*xq+(a*a-1)*yq+2*b)/(1+a*a);
            xr=xq-a*(yr-yq);
        }else{
            xr=2*x1-xq;
            yr=yq;
        }
        printf("%lf %lf\n",xr,yr);
    }
    
    return 0;
}



Measured memory_bytes: 1980
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/4/ALDS1_4_D
# 工夫すればO(logn)ぐらいで解けるかもしれないが、nは最大で10**5。なのでO(nlogn)でもギリギリ間に合う(1.7*10**6回ぐらい)
# Pを与えたときにk台のトラックに詰める荷物の量を返す関数(O(n))を設計すれば二分探索でO(nlogk)で処理できる。
# Pを与えたときに何台のトラックが必要かを返す関数(O(n))でもおk

# イメージとしては単調増加関数を経由して二分探索する感じ


# %%
def n_nimotu_if_P(P, k, arr):  # Pに対する単調増加関数
    weight = 0
    n_trucks = 1  # 1台目から積んでいく
    for i, a in enumerate(arr):
        # iの荷物について積むかどうか決め、それに応じてトラックの数を増加させる
        if P < a:  # P<aの時点で即時終了 絶対その荷物は積めないので
            return i  # i個の荷物が詰める(i-1番目までの荷物が積める)

        if weight + a <= P:  # Pを超える手前までどんどん積んでいく
            weight += a
        else:
            n_trucks += 1  # Pを超えるなら次のtruckを用意
            weight = a  # 新たなトラックに積んでいる

        if n_trucks == k+1:  # k+1台目のtruckは存在しない。これまでに積んだ荷物の数を返す
            return i  # (i-1番目までのi個の荷物が積める)

    # truckに余裕があるなら全部詰める
    return len(arr)  # すべて運べるならlen(arr)を返すとする。


# %%
n, k = map(int, input().split())
luggages = []
for _ in range(n):
    luggages.append(int(input()))

# 探索する配列が未知のため、pythonのbisectは使えない状況。自分で実装
# n_nimotui_if_P()==n ならば 荷物を全部運んだ(もしくは余裕があるということ)。
# ==ならPを小さくし<ならばPを大きくしていく二分探索で解ける

left, right = 0, 10000 * n
i_break = 0
while right - left > 1:
    mid = (left+right)//2
    if n <= n_nimotu_if_P(mid, k, luggages):  # もし余裕があるならPを減らす
        right = mid  # ギリギリOKなのはrightに最終的に格納されているはず
    else:  # 余裕がなければ(n>n_nimotu_if_P())、Pを増やす
        left = mid

print(right)



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

class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        double r = Double.parseDouble(s);
        //System.out.println(r);
        String x = String.format("%.6f",(r * r * Math.PI));
        String y = String.format("%.6f",( 2 * Math.PI *r));
        System.out.println(x+" "+y);
    }
}

Measured memory_bytes: 17072
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
int n,arr[101];
int cal(int a,int b){return (arr[a]+arr[b])*(abs(a-b));}
void Min(int &a,int b){a=min(a,b);}

int mem[3][101][101][101];
int dfs(int f,int num,int l,int r){
  if(l>r)return 0;
  if(l==r)return (arr[l]==l+1) ? INF:0;
  if(r-l==1)return (arr[l]==l+1||arr[r]==r+1)? cal(l,r):0;
  if(mem[f][num][l][r]!=-1)return mem[f][num][l][r];

  int res=INF;  
  for(int i=l+1;i<r;i++){
    if(f!=2){
      swap(arr[l],arr[i]);
      Min(res,cal(l,i)+dfs(1,arr[l],l,i-1)+dfs(1,arr[i],i,r));
      swap(arr[l],arr[i]);
    }
    if(f!=1){
      swap(arr[i],arr[r]);
      Min(res,cal(i,r)+dfs(2,arr[i],l,i)+dfs(2,arr[r],i+1,r));
      swap(arr[i],arr[r]);
    }
  }

  for(int i=l;i<r;i++){
    int a=(f==1)? dfs(f,num,l,i):dfs(0,0,l,i);
    int b=(f==2)? dfs(2,num,i+1,r):dfs(0,0,i+1,r);
    Min(res,a+b);
  }

  return mem[f][num][l][r]=res;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>arr[i];
  memset(mem,-1,sizeof(mem));
  cout<<dfs(0,0,0,n-1)<<endl;
}

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

int main() {
	int n,h,m,s,t;
	//while (1) {
		cin >> n;
		if (n >= 0) {
			h = n / 3600;
			t = n % 3600;
			m = (n % 3600) / 60;
			s = (n % 3600) % 60;
		}
		cout << h << ":" << m << ":" << s << endl;
		//cout << t << endl;
		//ystem("pause");
	//}
	return 0;
	
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
using namespace std;

int main() {
  string S;
  cin >> S;
  ll cnt0 = 0, cnt1 = 0;
  for(ll i = 0; i < S.size(); i++) {
    if(S.at(i) == '0') cnt0++;
    else cnt1++;
  }
  cout << min(cnt0, cnt1) * 2 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;

ll n,m,a;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    for(ll i=0; i<m; i++) cin >> a , n-=a;

    cout << max( -1LL , n );

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll A, B, C, X;
    cin >> A >> B >> C >> X;
    
    ll ans = 0;
    for(ll i = 0; i <= A; i++){
        for(ll j = 0; j <= B; j++){
            for(ll k = 0; k <= C; k++){
                if(500 * i + 100 * j + 50 * k == X) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256