akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main()
{
	int a,b,c,d;
	char k;
	cin>>k;
	a=k-'0';
	cin>>k;
	b=k-'0';
	cin>>k;
	c=k-'0';
	cin>>k;
	d=k-'0';
	if(a+b+c+d==7)
	{
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"; 
		return 0;
	}
	if(a-b+c+d==7)
	{
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"; 
		return 0;
	}
	if(a+b-c+d==7)
	{
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
		return 0; 
	}
	if(a+b+c-d==7)
	{
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"; 
		return 0;
	}
	if(a-b-c+d==7)
	{
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"; 
		return 0;
	}
	if(a+b-c-d==7)
	{
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"; 
		return 0;
	}
	if(a-b+c-d==7)
	{
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"; 
		return 0;
	}
	if(a-b-c-d==7)
	{
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"; 
		return 0;
	}
	return 0;
}

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

int main(){
  int a,i,j,d,b,c,k,e=0,array[101];
  cin>>a;
    for(i=0;i<a;i++){
      cin>>array[i];
    }
  sort(array,array+a);
  for(i=1;i<a;i++){
    e+=(array[a-i-1]!=array[a-i]);
  }
  cout<<e+1<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>


struct dice{
	int top;
	int bottom;
	int up;
	int down;
	int left;
	int right;
};


int north( struct dice *n ){

	int temp;

	temp = n->top;
	n->top = n->down;
	n->down = n->bottom;
	n->bottom = n->up;
	n->up = temp;

	return 0;
};


int south( struct dice *n ){

	int temp;

	temp = n->top;
	n->top = n->up;
	n->up = n->bottom;
	n->bottom = n->down;
	n->down = temp;

	return 0;
}







int west( struct dice *n ){

	int temp;

	temp = n->top;
	n->top = n->right;
	n->right = n->bottom;
	n->bottom = n->left;
	n->left = temp;

	return 0;
}

int east( struct dice *n ){

	int temp;

	temp = n->top;
	n->top = n->left;
	n->left = n->bottom;
	n->bottom = n->right;
	n->right = temp;

	return 0;
}


int main(){

	int i;
	struct dice d1, d2;


	scanf( "%d %d %d %d %d %d", &d1.top, &d1.down,
			&d1.right, &d1.left, &d1.up, &d1.bottom );

	scanf( "%d %d %d %d %d %d", &d2.top, &d2.down,
			&d2.right, &d2.left, &d2.up, &d2.bottom );


	//
	if( d1.top == d2.up ) south( &d2 );
	else if( d1.top == d2.down ) north( &d2 );
	else if( d1.top == d2.right ) west( &d2 );
	else if( d1.top == d2.left ) east( &d2 );
	else if( d1.top == d2.bottom  ){
		north( &d2 ); north( &d2 );
	}

	//
	south( &d1 );
	south( &d2 );


	//
	for( i=0; i<4; i++ ){
		if( d1.up==d2.up && d1.down==d2.down &&
			d1.right==d2.right && d1.left==d2.left )
			break;

		west( &d2 );
	}


	//	
	if( d1.up==d2.up && d1.down==d2.down &&
		d1.right==d2.right && d1.left==d2.left &&
		d1.top==d2.top && d1.bottom==d2.bottom )
		printf( "Yes\n" );
	else
		printf( "No\n" );


	return 0;

}

Measured memory_bytes: 580
import sys
readline = sys.stdin.readline
write = sys.stdout.write
N = int(readline())
k, *B = map(int, readline().split())
M = sum(1 << b for b in B)

R = []
v = (-1) & M
while v:
    R.append(v)
    v = (v - 1) & M
R.sort()
write("0:\n")
for i in R:
    write("%d: %s\n" % (i, " ".join(str(j) for j in range(N) if i & (1 << j))))



Measured memory_bytes: 16052
#include <stdio.h>

const int MAX_VAL = 200000;
const int MAX_N = 3000;
const int MOD = 1e9 + 7;

struct Block {
  int r;
  int c;
};

int n;
Block blocks[MAX_N + 1];
int Count[MAX_N + 1];

long long fact[1 + MAX_VAL];
long long invFact[1 + MAX_VAL];

int mul(int a, int b) {
  return (long long)a * b % MOD;
}

void mulSelf(int &a, int b) {
  a = (long long)a * b % MOD;
}

void subSelf(int &a, int b) {
  a -= b;
  if (a < 0)
    a += MOD;
}

int pow(int base, int exp) {
  int answer = 1;
  while (exp > 0) {
    if (exp % 2 == 1)
      mulSelf(answer, base);
    mulSelf(base, base);
    exp /= 2;
  }
  return answer;
}

int choose(int n, int k) {
  return mul(mul(fact[n], invFact[k]), invFact[n - k]);
}

int allRoads(int x, int y) {
  return choose(x + y, x);
}

int count(int i) {
  if (Count[i] == 0) {
    Count[i] = allRoads(blocks[i].r - 1, blocks[i].c - 1);
    for (int j = 0; j <= n; j++) {
      if (i != j && blocks[j].r <= blocks[i].r && blocks[j].c <= blocks[i].c) {
        subSelf(Count[i], mul(count(j), allRoads(blocks[i].r - blocks[j].r, blocks[i].c - blocks[j].c)));
      }
    }
  }
  return Count[i];
}

int main() {
  fact[0] = 1;
  for (int i = 1; i <= MAX_VAL; i++)
    fact[i] = fact[i - 1] * i % MOD;
  invFact[MAX_VAL] = pow(fact[MAX_VAL], MOD - 2);
  for (int i = MAX_VAL - 1; i >= 0; i--)
    invFact[i] = invFact[i + 1] * (i + 1) % MOD;

  int h, w;
  scanf("%d%d%d", &h, &w, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &blocks[i].r, &blocks[i].c);
  }
  blocks[n].r = h;
  blocks[n].c = w;
  count(n);
  /*
  for (int i = 0; i <= n; i++)
    printf("%lld ", fact[i]);
  printf("\n");
  for (int i = 0; i <= n; i++)
    printf("%lld ", invFact[i]);
  printf("\n");//*/
  //for (int i = 0; i <= n; i++)
  //  printf("%d ", count(i));
  //printf("\n");
  printf("%d\n", count(n));
  return 0;
}


Measured memory_bytes: 3328
from itertools import product
N,Y=map(int, input().split())

def total_check(n, y):
    for b in range(N+1):
        for a in range(N+1):
            if a + b > N:
                break
            c = N - a - b
            t = 10000 * a + 5000 * b + 1000 * c
            if t==y:
                return a, b, c
    return -1,-1,-1
a,b,c=total_check(N,Y)
print(a,b,c)


Measured memory_bytes: 3060
#全部1にしたい
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
#端っこから区間をあらかじめ区切っておく
ans=0
i=0
while i<n-1:
  ans=ans+1
  i=i+k-1
  
  
print(ans)

  

Measured memory_bytes: 20544
#include <stdio.h>
#include <string.h>

#define min(A, B) ((B) > (A) ? (A) : (B))

/*
int min(int a, int b)
{
    return (b > a ? a : b);
}
*/

int main(void)
{
    int i, j, k;
    int n;
    int div[10001];
    int dp[2][5001][2];
    
    scanf("%d", &n);
    
    for (i = 1; i <= n - 1; i++){
        scanf("%d", div + i);
    }
    memset(dp, 1, sizeof(dp));
    dp[0][0][0] = dp[0][0][1] = 0;
    
    for (i = 0; i <= n / 2; i++){
        for (j = 0; j <= n / 2; j++){
            if (i > 0){
                dp[i & 1][j][0] = dp[(i - 1) & 1][j][0];
                dp[i & 1][j][1] = dp[(i - 1) & 1][j][0] + div[i + j];
            }
            if (j > 0){
                dp[i & 1][j][0] = min(dp[i & 1][j][0], dp[i & 1][j - 1][1] + div[i + j]);
                dp[i & 1][j][1] = min(dp[i & 1][j][1], dp[i & 1][j - 1][1]);
            }
        }
    }
    
    printf("%d\n", min(dp[0][n / 2][0], dp[0][n / 2][1]));
    
    return (0);
}

Measured memory_bytes: 484
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
//modpow.cpp
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll A[100005];
int main() {
    init();
    ll N, K;
    cin >> N >> K;

    ll ans = 0;
    reper(x,1,K+1){
        ll C = K / x, cnt = modpow(K / x, N, MOD);
        repe(i,2,C+1){
            cnt -= A[i * x];
            if (cnt < 0) cnt += MOD;
        }
        A[x] = cnt;
        (ans += cnt * x) %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4380
#include<iostream>
using namespace std;
int main(){
    int n,x;
    while (1){
        int count = 0;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        for (int i = 1;i <= n - 2;i++){
            for (int j = i+1;j <= n - 1;j++){
                for (int k = j+1;k <= n;k++){
                    if (i + j + k == x) count++;
                }
            }
        }
    cout << count <<endl;
    }
    return 0;
}


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

int main(void){
  double x[4],y[4];
  while(cin>>x[0]>>y[0],!cin.eof()){
    for(int i = 1 ; i < 4 ; i ++){
      cin>>x[i]>>y[i];
    }
    int X = false;
    int Y = false;
    if(min(x[1],x[3]) < max(x[0],x[2]))X=true;
    if(min(y[1],y[3]) < max(y[0],y[2]))Y=true;

    if(X+Y)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
  }
  
}

Measured memory_bytes: 1216
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
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) x=-x,pc('-');
  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=4e5,inf=yuzu<<10;
typedef int fuko[yuzu|10];
vector<int> lj[yuzu|10];
fuko a,s,dp;
int n,m;

typedef int karen[yuzu<<2|23];
struct segtree{
#define le rt<<1
#define ri le|1
#define ls le,l,mid
#define rs ri,mid+1,r
karen val;
void build(int rt=1,int l=1,int r=n){
  val[rt]=inf;
  if (l==r) return;
  int mid=l+r>>1;
  build(ls),build(rs);
  }
int update(int u,int v,int rt=1,int l=1,int r=n){
  if (u>r||u<l) return 0; 
  if (l==r) return val[rt]=min(val[rt],v);
  int mid=l+r>>1;
  update(u,v,ls),update(u,v,rs);
  val[rt]=min(val[le],val[ri]);
  }
int query(int ql,int qr,int rt=1,int l=1,int r=n){
  if (qr<l||ql>r) return inf;
  if (ql<=l&&qr>=r) return val[rt];
  int mid=l+r>>1;
  return min(query(ql,qr,ls),query(ql,qr,rs));
  }
}my_;

int main(){
int i,lat=0;
n=read(),my_.build();
for (i=1;i<=n;++i) s[i]=s[i-1]+((a[i]=read())?-1:1);
for (m=read();m--;){
  int u=read(),v=read();
  lj[u].push_back(v);
  } 
for (i=1;i<=n;++i){
  for (int p:lj[i]){
    int tmp=min(lat-s[i-1],my_.query(i,p))+s[p];
    dp[p]=min(dp[p],tmp);
    my_.update(p,tmp-s[p]);
    } 
  lat=min(lat,dp[i]);
  }
write((n-s[n])/2+lat);
}

Measured memory_bytes: 22528
/*
Author : Harsh AKA Codula
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define rep(n) for(ll i=0;i<n;++i)


class google
{

    public:
        void run()
        {
            ll a;
            cin>>a;
            int i=0;
            while(a--)
            {
                i+=1;
                cout<<"Cases #"<<i<<": ";
                cout<<"\n";
            }
        }
};
class codechefpattern
{

    public:
        void run()
        {
            ll a;
            cin>>a;
            while(a--)
            {
                cout<<"\n"; 
            } 

        }
};
class other
{
    private:
        bool distance(ll x,ll y,double d)
        {
            if (sqrt(pow(x,2)+pow(y,2))<=d)
            {
                /* code */
                return true;
            }
            else
            {
                return false;
            }
        }
    public:
        void run()
        {
            ll a,ans=0;
            double d;
            cin>>a>>d;
            vector<ll> x(a,0);
            vector<ll> y(a,0);
            rep(a)
            {
                cin>>x[i]>>y[i];
                if (distance(x[i],y[i],d))
                {
                    /* code */
                    ans+=1;
                }
            }
            cout<<ans;
        }
};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    google g;
    codechefpattern c;
    other o;

    o.run();
    return 0;
}

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

int main(){
  long long H;
  cin >> H;
  long long counter=0;
  long long ans=0;
  while (true)
  {
    if(H==1)break;
    H/=2;
    counter+=1;
  }
  for(long long i=counter; i>0; i--){
    ans += pow(2,i);
  }
  ans+=1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{
	char a,b,c;
	string s,t,r;
	cin>>s>>t>>r;
	if(s[s.length()-1]==t[0]&&t[t.length()-1]==r[0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

const long long mod = 998244353;

string normalize(string s) {
  int pos = s.find(1);
  if (pos == string::npos) return "";
  return s.substr(pos);
}

string gcd(string a, string b) {
  while (true) {
    if (a.size() > b.size()) {
      for (int i = 0; i < b.size(); i++) {
        a[i] ^= b[i];
      }
      a = normalize(a);
      if (a.empty()) return b;
    } else {
      for (int i = 0; i < a.size(); i++) {
        b[i] ^= a[i];
      }
      b = normalize(b);
      if (b.empty()) return a;
    }
  }
}

string input() {
  string s;
  cin >> s;
  for (char &c : s) c -= '0';
  return s;
}

long long modpow(long long x, long long y) {
  long long ret = 1;
  while (y > 0) {
    if (y & 1) ret = ret * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  string x = input();
  string g = input();
  for (int i = 1; i < n; i++) {
    g = gcd(g, input());
  }

  long long ans = 0;
  string curr(x.size(), 0);
  for (int i = 0; i + g.size() <= x.size(); i++) {
    if (curr[i] == 0 && x[i] == 0) {
      // can't use
    } else if (curr[i] == 1 && x[i] == 0) {
      for (int j = 0; j < g.size(); j++) {
        curr[i + j] ^= g[j];
      }
    } else if (curr[i] == 0 && x[i] == 1) {
      for (int j = 0; j < g.size(); j++) {
        curr[i + j] ^= g[j];
      }
      ans += modpow(2, x.size() - i - g.size());
      ans %= mod;
    } else if (curr[i] == 1 && x[i] == 1) {
      ans += modpow(2, x.size() - i - g.size());
      ans %= mod;
    }
  }
  if (curr <= x) {
    ans++;
    ans %= mod;
  }
  
  cout << ans << endl;
}


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

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  int res = 1000000;
  for (int i = 0; i < N; ++i) {
    long long tmp;
    cin >> tmp;
    int count = 0;
    while (tmp > 0) {
      if (1 & tmp)
        break;
      tmp >>= 1;
      ++count;
    }
    res = min(count, res);
  }

  cout << res << endl;

}

Measured memory_bytes: 256
//2018.9.27 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline int read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline int _abs(const res &x){
    return x>0?x:-x;
}
inline int _max(const res &x,const res &y){
    return x>y?x:y;
}
inline int _min(const res &x,const res &y){
    return x<y?x:y;
}
const int N=1e5+10;
namespace MAIN{
    int n;
    int a[N];
    LL ans;
    inline void MAIN(){
        n=read();
        for(res i=1;i<=n;i++)a[i]=read();
        for(res i=1;i<=n;i++){
            if(a[i]&1)
                if(a[i+1])ans++,a[i]--,a[i+1]--;
        }
        for(res i=1;i<=n;i++)ans+=a[i]>>1;
        printf("%lld\n",ans);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

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

using ll = long long int;
using ld = long double;
using pii = pair<int,int>;

const double PI=acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()


int main(){
  cout << fixed;
cout << setprecision(20);
  ld a,b,x;
  cin >> a >> b >> x;
  ll v= a*a*b;
  ld s=atan((v-x)*2.0/a/a/a)/PI*180;
  ld t=atan(b*a*b/2.0/x)/PI*180;
    if(x>=a*a*b/2){
      cout << s << endl;}
  else cout << t << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    vector<vector<ll>> xdp(h, vector<ll>(w, 0));
    rep(i, h) {
        rep(j, w) {
            if (s[i][j] == '#') continue;
            if (j == 0) xdp[i][j] = 1;
            else xdp[i][j] = xdp[i][j - 1] + 1;
        }
        ll cur = 0;
        rrep(j, w) {
            if (xdp[i][j] == 0) cur = 0;
            else cur = max(cur, xdp[i][j]);
            xdp[i][j] = cur;
        }
    }
    vector<vector<ll>> ydp(h, vector<ll>(w, 0));
    rep(j, w) {
        rep(i, h) {
            if (s[i][j] == '#') continue;
            if (i == 0) ydp[i][j] = 1;
            else ydp[i][j] = ydp[i - 1][j] + 1;
        }
        ll cur = 0;
        rrep(i, h) {
            if (ydp[i][j] == 0) cur = 0;
            else cur = max(cur, ydp[i][j]);
            ydp[i][j] = cur;
        }
    }
    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            if (s[i][j] == '#') continue;
            ans = max(ans, xdp[i][j] + ydp[i][j] - 1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 67200
//
//  main.cpp
//  CodeTest
//
//  Created by Sajor on 2019/3/16.
//  Copyright © 2019年 Sajor. All rights reserved.
//  6 5 3 1 3 4 3

#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

int main(int argc, const char * argv[]) {
    int n, s[200005], i;
    cin >> n;
    for(i=0; i<n; i++) {
        cin >> s[i];
    }
    int minv = s[0];
    int maxv = INT_MIN;
    for(i=1; i<n; i++){
        maxv = max(s[i] - minv, maxv);
        minv = min(minv, s[i]);
    }
    cout << maxv << endl;
    return 0;
}



Measured memory_bytes: 3868
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  int n;
  string S;
  cin >> n;
  cin >> S;

  vector<int> left_w(n);
  vector<int> right_e(n);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    if (S[i] == 'W')
      ++sum;
    left_w[i] = sum;
  }
  sum = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (S[i] == 'E') ++sum;
    right_e[i] = sum;
  }

  int ans = n;
  for (int i = 0; i < n; ++i) {
    ans = min(ans, left_w[i] + right_e[i] - 1);
  }
  cout << ans << endl;
  return 0;
}


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

public class Main{
	public static final int NMAX = 100000;
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
	
		long[] arr = new long[NMAX+1];
		
		for(int i=0; i<n; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			arr[a] += b;
		}
		
		for(int i=1; i<NMAX+1; i++){
			if(k <= arr[i]){
				System.out.println(i);
				break;
			}
			k -= arr[i]; 	
		}
	}
}

Measured memory_bytes: 64720
#include<cstdio>
using namespace std;
#define N 505
long long f[N][N],su1[N][N],su2[N][N],dp[N][N],n,su;
long long Max(long long a,long long b){return a>b?a:b;}
int main()
{
	scanf("%lld",&n);for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i!=j)scanf("%lld",&f[i][j]),su+=f[i][j];
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)su1[i][j]=f[i][j]*(i<j)+su1[i][j-1]+su1[i-1][j]-su1[i-1][j-1],su2[i][j]=f[i][j]*(i>j)+su2[i][j-1]+su2[i-1][j]-su2[i-1][j-1];
	for(int i=1;i<=n;i++)dp[1][i]=su2[i][i];
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int k=j+1;k<=n;k++)dp[j+1][k]=Max(dp[j+1][k],dp[i][j]+su1[j][k]-su1[j][j]+su2[k][k]-su2[k][i-1]-su2[j][k]+su2[j][i-1]);
	long long as=0;for(int i=1;i<=n;i++)as=Max(as,dp[i][n]);printf("%lld\n",su-as);
}//

Measured memory_bytes: 8064
#define s(a,b) t=a,a=b,b=t
f(int*a){*a=(*a&7)<<4|*a>>4;}k,m,a,b,c,t,r;main(n){while(scanf("%d",&n),n){r=1,a=97,b=82,c=67;while(n--){scanf(" %c%*s",&k);m=k-76;t=m%6==0?(s(b,c),f(m?&c:&b)):1<m&&m<8?(s(a,b),f(m^7?&b:&a)):(s(a,c),f(m>0?&c:&a));r+=a&7;}printf("%d\n",r);}}

Measured memory_bytes: 0
#include<iostream>
#include<climits>
#include<cmath>
using namespace std;
int main()
{ int n,k;
cin >> n >> k;
int *arr=new int[n];
for(int j=0; j<n; j++)
{
cin >> arr[j];
}


int *dp=new int[n];
dp[0]=0;

for(int i=1; i<n; i++)
{ int op=0;
  dp[i]=INT_MAX;
for(int j=1; j<=k; j++)
{ if(i-j>=0)
{ op=abs(arr[i]-arr[i-j])+dp[i-j];
dp[i]=min(dp[i],op);
}
}





}

cout << dp[n-1] << endl;}









Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String even="",odd="";
    for(int i = 0;i<s.length();i++){
      if(i%2==0){
        odd+=s.substring(i,i+1);
      }else{
        even+=s.substring(i,i+1);
      }
    }
    int ok = 0;
    odd=odd.replace("R","");
    odd=odd.replace("U","");
    odd=odd.replace("D","");
    even=even.replace("L","");
    even=even.replace("U","");
    even=even.replace("D","");
    if(odd.length()==0)ok++;
    if(even.length()==0)ok++;
    if(ok==2){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 39356
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll h,w,k;cin>>h>>w>>k;
  vector<string>s(h);
  rep(i,0,h)cin>>s[i];
  rep(i,0,1<<h)rep(j,0,1<<w){
    ll tmp=0;
    rep(x,0,h)rep(y,0,w){
      if(i&1<<x||j&1<<y)continue;
      if(s[x][y]=='#')tmp++;
    }
    if(tmp==k)res++;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3656
import io.StdIn.readLine

object Main extends App {
  val ns = Array.ofDim[Int](101)
  Iterator.continually(readLine)
    .takeWhile(_ != null)
    .foreach(e => {
      val n = e.toInt
      ns(n) += 1
    })
  val max = ns.max
  for(i <- 0 to 100 if ns(i) == max) println(i)
}


Measured memory_bytes: 43916
float w;main(i){for(;~scanf("%f",&w);i=(i+5)%11,i<8?printf("light %s\n"+i%2*6,"welter\0middle\0heavy\0 fly"+i/2*7):puts("bantam\0 feather\0light"+i*8-64))for(i=0;w>"0369<@EKQ[~"[i++];);}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


#define MOD 1000000007

long long pow_mod(long long x, long long y) {
	int res = 1;
	while (y) {
		if (y & 1)res = (res * x) % MOD;
		y >>= 1;
		x = (x * x) % MOD;
	}
	return res;
}

long long inv[200000 + 1];//MODを法とする乗法の逆元

long long c(int n, int r) {
	int a = max(n - r, r);
	int b = min(n - r, r);
	long long ret = 1;
	for (int i = a + 1; i <= n;i++) {
		ret = (ret * i) % MOD;
	}
	for (int i = 1; i <= b; i++) {
		ret = (ret * inv[i]) % MOD;
	}


	return ret;
}



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

	int n,a,b;
	cin >> n >> a >> b;

	inv[1] = 1;
	for (int i = 2; i <= max(a,b); i++) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;

	long long ans = pow_mod(2, n) - c(n, a) - c(n, b) - 1;

	cout << (ans % MOD + MOD) % MOD << endl;




	return 0;
}

Measured memory_bytes: 1792
n=int(input())
from collections import Counter
a=[input()for i in range(n)]
ca=Counter(a)
m=int(input())
b=[input()for i in range(m)]
cb=Counter(b)

ans=0
for i in a:
    tmp=ca[i]-cb[i]
    ans=max(ans,tmp)
print(max(ans,0))

Measured memory_bytes: 3316
import sys
import numpy as np


N = int(input())

dp = [float('inf')]*(N+1)
dp[0] = 0
for i in range(1,N+1):

    power = 1
    while power <= i:
        dp[i] = min(dp[i],dp[i-power]+1)
        power *= 6

    power = 1
    while power <= i:
        dp[i] = min(dp[i],dp[i-power]+1)
        power *= 9
print(dp[N])


Measured memory_bytes: 15032
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define pb push_back
#define mp make_pair

void solve()
{
	int n;
	cin >> n;
	int a[4] = {0};
	string s;
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		if (s == "AC")
			a[0]++;
		else if (s == "WA")
			a[1]++;
		else if (s == "TLE")
			a[2]++;
		else
			a[3]++;
	}
	for (int i = 0; i < 4; i++)
	{
		if (i == 0)
			cout << "AC x " << a[i] << "\n";
		else if (i == 1)
			cout << "WA x " << a[i] << "\n";
		else if (i == 2)
			cout << "TLE x " << a[i] << "\n";
		else
			cout << "RE x " << a[i] << "\n";
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin >> t;
	t = 1;
	while (t--)
	{
		solve();
	}
	return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  string s;
  cin >> s;
  int c = -1, f = -1;
  REP(i, s.size()){
    if(s[i] == 'C'){
      c = i;
      break;
    }
  }
  FOR(i, c+1, s.size()){
    if(s[i] == 'F'){
      f = i;
      break;
    }
  }
  if(c != -1 && f != -1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	ll ans = 1;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort (a.begin(), a.end());
	if (a[0] == 0){
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++){
		ll temp = ans;
		ans *= a[i];
		if (ans > 1000000000000000000 || temp > ans){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
     FasterIO
   int n,a;
   cin>>n;
   int b[n+2]={0};

   for(int i=1;i<n;i++)
   {
       cin>>a;
       b[a]++;
   }
    for(int i=1; i<=n; i++)
        cout<<b[i]<<endl;
    return 0;
}


Measured memory_bytes: 4404
#include<bits/stdc++.h>
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define inf 0x3f3f3f
typedef long long ll;
using namespace std;

const int maxn=1e5;

int a[maxn];

int main(){
    int n;cin>>n;
    FOR(i,1,n)scanf("%d",&a[i]);
    int t=a[1];
    FOR(i,2,n)t^=a[i];
    if(!t)puts("Yes");
    else puts("No");
}

Measured memory_bytes: 640
n,k = gets.chomp.split.map(&:to_f)
dice = (1.to_f/n)
coin = (1.to_f/2)
ans = 0

(1..n).each do |v|
  cnt = 0
  while v < k
    v *= 2
    cnt += 1
  end
  ans += dice * coin**cnt
end

puts ans


Measured memory_bytes: 1788
//\\//\\ * * * //\\// ||
#include <bits/stdc++.h> 

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int N = 10;

string s[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, k;
  cin >> h >> w >> k;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int ans = 0;
  for (int bh = 0; bh < (1 << h); bh++) {
    for (int bw = 0; bw < (1 << w); bw++) {
      int cnt = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (s[i][j] == '#' && (bh & (1 << i)) && (bw & (1 << j))) {
            ++cnt;
          }
        }
      }
      ans += (cnt == k);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <queue>
#include <unordered_map>
#include <algorithm>
using namespace std;
#define ll long long int
struct comb {
	ll sum, a, b, c;
};
class cmp {
	public:
	bool operator()(comb a, comb b) {
		return a.sum<b.sum;
	}
};
int main () {
	ll x, y, z, k;
	cin>>x>>y>>z>>k;
	ll a[x], b[y], c[z];
	for (int i=0; i<x; i++) cin>>a[i];
	for (int i=0; i<y; i++) cin>>b[i];
	for (int i=0; i<z; i++) cin>>c[i];
	sort(a, a+x, greater<ll>()), sort(b, b+y, greater<ll>()), sort(c, c+z, greater<ll>());
	priority_queue<comb, vector<comb>, cmp> pq;
	unordered_map<ll, bool> m;
	pq.push({a[0]+b[0]+c[0], 0, 0, 0}), m[0]=true;
	for (int i=0; i<k; i++) {
		ll d=pq.top().sum, p=pq.top().a, q=pq.top().b, r=pq.top().c;
		pq.pop();
		cout<<d<<endl;
		if (p+1<x && m.find(2000000LL*p+2000LL*q+2LL*r+2000000LL)==m.end()) pq.push({a[p+1]+b[q]+c[r], p+1, q, r}), m[2000000LL*p+2000LL*q+2LL*r+2000000LL]=true;
		if (q+1<y && m.find(2000000LL*p+2000LL*q+2LL*r+2000LL)==m.end()) pq.push({a[p]+b[q+1]+c[r], p, q+1, r}), m[2000000LL*p+2000LL*q+2LL*r+2000LL]=true;
		if (r+1<z && m.find(2000000LL*p+2000LL*q+2LL*r+2LL)==m.end()) pq.push({a[p]+b[q]+c[r+1], p, q, r+1}), m[2000000LL*p+2000LL*q+2LL*r+2LL]=true;
	}
}

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

int main(){
  ll N,M;
  cin >> N >>M;
  vector <long long int> H(N);
  rep(i,N) 
    cin >> H.at(i) ;
  vector<long long int> X(N,1);
  rep(i,M){
    ll A,B;
    cin >> A >> B;
    if ( H.at(A-1) < H.at(B-1) )
      X.at(A-1) = 0;
    if ( H.at(A-1) == H.at(B-1) ){
      X.at(A-1) = 0;
      X.at(B-1) = 0;
    }
    if ( H.at(A-1) > H.at(B-1) )
      X.at(B-1) = 0;
  }
  long long int counter=0;
  rep(i,N){
    if (X.at(i) == 1)
      counter ++;
  }
  cout  << counter <<endl;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi 1
#define LL long long
#define ULL unsigned long long
#define LD long double

using namespace std;

#define MAX_N 40005

#define int long long

int N;
int X[105];

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

//*********************************************************
// 最小公倍数（Least Common Multiple）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

signed main()
{
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }

  LL ans = 1;
  for (int i = 0; i < N; i++) {
    ans = lcm(ans, X[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
mod = int(1e9) + 7 # <-- input modulo
maxf = 500000           # <-- input factional limitation

def make_fact(n, k):
    tmp = n
    perm = [i for i in range(k)]
    L = [0 for _ in range(k)]
    for i in range(k):
        L[i] = tmp % (i + 1)
        tmp //= i + 1
    LL = [0 for _ in range(k)]
    for i in range(k):
        LL[i] = perm[L[-i-1]]
        for j in range(L[-i-1]+1, k):
            perm[j-1] = perm[j]
    return LL

def doubling(n, m, modulo=mod):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo=mod):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo

fact = [1 for _ in range(maxf+1)]
invf = [1 for _ in range(maxf+1)]

for i in range(maxf):
    fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
    invf[i-1] = (invf[i] * i) % mod
n, k = map(int, input().split())
S = 0
if n <= k + 1:
    print(fact[2*n-1]*invf[n]*invf[n-1]%mod)
else:
    S = 0
    for i in range(min(n, k+1)):
        S += invf[i]*invf[i]*invf[n-i-1]*invf[n-i]%mod
        S %= mod
    print(S*fact[n-1]*fact[n]%mod)

Measured memory_bytes: 48504
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

#define S first
#define C second

struct Node{
	int dis;
	bool rl, pal;
	string str;
	
	bool operator>(const Node& rhs) const {
		return dis > rhs.dis;
	}
	
	bool operator<(const Node& rhs) const {
		return dis < rhs.dis;
	}
};

bool ispal(string s){
	string r = s;
	
	reverse(r.begin(), r.end());
	
	return r == s;
}

void tran(vector<pair<string,int>> &in, priority_queue<Node, vector<Node>, greater<Node>> &Q, map<pair<bool, string>, int> &mp, Node n){
	
	if(n.rl) {
		for(int i = 0; i < in.size(); i++){
			bool flag = true;
			Node next;
			
			next.dis = n.dis + in[i].C;
			
			for(int j = 0; j < in[i].S.size() && j < n.str.size(); j++){
				if(in[i].S[j] != n.str[n.str.size() - j - 1]) {
					flag = false;
					break;
				}
			}
			
			if(flag) {
				if(n.str.size() >= in[i].S.size()) {
					next.str = n.str.substr(0, n.str.size() - in[i].S.size());
					next.rl = true;
				} else {
					next.str = in[i].S.substr(n.str.size(), in[i].S.size() - n.str.size());
					next.rl = false;
				}
				
				next.pal = ispal(next.str);
				
				if(mp.count({next.rl, next.str}) == 0 || mp[{next.rl, next.str}] > next.dis) {
					mp[{next.rl, next.str}] = next.dis;
					Q.push(next);
				}
			}
		}
	} else {
		
		for(int i = 0; i < in.size(); i++){
			bool flag = true;
			Node next;
			
			next.dis = n.dis + in[i].C;
			
			for(int j = 0; j < in[i].S.size() && j < n.str.size(); j++){
				if(in[i].S[in[i].S.size() - j - 1] != n.str[j]) {
					flag = false;
					break;
				}
			}
			
			if(flag) {
				if(n.str.size() > in[i].S.size()) {
					next.str = n.str.substr(in[i].S.size(), n.str.size() - in[i].S.size());
					next.rl = false;
				} else {
					next.str = in[i].S.substr(0, in[i].S.size() - n.str.size());
					next.rl = true;
				}

				next.pal = ispal(next.str);
				
				if(mp.count({next.rl, next.str}) == 0 || mp[{next.rl, next.str}] > next.dis) {
					mp[{next.rl, next.str}] = next.dis;
					Q.push(next);
				}
			}
		}
	}
}

int dijkstra(vector<pair<string,int>> &in){
	int N = in.size();
	
	priority_queue<Node, vector<Node>, greater<Node>> Q;
	map<pair<bool, string>, int> mp;

	for(int i = 0; i < N; i++){
		Q.push({in[i].C, false, ispal(in[i].S), in[i].S});
		
		if(mp.count({false, in[i].S}) == 0) mp[{false, in[i].S}] = in[i].C;
		else mp[{false, in[i].S}] = min(in[i].C, mp[{false, in[i].S}]);
	}
	
	
	while(!Q.empty()){
		Node n = Q.top(); Q.pop();
		
		if(n.pal) {
			return n.dis;
		}
		
		if(mp[{n.rl, n.str}] > n.dis) continue;
		
		tran(in, Q, mp, n);
	}
	
	return -1;
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	vector<pair<string,int>> in;
	int N;
	
	cin>>N;
	
	in.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].S>>in[i].C;
	}

	cout<<dijkstra(in)<<endl;
		
	return 0;
}

Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	while (true) {
		int r0, w0, c, r;
		cin >> r0 >> w0 >> c >> r;
		if (r0 == 0 && w0 == 0 && c == 0 && r == 0)break;

		int ans = (w0*c - r0 + r - 1) / r;
		cout << max(ans, 0) << endl;
	}
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int l = max(h, w);
    cout << (n + l - 1) / l << '\n';
    return 0;
}

Measured memory_bytes: 256
n = int(input())
*a, = map(int,input().split())
a.sort(reverse = True)
ans = 0
n -= 1
if n % 2 == 0:
    z = (n-2)//2
    ans += a[0]
    for i in range(1, 1 + z):
        ans += 2 * a[i]
    ans += a[z+1]

if not n % 2 == 0:
    z = (n-1)//2
    ans += a[0]
    for i in range(1, 1 + z):
        ans += 2 * a[i]

print(ans)


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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<int> l(n);
    for(int i=0; i<n; i++){
        cin >> l[i];
    }
    int cnt = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k=j+1; k<n; k++){
                if(l[i] + l[j] + l[k] > 2*max(l[i], max(l[j], l[k])) && l[i] != l[j] && l[j] != l[k] && l[i] != l[k]){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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

const int MAX = 50;

int main(){
    int n, d, x[10][10];
    cin >> n >> d;

    rep(i,n)rep(j,d){
        cin >> x[i][j];
    }

    int cnt = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int sum = 0;
            for(int k = 0; k < d; k++){
                sum += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
            }
            double dist = sqrt(sum);
            int dist_int = dist;
            if(dist - dist_int == 0) cnt++; 
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	while (true) {
		C -=B ;
		if (C <= 0) {
			cout << "Yes" << endl;
			break;
		}
		A -= D;
		if (A <= 0) {
			cout << "No" << endl;
			break;
		}
	}
	return 0;

}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main () {
	int m = ri();
	int f = ri();
	int b = ri();
	if (b <= m) std::cout << 0 << std::endl;
	else if (b <= m + f) std::cout << b - m << std::endl;
	else std::cout << "NA" << std::endl;
	return 0;
}



Measured memory_bytes: 3220
from collections import defaultdict


def main():
    N = int(input())
    A = list(map(int, input().split()))

    def default():
        return -float("inf")
    dp = [defaultdict(default) for _ in range(N)]
    dp[0][0] = 0
    dp[0][1] = A[0]
    dp[1][0] = 0
    dp[1][1] = max(A[0], A[1])
    for i in range(2, N):
        dp[i][i//2] = max(dp[i-2][i//2-1] + A[i], dp[i-1][i//2])
        dp[i][i//2+1] = max(dp[i-2][i//2] + A[i], dp[i-1][i//2+1])
    print(dp[N-1][N//2])


if __name__ == "__main__":
    main()


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

int n, a, b, c;
int t[10] = {0};

int solve();

int main() {
  cin >> n >> a >> b >> c;
  for(int i = 0; i < n; ++i) cin >> t[i];
  cout << solve() << endl;
  return 0;
}

int solve() {
  int num = (1 << n) - 1, ans = 1000000000;
  for(int i = num; i > 0; --i &= num)
    for(int j = num - i; j > 0; --j &= (num - i))
      for(int k = num - i - j; k > 0;
          --k &= (num - i - j)) {
        int l[3] = {i, j, k}, now = 0;
        int sum[3] = {0}, cnt[3] = {0};

        for(int m = 0; m < 3; ++m)
          for(int o = 0; o < n; ++o)
            if((l[m] >> o) % 2) {
              ++cnt[m];
              sum[m] += t[o];
            }
        now += max(a - sum[0], sum[0] - a);
        now += max(b - sum[1], sum[1] - b);
        now += max(c - sum[2], sum[2] - c);
        for(int m = 0; m < 3; ++m)
          now += 10 * (max(0, cnt[m] - 1));
        ans = min(ans, now);
      }
  return ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#define ll long long

ll int fac(int a) {
	ll int x = 1, v = 1000000007;
	for (int i = 1; i <= a; i++) {
		x *= i;
		if ((x > v)&&(x/v!=0)) x = x%v;
	}
	return x;
}

int max(int a, int b) {
	if (a > b) return a;
	else return b;
}

int min(int a, int b) {
	if (a > b) return b;
	else return a;
}

int main(void) {
	int N, M;
	ll int ans, pre, v = 1000000007;

	scanf("%d %d", &N, &M);
	
	if ((N - M > 1) || (M - N) > 1) printf("0\n");
	else if (N == M) {
		pre = fac(N) % v;
		ans = ((pre*pre) * 2) % v;
		printf("%lld\n", ans);
	}
	else {
		pre = fac(max(N, M)) % v;
		ans = fac(min(N, M)) % v;
		ans = (ans*pre) % v;
		printf("%lld\n", ans);
	}

	return 0;
}

Measured memory_bytes: 128
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

v_odd_common.append((0,0))
v_even_common.append((0,0))

if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1]))
  

Measured memory_bytes: 21084
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

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

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n;
	a=0;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			for(k=0;k<n;k++){
				a+=gcd(gcd(i+1,j+1),k+1);
			}
		}
	}
	cout<<a<<endl;
}

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

// 標準入力から改行かスペースまで読み取り、数字として返す
int get_num() {
    // 10文字+区切り文字までしか受け付けられない
    char s[11];
    int i, n;
    for (i = 0; i < sizeof(s); i++) {
        s[i] = getchar();
        if (s[i] == ' ' || s[i] == '\n') {
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}

int main(void) {
    int i, n, x;
    int m[1001];
    int count;
    
    int min_m;
    
    n = get_num();
    x = get_num();

    for (i = 0; i < n; i++) {
        m[i] = get_num();
    }
    
    min_m = m[0];
    
    for (i = 0; i < n; i++) {
        if (m[i] < min_m) {
            min_m = m[i];
        }
        x -= m[i];
    }
    count = n;
    count += x / min_m;
    
    printf("%d\n", count);
    
    return 0;
}


Measured memory_bytes: 384
/******************
 *AUTHOR: speckrel*
 ******************/
 
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
//Function to read int array
void read(ll arr[], ll n){
    for(ll i=0;i<n;i++){
        cin>>arr[i];
    }
}
 
void solve(){
    static int i=1;
    //cout<<"This is a test code "<<i<<"\n";
    i++;
}
 
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll temp;
  cin>>temp;
  if(temp>=30){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int i = 1;
        int x = 0;
        
        while(true){
            x = sc.nextInt();
            if(x == 0)break;
            System.out.println("Case" + " " + i + ":" + " " + x);
            i++;
        }
        
    }
}



Measured memory_bytes: 41596