akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int val(char c) {
    if (c == 'I') return 1;
    if (c == 'V') return 5;
    if (c == 'X') return 10;
    if (c == 'L') return 50;
    if (c == 'C') return 100;
    if (c == 'D') return 500;
    if (c == 'M') return 1000;
    return 0;
}

int main() {
    string s;
    while (getline(cin, s)) {
        int a = 0;
        rep (i, s.size()) {
            if (i+1 < (int)s.size() && val(s[i]) < val(s[i+1])) a -= val(s[i]);
            else a += val(s[i]);
        }
        printf("%d\n", a);
    }
    return 0;
}

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

int main(void) {
    int N, K;
    cin >> N >> K;
    map<int, int> A;
    REP(i, N) {
        int t;
        cin >> t;
        A[t]++;
    }
    vector<int> v;
    for(auto x : A) {
        v.push_back(x.second);
    }
    sort(v.rbegin(), v.rend());
    int ans = 0;
    for(int i=K; i<=v.size(); ++i) {
        ans += v[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 10748
#include <iostream>
#include <vector>

using namespace std;

const int INF = 2147483647;

struct SegmentTree {
    int n;
    vector<int> heap;
    
    SegmentTree(int n): n(n) {
        heap.assign(4 * n, INF);
    }
    
    void update(int nodeId, int l, int r, int ql, int qr, int v) {
        if (qr < l || ql > r) {
            return;
        }
        else if (ql <= l && r <= qr) {
            heap[nodeId] = v;
        }
        else {
            pushdown(nodeId);
            int m = l + (r - l)/2;
            update(nodeId * 2, l, m, ql, qr, v);
            update(nodeId * 2 + 1, m + 1, r, ql, qr, v);
        }
    }
    
    int query(int nodeId, int l, int r, int q) {
        if (q < l || q > r) {
            return -1;
        }
        else if (heap[nodeId] != -1) {
            return heap[nodeId];
        }
        else {
            int m = l + (r - l)/2;
            return max(query(nodeId * 2, l, m, q), query(nodeId * 2 + 1, m + 1, r, q));
        }
    }
    
    void pushdown(int nodeId) {
        //cout << "push: " << nodeId << endl;
        if (heap[nodeId] != -1) {
            heap[nodeId * 2] = heap[nodeId];
            heap[nodeId * 2 + 1] = heap[nodeId];
            heap[nodeId] = -1;   
        }
    }
    
};

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree st(n);
    for (int i = 0; i < q; i++) {
        int cmd;
        cin >> cmd;
        if (cmd == 0) {
            int ql, qr, v;
            cin >> ql >> qr >> v;
            st.update(1, 0, n -1, ql, qr, v);
//            for (int i = 0; i < 4 * n; i++) {
//                cout << i << ":" << st.heap[i] << endl; 
//            }
        }
        else {
            int pos;
            cin >> pos;
            cout << st.query(1, 0, n-1, pos) << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 4424
// 27
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) \
  for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) \
  for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef LOCAL
#define debug(e)                             \
  cerr << "\033[48;5;196m\033[38;5;15m" << e \
       << "\033[0m";
#else
#define debug(e)
#endif
// 4
template <class A, class B>
ostream &operator<<(ostream &o, const pair<A, B> &p) {
  return o << "(" << p.fi << " " << p.se << ")";
}
// 8
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  rep(i, (int)v.size()) o << setw(7) << left << v[i];
  return o << endl;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &o, const map<A, B> &m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 3
void _main(int tc) {
  int w, h, n;
  cin >> w >> h >> n;
  int top = h, bottom = 0, left = 0, right = w;
  rep(i, n) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      left = max(left, x);
    } else if (a == 2) {
      right = min(right, x);
    } else if (a == 3) {
      bottom = max(bottom, y);
    } else {
      top = min(top, y);
    }
  }
  debug(left << " " << w - right << " " << bottom << " " << h - top << endl);
  w -= (left + (w - right));
  h -= (bottom + (h - top));
  debug(w << " " << h << endl);
  cout << max(0, w) * max(0, h) << endl;

}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>
using namespace std;
int read()
{
	char ch=getchar();
	int num=0,flus=1;
	while(ch<'0'||ch>'9')
	{if(ch=='-') flus=-flus;ch=getchar();}
	while(ch>='0'&&ch<='9')
	{num=num*10+ch-'0';ch=getchar();}
	return num*flus;
}
const int MAXN=2e5+2e2;
struct node{
	int nxt,to;
};
node edge[MAXN];
int head[MAXN];
int depth[MAXN];
int Max[MAXN];
int n,s,t,maxn,tot;
void addedge(int u,int v)
{
	edge[++tot].nxt=head[u];
	edge[tot].to=v;
	head[u]=tot;
	return;
}
void dfs(int u,int last)
{
	Max[u]=depth[u]=depth[last]+1;
	for(int i=head[u];i;i=edge[i].nxt)
	{
		int v=edge[i].to;
		if(v!=last)
		{
			dfs(v,u);
			Max[u]=max(Max[u],Max[v]);
		}
	}
	return;
}
int Dfs(int u,int now,int last)
{
	if(now>=depth[u]) return 0;
	for(int i=head[u];i;i=edge[i].nxt)
	{
		int v=edge[i].to;
		if(v==last) continue;
		if(!Dfs(v,now+1,u))
			maxn=u;
	}
	return 1;
}
void DFS()
{
	dfs(t,0);
	Dfs(s,0,0);
	return;
}
int main(void)
{
	//freopen("working.in","r",stdin);
	//freopen("working.out","w",stdout);
	scanf("%d%d%d",&n,&s,&t);
	for(int i=1,u,v;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	DFS();
	printf("%d\n",Max[maxn]-2);
	return 0;
}

Measured memory_bytes: 6784
local n=io.read("*n")
local a={}
for i=1,n do
    local number=io.read("*n")
    if not a[number] then
        a[number]=1
    else
        a[number]=a[number]+1
    end
end

local total=0
for i,j in pairs(a) do
    if i<j then
        total=total+j-i
    elseif i>j then
        total=total+j
    end
end
print(total)

Measured memory_bytes: 5044
#include <iostream>

u_int getDigit(u_int n){
	u_int count = 1;
	
	while(n / 10 != 0){
		n /= 10;
		++count;
	}
	
	return count;
}
  
int main(){
    u_int a, b;
    
    while(std::cin >> a >> b){
        std::cout << getDigit(a + b) << std::endl;
    }
	
    return 0;
}

Measured memory_bytes: 3080
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n);
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); ++i)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)          (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)          (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define mp                  make_pair
#define pb                  push_back

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

void solve(vector<pair<int,int> > &v){
    int n[110];
    memset(n, 0, sizeof(n));
    int max = 0;
    FOREACH(it, v){
        n[it->first]++;
        n[it->second]++;
        max = MAX(max, it->first);
        max = MAX(max, it->second);
    }
    for(int i = 3; i <= max; i++){
        if(n[i] % 2 == 1){
            cout << "NG" << endl;
            return;
        }
    }
    if((n[1] % 2 == 1) && (n[2] % 2 == 1)){
        cout << "OK" << endl;
        return;
    }
    cout << "NG" << endl;
}

int main(){
    vector<pair<int,int> > v;
    int a, b;
    while(cin >> a >> b){
        if(a == 0 && b == 0){
            solve(v);
            v.clear();
            continue;
        }
        v.pb(mp(a,b));
    }
    if(!v.empty()) solve(v);
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    
    unsigned long long N,m=0,a=0,r=0,c=0,h=0;
    cin >>N;
    vector<string> S(N);
    for(int i=0;i<N;i++){
        cin >>S[i];
        if(S[i][0]=='M'){
            m++;
        }
        if(S[i][0]=='A'){
            a++;
        }
        if(S[i][0]=='R'){
            r++;
        }
        if(S[i][0]=='C'){
            c++;
        }
        if(S[i][0]=='H'){
            h++;
        }
    }
    
    cout <<(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h);

    return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

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

  long long n, m, l;
  cin >> n >> m >> l;
  vector<vector<ll> > flo(n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j){
        flo[i].push_back(0ll);
      }else{
        flo[i].push_back(INF);
      }
    }
  }
  long long a, b, c;
  for(int i=0;i<m;i++){
    cin >> a >> b >> c;
    a--; b--;
    if(l>=c){
      flo[a][b] = min(flo[a][b], c);
      flo[b][a] = min(flo[b][a], c);
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        flo[j][k] = min(flo[j][k], flo[j][i]+flo[i][k]);
      }
    }
  }

  //refuel[i][j] := 地点iから地点jに行くときの最小給油回数+1
  vector<vector<ll> > refuel(n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i == j){
        refuel[i].push_back(0ll);
      }else{
        refuel[i].push_back(INF);
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i == j) continue;
      if(flo[i][j] <= l){
        refuel[i][j] = min(refuel[i][j], 1ll);
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        refuel[j][k] = min(refuel[j][k], refuel[j][i]+refuel[i][k]);
      }
    }
  }

  long long q, s, t;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> s >> t;
    s--; t--;
    if(refuel[s][t] == INF){
      cout << "-1\n";
    }else{
      cout << refuel[s][t]-1 << "\n";
    }
  }
  return 0;
}


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

using namespace std;
typedef long long ll;

const int MAXN = 100005;

int n, m;
vector<int> g[MAXN];

bool hv[MAXN];
int val[MAXN];
bool rng[MAXN];
int L[MAXN], R[MAXN];

void input()
{
	scanf("%d", &n);
	for(int i = 1; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	scanf("%d", &m);
	for(int i = 1; i <= m; i++)
	{
		int x, v;
		scanf("%d%d", &x, &v);
		hv[x] = 1;
		val[x] = v;
	}
}

bool getrng(int x, int p)
{
	for(auto y: g[x])
	{
		if(y == p) continue;
		if(!getrng(y, x))
			return 0;
		if(rng[y])
		{
			int l = L[y] - 1;
			int r = R[y] + 1;
			if(rng[x])
			{
				if(R[x] < l || L[x] > r || ((L[x] + l) & 1))
					return 0;
				L[x] = max(l, L[x]);
				R[x] = min(r, R[x]);
			}
			else
			{
				rng[x] = 1;
				L[x] = l;
				R[x] = r;
			}
		}
	}
	if(hv[x])
	{
		if(rng[x] && (L[x] > val[x] || val[x] > R[x] || ((L[x] + val[x]) & 1)))
			return 0;
		rng[x] = 1;
		L[x] = R[x] = val[x];
	}
	return 1;
}

void getval(int x, int p)
{
	if(x == 1)
		val[x] = L[x];
	else
	{
		if(L[x] <= val[p] - 1)
			val[x] = val[p] - 1;
		else
			val[x] = val[p] + 1;
	}
	for(auto y: g[x])
		if(y != p)
			getval(y, x);
}

bool ok;

void solve()
{
	ok = getrng(1, 0);
	if(ok) getval(1, 0);
}

void output()
{
	if(ok)
	{
		puts("Yes");
		for(int i = 1; i <= n; i++)
			printf("%d\n", val[i]);
	}
	else puts("No");
}

int main()
{
	input();
	solve();
	output();

	return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException{
		String input = new BufferedReader(new InputStreamReader(System.in)).readLine();
		String s1 = input.substring(0,1);
		String s2 = input.substring(1,2);
		String s3 = input.substring(2,3);
		int day = 0;
		
		if(s1.equals("R")) {
			day = 1;
			if(s2.equals("R")) {
				day = 2;
				if(s3.equals("R")) {
					day = 3;
				}	
			}
		}
		else if(s2.equals("R")) {
			day = 1;
			if(s3.equals("R")) {
				day = 2;
			}	
		}
		else if(s3.equals("R")) {
			day = 1;
		}

		System.out.println(day);

	}

}

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

int main()
{
  vector<int> A;
  int N, count = 0;

  scanf("%d", &N);
  for (int k = 0; k < N; k++)
  {
    int num;
    
    scanf("%d", &num);
    A.push_back(num);
  }

  while (1)
  {
    for (int k = 0; k < N; k++)
    {
      if (A[k] % 2 == 0) 
      {
        A[k] = A[k] / 2;
      }
      else
      {
        printf("%d\n", count);
        return 0;
      }
    }
    count++;
  }

}

Measured memory_bytes: 256
import itertools
N = int(input())
nums = map(int, input().split(" "))
num_comb = list(itertools.combinations(nums, 3))

counter = 0
for _nums in num_comb:
    nums = list(_nums)
    nums.sort()
    n_pure = len(set(nums))
    # print(nums, n_pure)
    if (nums[0] + nums[1] > nums[2]) & (n_pure == 3):
        counter += 1
        
print(counter)
    

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> H(A), W(B);
  int mh = 0, mw = 0;
  set<pair<int, int>> S;
  for (int h, w; cin >> h >> w;) {
    mh = max(mh, ++H.at(--h)), mw = max(mw, ++W.at(--w));
    S.insert({h, w});
  }
  int cnt = 0;
  for (auto [h, w] : S) if (H.at(h) == mh && W.at(w) == mw) cnt++;
  int tmp = count(H.begin(), H.end(), mh) * count(W.begin(), W.end(), mw);
  cout << mh + mw - (cnt == tmp) << "\n";
}

Measured memory_bytes: 19640
#include "iostream"
#include "map"
#include "vector"
#include "algorithm"

using namespace std;

int n;
string s;

int main() {
    cin >> n >> s;

    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == 'W') {
            cnt++;
        }
    }

    int v_min = cnt;

    for (int i = n - 2; i >= 0; i--) {
        if (s[i] == 'W') {
            cnt--;
        }
        if (s[i + 1] == 'E') {
            cnt++;
        }

        v_min = min(v_min, cnt);
    }

    cout << v_min << endl;
}

Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    int a,b,c; cin >> a>>b>>c;
    int ans = 0;
    for(int i=a; i <= b; i++){
        if(c % i == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
char laz[maxn];
int pi[12*maxn],c[2];
int prefix_function(const string &s,const string &t) {
    ///search t on s
    int m=(int)t.length();
    int n = t.length()+s.length()+1;
    auto ss=[&](int idx){
        if(idx==m)return '#';
        if(idx<m)return t[idx];
        return s[idx-m-1];
    };
    pi[0]=0;
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && ss(i) != ss(j))
            j = pi[j-1];
        if (ss(i) == ss(j))
            j++;
        pi[i] = j;
    }
    int ma=-1;
    for(int i=n-1;i>m;i--){
        pi[i]=(pi[i]==m?1:0);
        if(i+m<n&&pi[i]==1){
            pi[i]+=pi[i+m];
        }
        ma=max(ma,pi[i]);
    }
    return ma;
}
string s,t,a,ss,tt;
/**
There exists a non-negative integer j
such that the concatenation of i copies of t
is a substring of the concatenation of j copies of s.
*/


int main(){
    scanf("%s",laz);
    ss=string(laz);
    scanf("%s",laz);
    t=string(laz);
    s=ss;
    while((int)s.length()<=(int)t.length()+(int)ss.length()){
        s+=ss;
    }
    s+=ss;
    int c=prefix_function(s,t);
    if(c==-1){
       return !printf("0");
    }
    s+=s;
    int cc=prefix_function(s,t);
    if(cc==c){
        return !printf("%d\n",cc);
    }
    else{
        return !printf("-1");
    }
}
/*
    Good Luck
        -Lci70121
*/


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

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

int main() {
    int n;cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    sort(a,a+n,greater<int>());
    
    int a1=0,b1=0;
    
    rep(i,n){
        if(i%2==0)a1+=a[i];
        else b1+=a[i];
    }
    cout<<a1-b1<<endl;

	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut map = HashMap::new();
    let mut vec = Vec::new();
    for _i in 0..n {
        let count = map.entry(read::<u32>()).or_insert(0);
        *count += 1;
    }

    for (key, value) in map.iter() {
        if value % 2 == 1 {
            vec.push(key);
        }
    }
    println!("{}",vec.len());
}


Measured memory_bytes: 8444
s = int(input())
mod = 10**9 + 7

# dp[i]: 最後に切った場所がi
dp = [0]*(s + 1)
dp[0] = 1

for i in range(1, s+1):
    for j in range(0, (i-3)+1):
        dp[i] += dp[j]
        dp[i] %= mod

print(dp[s])

Measured memory_bytes: 64820
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i,l,h) for(ll i=l;i<h;i++)
#define fr(i,h,l) for(ll i=h;i>=l;i--)

using namespace std;

typedef pair<ll,ll> pll;
const ll INF=(ll)(1e9+7);
typedef vector<ll> vll;

ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1) res=res*a;

        a=a*a;
        b>>=1;
    }
    return res;
}

int main()
{
    ll x;
    cin>>x;
    ll a,b;
    bool flag=true;
    for(ll i=-1000;i<=1000 && flag;i++){
        for(ll j=-1000;j<=1000 && flag;j++){
            if(power(i,5)-power(j,5)==x){
                a=i;
                b=j;
                flag=false;
            }
        }
    }
    cout<<a<<" "<<b<<endl;
}


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

int main(){
    
    int n;
    cin >> n;
    vector<int> l(n);
    int maxv = 0;
    for(int i=0; i<n; i++){
        cin >> l.at(i);
        if(maxv < l.at(i)){
            maxv = l.at(i);
        }
    }
    if(maxv < accumulate(l.begin(),l.end(),0)-maxv){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

int
main() {
  int n,k;
  vector<int> w;

  cin >> n >> k;
  for (int i=0;i<n;++i) {
    int t;
    cin >> t;
    w.push_back(t);
  }

  // naive algorithm;
  // increment p ...
  uint64_t m = accumulate(begin(w), end(w), 0);
  auto est_p = (m / k);
  // cout << "est_p " << est_p << endl;
  
  auto calc = [](vector<int> & xs, int k, int p) -> bool{
    int wi=0;
    int i=0;
    for (; i<k; ++i) {
      int v = p;
      // cout << "wi = " << wi << " v = " << v << endl;
      while ( v - xs[wi] >= 0) {

	v -= xs[wi];
	wi++;
	if (wi == xs.size()) return true;
	// cout << "v = " << v << endl;
      }
    }
    return false;
  };

  auto ap = est_p;
  do {
    if (calc(w, k, ap)) {
      break;
    }
    ap++;
  } while (true);
  cout << ap << endl;
  
  return 0;
}

Measured memory_bytes: 3504
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 1; i < (int)n+1; i++)


using namespace std;


 int main(){
 int n, ans, temp;
 cin >> n;

 vector<int> a(21), b(51), c(51);

 rep(i, n){
  cin >> a.at(i);
 }

 rep(i, n){
  cin >> b.at(i);
 }

 rep(i, n-1){
  cin >> c.at(i);
 }

 ans = 0;

 rep(i, n){
  temp = b.at(i);
  ans += temp; 
 }



 rep(i, n-1){
   int FoodNo = a.at(i);
   if (FoodNo +1 == a.at(i+1)) {
     FoodNo = a.at(i);
     ans += c.at(FoodNo);
   }  
 }

  cout << ans << endl;

 return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int sum = 0;
    int n = N;
    while(N>0){
      sum +=N%10;
      N /=10;


    }

    if(n%sum==0){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }


    
  }
}
                          
                         
                    
    
    
    
    
    
    


Measured memory_bytes: 21716
s=input()
np=0
ng=0
ans=0
for si in s:
  if si=='g' and np<ng:
    ans+=1
    np+=1
  elif si=='g' and np>=ng:
    ng+=1
  elif si=='p' and np<ng:
    np+=1
  elif si=='p' and np>=ng:
    ans-=1
    ng+=1
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s,t;
    cin >> s >> t;
    // 先頭から順番に番号をつけていって、一致したらおYES, 一致しなかったらNO
    // 番号と文字列のマッピングをして都度確認していく Map<char, int>
    // 番号をメモするやつ int
    vi a(s.size()), b(s.size());
    int64_t number = 0;
    map<char, int64_t> chmap;
    rep(i,s.size()){
        if(chmap.count(s.at(i))){
            a.at(i) = chmap.at(s.at(i));
        }else{
            chmap.insert(make_pair(s.at(i),number));
            a.at(i) = number;
            number++;
        }
    }
    number = 0;
    chmap.clear();
    rep(i,t.size()){
        if(chmap.count(t.at(i))){
            b.at(i) = chmap.at(t.at(i));
        }else{
            chmap.insert(make_pair(t.at(i),number));
            b.at(i) = number;
            number++;
        }
    }
    bool res = true;
    rep(i,s.size()){
        if(a.at(i)!=b.at(i)){
            res = false;
            break;
        }
    }
    if(res){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3988
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, L = map(int, input().split())
A = list(map(int, input().split()))

large_pair = -1
# 一つでもA[i]+A[i+1]>=Lとなるところが存在すれば、そこを最後まで残して、他を全部解けばいい
for i in range(N-1):
    if A[i]+A[i+1] >= L:
        large_pair = i
        break

if large_pair == -1:
    ans = "Impossible"
    print(ans)
else:
    # 解く順を逆から辿っていく
    ans = "Possible"
    order = [large_pair]
    for a in reversed(range(large_pair)):
        order.append(a)
    for a in range(large_pair+1, N-1):
        order.append(a)

    print(ans)
    print("\n".join(map(lambda x: str(x+1), reversed(order))))


Measured memory_bytes: 69480
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
    int N, A, B; cin >> N >> A >> B;
    string S; cin >> S;
    int nowPass = 0;
    int abroadNum = 0;
    for(auto s : S) {
        if (s == 'a' && nowPass < (A+B)) {
            cout << "Yes" << endl;
            nowPass += 1;
        } else if(s=='b' && nowPass < (A+B) && abroadNum < B) {
            cout << "Yes" << endl;
            nowPass += 1;
            abroadNum += 1;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e2+7, M = 8;
int main()
{
	ll k, a, b, res = 1;
	scanf("%lld%lld%lld", &k, &a, &b);
	if(a>=b)
	{
		printf("%lld\n", res+k);
		return 0;
	}
	if(res+k+1<=a)
	{
		printf("%lld\n", res+k);
		return 0;
	}
	res = b;
	res += ((k-a-1)>>1)*(b-a)+((k-a-1)&1);
	printf("%lld\n", max(k+1, res));
    return 0;
}

Measured memory_bytes: 256
#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define MOD 998244353

int inv(LLI n) {
    LLI r = 1;
    int e = MOD-2;
    while (e > 0) {
        if (e & 1) r *= n,r %= MOD;
        e >>= 1;
        n *= n,n %= MOD;
    }
    return r;
}
int fact[10000001],invfact[10000001];
int main() {
    int N;
    cin >> N;

    int i;
    fact[0] = 1;
    for (i = 1; i <= N; i++) fact[i] = ((LLI) fact[i-1]*i) % MOD;
    invfact[N] = inv(fact[N]);
    for (i = N-1; i >= 0; i--) invfact[i] = ((LLI) invfact[i+1]*(i+1)) % MOD;
    LLI ans = 0,p = 1;
    for (i = 0; i < N/2; i++) p *= 2,p %= MOD;
    for (i = N/2; i >= 0; i--) {
        LLI x = fact[N];
        x *= invfact[i],x %= MOD;
        x *= invfact[N-i],x %= MOD;
        ans += x*p,ans %= MOD;
        p *= 2,p %= MOD;
        LLI y = fact[N-i];
        y *= invfact[N/2],y %= MOD;
        y *= invfact[N/2-i],y %= MOD;
        p += MOD-y,p %= MOD;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    ll dx = tx - sx;
    ll dy = ty - sy;
    rep(i, dx) cout << "R";
    rep(i, dy) cout << "U";

    rep(i, dx) cout << "L";
    rep(i, dy) cout << "D";

    cout << "D";
    rep(i, dx+1) cout << "R";
    rep(i, dy+1) cout << "U";
    cout << "L";

    cout << "U";
    rep(i, dx+1) cout << "L";
    rep(i, dy+1) cout << "D";
    cout << "R";

    cout << endl;
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
     
     
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;
     
     
int main(){
  double T, X;

  cin >> T >> X;

#ifdef DEBUG
  cout << T << ", " << X << endl;
#endif

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n,k;
vector<vector<ll>> dp;
vector<ll> sum;

void rui(int i){
    rep(j,k+2) sum.at(j) = 0; 
    for(int j = 1; j <= k+1; j++){
        sum.at(j) += (sum.at(j-1)+ dp.at(i).at(j-1))%mod;
    }
    return;
}

int main(){

    cin >> n >> k;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++) cin >> a.at(i);
    dp.resize(n+1,vector<ll>(k+1));
    sum.resize(k+2,0);
 
    rep(i,k+1) dp.at(0).at(i) = 0;
    rep(i,n+1) dp.at(i).at(0) = 1;

    for(int i = 1; i <= n; i++){
        rui(i-1);
        for(int j = 1; j <= k; j++){
            int point = max(0,j - a.at(i));
            ll ans = sum.at(j+1) - sum.at(point);
            while(ans < 0) ans += mod;
            dp.at(i).at(j) = ans;
        }
    }
    cout << dp.at(n).at(k) << endl;
    return 0;   

}


Measured memory_bytes: 80256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
#define d read()
ll n,m,q,ans;
ll a[55],b[55],c[55],dd[55];
ll sq[15];
void dfs(ll u,ll st){
	if(u==n+1){
		ll k=0;
		f(i,1,q)if(sq[b[i]]-sq[a[i]]==c[i])k+=dd[i];
		ans=max(ans,k);
		return;
	}
	f(i,st,m)sq[u]=i,dfs(u+1,i);
}
int main(){
	n=d,m=d,q=d;
	f(i,1,q)a[i]=d,b[i]=d,c[i]=d,dd[i]=d;
	dfs(1,1);
	cout<<ans;
	return 0;
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if(a >= k) {
        cout << k << endl;
        return 0;
    }
    if(a + b >= k) {
        cout << a << endl;
        return 0;
    }
    int t = k - (a + b);
    int ans = a;
    ans -= t;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3608
# import sys
# import math #sqrt,gcd
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
from itertools import product,permutations,combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n,m = readInt()
    a = []
    b = []
    for i in range(n):
        x,y = readInt()
        a.append(x)
        b.append(y)
    c = []
    d = []
    for j in range(m):
        x,y = readInt()
        c.append(x)
        d.append(y)
    for i in range(n):
        length = INF
        ans = 0
        for j in range(m):
            if length>abs(a[i]-c[j])+abs(b[i]-d[j]):
                length = abs(a[i]-c[j]) + abs(b[i]-d[j])
                ans = j
        print(ans+1)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long
#define MAX_N 200001

using namespace std;

long long MOD = 1000000007;

long long fact[MAX_N];
void factorial(int N){
    fact[0]=1;
    for(int i=0; i<N; i++){
        fact[i+1]=(i+1)*fact[i]%MOD;
    }
}

map<long long, long long> inv;
long long inverse(long long x){
    if (inv.count(x)){
        return inv[x];
    }
    long long p=MOD-2;
    long long ret=1;
    long long tmp=x;
    while(p>0){
        if(p%2==1)ret=ret*tmp%MOD;
        tmp=tmp*tmp%MOD;
        p/=2;
    }
    inv[x]=ret;
    return ret;
}

long long comb(int a, int b){
    long long ret=fact[a]*inverse(fact[a-b])%MOD;
    return ret*inverse(fact[b])%MOD;
}

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

    factorial(200000);
    ll ans=0;
    for(ll y=0; y<N-1; y++){
        if(N*M-2<K-2)continue;
        ans+=((N+y)*(N-y-1)/2-y*(N-y-1))%MOD*M%MOD*M%MOD*comb(N*M-2,K-2)%MOD;
        ans%=MOD;
    }
    for(ll x=0; x<M-1; x++){
        if(M*N-2<K-2)continue;
        ans+=((M+x)*(M-x-1)/2-x*(M-x-1))%MOD*N%MOD*N%MOD*comb(M*N-2,K-2)%MOD;
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5144
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;

const LLI mod = 1e9+7;

int main(){
  int N;
  string S;
  while(cin >> N >> S){

    LLI ans = 0;

    vector<bool> dir(2*N);
    dir[0] = false;
    FOR(i,1,2*N){
      if(S[i-1] == S[i]) dir[i] = !dir[i-1];
      else dir[i] = dir[i-1];
    }

    bool no = false;
    if(S.front() == 'W' or S.back() == 'W') no = true;
    if(count(ALL(dir),false) != count(ALL(dir),true)) no = true;

    if(not no){
      LLI L = 0, R = 0;

      ans = 1;
      
      REP(i,2*N){
        if(dir[i] == true){
          if(L-R < 0) ans = 0;
          (ans *= (L-R+mod)%mod) %= mod;
          ++R;
        }else{
          ++L;
        }
      }

      FORE(i,1,N) (ans *= i) %= mod;
    }
    
    cout << ans << endl;    
  }

  return 0;
}


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

int main() {
    int n;
    cin >> n;
    string ans = "";
    while(n) {
        if(n%2==0) {
            ans += "0";
            n /= -2;
        } else {
            ans += "1";
            n--;
            n /= -2;
        }
    }
    if(ans == "") ans += "0";
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
}


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

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

ll GCD(ll a, ll b)
{
	ll max = std::max(a, b);
	ll min = std::min(a, b);
	ll div = max%min;
	if (div == 0)return min;
	return GCD(min, div);
}

ll LCM(ll a, ll b)
{
	ll gcd = GCD(a, b);
	return (a / gcd)*b;
}

ll T[105];

int main()
{
	int N;
	cin >> N;
	REP(i, N)
	{
		cin >> T[i];
	}
	REP(i, N - 1)
	{
		T[i + 1] = LCM(T[i], T[i + 1]);
	}
	cout << T[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main()
    {
        var NMX = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
        var N = NMX[0];					//本の種類N
        var M = NMX[1];					//アルゴリズムの種類M
        var X = NMX[2];					//目標経験値
        var exs = new int[N, M + 1];	//経験値群の二次元配列
        var prices = new int[N];		//書籍の値段リスト
        var index = new int[N];			//全件検索チェック用の配列
		
		//書籍から得られるアルゴリズムごとの経験値を二次元配列で保持する
        for (int n = 0; n < N; n++)
        {
            var ex = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
            prices[n] = ex[0];
            index[n] = n;
            for (int m = 1; m < M + 1; m++)
            {
                exs[n, m-1] = ex[m];
            }
        }
        
        var ans =int.MaxValue;
		//書籍の数分ループする
        for (int cnt = 1; cnt < N + 1; cnt++)
        {
			//全件検索のためIEnumerableインターフェースを返すメソッドをループする
            foreach (var cases in CasesReturn<int>(index, cnt))
            {
                var contFlg = true;	//Xを上回っているか判断するためのフラグ
                for(var m = 0;m < M;m++)
                {
					//チェック変数ですべての書籍による経験値がXを上回っていることを確認する
                    var check = 0;
                    foreach(var c in cases)
                    {
                        check = check + exs[c,m];
                    }
                    
					//Xより下回っている場合、ループを抜ける、また継続フラグをfalseにする
                    if(check < X) 
                    {
                        contFlg = false;
                        break;
                    }
                }
                if (contFlg)
                {
					//継続フラグ==>Trueの場合、条件を満たすので、解答用変数に結果を入力する
                    var priceCheck = 0;
                    foreach(var c in cases)
                    {
                        priceCheck = priceCheck + prices[c];
                    }
                    if (priceCheck < ans)
                    {
						//最小値を算出するため、これまでの最小値であることを確かめる
                        ans = priceCheck;
                    }
                }
            }
        }
        if(ans == int.MaxValue)
        {
            Console.WriteLine("-1");
        }
        else
        {
            Console.WriteLine(ans);
        }
    }
	
	//
    public static IEnumerable<T[]> CasesReturn<T>(IEnumerable<T> prices, int cnt)
    {
		//カウントが1の場合、配列の要素をひとつずつ返却する
        if (cnt == 1)
        {
            foreach (var p in prices)
            {
                yield return new T[] { p };
            }
            yield break;
        }
        else
        {
			//カウントが1より大きい場合、再帰的にCaseReturnを呼び出す
            foreach(var p in prices)
            {
                var left = new T[] { p };
                
                //pより前にある要素をすべてスキップして要素pもスキップする
                var used = prices.SkipWhile(e => !e.Equals(p)).Skip(1).ToArray();
                foreach (var cases in CasesReturn(used,cnt-1))
                {
					//最も左側の要素と返された配列の要素を結合する
                    yield return left.Concat(cases).ToArray();
                }
            }
        }
    }
}


Measured memory_bytes: 41228
#include<cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
    int w,a,b;
    while(~scanf("%d%d%d",&w,&a,&b))
    {
        int t;
        if(b<a)
        {
            t=a;
            a=b;
            b=t;
        }
        int res=b-a-w;
        if(res<0)
            printf("0\n");
        else
            printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <vector>
using namespace std;
int main(){
    string s;
    cin>>s;
    int a=s[0]-48;
    int b=s[1]-48;
    int c=s[2]-48;
    int d=s[3]-48;
    if(a+b+c+d==7)cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    else if(a+b+c-d==7)cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    else if(a+b-c+d==7)cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    else if(a+b-c-d==7)cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
    else if(a-b+c+d==7)cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    else if(a-b+c-d==7)cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    else if(a-b-c+d==7)cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    else if(a-b-c-d==7)cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
    return 0;
}

Measured memory_bytes: 256
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, a, b = sc.nextInt

  val ans = min(a * n, b)

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 27448
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n, m;
    cin >> n >> m;
    cout << + (int)pow(2,m)*(m*1900+(n - m) * 100)  << endl;

    return 0;
}


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

using namespace std;

int main()
{
    string str;
    while(cin >> str) {
        int cpos = -1, fpos = -1;
        for(int i = 0; i < str.size(); ++ i) {
            if(str[i] == 'C' && cpos == -1) cpos = i;
            if(str[i] == 'F') fpos = i;
        }
        if(cpos != -1 && fpos != -1 && cpos < fpos) cout << "Yes" << endl;
        else cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

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

long long lcm(long long a,long long b)
{
    long long d = gcd(a,b);
    return (a/d)*b;
}

int main()
{
    long long a,b;
    while(scanf("%lld %lld",&a,&b) != EOF)
    {
        printf("%lld %lld\n",gcd(a,b),lcm(a,b));
    }
    return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

void solve() 
{
    int n;cin>>n;vector<int>p(n);vector<int>q(n);REP(i,n)cin>>p[i];REP(i,n)cin>>q[i];
    int ans1=0,ans2=0;
    while(next_permutation(p.begin(),p.end()))
        ans1++;
    while(next_permutation(q.begin(),q.end()))
        ans2++;
    cout<<abs(ans1-ans2)<<endl;
}

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


Measured memory_bytes: 384
// 2016-12-12
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;

int main() {
	int n, v[100];
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			char c;
			cin >> c;
			v[i] = c - 'A';
		}
		pair<int, int> a[26];
		for (int i = 0; i < 26; i++) {
			a[i] = make_pair(0, i);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 26; j++) {
				if (v[i] == a[j].second) {
					a[j].first++;
					break;
				}
			}
			sort(a, a + 26);
			if (a[25].first - a[24].first > n - i - 1) {
				cout << char(a[25].second + 'A') << ' ' << i + 1 << endl;
				break;
			}
		}
		if (a[25].first == a[24].first) {
			cout << "TIE" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <unordered_map>
#define lli long long int
#define fl(i, a, b) for(int i = a; i < b; ++i)
#define fl2(i, a, b) for(int i = a; i <= b; ++i)
#define rfl(i, a, b) for(int i = a; i > b; --i)
#define rfl2(i, a, b) for(int i = a; i >= b; ++i)
#define all(v) ((v).begin(), (v).end())
#define all2(v) ((a) + 0, (a) + n);
#define sz(s) (s).size()
#define OO (lli)1e18
#define MIN INT_MIN
#define f first
#define s second		
#define mp make_pair
#define pb puch_back
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
using namespace std;

lli power(lli x, lli y) {
	lli i, power = 1;
	if (y == 0)
		return 1;
	for (i = 1; i <= y; i++)
		power = power * x;
	return power;
}

int32_t main() {

	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	//freopen("overcode.in","r",stdin);
	//freopen("output.txt", "w", stdout);

	clock_t z = clock();

	int a, b, c;
	cin >> a >> b >> c;
	a -= b;
	if (a >= c) cout << 0;
	else cout << c - a;
	cout << '\n';

	debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 256