akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ld long double

using namespace std;

const int N = 301;
long double dp[N][N][N];
long double n;

ld Count(int a, int b, int c)
{
    if(a == 0 && b == 0 && c == 0)
        return 0;

    if(dp[a][b][c]) return dp[a][b][c];
    dp[a][b][c] = n / (ld)(a + b + c);
    if(a > 0) dp[a][b][c] += Count(a - 1, b, c)*(ld)a/(ld)(a + b + c);
    if(b > 0) dp[a][b][c] += Count(a + 1, b - 1, c)*(ld)b/(ld)(a + b + c);
    if(c > 0) dp[a][b][c] += Count(a, b + 1, c - 1)*(ld)c/(ld)(a + b + c);
    return dp[a][b][c];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;

    int a = 0, b = 0, c = 0;

    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        if(x == 1) a++;
        if(x == 2) b++;
        if(x == 3) c++;
    }
    cout << fixed << setprecision(10) << Count(a, b, c);
}


Measured memory_bytes: 303104
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iomanip>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define RANGE(i,min,max) for(int i=(min), i##_len=((max)+1); i<i##_len; ++i)

constexpr int max_n = 1e5;
vector<pair<int, int> > wishlist(max_n);

void solve(int N, int M){
    sort(wishlist.rbegin(), wishlist.rend());
    int rFirst = N+1;
    int count = 0;
    REP(i, M) if(wishlist.at(i).second <=rFirst) count++, rFirst=wishlist.at(i).first;
    cout << count << endl;
}

int main(void){
    int N, M;
    cin >> N >> M;
    int i1, i2;
    
    wishlist.resize(M);
    for(auto& w: wishlist) cin >> w.first >> w.second;
    
    solve(N,M);
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = ((b-1) + (a-2)) / (a-1);
  cout << ans << '\n';
  return 0;
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) a.begin(), a.end()
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////
	
void solve() {	
	string a,b;
	cin >> a >> b;
	a += b;
	int n = atoi(a.c_str());
	for (int i = 1; i*i <= n; ++i) {
		if (i*i == n) {
			cout << "Yes";
			return;
		}
	}

	cout << "No\n";	
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
S=input()

ans=0
flag=False
if S[0]=='<':
  cnt1,cnt2=1,0
  for i in range(1,len(S)):
    if S[i-1]!=S[i]:
      if flag==False:
        flag=True
      else:
        flag=False
        if cnt1>cnt2:
          ans+=(cnt1*(cnt1+1)/2) + ((cnt2-1)*cnt2/2)
        else:
          ans+=((cnt1-1)*cnt1/2) + (cnt2*(cnt2+1)/2)
        cnt1,cnt2=0,0

    if S[i]=='<':
      cnt1+=1
    else:
      cnt2+=1
  if cnt1!=0 or cnt2!=0:
    if cnt1>cnt2:
      ans+=(cnt1*(cnt1+1)/2) + ((cnt2-1)*cnt2/2)
    else:
      ans+=((cnt1-1)*cnt1/2) + (cnt2*(cnt2+1)/2)
    print(int(ans))
  else:
    if S[-1]=='>':
      print(int(ans))
    else:
      print(int(ans)+1)
else:
  cnt1,cnt2=0,1
  for i in range(1,len(S)):
    if S[i-1]!=S[i]:
      if flag==True:
        flag=False
      else:
        flag=True
        if cnt1>cnt2:
          ans+=(cnt1*(cnt1+1)/2) + ((cnt2-1)*cnt2/2)
        else:
          ans+=((cnt1-1)*cnt1/2) + (cnt2*(cnt2+1)/2)
        cnt1,cnt2=0,0

    if S[i]=='<':
      cnt1+=1
    else:
      cnt2+=1
  if cnt1!=0 or cnt2!=0:
    if cnt1>cnt2:
      ans+=(cnt1*(cnt1+1)/2) + ((cnt2-1)*cnt2/2)
    else:
      ans+=((cnt1-1)*cnt1/2) + (cnt2*(cnt2+1)/2)
    print(int(ans))
  else:
    if S[-1]=='>':
      print(int(ans))
    else:
      print(int(ans)+1)

Measured memory_bytes: 4256
#include <stdio.h>

int main(){
  int h, w;
  while(1){
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0){break;}
        for(int i = 0; i < h; i++){
          for(int j = 0; j < w; j++){
                if((i + j) % 2 == 0){
                  printf("#");
                }else{
                  printf(".");
                }
          }
          printf("\n");
        }
        printf("\n");
  }
  return 0;
}


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

int main() {
  int N,X;
  cin>>N;
  
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin>>d.at(i);
  }
  sort(d.begin(),d.end());
  
  for(int i=0;i<N-1;i++){
    if(d.at(i)<d.at(i+1)){
      X++;
    }
  }
  cout<<X+1<<endl;
}

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

typedef long long ll;
typedef long long int lli;
const int MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < (n); i++)

using namespace std;

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

	int N,K,A=0; cin >> N>>K;
	vector<int> res(N);
	rep(i, N) { 
		cin >> res[i]; 
		if (res[i] >= K) { A++; }
	}
	cout << A << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, n) for (ll i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _per(i, n) peri(i, 0, n)
#define peri(i, a, n) for (ll i = (n) - 1; i >= (a); --i)
#define per(...) _overload3(__VA_ARGS__, peri, _per)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void chmax(T& a, const T& b) {if (a < b) a = b;}
template<typename T> inline void chmin(T& a, const T& b) {if (a > b) a = b;}
template<typename T> inline void print(const T& x) {cout << x << "\n";}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) {is >> p.fi >> p.se; return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {os << p.fi << " " << p.se; return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v) {each(in, v) is >> in; return is;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {rep(i, sz(v)) {os << v[i] << (i + 1 != sz(v) ? " " : "");} return os;}
struct Init {Init() {ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10);}} init;



int main() {
    ll n; cin >> n;
    if (n % 2 != 0) print(0);
    else {
        ll cnt = 0;
        ll d = 10;
        while (n >= d) {
            cnt += n / d;
            d = d * 5;
        }
        print(cnt);
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

int MOD_BIG = 1000000007;
int MOD_BIG2 = 998244353;
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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

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

int main() {
    
    int N;
    cin >> N;
    ll ans = 1;
    REP(i, N) {
        ll a;
        cin >> a;
        if (1000000000000000000 / ans < a) {
            ans = -1;
        } else {
            ans *= a;
        }
        if (a == 0) {
            ans = 0;
            break;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3636
n = gets.to_i
a = gets.split.map(&:to_i)
a << 0

have = 1000
now_day = 0
while now_day < n
  if a[now_day] <= a[now_day + 1]
    (now_day+1).upto(n-1) do |i|
      if a[i] > a[i+1]
        kabu = have / a[now_day]
        have -= a[now_day] * kabu
        have += a[i] * kabu
  
        now_day = i
        break
      end
    end
  end
  now_day += 1
end

puts have


Measured memory_bytes: 14260
#include <stdio.h>

int main()
{
	int A,B,C,max,mid,min,count,min2,mid2;
	
	scanf("%d %d %d", &A,&B,&C);
	count = 0;
	if(A>B)
	{
		if(C>A)
		{
			max = C; min = B; mid = A;
		}
		else
		{
			max = A;
			if(C>B){
				mid = C; min = B;
			}
			else {
				mid = B; min = C;
			}
		}
	}
	else
	{
		if(C>B)
		{
			max = C; min = A; mid = B; 
		}
		else
		{
			max = B;
			if(C>A) {
				mid = C; min = A;
			}
			else {
				mid = A; min = C;
			}
		}
	}
	
	count += (max-min)/2;
	count += (max-mid)/2;
	min2 = max - (max-min)%2;
	mid2 = max - (max-mid)%2;
	
	if(mid2 == min2 && mid2 == max)
	{
		count += 0;
	}
	else if(mid2 == min2)
	{
		count += 1;
	}
	else
	{
		count += 2;
	}
	
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 128
import math
import sys
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10 ** 9 + 7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

    
x, y = map(int, input().split())
if x  > 2 * y:
    print("0")
    sys.exit()
elif y  > 2 * x:
    print("0")
    sys.exit()
elif (x + y) % 3 != 0:
    print("0")
    sys.exit()


z = x + y
a = int(z / 3)
n = a
b = 2 * a
r = 0
ans = 1
while (True):
    if a == x and b == y:
        break
    a += 1
    b -= 1
    r += 1



print(cmb(n, r, mod))
        


        


    







        



Measured memory_bytes: 124588
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
int n;
vector <int> son[1000005];
char s[1000005];
void Solve() {
    s[n]='1';
    int nxt=0;
    for (int i=1;i<=n;i++) {
        if (s[i]=='1') {
            int wx=i-nxt-1;
            for (int j=0;j<=wx;j++) son[nxt+wx+1].push_back(nxt+j);
            nxt=i;
        }
    }
}
void Dfs(int n) {
    for (int i=0;i<(int)son[n].size();i++) {
        int kx=son[n][i];
        if (kx==0) continue;
        printf("%d %d\n",n,kx);
        Dfs(kx);
    }
}
int main() {
    scanf("%s",s+1);
    n=strlen(s+1);
    if (s[n]=='1'||s[1]=='0') {
        printf("-1\n");
        return 0;
    }
    for (int i=1;i<=n-1;i++)
        if (s[i]!=s[n-i]) {
            printf("-1\n");
            return 0;
        }
    Solve();
    Dfs(n);
    return 0;
}


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

const int N = 51;

typedef long long LL;

LL dp[N][N * N * N], sum[N];

int p[N], w[N], id[N]; LL pre[N], pre1[N];

int main() {
    int n, m, d; cin >> n >> m >> d;
    for (int i = 1; i <= n; i++) {
        cin >> sum[i], w[i] = 1, id[i] = i;
        if (i != 1) cin >> p[i];
    }
    for (int i = n; i >= 1; i--) 
        sum[p[i]] += sum[i], w[p[i]] += w[i];
    int lim = min(d, n);
    memset(dp, 0x3f, sizeof(dp)), dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= (i - 1) * lim * n; j++) if (dp[i - 1][j] <= m) {
            for (int k = 0; k <= lim; k++) {
                dp[i][j + k * w[i]] = min(dp[i][j + k * w[i]], dp[i - 1][j] + k * sum[i]);
                if (dp[i][j + k * w[i]] > m) break;
            }
        }
    }
    sort(id + 1, id + n + 1, [](int a, int b) {
        return w[a] * sum[b] > w[b] * sum[a];
    });
    for (int i = 1; i <= n; i++) {
        if (pre[i - 1] >= m) {
            pre[i] = pre[i - 1] + 1; continue;
        }
        int at = id[i], tmp = at == 1 ? 1e9 : d - lim;
        if (sum[at] >= m && tmp) pre[i] = m;
        else pre[i] = pre[i - 1] + tmp * sum[at], pre1[i] = pre1[i - 1] + (LL)tmp * w[at];
    }   
    LL res = 0;
    for (int i = 0; i <= n * n * lim; i++) if (dp[n][i] <= m) {
        LL remain = m - dp[n][i];
        int pos = upper_bound(pre + 1, pre + n + 1, remain) - pre - 1;
        res = max(res, i + pre1[pos] + w[id[pos + 1]] * ((remain - pre[pos]) / sum[id[pos + 1]]));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 53120
#include <bits/stdc++.h>
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define ld long double
#define el '\n'
#define PI (ld)3.14159265358979323846
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < int(n); i++)
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

/*vector<int> parent, rak;

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rank[a]+=rank[b];
    }
}*/

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

/*const int N = 1000001;
int lp[N+1];
vector<int> pr;
void s(){
for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}*/


ll kv;
ll t,n,x,y,h,k,z,p,q,w;

vector<vector<pll>>v,v1,v2;
//vector<ll>vis,d;
  

int main() {
    IOS;
    cin>>n;
    ll a[n],b[n+1],c[n+1];
    fo(i,n)cin>>a[i];
    b[0]=0;c[n]=0;
    fo(i,n)b[i+1]=__gcd(b[i],a[i]);
    fo(i,n)c[n-1-i]=__gcd(c[n-i],a[n-1-i]);
    fo(i,n)kv=max(kv,(ll)__gcd(b[i],c[i+1]));
    cout<<kv;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
  ll n,a[5],f[6]={},ans=0,ka[5],mn=1e16,k;
  cin>>n>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
  fr(i,5) mn=min(mn,a[i]);
  ans=5+(n-1)/mn;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
def to_m2(n):
    if n == 0:
        return "0"

    digits = []
    i = 0
    base = 1
    while n != 0:
        if n % (base * 2) == 0:
            digits.append("0")
        else:
            digits.append("1")
            n -= base
        i += 1
        base *= -2
    digits.reverse()
    return "".join(digits)


N = int(input())
print(to_m2(N))


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
 
typedef struct {
  char mark;
  int value;
} Card;
 
void BubbleSort(Card *, int);
void SelectionSort(Card *, int);
void print(Card *, int);
int isStable(Card *, Card *, int);
 
int main()
{
  Card c1[37], c2[37]; 
  int i, N;
   
  scanf("%d", &N);
 
  for( i = 0 ; i < N ; i++ ){
    scanf(" %c%d", &c1[i].mark, &c1[i].value);
  }
     
  for( i = 0 ; i < N ; i++ ) c2[i] = c1[i];
 
  BubbleSort(c1, N);  
  print(c1, N);
  printf("Stable\n");
 
  SelectionSort(c2, N);
  print(c2, N);
 
  if( isStable(c1, c2, N) == 0 ) printf("Stable\n");
  else printf("Not stable\n");
   
  return 0;
}
 
void BubbleSort(Card c1[], int N)
{
  int i, j;
  Card t;
   
  for( i = 0 ; i < N ; i++ ){
    for( j = N-1 ; j > i ; j-- ){
      if( c1[j].value < c1[j-1].value ){
	t = c1[j];
	c1[j] = c1[j-1];
	c1[j-1] = t;
      }
    }
  }
} 
 
void SelectionSort(Card c2[], int N)
{
  int i, j, minj;
  Card t;
 
  for( i = 0 ; i < N ; i++ ){
    minj = i;
    for( j = i ; j < N ; j++ ){
      if( c2[j].value < c2[minj].value ) minj = j;
    }
    t = c2[i];
    c2[i] = c2[minj];
    c2[minj] = t;
  }
}
     
void print(Card c[], int N)
{
  int i;
   
  for( i = 0 ; i < N ; i++ ){
    if( i > 0 ) printf(" ");
    printf("%c%d", c[i].mark, c[i].value);
  }
  printf("\n");
}
 
int isStable(Card c1[], Card c2[], int N)
{
  int i;
 
  for( i = 0 ; i < N ; i++ )
    if( c1[i].mark != c2[i].mark ) return 1;
   
  return 0;
}

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

#define STRING(str) #str

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

int main() {
	int N, Q;
	cin >> N >> Q;
	fenwick_tree<long long> fw(N);
	for (int i=0;i<N;i++) {
		long long a;
		cin >> a;
		fw.add(i, a);
	}
	for (int i=0;i<Q;i++) {
		int t;
		cin >> t;
		if (t == 0) {
			int p, x;
			cin >> p >> x;
			fw.add(p, x);
		} else { // t == 1
			int l, r;
			cin >> l >> r;
			cout << fw.sum(l, r) << endl;
		}
	}
}

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

const ll inf = 1e10;
ll n, m, q;

struct modv {
	vector<ll> v;
	ll inc(ll a = n - 1) {
		if (a == 0 && v[0] == m) {
			v[0] = -1;
			return v[0];
		}
		if (v[a] == m) {
			v[a] = inc(a - 1);
			return v[a];
		}
		else {
			++v[a];
			return v[a];
		}
	}
	modv() {
		v.resize(n, 1);
	}
};

int main() {
	cin >> n >> m >> q;
	vector<ll> a, b, c, d;
	for (ll i = 0; i < q; ++i) {
		ll A, B, C, D;
		cin >> A >> B >> C >> D;
		a.push_back(A - 1);
		b.push_back(B - 1);
		c.push_back(C);
		d.push_back(D);
	}
	modv m;
	ll ans = 0;
	while (m.v[0] != -1) {
		ll preans = 0;
		for (ll i = 0; i < q; ++i) {
			if (m.v[b[i]] - m.v[a[i]] == c[i])preans += d[i];
		}
		ans = max(ans, preans);
		m.inc();
	}
	cout << ans << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
 
ll f(ll x, ll c, ll d){
  return x-(x/c + x/d - x/lcm(c,d));
}
int main() {
 ll a,b,c,d;
 cin >> a >> b >> c >> d;
 cout << f(b,c,d) - f(a-1,c,d) << endl;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int A[N], max_A = 0, max_i = 0, next_A = 0;
  for (int i = 0; i < N; i++){
    cin >> A[i];
    if (A[i] > max_A){
      max_A = A[i];
      max_i = i;
    }
  }

  for (int i = 0; i < N; i++){
    if (A[i] > next_A && i != max_i){
      next_A = A[i];
    }
  }
  
  for (int i = 0; i < N; i++){
    if (i == max_i){
      printf("%d\n", next_A);
    }else{
      printf("%d\n", max_A);
    }
  }
  
  
}



Measured memory_bytes: 4496
N, M = map(int, input().split())
import math
def comb(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
CN, CM = 0, 0
if N >= 2:
  CN = comb(N, 2)
if M >= 2:
  CM = comb(M, 2)
print(CN + CM)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int
#define INF					1e5+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(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; }
template<class T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }

int main()
{
	int ans = 0;
	int n;
	cin >> n;
	vdef a(n, 0);
	vdef b(n, 0);
	for (int i = 0; i < n; ++i) cin >> a[i];

	b = a;
	sort(ALL(b));
	int max1 = b[n - 1];
	int max2 = b[n - 2];
	for (int i = 0; i < n; ++i)
	{
		if (a[i] != max1) cout << max1 << endl;
		else  cout << max2 << endl;
	}

	//cout << ans << endl;
	return 0;
}

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

using namespace std;

#define ll long long

ll sol(ll s1,ll h,ll w){
    ll s2,s3;

    if (h % 2 == 0 || w % 2 == 0){
        ll s = h * w;
        s2 = s3 = s / 2;
    }
    else {
        if (h < w){
            h ^= w;
            w ^= h;
            h ^= w;
        }
        s2 = (h / 2) * w;
        s3 = (h / 2 + 1) * w;
    }

    ll ans_temp1 = max({
        abs(s1 - s2),
        abs(s2 - s3),
        abs(s3 - s1)
    });

    if (h % 2 == 0 || w % 2 == 0){
        return ans_temp1;
    }

    s2 = (w / 2) * h;
    s3 = (w / 2 + 1) * h;

    ll ans_temp2 = max({
        abs(s1 - s2),
        abs(s2 - s3),
        abs(s3 - s1)
    });

    return min(ans_temp1,ans_temp2);
}

signed main(){
    ll h,w;
    cin >> h >> w;

    if (h % 3 == 0 || w % 3 == 0){
        cout << 0 << endl;
        return 0;
    }

    ll s1,s2,s3;
    if (h < w){
        h ^= w;
        w ^= h;
        h ^= w;
    }

    ll ans = sol(w * (h / 3), h - h / 3,w);
    ans = min(ans,sol(w * (h / 3 + 1),h - (h / 3 + 1),w));
    ans = min(ans,sol(h * (w / 3),w - (w / 3),h));
    ans = min(ans,sol(h * (w / 3 + 1),w - (w / 3 + 1),h));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int A =sc.nextInt();
    int B=sc.nextInt();
    int C =sc.nextInt();
    int D = B/A;
     int E = Math.min(C,D);
    System.out.println( E );
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a, b; cin >> a >> b;
  if (a>b) a--;
  COUT(a);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int mod=inf;

il void inc(int &x,const int &y){if((x+=y)>=mod) x-=mod;}

int f[2][20][1<<20];
int cons[21][21];
int n,m,k;

il int lowbit(const int &x){
	return x&-x;
}

il int newsta(const int &comb,const int &i){
	return comb^(1<<i)^lowbit((comb>>i)<<i);
}

int main(){
//	fileio("test");
	scanf("%d%d%d",&n,&m,&k),--n;
	memset(cons,-1,sizeof(cons));
	while(k--){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c),--b;
		cons[a][b]=c;
	}
	f[1][0][0]=1;
	rep(i,1,m){
		int c=i&1;
		memset(f[c^1],0,sizeof(f[c^1]));
		rep0(j,n-1) rep0(comb,1<<n){
			int &cur=f[c][j][comb];
			if(!cur) continue;
			if(comb>>j&1){
				if(cons[i][j]!=0) inc(f[c][j+1][comb],cur);
			}else{
				if(cons[i][j]!=1) inc(f[c][j+1][comb],cur);
				if(cons[i][j]!=0) inc(f[c][j+1][newsta(comb,j)],cur);
			}
		}
		int j=n-1;
		rep0(comb,1<<n){
			int &cur=f[c][j][comb];
			if(!cur) continue;
			if(comb>>j&1){
				if(cons[i][j]!=0) inc(f[c^1][0][comb],cur);
			}else{
				if(cons[i][j]!=1) inc(f[c^1][0][comb],cur);
				if(cons[i][j]!=0) inc(f[c^1][0][newsta(comb,j)],cur);
			}
		}
	}
	int c=m&1^1,ans=0;
	rep0(comb,1<<n) inc(ans,f[c][0][comb]);
	printf("%d\n",ans);
//	cerr<<(dbl)clock()/CLOCKS_PER_SEC<<endl;
	return 0;
} 

Measured memory_bytes: 164096
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

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

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	int n; cin>>n;
  vector<double> V;
  rep(i,n){
    double v; cin >> v;
    V.PB(v);
  }
  sort(RALL(V));
  rep(i,n-1){
    int ind = n-1-i;
    V[ind-1] = (V[ind]+V[ind-1])/2;
    V.pop_back();
  }
  cout << V[0] << endl;

}


Measured memory_bytes: 256
N, M = gets.split(' ').map(&:to_i)

cities = []
M.times do |i|
  p, y = gets.split(' ').map(&:to_i)
  cities.push([p, y, i])
end
cities.sort_by!{|city| city[1]}
code = Array.new(M)
pref = [1] * (N + 1)

cities.each do |city|
  p = city[0]
  x = pref[p]
  number = p.to_s.rjust(6, '0') + x.to_s.rjust(6, '0')
  code[city[2]] = number
  pref[p] += 1
end

puts code

Measured memory_bytes: 18120
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,s) for(int i=s;i>=0;--i)

using ll = long long;
using ull = unsigned long long;
using namespace std;

const ll INF = 1010101010;
const ll MOD = 1000000007;
ll n, m, ans = 0, A[10101];
int main() {
	cin >> n >> m;
	if (n % 2 == 0 || m % 2 == 0) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}


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

int main(){
  int n,W;
  cin>>n>>W;
  vector<ll> w(n),v(n);
  rep(i,n) cin>>w[i]>>v[i];
  
  ll dp[n+1][W+1];
  rep(i,n+1) rep(j,W+1) dp[i][j] = 0; 
  rep(i,n){
    for(int j = 1;j <= W;j++){
      if(j-w[i]<0) dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = max(dp[i][j],v[i]+dp[i][j-w[i]]);
    }
  }
  cout << dp[n][W] << endl;
}

Measured memory_bytes: 79104
#pragma comment(linker, "/STACK:10240000,10240000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
 
const int maxn = 2e5 + 7;
 
int n;
long long a[maxn], b[maxn];
 
void sort(long long *a, long long md) {
    int pos = n;
    for (int i = 0; i < n; i ++) {
        if (pos == n && a[i] >= md) pos = i;
        a[i] = a[i] & (md - 1);
    }
    inplace_merge(a, a + pos, a + n);
}
 
bool solve(long long limit) {
    long long ans = 0;
    int that = n - 1;
    for (int i = 0; i < n; i ++) {
        while (that >= 0 && a[i] + b[that] >= limit) that --;
        ans += n - 1 - that;
    }
    return ans & 1;
}
int main() {
#ifndef ONLINE_JUDGE
//    freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
    int T, cas = 0;
    {
        cin >> n;
        for (int i = 0; i < n; i ++) {
            scanf("%I64d", a + i);
        }
        for (int i = 0; i < n; i ++) {
            scanf("%I64d", b + i);
        }
        sort(a, a + n);
        sort(b, b + n);
        long long ans = 0;
        for (int i = 61; i >= 0; i --) {
            sort(a, (long long)2 << i);
            sort(b, (long long)2 << i);
            long long res =
                solve((long long)1 << i) ^
                solve((long long)2 << i) ^
                solve((long long)3 << i);
            ans |= res << i;
        }
        printf("%I64d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 4212
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

def main():
    A,B = map(int, readline().decode('utf-8').split())
    eight_start = int(-(-A//0.08))
    eight_end = int(-(-(A+1)//0.08))
    for i in range(eight_start,eight_end):
        ten = int(i * 0.1)
        if ten == B:
            print(i)
            break
    else:
        print('-1')

    return
if __name__ == '__main__':
    main()



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

queue<int> q;

void search(const vector< vector<int> >& v, vector<int>& d) {
    int i = q.front();
    q.pop();
    for (const auto& a : v[i]) {
        if (d[a] == -1) {
            d[a] = i;
            q.push(a);
        }
    }
}

int main() {
	ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector< vector<int> > v(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v[a - 1].push_back(b - 1);
        v[b - 1].push_back(a - 1);
    }

    vector<int> d(n, -1);
    d[0] = 0;
    q.push(0);
    while (!q.empty())
        search(v, d);

    cout << "Yes\n";
    for (int i = 1; i < n; i++) cout << d[i] + 1 << endl;
}

Measured memory_bytes: 10060
#include<stdio.h>

int funk(int);

int A[100][100],B[100],C[100];

int main() {
  int x,i,j;

  scanf("%d",&x);
  for(i = 0; i < x; i++) {
    for(j = 0; j < x; j++) {
      scanf("%d",&A[i][j]);
    }
  }

  printf("%d\n",funk(x));

  return 0;
}

int funk(int x) {
  int i,j,k = 1,min,minp,sum = 0;

  B[0] = 0;
  C[0] = 1;

  for(i = 1; i < x; i++) {
    C[i] = 0;
  }

  while(1) {
    min = 2001;
    for(i = 0; i < k; i++) {
      for( j = 0; j < x; j++) {
	if(A[B[i]][j] < min && A[B[i]] [j] != -1 && C[j] != 1) {
	  min = A[B[i]][j];
	  minp = j;
	}
      }
    }

    if(k == x) {
      break;
    }

    B[k] = minp;
    C[minp] = 1;
    sum += min;
    k++;
  }

  return sum;
}
	    
      



Measured memory_bytes: 2048
program main
	implicit none
	integer(8):: N,i,j,t,k
	character(200):: a, b, c
	read *, N
	read *, a,b
	do i=1,N*2
	if(mod(i,2)==1)then
	j=i/2+1
	 c(i:i)=a(j:j)
	 else 
	 j=i/2
	 c(i:i)=b(j:j)
	 end if
    end do
	print'(a)',c(1:N*2)
end program main

Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = 10**9 + 7
def nck(k):
    y, z = 1, 1
    for i in range(1, k+1):
        y = (y * (n+1-i)) % mod
        z = (z * pow(i, mod-2, mod)) % mod
    return (y*z) % mod
 
ans = (pow(2, n, mod) - 1 - nck(a) - nck(b)) % mod
print(ans)

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

int main(void)
{
	int i,x;
	int n;
	
	cin >> n;
	
	for(i = 3; i <= n; i++)
	{
		x = i;
		if(x % 3 == 0)
		{
			cout << " " << i;
		}
		else if(x % 10 == 3)
		{
			cout << " " << i;
		}
		else
		{
			while(x /= 10)
			{
				if(x % 10 == 3)
				{
					cout << " " << i;
					break;
				}
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>

using namespace std;

int f(int x) {
    int y = 0;

    while (x) {
        y += x % 10;
        x /= 10;
    }

    return y;
}

int main() {
    int n;
    cin >> n;
    int ans = n;

    for (int a = 1; a < n; a++) {
        int b = n - a;
        ans = min(f(a) + f(b), ans);
    }

    cout << ans << endl;
}


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

int main(){
    int N, K, ans =0, H, W;
    cin >> H >> W;
    vector<string> S(H);

    for(int i=0; i<H; i++){
	cin >> S[i];
    }
    for(int i=0; i<W+2; i++){
	cout << "#";
    }
    cout << endl;

    
    for(int i=0; i<H; i++){
	cout << "#" << S[i] << "#" << endl;
    }
    for(int i=0; i<W+2; i++){
	cout << "#";
    }
    cout <<endl;
}


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

typedef map<int, int> mii;
typedef long long ll;

mii gen(int x){
    map<int, int> res;
    for (int i = 2; i <= x; i++){
        if (x%i == 0){
            int c = 0;
            while (x%i == 0)x /= i, c++;
            res[i] = c;
        }
    }
    return res;
}

ll rev(mii x){
    ll res = 1;
    for (auto & p : x){
        ll a, b;
        tie(a, b) = p;
        assert(b >= 0);
        for (int i = 0; i < b; ++i) {
            res *= a;
        }
    }
    return res;
}

mii mul(mii a, mii b){
    for (auto & p : b){
        a[p.first] += p.second;
    }
    return a;
}

mii div(mii a, mii b){
    for (auto & p : b){
        a[p.first] -= p.second;
    }
    return a;
}

mii gcd(mii a, mii b){
    for (auto & p : b){
        a[p.first] = min(a[p.first], p.second);
    }
    return a;
}

mii lcm(mii a, mii b){
    for (auto & p : b){
        a[p.first] = max(a[p.first], p.second);
    }
    return a;
}

int main(int argc, char ** argv) {
    int n;
    while (cin >> n && n){
        mii d[20], v[20];
        mii l1;
        for (int i = 0; i < n; ++i) {
            ll dd, vv;
            cin >> dd >> vv;
            d[i] = gen(dd);
            v[i] = gen(vv);
            l1 = lcm(l1, v[i]);
        }
        mii l2;
        for (int i = 0; i < n; ++i) {
            l2 = lcm(l2, div(mul(d[i],l1) , v[i]));
        }
        for (int i = 0; i < n; ++i) {
            mii ans = div(mul(v[i], l2), mul(d[i], l1));
            cout << rev(ans) << endl;
        }
    }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct fenwick_tree{
	static const int DEFAULT = 200200;
	int size;
	vector<T> tree;
	fenwick_tree(int size = DEFAULT) : size(size) {
		clear();
	}
	void clear(){
		tree.assign(size, T(0));
	}
	void add(int pos, T v){
		for (; pos < size; pos += pos & -pos)
			tree[pos] = tree[pos] + v;
	}
	T sum(int pos){
		T r = T(0);
		for (; pos; pos -= pos & -pos)
			r = r + tree[pos];
		return r;
	}
	T query(int l, int r){
		return sum(r) - sum(l - 1);
	}
};
const int maxn = 100100;
int a[3][maxn], v[maxn], fp[maxn];
int main(){
	int n; cin >> n;
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < n; j++){
			cin >> a[i][j];
			a[i][j]--;
		}
	auto bad = [](){
		cout << "No" << endl;
		exit(0);
	};
	for(int i = 0; i < n; i++){
		if(a[0][i] == a[1][i] - 1 && a[1][i] == a[2][i] - 1){
			v[i] = a[0][i] / 3;
		} else if(a[0][i] == a[1][i] + 1 && a[1][i] == a[2][i] + 1){
			v[i] = a[2][i] / 3;
			fp[i] = 1;
		} else {
			bad();
		}
		if(v[i] % 2 != i % 2)
			bad();
	}
	int p[2][2] = {};
	for(int i = 0; i < 2; i++){
		fenwick_tree<long long> fenw;
		for(int j = i; j < n; j += 2){
			p[i][0] ^= (fenw.query(v[j] + 1, n) % 2);
			p[i][1] ^= fp[j];
			fenw.add(v[j] + 1, 1);
		}
	}
	if(p[0][1] == p[1][0] && p[0][0] == p[1][1]) cout << "Yes" << endl;
	else bad();
	return 0;
}


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

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

    rep(i, s.size()){
        if(s[i]=='?'){
            if(s[i-1]=='P') s[i]='D';
            else if(s[i+1]=='D' or s[i+1]=='?') s[i]='P';
            else s[i]='D';
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3708
//10:12-24+26+60
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<double,null_type,less_equal<double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
double a[50050],b[50050],c[50050],cut[50050],INF=-1e9;pair<double,int> pm[50050];int n,j;ll med;
void solve() {
    for (int i=0;i<n;i++) pm[i]=make_pair((double)(c[i]-(a[i]*INF))/b[i],i);
    sort(pm,pm+n);// for (int i=0;i<n;i++) cout<<fixed<<setprecision(6)<<pm[i].first<<" ! "<<pm[i].second<<endl;
    double lo=INF,hi=-lo,mid;int cnt=100;
    while (cnt--) {//cout<<fixed<<setprecision(12)<<lo<<" # "<<hi<<" ";
        mid=(lo+hi)*0.5; ordered_set aa; ll inv=0;
        for (int i=0;i<n;i++) j=pm[i].second,cut[j]=((double)(c[j]-(a[j]*mid))/b[j]);
        for (int i=n-1;i>=0;i--) j=pm[i].second,aa.insert(cut[j]),inv+=(aa.order_of_key(cut[j]));
        if (inv<med) lo=mid; else hi=mid;//cout<<inv<<"\n";
    }
    cout<<fixed<<setprecision(12)<<lo;
}
int main() {ios::sync_with_stdio(false);cin.tie(0);
    cin>>n; med=(n*(n-1))/2; med=(med+1)/2;
    for (int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
    solve(); swap(a,b); cout<<" "; solve();
}

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

#define rep(i,n) for(int i = 0;i < n;++i)
#define rep2(i,n,m) for(int i = n;i < m;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

P f(int x){
    int a = x % 10;
    int b = 0;
    while(x){
        b = x;
        x /= 10;
    }
    return P(a,b);
}

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

    int n,m;
    cin >> n >> m;
    vector<int> ans(n);
    vector<int> b(n);

    rep(i,m){
        int a;
        string s;
        cin >> a >> s;
        if(ans.at(a-1) == 1) continue;
        if(s == "AC"){
            ans.at(a-1) = 1;
            continue;
        }
        b.at(a-1)++;
    }
    int sum = 0,bb = 0;
    rep(i,n) sum += ans.at(i);
    rep(i,n){
        if(ans.at(i) == 1){
            bb += b.at(i);
        }
    }
    cout << sum << " " << bb << endl;

    cout << endl;
    return 0;
}

Measured memory_bytes: 1152
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        double r = in.nextDouble();
        out.println(2.0 * Math.PI * r);
        out.close();
    }
}

Measured memory_bytes: 28924
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 2020;
const int MOD = 924844033;
int dp[MAXN][MAXN][2];
int f[MAXN], t[MAXN], g[MAXN], fr[MAXN];
inline void chkMOD(int & x) {
	if (x >= MOD) x -= MOD;
	else if (x < 0) x += MOD;
}
inline void solve(int n, bool f1, bool f2) {
	rep (i, 0, n) {
		rep (j, 0, n) {
			dp[i][j][0] =
			dp[i][j][1] = 0;
		}
	}
	dp[0][0][f1] = 1;
	rep (i, 0, n - 1) rep (j, 0, n - 1) {
		rep (k, 0, 1) if (dp[i][j][k]) {
			if (k == 0) {
				chkMOD(dp[i + 1][j][0] += dp[i][j][k]);
				chkMOD(dp[i + 1][j + 1][0] += dp[i][j][k]);
				chkMOD(dp[i + 1][j + 1][1] += dp[i][j][k]);
			} else {
				chkMOD(dp[i + 1][j][0] += dp[i][j][k]);
				chkMOD(dp[i + 1][j + 1][1] += dp[i][j][k]);
			}
		}
	}
	rep (i, 0, n) {
		t[i] = dp[n][i][0];
		if (f2) chkMOD(t[i] += dp[n][i][1]);
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, K;
	cin >> n >> K;
	f[0] = 1;
	int cnt = 0;
	rep (i, 1, min(n, 2 * K)) {
		int tot = 1, now = i;
		while (now + 2 * K <= n) {
			now += 2 * K, ++tot;
		}
		solve(tot, i <= K, now + K <= n);
		rep (j, 0, cnt) g[j] = 0;
		per (j, cnt, 0) {
			rep (k, 0, tot) {
				chkMOD(g[j + k] += f[j] * 1ll * t[k] % MOD);
			}
		}
		cnt += tot;
		rep (j, 0, cnt) f[j] = g[j];
	}
	fr[0] = fr[1] = 1;
	rep (i, 2, n) {
		fr[i] = fr[i - 1] * 1ll * i % MOD;
	}
	int res = 0;
	rep (i, 0, n) {
		if (i & 1) {
			chkMOD(res -= f[i] * 1ll * fr[n - i] % MOD);
		} else {
			chkMOD(res += f[i] * 1ll * fr[n - i] % MOD);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 16128
using System;
using System.Linq;

namespace abc138_c
{
    static class Program
    {
        static void Main(string[] args)
        {
            // 具材の数
            var n = Console.ReadLine().ToInteger();
            // 具材の価値
            var v = Console.ReadLine().ToIntArray();

            // 1回目 (x + y) / 2 = x/2 + y/2
            // 2回目 ((x + y) / 2 + z) / 2 = x/4 + y/4 + z/2
            // 先に合成したものほど、価値が減っていく
            // つまり、小さいものから順に合成すればよい

            Array.Sort(v);

            var sum = (double)v[0];
            for (int i = 1; i < v.Length; i++)
            {
                sum = (sum + v[i]) / 2;
            }

            Console.WriteLine($"{sum}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static int[] ToIntArray(this string s, char separator = ' ')
        {
            return s.Split(separator).Select(m => m.ToInteger()).ToArray();
        }
    }
}


Measured memory_bytes: 13396
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

class Graph {
    int V;
    int[][] g, rg;
    this(int V) {
        g = new int[][V];
        rg = new int[][V];
        this.V = V;
    }
    void addEdge(int from, int to) {
        g[from] ~= to;
        rg[to] ~= from;
    }
    /* ???????£°?????????????????????????????§?????§??????????¬?????????????????????? */
    int[] scc() {
        auto used = new bool[V];
        int[] vs;
        void dfs1(int v) {
            used[v] = true;
            foreach (u; g[v]) {
                if (used[u]) continue;
                dfs1(u);
            }
            vs ~= v;
        }
        void dfs2(int v, int k, int[] order) {
            used[v] = true;
            order[v] = k;
            foreach (u; rg[v]) {
                if (used[u]) continue;
                dfs2(u, k, order);
            }
        }
        foreach (v; 0 .. V) {
            if (used[v]) continue;
            dfs1(v);
        }
        used[] = false;
        int k = 0;
        auto ord = new int[V]; ord[] = -1;
        foreach_reverse (v; vs) {
            if (used[v]) continue;
            dfs2(v, k++, ord);
        }
        return ord;
    }
}

void main() {
    int V, E; readf("%d %d\n", &V, &E);
    auto g = new Graph(V);
    foreach (i; 0 .. E) {
        int s, t; readf("%d %d\n", &s, &t);
        g.addEdge(s, t);
    }
    auto ord = g.scc();
    int Q; readf("%d\n", &Q);
    foreach (_; 0 .. Q) {
        int u, v; readf("%d %d\n", &u, &v);
        writeln(cast(int)(ord[u] == ord[v]));
    }
}

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

int main() {
	int N, ans = 0;
	cin >> N;
	vector<int> a(N);
	for (int& i : a) cin >> i;
	for (int i = 0; i < N; ++i) {
		if (1 + i == a[a[i] - 1]) ++ans;
	}
	cout << ans / 2;
}

Measured memory_bytes: 640
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define pf       push_front
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    string s;
    cin >> s;

    int q;
    cin >> q;

    deque<char> d;

    for(int i = 0; i < sz(s); i++) d.pb(s[i]);

    bool f = true;

    while(q--){

        int a;
        cin >> a;

        if(a == 1) f = !f;
        else{

            int c;
            cin >> c;

            char b;
            cin >> b;

            if(c == 1){
                if(f) d.pf(b);
                else d.pb(b);
            }
            else{
                if(f) d.pb(b);
                else d.pf(b);
            }
        }
    }

    if(f){
        while(!d.empty()){
            cout << d.front();
            d.pop_front();
        }
    }
    else{
        while(!d.empty()){
            cout << d.back();
            d.pop_back();
        }
    }
}


Measured memory_bytes: 4056