akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using P = pair<int,int>;
using ll = long long; 

int main(){
    int n;
    cin>>n;
    int rt[n];
    int tmp;
    rep(i,n){
        cin>>tmp;
        rt[i]=tmp-1;
    }

    int now=0;
    int ans=0;
    bool flg=false;
    rep(i,n){
        if(now==1){
            flg=true;
            break;
        }
        now = rt[now];
        ans++;
    }

    if(flg==true)cout<<ans<<endl;
    else cout<<-1<<endl;

}


Measured memory_bytes: 640
def run(N):
    # 3, 5, 7のみの数値を全列挙
    targets = make357(N)
    cnt = 0
    for t in targets:
        if all(t.count(s) for s in '357'):
            cnt += 1
    return cnt


def make357(N):
    '''
    3, 5 ,7のみを含むN以下の数を全列挙
    ただし文字列として格納
    '''
    targets = []
    targets_i = ['3', '5', '7']  # i桁の357のみを含む数
    for _ in range(1, len(str(N))):
        tmp = []
        for s in '357':
            tmp += [t + s for t in targets_i if int(t + s) <= N]
        targets_i = tmp
        targets += targets_i
    return targets


def main():
    N = int(input())
    print(run(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5464
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll a,b; cin>>a>>b;
	if(a==1&&b==2 || a==2&&b==1)cout<<3<<'\n';
	else
		if(a==1&&b==3 || a==3&&b==1)cout<<2<<'\n';
		else
			if(a==3&&b==2 || a==2&&b==3)cout<<1<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read

H, N, *AB = map(int, read().split())

INF = 10 ** 10
dp = [INF] * (H + 1)
r = INF
dp[0] = 0

for a, b in zip(*[iter(AB)] * 2):
    for i in range(a, H + 1):
        dp[i] = min(dp[i], dp[i - a] + b)
    r = min(r, min(dp[-a:]) + b)

print(min(r, dp[-1]))


Measured memory_bytes: 41836
#include<bits/stdc++.h>
using namespace std;
const int N = 3005;
int A[N], n, id[N];
bool f[N];
bool cmp (int a, int b) { return A[a] < A[b]; }
vector<int>V[N];

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &A[i]), id[i] = i;
	for (int i = 1, u, v; i < n; ++i) scanf("%d%d", &u, &v), V[u].emplace_back(v), V[v].emplace_back(u);
	sort(id + 1, id + n + 1, cmp);
	for (int i = 1, u; i <= n; ++i) {
		u = id[i];
		for (auto v : V[u]) if (A[v] < A[u]) {
			if (!f[v]) { f[u] = 1; break ; }
		}
	}
	for (int i = 1; i <= n; ++i) if (f[i]) printf("%d ", i);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int n, p[20], ans = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    for(int i=1;i<n-1;i++){
        if((p[i-1] <= p[i] && p[i] <= p[i+1]) || (p[i+1] <= p[i] && p[i] <= p[i-1])){
            ans++;
        }
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n;
	int d[52];
	scanf("%d",&n);
	rep(i,n)scanf("%d",&d[i]);
	
	sort(d,d+n);
	int ret = d[0];
	int e[52];
	rep(i,n){
		if(i%2 == 0)e[i] = d[i];
		else e[i] = 24-d[i];
	}
	sort(e,e+n);
	for(int i = 0 ; i+1 < n ; i ++){
		ret = min ( ret , e[i+1]-e[i] );
	}
	cout << ret << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

string s;

LL rec(int& idx){
    idx++;
    if(s[idx] != '['){
        // 数値
        LL now = 0;
        while(s[idx] != ']'){
            now *= 10;
            now += s[idx] - '0';
            idx++;
        }
        idx++;
        // cout << (now+1)/2 << " " << idx << endl;
        return (now+1)/2;
    }
    vector<LL> ward;
    while(s[idx] != ']') ward.push_back(rec(idx));
    sort(all(ward));
    LL ret = 0;
    rep(i, (ward.size()+1)/2){
        ret += ward[i];
    }
    idx++;
    // cout << ret << " " << idx << endl;
    return ret;
}

int main(){
    fastcin();

    int n;
    cin >> n;
    rep(t, n){
        cin >> s;
        int idx = 0;
        cout << rec(idx) << endl;
    }

}


Measured memory_bytes: 3204
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int MAX = 200000;

int n, k, a;
bool ok[MAX];

int main() {
    while (cin >> n >> k) {
        if (n == 0 && k == 0) break;
        memset(ok, 0, sizeof(ok));
        int rem = 0;
        for (int i = 0; i < k; ++i) {
            cin >> a; 
            if (a == 0) ++rem;
            else ok[a] = true;
        }
        int res = 1;
        int i = 0, j = 0;
        while (true) {
            if (rem > 0 || ok[j]) {
                if (!ok[j]) --rem;
                ++j;
                chmax(res, j-i);
            }
            else if (i < j) {
                if (!ok[i]) ++rem;
                ++i;
            }
            else {
                ++i; ++j;
            }
            if (j == n+1) break;
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1364
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n; scanf("%d", &n);
	int x[1000], y[1000];
	for(int i = 0; i < n; i++) scanf("%d %d", &x[i], &y[i]);
	int p = (abs(x[0]) + abs(y[0])) % 2;
	for(int i = 1; i < n; i++){
		if((abs(x[i]) + abs(y[i])) % 2 != p){ puts("-1"); return 0; }
	}
	int m = 31 + (p ? 0 : 1);
	printf("%d\n", m);
	for(int i = 0; i < m; i++) printf("%d%c", i == 31 ? 1 : 1 << i, i + 1 == m ? '\n' : ' ');
	char c[2][2] = {'L', 'D', 'U', 'R'};
	if(!p) for(int i = 0; i < n; i++) x[i]--;
	for(int i = 0; i < n; i++){
		int u = x[i] + y[i], v = x[i] - y[i];
		for(int j = 0; j < 31; j++) putchar(c[((u - 1) / 2 + (1 << 30)) >> j & 1][((v - 1) / 2 + (1 << 30)) >> j & 1]);
		if(!p) putchar('R');
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <cstdio>
using Int = long long;
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
int main()
{
    int N; cin >> N;
    vector<string> S(N); REP(i, N) cin >> S[i];
    vector<int> counter(26, 50);
    for (auto s : S) {
        vector<int> counter2(26, 0);
        for (auto c : s) {
            counter2[c-'a']++;
        }
        REP(i, 26) counter[i] = min(counter[i], counter2[i]);
    }
    REP(i, 26) REP(j, counter[i]) putchar('a' + i);
    putchar('\n');
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,m,x;cin>>n>>m>>x;
  int a[101]={};
  REP(i,m){
    int aa;cin>>aa;
    a[aa]=1;
  }
  int way0=0;
  int wayn=0;
  for(int i=1;i<=x;i++){
    way0+=a[i];
  }
  for(int j=x;j<=n;j++){
    wayn+=a[j];
  }
  P(min(way0, wayn));
  return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

const ll N_MAX = 400005;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];
void make(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll) i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

ll combination(ll C, ll D){
    return C*(C-1)/2;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    map<ll, ll> mp;
    REP(i, N) mp[A[i]]++;
    ll res = 0;
    for(auto x: mp){
    	res += combination(x.second, 2);
    }

    REP(i, N){
    	ll tmp = 0;
    	tmp += res;
    	tmp -= combination(mp[A[i]], 2);
    	tmp += combination(mp[A[i]]-1, 2);
    	cout << tmp << endl;
    }
    return 0;
}

Measured memory_bytes: 20480
N,D = map(int, input().split())
#
points = []
for i in range(N):
    point = list(map(int,input().split()))
    points.append(point)

int_length_count = 0
for i in range(N):
    ref_ppint = points[i]
    for j in range(i+1,N):
        tar_point = points[j]
        distans_of_coordinate = [x - y for (x,y) in zip(ref_ppint, tar_point)]
        squared_distans_of_coordinate =list(map(lambda x: x ** 2, distans_of_coordinate))
        if (sum(squared_distans_of_coordinate) ** .5).is_integer():
            int_length_count += 1
print(int_length_count)

Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;



int main(void){
  int n;
  ll l;
  cin >> n >> l;
  vector<ll> a(n);
  REP(i, 0, n) {
    cin >> a[i];
  }

  // exists consecutive ropes r_i, r_{i + 1}. r_i + r_{i + 1} >= l ?
  bool ok = 0;
  int pos = -1;
  REP(i, 0, n - 1) {
    if (a[i] + a[i + 1] >= l) {
      ok = 1;
      pos = i;
    }
  }
  if (!ok) {
    cout << "Impossible" << endl;
    return 0;
  }
  cout << "Possible" << endl;
  REP(i, 0, pos) {
    cout << i + 1 << endl;
  }
  for (int i = n - 2; i > pos; --i) {
    cout << i + 1 << endl;
  }
  cout << pos + 1 << endl;
}


Measured memory_bytes: 1536
#include <iostream>
using namespace std;
int main()
{
	int a;
	cin >> a;
	string s[50];
	int t[50];
	for (int i = 0;i < a;i++) {
		cin >> s[i];
		cin >> t[i];
	}
	string x;
	cin >> x;
	int z = 0;
	for (int i = 0;i < a;i++) {
		if (s[i] == x) {
			break;
		}
		else {
			z++;
		}
	}
	int j=0;
	int i;
	for (i = z + 1;i < a;i++) {
		j += t[i];
	}
	cout << j;
}

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

int main(){
	string s;
	cin >> s;

	if(s == "SUN") cout << 7 << endl;
	if(s == "MON") cout << 6 << endl;
	if(s == "TUE") cout << 5 << endl;
	if(s == "WED") cout << 4 << endl;
	if(s == "THU") cout << 3 << endl;
	if(s == "FRI") cout << 2 << endl;
	if(s == "SAT") cout << 1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int d[10],v1,v2;
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],&d[8],&d[9],&v1,&v2)!=EOF){
		int sum=0,table[11];
		for(int i=0;i<10;++i){
			table[i]=sum;
			sum+=d[i];
		}
		table[10]=sum;
		for(int i=10;i>=0;--i){
			if(table[i]<(double)(v1*sum)/(v1+v2)){
				cout<<i+1<<"\n";
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
struct custom_hash 
{
    static unsigned long long splitmix64(unsigned long long x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(unsigned long long x) const 
    {
        static const unsigned long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
mt19937 random_generator(chrono::steady_clock::now().time_since_epoch().count());

int s, w; 
void read()
{
	cin >> s >> w; 
}

void solve()
{
	if (w >= s)
	cout << "unsafe" << endl;
	
	else 
	cout << "safe" << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	read();
	solve();
}


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


int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int sum;
  sum = 500*A + 100*B + 50*C;
  
  int answer = 0;
  rep(i, A+1){
    if(X-i*500 < 0){
      break;
    }else{
      rep(j, B+1){
        if(X-i*500-j*100 < 0){
          break;
        }else{
          if((X-i*500-j*100)/50 <= C) answer++;
        }
      }
    }
  }
  
  cout << answer;
  
}

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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

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

const ll SIZE = 1e5+10;

char alpha, beta;

int main(){
  cin >> alpha;  
  if(alpha <= 'Z' && alpha >= 'A')cout << "A\n";
  else
  {
      cout << "a\n";
  }
  
}

Measured memory_bytes: 3576
A, B = map(int, input().split())
N = A*B
if A > 9 or B > 9:
  print("-1")
  exit()
  
for i in range(1, 10):
  for j in range(1, 10):
    if N == i*j:
      print(N)
      exit()
print("-1")      

Measured memory_bytes: 3060
a=Array.new(3).map{Array.new(3)}
3.times do |i|
    a[i]=gets.split.map(&:to_i)
end
n=gets.to_i
b=[]
n.times do |i|
    b[i]=gets.to_i
end

c=Array.new(3,0).map{Array.new(3,0)}
n.times do |i|
    3.times do |j|
        3.times do |k|
            if a[j][k]==b[i]
                c[j][k]+=1
            end
        end
    end
end

sum=0
3.times do |i|
    if c[i].sum==3
        puts "Yes"
        return
    end
    sum=0
    3.times do |j|
        sum+=c[j][i]
    end
    if sum==3
        puts "Yes"
        return
    end
end

if c[0][0]+c[1][1]+c[2][2]==3
    puts "Yes"
    return
end

if c[0][2]+c[1][1]+c[2][0]==3
    puts "Yes"
    return
end

puts "No"


Measured memory_bytes: 14384
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
 
void Main() {
  ll a,b,c,d,x;
  cin >> a >> b >> c >> d >> x;
  c=min(c,a*4);
  c=min(c,b*2);
  ll ans=0;
  if(x%2) {
    ans+=c;
    x--;
  }
  pr(ans+min(x*c,x/2*d));
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

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

int dp[5005][5005];

int main() {
    int N;
    string S;
    cin >> N >> S;
    for(int i=N-1; i>=0; i--) {
        for(int j=N-1; j>=0; j--) {
            if(S[i] != S[j]) dp[i][j] = 0;
            else dp[i][j] = dp[i+1][j+1]+1;
        }
    }

    int res = 0;
    rep(i, N) rep(j, N) {

        //iが左、jが右で固定
        if(i >= j) continue;

        //j-iがi,jからの共通部分の長さより小さいとき、重なりが生じているためNG
        int now = min(dp[i][j], j-i);
        
        res = max(res, now);
    }

    cout << res << endl;
    return 0;
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

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

vector <int> v;
int k,n,l;

int main(){

  scanf("%d %d",&n,&k);
  REP (i, n) {
    scanf("%d",&l);
    v.push_back(l);
  }

  sort(v.begin(), v.end(), greater<int>());


  int sum = 0;
  auto itr = v.begin();
  while (itr != v.begin() + k) {
    sum += *itr;
    itr++;
  }

  printf("%d\n",sum);
}


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

int  main()
{
	string s;
	cin >> s;
	set<char> st;
	rep(i, 3)
		st.insert(s[i]);
	if (st.size() == 3)
		cout << "Yes\n";
	else 
		cout << "No\n";

	return (0);
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
d = {}

def fac2(n):
    if n < 2:
        return 0
    ans = n * (n-1) // 2
    return ans

for key, val in c.items():
    d[key] = fac2(val)

d = {key:fac2(val) for key, val in c.items()}
sum_val = sum(d.values())
ans = [sum_val - d[a] + fac2(c[a]-1) for a in A]
print(*ans, sep="\n")


Measured memory_bytes: 37500
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,k,l,b;
double x,c;
char u[3];
int main()
{
  for(cin>>n;i<n;i++){
    cin>>x>>u;
    if(strcmp(u,"BTC")==0)x*=380000;
    c+=x;
  }
  printf("%.5f",c);
}

Measured memory_bytes: 384
using System;
using System.Linq;

namespace ITP1_11_C {
    class Dice {
        private int[] _dice;

        public int Top {
            get {
                return _dice[0];
            }
        }

        public Dice(int[] dice) {
            _dice = dice;
        }

        public bool IsSame(int[] arr) {
            for(int i = 0; i < 6; i++) {
                for(int j = 0; j < 4; j++) {
                    if (_dice.SequenceEqual(arr))
                        return true;
                    Move('R');
                }
                Move(i % 2 == 0 ? 'E' : 'N');
            }
            return false;
        }
        
        private bool IsSetTop(int top) {
            if (_dice[0] == top)
                return true;
            string dir = "NNNEEE";
            foreach (var d in dir) {
                Move(d);
                if (_dice[0] == top)
                    return true;
            }
            return false;
        }

        public void Move(string dir) {
            foreach (var d in dir) {
                Move(d);
            }
        }

        public void Move(char dir) {
            switch (dir) {
                case 'E':
                    Replace(0, 3, 5, 2);
                    break;
                case 'W':
                    Replace(0, 2, 5, 3);
                    break;
                case 'N':
                    Replace(0, 1, 5, 4);
                    break;
                case 'S':
                    Replace(0, 4, 5, 1);
                    break;
                case 'R':
                    Replace(1, 3, 4, 2);
                    break;
            }
        }

        private void Replace(int a, int b, int c, int d) {
            int temp = _dice[a];
            _dice[a] = _dice[b];
            _dice[b] = _dice[c];
            _dice[c] = _dice[d];
            _dice[d] = temp;
        }
    }

    class Program {
        static void Main(string[] args) {
            int[] d1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] d2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Dice dice = new Dice(d1);
            Console.WriteLine(dice.IsSame(d2) ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 9876
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

bool T[605][605];

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}

int main() {
  // ios_base::sync_with_stdio(0);

  int N, D1, D2;
  scanf("%d%d%d", &N, &D1, &D2);
  vector<int> Ds = {D1, D2};

  REP(i,2*N)REP(j,2*N) T[i][j] = true;
  for (auto d: Ds) {
    int p = 1;
    while (d % (4 * p * p) == 0) p *= 2;
    if ((d/p/p) % 4 == 1) {
      REP(i,2*N)REP(j,2*N) if ((i/p) % 2 != (j/p) % 2) T[i][j] = false;
    } else {
      REP(i,2*N)REP(j,2*N) if ((i/p) % 2 == 1) T[i][j] = false;
    }
  }
  //
  // REP(i,2*N) {
  //   REP(j,2*N) printf(T[i][j] ? "#" : ".");
  //   printf("\n");
  // }

  vector<PII> good;
  REP(i,2*N)REP(j,2*N) if (T[i][j]) {
    good.pb({i,j});
  }

  assert(good.size() >= N*N);
  REP(i,N*N) printf("%d %d\n", good[i].st, good[i].nd);
}


Measured memory_bytes: 2804
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define cinf(n,x,y,z) for(int i=0;i<(n);i++) cin >> x[i]>>y[i]>>z[i];
typedef long long int ll;
using namespace std;

int main(){
	int n; cin >>n;
	vector<int> c(n-1),s(n-1),f(n-1);
	cinf(n-1,c,s,f);
	for(int i=0;i<n;i++){
		int time=0;
		for(int j=i;j<n-1;j++){
			if(time<s[j])time=s[j];
			else if(time%f[j]==0);
			else time=time+f[j]-time%f[j];
			time+=c[j];
		}
		cout << time << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;
for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}


Measured memory_bytes: 2512
k = int(input())
l = 0
s = set()
for i in range(1,9000000):
    l = (l*10+7)%k
    if l == 0:
        print(i)
        exit()
    else:
        s.add(l)
        if len(s) == i-1:
            print(-1)
            exit()
print(-1)
exit()

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

int numofbits5(long bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main(){
	int n,s,ret,sum;
	while(cin >> n >> s && n || s){
		ret = 0;
		for(int i=0;i<(1<<10);i++){
			sum = 0;
			if(numofbits5(i)!=n)continue;
			for(int j=0;j<10;j++){
				if( (1<<j) & i )sum += j;
			}
			if(sum == s)ret++;
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
  string s;cin >> s;
  if(s=="Sunny"){
    cout <<"Cloudy"<<endl;  
  }else if(s=="Cloudy"){
    cout << "Rainy" <<endl;
  }else if(s=="Rainy"){
    cout << "Sunny" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
   if(A+B>C+D){
     cout<<"Left"<<endl;
   }
  else if(A+B==C+D){
    cout<<"Balanced"<<endl;
  }
  else{
    cout<<"Right"<<endl;
  }
}

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

int main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	int sum = 0;

	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
		sum += vec.at(i);
	}
	sort(vec.begin(), vec.end());
	if (sum - vec.at(N - 1) > vec.at(N - 1))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define PI acosl(-1.0)
int main(){
  int a,b,x;
  scanf("%d%d%d",&a,&b,&x);
  
  long double theta, tangent;
	if(2*x<=a*a*b){
    tangent = (2.0*x)/(a*b*b);
    theta = PI/2.0 - atanl(tangent);
  }
  else{
    tangent = (2.0*(a*a*b-x))/(a*a*a);
    theta = atanl(tangent);
  }
  printf("%.10Lf",theta*180/PI);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl
long long solve(long long n){
	if(n == 1) return 1;
	return 2 * solve(n / 2) + 1;
}
int main(){
	//freopen("input.txt", "r",stdin);
	long long h; cin>>h;
	cout<<solve(h)<<endl;
	return 0;
}
	


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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	string S;
	cin >> S;

	bool OK = true;
	for (int ii = 0; ii < A + B + 1; ++ii){
		if (ii == A){
			if (S[ii] != '-'){
				OK = false;
			}
		} else {
			if (S[ii] == '-'){
				OK = false;
			}
		}
	}

	if (OK){
	cout << "Yes" << "\n";
	} else{
	cout << "No" << "\n";

	}

	

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
typedef long long LL;
const int N=1e5+5;
LL n,x,a[N],ans;
int main()
{
	cin>>n>>x;
	rep(i,1,n)cin>>a[i];
	sort(a+1,a+1+n);
	a[n+1]=1e18;
	rep(i,1,n+1)
	{
		a[i]+=a[i-1];
		if(x<a[i]){ans=i-1;break;}
	}
	if(x!=a[n])ans=min(n-1,ans);
	cout<<max(0ll,ans)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	if(a+b < c) cout << a+b+1+b << '\n';
	else cout << c+b << '\n';
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == 1)return;for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(std::vector<T>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}

//CODE
void solve(void)
{
  int N,K;
  cin>>N>>K;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }
  SORT_(vec);
  int ANS = INF;
  for (int i = 0; i <= N-K; i++)
  {
    chmin(ANS,vec[i+K-1] - vec[i]);
  }
  cout<<ANS<<endl;
  
  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <tgmath.h>
#include <time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

char s[111111];
bool nyan = true;

main()
{
    scanf("%s", s);
    int l = strlen(s);
    for (int i = 0; i < l; i++)
    {
        switch (s[i])
        {
        case 'd':
            if (s[l - i - 1] != 'b')
            {
                nyan = false;
            }
            break;
        case 'b':
            if (s[l - i - 1] != 'd')
            {
                nyan = false;
            }
            break;
        case 'p':
            if (s[l - i - 1] != 'q')
            {
                nyan = false;
            }
            break;
        case 'q':
            if (s[l - i - 1] != 'p')
            {
                nyan = false;
            }
        default:
            break;
        }
        if (!nyan)
        {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import qualified Data.IntSet as IS
import qualified Data.IntMap as IM
import Debug.Trace

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

type MyMap = IM.IntMap IS.IntSet

mkDisRel :: Int -> [[Int]] -> MyMap
mkDisRel n abs = foldr op init abs
  where
    initSet x = IS.delete x (IS.fromList [1..n])
    init = IM.fromList [(x,initSet x) | x <- [1..n]]
    op [a,b] =   IM.adjust (IS.delete a) b
               . IM.adjust (IS.delete b) a

mkOEList :: Int -> MyMap -> Maybe [Int]
mkOEList n disRel =
  mkOELSub n disRel (IS.fromList [1..n]) []

mkOELSub :: Int -> MyMap -> IS.IntSet -> [Int] -> Maybe [Int]
mkOELSub n disRel yet acc
  | IS.null yet = Just acc
  | otherwise = case oneComp of
      Nothing -> Nothing
      Just (comp, done) ->
        mkOELSub n disRel (IS.difference yet done) (comp:acc)
  where
    k:_ = IS.toList yet
    oneComp = mkOneComp disRel k
    
mkOneComp :: MyMap -> Int -> Maybe (Int, IS.IntSet)
mkOneComp disRel k =
  case mkOneCompSub disRel [k] IS.empty IS.empty of
    Nothing -> Nothing
    Just (this, that) -> Just (abs(IS.size(this) - IS.size(that)),
                               IS.union this that)

mkOneCompSub :: MyMap -> [Int] -> IS.IntSet -> IS.IntSet -> 
                Maybe (IS.IntSet, IS.IntSet)
-- mkOneCompSub disRek ks this that
--   | trace ("mkOneCompSub " ++ show ks ++ " " ++ show this ++ show that) False = undefined
mkOneCompSub disRel [] this that = Just (this, that)
mkOneCompSub disRel (k:ks) this that =
  if IS.member k that then Nothing
  else if IS.member k this then mkOneCompSub disRel ks this that
  else case IM.lookup k disRel of
  Nothing -> mkOneCompSub disRel ks this that
  Just ls -> case mkOneCompSub disRel (IS.toList ls) that (IS.insert k this) of
    Nothing -> Nothing
    Just (that', this') -> mkOneCompSub disRel ks this' that'

findMinimum :: [Int] -> Int
findMinimum is = IS.findMin (IS.filter (>= 0) cands)
  where
    cands = foldr op (IS.singleton 0) is
      where
        op i iset = IS.union (IS.map (+   i)  iset)
                          (IS.map (+ (-i)) iset)

solve :: Int -> Int -> [[Int]] -> Int
solve n m abs =
  case mkOEList n disRel of
    Nothing -> -1
    Just oddEvenList ->
      let diff = findMinimum oddEvenList
          x = (n + diff) `div` 2
          y = n - x
      in x*(x-1) `div` 2 + y*(y-1) `div` 2
  where
    disRel = mkDisRel n abs

main = do
  conts <- B.getContents
  let [n, m] : abs = map bsReadInts (B.lines conts)
      answer = solve n m abs
  putStrLn (show answer)


Measured memory_bytes: 44284
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  string S;
  cin >> S;

  if(S.at(1)=='B')  cout << "ARC" << endl;
  else  cout << "ABC" << endl;

  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <algorithm>

#define BUF 200002
#define LIM_N 100001

char str[BUF];

long long N;

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%lld", &N);
}

int get_digit(long long n) {
	long long digit = 1;
	int count = 0;

	for (digit = 1; digit < n; digit *= 10) {
		count++;
	}
	if (digit == n) {
		count++;
	}

	return count;
}

int solve() {
	int min_digit = get_digit(N);
	for (long long a = 1; a*a <= N; a++) {
		if (N % a == 0) {
			int temp_digit = get_digit(N / a);
			min_digit = min_digit < temp_digit ? min_digit : temp_digit;
		}
	}
	return min_digit;
}

int main(void) {
	receive_input();

	printf("%d\n", solve());

	return 0;
}


Measured memory_bytes: 128
n = int(input())
trs = [int(input()) for _ in range(n)]
cum = []
cannot = False

acc = 0
for i in range(n):
  acc = max(acc, i + trs[i] // 10)
  acc = min(acc, n -  1)
  cum.append(acc)

rev = []
acc = 0
for i in range(n):
  acc = max(acc, i + trs[n - 1 - i] // 10)
  acc = min(acc, n - 1)
  rev.append(acc)

ind = 0
tmp = 0
while True:
  ind = cum[ind]
  if ind == n - 1:
    break
  if ind == tmp:
    cannot = True
    break
  tmp = ind

ind = 0
tmp = 0
while True:
  ind = rev[ind]
  if ind == n - 1:
    break
  if ind == tmp:
    cannot = True
    break
  tmp = ind

if cannot:
  print("no")
else:
  print("yes")


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

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

int main()
{
  ll N, A, B, C, D, E; cin >> N >> A >> B >> C >> D >> E;

  ll m = min({A, B, C, D, E});
  cout << (N+m-1)/m+4 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    string S;

    cin >> S;

    bool flag = false;

    for(int i = 0; i < 2; i++){
        if(S[i] != S[i+1]){
            flag = true;
            break; 
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }else{
        cout <<  "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, A, B = MAP()

if B <= A:
  print("delicious")
elif B-A <= X:
  print("safe")
else:
  print("dangerous")
  

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

int main(){
    int n;
    cin>>n;
    int heights[n], min_cost[n] = {0};
    for(int ind=0; ind<n; ind++)
        cin>>heights[ind];
    for(int ind=1; ind<n; ind++){
        int one_step = INT_MAX;
        int two_step = INT_MAX;
        if((ind-1)>=0) one_step = min_cost[ind-1] + abs(heights[ind]-heights[ind-1]);
        if((ind-2)>=0) two_step = min_cost[ind-2] + abs(heights[ind]-heights[ind-2]);
        min_cost[ind] = min(one_step, two_step);
    }
    cout << min_cost[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>

const int MAX_N=1000000;

typedef long long ll;

using namespace std;

ll n,dat[2*MAX_N-1];

void init(int n_){
	n=1;
	while(n<n_)n*=2;
}

void update(int k,ll a){
	k+=n-1;
	dat[k]=a;
	
	while(k>0){
		k=(k-1)/2;
		dat[k]=max(dat[2*k+1],dat[2*k+2]);
	}
}

ll query(int a,int b,int k,int l,int r){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k];
	else {
		ll vl=query(a,b,k*2+1,l,(l+r)/2);
		ll vr=query(a,b,k*2+2,(l+r)/2,r);
		return max(vl,vr);
	}
}

int main(void){
	
	ll in,m,ans=0;
	
	cin >> m;
	
	init(m);
	
	for(int i=0;i<m;i++){
		cin >> in;
		update(in,in+query(1,in+1,0,0,n));
		//ans=max(ans,dat[in+n-1]);
	}
	cout << m*(m+1)/2-query(1,m+1,0,0,n) << endl;
	
	return 0;
}

Measured memory_bytes: 2744
#include <iostream>
#include <cstring>

using namespace std;

char a[102],b[102];
int N,M;

int main()
{
    cin.getline(a,sizeof(a));
    cin.getline(b,sizeof(b));
    N = strlen(a),M = strlen(b);
    if(N > M)
        cout <<"GREATER";
    else if(N < M)
        cout <<"LESS";
    else
    {
        for(int i = 0; i < N ; ++i)
            if(a[i] > b[i])
            {
                cout <<"GREATER";
                return 0;
            }
            else if(b[i] > a[i])
            {
                cout <<"LESS";
                return 0;
            }
        cout <<"EQUAL";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i,a) for(i = 0;i < a;i++)
using namespace std;
int main(void)
{
	int n,i,s=0,m=0;
	
	fo(i,4){
		cin >> n ;
		s += n ;
	}
	m = s / 60 ;
	s = s % 60 ;
	cout << m << "\n" << s << endl ;
	
	return 0;
}

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

int main() {
  int N, count = 0;

  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      count += vec.at(i) * vec.at(j);
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
# Not Divisible

N = int(input())
A = [int(n) for n in input().split()]

check = [0] * 1000001
A.sort()

ok = [-1]
p = 0
for a in A:
    if a == p:
        if ok[-1] == p:
            ok = ok[:-1]
        continue
    p = a
    if check[a] == 1:
        continue
    for i in range(a, 1000001, a):
        check[i] = 1
    ok.append(a)

print(len(ok) - 1)


Measured memory_bytes: 224916
N, Y = list(map(lambda x: int(x), input().split(" ")))
flag = False
ans = []

for a in range(2001):
  for b in range(2001):
    if 9000 * a + 4000 * b == (Y - 1000 * N) and a + b <= N:
      flag = True
      ans.append((a, b, (N-a-b)))

if len(ans) == 0:
  print("-1 -1 -1")
else:
  print("{} {} {}".format(ans[0][0], ans[0][1], ans[0][2]))

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    int count = 0;
    String ABC;

    for (int i = 0; i < N-2; i++){
      ABC = S.substring(i, i + 3);
   //   System.out.println(ABC);
      if (ABC.equals("ABC")){
        count++;
      }
    }
    System.out.println(count);
}
}


Measured memory_bytes: 23124
import sys
input = sys.stdin.buffer.readline

def main():
    T1,T2 = map(int,input().split())
    A1,A2 = map(int,input().split())
    B1,B2 = map(int,input().split())
    l = (A1-B1)*T1 + (A2-B2)*T2
    if l == 0:
        print("infinity")
    elif l > 0:
        if A1 > B1:
            print(0)
        else:
            d = (B1-A1)*T1
            if d%l == 0:
                ans = 2*(d//l)
            else:
                ans = 1+2*(d//l)
            print(ans)
    else:
        l *= -1
        if B1 > A1:
            print(0)
        else:
            d = (A1-B1)*T1
            if d%l == 0:
                ans = 2*(d//l)
            else:
                ans = 1+2*(d//l)
            print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 
vector<int> val_list;

void createVal(int keta,int count,int val,string flag1,string flag2,string flag3){
    if(count==keta){
        if(flag1 + flag2 + flag3 == "111")    val_list.push_back(val);
    }else{
        count++;
        createVal(keta,count,val*10+7,"1",flag2,flag3);
        createVal(keta,count,val*10+5,flag1,"1",flag3);
        createVal(keta,count,val*10+3,flag1,flag2,"1");
    }
}

int main(){

    int N;
    cin >> N;

    int keta = to_string(N).length();
    if(N < 357){
        cout << 0;
    }else{
        for( int ni = keta ; ni >= 3  ; ni-- ){
            int val = 0;    
            int count = 0;
            createVal(ni,count,val,"","","");
        }

        while(val_list[0] > N) val_list.erase(val_list.begin());

        cout << val_list.size() << endl;
        
        //for( int ni = 0 ; ni < val_list.size() ; ni++ )  cout << val_list[ni] << endl;

        








    }

}

Measured memory_bytes: 512
from bisect import bisect_right
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    stream = []
    for a in A:
        idx = bisect_right(stream, -a)
        if idx < len(stream):
            stream[idx] = -a
        else:
            stream.append(-a)

    print(len(stream))


if __name__ == "__main__":
    main()


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

using namespace std;

#define hash sodnf9843bsd
#define ll long long
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define YESNO(ans) cout << (ans?"YES":"NO") << endl
#define prec(x) cout << fixed << setprecision(x)
#define pqueue priority_queue
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int n, w;cin>>n>>w;
    int iw[111], iv[111];
    _fi(n) cin>>iw[i]>>iv[i];

    ll dp[100005] = {};
    for(int i = 0;i < n;i++){
        for(int j = w;j >= iw[i];j--){
            dp[j] = max(dp[j], iv[i]+dp[j-iw[i]]);
        }
    }

    cout << dp[w] << endl;

    return 0;
}


Measured memory_bytes: 1024
import numpy as np
def LCS(s,t,rec=False):
  S=np.array(list(s))
  T=np.array(list(t))
  LS,LT=len(S),len(T)
  dp=np.zeros((LS+1,LT+1))
  for n in range(1,LS+1):
    dp[n,1:]=dp[n-1,:-1]+(S[n-1]==T)
    np.maximum(dp[n],dp[n-1],out=dp[n])
    np.maximum.accumulate(dp[n],out=dp[n])
  if rec:
    tmp=[]
    while LS>0 and LT>0:
      if S[LS-1]==T[LT-1]:
        LS,LT=LS-1,LT-1
        tmp.append(S[LS])
      elif dp[LS,LT]==dp[LS-1,LT]:
        LS-=1
      else:
        LT-=1
    return ''.join(reversed(tmp))
  else:
    return dp[LS][LT]
s=input()
t=input()
print(LCS(s,t,True))

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

using namespace std;

void solve(string s) {
    for (int i = 0; i < 3; i++) {
        int ni = 3 * i;
        if ((s[ni] != 's') && (s[ni] == s[ni + 1] && s[ni] == s[ni + 2])) {
            cout << s[ni] << endl;
            return;
        } else if ((s[i] != 's') && (s[i] == s[i + 3] && s[i] == s[i + 6])) {
            cout << s[i] << endl;
            return;
        }
    }

    if ((s[4] != 's') && ((s[4] == s[0] && s[4] == s[8]) || (s[4] == s[2] && s[4] == s[6]))) {
        cout << s[4] << endl;
        return;
    }

    cout << "d" << endl;
}

int main()  {
    string s;
    while (cin >> s)
        solve(s);

    return 0;
}


Measured memory_bytes: 3112