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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b,c,k; cin>>a>>b>>c>>k;
  ll tmp=k;
  k-=a;
  if(k<=0){
    cout<<1*tmp<<endl;
    return 0;
  }
  
  ll ans=1*a;
  k-=b;
  if(k<=0){
    cout<<ans<<endl;
    return 0;
  }
  
  cout<<ans-k<<endl;
  
}

Measured memory_bytes: 3640
n, T  = map(int, input().split())
c_t_list = [list(map(int, input().split())) for _ in range(n)]
mi = 1001
for c, t in c_t_list:
    if t <= T:
        mi = min(mi, c)
if mi == 1001:
    print("TLE")
else:
    print(mi)

Measured memory_bytes: 3060
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    X, t = MI()
    print(max(0,X-t))
if __name__ == '__main__':
    main()

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

H,W = 100,100
D = [["."]*100 for _ in [0]*50]+[["#"]*100 for _ in [0]*50]

c = 1
i = 1
j = 1
while c<B:
    D[i][j] = "#"
    c += 1
    j += 2
    if j>100:
        j-=100
        i+=2
c = 1
i = 51
j = 1
while c<A:
    D[i][j] = "."
    c += 1
    j += 2
    if j>100:
        j-=100
        i+=2

print(H,W)
for out in D:
    print("".join(out))

Measured memory_bytes: 3188
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    answer = 1
    last = A[0]
    diff = 0
    for i in range(1, N):
        if A[i] - last > 0:
            d = 1
        elif A[i] - last < 0:
            d = -1
        else:
            d = 0
        last = A[i]
        if diff == 0:
            diff = d
        elif d == 0:
            continue
        else:
            if diff == d:
                continue
            else:
                answer += 1
                diff = 0
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vii vector<pair<int, int> >
#define fi first
#define se second
#define ii pair<int, int> 
#define int long long
#define eb emplace_back

int a[200005], pf[200005];
signed main()
{
	int n, ans=LLONG_MAX;
	cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=n; i++) pf[i] = pf[i-1]+a[i];
	for(int i=2; i<=n-2; i++)
	{
		int ll = 1, rr = i-1;
		vii f, s;
		while(ll<rr) 
		{
			int mid = (ll+rr+1)/2;
			if(2*pf[mid]>pf[i]) rr=mid-1;
			else ll=mid; 
		}
		int lb=ll;
		ll=i+1, rr=n-1;
		while(ll<rr)
		{
			int mid = (ll+rr+1)/2;
			if(2*(pf[mid]-pf[i])>pf[n]-pf[i]) rr=mid-1;
			else ll=mid;
		}
		int rb = ll;
		for(int j=lb-10; j<=lb+10; j++)
		{
			for(int k=rb-10; k<=rb+10; k++)
			{
				if(j and j<i and k>i and k<n)
				{
					int t1 = pf[j],t2 = pf[i]-pf[j], t3 = pf[k]-pf[i], t4 = pf[n]-pf[k];
					int mn = min({t1, t2, t3, t4});
					int mx = max({t1, t2, t3, t4});
					ans=min(ans, mx-mn);
				}
			}
		}		
	}
	cout<<ans;
}


Measured memory_bytes: 6756
#include<stdio.h>
#include<string.h>

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[])
{
  int m,n,count=0;
  n = h2(getKey(str));
  for(m = h1(getKey(str)) ; count < M ; m+=n)
    {
      if(m >= M) m = m - M;
      if(strcmp(H[m],str) == 0) return 1;
      if(H[m][0] == '\0') return 0;
      count++;
    }
  return 0;
}

int insert(char str[])
{
  int m,n;
  
  n = h2(getKey(str));
  
  for(m = h1(getKey(str)) ; 1 ; m+=n)
    {
      if(m >= M) m = m - M;
      if(strcmp(H[m],str) == 0) break;
      if(H[m][0] == '\0')
	{
	  strcpy(H[m],str);
	  break;
	}
    }
  return 1;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ )
    {
      scanf("%s %s", com, str);
	
      if ( com[0] == 'i' )
	{
	  insert(str);
	}
      else
	{
	  if (find(str))
	    {
	      printf("yes\n");
	    }
	  else
	    {
	      printf("no\n");
	    }
	}
    }

  return 0;
}



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

bool is_prime(int x) {
	if (x % 2 == 0) {
		return x == 2;
	}
	for (int i = 3; i <= sqrt(x); i+=2) {
		if (x % i == 0) return false;
	}
	return true;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	while (!is_prime(n)) ++n;
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 3668
#ABC102C
N=int(input())
A=list(map(int, input().split()))
B=[0]*N
b=0
ans=0
for i in range(N):
    B[i]=A[i]-(i+1)
B_sorted=sorted(B)
if N%2==0:
    b=(B_sorted[int(N/2)]+B_sorted[int(N/2-1)])//2
else:
    b=(B_sorted[N//2])
for i in range(N):
    ans+=abs(A[i]-(b+i+1))
print(int(ans))

Measured memory_bytes: 26180
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    w = I()
    a = [LI(), LI()]
    a[1][0] += a[0][0]
    for i in range(1,w):
        a[0][i] += a[0][i-1]
        a[1][i] += max(a[1][i-1],a[0][i])

    return a[1][-1]


print(main())





Measured memory_bytes: 67052
#include <stdio.h>

#define SIZE 10010
#define MAXNUM 1000000
#define MINNUM -1000000

void m_m_s(int n, int *data){
    int max = MINNUM;
    int min = MAXNUM;
    long long int sum = 0;
    int i;
    for(i = 0; i < n; i++){
        if (max < data[i])
            max = data[i];
        if (min > data[i])
            min = data[i];
        sum += data[i];
    }
    printf("%d %d %lld\n", min, max, sum);
}

int main(void){
    int n, i;
    int data[SIZE];
    int *p = data;
    scanf("%d", &n);
    for(i = 0; i < n; i++)
        scanf("%d", &data[i]);
    m_m_s(n, p);

    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll 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 mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}
ll dp[100010][3];
ll a[100010][3];

void solve(long long N, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c)
{
}

int main()
{
    long long N;
    scanf("%lld", &N);

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                if (j == k)
                    continue;
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    cout << max(dp[N][2], max(dp[N][0], dp[N][1])) << endl;
    return 0;
}


Measured memory_bytes: 4992
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

// golangの正規表現置換だと間に合わない
// 累積和を使う

func main() {
	N, Q := nextInt(), nextInt()
	S := nextLine()
	T := make([]int, N)
	for i := 0; i < N-1; i++ {
		var cnt int
		if S[i:i+2] == "AC" {
			cnt = 1
		}
		T[i+1] = T[i] + cnt
	}
	for i := 0; i < Q; i++ {
		l, r := nextInt(), nextInt()
		fmt.Println(T[r-1] - T[l-1])
	}
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 5376
// ------------------------------------
// Date:2018/ 5/ 5
// Problem:/ / / b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int A, B, C, K;

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

  priority_queue< ll > a;
  REP(i, 3) {
    CIN(p);
    a.push(p);
  }
    
  cin >> K;

  REP(i, K) {
    ll tmp = a.top(); a.pop();
    tmp *= 2ll;
    a.push(tmp);
  }

  ll ans = 0ll;
  REP(i, 3) {
    ll tmp = a.top(); a.pop();
    ans += tmp;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N, Y;
    cin >> N >> Y;
    
    int res10000 = -1, res5000 = -1, res1000 = -1;
    
    for(int a = 0; a <= N; ++a){
        for(int b = 0; a + b <= N; ++b){
            int c = N - a - b;
            if(10000*a + 5000*b + 1000*c == Y){
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
            
        }
    }
    
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define llint long long 
#define inf 1000000000000000

using namespace std;

struct edge{
	llint to, cap, rev;
	edge(llint a, llint b, llint c){
		to = a, cap = b, rev = c;
	}
};

vector<edge> G[105];
bool used[105];

llint dfs(llint s, llint t, llint c)
{
	if(s == t) return c;
	used[s] = true;
	
	llint ret;
	for(llint i = 0; i < (llint)G[s].size(); i++){
		if(used[G[s][i].to] || G[s][i].cap == 0) continue;
		ret = dfs(G[s][i].to, t, min(c, G[s][i].cap));
		if(ret > 0){
			G[s][i].cap -= ret;
			G[ G[s][i].to ][ G[s][i].rev ].cap += ret;
			return ret;
		}
	}
	return 0;
}

llint N, S, T;
llint a[105], sum, psum;

void add_edge(llint s, llint t, llint c)
{
	G[s].push_back(edge(t, c, G[t].size()));
	G[t].push_back(edge(s, 0, G[s].size()-1));
}

int main(void)
{
	cin >> N;
	sum = psum = 0;
	for(llint i = 1; i <= N; i++){
		cin >> a[i];
		sum += a[i];
		a[i] *= -1;
		if(a[i] >= 0) psum += a[i];
	}
	
	S = 0, T = N+1;
	for(llint i = 1; i <= N; i++){
		for(llint j = 1; j <= N; j++){
			if(j % i == 0) add_edge(i, j, inf);
		}
	}
	
	for(llint i = 1; i <= N; i++){
		if(a[i] >= 0) add_edge(S, i, a[i]);
		else add_edge(i, T, -a[i]);
	}
	
	llint ans = 0, ret;
	while(1){
		for(llint i = S; i <= T; i++) used[i] = false;
		ret = dfs(S, T, inf);
		if(ret == 0) break;
		ans += ret;
	}
	
	cout << sum + (psum-ans) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
const double EPS = 1e-10;
typedef complex<double> P;
typedef pair<P,P> L;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
  }
}
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
 
bool intersectLL(const L &l, const L &m) {
  return abs(cross(l.S-l.F, m.S-m.F)) > EPS ||
         abs(cross(l.S-l.F, m.F-l.F)) < EPS;
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l.S - l.F, m.S - m.F);
  double B = cross(l.S - l.F, l.S - m.F);
  if (fabs(A) < EPS && fabs(B) < EPS) return m.F;
  return m.F + B / A * (m.S - m.F);
}
 
int main() {
  int n;
  while(cin >> n && n) {
    vector<L> v(n);
    int ans=1;
    for(int i=0; i<n; i++) {
      double x1,y1,x2,y2;
      cin >> x1 >> y1 >> x2 >> y2;
      v[i]=L(P(x1,y1),P(x2,y2));
      vector<P> p;
      for(int j=0; j<i; j++) {
        if(!intersectLL(v[i],v[j])) continue;
        P q=crosspoint(v[i],v[j]);
        if(q.real()>-100+EPS&&q.real()<100-EPS&&q.imag()>-100+EPS&&q.imag()<100-EPS) p.push_back(q);
      }
      sort(p.begin(),p.end());
      int c=p.size()?1:0;
      for(int j=1; j<p.size(); j++) {
        if(fabs(p[j-1].real()-p[j].real())<EPS&&fabs(p[j-1].imag()-p[j].imag())<EPS) continue;
        c++;
      }
      ans+=c+1;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3192
n = int(input())
li = list(map(int,input().split()))
ma = {}
for i,l in enumerate(li):
    if i+l+1 not in ma:
        ma[i+l+1] = 1
    else:
        ma[i+l+1] += 1
#print(ma)
ans = 0
for i,l in enumerate(li):
    j = i+1
    tmp = 0
    if j-li[i] in ma:
        tmp = ma[j-li[i]]
    if j-li[i] == li[i]+j:
        tmp -=1
    ans += tmp
print(ans)

Measured memory_bytes: 40436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll sum=0;
    map<string,ll> left;
    map<string,ll> right;
    rep(bi,bit(n)){
        string l,r;
        string ll,rr;
        rep(i,n){
            if(bi&bit(i)){
                l.pb(s[i]);
                r.pb(s[2*n-i-1]);
                //ll.pb('.');
                //rr.pb('.');
            }
            else{
                //l.pb('.');
                //r.pb('.');
                ll.pb(s[i]);
                rr.pb(s[2*n-i-1]);
            }
        }
      	l+='&';
      	r+='&';
        l+=ll;
        r+=rr;
        left[l]++;
        right[r]++;
    }
  	//for(auto x:right)cerr << x.F << endl;
  	//cerr << endl;
    for(auto x:left){
        sum+=x.S*right[x.F];
        //cerr << x.F << ' ' << x.S << ' ' << right[x.F] << endl;
    }
    cout << sum;

}

/*



 */



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

int main() {
	int A, B;
	cin >> A >> B;

	int large = 1;
	int small = 1;
	if (A > B) {
		large = A;
		small = B;
	}
	else {
		large = B;
		small = A;
	}

	// 大きい方を基準に走査

	long long int ans = large;
	
	while (1) {

		if (ans % small == 0) {
			break;
		}
		ans += large;
	}

	cout << ans;

	cin >> ans;
	return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

table = [False]*9

aaa1 = get_nums_l()
aaa2 = get_nums_l()
aaa3 = get_nums_l()
aaa = aaa1 + aaa2 + aaa3
n = int(input())
bbb = get_nums_n(n)

for b in bbb:
    for i,a in enumerate(aaa):
        if a == b:
            table[i] = True

check = [
    (0,3,6),
    (1,4,7),
    (2,5,8),
    (0,1,2),
    (3,4,5),
    (6,7,8),
    (0,4,8),
    (2,4,6)
]

for ch in check:
    for c in ch:
        if not table[c]:
            break
    else:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 38384
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n,q;
  string s;
  cin>>n>>s>>q;
  for(int i=0;i<q;i++){
    int k;
    cin>>k;
    int64_t d=0,m=0,dm=0;
    int64_t result=0;
    for(int si=0;si<s.size();si++){
      int trashed=si-k;
      if(trashed>=0){
        if(s[trashed]=='D'){
          dm-=m;
          d--;
        }else if(s[trashed]=='M'){
          m--;
        }
      }
      if(s[si]=='D'){
        d++;
      }else if(s[si]=='M'){
        dm+=d;
        m++;
      }else if(s[si]=='C'){
        result+=dm;
      }
    }
    cout<<result<<endl;
  }




  return 0;
}

Measured memory_bytes: 1948
#include <stdio.h>

int main(void){
	int m, f, r;
	char result;

	while(1){
	scanf("%d %d %d", &m, &f, &r);

	if(m == -1 && f == -1){
		if(f == -1 && r == -1){
			break;
		}
	}

	if(m == -1 || f == -1){
		result = 'F';
	}else if(m + f >= 80){
		result = 'A';
	}else if(m + f < 80 && m + f >= 65){
		result = 'B';
	}else if(m + f < 65 && m + f >= 50){
		result = 'C';
	}else if(m + f < 50 && m + f >= 30){
		result = 'D';
	if(r >= 50){
		result = 'C';
	}
	}else if(m + f < 30){
		result = 'F';
	}

	printf("%c\n", result);
	}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define N 300009
#define inf 2e16
#define pi pair<ll,ll>
#define pb push_back
using namespace std;
typedef long long ll;
void slv()
{
}
vector<int>adj[N];
bool vis[N];
int dis[N];
void vfs(int s)
{
    queue<int>q;
    q.push(s);
    dis[s]=0;
    vis[s]=1;
    while (!q.empty())
    {
        int u=q.front();
        q.pop();
        for(auto v : adj[u])
        {
            if(!vis[v])
            {
                vis[v]=1;
                dis[v]=dis[u]+1;
                q.push(v);
            }
        }
    }
    
}
int main()
{
    ll n,x;
    cin>>n>>x;
    vector<ll>a(n+1,0);
    for(ll i=1;i<=n;i++) cin>>a[i];
    ll ans=0LL;
    for(ll i=1;i<=n;i++)
    {
        ll s=a[i]+a[i-1];
        if(s>x)
        {
            ans += s-x;
            a[i] = min(a[i],a[i]-(s-x));
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11192
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2);
    d=(d*d);
    if(b&1)
        d=(d*a);
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;cin>>n;
    int p=26;
    int len=1;
    int count=0;
    int N=n;
    for(;;len++)
    {
        count+=p;
        if(count >=n)
            break;
        N-=p;
        p*=26;
    }
    int pos=len;
    string ans;
    n=N;
    // cout<<n<<endl;
    for(int i=pos;i>=1;i--)
    {
        if(i==1)
        {
            char ch='a'+n-1;
            ans+=ch;
            break;
        }
        for(char ch='a';ch<='z';ch++)
        {
            int p=power(26,i-1);
            if(p<n)
                n-=p;
            else
            {
                ans+=ch;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
#!/usr/bin/env python

def f(n: int) -> int:
    """
    >>> f(1)
    0
    >>> f(2)
    2
    >>> f(869121)
    2511445
    """
    return (10 ** n - 9 ** n - 9 ** n + 8 ** n) % (10 ** 9 + 7)


if __name__ == '__main__':
    n = int(input())
    print(f(n))

Measured memory_bytes: 11120
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,A = map(int,read().split())

"""
最適解の構造を観察する。
・最後のトドメ以外に関しては、「コストn+A払って倍率をn倍する」
・nとして現れるのは2種まで
・結局、nをx回、n+1をy回という形で、パラメータn,x,yで書ける（x\geq 1とする）
・最終枚数は、n^x(n+1)^y、これがN以上になって欲しい
・コストは、A(x+y-1) + nx + (n+1)y
・x+yを固定するごとに解く
"""

def F(K):
    # x+y = K
    # n^K <= N < (n+1)^K
    n = int(N**(1/K))
    while (n-1)*n**(K-1) > N:
        n -= 1
    while n * (n+1)**(K-1) < N:
        n += 1
    # n^x(n+1)^y >= N, yを最小にとる。面倒なので全探索
    for y in range(K):
        x = K-y
        if n**x * (n+1)**y >= N:
            break
    cost = A*(K-1) + n*x + (n+1)*y
    return cost

answer = min(F(K) for K in range(1,50))
print(answer)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
int main(){
  ll n;
  cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  sort(all(a));
  ll ans=a[0];
  for(int i=1;i<n;i++){
    ans=gcd(a[i],ans);
  }
  COUT(ans);
}

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

// ?????????????????????????????????????????°
int selectionSort(int A[], int N) {
  int sw = 0;
  for ( int i = 0; i < N; i++ ) {
    int minj = i;
    for ( int j = i; j < N; j++ ) {
      if ( A[j] < A[minj] ) minj = j;
    }
    if (i != minj) {
      swap(A[i], A[minj]);
      sw++;
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for ( int i = 0; i < N; i++ ) cin >> A[i];

  sw = selectionSort(A, N);

  for (int i = 0; i < N; i++ ) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl << sw << endl;

  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
#define inf 1072114514
 
int dx4[4]={1,-1,0,0};
int dy4[4]={0,0,1,-1};
 
#define size 16777216
 
int deque[size],fpt=size/2,bpt=(size/2)+1;
 
void push(int v,int isbk){
  if(isbk!=0){deque[bpt]=v;bpt++;}
  else{deque[fpt]=v;fpt--;}
}
 
int pop(int isbk){
  int r;
  if(isbk!=0){bpt--;r=deque[bpt];deque[bpt]=inf;}
  else{fpt++;r=deque[fpt];deque[fpt]=-inf;}
  return r;
}
 
int main(){
  int h,w;
  int sh,sw;
  int th,tw;
  char s[1024][1024];
  int dl[1024][1024];
  scanf("%d%d%d%d%d%d",&h,&w,&sh,&sw,&th,&tw);
  for(int i=0;i<=w+1;i++){s[0][i]='.';s[h+1][i]='.';}
  for(int i=1;i<=h;i++){
    s[i][0]='.';
    scanf("%s",&s[i][1]);
    s[i][w+1]='.';
    for(int j=1;j<=w;j++){dl[i][j]=inf;}
  }
  push(1024*sh+sw,0);
  dl[sh][sw]=0;
  while(fpt+1!=bpt){
    int v,ci,cj,ni,nj;
    v=pop(0);
    ci=(v/1024);cj=(v%1024);
    //printf("%d %d : %d\n",ci,cj,dl[ci][cj]);
    if(ci==th&&cj==tw){printf("%d\n",dl[th][tw]);return 0;}
    for(int k=0;k<4;k++){
      ni=ci+dx4[k];nj=cj+dy4[k];
      if(s[ni][nj]=='#'){continue;}
      if(dl[ci][cj]<dl[ni][nj]){
        dl[ni][nj]=dl[ci][cj];
        push(1024*ni+nj,0);
      }
    }
    for(int i=-2;i<=2;i++){
      for(int j=-2;j<=2;j++){
        ni=ci+i;nj=cj+j;
        if(s[ni][nj]=='#'){continue;}
        if(dl[ci][cj]+1<dl[ni][nj]){
          dl[ni][nj]=dl[ci][cj]+1;
          push(1024*ni+nj,1);
        }
      }
    }
  }
  puts("-1");
  return 0;
}

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

int main() {
  int N, A = 0, maxv = 0;
  cin >> N;
  string S;
  cin >> S;
  for(int i = 0; i < N; i++){
    if(S.at(i) == 'I'){
      A++;
    }
    else{ A--; }
    maxv = max(A, maxv);
  }
  cout << maxv << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()

int main(){
    int64_t n,a,b,s,t;
    cin>>n>>a>>b;
    s=n%(a+b);
    s>a ? t=a : t=s;
    cout<<n/(a+b)*a+t;
}



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

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

    bool flag = true;
    rep(i,n){
        int a;
        cin >> a;

        if(a % 2 == 0){
            if(a % 3 == 0 or a % 5 == 0) continue;
            else {
                flag = false;
                break;
            }
        }
    }
    if(flag) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n, p, num;
	int point[100] = { 0 };
	int target[100] = { 0 };
	cin >> n >> p;
	for (int i = 0; i < p; i++) {
		cin >> target[i];
	}
	for (int k = 0; k < p; k++) {
		for (int j = 0; j < n; j++) {
			cin >> num;
			if (num == target[k]) point[j]++;
			else point[target[k]-1]++;
		}
	}
	for (int s = 0; s < n; s++) {
		cout << point[s] << endl;
	}
}

Measured memory_bytes: 3116
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush


h,w,m=[int(x) for x in input().split()]

#defaultdictにすることにより後に使うmax関数のコストを削減
hcnt=defaultdict(int)
wcnt=defaultdict(int)
#存在チェックのアクセスがリストで持たせるより高速
#リストは突っ込めないので注意(hashabeのみOK)
bomb=defaultdict()
#O(H)
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb[(hi,wi)]=True

#O(H)
hmax=max(hcnt.values())
wmax=max(wcnt.values())

#O(H)
hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

#O(H**2)
ofst=-1
for i in hidx:
    for j in widx:
        if not bomb.get((i,j)):
            ofst=0
            break
                
print(hmax+wmax+ofst)


Measured memory_bytes: 237000
#include <iostream>

using namespace std;

int main(){
  int h, w;

  cin >> h >> w;

  int x[100001], y[100001];

  char a[h][w];

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> a[i][j];
      if(a[i][j] =='#'){
        x[i] = 1;
      }
    }
  }

  for(int j = 0; j < w; j++){
    for(int i = 0; i < h; i++){
      if(a[i][j] == '#'){
         y[j] = 1;
      }
    }
  }

  for(int i = 0; i < h; i++){
    if(x[i] == 1){
      for(int j = 0; j < w; j++){
        if(y[j] == 1){
          cout <<a[i][j];
        }
      }

    cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int m;
void bfs(int x, VV& tree, vector<bool>& visited, ll& ans, VL& mul) {
	queue<int> que;
	que.push(x);
	visited[x] = true;
	while (!que.empty()) {
		int X = que.front();
		que.pop();
		visited[X] = true;
		ans *= mul[X];
		ans %= MOD;
		mul[X] = (X == 0) ? m : m - 1;
		for (auto c : tree[X]) {
			if (!visited[c]) {
				que.push(c);
				mul[X]--;
				mul[c] = mul[X];
				visited[c] = true;
			}
		}
	}
}
int main() { // 問題文はしっかり読め!!!
	int n;
	cin >> n >> m;
	VV G(n);
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b); G[b].push_back(a);
	}
	ll ans = 1;
	VL mul(n, m);
	vector<bool> visited(n, false);
	bfs(0, G, visited, ans, mul);
	cout << ans << endl;
	return 0;
}

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

signed main(void)
{
	string s, t;
	int n;

	cin >> s;
	n = s.size();
	t = s;
	reverse(t.begin(), t.end());
	rep(i, n)
	{
		if (t[i] == 'p')
			t[i] = 'q';
		else if (t[i] == 'q')
			t[i] = 'p';
		else if (t[i] == 'b')
			t[i] = 'd';
		else if (t[i] == 'd')
			t[i] = 'b';
	}
	if (s == t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(a, max(b, c)) - min(a, min(b, c));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a; //nenrei
  int b;//ryokin
  
  cin>>a>>b;
  if (a>=13){
    cout<<b<<endl;}
  
  else if (a>=6){
    cout<<b/2<<endl;}
  
  else{cout<<0<<endl;}
  
}
    

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

int main() {
  int h,w,i,j;
  cin>>h>>w;
  char a[h][w],counth[h],countw[w],count=0;
  
  for(i=0;i<h;i++){
    counth[i]=0;
    for(j=0;j<w;j++){
      cin>>a[i][j];
      countw[j]=0;
    }
  }
    
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(a[i][j]=='.')
        count++;
    }
    if(count==w)
      counth[i]=1;
    count=0;
  }
    

  for(i=0;i<w;i++){
    for(j=0;j<h;j++){
      if(a[j][i]=='.')
        count++;
    }
    if(count==h)
      countw[i]=1;
    count=0;
  }
      
      for(i=0;i<h;i++){
        for(j=0;j<w;j++){
          if(counth[i]!=1 && countw[j]!=1)
            cout<<a[i][j];
        }
        if(counth[i]!=1)
          cout<<endl;
      }

}

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

int main(){
	int a,b,k;
  cin >> k >> a >> b;
  for(int i=a;i<=b;i++){
    if(i % k ==0){
    	cout << "OK" << endl;
      	break;
    }else if(i==b && b % k !=0){
    	cout << "NG" << endl;
    }
  }
}

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

typedef string::iterator State;
class ParseError {};
int op_cnt;

int ParseExpression(State &itr);

int ParseNumber(State &itr) {
  int ret = 0;
  if (*itr != '0' && *itr != '1') throw ParseError();

  while (*itr == '0' || *itr == '1') {
    ret = ret*2 + (*itr-'0');
    if (ret >= 1024) throw ParseError();
    itr++;
  }
  return ret;
}

int ParseFactor(State &itr) {
  if (*itr == '(') {
    itr++;
    int op_cnt_ = op_cnt;
    int ret = ParseExpression(itr);
    if (op_cnt_ == op_cnt) throw ParseError();
    op_cnt = op_cnt_;
    if (*itr != ')') throw ParseError();
    itr++;
    return ret;
  }
  
  //op_cnt++;
  return ParseNumber(itr);
}

int ParseTerm(State &itr) {
  int ret = ParseFactor(itr);
  
  while (1) {
    if (*itr == '*') {
      itr++;
      ret *= ParseFactor(itr);
      if (ret >= 1024) throw ParseError();
      op_cnt++;
    } else break;
  }

  return ret;
}

int ParseExpression(State &itr) {
  int ret = ParseTerm(itr);
  while (1) {
    if (*itr == '+') {
      itr++;
      ret += ParseTerm(itr);
      if (ret >= 1024) throw ParseError();
      op_cnt++;
    } else if (*itr == '-' ) {
      itr++;
      ret -= ParseTerm(itr);
      if (ret < 0) throw ParseError();
      op_cnt++;
    } else break;
  }
  return ret;
}

int n;
int ans = -1;
char cs[] = "+-01*().";
char buf[114514];
string s;
vector<int> pos;

void rec(int idx) {
  if (n <= idx) {
    auto itr = s.begin();
    try {
      int ret = ParseExpression(itr);
      if (itr != s.end()) throw ParseError();
      ans = max(ans, ret);
    } catch (const ParseError &e) {}
    return;
  }

  for (int i=0; i<8; i++) {
    s[pos[idx]] = cs[i];
    rec(idx+1);
  }
}

int main() {
  scanf("%s", buf);
  s = buf;
  while (1) {
    int idx = s.find('.');
    if (idx == string::npos) break;
    pos.emplace_back(idx);
    s[idx] = '$';
    n++;
  }

  ans = -1;
  rec(0);
  printf("%d\n", ans);
}

Measured memory_bytes: 3400
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

const ll INF = 5e15;
const ll MOD = 1e9 + 7;

struct B {
    ll w, s, v;
};

vector<ll> dp(2 * 1e4 + 10);

int main(){
    ll N;
    cin >> N;
    vector<B> V(N);
    for(auto &e : V) cin >> e.w >> e.s >> e.v;
    sort(V.begin(), V.end(), [](const B &a, const B &b){ return a.w + a.s < b.w + b.s; });
    for(const B &e : V){
        auto tmp = dp;
        for(ll W = 0; W + e.w < dp.size() && W <= e.s; W++) tmp[W + e.w] = max(tmp[W + e.w], dp[W] + e.v);
        dp = move(tmp);
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<double> A(N);
    double up = 1.0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        up *= A[i];
    }
    double down = 0.0;
    for (int i = 0; i < N; ++i) {
        down += up / A[i];
    }
    cout << fixed << setprecision(6);
    cout << up / down << endl;
    return 0;
}

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

#define N 100001

using namespace std;

const int MOD = 1e9 + 7;
int n;
vector<int> g[N + 1];
long long dp[N + 1][2];

long long solve(int u, int color, int p)
{
	if (dp[u][color] != -1)
		return dp[u][color];
	long long ans = 1;
	for (int v : g[u])
	{
		if (v == p)
			continue;
		if (color == 1)
			ans = (ans * solve(v, 0, u)) % MOD;
		else
			ans = (ans * (solve(v, 0, u) + solve(v, 1, u)) % MOD) % MOD;
	}
	return dp[u][color] = ans;
}

int main()
{
	cin >> n;
	int x, y;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	memset(dp, -1, sizeof(dp));
	cout << (solve(1, 0, 0) + solve(1, 1, 0)) % MOD << endl;
	return 0;
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
 
using namespace std;
 
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
 
void d_err() {
    cerr << endl;
}
 
template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}
 
template <typename T>
void print(T x) {
    cout << x << "\n";
}
 
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;
 
ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll  a, b, c, d;
    cin >> a >> b >> c >> d;
 
    print(max(a * c, max(a * d, max(b * c, b * d))));
    
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int a,b,c,m,n,sum=0;
int main()
{
	cin>>a>>b>>c>>m>>n;
	int k,l;
	l=min(m,n);
	k=max(m,n);
	if(c<(a+b)/2) 
	  {
	    sum+=2*c*l;
	    if(m>n) sum+=(m-n)*a;
	      else sum+=(n-m)*b;
	  }
	  else sum=a*m+b*n;
	if(c*2*k<sum) sum=c*2*k;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int A, B, C;

void _main() {
    cin >> A >> B >> C;
    cout << min(C, B / A) << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 19, Mod = 1e9 + 7;
int n, m, q, A[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    printf("%d %d %d\n", x, y, z);
    return 0;
}

Measured memory_bytes: 256
#入力
H,W=map(int,input().split())
h,w=map(int,input().split())
#計算
B_cells=h*W+w*H-h*w #黒色のマス目の数
W_cells=H*W-B_cells #白色のマス目の数
#出力
print(W_cells)

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

int main(){
    int N;
    cin >>N;
    int A[N];
    for(int i =0; i < N; i++){
        cin >> A[i];
    }
    sort(A,A+N);	
    // int temp = 0;
    // for(int i =0; i < N - 1; i++){
    //     for(int j = i + 1; j < N; j++){
    //         if(abs(A[i]-A[j]) >temp) temp =abs(A[i]-A[j]);
    //     }
    // }
    cout << A[N - 1] - A[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()





int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n), p(n);
    rep(i, n) {
        cin >> x[i] >> y[i] >> p[i];
    }
    vector<vector<int>> cost_vert(1<<n, vector<int>(n));
    vector<vector<int>> cost_hori(1<<n, vector<int>(n));
    rep (i, 1 << n) {
        vector<int> vert_lines;
        rep (j, n) {
            if ((1<<j) & i) {
                vert_lines.push_back(x[j]);
            }
        }
        vert_lines.push_back(0);
        vert_lines.push_back(-1e9);
        vert_lines.push_back(1e9);
        sort(all(vert_lines));
        rep (j, n) {
            auto it = lower_bound(all(vert_lines), x[j]);
            int r = *it;
            int q = *(--it);
            cost_vert[i][j] = min(abs(r-x[j]), abs(x[j]-q));
        }
    }
    rep (i, 1 << n) {
        vector<int> hori_lines;
        rep (j, n) {
            if ((1<<j) & i) {
                hori_lines.push_back(y[j]);
            }
        }
        hori_lines.push_back(0);
        hori_lines.push_back(-1e9);
        hori_lines.push_back(1e9);
        sort(all(hori_lines));
        rep (j, n) {
            auto it = lower_bound(all(hori_lines), y[j]);
            int r = *it;
            int q = *(--it);
            cost_hori[i][j] = min(abs(r-y[j]), abs(y[j]-q));
        }
    }
    vector<int> pow3(16, 1);
    rep (i, 15) {
        pow3[i+1] = pow3[i] * 3;
    }
    vector<ll> ans(n+1, 1e12);
    rep (i, pow3[n]) {
        int vert_idx = 0;
        int hori_idx = 0;
        int i_cp = i;
        int line_ctr = 0;
        rep (j, n) {
            if (i_cp % 3 == 0) {
                vert_idx += (1<<j);
                line_ctr++;
            } else if (i_cp % 3 == 1) {
                hori_idx += (1<<j);
                line_ctr++;
            }
            i_cp /= 3;
        }
        ll res = 0;
        rep (j, n) {
            res += 1ll * min(cost_vert[vert_idx][j], cost_hori[hori_idx][j]) * p[j];
        }
        chmin(ans[line_ctr], res);
    }
    rep (i, n+1) {
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 9720
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << setprecision(16);
    int n; cin >> n;
    vector<int> a(n),b(n);
    rep(i,n) cin >> a[i];
    b = a;
    sort(a.begin(), a.end());
    int x = a[n/2], y = a[n/2-1];
    for(int i: b){
        if(i <= y) cout << x << endl;
        else cout << y << endl;
    }
    return 0;
}


Measured memory_bytes: 3712