akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
	return ans;
}
int yakusuunowa(int n) {
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (n%i == 0)ans += i;
	}
	return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int ketanowa(int n) {
	int cnt = 0, sum = 0;
	for (int i = 10; i <= n * 10; i *= 10) {
		if (i == 10)cnt += n % i;
		else sum += (n%i - n % (i / 10)) / (i / 10);
	}
	return cnt + sum;
}
signed main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] == 'A'&&s[i+1] == 'C') {
			puts("Yes");
			getchar(); getchar(); return 0;
		}
	}
	puts("No");
	ll
}

Measured memory_bytes: 256
/*author: hyperion_1724
  date: 
*/

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

	READV(A);
	READV(B);
	if ((A+B)%2==1)
	{
		cout<<"IMPOSSIBLE"<<endl;
	}
	else
	{
		cout<<(A+B)/2<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
N, M = list(map(int,input().rstrip().split()))
k = []
s = []
for i in range(M):
    stdin = list(map(int,input().rstrip().split()))
    k.append(stdin[0])
    s.append(stdin[1:])
p = list(map(int,input().rstrip().split()))
ans = 0
for bit in range(2**N):
    od = 0
    for j in range(M):
        odd = 0
        for sw in s[j]:
            mask = 1 << (sw-1)
            if bit&mask: # 右からi番目にビットが立っているかどうか判定
                odd += 1
        if p[j] != odd%2:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
#define PRINT(s) cout << s << endl;
#define FOR(i, n) for (int i = 0; i < (n); i++)

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int aokiTurn = a / d;
    if (a % d != 0) {
        aokiTurn += 1;
    }
    int takahashiTurn = c / b;
    if (c % b != 0) {
        takahashiTurn += 1;
    }

    if (takahashiTurn > aokiTurn) {
        PRINT("No");
    } else {
        PRINT("Yes");
    }
    return 0;
}


Measured memory_bytes: 3600
// Library
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>

using namespace std;

// TYPEDEFS
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

// CONSTANTS
#define SZA 0
#define SZB 0

// MACRO
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
#define ABS(X) (((X) > 0)? (X) : -(X))
#define YN(X) ((X)? "YES" : "NO")
#define SWAP(T, X, Y) {T t; t = X; X = Y; Y = t;}

#define F first
#define S second
#define PB push_back
#define MP make_pair


// Global Tables

//ull gPreProcess[SZA][SZB];

// Functions

void Print2DVector(vector<vector<int>>& v)
{
    ull i, j; 
    for(i = 0; i < v.size(); i++)
    {
        for(j = 0; j < v[i].size(); j++)
        {
            cout << v[i][j];
            if(j == v[i].size()-1)
            {
                cout << endl;
            }
            else
            {
                cout << " ";
            }
        }
    }
}

void PrintVector(vi& v)
{
    ull i;
    for(i = 0; i < v.size(); i++)
    {
        cout << v[i];
        if(i == v.size()-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

void PrintArr(int* a, ull N)
{
    ull i;
    for(i = 0; i < N; i++)
    {
        cout << a[i];
        if(i == N-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

void PreProcessTables()
{
    ull i, j;
    for(i = 0; i < SZA; i++)
    {
        for(j = 0; j < SZB; j++)
        {
            break;
        }
        break;
    }
}

void TC(int t)
{
    ull N, n, i;
    string a;
    cin >> N;
    i = 1;
    unordered_map<string, int> m;
    for(n = 0; n < N; n++)
    {
        cin >> a;
        if(m[a] == 0)
        {
            m[a] = i;
            i++;
        }
    }
    cout << i-1 << endl;
}

// Main

int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    PreProcessTables();

    int T = 1, t;
    for(t = 1; t <= T; t++)
    {
        TC(t);
    }
    return 0;
}


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

ll solve() {
  ll N, A, B;
  cin >> N >> A >> B;
  if(A > B) return 0;
  if(N == 1) {
    if(A == B) return 1;
    else return 0;
  }
  if(N == 2) return 1;
  N -= 2;
  ll res = (B - A) * N + 1;
  return res;
}

int main() {
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.algorithm, std.conv, std.array, std.math, std.container, std.range;

void main(){
  auto hw = readln.split.map!(to!int);
  string[] arr;
  foreach(i;0..hw[0]){
    auto line = readln.chomp;
    if(line.any!"a=='#'")arr~=line;
  }

  string[] sw;
  foreach(col;iota(0, hw[1]).map!(i=>arr.transversal(i)))
  {
    if(col.any!"a=='#'")sw~=col.array;
  }

  foreach(line;iota(0, arr.length).map!(i=>sw.transversal(i)))line.writeln;
}

Measured memory_bytes: 380
box = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(box[int(input()) - 1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[100005];
int main(){
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a,a+n);
	cout << a[n/2]-a[n/2-1];
    return 0;
}

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

t_p = 0
h_p = 0

for i in range(n):
    t, h = input().split()
    if t>h:
        t_p += 3
    elif t<h:
        h_p += 3
    else:
        t_p += 1
        h_p += 1

print(t_p, h_p)
    


Measured memory_bytes: 5596
N = int(input())
dict = {
    "M":0,
    "A":0,
    "R":0,
    "C":0,
    "H":0
}
S = []
for _ in range(N):
    S = input()
    if S[0] == "M":
        dict[S[0]] += 1
    elif S[0] == "A":
        dict[S[0]] += 1
    elif S[0] == "R":
        dict[S[0]] += 1
    elif S[0] == "C":
        dict[S[0]] += 1
    elif S[0] == "H":
        dict[S[0]] += 1

ans = 0
ans += dict["M"] * dict["A"] * dict["R"]
ans += dict["M"] * dict["A"] * dict["C"]
ans += dict["M"] * dict["A"] * dict["H"]
ans += dict["M"] * dict["R"] * dict["C"]
ans += dict["M"] * dict["R"] * dict["H"]
ans += dict["M"] * dict["C"] * dict["H"]
ans += dict["A"] * dict["R"] * dict["C"]
ans += dict["A"] * dict["R"] * dict["H"]
ans += dict["A"] * dict["C"] * dict["H"]
ans += dict["R"] * dict["C"] * dict["H"]
print(ans)

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

int main() {
  int N=0,K,result=0;
  cin >> N >> K;
  int h[N];
  for(int i=0;i<N;i++){
    cin >> h[i];
    if(h[i] >= K){
      result++;
    }
  }

  cout << result; 
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>

using Graph = std::vector<std::deque<long long>>;

int main() {
    long long n, m, ta, tb;
    std::cin >> n >> m;
    Graph g(n);
    std::deque<long long> path;
    for (auto i = 0ll; i < m; i++) {
        std::cin >> ta >> tb;
        ta--; tb--;
        g[ta].push_back(tb);
        g[tb].push_back(ta);
    }
    path.push_back(ta);
    path.push_back(tb);
    std::vector<bool> done(n);
    done[ta] = true;
    done[tb] = true;

    while (true) {
        ta = path.front();
        tb = path.back();
        for (auto el : g[ta]) {
            if (!done[el]) {
                path.push_front(el);
                done[el] = true;
                break;
            }
        }
        if (ta != path.front()) continue;
        for (auto el : g[tb]) {
            if (!done[el]) {
                path.push_back(el);
                done[el] = true;
                break;
            }
        }
        if (tb != path.back()) continue;
        break;
    }

    std::cout << path.size() << std::endl;
    for (auto i = 0ll; i < path.size() - 1; i++) {
        std::cout << path[i] + 1 << " ";
    }
    std::cout << path[path.size() - 1] + 1 << std::endl;
    
    return 0;
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

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

    int a[n+1];
    rep(i,1,n+1){
        cin >> a[i];
    }
    rep(i,1,n+1){
        if(i == a[a[i]]) c++;
    }
    pout(c/2);    
    return 0;
}

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

using namespace std;
using ll = long long;

const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e9 + 7;
const ll INF = 1e18 + 5;

main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);
    int x;
    cin >> x;
    if (x >= 400 && x <= 599) cout << 8;
    if (x >= 600 && x <= 799) cout << 7;
    if (x >= 800 && x <= 999) cout << 6;
    if (x >= 1000 && x <= 1199) cout << 5;
    if (x >= 1200 && x <= 1399) cout << 4;
    if (x >= 1400 && x <= 1599) cout << 3;
    if (x >= 1600 && x <= 1799) cout << 2;
    if (x >= 1800 && x <= 1999) cout << 1;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  int L=S.size();
  vector<int> M(L+1);
  M.at(L)=0;
  M.at(L-1)=(S.at(L-1)-'0')%2019;
  int Mod=1;
  for(int i=0; i<L-1; i++){
    Mod=(Mod*10)%2019;
    M.at(L-2-i)=(S.at(L-2-i)-'0')*Mod+M.at(L-1-i);
    M.at(L-2-i)%=2019;
  }
  int Ans=0;
  vector<int> No(2019);
  for(int i=0; i<=L; i++){
    No.at(M.at(i))++;
  }
  for(int i=0; i<2019; i++){
    Ans+=No.at(i)*(No.at(i)-1)/2;
  }
  cout << Ans << endl;
}

Measured memory_bytes: 4388
// Peace Of SHIT
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + 5;
int n, si[maxn];
int sum = 0;
vector<int> e[maxn];
pii d[maxn];

void impossible() {
	cout << -1;
	exit(0);
}

void dfs(int u, int x) {
	sum += x;
	for(int i = 0; i < e[u].size(); i++) {
		dfs(e[u][i], x + 1);
	}
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) {
		int a;
		cin >> a;
		d[i] = {a, i};
	}
	sort(d, d + n);
	reverse(d, d + n);
	
	vector <pii> k (d, d + n);
	
	for(int q = 0; q < n - 1; q++) {
		int leaf = d[q].second;
		int parD = d[q].first - (n - (2 * (si[leaf] + 1)));
		auto it = lower_bound(k.rbegin(), k.rend(), pii(parD, 0));
//		cout << "PAR : " <<it->first << " : " << parD << '\n';
		if(it -> first != parD) {
//			cerr << "AVALI\n";
			impossible();
		}
		int par = it -> second;
		si[par] += si[leaf] + 1;
		if((si[leaf] + 1) * 2 > n) {
//			cout << "DOVOMI\n";
			impossible();
		}
		//SEVOMI HAM MISHE D[I] ROOT OK E ?
		e[par].push_back(leaf);
	}
	int D = d[n - 1].second;
	dfs(D, 0);
	if(sum != d[n - 1].first)
		impossible();
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < e[i].size(); j++)
			cout << i + 1 << " " << e[i][j] + 1 <<'\n';
	}
	return 0;
}

Measured memory_bytes: 13184
#include "stdio.h"

int length;
char letter[100002];
long long int num;


int main() {
	scanf("%s", letter);
	scanf("%lld", &num);
	for (int i = 0; i < 100001; i++) {
		if (letter[i] == 0) {
			length = i;
			break;
		}
	}
	for (int i = 0; i < length; i++) {
		if (letter[i] == 'a') {

		}
		else if ('z' - letter[i] + 1 <= num) {
			num -= 'z' - letter[i] + 1;
			letter[i] = 'a';
		}
	}
	num %= 26;
	letter[length - 1] += num;
	if (letter[length - 1] > 'z')letter[length - 1] -= 26;
	printf("%s\n", letter);
	return 0;
}

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

int n, m;
vector<string> a, b;

bool solve();

int main() {
  cin >> n >> m;
  a.resize(n);
  for (auto& p : a) cin >> p;
  b.resize(m);
  for (auto& p : b) cin >> p;
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}

bool solve() {
  for (int i = 0; i + m <= n; ++i)
    for (int j = 0; j + m <= n; ++j) {
      bool ch = 1;
      for (int k = 0; k < m; ++k)
        if (a[i + k].substr(j, m) != b[k]) ch = 0;
      if (ch) return 1;
    }
  return 0;
}

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



int main(){
    int n;
    int w[100];
    cin>>n;

    for (int i = 0; i < n; i++)
    {
        cin>>w[i];
    }
    
    int sum=0;
    for (int i = 0; i < n; i++)
    {
        sum +=w[i];
    }
    
    int ans= 10001;
    int temp = 0;
    for (int i = 0; i < n; i++)
    {
        temp+=w[i];
        if(ans>abs(sum-temp*2)){
            ans = abs(sum - temp*2);
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cfloat>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <iomanip>

using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define req(j, n) for (ll j = 1; j < (n+1); j++)
// #define rer(k, n) for (ll k = 1; k < (n+1); k++)


// 尺取り法
int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n);
    vector<int> b(m);
    ll t = 0;
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, m) {
        cin >> b[i];
    }
    rep(i,m) {
        // m冊全て読んだことにする
        t += b[i];
    }
    int j = m;
    int ans = 0;
    rep(i,n+1) {
        while(j > 0 && t > k) {
            --j;
            t -= b[j];
        }
        if (t > k) {
            break;
        }
        ans = max(ans, i+j);
        if (i == n) {
            break;
        }
        t += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4840
import heapq

n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[[i,0] for i in range(1,m+2)]
arr.extend(arr2)
arr=sorted(arr,reverse=True,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
tmp=arr[0][0]
q=[]
ans=0
pos=0
while 1:
  a,b=arr[pos]
  if a>m:
    break
  if a==arr[pos+1][0]:
    heapq.heappush(q,-b)
  else:
    heapq.heappush(q,-b)
    ans-=heapq.heappop(q)
  pos+=1
print(ans)

Measured memory_bytes: 44996
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n)cin >> h[i];
    
    ll cnt = 0;
    ll ans = 0;
    rep(i, n-1){
        if(h[i] >= h[i+1])cnt++;
        else cnt = 0;
        ans = max(cnt, ans);
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);	
		int x  = stdin.nextInt();
		int t= stdin.nextInt();
		if(x-t<0) {
			System.out.println(0);
		}else {
			System.out.println(x-t);
		}

		// TODO 自動生成されたメソッド・スタブ

	}

}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	string S;
	int K;
	cin >> S >> K;

	set<string> SS;
	for (int i = 0; i < S.size(); i++) { // i : 部分文字列の先頭
		for (int j = 1; i + j - 1 < S.size() && j <= K; j++) { // j : 部分文字列の長さ
															   // S[i]～S[i+j-1]
			string temp;
			for (int k = 0; k < j; k++) temp.push_back(S[i+k]);
			SS.insert(temp);
		}
	}
	
	set<string>::iterator it = SS.begin();
	for (int i = 0; i < K - 1; i++) it++;
	cout << *it << endl;

	return 0;
}

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

int main(){
    int K, S;
    cin >> K >> S;
    int z;
    int ans = 0;
    for (int x=0; x<=K; x++){
        for (int y=0; y<=K; y++){
            z = S-x-y;
            if (0 <= z && z <= K){
                ans += 1;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    vector<bool> n(N, true);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        if (H[a - 1] > H[b - 1]) {
            n[b - 1] = false;
        } else if (H[a - 1] < H[b - 1]) {
            n[a - 1] = false;
        } else {
            n[a - 1] = false;
            n[b - 1] = false;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (n[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3980
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    string n;
    cin>>n;
    int sz=n.size();
    int dp[sz+1][2];
    fill(dp[0],dp[sz+1],inf);
    dp[0][0]=0;
    dp[0][1]=1;
    rep(i,sz){
        int d=n[i]-'0';
        dp[i+1][0]=min(dp[i][0]+d,dp[i][1]+10-d);
        if(d!=9)dp[i+1][1]=dp[i][0]+d+1;
        dp[i+1][1]=min(dp[i+1][1],dp[i][1]+9-d);
    }
    cout<<dp[sz][0]<<endl;
}


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

int main() {
  string s;
  cin >> s;
  string a = "";
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'B') {
      if (a != "") a.pop_back();
    } else {
      a += s[i];
    }
  }
  cout << a;
  
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>

using namespace std;

int main() {
  int n, x, d;
  cin >> n >> d >> x;
  d--;
  int a = 0;
  for (int i=0; i<n; i++) {
    cin >> a;
    x += d/a + 1;
  }
  cout << x << endl;
  return 0;
}


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

vector<pair<long long,long long> >prime_factorize(long long n){
    vector<pair<long long,long long> >res;
    for(long long p=2;p*p<=n;p++){
        if(n%p!=0)continue;
        int num=0;
        while(n%p==0){++num;n/=p;}
        res.push_back(make_pair(p,num));
    }
    if(n!=1)res.push_back(make_pair(n,1));
    return res;
}

int N;
map<long long,int>sisuu;
long long rec(map<long long,int>::iterator p,long long mul){
    if(p==sisuu.end()){
        if(mul==1)return 1;
        else return 0;
    }
    long long res=0;
    for(int i=0;i<p->second+1;i++){
        if(mul%(i+1)!=0)continue;
        res+=rec(++p,mul/(i+1));
        --p;
    }
    return res;
}

int main(){
    cin>>N;
    for(int i=2;i<=N;i++){
        auto ps=prime_factorize(i);
        for(auto it:ps)sisuu[it.first]+=it.second;
    }
    cout<<rec(sisuu.begin(),75)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

const int maxm = 1e5 + 5;

int n, x, m, used[maxm];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x >> m;
    deque<int> cycle, tail;
    cycle.push_back(x);
    for(int i = 0; i < m; i++)
    {
        int cur = cycle.back();
        cur *= cur;
        cur %= m;
        if(used[cur])   // At max m distinct remainders, so will occur before that
        {
            while(cycle.front() != cur)
            {
                tail.push_back(cycle.front());
                cycle.pop_front();
            }
            break;
        }
        cycle.push_back(cur);
        used[cur] = 1;
    }
    int ans = 0;
    for(int i = 0; i < tail.size() && n > 0; i++)
    {
        ans += tail[i];
        n--;
    }
    int times = n / cycle.size(), extra = n % cycle.size();
    for(int i = 0; i < cycle.size(); i++)
    {
        ans += cycle[i] * times;
        if(i < extra)
            ans += cycle[i];
    }
    cout << ans << "\n";
    return 0;
}

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

int main(){
  int N,L;
  cin >> N >> L;
  string A[110];
  for (int i=0;i<N;i++)cin >> A[i];
  sort(A,A+N);
  for (int j=0;j<N;j++){
    cout << A[j];
  }
  cout << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n,c; cin >> n >> c;
    vector<vector<int> > d(c, vector<int>(c, 0));
    vector<vector<int> > oc(n, vector<int>(n, 0));
    vector<vector<int> > cost(3, vector<int>(c, 0));
    for(int i = 0; i < c; i++){
        for(int j = 0; j < c; j++){
            cin >> d[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> oc[i][j];
            oc[i][j]--;
        }
    }
    for(int i = 0; i < c; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                cost[(j+k)%3][i] += d[oc[j][k]][i];
            }
        }
    }

    int ans = 1<<30;
    int col[3];
    for(col[0] = 0; col[0] < c; col[0]++){
        for(col[1] = 0; col[1] < c; col[1]++){
            if(col[0] == col[1]) continue;
            for(col[2] = 0; col[2] < c; col[2]++){
                if(col[1] == col[2] || col[0] == col[2]) continue;
                int tmp = 0;
                for(int i = 0; i < 3; i++) tmp += cost[i][col[i]];
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{
	int R0, W0, C, R;
	while (cin >> R0 >> W0 >> C >> R, R0 || W0 || C || R) {
		if((W0*C - R0 + R - 1) / R > 0)
			cout << (W0*C - R0 + R - 1) / R << endl;
		else
			cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t; using i64 = int64_t; using f64 = double_t; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define stepup(a, b, s, i) for (i32 i = (a); i <= (b); i+=(s))
#define stepdown(a, b, s, i) for (i32 i = (a); i >= (b); i-=(s))
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define foreach(xs, x) for (auto &x : (xs))
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define maximum(xs) (*max_element(all(xs)))
#define minimum(xs) (*min_element(all(xs)))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

i64 n, a[100000], k, d[100000];

bool solve()
{
    cin >> n;
    i64 acc = 0; k = 0;
    times(n, i) {
        cin >> a[i];
        acc += a[i];
        while (acc >= n*(n+1)/2) {
            acc -= n*(n+1)/2;
            k++;
        }
    }
    if (acc != 0) return false;
    times(n-1, i) {
        d[i] = a[i+1] - a[i];
    }
    d[n-1] = a[0] - a[n-1];
    i64 cnt = 0;
    times(n, i) {
        d[i] -= k;
        if (d[i] > 0) return false;
        if (-d[i] % n != 0) return false;
        cnt += -d[i] / n;
    }
    return cnt == k;
}

i32 main()
{
    cout << (solve() ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<string.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<int>> mp(h, vector<int>(w));
	rep(i, h)rep(j, w) {
		char c;
		cin >> c;
		if (c == '.') mp[i][j] = 0;
		else mp[i][j] = 1;
	}
	int ans = 0;
	rep(biti, 1 << h) {
		rep(bitj, 1 << w) {
			vector<vector<int>> mpi = mp;
			int cnti = 0;
			rep(i, h) {
				if (1 & (biti >> i)) {
					rep(ww, w) mpi[i][ww] = 100;
				}
			}
			rep(j, w) {
				if (1 & (bitj >> j)) {
					rep(ii, h) mpi[ii][j] = 100;
				}
			}
			rep(i, h)rep(j, w) if (mpi[i][j] == 1) cnti++;
			if (cnti == k) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (true) {
            String m = scan.next();
            if (m.equals("-")) break;
            int n = scan.nextInt();
            for (int i = 0; i < n; i++) {
                int h = scan.nextInt();
                m = m.substring(h) + m.substring(0, h);
            }
            System.out.println(m);
        }
    }
}

Measured memory_bytes: 26304
#include <stdio.h>
#include <stdlib.h>

#define absmin(a,b) (((a) > 0) && 
int main(void) {
    int N;
    int a[100];
    int i,cnt;
    char str[512];
    char *p;

    int rd=0,ru=0,minus=0 ;
    int rdchk=0,ruchk=0,minux=0;
    
    fgets(str, 512, stdin);
    N = atoi(str);
    fgets(str, 512, stdin);
    p = str;
    for(i=0,cnt=0;i<512;i++){
        if(str[i] == ' '){
            str[i] = '\0';
            a[cnt++] = atoi(p);
            p = &str[i+1];
        }
    }
    a[cnt] = atoi(p);

    for(cnt=0;cnt<N;cnt++){
        rd +=a[cnt];
    }

    rd = rd / N;
    ru = rd + 1;
    minus = rd - 1;

    for(cnt=0;cnt<N;cnt++){
        rdchk += (a[cnt] - rd) * (a[cnt] - rd);
        ruchk += (a[cnt] - ru) * (a[cnt] - ru);
        minux += (a[cnt] - minus) * (a[cnt]-minus);
    }
    
    if(rdchk > ruchk) {
        if(ruchk > minux) {
        printf("%d\n", minux);
        } else {
        printf("%d\n", ruchk);
        }
    } else {
        if(rdchk > minux) {
        printf("%d\n", minux);
        } else {
        printf("%d\n", rdchk);
        }
    }

    return 0;
    
}


Measured memory_bytes: 128
#include <stdio.h>

int main(){
	int ax, ay;
	char f[12][12];
	int flag = 0;
	int x,y,i,j;

	for(y=0 ; y<12 ; y++){
		for(x=0 ; x<12 ; x++){
			f[y][x] = 0;
		}
	}

	while( 1 ){
		for(i=0 ; i<8 ; i++) {
			if( scanf("%s", f[i]) == EOF ){
				flag = 1;
				break;
			}
		}
		if(flag) break;

		for(i=0 ; i<64 ; i++){
			if(f[i/8][i%8]=='1'){
				ax = i%8;
				ay = i/8;
				break;
			}
		}
		if( f[ay+1][ax]=='1' && f[ay][ax+1]=='1' && f[ay+1][ax+1]=='1' ){
			printf("A\n");
		}else if( f[ay+1][ax]=='1' && f[ay+2][ax]=='1' && f[ay+3][ax]=='1' ){
			printf("B\n");
		}else if( f[ay][ax+1]=='1' && f[ay][ax+2]=='1' && f[ay][ax+3]=='1' ){
			printf("C\n");
		}else if( f[ay][ax+1]=='1' && f[ay+1][ax+1]=='1' && f[ay+1][ax+2]=='1' ){
			printf("E\n");
		}else if( f[ay+1][ax]=='1' && f[ay+1][ax+1]=='1' && f[ay+2][ax+1]=='1' ){
			printf("F\n");
		}else if( f[ay][ax+1]=='1' && f[ay+1][ax]=='1' && f[ay+1][ax-1]=='1' ){
			printf("G\n");
		}else if( f[ay+2][ax-1]=='1' && f[ay+1][ax]=='1' && f[ay+1][ax-1]=='1' ){
			printf("D\n");
		}
	}
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
#include <set>

typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


/*
 * 最大公約数計算
 */
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll R;
	cin >> R;
	
		cout << 2ll * M_PI * R << endl;

	

	return 0;

}


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

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int x = scan.nextInt();
        System.out.println(solve(x));
    }
    public static int solve(int x) {
        int upper = (int) Math.floor(Math.sqrt(x));
        int answer = 0;
        for (int i = 1; i <= upper; i++) {
            for (int j = 1; j <= 10; j++) {
                int target = (int) Math.pow(i, j);
                if (x < target) {
                    break;
                }
                if (target <= x && answer < target) {
                    answer = target;
                }
                if (i == 1) {
                    break;
                }
            }
        }
        return answer;
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
    unsigned long long x;
    cin >> x;
    vector<bool> candidates(2 * x, true);
    for (unsigned long long i = 2; i < sqrt(x); ++i) {
        for (unsigned long long j = i; j < 2 * x + 1; j += i) {
            candidates[j - 1] = false;
        }
    }
    for (unsigned long long i = x - 1; i < 2 * x; ++i) {
        if (candidates[i]) {
            cout << i + 1 << endl;
            break;
        }
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, k = MAP()
if(n==1):
    print(1)
else:
    print(ceil(log(n, k)))

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

int a,b,c,cnt,m;
int main() {
  cin >> a >> b >> c;
  if(a%2==b%2 && b%2==c%2 && c%2==a%2){
    cnt = 0;
  }else if(a%2==b%2){
    a++;b++;
    cnt = 1;
  }else if(b%2==c%2){
    b++;c++;
    cnt = 1;
  }else{
    c++;a++;
    cnt = 1;
  }
  m = max({a,b,c});
  for(int x:{a,b,c}){
    cnt += (m-x)/2;
  }
  cout << cnt << endl;
}

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

int main() {
	int n,p;
	cin >> n >> p;
	int c1=0;
	long long c0=1;
	for(int i=0;i<n;i++)
	{
		int b;
		cin >> b;
		if(b % 2 == 1)
		{
			c1++;
		}
		else
		{
			c0 *= 2;
		}
	}
	long long d=1;
	for(int i=0;i<=c1;i++)
	{
		if(p == 0)
		{
			if(c1 == 0)
			{
				d = 1;
				break;
			}
			if(i == 1)
			{
				d = 1;
			}
			if(i > 1)
			{
				d *= 2;
			}
		}
		else
		{
			if(c1 == 0)
			{
				d = 0;
				break;
			}
			if(i == 1)
			{
				d = 1;
			}
			if(i > 1)
			{
				d *= 2;
			}
		}	
	}
	long long kk = c0 * d;
    cout << kk << endl;
	return 0;
}


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

int main()
{
    int n, m;
    int t[105];
    int p[105], x[105];
    int sum = 0;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        sum += t[i];
    }

    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> p[i] >> x[i];

        p[i]--;
    }

    for (int i = 0; i < m; i++) {
        cout << sum - t[p[i]] + x[i] << endl;
    }
            
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; } return x; }
long lcm(long x, long y) { return (x / gcd(x, y) * y); }

//using pll = pair<long, long>;
//using W_graph = vector<vector<pll>>;

int main() {

	bool res = false;
	long N; cin >> N;

	for (int i = 1; i < 10; i++) for (int j = 1; j < 10; j++) if (N == i * j) res = true;

	if (res) cout << "Yes" << endl; else cout << "No" << endl;

}

Measured memory_bytes: 256
import math
MOD = 10 ** 9 + 7
n, a, b = map(int, input().split())

ans = pow(2, n, MOD) - 1
fa = math.factorial(a)
fb = math.factorial(b)
tmp = 1
for i in range(a):
    tmp = (tmp * (n-i)) % MOD
ans -= tmp*pow(fa, MOD-2, MOD)
for i in range(a, b):
    tmp = (tmp * (n-i))%MOD
ans -= tmp*pow(fb, MOD-2, MOD)
ans = ans % MOD
print(ans)


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

int main() {
	int A, B, cost;
	cin >> A >> B;

	if (A >= 13) {
		cost = B;
	} else {
		if (A >= 6) {
			cost = B / 2;
		} else {
			cost = 0;
		}
	}
	cout << cost << endl;
	return 0;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if((a % 2 == 1)&&(b % 2 == 1)) {
		cout << "Odd" << endl;
	} else {
		cout << "Even" << endl;
	}
	
	return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  int cnt = 0;
  while(n > 0) {
    if(n % 10 == 2) cnt++;
    n /= 10;
  }
  cout << cnt << endl;
}


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

struct UnionFind {
    vector<int> par;
    vector<int> siz;
    UnionFind(int N) : par(N),siz(N) {
        for (int i=0; i<N; i++) {
            par[i]=i,siz[i]=1;
        }
    }
    int root(int x) {
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x, int y) {
        int rx=root(x);
        int ry=root(y);
        if (rx==ry) return;
        par[rx]=ry;
        siz[ry]+=siz[rx];
    }
    bool same(int x,int y) {
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }
    int size (int x) {
        return siz[root(x)];
    }
};
int main() {
   int N,M;
   cin >> N >> M;
   UnionFind tree(N);
   for (int i=0; i<M; i++) {
       int a,b;
       cin >> a >> b;
       tree.unite(a-1,b-1);
   }
   int count=0;
   for (int i=1; i<N; i++) {
       if (!tree.same(0,i)) {
           count++;
           tree.unite(0,i);
       }
   }
   cout << count << endl;
}

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

int main()
{
  int a, b, c;
  set<int> s;
  cin >> a >> b >> c;
  int x = a % b;
  while (true)
  {
    if (x == c)
    {
      cout << "YES" << endl;
      break;
    }
    else if (s.count(x))
    {
      cout << "NO" << endl;
      break;
    }
    s.insert(x);
    x = (x + a) % b;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1LL<<60
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n;
ll a[4005];
ll sum[4005];
vector<ll> dp[4005];
vector<int> prevs[4005];
P val[4005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		sum[i+1]+=sum[i]+a[i];
		val[i]=P(sum[i+1],i);
	}
	sort(val,val+n);
	for(int i=0;i<=n;i++){
		dp[i]=vector<ll>(i+1,INF);
		prevs[i]=vector<int>(i+1,-1);
	}
	dp[0][0]=-INF;
	for(int i=0;i<n;i++){
		stack<int> st;
		int l=0;
		while(l<=i && dp[i][l]==INF){
			l++;
		}
		for(int j=i-1;j>=0;j--){
			dp[i][j]=min(dp[i][j],dp[i][j+1]);
		}
		for(int j=0;j<n;j++){
			int pos=val[j].second;
			if(pos<i)continue;
			ll vp=val[j].first-sum[i];
			while(l<=i && vp>dp[i][l]){
				if(dp[pos+1][l+1]>vp){
					//printf("%d %d-> %d %lld\n",i,l,pos,vp);
					dp[pos+1][l+1]=vp;
					prevs[pos+1][l+1]=i;
				}
				if(l+1<=i && vp>dp[i][l+1]){
					l++;
				}else{
					break;
				}
			}
		}
	}
	for(int i=n;i>=1;i--){
		if(dp[n][i]!=INF){
			printf("%d\n",i);
			vector<int> vec;
			int p=n;
			for(int j=i;j>1;j--){
				p=prevs[p][j];
				vec.push_back(p);
			}
			sort(vec.begin(),vec.end());
			for(int j=0;j<i-1;j++){
				printf("%d%c",vec[j],j+1==(i-1)?'\n':' ');
			}
			return 0;
		}
	}
	return 0;
} 


Measured memory_bytes: 128572
N, K = gets.split.map(&:to_i)
V = gets.split.map(&:to_i)

ans = 0
0.upto(K) do |l|
  0.upto(K) do |r|
    rest_k = K - l - r
    break if rest_k < 0 || l + r > N

    v = V[0, l] + V[-r, r]
    vol = v.inject(0, :+)
    vol -= v.reject { |g| g > 0 }.sort[0, rest_k].inject(0, :+)

    ans = vol if ans < vol
  end
end

puts ans

Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  vector<ll> a(7);
  rep(i, 7) cin >> a[i];

  ll k = 0;
  k += a[0] / 2 * 2;
  k += a[1];
  k += a[3] / 2 * 2;
  k += a[4] / 2 * 2;
  if (a[0] > 0 && a[3] > 0 && a[4] > 0) {
    ll resk = 3;
    a[0]--, a[3]--, a[4]--;
    resk += a[0] / 2 * 2;
    resk += a[1];
    resk += a[3] / 2 * 2;
    resk += a[4] / 2 * 2;
    chmax(k, resk);
  }
  cout << k << '\n';




  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
 
void solve(){
    
}
int main() {
    int k,t;
    int a[105];
    cin>>k>>t;
    for(int i=0;i<t;i++){
        cin>>a[i];
    }
    sort(a,a+t);
    int o=0;
    for(int i=0;i<t-1;i++){
        o+=a[i];
    }
    cout<<max(0,a[t-1]-1-o)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cur = sc.nextInt();
		int ans = 0;
		boolean used[] = new boolean[1000000 + 1];

		while(true) {
			ans += 1;
			if(used[cur]) {
				System.out.println(ans);
				return;
			} else {
				used[cur] = true;
				cur = cur % 2 == 0 ? cur / 2 : 3 * cur + 1;
			}
		}
	}
}

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

int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	
	int n, counter = 0;
	string s;
	cin >> n >> s;
	for(int i = 0; i < n - 2; ++i)
		if(s.substr(i, 3) == "ABC")
			counter++;
	cout << counter;	
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
      	int t = sc.nextInt();
        int a = sc.nextInt();
      	int b = sc.nextInt();
      	System.out.println(Math.min(t * a, b));
	}
}

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

using namespace std;

int main() {

    int N;
    cin >> N;
    int even = 0;
    int odd = 0;
    vector<int> A(N);
    int temp;
    for (int i = 0; i < N; ++i) {
        cin >> temp;
        if (temp % 2 == 0) { even++; }
        if (temp % 2 != 0) { odd++; }
    }

    while (1) {

        if (odd > 1) {
            if (odd % 2 == 0) {
                even += odd / 2;
                odd = 0;
            }
            if (odd % 2 == 1) {
                odd--;
                even += odd / 2;
                odd = 1;
            }
        }
        if (odd == 0 || odd == 1) { break; }
    }

    while (1) {
        if (even > 1) {
            if (even % 2 == 0) {
                even = even / 2;
            }
            if (even % 2 == 1) {
                int a = (even - 1) / 2;
                even -= a;
            }
        }
        if (even <= 1 ) {
            break;
        }
    }
    int ans = even + odd;
    if (ans == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    long A,B,C,D;
    cin >> A >> B >> C >> D;
    long c = (B/C) - ((A-1)/C);
    long d = (B/D) - ((A-1)/D);

    long memoc = C, memod =D;
    long memocd = C*D;
    if(C < D){
        long tmp = C;
        C = D; D = tmp;
    }

    long r = C % D;
    while(r!=0){
        C = D; D= r; r = C % D;
    }

    long long l = memocd / D;
    long ll = (B/l) - ((A-1)/l);

    long count = B - A + 1 - (c + d - ll);
    cout  << count << endl;
}


Measured memory_bytes: 256
use std::io;
use std::io::prelude::*;

fn main() {
    let mut s = String::new();
    let _ = io::stdin().read_to_string(&mut s).unwrap();
    let v: Vec<i32> = s.split('\n')
                       .filter(|x| !x.is_empty())
                       .map(|x| x.parse::<i32>().unwrap())
                       .collect();

    let mut v2 = v[1..].to_vec();
    v2.sort();

    let vec_size = v2.len() - 1;
    let first_max = v2[vec_size];
    let second_max = v2[vec_size - 1];

    if first_max == second_max {
        for _ in 0..(vec_size + 1) {
            println!("{}", first_max);
        }
    } else {
        for i in &v[1..] {
            if i == &first_max {
                println!("{}", second_max);
            }else {
                println!("{}", first_max);
            }
        }
    }
}


Measured memory_bytes: 9724
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
struct UnionFind {
    vector<int> A;
    UnionFind(int n) : A(n, -1) {}
    int find(int x) {
        if (A[x] < 0) return x;
        return A[x] = find(A[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (A[x] > A[y]) swap(x, y);
        A[x] += A[y];
        A[y] = x;
    }
};
int main() {
    int N, M; cin >> N >> M;
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--, b--;
        uf.unite(a, b);
    }
    int ngroups = 0;
    for (int i = 0; i < N; i++) {
        if (uf.find(i) == i) {
            ngroups++;
        }
    }
    cout << ngroups - 1 << '\n';
    return 0;
}


Measured memory_bytes: 3708
#include <iostream>
#include <vector>
typedef long long ll;
const ll mod = 1e9+7;
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

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

    int n, m; cin >> n >> m;
    vector<int> broken(n);
    rep(i, m) {
        int a; cin >> a;
        broken[a] = 1;
    }

    vector<int> dp(n+2);
    dp[n] = 1;
    for(int i = n-1; i >= 0; --i) {
        if(broken[i]) {
            dp[i] = 0;
            continue;
        } else {
            dp[i] = (dp[i+1] + dp[i+2])%mod;
        }
    }
    cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int64_t pow_int(int64_t base, int64_t index)
{
    int64_t ans = 1;
    for (int i = 0; i < index; i++)
    {
        ans *= base;
    }
    return ans;
}

int main()
{
    int64_t n, p;
    cin >> n >> p;

    map<int64_t, int64_t> primes;
    int64_t p_tmp = p;
    for (int64_t p = 2; p_tmp != 1 && p * p <= p_tmp; p++)
    {
        while (p_tmp % p == 0)
        {
            primes[p] += 1;
            p_tmp /= p;
        }
    }
    if (p_tmp > 1)
    {
        primes[p_tmp] = 1;
    }

    int64_t ans = 1;
    for (auto p_c : primes)
    {
        if (p_c.second >= n)
        {
            ans *= pow_int(p_c.first, p_c.second / n);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {


	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		for(;;){
			int n = in.nextInt();
			if(n==0) break;
			int a[] = new int[n];
			for(int i=0; i<n; i++) a[i] = in.nextInt();
			solve(a);
		}
	}

	static void solve(int[] a){
		int cnt[] = new int[7];
		for(int i=0; i<a.length; i++) cnt[(a[i]/10 > 6)?6:a[i]/10]++;
		for(int i=0; i<7; i++) System.out.println(cnt[i]);
	}
}

Measured memory_bytes: 16000