akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define nn 300008
#define int long long 
#define mod 998244353
int r,g,b,rb,rg,bg;
char str[nn];int n;
	int res=1;
signed main() {
	scanf("%lld%s",&n,str);for(int i=1;i<=n;i++) res=res*(i)%mod;n=n*3;
	for(int i=0;i<n;i++){
		if(str[i]=='R'){
			if(bg) res=res*bg%mod,bg--; 
			else if(b) res=res*b%mod,b--,rb++;
			else if(g) res=res*g%mod,g--,rg++;
			else r++;
		}
		else if(str[i]=='G'){
			if(rb) res=res*rb%mod,rb--; 
			else if(b) res=res*b%mod,b--,bg++;
			else if(r) res=res*r%mod,r--,rg++;
			else g++;
		}
		else{
			if(rg) res=res*rg%mod,rg--; 
			else if(g) res=res*g%mod,g--,bg++;
			else if(r) res=res*r%mod,r--,rb++;
			else b++;
		}
	}
	cout<<res;
	return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
bool is(string s){
  int n = s.size();
  for(int i = 0; i < n / 2; i++){
    if(s[i] != s[n - 1 - i]){
      return false;}
  }
  return true;
}
int main(){
  string s;
  cin >> s;
  int n = s.size();
  if(is(s) && is(s.substr(0, n / 2)) && is(s.substr(1 + n / 2, n / 2))){
    cout << "Yes" << endl;}
  else{
    cout << "No" << endl;}}


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

void Main() {
    // input
    u_int64_t N, A, B;
    cin >> N >> A >> B;


    // translate
    u_int64_t count = N / (A + B) * A;
    N %= A + B;
    count += min(N, A);




    // output
    cout << count << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
	bool flag = true;
	for( int i = 0; i < s.size(); ++i ){
		if(
			( i%2 == 0 and s[i] != 'h' )
				or
			( i%2 == 1 and s[i] != 'i' )
		) flag = false;
	}
	if( flag && s.size()%2 == 0 ){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

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

int main(){
	int N;
	cin >> N;
	
	
	REP(i,N){
		double val = double(i*1.08);
		if(floor(val) == N){
			cout << i << endl;
			return 0;
		}
	}
	
	cout << ":(" << endl;
	
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

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

  int H , n;
  cin >> H >> n;
  vector<pair<int,int> > P(n);
  for(int i = 0; i < n; i++) {
    cin >> P[i].first >> P[i].second;
  }
  vector<int> dp(H + 1, inf);
  dp[0] = 0;
  for(int i = 1; i <= H; i++) {
    for(int j = 0; j < n; j++) {
      int x = i - P[j].first;
      if(x < 0) x = 0;
      dp[i] = min(dp[i], dp[x] + P[j].second);
    }
  }
  cout << dp[H] << '\n';
}

Measured memory_bytes: 3724
import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    H, N, *ab = map(int, read().split())
    A = []
    B = []
    for a, b in zip(*[iter(ab)] * 2):
        A.append(a)
        B.append(b)

    A = np.array(A)
    B = np.array(B)
    
    dp = np.full((H+1), np.inf)
    dp[0] = 0


    for i in range(1,H+1):
        dp[i] = np.min(dp[np.maximum(i - A, 0)] + B)

    print(int(dp[H]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 12504
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define pb emplace_back
#define mp make_pair
#define eps 1e-8
#define lson (curpos<<1)
#define rson (curpos<<1|1)
/* namespace */
using namespace std;
/* header end */

const int maxn = 110;
int n, a[maxn];

int main() {
    cin >> n;
    int flag = 1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] & 1) continue;
        if (a[i] % 2 == 0 && (a[i] % 3 == 0 || a[i] % 5 == 0)) continue;
        else flag = 0;
    }
    if (flag) puts("APPROVED");
    else puts("DENIED");
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define mem(a,b) memset(a,b,sizeof(a))
#define shutdown ios::sync_with_stdio(false)
#define MAX 10e18+1000
#define INF 0x3f3f3f3f
#define FOR(x,k) for(int x=1;x<=k;x++)



int main()
{
    shutdown;
    string a;
    cin>>a;
    int l=a.length();
    for(int i=0;i<l-1;i++){
        if(a[i]=='A'&&a[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int v[] = new int[n];
		int c[] = new int[n];
		for(int i = 0; i < n; i++){
			v[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			c[i] = sc.nextInt();
		}
		
		int answer = 0;
		for(int i = 0; i < n; i++){
			if(v[i] > c[i]){
				answer += v[i] - c[i];
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 24020
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
int n,m,x;
int c[25];
int a[25][25];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>m>>x;
	rep(i,0,n-1){
		cin>>c[i];
		rep(j,1,m){
			cin>>a[i][j];
		}
	}
	int ans=inf;
	rep(i,0,(1<<n)-1){
		int ret=0,flag=1;
		int b[25]={0};
		rep(j,0,n-1) if(i>>j&1){
			rep(k,1,m) b[k]+=a[j][k];
			ret+=c[j];
		}
		rep(j,1,m) if(b[j]<x) flag=0;
		if(flag) ans=min(ans,ret);
	}
	if(ans==inf) ans=-1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
    unsigned int k,n;
    scanf("%d %d",&k,&n);
    unsigned int a[n];
    unsigned int l=0;
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=0;i<n-1;i++){
        if(a[i+1]-a[i]>l)l=a[i+1]-a[i];
    }
    if(a[0]+(k-a[n-1])>l)l=a[0]+(k-a[n-1]);
    printf("%d",k-l);
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int G[101][101];
int d[101];
int f[101];
int finded[101];  // init 0
/* 0:未訪問  1:訪問済 */

void dfs(int);
void visit(int, int);

main(){
  int i, j, k, l, n, adj;

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

  dfs(n);

  for(i=1; i<=n; i++){
    printf("%d %d %d\n", i, d[i], f[i]);
  }

  return 0;
}

void dfs(int n){
  int i;
  for(i=1; i<=n; i++){
    if(finded[i] == 0) visit(n, i);
  }
}

void visit(int n, int p){
  static int time=0;
  int j;

  finded[p] = 1;
  d[p] = ++time;

  for(j=1; j<=n; j++){
    if(G[p][j]==1 && finded[j]==0)
      visit(n, j);
  }
  f[p] = ++time;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,M;
  string S,T;
  cin>>N>>M>>S>>T;
  int K=__gcd(N,M);
  for(int i=0;i<K;i++)
    if(S[N/K*i]!=T[M/K*i]){
      puts("-1");
      return 0;
    }
  cout<<N/K*M<<endl;
}


Measured memory_bytes: 3760
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <locale>
#include <map>
#include <optional>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using i32 = int32_t;
using i64 = uint64_t;
using u32 = uint32_t;
using u64 = uint64_t;
template <typename T>
T input_value() {
  T result;
  std::cin >> result;
  return result;
}

template <typename T1, typename T2>
void input_multival_to_array(const T1& n, T2& array) {
  for (T1 i = T1(0); i < n; ++i) {
    array.emplace_back(input_value<typename T2::value_type>());
  }
}

template <typename T>
std::set<T> factorize(const T& n) {
  const T sqrtn = T(sqrt(double(n)));
  std::set<T> result = {T(1), T{n}};
  for (T i = T(2); i <= sqrtn; ++i) {
    if (n % i == T(0)) {
      result.insert(i);
      result.insert(n / i);
    }
  }
}

int main() {
  using namespace std;
#if _WIN32
  locale::global(locale(""));
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  const auto n_town = input_value<u32>();
  const auto n_teleports = input_value<u64>();
  vector<u32> dests;
  input_multival_to_array(n_town, dests);
  for_each(dests.begin(), dests.end(), [](u32& d) { --d; });

  vector<u32> routes_from_1st;
  unordered_set<u32> visited;
  u64 loop_start_index = 0;
  u32 current_town = 0;
  for (; visited.find(current_town) == visited.end();
       current_town = dests[current_town]) {
    visited.insert(current_town);
    routes_from_1st.push_back(current_town);
  }
  loop_start_index = distance(
    routes_from_1st.begin(),
    find(routes_from_1st.begin(), routes_from_1st.end(), current_town));

  u64 loop_size = routes_from_1st.size() - loop_start_index;

  if (n_teleports < routes_from_1st.size()) {
    cout << (routes_from_1st[n_teleports] + 1) << '\n';
  } else {
    cout << (routes_from_1st
               [(n_teleports - loop_start_index) % loop_size +
                loop_start_index] +
             1)
         << '\n';
  }
  return 0;
}


Measured memory_bytes: 12976
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

t = L()
#print(t)
for i in range(1,len(t)):
    if t[i] == "?":
        if t[i-1] == "P":
            t[i] = "D"
        else:
            t[i] = "D"
if t[0] == "?":t[0] = "D"
for i in t:
    print(i,end="")

Measured memory_bytes: 10632
#include <stdio.h>
#define H 500000

void maxHeapify(int *, int);

int h;

int main()
{
  int i, a[H];

  scanf("%d",&h);
  for(i=0;i<h;i++){
    scanf("%d",&a[i]);
  }


  for(i=H/2-1;i>=0;i--){
    maxHeapify(a, i);
  }
 
  for(i=0;i<h;i++){
    printf(" %d",a[i]);
  }
  printf("\n");

    return 0;
}

void maxHeapify(int *A, int i)
{
  int t, l, r, largest;

  if((i+1)*2+1<=h){
    l=2*(i+1)-1;
    r=2*(i+1);

    if(l<=h && A[l]>A[i]) largest=l;
    else largest=i;

    if(r<=H && A[r]>A[largest]) largest=r;
  
    if(largest!=i){
      t=*(A+i);
      *(A+i)=*(A+largest);
      *(A+largest)=t;
      maxHeapify(A, largest);
    }
  }

  else if((i+1)*2<=h){
     l=2*(i+1)-1;

    if(l<=h && A[l]>A[i]) largest=l;
    else largest=i;
  
    if(largest!=i){
      t=A[i];
      A[i]=A[largest];
      A[largest]=t;
      maxHeapify(A, largest);
    }
  }
  else{
    largest=i;
    if(largest!=i){
      t=*(A+i);
      *(A+i)=*(A+largest);
      *(A+largest)=t;
      maxHeapify(A, largest);
    }
  }
  
}

  



Measured memory_bytes: 3652
N = int(input())
AA = [int(input()) for _ in range(N)]
AA.sort()
AF = AA[:N//2]
AL = AA[N//2:]
ans = 0
if N % 2 == 0:
    ans = sum(AL)*2 - AL[0] - sum(AF)*2 + AF[-1]
else:
    ans1 = sum(AL)*2 - sum(AF)*2 - sum(AL[0:2])
    ans2 = sum(AL)*2 - sum(AF)*2 - 3 * AL[0] + AF[-1]
    ans = max(ans1, ans2)


print(ans)

Measured memory_bytes: 50904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int n;
vector<vector<int>> a;
vector<vector<int>> id;
const int mxN = 1003;
const int mxV = mxN*(mxN-1)/2;
int dp[mxV];
vector<int> to[mxV];
bool calculated[mxV] = {false};
bool seen[mxV] = {false};

int dfs(int i) {
    if(seen[i]) {
        if(!calculated[i]) return -1;
        return dp[i];
    }
    seen[i] = true;
    dp[i] = 1;
    for(auto v : to[i]) {
        int res = dfs(v);
        if(res == -1) return -1;
        chmax(dp[i], res + 1);
    }
    calculated[i] = true;
    return dp[i];
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    a.assign(n, vector<int>(n-1));
    id.assign(n, vector<int>(n));
    rep(i, n) {
        rep(j, n-1) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    int V = 0;
    rep(i, n) rep(j, n) {
        if(i < j) id[i][j] = V++;
    }
    auto getId = [&](int i, int j) {
        if(i > j) swap(i, j);
        return id[i][j];
    };
    rep(i, n) {
        rep(j, n-1) {
            a[i][j] = getId(i, a[i][j]);
        }
    }
    rep(i, n) {
        rep(j, n-2) {
            to[a[i][j+1]].push_back(a[i][j]);
        }
    }
    int ans = 0;
    rep(i, V) {
        int res = dfs(i);
        if(res == -1) {
            puts("-1");
            return 0;
        }
        chmax(ans, res);
    }
    cout << ans << endl;

}

Measured memory_bytes: 41472
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
print(sum(b)+ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <bitset>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

intmax_t rank(std::vector<intmax_t> b) {
  constexpr size_t m = 61;
  size_t n = b.size();
  size_t i = 0;
  for (size_t j = 0; j < m; ++j) {
    if (i >= n) break;
    for (size_t k = i; k < n; ++k) {
      if (~b[k] >> j & 1) continue;
      std::swap(b[i], b[k]);
      break;
    }
    if (~b[i] >> j & 1) continue;
    for (size_t k = 0; k < n; ++k) {
      if (k == i) continue;
      if (b[k] >> j & 1) b[k] ^= b[i];
    }
    ++i;
  }
  return i;
}

int main() {
  size_t n, m;
  scanf("%zu %zu", &n, &m);

  std::vector<std::vector<size_t>> s(m);
  for (size_t i = 0; i < m; ++i) {
    size_t k;
    scanf("%zu", &k);
    s[i].resize(k);
    for (auto& si: s[i]) scanf("%zu", &si), --si;
  }

  std::vector<size_t> p(m);
  for (auto& pi: p) scanf("%zu", &pi);

  std::vector<intmax_t> a(m), b(m+1);
  for (size_t i = 0; i < m; ++i) {
    for (auto j: s[i])
      a[i] |= 1_jd << j;

    b[i] = a[i] << 1 | p[i];
  }

  intmax_t ra = rank(a);
  intmax_t rb = rank(b);

  if (ra < rb) {
    puts("0");
  } else {
    printf("%jd\n", (1_jd << (n-ra)));
  }
}


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

int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        int n=max(a,b);
        int i;
        for(i=0;i<n;i++)
            printf("%d",min(a,b));
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
d,g=map(int, input().split())
A=[]
a=0
b=0
for i in range(d):
  a,b=map(int, input().split())
  A.append([a,b])


minp=0#現時点での問題数の最小値（最初は全問題数の合計にしておく）
for i in range(d):
  minp+=A[i][0]



for i in range(2**d):
  sco=0 #点数
  pro=0 #問題数
  bini=bin(i)[2:].zfill(d)
  #print(bini)
  for j in range(d):
    if bini[j]=="1" : #iの2進数で1の問題セットは完全に解く
      pro+=A[j][0]
      sco+=A[j][0]*100*(j+1)+A[j][1]
  if sco<g : #このとき、解いてない中でスコア最大の問題を何問か解く必要がある
    #print(bini)
    totyuu=-1
    j=0
    while totyuu==-1 :
      if bini[d-j-1]=="0" :
        totyuu=d-j-1
      j+=1
    #print(totyuu)
    #print(g-sco)
    if g-sco<=(A[totyuu][0]-1)*100*(totyuu+1):
      pro=pro+(g-sco-1)//(100*(totyuu+1))+1
    else:
      pro=minp

  #print(str(pro)+" "+bini)

  if pro<minp :
    minp=pro

print(minp)


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

int main(){
	//正四面体数とその中から奇数のものだけを抜きとったものを用意
	int sq[200]={0};
	int oddsq[200]={0};
	//その配列のindexを保存
	int index=0;
	int indexODD=0;
	 //dp初期化用の値
	int INF=2000000;
	
	for(int i=0; (i+1)*(i+2)*(i+3)/6<=1000000; ++i){
		sq[i]=(i+1)*(i+2)*(i+3)/6;
		if(sq[i]%2==1) oddsq[indexODD++]=sq[i];	
		//printf("%3d :%7d\n",i, sq[i]);
		index=i+1;
	}
	//printf("index= %d, inODD = %d\n", index, indexODD);
	
	//dpA[i]:=数iを正四面体数の和として表すときに必要な正四面体数の数の最小値		
	int dpA[1000001];
	fill(dpA,dpA+1000001,INF);
	dpA[0]=0;
		
	for(int i=0; i<1000001; ++i){
		for(int j=0; j<index; ++j){
			if(i+sq[j]<1000001) dpA[i+sq[j]]=min(dpA[i+sq[j]],dpA[i]+1);
			else break;	
		}	
	}
		
	//dpB[i]:=数iを正四面体数の和として表すときに必要な「奇数の」正四面体数の数の最小値		
	int dpB[1000001];
	fill(dpB,dpB+1000001,INF);
	dpB[0]=0;
		
	for(int i=0; i<1000001; ++i){
		for(int j=0; j<indexODD; ++j){
			if(i+oddsq[j]<1000001) dpB[i+oddsq[j]]=min(dpB[i+oddsq[j]],dpB[i]+1);
			else break;	
		}	
	}
		
	while(1){
		int n;
		scanf(" %d", &n);
		if(n==0) break;
		printf("%d %d\n", dpA[n], dpB[n]);
	}	
}


Measured memory_bytes: 10928
-- Question B

import Control.Applicative
import Control.Monad

main = do
  ys <- getLine
  putStrLn $ show ( check (length ys) (length ys) ys)


check :: Int -> Int -> String -> Int
check n k xs 
 | n == k = check (n-2) k (init (init xs))
 | take (n `div` 2) xs == drop (n `div` 2)  xs = length xs
 | otherwise = check (n-2) k (init (init xs))

Measured memory_bytes: 892
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	int A = abs(x - a);
	int B = abs(x - b);
	if (A > B)cout << "B" << endl;
	else cout << "A" << endl;
	return 0;
}

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

inline bool isPrime(int x){
	if(x==1) return false;
	if(x==2) return true;
	for(int i=2;i<=sqrt(x);i++){
		if(x%i==0) return false;
	}
	return true;
}

int main() {
	int n,x,ans=0;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&x);
		if(isPrime(x)) ans++;
	}printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3128
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
bool isOK(int k, vector<int> a) {
    int pos = 0;
    for (int i = 1; i <= k; i++) {
        bool innerflag = false;
        for (int j = pos; j < a.size(); j++) {
            pos = j;
            if (a[j] == i) {
                innerflag = true;
                break;
            }
        }
        if (!innerflag) {
            return false;
            break;
        }
        pos++;
    }
    return true;
}

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

    bool b = false;
    for (int i = 0; i < N; i++)if (a[i] == 1)b = true;
    if (!b) {
        cout << -1 << endl;
        return 0;
    }

    int ng = N+1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = -1; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, a)) ok = mid;
        else ng = mid;
    }
    cout << N - ok << endl;
    //cout << N - left << endl;

}

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

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	s = s + s;
	vector<vector<int>> nex(2 * n, vector<int>(26, -1));
	for (int i = 2 * n - 2; i >= 0; i--) {
		for (int j = 0; j < 26; j++) {
			if (s[i + 1] == 'a' + j) {
				nex[i][j] = i + 1;
			} else {
				nex[i][j] = nex[i + 1][j];
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 26; j++) {
			if (nex[i][j] >= n) {
				nex[i][j] -= n;
			}
		}
	}
	long long ans = 0;
	int now = t[0] == s[0] ? 0 : nex[0][t[0] - 'a'];
	if (now == -1) {
		cout << -1 << endl;
		return 0;
	}
	int cur = 1;
	while (cur < t.size()) {
		int tmp = nex[now][t[cur] - 'a'];
		if (tmp == -1) {
			cout << -1 << endl;
			return 0;
		}
		if (tmp <= now) {
			ans += n;
		}
		now = tmp;
		cur++;
	}
	cout << ans + now + 1 << endl;
	return 0;
}

Measured memory_bytes: 27136
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] d = new int[k];
		for (int i = 0; i < k; i++) {
			d[i] = sc.nextInt();
		}
		for (int i = n; ; i++) {
			boolean bre = false;
			String s = String.valueOf(i);
			for (int j = 0; j < k; j++) {
				if (s.contains(String.valueOf(d[j]))) {
					bre = true;
					break;
				}
			}
			if (!bre) {
				System.out.println(i);
				break;
			}
		}
	}
}

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

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

struct Dice {
  int a, b, c, d, e, f;

  Dice(int a_, int b_, int c_, int d_, int e_, int f_) {
    a = a_;
    b = b_;
    c = c_;
    d = d_;
    e = e_;
    f = f_;
  }

  int opposite(int n) {
    if (n == a) {
      return f;
    } else if (n == b) {
      return e;
    } else if (n == c) {
      return d;
    } else if (n == d) {
      return c;
    } else if (n == e) {
      return b;
    } else if (n == f) {
      return a;
    } else {
      return 0;
    }
  }

  void spin(char ch) {
    int aa = a;
    int bb = b;
    int cc = c;
    int dd = d;
    int ee = e;
    int ff = f;

    if (ch == 'E') {
      a = dd;
      c = aa;
      d = ff;
      f = cc;
    } else if (ch == 'N') {
      a = bb;
      b = ff;
      e = aa;
      f = ee;
    } else if (ch == 'S') {
      a = ee;
      b = aa;
      e = ff;
      f = bb;
    } else if (ch == 'W') {
      a = cc;
      c = ff;
      d = aa;
      f = dd;
    }
  }
};

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  Dice dice(a, b, c, d, e, f);

  int q;
  cin >> q;
  vector<int> v(q);

  rep(i, q) {
    int top, front;
    cin >> top >> front;
    bool found = false;
    bool e_or_w = false;

    while (!found) {
      if (e_or_w) {
        dice.spin('E');
      } else {
        dice.spin('W');
      }
      e_or_w = !e_or_w;

      rep(j, 3) {
        dice.spin('S');
        if (dice.a == top && dice.b == front) {
          v[i] = dice.c;
          found = true;
          break;
        } else if (dice.a == front && dice.b == top) {
          v[i] = dice.opposite(dice.c);
          found = true;
          break;
        }
      }
    }
  }

  for (auto &&i : v) {
    printf("%d\n", i);
  }
}



Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <deque>
#define N 100005
using namespace std;

int k;
bool v[N];
deque<int> qu, qc;
int main()
{
	int fu, fc, ne;
	cin >> k;
	qu.push_front(1);
	qc.push_front(1);
	while (!qu.empty()) {
		fu = qu.front(), qu.pop_front();
		fc = qc.front(), qc.pop_front();
		if (fu == 0) {cout << fc; return 0;}
		if (v[fu]) continue;
		v[fu] = 1;
		ne = fu * 10 % k;
		if (!v[ne]) qu.push_front(ne), qc.push_front(fc);
		ne = (fu + 1) % k;
		if (!v[ne]) qu.push_back(ne), qc.push_back(fc + 1);
	}
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<string>

using namespace std;

int main()
{
  string S,T;
  cin >> S >> T;
  
  int right_count = 0;
  
  for(int i = 0; i < 3; i ++)
     if(S[i] == T[i])
       right_count ++;
  cout << right_count << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			String str = stdIn.next();
			for(int i = 0; i < str.length(); ++i)
			{
				if(str.charAt(i) == '@')
				{
					for(int j = 0; j < str.charAt(i + 1) - '0'; ++j)
					{
						System.out.print(str.charAt(i + 2));
					}
					i += 2;
				}
				else
				{
					System.out.print(str.charAt(i));
				}
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 12000
# include<iostream>
# include<algorithm>
# include<cctype>
# include<cstdio>
# include<cstring>
# include<cmath>
using namespace std;
int main()
{
      int n, a[100];
      cin >> n;
      for (int i=0; i<n; i++)
      {
            cin >> a[i];
      }
      int sum = 0;
      for (int i=1; i<n-1; i++)
      {
            if (a[i]>a[i-1]&&a[i]<a[i+1]) sum++;
            else if (a[i]<a[i-1]&&a[i]>a[i+1]) sum++;
      }
      cout << sum << endl;
      return 0;
}

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


#define     SPEED       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	ll          long long int
#define 	pb          push_back
#define 	pii         pair<int,int>
#define 	vi          vector<int>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	hell        1000000007
#define 	rep(i,n)    for(i=0;i<n;i++)
#define 	repe(i,a,b) for(i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search
#define 	mp          make_pair

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2);
	if(b%2==0)
		return((c%hell)*(c%hell))%hell;
	return ((((c%hell)*(c%hell))%hell)*(a%hell))%hell;
}

ll dp[102][100005],w[100105],v[100105],n,wt;

ll f(ll x,ll p)
{
	if(p>wt)
		return (0-hell);
	if(x>=n)
		return 0;
	if(dp[x][p]==-1)
	{
		dp[x][p]=max(f(x+1,p+w[x])+v[x], f(x+1,p));
	}
	// cout<<x<<"&&^"<<p<<dp[x][p]<<"%^\n";
	return dp[x][p];
}


int main()
{
	SPEED;
	ll t,c=0,i,j,m,cs=0;
	t=1;

	//cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>wt;
		// n=s.length();
		rep(i,n)
		{
			cin>>w[i]>>v[i];
			memset(dp[i],-1,sizeof(dp[i]));
		}
		// dp[0]=0;
		// repe(i,1,n)
		// {
		// 	dp[i]=1e18;
		// 	for (j = 1;  j<=k && i-j>=0 ; ++j)
		// 	{
		// 		dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]), dp[i]);
		// 	}
		// 	// cout<<i<<"&(*"<<dp[i]<<"&\n";
		// }
		// c=max(f(1,0)+a[0][0],f(1,1)+a[0][1]);
		cout<<f(0,0);
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 78592
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m, x;
int c[12], a[12][12];

int solve() {
    int res = inf;
    int r[m];
    for (int i = 1; i < (1<<n); i++) {
        memset(r, 0, sizeof(r));
        int d = 0;
        for (int j = 0; j < n; j++) {
            if ((i>>j)&1) {
                d += c[j];
                for (int k = 0; k < m; k++) {
                    r[k] += a[j][k];
                }
            }
        }
        bool f = true;
        for (int j = 0; j < m; j++) {
            if (r[j] < x) {
                f = false;
                break;
            }
        }
        if (f) {
            res = min(res, d);
        }
    }
    return (res < inf ? res : -1);
}

void input() {
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3152
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  b.append(a[i]-i-1)
b.sort()
if n%2==1:x=b[int((n+1)/2)-1]
else:x=int((b[int(n/2)]+b[int(n/2)-1])/2)
c=0
for j in range(n):
  c+=abs(x-b[j])
print(c)

Measured memory_bytes: 26708
#include <iostream>
#include <vector>
//#include <fstream>

using namespace std;

int main(int argc, const char * argv[]) {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());
    
    int N;
    cin >> N;
    
    int max = 0;
    vector<int> V(N), C(N);
    for (int i=0; i<N; i++)
    {
        cin >> V[i];
    }
    for (int i=0; i<N; i++)
    {
        cin >> C[i];
    }
    for (int i=0; i<N; i++)
    {
        if (V[i] > C[i]) max += V[i] - C[i];
    }
    
    cout << max << endl;
    
    
    return 0;
}


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

int main() {
	int a;
	while (cin >> a, a) {
		unordered_map<int, int>U;
		for (int b = 0; b < a; b++) {
			int c; scanf("%d", &c);
			U[c]++;
		}
		for (auto b = U.begin(); b != U.end(); b++) {
			if (b->second * 2 > a) { cout << b->first << endl; goto l; }
		}
		puts("NO COLOR");
	l:;
	}
}

Measured memory_bytes: 4360
#include<bits/stdc++.h>
#define mx 100000
#define pb push_back
#define siz(v) v.size();
typedef unsigned long  ull;
typedef long long int lli;
using namespace std;

int main()
{
 	ios_base::sync_with_stdio(0);
 	cin.tie(0); cin.tie(0);
	
	int n;
	cin>>n;
	lli sum=0;
	
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			int rs=__gcd(i,j);
			for(int k=1;k<=n;k++){
				sum+=__gcd(rs,k);
			}
		}
	}
	cout<<sum<<endl;






 return 0;
 }


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

int main(){
    int K,N;
    cin >> K >> N;
    int A[N];
    for(int i=0;i<N;i++) cin >> A[i];

    int B[N];
    for(int i=0;i<N-1;i++) B[i]=A[i+1]-A[i];
    B[N-1]= K+A[0]-A[N-1];;

    sort(B,B+N);

    cout <<  K-B[N-1]  << endl;



}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long ll;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	ll g=gcd(a,b);
	return a/g*b;
}
 
ll digitsum(ll a){
	ll x=0;
	while(a>0){
		x+=a%10;
		a/=10;
	}
	return x;
}
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	if(b-a==c-b)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
}

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

#define MOD (int)(1e9+7)
typedef long long ll;
int N, K;
vector<vector<int>>E;
vector<char>used;
ll ans;

void solve(int i, int depth)
{
	used[i] = true;
	int cnt = 0;
	for (int j = 0; j < E[i].size(); j++)
	{
		if(used[E[i][j]])continue;

		ans *= max(K - 2, K - 1 - depth) - cnt;
		ans %= MOD;

		solve(E[i][j], depth + 1);
		cnt++;
	}
}

int main()
{
	cin >> N >> K;
	E.resize(N);
	for (int i = 0; i < N-1; i++)
	{
		int a, b; cin >> a >> b;
		a--; b--;

		E[a].push_back(b);
		E[b].push_back(a);
	}
	used.resize(N);

	ans = K;

	solve(0, 0);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,M;
vector<ll> par; vector<vector<pair<ll,ll>>> to;

void initialize(){
 par.resize(N); to.resize(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){
if( root(x) == root(y)){ return;}
else{
 par[root(x)] = root(y);}}

bool issame(int x, int y){
return root(x) == root(y);}

bool isroot(int x){
return par[x] == x;}

 

int main(){
  cin >> N >> M; initialize();
  vector<ll> x(N); vector<bool> visited(N,false);
 for(ll i = 0; i < M; i++){
   ll L,R,D; cin >> L >> R >> D; L--; R--; unite(L,R);
   to[L].push_back(make_pair(R,D)); to[R].push_back(make_pair(L,-D));}
  
  for(ll i = 0; i < N; i++){
    if( !isroot(i)){ continue;}
    
  x[i] = 0; visited[i] = true;
  //根iからの連結成分についてBFSを行い、矛盾なく距離を埋められるか調べる
   queue<ll> Q; Q.push(i);
    
    while(!Q.empty()){
      ll p = Q.front(); Q.pop();
      for(ll j = 0; j < (int) to[p].size(); j++){
        ll q = to[p][j].first; ll r = to[p][j].second;
        if(!visited[q]){ x[q] = x[p] + r; Q.push(q); visited[q] = true;}
        else{
          if( x[q] != x[p] + r){ //矛盾発生 
            cout << "No" << endl; return 0;}
         }
      }
    }
  }
  
  cout << "Yes" << endl; return 0;}
  
  
  

Measured memory_bytes: 14848
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
long long a[100010],b[100010],x[100010],v[100010];

int main()
{
//	cout<<a[0]<<" "<<b[0];
	long long n,c;
	cin>>n>>c;
	cin>>x[1]>>v[1];
	a[1]=v[1]-x[1];
	for(int i=2;i<=n;i++){
		cin>>x[i]>>v[i];
		a[i]=a[i-1]-x[i]+v[i]+x[i-1];
	}
	b[1]=v[n]-(c-x[n]);
	for(int i=2;i<=n;i++){
		b[i]=b[i-1]-(c-x[n-i+1])+v[n-i+1]+(c-x[n-i+2]);
	}
	long long ans=0;
	for(int i=2;i<=n;i++){
		a[i]=max(a[i-1],a[i]);
		b[i]=max(b[i-1],b[i]);
		ans=max(ans,max(a[i],b[i]));
	}
        ans=max(ans,max( a[n],b[n]) ) ;//疯狂查错--如果n=1则不执行上面的语句，所以要加上这一句特判
	long long ans1=0,ans2=0;
	for(int i=1;i<=n;i++){
		
		ans1=max(ans1, a[i]-x[i]+b[n-i] );
		ans2=max(ans2, b[i]-(c-x[n-i+1])+a[n-i] );
	}
	cout<<max( ans, max(ans1,ans2) )<<endl;
}

Measured memory_bytes: 3328
use proconio::{input, fastout};

use std::f64::consts::PI;

#[fastout]
fn main() {
    input!{
        A: f64,
        B: f64,
        H: f64,
        M: f64
    }
    
    let ath = H/12.0* 2.0*PI+2.0*PI/12.0*M/60.0;

    let bth = M/60.0* 2.0*PI;

    let diff = (ath-bth).abs();

    let res = (A.powf(2.0)+B.powf(2.0)-2.0*A*B*diff.cos()).sqrt();

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


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  string s;
  cin >> s;
  int siz = s.length();
  int left = 0, right = siz-1, ans = 0;
  bool ok = true;
  if (s[left] != s[right]) {
    if (s[left] == 'x') {
      ans++; left++; //末尾にxを追加
    }
    else if (s[right] == 'x') {
      ans++; right--;
    }
    else {
      ok = false;
    }
  }
  while (right - left >= 1 && ok) {
    if (s[left] == s[right]) {
      left++; right--;
    }
    else {
      if (s[left] == 'x') {
        ans++; left++; //xを挿入
      }
      else if (s[right] == 'x') {
        ans++; right--;
      }
      else {
        ok = false; break;
      }
    }
  }
  debug(left, right, ans);
  cout << (ok ? ans : -1) << endl;
  return 0;
}

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

int main(){
  int H, W;
  cin >> H >> W;
  char a[H][W];
  bool g[H], r[W];
  fill(g, g + H, false);
  fill(r, r + W, false);
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> a[i][j];
      if(a[i][j] == '#'){
        g[i] = true;
        r[j] = true;
      }
    }
  }
  for(int i = 0; i < H; i++){
    if(!g[i]) continue;

    for(int j = 0; j < W; j++){
      if(!r[j]) continue;
      cout << a[i][j];
    }
    cout << endl;
  }
  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;

#define int long long
const int N = 5002;
const int INF = 1e15 + 239;

int n;
int cost[N];
int val[N][N];

void add(int i1, int i2, int j1, int j2, int x) {
	val[i1][j1] += x;
	val[i2][j1] -= x;
	val[i1][j2] -= x;
	val[i2][j2] += x;
} 

void resolve() {
	auto gv = [&](int i, int j) {
		if (i < 0 || j < 0) return (int)0;
		return val[i][j];
	};
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			val[i][j] += gv(i - 1, j) + gv(i, j - 1) - gv(i - 1, j - 1);
		}
	}
}

void apply(vector<int> a) {
	vector<int> l(n);
	vector<int> r(n);
	{
		vector<int> st;
		for (int i = 0; i < n; i++) {
			while (!st.empty() && a[st.back()] <= a[i]) {
				st.pop_back();
			}
			if (st.empty()) {
				l[i] = -1;
			} else {
				l[i] = st.back();
			}
			st.push_back(i);
		}
	}
	{
		vector<int> st;
		for (int i = n - 1; i >= 0; i--) {
			while (!st.empty() && a[st.back()] < a[i]) {
				st.pop_back();
			}
			if (st.empty()) {
				r[i] = n;
			} else {
				r[i] = st.back();
			}
			st.push_back(i);
		}
	}
	for (int i = 0; i < n; i++) {
		add(l[i] + 1, i + 1, i, r[i], a[i]);
	}
}
	
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	

	int m;
	cin >> n >> m;
	for (int i = 0; i + 1 < n; i++) {
		cin >> cost[i];
	}
	vector<vector<int>> a(m);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int x;
			cin >> x;
			a[j].push_back(x);
		}
	}
	for (int i = 0; i < m; i++) {
		apply(a[i]);
	}
	resolve();
	int ans = -INF;
	for (int i = 0; i < n; i++) {
		int cs = 0;
		for (int j = i; j < n; j++) {
			ans = max(ans, val[i][j] - cs);
			if (j + 1 < n) {
				cs += cost[j];
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 206464
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main() {
    string str;
    cin >> str;
    int N = atoi(str.data());
    int sum = 0;

    for (auto i = 0; i < str.length(); i++) sum += str[i] - '0';

    cout << (N % sum == 0 ? "Yes" : "No") << endl;

    return 0;
}


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


int main() {
    int n, x;
    cin>>n;
    vector<int>l;
    map<int, int>m;
    for(int i=0; i<n; i++)
    {
        cin>>x;
        if(m.find(x) != m.end())
            m[x]++;
        else
        {
            m[x]=1;
            l.push_back(x);
        }
    }
    sort(l.begin(), l.end());
    int ans = 0;
    for(int i=0; i<l.size(); i++)
    {
        for(int j=i+1; j<l.size(); j++)
        {
            for(int k=j+1; k<l.size(); k++)
            {
                if(l[i]+l[j]>l[k])
                    ans+=(m[l[i]]*m[l[j]]*m[l[k]]);
            }
        }
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <algorithm>
#include <map>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
     
struct Node{
    Node *l,*r,*p;
    int s,v,m;
    Node():l(NULL),r(NULL),p(NULL){}
    static int Size(Node* x){
        return x?x->s:0;
    }
    static int Mini(Node* x){
        return x?x->m:1145141919;
    }
    Node* Update(){
        s=1+Size(l)+Size(r);
        m=min({v,Mini(l),Mini(r)});
        return this;
    }
    int Pos(){
        if(p&&p->l==this) return -1;
        if(p&&p->r==this) return 1;
        return 0;
    }
    void Rotate(){
        Node *q=p,*c;
        if(Pos()==1){
            c=l;
            l=p;
            p->r=c;
        }else{
            c=r;
            r=p;
            p->l=c;
        }
        if(c) c->p=p;
        p=p->p;
        q->p=this;
        if(p&&p->l==q) p->l=this;
        if(p&&p->r==q) p->r=this;
        q->Update();
    }
    Node* Splay(){
        while(p){
            int a=Pos(),b=p->Pos();
            if(b&&a==b) p->Rotate();
            if(b&&a!=b) Rotate();
            Rotate();
        }
        return Update();
    }
    Node* Idx(int i){
        if(i<Size(l)) return l->Idx(i);
        else if(i>Size(l)) return r->Idx(i-Size(l)-1);
        return Splay();
    }
} d[200000];
 
pair<Node*,Node*> Split(Node* x,int i){
    if(i<0) return MP((Node*)NULL,x);
    x=x->Idx(i);
    Node* c=x->r;
    if(c) c->p=NULL;
    x->r=NULL;
    return MP(x->Update(),c);
}
 
Node* Merge(Node* a,Node* b){
    if(!a||!b) return a?a:b;
    while(a->r) a=a->r;
    b->p=a->Splay();
    a->r=b;
    return a->Update();
}
 
int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    Node* w=NULL;
    REP(i,n){
        scanf("%d",&d[i].v);
        w=Merge(w,d[i].Update());
    }
    REP(_,q){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        if(x==0){
            auto r=Split(w,z);
            auto q=Split(r.first,z-1);
            auto p=Split(q.first,y-1);
            w=Merge(Merge(p.first,q.second),Merge(p.second,r.second));
        }else if(x==1){
            auto q=Split(w,z);
            auto p=Split(q.first,y-1);
            printf("%d\n",p.second->m);
            w=Merge(Merge(p.first,p.second),q.second);
        }else{
            w=w->Idx(y);
            w->v=z;
            w->Update();
        }
    }
}

Measured memory_bytes: 10532
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}



//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  ll S,W;cin>>S>>W;
  if(S<=W)cout<<"unsafe" <<endl;
  else cout<<"safe" <<endl;
}







Measured memory_bytes: 3628