akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  
///////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n;
	cin>>n;
	int a[n];
	int su=0;
	for(int  i=0;i<n;++i)
	{
		cin>>a[i];
		su+=a[i];
	}
	int ans=inf;
	int v=0;
	for(int i=0;i<n-1;++i)
	{
		v+=a[i];
		su-=a[i];
		ans=min(ans,abs(v-su));
	}
	cout<<ans;
}

Measured memory_bytes: 256
n,a = [int(i) for i in input().split()]

X = [int(i)-a for i in input().split()]
dp = [[0]*(100*n+1) for i in range(n+1)]
#print(dp)
dp[0][50*n]=1

for i in range(n):
    for j in range(50,100*n+1-50):
            dp[i+1][j] = dp[i][j]+dp[i][j-X[i]]
        
ans = dp[n][n*50]-1
    
print(ans)

Measured memory_bytes: 5620
#include<stdio.h>

int d[20],i,a,b;
double x,y;

int main(){
    while(scanf("%d",&d[0])!=EOF){
        x=d[0];y=0.0;
        for(i=1;i<10;i++)scanf(",%d",&d[i]),x+=d[i];
        scanf(",%d,%d",&a,&b);
        x=x*a/(a+b);i=0;
        while(y<x)y+=d[i],i++;
        printf("%d\n",i);
    }
    return 0;
}


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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
	fastio;

	int n;
	cin >> n;
	vector<int> a(n);
	int mn = INT_MAX, mx = INT_MIN;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		mn = min(mn, a[i]);
		mx = max(mx, a[i]);
	}
	int ans = INT_MAX;
	for(int i = mn; i <= mx; ++i) {
		int curr = 0;
		for(int j = 0; j < n; ++j) curr += (a[j] - i) * (a[j] - i);
		ans = min(ans, curr);
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define ll long long
using namespace std;

ll i,j,k;
const ll MOD = 1000000000 + 7;

int main(){
    ll n;
    cin>>n;
    ll ans=0;
    ll kane=100;
    while(n>kane){
        kane=(ll)kane*1.01;
        ans++;
    }
    
    cout<<ans<<'\n';

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<int64_t MOD> struct Mint {
  int64_t v;
  Mint() { v = 0; }
  Mint(int64_t x) { v = x % MOD; if(v < 0)  v += MOD; }

  Mint operator-() { return Mint{-v}; };
  Mint operator+(Mint x) { return Mint(v + x.v); };
  Mint operator-(Mint x) { return Mint(v - x.v); };
  Mint operator*(Mint x) { return Mint(v * x.v); };
  Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

  Mint& operator+=(Mint x) { return *this = (*this + x); };
  Mint& operator-=(Mint x) { return *this = (*this - x); };
  Mint& operator*=(Mint x) { return *this = (*this * x); };
  Mint& operator/=(Mint x) { return *this = (*this / x); };

  static Mint pow(Mint base, int64_t exp) {
    if(exp == 0)  return Mint(1);
    return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
  }

  friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

template<class T, int N> struct Poly {
  deque<T> f;
  Poly() { f.assign(N, T{}); }
  Poly(deque<T>& f) : f(f) {}
  Poly(const Poly& g) : f(g.f) {}

  void operator+=(Poly g) { for(int i=0; i<N; i++) f[i]+=g[i]; }
  void operator>>=(int c) { while(c--) f.push_front(T{}), f.pop_back(); }
  void operator<<=(int c) { while(c--) f.push_back(T{}), f.pop_front(); }
  void operator*=(T c) { for(auto& e : f) e *= c; }

  Poly operator+(Poly g) { auto r=Poly(f); r+=g; return r; }
  Poly operator-(Poly g) { auto r=Poly(f); r+=g*(-1); return r; }
  Poly operator>>(int c) { auto r=Poly(f); r>>=min(c,N); return r; }
  Poly operator<<(int c) { auto r=Poly(f); r<<=min(c,N); return r; }
  Poly operator*(T c) { auto r=Poly(f); r*=c; return r; }

  T& operator[](int i) { return f[i]; }
  inline auto begin() { return f.begin(); }
  inline auto end() { return f.end(); }
};

int main() {
  lint N, K;
  cin >> N >> K;

  vector<lint> A(N);
  for(auto& elem : A) cin >> elem;

  using P = Poly<mint, 112345>;
  P f; f[0] = 1;
  for(auto a : A) {
    f = f - (f>>(a+1));
    partial_sum(f.begin(), f.end(), f.begin());
  }
  cout << f[K] << endl;
}

Measured memory_bytes: 3988
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

YES = 'APPROVED'
NO = 'DENIED'

def solve(n, a):
    for i in range(n):
        if a[i] % 2 or (a[i] % 2 == 0 and (a[i] % 3 == 0 or a[i] % 5 == 0)):
            pass
        else:
            print(NO)
            return
    print(YES)


def main():
    n = int(input())
    a = []
    a = (list(map(int, input().split())))
    solve(n, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
  int n,max,min,a,i;
  long sum;
  
  scanf ("%d",&n);
  scanf ("%d",&a);
  max = min = a;
  sum = a;
  for(i = 1; i < n; i++) {
  	scanf("%d",&a);
	sum += a;
	if(max < a)
	max = a;
	if(min > a)
	min = a;
  }
  printf("%d %d %ld\n",min,max,sum);
  
return 0;
}


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

int main()
{
  ll q,h,s,d; cin>>q>>h>>s>>d;
  ll n; cin >> n;

  ll t = 8*q;
  t = min(t, 4*h);
  t = min(t, 2*s);
  t = min(t, d);
  ll u = min(4*q, 2*h);
  u = min(u, s);

  cout << (n/2)*t + (n%2)*u << endl;

  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; i++)
    {
        if(i%3 != 0 && i%5 != 0)
        {
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int p[10][10];
int id[10][10];
int side[100];
int size[100];
int share[100][100];
bool visited[10][10];


int main() {
  int w,h;
  while(cin>>w>>h,w||h) {
    int fx,fy,fq;
    cin>>fx>>fy>>fq;
    REP(i,h) REP(j,w) cin >> p[i][j];
    REP(i,100) side[i]=size[i]=0;
    memset(id,-1,sizeof(id));
    memset(share,0,sizeof(share));
    memset(visited,0,sizeof(visited));
    int num = 0;
    const int dy[4] = {-1,0,1,0};
    const int dx[4] = {0,1,0,-1};
    vector<pair<int, pii> > v;
    REP(i,h) REP(j,w) if (p[i][j]) v.push_back(make_pair(p[i][j], pii(i,j)));
    sort(ALL(v));
    FOR(it, v) {
      pii a = it->second;
      int i = a.first, j = a.second;
      if (id[i][j] == -1) {
        queue<pii> Q;
        Q.push(pii(i,j));
        while(!Q.empty()) {
          pii now = Q.front(); Q.pop();
          id[now.first][now.second] = num;
          size[num]++;
          REP(k,4) {
            int y = now.first + dy[k];
            int x = now.second + dx[k];
            if (valid(y,x,h,w)) {
              if (id[y][x] == -1 && p[y][x] == p[i][j] && !visited[y][x]) {
                visited[y][x] = 1;
                Q.push(pii(y,x));
              } else if (p[y][x] < p[i][j]) {
                if (p[y][x] > 0) share[num][id[y][x]]++;
                side[num]++;
              }
            } else {
              side[num]++;
            }
          }
        }
        num++;
      }       
    }
    // REP(i,h) {
    //   REP(j,w) {
    //     cout << id[i][j] << " ";
    //   }
    //   cout << endl;
    // }
    // REP(i,num) {
    //   REP(j,num) {
    //     cout << share[i][j] << " " ;
    //   }
    //   cout << endl;
    // }
    // REP(i,num) cout << side[i] << " "; cout << endl;
    int L;
    cin >> L;
    REP(i,L) {
      int t, x, y;
      cin >> t >> x >> y;
      double tmp[100] = {};
      tmp[id[fy][fx]] = t*fq;
      for (int idx=num-1; idx>=0; --idx) {
        if (side[idx] == 0) continue;
        double flow = max(0.0, tmp[idx]-30*30*30*size[idx]);
        flow /= side[idx];
        REP(j,num) {
          tmp[j] += flow * share[idx][j];
        }
      }
      double hei = min((double)30, tmp[id[y][x]] / (30*30*size[id[y][x]]));
      cout << int(hei + EPS) << endl;
    }
  }
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

const int tam = 1e5 + 10;

int P[tam];

int findParent(int v) {
    if (P[v] == -1) return v;
    return P[v] = findParent(P[v]);
}

int comps;

void join(int a, int b) {
    a = findParent(a);
    b = findParent(b);
    if (a == b) return;
    P[a] = b;
    comps--;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    clr(P, -1);
    int n, m;
    cin >> n >> m;
    comps = n;
    fore(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        join(a, b);
    }
    cout << comps-1 << '\n';
    return 0;
}
// Dinosaurs are cool!

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


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


    ll n, k;
    cin >> n >> k;

    ll d = n / k;
    cout << min(n-d*k, -(n-(d+1)*k)) << endl;


    return 0;
}



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


int main(int argc, char const *argv[])
{
	int n;
	//int arr[n];
	cin>>n;
	bool b = 0;
	int x;
	for (int i = 0; i < n; ++i)
	{
		cin>>x;
		if(x%2==0){
			if((x%3!=0)&&(x%5!=0)) b=1;
			//else b=1;
		}
	}
	if(!b) cout<<"APPROVED";
	else cout<<"DENIED";
	return 0;
}

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

int main() {
    int n,m,tem=0;
    cin>>n>>m;
    int a[n],sum=0;
    rep(i,n) {
        cin>>a[i];
        sum+=a[i];
    }
    rep(i,n) {
        if(a[i]*4*m>=sum)tem++;
    }
    if(tem>=m) {
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main(){
    int N,l,r;

    cin >> N;

    int left_min = 100001;
    int right_max = 0;

    int seat[100000] = {};

    for(int i = 0; i < N; i++)
    {
        cin >> l >> r;
        l = l-1;
        r = r-1;

        for (int j = l; j <= r; j++)
        {
            seat[j] = 1;
        }

        //if(left_min >= l)left_min = l;
        //if(right_max <= r)right_max = r;
    }
    int res = 0;

    for(int i = 0; i <= 100000; i++)
    {
        if(seat[i] == 1)res++;
    }

    cout << res << endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

/*
n * (n + 1) - 2x = 0
n ^ 2 + n - 2x = 0
n = (- 1 + sqrt(1 + 8x)) / 2
*/
ll solve(ll x){
    return (ll) ceil((sqrt(1 + 8 * x) - 1) / 2);
}

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

    ll x;
    cin >> x;
    cout << solve(x) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; ll M; cin >>N >>M;
  vector<ll> A(N); rep(i, N) cin >>A[i];
  vector<ll> Asum(N+1); rep(i, N) Asum[i+1] = Asum[i] + A[i];
  rep(i, N) Asum[i+1] %= M;
  map<ll,ll> S;
  ll res = 0;
  rep(i, N+1){
    res += S[Asum[i]];
    S[Asum[i]]++;
  }
  cout <<res <<endl;

}

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

using namespace std;

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

int main()
{
    int N, x, y, z;
    int ans;

    cin >> N;

    vector<int> a(N+1), b(N+1), c(N+1);

    a[0] = b[0] = c[0] = 0;

    for(int i=1; i<=N; i++)
    {
        cin >> x >> y >> z;

        a[i] = max1(b[i-1]+x, c[i-1]+x);
        b[i] = max1(a[i-1]+y, c[i-1]+y);
        c[i] = max1(a[i-1]+z, b[i-1]+z);
    }


    ans = max1(a[N], b[N]);
    ans = max1(ans, c[N]);
    cout << ans << endl;    

    return 0;
}    
     

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> x(n);
    rep(i,n) cin>>x[i];
    ll mn=1e9;
    rep(i,n-k+1) mn=min(mn,x[i+k-1]-x[i]+min(abs(x[i+k-1]),abs(x[i])));
    cout<<mn<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if(n==1&&k==1) return !printf("-1");
	if(k==0) for(int i=0;i<1<<n;i++) printf("%d %d ",i,i);
	else if(k<(1<<n))
	{
		printf("%d ",k);
		for(int i=(1<<n)-1;i>=0;i--) if(i!=k) printf("%d ",i);
		printf("%d ",k);
		for(int i=0;i<(1<<n);i++) if(i!=k) printf("%d ",i);
	}
	else printf("-1");
}

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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    int n;
    cin >> n;
    int a = n /100;
    int b = n % 10;
    if (a == b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

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

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;



void solve() {
    string s;
    cin >> s;
    int n = s.size();
    if ((s[n - 1] == '1') || (s[0] == '0')) {
        cout << -1 << endl;
        return;
    }
    for (int i = 0; i < n - 1; ++i) {
        if (s[i] != s[n - 2 - i]) {
            cout << -1 << endl;
            return;
        }
    }
    vector<int> a;
    for (int i = 0; i < n - 1; ++i) {
        if (s[i] == '1')
            a.push_back(i);
    }
    int m = a.size();
    vector<pii> ed;
    for (int i = 0; i < m; ++i) {
        ed.push_back(pii(i + 1, i + 2));
    }
    int k = m + 2;
    for (int i = 1; i < m; ++i) {
        for (int j = 0; j < a[i] - a[i - 1] - 1; ++j) {
            ed.push_back(pii(i + 1, k));
            ++k;
        }
    }
    if (k != n + 1) {
        cout << -1 << endl;
        return;
    }
    for (int i = 0; i < ed.size(); ++i) {
        cout << ed[i].first << " " << ed[i].second << "\n";

    }

}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

Measured memory_bytes: 2756
#include <iostream>

using namespace std;

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  if (0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3080
from collections import deque

def read_input():
    n, k = map(int, input().split())
    vlist = list(map(int, input().split()))

    return n, k, vlist


def submit():
    n, k, vlist = read_input()

    maxvalue = 0
    for kk in range(1, k + 1):
        # 左からi回宝石を取得する
        # 右からkk-i回宝石を取得する
        for i in range(kk + 1):
            getv = []
            minusv = []
            vq_temp = deque()

            for v in vlist:
                vq_temp.append(v)

            for j in range(i):
                if len(vq_temp) > 0:
                    vl = vq_temp.popleft()
                    if vl < 0:
                        minusv.append(vl)
                    else:
                        getv.append(vl)
                else:
                    break

            for j in range(kk - i):
                if len(vq_temp) > 0:
                    vr = vq_temp.pop()
                    if vr < 0:
                        minusv.append(vr)
                    else:
                        getv.append(vr)
                else:
                    break


            # k - kk回はminusを削除できる
            minusv.sort()
            for m in range(k - kk):
                if minusv:
                    minusv.remove(minusv[0])
                else:
                    break

            currvalue = sum(getv) + sum(minusv)

            if currvalue > maxvalue:
                maxvalue = currvalue

    print(maxvalue)

if __name__ == '__main__':
    submit()


Measured memory_bytes: 45276
H, W = map(int, input().split())
List1 = [list(map(str, input())) for row in range(H)]
List2 = [[0 for col in range(W)] for row in range(H)]
for row in range(H):
    for col in range(W):
        if List1[row][col] == "#":
            List2[row][col] = "#"
        else:
            c = 0
            for rdf in range(-1, 2):
                if 0 <= row + rdf < H:
                    for cdf in range(-1, 2):
                        if 0 <= col + cdf < W:
                            if List1[row + rdf][col + cdf] == "#":
                                c += 1
            List2[row][col] = c
for row in range(H):
    print(*List2[row], sep="")


Measured memory_bytes: 44912
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

ll num, dp[128][21]; //dp[i][j] : i個の項を使った時の計算結果j
ll T[101];
ll ans;

int main()
{
	int dx[] = {1, -1};
	cin >> num;
	for(int i = 1; i < num; i++)
	{
		cin >> T[i];
	}
	cin >> ans;

	dp[1][T[1]] = 1;

	for(int i = 1; i < num; i++)
	{
		for(int j = 0; j < 21; j++)
		{
			if(dp[i][j] == 0)
			{
				continue;
			}
			for(int k = 0; k <= 1; k++)
			{
				int r = j + T[i+1]*dx[k];

				if(r >= 0 && r <= 20)
				{
					dp[i+1][r] += dp[i][j];
				}
			}
		}
	}


	cout << dp[num-1][ans] << endl;
	return 0;
}

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

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

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


typedef pair<int, int> p;

int main(){
  int n, c;
  scanf("%d %d", &n, &c);

  int d[c + 1][c + 1];
  FOR (i, 1, c + 1) {
    FOR (j, 1, c + 1) {
      scanf("%d", &d[i][j]);
    }
  }

  int m[n + 1][n + 1];
  REP (i, n) {
    REP (j, n) {
      scanf("%d", &m[i][j]);
    }
  }

  int x[3][c + 1];
  REP (i, 3) REP (j, c + 1) x[i][j] = 0;

  REP (i, n) {
    REP (j, n) {
      x[(i + j) % 3][m[i][j]]++;
    }
  }

  LL ans = INF;
  FOR (c1, 1, c + 1) FOR (c2, 1, c + 1) FOR (c3, 1, c + 1) {
    LL sum = 0;
    if (c1 != c2 && c2 != c3 && c3 != c1) {
      FOR (c0, 1, c + 1) {
        sum += d[c0][c1] * x[0][c0] + d[c0][c2] * x[1][c0] + d[c0][c3] * x[2][c0];
      }
      ans = min(ans, sum);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1280
import sys
import copy

readline = sys.stdin.readline

def dfs(p, x):
    global graphtmp, check
    to = graphtmp[x]
    check[x] = 1
    for t in to:
        if p == t or check[t] == 1:
            continue
        dfs(x, t)

def main():
    global graphtmp, check
    N, M = map(int, readline().split())
    graph = [[] for _ in range(N)]
    nodelist = []
    for _ in range(M):
        a, b = map(int, readline().split())
        a -= 1; b-= 1
        nodelist.append([a, b])
        graph[a].append(b)
        graph[b].append(a)
    
    ans = 0
    for nodetmp in nodelist:
        check = [0]*N
        graphtmp = copy.deepcopy(graph)
        graphtmp[nodetmp[0]].remove(nodetmp[1])
        graphtmp[nodetmp[1]].remove(nodetmp[0])
        dfs(-1, 0)
        if 0 in check:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3564
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <list>
#include <math.h>
#include <map>
using namespace std;
#define REP(i, k, n) for(int i = k;i < n; i++)
#define rep(i, n) REP(i,0,n)
#define ll long long int
int dx[4] = {0,-1,1,0};
int dy[4] = {-1,0,0,1};
#define eps 10e-6
#define mod 1000000007
ll a[100001];
int n;
int main(void){
	int a = 100;
	int ans = 0;
	for(int i = 0; i < 3; i++){
		int tmp;
		cin >> tmp;
		ans += (tmp * a);
		a/=10;
	}
	cout << ((ans%4 == 0)?"YES":"NO") << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=500+5;
int n,m,v[N][N];

struct info
{
    int a,b,c,d;
};

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            cin>>v[i][j];
            v[i][j]%=2;
        }
    vector<info>ans;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<m;j++)
            if(v[i][j])
            {
                ans.push_back({i,j,i,j+1});
                v[i][j]=0;
                v[i][j+1]^=1;
            }
        if(v[i][m] && i!=n)
        {
            ans.push_back({i,m,i+1,m});
            v[i][m]=0;
            v[i+1][m]^=1;
        }
    }
    cout<<ans.size()<<"\n";
    for(auto x:ans)
        cout<<x.a<<" "<<x.b<<" "<<x.c<<" "<<x.d<<"\n";
    return 0;
}
/**

**/


Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int h;
    cin>>h;
    int n;
    cin>>n;
    int a[n];
    int kai=0;
    rep(i,n){
        cin>>a[i];
        kai+=a[i];
    }
    if(kai>=h){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


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

int gap(int number) {
    int i;
    for (i = 10; i < number ; i += 10) {
        ;
    }
    return (i - number);
}

int main() {
    int ans = 0;
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    int max_gap = 0;

    if (max_gap < gap(a)) max_gap = gap(a);
    if (max_gap < gap(b)) max_gap = gap(b);
    if (max_gap < gap(c)) max_gap = gap(c);
    if (max_gap < gap(d)) max_gap = gap(d);
    if (max_gap < gap(e)) max_gap = gap(e);


    ans = a + gap(a) + b + gap(b) + c + gap(c) + d + gap(d) + e + gap(e);

    if (max_gap == gap(a)) {
        ans -= gap(a);
    } else if (max_gap == gap(b)){
         ans -= gap(b);
     }
    else if (max_gap == gap(c)) ans -= gap(c);
    else if (max_gap == gap(d)) ans -= gap(d);
    else if (max_gap == gap(e)) ans -= gap(e);

    cout << ans << endl;
}


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

int main(){
  int n,a,b,sum,ans=0,hoge;
  cin >>n>>a>>b;
  for(int i=1;i<=n;i++){
    hoge = i;
    sum = 0;
    if(hoge/10000>0){
      sum += hoge/10000;
      hoge =hoge%10000;
    }
    if(hoge/1000 > 0){
      sum += hoge/1000;
      hoge = hoge%1000;
    }
    if(n/100 > 0){
      sum += hoge/100;
      hoge =hoge%100;
    }
    if(n/10 > 0){
      sum += hoge/10;
      hoge =hoge%10;
    }
    sum += hoge;
    if(sum <=b && a <= sum) ans+=i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
a,b,c = map(int,readline().split())
#a:美味しくない
#b:美味しい
#c:毒、美味しい

res = c-a
if res <= 0:
    print(b+c)
else:
    res = res-b
    if res <= 0:
        print(b+c)
    else:
        print(min(b+c,b+c-res+1))

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtCorder1
{
    class AtCorder160A
    {
        static void Main(string[] args)
        {
            string cr = Console.ReadLine();

            if (cr[2] == cr[3] && cr[4] == cr[5])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

struct node {
    int c, s, f;
};

int N;
vector<node> info;

int main() {
    cin >> N;
    int c, s, f;
    for(int i = 0; i < N-1; i++) {
	cin >> c >> s >> f;
	info.push_back(node{c, s, f});
    }

    int sz = info.size();
    for(int i = 0; i < sz; i++) {
	int current_time = 0;
	
	for(int j = i; j < sz; j++) {
	    if (current_time < info[j].s) {
		current_time += info[j].s - current_time;
	    } else if (current_time % info[j].f != 0) {
		current_time += info[j].f - (current_time % info[j].f);
	    }

	    current_time += info[j].c;
	}
	cout << current_time << endl;
    }
    cout << 0 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#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() {
  int a, b;
  cin >> a >> b;
  if(a * b % 2 == 0) cout << "Even" << endl;
  else cout << "Odd" << endl;
}

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

const int N = 200005;

char s[N];
char t[N];

int solve() {
  scanf("%s", s);
  scanf("%s", t);

  int n = strlen(s);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += (s[i] != t[i]);
  }

  printf("%d\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 4156
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 1000003;

int n;
int a[N];

int get_parity(int n, int k) {
  return (n | k) == n;
}

int main()
{
  cin >> n;
  int one = false;
  for(int i = 0 ; i < n ; i++) {
    char c; cin >> c;
    a[i] = c - '1';
    one |= a[i] == 1;
  }
  if(!one)
    for(int i = 0 ; i < n ; i++)
      a[i] >>= 1;
  int p = 0;
  for(int i = 0 ; i < n ; i++) {
    int cur = get_parity(n - 1, i);
    if(cur && a[i] == 1)
      p ^= 1;
  }
  if(p == 1) {
    if(one) cout << 1 << endl;
    else cout << 2 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */
/* main */
int main(){

    int n; cin >> n;
    vector<int> A(n);
    for (int i = 0 ; i < n; i++)
        cin >> A[i];

    int q; cin >> q;
    int b, e, target;
    for (int i = 0; i < q; i++) {
        cin >> b >> e >> target;
        // A[b] , ..., A[e-1];
        int cnt = count(A.begin() + b, A.begin() + e, target);
        cout << cnt << '\n';
    }
}



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

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

int main(){
    string s;
    cin>>s;
    if (s=="MON")
    {
        /* code */
        cout<<6<<endl;
    }
     if (s=="TUE")
    {
        /* code */
        cout<<5<<endl;
    }
     if (s=="WED")
    {
        /* code */
        cout<<4<<endl;
    }
     if (s=="THU")
    {
        /* code */
        cout<<3<<endl;
    }
     if (s=="FRI")
    {
        /* code */
        cout<<2<<endl;
    }
     if (s=="SAT")
    {
        /* code */
        cout<<1<<endl;
    }
     if (s=="SUN")
    {
        /* code */
        cout<<7<<endl;
    }
    
    }

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

int main(){
  int n,m,Q;
  cin >> n >> m >> Q;
  int l[m],r[m],c[n+1][n+1],x[n+1][n+1];
  for(int i = 0;i <= n;i++){
    for(int j = 0;j <= n;j++){
      c[i][j] = 0;
      x[i][j] = 0;
    }
  }
  for(int i = 0;i < m;i++){
    cin >> l[i] >> r[i];
    x[l[i]][r[i]]++;
  }
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      c[i][j] = c[i][j-1] + x[i][j];
    }
  }
  for(int i = 0;i < Q;i++){
    int p,q;
    cin >> p >> q;
    int sum = 0;
    for(int j = p;j <= q;j++){
      sum += c[j][q] - c[j][p-1];
    }
    cout << sum << endl;
  }
}

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

#define int long long
const int N = 1e5 + 10 ;
int tp = N ;
int dp[N] ;
int32_t main(){
	int n, val; 
	cin >> n >> val ;
	for(int i = 0 ; i < n ; i++){
		int w , v ; 
		cin >> w >> v ;
		for(int j = tp - w - 1 ; j >= 0 ; j--){
			dp[j+w] = max(dp[j+w] , dp[j] + v) ;
		}
	}
	cout << dp[val] ;
	return 0 ;
}



Measured memory_bytes: 4368
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let n: u64 = itr.next().unwrap().parse().unwrap();
    let m: u64 = itr.next().unwrap().parse().unwrap();

    if n * 2 <= m {
        let l = m - n * 2;
        println!("{}", n + l / 4);
    } else {
        println!("{}", m / 2);
    }
}


Measured memory_bytes: 2100
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ABC155C
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var N = NN;
            var SList = NSList(N).GroupBy(e => e).ToDictionary(e => e.Key, e => e.Count());
            var max = SList.Values.Max();
            foreach (var item in SList.Where(e => e.Value == max).Select(e => e.Key).OrderBy())
            {
                Console.WriteLine(item);
            }
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static IEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 68460
x = int(input())
while True:
    isAns = True
    for d in range(2, int(x ** 0.5) + 2):
        if d == x:
            continue
        if x % d == 0:
            isAns = False
            break
    if isAns:
        print(x)
        break
    x += 1


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp,t, n,j,x, k , d;
bool cond;
string s;
int main()
{
    //I am Monim, a tiny creature of Allah
    cin >> x >> k >> d;
    if(x<0)
        x  = -x;
    if(x/d>k)
    {
        cout << x - d*k << endl;
    }
    else{
        k = k - x/d;
        x = x%d;
        if(k%2==0)
            cout << x << endl;
        else
            cout << abs(x-d) << endl;
    }
    return 0;
}


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

using namespace std;

int N, M;
int arr[2005], brr[2005];
long long dp[2005][2005];
long long MOD = 1e9+7;

long long sum(long long a, long long b){
    return (a+b)%MOD;
}

long long sub(long long a, long long b){
    return ((a-b)%MOD+MOD)%MOD;
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N >> M;
    for(int i = 1; i<=N; i++){
        cin >> arr[i];
    }
    for(int i=1 ; i<=M; i++){
        cin >> brr[i];
    }
    for(int i = 0; i<=N; i++){
        dp[i][0] = 1;
    }
    for(int i = 0; i<=M; i++){
        dp[0][i] = 1;
    }
    for(int i = 1; i<=N; i++){
        for(int j = 1; j<=M; j++){
            dp[i][j] = sum(dp[i-1][j], dp[i][j-1]);
            if(arr[i] != brr[j]){
                dp[i][j] = sub(dp[i][j], dp[i-1][j-1]);
            }
        }
    }
    cout << dp[N][M] << endl;
}


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

typedef long long ll;
typedef long double ld;
const int MOD = 1e9+7;
const int MX = 2e5+5;
const ll  INF = 1e18;
const ld  PI = acos((ld) -1);
template<class T> inline void array_input(T a[], size_t n){for(size_t i = 0; i < n; i++)cin >> a[i];}
/*
template<class T>
inline void array_init(T a[], T val){
    for(size_t i )
}
*/
long long binExp(long long a, long long b, long long mod){
    long long res = 1;
    while(b > 0){
        if(b % 2) res = res * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return res;
}

//#define FILE
int main(){
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // 0

    ll x, k, d;
    cin >> x >> k >> d;

    if(x != 0){
        x = abs(x);
        ll t = x / d;
        if(k < t){
            cout << x - k * d << '\n';
            return 0;
        }
        x -= t * d;
        k -= t;
        k %= 2;

        if(k){
            cout << min(x+d, abs(x-d)) << '\n';

        }else cout << x << '\n';

    }else if(x == 0){
        if(k % 2) cout << d << '\n';
        else cout << "0\n";

    }


    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
long cd[111111];
void set(int s,int t){
cd[s]=t;
}
int compare(const void *a,const void *b){
return cd[*(int*)b]-cd[*(int*)a];
}
int main(){
long n,k,t[111111],d[111111],i,c[111111],ans=0,p[111111],sum=0,q[111111],r=0,m=0;
scanf("%ld%ld",&n,&k);
for(i=0;i<n;i++){
scanf("%ld%ld",&t[i],&d[i]);
set(i,d[i]);
c[i]=0;
p[i]=i;
}
qsort(p,n,sizeof(long),compare);
for(i=0;i<k;i++){
if(c[t[p[i]]-1]>0){
q[r]=d[p[i]];
r++;
}
else
m++;
c[t[p[i]]-1]++;
sum+=d[p[i]];
}
ans=sum+m*m;
r--;
for(;i<n&&m<k;i++){
if(c[t[p[i]]-1]==0){
m++;
sum+=d[p[i]]-q[r];
r--;
if(ans<sum+m*m)
ans=sum+m*m;
}
c[t[p[i]]-1]++;
}
printf("%ld\n",ans);
return 0;
}

Measured memory_bytes: 6012
#include<stdio.h>
int main(){
	char s[5];
	int i,flg=0;
	scanf("%s",s);
	for(i=0;i<3;i++){
		if(s[i]==s[i+1]){
			flg=1;
			break;
		}
	}
	if(flg==1) printf("Bad\n");
	else printf("Good\n");
	return 0;
}

Measured memory_bytes: 1644
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll a[200005];
    for(int i = 0; i < n; i++) cin >> a[i];
    int left = 0, right = 1000000000;
    while(right - left > 1){
        ll mid = (right + left) / 2;
        ll c = 0;
        for(int i = 0; i < n; i++){
            if(a[i] % mid == 0) c += a[i] / mid - 1;
            else c += a[i] / mid;
        }
        if(c <= k) right = mid;
        else left = mid;
    }
    cout << right << endl;
}


Measured memory_bytes: 5192
'use strict';

function Main(INPUT) {
    const input = INPUT.split("\n");
    const a = input[0];
    const b = input[1];

    console.log(a[0] == b[2] && a[1] == b[1] && a[2] == b[0] ? "YES" : "NO");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11340
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,cnt=0,p=1,tmp;
  cin >> N;
  vector<int> A(N+1);
  for(int i=1;i<=N;i++){
    cin >> A[i];
  }
  while(1){
    if(A[p]==-1 || A[p]==2) break;
    tmp=p;
    p=A[p];
    A[tmp]=-1;
    cnt++;
  }
  cout << (A[p]==-1?-1:cnt+1) << endl;
}

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

int main() {
	int X;
	cin >> X;
	switch (X % 7) {
	case 0:
		cout << "thu";
		break;
	case 1:
		cout << "fri";
		break;
	case 2:
		cout << "sat";
		break;
	case 3:
		cout << "sun";
		break;
	case 4:
		cout << "mon";
		break;
	case 5:
		cout << "tue";
		break;
	default:
		cout << "wed";
	}
	cout << endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
    FIO
    double n;
    cin>>n;
    double odd = ceil(n/2);
    double probability = odd/n;
    cout<<fixed<<setprecision(10)<<probability;
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main()
{
	int N;

	cin >> N;

	std::vector<int> array(N);

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

	}



	int max_value = 0;
	int max_value_num = 0;
	int sub_value = 0;
	for (int i = 0; i < N; ++i)
	{
		if (max_value < array[i])
		{
			if (sub_value <= max_value)
			{
				sub_value = max_value;
			}
			max_value = array[i];
			max_value_num = 1;

		}
		else if (max_value == array[i])
		{
			max_value_num++;
		}
		else if (sub_value < array[i])
		{
			sub_value = array[i];
		}

	}
	for (int i = 0; i < N; ++i)
	{
		if (array[i] == max_value)
		{
			if (max_value_num == 1)
			{
				cout << sub_value << endl;
			}
			else
			{
				cout << max_value << endl;
			}
		}
		else
		{
			cout << max_value << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 2432
#include <iostream>

using namespace std; 


int main(){
	long int n; 
	cin >> n; 
	long long int sum = 0, now, prev = 0; 
 	for (long int i= 0; i < n; i++){
		cin >> now; 
		sum+= prev-now > 0? prev-now: 0;  
		prev = prev-now > 0? prev: now;
	} 
	
	cout << sum << endl; 
	
} 



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

using namespace std;

const int maxn = 1e5 + 7;

int n, q, a[maxn], k, f[maxn][26][26], prf[maxn];
string s[maxn], order;
struct Trie
{
    int id, cnt;
    Trie* Child[26];
};

Trie* GetTrie()
{
    Trie* cac = new Trie;
    cac->id = cac->cnt = 0;
    for(int i = 0; i < 26; i++) cac->Child[i] = NULL;
    return cac;
}

Trie* cac = GetTrie();

void Insert(int x)
{
    Trie* ahihi = cac;
    for(auto i: s[x])
    {
        if(ahihi->Child[i - 'a'] == NULL) ahihi->Child[i - 'a'] = GetTrie();
        ahihi = ahihi->Child[i - 'a'];
        ahihi->cnt++;
    }
    ahihi->id = x;
}

void Solve(int x)
{
    Trie* ahihi = cac;
    for(auto i: s[x])
    {
        if(ahihi->id != 0) prf[x]++;
        i -= 'a';
        for(int j = 0; j < 26; j++)
        {
            if(j != i && ahihi->Child[j] != NULL)
            {
                f[x][j][i] += ahihi->Child[j]->cnt;
            }
        }
        ahihi = ahihi->Child[i];
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s[i];
        Insert(i);
    }
    for(int i = 1; i <= n; i++) Solve(i);
    cin >> q;
    for(int i = 1; i <= q; i++)
    {
        cin >> k >> order;
        int ans = 0;
        for(int x = 1; x < 26; x++)
        {
            for(int y = x - 1; y >= 0; y--)
            {
                ans += f[k][order[y] - 'a'][order[x] - 'a'];
            }
        }
        cout << ans + prf[k] + 1 << '\n';
    }
}


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

using namespace std;

int  main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int ans = 1e9;
	for (int k = 0; k <= max(x, y); k++) {
		ans = min(ans, k * 2 * c + max(0, x - k)*a + max(0, y - k)*b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
 
int main() {
  ll n,t,a;
  ci(n>>t>>a);
  vector<double> h(n);
  for(i,0,n)
    ci(h[i]);
  double b=10000,c=0;
  for(i,0,n)
    if(b>abs(a-(t-h[i]*0.006))){
      b=abs(a-(t-h[i]*0.006));
      c=i;
    }
  co(c+1);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
using namespace std;
struct procedure{
    char name[100];
    int time;
};
int main(){
    int n,m,t=0;
    queue<procedure> a;
    procedure b;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%s",b.name);
        scanf("%d",&b.time);
        a.push(b);
        for(int j=0;j<100;j++)b.name[j]='\0';
    }
    while(!a.empty()){
        b=a.front();
        a.pop();
        if(b.time<=m){
            t+=b.time;
            printf("%s",b.name);
            printf(" %d\n",t);
        }
        else{
            t+=m;
            b.time-=m;
            a.push(b);
        }
    }
}

Measured memory_bytes: 7576