akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
typedef long long i64;
int main(){
    string c1,c2;
    cin >> c1 >> c2;
    reverse(c1.begin(), c1.end());
    cout << (c1==c2 ? "YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      string[] input = Console.ReadLine().Split();
      int a = int.Parse(input[0]);
      int b = int.Parse(input[1]);
      if (a%3==0 || b%3==0 || (a+b)%3==0)
      {
        Console.WriteLine("Possible");
      }
      else
      {
        Console.WriteLine("Impossible");
      }
    }
}


Measured memory_bytes: 27356
// https://atcoder.jp/contests/abc072/tasks/arc082_b
// 5min ~ 10min
#include <stdio.h>
 
int main(void) {
    int N;
    scanf("%d", &N);
 
    int pi[N+1];
    for (int i=1; i<=N; i++) {
        scanf("%d", &(pi[i]));
    }
 
    int count = 0;
    for (int i=1; i<N; i++) {
        if (pi[i] == i) {
            int tmp = pi[i];
            pi[i] = pi[i+1];
            pi[i+1] = tmp;
            count++;
        }
    }
    if (pi[N] == N) {
        count++;
    }
 
    printf("%d\n", count);
 
    return 0;
}


Measured memory_bytes: 512
#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>;

int main(){
  int l, r, d;
  cin >> l >> r >> d;
  
  int count = 0;
  for(int i=l; i<=r; i++){
    if(i%d==0){
      count++;
    }
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<math.h>

using namespace std;

struct Point {
	int x, y;
	bool operator < (const Point& p)const {
		return y < p.y;
	}
};

struct Line {
	Point b, e;
	bool operator < (const Line& l)const {
		return b.y < l.b.y;
	}
};

int main() {
	int n;
	vector<Line> lines;
	vector<Point> points;

	cin >> n;
	for (int i = 0; i < n; i++) {
		Point pb, pe;
		cin >> pb.x >> pb.y >> pe.x >> pe.y;
		
		if (pb.y == pe.y) {
			Line l;
			l.b = pb.x < pe.x ? pb : pe;
			l.e = pb.x < pe.x ? pe : pb;
			lines.push_back(l);
		}
		else {
			if (pb.y < pe.y) {
				pb.y--;
			}
			else {
				pe.y--;
			}
			points.push_back(pb);
			points.push_back(pe);
		}
	}

	sort(lines.begin(), lines.end());
	sort(points.begin(), points.end());

	int cnt = 0;
	int i = 0;
	int j = 0;
	set<int> s;

	while (i < points.size()) {
		while ( j < lines.size() && points[i].y >= lines[j].b.y) {
			set<int>::iterator lb = lower_bound(s.begin(), s.end(), lines[j].b.x);
			set<int>::iterator ub = upper_bound(s.begin(), s.end(), lines[j].e.x);
			cnt += distance(lb, ub);
			j++;
		}
		if (s.find(points[i].x) == s.end()) {
			s.insert(points[i].x);
		}
		else {
			s.erase(points[i].x);
		}
		i++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 7268
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}


int main()
{
	int n;
	cin >> n;
	vector<int>dif(n);
	rep(i, n) {
		cin >> dif[i];
	}
	sort(all(dif));
	if (n % 2 == 0) {
		cout << dif[n / 2] - dif[n / 2 - 1] << endl;
	}
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main()
{
	char s[1000];
	scanf(" %s", s);
	int l = strlen(s);
	int a, b=0, c;
	a = (s[0] - 49) + 9 * (l - 1);
	for (int i = 0;i < l;i++)
		b += (s[i]-48);
	c = a > b ? a : b;
	printf("%d", c);
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>
 
#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;
 
int main()
{
	int n,k,ans = 1;
	cin >> n >> k;
	
	REP(i,n)
	{
		if(ans < k)
		{
			ans *= 2;
			
		}
		else
		{
			ans += k;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

#define lld long long int
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);	cout.tie(0);

/* 											CODE:-									*/
														


void IMPLEMENT_CODE(){
	
	lld n, W;
	cin>>n>>W;

	lld w[n];
	lld v[n];

	for(lld i=0; i<n; i++)
		cin>>w[i]>>v[i];

	lld dp[n+1][W+1];
	for(lld i=0; i<W+1; i++)
		dp[0][i] = 0;

	for(lld i=1; i<n+1; i++){
		for(lld j=0; j<W+1; j++){
			dp[i][j] = 0;
			if(j-w[i-1]>=0){
				dp[i][j] = max(dp[i-1][j], v[i-1]+dp[i-1][j-w[i-1]]);
				//cout<<" -a";
			}
			else
				dp[i][j] = dp[i-1][j];
			//cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}
	cout<<dp[n][W]<<endl;
}



int main(){
	
	FASTIO;

	IMPLEMENT_CODE();

	return 0;

}


Measured memory_bytes: 82452
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int N, K; cin >> N >> K;
    cout << (N-K+1) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
 
LL N, K, ans;
 
int main()
{
	in >> N >> K;
	std::vector<LL>a(N), max(N + 1);
	rep(i, N)
	{
		in >> a[i];
		max[i + 1] = a[i];
	}
	rep(i, N) max[i + 1] = std::max(max[i + 1], max[i]);
	ans = 112345678901;
	rep(bit, (1LL << N))
	{
		std::vector<LL>idxs;
		rep(i, N)
		{
			if (bit&(1LL << i)) idxs.push_back(i);
		}
		if (idxs.size() != K) continue;
		LL maxH = 0, res = 0;
		rep(i, K)
		{
			maxH = std::max(maxH, max[idxs[i]]);
			if (a[idxs[i]] <= maxH)
			{
				++maxH;
				res += maxH - a[idxs[i]];
			}
			else maxH = a[idxs[i]];
		}
		ans = std::min(ans, res);
	}
	out << ans << std::endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#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(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

int main(void){
    string S;
    int N;
    int ATCG[10];

    cin >> S;

    int idx = 0;
    N = S.length();

    rep(i, N){
        string b = S.substr(i, 1);
        bool is_atcg = (b == "A" || b == "T" || b == "C" || b == "G");
        
        if (!is_atcg){
            ATCG[idx] = i;
            idx ++;
        }
    }

    int answer;

    if(idx != 0){
        answer = max(N - ATCG[idx - 1] - 1, ATCG[0]);
    }else{
        answer = N;
    }

    For(i, 1, idx){
        answer = max(answer, ATCG[i] - ATCG[i - 1] - 1);
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{

    int n;
    cin >> n;
    
    ve<ve<ve<ve<ll>>>> dp(n+1,ve<ve<ve<ll>>>(4,ve<ve<ll>>(4,ve<ll>(4,0))));
    rep(i,4) rep(j,4){
        dp[2][3][i][j] = 1;
    }
    reps(o,3,n+1){
        rep(i,4) rep(j,4) rep(k,4){
            rep(m,4){
                if(j==0&&k==1&&m==2) continue;
                if(j==0&&k==2&&m==1) continue;
                if(j==1&&k==0&&m==2) continue;
                if(i==0&&k==1&&m==2) continue;
                if(i==0&&j==1&&m==2) continue;
                if(i==0&&j==1&&k==2) continue;
                dp[o][j][k][m] += dp[o-1][i][j][k]%mod;
                dp[o][j][k][m] %= mod;
            }
        }
    }
    ll ans = 0;
    rep(i,4) rep(j,4) rep(k,4){
        ans += dp[n][i][j][k];
        ans %= mod;
    }
    out(ans);
    
    return 0;
}


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

int main() {
int a;
int b;
cin>>a>>b;
if (a > b) {
cout << "a > b"<<endl;
} else if (b > a) {
cout << "a < b" << endl;
} else {
cout << "a == b"<< endl;
}
return 0;
}


Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

// 

public class ABC117_A // ←Class名変更！！
{
    public static void Main()
    {
        var n = Ria();

        WriteLine($"{(double)n[0]/ (double)n[1]}");

    } // Main

    public static string Rs() { return ReadLine(); }
    public static char Rc() { var c = ReadLine(); return c[0]; }    //最初の1文字だけ返す
    public static int Ri() { return int.Parse(ReadLine()); }
    public static long Rl() { return long.Parse(ReadLine()); }
    public static char[] Rca() { return ReadLine().ToCharArray(); }
    public static int[] Ria() { return Array.ConvertAll(ReadLine().Split(' '), int.Parse); }
    public static long[] Rla() { return Array.ConvertAll(ReadLine().Split(' '), long.Parse); }
} // Class


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

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


Measured memory_bytes: 256
N, K = map(int, input().split())
D = 60
to = [None] * D
to[0] = [None] * N
for i, a in enumerate(map(int, input().split())):
    to[0][i] = a - 1
for t in range(1, D):
    to[t] = [None] * N
    for i in range(N):
        to[t][i] = to[t-1][to[t-1][i]]
v = 0
for i in reversed(range(D)):
    l = 1<<i
    if l <= K:
        v = to[i][v]
        K -= l
        if K <= 0:
            print(v + 1)
            exit()

Measured memory_bytes: 177116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    int a, b; cin >> a >> b;
    int tmp[3];
    tmp[0] = a+b;
    tmp[1] = a-b;
    tmp[2] = a*b;
    sort(tmp, tmp+3);
    cout << tmp[2] <<endl;
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    ll a;
    string b;
    cin >> a >> b;

    int hoge = 0;
    for (char c : b) {
        if (c == '.') continue;
        hoge = hoge * 10 + (c - '0');
    }

    cout << a * hoge / 100 << newl;
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	int R,G,B,N;
//	int i=0,j=0,k=0;
	cin >> R >> G >> B >> N;
	int cnt = 0;
	rep(i,0,N+1){
		if(R*i > N){
			break;
		}
	  rep(j,0,N+1){
		  if(R*i + G*j > N) break;
//	while(R*i<=N){
//		while(R*i+G*j<=N){
			if((N-R*i-G*j)%B==0){
				cnt++;
			}
//			j++;
		}
//		i++;
	}
	cout << cnt << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int64_t> cnt(5);
    for(int i=0; i<N; i++) {
        string S;
        cin >> S;
        if(S.front() == 'M') {
            cnt[0]++;
        } else if(S.front() == 'A') {
            cnt[1]++;
        } else if(S.front() == 'R') {
            cnt[2]++;
        } else if(S.front() == 'C') {
            cnt[3]++;
        } else if(S.front() == 'H') {
            cnt[4]++;
        }
    }

    int64_t ans = 0;
    for(int i=0; i<5; i++) {
        for(int j=i+1; j<5; j++) {
            for(int k=j+1; k<5; k++) {
                ans += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
#include <bitset>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

ll lower_bound(const std::vector<ll>& values, const ll bound)
{
    auto length = values.size();

    auto idx=0;
    while (length != 0)
    {
        auto half = length / 2;
        auto mid = values[idx + half];

        if (mid < bound)
        {
            length -= half + 1;
            idx += half + 1;
        }
        else
        {
            length = half;
        }
    }

    if (values.size() < idx)
        idx = values.size() - 1;

    return idx;
}

ll upper_bound(const std::vector<ll>& values, const ll bound)
{
    auto length = values.size();

    auto idx=0;
    while (length != 0)
    {
        auto half = length / 2;
        auto mid = values[idx + half];

        if (mid <= bound)
        {
            length -= half + 1;
            idx += half + 1;
        }
        else
        {
            length = half;
        }
    }

    if (values.size() < idx)
        idx = values.size() - 1;

    return idx;
}

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

    std::vector<ll> A(N), B(N), C(N);
    for (auto i=0; i<N; ++i)
        std::cin >> A[i];

    for (auto i=0; i<N; ++i)
        std::cin >> B[i];

    for (auto i=0; i<N; ++i)
        std::cin >> C[i];

    ll result = 0;
    std::sort(A.begin(), A.end());
    std::sort(C.begin(), C.end());
    for (auto i=0; i<B.size(); ++i)
    {
        auto b = B[i];
        auto aLimitIdx = upper_bound(A, b - 1);
        ll aPos = aLimitIdx;

        auto cLimitIdx = lower_bound(C, b + 1);
        ll cPos = C.size() - cLimitIdx;

        result += aPos * cPos;
    }

    std::cout << result << std::endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

int main() {
    int n; cin >> n;
    int d[n];
    rep(i, n) cin >> d[i];

    int sum = 0;
    rep(i, n){
        REP(j, i + 1, n){
            sum += d[i] * d[j];
        }
    }
    OP(sum);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;

int main() {
	ll a, b;
	cin >> a >> b;
	if (a == 1&&b==1) {
		cout << "Draw" << endl;
	}
	else if (a == 1) {
		cout << "Alice" << endl;
	}
	else if(b==1){
		cout << "Bob" << endl;
	}
	else {
		if (a < b) {
			cout << "Bob" << endl;
		}
		else if (a > b) {
			cout << "Alice" << endl;
		}
		else {
			cout << "Draw" << endl;
		}
	}

}

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


int main() {


    int A, B;
    cin >> A >> B;
    
    for(int i = 0; i < 1e6; i++){
        if(floor(i*0.08) == A && floor(i*0.10) == B){
        cout << i << endl;
        return 0;
        }
    }
    cout << "-1" << endl;
    

    return 0;
}

Measured memory_bytes: 3572
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int N;
  while (cin >> N) {
    int v[N];
    for (int i : range(N)) {
      cin >> v[i];
      v[i]--;
    }

    vector<int> xs(N * N, -1);
    vector<pair<int, int>> ps, bs;
    for (int i : range(N)) {
      xs[v[i]] = i;
      ps.push_back({v[i], i});
      bs.push_back({v[i], N - 1 - i});
    }

    sort(ps.begin(), ps.end());
    for (int ptr = 0, i = 0, pu = 0; i < N; ) {
      if (pu >= ps[i].second) {
        i++;
        pu = 0;
        continue;
      }
      if (xs[ptr] != -1) {
        ptr++;
        continue;
      }
      if (ptr > ps[i].first) goto FAIL;
      xs[ptr] = ps[i].second;
      ptr++;
      pu++;
    }

    sort(bs.begin(), bs.end());
    reverse(bs.begin(), bs.end());
    for (int ptr = N * N - 1, i = 0, pu = 0; i < N; ) {
      if (pu >= bs[i].second) {
        i++;
        pu = 0;
        continue;
      }
      if (xs[ptr] != -1) {
        ptr--;
        continue;
      }
      if (ptr < bs[i].first) goto FAIL;
      xs[ptr] = N - 1 - bs[i].second;
      ptr--;
      pu++;
    }

    puts("Yes");
    for (int i : range(N * N)) {
      if (i) printf(" ");
      printf("%d", xs[i] + 1);
    }
    puts("");
    continue;

FAIL:
    puts("No");
  }
}


Measured memory_bytes: 2304
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, M;
	in >> N >> M;
	std::vector<LL>A(N), B(M), C(M);
	rep(i, N) in >> A[i];
	rep(i, M) in >> B[i] >> C[i];

	std::vector<std::pair<LL, LL>>ope;
	rep(i, M) ope.push_back(std::make_pair(C[i], B[i]));
	ope.push_back(std::make_pair(0, 114514));
	std::sort(A.begin(), A.end());
	std::sort(ope.rbegin(), ope.rend());

	LL ans = 0, seek = 0;
	rep(i, N)
	{
		auto it = std::lower_bound(A.begin() + i, A.end(), ope[seek].first);
		LL cnt = std::min<LL>(it - (A.begin() + i), ope[seek].second);
		ans += ope[seek].first * cnt;
		ope[seek].second -= cnt;
		if (ope[seek].second == 0) ++seek;
		if (cnt == 0) ans += A[i];
		else i += cnt - 1;
	}

	out << ans << std::endl;
}


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


int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = a + b + c - max(a, max(b,c));
    int res = pow(2,k)*max(a, max(b,c));
    cout << ans + res << endl;
}


Measured memory_bytes: 256
def search(arr1,arr2,k)
  result_arr = []
  arr1.each do |i|
    arr2.each do |j|
      # break if result_arr.size >= k && result_arr.min > i + j
      result_arr << i + j
    end
    # result_arr = result_arr.sort.reverse[0..[k - 1,result_arr.size].min]
  end
  result_arr.sort.reverse[0..k - 1]
  # arr1.product(arr2).map{|i,j| i + j}.sort.reverse[0..k - 1]
end

x,y,z,k = gets.chomp.split(' ').map(&:to_i)
x_arr   = gets.chomp.split(' ').map(&:to_i).sort.reverse
y_arr   = gets.chomp.split(' ').map(&:to_i).sort.reverse
z_arr   = gets.chomp.split(' ').map(&:to_i).sort.reverse

search(search(x_arr,y_arr,k), z_arr,k).each do |i|
  puts i
end


Measured memory_bytes: 112112
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

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

	sort(ALL(s));
	sort(ALL(t));
	reverse(ALL(t));

	if (s < t)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

#define MAX_P 10
#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(void)
{
	int N;
	long M;
	while(cin >> N >> M, N > 0){
		long D[MAX_P + 1];
		long result = 0;
		//配列Dを初期化
		rep(i, MAX_P + 1){
			D[i] = 0;
		}
		//配列Dを構成
		rep(i, N){
			int d, p;
			cin >> d >> p;
			D[p] += d;
		}
		rep(i, MAX_P + 1){
			if (M >= D[MAX_P - i]){
				M -= D[MAX_P - i];
			}else if(M > 0){
				result += (D[MAX_P - i]-M) * (MAX_P - i);
				M = 0;
			}else{
				result += D[MAX_P - i] * (MAX_P - i);
			}
		}
		cout << result << endl;
	}
	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int x, y;
  cin >> x >> y;

  // c has 2 legs
  // t has 4 legs

  // x animals
  // y legs

  //  c +  t = x
  // 2c + 4t = y

  // x = c + t
  // y = 2 * (c + 2t)  --> y is an even number

  //  c +  t = x
  // 2c + 4t = y

  // 4c + 4t = 4x    <-->    4t = 4x - 4c
  // 2c + 4t = y

  // 4c + 4t = 4x      <-->    4t = 4x - 4c
  // 2c + 4x - 4c = y  <-->    -2c + 4x = y
  //                   <-->     2c = 4x - y   <--> c = 2x - y/2 = (4x - y) / 2

  // c = (4x - y) / 2
  // t = x - c
  //   = x - 2x + y/2
  //   = y/2 - x
  // t = (y - 2x) / 2

  // c = (4x - y) / 2   --> 4x >= y
  // t = (y - 2x) / 2   --> y >= 2x    --> 2x <= y <= 4x

  if (y % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  if (2 * x <= y and y <= 4 * x) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

void solve(int tc) {
	int n, m;
	cin>>n>>m;
	ll total = 0;
	for(int i=0; i<m; ++i) {
		int a;
		cin>>a;
		total += a;
	}
	if(total > n) {
		cout<<-1<<endl;
	}
	else
		cout<<n - total<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    for(int tc=1; tc<=t; ++tc) {
        solve(tc);
    }    
    return 0;
}

Measured memory_bytes: 3616
x,n = map(int,input().split())
if n==0:
    print(x)
else:
    p = list(map(int,input().split()))
    for i in range(100):
        if x-i not in p:
            print(x-i)
            break
        elif x+i not in p:
            print(x+i)
            break


Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<string> s = {"a", "i", "u", "e", "o"};
    string c;
    cin >> c;
    for (int i = 0; i < s.size(); i++){
        if (c == s[i]){
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define ll long long
#define INF 10000000010
using namespace std;

//h[i =1~n]

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    int h[n];
    int ans = 0;
    int cnt = 0;
    int prv = -1;
    for(int i =1; i<= n; i++){
        cin>>h[i];
        if(h[i] <= prv){
            cnt++;
            prv = h[i];
        }
        else{
            cnt = 0;
            prv = h[i];
        }
        ans = max(ans,cnt);
    }
    cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 640
<?php
fscanf(STDIN, "%d %d %d %d", $a, $b, $h, $m);

$dH = ($h * 30) + ($m * 0.5);
$dM = $m * 6;

$d = abs($dH - $dM);

if ($d > 180) {
    $d = 360 - $d;
}

$c2 = ($a ** 2) + ($b ** 2) - (2 * $a * $b * cos(deg2rad($d)));
$c = sqrt($c2);

echo "{$c}\n";


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

using ll = long long;
using P = pair<int, int>;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  vector<int> divisor;
  divisor.push_back(1);
  divisor.push_back(M + 1);
  // Mの約数を列挙
  for (int i = 1; i * i <= M; i++) {
    if (M % i == 0) {
      divisor.push_back(i);
      divisor.push_back(M / i);
    }
  }

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

  for (int i = 1; i < divisor.size(); i++) {
    if (divisor[i] > M / N) {
      cout << divisor[i-1] << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define C(n,m) ((LL)fac[(n)+(m)]*ifac[n]%mo*ifac[m]%mo)

const int N=2e6;
const int maxn=N+10;
const int mo=1e9+7;

int X1,X2,X3,X4,X5,X6;
int Y1,Y2,Y3,Y4,Y5,Y6;
int fac[maxn],ifac[maxn];

int power(int x,int k)
{
	int res=1;
	while (k)
	{
		if (k&1) res=(LL)res*x%mo;
		x=(LL)x*x%mo;
		k>>=1;
	}
	return res;
}

int solve(int Px,int Py,int Ax,int Ay,int Bx,int By)
{
	int X1=abs(Px-Ax);
	int Y1=abs(Py-Ay);
	int X2=abs(Px-Bx);
	int Y2=abs(Py-By);
	if (X1>X2) swap(X1,X2);
	if (Y1>Y2) swap(Y1,Y2);
	int A=(C(X1,Y1)+C(X2+1,Y2+1))%mo;
	int B=(C(X1,Y2+1)+C(X2+1,Y1))%mo;
	return (A+mo-B)%mo;
}

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,x,y,A=0,B=0;
	fac[0]=1;
	for (i=1;i<=N;i++)
		fac[i]=(LL)fac[i-1]*i%mo;
	ifac[N]=power(fac[N],mo-2);
	for (i=N;i>=1;i--)
		ifac[i-1]=(LL)ifac[i]*i%mo;
	scanf("%d%d%d%d%d%d",&X1,&X2,&X3,&X4,&X5,&X6);
	scanf("%d%d%d%d%d%d",&Y1,&Y2,&Y3,&Y4,&Y5,&Y6);
	for (x=X3;x<=X4;x++) (A+=(LL)solve(x,Y3,X5,Y5,X6,Y6)*solve(x,Y3-1,X1,Y1,X2,Y2)%mo*(x+Y3)%mo)%=mo;
	for (y=Y3;y<=Y4;y++) (A+=(LL)solve(X3,y,X5,Y5,X6,Y6)*solve(X3-1,y,X1,Y1,X2,Y2)%mo*(X3+y)%mo)%=mo;
	for (x=X3;x<=X4;x++) (B+=(LL)solve(x,Y4,X1,Y1,X2,Y2)*solve(x,Y4+1,X5,Y5,X6,Y6)%mo*(x+Y4+1)%mo)%=mo;
	for (y=Y3;y<=Y4;y++) (B+=(LL)solve(X4,y,X1,Y1,X2,Y2)*solve(X4+1,y,X5,Y5,X6,Y6)%mo*(X4+y+1)%mo)%=mo;
	printf("%d\n",(B+mo-A)%mo);
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX INT_MAX
#define MIN INT_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
void solve() {
 	int l;
 	cin >> l;
 	string str;
 	cin >> str;
 	int c = 0;
 	for(int i=0;i<l-2;i++) {
 		if(str[i] == 'A' && str[i+1] == 'B' && str[i+2] == 'C')
 			c++;
 	}
 	cout << c;
    return;
}
int32_t main() {
    FO;
    solve();
    return 0;
}


Measured memory_bytes: 256
import itertools
import sys

n = int(input())
S = [0]*n
while True:
    print("".join(map(lambda x:chr(ord('a')+x),S)))
    for i in range(n-1,0,-1):
        if(i>0 and max(S[:i])>=S[i]):
            S[i] += 1
            for j in range(i+1,n):
                S[j] = 0
            break
    else:
        break

Measured memory_bytes: 4420
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int Mod=998244353;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


signed main() {
    vector<int> a(3);
    rep(i,3)cin >>a[i];int hi;
    sort(all(a));
    if((a[0]%2)&&(a[1]%2)&&(a[2]%2)){
        cout <<(a[2]-a[1])/2+(a[2]-a[0])/2<<endl;
        return 0;
    }else if((a[0]%2)==0&&(a[1]%2)==0&&(a[2]%2)==0){
        cout <<(a[2]-a[1])/2+(a[2]-a[0])/2<<endl;
        return 0;
    }
    bool flag=false;
    if((a[0]+a[1]+a[2])%2)flag=true;
    rep(i,3){
        if(flag){
            if(a[i]%2)hi=i;
            else a[i]++;
        }else{
            if(a[i]%2==0)hi=i;
            else a[i]++;
        }
    }
    sort(all(a));
    cout <<(a[2]-a[1])/2+(a[2]-a[0])/2+1<<endl;

}


















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

void solve () {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 1; i <= n; i++) {
        a[i - 1] = i;
    }
    vector<vector<int>> b(2, vector<int>(n)), c;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < n; j++) {
            cin >> b[i][j];
        }
    }
    int f = 0;
    int s = 0;
    int cnt = 0;
    do {
        if (a == b[0]) f = cnt;
        if (a == b[1]) s = cnt;
        cnt++;
    } while (next_permutation (a.begin(), a.end()));
    cout << abs (f - s);


}

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


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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int n,i,j;
    cin>>n;
    long long int A[n],result[n]={0};
    for(i=0;i<n;i++){
        cin>>A[i];
    }
    result[0]=0;
    result[1]=abs(A[1]-A[0]);
    for(i=2;i<n;i++){
        result[i]=min(result[i-1]+abs(A[i]-A[i-1]),result[i-2]+abs(A[i]-A[i-2]));
    }
    cout<<result[n-1];
    return 0;
}


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

#ifdef _DEBUG
    #include "/home/v-o_o-v/deb.h"
    #define deb(x...)cerr << "[" << #x << "] = [";_print(x);
#else
    #define deb(x...)
#endif

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
   
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    sort(all(a));
    int sum = 0;
    for(int i = 0; i < k; i++)sum += a[i];
    cout << sum << '\n';
    return 0;
}
// Write Here


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Main {
    int n;
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private boolean ng (int a, int b, int c) {
        return (a == 1 && b == 2 && c == 3);
    }

    private void solve() {
        try {
            long seven = (long) Math.pow(10, 9) + 7;
            n = sc.nextInt();
            long ans = 0;
            long[][][][] dp = new long[n+1][4][4][4];

            dp[0][0][0][0] = 1;

            for (int i = 0; i < n; i++) {
                for (int a = 0; a < 4; a++) {
                    for (int b = 0; b < 4; b++) {
                        for (int c = 0; c < 4; c++) {
                            for (int d = 0; d < 4; d++) {
                                if(ng(b, c, d) || ng(c, b, d) || ng(b, d, c))
                                    continue;
                                if(ng(a, c, d) || ng(a, b, d))
                                    continue;
                                dp[i+1][b][c][d] += dp[i][a][b][c];
                                dp[i+1][b][c][d] %= seven;
                            }
                        }
                    }
                }
            }

            for(int a=0; a<4; a++)
                for(int b=0; b<4; b++)
                    for(int c=0; c<4; c++)
                        ans = (ans + dp[n][a][b][c]) % seven;

            System.out.println(ans);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

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

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

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 22996
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    aa=LI()
    ac=Counter(aa)
    s=sum(c*(c-1)//2 for a,c in ac.items())
    for a in aa:
        c=ac[a]
        print(s-c*(c-1)//2+(c-1)*(c-2)//2)

main()

Measured memory_bytes: 25236
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
using namespace std;
char h[500005] = { 0 };

int main()
{
	string  s;
	cin >> s;
	//char c;
	for (int i = 0; i < s.size(); i++) {

		h[300000 + i + 1] = s[i];

	}
	int L = 300000;
	int R = 300000 + s.size() + 1;

	int sign = 1;//R
	int q;
	cin >> q;
	for (int j = 1; j <= q; j++) {
		int a;
		cin >> a;
		if (a == 1)sign *= -1;
		if (a == 2) {
			int b; char d;
			cin >> b >> d;
			if (b == 1 && sign == 1) {
				h[L] = d;
				L--;
			}
			else if (b == 2 && sign == -1) {
				h[L] = d;
				L--;
			}
			else if (b == 1 && sign == -1) {
				h[R] = d;
				R++;
			}
			else if (b == 2 && sign == 1) {
				h[R] = d;
				R++;
			}
		}
	}
	if (sign == 1) {
		for (int j = L + 1; j < R; j++)cout << h[j];
		cout << endl;
	}
	else {
		for (int j = R - 1; L < j; j--)cout << h[j];
		cout << endl;
	}


}

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

int main() {
  int x, y;
  for(x = 1; x < 10; x++) {
    for(y = 1; y < 10; y++) {
      cout << x << "x" << y << "=" << x*y << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 2980
#include "bits/stdc++.h"
using namespace std;
using long_t = int64_t;

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		int N;
		cin >> N;

		vector<int> A( N ), B( N );
		for( auto& v: A ) { cin >> v; }
		for( auto& v: B ) { cin >> v; }

		int ans = 0;
		long_t sum = 0;
		vector<int> C( N );
		for( int i = 0; i < N; ++i ) {
			if( A[i] < B[i] ) {
				sum += B[i] - A[i];
				ans += 1;
			}
			C[i] = A[i] - B[i];
		}
		sort( C.begin(), C.end(), greater<>() );

		for( int i = 0; i < N; ++i ) {
			if( sum <= 0 || C[i] <= 0 ) {
				break;
			}
			sum -= C[i];
			ans += 1;
		}

		cout << (sum > 0 ? -1 : ans) << endl;
	}
};

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


Measured memory_bytes: 1408
#二分ヒープ
class BinaryHeap
  def initialize(n, &b)
    @heap = Array.new(n)
    @size = 0
    #ex) |parent, child| parent <= child
    @b = b
  end
  def push(x)
    @size += 1
    upfrom(@size - 1, x)
  end
  def shift
    wk = @heap[0]
    @size -= 1
    downfrom(0, @heap[@size])
    wk
  end

  private

  def upfrom(i, x)
    me = i
    while 0 < me do
      parent = (me - 1) >> 1
      break if @b.call(@heap[parent], x)
        @heap[me] = @heap[parent]
        me = parent
    end
    @heap[me] = x
  end
  def downfrom(i, x)
    me = i
    while me < @size do
      child = (me << 1) + 1
      break if child >= @size
      if (child + 1) < @size && @b.call(@heap[child + 1], @heap[child]) then
        child += 1
      end
      break if @b.call(x, @heap[child])
      @heap[me] = @heap[child]
      me = child
    end
    @heap[me] = x
  end
end

X, Y, Z, K = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)
B = gets.chomp.split(" ").map(&:to_i)
C = gets.chomp.split(" ").map(&:to_i)

bh = BinaryHeap.new(K){|parent, child| parent[0] >= child[0]}
A.sort!.reverse!
B.sort!.reverse!
C.sort!.reverse!
ia, ib, ic = [0, 0, 0]
bh.push([A[0]+B[0]+C[0], 0, 0, 0])

K.times{
  wk = bh.shift
  puts wk[0]
  oa, ob, oc = [ia, ib, ic]
  fa, fb, fc = [false, false, false]
  (ia += 1; fa = true) if wk[1] == ia && ia < X - 1
  (ib += 1; fb = true) if wk[2] == ib && ib < Y - 1
  (ic += 1; fc = true) if wk[3] == ic && ic < Z - 1
  if fa then
    (0..ob).each{|b|
      (0..oc).each{|c|
        bh.push([A[ia]+B[b]+C[c], ia, b, c])
      }
    }
  end
  if fb then
    (0..oa).each{|a|
      (0..oc).each{|c|
        bh.push([A[a]+B[ib]+C[c], a, ib, c])
      }
    }
  end
  if fc then
    (0..oa).each{|a|
      (0..ob).each{|b|
        bh.push([A[a]+B[b]+C[ic], a, b, ic])
      }
    }
  end
  if fa && fb then (0..oc).each{|c| bh.push([A[ia]+B[ib]+C[c], ia, ib, c])} end
  if fa && fc then (0..ob).each{|b| bh.push([A[ia]+B[b]+C[ic], ia, b, ic])} end
  if fb && fc then (0..oa).each{|a| bh.push([A[a]+B[ib]+C[ic], a, ib, ic])} end
  if fa && fb && fc then bh.push([A[ia]+B[ib]+C[ic], ia, ib, ic]) end
}


Measured memory_bytes: 142840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] p=new int[n];
		for(int i=0;i<n;i++) p[i]=sc.nextInt();

		int swap=0;
		for(int i=0;i<n-1;i++){
			if(p[i]==i+1){
				int tmp=p[i];
				p[i]=p[i+1];
				p[i+1]=tmp;
				swap++;
			}
		}
		if(p[n-1]==n)swap++;
		System.out.println(swap);
	}
}


Measured memory_bytes: 50920
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 110;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}


int main(){
    ll n,k; cin >> n >> k;
    vector<Pll> ans;
    if((n-1) * (n-2) / 2 < k){
        cout << -1 << endl;
        return 0;
    }
    vector< bitset<n_max> > graph(n, bitset<n_max>(0));
    rep(i,n-1){
        graph[0][i+1] = 1;
        graph[i+1][0] = 1;
        ans.emplace_back(1, i + 2);
    }
    ll num = (n-1) * (n-2) / 2;
    bool ok = num <= k;
    for(int i = 1; i < n; i++){
        if(ok)break;
        for(int j = i+1; j < n; j++){
            if(ok)break;
            if(graph[i][j] == 0){
                graph[i][j] = 1;
                graph[j][i] = 1;
                ans.emplace_back(i+1, j+1);
                num--;
                ok = (num <= k);
            }
        }
    }

    cout << ans.size() << endl;
    rep(i,ans.size())print(ans[i]);
}

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

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

const long long MOD = 1000000007;

int main(){
  int n,m,k,s;
  cin >> n >> m;
  vector<set<int>> sw(m);
  rep(i,m){
    cin >> k;
    rep(j,k){
      cin >> s;
      sw.at(i).insert(s-1);
    }
  }
  vector<int> p(m);
  rep(i,m) cin >> p.at(i);
  int t=0,ans=0;
  bool ck=true;
  vector<bool> tes(n);
  rep(x,pow(2,n)){
    ck=true;
    int xx=x;
    rep(i,n){
      if((xx%2)==1) tes.at(i)=true;
      else tes.at(i) = false;
      xx/=2;
    }
    rep(i,m){
      t=0;
      for(int a:sw.at(i)){
        if(tes.at(a)) t++;
      }
      if(t%2 != p.at(i)) ck=false;
    }
    if(ck){ 
      ans++;
      //cout<<x<<endl;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
r,g,b,n = map(int,input().split())
numR = n//r
numG = n//g
numB = n//b
c = 0
for i in range(0,n+1,r):
    for j in range(0,n+1,g):
        x = n-(i+j)
        if x%b ==0 and (i+j)<=n:
            c+=1

print(c)

Measured memory_bytes: 40684
#include <bits/stdc++.h>
using namespace std;
#define clr(a, x) memset(a, x, sizeof(a))
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define X first
#define Y second
#define fastin                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;

bool solve(string s, int a, int b)
{
    if (s.length() != a + b + 1) return false;
    for (int i = 0; i < s.length(); i++)
    {
        if (i == a && s[i] != '-') return false;
        if (i != a && !isdigit(s[i])) return false;
    }
    return true;
}

int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.in", "r", stdin);
// freopen("1.out", "w", stdout);
#endif
    int a, b;
    string s;
    while (cin >> a >> b >> s)
        solve(s, a, b) ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <stdlib.h>
#include <cmath>
using namespace std;
int main() {
	double x1, y1, x2, y2;
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	double result;
	result = sqrt(pow(x2-x1, 2.0) + pow(y2-y1, 2.0));
	printf("%f\n", result);
}


Measured memory_bytes: 2732
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        i = 0
        while n > 1:
            n = math.ceil(n/3)
            i += 1

        rr.append(i)
        break

    return '\n'.join(map(str, rr))


print(main())




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

int main() {
  string s;
  cin >> s;
  int a,z;
  a = z = -1;
  for(int i = 0;i < s.size(); i++) {
    if(s[i]== 'A' && a == -1) {
      a = i;
    }
    if(s[i]== 'Z') {
      z = i;
    }
  }
  cout << z - a + 1 << endl;
}

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

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<i64>();
    let m = input::<i64>();
    let mut ab = (0..n)
        .map(|_| {
            let a = input();
            let b = input();
            (a, b)
        })
        .collect::<Vec<(i64, i64)>>();
    ab.sort();

    let mut ans = 0;
    let mut buy = m;
    for (a, b) in ab {
        let cnt = std::cmp::min(b, buy);
        ans += a * cnt;
        buy -= cnt;
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396