akhauriyash/Code-Regression huggingface dataset:
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

    def f(self, p, q):
        return self.fact[p + q] * self.factInv[p] * self.factInv[q] % MOD


X, Y = map(int, input().split())
MOD = 10**9 + 7

if (X + Y) % 3 != 0:
    print(0)
    exit()

time = (X + Y) // 3
ans = 0
comb = Combination(time + 10)

for y in range(time + 1):
    x = time - y

    if X == x * 2 + y and Y == y * 2 + x:
        ans += comb.f(x, y)
        ans %= MOD

print(ans % MOD)


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

void solve() {
    ll K, N;
    cin >> K >> N;
    vector<ll> hs(N);
    for (int i = 0; i < N; ++i) {
        cin >> hs[i];
    }
    ll k_min = 100100100100;
    for (int i = 0; i < N; ++i) {
        // 時計まわり
        ll cl_i = (i + N - 1) % N;
        ll ad = K - hs[i];
        ll k_cl = 0;
        if (i < cl_i) {
            ll bd = K - hs[cl_i];
            k_cl = ad - bd;
        } else {
            k_cl = ad + hs[cl_i];
        }

        // 反時計まわり
        ll n_cli_i = (i + 1) % N;
        ll nk_cl = 0;
        if (i < n_cli_i) {
            nk_cl = hs[i] + K - hs[n_cli_i];
        } else {
            nk_cl = hs[i] - hs[n_cli_i];
        }

        k_min = min(k_min, min(k_cl, nk_cl));
    }
    cout << k_min << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long N=sc.nextLong(),K = sc.nextLong();
		long amari = N%K;
		if(amari!=0) {
			long ans = Long.min(amari, K-amari);
			System.out.println(ans);
		}else {
			System.out.println(0);
		}
	}

}

Measured memory_bytes: 21716
n,m = map(int,input().split())

a=  list(map(int,input().split()))

a = sorted(a)
a = a[::-1]

p = 1/(4*m)
s=  sum(a)
p = p*s

# print(a[m-1])
if( a[m-1] >= p ):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
//??¶?????????????????????????????§MinMax???????????\??????????????????, ????????????????????¶????????????????????§,
//??????????????¢?´¢??????, ????????¶????????´??°????????????
//????????¢?????¶???, Alice??????????????§???????????¶???????¢??????????????????????????????¢?????????????????§, 1-indexed??§????£??????????

#include <iostream>
#include <queue>
#include <tuple>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;

int h, w, r, c;
int horz[502][502];
int vert[502][502];
bool is_win[2][502][502];

bool input() {
	int i, j;
	
	cin >> h >> w >> r >> c; if (!h) return false;
	rep(i, h) {
		rep(j, w) cin >> horz[i + 1][j + 1];
		rep(j, w + 1) cin >> vert[i + 1][j + 1];
	}
	rep(j, w) cin >> horz[h + 1][j + 1];
	return true;
}

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

bool is_range(int r, int c) { return (1 <= r && r <= h && 1 <= c && c <= w); }
typedef tuple<int, int, int> T;

void bfs() {
	int i, j;
	static queue<T> que;
	
	rep(i, h + 2) rep(j, w + 2) { is_win[0][i][j] = true;  }
	rep(i, h) rep(j, w) { is_win[0][i + 1][j + 1] = false; }
	rep(i, h + 2) rep(j, w + 2) { is_win[1][i][j] = is_win[0][i][j]; if (is_win[0][i][j]) { que.push(T(0, i, j)); que.push(T(1, i, j)); } }
	
	while (!que.empty()) {
		T now = que.front(); que.pop();
		int flip = get<0>(now);
		int y = get<1>(now);
		int x = get<2>(now);
		
		if (!is_win[!flip][y][x]) continue;		//??????????????¶?????????????????´??????, ????????????????§?????????¨?????????
		
		for (i = 0; i < 4; i++) {
			if (!is_range(y + dy[i], x + dx[i])) continue;
			
			int next_flip;
			if (i == 0) next_flip = horz[y][x];
			if (i == 1) next_flip = vert[y][x+1];
			if (i == 2) next_flip = horz[y+1][x];
			if (i == 3) next_flip = vert[y][x];
			
			if (is_win[next_flip][y + dy[i]][x + dx[i]]) continue;	//?????????
			is_win[next_flip][y + dy[i]][x + dx[i]] = true;
			que.push(T(next_flip, y + dy[i], x + dx[i]));
		}
	}
}

int main() {
	while (input()) {
		bfs();
		cout << ((is_win[0][r][c]) ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 5596
import sys

sys.setrecursionlimit(10000000)
N,K = [int(v) for v in input().split()]
A = [int(v) for v in input().split()]

loop = []
pre = []
visited = set()

def dfs(index,now):
    global pre
    global loop
    loop.append(now)
    if now in visited:
        for left in range(len(loop)):
            if now == loop[left]:
                break
        pre = loop[:left]
        loop = loop[left:index]
        return
    else:
        visited.add(now)
        dfs(index+1,A[now-1])
dfs(0,1)

if len(pre) > K:
    print(pre[K])
else:
    K-=len(pre)
    print(loop[K%len(loop)])


Measured memory_bytes: 191740
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;
immutable long INF = 1L << 59;


void main() {
    auto C = 3.iota.map!(_ => readln.split.map!(to!int).array).array;
    auto A = new int[][](3, 2);
    auto B = new int[][](2, 3);
    foreach (i; 0..3) A[i][0] = C[i][1] - C[i][0], A[i][1] = C[i][2] - C[i][1];
    foreach (i; 0..3) B[0][i] = C[1][i] - C[0][i], B[1][i] = C[2][i] - C[1][i];
    bool ok = true;
    foreach (i; 0..2) foreach (j; 0..2) if (A[i][j] != A[i+1][j]) ok = false;
    foreach (i; 0..2) foreach (j; 0..2) if (B[i][j] != B[i][j+1]) ok = false;
    writeln(ok ? "Yes" : "No");
}


Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
P = sum(X)//len(X)
Q = P+1
ans_p = 0
ans_q = 0
for x in X:
  ans_p += (x-P)**2
  ans_q += (x-Q)**2
print(min(ans_p, ans_q))

Measured memory_bytes: 3060
text = input()
if text[1] == "S":
    if text[0] == "R" or text[2] == "R":
        print(1)
    else:
        print(0)
else:
    if text[0] == "R" and text[2] == "R":
        print(3)
    elif text[0] == "R" or text[2] == "R":
        print(2)
    else:
        print(1)



Measured memory_bytes: 9104
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
#include<unordered_set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

VI g[100010];
bool used[100010];
signed main(void)
{
	int n, m;
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].PB(b);
		g[b].PB(a);
	}
	deque<int> q{0, g[0][0]};
	int idx1 = 0, idx2 = g[0][0];
	used[0] = used[g[0][0]] = true;
	while(true) {
		//cout << "a:" << idx1 << " b:" << idx2 << endl;
		//REP(i, n) cout << (used[i]?"o ":"x "); cout << endl;
		//REP(i, q.size()) cout << q[i] << " "; cout << endl;
		bool flag = true;
		REP(i, g[idx1].size()) if(!used[g[idx1][i]]) {
			//cout << g[idx1][i] << endl;
			used[g[idx1][i]] = true;
			q.push_front(g[idx1][i]);
			idx1 = g[idx1][i];
			flag = false;
		}
		//cout << "c" << endl;
		if(!flag) continue;
		//cout << "d" << endl;
		REP(i, g[idx2].size()) if(!used[g[idx2][i]]) {
			//cout << g[idx2][i] << endl;
			used[g[idx2][i]] = true;
			q.push_back(g[idx2][i]);
			idx2 = g[idx2][i];
			flag = false;
		}
		//cout << "d" << endl;
		if(!flag) continue;
		//cout << "e" << endl;
		break;
	}
	cout << q.size() << endl;
	REP(i, q.size()) {
		cout << q[i]+1;
		if(i != q.size()-1) cout << " ";
	}

	return 0;
}


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

int main(){
    int n;
    ll x;
    cin >> n >> x;
    ll a[n];
    rep(i, n){
        cin >> a[i];
    }

    ll ans = 0;
    ll tmp;
    if(a[0]>x){
        tmp = a[0]-x;
        ans += tmp;
        a[0] -= tmp;
    }
    for (int i = 0; i < n-1; i++){
        tmp = a[i]+a[i+1] - x;
        if(tmp>0){
            a[i+1] -= tmp;
            ans += tmp;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
  int t;
  cin>>t;
  int cnt[4];
  cnt[0]=0;
  cnt[1]=0;
  cnt[2]=0;
  cnt[3]=0;
  while(t--)
  {
    string s;
    cin>>s;
    if(s=="AC")
      cnt[0]++;
    else if(s=="WA")
      cnt[1]++;
    else if(s=="TLE")
      cnt[2]++;
    else
      cnt[3]++;
  }
  cout<<"AC x "<<cnt[0]<<"\n";
  cout<<"WA x "<<cnt[1]<<"\n";
  cout<<"TLE x "<<cnt[2]<<"\n";
  cout<<"RE x "<<cnt[3]<<"\n";
  return 0;
}

Measured memory_bytes: 3224
#include<iostream>
#include<list>

using namespace std;

void print_list(list<int> l){
  cout << l.front();
  l.pop_front();
  int len = (int)l.size();
  for(int i = 0; i < len; i++){
    cout << " ";
    cout << l.front();
    l.pop_front();
  }
  
  cout << endl;

  return;
}

int main(){
  int n;
  while(cin >> n){
    list<int> l;
    int i;
    
    for(i = 0; i < n; i++){
      int tmp;
      cin >> tmp;

      if(i % 2 == 1) l.push_front(tmp);
      else l.push_back(tmp);
    }

    if(i % 2 == 1) l.reverse();    

    print_list(l);
  }

  return 0;
}


Measured memory_bytes: 14720
package main

import (
	"fmt"
)


func main() {
	var n int
	fmt.Scan(&n)
	values := ScanNums(n)
	costs := ScanNums(n)
	maxValue := 0
	for i := 0; i < n; i++ {
		if values[i] > costs[i] {
			maxValue += values[i] - costs[i]
		}
	}
	fmt.Println(maxValue)
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


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

int main(){
  int a,b,c,getC;
  int kekka = 0;
  
  cin >> a >> b >> c >> getC;
  
  if(a >= getC){
    kekka = getC;
  }else if(a+b >= getC){
    kekka = a;
  }else{
    kekka = a;
    getC = getC - (a+b);
    kekka += (getC*-1);
  }
  
  cout << kekka;
}

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

int main(){

  string mp;
  cin>>mp;
  
  int cnt=0;
  int stone=mp[0];
  for(int i=1;i<mp.size();i++){
    if(mp[i]!=stone) cnt++,stone=mp[i];
  }
  cout <<cnt<<endl;

  return 0;
}


Measured memory_bytes: 640
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    D, G = read_values()
    P = [0] * D
    C = [0] * D
    for i in range(D):
        P[i], C[i] = read_values()
        
    dp = [0] * (sum(P) + 1)
    for i in range(2 ** D):
        A = [0 if (i >> k) & 1 else P[k] - 1 for k in range(D)]
        r = sum(P[k] if (i >> k) & 1 else 0 for k in range(D))
        t = sum(C[k] + P[k] * (k + 1) * 100 if (i >> k) & 1 else 0 for k in range(D))
        dp[r] = max(dp[r], t)
        for j in range(D - 1, - 1, -1):
            for k in range(1, A[j] + 1):
                r += 1
                t += (j + 1) * 100
                dp[r] = max(dp[r], t)
    for i in range(len(dp) - 1):
        dp[i + 1] = max(dp[i +1], dp[i])
    # print(dp)
    print(bisect.bisect_left(dp, G))


if __name__ == "__main__":
    main()


Measured memory_bytes: 75652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int N;
	long long x;
	long long a[100000];
	
	scanf("%d %lld",&N,&x);
	for(int i=0;i<N;i++){
		scanf("%lld",&a[i]);
	}

	long long ans = 0;
	if(a[0]>x){
		ans += a[0] - x;
		a[0] -= ans;
	}
	for(int i=0;i<N-1;i++){
		if(a[i]+a[i+1]>x){
			long long tmp = a[i]+a[i+1]-x;
			ans += tmp;
			a[i+1] -= tmp;
		}
	}
	
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1024
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
f.sort()
a.sort(reverse=True)
x = 0
l = []
for i in range(n):
    l.append(a[i]*f[i])
m = max(l)
nibu = [0,m]
while nibu[0]+1 < nibu[1]:
    p = (nibu[0]+nibu[1])//2
    count = 0
    for i in range(n):
        if p < l[i]:
            count += (l[i]-p)//f[i]
            if (l[i]-p)%f[i] > 0:
                count += 1
    if count > k:
        nibu[0] = p
    else:
        nibu[1] = p
count = 0
p = nibu[0]
#print(a,f)
for i in range(n):
    if p < l[i]:
        count += (l[i]-p)//f[i]
        if (l[i]-p)%f[i] > 0:
            count += 1
    #print(count)
if count > k:
    print(nibu[1])
else:
    print(nibu[0])

Measured memory_bytes: 119500
N,M,Q = map(int,input().split())
Train = [list(map(int,input().split())) for i in range(M)]
Query = [list(map(int,input().split())) for i in range(Q)]

City = [[0]*N for i in range(N)]
Accum = [[0]*(N+1) for i in range(N+1)]

for train in Train:
  City[train[0]-1][train[1]-1] += 1

for i in range(N):
  for j in range(N):
    Accum[i+1][j+1] = Accum[i+1][j] + City[i][j]
for j in range(N):
  for i in range(N):
    Accum[i+1][j+1] += Accum[i][j+1]

for query in Query:
  print(
    Accum[query[1]][query[1]]
  - Accum[query[1]][query[0]-1]
  - Accum[query[0]-1][query[1]]
  + Accum[query[0]-1][query[0]-1]
    )

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

int main() {
    int n, sum1 = 0, sum2 = 0, sum;
    cin >> n;
    int c[n], v[n];

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

    for(int j = 0; j < n; j++)
        cin >> v[j];

    for(int k = 0; k < n; k++) {
        if(c[k] > v[k]) {
            sum1 += c[k];
            sum2 += v[k];
        }
    }
    sum = sum1 - sum2;
    cout << sum << endl;

}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  int n,m;
  cin >> n >> m;
  map<int,int> mp;
  FOR(i,0,m-1){
    int a,b;
    cin >> a >> b;
    ++mp[a];
    ++mp[b];
  }

  FOR(i,1,n){
    if(mp[i]%2!=0){
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
  return 0;



}



Measured memory_bytes: 4992
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <iomanip>
#include <unordered_map>
#include <bits/stdc++.h>

using namespace std;
int dp[3001][3001];
vector<int> v;
string s,t;
int lcs(int n,int m)
{
    if(n==0||m==0)
        return 0;
    if(dp[n][m]!=-1) return dp[n][m];
    if(s[n-1]==t[m-1]) return 1+lcs(n-1,m-1);
    dp[n][m]=max(lcs(n-1,m),lcs(n,m-1));
    return dp[n][m];
}

string record(int n,int m)
{
    if(n==0||m==0) return "";
    if(s[n-1]==t[m-1]) return s[n-1]+record(n-1,m-1);
    else
    {
        if(lcs(n,m-1)>lcs(n-1,m)) return record(n,m-1);
        else return record(n-1,m);
    }
}

int main()
{
    memset(dp,-1,sizeof dp);
    getline(cin,s);
    getline(cin,t);
    string ans=record(s.size(),t.size());
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}


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

int main() {
  int K, T;
  cin >> K >> T;
  vector<int> A(T);
  for (int i = 0; i < T; i++) cin >> A.at(i);
  
  int H = -1;
  for (int i = 0; i < T; i++) {
    if (A.at(i) > (K + 1) / 2) {
      H = A.at(i);
      break;
    }
  }
  
  if (H == -1) cout << 0 << endl;
  else cout << 2 * H - K - 1 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

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

	int x; cin >> x;
	cout << 1 - x << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  for(int i=n;i<1000;i++){
    if(i%111 == 0){
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
  
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc097b()
}

fun abc097b() {
    val x = readLine()!!.toInt()

    val answer = (1..32).map { n1 -> (2..10).map { n2 -> Math.pow(n1.toDouble(), n2.toDouble()).toLong() } }
        .flatten().sorted().findLast { it <= x }

    println(answer)
}


Measured memory_bytes: 36188
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;
#define out(i) cout<<(i)<<endl

int main() {
  ll K,N,sum=0;
  cin>>K>>N;
  vector<ll> data(N),d(N);
  rep0(i,N){cin>>data[i];}
  rep0(i,N){if(i<N-1){d[i]=data[i+1]-data[i];} else if(i==N-1){d[i]=K-data[i]+data[0];}}
  sort(all(d));
  d.pop_back();
  rep0(i,N-1){sum+=d[i];}
  out(sum);
}

Measured memory_bytes: 3328
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int r = sc.nextInt();
        int s = sc.nextInt();
        int p = sc.nextInt();
        String[] t = sc.next().split("");

        int[] expected = new int[n];
        int res = 0;
        for(int i=0;i<n;i++){
            if(t[i].equals("r")){
                expected[i] = p;
            }
            else if(t[i].equals("s")){
                expected[i] = r;
            }
            else if(t[i].equals("p")){
                expected[i] = s;
            }
            res += expected[i];
        }

        int minus = 0;
        for(int i=0;i<k;i++){
            int pre_point = -1;
            String pre_str = "";
            int cnt = 1;
            for(int j=0;i+j<n;j+=k){
                if(t[i+j].equals(pre_str)){
                    cnt++;
                }
                else{
                    if(cnt > 1){
                        minus += pre_point * ((int)cnt/2);
                    }
                    cnt = 1;
                }
                pre_point = expected[i+j];
                pre_str = t[i+j];
            }
            if(cnt > 1){
                minus += pre_point * ((int)cnt/2);
            }
        }
        System.out.println(res-minus);
    }
}


Measured memory_bytes: 33972
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  sort(a,a+n);
  int mx=a[n-1];
  int mn=mx/2;
  int mp[mn+1];
  //cout<<mx<<" "<<(mx+1)/2<<endl;
  rep(i,mn+1){
    mp[i]=-1;
  }
  if(mx%2==0){
    mp[mn]=0;
  }
  rep(i,n){
    if(a[i]<((mx+1)/2) || a[i]>mx){
      cout<<"Impossible"<<endl;
      return 0;
    }else{
      mp[mx-a[i]]++;
    }
  }
  rep(i,mn+1){
    if(mp[mn]!=1 || mp[i]<=0 ){
      cout<<"Impossible"<<endl;
      return 0;
    }
  }
  cout<<"Possible"<<endl;
  

  return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c, k = map(int, read().split())

cnt = 0

while b <= a:
    b *= 2
    cnt += 1

while c <= b:
    c *= 2
    cnt += 1

if cnt <= k:
    print("Yes")
else:
    print("No")


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

using namespace std;

int H, W;
int M[1000][1000];
int reach[1000][1000];
int x[1000000], y[1000000];
const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0};


int main()
{
  scanf("%d %d", &H, &W);
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      scanf("%d", &M[i][j]);
      --M[i][j];
      x[M[i][j]] = j;
      y[M[i][j]] = i;
    }
  }
  int ret = 0;
  for(int i = 0; i < H * W; i++) {
    int proc = i;
    for(int j = 0; j < 4; j++) {
      int nx = x[i] + vx[j], ny = y[i] + vy[j];
      if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
      if(M[ny][nx] < i) {
        if(proc == i) proc = reach[ny][nx];
        else if(proc != reach[ny][nx]) proc = -1;
      }
    }
    reach[y[i]][x[i]] = proc;
    ret += proc == -1;
  }

  printf("%d\n", ret);
}

Measured memory_bytes: 18832
#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;

int main()
{
	while (1) 
	{
		int a;
		cin >> a;
		if (a == 0)break;
		map<double, string>s;
		for (int p = 0; p < a; p++) {
			string b;
			cin>>b;
			int c = 0;
			for (int d = 0; d <(a-1); d++) {
				int e;
				cin >> e;
				if (e == 0)c -= 100;
				else if (e == 2)c--;
			}
			s.insert(pair<double, string>(c+p/(double)100, b));
		}
		for (auto q = s.begin(); q != s.end(); q++) {
			cout << q->second << endl;
		}
	}
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REPR(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define FOR(i, x, n) for (int i = x; i < (int)(n); ++i)
#define ALL(n) begin(n), end(n)
#define ll long long
#define INF 1e9
int main() {
    int n;
    cin >> n;
    if (n % 10 == 3)
        cout << "bon" << endl;
    else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
        cout << "pon" << endl;
    else
        cout << "hon" << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  string a,b; cin>>a>>b;
  if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 384
def check(i):
    global kmax,nmax
    cnt = 0
    for j in range(i):
        cnt += K[j]*B[j]
    if sum(B[:i])+(N-cnt)//K[i]<kmax:
        return
    for k in range((N-cnt)//K[i],-1,-1):
        if cnt+K[i]*k==N:
             if kmax<=sum(B[:i])+k:
                    kmax = sum(B[:i])+k
                    B[i] = k
                    num = ""
                    for j in range(len(K)):
                        num += str(D[j])*B[K.index(C[D[j]])]
                    num = int(num)
                    nmax = max(nmax,num)
        else:
            if i<len(K)-1:
                B[i] = k
                check(i+1)
            else:
                B[i] = 0
                return
C = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
N,M = map(int,input().split())
A = list(map(int,input().split()))
G = {}
for i in range(M):
    a = A[i]
    k = C[a]
    if k not in G:
        G[k] = 0
    if a>G[k]:
        G[k] = a
K = sorted(list(G.keys()))
D = sorted(list(G.values()),reverse=True)
B = [0 for _ in range(len(K))]
kmax = 0
nmax = 0
check(0)
print(nmax)

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

int main() {
	int L; cin >> L;
	int l[30], g[30], ToLast[30];
	int n=0, m=0;
	--L;
	while(L>0){
	    ToLast[n]=L%2;
	    l[n]=1-L%2;
	    g[n]=1+L/2;
	    L=(L+1)/2 - 1;
	    m += 3-ToLast[n];
	    ++n;
	}
	cout << n+1 << ' ' << m << endl;
	for(int i=0; i<n; ++i){
	    cout << i+1 << ' ' << i+2 << ' ' << l[i] << endl;
	    cout << i+1 << ' ' << i+2 << ' ' << g[i] << endl;
	    if(ToLast[i]==0) cout << i+1 << ' ' << n+1 << ' ' << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var accumOdd = new long[n + 1];
        var accumEven = new long[n + 1];
        for (int i = 0; i < n; i++)
        {
            if (i % 2 == 0)
            {
                accumEven[i + 1] = accumEven[i] + a[i];
                accumOdd[i + 1] = accumOdd[i];
            }
            else
            {
                accumEven[i + 1] = accumEven[i];
                accumOdd[i + 1] = accumOdd[i] + a[i];
            }
        }
        if (n % 2 == 0)
        {
            var res = Max(accumOdd.Last(), accumEven.Last());
            var sum = 0L;
            for (int i = accumEven.Length - 3; i >= 0; i -= 2)
            {
                sum += a[i + 1];
                res = Max(res, accumEven[i] + sum);
            }
            Console.WriteLine(res);
            return;
        }
        else
        {
            var sum = 0L;
            for (int i = 0; i < a.Length - 1; i += 2) sum += a[i];
            var res = sum;
            var tailDiff = 0L;
            var tailDiffMax = 0L;
            for (int i = a.Length - 3; i >= 0; i -= 2)
            {
                sum -= a[i]; sum += a[i + 1];
                tailDiff += a[i + 2]; tailDiff -= a[i + 1];
                tailDiffMax = Max(tailDiffMax, tailDiff);
                res = Max(res, sum + tailDiffMax);
            }
            Console.WriteLine(res);
            return;
        }
    }
}


Measured memory_bytes: 50140
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#define SIZE 10
using namespace std;

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

	int N;
	int i,j;
	double tmp;
	double sum;
	vector<string> given;
	
	cin >> N;

	for(i=0;i<N;i++){
		cin >> tmp;
		sum+=(1/tmp);
	}
	
	printf("%.8f",(1/sum));

	return 0;
}



Measured memory_bytes: 256
//AtCoder Beginner Contest 174
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e9 + 50;
const ll N1 = 2e5 + 50;
const double E = 1e-9;

//------------------------------------------------------------------------------
ll a[N1], n, k;;
bool check(int x)
{
	int res = 0;
	for (ll i = 0; i < n; i++)
		res += (a[i] + x - 1) / x - 1;
	return (res <= k);
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*ifstream cin("input.txt");
	ofstream cout("output.txt");*/
	cin >> n >> k;
	for (ll i = 0; i < n; i++)
		cin >> a[i];
	ll l = 1, r = N;
	while (l < r)
	{
		int mid = (l + r) / 2;
		if (check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << (check(l) ? l : r);
	return 0;
}
//02-08-2020 20:52:49
//------------------------------------------------------------------------------

Measured memory_bytes: 5152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int A1 = sc.nextInt();
	    int A2 = sc.nextInt();
	    int A3 = sc.nextInt();
	    
	    if (A1 + A2 + A3 <= 21) {
	    	System.out.println("win");
	    } else {
	    	System.out.println("bust");
	    }
	}	
}	

Measured memory_bytes: 20948
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long c = sc.nextLong();
        long[] xArr = new long[n];
        long[] vArr = new long[n];

        for(int i = 0; i < n; i++) {
        	xArr[i] = sc.nextLong();
        	vArr[i] = sc.nextLong();
        }

        long[] left = new long[n+1];
        long[] leftBack = new long[n+1];
        long aSumValue = 0;
        for(int i = 1; i < n+1; i++) {
        	left[i] = Math.max(left[i-1], aSumValue + vArr[i-1] - xArr[i-1]);
        	leftBack[i] = Math.max(leftBack[i-1], aSumValue + vArr[i-1] - xArr[i-1] * 2);
        	aSumValue += vArr[i-1];
        }

        long[] right = new long[n+1];
        long[] rightBack = new long[n+1];
        long bSumValue = 0;
        for(int i = 1; i < n+1; i++) {
        	int idx = n - i;
        	right[i] = Math.max(right[i-1], bSumValue + vArr[idx] - (c - xArr[idx]));
        	rightBack[i] = Math.max(rightBack[i-1], bSumValue + vArr[idx] - (c - xArr[idx]) * 2);
        	bSumValue += vArr[idx];
        }

        long max = 0;
        for(int i = 0; i < n+1; i++) {
        	max = Math.max(max, Math.max(left[i] + rightBack[n-i], right[n-i] + leftBack[i]));
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 92244
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>

using namespace std;
void print(vector<int> a);

int main(){
    int n; cin >> n;
    vector<int> a(n); for (int i=0;i<n;i++) cin >> a[i];
    for (int i = 0;i<n;i++){
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        print(a);
    }

    return 0;
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

//Sum accumulate(v.begin(),v.end(),0);
//Sort sort(v.begin(),v.end())
//Power pow(base, e)
//Min min = *std::min_element(vec.begin(), vec.end());
//Max max = *std::max_element(vec.begin(), vec.end());



Measured memory_bytes: 3160
/*
author: Apoorv Singh
*/

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

typedef vector <int> vi;
typedef vector <long long> vl;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
#define ll long long
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second

ll modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i;
    cin >> n >> i;
    cout << n-i+1;
    return 0;
}

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

int N, M;
vector<int> point;
vector<int> sel_two;

int find_max_under(int n) {
	int ub = sel_two.size()-1;
	int lb = 0;
	int mid = (lb + ub) / 2;

	while (!(lb == ub-1)) {
		mid = (lb + ub) / 2;
		if (sel_two[mid] < n) {
			lb = mid;
		} else if (sel_two[mid] > n) {
			ub = mid;
		} else {
			return n;
		}
	}
	return sel_two[lb];
}

int main() {
	while (cin >> N >> M, N || M) {
		point.clear(); point.resize(N+1);
		sel_two.clear();
		point[0] = 0;
		for (int i = 1; i <= N; i++) cin >> point[i];
		
		int max_point = 0;
		for (int i = 0; i <= N; i++) 
			for (int j = 0; j <= N; j++) 
				if (point[i] + point[j] <= M) sel_two.push_back(point[i] + point[j]);
		sort(sel_two.begin(), sel_two.end());
		for (int i = 0; i < sel_two.size(); i++) {
			int max_under = find_max_under(M - sel_two[i]);
			max_point = max(sel_two[i] + max_under, max_point);
		}
//		for (int i = 0; i < sel_two.size(); i++) cout << sel_two[i] << ' ';
//		cout << endl;

		cout << max_point << endl;
	}
	return 0;
}

Measured memory_bytes: 4952
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define rep(i, b) for( int i = 0; i < b; i++ )
#define m_t 60
#define max (3*m_t*(m_t+1)+1)
#define zero (max/2)
#define mp make_pair

int dx[6] = {0,1,-1,1,-1,0};
int dy[6] = {1,1,0,0,-1,-1};
vector<int> field(max);
int t, n;
int cnt;

int main(){
    while( cin >> t >> n, t ){
        fill( field.begin(), field.end(), 1 );  // reset
        int x, y;
        /* input of obstacle */
        rep(i, n){
            cin >> x >> y;
            y = y * (m_t*2 + m_t*2+1-abs(y)) / 2;
            field[zero+x+y] = 0;
        }
        int sx, sy;
        /* input of the starting point */
        cin >> sx >> sy;
        x = sx;
        y = sy * (m_t*2 + m_t*2+1-abs(sy)) / 2;
        field[zero+x+y] = 0;
        //cnt = 0;
        //dfs(sx, sy, 0);

        int ans = 0;
        queue< pair< pair<int, int>, int > > rt;
        rt.push(mp(mp(sx, sy), 0));

        while( !rt.empty() ){
            ans++;
            int cx = rt.front().first.first;
            int cy = rt.front().first.second;
            int ct = rt.front().second;
            rt.pop();

            if( ct < t ){
                rep(i, 6){
                    int nx = cx + dx[i];
                    int ny = (cy + dy[i]) * (m_t*2 + m_t*2+1-abs(cy+dy[i])) / 2;
                    if( field[zero+nx+ny] ){
                        field[zero+nx+ny] = 0;
                        rt.push(mp(mp(nx, cy+dy[i]), ct+1));
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1264
N = int(input())
XY = sorted([tuple(map(int, input().split())) for _ in range(N)])
PQ = []
for i in range(N-1):
    for j in range(i, N):
        PQ.append((XY[j][0]-XY[i][0], XY[j][1]-XY[i][1]))
PQ = list(set(PQ))
ans = N
for p, q in PQ:
    tmp1 = 1
    check=[0]*N
    for i in range(N-1):
        if check[i]:
            continue
        else:
            check[i] = 1
            tmp2 = 1
        for j in range(i, N):
            if check[j]:
                continue
            else:
                if XY[j][0] - p == XY[i][0] and XY[j][1] - q == XY[i][1]:
                    check[j] == 1
                    tmp2 = 0
                    break
        tmp1 += tmp2        
    ans = min(ans, tmp1)
print(ans)


        


    


Measured memory_bytes: 3188
import bisect

def main():
    N = int(input())
    v = sorted(list(map(int, input().split())))
    while len(v) > 1:
        num1 = v.pop(0)
        num2 = v.pop(0)
        avg = (num1 + num2) / 2
        idx = bisect.bisect(v, avg)
        v.insert(idx, avg)
    print(v[0])
main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<type> 
#define all(c) (c.begin(),c.end())


/*##################################################################################*/

/*
int prime[1000000] = {0} ;
void calculateprime()
{
    //calculating primes
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; (ll)i*i <= 1000000 ; i++)
    {
        if(prime[i] == 0)
        {
            for(ll j = i*i ; j <= 1000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}
*/
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        int k;cin>>k;
        ll sum = 0 ; 
        for(int i = 1 ; i <= k ; i++)
        {
            for(int j = 1 ; j <= k ; j++ )
            {
                for(int l = 1 ; l <= k ; l++)
                {
                    sum += gcd(gcd(i,j),l);
                }
            }
        }
        cout<<sum;
    }
    return 0;
}

Measured memory_bytes: 3692
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    var p = Array.fill(n)(sc.nextInt)
    var q = Array.fill(n)(sc.nextInt)

    val permutations = (1 to n).permutations.toList
    val px = permutations.indexOf(p.toVector)
    val qx = permutations.indexOf(q.toVector)
    println(math.abs(px - qx))
  }
}


Measured memory_bytes: 50000
import java.util.Scanner;

class Main {

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

        int t[] = new int[10];
        t[0] = scan.nextInt();
        t[1] = scan.nextInt();
        t[2] = scan.nextInt();
        t[3] = scan.nextInt();
        t[4] = scan.nextInt();
        t[5] = scan.nextInt();
        t[6] = scan.nextInt();
        t[7] = scan.nextInt();
        t[8] = scan.nextInt();
        t[9] = scan.nextInt();

        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9 - i; j++) {
                if (t[j] < t[j + 1]) {
                    int temp = t[j];
                    t[j] = t[j + 1];
                    t[j + 1] = temp;

                }
            }
        }

        for (int i = 0; i < 3; i++) {
            System.out.println(t[i]);
        }
    }
}



Measured memory_bytes: 26364
# 参考: https://atcoder.jp/contests/agc033/submissions/5279051
def a_darker_and_darker(H, W, Grid):
    from scipy.ndimage import distance_transform_cdt
    # 2次元リストの各位置に対して、Falseとみなされる要素がある位置から
    # 最短の距離が格納された2次元リストを返す
    # 距離の測り方は、metricが'taxicab'だとマンハッタン距離に、
    # 'chessboard'だとチェビシェフ距離に基づく

    grid = [[1 if c == '.' else 0 for c in row] for row in Grid]
    return distance_transform_cdt(grid, metric='taxicab').max()

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(a_darker_and_darker(H, W, Grid))

Measured memory_bytes: 47808
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define rep(i,a,n) for (int i=a;i<n;i++)
#define MAXN 1000001 
using namespace std;
void solve() {
	ll n;
	cin>>n;
	ll sum=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				 sum+=__gcd(i,__gcd(j,k));
			}
		}
	}
	cout<<sum<<"\n";
	return;
}

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

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

}

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

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

#define MAX_N 100000
#define MIN_A 0
ll n;
ll a[MAX_N];
ll len = 0;
ll seq[MAX_N] = {};

int main() {
    cin >> n;
    repeat (i,n) { cin >> a[i]; ++ a[i]; }
    repeat (i,n) {
        ll *p = lower_bound(seq,seq+len,a[i]);
        if (p == seq+len) ++ len;
        *p = a[i];
    }
    cout << len << endl;
    return 0;
}

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

int main()
{
  int num;
  cin >> num;

  vector<int> vec(num);
  for(int i = 0; i < num; ++i) cin >> vec.at(i);

  // 重複した要素を除くため, 集合に変換する
  set<int> set_vals;
  for(int i = 0; i < num; ++i){
    set_vals.insert(vec.at(i));
  }

  // 集合のサイズが求めるもの
  cout << set_vals.size() << endl;

  return 0;

}


Measured memory_bytes: 256
//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target_ans("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

#define int long long
//#define int unsigned int
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

vi xx = { 1, 0, -1, 0 };
vi yy = { 0, 1, 0, -1 };
string dir = "LRUD";

const int N = 5e5 + 50, oo = 3e18 + 500;
const int mod = 998244353;
//const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const double eps = 1e-12, PI = 2 * acos(0.0);
int n, m, k;
long long cnt = 0;
int lg = 18;
vi g[N];
vi rg[N];
vi visit(N, 0);



signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	/*freopen("abbreviation.in", "r", stdin);
	freopen("abbreviation.out", "w", stdout);*/
	//ПРОВЕРЯЙ ДЕФАЙНЫ ТУПОЙ!!!

	string s;
	cin >> s;
	n = SZ(s);

	for (int i = 0; i < n; i++)
	{
		if (s[i] == '?')
		{
			s[i] = 'D';
		}
	}

	cout << s << endl;
}




Measured memory_bytes: 30832
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    int count = 0;
    long ans = 0;

    while(h>0){
      h = h/2;
      count++;
    }
    
    for(int i = 0 ; i < count ; ++i){
        ans += (long)Math.pow(2,i);
    }
        
    System.out.println(ans);

  }
}

Measured memory_bytes: 35868
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N = 3010;
inline LL read()
{
  LL p=0; LL f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
  return p*f;
}
LL C[N][N],S[N][N];
LL qpow(LL x,LL k,LL mo){LL s=1; while(k){if(k&1) s=s*x%mo; x=x*x%mo; k>>=1;} return s;}
int main()
{
  LL n = read(); LL p = read();
  C[0][0] = 1; for(LL i=1;i<=n+1;i++)
  {
  	C[i][0] = 1; for(LL j=1;j<=i;j++) C[i][j] = (C[i-1][j] + C[i-1][j-1]) % p;
  }
  S[0][0] = 1; for(LL i=1;i<=n+1;i++)
  {
    S[i][1] = 1; for(LL j=2;j<=i;j++) S[i][j] = (S[i-1][j] * j + S[i-1][j-1]) % p;
  }
  
  LL ans = 0;
  for(LL i=0;i<=n;i++)
  {
    LL s = C[n][i] * qpow(2,qpow(2,n-i,p-1),p) % p;
    LL fr = 0; for(LL j=0;j<=i;j++) fr = (fr + qpow(2,(n-i)*j%(p-1),p) * S[i+1][j+1] % p) % p;
    // printf("%lld %lld\n",s,fr);
    ans =( (ans + ((i&1) ? (-1) : 1) * s % p * fr % p ) % p + p ) % p;
  }
  return printf("%lld\n",ans),0;
}

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

int main() {
  int n, a, b;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
  }
  else {
    cin >> a;
    cin >> b;
    cout << a + b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = []; x = []; y = []

n.times do |i|
  a[i] = gets.to_i
  x << []; y << []
  a[i].times {|j| x[i][j], y[i][j] = gets.split.map(&:to_i) }
end

max = 0

1.upto(2 ** n - 1) do |i|
  flg = nil

  n.times do |j|
    if i[j] == 1
      a[j].times do |k|
        flg = true if y[j][k] ^ i[x[j][k] - 1] == 1
      end
    end
  end

  next if flg

  tmp = i.to_s(2).split('').count {|e| e == '1' }
  max = tmp if max < tmp
end

puts max

Measured memory_bytes: 3836
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long max_profit = -999999999;
		long prev = 1000000001;
		
		int N = sc.nextInt();
		long[] R = new long[N];
		for (int i = 0; i < N; i++) {
			R[i] = sc.nextLong();
		}
		
		for (int i = 0; i < N; i++) {
			if (prev <= R[i]) {
				continue;
			}
			for (int j = i+1; j < N; j++) {
				long tmp = R[j] - R[i];
				max_profit = Math.max(max_profit, tmp);
			}
			prev = R[i];
		}
		
		System.out.println(max_profit);
	}
}

Measured memory_bytes: 102956
fun main(args:Array<String>){
            val num = readLine()!!.toInt()
            val list = readLine()!!.split(" ").map(String::toInt)
            val manzoku = readLine()!!.split(" ").map(String::toInt)
            val bonusup = readLine()!!.split(" ").map(String::toInt).toMutableList()
            var m = 0
            for(i in 0 until num){
                m += manzoku[list[i]-1]
                              if(i >= 1) {

                if (list[i] == list[i-1]+1) m += bonusup[list[i]-1-1]
                              }
            }
            println(m)
        }

Measured memory_bytes: 36560
require "prime"
primes = Prime.each(10000).to_a
arr = Hash.new(0)
0.upto(primes.length - 1){|i|
    sum = 0
    i.upto(primes.length - 1){|j|
        sum += primes[j]
        arr[sum] += 1
    }
}
while true
    x = gets.to_i
    break if x == 0
    puts arr[x]
end


Measured memory_bytes: 45624
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
#define ll long long 


string convertToTitle(ll n) {
    string ans;
    while (n) {
        ans = char ((n - 1) % 26 + 'a') + ans;
        n = (n - 1) / 26;
    }
    return ans;
}


int main()
{
  ll n; cin>>n;
  cout<<convertToTitle(n);
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int64_t h;
  int c=0;
  int64_t d;
  scanf("%ld",&h);
  while(h>0){
    h=h/2;
    c++;
  }
  d=pow(2,c)-1;
  printf("%ld",d);
  return 0;
}

Measured memory_bytes: 256
i = raw_input().strip().split(" ")
x = int(i[0])
y = int(i[1])

groups = []
groups.append([1, 3, 5, 7, 8, 10, 12])
groups.append([4, 6, 9, 11])
groups.append([2])

for g in groups:
    if x in g and y in g:
        print "Yes"
        break
else:
    print "No"

Measured memory_bytes: 2568