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

const int INF = 100000;

int pay(int N, int M, int C[]) {
    int dp[N+10010]; // dp[v] v円になるコインの最小枚数
    rep(i, N+10010) dp[i] = INF;

    dp[0] = 0;
    for (int n=0; n<=N; n++) {
        for (int i=0; i<M; i++) {
            dp[n+C[i]] = min(dp[n+C[i]], dp[n] + 1);
        }
    }
    return dp[N];
}

int main() {
    int N, M;
    cin >> N >> M;

    int C[M];
    rep(i, M) cin >> C[i];

    cout << pay(N, M, C) << endl;

    return 0;
}




Measured memory_bytes: 3336
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<int> > g(N);
  for(int i = 0; i < N; ++i) {
    int t, d;
    cin >> t >> d; --t;
    g[t].push_back(d);
  }
  vector<int> basic, addit;
  for(int i = 0; i < N; ++i) {
    sort(g[i].begin(), g[i].end(), greater<int>());
    if(g[i].size() >= 1) {
      basic.push_back(g[i].front());
    }
    if(g[i].size() >= 2) {
      addit.insert(addit.end(), g[i].begin() + 1, g[i].end());
    }
  }
  sort(basic.begin(), basic.end(), greater<int>());
  sort(addit.begin(), addit.end(), greater<int>());
  int lb = basic.size(), la = addit.size();
  vector<long long> sbasic(lb + 1), saddit(la + 1);
  for(int i = 0; i < lb; ++i) sbasic[i + 1] = sbasic[i] + basic[i];
  for(int i = 0; i < la; ++i) saddit[i + 1] = saddit[i] + addit[i];
  long long ans = 0;
  for(int i = 0; i <= K && i <= lb; ++i) {
    if(K - i <= la) {
      ans = max(ans, (long long)(i) * i + sbasic[i] + saddit[K - i]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7032
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
    ll a,b,c;
    cin>>a>>b>>c;

    if( c-a-b > 0 && 4*a*b < (c-a-b)*(c-a-b) ) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <iomanip>


using namespace std;

using ll = long long;
const ll INF = 1e18L + 5;

const int nax = 2e5 + 5;

vector<pair<int, int>> intervals[nax];

struct S {
    ll small, lazy;
    void merge(const S& a, const S& b){
        small = min(a.small, b.small);
        
    }
    void add(ll x){
        small += x;
        lazy += x;
    }
};

vector<S> tree;

const int TYPE_ADD = 1, TYPE_MIN = 2;
void rec(int id, int low, int high, int qLow, int qHigh, int type, ll& x){
    if(high < qLow || qHigh < low){
        return;
    }
    if(qLow <= low && high <= qHigh){
        if(type == TYPE_ADD){
            tree[id].add(x);
        }
        else if(type = TYPE_MIN){
            x =  min(x, tree[id].small);
        }
        /////
        return;
    }
    for(int b : {2 * id, 2 * id + 1}){
        tree[b].add(tree[id].lazy);
    }
    tree[id].lazy = 0;
    
    int lastLeft = (low + high) / 2;
    rec(2 * id, low, lastLeft, qLow, qHigh, type, x);
    rec(2 * id + 1, lastLeft + 1, high, qLow, qHigh, type, x);
    
    tree[id].merge(tree[2 * id], tree[2 * id + 1]);
}


int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    ll sum_of_scores = 0;
    for(int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        intervals[b].emplace_back(a, c);
        sum_of_scores += c;
    }
    ll answer = 0;
    
    int base = 1;
    while(base <= n + 1) {
        base *= 2;
    }
    tree.resize(2 * base, {INF, 0});
    
    ll whatever = 0 - INF;
    rec(1, 0, base - 1, 0, 0, TYPE_ADD, whatever);
    for(int i = 1; i <= n + 1; ++i) {
        // I want to put '1' here
        for(pair<int,int> p : intervals[i-1]) {
            whatever = p.second;
            rec(1, 0, base - 1, 0, p.first - 1, TYPE_ADD, whatever);
        }
        ll best = INF;
        rec(1, 0, base - 1, 0, base - 1, TYPE_MIN, best);
        if(i == n + 1) {
            answer = best;
        }
        whatever = best - INF;
        rec(1, 0, base - 1, i, i, TYPE_ADD, whatever);
    }
    
    
    printf("%lld\n", sum_of_scores - answer);
}
/*
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, m;
    ll sum;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        intervals[b].emplace_back(a, c);
        sum += c;
    }
    
    ll answer = 0;
    
    int base = 1;
    while(base <= n + 1){
        base *= 2;
    }
    tree.resize(2 * base, {INF, 0});
    ll xd = -INF;
    rec(1, 0, base - 1, 0, 0, TYPE_ADD, xd);
    
    for(int i = 1; i <= n + 1; i++){
        for(pair<int, int> p : intervals[i - 1]){
            xd = p.second;
            rec(1, 0, base - 1, 0, p.first - 1, TYPE_ADD, xd);
        }
        ll best = INF;
        rec(1, 0, base - 1, 0, base - 1, TYPE_MIN, best);
        if(i == n + 1){
            answer = best;
        }
        xd = best - INF;
        rec(1, 0, base - 1, i, i, TYPE_ADD, xd);
    }
    cout << sum - answer << "\n";
    

}
*/


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

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> res;
  rep(k,n) {
    bool ope = false;
    int cnt = n-k;
    for (int i = n-1; i >= 0; --i) {
      if (a[i] == -1) continue;
      if (a[i] == cnt) {
        // debug(cnt, a[i]);
        ope = true;
        res.emplace_back(a[i]);
        a[i] = -1;
        break;
      } 
      cnt--;
    }
    if (!ope) {
      cout << -1 << endl;
      return 0;
    }
  }
  reverse(all(res));
  rep(i,n) cout << res[i] << "\n";
  return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    ll n ; 
    cin >> n ; 
    map<string,ll> mp ; 
    for(ll i=0;i<n;i++){
    	string x ; 
    	cin >> x ; 
    	sort(x.begin(),x.end()) ; 
    	mp[x]++ ; 
    }
    ll ans = 0 ; 
    for(auto &p : mp){
    	ll m = p.second - 1LL ;
    	ans += (m*(m+1LL))/2LL;
    }
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
#ifdef _WIN32
    #define gx getchar
    #define px putchar
    #define ps putchar(' ')
    #define pn putchar('\n')
    #define DEBUG 1
#else
    #define gx getchar_unlocked
    #define px putchar_unlocked
    #define ps putchar_unlocked(' ')
    #define pn putchar_unlocked('\n')
    #define DEBUG 0
#endif
 
#define rep(i,j,k) for(ll i=0;i<j;i+=k)
//input
void scan(int &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' ) sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * sign;
}
void lscan(ll &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' )
        sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * (ll)(sign);
}
int sscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
int wscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n' && c!=' ')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
 
//output
void print(int n)
{
    if(n<0)
    {
        n=-n;
        px('-');
    }
    int i=10;
    char o[10];
    do{o[--i] = (n%10) + '0'; n/=10;}while(n);
    do{px(o[i]);}while(++i<10);
}
void lprint(ll n)
{
    if(n<0LL)
    {
        n=-n;
        px('-');
    }
    int i=21;
    char o[21];
    do{o[--i] = (n%10LL) + '0'; n/=10LL;}while(n);
    do{px(o[i]);}while(++i<21);
}
void sprint(const char a[])
{
    const char *p=a;
    while(*p)px(*p++);
}
 
 
ll po(ll a, ll b, ll m)
{
	ll x=1,y=a;
	while(b > 0)
	{
		if(b%2 == 1)
		{
			x=(x*y);
			if(x>m) x%=m;
		}
		y = (y*y);
		if(y>m) y%=m;
		b /= 2;
	}
	return x;
}
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
	ll a,b;
	cin>>a>>b;
	cout<<a*b<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll gcd (ll a, ll b){
    if (b==0) return a;
    return gcd(b, a%b);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    ll ans;
        ll a,b;
        cin>>a>>b;
        ans=gcd(a,b);
    rep(i,2,N){
        ll x;
        cin>>x;
        ans=gcd(ans,x);
    }
    cout <<ans<<"\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 100000
#define NIL -1


struct node {
  int parent;
  int left;
  int right;
};

struct node T[MAX];
int n,D[MAX];
int setdepth(int ,int );

void printchildren(int);

int main(){

  int id,k,j,i,a,r,l;
 
  scanf("%d",&n); 
  for(i=0;i<n;i++){
    T[i].parent=NIL;
    T[i].left=NIL;
    T[i].right=NIL;
  }
  
  for(i=0;i<n;i++){
    l = 0;
    scanf("%d",&id);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&a);
      if(j==0) T[id].left=a;
      else T[l].right=a;
      l = a;
      T[a].parent=id;
    }

  }
  for(i=0;i<n;i++){
    if(T[i].parent == NIL) r = i;

  }
  setdepth(r,0);

  for(i=0;i<n;i++) printchildren(i);
  return 0;
}


int setdepth(int u,int p){

  D[u] = p;
  if(T[u].right != NIL){
    setdepth(T[u].right,p);
  }
  if(T[u].left != NIL){
    setdepth(T[u].left,p+1);
  }



  return p;
   }

void printchildren(int u){
  int c,i;

    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("depth = %d, ",D[u]);

    if(T[u].parent == NIL) printf("root, ");
    else if(T[u].left == NIL) printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    c=T[u].left;
    for(i=0;c!=NIL;i++){
      printf("%d",c);
      if(T[c].right!=NIL) printf(", ");
      c=T[c].right;
      
        
    }
    printf("]");
    printf("\n");
      
}





Measured memory_bytes: 6384
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int n[] = {1,  1,  1,  2,  1,  2,  1,  5,  2,  2,  1,  5,  1,  2,  1,  14,  1,  5,  1,  5,  2,  2,  1,  15,  2,  2,  5,  4,  1,  4,  1,  51};
  int K; cin >> K;
  cout << n[K-1] << endl;
}


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

using namespace std;

int f(int n){
    int ans = 0;
    while (n > 0){
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

int main(){
    int n;
    scanf("%d", &n);
    int ans = INT_MAX;
    for (int i = 1; i <= (n >> 1); i++){
        int cur = f(i) + f(n - i);
        ans = min(ans, cur);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
import math
import itertools
import statistics
#import numpy as np
import collections

#n = int(input())
n, l = list(map(int, input().split()))
#a = list(map(int, input().split()))
s = []
for i in range(n):
    s.append(input())

s.sort()

for i in range(n):
    print(s[i], end="")

Measured memory_bytes: 5648
#include<stdio.h>
#include<ctype.h>
int main() {
	int c,v=0,s=0;
	while(c=getchar(),c!=EOF){
		if(isdigit(c))
			v=v*10+c-'0';
		else {
			s+=v;
			v=0;
		}
	}
	printf("%d\n",s);
	return 0;
}

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


int main(){

int N;
cin >> N;

vector<int> t(110000), x(110000), y(110000);
for(int i=0; i<N; i++){
    cin >>t.at(i+1) >> x.at(i+1) >>y.at(i+1);
}

    bool flag = true;
for(int i = 0; i < N ;i++){
    int dt = t.at(i+1)-t.at(i);
    int dist = abs(x.at(i+1)-x.at(i))+abs(y.at(i+1)-y.at(i));
    if (dt < dist) flag =false;
    if (dt % 2 != dist % 2) flag = false;
}

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

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int ans = INT32_MAX, temp;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, C;
    cin >> N >> C;
    int D[C][C];
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            cin >> D[i][j];
        }
    }
    map<int, int> M[3];
    int c;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> c;
            M[(i+j)%3][c-1]++;
        }
    }
    int i[3];
    for (i[0] = 0; i[0] < C; i[0]++) for (i[1] = 0; i[1] < C; i[1]++) if (i[0] != i[1]) for (i[2] = 0; i[2] < C; i[2]++) if (i[0] != i[2] && i[1] != i[2]) {
        temp = 0;
        for (int l = 0; l < 3; l++) {
            for (auto &m : M[l]) {
                temp += D[m.first][i[l]]*m.second;
            }
        }
        ans = min(temp, ans);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int n,k[100005],sum=0;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>k[i];
    sum+=k[i];
  }
  if(sum%(((1+n)*n)/2)){
    cout<<"NO"<<endl;
    return 0;
  }
  int mon=sum/(((1+n)*n)/2);
  long long int mo[100005];
  for(int i=0;i<n;++i){
    if(i!=n-1) mo[i]=k[i+1]-k[i]-mon;
    else mo[i]=k[0]-k[i]-mon;
    
    if(mo[i]>0||mo[i]%n){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  
  cout<<"YES"<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el cout << "\n"
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);
ll n , m ,k;
ll nbr;

int main()
{
	IOS;
	ll x;
	cin >> x;
	ll sum=(x/500)*1000+((x%500)/5)*5;
	cout << sum;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;


int main() {
  int n, a[100100];
  cin >> n;
  int num_neg = 0;
  int i_min_abs = 0;
  int v_min_abs = 1000000001;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < 0) {
      num_neg++;
    }
    if (abs(a[i]) < v_min_abs) {
      i_min_abs = i;
      v_min_abs = abs(a[i]);
    }
  }

  long long ans = 0;
  for (int i = 0; i < n; i++) {
      ans += abs(a[i]);
  }

  if (num_neg % 2 != 0) {
    ans -= v_min_abs * 2;
  }

  cout << ans << endl;



}


Measured memory_bytes: 640
// Pollock's conjecture
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1167&lang=jp 

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int MAX = 1000010;

int t(int n) { return n*(n+1)*(n+2) / 6; }
int main() { 
    vector<int> dp(MAX, 0);
    vector<int> odd_dp(MAX, 0);
    dp[0] = 0;
    odd_dp[0] = 0;
    for (int n = 1; n <= MAX; ++n) {
        dp[n] = n;
        odd_dp[n] = n;
        for (int k = 1; t(k) <= n; ++k) {
            dp[n] = min(dp[n - t(k)] + 1, dp[n]); 
            if (t(k) % 2) {
                odd_dp[n] = min(odd_dp[n - t(k)] + 1, odd_dp[n]); 
            }
        }
    }
    
    int N;
    while (cin >>  N) {
        if (N == 0) break;
        cout << dp[N] << " " << odd_dp[N] << endl;
    }
    return 0;
}

Measured memory_bytes: 10520
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  string t;
  cin >> t;
  string s;
  reverse(all(t));
  int n = t.size();
  REP(i, n) {
    char c = 'P';
    if (i>0) c = s.back();
    if (t[i] != '?') s.push_back(t[i]);
    else {
      s.push_back('D');
    }
  }
  reverse(all(s));
  cout << s << endl;


  return 0;
}

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

int main()
{
    int n;
    cin>>n;
    
    long long int total=0;
    
    for(int i=1;i<=n;i++)
    {
        if(i%3==0 || i%5==0)
        {
            total=total;
        }
        else
        {
            total+=i;
        }
    }
    
    cout<<total;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};
int main()
{
  int n,k; cin >> n >> k;

  vector<int> cost;
  
  for (int i = 1; i <= n; ++i) {
    int x = n/i - n/(i+1);
    if(x == 0) {
      rep(j,n/i) cost.push_back(1);
      break;
    }
    else {
      cost.push_back(x);
    }
  }

  reverse(cost.begin(), cost.end());
  int m = cost.size();
  
  vector<vector<mint>> dp(k+1, vector<mint>(m));
  vector<vector<mint>> sum(2, vector<mint>(m+1));
  dp[0][0].x = 1;
  rep(i,m) sum[0][i+1] = sum[0][i] + dp[0][i];

  rep(i,k) {
    rep(j,m) {
      dp[i+1][j] = sum[0][m-j]*(mint)cost[j];
      sum[1][j+1] = sum[1][j] + dp[i+1][j];
    }
    sum[0] = sum[1];
  }
  
  mint res;
  rep(i,m) res += dp[k][i];
  cout << res.x << "\n";
  
  return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli cnt[4000];

void func(long long N, long long X, long long Y){

    REP(i,0,N){
        REP(j,i+1,N){
            lli l = min( {abs(j-i),abs(i-X)+abs(j-Y)+1LL,abs(i-Y)+abs(j-X)+1LL} );
            cnt[l]++;
        }
    }
    REP(i,1,N)cout<<cnt[i]<<endl;


}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    X--,Y--;
    func(N, X, Y);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int i,j;
double avg,sum2,n,sum,sum1;
double s[1001];
int main()
{

    while(cin>>n)
    {
        sum=sum1=sum2=avg=0;
        if(n==0)
            break;
        for(i=0; i<n; i++)
        {
            cin>>s[i];
            sum+=s[i];

        }
        avg=sum/n;
        for(i=0; i<n; i++)
        {
            sum1=abs(s[i]-avg);
            sum2+=sum1*sum1;
            s[i]=0;
        }
        cout<<fixed<<setprecision(8)<<sqrt(sum2/n)<<endl;

    }
    return 0;
}



Measured memory_bytes: 3292
n,k = map(int,input().split())
s = list(input())
LR = 0
RL = 0
RR = 0
LL = 0
for i in range(n-1):
  if s[i]=='L' and s[i+1]=='R':
    LR += 1
for i in range(n-1):
  if s[i]=='R' and s[i+1]=='L':
    RL += 1
for i in range(n-1):
  if s[i]=='R' and s[i+1]=='R':
    RR += 1
for i in range(n-1):
  if s[i]=='L' and s[i+1]=='L':
    LL += 1
ans = RR + LL
m = min(LR,RL)
M = max(LR,RL)
if k < m:
  ans += 2*k
else:
  ans += 2*m
  if k < M:
    ans += k-m
  else:
    ans += M-m
print(ans)


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

public class Main { // "Main" should be used for most online judges
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		if ((r * 100 + g * 10 + b) % 4 == 0)
			System.out.println("YES");
		else
			System.out.printf("NO");
	}
}

Measured memory_bytes: 22868
# -*- coding: utf-8 -*-
n = int(input())
vv = list(map(int, input().split()))
d1 = {}
d2 = {}

for i in range(n):
    v = vv[i]
    if i%2==0:
        if v not in d2:
            d2[v] = 0
        d2[v] += 1
    else:
        if v not in d1:
            d1[v] = 0
        d1[v] += 1

dl1 = sorted(list(d1.keys()), reverse=True, key=lambda k:d1[k])
dl2 = sorted(list(d2.keys()), reverse=True, key=lambda k:d2[k])
i1 = 0
i2 = 0

if len(dl1)==1 and len(dl2)==1:
    if dl1[0]==dl2[0]:
        print(n//2)
    else:
        print(0)
    exit()
elif len(dl1)==1:
    print(sum(sorted(d2.values(), reverse=True)[1:]))
    exit()
elif len(dl2)==1:
    print(sum(sorted(d1.values(), reverse=True)[1:]))
    exit()


if dl1[0]!=dl2[0]:
    res = 0
    res += sum(sorted(d1.values(), reverse=True)[1:])
    res += sum(sorted(d2.values(), reverse=True)[1:])
    print(res)
else:
    res1 = 0
    l = sorted(d1.values(), reverse=True)
    res1 += l[0]
    if len(l)>2:
        res1 += sum(l[2:])
    res1 += sum(sorted(d2.values(), reverse=True)[1:])

    res2 = 0
    l = sorted(d2.values(), reverse=True)
    res2 += l[0]
    if len(l)>2:
        res2 += sum(l[2:])
    res2 += sum(sorted(d1.values(), reverse=True)[1:])
    print(min(res1,res2))


Measured memory_bytes: 17632
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9+5;
const ll INF=1e18+5;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int h,w,q,x[90005]={},posx[90005]={},posy[90005]={},d,a[305][305]={},l,r;
  cin >> h >> w >> d;
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cin >> a[i][j];
      posy[a[i][j]]=i,posx[a[i][j]]=j;
    }
  }
  for(int i=d+1; i<=h*w; i++) {
    x[i]=x[i-d]+abs(posy[i]-posy[i-d])+abs(posx[i]-posx[i-d]);
  }
  cin >> q;
  while(q--) {
    cin >> l >> r;
    cout << x[r]-x[l] << "\n";
  }
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define mod 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

using namespace std;

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

int main() {
	int H, W;
	cin >> H >> W;
	char grid[2001][2001];
	int ans[2001][2001] = {};

	vector <queue<int>> q(2001);
	vector <queue<int>> r(2001);
	

	 rep(i, 0, H)rep(j, 0, W){
		cin >> grid[i][j];
		if (grid[i][j] == '#') {
			q[i].push(j);
			r[j].push(i);
		}
	}
	int m, u;

	rep(i, 0, H) {
		q[i].push(W);
	}
	rep(i, 0, W) {
		r[i].push(H);
	}

	 rep(i, 0, H) {
		m = -1; u = q[i].front(); q[i].pop();
		rep(j, 0, W) {
			if (u > j) {
				ans[i][j] += (u - m - 1);
			}
			else if (u == j) {
				m = u;
				u = q[i].front();
				q[i].pop();
			}
		}
	}

	

	rep(j, 0, W) {
		m = -1; u = r[j].front(); r[j].pop();
		rep(i, 0, H) {
			if (u > i) {
				ans[i][j] += (u - m - 1);
			}
			else if (u == i) {
				m = u;
				u = r[j].front();
				r[j].pop();
			}
		}

	}


	int maxa = 0;
	rep(i, 0, H)rep(j, 0, W) {
		maxa = max(maxa, ans[i][j]);
	}

	

	if(maxa!=0)cout << maxa-1;
	else cout << 0;
	
	return 0;
}

Measured memory_bytes: 55040
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String args[]) {

        int n = sc.nextInt();


        int count = 0;
        for (int i=105; i <= n; i += 2) {
            if (numOfDivisors(i) == 8)
                count++;
        }

        System.out.println(count);


    }

    private static int numOfDivisors(int n) {
        int c = 0;
        for (int i=1; i <= n; i++) {
            if (n % i == 0)
                c++;
        }
        return c;
    }

}


Measured memory_bytes: 22736
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
typedef long long LL;
typedef pair<int,int> pii;


void run_case() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " "<< x << " " << y;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(10);
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 256
N = int(input())

A = [0,0,0,0]
for _ in range(N):
  s = input()
  i=0
  if s=="AC": i=0
  if s=="WA": i=1
  if s=="TLE": i=2
  if s=="RE": i=3
  A[i] += 1

print( "AC x " + str(A[0]))
print( "WA x " + str(A[1]) )
print( "TLE x " + str(A[2]) )
print( "RE x " + str(A[3]) )



Measured memory_bytes: 9224
#include <iostream>
using namespace std;
int main(){
  long long N,ans = 0;
  cin >> N;
  for (int i = 1; i <= N; ++i)
  {
    if(i%3 != 0 && i%5 != 0){
      ans += i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<ll>East(n+1,0);
    vector<ll>West(n+1,0);
    for (int i=1; i<=n; i++){ //累積和を格納
        if (s[i-1] == 'E'){
            East[i] = East[i-1]+1;
            West[i] = West[i-1];
        }
        else{
            East[i] = East[i-1];
            West[i] = West[i-1]+1;
        }
    }
    // rep(i,n+1) cout << East[i] << ", " << West[i] << endl;
    ll ans = LLINF;
    for (int i=1; i<=n; i++){ //i番目の人がリーダー
        ll left_to_right = West[i-1];
        ll right_to_left = East[n] - East[i];
        ans = min(ans, left_to_right+right_to_left);
    }
    cout << ans << endl;
}

Measured memory_bytes: 8216
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long ll;

int main(){
  int n, m; cin >> n >> m;
  vector<bool> oneTo(200000, false);
  vector<bool> toLast(200000, false);
  bool isPossible = false;
  rep(i, 0, m){
    int a, b; cin >> a >> b;
    if(a == 1){
      oneTo[b-1] = true;
    }
    if(b == n){
      toLast[a-1] = true;
    }
  }

  rep(i, 1, n){
    if(isPossible)  break;
    if(oneTo[i] && toLast[i]){
      isPossible = true;
    }
  }

  if(isPossible)  cout << "POSSIBLE" << endl;
  else  cout << "IMPOSSIBLE" << endl;
  return 0;
}

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

ll X,Y;
int main(){
	cin>>X>>Y;
	ll cnt=0;
	while(X<=Y){
		X<<=1;
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    private static int fact(int n) { int ans=1; for(int i=2;i<=n;i++) ans*=i; return ans; }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int a[] = new int[5];
        for(int i=0;i<5;i++){
            a[i] = in.nextInt();
        }
        int k = in.nextInt();
        if(a[4]-a[0]<=k) out.println("Yay!");
        else out.println(":(");
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 21460
#include <cstdio>

int main(){
	int a[100001], n, k, max;
	while(scanf("%d %d", &n, &k), n || k){
		max = 0;
		for(int i = 0;i < n;i++)scanf("%d", &a[i]);
		for(int i = 0;i < k;i++)max += a[i];
		for(int i = 1;i < n-k+1;i++){
			int s = 0;
			for(int j = i;j < i+k;j++)s += a[j];
			if(s > max)max = s;
		}
		printf("%d\n", max);
		}
	return 0;
}

Measured memory_bytes: 2960
A2Z="abcdefghijklmnopqrstuvwxyz"

def affine(msg, a, b):
    offset = ord('a')
    x=[]
    for c in msg:
        if 'a'<=c<='z':
            try:
                c = A2Z[(A2Z.index(c)*a+b)%26]
            except:
                print c
        x.append(c)
    return "".join(x)

def rot(msg, a):
    a = a % 26
    L2 = A2Z[a:]+A2Z[:a]
    x = [L2[A2Z.index(c)] for c in msg]
    return "".join(x)

def checkkey(msg):
    c0=('t')
    for i in range(26):#[2,3,5,7,11,13,17,19,23]:
        x = affine(msg,i,0)
        if x[0]!=c0:
            a = (ord(c0)-ord(x[0]))%26
            x = rot(x,a)
        else:
            a = 0
        if x in['this','that']: return i,a
    return -1,-1

n = input()
for i in range(n):
    msg = raw_input()
    for word in msg.split():
        if len(word)==4:
            a,b = checkkey(word)
            if a!=-1: break
    print affine(msg,a,b)

Measured memory_bytes: 4284
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        int c = Integer.parseInt(scan.next());

        if (a < b && b < c)
            System.out.println("Yes");
        else
            System.out.println("No");

    }
}

Measured memory_bytes: 26152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string s;
	int B = 0;
	long long ans = 0;
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i] == 'W'){
            ans+=B;
        }else{
            B++;
        } 
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000 //1e16
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,s,sum=0,flag=0,count=0;
    string S,T,U; 
    int a,b,x,y,z,c;
    cin>>n>>a;
    while(n>0)
    {
        n-=a;
        count++;
    }
    cout<<count;
}

 

signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

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

int main() {
  int N, C, K;
  cin >> N >> C >> K;
  
  vector<int> T(N);
  for (int i = 0; i < N; ++i) cin >> T.at(i);
  sort(T.begin(), T.end());
  
  int count = 0;
  int i = 0;
  while (i < N) {
    ++count;
	int start = i;
    
    while (i < N && i - start < C && T.at(i) - T.at(start) <= K) ++i; 
  }
  cout << count << endl;
}

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

Measured memory_bytes: 6712
import java.io.BufferedReader;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int h, w;
	int n;
	int[][] map;
	int[][] walk;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			h = sc.nextInt();
			w = sc.nextInt();
			n = sc.nextInt();
			if( (h|w|n) == 0 ) break;
			map = new int[h][w];
			walk = new int[h+1][w+1];
			for(int i=0;i<h;i++) for(int j=0;j<w;j++){
				map[i][j] = Integer.parseInt(sc.next());
			}
			solve();
		}
	}
	
	void solve() {
		int px = 1, py = 1;
		walk[0][0] = n;
		for(int i=0;i<h;i++) for(int j=0;j<w;j++) {
			walk[i][j+1] += walk[i][j]/2 + (walk[i][j]%2) * map[i][j];
			walk[i+1][j] += walk[i][j]/2 + (walk[i][j]%2) * (1-map[i][j]);
			if( i+1==py && j+1==px ) {
				if((map[i][j]+walk[i][j])%2==0) { px++; }
				else          				  	{ py++; }
			}
			if( px == w+1 || py == h+1 ) {
				System.out.println((py) + " " + (px));
				return;
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

using namespace std;

#define N 100010
vector<int> g[N];
int res,n,dist[2][N],id;

void dfs(int v,int p=-1){
    if(p!=-1) dist[id][v]=dist[id][p]+1;
    for(int i=0;i<g[v].size();i++) if(g[v][i]!=p) dfs(g[v][i],v);
    return;
}

int main(){
	ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    id=0;dfs(0);
    id=1;dfs(n-1);
    for(int i=0;i<n;i++) if(dist[0][i]<=dist[1][i]) res++;
    if(res>=n/2+1) cout<<"Fennec";
    else cout<<"Snuke";
    return 0;
}

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int K, X;
  std::cin >> K >> X;

  if(500 * K >= X) {
    std::cout << "Yes" << '\n';
  } else {
    std::cout << "No" << '\n';
  }
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::vec::Vec;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        x: chars,
    }
    let mut length = x.len();
    let mut stack = Vec::new();
    for ch in x {
        if ch == 'T' && stack.last() == Some(&'S') {
            length -= 2;
            stack.pop();
        } else {
            stack.push(ch);
        }
    }
    println!("{}", length);
}


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

#define fi first
#define se second

typedef pair<int,int> pii;

pii dptab[32][32][32][32];
int sum[32][32];
int in[32][32];
int h, w, s;
int all;
int segmin;

pii solve(pii ul, pii br) {
	if(dptab[ul.fi][ul.se][br.fi-1][br.se-1].fi + 1)
		return dptab[ul.fi][ul.se][br.fi-1][br.se-1];

	int tmp = 0;
	if(br.fi > 0 && br.se > 0)
		tmp += sum[br.fi-1][br.se-1];
	if(ul.fi > 0 && br.se > 0)
		tmp -= sum[ul.fi-1][br.se-1];
	if(br.fi > 0 && ul.se > 0)
		tmp -= sum[br.fi-1][ul.se-1];
	if(ul.fi > 0 && ul.se > 0)
		tmp += sum[ul.fi-1][ul.se-1];

	if(tmp < segmin)
		return dptab[ul.fi][ul.se][br.fi-1][br.se-1] = pii(0,-1);

	pii nex = pii(1, tmp-segmin);
	pii res0, res1;
	for(int i = ul.fi+1; i < br.fi; i++) {
		res0 = solve(ul, pii(i, br.se));
		res1 = solve(pii(i, ul.se), br);

		if(res0.fi > 0 && res1.fi > 0) {
			if(res0.fi + res1.fi > nex.fi) {
				nex.fi = res0.fi + res1.fi;
				nex.se = min(res0.se, res1.se);
			}
			else if(res0.fi + res1.fi == nex.fi && min(res0.se, res1.se) > nex.se) {
				nex.se = min(res0.se, res1.se);
			}
		}
	}
	for(int i = ul.se+1; i < br.se; i++) {
		res0 = solve(ul, pii(br.fi, i));
		res1 = solve(pii(ul.fi, i), br);

		if(res0.fi > 0 && res1.fi > 0) {
			if(res0.fi + res1.fi > nex.fi) {
				nex.fi = res0.fi + res1.fi;
				nex.se = min(res0.se, res1.se);
			}
			else if(res0.fi + res1.fi == nex.fi && min(res0.se, res1.se) > nex.se) {
				nex.se = min(res0.se, res1.se);
			}
		}
	}
	return dptab[ul.fi][ul.se][br.fi-1][br.se-1] = nex;
}

int main() {
	while(cin >> h >> w >> s, h || w || s) {
		// init
		for(int i = 0; i < 32*32; i++) sum[0][i] = in[0][i] = 0;
		for(int i = 0; i < 1024*1024; i++) dptab[0][0][0][i] = pii(-1,-1);
		all = 0;
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				cin >> in[i][j];
				all += in[i][j];
			}
		}
		segmin = all-s;

		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				sum[i][j] = in[i][j];
				if(i-1 >= 0)
					sum[i][j] += sum[i-1][j];
				if(j-1 >= 0)
					sum[i][j] += sum[i][j-1];
				if(i-1 >= 0 && j-1 >= 0)
					sum[i][j] -= sum[i-1][j-1];
			}
		}

		pii res;
		res = solve(pii(0,0),pii(h,w));
		cout << res.fi << " " << res.se << endl;
	}
}

Measured memory_bytes: 9372
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;

#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

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

int main() {
  ll a;
  string s;
  cin >> a >> s;
  int b = (s[0] - '0') * 100 + (s[2] - '0') * 10 + s[3] - '0';
  cout << a * b / 100 << endl;
  return 0;
}


Measured memory_bytes: 3624
n,d,a = gets.split.map(&:to_i)
monsters = n.times.map{ gets.split.map(&:to_i) } 

monsters.map!{ |xh| xh[1] = (xh[1]+a-1)/a; xh }.sort_by!{ |x,h| x }

deq = []
acc_damage = 0
ans = 0
monsters.each do |x,h|
  
  while deq.size > 0 && deq[0][0] < x do
    acc_damage -= deq[0][1]
    deq.shift
  end
  
  need = h - acc_damage
  # need = 0 if need < 0
  
  if need > 0
    acc_damage += need
    ans += need
    deq.push( [x + d*2, need] )
  end
end

puts ans

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

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef long long ll;
vector<int> cunt(1000000,0);
bool getdiv(int n){
	if(n!=1 && cunt[1]>0||cunt[n]>1){
		return true;
	}
	int sum=0;
	for(int i=2;(long long)i*i<=n;i++){
		if(n%i==0){
			if(cunt[i]>0||cunt[n/i]>0){
				return true;
			}
		}

	}
	return false;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
// online submission
#endif
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		cunt[v[i]]++;
	}
	int coun=0;
	for(int i=0;i<n;i++){
		if(getdiv(v[i])) coun++;
	}
	cout<<n-coun;
}

Measured memory_bytes: 7904