akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

#define N 4
#define N2 16
#define LIMIT 45

const int dx[4] { -1, 0, 1, 0 };
const int dy[4] { 0, -1, 0, 1 };
const char dir[4] { 'u', 'l', 'd', 'r' };
int MDT[N2][N2];

struct Puzzle {
	int f[N2], space, MD;
	bool operator <(const Puzzle p) const {
		for (int i = 0; i < N2; ++i) {
			if (f[i] == p.f[i])
				return f[i] > p.f[i];
		}
		return false;
	}
};

int getAllMd(Puzzle p) {
	int sum = 0;
	for (int i = 0; i < N2; ++i) {
		if (p.f[i] == N2)
			continue;
		sum += MDT[i][p.f[i] - 1];
	}
	return sum;
}

int limit;
Puzzle state;
int path[LIMIT];
bool dfs(int depth, int prev) {
	if (state.MD == 0)
		return true;

	if (state.MD + depth > limit)
		return false;

	int sx = state.space / N;
	int sy = state.space % N;
	Puzzle tmp;
	for (int r = 0; r < 4; ++r) {
		if (max(r, prev) - min(r, prev) == 2)
			continue;

		int tx = sx + dx[r];
		int ty = sy + dy[r];
		if (tx < 0 || ty < 0 || tx >= N || ty >= N)
			continue;

		tmp = state;
		state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
		state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
		swap(state.f[sx * N + sy], state.f[tx * N + ty]);
		state.space = tx * N + ty;
		if (dfs(depth + 1, r)) {
			path[depth] = dir[r];
			return true;
		}
		state = tmp;
	}

	return false;
}

string deepening(Puzzle p) {
	int md = getAllMd(p);
	p.MD = md;
	for (limit = md; limit <= LIMIT; ++limit) {
		state = p;
		if (dfs(0, -100)) {
			string ans;
			for (int i = 0; i < limit; ++i) {
				ans += dir[path[i]];
			}
			return ans;
		}
	}

	return "";
}

int main() {
	for (int i = 0; i < N2; ++i) {
		for (int j = 0; j < N2; ++j) {
			MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
		}
	}
	Puzzle p;
	for (int i = 0; i < N2; ++i) {
		scanf("%d", &p.f[i]);
		if (p.f[i] == 0) {
			p.f[i] = N2;
			p.space = i;
		}
	}
	string ans = deepening(p);
	cout << ans.size() << endl;

	return 0;
}

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


int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.rbegin(), a.rend());

  int t = n - 1;
  ll ans = 0;
  rep(i,n){
    int lim = 2;
    if (i == 0) lim = 1;
    rep(j,lim){
      if (t > 0){
        ans += a.at(i);
        t--;
      }
      else goto OUT;
    }
  }
  OUT:

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

// int main(){
  //   int n;
  //   cin >> n;
  //
  //   vi a(n);
  //   rep(i,n) cin >> a.at(i);
  //   sort(a.begin(), a.end());
  //   reverse(a.begin(), a.end());
  //
  //   int cnt = 0;
  //   ll ans = 0;
  //   cnt++;
  //   ans += a.at(0);
  //   cnt++;
  //   REP(i,1,n){
    //     if (cnt == n) break;
    //     ans += a.at(i);
    //     cnt++;
    //     if (cnt == n) break;
    //     ans += a.at(i);
    //     cnt++;
    //     if (cnt == n) break;
    //   }
    //   cout << ans << endl;
    //   return 0;
    // }


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI=3.14159265358979323846;



int main(){
   ll n,cnt=0;;
   string s;
   int a,b,c;
   cin>>n;
   n-=400;
   n/=200;
   cout<<8-n<<endl;
   
}


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

int main()
{
  long long int N, K;
  cin >> N >> K;

  const auto x { N/K };
  
  auto ans { x*x*x };
  
  if(K%2 == 0){
    const auto y { (N+K/2)/K };
    ans += y*y*y;
  }

  cout << ans << endl;
}

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

#define MAX_ARRAY 100

void insertion(int [], int );

void insertion(int A[], int n){
    int i, j, k;
    int key;
    
    for(k = 0; k < n; k++){
        if(k) cout << " ";
        cout << A[k];
    }
    cout << endl;
        
    for(i = 1; i <= n - 1; i++){
        key = A[i]; 
        j = i - 1;
        while(0 <= j && key < A[j]){
             A[j+1] = A[j];
             j--;
        }
        A[j+1] = key;
        
        for(k = 0; k < n; k++){
            if(k) cout << " ";
            cout << A[k];
        }
    cout << endl;
    }
    
    
}

int main(void){
    int n;
    int arr[MAX_ARRAY];
    int i;
    
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> arr[i];
    }
    
    insertion(arr, n);
    
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <climits>
#include <cstdlib>
using namespace std;
int main() {
    long long int n;
    cin >> n;
    long long int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    long long int sum=0;
    for(int i=0;i<n;i++)
        sum+=a[i];

    long long int x,y,sum1=sum,sum2,min=INT_MAX;
    for(int i=1;i<n;i++){
        sum1-=a[n-i];
        sum2=sum-sum1;
        if(abs(sum2-sum1)<min)
            min=abs(sum2-sum1);
    }
    cout << min << endl;
    return 0;
}

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

int n;
int a[200001];

int main()
{
	ios::sync_with_stdio(false);
	int m(200002);
	int ans(0);
	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] < m)
		{
			m = a[i];
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace ABC170B
{
    class Program
    {
        static void Main(string[] args)
        {
            var XY = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var X = XY[0];
            var Y = XY[1];

            int a, b = 0;
            b = Y / 2 - X;
            a = 2 * X - Y / 2;

            if (a >= 0 && b >= 0 && a + b == X && 2 * a + 4 * b == Y)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

        }
    }
}


Measured memory_bytes: 19044
s = input()

for i in range(len(s)):
    if s[i] == 'A':
        a_index = i
        break

for j in range(-1, -(len(s)-a_index), -1):
    if s[j] == 'Z':
        z_index = j
        break

length = (len(s) + z_index) - a_index + 1
print(length)


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

void trace(int A[], int N) {
  for (int i = 0; i < N; i++) {
    if (i > 0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main() {
  int N, A[100];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];

  trace(A, N);
  for (int i = 1; i < N; i++) {
    int v = A[i];
    int j = i-1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A, N);
  }
}



Measured memory_bytes: 3152
#include <stdio.h>

int main() {
   int i, n, A[10000+1], q, key, sum = 0; 

    scanf("%d", &n);
    for( i = 0; i < n; i++ ) scanf("%d", &A[i]);
    
    scanf("%d", &q);
    for ( i = 0; i < q; i++) {
        scanf("%d", &key);
        if( search(A, n, key) ) sum++;
    }
    printf("%d\n", sum);
    
    return 0;
}

// 線形探索
int search(int A[], int n, int key) {
    int i = 0;
    A[n] = key;
    while ( A[i] != key ) i++;
    return i != n;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi; 
typedef pair<int,int> pi;
typedef long long ll;
#define F first 
#define S second 
#define PB push_back 
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)

vector<ll> dp;
vector< vector<ll> > s;

bitset<100010> can;

void see(ll here){
	
	can[here] = 1;
	
	ll f = s[here].size();
	
	for(ll i = 0; i < f; i++){
		
		if(!can[ s[here][i] ]){
			see( s[here][i] );
		}
		
		dp[here] = max(dp[here],  dp[s[here][i]] + 1 );
	}
	
}

int main(){
	
	ios::sync_with_stdio(0); cin.tie(0);
	
	ll n, m,a,b;
	
	cin >> n >> m;
	
	dp.assign( n+1 , 0);
	s.assign( n+1 , vector<ll>(0,0));
	
	for(ll i = 0; i < m; i++){
		
		cin >> a >> b;
		s[a].PB(b);
	}
	
	for(ll i = 1; i <= n; i++){
 		if(!can[i]) see(i);
	}

 
 	ll maxi = 0;
 
 	for(ll i = 1; i <= n; i++){
 		maxi = max(maxi, dp[i]);
	}
	
	cout << maxi << endl;
 
	return 0;
}

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

int main(){
    string S;
    cin >> S;
    if(S[0] != S[1] || S[0] != S[2] || S[1] != S[2]){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

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

#define fi first
#define se second
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;

const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

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

	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i <= r; i++)
		ans += (i % d == 0);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3604
import sys
readline = sys.stdin.readline
n, k = map(int, input().split())
v = tuple(int(readline()) for _ in range(n))
lo = max(v) - 1
hi = int(1e10)
while hi - lo > 1:
    p = P = (lo + hi) // 2
    m = 1
    for i in range(n):
        if v[i] > p:
            p = P
            m += 1
        p -= v[i]
    if m <= k:
        hi = P
    else:
        lo = P
print(hi)



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

string S;

int main() {
    cin >> S;
    map<char, int> mp;
    for (int i = 0; i < S.size(); i++) {
        // cout << S[i] << endl;
        mp[S[i]]++;
    }

    string ans = (mp.size() == 2) ? "Yes" : "No";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;

signed main(){
    int n; cin>>n;
    vector<int> c(n);
    rep(i,n) cin>>c.at(i);
    vector<int> cnt(n); int count=1;
    vector<vector<P>> sum(200000,vector<P>(0));
    rep(k,n){
        int i=c.at(k);
        int j=(int)sum.at(i-1).size();
        if(j>0){
            if(c.at(k-1)!=i) count=(count+cnt.at(sum.at(i-1).back().S))%mod;
        }
        sum.at(i-1).push_back(P(j,k));
        cnt.at(k)=count;
    }
    cout<<cnt.back()<<endl;
}

Measured memory_bytes: 14336
import sys


sys.setrecursionlimit(2**30)


def solve(i, x, y):
    global max_sub
    if i == N:
        max_sub = max(max_sub, x-y)
    else:
        solve(i+1, x+V[i], y+C[i])
        solve(i+1, x, y)


N = int(input())
V = [int(v) for v in input().split()]
C = [int(c) for c in input().split()]
max_sub = 0
solve(0, 0, 0)
print(max_sub)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

ll print_map_total(map<ll, ll> a) {
    ll total = 0;
    for(auto i = a.begin(); i != a.end(); ++i) {
        total += (i->first) * (i->second);
    }

    return total;
}

int main() {
    int n;
    cin >> n;
    map<ll, ll> a;

    int temp;
    rep(i, n) {
        cin >> temp;
        a[temp]++;
    }

    int q;
    cin >> q;
    vector<ll> b(q), c(q);
    rep(i, q) {
        cin >> b[i];
        cin >> c[i];
    }

    ll total = print_map_total(a);

    int henka = 0;
    rep(i, q) {
        // 消える数の個数を取得
        henka = a[b[i]];
        // 消す数の個数をCに追加
        a[c[i]] += henka;
        // 合計からb*(bの要素数)を引く
        total -= b[i] * henka;
        // 合計にC*(Cの要素数)を足す
        total += c[i] * henka;
        // bを削除
        a.erase(b[i]);
        cout << total << endl;
    }
}

Measured memory_bytes: 12704
#include <bits/stdc++.h>
#include <cstdlib> // abs(x-y)
#include <iomanip> // 出力の桁数指定
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
  int n;
  cin >> n;
  string ans = "No";
  
  rep (i, 1, 10) {
    rep (j, 1, 10) {
      if (n == i*j) {
        ans = "Yes";
      }
    }
  }
  cout << ans << endl;
}


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

typedef pair<int, int> pii;
const int N = 2e5 + 100;

int n, m, u, v, d[N][2];
bool done[N];
string s;
queue<int> q;
vector<pii> nei[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m >> s;
	while(m--) {
		cin >> u >> v;
		int c = (s[--u] == s[--v]);
		nei[u].push_back(pii(v, c));
		nei[v].push_back(pii(u, c));
	}
	for (int i = 0; i < n; i++)
		for (pii p: nei[i])
			d[i][p.second]++;
	for (int i = 0; i < n; i++)
		if(d[i][0] == 0 || d[i][1] == 0) {
			q.push(i);
			done[i] = true;
		}
	while(q.size()) {
		n--;
		v = q.front();
		q.pop();
		done[v] = true;
		for (pii p: nei[v]) {
			d[p.first][p.second]--;
			if(done[p.first] == false && (d[p.first][0] == 0 || d[p.first][1] == 0)) {
				done[p.first] = true;
				q.push(p.first);
			}
		}
	}
	cout << (n? "Yes": "No");
	return 0;
}

Measured memory_bytes: 13904
R,C,k = map(int,input().split())
dp1 = [[0]*(C+1) for i in range(R+1)]
dp2 = [[0]*(C+1) for i in range(R+1)]
dp3 = [[0]*(C+1) for i in range(R+1)]
for i in range(k):
    r,c,v = map(int,input().split())
    dp1[r][c] = v
for i in range(1,R+1):
    for j in range(1,C+1):
        a = dp1[i][j]
        dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1])
        dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1])
        dp1[i][j] = max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a)
print(max(dp1[R][C],dp2[R][C],dp3[R][C]))

Measured memory_bytes: 284864
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


int main(){
	int n,k;
	cin>>n>>k;
	int a[101010]={},dp[101010]={};
	FOR(i,0,n){
		cin>>a[i];
		dp[i]=mod;
	}
	dp[0]=0;
	FOR(i,0,n){
		FORQ(kk,1,k){
			if(i+kk<n)dp[i+kk]=min(dp[i+kk],dp[i]+abs(a[i+kk]-a[i]));
		}
	}
	cout<<dp[n-1]<<endl;
    return 0;
}


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

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

    priority_queue<int, vector<int>, greater<int>> Q;

    int counter = 0;
    rep(i, N){
        int p; cin >> p;
        Q.push(p);
        if(Q.top() == p)counter++;
    }

    cout << counter << endl;
}

Measured memory_bytes: 1400
package main

import (
	"fmt"
	"math"
)

func primep(n int) bool {
	if n == 2 {
		return true
	}

	m := int(math.Ceil(math.Sqrt(float64(n))))

	for k := 2; k <= m; k++ {
		if n%k == 0 {
			return false
		}
	}

	return true
}

func main() {
	var n int

	fmt.Scanf("%d", &n)

	nums := make([]int, n)

	for k := 0; k < n; k++ {
		fmt.Scanf("%d", &nums[k])
	}

	var answer int = 0
	for k := 0; k < n; k++ {
		if primep(nums[k]) {
			answer++
		}
	}

	fmt.Println(answer)
}



Measured memory_bytes: 1772
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  string s, ss;
  getline(cin, s);
  
  for(int i = 0; i < (int)s.size(); ++i){
    char ch = s[i];
    ss = s[i];
    if(isupper(ch)) {
      std::transform(ss.begin(), ss.end(), ss.begin(), ::tolower);
    }else if (islower(ch)) { 
      std::transform(ss.begin(), ss.end(), ss.begin(), ::toupper);
    }
    cout << ss;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

ll n, m;
ll res = 0;

int main(int argc, char *argv[]){
    cin >> n >> m;
    // if(m >= 2 * n){
    //     res = m - 2 * n;
    //     cout << n + res / 4 << endl;
    // }
    // else cout << m / 2 << endl;
    if (m >= 2 * n) cout << n + (m - 2 * n) / 4 << endl;
    else cout << m / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}


struct edge{
	int to;
	ll cost;
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<vector<edge>> g(n);
	rep(i,n - 1){
		int a,b,c;cin >> a >> b >> c;
		a--;
		b--;
		edge e1 = {b, c}, e2 = {a, c};
		g.at(a).pb(e1);
		g.at(b).pb(e2);
	}
	int q,k;cin >> q >> k;
	vector<ll> dist(n);
	k--;
	queue<pair<int,ll>> que;
	vector<bool> visited(n);
	visited.at(k) = true;
	que.push(mp(k,0));
	while(!que.empty()){
		int cur = que.front().first;
		ll sum = que.front().second;
		que.pop();
		rep(i,g.at(cur).size()){
			int next = g.at(cur).at(i).to;
			if(!visited.at(next)){
				visited.at(next) = true;
				dist.at(next) = sum + g.at(cur).at(i).cost;
				que.push(mp(next, sum + g.at(cur).at(i).cost));
			}
		}
	}
	rep(i,q){
		int x,y;cin >> x >> y;
		x--;y--;
		cout << dist.at(x) + dist.at(y) << endl;
	}
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		String current = "A";
		while ((line = br.readLine()) != null) {
			if (line.contains(current))
				current = line.replace(current, "").replace(",", "");
		}
		System.out.println(current);
	}
}

Measured memory_bytes: 16896
// 優先度付きキュー
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_H 2000000
// 無効な値の定義
const int INV = -1;

int parent(int i);
int leftNode(int i);
int rightNode(int i);

void buildPriorityQueue(int queue[], int size, int addElement);
int MaxPriorityQueue(int queue[], int size);

int main(void)
{
    char order[10];
    int size = 0, number;
    int priorityQueue[MAX_H];

    for(int i = 0; i < MAX_H; i++)
    {
        priorityQueue[i] = INV;
    }

    while( 1 )
    {
        cin >> order;

        if( strncmp("insert", &order[0] , 6) == 0 )
        {
            cin >> number;
            // キューを構築する
            buildPriorityQueue(&priorityQueue[0], size, number);
            size++;
        }
        else if( strncmp("extract", &order[0] , 7) == 0 )
        {
            // 最大値を返して, キューを再構築する
            cout << MaxPriorityQueue(&priorityQueue[0], size) << endl;
            size--;
        }
        else
        {
            // end が来た時
            break;
        }
    }

    return 0;
}

// 節点の親のNo.を返す関数
int parent(int i)
{
    return i / 2;
}

// 節点の左の子のNo.を返す関数
int leftNode(int i)
{
    return 2 * i;
}

// 節点の右の子のNo.を返す関数
int rightNode(int i)
{
    return ( 2 * i ) + 1;
}

// 優先度付きキューを構築する関数
void buildPriorityQueue(int queue[], int lastNo, int addElement)
{
    bool cmpFlag = true;
    int parentNo;

    if( lastNo == 0 )
    {
        queue[1] = addElement;

        return;
    }

    // [キューの最後尾 + 1]に要素を追加して, 上に上がっていく
    lastNo++;
    queue[lastNo] = addElement;

    while( cmpFlag == true )
    {
        cmpFlag = false;

        parentNo = parent(lastNo);

        if( parentNo <= 0 )
        {
            // ルートの要素まで来たら, 処理は終了
            break;
        }

        if( queue[lastNo] > queue[parentNo] )
        {
            // 親の値よりも大きければ交換する
            swap(queue[lastNo], queue[parentNo]);
            lastNo = parentNo;

            cmpFlag = true;
        }
    }

    return;
}

// 最大値を返して, 優先度付きキューを再構築する関数
int MaxPriorityQueue(int queue[], int lastNo)
{
    bool cmpFlag = true;
    int eleNum = 0, leftNo = 0, rightNo = 0;
    int cmpNo;

    int max = queue[1];

    if( lastNo < 0 )
    {
        // 要素が存在しない時は, 無効値を返す
        return INV;
    }

    // 最後の要素を先頭に持ってくる
    queue[1] = queue[lastNo];
    queue[lastNo] = INV;
    eleNum = 1;

    // 先頭に移動させた最後尾の要素を, 下に下ろしていく
    while( cmpFlag == true )
    {
        cmpFlag = false;

        leftNo = leftNode(eleNum);
        rightNo = rightNode(eleNum);

        // 節点の兄弟のうち, 値の大きい方と比較する
        if( queue[leftNo] >= queue[rightNo] )
        {
            cmpNo = leftNo;
        }
        else
        {
            cmpNo = rightNo;
        }

        if( cmpNo < lastNo
            && queue[cmpNo] > queue[eleNum] )
        {
            cmpFlag = true;
            // 節点の兄弟のうち, 値の大きい方と比較する
            swap(queue[cmpNo], queue[eleNum]);
            eleNum = cmpNo;
        }
    }

    return max;
}



Measured memory_bytes: 10892
function Main(input){
  input = input.trim().split(' ').map(x=>parseInt(x));
  anis = input[0];
  legs = input[1];
  var ans = 'No'
  for (i=0;i<=anis;i++){
    if (i*2 + (anis-i)*4 === legs){
      ans = 'Yes';
      break;
    }
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29628
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
long long W,a,b;
int main(){
	cin>>W>>a>>b;
	long long R=0;

	if((a+W)<b) R = b-(a+W);
	else if((b+W)<a)R = a-(b+W);

	cout<<R<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

const int N = 1e5 + 10;
vpii adj[N];
int ans[N];

void dfs(int v, int p, int c)
{
    int l = 1;
    for(auto [u, id] : adj[v])
    {
        if(u == p) continue;
        if(l == c) ++l;
        ans[id] = l;
        dfs(u, v, l++);
    }
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int n; cin >> n;

    for(int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].emplace_back(b, i);
        adj[b].emplace_back(a, i);
    }

    dfs(1, 1, 0);
    
    cout << *max_element(ans + 1, ans + n) << endl;
    for(int i = 1; i < n; i++)
        cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 12468
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String answer = "";
    
    if(n == 0){
      System.out.println("0");
      return ;
    }
    while(n != 1){
      answer = Integer.toString(((n % (-2)) == -1)?1:n%(-2)) + answer;
      n = div(n);
    }
    System.out.println("1" +answer);
  }
  
  public static int div(int a){
    if(a<0 && a%2 != 0) return a/(-2) +1;
    else return a/(-2);
  }
}

Measured memory_bytes: 23124
import itertools
n = int(input())  # nは入力回数
#num_list = [int(input()) for _ in range(n)]
ans = 0

set_m = set()
set_a = set()
set_r = set()
set_c = set()
set_h = set()

for i in range(n):
    s = input()
    if s[0] == "M":
        set_m.add(s)
    if s[0] == "A":
        set_a.add(s)
    if s[0] == "R":
        set_r.add(s)
    if s[0] == "C":
        set_c.add(s)
    if s[0] == "H":
        set_h.add(s)

l_m = len(set_m)
l_a = len(set_a)
l_r = len(set_r)
l_c = len(set_c)
l_h = len(set_h)

l_l = [l_m,l_a,l_r,l_c,l_h]

comb_list = list(itertools.combinations(l_l,3))

for i in range(len(comb_list)):
    ans += comb_list[i][0]*comb_list[i][1]*comb_list[i][2]

print(ans)

Measured memory_bytes: 25848
# -*- coding: utf-8 -*-
import sys
from collections import deque
N,Q=map(int, sys.stdin.readline().split())

al=[ [] for _ in range(N+1) ]	#隣接リスト
for _ in range(N-1):
	u,v=map(int, sys.stdin.readline().split())
	al[u].append(v)
	al[v].append(u)

increment=[ 0 for _ in range(N+1) ]
for _ in range(Q):
    p,x=map(int, sys.stdin.readline().split())
    increment[p]+=x

#BFS
visit=[ 0 for _ in range(N+1) ] #訪問した頂点
q=deque()
q.append((0,1)) #親,自分
visit[1]=1

score=[ 0 for _ in range(N+1) ] #各頂点のカウンターの値を記録
point=0

while q:
    par,cur=q.popleft()
    score[cur]=score[par]+increment[cur]    #自分のカウンターの値は、親の値+自分のところでの増加分
    for to in al[cur]:
        if visit[to]==0:
            visit[to]=1
            q.append((cur,to))

for i in range(1,N+1):
    print score[i],

Measured memory_bytes: 79644
import itertools
import copy
deta = [0,1]

h,w,k1 = map(int,input().split())

c = [list(input()) for _ in range(h)]

#print(c)

h1 = list(itertools.product(deta, repeat=h))
w1 = list(itertools.product(deta, repeat=w))

count = 0

for i in h1:
    for j in w1:
        c1 = copy.deepcopy(c)
        for k in range(h):
            if i[k] == 1:
                for l in range(w):
                    c1[k][l] = '.'
        for l in range(w):
            if j[l] == 1:
                for k in range(h):
                    c1[k][l] = '.'
        #print(c1)

        temp = 0
        for k in range(h):
            for l in range(w):
                if c1[k][l] == "#":
                    temp += 1
        if temp == k1:
            count += 1

print(count)


Measured memory_bytes: 9264
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int a,b;
  cin >> a >> b;

  cout << (a<=b ? a : a-1) << endl;
  return 0;
} 

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

using LL = long long;

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

    string N(4, '0');
    cin >> N;

    if(N[0] == N[1] && N[1] == N[2]){
        cout << "Yes" << endl;
        return 0;
    }

    if(N[1] == N[2] && N[2] == N[3]){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import sys

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    S = [input() for i in range(N)]
    MARCH = 'MARCH'
    dic = {
        'M': 0,
        'A': 0,
        'R': 0,
        'C': 0,
        'H': 0
    }
    for i in range(N):
        if S[i][0] in dic:
            dic[S[i][0]] += 1

    ans = 0

    for i in range(3):
        for j in range(i+1, 4):
            for k in range(j+1, 5):
                ans += dic[MARCH[i]]*dic[MARCH[j]]*dic[MARCH[k]]

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 80096
#include<iostream>
#include<bitset>
#include<algorithm>
#include<vector>
#include<cstdio>
#define MAX 50001
using namespace std;
struct Query
{
  int A,B,order;
  Query(int A=-1,int B=-1,int order=-1):A(A),B(B),order(order){}
};
int r,c,q;
bool used[2][MAX];
Query queries[MAX];

int main()
{
  while(true)
    {
      scanf("%d %d %d",&r,&c,&q);
      if(r+c+q == 0)break;
      for(int i=0;i<r;i++)used[0][i] = false;
      for(int j=0;j<c;j++)used[1][j] = false;

      for(int i=0;i<q;i++)
	scanf("%d %d %d",&queries[q-(i+1)].A,&queries[q-(i+1)].B,&queries[q-(i+1)].order);
	
      int ru,rd,cu,cd,total;
      ru = rd = cu = cd = total = 0;

      for(int i=0;i<q;i++)
	{
	  Query qw = queries[i];
	  if(used[qw.A][qw.B])continue;
	  used[qw.A][qw.B] = true;

	  if(qw.order)
	    {
	      if(!qw.A)
		{
		  total += c - (ru+rd);
		  cu++;
		}
	      else 
		{
		  total += r - (cu+cd);
		  ru++;
		}
	    }
	  else
	    {
	      if(!qw.A)
		  cd++;
	      else 
		  rd++;
	    }
	}
      printf("%d\n",total);
    }
  return 0;
}

Measured memory_bytes: 1872
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String day = sc.next();
		
		int result = 0;
		if ("SUN".equals(day)) result = 7;
		if ("MON".equals(day)) result = 6;
		if ("TUE".equals(day)) result = 5;
		if ("WED".equals(day)) result = 4;
		if ("THU".equals(day)) result = 3;
		if ("FRI".equals(day)) result = 2;
		if ("SAT".equals(day)) result = 1;
		
		System.out.println(result);
		
		
	}
}


Measured memory_bytes: 21076
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

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

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> L(N);
  FOR(i, N) cin >> L[i];
  sort(ALL(L));
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N - 1; ++j) {
      int a = L[i], b = L[j];
      int mn = max(a - b, b - a);
      int mx = a + b;
      auto low = upper_bound(L.begin() + j, L.end(), mn);
      auto high = lower_bound(L.begin() + j, L.end(), mx) - 1;
      ans += high - low;
      // debug(i, j, a, b, mn, mx, low - L.begin(), high - L.begin());
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 
//Available in Snips
#define fi(i, x, y)   for (__typeof(x) i = x; i < y; i ++)
#define fir(i, x, y)  for (__typeof(x) i = x; i > y; i --)
#define fv(x)   for (auto itr = x.begin(); itr != x.end(); itr ++)
#define fvr(x)  for (auto itr = x.end() - 1; itr != x.begin() - 1; itr --)
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//codell here
	int n,m;
	cin >> n>>m;
	vi a(n,-1);
	while(m--){
		int i,v;
		cin >> i >> v;
		i =i-1;
		if(a[i]!=-1 and a[i]!=v){
			cout << -1;
			return 0;
		}
		a[i] = v;
	}
	if(n!=1){
		if(a[0]==0){
			cout << -1;
			return 0;
		}
	
		if(a[0]==-1){
			a[0]=1;
		}
		
		for(int i=1;i<n;i++){
			if(a[i]==-1){
				a[i]=0;
			}
		}
	}
	else {
		if(a[0]==-1){
			cout << 0;
			return 0;
		}
	}

	for(int x:a){
		cout<<x;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstring>
#define ll long long
#define INF 1000000000
#define For(i,a,b) for(int i=a;i<=b;++i)
#define Rev(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define pq priority_queue
#define PI acos(-1)

namespace IO
{
#define p(x) ('0'<=x&&x<='9')
	char cc; int C;
	template <class T>
	void read( T &x )
	{
		x=0; cc=getchar(); C=1;
		while(!p(cc)) { if(cc=='-') C=-1; cc=getchar(); }
		while(p(cc)) { x=x*10+cc-48; cc=getchar(); }
		x*=C;
	}
#undef p
}

using namespace IO;
using namespace std;

bool p(int n)
{
	if(n==111||n==222||n==333||n==444||n==555||n==666||n==777||n==888||n==999) return 1;
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	srand(time(0));
#ifdef LOCAL
	freopen("./tmp/input.txt", "r", stdin);
#endif

	int n;
	read(n);

	while(n)
	{
		if(p(n)) break;
		++n;
	}
	cout << n << endl;


	return 0;
}


Measured memory_bytes: 632
N=int(input())
a=0
b=0
ab=0
ans=0
for _ in range(N):
    s=input()
    ans+=s.count('AB')
    if s[0]=='B' and s[-1]=='A':
        ab+=1
    elif s[0]=='B':
        b+=1
    elif s[-1]=='A':
        a+=1
if ab==0:
    print(ans+min(a,b))
else:
    if a==0 and b==0:
        print(ans+ab-1)
    else:
        print(ans+min(a+ab,b+ab))


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

int main(){
    unsigned long a,b,x;
    cin >> a >> b;

    x = a * b;

    if(a < b){
        unsigned long tmp;
        tmp = a;
        a = b;
        b = tmp;
    }

    unsigned long r;
    r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }

    cout << x / b << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int count = 0;

		if( B - A * C >= 0) {
			count = C;
			System.out.println(count);
		}
		if(B - A * C < 0 && B >= A) {
			count = B / A;
			System.out.println(count);
		}
		if(B - A * C < 0 && B < A) {
			count = 0;
			System.out.println(count);
		}
	}

}


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

using namespace std;
#define ll long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define f(i,l,u) for(ll i=l;i<u;i++)

unsigned long long fac[2000001]; 

// A modular inverse based solution to 
// compute nCr % p 

/* Iterative Function to calculate (x^y)%p 
in O(log y) */
unsigned long long power(unsigned long long x, 
						ll y, int p) 
{ 
	unsigned long long res = 1; // Initialize result 

	x = x % p; // Update x if it is more than or 
	// equal to p 

	while (y > 0) { 
		// If y is odd, multiply x with result 
		if (y & 1) 
			res = (res * x) % p; 

		// y must be even now 
		y = y >> 1; // y = y/2 
		x = (x * x) % p; 
	} 
	return res; 
} 
void powe(ll p)
{
    	
	fac[0] = 1; 
	for (int i = 1; i <= 2000000; i++) 
		fac[i] = (fac[i - 1] * i) % p; 
    
    
}
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
	return power(n, p - 2, p); 
} 

// Returns nCr % p using Fermat's little 
// theorem. 
unsigned long long nCrModPFermat(unsigned long long n, 
								int r, int p) 
{ 
	// Base case 
	if (r == 0) 
		return 1; 

	// Fill factorial array so that we 
	// can find all factorial of r, n 
	// and n-r 


	return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 




int main() {
    ll k;
    cin>>k;
    string s;
    cin>>s;
    ll n=s.length();
    powe(1000000007);
    ll ans=0;
    f(i,0,k+1)
    {
        ll val=nCrModPFermat(n+k-1-i,n-1,1000000007);
        val=(((val*power(25,k-i,1000000007))%1000000007)*(power(26,i,1000000007)))%1000000007;
        ans=(ans+val)%1000000007;
        
        
        
        
    }
    
 cout<<ans<<endl;   
    
    
    
    
    return 0;
}


Measured memory_bytes: 20072
#include <iostream>

using namespace std;

int get_pattern(int A,int B,int C,int X);

int main(){
int A,B,C,X,ans;
// 入力
// cout << "input A\n";
cin >> A;
// cout << "input B\n";
cin >> B;
// cout << "input C\n";
cin >> C;
// cout << "input X\n";
cin >> X;

try{
    if((A < 0 || A > 50) \
    || (B < 0 || B > 50) \
    || (C < 0 || C > 50) \
    || (X < 50 || X > 20000) \
    || (A+B+C <1) \
    || (X%50 != 0))
    throw "input error";
  }

catch(const char* err){
  cout << "エラー:" << err << '\n';
  return 1;
  }

ans=get_pattern(A,B,C,X);
cout << ans << endl;

return 0;
}


int get_pattern(int A,int B,int C,int X)
{
  int re500,re100,i,j,k,count,temp1,temp2;

  temp1 = temp2 = count = 0;
  re500 = min(X/500,A) + 1;

  for(i=0; i<re500; i++){
    temp1 = X - 500*i;
    re100 = min(temp1/100,B) + 1;
    for(j=0; j<re100; j++){
      temp2 = temp1 - 100*j;
      if((temp2%50==0) && (temp2/50<=C))
        count++;
    }
  }
  return count;
}


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

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    
    double max = 0;
    int max_water = 0, max_sugar = 0;
    for(int i = 0; 100*a*i <= f ; ++i) {
        for(int j = 0; 100*a*i + 100*b*j <= f; ++j) {
            double water = 100*a*i + 100*b*j;
            if(water == 0) continue;
            double sugar_limit = min(f - water, e * water/100);
            
            for(int p = 0; c*p <= sugar_limit; ++p) {
                for(int q = 0; c*p + d*q <= sugar_limit; ++q) {
                    double sugar = c*p + d*q;
                    if(max <= sugar/(sugar + water)) {
                        max = sugar/(sugar + water);
                        max_water = water;
                        max_sugar = sugar;
                    }
                }
            }
        }
    }
    
    cout << max_water + max_sugar << " " << max_sugar << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

vector<vector<int>> edges;
vector<int> father;
int cant(int from) {
	int res = 0;
	
	bool hasPalito = false;
	for (int neigh : edges[from]) if (neigh != father[from]) {
		father[neigh] = from;
		int cur = cant(neigh);
		res += max(1, cur);
		hasPalito |= (cur == 0);
	}
	
	return res - hasPalito;
}

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

	int n; cin >> n;
	edges = vector<vector<int>>(n, vector<int>());
	father = vector<int>(n, -1);
	
	forn(i,n-1) {
		int a, b; cin >> a >> b;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	int rootFrom = 0;
	forn(i,n) if (edges[i].size() > edges[rootFrom].size()) rootFrom = i;
	
	cout << max(1, cant(rootFrom)) << endl;
}


Measured memory_bytes: 12288
a=gets.chomp.to_i
b=gets.chomp.split.map(&:to_i)
d=gets.chomp.split.join.to_i

c=b.permutation(a).to_a
h=0
c.each do |x|
  c[h]=x.join.to_i
  h+=1
end
c=c.sort
b=b.join.to_i
v=c.index(b)
n=c.index(d)
if v-n>0
  puts v-n
else puts n-v
end


Measured memory_bytes: 9848
import qualified Data.ByteString.Lazy.Char8 as B
import           Data.Char
import qualified Data.IntMap.Strict         as M
import           Data.List

main :: IO ()
main = do
  getLine
  as <- unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getContents
  print $ solve as

solve :: [Int] -> Int
solve = M.foldl' (+) 0
    . fmap (\x -> x * (x - 1) `div` 2)
    . foldl' (\mp x -> M.insertWith (+) x 1 mp) (M.singleton 0 0)
    . scanl' (+) 0

Measured memory_bytes: 41212
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

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

    int n,k; cin >> n >> k;
    VI x(n); REP(i,n) cin >> x[i];
    int ans = 0; REP(i,n) ans += min(x[i]*2,abs(k-x[i])*2);
    out(ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
  int X;
  cin >> X;

  int i, j;

  if(X == 2){
    cout << "2" << endl;
    return 0;
  }
  while(1){
    j=3;
    if(X%2 == 0)
      X++;
    else{
      while(X%j != 0)
	j += 2;
      if(j>=X)
	break;
      X++;
    }
  }

  cout << X << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?9e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	ll out=1;
	rep(i,n){
		int a;cin>>a;
		if(a%2);
		else out*=2;
	}
	ll t=1;
	rep(i,n)t*=3;
	cout<<t-out<<endl;
}
















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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(){
    ll n;
    cin >> n;
    vector<ll> a(n), x(n,0);
    for (ll i = 0; i < n; i++) cin >> a[i];
    ll sum = 0;
    for (ll i = 0; i < n; i++) sum += a[i];
    x[0] = sum;
    for (ll i = 1; i < n - 1; i+=2) x[0] -= 2 * a[i];
    for (ll i = 0; i < n - 1; i++) {
        x[i + 1] = 2 * a[i] - x[i];
    }
    for (ll i = 0; i < n; i++) cout << x[i] << " \n"[i == n - 1];
}

Measured memory_bytes: 4812