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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

map<ll,ll> mp;
ll n,a,b,c,d;

ll rec(ll x){
    //cout<<x<<en;
    if(mp.find(x)!=mp.end()) return mp[x];
    ll ret=INF;
    if((ll)2e9+10>=x) chmin(ret, x*d);
    chmin(ret, rec(x/2)+a+x%2*d);
    if((x+1)/2!=x) chmin(ret, rec((x+1)/2)+a+x%2*d);
    chmin(ret, rec(x/3)+b+x%3*d);
    if((x+2)/3!=x) chmin(ret, rec((x+2)/3)+b+(3-x%3)*d);
    chmin(ret, rec(x/5)+c+x%5*d);
    if((x+4)/5!=x) chmin(ret, rec((x+4)/5)+c+(5-x%5)*d);
    //cout<<x<<":"<<ret<<en;
    return mp[x] = ret;
}

void solve(){
    cin>>n>>a>>b>>c>>d;
    mp.clear();
    mp[0]=0;
    cout<< rec(n) <<en;
    
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	//solve();
	ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 4436
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> c(100010);
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
		c[a[i]]++;
		c[a[i] + 1]++;
		c[a[i] + 2]++;
	}
	cout << *max_element(all(c)) << endl;
	return 0;
}

Measured memory_bytes: 1024
a,b,c=map(int,input().split())
#GCD of a,b
gcd=1
for i in range(2,100):
    if a%i==0 and b%i==0:
        gcd=max(gcd,i)
#print(gcd)
if c%gcd==0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9072
#include<stdio.h>
#include<math.h>
main(){
  int a;
  float c,d;
  scanf("%d",&a);
  if( a % 2 == 0 ){
  	c=a/2;
  	d=c/a;
  printf("%f",d);
  } else {
  	c=a/2;
  	c=c+1;
  	d=c/a;
  printf("%f",d);
  }
  
  }
  

Measured memory_bytes: 128
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
namespace mp = boost::multiprecision;
using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,k;
  ll ans=0;
  cin>>n>>k;
  cout<<n-k+1<<endl;
}


Measured memory_bytes: 888
import java.io.*;
    
class Main
{
     static InputStreamReader isr;
     static BufferedReader br;
     static String output;
     static String[] data = new String[3];
    
     static void initialize ()
     {
          isr = new InputStreamReader(System.in);
          br = new BufferedReader(isr);
          output = null;
          for (String d : data)
          {
               d = null;
          }
     }

     static void output (String[] data)
     {
           int i = 0;
           output = "No";
           if (Integer.parseInt(data[i])-Integer.parseInt(data[++i]) < 0) if (Integer.parseInt(data[i])-Integer.parseInt(data[++i]) < 0) output = "Yes";
           System.out.println(output);
     }
    
     public static void main (String[] args)
     {
           initialize();
           try {
                data = (br.readLine()).split(" ");
                output(data);
           } catch (IOException e) {
           } finally {
                try {
                      br.close();
                } catch (IOException e) {
                }
           }
     }
}

Measured memory_bytes: 24396
#include<iostream>

using namespace std;

const int N = 1e5+1;
int h[N];
int dp[N];

int main(){
  int n;
  cin >> n;
  for(int i = 1; i<=n; i++){
    cin >> h[i];
  }
  for (int i = 3; i <= n; i++){
    dp[i] = 2147483647;
  }
  dp[1]=0;
  dp[2]=abs(h[2]-h[1]);
  for(int i = 1; i<n-1; i++){
    if(dp[i+2]>dp[i+1]+abs(h[i+2]-h[i+1]))
      dp[i+2] = dp[i+1]+abs(h[i+2]-h[i+1]);
    if(dp[i+2]>dp[i]+abs(h[i+2]-h[i]))
      dp[i+2] = dp[i]+abs(h[i+2]-h[i]);
  }
  cout << dp[n] << endl;
return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  long long sum = 0;
  vector<pair<long long,long long>> ab(N);
  for(int i = 0;i < N;i++) {
    cin >> ab.at(i).first;
    sum += ab.at(i).first;
  }

   for(int i = 0;i < N;i++) {
    cin >> ab.at(i).second;
    ab.at(i).first -= ab.at(i).second; 
   }

    sort(ab.begin(),ab.end());

    int ans = 0;
    for(int i = 0;i < N;i++) {
      sum -= ab.at(i).second;
      if(ab.at(i).first < 0) ans++;
      if(sum < 0) {
          cout << -1 << endl;
          return 0;
      }
    }

    for(int i = 0;i < N;i++) {
      if(ab.at(i).first > 0) {
        sum -= ab.at(i).first;
        if(sum < 0) ans++;
        if(sum > 0 && i == N-1) ans++;
      }
    }

    cout << ans << endl;


}


Measured memory_bytes: 1792
count = int(input())
sum_n = 0
sum_list = []

li = list(map(int, input().split(" ")))

for i in range(min(li),max(li) + 1):
  for j in li:
    sum_n += (i - j)**2
  sum_list.append(sum_n)
  sum_n = 0
    
print(min(sum_list))

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int a, b;
  scanf("%d %d", &a, &b);
  if (b % a == 0)
    printf("%d\n", a + b);
  else
    printf("%d\n", b - a);
  return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
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; }

typedef tuple<ll, ll, ll, ll> in;

vector<in> nums(50);
ll n, m, q;
ll ans;

vector<ll> buf;
void dfs(ll i, const ll size, const ll range_start, const ll range_end)
{
	if (i == size) {
		ll s = 0;
		rep(i, q)
		{
			if (buf[get<1>(nums[i]) - 1] - buf[get<0>(nums[i]) - 1] == get<2>(nums[i]))
				s += get<3>(nums[i]);
		}
		chmax(ans, s);
	}
	else {
		for (ll j = range_start; j <= range_end; ++j) {
			buf[i] = j;
			dfs(i + 1, size, j, range_end);
		}
	}
}

int main()
{
	cout << fixed << setprecision(18);
	cin >> n >> m >> q;

	ll a, b, c, d;
	ans = 0;

	rep(i, q)
	{
		cin >> a >> b >> c >> d;
		nums[i] = {a, b, c, d};
	}

	buf.resize(n);

	dfs(0, n, 1, m);

	cout << ans << endl;

	return 0;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;

    vector<vector<int>> F(N, vector<int>(10));
    REP(i, N) {
        REP(j, 10) {
            std::cin >> F[i][j];
        }
    }
    vector<vector<int>> P(N, vector<int>(11));
    REP(i, N) {
        REP(j, 11) {
            std::cin >> P[i][j];
        }
    }

    ll max_profit = -INF;
    for(size_t i = 1; i < (1 << 10); i++) {
        ll profit = 0;
        REP(k, N) {
            int cnt = 0;
            for(size_t j = 0; j < 10; j++) {
                if(i & (1 << j)) {
                    cnt += F[k][j] ? 1 : 0;
                }
            }
            profit += P[k][cnt];
        }
        chmax(max_profit, profit);
    }

    std::cout << max_profit << std::endl;

    return 0;
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 

	int a , b , c , d;
	cin >> a >> b >> c >> d;
	
	int l = max(a , c);
	int r = min(b , d);
	
	int ans = max(r - l , 0);
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace AtcoderExpress
{


    class Program2
    {

        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            var nums = new long[N + 1];
            for (int i = 0; i < N; i++)
            {
                nums[A[i]]++;
            }

            var sum = 0L;
            for (int i = 1; i <= N; i++)
            {
                sum += (nums[i] * (nums[i] - 1)) / 2;
            }
            //Console.WriteLine(sum);

            for (int i = 0; i < N; i++)
            {
                var tmp = ((nums[A[i]] - 1) * (nums[A[i]] - 2))/2 - nums[A[i]] * (nums[A[i]] - 1)/2;
                Console.WriteLine(sum+tmp);
            }
        }


    }
}


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

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

int main(){
  int n,m;
  ll k;
  cin >> n >> m >> k;

  vector<ll> a(n);
  vector<ll> b(m);
  rep(i,n) cin >> a.at(i);
  rep(i,m) cin >> b.at(i);

  vector<ll> suma(n);
  vector<ll> sumb(m);

  suma.at(0) = a.at(0);
  sumb.at(0) = b.at(0);
  rep(i,n-1) suma.at(i+1) = suma.at(i) + a.at(i+1);
  rep(i,m-1) sumb.at(i+1) = sumb.at(i) + b.at(i+1);

  ll ans=0;
  rep(i,n){
    if(suma.at(i)>k) break;
    ll rest = k - suma.at(i);
    int j = upper_bound(sumb.begin(), sumb.end(), rest) - sumb.begin();
    //cout << j << endl;

    if(i+j+1>=ans) ans = i+j+1;
  }

  rep(i,m){
    if(sumb.at(i)>k) break;
    if(i+1>ans) ans = i+1;
  }
  
  //rep(i, suma.size()) cout << suma.at(i) << endl;

  cout << ans;
}

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

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

  if (A+B>C+D) {
    cout<<"Left"<<endl;
  }
  else if (A+B==C+D){
    cout<<"Balanced"<<endl;
  }
  else cout<<"Right"<<endl;
}

Measured memory_bytes: 256
/* ALDS1_5_A: Exhaustive */
/* 20181118 */

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#define N 20
#define M 200

int flag[40000], n, A[N];

void exhaustiveSearch(int m, int sum);

int main(void){
	int i = 0, q, Q[M];
	
	scanf("%d", &n);
	while(i < n){
		scanf("%d", &A[i++]);
	}

	exhaustiveSearch(0, 0);
	i = 0;
	scanf("%d", &q);
	while(i < q){
		scanf("%d", &Q[i]);
		if(flag[Q[i++]]){
			puts("yes");
		}else{
			puts("no");
		}
	}

	return 0;
}

void exhaustiveSearch(int m, int sum){
	if(m == n){
		flag[sum] = 1;
		return ;
	}

	exhaustiveSearch(m + 1, sum);
	exhaustiveSearch(m + 1, sum + A[m]);
}



Measured memory_bytes: 1968
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  int res=0,a,b=1;
  vector<int> c(n,0);
  for(a=1; a*b<n; ++a){
    for(b=1; a*b<n; ++b){
      c[n-a*b]++;
    }
    b=1;
  }
  for(int i=1; i<n; ++i) res+=c[i];
  cout<<res;
  return 0;
}

Measured memory_bytes: 7132
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <iterator>
using namespace std;

struct UnionFind {
    vector<int> data;
    UnionFind(int n) : data(n, -1) { }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    bool same(int x, int y) { return root(x) == root(y); }
    void merge(int x, int y) {
        x = root(x); y = root(y);
        if(x != y) {
            data[x] += data[y];
            data[y] = x;
        }
    }
};

int main() {
    int V, E; cin >> V >> E;
    vector<pair<int, pair<int, int> > > ES(E);
    for(int i = 0; i < E; i++) {
        cin >> ES[i].second.first >> ES[i].second.second >> ES[i].first;
    }
    sort(begin(ES), end(ES));
    int ans = 0;
    UnionFind uf(V);
    for(auto item : ES) {
        if(uf.same(item.second.first, item.second.second) == false) {
            ans += item.first;
            uf.merge(item.second.first, item.second.second);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2400
// alds87.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<string>
#include<algorithm>

#define LEN 100005
using namespace std;
	int head, tail, n;
typedef struct pp_ {
	string ps;
	int time;
} pp;
vector<pp>Q(LEN); // 配列を準備する
void enqueue(pp x) {
	Q.at(tail) = x;
	tail = (tail + 1) % LEN;
}
pp dequeue() {
	pp x = Q.at(head);
	head = (head + 1) % LEN;
	return x;
}
int main()
{
	int q; // クオンタム
	int x; // 各処理時間
	string s; // 名前
	cin >> n >> q;
	for (int i = 0; i < n; i++)
	{
		cin >> s >> x;
		Q.at(i).ps = s;
		Q.at(i).time = x;
	}
	head = 0;
	tail = n;

	int elaps = 0; // 経過時間
	while (head!=tail)
	{
		pp u = dequeue();
		elaps += min(u.time, q);
		u.time = u.time - min(u.time, q);
		if (u.time>0)
		{
			enqueue(u);
		}
		else {
			cout << u.ps << " " << elaps << endl;
		}
	}

}
/*
5 100
p1 150
p2 80
p3 200
p4 350
p5 20

*/



Measured memory_bytes: 6728
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define FOR(i, l, r) for(int i = l; i < r; i++)
#define RFOR(i, l,r) for(int i= (l)-1; i>= (r) ; i--)

int main()
{
    ios::sync_with_stdio(false);
    int a = 0, b = 0;
    REP(i, 3)
    {
        int tmp;
        cin >> tmp;
        if(tmp == 5)
            a++;
        else if(tmp == 7)
            b++;
    }
    if(a==2 && b==1)
        cout << "YES\n";
    else
        cout << "NO\n";

}



Measured memory_bytes: 256
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = getlist()
	ans = 0
	for i in range(1, N):
		if (N - 1) % i == 0:
			var = 0
			left = 0; right = 0
			cnt = 0
			while True:
				if 2 * i * cnt >= N - 1:
					break
				left += S[i * cnt]
				right += S[N - 1 - i * cnt]
				var = max(var, left + right)
				cnt += 1

			ans = max(ans, var)

		else:
			var = 0
			left = 0; right = 0
			cnt = 0
			while True:
				if i * cnt > N - 1 - i:
					break
				left += S[i * cnt]
				right += S[N - 1 - i * cnt]
				var = max(var, left + right)
				cnt += 1

			ans = max(ans, var)

	print(ans)

if __name__ == '__main__':
	main()

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

int main() {
	int N, K;
	cin >> N >> K;
	vector<ll> A(N);
	rep(i, N) cin >> A[i];

	for(int i = K; i < N; i++) {
		if(A[i - K] < A[i])
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int x, n;
    cin >> x >> n;
    set<int> st;
    for (int i = 0; i < n; i++) {
        int z;
        cin >> z;
        st.insert(z);
    }
    int opt = 0;
    for (int i = 0; i <= 101; i++) {
        if (st.find(i) != st.end()) continue;
        if (abs(i - x) < abs(opt - x)) {
            opt = i;
        }
    }
    cout << opt << '\n';

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  string s;
  int n;
  cin >> s;
  n = s.length();
  int cur = 0;
  int ans = 0;
  stack<char> st;
  rep(i, n) {
    if(st.empty()) {
      st.push(s[i]);
    } else {
      char c = st.top();
      if (c == 'S' && s[i] == 'T') st.pop();
      else st.push(s[i]);
    }
  }
  cout << st.size() << endl;
}

Measured memory_bytes: 644
H, W, A, B = map(int, input().split())
x = '1' * (W-A)
y = '0' * (W-A)
x = x.rjust(W, "0")
y = y.rjust(W, "1")

for i in range(B):
  print(x)
for i in range(H-B):
  print(y)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> cnt(n, 0);
  REP(i, n) { cin >> a[i]; }
  sort(ALL(a));
  reverse(ALL(a));
  ll ans = 0, c = 0, c2 = 0;

  cnt[0] = 1;
  while (1) {
    if (cnt[c] <=1) {
      ans += a[c];
      cnt[c]++;
      c2++;
    } else
      c++;
    if (c2 == n-1) break;
  }
  cout << ans << "\n";
  return 0;
}


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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint>PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};


int N;
int a[]={2,5,63,20,30};
ll gcd(ll x,ll y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}
signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>N;
    if(N<=5){
        rep(i,0,N){
            cout<<a[i];
            if(i!=N-1)cout<<" ";
        }
        return 0;
    }
   vint ans;
   rep(i,0,30000/4+1){
       ans.pb(i*6+2);
       ans.pb(i*6+3);
       ans.pb(i*6+4);
       ans.pb((i+1)*6);
   }
   if(N%8==7||N%8==0){
       rep(i,0,N){
           cout<<ans[i];
           if(i!=N-1)cout<<" ";
       }
   }else if(N%8==1||N%8==6){
        rep(i,0,N){
            if(ans[i]==8)continue;
            cout<<ans[i]<<" ";
        }
        cout<<30000;
    }else if(N%8==3||N%8==4){
        rep(i,0,N){
            if(ans[i]==9)continue;
            cout<<ans[i]<<" ";
        }
        cout<<30000;
    }else {
        rep(i,0,N){
            if(ans[i]==9)continue;
            cout<<ans[i]<<" ";
        }
        cout<<29998;
    }
    cout<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 764
n,k = map(int, input().split())
res = [0]*(10**5+1)
for _ in range(n):
    a,b = map(int, input().split())
    res[a] += b

for i, x in enumerate(res):
    if k>x:
        k -= x
    else:
        print(i)
        exit()

Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

const int N = 300005;

int n;
LL a[N];

int main()
{
    cin >> n;
	for (int i = 1; i <= 3 * n; i++) cin >> a[i];
	sort(a + 1, a + 3 * n  + 1);
	LL ans = 0, t = 3 * n - 1;
	for (int i = 1; i <= n; i++) ans += a[t], t -= 2;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{    

    class Program
    {      
        

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] input;
            string order;
            int key = 0;

            var data = new LinkedList<int>();
            
            for(int i = 0; i < n; i++)
            {
                input = Console.ReadLine().Split(' ');
                order = input[0];
                if(input.Length != 1)

                {
                    key = int.Parse(input[1]);
                }                

                if(order[0] == 'i')
                {
                    data.AddFirst(key);
                }
                else
                {
                    if(order == "delete")
                    {
                        data.Remove(key);
                    }
                    else if(order[6] == 'F')
                    {
                        data.RemoveFirst();
                    }
                    else if(order[6] == 'L')
                    {
                        data.RemoveLast();
                    }
                    
                }
            }

            Console.WriteLine(String.Join(" ", data));
            

        }
    }
}



Measured memory_bytes: 71208
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{	
	int W, H, x, y;
	cin >> W >> H >> x >> y;
	double S = (double)W*H*0.50;
	bool b = false;
	if(2*x == W && 2*y == H) b = true;
	cout << fixed << setprecision(12);
	if(b) cout << S << " " << 1 << endl;
	else cout << S << " " << 0 << endl;
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<exception>
#include<stdexcept>
#include<streambuf>
#include<iterator>
#include<string.h>
#include<stdlib.h>
#include<typeinfo>
#include<valarray>
#include<iostream>
#include<sstream>
#include<istream>
#include<stdio.h>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<ctype.h>
#include<cassert>
#include<cstdlib>
#include<utility>
#include<cstring>
#include<numeric>
#include<ostream>
#include<cwctype>
#include<fstream>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cctype>
#include<string>
#include<vector>
#include<limits>
#include<locale>
#include<memory>
#include<cerrno>
#include<time.h>
#include<iosfwd>
#include<cfloat>
#include<cstdio>
#include<cwchar>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<ios>
#include<map>
#include<set>
#include<new>
#define LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define FILLBIG(a) FILL(a,0x7f)
#define ALL(a) (a).begin(),(a).end()
#define Inf ((int)0x7f7f7f7f)
#define Mod 1000000007
#define foreach(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
#define fastio ios::sync_with_stdio(0)
#define filei(f) freopen(f,"r",stdin)
#define fileo(f) freopen(f,"w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define MASK(a) (1<<(a))
#define MASKX(x,a) ((x)<<(a))
#define BIT(a,b) ((a>>b)&1)
#define cddx(a) priority_queue<a >
#define cxdd(a) priority_queue<a,vector<a >,greater<a > >
#define deval(a) {cerr<<#a<<" = "<<a<<endl;}
#define dearr(be,en) {cerr<<#be;cerr<<" = {";for(auto i=be;i!=en;i++)cerr<<' '<<*i;cerr<<" }\n";}
#define reg register
using namespace std;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int uint;
typedef long long INT;
typedef long double ldouble;
typedef pair<INT,INT> PII;
typedef stringstream sst;
typedef istringstream iss;
typedef vector<int> vint;
typedef vector<INT> VINT;
typedef vector<pii> vpii;
typedef vector<PII> VPII;
typedef priority_queue<int> pqi;
typedef priority_queue<INT> PQI;
typedef priority_queue<pii> pqp;
typedef priority_queue<PII> PQP;
typedef priority_queue<int,vint,greater<int> > xqi;
typedef priority_queue<INT,VINT,greater<INT> > XQI;
typedef priority_queue<pii,vpii,greater<pii> > xqp;
typedef priority_queue<PII,VPII,greater<PII> > XQP;
const int INF=1e9+7;
using namespace std;
int n,a,b;
int main()
{
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n>>a>>b;
	cout<<min(a*n,b);
	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 reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define lin(n) ll n;scanf("%lld",&n)
#define itn int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define in insert
#define emp emplace
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define LINE puts("------------------");
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef struct{ll to;ll cost;} Graphs;
typedef V<V<Graphs>> AdjList;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T center(T a,T b,T c){
  if( (a<=b&&b<=c)||(a>=b&&b>=c) )return b;
  if( (b>=a&&a>=c)||(b<=a&&a<=c) )return a;
  return c;
}
inline void print(){cout<<endl;}
template<class Head,class... Tail>
inline void print(Head&& head, Tail&&... tail){
  cout<<head<<", ";
  print(forward<Tail>(tail)...);
}
inline void input(){}
template<class Head,class... Tail>
inline void input(Head&& head, Tail&&... tail){
  cin>>head;
  input(forward<Tail>(tail)...);
}
template<typename T>
inline ostream &operator<<(ostream&out,const vector<T>&v){
  if(!v.empty()){
    copy(v.begin(),v.end(),ostream_iterator<T>(out,", "));
    out<<"\b\b";
  }
  return out;
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream&out,const pair<T1,T2>&p){
  out<<p.first<<", "<<p.second;
  return out;
}
template<typename T>
inline ostream &operator<<(ostream&out,const set<T>&st){
  for(const auto&elemnt:st)out<<elemnt<<", ";
  return out;
}
template<typename T1,typename T2>
inline ostream &operator<<(ostream&out,const vector<pair<T1,T2>>&vp){
  for(const auto &element:vp)
    out<<element.first<<", "<<element.second<<"\n";
  return out;
}
template<typename T>
inline istream &operator>>(istream&input,vector<T>&v){
  for(T&elemnt:v)input>>elemnt;
  return input;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  ll a,b;
  cin>>a>>b;
  out(max({a+b,a-b,a*b}));


  return 0;
}


Measured memory_bytes: 256
N, M, C= map(int, input().split())
B = list(map(int, input().split()))

res = 0
c = -C

for _ in range(N):
    A = list(map(int, input().split()))
    t = 0
    for i in range(M):
        t += A[i] * B[i]

    if t > c:
        res += 1

print(res)

Measured memory_bytes: 9080
from collections import deque

N, M = [int(n) for n in input().split()]
n = [[] for _ in range(N)]

def dfs(p, done):
    curr = p[-1]
    nodes = n[curr]
    paths = list(set(nodes) - set(p))
    for path in paths:
        p.append(path)
        dfs(p, done)
    if not paths:
        done.append(list(p))
    del p[-1]
        
def main():
    for _ in range(M):
        a, b = map(lambda s: int(s) - 1, input().split())
        n[a].append(b)
        n[b].append(a)
    done = []
    p = deque([0])
    dfs(p, done)
    ans = sum(1 for li in done if len(li) == N)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4204
K = int(input())


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


ans = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
            ans += gcd(gcd(a+1, b+1), c+1)

print(ans)


Measured memory_bytes: 77532
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ull H;
	cin >> H;

	ull power = 0;
	while (true){
		// ull tmp = 2 << power;
		// if (tmp > H){
		if (pow(2, power) > H) {
			// value = tmp - 1;
			break;
		} else {
			power++;
		}
	}

	ull value = pow(2, power) - 1;
	cout << value << endl;


	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
//#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 1005  //check the limits, man
const ll INF = 1e12;
int main()
{
    int n,i,f;
    string str;
    llin(str);
    n=str.size();
    string A="dream";
    string B="dreamer";
    string C="erase";
    string D="eraser";
    reverse(all(str));
    reverse(all(A));
    reverse(all(B));
    reverse(all(C));
    reverse(all(D));
    i=0,f=1;
    string temp;
    temp=str.substr(i,5);
    while(i<n & f)
    {
        f=0;
        if(i+4<n)
        {
            temp=str.substr(i,5);
            if(temp==A || temp==C)
                f=1,i+=5;
        }
        if(i+5<n && !f)
        {
            temp=str.substr(i,6);
            if(temp==D)
                f=1,i+=6;
        }
        if(i+6<n && !f)
        {
            temp=str.substr(i,7);
            if(temp==B)
                f=1,i+=7;
        }
    }
    if(f)
        yes;
    else
        no;
}




Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

// Mod int
// cf. https://www.youtube.com/watch?v=1Z6ofKN03_Y
struct mint {
  ll x;
  mint(ll x = 0) : x((x + MOD) % MOD) {}
  mint& operator+= (const mint a) {
    if ((x += a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator+ (const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint& operator-= (const mint a) {
    if ((x += MOD - a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator- (const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint& operator*= (const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  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;
  }
};

mint dp0[2005][2005];
mint dp1[2005][2005];

int main(int argc, char** argv) {
  ll N, M;
  cin >> N >> M;
  vector<ll> S(N+1); // S[N] is dummy
  vector<ll> T(M+1); // T[M] is dummy
  rep(i, N) {
    cin >> S[i];
  }
  rep(i, M) {
    cin >> T[i];
  }

  dp0[0][0] = 1;
  rep(i, N+1) rep(j, M+1) {
    dp0[i+1][j] += dp0[i][j]; // i increaes in dp0
    dp1[i][j] += dp0[i][j];
    dp1[i][j+1] += dp1[i][j]; // j increaes in dp1
    if (S[i] == T[j]) {
      dp0[i+1][j+1] += dp1[i][j];
    }
  }

  mint ans = dp1[N][M];
  cout << ans.x << endl;
}


Measured memory_bytes: 63104
#include <bits/stdc++.h>
using namespace std;
pair<int, int> operator +(pair<int, int> a, int val) {
  auto func = [&] (int x) {
    return (x / 3) * 2 + (x % 3 != 0);
  };
  pair<int, int> res = {max(a.second + func(val - 1) + 1, a.first + func(val)),
                        a.first + func(val - 1)
                       };
  if (val >= 2) {
    res.second = max(res.second, a.second + func(val - 2) + 1);
  }
  return res;
}
int main() {
  string str;
  cin >> str;
  vector<int> vec;
  for (int i = 0, j = 0; i < str.size(); i++) {
    if (i + 1 == str.size() || str[i] != str[i + 1]) {
      vec.push_back(i - j + 1);
      j = i + 1;
    }
  }
  pair<int, int> current = {0, INT_MIN};
  for (int val : vec) {
    current = current + val;
  }
  cout << current.first << endl;
  return 0;
}


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

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

    int n = s.size();
    int ans = 0;
    rep(i, n / 2)
        if (s[i] != s[n - 1 - i])
            ans++;

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

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
 
 
int main () {
    int n, w, i, j, itmv, itmw, v1, v2;
    int value[100], weight[100];
    int **wv, *wv_data;
 
    scanf("%d %d", &n, &w);
    for (i=0; i<n; i++) {
        scanf("%d %d", &value[i], &weight[i]);
    }
 
    wv_data = (int*)malloc(sizeof(int) * (n+1) * (w+1));
    wv = (int**)malloc(sizeof(int*) * (n+1));
    for (i = 0; i <= n; i++) {
        wv[i] = &(wv_data[i*(w+1)]);
    }
 
    for (i=0; i <= w; i++) {
        wv[0][i] = 0;
    }
    for (i=1; i <= n; i++) {
        wv[i][0] = 0;
    }
 
    for (i = 1; i <= n; i++) {
        itmv = value[i-1];
        itmw = weight[i-1];
        for (j = 1; j <= w; j++) {
            if (j >= itmw) {
                v1 = wv[i][j-itmw] + itmv;
                v2 = wv[i-1][j];
                wv[i][j] = v1 > v2 ? v1 : v2;
            }
            else {
                wv[i][j] = wv[i-1][j];
            }
        }
    }
    printf("%d\n", wv[n][w]);
 
    free(wv_data);
    free(wv);
 
    return 0;
}


Measured memory_bytes: 5508
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    L = list(map(int, input().split()))

    return N, L


def main(L: list) -> None:
    """
    メイン処理.

    Args:\n
        L (list): 棒の長さ
    """
    # 求解処理
    ans = 0
    for L_i, L_j, L_k in itertools.combinations(L, 3):
        if (L_i == L_j) or (L_j == L_k) or (L_k == L_i):
            continue
        if L_i + L_j + L_k > 2 * max(L_i, L_j, L_k):
            ans += 1

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, L = get_input()

    # メイン処理
    main(L)


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

vector <int> edges[2000];
int a[2000];
int b[2000];

int d[2000];

void bfs_init(int N){
    for(int i = 0; i < N; i++){
        d[i] = -1;
    }
    return;
}

void bfs(int start){
    queue <int> q;
    q.push(start);
    while(!q.empty()){
        int cur = q.front();
        q.pop();
        for(int i = 0; i < edges[cur].size(); i++){
            int next = edges[cur][i];
            if(d[next] < 0){
                d[next] = d[cur] + 1;
                q.push(next);
            }
        }
    }
    return;
}

int main(void){
    // Your code here!
    int N;
    int K;
    cin >> N;
    cin >> K;
    for(int i = 0; i < N - 1; i++){
        cin >> a[i] >> b[i];
        edges[a[i] - 1].push_back(b[i] - 1);
        edges[b[i] - 1].push_back(a[i] - 1);
    }
    
    int ans = 0;
    if(K % 2 == 0){
        for(int i = 0; i < N; i++){
            int tmp_ans = 0;
            bfs_init(N);
            d[i] = 0;
            bfs(i);
            for(int i = 0; i < N; i++){
                if(d[i] <= K / 2){
                    tmp_ans ++;
                }
            }
            ans = max(ans, tmp_ans);
        }
    } else {
        for(int i = 0; i < N - 1; i++){
            int tmp_ans = 0;
            bfs_init(N);
            d[a[i] - 1] = 0;
            d[b[i] - 1] = 0;
            bfs(a[i] - 1);
            bfs(b[i] - 1);
            for(int i = 0; i < N; i++){
                if(d[i] <= K / 2){
                    tmp_ans ++;
                }
            }
            ans = max(ans, tmp_ans);
        }
    }
    cout << N - ans << endl;
    return 0;
}

Measured memory_bytes: 384
import math
import sys
readline = sys.stdin.readline


def main():
    x, y = map(int, readline().rstrip().split())
    c = y - 2 * x
    a = c % 2 == 0 and c >= 0 and y - 4 * x <= 0
    print('YNeos'[not(a)::2])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9024
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def extgcd(a,b): # ax+by=1 をみたす(x,y)の組を求める
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return ( m + x%m ) % m
    
def nCk(n,k):
    res = 1
    a=n-k
    b=k
    for i in range(1,a+b+1):
        res = res*i%mod
    for i in range(1,a+1):
        res = res*mod_inv(i,mod)%mod
    for i in range(1,b+1):                                 
        res = res*mod_inv(i,mod)%mod
    return res
    
def main():
    n,k = inpm()
    z = inpl()
    z.sort()
    ans = 0

    res = 1
    a=n-k
    b=k-1
    for i in range(1,b+1):                                 
        res = res*mod_inv(i,mod)%mod
    for i in range(1,b+1):
        res = res*i%mod
    for i in range(1,a+2):
        ans = ( ans + z[k-2+i]*res)%mod
        ans = ( ans - z[n-k+1-i]*res)%mod
        res = res*(i+b)%mod
        res = res*mod_inv(i,mod)%mod
    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 67100
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (A == B) {
			System.out.println("Draw");
		} else if ((A > B) && (B != 1) || (A == 1)) {
			System.out.println("Alice");
		} else {
			System.out.println("Bob");
		}
	}
}

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


int main(){
  int K;
  string S;
  
   cin >> K >> S;
  
  if(S.size()<=K) {
    cout << S << endl;
    return 0; 
  }
  else{
    rep(i,K){
     cout << S.at(i);
    }
     cout << "..."<< endl;
     return 0;
  }
  
}
    
  


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 
vector<map<P,int>> m(15);
int c[4][6]={
    {3,0,1,2,4,5},
    {1,2,3,0,4,5},
    {4,1,5,3,2,0},
    {5,1,4,3,0,2}
};

void rec(int k,int i,int y,int x,string s,vector<int> v){
    m[i][{y,x}]=v[0];
    if(s.length()==k) return;
    vector<int> t(6);
    if(s[k]=='L'){
        for (int j = 0; j < 6; j++) {
            t[j]=v[c[0][j]];
        }
        rec(k+1,i,y,x-1,s,t);
    }
    else if(s[k]=='R'){
        for (int j = 0; j < 6; j++) {
            t[j]=v[c[1][j]];
        }
        rec(k+1,i,y,x+1,s,t);
    }
    else if(s[k]=='F'){
        for (int j = 0; j < 6; j++) {
            t[j]=v[c[2][j]];
        }
        rec(k+1,i,y-1,x,s,t);
    }
    else{
        for (int j = 0; j < 6; j++) {
            t[j]=v[c[3][j]];
        }
        rec(k+1,i,y+1,x,s,t);
    }
}



int main(){
    int n;
    while(cin >> n,n){
        m.clear();
        m.resize(16);
        for (int i = 0; i < n; i++) {
            int x,y;cin >> x >> y;
            vector<int> u(6);
            cin >> u[3] >> u[1] >> u[4] >> u[5] >> u[0] >> u[2];
            string ss;cin >> ss;
            rec(0,i,y,x,ss,u);
        }
        vector<int> dp((1<<n)+1,-INF);
        dp[0]=0;
        int ans=-INF;
        for (int bit = 0; bit < 1<<n; bit++) {
            ans=max(ans,dp[bit]);
            for (int i = 0; i < n; i++) {
                if(bit&(1<<i)) continue;
                int sum = 0;
                for (auto p:m[i]) {
                    P t=p.first;
                    bool f=true;
                    for (int j = 0; j < n; j++) {
                        if(bit&(1<<j)){
                            if(m[j].find(t)!=m[j].end()){
                                f=false;
                                break;
                            }
                        }
                    }
                    if(f) sum+= p.second;
                }
                int nx = bit|(1<<i);
                dp[nx]=max(dp[nx],dp[bit]+sum);
            }
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3260