akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<char> c(n);
    // map<char, int> color;
    vector<int> w, r;
    // color['R'] = 0;
    // color['W'] = 0;
    rep(i, n){
        char tmp;
        cin >> tmp;
        c[i] = tmp;
        // color[tmp]++;
        if(tmp == 'R'){
            r.push_back(i);
        }
        else{
            w.push_back(i);
        }
    }
    // if(color['R'] == 0|| color['W'] == 0){
    //     cout << 0 << endl;
    //     return 0;
    // }
    if(r.empty() || w.empty()){
        cout << 0 << endl;
        return 0;
    }

    int ans = 0;
    while(1){
        if(w.empty() || r.empty()) break;
        int wnum = w.front();
        int rnum = r.back();
        if(wnum > rnum) break;
        ans++;
        w.erase(w.begin());
        r.erase(r.begin() + r.size() - 1);
    }

    cout << ans << endl;
    return 0;


}

// bool setcheck(string &c){
//     auto previous = c.front();
//     for(int i = 1; i < c.size(); i++){
//         auto now = c[i];
//         if(previous != now){
//             return false;
//         }
//         previous = now;
//     }
//     return true;
// }

// int main(){
//     int n;
//     cin >> n;
//     string c;
//     cin >> c;

//     if(setcheck(c)){
//         cout << 0 << endl;
//         return 0;
//     }

//     int ans = 0;
//     while(1){
// link1:
//         bool flag = false;
//         for(int i = 0; i < c.size(); i++){
//             if(c[i] == 'W'){
//                 for(int j = c.size() - 1; j >= 0; j--){
//                     if(j < i){
//                         flag = true;
//                         break;
//                     }
//                     if(c[j] == 'R'){
//                         c[j] = 'W';
//                         c[i] = 'R';
//                         ans++;
//                         goto link1;
//                     }
//                 }
//             }
//             if(flag) break;
//         }
//         if(flag) break;
//     }

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

Measured memory_bytes: 4680
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}

ll i,j,k,ii,jj;
ll n,m;
ll a,b,c,d,e,g,h,r,w;
ll l;
ll num;
ll x[500005],y[500005],z[500005];
char s[600][600];
ll dp[600][600];
ll check[600][600];
bool dame,flag;
ll ok,ng;
ll ans[500005];
ll sum[500005],oddsum[500005];
ll num0[800005],num1[800005];

int main(){
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	sort(x,x+n);
	a = 0;
	for(i=0;i<n;i++){
		a += x[i];
		if((n - i) % 2 == 1){
			b += x[i];
		}
		oddsum[i] = b;
		sum[i] = a;
	}
	for(i=0;i<n;i++){
		//pe(sum[i]);
	}
	//el;
	for(i=0;i<k;i++){
		cin >> y[i];
	}
	for(i=1;i<=(n+1)/2;i++){
		//先頭のi個をとる場合
		z[i] = (x[n-i] + x[n+1-2*i])/2;
		//pe(z[i]);
	}
	//el;
	for(i=1;i<=(n+1)/2;i++){
		a = 0;
		a += sum[n-1];
		a -= sum[n-1-i];
		if(n + 1 - 2 * i >= 0)a += oddsum[n-1-2*i];
		ans[i] = a;
		//pe(ans[i]);
	}
	//el;
	for(i=0;i<k;i++){
		ok = 1;
		ng = (n+1)/2 + 1;
		while(abs(ok - ng) > 1){
			ll mid = (ok + ng) / 2;
			if(z[mid] >= y[i]){
				ok = mid;
			}else{
				ng = mid;
			}
		}
		p(ans[ok]);
	}






			

	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<P> v;
    for (int i = 0; i < n; i++) {
        ll a;
        int b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }
    sort(v.begin(), v.end());

    int rest = m;
    ll ans = 0;
    for (P& p : v) {
        if (rest > p.second) {
            rest -= p.second;
            ans += p.first * p.second;
        } else {
            ans += p.first * rest;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
N, K = map(int,input().split())
num_list =[]
num_list = input().split()
use_num = [s for s in ["0","1","2","3","4","5","6","7","8","9"] if s not in num_list]
flag = False
answer = []

for i in range(1,len(str(N))+1):
    tmp = str(N)[-i]
    if(flag):
        flag=False
        if(tmp==str(9)):
            answer.insert(0,use_num[0])
            flag =True
            continue
        else:
            tmp = str(int(tmp) + 1)

    if(tmp in num_list):
        answer.clear()
        for j in range(i-1):
            answer.insert(0,use_num[0])
    else:
        answer.insert(0,tmp)
        
    while(tmp in num_list):
        if(tmp==str(9)):
            flag =True
            answer.insert(0,use_num[0])
            if(i==len(str(N))):
                if(use_num[0]==str(0)):
                    answer.insert(0,use_num[1])
                else:
                    answer.insert(0,use_num[0])
            break
        else:
            tmp = str(int(tmp) + 1)
            if(tmp in use_num):
                answer.insert(0,tmp)

print("".join(answer))


Measured memory_bytes: 3064
S = input()
s = []
for _ in S:
  s.append(int(_))
s1 = [1]
s2 = [0]
for i in range(1,len(s)):
  if s1[i-1] == 0:
    s1.append(1)
  else:
    s1.append(0)
  if s2[i-1] == 0:
    s2.append(1)
  else:
    s2.append(0)
    
a = 0
b = 0
for j in range(len(s)):
  if s[j] != s1[j]:
    a += 1
  if s[j] != s2[j]:
    b += 1
print(min(a,b))

Measured memory_bytes: 11732
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    ll r;
    cin >> r;
    cout << 3 * (r * r) << endl;


    return 0;
}

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

int main(){
  vector<int> ans;
  vector<vector<int> > path_field;
  int n;

  cin >> n;
  n++;
  path_field.resize(n);
  ans.resize(n);
  for(int i=1;i<n;i++){
    ans[i]=-1;
  }
  for(int i=1;i<n;i++){
    int _m,m;

    path_field[i].resize(n);
    for(int j=1;j<n;j++){
      path_field[i][j]=0;
    }

    cin >> _m >> m;
    for(int j=0;j<m;j++){
      int to;
      
      cin >> to;
      path_field[i][to]=1;
    }
  }

  deque<tuple<int,int> > que;

  que.push_back(make_tuple(1,0));
  ans[1]=0;
  while(!que.empty()){
    int& standingby=get<0>(que.front());

    for(int i=1;i<n;i++){
      if((path_field[standingby][i]==1)&&(ans[i]==-1)){
        que.push_back(make_tuple(i,get<1>(que.front())+1));
	ans[i]=get<1>(que.front())+1;
      }
    }
    que.pop_front();
  }

  for(int i=1;i<n;i++){
    cout << i << " " << ans[i] << endl;
  }
}


Measured memory_bytes: 3116
n = int(input())

xs = [int(x) for x in input().split()]

mn = 1000000000
for i in range(len(xs)):
    s1 = 0
    s2 = 0
    for j in range(i):
        s1 += xs[j]
    for k in range(i, len(xs)):
        s2 += xs[k]
    diff = abs(s1 - s2)
    mn = min(mn, diff)

print(mn)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int LP[1005][1005]={};

int main() {
  int j,k;
  string x,y;
  cin >> x >> y;
  for(j=1;j<=x.size();j++) LP[j][0] = j;
  for(k=1;k<=y.size();k++) LP[0][k] = k;

  //aをbに近づけたい!
  for(j=1;j<=x.size();j++) {
    for(k=1;k<=y.size();k++) {
      //a[j]を削除するか、a[j+1]にb[k]と同じ文字を挿入するか
      //上記２つの行為の回数で最小な方を採用
      int m = min(LP[j-1][k]+1, LP[j][k-1]+1);
      if(x[j-1] == y[k-1]) {
        //最後の文字が同じだから最後の文字がなくても編集距離は同じ
        m = min(m,LP[j-1][k-1]);
        LP[j][k] = m;
      }else {
        //最後の文字を置換する
        m = min(m,LP[j-1][k-1]+1);
        LP[j][k] = m;
      }
    }
  }
  cout << LP[x.size()][y.size()] << endl;
  return 0;
}


Measured memory_bytes: 7084
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	double a,b;
	cin >> a>>b;
	cout << a / b << endl;
	return 0;
}


Measured memory_bytes: 256
import math
from decimal import Decimal
#from decimal import Decimal
a, b, c, d = map(Decimal, input().split())

def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

def count(a, c, d):
    tmp_a= a - math.floor(a/c) - math.floor(a/d)
    tmp_a += math.floor(a/((c*d)/gcd(c, d)))
    return tmp_a

print(int(count(b,c,d))-int(count(a-1, c, d)))

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

int main(void){
	string S, T;
	cin >> S >> T;
	if (T.substr(0,S.size()) != S) cout << "No" << endl;
	else cout << "Yes" << endl;

return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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

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

	ll N = s.size();
	ll M = t.size();
	vvll dp(N + 1, vll(M + 1, 0));

	repn(i, N)repn(j, M) {
		dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		if (s[i - 1] == t[j - 1]) { dp[i][j] = dp[i-1][j-1]+1; }
	}

	string ans;

	ll x = N;
	ll y = M;
	while (x > 0 && y > 0) {
		if (s[x-1]==t[y-1]) { ans.push_back(s[x - 1]); x--; y--; }
		else if (dp[x-1][y]>dp[x][y-1]) { x--; }
		else { y--; }
		//cout << x << y << endl;
	}

	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}

Measured memory_bytes: 73744
N,K=map(int,input().split())
A=list(map(int,input().split()))
city=0
if K<=N:
    for k in range(K):
        city=A[city]-1
    print(city+1)
else:
    visited=[-1]*N
    for k in range(K):
        if visited[city]!=-1:
            roop_start=visited[city]
            cycle_num=k-roop_start
            break
        visited[city]=k
        city=A[city]-1
    K=(K-roop_start)%cycle_num+roop_start
    city=0
    for k in range(K):
        city=A[city]-1
    print(city+1)

Measured memory_bytes: 32380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<double>vec(N);
  for (int X=0;X<N;X++){
    cin>>vec.at(X);
  }
  sort(vec.begin(), vec.end());
  double M=vec.at(0);
  for (int X=1;X<N;X++){
    M+=vec.at(X);
    M/=2;
  }
  cout << M << endl;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int arith_sum1(long long int,long long int,long long int);
long long int arith_sum2(long long int,long long int,long long int);
long long int series_sum(long long int);

int main(){
    int n;
    cin>>n;
    vector<pair<ll,ll>> vec(n);
    ll a,b;
    rep(i,n){
        cin>>a>>b;
        vec[i]=make_pair(b,-a);
    }
    ll t=0;
    sort(all(vec));
    int ans=1;
    rep(i,n){
        t+=abs(vec[i].second);
        //cerr<<t<<":"<<vec[i].first<<" "<<vec[i].second<<endl;
        if(vec[i].first<t){
            ans=0;
            break;
        }
    }
    yn(ans);
}

Measured memory_bytes: 6356
import java.util.*;

public class Main {
    	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long[] a = new long[3];
		for(int i=0; i<3; i++) a[i] = sc.nextLong();
		Arrays.sort(a);
		
		if(a[2]%2 == 1) System.out.println(a[0]*a[1]);
		else System.out.println(0);
	}
}


Measured memory_bytes: 21844
#include<cstdio>
#include<iostream>
#include<map>
using namespace std;
inline bool check(int year) {
	return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
int cnt(int year) {
	int ans = 0;
	for(int i = 1; i <= year; i++) {
		if(check(i)) ans++;
	}
	return ans;
}
int main() {
	int d[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	for(int i = 2; i <= 12; i++) {
		d[i] += d[i-1];
	}
	int y1,m1,d1,y2,m2,d2;
	while(scanf("%d%d%d%d%d%d",&y1,&m1,&d1,&y2,&m2,&d2)) {
		if(y1 == -1 || m1 == -1 || d1 == -1 || y2 == -1 || m2 == -1 || d2 == -1) break;
		int a1 = 365 * (y1 - 1) + cnt(m1 > 2 ? y1 : y1 - 1) + d[m1-1] + d1;
		int a2 = 365 * (y2 - 1) + cnt(m2 > 2 ? y2 : y2 - 1) + d[m2-1] + d2;
		printf("%d\n",a2 - a1);
	}
	
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main() {

	string s, o, sub1, sub2;

	cin >> s;
	o = "keyence";

	sub1=s.substr(0, 7);
	sub2 = s.substr(s.size() - 7, 7);
	
	if (o == sub1 || o == sub2) {
		YES; return 0;
	}
	else {
		rep(i, 0, 7) {
			sub1 = s.substr(0, i);
			sub2 = s.substr(s.size() - 7 + i, 7 - i);
			
			if (sub1 + sub2 == o) {
				YES; return 0;
			}
		}
	}
	
	NO;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
const long D = 1000000007;

int main()
{
  int n, m;
  cin >> n >> m;
  int a[n], b[n];
  int c[m], d[m];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < m; i++)
  {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i < n; i++)
  {
    int minI = 0, min = D;
    for (int j = 0; j < m; j++)
    {
      int dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (dis < min)
      {
        minI = j;
        min = dis;
      }
    }
    cout << minI + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;
// Bottom, Front, Left, Right, Back, Top
// 0     , 1    , 2   , 3    , 4   , 5
int T[6];

bool valid(){
    if(T[0] < 0) return false;

    int sum = 0;
    REP(i, 6) sum += T[i];

    if(2*(T[0] + T[5]) > sum) return false;
    if(2*(T[1] + T[4]) - 1 > sum) return false;
    if(2*(T[2] + T[3]) - 1 > sum) return false;
    return true;
}

// a, b, c, d -> b, c, d, a
inline void roll(int a, int b, int c, int d) {
    int tmp = T[a];
    T[a] = T[b];
    T[b] = T[c];
    T[c] = T[d];
    T[d] = tmp;
}

inline void rollN(){
    roll(0, 4, 5, 1);
}
inline void rollS() {
    roll(1, 5, 4, 0);
}
inline void rollW() {
    roll(5, 2, 0, 3);
}
inline void rollE() {
    roll(3, 0, 2, 5);
}

inline void rollX(char c){
    if(c == 'N') rollN();
    else if(c == 'S') rollS();
    else if(c == 'W') rollW();
    else if(c == 'E') rollE();
}

inline void roll_backX(char c) {
    if(c == 'S') rollN();
    else if(c == 'N') rollS();
    else if(c == 'E') rollW();
    else if(c == 'W') rollE();
}

bool is_end() {
    REP(i, 6) if(T[i] != 0) return false;
    return true;
}

char ans[55555];
int LEN;
bool dfs(int idx) {
    if(idx == LEN) return true;
    // E, N, S, W
    {
        rollE();
        T[0]--;
        if(valid()){
            ans[idx] = 'E';
            if(dfs(idx + 1)) {
                return true;
            }
        }
        T[0]++;
        rollW();
    }
    {
        rollN();
        T[0]--;
        if(valid()){
            ans[idx] = 'N';
            if(dfs(idx + 1)) {
                return true;
            }
        }
        T[0]++;
        rollS();
    }
    {
        rollS();
        T[0]--;
        if(valid()){
            ans[idx] = 'S';
            if(dfs(idx + 1)) {
                return true;
            }
        }
        T[0]++;
        rollN();
    }
    {
        rollW();
        T[0]--;
        if(valid()){
            ans[idx] = 'W';
            if(dfs(idx + 1)) {
                return true;
            }
        }
        T[0]++;
        rollW();
    }
    return false;
}

int main(){
    while(true){
        vector<int> t(6);
        REP(i, 6) cin >> t[i];

        REP(i, 6) T[i] = t[i];
        if(is_end()) break;
        LEN = accumulate(t.begin(), t.end(), 0);

        int p, q;
        cin >> p >> q;
        p--;

        string answer = "Z";

        sort(t.begin(), t.end());
        do{
            REP(i, 6) T[i] = t[i];
            bool res = dfs(0);
            if(res) {
                string cand;
                REP(i, LEN) cand += ans[i];
                answer = min(answer, cand);
            }
        }while(next_permutation(t.begin(), t.end()));

        if(answer == "Z") {
            cout << "impossible" << endl;
        } else {
            for(int i = p; i < q; i++) {
                cout << answer[i];
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int W, H, X, Y;
	cin >> W >> H >> X >> Y;
	int res = 0;
 
	if (X * 2 == W && 2 * Y == H) {
		res = 1;
	}
 
	cout << fixed << setprecision(15) << (W*H / 2.0) << " " << res << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<bool>A(N - 1, false);
    vector<int>H(N);
    cin >> H[0];
    REP(i, N) {
        cin >> H[i];
        if (H[i] <= H[i - 1])A[i-1] = true;
    }
    int ans = 0;
    int answer = 0;
    rep(i, N-1) {
        if (A[i] == true)ans++;
        else {
            if (answer == 0) {
                answer = ans;
                ans = 0;
                continue;
            }
            answer = max(ans,answer);
            ans = 0;
        }
    }
    cout << max(ans,answer) << endl;
}

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

int main() {
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int N; ll a=0, b=0;
	cin>>N;
	vector<int> A(3*N);
	rep(i, 0, 3*N) cin>>A[i];
	vector<ll> B(N+1), C(N+1);
	priority_queue<int> q;
	rep(i, 0, N) q.push(-A[i]), a+=A[i];
	B[0]=a;
	rep(i, N, 2*N) {
		q.push(-A[i]), a+=A[i];
		B[i-N+1]=a+=q.top(); q.pop();
	}
	while(q.size()) q.pop();
	repr(i, 3*N, 2*N) q.push(A[i]), b+=A[i];
	C[N]=b;
	repr(i, 2*N, N) {
		q.push(A[i]), b+=A[i];
		C[i-N]=b-=q.top(); q.pop();
	}
	ll m=LLONG_MIN;
	rep(i, 0, N+1) m=max(m, B[i]-C[i]);
	cout<<m;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;



int main()
{
    ios_base::sync_with_stdio(false);

    int good = 0;
    string s;
    cin >> s;
    for (int i = 0; i + 1 < s.size(); ++i) {
        if (s[i] == 'A' && s[i + 1] == 'C')
            good = 1;
    }
    cout << (good ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
int main(void)
{
  char str[201],temp[201]={};
  int m,i,sh;
  size_t len;

  for( ; ; ){
      scanf("%s",&str);
      if(str[0] == '-'){break;}
  scanf("%d",&m);
  for(i=0;i<m;i++)
    {
      memset(temp,0,201*sizeof(char));
      scanf("%d",&sh);
      len= sh*sizeof(char);
      strncpy(temp,str,len);
      strcpy(str,str+len);
      strcat(str,temp);
    }
  printf("%s\n",str);   
  }
  return 0;
}

Measured memory_bytes: 604
n, m = map(int, input().split())
rootList = [-1 for i in range(n)]
 
def getRoot(x):
    r = rootList[x]
    if r < 0:
        rootList[x] = x
    elif r != x:
        rootList[x] = getRoot(r)
    return rootList[x]
 
 
def setSameRoot(x, y):
    x = getRoot(x)
    y = getRoot(y)
    if x != y:
        rootList[x] = rootList[y] = min(x, y)
 
for i in range(m):
    s, t = map(int, input().split())
    setSameRoot(s, t)
q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    print("yes" if getRoot(s) == getRoot(t) else "no")

Measured memory_bytes: 7016
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

void solve()
{
    int n,r;
    cin>>n>>r;

    if ( n >= 10 )
    {
        cout<<r<<endl;
    }
    else
    {
        cout<<r + 100*(10-n)<<endl;
    }
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 200005

struct LOC{

	bool operator<(const struct LOC &arg) const{

		return X < arg.X;
	}
	ll S,T,X;
};

ll N,Q;
ll ans[SIZE];
map<ll,ll> MAP;
set<ll> SET;
LOC loc[SIZE];


int main(){

	scanf("%lld %lld",&N,&Q);

	for(int i = 0; i < Q; i++){

		ans[i] = -1;
	}

	for(ll i = 0; i < N; i++){

		scanf("%lld %lld %lld",&loc[i].S,&loc[i].T,&loc[i].X);
	}
	sort(loc,loc+N);

	ll D;
	for(ll i = 0; i < Q; i++){

		scanf("%lld",&D);
		MAP[D] = i;
		SET.insert(D);
	}

	vector<ll> work;

	for(int i = 0; i < N; i++){

		//printf("%lld-%lld\n",max(0LL,loc[i].S-loc[i].X),max(0LL,(loc[i].T-1)-loc[i].X));

		auto left = SET.lower_bound(max(0LL,loc[i].S-loc[i].X));

		if(*left+loc[i].X >= loc[i].T)continue;

		auto right = SET.lower_bound(max(0LL,loc[i].T-loc[i].X));

		if(left == SET.end())continue;

		work.clear();

		while(true){

			ans[MAP[*left]] = loc[i].X;
			work.push_back(*left);
			left++;
			if(left == right)break;
		}

		for(int k = 0; k < work.size(); k++){

			SET.erase(work[k]);
		}
	}

	for(int i = 0; i < Q; i++){

		printf("%lld\n",ans[i]);
	}

	return 0;
}


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

using namespace std;

int main()
{
    size_t n, m;
    cin >> n >> m;

    vector<vector<int> > A(n);
    vector<int> b(m);
    for (auto& v : A) {
        v.resize(m);
        for (auto &a : v) {
            cin >> a;
        }
    }
    for (auto& v : b) {
        cin >> v;
    }

    for (auto& v : A) {
        long long acc = 0;
        for (size_t i = 0; i < m; ++i) {
            acc += v.at(i) * b.at(i);
        }
        cout << acc << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3112
n, m = map(int, input().split())
ab = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    ab[a - 1].append(b)
    ab[b - 1].append(a)
flag = [False for i in range(n)]
prev = [float("inf") for i in range(n)]

num = [i for i in ab[0]]
for i in num:
    prev[i - 1] = 1
    flag[i - 1] = True
flag[0] = True
while num:
    test = num.pop(0)
    for i in ab[test - 1]:
        if flag[i - 1] == False:
            prev[i - 1] = test
            flag[i - 1] = True
            num.append(i)
print("Yes")
for i in range(n - 1):
    print(prev[i + 1])

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

using namespace std;

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

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

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

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

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

  int n;
  cin >> n;

  vector<int> a(n+5);
  bool allEven = true;
  rep(i, n) {
    cin >> a[i];
    if (a[i] % 2 != 0) allEven = false;
  }

  if (!allEven) {
    cout << 0 << "\n";
    return 0;
  }

  int cnt = 0;
  while (true) {
    rep(i, n) {
      a[i] /= 2;
      if (a[i] % 2 != 0) allEven = false;
    }

    ++cnt;

    if (!allEven) {
      cout << cnt << "\n";
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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 (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    ll a,b,c,k;cin >> a >> b >> c >> k;
    if(k<=a)cout<< k << endl;
    else if(a<k and k<=a+b)cout << a << endl;
    else if(a+b<k and k<a+b+c)cout << a - (k-a-b) << endl;
    else cout << a-c << endl;

}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
typedef long long ll;

ll combi2(ll n){
    if(n < 2) return 0;
    return n * (n - 1) / 2;
}

int main() {
    ll n; cin >> n;
    vector<int> a(n + 1);
    vector<int> v(n + 1);
    rep(i, n){
        cin >> a[i];
        v[a[i]]++;
    }

    ll sum = 0;
    REP2(i, 1, n){
        sum += combi2(v[i]);
    }

    rep(i, n){
        ll tmp = v[a[i]];
        OP(sum - combi2(tmp) + combi2(tmp - 1));
    }
}


Measured memory_bytes: 4096
using System;
using System.Linq;
using System.Collections.Generic;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var s =input.ToLower();
            if (input == s)
                Console.WriteLine("a");
            else
                Console.WriteLine("A");
        }
    }
}


Measured memory_bytes: 26220
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

vec kmp_table(vec &Pattern) {
    ll i = 2, j = 0;
    vec T(Pattern.size(), -1);
    T[1] = 0;

    while (i < Pattern.size()) {
        if (Pattern[i-1] == Pattern[j]) {
            T[i] = j+1;
            i++;
            j++;
        } else if (j > 0) {
            j = T[j];
        } else {
            T[i] = 0;
            i++;
        }
    }

    return T;
}

vec kmp_search (vec &Text, vec &Pattern, vec &kmptable) {
    vec ret;
    ll m = 0, i = 0;
    while (m+i < Text.size()) {
        if (Pattern[i] == Text[m+i]) {
            i++;
            if (i == Pattern.size()) {
                ret.push_back(m);
                i--;
                m = m+i-kmptable[i];
                i = kmptable[i];
            }
        } else {
            m = m+i-kmptable[i];
            if (i > 0) i = kmptable[i];
        }
    } 
    return ret;
}

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

    ll N;
    cin >> N;
    vec A(N), B(N);
    Rep (i, N) cin >> A[i];
    Rep (i, N) cin >> B[i];

    vec da(N), db(N);
    Rep (i, N) {
        da[i] = A[i] ^ A[(i+1)%N];
        db[i] = B[i] ^ B[(i+1)%N];
    }

    da.resize(2*N-1);
    Rep (i, N-1) da[i+N] = da[i];

    vec t = kmp_table(db);
    t = kmp_search(da, db, t);
    Rep (i, t.size()) {
        cout << t[i] << " " << (A[0] ^ B[(N-t[i])%N]) << "\n";
    }

}

Measured memory_bytes: 13284
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_4_C_Dictionary
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var command = new string[n][];
            for (int i = 0; i < n; i++)
            {
                command[i] = Console.ReadLine().Split(' ');
            }
            var hash = new HashSet<string>();

            for (int i = 0; i < n; i++)
            {
                if(command[i][0]== "insert")
                {
                    hash.Add(command[i][1]);
                }
                else
                {
                    if (hash.Contains(command[i][1]))
                    {
                        Console.WriteLine("yes");
                    }
                    else
                    {
                        Console.WriteLine("no");
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 173756
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 30000;
	int l, r;
	cin >> l >> r;
	int mo[2019] = {};
	if(r-l+1 >= 2019){
		cout << 0 << endl;
		return 0;
	}
	else{
		for(int i = l; i<=r; i++){
			mo[i%2019]++;
		}
		for(int j = 0; j <2019; j++){
			for(int k = j+1; k<2019; k++){
				if(mo[j]==0 || mo[k]==0) continue;
				ans = min(ans, (j*k)%2019);
			}
		}
		cout << ans << endl;
	}
}

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

int main()
{
    int n,m;
    std::cin >> n >> m;
    int k;
    k = m * 1900 + (n - m) * 100;

    //幾何分布に従う
    int waru = std::pow(2,m);
    std::cout << k * waru << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

vector<int> ans(100005, -1);

vector<vector<int>> g(100005);


void bfs(int s) {
	queue<int> Q;
	Q.push(s);
	while (!Q.empty()) {
		int v = Q.front(); Q.pop();
		for (int to: g[v]) {
			if (ans[to] == -1) {
				ans[to] = v;
				Q.push(to);
			}
		}
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	rep (i, m) {
		int a, b;
		cin >> a >> b;
		g[a].pb(b);
		g[b].pb(a);
	}

	ans[1] = 0;

	bfs(1);

	cout << "Yes" << endl;
	for (int i = 2; i <= n; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 10344
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
class QuickUnionFind {
private:
	int size_; std::vector<int> g; std::vector<std::vector<int> > v;
public:
	QuickUnionFind() : size_(0), g(std::vector<int>()), v(std::vector<std::vector<int> >()) {};
	QuickUnionFind(int size__) : size_(size__) {
		g.resize(size_); v.resize(size_);
		for (int i = 0; i < size_; i++) g[i] = i, v[i] = { i };
	};
	int size() { return size_; }
	int root(int x) { return g[x]; }
	int size(int x) { return v[x].size(); }
	bool same(int x, int y) { return g[x] == g[y]; }
	void unite(int x, int y) {
		x = g[x], y = g[y];
		if (x == y) return;
		if (v[x].size() < v[y].size()) std::swap(x, y);
		v[x].insert(v[x].end(), v[y].begin(), v[y].end());
		for (auto &e : v[y]) g[e] = x;
		v[y].clear();
	}
	std::vector<int> connected(int x) { return v[g[x]]; }
	bool operator==(const QuickUnionFind& u) { return g == u.g; }
	bool operator!=(const QuickUnionFind& u) { return g != u.g; }
};
long long n, a[2000000], b[200000], c[200000], ret;
vector<tuple<int, int, int>>tup;
int main() {
	cin >> n; for (int i = 0; i < n - 1; i++) { cin >> a[i] >> b[i] >> c[i]; tup.push_back(make_tuple(c[i], a[i], b[i])); }
	sort(tup.begin(), tup.end()); QuickUnionFind UF(n);
	for (int i = 0; i < tup.size(); i++) {
		long long a1 = get<0>(tup[i]), a2 = get<1>(tup[i]), a3 = get<2>(tup[i]);
		ret += 1LL * a1*UF.size(UF.root(a2))*UF.size(UF.root(a3)); UF.unite(a2, a3);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 29420
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> path;
typedef pair<ll,P> now;
vector<path> E[101];
P V[55];
ll dp[55][2505];
ll N,M,S;
 
 
int main(){
    cin >> N >> M >> S;
    for(int i=0;i<M;i++){
        ll u,v,a,b;
        cin >> u >> v >> a >> b;
        E[u-1].push_back(path(P(a,b),v-1));
        E[v-1].push_back(path(P(a,b),u-1));
    }
    for(int i = 0;i<N;i++){
        ll C,D;
        cin >> C >> D;
        V[i] = P(C,D);
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<=50*N;j++){
            dp[i][j] = 1e16;
        }
    }
    
    priority_queue<now,vector<now>,greater<now>> que;
    if(N*50< S){
        S = N*50;
    }
    dp[0][S] = 0;
    que.push(now(0,P(S,0)));
    while(!que.empty()){
        now v = que.top();
        que.pop();
        ll time = v.first;
        ll money = v.second.first;
        ll position = v.second.second;
        if(dp[position][money] > time) continue;
        
        if(money < N*50){
            
            ll m;
            if(N*50 < money + V[position].first){
                m = N*50;
            }else{
                m = money + V[position].first;
            }
            
            if(dp[position][money]+V[position].second<dp[position][m]){
                dp[position][m] = dp[position][money]+V[position].second;
                que.push(now(dp[position][m],P(m,position)));
            }
        }
        for(int i=0;i<E[position].size();i++){
            path p = E[position][i];
            ll umoney = p.first.first;
            ll utime = p.first.second;
            ll to = p.second;
            if(money-umoney >= 0){
                if(dp[to][money-umoney]>dp[position][money] + utime){
                    dp[to][money-umoney] = dp[position][money] + utime;
                    que.push(now(dp[to][money-umoney],P(money-umoney,to)));
                }
            }
        }
    }
    
    for(int i=1;i<N;i++){
        ll mi = dp[i][0];
        for(int j = 0;j<=N*50;j++){
            if(mi > dp[i][j] ){
                mi = dp[i][j];
            }
        }
        cout << mi << endl;
    }
    
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve() {
    int x;
    cin >> x;
    if(x > 399 && x < 600) cout << 8;
    else if(x > 599 && x < 800) cout << 7;
    else if(x > 799 && x < 1000) cout << 6;
    else if(x > 999 && x < 1200) cout << 5;
    else if(x > 1199 && x < 1400) cout << 4;
    else if(x > 1399 && x < 1600) cout << 3;
    else if(x > 1599 && x < 1800) cout << 2;
    else if(x > 1799 && x < 2000) cout << 1;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
    ///cin >> t;
    while(t--) solve(), cout << '\n';
    return 0;
}


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

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    string s = read!string;

    bool good = true;
    for (int i = 1; i < s.length; i++) {
        if (s[i - 1] == s[i]) {
            good = false;
            break;
        }
    }
    writeln(good ? "Good" : "Bad");
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    ArrayList<Integer> fruit = new ArrayList<Integer>();
    for(int i = 0;i < n;i++){
      fruit.add(sc.nextInt());
    }
    int sum = 0;
    Collections.sort(fruit);
    for(int i = 0;i < k;i++){
      sum += fruit.get(i);
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 38688
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 998244353;
const int INF = 1e9 + 7;
const int MAXN = 3e6 + 5;
const double eps = 1e-9;
ll fac[MAXN], ifac[MAXN];

ll pw(ll a, ll b) {
	ll r = 1;
	while (b) {
		if (b & 1)
			r = (r * a) % MOD, b--;
		else
			a = (a * a) % MOD, b /= 2;
	}
	return r;
}

ll ncr(int n, int k) {
	return (fac[n] * ifac[k] % MOD) * ifac[n-k] % MOD;
}

int main() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 1; i < MAXN; i++) {
		fac[i] = (fac[i-1] * i) % MOD;
		ifac[i] = pw(fac[i], MOD - 2);
	}
	int n, m;
	scanf("%d %d", &n, &m);
	if (n == 2)
		return !pri(m+1);
	ll ans = ncr(3*m+n-1, n-1);
	for (int i = 2*m+1; i <= 3*m; i++)
		ans = (ans - (ll)n * ncr(3*m-i+n-2, n-2) % MOD + MOD) % MOD;
	for (int i = 0; i < m; i++)
		if (n >= 3*m-2*i)
			ans = (ans - ncr(i+n-1,n-1) * ncr(n, 3*m-i*2) % MOD + MOD) % MOD;
	prl(ans);
	return 0;
}


Measured memory_bytes: 47104
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ull unsigned long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a); i>=(b);i--)
 
const int maxn = 1e5 + 5;
const int maxm = 5000 + 5;
const int MOD = 1e9 + 7;
const int N = 1005;

ll n,k;
int a[2005];


ll inv(ll t, ll p) 
{
    return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p;
}


int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   // #ifndef ONLINE_JUDGE 
   //freopen("input.txt", "r", stdin);
   //#endif // ONLINE_JUDGE 
   cin >> n >> k;
   rep(i,1,n) cin >> a[i];
   ll ans = 0;
   ll inv2 = inv(2,MOD);
   rep(i,1,n){
        ll sum = 0;
        rep(j, i + 1, n) {
            if(a[i] > a[j]) sum++;
        }
        ans = (ans + sum * k % MOD * (k + 1)  % MOD * inv2 % MOD) % MOD;
        sum = 0;
         rep(j, 1, i - 1) {
            if(a[i] > a[j]) sum++;
        }
         ans = (ans + sum * k % MOD * (k - 1) % MOD * inv2 % MOD) % MOD;
   }
   cout << ans % MOD << endl;
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, m, l, i, j, k, e;
	long c_ij;

	scanf("%d %d %d", &n, &m, &l);

	int A[n][m];
	int B[m][l];

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

	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) {
			scanf("%d", &e);
			B[i][j] = e;
		}
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			c_ij = 0;
			for (k = 0; k < m; k++) {
				c_ij += A[i][k] * B[k][j];
			}
			printf("%ld", c_ij);
			if (j != l - 1) putchar(' ');
		}
		putchar('\n');
	}

	return 0;
}

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

const int M=100010;

int n,a,b,ans;
int h[M];

bool check(int x)
{
	long long cnt=0;
	for(int i=0;i<n;i++)
		if(h[i]>1ll*b*x)
			cnt+=(h[i]-b*x+a-b-1)/(a-b);
	return cnt<=x;
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>a>>b;
	for(int i=0;i<n;i++)
		cin>>h[i];
	sort(h,h+n,less<int>());
	int l=0,r=1e9;
	while(l<r)
	{
		int mi=l+r>>1;
		if(check(mi)) r=mi;
		else l=mi+1;
	}
	cout<<l;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

#define MAX 500000
int h,a[MAX+1];

void maxHeapify(int i){
  int l,r,est,tmp;

  l=2*i;
  r=2*i+1;
  if(l<=h && a[l]>a[i]){est=l;}
  else{est=i;}
  if(r<=h && a[r]>a[est]){est=r;}
  if(est!=i){
    tmp=a[est];
    a[est]=a[i];
    a[i]=tmp;
    maxHeapify(est);
  }
}

int main()
{
  int i;
  scanf("%d",&h);
  for(i=1;i<=h;i++) scanf("%d",&a[i]);
  for(i=h/2;i>=1;i--) maxHeapify(i);
  for(i=1;i<h+1;i++){
    if(i>0){printf(" ");}
    printf("%d",a[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 3732
#include <stdio.h>
const int MAX_V = 999999;

int main() {
	int i, k, n, cnt;
	int prime[MAX_V + 1];
	for( i = 2; i <= MAX_V; i++) {
		 prime[i] = 1;
	}
	for( i = 2; i * i <= MAX_V; i++) {
		if(prime[i]) {
			for( k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	while(scanf("%d", &n) != EOF) {
		cnt = 0;
		for( i = 2; i <= n; i++) {
			if(prime[i]) cnt++;
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 4500
#include<stdio.h>

int main(){
	char a, b;
	
	scanf("%c %c", &a, &b);
	
	if(a=='H'){
		b=b;
	}
	if(a=='D'){
		if(b=='D')b='H';
		else if(b=='H')b='D';
	}
	printf("%c\n", b);
	return 0;
}

Measured memory_bytes: 128