akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;

int main(){
  ll n,x,l[110];
  cin>>n>>x;
  ll d=0,ans=1;
  for(int i=0;i<n;i++){
      cin>>l[i];
      d+=l[i];
      if(d<=x)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
	string s; cin >> s;
	
	if (s.at(0) != 'A') {
		cout << "WA" << endl;
		return 0;
	}

	int cnt = 0;
	int indexC;
	for (int i = 2; i < s.size() - 1  ; i++) {
		if (s.at(i) == 'C') {
			cnt++;
			indexC = i;
		}
	}
	if (cnt != 1) {
		cout << "WA" << endl;
		return 0;
	}

	bool small = true;
	for (int i = 1; i < s.size(); i++) {
	
		if (i != indexC) {

			if (s.at(i) < 'a' || 'z' < s.at(i)) {

				small = false;

			}

		}	
	
	}

	if (!small) {
		cout << "WA" << endl;
		return 0;
	}
	
	cout << "AC" << endl;	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
string s;
int main(){
	long long i,j,ans = 100000000000,a[20],ret;
	cin >> s;
	int n = s.size();
	for(i=0;i<n;i++){
		a[i] = s[i]-'0';
	}
	for(i=0;i<n-2;i++){
		ret = 0;
		for(j=i;j<i+3;j++){
			ret *= 10;
			ret += a[j];
		}
		ans = min(ans,abs(ret-753));
	}
	cout << ans << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;

  while (1) {
    if (n <= 0) {
      cout << ans << endl;
      return 0;
    }
    if (ans == 0) {
      ans++;
      n -= k;
    }
    else {
      ans++;
      n -= (k - 1);
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

typedef tuple<ll,int,int,int> TP;

int main(){
    ios();
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> a(X), b(Y), c(Z);
    for(auto& i : a) cin >> i;
    for(auto& i : b) cin >> i;
    for(auto& i : c) cin >> i;
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());

    TP t = make_tuple(a[0] + b[0] + c[0], 0, 0, 0);
    priority_queue<TP> pq;
    pq.push(t);

    set<TP> st;
    st.insert(t);

    REP(i, K){
        TP t = pq.top();
        pq.pop();
        cout << get<0>(t) << '\n';
        int x = get<1>(t), y = get<2>(t), z = get<3>(t);
        if(x+1 < X){
            TP t = make_tuple(a[x+1] + b[y] + c[z], x+1, y, z);
            if(find(all(st), t) == st.end()){
                pq.push(t);
                st.insert(t);
            }
        }
        if(y+1 < Y){
            TP t = make_tuple(a[x] + b[y+1] + c[z], x, y+1, z);
            if(find(all(st), t) == st.end()){
                pq.push(t);
                st.insert(t);
            }
        }
        if(z+1 < Z){
            TP t = make_tuple(a[x] + b[y] + c[z+1], x, y, z+1);
            if(find(all(st), t) == st.end()){
                pq.push(t);
                st.insert(t);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 896
/*Mrc01*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#define ll long long 
#define ull unsigned long long 
#define f(i,x,n) for(ll int i=x;i<n;i++) 
#define re(j,x,n) for(ll int j=x;j>=n;j--)
#define f1(k,x,n) for(ll int k=x;k<=n;k++)
#define endl "\n"
#define mp make_pair
#define pb push_back
#define bit(x, i) (x >>(i - 1) & 1ll)
#define MAX 1000001
const int mod=1000000007;
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<ll int,ll int>,null_type, less<pair<ll int,ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
      new_data_set;
vector<ll int > v[1000100],check;
ll int a[1000010],vis[1000100]; 

void dfs(ll int vtx,ll int count)
{
   ll int f=0;
   vis[vtx]=1;
   count++;
   for(ll int i:v[vtx])
   {
     if(vis[i]!=1)
     {
       f=1;
       dfs(i,count);
     }
   }
   if(f==0)
   {
     check.pb(count-1);
   }
}
void solve()
{  
   string s;
    cin>>s;
   string s1;
   s1=s;
   reverse(s1.begin(),s1.end());
   if(s1!=s)
   {
     cout<<"No";
     return;
   }
   s1=s.substr(0,(s.size()-1)/2);
   string s3;
   s3=s1;
   reverse(s1.begin(),s1.end());
   if(s3!=s1)
   {
     cout<<"No";
     return;
   }
   s1.clear();
   f(i,(s.size()+3)/2-1,s.size())
    s1+=s[i];
   s3=s1;
   reverse(s1.begin(),s1.end());
   if(s3!=s1)
   {
     cout<<"No";
     return;
   }
   cout<<"Yes";
}

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


Measured memory_bytes: 24960
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1,2,0,-2,0};
const int dy[]={0,1,-1,0,1,1,-1,-1,0,2,0,-2};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef pair<int,Pii > P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
int main(){
	int e;
	while(scanf("%d",&e),e){
		int ans = INF;
		rep(y,1001){
			rep(z,101){
				int Y = y*y;
				int Z = z*z*z;
				if(Y+Z > e)continue;
				ans = min(ans,e-Y-Z+y+z);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1188
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long ll;

int main() {
	ll n, m;
	cin >> n >> m;
	for (ll i = n / 2, j = i + 1, k = 1; k <= m; k++, i--, j++) {
		if (n % 2 == 0 && (j - i == n / 2 || j - i == n / 2 + 1)) j++;
		cout << i << ' ' << j << endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


int main(){
  vector<ll> a(2);
  cin >> a[0] >> a[1];
  sort(ALL(a));
  ll ans;
  if (a[0] > 1){
    ans = (a[0] - 2) * (a[1] - 2);
  }else{
    if (a[1] > 1){
      ans = a[1] - 2;
    } else {
      ans = 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int main () {
  string s;
  cin>>s;
  char a,b;
  bool af = false, bf = false;
  a=s[3];
  rep(i, 3){
    if(a == s[i]) af = true;
    else if(b == s[i]) bf = true;
    else b = s[i];
  }
  cout << (af && bf ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <set>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, m, ans = 0, l = 0;
  scanf("%lld%lld", &n, &m);
  pair<ll, ll> a[m];
  set< pair<ll, ll> > b;
  set< pair<ll, ll> >::iterator it;
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld", &a[i].first, &a[i].second);
    b.insert(make_pair(a[i].second, a[i].first));
  }
  sort(a, a + m);
  while( l != m ) {
    it = b.begin();
    ++ans;
    pair<ll, ll> p = make_pair((*it).first, 0);
    ll po = lower_bound(a, a + m, p) - a;
    for(i = l; i < po; ++i) b.erase(b.find(make_pair(a[i].second, a[i].first)));
    l = po;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 10112
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>

#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    string S;
    cin >> S;
    double half;
    half = ((double)S.size())/2.0;
    llong ans = 0;
    for(int i=0; i<ceil(half); i++){
        if(S[i]!=S[S.size()-1-i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 3196
#include<iostream>

using namespace std;

int GCD(int a, int b){
  return !b ? a : GCD(b, a%b);
}

int main(void){
  long long a,b,gcd,lcm;

  while(cin >> a >> b){
    gcd=GCD(a,b);
    lcm=a*b/gcd;
    cout << gcd << " " << lcm << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long countMax = sc.nextLong();
		long array[] = new long[num];
		long sorted[][] = new long[num][2];
		for(int i = 0; i < num; i ++) {
			array[i] = sc.nextLong();
			sorted[i][0] = array[i];
			sorted[i][1] = i;
		}
		Arrays.sort(sorted, (a, b) -> Long.compare(a[0], b[0]));
		int next[] = new int[num];
		int prv = (int)sorted[0][1];
		for(int i = 1; i < num; i ++) {
			if(sorted[i][0] == sorted[i - 1][0]) {
				next[(int)sorted[i - 1][1]] = (int)sorted[i][1];
			}else {
				next[(int)sorted[i - 1][1]] = prv;
				prv = (int)sorted[i][1];
			}
		}
		next[(int)sorted[num - 1][1]] = prv;

		int count = 1;
		int tmpIndex = 0;
		int lastIndex[] = new int[num];
		while(tmpIndex != num) {
			if(next[tmpIndex] <= tmpIndex) {
				lastIndex[count - 1] = tmpIndex;
				count ++;
			}
			tmpIndex = next[tmpIndex] + 1;
		}
		countMax = (countMax - 1) % count;
		if(countMax == count - 1) {
			System.out.println(); return;
		}

		StringBuilder ans = new StringBuilder();
		tmpIndex = lastIndex[(int)countMax];
		while(tmpIndex < num) {
			if(next[tmpIndex] <= tmpIndex) {
				ans.append(array[tmpIndex]+" ");
				tmpIndex ++;
			}else {
				tmpIndex = next[tmpIndex] + 1;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 101096
/**
 *      AGC 19 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-15 00:22:34
**/

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

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

    ll Q, H, S, D; cin >> Q >> H >> S >> D;
    ll N; cin >> N;

    if (N % 2 == 0){
        cout << min(min(D * N / 2, S * N), min(H * 2 * N, Q * 4 * N)) << endl;
    }
    else {
        cout << min(min(S, 2 * H), 4 * Q) + min(min(D * (N - 1) / 2, S * (N - 1)), min(H * 2 * (N - 1), Q * 4 * (N - 1))) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long unsigned
using namespace std;
int a[100005][4];
int dp[100005][4];
int n;
int vacation(int day, int job){
    if(day == n) return 0;

    if(dp[day][job]!=-1) return dp[day][job];
int max1=0;
if(job==0){
    max1 = max(max1,a[day][1]+vacation(day+1,1));
    max1 = max(max1,a[day][2]+vacation(day+1,2));
    max1 = max(max1,a[day][3]+vacation(day+1,3));
}
else if(job==1){
     max1 = max(max1,a[day][2]+vacation(day+1,2));
     max1 = max(max1,a[day][3]+vacation(day+1,3));
}

else if(job==2){
     max1 = max(max1,a[day][1]+vacation(day+1,1));
     max1 = max(max1,a[day][3]+vacation(day+1,3));
}

else {
     max1 = max(max1,a[day][1]+vacation(day+1,1));
     max1 = max(max1,a[day][2]+vacation(day+1,2));
}
return dp[day][job]=max1;
}
int main(){
cin>>n;
for(int i=0;i<n;i++) cin>>a[i][1]>>a[i][2]>>a[i][3];
memset(dp,-1,sizeof dp);
cout<<vacation(0,0)<<endl;
}


Measured memory_bytes: 14492
import java.util.Scanner;


public class Main {
	public static void main(String args[]) {
		    Scanner sc = new Scanner(System.in);	
			
			int hoge = sc.nextInt();
			System.out.println(Go_Home(hoge));

		    sc.close(); }
	
	public static int Go_Home(int n) {
		int ans = 0;
		while((ans + 1)*ans/2 < n){
			ans++;
		}
		return ans;
	}
}


Measured memory_bytes: 23252
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N;
    cin>>N;
    vector<Int> A(N);
    for(int i = 0;i < N;i++) {
        cin>>A[i];
    }
    Int s = 0;
    for(int i = 0;i < N;i++) {
        s ^= A[i];
    }
    Int ans = s;
    for(int i = 0;i < N;i++) {
        A[i] &= ~s;
    }

    int r = 0;
    vector<int> top(N);
    for(int i = 60;i >= 0;i--) {
        int j = r;
        for(;j < N;j++) {
            if(A[j]>>i&1) {
                swap(A[r],A[j]);
                break;
            }
        }
        if(j == N)
            continue;
        top[r] = i;
        for(int k = 0;k < N;k++) {
            if(r == k)
                continue;
            if(A[k]>>i&1)
                A[k] ^= A[r];
        }
        r++;
    }
    Int x = 0;
    for(int i = 60;i >= 0;i--) {
        Int nx = x |(1LL<<i);
        {
            Int b = nx;
            for(int j = 0;j < r;j++) {
                if(b>>top[j]&1)
                    b ^= A[j];
            }
            if((b&nx) == 0)
                x = nx;
        }
    }
    ans += x*2;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	vector<vi > grid(2020, vi(2020, 0));
	for (ll i = 0; i <= 2019; i++)
	{
		for (ll j = 0; j <= 2019; j++)	grid[i][j] = (i * j) % 2019;
	}
	ll l, r;
	cin >> l >> r;
	if (r - l >= 2019)
	{
		ll mini = LLONG_MAX;
		for (ll i = 0; i < 2019; i++)
		{
			for (ll j = i + 1; j <= 2019; j++)
			{
				if (i == j) continue;
				mini = min(mini, grid[i][j]);
			}
		}
		cout << mini ;
		return 0;
	}
	if (l / 2019 == r / 2019)
	{
		l %= 2019;
		r %= 2019;
		ll mini = LLONG_MAX;
		for (ll i = l; i <= r; i++)
		{
			for (ll j = i + 1; j <= r; j++)	 mini = min(mini, grid[i][j]);
		}
		cout << mini ;
		return 0;
	}
	ll mini = LLONG_MAX;
	l %= 2019;
	r %= 2019;
	// cout << r << endl;
	for (ll i = l; i != r ; i++, i%=2019)
	{
		for (ll j = i + 1; true ; j++, j%=2019)
		{
			if (i == j) continue;
			mini = min(mini, grid[i][j]);
			// cout << i << " " << j << " " << mini << endl;
			if(j == r) break;
		}
	}
	cout << mini ;
	return 0;
}

Measured memory_bytes: 32256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 10000000;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };
int a[10];
int cost[10] = { 0,2,5,5,4,5,6,3,7,6 };
int cnt[20];
int dp[10006],memo[10006];
vector<int>G[10];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, m)cin >> a[i];
	sort(a, a + m);
	vector<int>cst;
	rep(i, m)cst.push_back(cost[a[i]]);

	rep(i, m) {
		G[cost[a[i]]].push_back(a[i]);
	}

	fill(dp, dp + n, -inf);
	dp[0] = 0;




	rep(i, cst.size()) {
		rep(j, n) {
			int x = j + cst[i];
			if (x <= n&&dp[j] >= 0) {
				if (dp[x] <= dp[j] + 1) {
					dp[x] = max(dp[x], dp[j] + 1);
					memo[x] = j;
				}
			}
		}
	}

	int ptr = n;
	while (1) {
		if (!ptr)break;
		cnt[ptr - memo[ptr]]++;
		ptr = memo[ptr];
	}
	string ans;
	
	

	for (int i = 7; i >= 2; i--) {
		int mx = 0;
			rep(k, G[i].size())mx = max(mx, G[i][k]);
			for (int j = 0; j < cnt[i]; j++) {
			ans.push_back('0' + mx);
		}
	}
	sort(ans.begin(), ans.end());
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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 LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0, 0,-1,1,-1, 1,-1};
int dy[]={0,1,-1, 0,1,-1,-1, 1};


int main(){
    int n;cin >> n;
    string s;cin >> s;
    vector<bool> f(n,false);
    for (int i = 0; i < n-1; i++) {
        if(s[i] == '0' && s[i+1] == '0'){
            f[i] = f[i+1] = true;
        }
    }
    vector<string> v;
    string t="";
    for (int i = 0; i < n; i++) {
        if(f[i]){
            if(t!=""){
                v.pb(t);
                t = "";
            }
        }
        else{
            t += s[i];
        }
        if(i==n-1&&t!=""){
            v.pb(t);
        }
    }
    int ans = 0;
    for(auto vp:v){
        vector<int> a,b;
        int N = vp.size();
        for (int i = 0; i < N; i++) {
            if(vp[i] == '0'){
                int cnta = 0,cntb = 0;
                for (int j = i-1; j >= 0; j--) {
                    if(vp[j] == '0') break;
                    else cnta++;
                }
                for (int j = i+1; j < N; j++) {
                    if(vp[j] == '0') break;
                    else cntb++;
                }
                if(cnta&&cntb){
                    a.pb(cnta);
                    b.pb(cntb);
                }
            }
        }
        int sz = a.size();
        vector<vector<vector<int>>> dp(sz+1,vector<vector<int>> (3,vector<int>(2,0)));
        for (int i = 0; i < sz; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 2; k++) {
                    chmax(dp[i+1][0][0], dp[i][j][k]);
                }
            }
            chmax(dp[i+1][1][0], dp[i][0][0] + a[i]);
            chmax(dp[i+1][2][0], dp[i][0][0] + b[i] - 1);
            chmax(dp[i+1][2][1], dp[i][0][0] + b[i]);
            if(a[i]-1>0){
                chmax(dp[i+1][1][0], dp[i][1][0] + (a[i] - 1));
                chmax(dp[i+1][2][0], dp[i][1][0] + b[i] - 1);
                chmax(dp[i+1][1][0], dp[i][2][0] + 1);
                chmax(dp[i+1][2][0], dp[i][2][0] + b[i] - 1);
                chmax(dp[i+1][2][1], dp[i][1][0] + b[i]);
                chmax(dp[i+1][2][1], dp[i][2][0] + b[i]);
            }
        }
        int mx = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 2; j++) {
                chmax(mx,dp[sz][i][j]);
            }
        }
        ans += mx;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

const int MAX_N = 1010;
int X, Y, Z, K;
int128_t A[MAX_N], B[MAX_N], C[MAX_N];

int main(int argc, char **argv) {
    std::cin >> X >> Y >> Z >> K;
    for (int i = 1; i <= X; i++) {
        std::cin >> A[i];
    }
    for (int i = 1; i <= Y; i++) {
        std::cin >> B[i];
    }
    for (int i = 1; i <= Z; i++) {
        std::cin >> C[i];
    }
    std::vector<int128_t> AB_sum;
    for (int i = 1; i <= X; i++) {
        for (int j = 1; j <= Y; j++) {
            AB_sum.push_back(A[i] + B[j]);
        }
    }
    std::sort(AB_sum.begin(), AB_sum.end(), std::greater<int128_t>());

    std::vector<int128_t> total;
    for (int i = 0; i < std::min(X*Y, K); i++) {
        for (int j = 1; j <= Z; j++) {
            total.push_back(AB_sum[i] + C[j]);
        }
    }
    std::sort(total.begin(), total.end(), std::greater<int128_t>());

    for (int i = 0; i < K; i++) {
        std::cout << total[i] << std::endl;
    }



    return 0;
}

Measured memory_bytes: 84320
#include <algorithm>
#include <string>
#include <array>
#include <vector>
#include <iostream>

using namespace std;

int main() {

  int n;
  int ans = 0;
  int prev = 0;
  int tmp = 0;

  cin >> n;
  
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp >= prev) {
      ans ++;
      prev = tmp;
    } 
  }

  cout << ans << endl;
  
}


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

signed main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<int> A(N + 1);
  for (int i = N; ~i; --i) cin >> A[i];

  set<int> ans;

  int g = 0;
  for (int a : A) g = __gcd(g, abs(a));
  for (int &a: A) a /= g;
  for (int i = 2; i * i <= g; ++i) {
    if (g % i == 0) {
      while (g % i == 0) g /= i;
      ans.insert(i);
    }
  }
  if (1 < g) ans.insert(g);

  set<int> primes; {
    int c = A[0];
    for (int i = 2; i * i <= c; ++i) {
      if (c % i == 0) {
        while (c % i == 0) c /= i;
        primes.insert(i);
      }
    }
    if (1 < c) primes.insert(c);
    vector<int> np(N + 1);
    for (int i = 2; i < N + 1; ++i) {
      if (np[i]) continue;
      primes.insert(i);
      for (int j = 2*i; j < N + 1; j += i) {
        np[j] = 1;
      }
    }
  }

  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  for (int p : primes) {
    auto valid = [&rng, &N, &A](int p) {
      const int _t = 20;
      for (int _ = 0; _ < _t; ++_) {
        int x = uniform_int_distribution<int>(0, 1e9)(rng);
        if (_ * 2 < _t) x *= -1;
        int s = 0;
        for (int i = 0, n = 1; i < N + 1; ++i) {
          s += 1LL * n * A[i] % p;
          s %= p;
          n = 1LL * n * x % p;
        }
        if (s) return false;
      }
      return true;
    };
    if (valid(p)) ans.insert(p);
  }

  for (int p : ans) cout << p << '\n';

  return 0;
}


Measured memory_bytes: 384
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

template <int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

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

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

const int mod = 998244353;
using mint = ModInt<mod>;

int main() {
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<mint> dp(s + 1, 0);
    dp[0] = mint(2).pow(n);
    rep(i, n) {
        vector<mint> nx(dp);
        rep(j, s) {
            int nj = j + a[i];
            if (nj > s) break;
            nx[nj] += dp[j] / 2;
        }
        swap(dp, nx);
    }
    cout << dp[s] << "\n";
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
		
	vecl(A)
	ll N;
	cin>>N;
	fx(5){
		vecpl(A)
	}
	sorts(A)
	ll ans=N/A.at(0)+4;
	if(N%A.at(0)!=0){ans++;}
	ce(ans)
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int n, a, b;
    cin >> n >> a >> b;

    int sum = 0;
    for(int i = 1; i <= n; i++){
        int c = 0;
        int x = i;
        for(int j = 0; j < 5; j++){
            c += x % 10;
            x /= 10;
        }
        if(a <= c && c <= b) sum += i;
    }
    p(sum);
}


Measured memory_bytes: 384
attrs = Array.new
while line = $stdin.gets
  attrs << line.chomp.split
end

l_1 = attrs[0]
l_2 = attrs[1]

min = l_2.map {|i| i.to_i}.min
max = l_2.map {|i| i.to_i}.max

results = []
min.upto(max).each do |i|
  r = 0
  l_2.each do |j|
    r += (j.to_i - i.to_i)**2
  end
  results.push r
end

puts results.min

Measured memory_bytes: 1788
<?php
  
fscanf(STDIN,"%d",$a);
fscanf(STDIN,"%s",$s);

$del = $a/2;

if($a==1){
  echo "No"."\n";
  exit;
}

if ($a % 2 === 0) {
} else {
  echo "No"."\n";
  exit;
}


$ar = str_split($s, $del);

if($ar[0] == $ar[1]){
  echo "Yes"."\n";
  exit;
}else{
  echo "No"."\n";
  exit;
}

?>

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

int dist[1 << 16];
int N;
int W[16], H[16];
char goal[4][4];


int main(){

  cin >> N;
  REP(i, N) cin >> H[i] >> W[i];
  REP(i, 4)REP(j, 4){
    cin >> goal[i][j];
    if(goal[i][j] == 'R') goal[i][j] = 0;
    if(goal[i][j] == 'G') goal[i][j] = 1;
    if(goal[i][j] == 'B') goal[i][j] = 2;
  }

  
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, 0));
  fill(dist, dist + (1 << 16), INF);
  dist[0] = 0;
  
  while(!que.empty()){
    int cost = que.top().first;
    int mask = que.top().second;
    que.pop();
    if(cost > dist[mask]) continue;

    if(mask == 0xFFFF){
      cout << cost << endl;
      return 0;
    }
    
    
    REP(i, N){
      for(int h1 = -H[i] + 1; h1 < 4; h1++){
        for(int w1 = -W[i] + 1; w1 < 4; w1++){
          int h2 = h1 + H[i];
          int w2 = w1 + W[i];
          int nmaskc[3] = {0,0,0};
          
          int nmaskn = 0;
          
          REP(r, 4)REP(c, 4){
            if(h1 <= r && r < h2 && w1 <= c && c < w2){
              nmaskc[goal[r][c]] |= 1 << (r * 4 + c);
            }else{
              nmaskn |= mask & (1 << (r * 4 + c));
            }
          }

          REP(color, 3){
            int nmask = nmaskc[color] | nmaskn;
            if(dist[nmask] > cost + 1){
              dist[nmask] = cost + 1;
              que.push(P(cost + 1, nmask));
            }
          }
        }
      }
    }
  }
  assert(false);
  return 0;
}

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

using namespace std;

int main(){
  int h,w; cin >> h >> w;
  long long a; 
  unsigned long long ans=0;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      cin >> a;
      ans+=a*(i+1)*(j+1)*(h-i)*(w-j); //左上のどれかが右下のどれかを選ぶ個数
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
using namespace std;

using int64 = long long;
using int128 = __int128;

#define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++)

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

  int N, K;
  cin >> N >> K;

  vector<int64> t(N), d(N);
  repeat (i, N) {
    cin >> t[i] >> d[i];
    t[i]--;
  }
  vector<int> indices(N);
  iota(begin(indices), end(indices), 0);
  sort(begin(indices), end(indices), [&](int i, int j) { return d[i] > d[j]; });

  using P = pair<int, int>; // (美味しさ, 種類)
  
  int64 x = 0, sum_d = 0;
  vector<int> counter(N, 0);
  priority_queue<P, vector<P>, greater<P>> pque;

  repeat (i, K) {
    int idx = indices[i];
    sum_d += d[idx];
    counter[t[idx]]++;

    if (counter[t[idx]] == 1) x++;
    else pque.push(P(d[idx], t[idx]));
  }

  int64 ans = sum_d + x * x;

  for (int i = K; i < N; i++) {
    int idx = indices[i];

    if (!pque.empty() and counter[t[idx]] == 0) {
      sum_d -= pque.top().first;  pque.pop();
      sum_d += d[idx];
      x++;
      counter[t[idx]]++;
    }
    ans = max(ans, sum_d + x * x);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3196
#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>;
using G = vector<vector<int>>;
    
int main(){
    int a, b;
    cin >> a >> b;
    int ans;
    ans = a * b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
/*
	直接想贪心
	序列是从祖先到子树里扩展的
	把一个点弄开后，肯定先把所有的 0 给弄进序列里
	这启发我们将点合在一起，即选择了父亲一定再选儿子
	考虑两端序列那个放在前面更优
	发现结果是只要让 cnt_1 / cnt_0 尽量小就行 
*/
#include <bits/stdc++.h>
#define N 200005

using namespace std;

int n;
int fa[N], x[N], y[N]; // x : cnt_1, y : cnt_0
int val[N], o;

namespace UFS {
	int fa[N];
	inline void init() { for(int i = 1; i <= n; ++i) fa[i] = i; }
	inline int find(int u) { return fa[u] == u ? u : fa[u] = find(fa[u]); }
}

struct cmpNode {
	bool operator () (const int &lhs, const int &rhs) {
		if(lhs == 1 || rhs == 1) {
			return lhs > rhs;
		} else if(1LL * x[lhs] * y[rhs] == 1LL * x[rhs] * y[lhs]) {
			return lhs < rhs;
		} else {
			return 1LL * x[lhs] * y[rhs] < 1LL * x[rhs] * y[lhs];
		}
	}
};
set<int, cmpNode> se;

int main() {
	scanf("%d", &n);
	for(int i = 2; i <= n; ++i)
		scanf("%d", &fa[i]);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &val[i]);
	
	UFS::init();
	for(int i = 1; i <= n; ++i) {
		if(val[i]) {
			++x[i];
		} else {
			++y[i];
		}
		se.insert(i);
	}
	
	long long ans = 0;
	set<int, cmpNode>::iterator it;
	for(int i = n; i > 1; --i) {
		it = se.begin();
		int u = *it, v = UFS::find(fa[u]);
		UFS::fa[u] = v;
		se.erase(u), se.erase(v);
		ans += 1LL * y[u] * x[v];
		x[v] += x[u], y[v] += y[u];
		se.insert(v);
	}
	
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 15616
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	
	static int totalVertex;
	static ArrayList<ArrayList<Integer>> adjList;
	static int[] distances;
	static ArrayList<Integer> undiscovered;
	
	public static void main(String[] args) {
		
		getInput();
		
		distances = new int[totalVertex];
		undiscovered = new ArrayList<Integer>();
		
		for(int i = 0; i < totalVertex; i++) {
			distances[i] = -1;
			undiscovered.add(i);
		}
		
		distances[0] = 0;
		
		
		
		traverseGraph();
		
		for(int i = 0; i < totalVertex; i++) {
			System.out.println((i + 1) + " " + distances[i]);
		}
		
	}
	
	public static void traverseGraph() {
		
		Queue<Integer> queue = new LinkedList<Integer>();
		
		undiscovered.remove(undiscovered.indexOf(0));
		queue.add(0);
		
		while(queue.isEmpty() == false) {
			
			int currentNode = (int) queue.remove();
			
			for(int i = 0; i < adjList.get(currentNode).size(); i++) {
				
				int nextNode = adjList.get(currentNode).get(i);
				if(undiscovered.contains(nextNode)) {
					
					undiscovered.remove(undiscovered.indexOf(nextNode));
					
					distances[nextNode] = distances[currentNode] + 1;
					
					queue.add(nextNode);
					
				}
				
			}
			
		}
		
	}
	
	public static void getInput() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new ArrayList<ArrayList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			ArrayList<Integer> tmp = new ArrayList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}

}


Measured memory_bytes: 28776
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

constexpr int MAX_N = 100'000;
constexpr int MAX_VAL = 100'000;

struct Card {
    char soot;
    int key;
    void print() {
        cout << this->soot << " " << this->key << endl;
    }
};

int partition(Card* A, const int& p, const int& r) {
    int x = A[r].key;
    int i = p;
    for (int j = p; j < r; j++) {
        if (A[j].key <= x) {
            swap(A[i], A[j]);
            i++;
        }
    }
    swap(A[i], A[r]);
    return i;
}

void quickSort(Card* A, const int& p, const int& r) {
    if (p >= r) { return; }
    int q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
}

int merge(Card* A, const int& left, const int& mid, const int& right) {
    const int n1 = mid - left;
    const int n2 = right - mid;

    auto L = new Card[n1+1];
    auto R = new Card[n2+1];
    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }

    L[n1].key = MAX_VAL;
    R[n2].key = MAX_VAL;

    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i].key <= R[j].key) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
    }
    delete[] L;
    delete[] R;
    return right - left;
}

int mergeSort(Card* A, const int& left, const int& right) {
    int count = 0;
    if (left + 1 < right) {
        const int mid = (left + right) / 2;
        count += mergeSort(A, left, mid);
        count += mergeSort(A, mid, right);
        return count + merge(A, left, mid, right);
    }
    return 0;
}


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

    Card A[MAX_N];
    Card B[MAX_N];

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i].soot >> A[i].key;
        B[i] = A[i];
    }

    quickSort(A, 0, n-1);
    mergeSort(B, 0, n);

    bool isStable = true;
    for (int i = 0; i < n; i++) {
        if (A[i].soot != B[i].soot) {
            isStable = false;
            break;
        }
    }
    if (isStable) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    for (int i = 0; i < n; i++) {
        A[i].print();
    }

    return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>
int main(void)
{
    int a,b,sum=0,count=0;
    while(scanf("%d%d",&a,&b) != EOF){
        sum=a+b;
        for(;;){
            sum=sum/10;
            count++;
            if(sum==0)
            break;
        }
        printf("%d\n",count);
        count=0;
    }

    return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

int vec[100001];

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

	for (int i = 1; i <= n; i++)
		scanf("%d", &vec[i]);

	// 우선순위는 둘다 같을 경우.
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (i != n && vec[i] == i && vec[i + 1] == i + 1) {
			swap(vec[i], vec[i + 1]);
			cnt++;
		}
		else if (vec[i] == i) {
			if (i == 1) {
				swap(vec[i], vec[i + 1]);
				cnt++;
			}
			else {
				swap(vec[i], vec[i - 1]);
				cnt++;
			}
		}
	}

	printf("%d", cnt);
}

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

#define PI 3.14159265358979323846

// #define ll long long int
#define ff first
#define ss second
#define int long long int
#define pb push_back

#define N 10000010
#define MOD 1000000007

int bexp(int a, int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    string s;
    cin >> s;

    int cnt = 0, ans = 0;
    int i = 0;
    while (i < 3)
    {
        cnt = 0;
        while (s[i++] == 'R') cnt++;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


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

const int N = 200000;

int n;
char s[N + 5];

int main() {
  scanf("%s", s);
  n = strlen(s);

  vector<int> a; 
  int j = 0;
  for (int i = 0; i < n; ++i) {
    if (i && s[i] != s[i-1]) a.push_back(j), j = 1; else ++ j;
  }
  a.push_back(j);

  int ans = 0;
  while (!a.empty()) {
    int x = a.back(); a.pop_back();
    if (x % 3 == 0) ans += x / 3 * 2;
    if (x % 3 == 1) ans += x / 3 * 2 + 1;
    if (x % 3 == 2) {
      if (!a.empty()) a.back() --, ans += x / 3 * 2 + 2;
      else ans += x / 3 * 2 + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1528
N = int(input())
S = input()
diff = [0] * (N + 1)
for i in range(N):
    if S[i] == "(":
        diff[i + 1] = diff[i] + 1
    else:
        diff[i + 1] = diff[i] - 1
min_diff = min(diff)
print("(" * -min_diff + S + ")" * (diff[N] - min_diff))


Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define out() fflush(stdout)
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define pii pair < int, int >
typedef vector<int> vi;
typedef   long long ll;
const int mod =1e9+7;

void solve(){
	string s;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2];
}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> A(N), B(N);
    rep (i, N) {
        cin >> A[i] >> B[i];
    }

    vector<Pll> p;
    rep (i, N) {
        p.push_back(make_pair(B[i], A[i]));
    }

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

    ll ans = 0;
    rep (i, N) {
        ans += p[i].second;
        if (p[i].first < ans) {
            No;
            return 0;
        } 
    }

    Yes;
    return 0;
}

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

int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<int>> table(h, vector<int>(w));
    rep(i, h)
    {
        string s;
        cin >> s;
        rep(j, w) table[i][j] = s[j] - '0';
    }

    int ans = 0;
    rep(ri, h) rep(rj, w)
    {
        int sum = 0;
        int rate = 1;
        auto tmp_table = table;
        tmp_table[ri][rj] = -1;
        {
            int j = rj;
            int s = ri;
            for (int i = ri; i >= 0; --i)
                if (tmp_table[i][j] != -1)
                    swap(tmp_table[i][j], tmp_table[s][j]), --s;
        }
        while (1)
        {
            int prev = sum;
            rep(i, h) rep(j, w - k + 1)
            {
                int tmp = tmp_table[i][j];
                if (tmp == -1)
                    continue;
                int con = 1;
                for (int l = j + 1; l < w; ++l)
                    if (tmp_table[i][l] == tmp)
                        ++con;
                    else
                        break;
                if (con >= k)
                {
                    rep(l, con) tmp_table[i][j + l] = -1;
                    sum += tmp * con * rate;
                }
            }
            if (sum == prev)
                break;
            rep(j, w)
            {
                int s = h - 1;
                for (int i = h - 1; i >= 0; --i)
                    if (tmp_table[i][j] != -1)
                        swap(tmp_table[i][j], tmp_table[s][j]), --s;
            }
            rate <<= 1;
        }

        ans = max(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  vl a(5, 0);
  rep(i,6){
    ll n;
    cin >> n;
    a[n]++;
  }
  bool ans = true;
  for (ll i = 1; i < 5; i++){
    if(a[i]>2){
      ans = false;
    }
  }
  if(ans){
    print("YES");
  }
  else{
    print("NO");
  }
}

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

using namespace std;
char s[5050];
int k;

int main() {
    scanf("%s%d", s, &k);
    int n = strlen(s);
    map<long long, string> pq;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 5; j++)
            if (i + j < n) {
                long long pri = 0;
                char *pt = (char *) &pri;
                for (int l = 0; l <= j; l++)
                    pt[5 - l] = s[i + l];
                pq[-pri] = string(s + i, s + i + j + 1);
                if (pq.size() > k)pq.erase(pq.begin());
            }
    //for (const auto &x:pq)cout << x.second << endl;
    puts(pq.begin()->second.c_str());
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
int main(){
	int n,i,j;
	long long sum=0;
	scanf("%d",&n);
	for(i=0;i<=n;i++)
		scanf("%lld",&a[i]);
	for(i=0;i<n;i++)
		scanf("%lld",&b[i]);
	for(i=0;i<n;i++){
		int k=a[i]+a[i+1]-b[i];
		if(k>=0){
			sum+=b[i];
			if(a[i]<b[i])a[i+1]=k;
		}
		if(k<0){
			sum=sum+a[i]+a[i+1];
			a[i+1]=0;
		}
	}
	printf("%lld\n",sum);
		
	
	
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 200000001;
int m[101][101];
int p[101];

int main(void)
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> p[i] >> p[i + 1];
	for (int i = 1; i <= n; i++)
		m[i][i] = 0;
	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = MAX;
			for (int k = i; k <= j - 1; k++)
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
		}
	}
	cout << m[1][n] << endl;
	return 0;
}


Measured memory_bytes: 3136