akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

int main() {
	double n;
	cin >> n;
	double pi = 3.14159;
	cout << n * 2 * pi << endl;
}


Measured memory_bytes: 3760
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<double> a(n);
	vector<string> b(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
		cin >> b.at(i);
	}
	long double sum=0;
	for (int i = 0; i < n; i++)
	{
		if (b.at(i) == "JPY")
			sum += a.at(i);
		else
			sum += a.at(i) * 380000.0;
	}
	printf("%10.5Lf", sum);
}

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

X = [[0 for i in range(D)]for j in range(N)]

for i in range(N):
	X[i] = list(map(int, input().split()))

cnt = 0
for i in range(N):
	for j in range(i+1, N):
		lo = 0
		for k in range(D):
			lo += (X[j][k] - X[i][k])**2
		k = 0
		while k <= lo:
			if k*k == lo:
				cnt += 1
			k += 1

print(cnt)


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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = INT_MAX / 2;

int n, q;
int m;
VI ds;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	while (1) {
		cin >> n >> q;
		if (n == 0 && q == 0) break;
		VI ps(101);
		rep (i, n) {
			cin >> m;
			rep (j, m) {
				int a;
				cin >> a;
				ps[a]++;
			}
		}
		int ans_v = -1, ans_i = 0;
		rep (i, ps.size()) {
			if (ps[i] > ans_v && ps[i] >= q) {
				ans_i = i;
				ans_v = ps[i];
			}
		}
		cout << ans_i << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3068
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

struct Node {
	int key;
	Node *prev, *next;
};

Node *nil;

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* listsearch(int key) {
	Node *cur = nil->next;
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t) {
	if (t == nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deletekey(int key) {
	deleteNode(listsearch(key));
}

void printList() {
	Node *cur = nil->next;
	int isf = 0;
	while (1) {
		if (cur == nil)break;
		if (isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') { insert(key); np++; size++; }
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L')deleteLast();
			}
			else {
				deletekey(key); nd++;
			}
			size--;
		}
	}

	printList();

	return 0;
}


Measured memory_bytes: 33820
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;

struct Edge {
    int to;
    int weight;

    Edge(int to, int weight) : to(to), weight(weight) {}
};

using Graph = vector<vector<Edge>>;
vector<int> colors;
vector<bool> seen;

Graph graph;

void dfs(int v, int c) {
    seen[v] = true;
    colors[v] = c;
    for (auto e : graph[v]) {
        if (seen[e.to]) continue;
        if (e.weight % 2 != 0) dfs(e.to, 1 - c);
        else dfs(e.to, c);
    }
}

int main() {

    int N;
    cin >> N;

    graph.assign(N, vector<Edge>());
    seen.assign(N,false);
    colors.assign(N, 0);

    for (int i = 0; i < N - 1; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        u -= 1;
        v -= 1;
        graph[u].push_back(Edge(v, w));
        graph[v].push_back(Edge(u, w));
    }

    dfs(0, 1);

    for (int i = 0; i < N; ++i) {
        cout << colors[i] << endl;
    }

}

Measured memory_bytes: 11180
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int ans = 0;
        rep(i, 1, 1001){
            rep(j, 2, 100){
                int sum = i * j + j * (j - 1) / 2;
                if(sum == n) ans++;
            }
        }
        cout << ans << endl;
    }
}

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

int main() {
	int n, cnt = 0, max = 0, ans = 1;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int t = i;
		cnt = 0;
		while (t % 2 == 0) {
			t /= 2;
			cnt++;
		}
		if (max < cnt) {
			max = cnt;
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

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


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

  int n;
  cin >> n;
  vector<ll> a(n+1);
  vector<ll> sum(n+1,0);
  rep(i,n+1) cin >> a[i];
  sum[n] = a[n];
  for(int i = n-1; i>=0; i--){
    sum[i] = a[i] + sum[i+1];
  }
  ll pre = 0;
  ll ans = 0;
  ll rest = 0;
  rep(i,n+1){
    ll v = min(rest *2, (ll) 5e13);
    if(i==0) v = 1;
    // ll tmp = rest*2;
    // if(i==0) tmp = 0;
    // ll mu = 2;
    // ll v = 1;
    // while(tmp>0){
    //   if(mu>5e13 || v > 5e13){
    //     v = 5e13+1;
    //     break;
    //   }
    //   if(tmp&1){
    //     v *= mu;
    //   }
    //   tmp >>= 1;
    //   mu*=mu;
    // }
    if(a[i] > v){
      cout << -1 << endl;
      return 0;
    }
    rest = v - a[i];
    ans += min(v,sum[i]);
    // cout << ans << endl;
  }
  // }
  // for(int i = n; i>=0; i--){
  //   int tmp = i;  
  //   ll mu = 2;
  //   ll v = 1;
  //   while(tmp>0){
  //     if(mu>5e13 || v > 5e13){
  //       v = 5e13+1;
  //       break;
  //     }
  //     if(tmp&1){
  //       v *= mu;
  //     }
  //     tmp >>= 1;
  //     mu*=mu;
  //   }
  //   ll cmin = pre/2 + a[i];
  //   ll cmax = pre + a[i];
  //   if(cmin > v){
  //     cout << -1 << endl;
  //     return 0;
  //   }
  //   ans += min(cmax,v);
  //   pre = min(cmax,v);
  //   cout << pre << " " << v << endl;
  // }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 4784
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cassert>
using namespace std;
using VI = vector<int>;
using P = pair<int, int>;
VI adj[101010];

int main() {
    int n;
    cin >> n;
    VI num(n, -1);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int k;
    cin >> k;
    priority_queue<P, vector<P>, greater<>> q;
    for (int i = 0; i < k; i++) {
        int v, p;
        cin >> v >> p;
        v--;
        q.push(P(p, v));
        num[v] = p;
    }
    while (!q.empty()) {
        P t = q.top();
        q.pop();
        for (int v: adj[t.second]) {
            if (num[v] != -1) {
                if (abs(num[v] - t.first) != 1) {
                    cout << "No" << endl;
                    return 0;
                }
            } else {
                num[v] = t.first + 1;
                q.push(P(t.first + 1, v));
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 0; i < n; i++) {
        cout << num[i] << endl;
    }
}


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

using namespace std;

int main(void){
	string s;
	cin >> s;
	int sum = 700;
	for(int i=0;i<3;i++){
		if(s[i]=='o'){
			sum += 100;
		}
	}
	cout << sum << endl;

	return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];
  int mx = *max_element(A.begin(), A.end());
  int mn = *min_element(A.begin(), A.end());
  cout << mx - mn << endl;
  return 0;
}


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

int main() {
  int a, b, c, d, e;
  cin >> a;
  b=a%100;
  c=a%10;
  d=(b-c)/10;
  e=(a-b)/100;
  cout << c + d + e << endl;
  
}

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


#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define len(s) s.length()
#define forp(i,a,b) for( i=a;i<=b;i++)
#define rep(i,n)    for( i=0;i<n;i++)
#define ren(i,n)    for( i=n-1;i>=0;i--)
#define forn(i,a,b) for( i=a;i>=b;i--)
#define on cout<<endl
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ret return 0
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100001
#define SIZ 1000001
#define SIZE 200001

typedef long long  ll;
typedef long double  ldo;
typedef double  db ;
using namespace std;
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define w(x)            int x; cin>>x; while(x--)

void c_p_c()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 //  c_p_c();
   int n,a,b,c;
   cin>>n;
   int dp[100001][3][3];
   cin>>a>>b>>c;
   dp[0][0][1]=b;
   dp[0][0][2]=c;
   dp[0][1][0]=a;
   dp[0][1][2]=c;
   dp[0][2][0]=a;
   dp[0][2][1]=b;
   for(int i=1;i<=n;i++){
        cin>>a>>b>>c;
        dp[i][0][1]=b+max(dp[i-1][1][0],dp[i-1][2][0]);
        dp[i][0][2]=c+max(dp[i-1][1][0],dp[i-1][2][0]);
        dp[i][1][0]=a+max(dp[i-1][0][1],dp[i-1][2][1]);
        dp[i][1][2]=c+max(dp[i-1][0][1],dp[i-1][2][1]);
        dp[i][2][0]=a+max(dp[i-1][1][2],dp[i-1][0][2]);
        dp[i][2][1]=b+max(dp[i-1][1][2],dp[i-1][0][2]);
   }   
   cout<<max({dp[n-1][0][1],dp[n-1][0][2],dp[n-1][1][0],dp[n-1][1][2],dp[n-1][2][1],dp[n-1][2][0]});
   return 0;
}

Measured memory_bytes: 7184
#include<bits/stdc++.h>
using namespace std;
int main(){
  	string s;
  	cin>>s;
  	long long sum=0;
  	for(int i=0;i<s.length();i++){
    	sum += (s[i]-'0');
    }
  	if(sum%9 == 0)
      cout<<"Yes";
  	else 
      cout<<"No";
  	return 0;
}

Measured memory_bytes: 3652
import sys
readline = sys.stdin.readline

N = int(readline())
S = readline().rstrip()

# 0,1がSS,SW,WS,WWの4パターンで始めてN-1まで埋める。
# このとき、0が言っていることに矛盾がなければOK

# 1:S
# 0:W
ANI = "WS"
for n in range(4):
  pat = [None] * N
  pat[0] = n & 1
  pat[1] = (n >> 1) & 1
  for i in range(1, N - 1):
    if pat[i]:
      # 羊の場合
      if S[i] == "o":
        pat[i + 1] = pat[i - 1]
      else:
        pat[i + 1] = pat[i - 1] ^ 1
    else:
      # 狼の場合
      if S[i] == "o":
        pat[i + 1] = pat[i - 1] ^ 1
      else:
        pat[i + 1] = pat[i - 1]
  # 0の動物とN-1の動物が正しいことを言っているか判定する
  # 0の動物
  ok = True
  if (pat[0] == 1 and S[0] == "o") or (pat[0] == 0 and S[0] == "x"):
    if pat[N - 1] != pat[1]:
      ok = False
  elif (pat[0] == 1 and S[0] == "x") or (pat[0] == 0 and S[0] == "o"):
    if pat[N - 1] == pat[1]:
      ok = False
  if (pat[N - 1] == 1 and S[N - 1] == "o") or (pat[N - 1] == 0 and S[N - 1] == "x"):
    if pat[N - 2] != pat[0]:
      ok = False
  elif (pat[N - 1] == 1 and S[N - 1] == "x") or (pat[N - 1] == 0 and S[N - 1] == "o"):
    if pat[N - 2] == pat[0]:
      ok = False
  if ok:
    ans = ""
    for p in pat:
      ans += ANI[p]
    print(ans)
    break
else:
  print(-1)

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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 100010;

signed main() {
    IOS;

    int D, T, S;
    cin >> D >> T >> S;

    Yes(D <= T * S) ;

    return 0;
}


Measured memory_bytes: 3636
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
ll x,y;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>x>>y;
  ll t = 0;
  if(abs(x)>abs(y)){
    if(x>0)t++;
    t+=abs(x)-abs(y);
    if(y>0)t++;
  }else{
    if(x<0)t++;
    t+=abs(y)-abs(x);
    if(y<0)t++;
  }
  cout<<t<<endl;
}

int main(){
  solve();
  return 0;
}


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

int main(){
    string s; cin >> s;
    map<char,int> mp;

    for(auto c : s){
        mp[c]++;
    }

    for(auto a : mp){
        if(a.second mod 2 == 1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
sum=[0]*(len(a)+1)
for i in range(len(a)):
    sum[i+1]=sum[i]+a[i]
# print(sum)

mini=2020202020
for i in range(len(sum)):
    mini=min(mini, abs(sum[i] - (sum[-1] - sum[i])))

print(mini)

Measured memory_bytes: 89164
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,m,a[SZ],p[SZ],t[SZ],tmp[SZ],rt[SZ]; ll k;
void mul(int*a,int*b)
{
	for(int i=1;i<=n;++i)
		tmp[i]=b[a[i]];
	for(int i=1;i<=n;++i)
		a[i]=tmp[i];
}
ll x[SZ];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%lld",x+i),p[i]=t[i]=i;
	scanf("%d%lld",&m,&k);
	for(int i=1;i<=m;++i)
		scanf("%d",a+i),swap(p[a[i]-1],p[a[i]]);
	while(k)
	{
		if(k&1) mul(t,p);
		mul(p,p); k>>=1;
	}
	ll s=x[1]; printf("%lld\n",s);
	for(int i=2;i<=n;++i)
	{
		int g=t[i-1];
		s+=x[g+1]-x[g];
		printf("%lld\n",s);
	}
}



Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

int main(void){
    std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
    int n; std::cin >> n; std::vector<int> A(n); for(int i = 0; i < n; ++i) std::cin >> A[i];
    std::multiset<int, std::greater<int>> S(A.begin(), A.end());
    int res = 0;
    while(not S.empty()){
        const int val1 = *S.begin(); S.erase(S.begin());
        const int val2 = (1 << (32 - __builtin_clz(val1))) - val1;
        const auto itr = S.find(val2);
        if(itr != S.end()){ S.erase(itr); ++res; }
    }
    std::cout << res << '\n';
    return 0;
}

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

int main(){
  string s="MARCH";
  long long c[5]={0};
  long long n;
  cin >> n;
  for (long long i=0;i<n;++i){
    string t;
    cin >> t;
    for (int j=0;j<5;++j){
      if (t[0]==s[j]){
        c[j]++;
      }
    }
  }
  long long ans=0;
  for (int i=0;i<5;++i){
    for (int j=i+1;j<5;++j){
      for (int k=j+1;k<5;++k){
        ans+=c[i]*c[j]*c[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int n;cin>>n;
  int t,a;cin>>t>>a;
  int h[n];
  for(int i = 0; n > i; i++){
    cin >> h[i];
  }
  for(int i = 0; n > i; i++){
    h[i] = (t*1000)-(h[i]*6);
  }
  for(int i = 0; n > i; i++){
    h[i] = abs(a*1000-h[i]);
  }
  int ret;
  int mn = 1145141919;
  for(int i = 0; n > i; i++){
    if(mn > h[i]){
      mn = h[i];
      ret = i+1;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;

    queue<int> q[n+1];
    int a,s;
    int i;
    for(i=1;i<=m;i++){
        cin>>a>>s;

        if(a==0){
            cout<<q[s].front()<<"\n";
            q[s].pop();
        }

        if(a==1){
            int min=1;
            int j;
            for(j=2;j<=n;j++){//累積min
                if(q[min].size()>q[j].size()){
                    min=j;
                }
            }

            q[min].push(s);
        }
    }
    return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <cmath>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

int main()
{
    long long X, K, D;
    cin >> X >> K >> D;

    X=abs(X);

    if (X / D >= K)
        cout << X - K * D << endl;
    else
    {
        if ((K - X / D) % 2 == 0)
            cout << X % D<< endl;
        else
        {
            cout << -(X % D - D) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;

int main() {
	int n;
	while(cin >> n && n){
		unsigned int p[65000], jo[65000];
		for(int i = 0; i < n; ++i)
			cin >> p[i];
		for(int i = 0; i < n - 1; ++i)
			cin >> jo[i];

		sort(jo, jo + n - 1, greater<int>());
		unsigned jsum = 0, sum = accumulate(p, p + n, 0), ans = 0;
		ans = sum * n;
		for(int i = 1; i < n; i++){
			jsum += jo[i - 1];
			ans = max(ans, (sum + jsum) * (n - i));
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1684
use proconio::{fastout, input};

const M: usize = 1000005;

#[fastout]
fn main() {
    input! {
        n: usize,
        a_vec: [i64; n],
    }

    let mut cnt: Vec<usize> = vec![0; M];
    for a in a_vec.iter() {
        if cnt[*a as usize] != 0 {
            cnt[*a as usize] = 2;
            continue;
        }
        for i in ((*a as usize)..M).step_by(*a as usize) {
            cnt[i] += 1;
        }
    }
    let mut ans = 0;
    for a in a_vec {
        if cnt[a as usize] == 1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 12760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1001001001;
typedef unsigned long long ll;

struct Puzzle{
  int f[9];
  int space;
  int cnt;

  bool operator < (const Puzzle &p) const {
    rep(i, 9){
      if(f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

queue<Puzzle> Q;
map<Puzzle, bool> V;

static const int dx[4] = {1, 0, -1, 0};
static const int dy[4] = {0, 1, 0, -1};

bool isTarget(Puzzle p){
  rep(i, 9) if(p.f[i] != (i+1)) return false;
  return true;
}

int main(){
  Puzzle in;

  rep(i, 9){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = 9;
      in.space = i;
    }
  }
  in.cnt = 0;

  V[in] = true;
  Q.push(in);
  int ans;
  while(!Q.empty()){
    Puzzle u = Q.front(); Q.pop();
    if(isTarget(u)){
      ans = u.cnt;
      break;
    } 
    int sx = u.space / 3;
    int sy = u.space % 3;
    rep(i, 4){
      int tx = sx + dx[i];
      int ty = sy + dy[i];
      if(tx<0 || ty<0 || 3<=tx || 3<=ty) continue;
      Puzzle v = u;
      v.space = tx * 3 + ty;
      swap(v.f[u.space], v.f[v.space]);
      v.cnt++;
      if(!V[v]){
        V[v] = true;
        Q.push(v);
      }
    }
  }

  cout << ans << endl;

  return 0;
}





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

using namespace std;

const int dx[5] = {-1,0,0,0,1};
const int dy[5] = {0,-1,0,1,0};

int arr[10][10];
int ans[10][10],flip[10][10];

int get(int x,int y){
  int c = arr[x][y];
  for(int d = 0 ; d < 5 ; d++){
    int x2 = x + dx[d], y2 = y + dy[d];
    if(0 <= x2 && x2 < 10 && 0 <= y2 && y2 < 10){
      c += flip[x2][y2];
    }
  }
  return c % 2;
}

int calc(){
  for(int i = 1 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      if(get(i-1,j) != 0){
        flip[i][j] = 1;
      }
    }
  }

  for(int j = 0 ; j < 10 ; j++){
    if(get(9,j) != 0){
      return -1;
    }
  }

  int res = 0;
  for(int i = 0 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      res += flip[i][j];
    }
  }
  return res;
}

void solve(){
  int res = -1;

  for(int i = 0 ; i < (1<<10) ; i++){
    memset(flip,0,sizeof(flip));
    for(int j = 0 ; j < 10 ; j++){
      flip[0][10-j-1] = i >> j & 1;
    }
    int num = calc();
    if(num >= 0 && (res < 0 || res > num)){
      res = num;
      memcpy(ans,flip,sizeof(ans));   
    }
  }

  for(int i = 0 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      printf("%d%c" ,ans[i][j], j+1 == 10 ? '\n' : ' ');
    }
  }
}

int main(){
  int Tc;

  cin >> Tc;
  while(Tc--){
    for(int i = 0 ; i < 10 ; i++){
      for(int j = 0 ; j < 10 ; j++){
        cin >> arr[i][j];
      }
    }
    solve();
  }

  return 0;
}

Measured memory_bytes: 1140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
	
	public static final int INF = Integer.MAX_VALUE / 2 - 1;
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		int[][] adj = new int[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				adj[i][j] = -1;
			}
		}
		
		for(int i = 0; i < n; i++){
			final int u = sc.nextInt();
			
			final int k = sc.nextInt();
			
			for(int j = 0; j < k; j++){
				final int v = sc.nextInt();
				final int c = sc.nextInt();
				
				adj[u][v] = c;
			}
		}
		
		boolean[] visited = new boolean[n];
		int[] costs = new int[n];
		Arrays.fill(costs, INF);

		costs[0] = 0;
		for(int tt = 0; tt < n; tt++){
			int min = INF;
			int min_pos = -1;
			
			for(int i = 0; i < n; i++){
				if(!visited[i] && costs[i] < min){
					min = costs[i];
					min_pos = i;
				}
			}
			
			visited[min_pos] = true;
			
			for(int next = 0; next < n; next++){
				if(adj[min_pos][next] < 0){ continue; }
				
				costs[next] = Math.min(costs[next], costs[min_pos] + adj[min_pos][next]);
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println(i + " " + costs[i]);
		}
		
	}

	public static class Scanner {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public void close() throws IOException {
			br.close();
		}
	}

}

Measured memory_bytes: 22044
n,p,q = map(int,input().split())
cn=[]
for i in range(n):
    cn.append(int(input()))
difs=[p*(q-i)-cn[i] for i in range(n)]
difs=sorted(difs, reverse=True)
ans=[sum(cn)]
for i in range(n):
    ans.append(ans[-1]+2*i*p+difs[i])
print(max(ans))


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int A[300010];
int D[300010];
pii F[300010];

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

	cin >> N;
	rep(i, 0, N)
	{
		cin >> A[i];
	}

	sort(A, A + N);

	int DN = 0;
	int c = 0;
	int pa = A[0];
	rep(i, 0, N)
	{
		if (A[i] != pa)
		{
			D[DN] = c;
			c = 0;
			DN++;
		}
		c++;
		pa = A[i];
		if (i == N - 1)
		{
			D[DN] = c;
			c = 0;
			DN++;
		}
	}

	sort(D, D + DN);

	int r = 0;
	int t = 0;
	rep(i, 1, N + 1)
	{
		while (r < DN&&D[r] < i)r++;
		t += DN - r;
		F[i - 1] = mp(t / i, i);
	}

	sort(F, F + N, [&](const pii& a, const pii& b) {return a.first != b.first ? a.first<b.first : a.second>b.second; });

	rep(i, 1, N + 1)
	{
		auto itr = lower_bound(F, F + N, mp(i, 0LL));
		if (itr == F + N)
		{
			cout << 0 << endl;
		}
		else
		{
			cout << itr->second << endl;;
		}
	}

	return 0;
}

Measured memory_bytes: 10240
#include<stdio.h>
#include<stdlib.h>
#define MAX 25
#define NIL -1
#define N 2
typedef struct {
    int parent,left,right;
}node;
node t[MAX];
int n;
void preparse(int u){
  if(u==NIL)return;
  printf(" %d",u);
  preparse(t[u].left);
  preparse(t[u].right);
}
void inparse(int u){
  if(u==NIL)return;
  inparse(t[u].left);
  printf(" %d",u);
  inparse(t[u].right);
}
void postparse(int u){
  if(u==NIL)return;
  postparse(t[u].left);
  postparse(t[u].right);
  printf(" %d",u);
}

int main(){                                                                                  
  int i,id,k,*c,j,df;                                                                   
  scanf("%d",&n);                                                                      
  for(i=0;i<n;i++) t[i].parent=t[i].left=t[i].right=NIL;                                     
  for(i=0;i<n;i++){                                                                          
    scanf("%d",&id);                                                                    
    c=(int*)malloc(sizeof(int)*N);                                                           
    for(j=0;j<N;j++)scanf("%d",&c[j]);                                                                                                                       
    for(j=0;j<N;j++)t[c[j]].parent=id;
    t[id].right=c[1];
    t[id].left=c[0];                         
  } 
  for(i=0;i<n;i++)if(t[i].parent==NIL)df=i;
  printf("Preorder\n");
  preparse(df);
  printf("\nInorder\n");
  inparse(df);
  printf("\nPostorder\n");
  postparse(df);
  printf("\n");
  return 0;                                                                                  
}     


Measured memory_bytes: 2108
package main

import (
	"fmt"
)

func main() {
	var n,d int
	fmt.Scan(&n,&d)

	r := 2 * d + 1

	if n % r == 0 {
		fmt.Println(n / r)
	} else {
		fmt.Println(n / r + 1)
	}
}

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

int main() {
  int N;
  cin >> N;
  long double otoshidama;
  string passing;

  long double money = 0;
  for (int i = 0; i < N; ++i) {
    cin >> otoshidama >> passing;
    money += passing == "JPY" ? otoshidama : otoshidama * 380000.0;
  }

  cout << setprecision(20) << money << endl;
  return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
N=int(input())
D=[]
for i in range(N):
  s,p=input().split()
  D.append((s, int(p), i+1))
D.sort(key=lambda d: (d[0], -d[1], d[2]))

for d in D:
  print(d[2])




Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mt make_tuple
#define pb push_back
const int N = 1e5 + 10;
struct node{
    int a,b,c;
};
int main(){
    int n;
    node arr[N];
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i].a>>arr[i].b>>arr[i].c;
    }
    for(int i=2;i<=n;i++){
        arr[i].a = max(arr[i-1].b,arr[i-1].c)+arr[i].a;
        arr[i].b = max(arr[i-1].a,arr[i-1].c)+arr[i].b;
        arr[i].c = max(arr[i-1].b,arr[i-1].a)+arr[i].c;
    }
    cout<<max(arr[n].c,max(arr[n].a,arr[n].b))<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<n;++i)

typedef long long ll;
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n*a, b)<< "\n";
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {
	public static void main(String[] args) throws IOException {
		PrintStream printStream = System.out;
		InputStream inputStream = System.in;

		InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

		String input = bufferedReader.readLine();
		long x = Long.parseLong(input);

		printStream.println(x * x * x);
	}
}

Measured memory_bytes: 17024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scanner = new Scanner(System.in);
		String input = scanner.nextLine();

		int num = Integer.parseInt(input);

		String[] arr = scanner.nextLine().split(" ");

		//int[] intarr = new int[num];

		for(int i=arr.length-1;i>=0;i--){

			System.out.print(arr[i]);
			if(i!=0){System.out.print(" ");}else{System.out.println();}
		}
	}
}

Measured memory_bytes: 26072
<?php
fscanf(STDIN, rtrim("%s"), $str);

switch ($str)
{
	case "SUN":
		echo ("7");
	break;

		case "MON":
		echo ("6");
	break;

	case "TUE":
		echo ("5");
	break;

		case "WED":
		echo ("4");
	break;

		case "THU":
		echo ("3");
	break;

		case "FRI":
		echo ("2");
	break;

		case "SAT":
		echo ("1");
	break;
}

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

int main (void) {

  int r, g, b;
  cin >> r >> g >> b;

  int num;
  num = r * 100 + g * 10 + b;
  if(num%4==0){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve(t):
    N, T, K = map(int, readline().split())
    if N == T == K == 0:
        return False
    G = [[] for i in range(N)]
    E = []
    res = 0
    for i in range(N-1):
        a, b, c = map(int, readline().split())
        res += c
        E.append((c, a-1, b-1))
    E.sort(reverse=1)
    sz = [0]*N
    for i in range(T):
        v = int(readline())-1
        sz[v] = 1
    *prt, = range(N)
    def root(x):
        if x == prt[x]:
            return x
        prt[x] = y = root(prt[x])
        return y
    def unite(x, y):
        px = root(x); py = root(y)
        if px < py:
            prt[py] = px
            sz[px] += sz[py]
        else:
            prt[px] = py
            sz[py] += sz[px]
    d = T - K - 1
    for c, a, b in E:
        pa = root(a); pb = root(b)
        if sz[pa] == 0 or sz[pb] == 0:
            unite(a, b)
            res -= c
            continue
        if d > 0:
            d -= 1
            unite(a, b)
            res -= c
    write("Case %d: %d\n" % (t, res))
    return True
i = 1
while solve(i):
    i += 1


Measured memory_bytes: 9180
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 15;

string s[N];

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

	int h, w, k;
	cin >> h >> w >> k;

	for(int i = 0; i < h; i++) cin >> s[i];
	
	int ans = 1e9;

	for(int i = 0; i < (1 << (h - 1)); i++) {
		vector<int> bts;
		for(int j = 0; j < (h - 1); j++) {
			if(i>>j&1) bts.push_back(j + 1);
		}
		if(bts.size()) assert(bts.back() < h);
		bts.push_back(h);
		int a = 0;
		// last total sum of each component
		vector<int> sums(bts.size(), 0);
		bool ok = true;
		for(int col = 0; col < w; col++) {
			// sum of each component
			vector<int> go(bts.size(), 0);
			int last = 0;
			int pos = 0;
			for(int x : bts) {
				int sum = 0;
				for(int row = last; row < x; row++) {
					if(s[row][col] == '1') sum++;
				}
				go[pos] = sum;
				last = x;
				pos++;
			}
			
			for(int j = 0; j < go.size(); j++) {
				if(go[j] > k) {
					ok = false;
					break;
				}
			}

			if(!ok) break;

			bool div = false;
			for(int j = 0; j < go.size(); j++) {
				if(sums[j] + go[j] > k) {
					div = true;
					break;
				}
			}
			if(div) {
				a++;
				for(int j = 0; j < go.size(); j++) {
					sums[j] = go[j];
				}
			}
			else {
				for(int j = 0; j < go.size(); j++) {
					sums[j] += go[j];
				}
			}
		}

		if(ok) ans = min(ans, a + (int)bts.size() - 1);
	}

	cout << ans;

	
	return 0;
}


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

const int MAX = 5100;
const int MOD = 1000000007; // 今回使う余り

int main() {
	int N;
	string s;
	cin >> N >> s;
	static int l = s.size(), dp[MAX][MAX]; // dp[i][j] = i文字入力した時点でj文字が表示される通り数
	for (int i = 0;i < N;i ++) dp[0][i] = 0;
	dp[0][0] = 1;
	for (int i = 1;i <= N;i ++) {
		dp[i][0] = (dp[i - 1][1] + dp[i - 1][0]) % MOD;
		for (int j = 1;j <= N;j ++) {
			dp[i][j] = (2 * dp[i - 1][j - 1] % MOD + dp[i - 1][j + 1]) % MOD;
		}
	}
	// ここでdp[N][l]は求めたい文字列……だけじゃなく余計なパターンが入っているので、正しいパターンは2^lで割った値
	int64_t rev = (MOD + 1) >> 1; // この値に対し2倍するとMOD + 1、だからこれは逆元
	
	int ans = dp[N][l];
	for (int i = 0;i < l;i ++) ans = (ans * rev) % MOD;
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、求めたい文字列の長さになる組み合わせは動的計画法を用いて解くことができるね
この時、出てきた文字列って0000…から1111…の全ての組み合わせの総和じゃん？
各確率は独立かつ等しいので、2^lで割れば答え出るじゃん
*/

Measured memory_bytes: 100608
<?php

fscanf(STDIN, "%s", $s);

$array = str_split($s);
$len = strlen($s);
$buff=[-1,0,0];
$ans = array_fill(0,strlen($s), 0);
foreach ($array as $i => $value){
    if($buff[0] >= $i){
        if($i % 2 == $buff[1]){
            $ans[$buff[2]]++;
        }else{
            $ans[$buff[2]- 1]++;
        }
    }elseif($value == "R"){
        $k = 1;
        while($array[$k + $i] == "R"){
            $k++;
        }

        if($k % 2 == 0){
            $ans[$i+$k]++;
            $buff = [$i+$k, ($i % 2),$i+$k];
        }else{
            $ans[$i + $k -1]++;
            $buff = [$i+$k, ($i + 1) % 2, $i+$k];
        }
    }else{
        $k = 1;
        while($array[$i - $k] == "L"){
            $k++;
        }
        $l = 0;
        while($len > $i + $l && $array[$i + $l] == "L" ){
            $l++;
        }
        $l--;
        if($k % 2 == 0){
            $ans[$i - $k]++;
            $buff = [$i + $l, ($i+1) %2, $i - $k + 1];
        }else{
            $ans[$i - $k + 1]++;
            $buff = [$i + $l, ($i % 2), $i - $k + 1];
        }

    }
}

echo implode(" ", $ans);


Measured memory_bytes: 16888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    if (n%2==1) n*=2;
  cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int N=2e5+100,M=63;
ll x[N];
ll y[N];
ll z[N];
pii a[N];
pii ans1[N];
pii ans2[N];
int32_t main(){
    sync;
    ll x111,y111,z111;
    cin >> x111 >> y111 >> z111;
    ll n=x111+y111+z111;
    ll g=0;
    for (int i=0;i<n;i++){
        cin >> x[i] >> y[i] >> z[i];
        g+=z[i];
        a[i]={-x[i]+y[i],i};
    }
    sort(a,a+n);
    ll cnt=0;
    set <pii> s;
    ll w=0;

    for (int i=0;i<x111;i++){
        ll id=a[i].S;
        s.insert({{x[id]-z[id]},id});
        w+=x[id];
        cnt+=z[id];
        ans1[i]={-1e9,1e9};
        if (i==x111-1){
            ans1[i]={w,cnt};
         //   cout << i << " " << w << " " << cnt << endl;
        }
    }
    for (int i=x111;i<n;i++){
        ll id=a[i].S;
        ll p=s.begin()->F;
        if (p<x[id]-z[id]){
            p=s.begin()->S;
            w-=x[p];
            cnt-=z[p];
            s.erase(s.begin());
            s.insert({{x[id]-z[id]},id});
            w+=x[id];
            cnt+=z[id];
        }
        ans1[i]={w,cnt};
       // cout << i << " " << w << " " << cnt << endl;
    }
    s.clear();
    reverse(a,a+n);
    w=0;
    cnt=0;

    for (int i=0;i<y111;i++){
        ll id=a[i].S;
        s.insert({{y[id]-z[id]},id});
        w+=y[id];
        cnt+=z[id];
        ans2[i]={-1e9,1e9};
        if (i==y111-1){
            ans2[i]={w,cnt};
          //  cout << i << " " << w << " " << cnt << endl;
        }
    }
    for (int i=y111;i<n;i++){
        ll id=a[i].S;
        ll p=s.begin()->F;
        ll o=p;
        if (p<y[id]-z[id]){
            p=s.begin()->S;
            w-=y[p];
            cnt-=z[p];
            s.erase(s.begin());
            s.insert({{y[id]-z[id]},id});
            w+=y[id];
            cnt+=z[id];
        }
        ans2[i]={w,cnt};
      //  cout << i << " " << w << " " << cnt << " " << o << endl;
    }
    reverse(ans2,ans2+n);
    ll ma=0;
    for (int i=x111-1;i<n-y111;i++){
        ma=max(ma,ans1[i].F+ans2[i+1].F+g-ans1[i].S-ans2[i+1].S);
       // cout << i << " " << ans1[i].F << " " << ans2[i].F << " " << g << " " << ans1[i].F+ans2[i+1].F+g-ans1[i].S+ans2[i+1].S  << endl;
    }
    cout << ma << endl;

}


Measured memory_bytes: 18688
#include <bits/stdc++.h>
template <long long mod>
class Combination
{
    std::vector<long long> fact, finv, inv;
public:
    Combination() {}
    Combination(int sz)
    {
        fact.resize(sz);
        finv.resize(sz);
        inv.resize(sz);
        fact[0] = 1;
        for (int i = 1; i < sz; ++i)
        {
            fact[i] = fact[i - 1] * i % mod;
        }
        inv[0] = 0;
        inv[1] = 1;
        for (int i = 2; i < sz; ++i)
        {
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        }
        finv[0] = 1;
        for (int i = 1; i < sz; ++i)
        {
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    long long C(long long n, long long k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return (fact[n] * finv[k] % mod) * finv[n - k] % mod;
    }
    long long P(long long n, long long k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fact[n] * finv[n - k] % mod;
    }
    long long H(long long n, long long k)
    {
        return this->C(n + k - 1, k);
    }
    long long getfact(int i)
    {
        return fact[i];
    }
    long long getinv(int i)
    {
        return inv[i];
    }
    long long getfinv(int i)
    {
        return finv[i];
    }
};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int k; cin >> k;
  string s; cin >> s;
  int n = (int)(s.size());
  Combination<MOD> comb(3000000);
  vi v;
  for(int i=0;i<(n);++i) {
    v.push_back(comb.C(n+k, i));
  }
  reverse((v).begin(),(v).end());
  ll now = 1;
  ll ans = 0;
  for(int i=0;i<(n+k+1-(int)(v.size()));++i) {
    now *= 25;
    now %= MOD;
  }
  for(int i=0;i<((int)(v.size()));++i) {
    ans += now * v[i] % MOD;
    ans %= MOD;
    now *= 25;
    now %= MOD;
  }
  ll all = 1;
  for(int i=0;i<(n+k);++i) {
    all *= 26;
    all %= MOD;
  }
  cout << (all + MOD - ans) % MOD << endl;
}


Measured memory_bytes: 79112