akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")
# define int long long

using namespace std;

const int N = 3e5 + 7;
const int mod = 1e7;

int dp[N], h[N];

int32_t main() {
    speed;
    int n;
    cin >> n;
    for ( int i = 1; i <= n; i++ ) {
        cin >> h[i];
        dp[i] = 1e12;
    }
    dp[1] = 0;
    for ( int i = 1; i <= n; i++ ) {
        dp[i + 1] = min( dp[i + 1], dp[i] + abs( h[i] - h[i + 1] ) );
        dp[i + 2] = min( dp[i + 2], dp[i] + abs( h[i] - h[i + 2] ) );
    }
    cout << dp[n];
}


Measured memory_bytes: 5176
#include <iostream>
#include <algorithm>

using namespace std;

bool mx[33][33];
bool my[33][33];

bool check(int y, int x){
  if(y<0 || y>=33) return false;
  if(x<0 || x>=33) return false;
  return true;
}

void solve(){
  int x = 3;
  int y = 1;
  int dx = 1, dy = 1;
  while(1){
    int ny = y + dy, nx = x + dx;
    if(!check(ny, nx)) break;
    if(ny == 1 && nx == 3){
      y = 1;
      x = 3;
      break;
    }
    y = ny;
    x = nx;
    if(y>=2){
      if(my[y-2][x]) dx *= -1;
    }
    if(x>=2){
      if(mx[y][x-2]) dy *= -1;
    }
  }
  cout << x*25 << ' ' << y*25 << endl;
}

main(){
  int n;
  while(cin >> n){
    if(n == -1) break;
    for(int i=0;i<33;i++){
      for(int j=0;j<33;j++){
        mx[i][j] = my[i][j] = false;
      }
    }
    for(int i=0;i<n;i++){
      char c;
      int a, b;
      cin >> c >> a >> b;
      if(c == 'x') mx[b*4][a*4] = true;
      else my[b*4][a*4] = true;
    }
    solve();
  }
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int a, b, m; cin >> a >> b >> m;
    vector<int> A(a), B(b);
    int mnA = 2e9, mnB = 2e9;
    for (int i = 0; i < a; i++) {
        cin >> A[i];
        mnA = min(mnA,A[i]);
    }
    for (int i = 0; i < b; i++) {
        cin >> B[i];
        mnB = min(mnB,B[i]);
    }
    int ans = mnA+mnB;
    for (int i = 0; i < m; i++) {
        int x, y, c; cin >> x >> y >> c;
        --x;
        --y;
        int tr = A[x] + B[y] - c;
        ans = min(ans,tr);
    }
    cout << ans << endl;
}



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int main() {
    ll a,b,q;
    cin>>a>>b>>q;
    vll s;
    vll t;
    s.push_back(-100000000000000);
    t.push_back(-100000000000000);
    rep(i,a){
        ll ss;
        cin>>ss;
        s.push_back(ss);
    }
    rep(i,b){
        ll tt;
        cin>>tt;
        t.push_back(tt);
    }
    s.push_back(10000000000000);
    t.push_back(10000000000000);
    rep(i,q){
        ll x;
        cin>>x;
      
        auto indexs=s.begin();
        auto indext=t.begin();


        auto index1=lower_bound(all(s),x);
        ll x1=s[index1-s.begin()];
        ll x2=s[index1-1-s.begin()];
        auto index12=lower_bound(all(t),x1);
        auto index22=lower_bound(all(t),x2);
        ll ans12=min(abs(x1-t[index12-indext]),abs(x1-t[index12-1-indext]));
        ll ans22=min(abs(x2-t[index22-indext]),abs(x2-t[index22-1-indext]));

        ll ans1=min(abs(x-x1)+ans12,abs(x-x2)+ans22);

        auto index2=lower_bound(all(t),x);
        ll x3=t[index2-indext];
        ll x4=t[index2-1-indext];
        auto index33=lower_bound(all(s),x3);
        auto index44=lower_bound(all(s),x4);
        ll ans33=min(abs(x3-s[index33-indexs]),abs(x3-s[index33-1-indexs]));
        ll ans44=min(abs(x4-s[index44-indexs]),abs(x4-s[index44-1-indexs]));

        ll ans2=min(abs(x-x3)+ans33,abs(x-x4)+ans44);

        ll ans=min(ans1,ans2);
        cout<<ans<<endl;

    }


    return 0;
}

Measured memory_bytes: 3060
import java.util.*;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int K = sc.nextInt();
        int R = sc.nextInt();
        int S = sc.nextInt();
        int P = sc.nextInt();
        String T = sc.next();
        int[] j = new int[K];
        char[] k = new char[K];
        char[] t = new char[N];

        for(int i=0; i<K; i++){
            j[i] = 0;
        }

        for(int i=0; i<N; i++){
            if(i<K){
                t[i] = T.charAt(i);
                if(t[i]=='r'){
                    j[i] += P;
                    k[i] = 'p';
                }
                else if(t[i]=='s'){
                    j[i] += R;
                    k[i] = 'r';
                }
                else{
                    j[i] = S;
                    k[i] = 's';
                }
            }
            else{
                t[i] = T.charAt(i);
                if(t[i]=='r'){
                    if(k[i%K]!='p'){
                        j[i % K] += P;
                        k[i % K] = 'p';
                    }
                    else{
                        k[i % K] = 'a';
                    }
                }
                else if(t[i]=='s'){
                    if(k[i%K]!='r'){
                        j[i % K] += R;
                        k[i % K] = 'r';
                    }
                    else{
                        k[i % K] = 'a';
                    }
                }
                else{
                    if(k[i%K]!='s'){
                        j[i % K] += S;
                        k[i % K] = 's';
                    }
                    else{
                        k[i % K] = 'a';
                    }
                }
            }
        }
        int ans = 0;
        for(int i=0; i<K; i++){
            ans += j[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27884
import math
from numba import jit
import numpy as np

@jit
def solve():
    
    r,c,k = map(int,input().split())

    value = np.zeros((r,c), dtype=np.int64)
    for i in range(k):
        r_t,c_t,v_t = map(int,input().split())
        value[r_t-1][c_t-1] = v_t

    dp = np.zeros((r,c,4), dtype=np.int64)
    dp[0][0][0] = 0

    for i in range(r):
        for j in range(c):
            for m in range(4):
                if i + 1 < r:
                    dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][m])
                if j + 1 < c:
                    dp[i][j+1][m] = max(dp[i][j+1][m],dp[i][j][m])
                if value[i][j] != 0 and m < 3:
                    if i + 1 < r:
                        dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][m]+value[i][j])
                    if j + 1 < c:
                        dp[i][j+1][m+1] = max(dp[i][j+1][m+1],dp[i][j][m]+value[i][j])

    for m in range(2,-1,-1):
        dp[r-1][c-1][m+1] = max(dp[r-1][c-1][m+1],dp[r-1][c-1][m]+value[r-1][c-1])
    return max(dp[r-1][c-1])

print(solve())

Measured memory_bytes: 479788
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    N,M = map(int,input().split())
    H = list(map(int,input().split()))
    G = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    ans = 0
    for i in range(N):
        flag = True
        for e in G[i]:
            if H[e] >=  H[i]:
                flag = False
                break
        if flag:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main() 

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

int main(){
	int N;
	cin>>N;
	int h[N+1]={0};
	int cost[N+1]={0};
	for(int i=1; i<=N; i++){
		cin>>h[i];
	}
	cost[1] = 0;
	cost[2] = abs(h[2] - h[1]);
	for(int i=3; i<=N; i++){
		cost[i] = std::min(cost[i-1] + abs(h[i] - h[i-1]), cost[i-2] +  abs(h[i] - h[i-2]));
	}
	cout<<cost[N];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool solve(long double mid, ll n, ll a[], ll k){
  bool ok=0;
  for(int i=0; i<n; ++i){
    ll req=a[i]/mid;
    k-=req;
  }
  if(k>=0) return false;
  else return true;
}
int main()
{
  ll n, k; cin >> n >> k;
  ll a[n];
  for(int i=0; i<n; ++i) cin >> a[i];
  sort(a,a+n);
  if(k==0){
    cout << a[n-1] << "\n";
    return 0;
  }
  long double lo=0, hi=1e12;
  int count=0;
  while(1){
    ++count;
    if(count==150) break;
    long double mid=lo+(hi-lo)/2;
    if(mid==0) continue;
    //cout << lo << " " << hi << " " << mid << " " << solve(mid,n,a,k) << "\n";
    if(solve(mid,n,a,k)) lo=mid;
    else hi=mid;
  }
  cout << (ll)ceil(lo) << endl;
}

Measured memory_bytes: 5156
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use itertools::Itertools;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let s: String = read!();
    println!("{}", s.chars().filter(|c| *c == '2').count());
}

Measured memory_bytes: 2104
#include <iostream>
#include <cstdio>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vec vector
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll n,m,ans,buf=0;
	string s = "Yes";

	cin >> n >> m;

	vector<ll> a(m);

	forll(i, 0, m)
		cin >> a[i];
	   
	forll(i, 0, m)
		buf += a[i];

	ans = max((ll)-1, n - buf);

	cout << ans << "\n";
}

Measured memory_bytes: 3680
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		
		if (n == 1) {
			pr.println("Hello World");
		} else {
			int a = sc.nextInt();
			int b = sc.nextInt();

			pr.println(a + b);
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 22736
#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const LL N=100005,mo=1e9+7;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int main()
{
	int n=read(),ans=0;
	for(int i=1;i<=n;i++){
		int cnt=0;
		for(int j=1;j<=i;j++)
		  if(i%j==0) cnt++;
		if(cnt==8&&i%2==1) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    int a1 , a2 , a3;
    scanf( "%d%d%d" , &a1 , &a2 , &a3 );
    if( a1 + a2 + a3 >= 22 ) puts( "bust" );
    else puts( "win" );

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

constexpr int MAXN = 100;
int V[MAXN][MAXN];
int D[MAXN];
int F[MAXN];

template<int STACK_SIZE, typename T = int>
class Stack {

public:
    Stack() {};

    void Push(T val) {
        if (top_ < STACK_SIZE) {
            stack_[top_++] = val;
        }else{
            std::cerr << "Stack over flow..." << std::endl;
            exit(-11);
        }
    };
    bool Pop() {
        if (top_ > 0) {
            stack_[--top_];
            return true;
        }
        return false;
    };

    T Top() {
        return stack_[top_ - 1];
    }

    int Size() {return top_;}


private:
    int max_size_ = STACK_SIZE;
    int top_ = 0;
    T stack_[STACK_SIZE];
};

Stack<MAXN, int> S;

int main() {

    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        int id, e_num;
        std::cin >> id >> e_num;
        for (int j = 0; j < e_num; j++) {
            int t;
            std::cin >> t;
            V[id - 1][t - 1] = 1;
        }
    }
    int cnt = 0;
    for (int t = 0; t < n; t++) {
        if (D[t] == 0) {
            D[t] = ++cnt;
            S.Push(t);
            while (S.Size()) {
                for (int i = 0; i < n; i++) {
                    if ((V[S.Top()][i] == 1) && (D[i] == 0)) {
                        S.Push(i);
                        D[i] = ++cnt;
                        break;
                    }
                    if (i == n - 1) {
                        F[S.Top()] = ++cnt;
                        S.Pop();
                    }
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        std::cout << i + 1 << " " << D[i] << " " << F[i] << std::endl;
    }

}


Measured memory_bytes: 3152
#include <iostream>
typedef long long in;
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    in a,b,diff,h[123456],mid,l,r,temp,t=0;
    int n;
    cin>>n>>a>>b;
    diff=a-b;
    l=1; r=10e9+10;
    in res=r;
    for (int i=0;i<n;i++) cin>>h[i];
    while (l<=r){
        mid = (l+r)>>1;
        t=0;
        for (int i=0;i<n;i++)
            {
                temp = h[i]-b*mid;
                if (temp>=0) {t+=temp/diff;
                        if (temp%diff!=0) t++;
                }
            }
        if (t>mid) l=mid+1;
        else r=mid-1,res=mid;
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, X;
    cin >> K >> X;
    int s = X - K + 1, e = X + K - 1;
    for (int i = s; i <= e; i++) {
        cout << i << " ";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


struct topological_sort{
    const int V;
    vector<vector<int>> board;
    vector<int> into,list;
    vector<bool> visited;
    topological_sort(int v)
        :V(v)
        ,into(v,0)
        ,visited(v,false)
        {
            board.assign(v,vector<int>());
        }
    // 入力
    void add(int from,int to){
        board[from].push_back(to);
        into[to]++;
    }
    // トポロジカルソート
    void build(){
        for(int i=0;i<V;i++){
            if(into[i]==0&&!visited[i]){
                queue<int> q;
                q.push(i);
                while(q.size()){
                    int from=q.front(); q.pop();
                    list.push_back(from);
                    visited[from]=true;
                    for(int to:board[from]){
                        into[to]--;
                        if(into[to]==0&&!visited[to]){
                            q.push(to);
                        }
                    }
                }
            }
        }
    }
    // 取得
    vector<int> get(){
        return list;
    }
};
int main(){
    int V,E; cin>>V>>E; E+=V-1;
    topological_sort graph(V);
    vector<vector<int>> bboard(V);
    while(E--){
        int s,t; cin>>s>>t;
        graph.add(--s,--t);
        bboard[t].push_back(s);
    }
    graph.build();
    vector<int> l=graph.get();
    int used[V]={};
    int ans[V];
    rep(i,V){
        if(i==0){
            ans[l[i]]=-1;
            used[l[i]]=1;
        }else{
            int depth=0;
            for(int from:bboard[l[i]]){
                if(used[from]){
                    if(depth<used[from]){
                        depth=used[from];
                        ans[l[i]]=from;
                    }
                }
            }
            used[l[i]]=depth+1;
        }
    }
    rep(i,V){
        cout<<ans[i]+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 13820
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int rec(vector<P> a,vector<P> b){
  if(a.size()!=b.size())return 0;
  for(int i=0;i<a.size();i++){
    if(a[i].second-a[0].second!=b[i].second-b[0].second)return 0;
    if(a[i].first-a[0].first!=b[i].first-b[0].first)return 0;
  }
  return 1;
}

int main(){
  int n;
  while(cin>>n,n){
  vector<P> v[55];
  for(int i=0;i<=n;i++){
    int m;
    cin>>m;
    for(int j=0;j<m;j++){
      int x,y;
      cin>>x>>y;
      v[i].push_back(P(x,y));
    }
  }
  vector<P> t[8];
  int s=v[0].size();
  for(int i=0;i<s;i++){
    int x=v[0][i].first;
    int y=v[0][i].second;
    t[0].push_back(P(x,y));
    t[1].push_back(P(-x,-y));
    t[2].push_back(P(y,-x));
    t[3].push_back(P(-y,x));
    x=v[0][s-1-i].first;
    y=v[0][s-1-i].second;
    t[4].push_back(P(x,y));
    t[5].push_back(P(-x,-y));
    t[6].push_back(P(y,-x));
    t[7].push_back(P(-y,x));
  }
  for(int i=1;i<=n;i++){
    int f=0;
    for(int j=0;j<8;j++){
      if(rec(v[i],t[j]))f=1;
    }
    if(f)cout<<i<<endl;
  }
  cout<<"+++++"<<endl;
}
  return 0;
  
}



Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c; cin >> a >> b >> c;
	if(a == b && a != c) return cout << "Yes\n", 0;
	if(a == c && a != b) return cout << "Yes\n", 0;
	if(c == b && a != c) return cout << "Yes\n", 0;
	cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main() {

	string input;
	int ans = 0;

	cin >> input;

	if (input == "SUN")ans = 7;
	else if (input == "MON")ans = 6;
	else if (input == "TUE")ans = 5;
	else if (input == "WED")ans = 4;
	else if (input == "THU")ans = 3;
	else if (input == "FRI")ans = 2;
	else if (input == "SAT")ans = 1;

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
N = int(input())
hs = list(map(int, input().split()))

INF = 10 ** 10

dp = [INF] * N
dp[0] = 0
dp[1] = abs(hs[1] - hs[0])

for i in range(2, N):
    dp[i] = min(dp[i - 1] + (abs(hs[i] - hs[i - 1])),
                dp[i - 2] + (abs(hs[i] - hs[i - 2])))

print(dp[N - 1])


Measured memory_bytes: 13924
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = 1LL << 32;

int main() {
  ll N, w;

  cin >> N >> w;

  vll ws(N);
  vll vs(N);
  ll w0;
  cin >> w0 >> vs[0];
  ws[0] = 0;
  for (ll i = 1; i < N; i++) {
    cin >> ws[i] >> vs[i];
    ws[i] -= w0;
  }

  ll ans = 0;
  for (ll n = 0; n <= N; n++) {
    ll wp = w - n * w0;
    if (wp < 0) continue;
    if (wp > 3 * n) {
      vvll dp(N + 1, vll(n + 1, 0));
      for (ll i = 1; i <= N; i++) {
        for (ll j = 0; j <= n; j++) {
          if (i < j) continue;
          dp[i][j] = dp[i - 1][j];
          if (j >= 1) chmax(dp[i][j], dp[i - 1][j - 1] + vs[i - 1]);
        }  // j
      }    // i
      chmax(ans, dp[N][n]);
    } else {
      vector<vvll> dp(N + 1, vvll(wp + 1, vll(n + 1, 0)));
      for (ll i = 1; i <= N; i++) {
        for (ll k = 0; k <= wp; k++) {
          for (ll j = 0; j <= n; j++) {
            if (i < j) continue;
            dp[i][k][j] = dp[i - 1][k][j];
            if (j >= 1 && k >= ws[i - 1])
              chmax(dp[i][k][j], dp[i - 1][k - ws[i - 1]][j - 1] + vs[i - 1]);
          }  // j
        }    // k
      }      // i
      chmax(ans, dp[N][wp][n]);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string str;
	cin >> str;
	for (auto& c : str)
		if (c == ',') c = ' ';
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a, b, d=0, r=0;
  double f=0;

  scanf("%d %d", &a, &b);

  d = a / b;
  r = a % b;
  f = (double)a / (double)b;

  printf("%d %d %f", d, r, f);
}



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

int main() {
  string s;
  cin>>s;
  int n = s.length();
  int k = n;
  for (int i=1; i<n; i++) {
    if (s[i-1] != s[i]) {
      k = min(max(i, n - i), k);
    }
  }
  cout<<k<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int c=1;
	char s[5];
	cin >> s;
	sort(s, s + 4);
	char b = s[0];
	for (int i = 1;i < 4;i++)
	{
		if (s[i] != b)
		{
			c++;
			b = s[i];
		}
	}
	cout << (c == 2 ? "Yes" : "No") << '\n';
	return 0;
}

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

template <typename T>
inline T read(){
    T x=0,f=1;char c=getchar();
    while(!isdigit(c)){ if(c=='-') f=-f;c=getchar();}
    while(isdigit(c)){x=(x<<3)+(x<<1)+(c-48);c=getchar();}
    return x*f;
}

#define lint long long int
#define ulint unsigned lint
#define readint read<int>()
#define readlint read<lint>()
const int inf=1e9+1e7;

int n;

int main(void){

    // freopen("testdata.in","r",stdin);
    // freopen("testdata.out","w",stdout);

    scanf("%d",&n);
    if(n>=30) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(void)
{
    string S;
    cin >> S;

    char s1 = S[0], s2 = 0;
    int c1 = 1, c2 = 0;
    for (int i = 1; i < 4; ++i)
    {
        if (S[i] == s1) c1++;
        if (S[i] == s2) c2++;

        if (S[i] != s1 && s2 == 0)
        {
            s2 = S[i];
            c2++;
        }
    }

    if (c1 == c2 && c1 == 2)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){

  int K, X; cin >> K >> X;
  for (int i = 0; i < 2 * K - 1; i++){
    cout << X - K + i + 1;
    if (i != 2 * K - 2) cout << " ";
    else cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(void){
    string s;
    cin>>s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]){
        cout<<"Bad"<<endl;
    }
    
    else cout<<"Good"<<endl;
    
}


Measured memory_bytes: 256
import java.util.Scanner;
class Restaurant {
    int number;
    String city;
    int point;
    Restaurant(int n, String s, int p) {
        this.number = n;
        this.city = s;
        this.point = p;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Restaurant[] res = new Restaurant[n];
        for (int i = 0; i < n; i++) {
            res[i] = new Restaurant(i + 1, sc.next(), sc.nextInt());
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (res[j].point < res[j + 1].point) {
                    Restaurant memo = res[j];
                    res[j] = res[j + 1];
                    res[j + 1] = memo;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (res[j].city.compareTo(res[j + 1].city) > 0) {
                    Restaurant memo = res[j];
                    res[j] = res[j + 1];
                    res[j + 1] = memo;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.println(res[i].number);
        }
        sc.close();
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i, n) for(int i = 0; i < int(n); ++i)
#define FOR(i, a, n) for(int i = int(a); i < int(n); ++i)

const int MAX = 7400006;

bool used[MAX];

signed main() {
	
	while (true) {
		int m, n;
		std::cin >> m >> n;
		if (m == 0 && n == 0) break;

		REP(i, MAX) used[i] = false;

		int p = 0;
		FOR(i, m, MAX) {
			if (used[i]) continue;
			if (p++ == n) {
				std::cout << i << std::endl;
				break;
			}
			for (int j = 1; i * j < MAX; ++j) used[i * j] = true;
		}
	}

	return 0;
}


Measured memory_bytes: 10316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    if(s.length()%2==1)
    {
        cout<<"No";
    }
    else
    {
        ll flag=1;
        for(ll i=0;i<s.length()/2;i++)
        {
            if(s[2*i]!='h' || s[2*i+1]!='i')
                flag=0;
        }
        if(flag==0)
            cout<<"No";
        else
            cout<<"Yes";
    }
}

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

int main(void)
{
    int r,d;
    long long x;
    cin >> r >> d >> x;


    for (int i = 0; i < 10; i++)
    {
        x = r * x - d;
        cout << x << endl;
    }
    

    return 0;
}

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

int main()
{
    int a, b;
    int sum = 0, n;

    while( cin >> a >> b >> n )
    {
        string c = "";
        for( int i = 0; i <= n; i++ )
        {
            c += ( a / b ) + '0';           //整数部分は無視。変な値が入っても問題ない。
            a = a % b * 10;
        }
        int sum = 0;
        for( int i = 1; i < c.size(); i++ )
            sum += c[i] - '0';
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;


int main(void) {
	ll x;
	cin >> x;
	ll ngo = x / 500;
	x = x - ngo * 500;
	ll ngo2 = x / 5;
	cout << (ngo * 1000 + ngo2 * 5) << endl;
	return 0;
}


Measured memory_bytes: 3552
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
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;
}
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

void solve() {
    ll n;
    cin >> n;
    ll ans = n * (n - 1) / 2;
    cout << ans << "\n";
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main(){
    ll k,a,b; cin >> k >> a >> b;
    ll ans = 0;

    ll bisket = 1;
    if(a+2 >= b){
        cout << k+1 << endl;
        return 0;
    }
    if(k+1 <= a) {
        cout << k+1 << endl;
        return 0;
    }
    for(int i = 0; i < k; i++){
        if(bisket < a) bisket++;
        else {
            if((k-i) == 1){
                bisket += 1;
                break;
            } else if((k-i)%2 == 0){
                bisket += ((k-i)/2)*(b-a);
                break; 
            } else {
                bisket += ((k-i)/2)*(b-a)+1;
                break;
            }
        } 
    }
    cout << bisket << endl;
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int N, H, W;
    cin >> N >> H >> W;

    int ans = 0;
    int curh;
    int curw;
    for (int i = 0; i < N; i++) {
        cin >> curh;
        cin >> curw;
        if (curh >= H && curw >= W) {
            ans++;
        }
    }
    cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
use std::collections::HashMap;
// stdin
macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

// input
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        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")
    };
}

// Test
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"6 3 4
3
1
3
2
" => r"No
No
Yes
No
No
No",

r"6 5 4
3
1
3
2
" => r"Yes
Yes
Yes
Yes
Yes
Yes",

r"10 13 15
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9
" => r"No
No
No
No
Yes
No
No
No
Yes
No"
}

fn solve(src: &str) -> String {
    input! {
        source=src,
        n:i32,
        k:i32,
        q:i32,
        a:[i32;q],
    };

    let n: i32 = n;
    let k: i32 = k;
    let q: i32 = q;
    let a: Vec<i32> = a;

    let mut map = HashMap::new();

    for &v in a.iter() {
        match map.get(&v) {
            None => {
                map.insert(v, 1);
            }
            Some(&vv) => {
                map.insert(v, vv + 1);
            }
        }
    }

//    let mut ans = vec![];

    for num in 1..n + 1 {
        let tmp = match map.get(&num) {
            None => {
                if k - q > 0 {
                    println!("Yes");
                }else{
                    println!("No");
                }
            },
            Some(&v) => {
                if k - (q - v) > 0 {
                    println!("Yes");
                }else{
                    println!("No");
                }

            },
        };
//        ans.push(tmp);
    }

//    let ans = ans.join("\n");
    "".to_string()
//    format!("{}", ans)
}


fn main() {
    println!("{}", solve(&stdin!()));
}



Measured memory_bytes: 10876
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string S;
	int count = 0, base, *s, mod[2019] = {1};

	cin >> S;

	s = new int[S.length() + 1];
	s[0] = 0;
	base = 1;
	for (int i = 1; i <= S.length(); i++)
	{
		s[i] = (s[i - 1] + (S[S.length() - i] - '0') * base) % 2019;
		base = (base * 10) % 2019;
		++mod[s[i]];
	}

	for (int i = 0; i < 2019; i++)
	{
		count += ((mod[i] - 1) * mod[i]) / 2;
	}

	cout << count << endl;

	delete s;

	return 0; 
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    cin >>a[0]>> a[1];
    int ans=a[1]-a[0];
    int mi=min(a[0],a[1]);
    for(int i=2;i<n;i++){
        cin>>a[i];
        ans=max(ans,a[i]-mi);
        mi=min(mi,a[i]);
    }
    cout << ans << endl;
}


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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int n, q;
string s;
vt<char> t, d;

bool fanc(int m, bool left) {
  rep(i, 0, q) {
    if(t[i] == s[m]) {
      if(d[i] == 'L') m--;
      else m++;
    }
  }

  if(left) return (m == 0);
  else return (m == n + 1);
}

int binary_search() {
  int left = 0, right = n + 1;
  {
    int ng = n + 1;
    while(abs(ng - left) > 1) {
      int mid = (left + ng) / 2;
      if(fanc(mid, true)) left = mid;
      else ng = mid;
    }
  }
  {
    int ng = left;
    while(abs(right - ng) > 1) {
      int mid = (right + ng) / 2;
      if(fanc(mid, false)) right = mid;
      else ng = mid;
    }
  }
  return n - (n + 1 - right) - left;
}

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

  cin >> n >> q >> s;
  t.resize(q); d.resize(q);
  rep(i, 0, q) cin >> t[i] >> d[i];
  s = " " + s + " ";
  cout << binary_search() << endl;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
// #include <bits/stdtr1c++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;


/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/

/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       scanf("%lld %lld %lld", &x, &y, &z)
#define MAX                 10005
#define MOD                 1000000009
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 1<<29       // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932
// #define INF              0x3f3f3f3f3f3f3f3f
// #define inf              0x3f3f3f3f

int ara[13][13],p[13];
int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n,m,k,x;
    sii(n,m);
    FOR(i,1,m+1){
        si(k);
        FOR(j,1,k+1){
            si(x);
            ara[i][x]=1;
        }
    }
    FOR(i,1,m+1)si(p[i]);
    int ans=0;
    for(int i=0;i<(1<<n);i++){
        bool f=true;
        FOR(j,1,m+1){
            int tmp =0 ;
            for(int l=1;l<=n;l++){
                if(ara[j][l]==1 && (i&(1<<l-1)))tmp++;
            }
            if(tmp%2!=p[j]){
                f=false;
            }
        }
        if(f)ans++;
    }
    cout<<ans<<endl;
    #ifdef VAMP
       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[100000];
int p, q, r;
int ans = 1;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int cnt = 0;
		if (p == a[i])cnt++;
		if (q == a[i])cnt++;
		if (r == a[i])cnt++;
		if (!cnt) {
			cout << 0 << endl;
			return 0;
		}
		ans *= cnt;
		ans %= mod;
		if (p == a[i])p++;
		else if (q == a[i])q++;
		else if (r == a[i])r++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());//店の数
		int m = Integer.parseInt(sc.next());//買いたい本数
		long [][] a = new long[n][2];
		for(int i=0; i<n;i++) {
			a[i][0] = Long.parseLong(sc.next());
			a[i][1] = Long.parseLong(sc.next());
		}
		sc.close();

		Arrays.sort(a,(a1,a2)->Long.compare(a1[0],a2[0]));
		long cnt=0,sumYen=0;
		for(int i=0;i<n&&cnt<m;i++) {
			for(long j=a[i][1];cnt<m&&j>0;j--) {
				cnt++;
				sumYen+=a[i][0];
			}
			//System.out.println(a[i][0]+" "+a[i][1]);
		}
		System.out.println(sumYen);
	}
}


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

ll n,l,r,a[100010];

int main(){
    cin>>n;
    l=0; r=n-1;
    cout<<0<<endl; fflush(stdout);
    string s; cin>>s;
    if(s=="Male") a[0]=1;
    else if(s=="Female") a[0]=2;
    else if(s=="Vacant") exit(0);
    cout<<n-1<<endl; fflush(stdout);
    cin>>s;
    if(s=="Male") a[n-1]=1;
    else if(s=="Female") a[n-1]=2;
    else if(s=="Vacant") exit(0);
    while(l+1<r){
        ll mid=(l+r)>>1;
        cout<<mid<<endl; fflush(stdout);
		string s; cin>>s;
		if(s=="Male") a[mid]=1;
		else if(s=="Female") a[mid]=2;
		else if(s=="Vacant") exit(0);
        if((r-mid-1)&1){
            if(a[mid]==a[r]) r=mid;
            else l=mid;
        }
        else{
            if(a[mid]!=a[r]) r=mid;
            else l=mid;
        }
    }
    return 0;
}

Measured memory_bytes: 852
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int X=sc.nextInt();
        int Y=sc.nextInt();
        int Z=sc.nextInt();
        X=X-Y-2*Z;
        int n=1;
        for(int i=0;X>=Y+Z;i++){
            X=X-Y-Z;
            n++;


        }
        System.out.println(n);

        
        
     
    }
}

Measured memory_bytes: 21844
import numpy as np
n = int(input())
towns = []
for _ in range(n):
    x,y = map(int,input().split())
    towns.append((x,y))
dist = []
for i in range(n-1):
    for j in range(i+1,n):
        x1,y1 = towns[i]
        x2,y2 = towns[j]
        dist.append(np.sqrt((x1-x2)**2+(y1-y2)**2))
print((sum(dist)/len(dist)) * (n-1))


Measured memory_bytes: 13956
while True:
    w, h = map(int, input().split())
    if w == 0:
        break
    tatekabe = []
    yokokabe = []
    for _ in range(h-1):
        tatekabe.append(list(map(int, input().split())))
        yokokabe.append(list(map(int, input().split())))
    tatekabe.append(list(map(int, input().split())))

    field = [[1e10 for i in range(w)] for j in range(h)]
    
    x, y = 0, 0
    field[y][x] = 1
    stack = [[x, y]]
    while True:
        if stack == []:
            break
        x, y = stack.pop()
        c = field[y][x]
        if x != w-1 and tatekabe[y][x] == 0 and c+1 < field[y][x+1]:
            field[y][x+1] = c + 1
            stack.append([x+1, y])
        if x != 0 and tatekabe[y][x-1] == 0 and c+1 < field[y][x-1]:
            field[y][x-1] = c + 1
            stack.append([x-1, y])
        if y != h-1 and yokokabe[y][x] == 0 and c+1 < field[y+1][x]:
            field[y+1][x] = c + 1
            stack.append([x, y+1])
        if y != 0 and yokokabe[y-1][x] == 0 and c+1 < field[y-1][x]:
            field[y-1][x] = c + 1
            stack.append([x, y-1])
    if field[h-1][w-1] == 1e10:
        print(0)
    else:
        print(field[h-1][w-1])

Measured memory_bytes: 7740
mod = 1000000007
n= int(input())
a= list(map(int,input().split()))
check = [0]*(n+1)
g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,n+1+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)
def cmb2(n,r):
    mod = 1000000007
    if (r<0 or r>n ):return 0
    r = min(r, n-r)
    return g1[n]*g2[r]*g2[n-r]%mod
r=-1
jn=-1
for i in range(n+1):
    check[a[i]-1]+=1
    if check[a[i]-1]==2:
        jn,r=a[i],i
        break
l=a.index(jn)
s = min(l,n-r)
t = max(l,n-r)
print(n)
for p in range(2,n+1):
  w2=cmb2(n+1,p)
  y2=cmb2(s+t,p-1)
  print(((w2+mod)-y2) % mod)
print(1)

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>

int main(void){
    int N;
    long long ans=0;
    std::cin >> N;
    std::vector<long long> A(3 * N);

    for (int i=0; i<3 * N; ++i){
        std::cin >> A.at(i);
    }

    std::sort(A.begin(), A.end());

    for (int i=3*N-2; i>N-1; i-=2){
        ans += A.at(i);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 5608