akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

string replace_with_str(string str, string str_from, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(int argc, char const *argv[]){
    int X;
    cin >> X;
    if(X == 7 || X == 5 || X == 3){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    import sys

    sys.setrecursionlimit(10 ** 8)
    
    def calc(A: list):
        score = 0
        for a, b, c, d in lst:
            if A[b - 1] - A[a - 1] == c:
                score += d
        return score

    def dfs(A: list):
        nonlocal ans
        if len(A) == N:
            ans = max(ans, calc(A))
        elif len(A) == 0:
            for nx in range(1, M + 1):
                dfs(A + [nx])
        else:
            for nx in range(A[-1], M + 1):
                dfs(A + [nx])

    input = sys.stdin.readline

    N, M, Q = map(int, input().split())
    lst = [list(map(int, input().split())) for _ in range(Q)]
    ans = 0
    dfs([])
    print(ans)


main()


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

using namespace std;
using ll = long long;

int main()
{
    ll N, M;
    cin >> N >> M;

    vector<ll> A(N);
    for(ll i=0; i<N; ++i) cin >> A[i];
    sort(A.begin(), A.end());

    priority_queue<ll> MX;
    ll X, Y;
    X = A.back();
    A.pop_back();
    X /= 2;
    MX.push(X);
    for(ll i=1; i<M; ++i){
        if(A.empty()) X = 0; else X = A.back();
        if(MX.empty()) Y = 0; else Y = MX.top();
        if(X > Y){
            X = A.back();
            A.pop_back();
        }else{
            X = MX.top();
            MX.pop();
        }
        X /= 2;
        MX.push(X);
    }

    ll S = 0;
    for(ll i=0; i<A.size(); ++i){
        S += A[i];
    }
    ll len = MX.size();
    for(ll i=0; i<len; ++i){
        S += MX.top();
        MX.pop();
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
#define max1 10000005
#define siz 100000
#define mod 998244353
#define inf 1e18+5
#define ll long long int
#define debug(x) cout<<#x<<" "<<x<<endl
#define jam(x) cout<<"Case #"<<x<<": "
typedef pair<ll,ll> pr;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/
  ll n,w;
  cin>>n>>w;
  vector<ll> a(n+1),wt(n+1);
  for(ll i=1;i<=n;i++)
  {
    cin>>wt[i]>>a[i];
  }
  vector<vector<ll> > dp(2,vector<ll>(w+1,0) );
  for(ll i=1;i<=n;i++)
  {
    ll x=i%2;
    for(ll j=1;j<=w;j++)
    {
      if(j<wt[i])
      {
        dp[x][j]=dp[x^1][j];
        continue;
      }
      dp[x][j]=max({dp[x][j-1],dp[(x^1)][j-wt[i]]+a[i],dp[x^1][j]});
    }
  }
  cout<<dp[n%2][w]<<endl;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main()
{
    int n,a[101],i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
        {
            if(a[i]%3!=0&&a[i]%5!=0)
            {
                printf("DENIED");
                return 0;
            }
        }
    }
    printf("APPROVED");
    return 0;
}


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

using int64 = long long;
using Matrix = vector<vector<int64>>;

bool IsPossible(const int64 n, const int64 m, const Matrix& as, const int64 k) {
  vector<bool> not_used(m + 1, false), used(m + 1, false);
  vector<int64> sports(n, 0);
  for (int64 s = 0; s < m; ++s) {
    vector<int64> numbers(m + 1, 0);
    for (int64 i = 0; i < n; ++i) {
      if (sports[i] > 0)
        continue;
      for (int64 j = 0; j < m; ++j) {
        int64 sp = as[i][j];
        if (used[sp]) {
          sports[i] = sp;
          break;
        }
        if (not_used[sp])
          continue;
        ++numbers[sp];
        break;
      }
    }

    auto it = max_element(numbers.begin(), numbers.end());
    int64 id = it - numbers.begin();
    if (*it <= k) {
      used[id] = true;
    } else {
      not_used[id] = true;
      if (s == m - 1)
        return false;
    }
  }

  return true;
}

int main() {
  int64 n, m;
  cin >> n >> m;
  Matrix as(n, vector<int64>(m));
  for (int64 i = 0; i < n; ++i) {
    for (int64 j = 0; j < m; ++j) {
      cin >> as[i][j];
    }
  }

  int64 low = 0, up = n;
  while (low + 1 < up) {
    int64 k = (low + up) / 2;
    if (IsPossible(n, m, as, k)) {
      up = k;
    } else {
      low = k;
    }
  }
  cout << up << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x&&x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS*max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x*x + y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


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

	vector <int> x(N);
	vector <pair <int, int>> pr(N);

	for (int i = 0; i < N; ++i)
	{
		scanf("%d", &x[i]);
		pr[i].first = x[i];
		pr[i].second = i;
	}

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

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

		if (x[i] < pr[N / 2].first)
		{
			printf("%d\n", pr[N / 2].first);
		}
		else
		{
			printf("%d\n", pr[N / 2-1].first);
		}
	}


	return 0;
}

Measured memory_bytes: 4480
#include<iostream>
#include<queue>
#include<vector>
#define MAX_V 100
#define MAX_T 100
#define INF 1e9
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

int d[MAX_V][MAX_T + 1];

struct edge{
  int to,cost;  
};
vector<edge> G[MAX_V];

piii init(int a, int b, int c){
  return piii(a, pii(b, c));
}

int dijkstra(int s, int t, int m){
  priority_queue<piii, vector<piii>, greater<piii> > que;

  for (int i = 0; i < MAX_V; i++){
    for (int j = 0; j <= MAX_T; j++){
      d[i][j] = INF;
    }
  }

  d[s][m] = 0;
  que.push(piii(0, pii(m, s)));
  while(!que.empty()){
    piii pos = que.top();que.pop();
    int c = pos.first;
    int ti = pos.second.first;
    int v = pos.second.second;
    // cout << "v:" << v << endl;
    // cout << "size:" << que.size() << endl;
    if(v == t){
      return c;
    }

    for (int i = 0; i < G[v].size(); i++){
      int next_ti = ti - G[v][i].cost;
      int next_ver = G[v][i].to;
      // cout << "ti:" << ti << endl;
      // cout << "G[" << v << "][" << i << "].to:" << next_ver << endl;
      // cout << "G[" << v << "][" << i << "].cost:" << G[v][i].cost << endl;
      // cout << next_ti << endl;
      if(next_ver == v){
	if(ti < m && d[v][ti + 1] > c + 1){
	  d[v][ti + 1] = c + 1;
	  que.push( init(c + 1, ti + 1, v));
	}
      }else{
	if(next_ti < 0)continue;
	
	if(d[next_ver][next_ti] > c + G[v][i].cost){
	  d[next_ver][next_ti] = c + G[v][i].cost;
	  que.push( init(d[next_ver][next_ti], next_ti, next_ver));
	}
      }
    }
  }
  return -1;
}

void printd(){
  for (int i = 0; i <= 10; i++){
    for (int j = 0; j < 10; j++){
      cout << d[i][j] << " ";
    }
    cout << endl;
  }
}

int main(){
  int n,m,l,k,a,h;
  while(cin
	>> n 
	>> m
	>> l
	>> k
	>> a
	>> h,n){
    for (int i = 0; i < n; i++){
      G[i].clear(); 
    }
    for (int i = 0; i < l; i++){
      int freazer;
      cin >> freazer;
      G[freazer].push_back((edge){freazer, 1});
    }
    for (int i = 0; i < k; i++){
      edge e;
      int from;
      cin >> from >> e.to >> e.cost;
      G[from].push_back(e);
      G[e.to].push_back((edge){from, e.cost});
    }

    int ans = dijkstra(a, h, m);
    if(ans == -1){
      cout << "Help!" << endl;
    }else{
      cout << ans << endl;
    }
  }
  //printd();
  return 0;
}

Measured memory_bytes: 1488
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;

inline ll read() {
	reg ll s = 0, t = 0; reg char ch = getchar();
	while (!isdigit(ch)) t |= ch == '-', ch = getchar();
	while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return t ? -s : s;
}

int pos[maxn];
int main() {
	int k = read(), x = read();
	int cnt = 1;
	int tot = 0; pos[++tot] = x;
	if (k == 1) { cout << x << endl; return 0; }
	while (x - cnt >= -1000000) {
		pos[++tot] = x - cnt;
		cnt++;
		if (tot == k) break;
	}
	cnt = 1;
	while (x + cnt <= 1000000) {
		pos[++tot] = x + cnt;
		cnt++;
		if (tot == 2 * k - 1) break;	
	}
	sort(pos + 1, pos + tot + 1);
	for (int i = 1; i <= tot; i++) cout << pos[i] << " ";
	return 0;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    
    vector<int> v;
    
    for(int i=0;i<n;i++){
        if(i%2==0)v.push_back(a[i]);
        else v.insert(v.begin()+0,a[i]);
    }
    
    if(v.size()%2==1)reverse(v.begin(),v.end());
    
    for(int i=0;i<n;i++){
        if(i!=n-1)cout<<v[i]<<" ";
        else cout<<v[i]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    ll ans=1e15;
    for(int i=1;i<=100;i++){
        ll cnt=0;
        for(int j=0;j<n;j++){
            cnt+=(x[j]-i)*(x[j]-i);
        }
        ans=min(ans,cnt);
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
    /*int n, a, b, soma = 0;
    scanf("%d %d %d", &n, &a, &b);
    for(int i = 1; i <= n; i++){
        if(i >= a && i <= b){
            soma += i;
        }
    }

    printf("%d\n", soma);*/

    int a, b, c;
    cin >> a >> b >> c;
    cout << (a+b >= c ? "Yes\n":"No\n");

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	
	String str1,str2;
	while((str1=input.readLine())!=null)
	    {
		
		
		str2=input.readLine();
		String str1_ary[]=str1.split(" ");
		String str2_ary[]=str2.split(" ");
		int h=0,b=0;
		for(int i=0;i<str1_ary.length;i++)
		    {
			if(str1_ary[i].equals(str2_ary[i]))h++;
			for(int j=0;j<str2_ary.length;j++)
			    {
				if(!(str1_ary[i]).equals(str2_ary[i]) && (str1_ary[i]).equals(str2_ary[j]))b++;
			    }
		    }
		System.out.println(h+" "+b);
		
	    }
    }
}

Measured memory_bytes: 16924
//ETO LOG POLON SIL I TI ZRYA ZA MNOI HODIL
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define pi acos(-1.0)
#define uniq(v) (v).erase(unique((v).begin(),(v).end()),(v).end())

using namespace std;

ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}

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

ll to_i(string a)
{
    ll x = 0;
    for (char i : a)
    {
        x = x * 10 + (i - '0');
    }
    return x;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n, k;
    cin >> n >> k;
    vector <ll> v(n);
    for (ll i = 0; i < n; i++) cin >> v[i];
    ll ans = 3e8 + 1337;
    for (ll i = 0; i < n - k + 1; i++)
    {
        ll a = abs(v[i]) + abs(v[i] - v[i + k - 1]);
        ll b = abs(v[i + k - 1]) + abs(v[i] - v[i + k - 1]);
        a = min(a, b);
        if (a < ans) ans = a;
    }
    
    cout << ans;
    
    
    
    
    
    
}



/*
 
 5 3
 -30 -10 10 20 50
 0   1   2  3  4
 
 
 auto begin = chrono::steady_clock::now();
 
 
 auto end = chrono::steady_clock::now();
 auto elapsed_ms = chrono::duration_cast<std::chrono::milliseconds>(end - begin);
 cout << "\nThe time: " << elapsed_ms.count() << " ms\n";
 
 */


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}


int main()
{
	int X,N;
	cin>>X>>N;
	vector<int> p(N);
	for(int i=0; i<N; i++)
	{
		cin>>p[i];
	}
	priority_queue<pair<int,int>> pq;
	for(int i=0; i<=101; i++)
	{
		bool flag = true;
		for(int j=0; j<N; j++)
		{
			if(p[j] == i)
			{
				flag = false;
				break;
			}
		}

		if(flag)
		{
			pq.push(make_pair(-abs(X-i),-i));
		}
	}

	cout<<-pq.top().second<<endl;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>

#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)>(b)? (a): (b))

void calc_mm( long n, std::vector<long long>& s, std::vector<std::pair<long long, long long> >& mm )
{
    long i;
    long j = 0;
    long k;
    for(i=0; i<n; i++) {
        long id_min = j;
        long long min = s[n-1];
        for(k=j; k<i; k++) {
            long long tmp = abs(s[i] - s[k]*2);
            if(min > tmp) {
                min = tmp;
                id_min = k;
            }
            if(s[k]*2 > s[i]) {
                break;
            }
        }
        j = id_min;
        mm[i] = (s[i]-s[j]>s[j]? std::make_pair( s[j], s[i]-s[j]): std::make_pair( s[i]-s[j], s[j]));
    }

    return;
}

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    std::vector<long> a(n);
    std::vector<long long> s(n);
    std::vector<long long> t(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &(a[i]));
        s[i] = a[i];
        t[n-1-i] = a[i];
    }
    for(i=1; i<n; i++) {
        s[i] = s[i-1] + a[i];
        t[i] = t[i-1] + a[n-1-i];
    }

    std::vector<std::pair<long long, long long> > smm(n);
    calc_mm( n, s, smm );

    std::vector<std::pair<long long, long long> > tmm(n);
    calc_mm( n, t, tmm );

    long long ans = 10000000000;
    for(i=1; i<n-1; i++) {
        long long tmpmin = MIN( smm[i].first, tmm[n-2-i].first );
        long long tmpmax = MAX( smm[i].second, tmm[n-2-i].second );
        if(ans > tmpmax - tmpmin) {
            ans = tmpmax - tmpmin;
        }
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 11136
// https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_b

#include "algorithm"
#include "cmath"
#include "functional"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;
  VL as(N);

  rep(i, N) cin >> as[i];

  ll sum = 0;
  for (auto a : as) sum += a;

  ll ov = -1;

  ll cur = 0;

  rep(i, N) {
    cur += as[i];
    if (sum % 2 == 0 && cur == sum / 2) drop(0);
    if (cur > sum / 2) {
      ov = i;
      break;
    }
  }

  ll leftEdge = cur - as[ov];
  ll rightEdge = sum - cur;
  ll res = min(sum - 2 * leftEdge, sum - 2 * rightEdge);

  cout << res << endl;
}

void solve2() {
  ll N;
  cin >> N;
  VL as(N);

  rep(i, N) cin >> as[i];

  VL sums(N);
  rep(i, N) {
    if (i > 0) sums[i] += sums[i - 1];
    sums[i] += as[i];
  }

  ll res = INF;
  rep(i, N - 1) {
    ll left = sums[i];
    ll right = sums[N - 1] - left;

    chmin(res, abs(left - right));
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int main() {
	double N;
	cin >> N;
	double A;
	double minimum = 10000000000000010LL;
	for (int i = 0; i < 5; i++) {
		cin >> A;
		minimum = min(minimum, A);
	}
	cout << (long long)ceil(N / minimum) + 4 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
	a = max(a,b);
}

void solve(){	
    int n;
    cin >> n;
    ll p = (n/500) * 1000 + ((n%500)/5)*5;
    cout << p << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    //int t; cin >> t;
    //while(t--) solve();
    //
    solve();
    return 0;
}


Measured memory_bytes: 256
# D

x = int(input())

a = int(x**(1/5))
b = int(abs(x-a**5)**(1/5))
i = 1
while True:
    if a**5 - b**5 != x and a**5 - (-b)**5 != x:
        if a**5 - x > (a+1)**5 - x:
            a += i
            b = int(abs(x-a**5)**(1/5))
            if a**5 - b**5 == x:
                print(a,b)
                break
            elif a**5 - (-b)**5 == x:
                print(a,-b)
                break
            else:
                pass
        else:
            a -= 1
            b = int(abs(x-a**5)**(1/5))
            if a**5 - b**5 == x:
                print(a,b)
                break
            elif a**5 - (-b)**5 == x:
                print(a,-b)
                break
            else:
                pass
    elif a**5 - b**5 == x:
        print(a,b)
        break

    else:
        print(a,-b)
        break

    


Measured memory_bytes: 9504
n = int(input())
s = [input() for i in range(n)]
for k in range(n):
    s[k]=sorted(list(s[k]))
s=sorted(s)

c = 1
count = 0

for x in range (n-1):
        if s[x]==s[x+1]:
            c += 1
        else:
            if c>= 2:
                count += c*(c-1)//2
            c = 1
if c >=2:
    count += c*(c-1)//2
print(count)


Measured memory_bytes: 25432
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

bool pairCompare(const pair<ll, ll>& firstElof, const pair<ll, ll>& secondElof) {
    return firstElof.first < secondElof.first;
}

int main(void) {
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll> > shop;
    REP(i, n) {
        pair<ll, ll> input;
        cin >> input.first >> input.second;
        shop.push_back(input);
    }
    sort(shop.begin(), shop.end(), pairCompare);

    ll pos = 0;
    ll price = 0;
    while (m > 0) {
        while (shop[pos].second <= 0) pos++;
        shop[pos].second--;
        price += shop[pos].first;
        m--;
    }
    cout << price << endl;

    return 0;
}


Measured memory_bytes: 2420
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> jobs(N);
    for (int i = 0; i < N; i++) {
        int a, b; cin >> a >> b;
        jobs[i] = {b, a};
    }
    sort(jobs.begin(), jobs.end(), greater<pair<int, int>>());
    set<int> sche;
    for (int i = 0; i <= M; i++) {
        sche.insert(i);
    }
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        pair<int, int> crt_job = jobs[i];
        int money = crt_job.first;
        int day = crt_job.second;
        if (0 <= M - day) {
            auto itr = sche.upper_bound(M-day);
            if (itr == sche.begin()) continue;
            itr--;
            sche.erase(itr);
            ans += money;
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 5760
N = int(input())
T,A = map(int,input().split(" "))
Pos = [int(i) for i in input().split(" ")]
best_pos = 0
temp_abs = 10**9
for i in range(N):
  t = T - Pos[i]*0.006
  Abs = abs(A - t)
  if Abs < temp_abs:
    best_pos = i+1
    temp_abs = Abs
print(best_pos)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5;
int n,s;
int a[N],c[N];
long long ans;
int ask(int l,int r,int s)
{
	if(a[r]<=s)
	{
		ans+=s-a[l];return a[l];
	}
	if(a[l]>=s)return ans+=a[r]-s,a[r];
	if(c[l]>=c[r])
	{c[l]+=c[r];
		int sp=ask(l,r-1,s);ans+=a[r]-sp;
		return a[r];
	}
	else
	{c[r]+=c[l];
		int sp=ask(l+1,r,s);ans+=sp-a[l];return a[l];
	}
}
main()
{
	cin>>n>>s;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i],&c[i]);
	}
	ask(1,n,s);
	cout<<ans;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define MOD (ll)(998244353)
#define MAX (ll)(1e5 + 4)
#define INF (ll)(1e17)
using namespace std;
using ll =  long long;
using ld = long double;

int main () {
	int n;
	cin >> n;
	string st;
	cin >> st;
	bool fl = 0;
	if (n % 2 == 0) {
		for (int i = 0; i < n / 2; i++) {
			if (st[i] != st[i + n / 2]) {
				cout << "No\n";
				return 0;
			}
		}
		fl = 1;
	}
	if (fl) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}
		


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

namespace ConsoleApp15
{
    class Class57
    {
        static void Main()
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = nm[0], m = nm[1];
            var a = new int[n];
            var b = new int[n];
            for(int i = 0; i < n; i++)
            {
                string[] r = Console.ReadLine().Split();
                a[i] = int.Parse(r[0]);
                b[i] = int.Parse(r[1]);
            }
            var c = new int[m];
            var d = new int[m];
            for(int i = 0; i < m; i++)
            {
                string[] r = Console.ReadLine().Split();
                c[i] = int.Parse(r[0]);
                d[i] = int.Parse(r[1]);
            }

            for(int i = 0; i < n; i++)
            {
                int leng = int.MaxValue;
                int ans = int.MinValue;
                for(int j = 0; j < m; j++)
                {
                    if(leng>Abs(a[i] - c[j]) + Abs(b[i] - d[j]))
                    {
                        leng = Abs(a[i] - c[j]) + Abs(b[i] - d[j]);
                        ans = j+1;
                    }
                }
                Console.WriteLine(ans);
            }
        }
    }
}


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

#define N 200001 //size of array
const ll MOD = 1e9+7;

ll fac[N], inv[N], finv[N];

void C_init() {
  fac[0] = 1; fac[1] = 1;
  finv[0] = 1; finv[1] = 1;
  inv[1] = 1;
  for (int i=2; i<N; i++){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

ll C(int a, int b) {
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}

int main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  ll ans = 0;
  C_init();
  for (int i=B+1; i<=W; i++) {
    ans += (C(H-A+i-2, i-1) * C(W-i+A-1, A-1)) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8280
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String ch = sc.nextLine();
    char[] c = new char[ch.length()];

    for(int i = 0; i < ch.length() ; i++){
      c[i] = ch.charAt(i);
    }
    for(int i = 0; i < c.length ; i++){
      if(Character.isUpperCase(c[i])){ c[i] = Character.toLowerCase(c[i]);}
      else if(Character.isLowerCase(c[i])){ c[i] = Character.toUpperCase(c[i]);}
      System.out.print(c[i]);
    }
    System.out.println("");
  }
}



Measured memory_bytes: 27120
def main():
    N,K,Q = [int(i) for i in input().split()]
    q_list = [0] * N
    for i in range(Q):
        a = int(input()) - 1
        q_list[a] += 1
    for i in range(N):
        if K - (Q - q_list[i]) > 0:
            print("Yes")
        else:
            print("No")
if __name__ == "__main__":
    main()

Measured memory_bytes: 4680
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
    int n, q, t;
    string name;
    // 標準ライブラリから queue を使用
    queue<pair<string, int> > Q; // プロセスキュー

    cin >> n >> q;


    // 全てのプロセスをキューに順番を追加する
    for (int i = 0; i < n; i++) {
        cin >> name >> t;
        Q.push(make_pair(name, t));
    }

    pair<string, int> u;
    int elaps = 0, a;

    // シミュレーション
    while (!Q.empty()) {
        u = Q.front(); Q.pop();
        a = min(u.second, q);   // q または必要な時間 u.t だけ処理を行う
        u.second -= a;          // 残りの必要時間を計算
        elaps += a;            // 経過時間を加算
        if (u.second > 0) {
            Q.push(u);
        } else {
            cout << u.first << " " << elaps << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 6172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strs = br.readLine().split(" ");
        int count_five = 0;
        int count_seven =0;
        for(String s : strs){
            if(s.equals("5")){
                count_five++;
            }else if (s.equals("7")){
                count_seven++;
            }
        }
        if (count_five == 2 && count_seven == 1){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, x; cin >> n >> x;
  if (x == 1 or x == 2 * n - 1) {
    cout << "No" << "\n";
    return 0;
  }
  cout << "Yes" << "\n";
  if (n == 2) {
    for (int i = 1; i <= 3; i++) cout << i << "\n";
    return 0;
  }
  int res[2 * n - 1];
  for (int i = 0; i < 2 * n - 1; i++) res[i] = i + 1;
  if (x < n) {
    swap(*find(res, res + 2 * n - 1, x), res[n - 1]);
    swap(*find(res, res + 2 * n - 1, x - 1), res[n - 2]);
    swap(*find(res, res + 2 * n - 1, x + 1), res[n]);
    swap(*find(res, res + 2 * n - 1, x + 2), res[n - 3]);
  } else {
    swap(*find(res, res + 2 * n - 1, x), res[n - 1]);
    swap(*find(res, res + 2 * n - 1, x + 1), res[n - 2]);
    swap(*find(res, res + 2 * n - 1, x - 1), res[n]);
    swap(*find(res, res + 2 * n - 1, x - 2), res[n - 3]);
  }
  for (auto i : res) cout << i << "\n";
  return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

#define YES "Yes"
#define NO "No"

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

	string ret = NO;
	if(N[1] == N[2] && (N[0]==N[1] || N[2]==N[3]))
		ret = YES;

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
while True:
    (H,W) = [int(x) for x in input().split()]
    if H == W == 0:
        break

    for hc in range(H):
        if hc == 0 or hc == H - 1:
            print('#'* W)
        else:
            print('#' + '.' * (W - 2) + '#')
    print()    

Measured memory_bytes: 6724
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
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;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int n,a,b; cin >>n >>a >>b;
  string s; cin >>s;
  int aa = 1; int bb = 1;
  rep(i, n){
    if (s[i] == 'a'){
      if (aa <= a + b){
        cout <<"Yes" <<endl;
        aa++;
      }else cout <<"No" <<endl;
    }else if (s[i] == 'b'){
      if (aa <= a + b && bb <= b){
        cout <<"Yes" <<endl;
        aa++; bb++;
      }else{
        cout <<"No" <<endl;
        bb++;
      }
    }else cout <<"No" <<endl;
  }
}


Measured memory_bytes: 896
object Main extends App {
  import scala.io.StdIn._

  solve
  def solve: Unit = {
    val expression = readLine
    if (expression == null) return
    val calculator = Calculator()
    for (button ← expression.trim){
      calculator.push(button)
    }
    println(calculator.display)
    solve
  }
  case class Calculator(r1: Register = new Register, r2: Register = new Register, var r3: Operator = Null) {
    def push(button: Char): Unit = {
      button match {
        case d if d.isDigit ⇒ r2.addDigit(d)
        case o ⇒
          consumeOperator()
          o match {
            case '=' ⇒ r3 = Null
            case '+' ⇒ r3 = Add
            case '-' ⇒ r3 = Sub
            case '*' ⇒ r3 = Mul
            case _ ⇒ ???
          }
      }
    }
    private[this] def consumeOperator(): Unit = {
      r3 match {
        case Null ⇒ operate((_, b) ⇒ b)
        case Add ⇒ operate(_+_)
        case Sub ⇒ operate(_-_)
        case Mul ⇒ operate(_*_)
      }
    }
    private[this] def operate(op: (Int, Int) ⇒ Int): Unit = {
      r1.replace(r1.value.flatMap(a ⇒ r2.value.map(b ⇒ op(a, b))).filter(n ⇒ 0 <= n && n < 10000))
      r2.flush()
    }
    def display: String = {
      r1.value match {
        case None ⇒ "E"
        case Some(value) ⇒ value.toString
      }
    }
  }
  class Register{
    private[this] var acc: Option[Int] = Some(0)
    private[this] def validate(): Unit = {
      acc = acc.filter(n ⇒ 0 <= n && n < 10000)
    }
    def addDigit(digit: Char): Unit = {
      acc = acc.map(_ * 10 + digit.asDigit)
      validate()
    }
    def flush(): Unit = {
      acc = acc.map(_ ⇒ 0)
    }
    def copyFrom(register: Register): Unit = {
      acc = acc.flatMap(_ ⇒ register.value)
    }
    def replace(newValue: Option[Int]): Unit = {
      acc = acc.flatMap(_ ⇒ newValue)
      validate()
    }
    def value: Option[Int] = {
      validate()
      acc
    }
    override def toString: String = s"Register(${acc.getOrElse("E")})"
  }
  sealed trait Value
  case class Valid(value: Int) extends Value
  case object E extends Value
  sealed trait Operator
  case object Null extends Operator
  case object Add extends Operator
  case object Sub extends Operator
  case object Mul extends Operator
  implicit class Scope[T](val value: T) extends AnyVal{
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 62068
function main()
  N,M=map(x->parse(Int,x),split(readline()))
  mod=10^9+7
  a,b=1,0
  for i=0:N-1
    a,b=(M-i)*((M-N+i)*a%mod+i*b%mod*(M-i+1)%mod)%mod,a
  end
  println(a)
end
main()

Measured memory_bytes: 166756
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

int solve() {
	ll a;
	cin >> a;

	cout << a + a * a + a * a * a << endl;

	return 0;
}

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

	solve();

	return 0;
}


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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

int main(){
	ll k;
	string str;
	cin >> k >> str;
	if(str.size() <= k) {
		cout << str << endl;
	} else {
		cout << str.substr(0, k) << "...";
	}
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

ll N, T, A;
ll mi;

void init()
{
	cin >> N >> T >> A;
	T *= 1000;
	mi = 1e18;
	A *= 1000;
}

void solve()
{
	int res = -1;
	rep(i, N) {
		ll x;
		cin >> x;
		ll t = abs(T - x * 6 - A);
		if (t < mi) {
			mi = t;
			res = i+1;
		}
	}
	cout << res << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
using namespace std;



int main()
{
	int  u[26] = {};
	char ch;
	while (cin >> ch){
		ch = tolower(ch);
		if (isalpha(ch)){
			u[ch-'a']++ ;
		}
	}
	for (int i = 0; i < 26; i++){
		printf("%c : %d\n", i + 'a', u[i]);
	}
	return 0;
}




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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  map<int, int> cnt;
  int A, B;
  cin >> A >> B;

  for ( int i = 1; i*i <= A; i++ ) {
    if ( A%i == 0 ) cnt[i] = cnt[A/i] = 1;    
  }

  for ( int i = 1; i*i <= B; i++ ) {
    if ( B%i == 0 ) {
      if ( cnt[i] ) cnt[i] = 2;
      if ( cnt[B/i] ) cnt[B/i] = 2;     
    }
  }

  int sum = 0;
  vector<int> C;  
  for ( auto i : cnt ) {
    if ( i.second == 2 ) C.push_back(i.first);    
  }

  sort(C.begin(), C.end());  
  vector<bool> use(C.size(), true);  

  for ( int i = 0; i < (int)C.size(); i++ ) {
    if ( C[i] == 1 ) continue;
    for ( int j = i+1; j < (int)C.size(); j++ ) {
      if ( C[j]%C[i] == 0 ) use[j] = false;      
    }
  }

  for ( int i = 0; i < (int)use.size(); i++ ) {
    if ( use[i] ) sum++;
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;
public class Main{
    int x,kei;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        x = sc.nextInt();
        kei = x*x*x;
        System.out.print(kei+"\n");
        
    }
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

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

int main(){

	int N;

	cin >> N;

	char arare[N];
	bool yellow = false;
	for (int i = 0; i < N; ++i)
	{
		/* code */
		cin >> arare[i];
		if (arare[i] == 'Y') yellow = true;
		
	}

	if(yellow){
		cout << "Four" << endl;
	} else {
		cout << "Three" << endl;
	}
}

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

int main() {
  string s;
  cin >> s;
  if(s =="abc" || s=="acb" || s =="bca" || s=="cba" || s=="bac" || s == "cab") cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    std::string s;
    std::cin >> s;

    int64_t max = 0;
    int64_t count = 0;
    for (auto& c : s) {
        if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
            count++;
            max = std::max(max, count);
        } else {
            count = 0;
        }
    }

    std::cout << max << std::endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> buttens(n);	//ボタン一覧
  vector<bool> pushed(n);	//押されたボタン
  for (int i = 0; i < n; i++) {
    cin >> buttens.at(i);
  }
  
  int pushed_now = 0;
  int counter = 0;
  while(!pushed.at(pushed_now) && pushed_now != 1){
    pushed.at(pushed_now) = true;
    pushed_now = buttens.at(pushed_now) - 1;
    counter++;
  }
  
  if(pushed_now == 1) cout << counter << endl;
  else cout << -1 << endl;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      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;
  }
};

int main()
{
  ll a, b, n;
  cin >> a >> b >> n;
  auto f = [&](ll x) {
    ll res = (ll)floor((double)(a*x)/b) - a * (ll)floor((double)x/b);
    return res;
  };
  cout << f(min(b-1, n)) << endl;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int l=0,r=n-1;
  int c=0;
  while(l<r){
      if(s[l] == 'W' && s[r]=='R'){
          l++ ;
          r--;
          c++;
      }else if( s[l] == 'R' && s[r]=='W'){
          l++;
          r--;
          
      }else if( s[l] == 'W' && s[r]=='W'){
          r--;
          
      }else{
          l++;
      }
  }
  cout<<c;
  return 0;
}

Measured memory_bytes: 3748
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int W, a, b;
	std::cin >> W >> a >> b;
	
	if (a + W < b)
		std::cout << ((b - a) - W) << "\n";
	else if (b + W < a)
		std::cout << ((a - b) - W) << "\n";
	else
		std::cout << "0\n";
}


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

const int A = 15;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<int>> x(n, vector<int>(A)), y(n, vector<int>(A));
  rep(i, n) {
    cin >> a[i];
    rep(j, a[i]) {
      cin >> x[i][j] >> y[i][j];
      --x[i][j];
    }
  }

  int ans = 0;
  rep(bit, 1<<n) {
    int now = 0;
    bool ok = true;
    rep(i, n) {
      if (!(bit & 1<<i)) continue;
      ++now;
      rep(j, a[i]) {
        if (y[i][j] == 1 && !(bit & 1<<x[i][j])) ok = false;
        if (y[i][j] == 0 && bit & 1<<x[i][j]) ok = false;
      }
    }
    if (ok) ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624