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

using namespace std;

#define PB push_back
#define f first
#define s second

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

const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)2e5+1;

ll pref[MAXN], arr[MAXN], dp[MAXN];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    pref[0] = arr[0];
    for(int i=2; i<n; i+=2)
    {
        pref[i] = pref[i-2] + arr[i];
    }

    for(int i=1; i<n; i++)
    {
        if(i&1)
        {
            dp[i] = arr[i] + dp[i-2];
            dp[i] = max(dp[i], pref[i-1]);
        }
        else
        {
            dp[i] = dp[i-2] + arr[i];
            dp[i] = max(dp[i], dp[i-1]);
        }
    }
    cout << dp[n-1];
    return 0;
}


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

constexpr int64_t mod = 1000000007;

int64_t power(int64_t n, int64_t k) {
  if (k == 0) return 1;
  int64_t res = power(n * n % mod, k / 2);
  if (k % 2) {
    res = res * n % mod;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  map<pair<int64_t, int64_t>, int64_t> m;
  for (int i = 0; i < n; i++) {
    int64_t a, b, d;
    cin >> a >> b;
    if (a == 0 and b == 0) {
      m[make_pair(0, 0)]++;
      continue;
    }
    d = gcd(abs(a), abs(b));
    a /= d;
    b /= d;
    if (a < 0 or (a == 0 and b < 0)) {
      a = -a;
      b = -b;
    }
    m[make_pair(a, b)]++;
    auto x = make_pair(b, -a);
    if (x.first < 0 or (x.first == 0 and x.second < 0)) {
      x.first = -x.first;
      x.second = -x.second;
    }
    m[x] += 0;
  }
  int64_t ans = 1;
  for (auto x : m) {
    auto y = make_pair(x.first.second, -x.first.first);
    if (y.first < 0 or (y.first == 0 and y.second < 0)) {
      y.first = -y.first;
      y.second = -y.second;
    }
    if (x.first >= y) continue;
    ans *= (power(2, m[x.first]) + power(2, m[y]) + mod - 1) % mod;
    ans %= mod;
  }
  cout << (ans + mod - 1 + m[make_pair(0, 0)]) % mod << endl;
}


Measured memory_bytes: 28492
A, B, C = map(int, input().split())

if A == B == C:
    if A % 2:
        print(0)
    else:
        print(-1)
else:
    ans = 0
    while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
        A, B, C = (B + C) // 2, (C + A) // 2, (A + B) // 2
        ans += 1
    print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){
	int X,maxv=1;
  	cin>>X;
  	int i=1,j=2;
  	while(j<10){
      for(int i=1;(int)pow(i,j)<=X;++i)maxv=max(maxv,(int)pow(i,j));
  	  ++j;
    }cout<<maxv<<endl;
  	return 0;
}


Measured memory_bytes: 384
//good luck
# include <iostream>
# include <cstdio>
# include <cmath>
# include <cstdlib>
# include <cstring>
# include <string>
# include <algorithm>
# include <vector>
# include <queue>
# include <ctime>
# include <map>

#define LL long long
#define maxn (int)1e5+5
#define inf  (int)2147483640
#define is(a) (a>='0'&&a<='9')
#define iabs(a) ((a)>0?(a):(-a))
#define imax(a,b) ((a)>(b)?(a):(b))
#define imin(a,b) ((a)<(b)?(a):(b))
 
using namespace std;

LL N,d,a[maxn];

long double sum;

inline void read(LL &x)
{
  x=0;bool f=0;char ch=getchar();
  for (;!is(ch);ch=getchar()) f|=ch=='-';
  for (;is(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
  x=f?-x:x;
}


int main()
{
	read(N); 
	for (int i = 1; i <= N; ++i) read(a[i]);
	sort (a + 1, a + 1 + N);
	sum = a[1] * 1.0;
	for (int i = 2; i <= N; ++i) sum = (sum + a[i] * 1.0) /2;
	printf ("%.8LF",sum);
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  int W[N];
  for(int i=0;i<N;i++) cin>>W[i];
  int b=0;
  for(int i=0;i<N;i++) b+=W[i];
  int a=0;
  int ans=b;
  for(int i=0;i<N-1;i++){
    a+=W[i];
    b-=W[i];
    int c=abs(a-b);
    ans=min(ans,c);
  }
  cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,i,j;
  int count;

  while(1){
    scanf("%d",&n);
    if(n==0) break;

    count=0;
    for(i=n+1;i<=2*n;i++){
      for(j=2;j*j<=i;j++){
        if(i%j==0) break;
      }
      if(j*j>i) count++;
    }
    printf("%d\n",count);
  }
  return 0;
}


Measured memory_bytes: 2100
import copy
N = int(input())
h = list(map(int, input().split()))
l = []
l.append(h)
x = 0
while l != []:
	m = []
	for i in range(len(l)):
		a = [j for j, _ in enumerate(l[i]) if _ == min(l[i])]
		start = 0
		new = []
		for s in a:
			if l[i][start:s] != []:
				y = list(map(lambda _: _ - min(l[i]), l[i][start:s]))
				new.append(y)
			start = s + 1
		if l[i][start:] != []:
			z = list(map(lambda _: _ - min(l[i]), l[i][start:]))
			new.append(z)
		x += min(l[i])
		m = m + new
	l = copy.deepcopy(m)
print(x)

Measured memory_bytes: 3572
N,K=map(int,input().split())
P= [list(map(int, input().split())) for i in range(N)]
P=sorted(P)
pi=list(enumerate(P))
minA=float("inf")
for il,xyl in pi[:N-1]:
    left=xyl[0]
    for ir,xyr in pi[il+1:]:
        right=xyr[0]
        insd=[xy_ for i,xy_ in pi if xyl[0]<=xy_[0]<=xyr[0]]
        insd=sorted(insd,key=lambda xx:xx[1])
        in_L=len(insd)
        if in_L<K:continue
        for jd in range(in_L-K+1):
            ju=jd+K-1
            down=insd[jd][1]
            upper=insd[ju][1]
            minA=min(minA,(upper-down)*(right-left))

print(minA)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#define LEN (17 / 2 + 1)

const char* out = "ILMU";

int mf( std::string str ){
	int sum = 0, pt = 0;
	int n[ LEN + 1 ];

	std::fill( n, n + LEN + 1, 1 );

	for( int i = 0; i < str.size(); i++ ){
		if( i & 1 ){
			if( str[i] == '+' ){
				pt++;
			}
		}else{
			n[pt] *= (str[i] - '0');
		}
	}

	for( int i = 0; i <= pt; ++i ) sum += n[i];	

	return sum;
}

int lr( std::string str ){
	int sum = str[0] - '0' ;

	for( int i = 1; i < str.size(); i += 2 ){
		if(str[i] == '+'){
			sum += str[i+1] - '0';
		}else{
			sum *= str[i+1] - '0';
		}
	}

	return  sum;
}

int main(){
	std::string str;
	int res;
	bool equal[2];

	std::cin >> str >> res;

	equal[0] = (mf( str ) == res);
	equal[1] = (lr( str ) == res);

	std::cout << out[ ((int)equal[0] << 1) + equal[1] ] << std::endl;

	return 0;
}

Measured memory_bytes: 1200
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <ctime>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> cards;
	long long b = 0;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		cards.emplace_back(a);
		b += a;
	}
	long long ans = INF;
	long long arai = b;
	for (int i = 0; i < n-1; i++) {
		arai -= cards[i];
		long long snuke = b - arai;
		ans = min(ans, abs(snuke - arai));
	}
	cout << ans << endl;
}

	



Measured memory_bytes: 1400
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

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

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

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}


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

	ll ans=0;

	rep(i, n) {
		int m;
		cin >> m;
		if (((i + 1) % 2 != 0) && (m % 2 != 0)) {
			ans++;
		}
	}
	

	cout << ans << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,s,t,c;
vector<int> e[300003];
queue <int> q;
int chk[300003];
int main(){
    int i,j,nxt;
    scanf("%d %d",&n,&m);
    for(i=1;i<=m;i++){
        scanf("%d %d",&a,&b);
        e[a].push_back(b+n);
        e[a+n].push_back(b+2*n);
        e[a+2*n].push_back(b);
    }
    scanf("%d %d",&s,&t);
    q.push(s);
    chk[s]=1;
    while(!q.empty()){
        c=q.front();
        q.pop();
        for(nxt : e[c])if(!chk[nxt]){
            q.push(nxt);
            chk[nxt]=chk[c]+1;
        }
    }
    --chk[t];
    if(chk[t]%3) printf("-1");
    else printf("%d",chk[t]/3);
    return 0;
}


Measured memory_bytes: 17792
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;

//-----------------------------------------------------------------------

int N,Q;
int bit[100010];

void add(int k,int w)
{
    for(int x=k;x<=N;x+=x&-x) bit[x]+=w;
}

int getSum(int k)
{
    int ret=0;
    for(int x=k;x>0;x-=x&-x) ret+=bit[x];
    return ret;
}

signed main()
{
    cin>>N>>Q;
    while(Q--)
    {
        int type,x,y; cin>>type>>x>>y;
        if(type==0)
            add(x,y);
        else
            cout<<getSum(y)-getSum(x-1)<<endl;
    }
}



Measured memory_bytes: 3860
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using coord= pair<int, int>;
using idx= pair<coord, int>;

int BFS(const vector<string> &board, coord s, coord g){ // 辺の重みが0/1のときは両端キューを使って重み0の辺を辿るときpush_front, 重み1の辺を辿るときpush_backすると簡単にBFSできる。
  constexpr int TBC= INT_MAX;
  constexpr char block= '#';
  const int H= int(board.size());
  const int W= int(board.at(0).size());

  const vector<coord> diff0= {make_pair(0,-1), make_pair(-1,0), make_pair(1,0), make_pair(0,1) }; // 探索方向

  vector<vector<int>> pushed(H, vector<int>(W, TBC));
  vector<vector<int>> popped(H, vector<int>(W, TBC));
  deque<idx> bfs;
  pushed.at(s.first).at(s.second)= 0;
  bfs.push_front(make_pair(s, 0));

  while( !bfs.empty() ){
    idx pd= bfs.front();
    auto [p, dist]= pd;
    auto [x, y]= p;
    bfs.pop_front();
    if(p==g){
      popped.at(x).at(y)= dist;
      break;
    }
    else if(popped.at(x).at(y) <= dist){
      continue;
    }
    else{
      popped.at(x).at(y)= dist;
      // 徒歩圏内
      for(const auto& [dx,dy]:diff0){
        if(x+dx <= -1 || x+dx >= H || y+dy <= -1 || y+dy >= W) continue;
        else if(board.at(x+dx).at(y+dy)==block){
          continue;
        }
        else if(pushed.at(x+dx).at(y+dy) > dist){
          pushed.at(x+dx).at(y+dy)= dist;
          bfs.push_front(make_pair(make_pair(x+dx, y+dy), dist));
        }
      }
      // ワープ圏内
      for(int dx= -2; dx<= 2; dx++){
        for(int dy= -2; dy<= 2; dy++){
          if(x+dx <= -1 || x+dx >= H || y+dy <= -1 || y+dy >= W) continue;
          else if(board.at(x+dx).at(y+dy)==block){
            continue;
          }
          else if(pushed.at(x+dx).at(y+dy) > dist+ 1){
            pushed.at(x+dx).at(y+dy)= dist+ 1;
            bfs.push_back(make_pair(make_pair(x+dx, y+dy), dist+ 1));
          }
        }
      }
    }
  }

  int ans= (popped.at(g.first).at(g.second)==TBC) ? -1
                                                  : popped.at(g.first).at(g.second);

  return ans;
}


int main(){
  int H,W;
  cin >> H >> W;

  int s1,s2,g1,g2;
  cin >> s1 >> s2 >> g1 >> g2;
  s1--; s2--; g1--; g2--; // 1-indexed -> 0-indexed
  const coord s= make_pair(s1, s2);
  const coord g= make_pair(g1, g2);

  vector<string> board(H);
  for(int h=0; h<H; h++){
    cin >> board.at(h);
  }

  int ans= BFS(board, s, g);
  
  cout << ans << endl;
}

Measured memory_bytes: 13652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n){
    cin >> h[i];
  }
  vector<int> dp(n+1);
  dp[0] = 0;
  dp[1] = abs(h[0]-h[1]);
  rep(i,n-1){
    int way1 = dp[i] + abs(h[i+1]-h[i]);
    dp[i+1] = min(way1,dp[i+1]);
    int way2 = dp[i] + abs(h[i+2]-h[i]);
    dp[i+2] = way2;
  }
  cout << dp[n-1] << endl;
}

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

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

string s,t;
signed main(){
  cin>>s>>t;
  for(int i=0;i<s.size()||i<t.size();i++){
    if(i<s.size())cout<<s[i];
    if(i<t.size())cout<<t[i];
  }
  cout<<endl;
  return 0;

}


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

int main(){
	int k,a,b;
	cin>>k>>a>>b;
	
	for(;a<=b;a++)
	if(a%k==0){
		cout<<"OK";
		return 0;
	}
	
	cout<<"NG";
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main(){
    ll n;
    ll nw=0;
    ll nr=0;
    cin>>n;
    vector<char> a(n);
    rep(i,n){
        cin>>a[i];
        if(a[i]=='W')nw++;
        else nr++;
    }
    ll ans=0;
    for(ll i=nr;i<n;i++){
        if(a[i]=='R')ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main() {
    int n, k, x, y, output = 0;
    cin >> n;
    cin >> k;
    cin >> x;
    cin >> y;

    if (n <= k) {
        output = n * x;
    } else {
        output = k * x;
        output += (n - k) * y;
    }
    cout << output << endl;

    return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
if (y2-y1) >=0 and (x2-x1) >=0:
    x3 = x2 - abs(y2-y1)
    y3 = y2 + abs(x2-x1)
elif (y2-y1) >=0 and (x2-x1) <0:
    x3 = x2 - abs(y2-y1)
    y3 = y2 - abs(x2-x1)
elif (y2-y1) <0 and (x2-x1) >=0:
    x3 = x2 + abs(y2-y1)
    y3 = y2 + abs(x2-x1)
else:
    x3 = x2 + abs(y2-y1)
    y3 = y2 - abs(x2-x1)
x4 = x3 - (x2-x1)
y4 = y3 - (y2-y1)
print(x3, y3, x4, y4)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N, K; cin >> N >> K;
    vector<int> P(N); for (auto &p : P) cin >> p, p--;
    vector<Int> C(N); for (auto &c : C) cin >> c;
    vector<bool> visited(N);
    Int ans = -1e18;
    for (int i = 0; i < N; i++) {
        if (visited[i]) continue;
        vector<Int> A;
        int curr = i;
        while (!visited[curr]) {
            visited[curr] = true;
            A.push_back(C[curr]);
            curr = P[curr];
        }
        int M = A.size();
        vector<Int> S(M * 2 + 1);
        for (int i = 0; i < M; i++) {
            S[i + 1] = S[i] + A[i];
        }
        for (int i = 0; i < M; i++) {
            S[M + i + 1] = S[M + i] + A[i];
        }
        int Q = K / M;
        int R = K % M;
        if (Q != 0) ans = max(ans, S[M] * Q);
        for (int i = 0; i < M; i++) {
            for (int j = 1; j <= M; j++) {
                if (Q == 0 && j > R) continue;
                Int a = max(S[M], 0LL) * (j <= R ? Q : Q - 1) + S[i + j] - S[i];
                ans = max(ans, a);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n){
        cin >> s[i];
        sort(all(s[i]));
    }

    map<string, ll> mp;
    rep(i, n){
        mp[s[i]]++;
    }

    ll ans = 0;
    for(auto m : mp){
        if(m.second == 1) continue;
        ans += m.second * (m.second-1) / 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 18176
package main

import (
	"fmt"
	"math"
)

var S string
var ans int

func main() {
	fmt.Scan(&S)
	for i := 0; i < len(S)-1; i++ {
		if string(S[i]) != string(S[i+1]) {
			ans++
		}
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

func lcm(x, y uint64) uint64 {
	return (x / gcd(x, y)) * y
}

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> S(H);
	for(int i=0; i<H; i++) cin >> S[i];

	int ans = 10000000;
	for(int k=0; k<(1<<(H-1)); k++){
		int cnt = 0;
		int nbit = 0;
		bool ng = false;
		for(int j=0; j<H; j++) nbit += (k>>j)&1;
		debug(k, nbit);
		vector<int> xs(nbit+1), ys(nbit+1);
		for(int i=0; i<W; i++){
			int p = 0;
			int s = 0;
			for(int j=0; j<H; j++){
				if(S[j][i]=='1') s++;
				if((k>>j)&1){
					ys[p] = s;
					p++; s=0;
				}
			}
			ys[p] = s;

			debug(i, k);
			debugv(ys);

			bool cut = false;
			for(int j=0; j<=nbit; j++){
				if(xs[j]+ys[j] > K) cut = true;
				if(ys[j]>K) ng = true;
			}
			if(cut){
				for(int j=0; j<=nbit; j++) xs[j] = ys[j];
				cnt++;
			} else {
				for(int j=0; j<=nbit; j++) xs[j] += ys[j];
			}
		}
		debug("cnt", k, cnt);
		if(ng) continue;
		ans = min(ans, nbit+cnt);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  string s;
  cin >> s;
  rep(i, s.size()){
    if(s[i] == '?'){
      s[i] = 'D';
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3348
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define pb push_back
using namespace std;
double dp[3001][3001];
double solve(double *a, int i, int x)
{
    if(x==0)
        return 1;
    if(i==0)
        return 0;
    if(dp[i][x]>-0.9)
        return dp[i][x];
    return dp[i][x]=a[i-1]*solve(a,i-1,x-1)+(1-a[i-1])*solve(a,i-1,x);
}
int32_t main()
{
    int t;
    //cin>>t;
    //while(t--)
    {   
        int n;
        cin>>n;
        double a[3001];
        memset(dp,-1,sizeof(dp));
        for(int i=0;i<n;i++)
            cin>>a[i];
        cout<<fixed<<setprecision(10)<<solve(a,n,(n+1)/2);
    }
}






Measured memory_bytes: 74312
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#define MAXN 3010
#define LL long long
using namespace std;

const LL P=1000000007;

int n,m;
int s[MAXN];
int p[MAXN][2];
LL c[MAXN][MAXN];
LL f[MAXN][MAXN];

void init(){
	int _m;
	scanf("%d%d",&n,&_m);
	static char str[MAXN];
	scanf("%s",str+1);
	for(int i=1;i<=n;i++) s[i]=s[i-1]+(str[i]=='1'?1:0);
	for(int i=1;i<=_m;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		if(!m || r>p[m][1]){
			p[++m][0]=l;
			p[m][1]=r;
		}
	}
	for(int i=0;i<=n;i++){
		c[i][0]=1;
		for(int j=1;j<=i;j++)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%P;
	}
}

void update(LL &x,LL y){ x=(x+y)%P; }

void dp(){
	f[1][s[p[1][1]]-s[p[1][0]-1]]=1;
	for(int i=1;i<m;i++)
		if(p[i+1][0]<=p[i][1]){
			int delta=s[p[i+1][1]]-s[p[i][1]];
			for(int j=0;j<=p[i][1]-p[i][0]+1;j++)
				for(int k=max(j-(p[i][1]-p[i+1][0]+1),0);k<=p[i+1][0]-p[i][0] && k<=j;k++)
					update(f[i+1][j-k+delta],f[i][j]*c[p[i+1][0]-p[i][0]][k]);
			for(int j=p[i][1]-p[i][0]+2;j<=n;j++)
				assert(f[i][j]==0);
		}else{
			int delta=s[p[i+1][1]]-s[p[i+1][0]-1];
			for(int j=0;j<=p[i][1]-p[i][0]+1;j++)
				update(f[i+1][delta],f[i][j]*c[p[i][1]-p[i][0]+1][j]);
		}
}

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	init();
	dp();
	LL ans=0;
	for(int i=0;i<=p[m][1]-p[m][0]+1;i++)
		update(ans,f[m][i]*c[p[m][1]-p[m][0]+1][i]);
	printf("%lld\n",ans);
}



Measured memory_bytes: 105088
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

fn main() {
  use std::collections::HashMap;
  input! {
    n: usize,
    s: chars,
  }
  let (front, back) = s.split_at(n);
  let back: Vec<_> = back.into_iter().rev().collect();
  let mut hash = HashMap::new();
  for mask in 0 .. 1 << n {
    let mut rb = (String::new(), String::new());
    for (i, &c) in front.iter().enumerate() {
      if (mask >> i) & 1 == 1 {
        rb.1.push(c);
      } else {
        rb.0.push(c);
      }
    }
    if let Some(count) = hash.get_mut(&rb) {
      *count += 1i64;
      continue;
    }
    hash.insert(rb.clone(), 1);
  }
  let mut ans = 0i64;
  for mask in 0 .. 1 << n {
    let mut rb = (String::new(), String::new());
    for (i, &c) in back.iter().enumerate() {
      if (mask >> i) & 1 == 1 {
        rb.1.push(*c);
      } else {
        rb.0.push(*c);
      }
    }
    if let Some(count) = hash.get(&rb) {
      ans += *count;
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 59628
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
    int N;
    double A[100];
    cin >> N;
    for(int i = 0;i < N; i++){
        cin >> A[i];
    }
    double ans = 0;
    for(int i = 0; i < N; i++){
        ans += (1/A[i]);
    }
    ans = 1/ans;
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

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

using namespace std;

int main(){
  int n,p; cin >> n;
  int ans=0,maxi=0;
  while(n--){
    cin >> p;
    ans+=p;
    maxi=max(maxi,p);
  }
  cout << ans-(maxi/2) << endl;
  
  return 0;
}


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

int main(void){
    while(1){
        int m, f, r;
        cin >> m >> f >> r;
        if(m + f + r == -3) break;
        int x = m + f;
        if(m == -1 || f == -1) cout << 'F' << endl;
        else if(x >= 80) cout << 'A' << endl;
        else if(x >= 65) cout << 'B' << endl;
        else if(x >= 50 || (x >= 30 && r >= 50)) cout << 'C' << endl;
        else if(x >= 30) cout << 'D' << endl;
        else cout << 'F' << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e18;


int main()
{
    ll n,m;
    cin >> n >> m;
    priority_queue<ll> PQ;
    rep(i,n){
        ll a;
        cin >> a;
        PQ.push(a);
    }
    while(m--){
        ll x=PQ.top();
        PQ.pop();
        PQ.push(x/2);
    }
    ll ans=0;
    while(!PQ.empty()){
        ll x=PQ.top();
        PQ.pop();
        ans+=x;
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 1400
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)
#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)
#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;

int main() {
    int N,T;
    cin>>N>>T;
    
    int mn=INF;
    rep(i,N){
        int c,t;cin>>c>>t;
        if(T>=t){
            mn = min(mn,c);
        }
    }
    if(mn==INF){
        cout1("TLE");
    }else{
        cout1(mn);
    }
    
}

Measured memory_bytes: 256
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    
    if op == "?":
        break
    if op == "+":
        print(a+b)
    if op == "-":
        print(a-b)
    if op == '*':
        print(a*b)
    if op == "/":
        print(a//b)


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

using namespace std;

#define REP(var, n)  for (int var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<int>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

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

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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


auto solve() {
    int a, b, c;
    cin >> a >> b >> c;
    return a == b && b == c;

}


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

//    cout << (solve() ? "Heisei" : "TBD") << endl;
    cout << (solve() ? "Yes" : "No") << endl;
//    cout << solve() << endl;
//    solve();

    return 0;
}


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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  if (N >= B) {
    cout << (B-1)*A/B << endl;
  }
  else {
    cout << N*A/B << endl;
  }
}


Measured memory_bytes: 3592
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

string v[30][30];

signed main() {
    int H, W; cin >> H >> W;
    rep(i,0,H) rep(j,0,W) {
        cin >> v[i][j];
        if(v[i][j] == "snuke") {
            cout << (char)('A' + j);
            cout << i+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = []
m = []

for i in range(n):
    x, y = list(map(int, input().split()))
    p.append(x+y)
    m.append(x-y)

mnp = min(p)
mxp = max(p)
mnm = min(m)
mxm = max(m)

res = [mxp-mnp, mxm-mnm, mnm, mxm, mnp-mxp]
print(max(res))


Measured memory_bytes: 24892
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

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

int n,m,R;
int r[10];
int a[20000],b[20000],c[20000];

int d[210][210];

int main(){
	cin>>n>>m>>R;
	REP(i,R){
		cin>>r[i];
		r[i]--;
	}
	REP(i,210){
		REP(j,210){
			d[i][j]=10000000;
		}
	}
	
	REP(i,m){
		cin>>a[i]>>b[i]>>c[i];
		a[i]--,b[i]--;
		d[a[i]][b[i]]=c[i];
		d[b[i]][a[i]]=c[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
			}
		}
	}
	/*for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cout<<d[i][j]<<" ";
		}
		cout<<endl;
	}*/
	int ans=INF;
	sort(r,r+R);
	do{
		int tans=0;
		for(int i=0;i<R-1;i++){
			tans+=d[r[i]][r[i+1]];
		}
		ans=min(ans,tans);
	}while(next_permutation(r,r+R));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

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

  bool is_possible = false;
  if (N % 2 == 0) {
    is_possible = (N / 2 >= K);
  } else {
    is_possible = ((N + 1) / 2 >= K);
  }

  if (is_possible) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
N, M = input().split()
N = int(N)
M = int(M)
A = list(map(int, input().split()))
LA = len(A)
i = 0
SUM = 0

for i in range(LA):
    SUM = SUM + A[i]
    
if SUM > N:
    print('-1')
    
else:
    print(N - SUM)

Measured memory_bytes: 68200
require 'pp'

n, m, x = gets.split.map(&:to_i)
x_n = Array.new(n)

n.times do |i|
    x_n[i] = gets.split.map(&:to_i)
end

min = 10 ** 12
found = false

1.upto(n) do |i|
    x_n.combination(i) do |t|
        price = 0
        rikai = Array.new(m, 0)
#        pp t
        t.each do |b|
#            pp b
            b.each_with_index do |t2, i|
                if i == 0
                    price += t2
                else
                    rikai[i-1] += t2
                end
            end
        end

        if rikai.all? {|y| y >= x} && price < min
            min = price
            found = true
        end
    end
end

if found
    puts min
else
    puts "-1"
end


Measured memory_bytes: 14644
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  int sum, N;
  int d[55];
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> d[i];
  }
  
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      sum += d[i] * d[j];
    }
  }
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import qualified Data.List as L

import Control.Monad

main :: IO ()
main = do
    [h, w] <- fmap read . words <$> getLine
    ps     <- replicateM h $ read <$> getLine
    qs     <- replicateM w $ read <$> getLine
    print $ solve h w ps qs

solve :: Int -> Int -> [Int] -> [Int] -> Int
solve h w ps qs = connect ps' qs' (h + 1) (w + 1) id
  where
    ps' = L.sort ps
    qs' = L.sort qs
    connect :: [Int] -> [Int] -> Int -> Int -> (Int -> Int) -> Int
    connect [] [] = (.) ((.) ($ 0)) . const . flip const
    connect ps [] = onSN ps []
    connect [] qs = onEW [] qs
    connect ps qs = go   ps qs
      where
        go = if head ps <= head qs then onSN else onEW
    onSN (p : ps) qs !y !x cont = connect ps qs (pred y) x $ cont . (p * x +)
    onEW ps (q : qs) !y !x cont = connect ps qs y (pred x) $ cont . (q * y +)


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = int(1e9) + 7;

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

  int W, H, N;
  cin >> W >> H >> N;

  vector<int> X(N+1), Y(N+1);
  int ans = 0;
  rep(i, N) {
    cin >> X[i] >> Y[i];
    if (i) {
      if ((X[i] > X[i-1] && Y[i] < Y[i-1]) || (X[i] < X[i-1] && Y[i] > Y[i-1])) {
        ans += abs(X[i] - X[i-1]) + abs(Y[i] - Y[i-1]);
      }
      else ans += max(abs(X[i] - X[i-1]), abs(Y[i] - Y[i-1]));
    }
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3192
#define MAX 1000000000
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    
    int n,m,i,j,row=-1,t;
    long int a[100]={},b[100]={},c[100]={},d[100]={},e,f,g,h,sum,sum2,min=MAX,ans;
    scanf("%d %d",&n,&m);
    
    for(i=0;i<n;i++){
        scanf("%ld %ld",&a[i],&b[i]);
    }
    for(i=0;i<m;i++){
        scanf("%ld %ld",&c[i],&d[i]);
    }
    for(i=0;i<n;i++){
        e=a[i];
        f=b[i];
        for(j=0;j<m;j++){
            g=c[j];
            h=d[j];
            sum=labs(e-g);
            sum2=labs(f-h);
            ans=sum+sum2;
            if(ans<min){
                min=ans;
                t=j+1;
            }
        }
        printf("%d\n",t);
        min=MAX;
    }
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  s="0"+s;
  int k=0;
  for(int i=1;i<s.size();i++)
  {
    if(i&1)
    {
      if(s[i]=='R' || s[i]=='U' || s[i]=='D')
        continue;
      else
      {
        k=1;break;
      }
    }
    else
    {
      if(s[i]=='L' || s[i]=='U' || s[i]=='D')
        continue;
      else
      {
        k=1;break;
      }
    }
  }
  if(k==1)
    cout<<"No\n";
  else
    cout<<"Yes\n";
}


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

int main() {
 int n,k;cin>>n>>k;
int a[n]{0};
  rep(i, n){int p;
            cin>>p;
            a[p-1]++;}
  
  sort(a,a+n,greater<int>());

  
  int dec=0;
  rep(i, k)dec+=a[i];
  
  cout<<n-dec<<endl;
  
}


Measured memory_bytes: 1024
from copy import deepcopy

n, m, q = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]
pq = [list(map(int, input().split())) for _ in range(q)]

cnt = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in lr:
    cnt[l][r] += 1

acc = deepcopy(cnt)
for i in range(n):
    for j in range(n):
        tmp = acc[i][j + 1] + acc[i + 1][j] - acc[i][j]
        acc[i + 1][j + 1] += tmp

for p, q in pq:
    p -= 1
    ans = acc[q][q] - acc[p][q] - acc[q][p] + acc[p][p]
    print(ans)


Measured memory_bytes: 65964
#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000//000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000
 
using namespace std;
 
int match_q(char a,char b){
	if(a != b){
		if(a == '_' || b == '_') return 0;
		return -INF;
	}
	else return 1;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	
	string s,t;

	cin >> s >> t;

	int n = (int)s.size(),m = (int)t.size();

	int dp[n+1][m+1];

	for (int i = 0; i <= n; ++i){
		dp[i][0] = 0;
	}
	for (int i = 0; i <= m; ++i){
		dp[0][i] = 0;
	}

	for (int i = 1; i < n+1; ++i){
		for (int j = 1; j < m+1; ++j){
			dp[i][j] = max(dp[i-1][j-1] + match_q(s[i-1],t[j-1]),max(dp[i-1][j] + match_q(s[i-1],'_'),dp[i][j-1] + match_q('_',t[j-1])));
		}
	}

	string ans = "";

	int i = n,j = m;

	while(i && j){
		if(dp[i][j] == dp[i-1][j-1] + match_q(s[i-1],t[j-1])){
			ans += s[i-1];
			i--;j--;
		}else if(dp[i][j] == dp[i-1][j] + match_q(s[i-1],'_')){
			i--;
		}else{
			j--;
		}
	}

/*	for (int i = 0; i < n+1; ++i){
		for (int j = 0; j < m+1; ++j){
			cout << dp[i][j] << ' ';
		}
		cout << '\n';
	}
*/
	reverse(ans.begin(),ans.end());

	cout << ans << '\n';


	return 0;
}

Measured memory_bytes: 35456
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


int main(){
	int n;
	int p[55],a[55];
	cin>>n;
	rep(i,0,n)cin>>p[i],a[i]=p[i];
	sort(a,a+n);
	bool z=false,y=false;
	rep(i,0,n){
		if(p[i]!=a[i]){
			if(z==false){
				z=true;
				continue;
			}
			if(z==true&&y==true){
				print("NO");
				return 0;
			}
			if(y==false){
				y=true;
			}
		}
	}
	print("YES");

}

Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void ckmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void ckmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(A) A.begin(),A.end()

const int m=55;

int g[m][m];

void ep(set<int>& s,int d)
{
	vector<int> o(ALL(s));
	for (int p:o) s.insert(p%d);
}
bool ck(const set<int>& s,int t,int k)
{
	for (int p:s) if (g[p][t]<k) return true;
	return false;
}

int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	std::ios::sync_with_stdio(false);
	REP(i,m) REP(j,m) g[i][j]=100000000;
	REP(t,m)
	{
		set<int> e;
		e.insert(t);
		g[t][t]=0;
		for (int d=1;d<=m;d++)
		{
			REP(i,m) if (e.count(i%d)) e.insert(i);
			for (int p:e) ckmin(g[p][t],d);
		}
	}
	int n;
	cin>>n;
	int a[64],b[64];
	REP(i,n) cin>>a[i];
	REP(i,n) cin>>b[i];
	REP(i,n)
		if (g[a[i]][b[i]]>m)
		{
			printf("-1\n");
			return 0;
		}
	set<int> f[64];
	REP(i,n) f[i].insert(a[i]);
	int64 ret=0;
	for (int k=m-1;k>0;k--)
	{
		bool ok=true;
		REP(i,n) if (!ck(f[i],b[i],k)) { ok=false; break; }
		if (ok) continue;
		ret+=((int64{1})<<k);
		REP(i,n) ep(f[i],k);
		// REP(i,n) assert(ck(f[i],b[i],k));
	}
	cout<<ret<<endl;
	return 0;
}



Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

ll dp[55][55][2505];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, a;
	cin >> n >> a;
	vi x(n + 1);
	repn(i, 1, n + 1) cin >> x[i];
	ll ans = 0;
	repn(i, 1, n + 1){
		memset(dp, 0, sizeof(dp));
		dp[0][0][0] = 1;
		repn(j, 1, n + 1){
			rep(k, i + 1){
				rep(l, 2501) dp[j][k][l] += dp[j - 1][k][l]; //don't include it
				if(k){
					for(int l = 2500 - x[j]; l >= 0; l--){
						dp[j][k][l + x[j]] += dp[j - 1][k - 1][l];
					}
				}
			}
		}
		ans += dp[n][i][i * a];
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 59520
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n, k; cin >> n >> k;
        int pos, mn = INT_MAX;
        for (int x = 1; x <= n; ++x){
            int q; cin >> q;
            if (q < mn){
                mn = q;
                pos = x;
            }
        }
        int l = pos - 1;
        int lc = ceil(l * 1.00 / (k-1));
        int r = lc * (k-1) + 1;
        r = n - r;
        int rc = ceil(r * 1.00 / (k-1));
        cout << lc + rc << endl;
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  
  if(S == "Sunny") {
    cout << "Cloudy" << endl;
  } else if(S == "Cloudy") {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int A,B;
	char op;
	cin>>A>>op>>B;
	
	if(op=='+'){
		cout<<A+B<<endl;
	}
	else{
		cout<<A-B<<endl;
	}
	
    return 0;
}



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


int main() {
  string a,b;
  cin >> a >> b;
  int x=stoi(a+b);
  bool ans=false;
  for (int i=3;i*i<=x;i++){
    if (i*i==x){
      ans=true;
    }
  }
  if (ans){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

long long f (long long x) {
	long long ok = 0, ng = 1000000000;
	while (abs(ok - ng) > 1) {
		long long mid = (ok + ng) / 2;
		if (mid * mid < x) ok = mid;
		else ng = mid;
	}
	return ok;
}

long long solve (long long a, long long b) {
	if (a < b) swap(a, b);
	const long long k = f(a * b);
	long long ans = 2 * k;

	if (k * (k + 1) >= a * b) ans--;
	if ((a - 1) * (b + 1) >= a * b) ans--;
	if ((a + 1) * (b - 1) >= a * b) ans--;
	return ans;
}

int main() {
	int q;
	long long a, b;
	cin >> q;
	while (q--) {
		cin >> a >> b;
		cout << solve(a, b) << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
#define LL long long
#define INF 0x3f3f3f3f

const int MAXN = 1e5 + 5;
const LL MOD = 1e9+7;

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

    int n;
    cin >> n;
    int sum = 0;
    int nn = n;
    while(nn)
    {
        sum+=nn%10;
        nn = nn / 10;
    }
    if(n%sum== 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int main() {
  long N, C, K;
  cin >> N >> C >> K;
  vector<long> T(N);
  for(int i = 0; i < N; ++i) cin >> T[i];
  sort(T.begin(), T.end());
  int ans = 0;

  for(int i = 0; i < N;){
    ++ans;
    int start = i;
    while(i < N && T[i] - T[start] <= K && i - start < C) ++i;
  }
  cout << ans << "\n";

}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int main(){
  vector<int> ans;
  int a;
  double b,c;
  for(;;){
    if(scanf("%d,%lf,%lf",&a,&b,&c) == EOF) break;
    if(b/(c*c)>=25) ans.push_back(a);
  }
  for(int i=0; i<ans.size(); i++) cout <<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 1252