akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;

int main()
{ 
fast;
ll x;
cin>>x;


for(ll a=-120;a<=120;a++)
    for(ll b=-120;b<=120;b++)
        if(a*a*a*a*a-b*b*b*b*b==x)
        {
          cout<<a<<" "<<b<<endl;
           return  0;
        }
}

Measured memory_bytes: 3656
#include <stdio.h>

int main(void) {
	char b;
	int n = 0;
	
	while(scanf("%c", &b) != EOF){
		if(b == '\n') {
			if(n == 0) break;
			printf("%d\n", n);
			n = 0;
		}
		else{
			n += b - '0';
		}
	}
	return 0;
}

Measured memory_bytes: 536
#include <iostream>

using namespace std;

int main()
{
	int a[100], n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = n - 1; i > 0; i--) {
		cout << a[i] << " ";
	}
	cout << a[0] << endl;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void){
    int a,b,c;
    int i,count=0;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a<1||10000<a){
        printf("error\n");
        return 0;
    }
    if(b<1||10000<b){
        printf("error\n");
        return 0;
    }
    if(c<1||10000<c){
        printf("error\n");
        return 0;
    }
    if(a>b){
        printf("error\n");
        return 0;
    }
    
    for(i=a;i<=b;i++){
        if(c%i==0){
            count++;
        }
    }
    printf("%d\n",count);
    
    return 0;
}


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

using namespace std;
#define int int64_t
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

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

   int n, k, a, ans = 0, cnt = 0;
   cin >> n >> k;
   vector<int> x;

   rep(i, n)
   {
      cin >> a;
      x.push_back(a);
   }

   sort(all(x));

   rep(i, n - k)
   {
      cnt += x[i];
   }
   cout << cnt << '\n';
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    ll n,i,x,y,a,b,m,c,ans=LLONG_MAX;
    cin>>a>>b>>m;
    ll arr[a],arr1[b];
    for (i=0;i<a;i++){
        cin>>arr[i];
    }
    for (i=0;i<b;i++){
        cin>>arr1[i];
    }
    for (i=0;i<m;i++){
        cin>>x>>y>>c;
        x--;
        y--;
        ans=min(ans,arr[x]+arr1[y]-c);
    }
    //cout<<ans<<'\n';
    sort(arr,arr+a);
    sort(arr1,arr1+b);
    ans=min(ans,arr[0]+arr1[0]);
    cout<<ans<<'\n';

}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
int P[MAX_N];


int main2() {
  int N = nextInt();
  REP(i, N) P[i] = nextInt();
  int ans = 0;
  int mi = 1001001001;
  REP(i, N) {
    if (mi > P[i]) {
      ans++;
      mi = P[i];
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 1024
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    x = [0] * N
    tot = 0
    for i in range(N-1, 0, -1):
        tot += A[i]
        x[i] = tot

    ans = 0
    for i in range(N-1):
        ans += A[i] * x[i+1]
    ans = ans % (10**9 + 7)
    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 94092
import sys, heapq

N, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().rsplit()))
setA = set(A)
if len(setA) <= K:
    print(0)
    exit()

change = len(setA) - K

dic = dict()
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

q = list(dic.values())
heapq.heapify(q)
res = 0
for _ in range(change):
    res += heapq.heappop(q)
print(res)


Measured memory_bytes: 45168
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int L = GetInt();

		int r = msb(L);
		var ans = new StringBuilder();
		int N = r + 1;
		int M = 0;
		for(int i = 0; i < N - 1; i++)
		{
			ans.AppendFormat($"{i + 1} {i + 2} 0\n");
			ans.AppendFormat($"{i + 1} {i + 2} {1 << i}\n");
			M += 2;
		}

		int rest = L - (1 << r);
		for(int i = r - 1; i >= 0; i--)
		{
			if(rest >= (1 << i))
			{
				ans.AppendFormat($"{i + 1} {N} {L - rest}\n");
				rest -= (1 << i);
				M++;
			}
		}

		Console.WriteLine($"{N} {M}");
		Console.Write(ans);
	}

	private int msb(int s)
	{
		int cnt = 0;
		int rest = s;
		while(rest > 1)
		{
			cnt++;
			rest /= 2;
		}
		return cnt;
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 13268
import itertools

def takoyaki_festival2019(n, dli):

    ans = 0
    itelist = list(itertools.combinations(range(n), 2))

    for i, k in itelist:
        ans += dli[i]*dli[k]

    return ans

def main():
    n = int(input())
    dli = list(map(int, input().split()))
    print(takoyaki_festival2019(n, dli))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){ 

  int a,b,c;

  cin >> a >> b >> c ;
 
  if(a>b){
    swap(a,b);
}

  if(b>c){
    swap(b,c);
}

  if(a>b){
    swap(a,b);
}
 
  cout<<a<<" "<<b<<" "<<c<<endl;
  return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main (){
  int a;    cin >> a;
  vector<int>v(a);
  for(int i=0;i<a;i++)
  {
      cin>>v.at(i);
  }
  sort(v.begin(),v.end());
  for(int i=0;i<a-1;i++)
  {
      if(v.at(i)==v.at(i+1)){
          cout <<"NO"<< endl;
          return 0;
      }
  }
  cout << "YES" << endl;
}



Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#define ll long long
int main() {
    ll n, ans = 0, x = -1;
    bool flag = true;
    scanf("%lld", &n);
    for(int i = (int)sqrt(n); i >= 2; i--)
        if(n % i == 0) {
            x = i;
            break;
        }
    if(x > 0) {
        n /= x;
        while(n) {
            n /= 10;
            ans++;
        }
    }else {
        while(n) {
            n /= 10;
            ans++;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main()
{
    int n, m, x;
    cin >> n >> m;

    int sum = 0;
    for (int i = 0; i < m; ++i)
    {
        cin >> x;
        sum += x;
    }
    if (sum <= n)
        cout << n - sum << endl;
    else
        cout << -1 << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=2e5;
typedef int fuko[yuzu|10];
int main() {
  int i,n=read(),u,v;
  ll lxy=1ll*n*(n+1)*(n+2)/6;
  for (i=1;i<n;++i) {
    read(u),read(v);
    if (u>v) swap(u,v);
    lxy-=1ll*u*(n-v+1);
  }
  printf("%lld\n",lxy);
}

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

int main() {
  char s1[3], s2[3];
  for(int i = 0; i != 3; ++i) cin >> s1[i];
  for(int i = 0; i != 3; ++i) cin >> s2[i];
  if(s1[2] == s2[0] && s1[1] == s2[1] && s1[0] == s2[2]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
for i in range(len(s)):
    if (i+1) % 2 == 1:
        if s[i] not in ['R', 'U', 'D']:
            print('No')
            exit()
    else:
        if s[i] not in ['L', 'U', 'D']:
            print('No')
            exit()
print('Yes')


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A > B) {
    cout << 0 << endl;
  } else if (A <= B && B / A >= C) {
    cout << C << endl;
  } else {
    cout << B / A << endl;
  }
}

Measured memory_bytes: 256
N,K=map(int,input().split())
P=[int(a)-1 for a in input().split()]
C=[int(a) for a in input().split()]
ans=-float("inf")
for si in range(N):
  x=si
  S=[]
  tot=0
  while True:
    x=P[x]
    S.append(C[x])
    tot+=C[x]
    if x==si:
      break
  L=len(S)
  t=0
  for i in range(L):
    t+=S[i]
    if i+1>K:
      break
    now=t
    if tot>0:
      e=(K-i-1)//L
      now+=tot*e
    ans=max(ans,now)
    
print(ans)

Measured memory_bytes: 77064
# include<iostream>
# define N 1000000
int main(){
    int n; scanf("%d",&n);
    int S[N]; for(int i=0; i<n; i++) scanf("%d",&S[i]);

    int q; scanf("%d",&q);
    int T[N]; for(int i=0; i<q; i++) scanf("%d",&T[i]);

    int cnt = 0;
    for(int i=0; i<q; i++){
        for(int j=0; j<n; j++){
            if(T[i] == S[j]){
               cnt++;
                break;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
 

int main() {
	ll n;
	cin>>n;
	if(n>=30){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	// your code goes here
	return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
// #define endl '\n'

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep (i, h) {
    cin >> s[i];
  }

  vii l(h, vi(w));
  vii r(h, vi(w));
  vii u(h, vi(w));
  vii d(h, vi(w));
  
  rep (i, h) {
    int k = -1;
    rep (j, w) {
      if (s[i][j] == '#') k = j;
      l[i][j] = k;
    }
  }
  rep (i, h) {
    int k = w;
    rrep (j, w) {
      if (s[i][j] == '#') k = j;
      r[i][j] = k;
    }
  }
  rep (j, w) {
    int k = -1;
    rep (i, h) {
      if (s[i][j] == '#') k = i;
      u[i][j] = k;
    }
  }
  
  rep (j, w) {
    int k = h;
    rrep (i, h) {
      if (s[i][j] == '#') k = i;
      d[i][j] = k;
    }
  }

  int ans = 0;
  rep (i, h) {
    rep (j, w) {
      if (s[i][j] == '#') continue;
      int temp = (r[i][j] - 1) - l[i][j];
      temp += (d[i][j] - 1) - u[i][j];
      temp--;
      chmax(ans, temp);
    }
  }
  cout << ans << endl;
  
}



Measured memory_bytes: 67200
// priority_queue is generally max heap to make it min heap use priority_queue<int,vector<int>,greater<int>> pq;"
#include <bits/stdc++.h>
#define int                 long long int
#define double              long double
#define get(a,n)            for(int i=0;i<n;i++){cin>>a[i];}
#define maxm(a)             int maxi=LLONG_MIN;int index;for(int i=0;i<n;i++){if(maxi<a[i]){maxi=a[i];index=i;}}
#define minm(a)             int mini=LLONG_MAX;int index;for(int i=0;i<n;i++){if(mini>a[i]){mini=a[i];index=i;}}
#define db(x)               cout<<"["<<x<<"]"<<endl;
#define vv                  vector
#define endl                "\n"
#define PI                  acos(-1)
#define half(a)             a%2?(a/2+1):a/2
#define array               int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define pb                push_back
#define all(a)              a.begin(),a.end()
#define mod                 1000000007
#define no                  "NO"
#define yes                 "YES"
using namespace std;
template <typename T>
void printvec(vector<T>& vec){
	for(int i=0;i<vec.size();i++) cout<<vec[i]<<" ";
	cout<<endl;
}
vector<bool> is_prime(100000+1, true);
void seive(int n)
{
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (is_prime[i]) {
            for (int j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
}
//this function returns 0 indexing array if the required element
//is less than minimum it returns -1 and greater than max it returns n.
int special_binary(int *a,int n,int x)
{
    int l=0;int r=n-1;int m=0;int f=x;int c=0;
     while(l<=r)
     {
       if(f>a[n-1])
        return n;
       m=(l+r)/2;
       if(a[m]<=f)
       {
           c=m+1;
           l=m+1;
       }
       else
       {
           r=m-1;
       }
     }
     return c-1;
}
void show(int *a,int n)
{
    int size = n;
    for(int i=0;i<size;i++)
    {
            cout<<a[i]<<" ";
    }   
    cout<<endl;
}
int binary_search(int *a,int n,int e)
{
    int f,l,m;f=0;l=n-1;
    while(f<=l)
    {//returns index of that value.
        m=(f+l)/2;
        if(e==a[m])
            return(m);
        else if(e>a[m])
                f=m+1;
            else
                l=m-1;
    }
    return -1;
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second<b.second);
}
void solve()
{
    int n,k;
    cin>>n>>k;
    int dp[n+1];
    int h[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        dp[i]=LLONG_MAX;
        for(int j=1;j<=k;j++)
        {
            if(i>j)
            {
                dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
            }
        }
    }
   cout<<dp[n]<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(15);
    int t=1;
    //cin>>t;
    //seive(100000);
    while(t--)
    {
        solve();
        
    }
   

  
}

Measured memory_bytes: 5208
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int H;
  int W;
  cin >>H>>W;
  
  vector<vector<char>> data(H,vector<char>(W));
  
  rep(i,H) {
    rep(j,W) {
      cin >>data.at(i).at(j);
    }
  }
  
  vector<vector<char>> datamain(H+2,vector<char>(W+2));
  
  rep(i,H) {
    rep(j,W) {
      datamain.at(i+1).at(j+1)=data.at(i).at(j);
    }
  }
  
  rep(i,H+2) {
    datamain.at(i).at(0)='#';
  }
  rep(i,H+2) {
    datamain.at(i).at(W+1)='#';
  }
  rep(j,W+2) {
    datamain.at(0).at(j)='#';
  }
  rep(j,W+2) {
    datamain.at(H+1).at(j)='#';
  }
  
  rep(i,H+2) {
    rep(j,W+2) {
      cout<<datamain.at(i).at(j);
    }
    cout<<endl;
  }
  
  
  
}
  
 

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

int main()
{
  int w;
  char d[20];

  cin>>w;

  for(int i = 0;i<20;i++)d[i] = 'a';

  while(1){
    bool flag=false;
    int count=0;
    for(int i=0;i<20;i++){
      char ans;
      count+=pow(3,i);
      if(abs(w)<=count){
        if(w>0){
	 
	  w -=pow(3,i);
	 
	  ans = '+';
	}
	else if(w<0){
	  w +=pow(3,i);
	  ans = '-';
	}
	if(w==0){
	  flag = true;
	}
	for(int j=0;j<=i;j++){
	  d[i] = '0';
	}
	d[i] = ans;
	break;
      }
    }
    if(flag)break;
  }
  bool f = false;
  for(int i = 19;i>=0;i--){
    if(d[i]!='a')f = true;
    if(f){
      if(d[i]!='a')cout<<d[i];
      else cout<<'0';
    }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 
}

void solve()
{
	string s, t;
	cin >> s >> t;
	if(s.find(t) != string::npos){
		rep(i, sz(s)) if(s[i] == '?') s[i] = 'a';
		cotu << s;
		return;
	}
	for(int i = sz(s) - sz(t); i >= 0; --i){
		string p = s.substr(i, sz(t));
		bool bad = 0;
		for(int j = 0; j < sz(p); ++j){
			if(t[j] != p[j] && p[j] != '?') bad = 1;
		}
		if(bad) continue;
		else{
			for(int j = 0; j < sz(s); ++j){
				if(j >= i && j <= i + sz(t) - 1) s[j] = t[j - i];
				else if(s[j] == '?') s[j] = 'a';
				cout << s[j];
			}
			return;
		}
	}
	cout << "UNRESTORABLE";
} 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
const int MX=1e5+5;
pair<long long,int> a[MX];
map<long long,int> mp;
long long n;
int p[MX];
int visit[MX];
long long s[MX];
long long dp[MX];
int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    int i;
    for(i=1 ; i<=n ; i++){
        cin>>a[i].first;
      ///  a[i].first++;
        a[i].second=i;
        mp[a[i].first]=i;
    }
    sort(a+1,a+n+1);
    for(i=n ; i>=2 ; i--){
      ///  cout<<i<<endl;
        s[a[i].second]++;

        int k=mp[a[i].first+2*s[a[i].second]-n];
        if(k==0 || k==a[i].second || a[i].first+2*s[a[i].second]-n>=a[i].first){
            cout<<-1;
            return 0;
        }
        s[k]+=s[a[i].second];
        dp[k]+=dp[a[i].second]+s[a[i].second];
        p[a[i].second]=k;
    }
    if(dp[a[1].second]!=a[1].first){
        cout<<-1;
        return 0;
    }
    for(i=2 ; i<=n ;i++){
        cout<<a[i].second<<" "<<p[a[i].second]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 11264
/*maximum subarray sum 
 * kadane algo space optimize dp
*/




#include <bits/stdc++.h>
using namespace std;



int main()
{
	int n;
	cin>>n;
	int arr[n];
	for(int i = 0;i<n;i++)
	cin>>arr[i];
	int dp[n];
	dp[0] = 0;
	for(int i  = 1;i<n;i++)
	{
		int opt = INT_MAX,opt2 = INT_MAX;
		opt = dp[i-1] + abs(arr[i] - arr[i-1]);
		if(i-2 >= 0) opt2 = dp[i-2] + abs(arr[i] - arr[i-2]);
		dp[i] = min(opt,opt2);
	}
	cout<<dp[n-1]<<endl;
	
}


Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string N;
  cin >> N;
  ll L = N.size();
  vector<vector<ll>> dp(L + 1, vector<ll>(2, -INF));
  dp.at(0).at(0) = 0;
  for (ll i = 0; i < L; ++i) {
    dp.at(i + 1).at(0) = dp.at(i).at(0) + (ll)(N.at(i) - '0');
    dp.at(i + 1).at(1) = dp.at(i).at(1) + 9;
    if (N.at(i) != '0') {
      dp.at(i + 1).at(1) = max(dp.at(i + 1).at(1), dp.at(i).at(0) + N.at(i) - '1');
    }
  }
  ll ans = max(dp.at(L).at(0), dp.at(L).at(1));
  cout << ans << "\n";
}


Measured memory_bytes: 3596
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N;
  cin >> N;
  
  vector<int> A(N), B(N);
  for (int& a : A) {
    cin >> a;
  }
  for (int& b : B) {
    cin >> b;
  }
  
  multiset<int> A_less, B_less;
  for (int i = 0; i < N; ++i) {
    if (A[i] < B[i]) {
      A_less.insert(B[i] - A[i]);
    } else if (A[i] > B[i]) {
      B_less.insert(A[i] - B[i]);
    }
  }
  
  while (!B_less.empty()) {
    int value = *B_less.begin();
    B_less.erase(B_less.begin());

    while (value > 0 && !A_less.empty()) {
      int steps = min(*A_less.rbegin() / 2, value);
      if (steps == 0) {
        break;
      }
      int impact = steps * 2;
      int rem = *A_less.rbegin() - impact;
      
      A_less.erase(A_less.find(*A_less.rbegin()));
      if (rem > 0) {
        A_less.insert(rem);
      }
      
      value -= steps;
    }
    
    if (value > 0) {
      cout << "No" << '\n';
      return 0;
    }
  }
  
  cout << "Yes" << '\n';
  
  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int H,N;
  cin>>H>>N;
  
  vector<int> A(N);
  ll power=0;
  rep(i,N){
    cin>>A[i];
    power+=A[i];
  }
  
  if(power>=H)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
  
  
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n, m;
	cin >> n>>m;
	vector<int> vi(m);
	REP(i, m)
		cin >> vi[i];
	int dp[50001];
	REP(i, 50001)
		dp[i] = 50001;
	REP(j, m)
		dp[vi[j]] = 1;
	REP(i, n + 1){
		REP(j, m){
			if (i >= vi[j])
				dp[i] = min(dp[i], dp[i - vi[j]]+1);
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1388
h = [int(s) for s in input().split()]
N = h[0]
Y = h[1]

def otoshidama(N,Y):
	ok_flag = 0
	money = 0
	for i in range(N+1):
		for j in range(N+1-i):
			money = 10000*i + 5000*j + 1000*(N-i-j)
			if money == Y:
				print(i,j,N-i-j)
				ok_flag = 1
				return
			money = 0
		money = 0
	if ok_flag == 0:
		print(-1,-1,-1)
  
otoshidama(N,Y)

Measured memory_bytes: 3064
#include <stdlib.h>
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    string s;
    cin>>s;
    long long lastnum=0;
    long long sum=0;
    long long count=1;
    char lastchar=s.at(0);
    vector<long long> sumvec(5*100000+1);
    sumvec.at(0)=0;
    rep(i,5*100000){
        sumvec.at(i+1)=sumvec.at(i)+i+1;
    }
    rep(i,s.size()){
        if(lastchar!=s.at(i)){
            count++;
        }
        lastchar=s.at(i);
    }
    lastchar=s.at(0);
    vector<long long> vec;
    s+="#";
    rep(i,s.size()){
        if(s.at(i)==lastchar){
            lastnum++;
        }
        else{
            lastchar=s.at(i);
            vec.push_back(lastnum);
            lastnum=1;
        }
    }
    //cout<<count<<endl;
    bool flag=true;
    if(s.at(0)!='<'){
        flag=false;
    }
    if(flag){
        if(count%2==0){
            for(long long i=0;i<count-1;i=i+2){
                if(vec.at(i)<=vec.at(i+1)){
                    sum+=sumvec.at(vec.at(i))+sumvec.at(vec.at(i+1))-vec.at(i);
                }
                else{
                    sum+=sumvec.at(vec.at(i))+sumvec.at(vec.at(i+1))-vec.at(i+1); 
                }
            }
        }
        else{
            for(long long i=0;i<count-1;i=i+2){
                if(vec.at(i)<=vec.at(i+1)){
                    sum+=sumvec.at(vec.at(i))+sumvec.at(vec.at(i+1))-vec.at(i);
                }
                else{
                    sum+=sumvec.at(vec.at(i))+sumvec.at(vec.at(i+1))-vec.at(i+1); 
                }
            }
            sum+=sumvec.at(vec.at(count-1));
        }
    }
    else{
        sum+=sumvec.at(vec.at(0));
        if(count%2==1){
            for(long long i=1;i<count-1;i=i+2){
                if(vec.at(i)<=vec.at(i+1)){
                    sum+=sumvec.at(vec.at(i))+sumvec.at(vec.at(i+1))-vec.at(i);
                }
                else{
                    sum+=sumvec.at(vec.at(i))+sumvec.at(vec.at(i+1))-vec.at(i+1); 
                }
            }
        }
        else{
            for(long long i=1;i<count-1;i=i+2){
                if(vec.at(i)<=vec.at(i+1)){
                    sum+=sumvec.at(vec.at(i))+sumvec.at(vec.at(i+1))-vec.at(i);
                }
                else{
                    sum+=sumvec.at(vec.at(i))+sumvec.at(vec.at(i+1))-vec.at(i+1); 
                }
            }
            sum+=sumvec.at(vec.at(count-1));
        }


    }
    if(count==1){
        sum=sumvec.at(vec.at(0));
    }
    cout<<sum<<endl;
    
}





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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1e9 + 7, N = 1e6 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

map <ll, ll> mp ;

int main()
{
    ll n, x ;
    cin >> n ;
    for (int i = 2; i <= n; i++) {
        cin >> x ;
        mp[x]++ ;
    }
    for (int i = 1; i <= n; i++) {
        cout << mp[i] << endl ;
    }

    return 0 ;
}


Measured memory_bytes: 16100
#include <iostream>
#include <vector>
int ans(int n, int k){
	n -= k;
	if (n <= 0) return 1;
	for (int i = 2; ; i++){
		n -= (k-1);
		if (n <= 0) return i;
	}
}

int main(){
	std::vector<int> a;
	int n, k;
	std::cin >> n >> k;
	a.resize(n);
	for (int i = 0; i < n; i++){
		std::cin >> a[i];
	}
	std::cout << ans(n, k) << std::endl;
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007LL
#define eps 1e-8
#define N 1000002
#define all(x) (x).begin(), (x).end()

using namespace std;

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

    cout << ((n+1)/2) << '\n';
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define M 101

using namespace std;

int main()
{
	int n, tot = 1;
	char ch,last;

	cin >> n;
	cin >> last;

	for (int i = 2; i <= n; i++)
	{
		cin >> ch;
		if (ch == last)
			continue;
		else
		{
			tot++;
			last = ch;
		}
	}

	cout << tot << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    priority_queue<pll,vector<pll>,greater<pll>> Q;
    set<ll> S;
    S.insert(-1);
    S.insert(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        Q.push({a[i],i});
    }
    ll ans=0;
    while(!Q.empty()){
        pll w=Q.top(); Q.pop();
        auto I=S.lower_bound(w.S);
        ll r=*I;
        --I;
        ll l=*I;
        ans+=(r-w.S)*(w.S-l)*w.F;
        S.insert(w.S);
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 15340
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;



int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",(a-b)%c);
	return 0;
} 

Measured memory_bytes: 256
n=gets.to_i
a=gets.split(" ").map(&:to_i)
max=10**18
sum=1
flag = 1
a.each do |i|
  sum*=i
  if sum>max
      flag=0
      break
  end
end
=begin
if flag==1
  if a.include?(0)
    puts
  end
  puts sum
else
  puts -1
end
=end
if a.include?(0)
  puts 0
elsif flag==1
  puts sum
else
  puts -1
end


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

int main() {
    int N;
    while (cin >> N, N) {
        int ans = -1;
        int p;
        for (int i = 0; i < N; i++) {
            int t, d, c;
            cin >> t >> d >> c;
            if (ans < d + c) ans = d + c, p = t;
        }
        cout << p << " " << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3012
main(i,N,T,E,x,y){for(scanf("%d%d%d",&N,&T,&E),i=1;i<=N;i++){
	for(scanf("%d",&x),y=0;y<T-E;y+=x);
	if(y<=T+E)exit(!printf("%d\n",i));
}exit(!puts("-1"));}

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

def solve(N,K,X,Y):
    if(N<=K):
        print(N*X)
    else:    
        print(X*K + Y*(N-K))

if __name__ == '__main__':
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())
    
    solve(N,K,X,Y)

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val hList = readLine()!!.split(" ").map{ it.toInt() }
    
    var height: Int = 0;
    var ans = 0;
    
    for(h in hList){
        if(h >= height){
            ans++
            height = h;
        }
    }
    println(ans)
}


Measured memory_bytes: 38056
import math
import itertools
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
rt=[]
for i in range(n):
    for j in range(i+1,n):
        x1=xy[i][0]
        y1=xy[i][1]
        x2=xy[j][0]
        y2=xy[j][1]
        rt.append([(i,j),math.sqrt((x1-x2)**2+(y1-y2)**2)])
l=[i for i in range(n)]
sm=0
cnt=0
for v in list(itertools.permutations(l,n)):
    for i in range(n-1):
        f,t=v[i],v[i+1]
        if f>t:
            f,t=t,f
        for r in rt:
            if r[0]==(f,t):
                sm+=r[1]
    cnt+=1
print(sm/cnt)

Measured memory_bytes: 47596
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	int ans = 0;
	for1(i, n){
		string s = to_string(i);
		if(s.size() % 2)ans++;
	}
	cout <<  ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <assert.h>
#include <sstream>
#include <type_traits>
#define SET(x,y) x |= (1 << y)
#define CLEAR(x,y) x &= ~(1<< y)
#define READ(x,y) ((0u == (x & (1<<y)))?0u:1u)
#define TOGGLE(x,y) (x ^= (1<<y))
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define si(n) scanf("%d",&n)
#define sf(n) scanf("%f",&n)
#define sl(n) scanf("%lld",&n)
#define slu(n) scanf("%llu",&n)
#define sd(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
#define pnl printf("\n")
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pF first
#define pS second
#define CL(a,b) memset(a,b,sizeof(a))
#define sqr(x) ((x)*(x))
#define intLIMIT numeric_limits<int>
#define longLIMIT numeric_limits<long long>
#define GCD(a,b) __gcd((a),(b))
#define dbl(x) (double)(x)
#define vi vector <int>
#define vii vector < pair <int, int> >
#define vll vector <long long>
#define allof(x) (x).begin(), (x).end()
#define fastCin cin.sync_with_stdio(0);cin.tie(0)
#define scanUnsigned(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#define printArr(a,l) cout<<#a<<": ";for(int i=0;i<(l);i++){cout<<a[i]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(int i=0;i<(r);i++){for(int j=0;j<(c);j++){cout<<a[i][j]<<" ";}cout<<endl;}
char _;
using namespace std;
void PRINT (int x, int y) { for (int i = y-1; i >= 0; i--) { cout << READ(x,i); } cout << endl; }

vector<string>vec_splitter(string s){s+=',';vector<string>res;while(!s.empty()){res.push_back(s.substr(0,s.find(',')));s=s.substr(s.find(',')+1);}
return res;}
void debug_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM){cerr<<endl;}
template<typename Head,typename...Tail>void debug_out(vector<string>args,int idx,int LINE_NUM,Head H,Tail...T){if(idx>0)cerr<<", ";else cerr<<"Line("<<LINE_NUM<<") ";stringstream ss;ss<<H;cerr<<args[idx]<<" = "<<ss.str();debug_out(args,idx+1,LINE_NUM,T...);}
#ifdef LOCAL_DBG
#define dbg(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define dbg(...) 42
#endif

int main () {
	fastCin;
	int n;
	cin >> n;
	vi s(n);
	for (int x =0; x < n; x++) {
		cin >> s[x];
	}
	int ans = 0;
	for (int x = 0; x < n-2; x++) {
		for (int i = x+1; i < n-1; i++) {
			for (int j = i+1; j < n; j++) {
				if (s[x] == s[i] || s[x] == s[j] || s[i] == s[j]) {
					continue;
				}
				int sum = s[x]+s[i]+s[j], mx = max ({s[x], s[i], s[j]});
				if (sum-mx > mx) {
					ans++;
					// dbg(s[x], s[i], s[j]);
				}
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3200
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 0;
  if ((a + b) <= 2 * c){
    ans += a * x + b * y;
  } else {
    ans += 2 * c * min(x, y);
    if (x > y){
      int z = x - y;
      if (a <= 2*c) ans += a * z;
      else ans += 2*c * z;
    }
    else if (y > x){
      int z = y - x;
      if (b <= 2*c) ans += b * z;
      else ans += 2*c * z;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int N=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int dp[1<<N], temp[1<<N];
bool bad[N+1][N+1][2];

inline void fix(int &x){
	if (x>=mod) x-=mod;
	if (x<0) x+=mod;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m>>k;
	n--;
	while (k--){
		cin>>a>>b>>x;
		bad[a-1][b-1][x^1]=1;
	}
	dp[0]=1;
	for (int i=0; i<m; i++){
		int x=(i&1);
		for (int j=0; j<n; j++){
			memset(temp, 0, sizeof(temp));
			for (int mask=0; mask<(1<<n); mask++){
				if (!bad[i][j][0] && ((mask>>j)&1)==0)
					fix(temp[mask]+=dp[mask]);
				if (!bad[i][j][1]){
					if (mask&(1<<j)) fix(temp[mask]+=dp[mask]);
					else{
						int msk=mask|(1<<j);
						int tmp=mask&(~((1<<j)-1));
						int bit=__builtin_ctz(tmp);
						if (tmp) msk^=(1<<bit);
						fix(temp[msk]+=dp[mask]);
					}
				}
			}
			memcpy(dp, temp, sizeof(dp));
		}
	}
	for (int mask=0; mask<(1<<n); mask++) fix(ans+=dp[mask]);
	cout<<ans<<"\n";
	
	return 0;
}


Measured memory_bytes: 11868
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			String[][] s = new String[h][w];

			String tmp = sc.nextLine();
			for (int i = 0; i < h; i++) {
				tmp = sc.nextLine();
				for (int j = 0; j < tmp.length(); j++){
					s[i][j] = String.valueOf(tmp.charAt(j));
				}
			}
			
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (".".equals(s[i][j])) {
						int count = 0;
						for (int x = i - 1; x <= i + 1; x++) {
							for (int y = j - 1; y <= j + 1; y++) {
								if (0 <= x && x <= h - 1 && 0 <= y && y <= w - 1) {
									if ("#".equals(s[x][y])) {
										count++;
									}
								}
							}
						}
						System.out.print(count);
					} else {
						System.out.print(s[i][j]);
					}
				}
				System.out.println();
			}
		}
	}
}

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

bool jug(int* s1, int* s2, int len){
    for(int i = 0; i < len; ++i) {
        if (s1[i] != s2[i]) return false;
    }
    return true;
}
int main(){
    int n,count,tmp,x;
    int* s = new int[12];
    int* ans = new int[12];
    while(true) {
        cin >> n;
        if (n ==  0) {
            break;
            cout << endl;
        }
        for(int i = 0; i < n; ++i) {
            cin >> s[i];
        }
        x = 0;
        while(true){
            for(int i = 0; i < n; ++i) {
                count = 0;
                for(int j = 0; j < n; ++j) {
                    if (s[i] == s[j]) {
                        ++count;
                    }
                }
                ans[i] = count;
            }
            if (jug(s, ans, n)) break;
            x++;

            for (int i = 0; i < n; i++) {
                tmp = s[i];
                s[i] = ans[i];
                ans[i] = tmp;
            }
        }
        cout << x << endl;
        for (int i = 0; i < n; i++) {
            cout << s[i];
            if (i == n-1) {
                break;
            }
            cout << " ";
        }
        cout << endl;
    }
    delete s;
    delete ans;
}

Measured memory_bytes: 1192
from decimal import Decimal, getcontext
getcontext().prec = 20
N, K = map(int, input().split())
res = 0
for p in range(1,N+1):
    cnt = 0
    q = 1
    while p*q <K:
        cnt += 1
        q *= 2
    res += Decimal(pow(1/2,cnt))
print(res/N)

Measured memory_bytes: 154280
const lines = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line) {
  lines.push(line);
});

reader.on("close", function () {
  const input = (lines[0] as string).split(" ");
  const maximum = input[0];
  const min = Number(input[1]);
  const max = Number(input[2]);

  console.log(sum(maximum, min, max));
});

function sum(maximum: string, min: number, max: number): number {
  let sum = 0;

  for (let i = 1; i <= Number(maximum); i++) {
    const iSum = digitSum(i);
    if (iSum >= min && iSum <= max) {
      sum = sum + i;
    }
  }

  return sum;
}

function digitSum(number): number {
  const numberArray: number[] = [];
  for (let i = 0; i < String(number).length; i++) {
    numberArray.push(+String(number).charAt(i));
  }
  return numberArray.reduce((accumulator, element) => {
    return accumulator + Number(element);
  });
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int main(){
    int card[3][3];
    rep(i,3)rep(j,3) cin >> card[i][j];
    int n; cin >> n;
    rep(k,n){
        int num; cin >> num;
        rep(i,3)rep(j,3) if(card[i][j]==num) card[i][j] = 0;
    }
    
    bool has_bingo = false;
    
    rep(i, 3){
        int t1 = 0, t2 = 0;
        rep(j, 3){
            t1 += card[i][j];
            t2 += card[j][i];
        }
        if(t1==0||t2==0) has_bingo = true;
    }
    
    int t1 = 0, t2 = 0;
    rep(i, 3){
        t1 += card[i][i];
        t2 += card[i][2-i];
    }
    if(t1==0||t2==0) has_bingo = true;
    
    cout << (has_bingo ? "Yes" : "No") << endl;
    
    return 0;
}

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

int main(void) {
  int N,Q,P;
  long long sum=0;
  cin>>N;
  vector<long long> X(100010);
  for(int i=0;i<N;i++){
    cin>>P;
    X.at(P-1)++;
    sum+=P;
  }
  cin>>Q;
  int B,C;
  
  for(int i=0;i<Q;i++){
    cin>>B>>C;
    sum+=(C-B)*X.at(B-1);
    cout<<sum<<endl;
    X.at(C-1)+=X.at(B-1);
    X.at(B-1)=0;
  }
  return 0;
}


Measured memory_bytes: 4048
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

int A,B,N,W,H,ans,dp[HMAX][WMAX];
char C;
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){

}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >> A >> C >> B;
	if(C == '+'){
		ans = A + B;
	}else{
		ans = A - B;
	}
	answer();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
int a,b,c;cin>>a>>b>>c;
if((a+b)>=c){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
}


Measured memory_bytes: 256