akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(a, b, c, d, e, f, D)
{
	double x, y;
	while( scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF ) {
		if( (D = a*e - b*d) != 0 ) {
			x = D>0 ?
				((double)(c*e - b*f)/abs(D)) : ((double)(b*f - c*e)/abs(D));
			y = D>0 ? 
				((double)(a*f - c*d)/abs(D)) : ((double)(c*d - a*f)/abs(D));
			printf("%.3lf %.3lf\n", x, y);
		}
	}
	return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
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 (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}

int main() {
    int w,h,n;
    cin >> w >> h >> n;
    vector<int> X(n);
    vector<int> Y(n);
    vector<int> A(n);
    rep(i, n) {
        cin >> X[i] >> Y[i] >> A[i];
    }
    vector<vector<int>> s(h,vector<int>(w,false));
    rep(i,n) {
        if (A[i]==1) {
            rep(j,h) {
                for(int k=0; k<X[i]; ++k) {
                    s[j][k] = true;
                }
            }
        }
        if (A[i]==2) {
            rep(j,h) {
                for(int k=X[i]; k<w; ++k) {
                    s[j][k] = true;
                }
            }
        }
        if (A[i]==3) {
            for(int j=h-Y[i]; j<h; ++j) {
                rep(k,w) {
                    s[j][k] = true;
                }
            }
        }
        if (A[i]==4) {
            for(int j=0; j<h-Y[i]; ++j) {
                rep(k,w) {
                    s[j][k] = true;
                }
            }
        }
    }
    int kuro = 0;
    rep(i,h) {
        rep(j,w) {
            if (s[i][j] == false) {
                kuro++;
            }
        }
    }
    cout << kuro << "\n";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 26;
string s, t;
vector<int> a[N];
long long pv = -1, ans[N], req, idx[N], n;
int main() {
	cin >> s >> t;

	for (auto c : t)
		if (s.find(c) == string::npos)
			return 0 * printf("-1");

	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a'].push_back(i);

	n = s.size();
	for (auto c : t) {
		int i = c - 'a';

		while (idx[i] < a[i].size() and pv >= a[i][idx[i]]) {
			idx[i]++;
		}

		if (idx[i] == a[i].size()) {
			req++;
			for (int i = 0; i < N; i++)
				idx[i] = 0;
		}

		ans[i] = 1ll * req * n + a[i][idx[i]];
		pv = a[i][idx[i]];
		idx[i]++;
	}

	cout << *max_element(ans, ans + N) + 1;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<std::string,std::string> P;

std::string substring(std::string s, int begin, int end){
    return s.substr(begin, end-begin);
}

P child(std::string tree){
    P res;
    int parLevel = 0;

    for(int i=1;i<tree.size()-1;i++){
        if(tree[i] == '('){
            parLevel++;
        }else if(tree[i] == ')'){
            parLevel--;
        }else if(tree[i] == ',' && !parLevel){
            res.first = substring(tree, 1, i);
            res.second = substring(tree, i+1, tree.size()-1);
        }
    }

    return res;
}

std::string Union(std::string a, std::string b){
    P a_child = child(a), b_child = child(b);
    std::string 
        al_child = a_child.first,
        ar_child = a_child.second,
        bl_child = b_child.first,
        br_child = b_child.second,
        l_child = "",
        r_child = "";

    // std::cout << boost::format("%1% %2%") % al_child % ar_child << std::endl;
    // std::cout << boost::format("%1% %2%") % bl_child % br_child << std::endl;
        
    if(al_child != "" && bl_child == ""){
        l_child = al_child;
    }else if(al_child == "" && bl_child != ""){
        l_child = bl_child;
    }else if(al_child != "" && bl_child != ""){
        l_child = Union(al_child, bl_child);
    }

    if(ar_child != "" && br_child == ""){
        r_child = ar_child;
    }else if(ar_child == "" && br_child != ""){
        r_child = br_child;
    }else if(ar_child != "" && br_child != ""){
        r_child = Union(ar_child, br_child);
    }

    // std::cout << "Result: " << "(" + l_child + "," + r_child + ")" << std::endl;
    return "(" + l_child + "," + r_child + ")";
}

std::string Intersection(std::string a, std::string b){
    P a_child = child(a), b_child = child(b);
    std::string 
        al_child = a_child.first,
        ar_child = a_child.second,
        bl_child = b_child.first,
        br_child = b_child.second,
        l_child = "",
        r_child = "";

    if(al_child != "" && bl_child != ""){
        l_child = Intersection(al_child, bl_child);
    }

    if(ar_child != "" && br_child != ""){
        r_child = Intersection(ar_child, br_child);
    }

    return "(" + l_child + "," + r_child + ")";
}

int main(){
    char c;
    std::string a, b;

    while(std::cin >> c >> a >> b, !std::cin.eof()){
        if(c == 'u'){
            std::cout << Union(a, b) << std::endl;
        }else if(c == 'i'){
            std::cout << Intersection(a, b) << std::endl;
        }
    }
}

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

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

	int N;
	scanf("%d", &N);

	int A;
	vector<int> C(N + 1);
	for (int i = 2; i <= N; i++) {
		scanf("%d", &A);
		C[A]++;
	}

	for (int i = 1; i <= N; i++) {
		printf("%d\n", C[i]);
	}

	return 0;
}

Measured memory_bytes: 4056
h, n = map(int, input().split())
a_list = []
b_list = []

for _ in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

max_a = max(a_list)    
dp = [float('inf')] * (h + max_a + 1)

dp[0] = 0
for i in range(h):
    for j in range(n):
        dp[i + a_list[j]] = min(dp[i] + b_list[j], dp[i + a_list[j]])
print(min(dp[h:]))

Measured memory_bytes: 42332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
   int n;
   cin >> n;
   int cnt = 0;
   int state = 0;
   rep(i,n){
       int a,b;
       cin >> a >> b;
       if(a == b) cnt++;
       else cnt = 0;
       if(cnt >= 3) state = 1;
   } 
   if (state) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void) {

	int n;
	scanf("%d",&n);

	int r[n];
	int i;

	for(i=0; i<n; i++) {
		scanf("%d",&r[i]);
	}

	int maxv = r[1]-r[0];
	int minv = r[0];
	
	//printf("%d",maxv);
	
	for(i=1; i<n; i++) {
		if(maxv < r[i]-minv) {
			maxv = r[i]-minv;
			
		}
		if(minv > r[i]){
			minv = r[i];
		}
	}
	
	printf("%d\n",maxv);

	return 0;

}


Measured memory_bytes: 2544
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int Q;
int findpos(int A, int B, int k)
{
	if (A==(B+1)*k) return B+1;
	ll l = 0, r = B;
	while (l<=r)
	{
		ll m = l+r>>1;
		if (A>=m*k&&(B-m)/k<=(A-m*k)) l = m+1;
		else r = m-1;
	}
	return r;
}
char ans[111];
void solve(int A, int B, int L, int R, bool rev)
{
	if (A<=0&&B<=0) return;
	if (A==B)
	{
		for (int i=max(1,L); i<=min(A+B,R); i++)
		{
			if (!rev) ans[i-L] = (i&1? 'A': 'B');
			else ans[(R-L)-(i-L)] = (i&1? 'B': 'A');
		}
		return;
	}
	if (A<B)
	{
		solve(B, A, A+B-R+1, A+B-L+1, rev^1);
		return;
	}
	else
	{
		int k = (B+A)/(B+1);
		int p = findpos(A, B, k);
		int p2 = (B-p)/k;
		for (int i=max(1,L); i<=min(A+B,R); i++)
		{
			char c;
			int pos = rev? (R-L)-(i-L): i-L;
			if (i<=p*(k+1))
			{
				if ((i-1)%(k+1)<k) c = 'A';
				else c = 'B';
			}
			else if (A+B-i<p2*(k+1))
			{
				if ((A+B-i)%(k+1)<k) c = 'B';
				else c = 'A';
			}
			else if (i>A+B-p2*(k+1)-(B-p)%k)
			{
				c = 'B';
			}
			else
			{
				c = 'A';
			}
			if (rev) c ^= 'A'^'B';
			ans[pos] = c;
		}
	}
}
int main()
{
	geti(Q);
	for (int i=1; i<=Q; i++)
	{
		int A, B, L, R;
		getii(A, B);
		getii(L, R);
		solve(A, B, L, R, 0);
		for (int j=0; j<=R-L; j++) putchar(ans[j]); puts("");
	}
	return 0;
}


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

#define in cin
#define out cout

#define REP(i,n) for(int i=0; i<n; i++)
#define REP2(i,s,e) for(int i=s; i<e; i++)
#define REPE(i,s,e) for(int i=s; i<=e; i++)
#define REPR(i,s,e) for(int i=s; i>=e; i--)

#define all(v) v.begin(), v.end()
#define pb push_back

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rd(n) scanf("%d", &n)

#define x first
#define y second
#define intINF 2147483647
#define llINF 9223372036854775807LL
#define MOD 1000000007

int h, w, n;
ll k;
int board[50][50];

int ask(int sx, int sy, int ex, int ey)
{
    out << "? ";
    out << sx << " ";
    out << sy << " ";
    out << ex << " ";
    out << ey << endl;

    int ret; in >> ret;
    return ret;
}

void fill(int sx, int sy, int ex, int ey)
{
    REPE(i, sx, ex) REPE(j, sy, ey) board[i][j] = 1;
}

void f(int sx, int sy, int ex, int ey, int bomb)
{
    int mx = (sx+ex+1)/2;
    int my = (sy+ey+1)/2;

    int bombLeft = bomb;

    int ans1 = ask(sx, sy, mx-1, my-1);
    int area1 = ((mx-1)-(sx)+1)*((my-1)-(sy)+1);
    if(ans1 == area1) fill(sx, sy, mx-1, my-1);
    else if(ans1 != 0)
    {
        f(sx, sy, mx-1, my-1, ans1);
    }

    bombLeft -= ans1;
    if(bombLeft == 0) return;

    int ans2 = ask(sx, my, mx-1, ey);
    int area2 = ((mx-1)-(sx)+1)*((ey)-(my)+1);
    if(ans2 == area2) fill(sx, my, mx-1, ey);
    else if(ans2 != 0 && bombLeft > 0)
    {
        f(sx, my, mx-1, ey, ans2);
    }

    bombLeft -= ans2;
    if(bombLeft == 0) return;

    int ans3 = ask(mx, sy, ex, my-1);
    int area3 = ((ex)-(mx)+1)*((my-1)-(sy)+1);
    if(ans3 == area3) fill(mx, sy, ex, my-1);
    else if(ans3 != 0 && bombLeft > 0)
    {
        f(mx, sy, ex, my-1, ans3);
    }

    bombLeft -= ans3;
    if(bombLeft == 0) return;

    int ans4 = ask(mx, my, ex, ey);
    int area4 = ((ex)-(mx)+1)*((ey)-(my)+1);
    if(ans4 == area4) fill(mx, my, ex, ey);
    else if(ans4 != 0 && bombLeft > 0)
    {
        f(mx, my, ex, ey, ans4);
        bombLeft -= ans4;
    }
}

int main()
{
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif

    in >> h >> w >> n >> k;
    f(0, 0, h-1, w-1, n);

    ll p2 = 1LL;
    ll res = 0;
    REP(i, h) REP(j, w)
    {
        res = (res + board[i][j] * p2) % k;
        p2 = (2LL * p2) % k;
    }

    out << "! " << res << "\n";

    return 0;
}


Measured memory_bytes: 724
#include <set>
#include <functional>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int &i : a) {
		cin >> i;
	}
	int k = 0, r1 = 0, r2 = 0;
	sort(begin(a), end(a), greater<int>());
	for (int i : a) {
		if (k % 2 == 0) {
			r1 += i;
		}
		else {
			r2 += i;
		}
		++k;
	}
	cout << r1 - r2;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a[3],tmp;
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    if(a[0]<a[1]){
        tmp = a[0];
        a[0] = a[1];
        a[1] = tmp;
    }
    if(a[1]<a[2]){
        tmp = a[1];
        a[1] = a[2];
        a[2] = tmp;
    }
    if(a[0]<a[1]){
        tmp = a[0];
        a[0] = a[1];
        a[1] = tmp;
    }
    printf("%d\n",10*a[0]+a[1]+a[2]);
    return 0;
}

Measured memory_bytes: 128
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Remainder Game
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int MAX_A = 50;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], bs[MAX_N];
bool es[MAX_A + 1][MAX_A + 1];
ll ebits[MAX_A + 1][MAX_A + 1];

/* subroutines */

bool check(int n, ll msk) {
  memset(es, false, sizeof(es));
  for (int i = 0; i <= MAX_A; i++) {
    es[i][i] = true;
    for (int j = 0; j < i; j++)
      if ((ebits[i][j] & msk) != 0LL) es[i][j] = true;
  }

  for (int k = 0; k <= MAX_A; k++)
    for (int i = 0; i <= MAX_A; i++)
      for (int j = 0; j <= MAX_A; j++)
	es[i][j] |= es[i][k] & es[k][j];

  for (int i = 0; i < n; i++)
    if (! es[as[i]][bs[i]]) return false;
  return true;
}

/* main */

int main() {
  ll msk = 0;
  for (int r = 1; r <= MAX_A; r++) {
    ll br = (1LL << r);
    msk |= br;
    for (int i = 0; i <= MAX_A; i++)
      ebits[i][i % r] |= br;
  }

  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", &as[i]);
  for (int i = 0; i < n; i++) scanf("%d", &bs[i]);

  if (! check(n, msk)) {
    puts("-1");
    return 0;
  }

  for (int r = MAX_A; r >= 1; r--) {
    ll br = (1LL << r);
    if (check(n, msk ^ br)) msk ^= br;
  }

  printf("%lld\n", msk);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int64_t A, B;
    int K; cin >> A >> B >> K;
    set<int> s;
    rep(i, 0, K) {
        if (A + i <= B) s.insert(A + i);
        if (B - i >= A) s.insert(B - i);
    }
    trav(n, s) cout << n << endl;
    return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 100010;

int N, S;
int X[MN];
ll P[MN], ans[MN];
vector<pair<pii, ll>> info;

void calc(int l, int r) //[l, r]
{
	if (S < X[l]) {
		for (int k = l; k <= r; ++k) {
			ans[k] = X[k] - S;
		}
	} else if (X[r] < S) {
		for (int k = l; k <= r; ++k) {
			ans[k] = S - X[k];
		}
	} else {
		if (P[l] >= P[r]) {
			info.eb(mp(l, r), X[r] - X[l]);
			P[l] += P[r];
			calc(l, r - 1);
		} else {
			info.eb(mp(r, l), X[r] - X[l]);
			P[r] += P[l];
			calc(l + 1, r);
		}
	}
}

int main() {
	cin >> N >> S;
	rep(i, N) cin >> X[i] >> P[i];

	calc(0, N-1);

	reverse(ALL(info));

	for (auto d : info) {
		ans[d.fi.se] = ans[d.fi.fi] + d.se;
	}

	cout << *max_element(ans, ans + N) << endl;

	return 0;
}

Measured memory_bytes: 10096
w, h, x, y, r = map(int, raw_input().split(' '))
if x+r < 0 or x+r > w or x-r < 0 or x-r > w or y+r < 0 or y+r > h or y-r < 0 or y-r > h:
    print "No"
else:
    print "Yes"

Measured memory_bytes: 6436
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    char a[100000+10];
    cin>>a;
    int len=strlen(a);
    int flag=0;
    for(int i=0;i<len;i++)
    {
        if(a[i]==a[i+1])
        {
            cout<<i+1<<" "<<i+2<<endl;
            flag=1;
            break;
        }
        if(a[i]==a[i+2])
        {
            cout<<i+1<<" "<<i+3<<endl;
            flag=1;
            break;
        }
    }
    if(flag==0)
        cout<<-1<<" "<<-1<<endl;
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;
const int maxn = 2e5 + 5;

int n;
int dp[maxn][2];
char s[maxn];

int main(){
	scanf("%s", s);
	n = strlen(s);
	FOR(i, 0, n)
		dp[i][0] = dp[i][1] = -INF;
	FOR(i, 0, n){
		if(s[i] == 'P' || s[i] == '?'){
			dp[i][0] = (i ? max(dp[i - 1][0], dp[i - 1][1]) : 0);
		}
		if(s[i] == 'D' || s[i] == '?'){
			dp[i][1] = (i ? max(dp[i - 1][0] + 2, dp[i - 1][1] + 1) : 1);
		}
	}
	for(int i = n - 1, j = (dp[n - 1][0] < dp[n - 1][1] ? 1 : 0); i >= 0; --i){
		if(!j){
			s[i] = 'P';
			if(dp[i][j] == dp[i - 1][0])
				j = 0;
			else
				j = 1;
		}
		else{
			s[i] = 'D';
			if(dp[i][j] == dp[i - 1][0] + 2)
				j = 0;
			else
				j = 1;
		}
	}
	printf("%s\n", s);
	return 0;
}


Measured memory_bytes: 5520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

    ll l = 0, r = n-1;
    ll ans = 0;
    while(l < r){
        while(l < n && s[l] == 'R'){
            l++;
        }
        while(0 <= r && s[r] == 'W'){
            r--;
        }
        if(l>r){
            break;
        }
        s[l] = 'R';
        s[r] = 'W';
        ans++;
    }

    cout << ans << endl;


}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";

        int const mod = 1e9 + 7;
        int dp[100009];
        int n,k;

        int power_mod(int a, int b, int mod)
        {
            a%=mod;
            int res = 1;
            while(b > 0)
            {
                if(b&1)
                    res = (res*a)%mod;
                a = (a * a)%mod;
                b/=2;
            }
            return res%mod;
        }
        int fun(int x)
        {
            if(x == k)
                return 1;
            else if(dp[x] != -1)
                return dp[x];
            else 
            {
                int ans = power_mod(k/x, n, mod);

                for(int i = 2*x; i <= k; i+=x)
                    ans = (ans - fun(i) + mod)%mod;
                return dp[x] = ans;
            }
        }

        int32_t main()
        {
            tani_nachi_ke  
            
            cin >> n >> k;
            int ans = 0;
            memset(dp, -1, sizeof(dp));
            for(int i = 1; i <= k; i++)
            {
                ans += (i*fun(i))%mod;
            }
            cout << ans%mod << endl;
            





           return 0;
        }
          

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int ct[10005];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    string s;
    cin >> s;
    if (k == 2){
        ll ans = 0;
        for (int i = 0; i < n; i++){
            if ((s[i]-'0') % 2 == 0) ans += i+1;
        }
        printf("%lld",ans);
        return 0;
    }
    if (k == 5){
        ll ans = 0;
        for (int i = 0; i < n; i++){
            if ((s[i]-'0') % 5 == 0) ans += i+1;
        }
        printf("%lld",ans);
        return 0;
    }
    ll cur = 0;
    ll mul = 1;
    ll ans = 0;
    ct[0] = 1;
    for (int i = n-1; i >= 0; i--){
        cur += (s[i]-'0')*mul;
        cur %= k;
        ans += ct[cur];
        ct[cur]++;
        mul = (mul*10)%k;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 644
class Beginner:
    def check_ten(self, N):
        if N >= 10:
            return True
        else:
            return False
    def calculate_rate(self, N, ten_or_not, open_rate):
        if ten_or_not:
            return open_rate
        else:
            return open_rate + 100*(10 -N)
if __name__ == "__main__":
    N, R = map(int, input().split())
    b = Beginner()
    result_1 = b.check_ten(N)
    result_2 = b.calculate_rate(N, result_1, R)
    print(str(result_2))



Measured memory_bytes: 38384
#include<stdio.h>

int main(){
    int i,j,a,n;
    
    scanf("%d",&a);
    
    for(i=1;i<=a;i++){
        n=i;
        if(n%3==0){ printf(" %d",i);
    }else{
        do{
            if(n%10==3){ printf(" %d",i);
            n=0;
        }
        n/=10;
        }while(n);
    }
    }
      printf("\n");
      return 0;
    }
    
   


Measured memory_bytes: 2044
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b = list(map(int, input().split()))
    for i in range(1, 2000):
        if int(i*0.08)==a and int(i*0.1)==b:
            print(i)
            exit()
    print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main(int argc, char const *argv[])
{
    ll n, x;
    cin >> n >> x;
    vector<ll> v(n);
    rep(i, n) { cin >> v[i]; }
    auto tmp = v;
    ll ans1 = 0, ans2 = 0;
    rep(i, 1, n)
    {
        if (v[i - 1] + v[i] > x)
        {
            ll diff = (v[i - 1] + v[i]) - x;
            ans1 += diff;
            v[i] = max(0ll, v[i] - diff);
        }
    }

    cout << ans1 << endl;

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n, cnt[N];

int main()
{
	scanf("%d", &n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		int x; scanf("%d", &x);
		cnt[x]++; sum += x;
	}
	int q; scanf("%d", &q);
	while (q--) {
		int b, c; scanf("%d%d", &b, &c);
		sum += (c-b) * cnt[b];
		cnt[c] += cnt[b];
		cnt[b] = 0;
		printf("%lld\n", sum);
	}
	return 0;
}

Measured memory_bytes: 4184
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long Pow(long x,long r){
	if(r == 0){
		return 1;
	}
	if(r % 2){
		return Pow(x,r-1) * x % mod;
	}
	else{
		long t = Pow(x,r/2);
		return t*t%mod;
	}
}
void Calc(){
	long H = rei();
	long W = rei();
	long K = rel();
	if(K-2 >= mod){
		cout << 0 << endl;
		return;
	}
	long ans = 1;
	for(int i=2;i<K;i++){
		ans *= (H*W-i);
		ans %= mod;
	}
	long c2 = 1;
	for(int i=1;i<=K-2;i++){
		c2 *= i;
		c2 %= mod;
	}
	ans *= Pow(c2,mod-2);
	ans %= mod;
	long c = 0;
	for(int i=1;i<H;i++){
		c += (H-i) * W * W % mod * i;
		c %= mod;
	}
	for(int i=1;i<W;i++){
		c += (W-i) * H * H % mod * i;
		c %= mod;
	}
	cout << ans * c % mod << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
using namespace std;

int main(){
  int n, q;
  cin >> n >> q;

  queue<string> name;
  queue<int> time;
  for(int i=0;i<n;i++){
    string nm;
    int tm;
    cin >> nm >> tm;
    name.push(nm);
    time.push(tm);
  }

  int total=0;
  while(! name.empty()){
    if(time.front()<=q){
      total += time.front();

      cout << name.front() << ' ' << total << endl;
      
      time.pop();
      name.pop();
    }else{
      total += q;
      time.push(time.front()-q);
      name.push(name.front());
      time.pop();
      name.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 5704
#include<stdio.h>

int data[100],size=0;
void push(int n){data[size++] = n;}
int pop(){return data[--size];}

int main(){
  char c;
  int num=-1;
  while(scanf("%c",&c) != EOF){
    if(c == ' '){
      if(num >= 0) push(num);
      num = -1;
    }
    
    if(c == '+') push(pop()+pop());
    if(c == '-'){
      int a = pop(), b = pop();
      push(b-a);
      // push(-(pop()-pop()));
    }
    if(c == '*') push(pop()*pop());
    if('0' <= c && c <= '9') num = (num<0?c-'0':10*num+c-'0');
  }
  printf("%d\n",pop());
  return 0;
}

Measured memory_bytes: 540
#include <stdio.h>
#include <string.h>
int main(void){
    char s[11];
    char t[11];
    char u[11];
    int a,b,i=0;
    
    scanf("%s",&s);
    scanf("%s",&t);
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%s",&u);
    
    if(strcmp(s,u)==0){
        printf("%d %d",a-1,b);
    }else{
        printf("%d %d",a,b-1);
    }

    
    return 0;
}


Measured memory_bytes: 128
from math import cos
from math import sqrt
from math import radians
A, B, H, M = map(int, input().split())
a = H*30+(M/60)*30
b = M*6
c = min(abs(a-b), abs(b-a))
if a == 0:
    a += 360
if b == 0:
    b += 360
c = min(c, abs(a-b), abs(b-a))
print(sqrt(A**2+B**2-2*A*B*cos(radians(c))))


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

int main() {
  int N, A;
  int dat = 0;
  cin >> N >> A;
  dat = N % 500;
  if(dat <= A)
  {
      cout << "Yes" << endl;
  }
  else
  {
     cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int res = b - a, res2 = d - c;
	int ans = min({ res,res2,abs(b-c),abs(a-d)});
	if (c >= b || a >= d)cout << 0 << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    private final static String NEG = "NO\n";

    private final static String AFF = "YES\n";

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in), 1024);
        int number = Integer.parseInt(br.readLine());
        int sides[] = new int[3];
        StringTokenizer tknz;
        StringBuilder builder = new StringBuilder();

        for (; 0 < number; number--) {
            tknz = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++) {
                sides[i] = Integer.parseInt(tknz.nextToken());
            }
            Arrays.sort(sides);
            if (sides[1] % 2 != 0) {
                builder.append(NEG);
            } else if (sides[0] * sides[1] * sides[2] % 60 != 0) {
                builder.append(NEG);
            } else if (Math.pow(sides[0], 2) + Math.pow(sides[1], 2) != Math
                    .pow(sides[2], 2)) {
                builder.append(NEG);
            } else {
                builder.append(AFF);
            }
        }
        System.out.print(builder);
    }
}

Measured memory_bytes: 18376
#include<bits/stdc++.h>
using namespace std;
char s[100001];//怕太大，放外面 
int main()
{
    int a,b,i;
    cin>>a>>b;
    for(i=1;i<=a+b+1;i++) 
	{
		cin>>s[i];//输入数组 
	}
    for(i=1;i<=a+b+1;i++)
    {
        if(s[i]<48&&i!=a+1||s[i]>58&&i!=a+1)//如果第A+1个字符不为字符'-' 输出"No" 
        {
            cout<<"No"<<endl;//输出no 
            return 0;//结束 
        }
        if(i==a+1&&s[i]!='-')//如果除了S的第A+1个字符，其他有一个或以上不为0~9  
        {
            cout<<"No"<<endl;//输出no 
            return 0; //结束 
        }
    }
    cout<<"Yes"<<endl;//如果S只有第A+1个字符并且以上为0~9并且如果第A+1个字符为字符'-'，输出yes 
	return 0;//结束 
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
 
using namespace std;
int main() {
    
    long long x;
    cin >> x;
    long long ans1=0;
    long long ans2=0;
    
    ans1= x/500;
    ans2= x%500/5;
    cout << ans1*1000+ans2*5 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#define rep(i,min,sup) for(int i=min;i<sup;i++)
#define per(i,min,sup) for(int i=(sup-1);i>=min;i--)
#define ll long long

using namespace std;
main(){
  int N,X,Y;
  scanf("%d %d %d",&N,&X,&Y);
  X--;Y--;
  int D[N][N];
  rep(i,0,N)rep(j,0,N){
    D[i][j]=abs(i-j);
  }
  int d;
  rep(i,0,N)rep(j,0,N){
    d=D[i][X]+1+D[Y][j];
    if(D[i][j]>d)D[i][j]=d;
    d=D[i][Y]+1+D[X][j];
    if(D[i][j]>d)D[i][j]=d;
  }
  int ans[N]={};
  rep(i,0,N)rep(j,i+1,N)ans[D[i][j]]++;  
  printf("%d",ans[1]);
  rep(i,2,N)printf("\n%d",ans[i]);
}

Measured memory_bytes: 15872
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder {
    class Program {
        static void Main() {
            long[] input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long n = input[0], k = input[1];
            int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var town = new List<int>();
            int[] first = new int[n];
            for(int i = 0; i < n; i++) first[i] = -1;
            int now = 0;
            town.Add(0);
            first[0] = 0;
            for(int i = 1; i <= k; i++) {
                now = a[now] - 1;
                if(first[now] != -1) {
                    var temp = town[first[now] + (int)((k - first[now]) % (i - first[now]))];
                    Console.WriteLine(temp + 1);
                    return;
                }
                town.Add(now);
                first[now] = i;
            }
            Console.WriteLine(now + 1);
        }
    }
}

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

const int N = 305;

int n;
int cnt[N];
double dp[N][N][N];

double solve(int ones, int twos, int threes) {
	if (ones == 0 && twos == 0 && threes == 0) {
		return 0;
	}
	double &res = dp[ones][twos][threes];
	if (res >= 0) {
		return res;
	}
	const double p_waste = (n - ones - twos - threes) * 1.0 / (n);
	res = 1 + (p_waste / (1 - p_waste));
	if (threes > 0) {
		const double choose = (threes) * 1.0 / (ones + twos + threes);
		res += choose * solve(ones, twos + 1, threes - 1);
	}
	if (twos > 0) {
		const double choose = (twos) * 1.0 / (ones + twos + threes);
		res += choose * solve(ones + 1, twos - 1, threes);
	}
	if (ones > 0) {
		const double choose = (ones) * 1.0 / (ones + twos + threes);
		res += choose * solve(ones - 1, twos, threes);
	}
	return res;
}

int main() {
    cout << fixed << setprecision(10);
   	cin >> n;
   	for (int i = 1; i <= n; i++) {
   		int x; cin >> x;
   		cnt[x]++;
   	}
   	memset(dp, -1, sizeof dp);
   	cout << solve(cnt[1], cnt[2], cnt[3]) << endl;
}

Measured memory_bytes: 221952
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int h, w, sxl, syl, sxr, syr, gxl, gyl, gxr, gyr;
char cl[55][55], cr[55][55];
bool used[55][55][55][55];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

bool in(int x, int y){
    return 0<=x && x<h && 0<=y && y<w;
}

bool gl(int xl, int yl){
    return xl == gxl && yl == gyl;
}

bool gr(int xr, int yr){
    return xr == gxr && yr == gyr;
}

void solve(){
    rep(xl, h)rep(yl, w)rep(xr, h)rep(yr, w) used[xl][yl][xr][yr] = false;
    queue<pair<pii, pii>> que;
    que.push({{sxl, syl}, {sxr, syr}});
    used[sxl][syl][sxr][syr] = true;
    while(!que.empty()){
        int xl, yl, xr, yr;
        tie(xl, yl) = que.front().fi;
        tie(xr, yr) = que.front().se;
        que.pop();
        rep(i, 4){
            int nxl = xl + dx[i], nyl = yl + dy[i];
            int nxr = xr + dx[i], nyr = yr - dy[i];
            if(!in(nxl, nyl) || cl[nxl][nyl] == '#'){
                nxl = xl; nyl = yl;
            }
            if(!in(nxr, nyr) || cr[nxr][nyr] == '#'){
                nxr = xr; nyr = yr;
            }
            if(!used[nxl][nyl][nxr][nyr]){
                if(gl(nxl, nyl) ^ gr(nxr, nyr)) continue;
                que.push({{nxl, nyl}, {nxr, nyr}});
                used[nxl][nyl][nxr][nyr] = true;
            }
        }
    }
    puts(used[gxl][gyl][gxr][gyr] ? "Yes" : "No");
}

int main(){
    while(scanf("%d%d", &w, &h) && h){
        rep(i, h){
            rep(j, w){
                scanf(" %c", &cl[i][j]);
                if(cl[i][j] == 'L') sxl = i, syl = j;
                if(cl[i][j] == '%') gxl = i, gyl = j;
            }
            rep(j, w){
                scanf(" %c", &cr[i][j]);
                if(cr[i][j] == 'R') sxr = i, syr = j;
                if(cr[i][j] == '%') gxr = i, gyr = j;
            }
        }
        solve();
    }
}


Measured memory_bytes: 11440
#include <iostream>
#include <string>
#include <vector>
#include <set>
using ll=long long;
using namespace std;

int main(){
    int N,a,ans;
    cin>>N;
    set<int> A;
    ans=0;
    for(int i=0;i<N;i++){
        cin>>a;
        if(A.find(a)!=A.end()){
            ans=1;
        }
        A.insert(a);
    }
    if(ans){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }

    return 0;
}

Measured memory_bytes: 12988
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int MOD = 1e+7;

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

  string s;
  cin >> s;
  cout << "2018/" << s.substr(5,5) << endl;
  return 0;
}

Measured memory_bytes: 256
"""
0, K, 2K, 3K, 4K, ... = N-1 のとき, 答え.
"""
def makediv(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

n = int(input())
ans = 0
themakedivlist = makediv(n-1)
for i in themakedivlist:
	if i >= 2:
		ans += 1
k = makediv(n)
k.remove(1)
for i in k:
	tmpn = n
	while True:
		if tmpn == 1:
			ans += 1
			break
		elif tmpn % i == 0:
			tmpn //= i
		elif (tmpn-1) % i == 0:
			ans += 1
			break
		else:
			break
print(ans)

Measured memory_bytes: 9168
def main():
    """
    1 <= N <= 1000
    0 <= M <= N
    - 10^10 <= xi,yi,zi <= 10^10
    """
    N, M = map(int, input().split())
    xyz = [
        list(map(int, input().split()))
        for _ in range(N)
    ]

    ans = editorial(N, M, xyz)
    print(ans)


def editorial(N, M, xyz):
    """
    1: max  sum(x)  +  sum(y)  +  sum(z)  (解説用)
    2: max |sum(x)| + |sum(y)| + |sum(z)| (本題)

    1 の場合:
        各ケーキについてスコアを算出し
        スコアが大きいM個を選ぶだけ

    2 の場合:
        |x| = max(x, -x)

          max(|x|, |y|)
        = max(max(x, -x), max(y, -y))
        = max(max(x, y), max(-x, -y))

        3要素について、「正の方向に最大化する」 「負の方向に最大化する」 のどちらを選ぶか、
        ということを考えると分かりやすいです。
        要素は 3 つあるので、2^3 = 8通り全探索します。

        1要素なら分かる
            なにもせずそのままで足す
            符号を反転してからで足す
                ※M個でなく、すべて足すなら反転してもしなくても同じ
        2要素以上
            1の場合(1要素ではなく)を想定しないと場合分けの想定できない
            それぞれの最大化の組合せ
    """
    max_scores = []
    for i in range(8):
        sign_x = 1 if (1 << 2) & i else -1
        sign_y = 1 if (1 << 1) & i else -1
        sign_z = 1 if (1 << 0) & i else -1

        scores = []
        for x, y, z in xyz:
            s = sum([x * sign_x, y * sign_y, z * sign_z])
            scores.append(s)

        max_s = sum(sorted(scores, reverse=True)[:M])
        max_scores.append(max_s)

    ans = max(max_scores)
    return ans


if __name__ == '__main__':
    main()


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

#define int             long long
#define	ll				long long

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

void sieve()
{
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;i++)
		prime[i]=1;

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

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

int lcm(int a, int b)
{
	return (a / gcd(a, b)) * b;
}

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

int sod(int n)
{
	int sum=0;
	while(n)
	{
		sum+=(n%10);
		n/=10;
	}
	return sum;
}



void solve()
{
  int a[5];
  for(int i =0;i<5;i++){
  	cin>>a[i];
  }
  for(int i =0;i<5;i++){
  	if(a[i]==0)
  	cout<<i+1;
  }
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

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

	ll N, M;
	cin >> N >> M;

	ll A, B;
	multiset<P> drink;
	rep(i, N) {
		cin >> A >> B;
		drink.emplace(A, B);
	}

	ll ans = 0;
	ll num = 0;
	auto itr = drink.begin();
	while(num<M) {
		if (itr->second > (M - num)) {
			ans += itr->first * (M - num);
			num = M;
		}
		else {
			ans += itr->first * itr->second;
			num += itr->second;
		}
		itr++;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

int K,X,Y;
void input()
{
    cin>>K;
    cin>>X>>Y;
}
void solve()
{

    // クリア可能な場合
    bool xrev = false, yrev = false, swapped=false;
    if (X<0){X*=-1;xrev=1;}
    if (Y<0){Y*=-1;yrev=1;}
    if (X<Y){swap(X,Y);swapped=1;} // X>Yにする
    // クリア可能かどうか
    if (K%2==0 and (X+Y)%2==1){
        // 不可能
        cout<<-1<<endl;
        return;
    }

    vector<pii> anss;
    int N = max((X+Y+K-1)/K , 2LL);
    if ((X+Y)%2 != N*K%2) N++; // 

    if (X+Y==K) anss.push_back(pii(X,Y));
    else if (N==3 && X<K) {
        int mid = (K+X-Y) / 2;
        anss.push_back(pii(X,X-K));
        anss.push_back(pii(X+mid, Y-K+mid));
        anss.push_back(pii(X,Y));
    }
    else {
        int over = (N*K-X-Y)/2;
        rep(i,1,N){
            int d = i*K; // 総移動距離
            if (d <= Y+over) anss.push_back(pii(0,d));
            else if (d <= Y + over + X) anss.push_back(pii(d-Y-over,Y+over));
            else anss.push_back(pii(X, Y+(N-i)*K));
        }
    }
    if (swapped) rep(i,0,anss.size()-1) swap(anss[i].first, anss[i].second);
    if (xrev) rep(i,0,anss.size()-1) anss[i].first*=-1;
    if (yrev) rep(i,0,anss.size()-1) anss[i].second*=-1;

    cout<<anss.size()<<endl;
    for(auto &x : anss){
        cout<<x.first<<" "<<x.second<<endl;;
    }

}
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 5484
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

ll a[200005];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin>>n;
  forn(i,0,n)
    cin>>a[i];
  ll mn=a[0],ans=1;
  forn(i,1,n){
    if(a[i] < mn){
      ans++;
      mn = min(mn,a[i]);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1920